DGtal  1.5.beta
dgtalCalculus-geodesic.cpp File Reference
#include <iostream>
#include <string>
#include <DGtal/base/Common.h>
#include <DGtal/helpers/StdDefs.h>
#include <DGtal/helpers/Shortcuts.h>
#include <DGtal/helpers/ShortcutsGeometry.h>
#include <DGtal/shapes/SurfaceMesh.h>
#include <DGtal/geometry/surfaces/DigitalSurfaceRegularization.h>
#include <DGtal/dec/PolygonalCalculus.h>
#include <DGtal/dec/GeodesicsInHeat.h>
#include <polyscope/polyscope.h>
#include <polyscope/surface_mesh.h>
#include <polyscope/point_cloud.h>
#include "ConfigExamples.h"
#include <Eigen/Dense>
#include <Eigen/Sparse>
Include dependency graph for dgtalCalculus-geodesic.cpp:

Go to the source code of this file.

Typedefs

typedef Shortcuts< Z3i::KSpaceSH3
 
typedef ShortcutsGeometry< Z3i::KSpaceSHG3
 
typedef SurfaceMesh< RealPoint, RealVectorSurfMesh
 
typedef SurfMesh::Face Face
 
typedef SurfMesh::Vertex Vertex
 
typedef PolygonalCalculus< SH3::RealPoint, SH3::RealVectorPolyCalculus
 

Functions

void precompute ()
 
std::vector< std::pair< size_t, int > > source2count (GeodesicsInHeat< PolyCalculus >::Vector &source)
 
void addSource ()
 
void clearSources ()
 
void computeGeodesics ()
 
void myCallback ()
 
int main ()
 

Variables

polyscope::SurfaceMesh * psMesh
 
polyscope::SurfaceMesh * psMeshReg
 
SurfMesh surfmesh
 
SurfMesh surfmeshReg
 
float dt = 2.0
 
CountedPtr< SH3::BinaryImagebinary_image
 
CountedPtr< SH3::DigitalSurfacesurface
 
GeodesicsInHeat< PolyCalculus > * heat
 
PolyCalculuscalculus
 
GeodesicsInHeat< PolyCalculus > * heatReg
 
PolyCalculuscalculusReg
 
SHG3::RealVectors iinormals
 
int sourceVertexId =0
 
float radiusII = 3.0
 
bool skipReg = true
 
bool useProjectedCalculus = true
 
bool isPrecomputed =false
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2021/09/02

This file is part of the DGtal library.

Definition in file dgtalCalculus-geodesic.cpp.

Typedef Documentation

◆ Face

Definition at line 55 of file dgtalCalculus-geodesic.cpp.

◆ PolyCalculus

◆ SH3

Definition at line 51 of file dgtalCalculus-geodesic.cpp.

◆ SHG3

Definition at line 52 of file dgtalCalculus-geodesic.cpp.

◆ SurfMesh

Definition at line 54 of file dgtalCalculus-geodesic.cpp.

◆ Vertex

Definition at line 56 of file dgtalCalculus-geodesic.cpp.

Function Documentation

◆ addSource()

void addSource ( )

Definition at line 128 of file dgtalCalculus-geodesic.cpp.

129 {
130  auto pos =rand() % surfmesh.nbVertices();
131  heat->addSource( pos );
132  GeodesicsInHeat<PolyCalculus>::Vector source = heat->source();
133  psMesh->addVertexCountQuantity("Sources", source2count(source));
134 
135  if (!skipReg)
136  {
137  heatReg->addSource( pos );
139  psMeshReg->addVertexCountQuantity("Sources", source2count(source));
140  }
141 }
PolygonalCalculus::Vector Vector
std::vector< std::pair< size_t, int > > source2count(GeodesicsInHeat< PolyCalculus >::Vector &source)
bool skipReg
GeodesicsInHeat< PolyCalculus > * heatReg
polyscope::SurfaceMesh * psMesh
SurfMesh surfmesh
polyscope::SurfaceMesh * psMeshReg
GeodesicsInHeat< PolyCalculus > * heat
Size nbVertices() const
Definition: SurfaceMesh.h:288

References heat, heatReg, DGtal::SurfaceMesh< TRealPoint, TRealVector >::nbVertices(), psMesh, psMeshReg, skipReg, source2count(), and surfmesh.

