DGtal 1.4.0
Loading...
Searching...
No Matches
dgtalCalculus-halfsphere.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/dec/PolygonalCalculus.h>
#include <DGtal/dec/GeodesicsInHeat.h>
#include <polyscope/polyscope.h>
#include <polyscope/surface_mesh.h>
#include <polyscope/pick.h>
#include "ConfigExamples.h"
#include <Eigen/Dense>
#include <Eigen/Sparse>
Include dependency graph for dgtalCalculus-halfsphere.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 ()
 
void picksource (int v_idx)
 
void computeGeodesics ()
 
void myCallback ()
 
int main ()
 

Variables

polyscope::SurfaceMesh * psMesh
 
SurfMesh surfmesh
 
float dt = 2.0
 
float Lambda = 0.05
 
bool Mixed = false
 
GeodesicsInHeat< PolyCalculus > * heat
 
PolyCalculuscalculus
 
int vertex_idx = -1
 
int face_idx = -1
 
int edge_idx = -1
 
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
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2022/04/10

This file is part of the DGtal library.

Definition in file dgtalCalculus-halfsphere.cpp.

Typedef Documentation

◆ Face

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

◆ PolyCalculus

◆ SH3

Definition at line 50 of file dgtalCalculus-halfsphere.cpp.

◆ SHG3

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

◆ SurfMesh

Definition at line 53 of file dgtalCalculus-halfsphere.cpp.

◆ Vertex

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

Function Documentation

◆ computeGeodesics()

void computeGeodesics ( )

Definition at line 97 of file dgtalCalculus-halfsphere.cpp.

98{
99 // heat->addSource( 0 ); //Forcing one seed (for screenshots)
101 psMesh->addVertexDistanceQuantity("geodesic", dist);
102}
PolygonalCalculus::Vector Vector
polyscope::SurfaceMesh * psMesh
GeodesicsInHeat< PolyCalculus > * heat

References heat, and psMesh.

Referenced by myCallback().

◆ main()

int main ( void )

Definition at line 154 of file dgtalCalculus-halfsphere.cpp.

155{
157 params("surfaceComponents", "All");
158 params("polynomial", "x^2+(y+1)^2+z^2-1.0")
159 ("minAABB",-1.0)("maxAABB",1.0)("offset",1.0)
160 ("gridstep",0.0625);
161 auto shape = SH3::makeImplicitShape3D( params );
162 auto dshape = SH3::makeDigitizedImplicitShape3D( shape, params );
163 auto K = SH3::getKSpace( params );
164 auto binary_image = SH3::makeBinaryImage( dshape, params );
166 auto primalSurface= SH3::makePrimalSurfaceMesh(surface);
167 auto surfels = SH3::getSurfelRange( surface, params );
168 auto normals = SHG3::getNormalVectors( shape, K, surfels, params );
169
170 //Need to convert the faces
171 std::vector<std::vector<SH3::SurfaceMesh::Vertex>> faces;
172 std::vector<RealPoint> positions;
173
174 for(auto face= 0 ; face < primalSurface->nbFaces(); ++face)
175 faces.push_back(primalSurface->incidentVertices( face ));
176
177 //Recasting to vector of vertices
178 positions = primalSurface->positions();
179
180 surfmesh = SurfMesh(positions.begin(),
181 positions.end(),
182 faces.begin(),
183 faces.end());
184 surfmesh.setFaceNormals( normals.cbegin(), normals.cend() );
185 std::cout << surfmesh << std::endl;
186 std::cout<<"number of non-manifold Edges = " << surfmesh.computeNonManifoldEdges().size()<<std::endl;
187
188 // Initialize polyscope
189 polyscope::init();
190
191 psMesh = polyscope::registerSurfaceMesh("digital surface", positions, faces);
192
193 // Set the callback function
194 polyscope::state::userCallback = myCallback;
195 polyscope::show();
196 return EXIT_SUCCESS;
197}
static Parameters parametersGeometryEstimation()
static RealVectors getNormalVectors(CountedPtr< ImplicitShape3D > shape, const KSpace &K, const SurfelRange &surfels, const Parameters &params=parametersShapeGeometry())
static Parameters defaultParameters()
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
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
SurfaceMesh< RealPoint, RealVector > SurfMesh
void myCallback()
SurfMesh surfmesh
bool setFaceNormals(RealVectorIterator itN, RealVectorIterator itNEnd)
Edges computeNonManifoldEdges() const
KSpace K

