DGtal 2.1.0
Loading...
Searching...
No Matches
viewer3D-12-quantities.cpp
Go to the documentation of this file.
1
33#include "ConfigExamples.h"
34#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/helpers/Shortcuts.h"
36#include "DGtal/helpers/ShortcutsGeometry.h"
37
38#include "DGtal/io/viewers/PolyscopeViewer.h"
39
40using namespace std;
41using namespace DGtal;
42using namespace Z3i;
43
44int main() {
45 typedef Shortcuts<KSpace> SH3;
47
48 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
49
50 params( "polynomial", "3*x^2+2*y^2+z^2-90" )( "gridstep", 0.25 );
51 auto implicit_shape = SH3::makeImplicitShape3D ( params );
52 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
53 auto binary_image = SH3::makeBinaryImage ( digitized_shape, params );
54 auto K = SH3::getKSpace( params );
55 auto surface = SH3::makeLightDigitalSurface( binary_image, K, params );
56 auto surfels = SH3::getSurfelRange( surface, params );
57 auto positions = SHG3::getPositions( implicit_shape, K, surfels, params );
58 auto normals = SHG3::getNormalVectors( implicit_shape, K, surfels, params );
59 auto mean_curvs = SHG3::getMeanCurvatures( implicit_shape, K, surfels, params );
60 auto gauss_curvs = SHG3::getGaussianCurvatures( implicit_shape, K, surfels, params );
61
62 PolyscopeViewer viewer;
64 // Option 1: stream operator (Scell_1_2d in viewer)
65 // Most usefull when adding single quantity, otherwise
66 // it should be nested.
67 viewer << WithQuantity(
70 surfels, "Mean Curv", mean_curvs
71 ),
72 "Gauss Curve", gauss_curvs
73 ),
74 "Normal", normals
75 );
77
79 // Option 2: draw first then add quantities (Surfels 1 in viewer)
80 // This requires to obtain or set object name
81 std::string objectName = "Surfels 1";
82 viewer.draw(surfels, objectName); // Draws the object independantly
83 viewer.addQuantity(objectName, "Mean Curv", mean_curvs);
84 viewer.addQuantity(objectName, "Gauss Curv", gauss_curvs);
85 viewer.addQuantity(objectName, "Normal", normals);
87
88 // Option 3: Within loops (Surfels 3 within the viewer)
89 // Here, a group must be created for the colormaps to work
90 // Note: here Option 1 and 2 are superior, this is just an example
91
93 std::string objectName2 = "Surfels 3";
94 viewer.newVolumetricList(objectName2); // Signed cells are drawn as volumetric meshes
95 viewer.allowReuseList = true; // Allows for automatic groupping
96
97 auto surfIt = surfels.begin();
98 auto mcurveIt = mean_curvs.begin();
99 auto gcurveIt = gauss_curvs.begin();
100 auto ncurveIt = normals.begin();
101
102 for (; surfIt != surfels.end(); ++surfIt, ++mcurveIt, ++gcurveIt, ++ncurveIt) {
103 // Both options 1 and 2 can be used together, as long as we know the name for sure
104 viewer << WithQuantity(*surfIt, "Mean Curv", *mcurveIt);
105 viewer.addQuantity(objectName2, "Gauss Curve", *gcurveIt);
106 viewer.addQuantity(objectName2, "Normals", *ncurveIt);
107 }
109
110 viewer.show();
111 return 0;
112 }
113
std::string draw(const Point &p, const std::string &uname="Point_{i}")
void addQuantity(const std::string &oName, const std::string &qName, const Type &value, QuantityScale scale=QuantityScale::UNKNOWN)
std::string newVolumetricList(const std::string &name)
Definition Display3D.h:541
void show() override
Starts the event loop and display of elements.
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:102
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
Attach a property to an element.
Definition Display3D.h:331
Shortcuts< KSpace > SH3
KSpace K
ShortcutsGeometry< Z3i::KSpace > SHG3