Skip to content

Commit

Permalink
Merge pull request #1719 from DGtal-team/FixAreaWinding
Browse files Browse the repository at this point in the history
Fixing Point Areas in WindingNumbersShape
  • Loading branch information
dcoeurjo authored Mar 26, 2024
2 parents 640fd9e + cd29dc7 commit c3c5b19
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
- Fix duplicate symbols on Windows due to stb_image, see issue #1714 (David Coeurjolly,
[#1715](https://github.com/DGtal-team/DGtal/pull/1715)


- *Shapes*
- Add flips to SurfaceMesh data structure
(Jacques-Olivier Lachaud, [#1702](https://github.com/DGtal-team/DGtal/pull/1702))
- Add method to remove isolated vertices in Mesh, improve obj
material reading from potential obsolete path. (Bertrand Kerautret,
[#1709](https://github.com/DGtal-team/DGtal/issues/1709))

- Update of the WindingNumber constructor to allow external computation of point areas
(David Coeurjolly,[#1719](https://github.com/DGtal-team/DGtal/issues/1719))

- *Github*
- New `/builddoc` and `/fullbuild` commands on PR comments (David Coeurjolly,
Expand Down
42 changes: 23 additions & 19 deletions src/DGtal/shapes/WindingNumbersShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,36 @@ namespace DGtal
/// Construct a WindingNumberShape Euclidean shape from an oriented point cloud.
/// This constructor estimates the @a area @a of each point using CGAL.
///
/// If the number of points is greater than 20, CGAL is used to estimate the
/// per-sample area.
/// If the number of points is greater than 20, CGAL is used to estimate the
/// per-sample area (if skipPointAreas is set to false).
///
/// @param points a "nx3" matrix with the sample coordinates.
/// @param normals a "nx3" matrix for the normal vectors.
WindingNumbersShape(ConstAlias<Eigen::MatrixXd> points,
ConstAlias<Eigen::MatrixXd> normals)
/// @param skipPointAreas if true, we do not estimate the point areas using CGAL (default: false)
WindingNumbersShape(ConstAlias<Eigen::MatrixXd> points,
ConstAlias<Eigen::MatrixXd> normals,
bool skipPointAreas = false)
{
myPoints = points;
myNormals = normals;
myPointAreas = Eigen::VectorXd::Ones(myPoints->rows());
// Build octree, from libIGL tutorials
igl::octree(*myPoints,myO_PI,myO_CH,myO_CN,myO_W);
if (points->rows()> 20)
{
Eigen::MatrixXi I;
igl::knn(*myPoints,(int)points->rows(),myO_PI,myO_CH,myO_CN,myO_W,I);
// CGAL is only used to help get point areas
igl::copyleft::cgal::point_areas(*myPoints,I,*myNormals,myPointAreas);
trace.info()<<" Min/max point area : "<<myPointAreas.minCoeff()<<" -- "<<myPointAreas.maxCoeff()<<std::endl;
}
if (skipPointAreas)
trace.warning()<<"[WindingNumberShape] Skipping the CGAL point area estimation. By default, point areas are set to 1.0"<<std::endl;
else
{
trace.warning()<<"[WindingNumberShape] Too few points to use CGAL point_areas. Using the constant area setting."<<std::endl;
}
if (points->rows()> 20)
{
Eigen::MatrixXi I;
igl::knn(*myPoints,(int)points->rows(),myO_PI,myO_CH,myO_CN,myO_W,I);
// CGAL is only used to help get point areas
igl::copyleft::cgal::point_areas(*myPoints,I,*myNormals,myPointAreas);
trace.info()<<"[WindingNumberShape] Min/max point area : "<<myPointAreas.minCoeff()<<" -- "<<myPointAreas.maxCoeff()<<std::endl;
}
else
{
trace.warning()<<"[WindingNumberShape] Too few points to use CGAL point_areas. Using the constant area setting."<<std::endl;
}
}

/// Construct a WindingNumberShape Euclidean shape from an oriented point cloud.
Expand Down Expand Up @@ -155,11 +160,11 @@ namespace DGtal
const double threshold = 0.3) const
{
Eigen::VectorXd W;
std::vector<Orientation> results( queries.rows() );
std::vector<Orientation> results( queries.rows(), DGtal::OUTSIDE );
Eigen::MatrixXd O_CM;
Eigen::VectorXd O_R;
Eigen::MatrixXd O_EC;

//Checking if the areas
igl::fast_winding_number(*myPoints,*myNormals,myPointAreas,myO_PI,myO_CH,2,O_CM,O_R,O_EC);
igl::fast_winding_number(*myPoints,*myNormals,myPointAreas,myO_PI,myO_CH,O_CM,O_R,O_EC,queries,2,W);
Expand All @@ -185,7 +190,6 @@ namespace DGtal
///Const alias to point area measure
Eigen::VectorXd myPointAreas;


///libIGL octree for fast queries data structure
std::vector<std::vector<int > > myO_PI;
///libIGL octree for fast queries data structure
Expand All @@ -194,7 +198,7 @@ namespace DGtal
Eigen::MatrixXd myO_CN;
///libIGL octree for fast queries data structure
Eigen::VectorXd myO_W;


};
}
Expand Down
4 changes: 2 additions & 2 deletions src/DGtal/shapes/doc/moduleWinding.dox
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ std::vector<Orientation> orientations = winding.orientationBatch(queries);
The output vector contains the orientation of the query points in the same order.

At this point, we completely rely on libIGL and CGAL to estimate the @f$ a_i @f$ area measures. If the user
wants to provide these quantities, the @f$\{a_i\}@f$ can be prescribed at the constructor, or using the `setAreaMeasure()` method.
wants to provide these quantities, the @f$\{a_i\}@f$ can be prescribed at the constructor, or using the `setAreaMeasure()` method (with a `skipPointAreas` to `true` at the constructor).

@note The orientation methods have a default thresholding parameter set to 0.3. Please check the class documentation for details.

*/
}
}

0 comments on commit c3c5b19

Please sign in to comment.