DGtal  1.5.beta
dgtalCalculus-single.cpp
Go to the documentation of this file.
1 
26 #include <iostream>
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 
35 #include <polyscope/polyscope.h>
36 #include <polyscope/surface_mesh.h>
37 #include <polyscope/point_cloud.h>
38 #include <polyscope/curve_network.h>
39 
40 #include <Eigen/Dense>
41 #include <Eigen/Sparse>
42 
43 using namespace DGtal;
44 using namespace Z3i;
45 
46 // Using standard 3D digital space.
49 // The following typedefs are useful
55 
56 
57 //Polyscope global
58 polyscope::SurfaceMesh *psMesh;
59 polyscope::PointCloud *psVertices;
60 polyscope::CurveNetwork *psBoundary;
61 
64 
65 void initPhi()
66 {
67  phiEigen.resize(5);
68  phiEigen << 1.0, 2.0, 0.0, 5.0 ,1.5;
69 
70  psMesh->addVertexScalarQuantity("Phi", phiEigen);
71  psVertices->addScalarQuantity("Phi", phiEigen);
72 }
73 
75 {
77 
80  std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Real3dPoint> normals;
81  std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Real3dPoint> vectorArea;
82  std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Real3dPoint> centroids;
83  std::vector<double> faceArea;
84 
86 
88  gradients.push_back( grad );
89 
91  cogradients.push_back( cograd );
92 
93  normals.push_back(calculus.faceNormalAsDGtalVector(f));
94 
96  vectorArea.push_back({vA(0) , vA(1), vA(2)});
97 
98  faceArea.push_back( calculus.faceArea(f));
99  centroids.push_back( calculus.centroidAsDGtalPoint(f) );
100 
103 
104  psMesh->addFaceVectorQuantity("Gradients", gradients);
105  psMesh->addFaceVectorQuantity("co-Gradients", cogradients);
106  psMesh->addFaceVectorQuantity("Normals", normals);
107  psMesh->addFaceScalarQuantity("Face area", faceArea);
108  psMesh->addFaceVectorQuantity("Vector area", vectorArea);
109 
110  psBoundary->addEdgeScalarQuantity("d0*phi", dPhi);
111  psBoundary->addEdgeScalarQuantity("A*phi", av);
112 
113  //Face centroid
114  polyscope::registerPointCloud("Centroids", centroids);
115 
116  //Flat Sharp
118  v << 50,-50,-100;
120  psMesh->addFaceVectorQuantity("A vector", someV);
121 
123  psBoundary->addEdgeScalarQuantity("flat (1-form)", flat);
124 
127  psMesh->addFaceVectorQuantity("Sharp", sharpRes);
128 }
129 
130 int main()
131 {
132  std::vector<RealPoint> positions={ {0,0,0},{20,0,0}, {20,10,0}, {10,8,5}, {0,15,1} };
133  std::vector<std::vector<size_t>> faces={ {0,1,2,3,4} };
134 
135  surfmesh = SurfMesh(positions.begin(),
136  positions.end(),
137  faces.begin(),
138  faces.end());
139 
140  psVertices = polyscope::registerPointCloud("Vertices", positions);
141 
142  std::vector<std::array<size_t,2>> edges={{0,1},{1,2},{2,3},{3,4},{4,0} };
143  psBoundary = polyscope::registerCurveNetwork("Edges", positions, edges);
144 
145  // Initialize polyscope
146  polyscope::init();
147 
148  psMesh = polyscope::registerSurfaceMesh("Single face", positions, faces);
149 
150  initPhi();
151  initQuantities();
152 
153  polyscope::show();
154  return EXIT_SUCCESS;
155 
156 }
Implements differential operators on polygonal surfaces from .
DenseMatrix D(const Face f) const
Real3dVector faceNormalAsDGtalVector(const Face f) const
Real3dPoint centroidAsDGtalPoint(const Face f) const
Vector vectorArea(const Face f) const
DenseMatrix sharp(const Face f) const
double faceArea(const Face f) const
DenseMatrix coGradient(const Face f) const
DenseMatrix gradient(const Face f) const
MySurfaceMesh::Face Face
Face type.
LinAlg::DenseVector Vector
Type of Vector.
DenseMatrix A(const Face f) const
DenseMatrix flat(const Face f) const
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...
Definition: Shortcuts.h:105
PolyCalculus * calculus
SurfaceMesh< RealPoint, RealVector > SurfMesh
PolygonalCalculus< SH3::RealPoint, SH3::RealVector >::Vector phiEigen
SurfMesh::Vertices Vertices
SurfMesh::Face Face
polyscope::CurveNetwork * psBoundary
void initPhi()
polyscope::SurfaceMesh * psMesh
SurfMesh::Vertex Vertex
Shortcuts< Z3i::KSpace > SH3
SurfMesh surfmesh
ShortcutsGeometry< Z3i::KSpace > SHG3
void initQuantities()
polyscope::PointCloud * psVertices
int main()
DigitalPlane::Point Vector
Space::RealPoint RealPoint
Definition: StdDefs.h:170
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition: SurfaceMesh.h:92
std::vector< Vertex > Vertices
The type that defines a list/range of vertices (e.g. to define faces)
Definition: SurfaceMesh.h:112
TRealPoint RealPoint
Definition: SurfaceMesh.h:93
K init(Point(0, 0, 0), Point(512, 512, 512), true)