Referenced by myCallback().

◆ clearSources()

void clearSources ( )

Definition at line 143 of file dgtalCalculus-geodesic.cpp.

144 {
145  heat->clearSource();
146  psMesh->addVertexScalarQuantity("source", heat->source());
147 }

References heat, and psMesh.

Referenced by myCallback().

◆ computeGeodesics()

void computeGeodesics ( )

Definition at line 149 of file dgtalCalculus-geodesic.cpp.

150 {
151  heat->addSource( sourceVertexId ); //Forcing one seed (for screenshots)
152  GeodesicsInHeat<PolyCalculus>::Vector source = heat->source();
153  psMesh->addVertexCountQuantity("Sources", source2count(source));
155  psMesh->addVertexDistanceQuantity("geodesic", dist);
156 
157  if (!skipReg)
158  {
159  heatReg->addSource( sourceVertexId ); //Forcing one seed (for screenshots)371672
160  GeodesicsInHeat<PolyCalculus>::Vector sourceReg = heatReg->source();
161  psMeshReg->addVertexCountQuantity("Sources", source2count(sourceReg));
163  psMeshReg->addVertexDistanceQuantity("geodesic", dist);
164  }
165 }
int sourceVertexId

References heat, heatReg, psMesh, psMeshReg, skipReg, source2count(), and sourceVertexId.

Referenced by myCallback().

◆ main()

int main ( void  )

Definition at line 213 of file dgtalCalculus-geodesic.cpp.

214 {
215  auto params = SH3::defaultParameters() | SHG3::defaultParameters() | SHG3::parametersGeometryEstimation();
216  params("surfaceComponents", "All");
217  params("r-radius", (double) radiusII);
218  std::string filename = examplesPath + std::string("/samples/bunny-128.vol");
219  binary_image = SH3::makeBinaryImage(filename, params );
220  auto K = SH3::getKSpace( binary_image, params );
221  surface = SH3::makeDigitalSurface( binary_image, K, params );
222  auto primalSurface = SH3::makePrimalSurfaceMesh(surface);
223 
224  //Need to convert the faces
225  std::vector<std::vector<SH3::SurfaceMesh::Vertex>> faces;
226  std::vector<RealPoint> positions;
227 
228  for(auto face= 0 ; face < primalSurface->nbFaces(); ++face)
229  faces.push_back(primalSurface->incidentVertices( face ));
230 
231  //Recasting to vector of vertices
232  positions = primalSurface->positions();
233 
234  surfmesh = SurfMesh(positions.begin(),
235  positions.end(),
236  faces.begin(),
237  faces.end());
238  std::cout << surfmesh << std::endl;
239  std::cout<<"number of non-manifold Edges = " << surfmesh.computeNonManifoldEdges().size()<<std::endl;
240 
241  //Construction of a regularized surface
243  regul.init();
244  regul.attachConvolvedTrivialNormalVectors(params);
245  regul.regularize();
246  auto regularizedPosition = regul.getRegularizedPositions();
247 
248  surfmeshReg = SurfMesh(regularizedPosition.begin(),
249  regularizedPosition.end(),
250  faces.begin(),
251  faces.end());
252 
253  // Initialize polyscope
254  polyscope::init();
255 
256  psMesh = polyscope::registerSurfaceMesh("digital surface", positions, faces);
257  psMeshReg = polyscope::registerSurfaceMesh("regularized surface", regularizedPosition, faces);
258  psMeshReg->setEnabled(false);
259 
260  // Set the callback function
261  polyscope::state::userCallback = myCallback;
262  polyscope::show();
263  return EXIT_SUCCESS;
264 }
Aim: Implements Digital Surface Regularization as described in .
SurfaceMesh< RealPoint, RealVector > SurfMesh
CountedPtr< SH3::DigitalSurface > surface
float radiusII
CountedPtr< SH3::BinaryImage > binary_image
void myCallback()
SurfMesh surfmeshReg
Edges computeNonManifoldEdges() const
K init(Point(0, 0, 0), Point(512, 512, 512), true)
KSpace K

