DGtal  1.5.beta
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 155 of file dgtalCalculus-halfsphere.cpp.

156 {
157  auto params = SH3::defaultParameters() | SHG3::defaultParameters() | SHG3::parametersGeometryEstimation();
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 );
166  auto surface = SH3::makeDigitalSurface( binary_image, K, 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 }
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
K init(Point(0, 0, 0), Point(512, 512, 512), true)
KSpace K

References binary_image, DGtal::SurfaceMesh< TRealPoint, TRealVector >::computeNonManifoldEdges(), init(), K, myCallback(), 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  ImGui::Text("You can use the mouse left-click to select the new source point.");
153 }
void precompute()
bool isPrecomputed
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 );
77  RealPoint p = surfmesh.position( v );
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);
87  trace.endBlock();
88 }
This class implements on polygonal surfaces (using Discrete differential calculus on polygonal surfa...
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
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
RealPoint & position(Vertex v)
Definition: SurfaceMesh.h:647
RealPoint faceCentroid(Index f) const
RealVector & faceNormal(Face f)
Definition: SurfaceMesh.h:687

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().