DGtal  1.2.0
PlaneProbingDigitalSurfaceLocalEstimator.h
1 
17 #pragma once
18 
31 #if defined(PlaneProbingDigitalSurfaceLocalEstimator_RECURSES)
32 #error Recursive header files inclusion detected in PlaneProbingDigitalSurfaceLocalEstimator.h
33 #else // defined(PlaneProbingDigitalSurfaceLocalEstimator_RECURSES)
35 #define PlaneProbingDigitalSurfaceLocalEstimator_RECURSES
36 
37 #if !defined PlaneProbingDigitalSurfaceLocalEstimator_h
39 #define PlaneProbingDigitalSurfaceLocalEstimator_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <unordered_map>
45 #include "DGtal/base/Common.h"
46 #include "DGtal/geometry/surfaces/DigitalSurfacePredicate.h"
47 #include "DGtal/geometry/surfaces/estimation/MaximalSegmentSliceEstimation.h"
48 #include "DGtal/topology/KhalimskyCellHashFunctions.h"
49 #include "DGtal/topology/CDigitalSurfaceContainer.h"
51 
52 namespace DGtal
53 {
54 
56  // template class PlaneProbingDigitalSurfaceLocalEstimator
69  template <typename TSurface, typename TInternalProbingAlgorithm>
71  {
73 
74  // ----------------------- Public types ------------------------------
75  public:
76  using Surface = TSurface;
77  using InternalProbingAlgorithm = TInternalProbingAlgorithm;
79  using Scalar = double;
80 
85  struct ProbingFrame
86  {
87  Point p;
96  {
97  Point newP = p + b1,
98  newB1 = b2,
99  newB2 = -b1,
100  newNormal = newB1.crossProduct(newB2);
101 
102  return { newP, newB1, newB2, newNormal };
103  }
104 
108  Point shift () const
109  {
110  return b1 + b2 + normal;
111  }
112  };
113 
115  using ProbingFactory = std::function<InternalProbingAlgorithm*(const ProbingFrame&, Predicate const&)>;
117  using PointOnProbingRay = typename InternalProbingAlgorithm::PointOnProbingRay;
118 
119  // ----------------------- model of CDigitalSurfaceLocalEstimator ----------------
120  using Surfel = typename Surface::Surfel;
121  using Quantity = typename InternalProbingAlgorithm::Quantity;
122 
123  // -------------------------------------- other types ----------------------------
124  using KSpace = typename Surface::KSpace;
125  using SCell = typename KSpace::SCell;
126  using Cell = typename KSpace::Cell;
127  using Space = typename KSpace::Space;
128  using RealPoint = typename Space::RealPoint;
129 
130  // ----------------------- Standard services ------------------------------
131  public:
136 
137  /*
138  * Constructor.
139  *
140  * @param aSurface a digital surface.
141  */
143 
144  /*
145  * Constructor.
146  *
147  * @param aProbingFactory functor to produce a plane-probing estimator from a frame and a predicate.
148  * @param aPreEstimations map of pre-estimated normal vectors (empty by default) to help choose the correct octant.
149  * @param aVerbose a boolean indicating the level of verbosity.
150  */
152  std::unordered_map<Surfel, RealPoint> const& aPreEstimations = {},
153  bool aVerbose = false);
154 
155  /*
156  * Constructor.
157  *
158  * @param aSurface a digital surface.
159  * @param aProbingFactory functor to produce a plane-probing estimator from a frame and a predicate.
160  * @param aPreEstimations map of pre-estimated normal vectors (empty by default) to help choose the correct octant.
161  * @param aVerbose a boolean indicating the level of verbosity.
162  */
164  ProbingFactory const& aProbingFactory,
165  std::unordered_map<Surfel, RealPoint> const& aPreEstimations = {},
166  bool aVerbose = false);
167 
172 
178 
184 
191 
198 
199  // ----------------- model of CSurfelLocalEstimator -----------------------
200  public:
208  template < typename SurfelConstIterator >
209  void init (Scalar const& h, SurfelConstIterator itb, SurfelConstIterator ite);
210 
219  template < typename SurfelConstIterator >
220  Quantity eval (SurfelConstIterator it);
221 
230  template < typename SurfelConstIterator, typename OutputIterator >
231  OutputIterator eval (SurfelConstIterator itb, SurfelConstIterator ite, OutputIterator out);
232 
236  Scalar h () const;
237 
238  // --------------- model of CDigitalSurfaceLocalEstimator ------------------
239  public:
244  void attach (ConstAlias<Surface> aSurface);
245 
253  void setParams (ProbingFactory const& aProbingFactory,
254  std::unordered_map<Surfel, RealPoint> const& aPreEstimations = {},
255  bool aVerbose = false);
256 
257  // ----------------------- Interface --------------------------------------
258  public:
259 
264  void selfDisplay ( std::ostream & out ) const;
265 
270  bool isValid() const;
271 
276  template < typename SurfelConstIterator >
277  RealPoint getPreEstimation (SurfelConstIterator it) const;
278 
279  // ------------------------- Protected Datas ------------------------------
280  protected:
281 
282  // ------------------------- Private Datas --------------------------------
283  private:
290  mutable std::unordered_map<Surfel, RealPoint> myPreEstimations;
291  bool myVerbose;
293  // ------------------------- Hidden services ------------------------------
294  protected:
295 
296  // ------------------------- Internals ------------------------------------
297  private:
305 
314  ProbingFrame probingFrameWithPreEstimation (ProbingFrame const& aInitialFrame, RealPoint const& aPreEstimation) const;
315 
320  static int signComponent (double x)
321  {
322  return (x >= 0) ? 1 : -1;
323  }
324 
329  static std::vector<int> findZeros (RealPoint const& p)
330  {
331  std::vector<int> zeros;
332 
333  for (int i = 0; i < 3; ++i)
334  {
335  if (p[i] == 0)
336  {
337  zeros.push_back(i);
338  }
339  }
340 
341  return zeros;
342  }
343 
350  static std::vector<PointOnProbingRay> getProbingRaysOneFlatDirection (int aIndex)
351  {
352  if (aIndex == 0)
353  {
354  return { PointOnProbingRay({ 2, 1, 0 }), PointOnProbingRay({ 1, 2, 0 }) };
355  }
356  else if (aIndex == 1)
357  {
358  return { PointOnProbingRay({ 0, 2, 1 }), PointOnProbingRay({ 2, 0, 1 }) };
359  }
360  else
361  {
362  ASSERT(aIndex == 2);
363  return { PointOnProbingRay({ 1, 0, 2 }), PointOnProbingRay({ 0, 1, 2 }) };
364  }
365  }
366 
373  Point getNormalOneFlatDirection (int aIndex) const
374  {
375  int im1 = (aIndex - 1 + 3) % 3,
376  im2 = (aIndex - 2 + 3) % 3;
377 
378  return myProbingAlgorithm->m(im1).crossProduct(myProbingAlgorithm->m(aIndex)) +
379  myProbingAlgorithm->m(aIndex).crossProduct(myProbingAlgorithm->m(im2));
380  }
381  }; // end of class PlaneProbingDigitalSurfaceLocalEstimator
382 
383 
390  template < typename TSurface, typename TInternalProbingAlgorithm >
391  std::ostream&
393 
394 } // namespace DGtal
395 
396 
398 // Includes inline functions.
399 #include "DGtal/geometry/surfaces/estimation/PlaneProbingDigitalSurfaceLocalEstimator.ih"
400 
401 // //
403 
404 #endif // !defined PlaneProbingDigitalSurfaceLocalEstimator_h
405 
406 #undef PlaneProbingDigitalSurfaceLocalEstimator_RECURSES
407 #endif // else defined(PlaneProbingDigitalSurfaceLocalEstimator_RECURSES)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
Aim: Adapt a plane-probing estimator on a digital surface to estimate normal vectors.
PlaneProbingDigitalSurfaceLocalEstimator & operator=(const PlaneProbingDigitalSurfaceLocalEstimator &other)
ProbingFrame probingFrameWithPreEstimation(ProbingFrame const &aInitialFrame, RealPoint const &aPreEstimation) const
BOOST_CONCEPT_ASSERT((concepts::CDigitalSurfaceContainer< typename TSurface::DigitalSurfaceContainer >))
void init(Scalar const &h, SurfelConstIterator itb, SurfelConstIterator ite)
std::function< InternalProbingAlgorithm *(const ProbingFrame &, Predicate const &)> ProbingFactory
PlaneProbingDigitalSurfaceLocalEstimator(const PlaneProbingDigitalSurfaceLocalEstimator &other)
PlaneProbingDigitalSurfaceLocalEstimator(ConstAlias< Surface > aSurface, ProbingFactory const &aProbingFactory, std::unordered_map< Surfel, RealPoint > const &aPreEstimations={}, bool aVerbose=false)
void selfDisplay(std::ostream &out) const
PlaneProbingDigitalSurfaceLocalEstimator(PlaneProbingDigitalSurfaceLocalEstimator &&other)=delete
void setParams(ProbingFactory const &aProbingFactory, std::unordered_map< Surfel, RealPoint > const &aPreEstimations={}, bool aVerbose=false)
ProbingFrame probingFrameFromSurfel(Surfel const &aSurfel) const
static std::vector< PointOnProbingRay > getProbingRaysOneFlatDirection(int aIndex)
void attach(ConstAlias< Surface > aSurface)
Quantity eval(SurfelConstIterator it)
OutputIterator eval(SurfelConstIterator itb, SurfelConstIterator ite, OutputIterator out)
PlaneProbingDigitalSurfaceLocalEstimator(ProbingFactory const &aProbingFactory, std::unordered_map< Surfel, RealPoint > const &aPreEstimations={}, bool aVerbose=false)
RealPoint getPreEstimation(SurfelConstIterator it) const
PlaneProbingDigitalSurfaceLocalEstimator(ConstAlias< Surface > aSurface)
typename InternalProbingAlgorithm::PointOnProbingRay PointOnProbingRay
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: The digital surface container concept describes a minimal set of inner types and methods so as t...
Z2i::RealPoint RealPoint
MyPointD Point
Definition: testClone2.cpp:383
KSpace::Cell Cell