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 }
DGtal::SurfaceMesh::Vertex
Index Vertex
Definition: SurfaceMesh.h:108
DGtal::PolygonalCalculus::Face
MySurfaceMesh::Face Face
Face type.
Definition: PolygonalCalculus.h:87
DGtal::PolygonalCalculus::vectorArea
Vector vectorArea(const Face f) const
Definition: PolygonalCalculus.h:316
SH3
Shortcuts< KSpace > SH3
Definition: testArithmeticalDSSComputerOnSurfels.cpp:49
DGtal::PolygonalCalculus::faceNormalAsDGtalVector
Real3dVector faceNormalAsDGtalVector(const Face f) const
Definition: PolygonalCalculus.h:358
Face
TriMesh::Face Face
Definition: testTriangulatedSurface.cpp:56
boost::edges
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator > edges(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
Definition: DigitalSurfaceBoostGraphInterface.h:503
DGtal::PolygonalCalculus::centroidAsDGtalPoint
Real3dPoint centroidAsDGtalPoint(const Face f) const
Definition: PolygonalCalculus.h:436
DGtal::SurfaceMesh
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition: SurfaceMesh.h:91
DGtal::PolygonalCalculus::faceArea
double faceArea(const Face f) const
Definition: PolygonalCalculus.h:340
DGtal::PolygonalCalculus
Implements differential operators on polygonal surfaces from .
Definition: PolygonalCalculus.h:70
DGtal::Shortcuts
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:104
DGtal::PolygonalCalculus::coGradient
DenseMatrix coGradient(const Face f) const
Definition: PolygonalCalculus.h:367
Vertex
TriMesh::Vertex Vertex
Definition: testTriangulatedSurface.cpp:57
DGtal::SurfaceMesh::Vertices
std::vector< Vertex > Vertices
The type that defines a list/range of vertices (e.g. to define faces)
Definition: SurfaceMesh.h:112
DGtal::PolygonalCalculus::D
DenseMatrix D(const Face f) const
Definition: PolygonalCalculus.h:261
SHG3
ShortcutsGeometry< Z3i::KSpace > SHG3
Definition: testIntegralInvariantShortcuts.cpp:47
Vertices
SMesh::Vertices Vertices
Definition: fullConvexitySphereGeodesics.cpp:118
DGtal::Z3i::RealPoint
Space::RealPoint RealPoint
Definition: StdDefs.h:170
DGtal::PolygonalCalculus::sharp
DenseMatrix sharp(const Face f) const
Definition: PolygonalCalculus.h:445
DGtal::PolygonalCalculus::gradient
DenseMatrix gradient(const Face f) const
Definition: PolygonalCalculus.h:390
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::ShortcutsGeometry
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: ShortcutsGeometry.h:76
DGtal::SurfaceMesh::Face
Index Face
Definition: SurfaceMesh.h:106
Vector
FreemanChain< int >::Vector Vector
Definition: testCombinDSS.cpp:60
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::PolygonalCalculus::Vector
LinAlg::DenseVector Vector
Type of Vector.
Definition: PolygonalCalculus.h:96
DGtal::SurfaceMesh::RealPoint
TRealPoint RealPoint
Definition: SurfaceMesh.h:93
DGtal::PolygonalCalculus::flat
DenseMatrix flat(const Face f) const
Definition: PolygonalCalculus.h:404
init
K init(Point(0, 0, 0), Point(512, 512, 512), true)
DGtal::PolygonalCalculus::A
DenseMatrix A(const Face f) const
Definition: PolygonalCalculus.h:295