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>
34 #include <DGtal/dec/PolygonalCalculus.h>
35 #include <DGtal/dec/GeodesicsInHeat.h>
36 #include <DGtal/dec/VectorsInHeat.h>
38 #include <DGtal/math/linalg/DirichletConditions.h>
40 #include <DGtal/shapes/Mesh.h>
41 #include <DGtal/io/readers/MeshReader.h>
43 #include <polyscope/polyscope.h>
44 #include <polyscope/surface_mesh.h>
45 #include <polyscope/curve_network.h>
46 #include <Eigen/Dense>
47 #include <Eigen/Sparse>
49 #include "ConfigExamples.h"
51 using namespace DGtal;
63 typedef std::vector<Vertex> chain;
71 polyscope::SurfaceMesh *
psMesh;
76 std::vector< std::vector<SurfMesh::Index> > faces;
77 std::vector<RealPoint> positions;
90 std::pair<PC::Vector,PC::Vector> FixBoundaryParametrization(
const std::vector<Vertex>& boundary)
92 auto nb = boundary.size();
96 double totalBoundaryLength = 0;
97 for (
Vertex i = 0;i<nb;i++)
100 double partialSum = 0;
101 for (
Vertex i = 0;i<nb;i++)
103 double th = 2*M_PI*partialSum/totalBoundaryLength;
104 auto vi = boundary[i];
105 auto vj = boundary[(i+1)%nb];
106 u(vi) = std::cos(th);
107 v(vj) = std::sin(th);
118 void VisualizeParametrizationOnCircle(
const DenseMatrix& UV)
121 std::vector<RealPoint> pos(n);
124 for (
size_t v = 0;v<n;v++)
128 if (p.norm() > scale)
133 for (
size_t v = 0;v<n;v++)
134 pos[v] =
RealPoint{scale*UV(v,0),scale*UV(v,1),0.} + avg;
135 polyscope::registerSurfaceMesh(
"On circle parametrization", pos, faces)->setEnabled(
false);
151 std::cout<<
"Nb boundaries = "<< chains.size() << std::endl;
153 auto B = *std::max_element(chains.begin(),chains.end(),[] (
const chain& A,
const chain& B) {return A.size() < B.size();});
156 std::vector<RealPoint> pos;
159 polyscope::registerCurveNetworkLoop(
"Longest boundary", pos);
161 IntegerVector boundary = IntegerVector::Zero(n);
165 std::pair<PC::Vector,PC::Vector> uv_b = FixBoundaryParametrization(B);
205 Eigen::VectorXd ph(nf);
207 for(
auto v: vertices)
228 std::vector<PC::Vector> gradients;
229 std::vector<PC::Vector> cogradients;
230 std::vector<PC::Real3dPoint> normals;
231 std::vector<PC::Real3dPoint> vectorArea;
232 std::vector<PC::Real3dPoint> centroids;
234 std::vector<double> faceArea;
239 gradients.push_back( grad );
242 cogradients.push_back( cograd );
247 vectorArea.push_back({vA(0) , vA(1), vA(2)});
253 psMesh->addFaceVectorQuantity(
"Gradients", gradients);
254 psMesh->addFaceVectorQuantity(
"co-Gradients", cogradients);
255 psMesh->addFaceVectorQuantity(
"Normals", normals);
256 psMesh->addFaceScalarQuantity(
"Face area", faceArea);
257 psMesh->addFaceVectorQuantity(
"Vector area", vectorArea);
264 std::vector<double> X_0;
273 for(
auto i=0; i < nbSources; ++i)
279 psMesh->addVertexScalarQuantity(
"X_0",X_0);
280 psMesh->addVertexDistanceQuantity(
"GeodeiscInHeat", GHM.compute());
284 void computeHeatVectors()
289 std::vector<Vector> X_0;
295 X_0.resize(nv,Vector::Zero(3));
298 for(
auto i=0; i < nbSources; ++i)
301 VHM.addSource(
id,Eigen::Vector3d::Random(3).normalized());
302 X_0[id] = VHM.extrinsicVectorSourceAtVertex(
id);
305 psMesh->addVertexVectorQuantity(
"X_0",X_0);
306 psMesh->addVertexVectorQuantity(
"VHM field",VHM.compute());
311 ImGui::SliderFloat(
"Phi scale", &scale, 0., 10.);
312 ImGui::SliderInt(
"Nb Sources", &nbSources, 1, 10);
314 if (ImGui::Button(
"Phi and basic operators"))
319 if (ImGui::Button(
"Geodesics in heat"))
321 if (ImGui::Button(
"Heat Vectors"))
322 computeHeatVectors();
323 if(ImGui::Button(
"Harmonic parametrization"))
329 VisualizeParametrizationOnCircle(UV);
330 psMesh->addVertexParameterizationQuantity(
"Harmonic parametrization",UV)->setEnabled(
true);
336 std::string inputFilename(examplesPath +
"samples/bunnyheadhole.obj" );
339 a3DMesh << inputFilename;
341 for(
auto it = a3DMesh.
faceBegin(), itend = a3DMesh.
faceEnd(); it != itend; ++it)
342 faces.push_back(*it);
Aim: A helper class to solve a system with Dirichlet boundary conditions.
LinearAlgebraBackend::IntegerVector IntegerVector
static DenseVector dirichletVector(const SparseMatrix &A, const DenseVector &b, const IntegerVector &p, const DenseVector &u)
static SparseMatrix dirichletOperator(const SparseMatrix &A, const IntegerVector &p)
static DenseVector dirichletSolution(const DenseVector &xd, const IntegerVector &p, const DenseVector &u)
This class implements on polygonal surfaces (using Discrete differential calculus on polygonal surfa...
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
FaceStorage::const_iterator faceEnd() const
ConstIterator vertexEnd() const
FaceStorage::const_iterator faceBegin() const
ConstIterator vertexBegin() const
Aim: Implements basic operations that will be used in Point and Vector classes.
double norm(const NormType type=L_2) const
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::DenseMatrix DenseMatrix
Type of dense matrix.
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...
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
void beginBlock(const std::string &keyword="")
This class implements on polygonal surfaces (using Discrete differential calculus on polygonal surfa...
SurfaceMesh< RealPoint, RealVector > SurfMesh
PolygonalCalculus< SH3::RealPoint, SH3::RealVector >::Vector phiEigen
double phiVertex(const Vertex v)
polyscope::SurfaceMesh * psMesh
PolygonalCalculus< SH3::RealPoint, SH3::RealVector >::Vector phi(const Face f)
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 ...
RealPoint & position(Vertex v)
const std::vector< RealPoint > & positions() const
std::vector< Vertices > computeManifoldBoundaryChains() const
const Vertices & incidentVertices(Face f) const
Scalar distance(const Vertex i, const Vertex j) const
Edges computeManifoldBoundaryEdges() const
Edges computeNonManifoldEdges() const
Scalar averageEdgeLength() const
int main(int argc, char **argv)
K init(Point(0, 0, 0), Point(512, 512, 512), true)
EigenLinearAlgebraBackend::SparseMatrix SparseMatrix
EigenLinearAlgebraBackend::DenseMatrix DenseMatrix
ShortcutsGeometry< Z3i::KSpace > SHG3