Skip to content

Commit a58db93

Browse files
committed
Add optional parameter to the ComputeCharacteristic method to pass a 'up direction' to compute signed roughness
1 parent 3d13c41 commit a58db93

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

include/GeometricalAnalysisTools.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace CCCoreLib
4848
\param subOption feature / curvature type / local density computation algorithm or nothing (0)
4949
\param cloud cloud to compute the characteristic on
5050
\param kernelRadius neighbouring sphere radius
51+
\param roughnessUpDir up direction to compute signed roughness values (optional)
5152
\param progressCb client application can get some notification of the process progress through this callback mechanism (see GenericProgressCallback)
5253
\param inputOctree if not set as input, octree will be automatically computed.
5354
\return succes
@@ -56,6 +57,7 @@ namespace CCCoreLib
5657
int subOption,
5758
GenericIndexedCloudPersist* cloud,
5859
PointCoordinateType kernelRadius,
60+
CCVector3* roughnessUpDir = nullptr,
5961
GenericProgressCallback* progressCb = nullptr,
6062
DgmOctree* inputOctree = nullptr);
6163

include/Neighbourhood.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,13 @@ namespace CCCoreLib
194194
**/
195195
ScalarType computeMomentOrder1(const CCVector3& P);
196196

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

203205
//! Computes the curvature of a set of point (by fitting a 2.5D quadric)
204206
/** \return curvature value at a given position P or CCCoreLib::NAN_VALUE if the computation failed

src/GeometricalAnalysisTools.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ GeometricalAnalysisTools::ErrorCode GeometricalAnalysisTools::ComputeCharactersi
2626
int subOption,
2727
GenericIndexedCloudPersist* cloud,
2828
PointCoordinateType kernelRadius,
29+
CCVector3* roughnessUpDir/*=nullptr*/,
2930
GenericProgressCallback* progressCb/*=nullptr*/,
3031
DgmOctree* inputOctree/*=nullptr*/)
3132
{
@@ -104,7 +105,8 @@ GeometricalAnalysisTools::ErrorCode GeometricalAnalysisTools::ComputeCharactersi
104105
{
105106
static_cast<void*>(&c),
106107
static_cast<void*>(&subOption),
107-
static_cast<void*>(&kernelRadius)
108+
static_cast<void*>(&kernelRadius),
109+
static_cast<void*>(roughnessUpDir)
108110
};
109111

110112
ErrorCode result = NoError;
@@ -165,12 +167,13 @@ GeometricalAnalysisTools::ErrorCode GeometricalAnalysisTools::ComputeCharactersi
165167

166168
bool GeometricalAnalysisTools::ComputeGeomCharacteristicAtLevel(const DgmOctree::octreeCell& cell,
167169
void** additionalParameters,
168-
NormalizedProgress* nProgress/*=0*/)
170+
NormalizedProgress* nProgress/*=nullptr*/)
169171
{
170172
//parameters
171173
GeomCharacteristic c = *static_cast<GeomCharacteristic*>(additionalParameters[0]);
172174
int subOption = *static_cast<Neighbourhood::CurvatureType*>(additionalParameters[1]);
173175
PointCoordinateType radius = *static_cast<PointCoordinateType*>(additionalParameters[2]);
176+
CCVector3* roughnessUpDir = static_cast<CCVector3*>(additionalParameters[3]);
174177

175178
//structure for nearest neighbors search
176179
DgmOctree::NearestNeighboursSphericalSearchStruct nNSS;
@@ -257,7 +260,7 @@ bool GeometricalAnalysisTools::ComputeGeomCharacteristicAtLevel(const DgmOctree:
257260

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

262265
//swap the points back to their original position (DGM: not necessary in this case)
263266
//if (localIndex+1 < neighborCount)

src/Neighbourhood.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,12 +901,24 @@ double Neighbourhood::computeFeature(GeomFeature feature)
901901
return value;
902902
}
903903

904-
ScalarType Neighbourhood::computeRoughness(const CCVector3& P)
904+
ScalarType Neighbourhood::computeRoughness(const CCVector3& P, CCVector3* roughnessUpDir/*=nullptr*/)
905905
{
906906
const PointCoordinateType* lsPlane = getLSPlane();
907907
if (lsPlane)
908908
{
909-
return std::abs(DistanceComputationTools::computePoint2PlaneDistance(&P, lsPlane));
909+
ScalarType distToPlane = DistanceComputationTools::computePoint2PlaneDistance(&P, lsPlane);
910+
if (roughnessUpDir)
911+
{
912+
if (CCVector3::vdot(lsPlane, roughnessUpDir->u) < 0)
913+
{
914+
distToPlane = -distToPlane;
915+
}
916+
}
917+
else
918+
{
919+
distToPlane = std::abs(distToPlane);
920+
}
921+
return distToPlane;
910922
}
911923
else
912924
{

0 commit comments

Comments
 (0)