27#include <DGtal/base/Common.h>
28#include <DGtal/helpers/StdDefs.h>
29#include <DGtal/helpers/Shortcuts.h>
30#include <DGtal/helpers/ShortcutsGeometry.h>
31#include <DGtal/shapes/SurfaceMesh.h>
32#include <DGtal/geometry/surfaces/DigitalSurfaceRegularization.h>
33#include <DGtal/dec/PolygonalCalculus.h>
34#include <DGtal/math/linalg/DirichletConditions.h>
36#include <polyscope/polyscope.h>
37#include <polyscope/surface_mesh.h>
38#include <polyscope/point_cloud.h>
40#include <Eigen/Sparse>
42#include "ConfigExamples.h"
56polyscope::SurfaceMesh *psMesh;
62double phiVertex(
const Vertex v)
64 return cos(scale*(surfmesh.
position(v)[0]))*sin(scale*surfmesh.
position(v)[1]);
72 Eigen::VectorXd ph(nf);
76 ph(cpt) = phiVertex(v);
85 for(
auto i = 0; i < surfmesh.
nbVertices(); ++i)
86 phiEigen(i) = phiVertex(i);
87 psMesh->addVertexScalarQuantity(
"Phi", phiEigen);
95 std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Vector> gradients;
96 std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Vector> cogradients;
97 std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Real3dPoint> normals;
98 std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Real3dPoint> vectorArea;
99 std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Real3dPoint> centroids;
101 std::vector<double> faceArea;
103 for(
auto f=0; f < surfmesh.
nbFaces(); ++f)
106 gradients.push_back( grad );
109 cogradients.push_back( cograd );
114 vectorArea.push_back({vA(0) , vA(1), vA(2)});
116 faceArea.push_back( calculus.
faceArea(f));
120 psMesh->addFaceVectorQuantity(
"Gradients", gradients);
121 psMesh->addFaceVectorQuantity(
"co-Gradients", cogradients);
122 psMesh->addFaceVectorQuantity(
"Normals", normals);
123 psMesh->addFaceScalarQuantity(
"Face area", faceArea);
124 psMesh->addFaceVectorQuantity(
"Vector area", vectorArea);
128void initQuantitiesCached()
133 std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Vector> gradients;
134 std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Vector> cogradients;
135 std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Real3dPoint> normals;
136 std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Real3dPoint> vectorArea;
137 std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Real3dPoint> centroids;
139 std::vector<double> faceArea;
141 for(
auto f=0; f < surfmesh.
nbFaces(); ++f)
144 gradients.push_back( grad );
147 cogradients.push_back( cograd );
152 vectorArea.push_back({vA(0) , vA(1), vA(2)});
154 faceArea.push_back( calculus.
faceArea(f));
158 psMesh->addFaceVectorQuantity(
"Gradients", gradients);
159 psMesh->addFaceVectorQuantity(
"co-Gradients", cogradients);
160 psMesh->addFaceVectorQuantity(
"Normals", normals);
161 psMesh->addFaceScalarQuantity(
"Face area", faceArea);
162 psMesh->addFaceVectorQuantity(
"Vector area", vectorArea);
178 DC::IntegerVector p = DC::nullBoundaryVector( g );
179 for(
auto cpt=0; cpt< 10;++cpt)
181 int idx = rand() % nbv;
182 g( idx ) = rand() % 100;
190 DC::SparseMatrix L_dirichlet = DC::dirichletOperator( L, p );
191 solver.compute( L_dirichlet );
192 ASSERT(solver.info()==Eigen::Success);
199 ASSERT(solver.info()==Eigen::Success);
202 psMesh->addVertexScalarQuantity(
"g", g);
203 psMesh->addVertexScalarQuantity(
"u", u);
208 ImGui::SliderFloat(
"Phi scale", &scale, 0., 1.);
209 if (ImGui::Button(
"Phi and basic operators"))
214 if (ImGui::Button(
"Phi and basic operators (cached)"))
217 initQuantitiesCached();
219 if(ImGui::Button(
"Compute Laplace problem"))
226 params(
"surfaceComponents",
"All");
228 std::string filename = examplesPath + std::string(
"/samples/bunny-32.vol");
236 std::vector<std::vector<SH3::SurfaceMesh::Vertex>> faces;
237 std::vector<RealPoint> positions;
239 for(
auto face= 0 ; face < primalSurface->nbFaces(); ++face)
240 faces.push_back(primalSurface->incidentVertices( face ));
243 positions = primalSurface->positions();
245 surfmesh =
SurfMesh(positions.begin(),
251 psMesh = polyscope::registerSurfaceMesh(
"digital surface", positions, faces);
257 polyscope::state::userCallback = myCallback;
Aim: A helper class to solve a system with Dirichlet boundary conditions.
Implements differential operators on polygonal surfaces from .
LinAlg::SparseMatrix SparseMatrix
Type of sparse matrix.
Real3dVector faceNormalAsDGtalVector(const Face f) const
Vector vectorArea(const Face f) const
SparseMatrix globalLaplaceBeltrami(const double lambda=1.0) const
LinAlg::SolverSimplicialLDLT Solver
Type of a sparse matrix solver.
double faceArea(const Face f) const
DenseMatrix coGradient(const Face f) const
DenseMatrix gradient(const Face f) const
LinAlg::DenseVector Vector
Type of Vector.
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
static Parameters parametersGeometryEstimation()
static Parameters defaultParameters()
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
std::map< Cell, IdxVertex > Cell2Index
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters ¶ms=parametersDigitalSurface())
static Parameters defaultParameters()
static CountedPtr< SurfaceMesh > makePrimalSurfaceMesh(Cell2Index &c2i, CountedPtr< ::DGtal::DigitalSurface< TContainer > > aSurface)
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
const Vertices & incidentVertices(Face f) const
RealPoint & position(Vertex v)
Edges computeNonManifoldEdges() const
int main(int argc, char **argv)