Skip to content

Commit

Permalink
Syntax fix + proper propagation of the'local quadric coordinate system
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardeau committed Jan 4, 2025
1 parent 29c748b commit 4514bbc
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 327 deletions.
19 changes: 7 additions & 12 deletions include/Neighbourhood.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "GenericIndexedCloudPersist.h"
#include "SquareMatrix.h"


namespace CCCoreLib
{
class GenericIndexedMesh;
Expand Down Expand Up @@ -260,11 +259,12 @@ namespace CCCoreLib
//! Returns the best interpolating 2.5D quadric
/** Returns an array of the form [a,b,c,d,e,f] such as:
Z = a + b.X + c.Y + d.X^2 + e.X.Y + f.Y^2
\warning: 'X','Y' and 'Z' are output in dims (optional):
dims = [index(X),index(Y),index(Z)] where: 0=x, 1=y, 2=z
\warning: 'X','Y' and 'Z' are implicitly expressed in a local coordinate system (see 'toLocalCS')
\param[out] toLocalOrientation optional 3x3 matrix to convert the points to the local coordinate/orientation system in which the Quadric is expressed
(point coordinates should already be expressed relative to the gravity center)
\return nullptr if computation failed
**/
const PointCoordinateType* getQuadric(Tuple3ub* dims = nullptr);
const PointCoordinateType* getQuadric(SquareMatrix* localOrientation = nullptr);

//! Computes the best interpolating quadric (Least-square)
/** \param[out] quadricEquation an array of 10 coefficients [a,b,c,d,e,f,g,l,m,n] such as
Expand All @@ -279,10 +279,6 @@ namespace CCCoreLib
//! Returns the set 'radius' (i.e. the distance between the gravity center and the its farthest point)
PointCoordinateType computeLargestRadius();

double* initFromParameters(double alpha_rad,
const Vector3Tpl<double>& axis3D,
const Vector3Tpl<double>& t3D);

protected:

//! 2.5D Quadric equation
Expand All @@ -292,11 +288,10 @@ namespace CCCoreLib
**/
PointCoordinateType m_quadricEquation[6];

//! 2.5D Quadric equation dimensions
/** Array (index(X),index(Y),index(Z)) where: 0=x, 1=y, 2=z
Only valid if 'structuresValidity & QUADRIC != 0'.
//! 2.5D Quadric equation local coordinate/orientation system
/** Only valid if 'structuresValidity & QUADRIC != 0'.
**/
Tuple3ub m_quadricEquationDirections;
SquareMatrix m_quadricEquationOrientation;

//! Least-square best fitting plane parameters
/** Array [a,b,c,d] such that ax+by+cz = d
Expand Down
47 changes: 21 additions & 26 deletions src/LocalModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,15 @@ class QuadricLocalModel : public LocalModel

//! Constructor
QuadricLocalModel( const PointCoordinateType eq[6],
unsigned char X,
unsigned char Y,
unsigned char Z,
CCVector3 gravityCenter,
const SquareMatrix& localOrientation,
const CCVector3& gravityCenter,
const CCVector3 &center,
PointCoordinateType squaredRadius )
: LocalModel(center, squaredRadius)
, m_X(X)
, m_Y(Y)
, m_Z(Z)
, m_localOrientation(localOrientation)
, m_gravityCenter(gravityCenter)
{
m_localOrientationInv = m_localOrientation.inv();
memcpy(m_eq, eq, sizeof(PointCoordinateType) * 6);
}

Expand All @@ -130,31 +127,31 @@ class QuadricLocalModel : public LocalModel
//inherited from LocalModel
ScalarType computeDistanceFromModelToPoint(const CCVector3* _P, CCVector3* nearestPoint = nullptr) const override
{
CCVector3 P = *_P - m_gravityCenter;
CCVector3 Plocal = m_localOrientation * (*_P - m_gravityCenter);

//height = h0 + h1.x + h2.y + h3.x^2 + h4.x.y + h5.y^2
PointCoordinateType z = m_eq[0] + m_eq[1] * P.u[m_X] + m_eq[2] * P.u[m_Y] + m_eq[3] * P.u[m_X] * P.u[m_X] + m_eq[4] * P.u[m_X] * P.u[m_Y] + m_eq[5] * P.u[m_Y] * P.u[m_Y];
PointCoordinateType z = m_eq[0]
+ m_eq[1] * Plocal.x
+ m_eq[2] * Plocal.y
+ m_eq[3] * Plocal.x * Plocal.x
+ m_eq[4] * Plocal.x * Plocal.y
+ m_eq[5] * Plocal.y * Plocal.y;

if (nearestPoint)
{
nearestPoint->u[m_X] = P.u[m_X];
nearestPoint->u[m_Y] = P.u[m_Y];
nearestPoint->u[m_Z] = z;
*nearestPoint = m_localOrientationInv * CCVector3(Plocal.x, Plocal.y, z);
}

return static_cast<ScalarType>(std::abs(P.u[m_Z] - z));
return static_cast<ScalarType>(std::abs(Plocal.z - z));
}

protected:

//! Quadric equation
PointCoordinateType m_eq[6];
//! Height function first dimension (0=X, 1=Y, 2=Z)
unsigned char m_X;
//! Height function second dimension (0=X, 1=Y, 2=Z)
unsigned char m_Y;
//! Height function third dimension (0=X, 1=Y, 2=Z)
unsigned char m_Z;
//! Quadric local 'orientation' system
SquareMatrix m_localOrientation;
//! Quadric local 'orientation' system (inverse)
SquareMatrix m_localOrientationInv;
//! Model gravity center
CCVector3 m_gravityCenter;

Expand Down Expand Up @@ -202,17 +199,15 @@ LocalModel* LocalModel::New(LOCAL_MODEL_TYPES type,

case QUADRIC:
{
Tuple3ub dims;
const PointCoordinateType* eq = subset.getQuadric(&dims);
SquareMatrix toLocalCS;
const PointCoordinateType* eq = subset.getQuadric(&toLocalCS);
if (eq)
{
return new QuadricLocalModel( eq,
dims.x,
dims.y,
dims.z,
toLocalCS,
*subset.getGravityCenter(), //should be ok as the quadric computation succeeded!
center,
squaredRadius);
squaredRadius );
}
}
break;
Expand Down
Loading

0 comments on commit 4514bbc

Please sign in to comment.