29 m_minCorner(minCorner),
30 m_maxCorner(maxCorner),
58 if (!
init(vertCount,
true, triCount, 0)) {
83 if (
x != 0 ||
y != 0) {
99 if (
x != 0 &&
y != 0) {
101 unsigned iB = iA + 1;
128 QString(
"[ccQuadric::fitTo] Not enough points in input cloud "
129 "to fit a quadric! (%1 at the very least are required)")
143 "[ccQuadric::Fit] Not enough points to fit a quadric!");
165 for (
unsigned k = 0; k <
count; ++k) {
203 const unsigned char dX = dims.
x;
204 const unsigned char dY = dims.
y;
209 for (
unsigned k = 0; k <
count; ++k) {
214 eq[0] + eq[1] * P->
u[dX] + eq[2] * P->
u[dY] +
215 eq[3] * P->
u[dX] * P->
u[dX] + eq[4] * P->
u[dX] * P->
u[dY] +
216 eq[5] * P->
u[dY] * P->
u[dY];
217 *rms += (
z - P->
z) * (
z - P->
z);
221 *rms = sqrt(*rms /
count);
222 quadric->
setMetaData(QString(
"RMS"), QVariant(*rms));
235 const unsigned char dX =
m_dims.
x;
236 const unsigned char dY =
m_dims.
y;
237 const unsigned char dZ =
m_dims.
z;
241 m_eq[3] * Q.
u[dX] * Q.
u[dX] +
m_eq[4] * Q.
u[dX] * Q.
u[dY] +
242 m_eq[5] * Q.
u[dY] * Q.
u[dY];
246 return originalZ - Q.
u[dZ];
250 const unsigned char dX =
m_dims.
x;
251 const unsigned char dY =
m_dims.
y;
252 const unsigned char dZ =
m_dims.
z;
253 static const char dimChars[3] = {
'x',
'y',
'z'};
255 QString equationStr = QString(
"%1 = %2 + %3 * %4")
260 equationStr += QString(
" + %1 * %2 + %3 * %4^2")
265 equationStr += QString(
" + %1 * %2*%3 + %4 * %5^2")
276 assert(out.isOpen() && (out.openMode() & QIODevice::WriteOnly));
277 if (dataVersion < 35) {
285 QDataStream outStream(&out);
291 for (
unsigned i = 0; i < 6; ++i) outStream <<
m_eq[i];
297 return std::max(
static_cast<short>(35),
310 QDataStream inStream(&in);
320 for (
unsigned i = 0; i < 6; ++i)
constexpr unsigned CV_LOCAL_MODEL_MIN_SIZE[]
Min number of points to compute local models (see CV_LOCAL_MODEL_TYPES)
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
float PointCoordinateType
Type of the coordinates of a (N-D) point.
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Type dot(const Vector3Tpl &v) const
Dot product.
ccGLMatrixTpl< T > inverse() const
Returns inverse transformation.
void apply(float vec[3]) const
Applies transformation to a 3D vector (in place) - float version.
Float version of ccGLMatrixTpl.
ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
Generic primitive interface.
bool init(unsigned vertCount, bool vertNormals, unsigned faceCount, unsigned faceNormCount)
Inits internal structures.
virtual bool setDrawingPrecision(unsigned steps)
Sets drawing precision.
ccGenericPrimitive * finishCloneJob(ccGenericPrimitive *primitive) const
Finished 'clone' job (vertices color, etc.)
ccPointCloud * vertices()
Returns vertices.
unsigned m_drawPrecision
Drawing precision (for primitives that support this feature)
static const int MIN_DRAWING_PRECISION
Minimum drawing precision.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
ccGLMatrix m_transformation
Associated transformation (applied to vertices)
short minimumFileVersion_MeOnly() const override
void addTriangle(unsigned i1, unsigned i2, unsigned i3)
Adds a triangle to the mesh.
bool computeNormals(bool perVertex)
Computes normals.
virtual QString getName() const
Returns object name.
void setMetaData(const QString &key, const QVariant &data)
Sets a meta-data element.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool hasNormals() const override
Returns whether normals are enabled or not.
bool reserve(unsigned numberOfPoints) override
Reserves memory for all the active features.
CCVector2 m_maxCorner
Max corner.
short minimumFileVersion_MeOnly() const override
PointCoordinateType m_minZ
Min height.
CCVector2 m_minCorner
Min corner.
ccQuadric(CCVector2 minCorner, CCVector2 maxCorner, const PointCoordinateType eq[6], const Tuple3ub *dims=0, const ccGLMatrix *transMat=0, QString name=QString("Quadric"), unsigned precision=DEFAULT_DRAWING_PRECISION)
Default constructor.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
Tuple3ub m_dims
Dimension indexes.
QString getEquationString() const
Returns the quadric equation coefficients as a string.
PointCoordinateType m_eq[6]
Equation coefficients.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
PointCoordinateType m_maxZ
Max height.
static ccQuadric * Fit(cloudViewer::GenericIndexedCloudPersist *cloud, double *rms)
Fits a quadric primitive on a cloud.
virtual ccGenericPrimitive * clone() const override
Clones primitive.
PointCoordinateType projectOnQuadric(const CCVector3 &P, CCVector3 &Q) const
Projects a 3D point in the quadric coordinate system.
virtual ccBBox getOwnFitBB(ccGLMatrix &trans) override
Returns best-fit bounding-box (if available)
virtual bool buildUp() override
Builds primitive.
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
static void CoordsFromDataStream(QDataStream &stream, int flags, PointCoordinateType *out, unsigned count=1)
const Vector3Tpl< T > & maxCorner() const
Returns max corner (const)
const Vector3Tpl< T > & minCorner() const
Returns min corner (const)
virtual void placeIteratorAtBeginning()=0
Sets the cloud iterator at the beginning.
virtual const CCVector3 * getNextPoint()=0
Returns the next point (relatively to the global iterator position)
virtual unsigned size() const =0
Returns the number of points.
A generic 3D point cloud with index-based and presistent access to points.
const PointCoordinateType * getQuadric(Tuple3ub *dims=nullptr)
Returns the best interpolating 2.5D quadric.
const CCVector3 * getLSPlaneY()
Returns best interpolating plane (Least-square) 'Y' base vector.
const PointCoordinateType * getLSPlane()
Returns best interpolating plane equation (Least-square)
const CCVector3 * getGravityCenter()
Returns gravity center.
void setLSPlane(const PointCoordinateType eq[4], const CCVector3 &X, const CCVector3 &Y, const CCVector3 &N)
Sets the best interpolating plane equation (Least-square)
const CCVector3 * getLSPlaneX()
Returns best interpolating plane (Least-square) 'X' base vector.
void setGravityCenter(const CCVector3 &G)
Sets gravity center.
void addPoint(const CCVector3 &P)
Adds a 3D point to the database.
const CCVector3 * getPoint(unsigned index) const override