Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
examplePlaneProbingSurfaceLocalEstimator.cpp
Go to the documentation of this file.
1
16
29
31#include <iostream>
32#include <unordered_map>
33#include "ConfigExamples.h"
34#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/base/Common.h"
36#include "DGtal/geometry/surfaces/estimation/PlaneProbingTetrahedronEstimator.h"
37#include "DGtal/geometry/surfaces/estimation/PlaneProbingParallelepipedEstimator.h"
38#include "DGtal/geometry/surfaces/DigitalSurfacePredicate.h"
39#include "DGtal/geometry/surfaces/estimation/PlaneProbingDigitalSurfaceLocalEstimator.h"
40#include "DGtal/helpers/Shortcuts.h"
41#include "DGtal/helpers/ShortcutsGeometry.h"
42#include "DGtal/io/viewers/PolyscopeViewer.h"
44
45using namespace std;
46using namespace DGtal;
47
48using KSpace = Z3i::KSpace;
53using Point = SH3::Point;
55using Integer = Point::Coordinate;
56
58{
59 auto pointels = SH3::getPrimalVertices(K, s, true);
60
61 Point p = K.uCoords(pointels[0]),
62 u = K.uCoords(pointels[1]) - p,
63 v = K.uCoords(pointels[3]) - p;
64
65 static const RealPoint shift(-0.5, -0.5, -0.5);
66
67 return p + 0.5 * u + 0.5 * v + shift;
68}
69
71
72int main( int argc, char** argv )
73{
74 std::string volfile = (argc > 1) ? argv[1] : (examplesPath + "samples/cat10.vol");
75
77 auto bimage = SH3::makeBinaryImage(volfile, params);
78 auto K = SH3::getKSpace(bimage, params);
79 auto surface = SH3::makeDigitalSurface(bimage, K, params);
80 auto surfels = SH3::getSurfelRange(surface);
81
82 Integer bound = params["maxAABB"].as<Integer>();
83 double gridstep = params["gridstep"].as<double>();
84
85 PolyscopeViewer<> viewer(K);
86
88 using SurfacePredicate = DigitalSurfacePredicate<Surface>;
90 // The general form is PlaneProbingDigitalSurfaceLocalEstimator<SurfaceType, ProbingAlgorithm>
92
93 // Parameters of the estimator:
94 // - the probing factory
95 Estimator::ProbingFactory probingFactory = [&bound](const Estimator::ProbingFrame& frame, const SurfacePredicate& surfacePredicate) {
96 // If the base estimator is a PlaneProbingTetrahedronEstimator
97 // return new ProbingAlgorithm(frame.p, { frame.b1, frame.b2, frame.normal }, surfacePredicate);
98
99 // For a PlaneProbingParallelepipedEstimator
100 return new ProbingAlgorithm(frame.p, { frame.b1, frame.b2, frame.normal }, surfacePredicate, bound);
101 };
102
103 // - an optional hashmap of pre-estimations
104 std::unordered_map<Surfel, RealPoint> preEstimations;
105 // The user can provide the pre-estimation
106 // auto preEstimationsVector = SHG3::getCTrivialNormalVectors(surface, surfels, params);
107 // for (std::size_t i = 0; i < surfels.size(); ++i)
108 // {
109 // preEstimations[surfels[i]] = preEstimationsVector[i];
110 // }
111 // Or if it is not given, it is implicitly done inside the Estimator::eval function (using the MaximalSegmentSliceEstimation estimator)
112
113 // - a verbosity flag
114 bool verbose = true;
115
116 Estimator estimator(surface, probingFactory, preEstimations, verbose);
117 estimator.init(gridstep, surfels.begin(), surfels.end());
119
121 // Evaluation on a range of surfels
122 std::vector<Estimator::Quantity> quantities;
123 estimator.eval(surfels.begin(), surfels.end(), std::back_inserter(quantities));
124
125 // Or on one surfel 's'
126 // Estimator::Quantity q = estiamtor.eval(s);
128 Color fillColor = Color::White;
129 int i = 0;
130 for (auto it = surfels.begin(); it != surfels.end(); ++it, ++i)
131 {
132 const Surfel& s = *it;
133 const Estimator::Quantity& n = quantities[i];
134
135 RealPoint origin = centerSurfel(K, s);
136
137 viewer.drawColor(fillColor);
138 viewer << s;
139
140 // Pre-estimation in red
141 RealPoint const& preEstimation = estimator.getPreEstimation(it);
142 viewer.drawColor(Color::Red);
143 viewer.drawLine(origin, origin + 1.5 * preEstimation.getNormalized());
144
145 // Estimated normal in green;
146 viewer.drawColor(Color::Green);
147 viewer.drawLine(origin, origin + 1.5 * n.getNormalized());
148 }
149
150 viewer.show();
151 return 0;
152}
153// //
Structure representing an RGB triple with alpha component.
Definition Color.h:77
static const Color Red
Definition Color.h:425
static const Color Green
Definition Color.h:426
static const Color White
Definition Color.h:424
Aim: A point predicate which tells whether a point belongs to the set of pointels of a given digital ...
Aim: Adapt a plane-probing estimator on a digital surface to estimate normal vectors.
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...
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition Shortcuts.h:106
LightDigitalSurface::Surfel Surfel
Definition Shortcuts.h:162
Space::RealPoint RealPoint
Definition Shortcuts.h:124
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition Shortcuts.h:333
static CellRange getPrimalVertices(const KSpace &K, const SCell &s)
Definition Shortcuts.h:3263
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1548
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1210
::DGtal::DigitalSurface< ExplicitSurfaceContainer > DigitalSurface
Definition Shortcuts.h:159
static Parameters defaultParameters()
Definition Shortcuts.h:204
LightDigitalSurface::SCell SCell
Definition Shortcuts.h:164
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition Shortcuts.h:562
CountedPtr< SH3::DigitalSurface > surface
SH3::DigitalSurface Surface
PlaneProbingParallelepipedEstimator< DigitalPlane, ProbingMode::R1 > Estimator
RealPoint centerSurfel(KSpace const &K, SH3::SCell const &s)
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
Shortcuts< KSpace > SH3
int main()
Definition testBits.cpp:56
KSpace K
ShortcutsGeometry< Z3i::KSpace > SHG3
PointVector< 3, double > RealPoint