DGtal  1.5.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)
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 
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&
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)
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)
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)
std::pair< bool, ProbingFrame > probingFrameWithPreEstimation(ProbingFrame const &aInitialFrame, RealPoint const &aPreEstimation) const
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
Z3i::SCell SCell
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
Aim: The digital surface container concept describes a minimal set of inner types and methods so as t...
MyPointD Point
Definition: testClone2.cpp:383
KSpace::Cell Cell
PointVector< 3, double > RealPoint