DGtal  1.3.beta
examplePlaneProbingSurfaceLocalEstimator.cpp
Go to the documentation of this file.
1 
30 #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/Viewer3D.h"
44 
45 using namespace std;
46 using namespace DGtal;
47 
53 using Point = SH3::Point;
55 using 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 
72 int main( int argc, char** argv )
73 {
74  QApplication application(argc, argv);
75 
76  std::string volfile = (argc > 1) ? argv[1] : (examplesPath + "samples/cat10.vol");
77 
78  auto params = SH3::defaultParameters() | SHG3::defaultParameters();
79  auto bimage = SH3::makeBinaryImage(volfile, params);
80  auto K = SH3::getKSpace(bimage, params);
81  auto surface = SH3::makeDigitalSurface(bimage, K, params);
82  auto surfels = SH3::getSurfelRange(surface);
83 
84  Integer bound = params["maxAABB"].as<Integer>();
85  double gridstep = params["gridstep"].as<double>();
86 
87  Viewer3D<> viewer(K);
88  viewer << SetMode3D(Surfel().className(), "Basic");
89  viewer.show();
90 
92  using SurfacePredicate = DigitalSurfacePredicate<Surface>;
94  // The general form is PlaneProbingDigitalSurfaceLocalEstimator<SurfaceType, ProbingAlgorithm>
96 
97  // Parameters of the estimator:
98  // - the probing factory
99  Estimator::ProbingFactory probingFactory = [&bound](const Estimator::ProbingFrame& frame, const SurfacePredicate& surfacePredicate) {
100  // If the base estimator is a PlaneProbingTetrahedronEstimator
101  // return new ProbingAlgorithm(frame.p, { frame.b1, frame.b2, frame.normal }, surfacePredicate);
102 
103  // For a PlaneProbingParallelepipedEstimator
104  return new ProbingAlgorithm(frame.p, { frame.b1, frame.b2, frame.normal }, surfacePredicate, bound);
105  };
106 
107  // - an optional hashmap of pre-estimations
108  std::unordered_map<Surfel, RealPoint> preEstimations;
109  // The user can provide the pre-estimation
110  // auto preEstimationsVector = SHG3::getCTrivialNormalVectors(surface, surfels, params);
111  // for (std::size_t i = 0; i < surfels.size(); ++i)
112  // {
113  // preEstimations[surfels[i]] = preEstimationsVector[i];
114  // }
115  // Or if it is not given, it is implicitly done inside the Estimator::eval function (using the MaximalSegmentSliceEstimation estimator)
116 
117  // - a verbosity flag
118  bool verbose = true;
119 
120  Estimator estimator(surface, probingFactory, preEstimations, verbose);
121  estimator.init(gridstep, surfels.begin(), surfels.end());
123 
125  // Evaluation on a range of surfels
126  std::vector<Estimator::Quantity> quantities;
127  estimator.eval(surfels.begin(), surfels.end(), std::back_inserter(quantities));
128 
129  // Or on one surfel 's'
130  // Estimator::Quantity q = estiamtor.eval(s);
132 
133  Color fillColor = viewer.getFillColor();
134 
135  int i = 0;
136  for (auto it = surfels.begin(); it != surfels.end(); ++it, ++i)
137  {
138  const Surfel& s = *it;
139  const Estimator::Quantity& n = quantities[i];
140 
141  RealPoint origin = centerSurfel(K, s);
142 
143  viewer.setFillColor(fillColor);
144  viewer << s;
145 
146  // Pre-estimation in red
147  RealPoint const& preEstimation = estimator.getPreEstimation(it);
148  viewer.setLineColor(Color::Red);
149  viewer.addLine(origin, origin + 1.5 * preEstimation.getNormalized(), 0.3);
150 
151  // Estimated normal in green;
152  viewer.setLineColor(Color::Green);
153  viewer.addLine(origin, origin + 1.5 * n.getNormalized(), 0.3);
154  }
155 
156  viewer << Viewer3D<>::updateDisplay;
157  application.exec();
158 
159  return 0;
160 }
161 // //
DGtal::PlaneProbingParallelepipedEstimator
Aim:
Definition: PlaneProbingParallelepipedEstimator.h:62
DGtal::PlaneProbingDigitalSurfaceLocalEstimator
Aim: Adapt a plane-probing estimator on a digital surface to estimate normal vectors.
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:70
DGtal::DigitalSurface
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Definition: DigitalSurface.h:139
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Shortcuts::makeDigitalSurface
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1209
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::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
centerSurfel
RealPoint centerSurfel(KSpace const &K, SH3::SCell const &s)
Definition: examplePlaneProbingSurfaceLocalEstimator.cpp:57
DGtal::Shortcuts::RealPoint
Space::RealPoint RealPoint
Point with floating-point coordinates.
Definition: Shortcuts.h:123
DGtal::Shortcuts::DigitalSurface
::DGtal::DigitalSurface< ExplicitSurfaceContainer > DigitalSurface
defines an arbitrary digital surface over a binary image.
Definition: Shortcuts.h:158
DGtal::Viewer3D
Definition: Viewer3D.h:135
DGtal::Shortcuts::defaultParameters
static Parameters defaultParameters()
Definition: Shortcuts.h:203
Surfel
SH3::Surfel Surfel
Definition: examplePlaneProbingSurfaceLocalEstimator.cpp:52
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::PointVector::getNormalized
PointVector< dim, double, std::array< double, dim > > getNormalized() const
DGtal::Shortcuts::Point
Space::Point Point
Point with integer coordinates.
Definition: Shortcuts.h:117
main
int main(int argc, char **argv)
Definition: examplePlaneProbingSurfaceLocalEstimator.cpp:72
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::KhalimskySpaceND::uCoords
Point uCoords(const Cell &c) const
Return its digital coordinates.
DGtal::Shortcuts::SCell
LightDigitalSurface::SCell SCell
Definition: Shortcuts.h:163
DGtal::DigitalSurfacePredicate< Surface >
DGtal::PlaneProbingParallelepipedEstimator::Quantity
typename TetrahedronEstimator::Quantity Quantity
Definition: PlaneProbingParallelepipedEstimator.h:77
DGtal::SetMode3D
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Definition: DrawWithDisplay3DModifier.h:73
Integer
Point::Coordinate Integer
Definition: examplePlaneProbingParallelepipedEstimator.cpp:44
DGtal::Shortcuts::getKSpace
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition: Shortcuts.h:332
DGtal::Shortcuts::Surfel
LightDigitalSurface::Surfel Surfel
Definition: Shortcuts.h:161
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
KSpace
Z3i::KSpace KSpace
Definition: examplePlaneProbingSurfaceLocalEstimator.cpp:48
DGtal::Shortcuts::getPrimalVertices
static CellRange getPrimalVertices(const KSpace &K, const SCell &s)
Definition: Shortcuts.h:3180
DGtal::Shortcuts::getSurfelRange
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1547
DGtal::Shortcuts::makeBinaryImage
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition: Shortcuts.h:561
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64