Skip to content

Commit

Permalink
Add optional parameter to the ComputeCharacteristic method to pass a …
Browse files Browse the repository at this point in the history
…'up direction' to compute signed roughness
  • Loading branch information
dgirardeau committed Jan 12, 2022
1 parent 3d13c41 commit 6d17497
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
2 changes: 2 additions & 0 deletions include/GeometricalAnalysisTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace CCCoreLib
\param subOption feature / curvature type / local density computation algorithm or nothing (0)
\param cloud cloud to compute the characteristic on
\param kernelRadius neighbouring sphere radius
\param roughnessUpDir up direction to compute signed roughness values (optional)
\param progressCb client application can get some notification of the process progress through this callback mechanism (see GenericProgressCallback)
\param inputOctree if not set as input, octree will be automatically computed.
\return succes
Expand All @@ -56,6 +57,7 @@ namespace CCCoreLib
int subOption,
GenericIndexedCloudPersist* cloud,
PointCoordinateType kernelRadius,
const CCVector3* roughnessUpDir = nullptr,
GenericProgressCallback* progressCb = nullptr,
DgmOctree* inputOctree = nullptr);

Expand Down
8 changes: 5 additions & 3 deletions include/Neighbourhood.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,13 @@ namespace CCCoreLib
**/
ScalarType computeMomentOrder1(const CCVector3& P);

//! Computes the roughness of a set of point (by fitting a 2D plane)
/** \return roughness value at a given position P
//! Computes the roughness of a point (by fitting a 2D plane on its neighbors)
/** \param P point for which to compute the roughness value
\param roughnessUpDir up direction to compute a signed roughness value (optional)
\return roughness value at a given position P
\warning The point P shouldn't be in the set of points
**/
ScalarType computeRoughness(const CCVector3& P);
ScalarType computeRoughness(const CCVector3& P, const CCVector3* roughnessUpDir = nullptr);

//! Computes the curvature of a set of point (by fitting a 2.5D quadric)
/** \return curvature value at a given position P or CCCoreLib::NAN_VALUE if the computation failed
Expand Down
15 changes: 9 additions & 6 deletions src/GeometricalAnalysisTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ GeometricalAnalysisTools::ErrorCode GeometricalAnalysisTools::ComputeCharactersi
int subOption,
GenericIndexedCloudPersist* cloud,
PointCoordinateType kernelRadius,
const CCVector3* roughnessUpDir/*=nullptr*/,
GenericProgressCallback* progressCb/*=nullptr*/,
DgmOctree* inputOctree/*=nullptr*/)
{
Expand Down Expand Up @@ -104,7 +105,8 @@ GeometricalAnalysisTools::ErrorCode GeometricalAnalysisTools::ComputeCharactersi
{
static_cast<void*>(&c),
static_cast<void*>(&subOption),
static_cast<void*>(&kernelRadius)
static_cast<void*>(&kernelRadius),
static_cast<void*>(const_cast<CCVector3*>(roughnessUpDir))
};

ErrorCode result = NoError;
Expand Down Expand Up @@ -165,12 +167,13 @@ GeometricalAnalysisTools::ErrorCode GeometricalAnalysisTools::ComputeCharactersi

bool GeometricalAnalysisTools::ComputeGeomCharacteristicAtLevel(const DgmOctree::octreeCell& cell,
void** additionalParameters,
NormalizedProgress* nProgress/*=0*/)
NormalizedProgress* nProgress/*=nullptr*/)
{
//parameters
GeomCharacteristic c = *static_cast<GeomCharacteristic*>(additionalParameters[0]);
int subOption = *static_cast<Neighbourhood::CurvatureType*>(additionalParameters[1]);
PointCoordinateType radius = *static_cast<PointCoordinateType*>(additionalParameters[2]);
GeomCharacteristic c = *static_cast<GeomCharacteristic*>(additionalParameters[0]);
int subOption = *static_cast<Neighbourhood::CurvatureType*>(additionalParameters[1]);
PointCoordinateType radius = *static_cast<PointCoordinateType*>(additionalParameters[2]);
const CCVector3* roughnessUpDir = static_cast<const CCVector3*>(additionalParameters[3]);

//structure for nearest neighbors search
DgmOctree::NearestNeighboursSphericalSearchStruct nNSS;
Expand Down Expand Up @@ -257,7 +260,7 @@ bool GeometricalAnalysisTools::ComputeGeomCharacteristicAtLevel(const DgmOctree:

DgmOctreeReferenceCloud neighboursCloud(&nNSS.pointsInNeighbourhood, neighborCount - 1); //we don't take the query point into account!
Neighbourhood Z(&neighboursCloud);
value = Z.computeRoughness(nNSS.queryPoint);
value = Z.computeRoughness(nNSS.queryPoint, roughnessUpDir);

//swap the points back to their original position (DGM: not necessary in this case)
//if (localIndex+1 < neighborCount)
Expand Down
16 changes: 14 additions & 2 deletions src/Neighbourhood.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,12 +901,24 @@ double Neighbourhood::computeFeature(GeomFeature feature)
return value;
}

ScalarType Neighbourhood::computeRoughness(const CCVector3& P)
ScalarType Neighbourhood::computeRoughness(const CCVector3& P, const CCVector3* roughnessUpDir/*=nullptr*/)
{
const PointCoordinateType* lsPlane = getLSPlane();
if (lsPlane)
{
return std::abs(DistanceComputationTools::computePoint2PlaneDistance(&P, lsPlane));
ScalarType distToPlane = DistanceComputationTools::computePoint2PlaneDistance(&P, lsPlane);
if (roughnessUpDir)
{
if (CCVector3::vdot(lsPlane, roughnessUpDir->u) < 0)
{
distToPlane = -distToPlane;
}
}
else
{
distToPlane = std::abs(distToPlane);
}
return distToPlane;
}
else
{
Expand Down

0 comments on commit 6d17497

Please sign in to comment.