References DGtal::DigitalSurfaceRegularization< TDigitalSurface >::attachConvolvedTrivialNormalVectors(), binary_image, DGtal::SurfaceMesh< TRealPoint, TRealVector >::computeNonManifoldEdges(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::getRegularizedPositions(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::init(), init(), K, myCallback(), psMesh, psMeshReg, radiusII, DGtal::DigitalSurfaceRegularization< TDigitalSurface >::regularize(), surface, surfmesh, and surfmeshReg.

◆ myCallback()

void myCallback ( )

Definition at line 168 of file dgtalCalculus-geodesic.cpp.

169 {
170  ImGui::SliderFloat("dt", &dt, 0.,4.);
171  ImGui::SliderFloat("ii radius for normal vector estimation", &radiusII , 0.,10.);
172  ImGui::Checkbox("Skip regularization", &skipReg);
173  ImGui::Checkbox("Using projection", &useProjectedCalculus);
174  ImGui::InputInt("Index of the first source vertex", &sourceVertexId);
175 
176 
177  if(ImGui::Button("Precomputation (required if you change parameters)"))
178  {
179  precompute();
180  isPrecomputed=true;
181  }
182  ImGui::Separator();
183  if(ImGui::Button("Add a random source"))
184  {
185  if (!isPrecomputed)
186  {
187  precompute();
188  isPrecomputed=true;
189  }
190  addSource();
191  }
192  if(ImGui::Button("Clear sources"))
193  {
194  if (!isPrecomputed)
195  {
196  precompute();
197  isPrecomputed=true;
198  }
199  clearSources();
200  }
201 
202  if(ImGui::Button("Compute geodesic"))
203  {
204  if (!isPrecomputed)
205  {
206  precompute();
207  isPrecomputed=true;
208  }
210  }
211 }
void addSource()
void precompute()
bool useProjectedCalculus
void clearSources()
bool isPrecomputed
void computeGeodesics()

References addSource(), clearSources(), computeGeodesics(), dt, isPrecomputed, precompute(), radiusII, skipReg, sourceVertexId, and useProjectedCalculus.

Referenced by main().

◆ precompute()

void precompute ( )

Definition at line 83 of file dgtalCalculus-geodesic.cpp.

84 {
85 
88  else
89  {
90  //Using the projection embedder
91  auto params2 = SH3::defaultParameters() | SHG3::defaultParameters() | SHG3::parametersGeometryEstimation();
92  params2("r-radius", (double) radiusII);
93  auto surfels = SH3::getSurfelRange( surface, params2 );
94  iinormals = SHG3::getIINormalVectors(binary_image, surfels,params2);
95  trace.info()<<iinormals.size()<<std::endl;
96  psMesh->addFaceVectorQuantity("II normals", iinormals);
97 
100  calculus->setEmbedder( embedderFromNormals );
101  }
102 
104 
105  if (!skipReg)
106  {
109  }
110  trace.beginBlock("Init solvers");
111  heat->init(dt);
112  if (!skipReg)
113  heatReg->init(dt);
114  trace.endBlock();
115 }
This class implements on polygonal surfaces (using Discrete differential calculus on polygonal surfa...
void setEmbedder(const std::function< Real3dPoint(Face, Vertex)> &externalFunctor)
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
PolyCalculus * calculusReg
PolyCalculus * calculus
PolygonalCalculus< SH3::RealPoint, SH3::RealVector > PolyCalculus
SHG3::RealVectors iinormals
Trace trace
Definition: Common.h:153
Functor that projects a face vertex of a surface mesh onto the tangent plane given by a per-face norm...

References DGtal::Trace::beginBlock(), binary_image, calculus, calculusReg, dt, DGtal::Trace::endBlock(), heat, heatReg, iinormals, DGtal::Trace::info(), psMesh, radiusII, DGtal::PolygonalCalculus< TRealPoint, TRealVector >::setEmbedder(), skipReg, surface, surfmesh, surfmeshReg, DGtal::trace, and useProjectedCalculus.

Referenced by myCallback().

◆ source2count()

std::vector<std::pair<size_t,int> > source2count ( GeodesicsInHeat< PolyCalculus >::Vector source)

Definition at line 117 of file dgtalCalculus-geodesic.cpp.

118 {
119  std::vector<std::pair<size_t,int>> counts;
120  for(auto i=0; i< source.size(); ++i)
121  {
122  if (source(i)!=0.0)
123  counts.push_back(std::pair<size_t,int>(i,1));
124  }
125  return counts;
126 }

Referenced by addSource(), and computeGeodesics().

Variable Documentation

◆ binary_image

◆ calculus

◆ calculusReg

PolyCalculus* calculusReg

Definition at line 73 of file dgtalCalculus-geodesic.cpp.

Referenced by precompute().

◆ dt

◆ heat

◆ heatReg

Definition at line 72 of file dgtalCalculus-geodesic.cpp.

Referenced by addSource(), computeGeodesics(), and precompute().

◆ iinormals

SHG3::RealVectors iinormals

Definition at line 75 of file dgtalCalculus-geodesic.cpp.

Referenced by precompute().

◆ isPrecomputed

bool isPrecomputed =false

Definition at line 167 of file dgtalCalculus-geodesic.cpp.

Referenced by myCallback().

◆ psMesh

polyscope::SurfaceMesh* psMesh

◆ psMeshReg

polyscope::SurfaceMesh* psMeshReg

Definition at line 60 of file dgtalCalculus-geodesic.cpp.

Referenced by addSource(), computeGeodesics(), and main().

◆ radiusII

float radiusII = 3.0

◆ skipReg

bool skipReg = true

Definition at line 80 of file dgtalCalculus-geodesic.cpp.

Referenced by addSource(), computeGeodesics(), myCallback(), and precompute().

◆ sourceVertexId

int sourceVertexId =0

Definition at line 77 of file dgtalCalculus-geodesic.cpp.

Referenced by computeGeodesics(), and myCallback().

◆ surface

Examples
geometry/meshes/curvature-comparator-ii-cnc-3d.cpp, geometry/meshes/digpoly-curvature-measures-cnc-3d.cpp, geometry/meshes/digpoly-curvature-measures-cnc-XY-3d.cpp, geometry/meshes/vol-curvature-measures-icnc-3d.cpp, geometry/meshes/vol-curvature-measures-icnc-XY-3d.cpp, geometry/surfaces/dvcm-3d.cpp, geometry/volumes/fullConvexityAnalysis3D.cpp, geometry/volumes/fullConvexityShortestPaths3D.cpp, geometry/volumes/fullConvexitySphereGeodesics.cpp, and geometry/volumes/fullConvexityThinning3D.cpp.

Definition at line 66 of file dgtalCalculus-geodesic.cpp.

Referenced by DGtal::ShortcutsGeometry< TKSpace >::getATScalarFieldApproximation(), DGtal::ShortcutsGeometry< TKSpace >::getATVectorFieldApproximation(), DGtal::Shortcuts< TKSpace >::getCellEmbedder(), DGtal::Shortcuts< TKSpace >::getCellRange(), DGtal::ShortcutsGeometry< TKSpace >::getCTrivialNormalVectors(), DGtal::Shortcuts< TKSpace >::getIdxSurfelRange(), DGtal::Shortcuts< TKSpace >::getKSpace(), DGtal::Shortcuts< TKSpace >::getPointelRange(), DGtal::Shortcuts< TKSpace >::getSCellEmbedder(), getSlice(), DGtal::Shortcuts< TKSpace >::getSurfelRange(), DGtal::ShortcutsGeometry< TKSpace >::getVCMNormalVectors(), main(), DGtal::Shortcuts< TKSpace >::makeIdxDigitalSurface(), DGtal::makeShroudsRegularization(), DGtal::Shortcuts< TKSpace >::outputDualDigitalSurfaceAsObj(), DGtal::Shortcuts< TKSpace >::outputPrimalDigitalSurfaceAsObj(), DGtal::Shortcuts< TKSpace >::outputPrimalIdxDigitalSurfaceAsObj(), precompute(), DGtal::Shortcuts< TKSpace >::refKSpace(), LibBoard::Board::saveCairo(), SCENARIO(), TEST_CASE(), testCube(), testFitting(), and testLocalEstimatorFromFunctorAdapter().

◆ surfmesh

SurfMesh surfmesh

Definition at line 61 of file dgtalCalculus-geodesic.cpp.

Referenced by addSource(), main(), and precompute().

◆ surfmeshReg

SurfMesh surfmeshReg

Definition at line 62 of file dgtalCalculus-geodesic.cpp.

Referenced by main(), and precompute().

◆ useProjectedCalculus

bool useProjectedCalculus = true

Definition at line 81 of file dgtalCalculus-geodesic.cpp.

Referenced by myCallback(), and precompute().