DGtal 2.1.0
Loading...
Searching...
No Matches
exampleMaximalSegmentSliceEstimation.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "ConfigExamples.h"
33#include "DGtal/helpers/StdDefs.h"
34#include "DGtal/base/Common.h"
35#include "DGtal/geometry/surfaces/estimation/MaximalSegmentSliceEstimation.h"
36#include "DGtal/helpers/Shortcuts.h"
37#include "DGtal/io/viewers/PolyscopeViewer.h"
39
40using namespace std;
41using namespace DGtal;
42
45using Surface = SH3::DigitalSurface;
46using Surfel = Surface::Surfel;
47using RealPoint = SH3::RealPoint;
48using Point = SH3::Point;
49
51{
52 auto pointels = SH3::getPrimalVertices(K, s, true);
53
54 Point p = K.uCoords(pointels[0]),
55 u = K.uCoords(pointels[1]) - p,
56 v = K.uCoords(pointels[3]) - p;
57
58 static const RealPoint shift(-0.5, -0.5, -0.5);
59
60 return p + 0.5 * u + 0.5 * v + shift;
61}
62
64
65int main()
66{
67 auto params = SH3::defaultParameters();
68 params("polynomial", "ellipsoid")("gridstep", "1.0");
69 auto implicit_shape = SH3::makeImplicitShape3D ( params );
70 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
71 auto K = SH3::getKSpace( params );
72 auto binary_image = SH3::makeBinaryImage( digitized_shape, params );
73 auto surface = SH3::makeDigitalSurface( binary_image, K, params );
74 auto surfels = SH3::getSurfelRange(surface);
75
76 double gridstep = params["gridstep"].as<double>();
77
78 PolyscopeViewer<> viewer(K);
79
81 // Instantiation
83 Estimator estimator;
84 estimator.init(gridstep, surfels.begin(), surfels.end());
85 estimator.attach(surface);
86
87 // Usage
88 std::vector<Estimator::Quantity> quantities;
89 estimator.eval(surfels.begin(), surfels.end(), std::back_inserter(quantities));
91
92 Color fillColor = Color::White;
93
94 for (std::size_t i = 0; i < surfels.size(); ++i)
95 {
96 const Surfel& s = surfels[i];
97 const Estimator::Quantity& normal = quantities[i];
98
99 const RealPoint& n = normal.getNormalized();
100 RealPoint origin = centerSurfel(K, s);
101
102 viewer.drawColor(fillColor);
103 viewer << s;
104
105 viewer.drawColor(Color::Green);
106 viewer.drawLine(origin, origin + 1.5 * n);
107 }
108
109 viewer.show();
110 return 0;
111}
112// //
Structure representing an RGB triple with alpha component.
Definition Color.h:77
static const Color Green
Definition Color.h:426
static const Color White
Definition Color.h:424
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Point uCoords(const Cell &c) const
Return its digital coordinates.
void init(Scalar const &h, SurfelConstIterator itb, SurfelConstIterator ite)
PointVector< dim, double, std::array< double, dim > > getNormalized() const
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition Shortcuts.h:102
LightDigitalSurface::SCell SCell
Definition Shortcuts.h:160
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
SH3::DigitalSurface Surface
RealPoint centerSurfel(KSpace const &K, SH3::SCell const &s)
PlaneProbingParallelepipedEstimator< DigitalPlane, ProbingMode::R1 > Estimator
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Shortcuts< KSpace > SH3
KSpace K