DGtal 1.4.2
Loading...
Searching...
No Matches
dgtalCalculus-halfsphere.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
34#include <DGtal/dec/PolygonalCalculus.h>
35#include <DGtal/dec/GeodesicsInHeat.h>
36
37#include <polyscope/polyscope.h>
38#include <polyscope/surface_mesh.h>
39#include <polyscope/pick.h>
40
41#include "ConfigExamples.h"
42
43#include <Eigen/Dense>
44#include <Eigen/Sparse>
45
46using namespace DGtal;
47using namespace Z3i;
48
49// Using standard 3D digital space.
52// The following typedefs are useful
54typedef SurfMesh::Face Face;
57//Polyscope global
58polyscope::SurfaceMesh *psMesh;
60float dt = 2.0;
61float Lambda = 0.05;
62bool Mixed = false;
65int vertex_idx = -1;
66int face_idx = -1;
67int edge_idx = -1;
68
69
70
72{
73 auto projEmbedder = [&]( int f, int v)
74 {
75 auto nn = surfmesh.faceNormal( f );
76 RealPoint centroid = surfmesh.faceCentroid( f );
78 const auto cp = p - centroid;
79 RealPoint q = p - nn.dot(cp)*nn;
80 return q;
81 };
83 calculus->setEmbedder( projEmbedder );
85 trace.beginBlock("Init solvers");
86 heat->init(dt,Lambda,Mixed);
88}
89
90void picksource( int v_idx )
91{
92 heat->addSource( v_idx );
94 psMesh->addVertexScalarQuantity("source", source);
95}
96
98{
99 // heat->addSource( 0 ); //Forcing one seed (for screenshots)
101 psMesh->addVertexDistanceQuantity("geodesic", dist);
102}
103
104bool isPrecomputed=false;
106{
107 // Select a vertex with the mouse
108 if (polyscope::pick::haveSelection()) {
109 bool goodSelection = false;
110 auto selection = polyscope::pick::getSelection();
111 auto selectedSurface = static_cast<polyscope::SurfaceMesh*>(selection.first);
112 size_t idx = selection.second;
113
114 // Only authorize selection on the input surface and the reconstruction
115 auto surf = polyscope::getSurfaceMesh("digital surface");
116 goodSelection = goodSelection || (selectedSurface == surf);
117 const auto nv = selectedSurface->nVertices();
118 // Validate that it its a face index
119 if ( goodSelection && idx < nv )
120 {
121 std::ostringstream otext;
122 otext << "Selected vertex = " << idx;
123 ImGui::Text( "%s", otext.str().c_str() );
124 vertex_idx = idx;
125 if (!isPrecomputed)
126 {
127 precompute();
128 isPrecomputed=true;
129 }
131 }
132 }
133
134 ImGui::SliderFloat("Lambda parameter", &Lambda, 0.0, 1.0);
135 ImGui::SliderFloat("dt", &dt, 0.,4.);
136 ImGui::Checkbox("Use mixed Neumann+Dirichlet heat solution", &Mixed);
137 if(ImGui::Button("Precomputation (required if you change the dt)"))
138 {
139 precompute();
140 isPrecomputed=true;
141 }
142
143 if(ImGui::Button("Compute geodesic"))
144 {
145 if (!isPrecomputed)
146 {
147 precompute();
148 isPrecomputed=true;
149 }
151 }
152 ImGui::Text("You can use the mouse left-click to select the new source point.");
153}
154
155int main()
156{
158 params("surfaceComponents", "All");
159 params("polynomial", "x^2+(y+1)^2+z^2-1.0")
160 ("minAABB",-1.0)("maxAABB",1.0)("offset",1.0)
161 ("gridstep",0.0625);
162 auto shape = SH3::makeImplicitShape3D( params );
163 auto dshape = SH3::makeDigitizedImplicitShape3D( shape, params );
164 auto K = SH3::getKSpace( params );
165 auto binary_image = SH3::makeBinaryImage( dshape, params );
167 auto primalSurface= SH3::makePrimalSurfaceMesh(surface);
168 auto surfels = SH3::getSurfelRange( surface, params );
169 auto normals = SHG3::getNormalVectors( shape, K, surfels, params );
170
171 //Need to convert the faces
172 std::vector<std::vector<SH3::SurfaceMesh::Vertex>> faces;
173 std::vector<RealPoint> positions;
174
175 for(auto face= 0 ; face < primalSurface->nbFaces(); ++face)
176 faces.push_back(primalSurface->incidentVertices( face ));
177
178 //Recasting to vector of vertices
179 positions = primalSurface->positions();
180
181 surfmesh = SurfMesh(positions.begin(),
182 positions.end(),
183 faces.begin(),
184 faces.end());
185 surfmesh.setFaceNormals( normals.cbegin(), normals.cend() );
186 std::cout << surfmesh << std::endl;
187 std::cout<<"number of non-manifold Edges = " << surfmesh.computeNonManifoldEdges().size()<<std::endl;
188
189 // Initialize polyscope
190 polyscope::init();
191
192 psMesh = polyscope::registerSurfaceMesh("digital surface", positions, faces);
193
194 // Set the callback function
195 polyscope::state::userCallback = myCallback;
196 polyscope::show();
197 return EXIT_SUCCESS;
198}
This class implements crane2013 on polygonal surfaces (using Discrete differential calculus on polygo...
PolygonalCalculus::Vector Vector
auto dot(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::dotProduct(*this, v))
Dot product with a PointVector.
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()
static RealVectors getNormalVectors(CountedPtr< ImplicitShape3D > shape, const KSpace &K, const SurfelRange &surfels, const Parameters &params=parametersShapeGeometry())
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 CountedPtr< DigitizedImplicitShape3D > makeDigitizedImplicitShape3D(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition Shortcuts.h:523
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
static CountedPtr< ImplicitShape3D > makeImplicitShape3D(const Parameters &params=parametersImplicitShape3D())
Definition Shortcuts.h:282
void beginBlock(const std::string &keyword="")
double endBlock()
SurfaceMesh< RealPoint, RealVector > SurfMesh
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
void precompute()
PolyCalculus * calculus
PolygonalCalculus< SH3::RealPoint, SH3::RealVector > PolyCalculus
void computeGeodesics()
void myCallback()
polyscope::SurfaceMesh * psMesh
void picksource(int v_idx)
Shortcuts< Z3i::KSpace > SH3
SurfMesh surfmesh
ShortcutsGeometry< Z3i::KSpace > SHG3
GeodesicsInHeat< PolyCalculus > * heat
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
RealVector & faceNormal(Face f)
RealPoint faceCentroid(Index f) const
bool setFaceNormals(RealVectorIterator itN, RealVectorIterator itNEnd)
RealPoint & position(Vertex v)
Edges computeNonManifoldEdges() const
KSpace K
TriMesh::Face Face
TriMesh::Vertex Vertex