File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 1.4.2
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 PolygonalCalculus< SH3::RealPoint, SH3::RealVectorPolyCalculus
 

Functions

void precompute ()
 
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

◆ PolyCalculus

◆ SH3

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

◆ SHG3

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

Function Documentation

◆ addSource()

void addSource ( )

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

120{
121 auto pos =rand() % surfmesh.nbVertices();
122 heat->addSource( pos );
124 psMesh->addVertexScalarQuantity("Sources", source);
125
126 if (!skipReg)
127 {
128 heatReg->addSource( pos );
130 psMeshReg->addVertexScalarQuantity("Sources", source);
131 }
132}
PolygonalCalculus::Vector Vector
GeodesicsInHeat< PolyCalculus > * heatReg
polyscope::SurfaceMesh * psMesh
SurfMesh surfmesh
polyscope::SurfaceMesh * psMeshReg
GeodesicsInHeat< PolyCalculus > * heat
Size nbVertices() const

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

Referenced by myCallback().

◆ clearSources()

void clearSources ( )

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

135{
136 heat->clearSource();
137 psMesh->addVertexScalarQuantity("source", heat->source());
138}

References heat, and psMesh.

Referenced by myCallback().

◆ computeGeodesics()

void computeGeodesics ( )

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

141{
142 heat->addSource( sourceVertexId ); //Forcing one seed (for screenshots)
144 psMesh->addVertexScalarQuantity("Sources", source);
146 psMesh->addVertexDistanceQuantity("geodesic", dist);
147
148 if (!skipReg)
149 {
150 heatReg->addSource( sourceVertexId ); //Forcing one seed (for screenshots)371672
152 psMeshReg->addVertexScalarQuantity("Sources", sourceReg);
154 psMeshReg->addVertexDistanceQuantity("geodesic", dist);
155 }
156}
int sourceVertexId

References DGtal::GeodesicsInHeat< TPolygonalCalculus >::compute(), heat, heatReg, psMesh, psMeshReg, skipReg, and sourceVertexId.

Referenced by myCallback().

◆ main()

int main ( void )

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

