DGtal 2.1.0
Loading...
Searching...
No Matches
examplePlaneProbingSurfaceLocalEstimator.cpp File Reference
#include <iostream>
#include <unordered_map>
#include "ConfigExamples.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
#include "DGtal/geometry/surfaces/estimation/PlaneProbingTetrahedronEstimator.h"
#include "DGtal/geometry/surfaces/estimation/PlaneProbingParallelepipedEstimator.h"
#include "DGtal/geometry/surfaces/DigitalSurfacePredicate.h"
#include "DGtal/geometry/surfaces/estimation/PlaneProbingDigitalSurfaceLocalEstimator.h"
#include "DGtal/helpers/Shortcuts.h"
#include "DGtal/helpers/ShortcutsGeometry.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
Include dependency graph for examplePlaneProbingSurfaceLocalEstimator.cpp:

Go to the source code of this file.

Typedefs

using KSpace = Z3i::KSpace
 
using SH3 = Shortcuts< KSpace >
 
using SHG3 = ShortcutsGeometry< KSpace >
 
using Surface = SH3::DigitalSurface
 
using Surfel = SH3::Surfel
 
using Point = SH3::Point
 
using RealPoint = SH3::RealPoint
 
using Integer = Point::Coordinate
 

Functions

RealPoint centerSurfel (KSpace const &K, SH3::SCell const &s)
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jocelyn Meyron (jocel.nosp@m.yn.m.nosp@m.eyron.nosp@m.@lir.nosp@m.is.cn.nosp@m.rs.f.nosp@m.r ) Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2020/12/07

An example file that shows how to construct and use a PlaneProbingDigitalSurfaceLocalEstimator.

This file is part of the DGtal library.

Definition in file examplePlaneProbingSurfaceLocalEstimator.cpp.

Typedef Documentation

◆ Integer

using Integer = Point::Coordinate

Definition at line 55 of file examplePlaneProbingSurfaceLocalEstimator.cpp.

◆ KSpace

◆ Point

using Point = SH3::Point

Definition at line 53 of file examplePlaneProbingSurfaceLocalEstimator.cpp.

◆ RealPoint

using RealPoint = SH3::RealPoint

Definition at line 54 of file examplePlaneProbingSurfaceLocalEstimator.cpp.

◆ SH3

using SH3 = Shortcuts<KSpace>

Definition at line 49 of file examplePlaneProbingSurfaceLocalEstimator.cpp.

◆ SHG3

◆ Surface

using Surface = SH3::DigitalSurface

Definition at line 51 of file examplePlaneProbingSurfaceLocalEstimator.cpp.

◆ Surfel

using Surfel = SH3::Surfel

Definition at line 52 of file examplePlaneProbingSurfaceLocalEstimator.cpp.

Function Documentation

◆ centerSurfel()

RealPoint centerSurfel ( KSpace const &  K,
SH3::SCell const &  s 
)

Definition at line 57 of file examplePlaneProbingSurfaceLocalEstimator.cpp.

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}
Point uCoords(const Cell &c) const
Return its digital coordinates.
KSpace K

References K, and DGtal::KhalimskySpaceND< dim, TInteger >::uCoords().

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

[PlaneProbingDigitalSurfaceLocalEstimatorConstruction]

[PlaneProbingDigitalSurfaceLocalEstimatorConstruction]

[PlaneProbingDigitalSurfaceLocalEstimatorUsage]

[PlaneProbingDigitalSurfaceLocalEstimatorUsage]

Definition at line 72 of file examplePlaneProbingSurfaceLocalEstimator.cpp.

73{
74 std::string volfile = (argc > 1) ? argv[1] : (examplesPath + "samples/cat10.vol");
75
76 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
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}
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
CountedPtr< SH3::DigitalSurface > surface
PlaneProbingParallelepipedEstimator< DigitalPlane, ProbingMode::R1 > Estimator
RealPoint centerSurfel(KSpace const &K, SH3::SCell const &s)
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.

References centerSurfel(), DGtal::PointVector< dim, TEuclideanRing, TContainer >::getNormalized(), DGtal::Color::Green, K, DGtal::Color::Red, surface, and DGtal::Color::White.