Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 1.4.2
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dgtalCalculus-geodesic.cpp
Go to the documentation of this file.
1
26#include <iostream>
27#include <string>
28#include <DGtal/base/Common.h>
29#include <DGtal/helpers/StdDefs.h>
30#include <DGtal/helpers/Shortcuts.h>
31#include <DGtal/helpers/ShortcutsGeometry.h>
32#include <DGtal/shapes/SurfaceMesh.h>
33#include <DGtal/geometry/surfaces/DigitalSurfaceRegularization.h>
34
35#include <DGtal/dec/PolygonalCalculus.h>
36#include <DGtal/dec/GeodesicsInHeat.h>
37
38#include <polyscope/polyscope.h>
39#include <polyscope/surface_mesh.h>
40#include <polyscope/point_cloud.h>
41
42#include "ConfigExamples.h"
43
44#include <Eigen/Dense>
45#include <Eigen/Sparse>
46
47using namespace DGtal;
48using namespace Z3i;
49
50// Using standard 3D digital space.
53// The following typedefs are useful
55typedef SurfMesh::Face Face;
58//Polyscope global
59polyscope::SurfaceMesh *psMesh;
60polyscope::SurfaceMesh *psMeshReg;
63float dt = 2.0;
64
67
68
71
74
76
78float radiusII = 3.0;
79
80bool skipReg = true; //Global flag to enable/disable the regularization example.
81bool useProjectedCalculus = true; //Use estimated normal vectors to set up te embedding
82
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}
116
117
118
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}
133
135{
136 heat->clearSource();
137 psMesh->addVertexScalarQuantity("source", heat->source());
138}
139
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}
157
158bool isPrecomputed=false;
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}
203
204int main()
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();
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: Smart pointer based on reference counts.
Definition CountedPtr.h:80
Aim: Implements Digital Surface Regularization as described in coeurjolly17regdgci.
void init(const double alpha=0.001, const double beta=1.0, const double gamma=0.05)
Initialize the parameters of the energy function.
void attachConvolvedTrivialNormalVectors(const Parameters someParams=SH3::defaultParameters()|SHG3::defaultParameters())
double regularize(const unsigned int nbIters, const double dt, const double epsilon, const AdvectionFunction &advectionFunc)
Main regularization loop.
This class implements crane2013 on polygonal surfaces (using Discrete differential calculus on polygo...
PolygonalCalculus::Vector Vector
Implements differential operators on polygonal surfaces from degoes2020discrete.
void setEmbedder(const std::function< Real3dPoint(Face, Vertex)> &externalFunctor)
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
static Parameters parametersGeometryEstimation()
std::vector< RealVector > RealVectors
static RealVectors getIINormalVectors(CountedPtr< BinaryImage > bimage, const SurfelRange &surfels, const Parameters &params=parametersGeometryEstimation()|parametersKSpace())
static Parameters defaultParameters()
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition Shortcuts.h:105
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition Shortcuts.h:332
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1547
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
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
SurfaceMesh< RealPoint, RealVector > SurfMesh
void addSource()
PolyCalculus * calculusReg
void precompute()
bool useProjectedCalculus
GeodesicsInHeat< PolyCalculus > * heatReg
PolyCalculus * calculus
void clearSources()
CountedPtr< SH3::DigitalSurface > surface
bool isPrecomputed
float radiusII
PolygonalCalculus< SH3::RealPoint, SH3::RealVector > PolyCalculus
void computeGeodesics()
CountedPtr< SH3::BinaryImage > binary_image
int sourceVertexId
void myCallback()
polyscope::SurfaceMesh * psMesh
Shortcuts< Z3i::KSpace > SH3
SurfMesh surfmesh
ShortcutsGeometry< Z3i::KSpace > SHG3
SHG3::RealVectors iinormals
polyscope::SurfaceMesh * psMeshReg
GeodesicsInHeat< PolyCalculus > * heat
SurfMesh surfmeshReg
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition SurfaceMesh.h:92
Size nbVertices() const
Edges computeNonManifoldEdges() const
Functor that projects a face vertex of a surface mesh onto the tangent plane given by a per-face norm...
KSpace K
TriMesh::Face Face
TriMesh::Vertex Vertex