205{
207 params("surfaceComponents", "All");
208 params("r-radius", (double) radiusII);
209 std::string filename = examplesPath + std::string("/samples/bunny-128.vol");
210 binary_image = SH3::makeBinaryImage(filename, params );
211 auto K = SH3::getKSpace( binary_image, params );
213 auto primalSurface = SH3::makePrimalSurfaceMesh(surface);
214
215 //Need to convert the faces
216 std::vector<std::vector<SH3::SurfaceMesh::Vertex>> faces;
217 std::vector<RealPoint> positions;
218
219 for(auto face= 0 ; face < primalSurface->nbFaces(); ++face)
220 faces.push_back(primalSurface->incidentVertices( face ));
221
222 //Recasting to vector of vertices
223 positions = primalSurface->positions();
224
225 surfmesh = SurfMesh(positions.begin(),
226 positions.end(),
227 faces.begin(),
228 faces.end());
229 std::cout << surfmesh << std::endl;
230 std::cout<<"number of non-manifold Edges = " << surfmesh.computeNonManifoldEdges().size()<<std::endl;
231
232 //Construction of a regularized surface
234 regul.init();
235 regul.attachConvolvedTrivialNormalVectors(params);
236 regul.regularize();
237 auto regularizedPosition = regul.getRegularizedPositions();
238
239 surfmeshReg = SurfMesh(regularizedPosition.begin(),
240 regularizedPosition.end(),
241 faces.begin(),
242 faces.end());
243
244 // Initialize polyscope
245 polyscope::init();
246
247 psMesh = polyscope::registerSurfaceMesh("digital surface", positions, faces);
248 psMeshReg = polyscope::registerSurfaceMesh("regularized surface", regularizedPosition, faces);
249 psMeshReg->setEnabled(false);
250
251 // Set the callback function
252 polyscope::state::userCallback = myCallback;
253 polyscope::show();
254 return EXIT_SUCCESS;
255}
Aim: Implements Digital Surface Regularization as described in coeurjolly17regdgci.
static Parameters parametersGeometryEstimation()
static Parameters defaultParameters()
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition Shortcuts.h:332
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1209
static Parameters defaultParameters()
Definition Shortcuts.h:203
static CountedPtr< SurfaceMesh > makePrimalSurfaceMesh(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
Definition Shortcuts.h:2372
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition Shortcuts.h:561
SurfaceMesh< RealPoint, RealVector > SurfMesh
CountedPtr< SH3::DigitalSurface > surface
float radiusII
CountedPtr< SH3::BinaryImage > binary_image
void myCallback()
SurfMesh surfmeshReg
Edges computeNonManifoldEdges() const
KSpace K

References DGtal::DigitalSurfaceRegularization< TDigitalSurface >::attachConvolvedTrivialNormalVectors(), binary_image, DGtal::SurfaceMesh< TRealPoint, TRealVector >::computeNonManifoldEdges(), DGtal::Shortcuts< TKSpace >::defaultParameters(), DGtal::ShortcutsGeometry< TKSpace >::defaultParameters(), DGtal::Shortcuts< TKSpace >::getKSpace(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::getRegularizedPositions(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::init(), K, DGtal::Shortcuts< TKSpace >::makeBinaryImage(), DGtal::Shortcuts< TKSpace >::makeDigitalSurface(), DGtal::Shortcuts< TKSpace >::makePrimalSurfaceMesh(), myCallback(), DGtal::ShortcutsGeometry< TKSpace >::parametersGeometryEstimation(), psMesh, psMeshReg, radiusII, DGtal::DigitalSurfaceRegularization< TDigitalSurface >::regularize(), surface, surfmesh, and surfmeshReg.

◆ myCallback()

void myCallback ( )

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

160{
161 ImGui::SliderFloat("dt", &dt, 0.,4.);
162 ImGui::SliderFloat("ii radius for normal vector estimation", &radiusII , 0.,10.);
163 ImGui::Checkbox("Skip regularization", &skipReg);
164 ImGui::Checkbox("Using projection", &useProjectedCalculus);
165 ImGui::InputInt("Index of the first source vertex", &sourceVertexId);
166
167
168 if(ImGui::Button("Precomputation (required if you change parameters)"))
169 {
170 precompute();
171 isPrecomputed=true;
172 }
173 ImGui::Separator();
174 if(ImGui::Button("Add a random source"))
175 {
176 if (!isPrecomputed)
177 {
178 precompute();
179 isPrecomputed=true;
180 }
181 addSource();
182 }
183 if(ImGui::Button("Clear sources"))
184 {
185 if (!isPrecomputed)
186 {
187 precompute();
188 isPrecomputed=true;
189 }
190 clearSources();
191 }
192
193 if(ImGui::Button("Compute geodesic"))
194 {
195 if (!isPrecomputed)
196 {
197 precompute();
198 isPrecomputed=true;
199 }
201 }
202}
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
92 params2("r-radius", (double) radiusII);
93 auto surfels = SH3::getSurfelRange( surface, 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 crane2013 on polygonal surfaces (using Discrete differential calculus on polygo...
void setEmbedder(const std::function< Real3dPoint(Face, Vertex)> &externalFunctor)
static RealVectors getIINormalVectors(CountedPtr< BinaryImage > bimage, const SurfelRange &surfels, const Parameters &params=parametersGeometryEstimation()|parametersKSpace())
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1547
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, DGtal::Shortcuts< TKSpace >::defaultParameters(), DGtal::ShortcutsGeometry< TKSpace >::defaultParameters(), dt, DGtal::Trace::endBlock(), DGtal::ShortcutsGeometry< TKSpace >::getIINormalVectors(), DGtal::Shortcuts< TKSpace >::getSurfelRange(), heat, heatReg, iinormals, DGtal::Trace::info(), DGtal::ShortcutsGeometry< TKSpace >::parametersGeometryEstimation(), psMesh, radiusII, DGtal::PolygonalCalculus< TRealPoint, TRealVector >::setEmbedder(), skipReg, surface, surfmesh, surfmeshReg, DGtal::trace, and useProjectedCalculus.

Referenced by myCallback().

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 158 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 >::getATScalarFieldApproximation(), DGtal::ShortcutsGeometry< TKSpace >::getATVectorFieldApproximation(), DGtal::ShortcutsGeometry< TKSpace >::getATVectorFieldApproximation(), DGtal::Shortcuts< TKSpace >::getCellEmbedder(), DGtal::Shortcuts< TKSpace >::getCellEmbedder(), DGtal::Shortcuts< TKSpace >::getCellRange(), DGtal::Shortcuts< TKSpace >::getCellRange(), DGtal::ShortcutsGeometry< TKSpace >::getCTrivialNormalVectors(), DGtal::Shortcuts< TKSpace >::getIdxSurfelRange(), DGtal::Shortcuts< TKSpace >::getIdxSurfelRange(), DGtal::Shortcuts< TKSpace >::getKSpace(), DGtal::Shortcuts< TKSpace >::getKSpace(), DGtal::Shortcuts< TKSpace >::getPointelRange(), DGtal::Shortcuts< TKSpace >::getPointelRange(), DGtal::Shortcuts< TKSpace >::getSCellEmbedder(), DGtal::Shortcuts< TKSpace >::getSCellEmbedder(), getSlice(), DGtal::Shortcuts< TKSpace >::getSurfelRange(), DGtal::Shortcuts< TKSpace >::getSurfelRange(), DGtal::ShortcutsGeometry< TKSpace >::getVCMNormalVectors(), main(), main(), main(), main(), DGtal::Shortcuts< TKSpace >::makeIdxDigitalSurface(), DGtal::makeShroudsRegularization(), DGtal::Shortcuts< TKSpace >::outputDualDigitalSurfaceAsObj(), DGtal::Shortcuts< TKSpace >::outputDualDigitalSurfaceAsObj(), DGtal::Shortcuts< TKSpace >::outputPrimalDigitalSurfaceAsObj(), DGtal::Shortcuts< TKSpace >::outputPrimalDigitalSurfaceAsObj(), DGtal::Shortcuts< TKSpace >::outputPrimalIdxDigitalSurfaceAsObj(), DGtal::Shortcuts< TKSpace >::outputPrimalIdxDigitalSurfaceAsObj(), precompute(), DGtal::Shortcuts< TKSpace >::refKSpace(), DGtal::Shortcuts< TKSpace >::refKSpace(), LibBoard::Board::saveCairo(), SCENARIO(), SCENARIO(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), 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().