DGtal  1.4.beta
dgtalCalculus-single.cpp
1 
25 #include <iostream>
26 #include <DGtal/base/Common.h>
27 #include <DGtal/helpers/StdDefs.h>
28 #include <DGtal/helpers/Shortcuts.h>
29 #include <DGtal/helpers/ShortcutsGeometry.h>
30 #include <DGtal/shapes/SurfaceMesh.h>
31 #include <DGtal/geometry/surfaces/DigitalSurfaceRegularization.h>
32 #include <DGtal/dec/PolygonalCalculus.h>
33 
34 #include <polyscope/polyscope.h>
35 #include <polyscope/surface_mesh.h>
36 #include <polyscope/point_cloud.h>
37 #include <polyscope/curve_network.h>
38 
39 #include <Eigen/Dense>
40 #include <Eigen/Sparse>
41 
42 using namespace DGtal;
43 using namespace Z3i;
44 
45 // Using standard 3D digital space.
48 // The following typedefs are useful
52 typedef SurfMesh::Face Face;
53 typedef SurfMesh::Vertex Vertex;
54 
55 
56 //Polyscope global
57 polyscope::SurfaceMesh *psMesh;
58 polyscope::PointCloud *psVertices;
59 polyscope::CurveNetwork *psBoundary;
60 
61 SurfMesh surfmesh;
63 
64 void initPhi()
65 {
66  phiEigen.resize(5);
67  phiEigen << 1.0, 2.0, 0.0, 5.0 ,1.5;
68 
69  psMesh->addVertexScalarQuantity("Phi", phiEigen);
70  psVertices->addScalarQuantity("Phi", phiEigen);
71 }
72 
73 void initQuantities()
74 {
76 
79  std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Real3dPoint> normals;
80  std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Real3dPoint> vectorArea;
81  std::vector<PolygonalCalculus<SH3::RealPoint,SH3::RealVector>::Real3dPoint> centroids;
82  std::vector<double> faceArea;
83 
85 
87  gradients.push_back( grad );
88 
90  cogradients.push_back( cograd );
91 
92  normals.push_back(calculus.faceNormalAsDGtalVector(f));
93 
95  vectorArea.push_back({vA(0) , vA(1), vA(2)});
96 
97  faceArea.push_back( calculus.faceArea(f));
98  centroids.push_back( calculus.centroidAsDGtalPoint(f) );
99 
102 
103  psMesh->addFaceVectorQuantity("Gradients", gradients);
104  psMesh->addFaceVectorQuantity("co-Gradients", cogradients);
105  psMesh->addFaceVectorQuantity("Normals", normals);
106  psMesh->addFaceScalarQuantity("Face area", faceArea);
107  psMesh->addFaceVectorQuantity("Vector area", vectorArea);
108 
109  psBoundary->addEdgeScalarQuantity("d0*phi", dPhi);
110  psBoundary->addEdgeScalarQuantity("A*phi", av);
111 
112  //Face centroid
113  polyscope::registerPointCloud("Centroids", centroids);
114 
115  //Flat Sharp
117  v << 50,-50,-100;
119  psMesh->addFaceVectorQuantity("A vector", someV);
120 
122  psBoundary->addEdgeScalarQuantity("flat (1-form)", flat);
123 
126  psMesh->addFaceVectorQuantity("Sharp", sharpRes);
127 }
128 
129 int main()
130 {
131  std::vector<RealPoint> positions={ {0,0,0},{20,0,0}, {20,10,0}, {10,8,5}, {0,15,1} };
132  std::vector<std::vector<size_t>> faces={ {0,1,2,3,4} };
133 
134  surfmesh = SurfMesh(positions.begin(),
135  positions.end(),
136  faces.begin(),
137  faces.end());
138 
139  psVertices = polyscope::registerPointCloud("Vertices", positions);
140 
141  std::vector<std::array<size_t,2>> edges={{0,1},{1,2},{2,3},{3,4},{4,0} };
142  psBoundary = polyscope::registerCurveNetwork("Edges", positions, edges);
143 
144  // Initialize polyscope
145  polyscope::init();
146 
147  psMesh = polyscope::registerSurfaceMesh("Single face", positions, faces);
148 
149  initPhi();
150  initQuantities();
151 
152  polyscope::show();
153  return EXIT_SUCCESS;
154 
155 }
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
DigitalPlane::Point Vector
SMesh::Vertices Vertices
Space::RealPoint RealPoint
Definition: StdDefs.h:170
DGtal is the top-level namespace which contains all DGtal functions and types.
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator > edges(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
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
int main(int argc, char **argv)
Shortcuts< KSpace > SH3
K init(Point(0, 0, 0), Point(512, 512, 512), true)
ShortcutsGeometry< Z3i::KSpace > SHG3
TriMesh::Face Face
TriMesh::Vertex Vertex