References binary_image, DGtal::SurfaceMesh< TRealPoint, TRealVector >::computeNonManifoldEdges(), DGtal::Shortcuts< TKSpace >::defaultParameters(), DGtal::ShortcutsGeometry< TKSpace >::defaultParameters(), DGtal::Shortcuts< TKSpace >::getKSpace(), DGtal::ShortcutsGeometry< TKSpace >::getNormalVectors(), DGtal::Shortcuts< TKSpace >::getSurfelRange(), K, DGtal::Shortcuts< TKSpace >::makeBinaryImage(), DGtal::Shortcuts< TKSpace >::makeDigitalSurface(), DGtal::Shortcuts< TKSpace >::makeDigitizedImplicitShape3D(), DGtal::Shortcuts< TKSpace >::makeImplicitShape3D(), DGtal::Shortcuts< TKSpace >::makePrimalSurfaceMesh(), myCallback(), DGtal::ShortcutsGeometry< TKSpace >::parametersGeometryEstimation(), psMesh, DGtal::SurfaceMesh< TRealPoint, TRealVector >::setFaceNormals(), surface, and surfmesh.

◆ myCallback()

void myCallback ( )

Definition at line 105 of file dgtalCalculus-halfsphere.cpp.

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}
void precompute()
void computeGeodesics()
void picksource(int v_idx)

References computeGeodesics(), dt, isPrecomputed, Lambda, Mixed, picksource(), precompute(), and vertex_idx.

Referenced by main().

◆ picksource()

void picksource ( int v_idx)

Definition at line 90 of file dgtalCalculus-halfsphere.cpp.

91{
92 heat->addSource( v_idx );
94 psMesh->addVertexScalarQuantity("source", source);
95}

References heat, and psMesh.

Referenced by myCallback().

◆ precompute()

void precompute ( )

Definition at line 71 of file dgtalCalculus-halfsphere.cpp.

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}
This class implements Crane2013 on polygonal surfaces (using Discrete differential calculus on polygo...
Aim: Implements basic operations that will be used in Point and Vector classes.
auto dot(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::dotProduct(*this, v))
Dot product with a PointVector.
void setEmbedder(const std::function< Real3dPoint(Face, Vertex)> &externalFunctor)
void beginBlock(const std::string &keyword="")
double endBlock()
PolyCalculus * calculus
PolygonalCalculus< SH3::RealPoint, SH3::RealVector > PolyCalculus
Trace trace
Definition Common.h:153
RealVector & faceNormal(Face f)
RealPoint faceCentroid(Index f) const
RealPoint & position(Vertex v)

References DGtal::Trace::beginBlock(), calculus, DGtal::PointVector< dim, TEuclideanRing, TContainer >::dot(), dt, DGtal::Trace::endBlock(), DGtal::SurfaceMesh< TRealPoint, TRealVector >::faceCentroid(), DGtal::SurfaceMesh< TRealPoint, TRealVector >::faceNormal(), heat, Lambda, Mixed, DGtal::SurfaceMesh< TRealPoint, TRealVector >::position(), DGtal::PolygonalCalculus< TRealPoint, TRealVector >::setEmbedder(), surfmesh, and DGtal::trace.

Referenced by myCallback().

Variable Documentation

◆ calculus

PolyCalculus* calculus

Definition at line 64 of file dgtalCalculus-halfsphere.cpp.

Referenced by precompute().

◆ dt

float dt = 2.0

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

Referenced by myCallback(), and precompute().

◆ edge_idx

int edge_idx = -1

Definition at line 67 of file dgtalCalculus-halfsphere.cpp.

◆ face_idx

int face_idx = -1

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

◆ heat

◆ isPrecomputed

bool isPrecomputed =false

Definition at line 104 of file dgtalCalculus-halfsphere.cpp.

Referenced by myCallback().

◆ Lambda

float Lambda = 0.05

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

Referenced by myCallback(), and precompute().

◆ Mixed

bool Mixed = false

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

Referenced by myCallback(), and precompute().

◆ psMesh

polyscope::SurfaceMesh* psMesh

Definition at line 58 of file dgtalCalculus-halfsphere.cpp.

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

◆ surfmesh

SurfMesh surfmesh

Definition at line 59 of file dgtalCalculus-halfsphere.cpp.

Referenced by main(), and precompute().

◆ vertex_idx

int vertex_idx = -1

Definition at line 65 of file dgtalCalculus-halfsphere.cpp.

Referenced by myCallback().