DGtal  1.3.beta
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)
34 
35 #define PlaneProbingDigitalSurfaceLocalEstimator_RECURSES
36 
37 #if !defined PlaneProbingDigitalSurfaceLocalEstimator_h
38 
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:
304  ProbingFrame probingFrameFromSurfel (Surfel const& aSurfel) const;
305 
315  std::pair<bool, ProbingFrame> probingFrameWithPreEstimation (ProbingFrame const& aInitialFrame, RealPoint const& aPreEstimation) const;
316 
321  static int signComponent (double x)
322  {
323  return (x >= 0) ? 1 : -1;
324  }
325 
330  static std::vector<int> findZeros (RealPoint const& p)
331  {
332  std::vector<int> zeros;
333 
334  for (int i = 0; i < 3; ++i)
335  {
336  if (p[i] == 0)
337  {
338  zeros.push_back(i);
339  }
340  }
341 
342  return zeros;
343  }
344 
351  static std::vector<PointOnProbingRay> getProbingRaysOneFlatDirection (int aIndex)
352  {
353  if (aIndex == 0)
354  {
355  return { PointOnProbingRay({ 2, 1, 0 }), PointOnProbingRay({ 1, 2, 0 }) };
356  }
357  else if (aIndex == 1)
358  {
359  return { PointOnProbingRay({ 0, 2, 1 }), PointOnProbingRay({ 2, 0, 1 }) };
360  }
361  else
362  {
363  ASSERT(aIndex == 2);
364  return { PointOnProbingRay({ 1, 0, 2 }), PointOnProbingRay({ 0, 1, 2 }) };
365  }
366  }
367 
374  Point getNormalOneFlatDirection (int aIndex) const
375  {
376  int im1 = (aIndex - 1 + 3) % 3,
377  im2 = (aIndex - 2 + 3) % 3;
378 
379  return myProbingAlgorithm->m(im1).crossProduct(myProbingAlgorithm->m(aIndex)) +
380  myProbingAlgorithm->m(aIndex).crossProduct(myProbingAlgorithm->m(im2));
381  }
382  }; // end of class PlaneProbingDigitalSurfaceLocalEstimator
383 
384 
391  template < typename TSurface, typename TInternalProbingAlgorithm >
392  std::ostream&
393  operator<< ( std::ostream & out, const PlaneProbingDigitalSurfaceLocalEstimator<TSurface, TInternalProbingAlgorithm> & object );
394 
395 } // namespace DGtal
396 
397 
399 // Includes inline functions.
400 #include "DGtal/geometry/surfaces/estimation/PlaneProbingDigitalSurfaceLocalEstimator.ih"
401 
402 // //
404 
405 #endif // !defined PlaneProbingDigitalSurfaceLocalEstimator_h
406 
407 #undef PlaneProbingDigitalSurfaceLocalEstimator_RECURSES
408 #endif // else defined(PlaneProbingDigitalSurfaceLocalEstimator_RECURSES)
DGtal::PlaneProbingDigitalSurfaceLocalEstimator
Aim: Adapt a plane-probing estimator on a digital surface to estimate normal vectors.
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:70
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::~PlaneProbingDigitalSurfaceLocalEstimator
~PlaneProbingDigitalSurfaceLocalEstimator()
DGtal::ConstAlias
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::PointOnProbingRay
typename InternalProbingAlgorithm::PointOnProbingRay PointOnProbingRay
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:117
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::getProbingRaysOneFlatDirection
static std::vector< PointOnProbingRay > getProbingRaysOneFlatDirection(int aIndex)
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:351
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::Scalar
double Scalar
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:79
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::ProbingFrame::rotatedCopy
ProbingFrame rotatedCopy() const
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:95
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::myH
Scalar myH
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:285
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CDigitalSurfaceContainer< typename TSurface::DigitalSurfaceContainer >))
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::getNormalOneFlatDirection
Point getNormalOneFlatDirection(int aIndex) const
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:374
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::ProbingFrame::b2
Point b2
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:89
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::PlaneProbingDigitalSurfaceLocalEstimator
PlaneProbingDigitalSurfaceLocalEstimator()
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::attach
void attach(ConstAlias< Surface > aSurface)
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::myPredicate
Predicate myPredicate
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:287
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::myProbingFactory
ProbingFactory myProbingFactory
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:289
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::Point
typename InternalProbingAlgorithm::Point Point
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:78
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::operator=
PlaneProbingDigitalSurfaceLocalEstimator & operator=(const PlaneProbingDigitalSurfaceLocalEstimator &other)
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::ProbingFrame
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:85
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::ProbingFrame::shift
Point shift() const
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:108
DGtal::concepts::CDigitalSurfaceContainer
Aim: The digital surface container concept describes a minimal set of inner types and methods so as t...
Definition: CDigitalSurfaceContainer.h:127
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::probingFrameWithPreEstimation
std::pair< bool, ProbingFrame > probingFrameWithPreEstimation(ProbingFrame const &aInitialFrame, RealPoint const &aPreEstimation) const
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::getPreEstimation
RealPoint getPreEstimation(SurfelConstIterator it) const
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::SCell
typename KSpace::SCell SCell
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:125
DGtal::KhalimskySpaceND::Cell
KhalimskyCell< dim, Integer > Cell
Definition: KhalimskySpaceND.h:415
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::Cell
typename KSpace::Cell Cell
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:126
DGtal::KhalimskySpaceND::SCell
SignedKhalimskyCell< dim, Integer > SCell
Definition: KhalimskySpaceND.h:417
DGtal::CountedConstPtrOrConstPtr< Surface >
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::RealPoint
typename Space::RealPoint RealPoint
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:128
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::ProbingFrame::p
Point p
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:87
DGtal::KhalimskySpaceND::Space
SpaceND< dim, Integer > Space
Definition: KhalimskySpaceND.h:410
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::findZeros
static std::vector< int > findZeros(RealPoint const &p)
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:330
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::myVerbose
bool myVerbose
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:291
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::probingFrameFromSurfel
ProbingFrame probingFrameFromSurfel(Surfel const &aSurfel) const
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::ProbingFactory
std::function< InternalProbingAlgorithm *(const ProbingFrame &, Predicate const &)> ProbingFactory
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:115
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::myPreEstimationEstimator
PreEstimation myPreEstimationEstimator
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:288
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::eval
Quantity eval(SurfelConstIterator it)
DGtal::DigitalSurfacePredicate< Surface >
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::InternalProbingAlgorithm
TInternalProbingAlgorithm InternalProbingAlgorithm
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:77
DGtal::MaximalSegmentSliceEstimation< Surface >
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::myProbingAlgorithm
InternalProbingAlgorithm * myProbingAlgorithm
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:284
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::ProbingFrame::b1
Point b1
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:88
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::Surface
TSurface Surface
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:76
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::isValid
bool isValid() const
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::KSpace
typename Surface::KSpace KSpace
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:124
DGtal::SpaceND::RealPoint
PointVector< dim, double > RealPoint
Definition: SpaceND.h:117
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::Space
typename KSpace::Space Space
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:127
DGtal::DigitalSurface::Surfel
DigitalSurfaceContainer::Surfel Surfel
Definition: DigitalSurface.h:162
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::Surfel
typename Surface::Surfel Surfel
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:120
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::h
Scalar h() const
DGtal::DigitalSurface::KSpace
DigitalSurfaceContainer::KSpace KSpace
Definition: DigitalSurface.h:159
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::setParams
void setParams(ProbingFactory const &aProbingFactory, std::unordered_map< Surfel, RealPoint > const &aPreEstimations={}, bool aVerbose=false)
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::mySurface
CountedConstPtrOrConstPtr< Surface > mySurface
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:286
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::Quantity
typename InternalProbingAlgorithm::Quantity Quantity
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:121
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::ProbingFrame::normal
Point normal
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:90
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::selfDisplay
void selfDisplay(std::ostream &out) const
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::myPreEstimations
std::unordered_map< Surfel, RealPoint > myPreEstimations
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:290
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::signComponent
static int signComponent(double x)
Definition: PlaneProbingDigitalSurfaceLocalEstimator.h:321
DGtal::PlaneProbingDigitalSurfaceLocalEstimator::init
void init(Scalar const &h, SurfelConstIterator itb, SurfelConstIterator ite)