DGtal  1.5.beta
PlaneProbingEstimatorHelper.h
1 
17 #pragma once
18 
36 #if defined(PlaneProbingEstimatorHelper_RECURSES)
37 #error Recursive header files inclusion detected in PlaneProbingEstimatorHelper.h
38 #else // defined(PlaneProbingEstimatorHelper_RECURSES)
40 #define PlaneProbingEstimatorHelper_RECURSES
41 
42 #if !defined PlaneProbingEstimatorHelper_h
44 #define PlaneProbingEstimatorHelper_h
45 
47 // Inclusions
48 #include <array>
49 #include <cassert>
50 #include "DGtal/math/linalg/SimpleMatrix.h"
51 #include "DGtal/base/Common.h"
52 #include "DGtal/kernel/CInteger.h"
54 
55 namespace DGtal
56 {
57  namespace detail
58  {
65  template < typename Point >
66  typename Point::Coordinate squaredNorm (Point const& aPoint);
67 
74  template < int N, typename T >
75  T determinant (const T aMatrix[N][N]);
76 
83  template < typename Point >
84  inline
85  typename Point::Coordinate distToSphere (std::array<Point, 5> const& aPoints);
86 
94  template < typename Point >
95  inline
96  bool isBasisReduced (Point const& aU, Point const& aV);
97 
99  // template class PointOnProbingRay
111  template < typename Integer = int, typename Index = std::size_t >
113  {
115 
116  // ----------------------- Public types ------------------------------
117  public:
118  using Permutation = std::array<Index, 3>;
119 
120  public:
124  PointOnProbingRay () = default;
125 
132  PointOnProbingRay (Permutation const& aSigma, Integer const& aInt = Integer(0));
133 
138 
142  Permutation const& sigma () const;
143 
148  Index sigma (Index const& aIndex) const;
149 
153  Integer const& position () const;
154 
162  template < typename Point >
163  Point relativePoint (std::array<Point, 3> const& aM) const;
164 
172  bool operator== (PointOnProbingRay const& aRay) const;
173 
180  bool operator!= (PointOnProbingRay const& aRay) const;
181 
191  bool operator<= (PointOnProbingRay const& aRay) const;
192 
197  PointOnProbingRay next (Integer const& aInc) const;
198 
203  PointOnProbingRay previous (Integer const& aDec) const;
204 
205  private:
208  }; // end of class PointOnProbingRay
209 
217  template < typename Integer, typename Index >
218  std::ostream& operator<< (std::ostream& aOs, PointOnProbingRay<Integer,Index> const& aRay);
219 
221  // template class GridPoint
237  template < typename Integer = int, typename Index = std::size_t >
238  class GridPoint
239  {
241 
242  public:
243 
247  GridPoint () = default;
248 
256  GridPoint (std::pair<Integer,Integer> const& aDir, Index const& aK ) : myDir(aDir), myK(aK) {}
257 
266  GridPoint (Integer const& aX, Integer const& aY, Index const& aK ) : myDir(std::make_pair(aX,aY)), myK(aK) {}
267 
275  std::pair<Integer,Integer> direction() const {
276  return myDir;
277  }
278 
284  Index k() const {
285  return myK;
286  }
287 
296  template < typename Vector >
297  Vector directionVector (std::array<Vector, 3> const& aM) const {
298  return aM[(myK+1)%3]*myDir.first + aM[(myK+2)%3]*myDir.second;
299  }
300 
308  template < typename Point >
309  Point relativePoint (std::array<Point, 3> const& aM) const {
310  return -aM[myK] + directionVector(aM);
311  }
312 
320  bool operator== (GridPoint const& other) const {
321  return (myDir == other.myDir) && (myK == other.myK);
322  }
323 
330  bool operator!= (GridPoint const& other) const {
331  return !(*this == other);
332  }
333 
340  GridPoint getOnSameGrid(const std::pair<Integer,Integer>& aDir) const {
341  return GridPoint(aDir,myK);
342  }
343 
350  GridPoint operator+(const GridPoint & other) const {
351  ASSERT(myK == other.myK);
352  std::pair<Integer,Integer> d = std::make_pair(myDir.first+other.myDir.first,
353  myDir.second+other.myDir.second);
354  return getOnSameGrid(d);
355  }
356 
363  GridPoint operator*(Integer aValue) const {
364  std::pair<Integer,Integer> d = std::make_pair(myDir.first*aValue,
365  myDir.second*aValue);
366  return getOnSameGrid(d);
367  }
368 
376  bool isValid() const {
377  if ( (myDir.first != 0) || (myDir.second != 0) ) { //not both null
378  return ( (myDir.first >= 0) && (myDir.second >= 0)
379  && (myK >= 0) && (myK <= 2)
380  );
381  } else {
382  return false;
383  }
384  }
385 
386  private:
387 
388  std::pair<Integer,Integer> myDir;
391  }; //end of class GridPoint
392 
400  template < typename Integer, typename Index >
401  std::ostream& operator<< (std::ostream& aOs, GridPoint<Integer,Index> const& aGridPoint) {
402  aOs << "GridPoint[k=" << aGridPoint.k()
403  << ", a=" << aGridPoint.direction().first
404  << ", b=" << aGridPoint.direction().second
405  << "]";
406  return aOs;
407  }
408 
410  // template class GridPointOnProbingRay
422  template < typename Integer = int, typename Index = std::size_t >
424  {
426 
427  public:
431  GridPointOnProbingRay () = default;
432 
441  const std::pair<Integer,Integer>& aDirection,
442  const Integer& aIdx = 0)
443  : myOrigin(aGridPoint), myDirection(aDirection), myIdx(aIdx) {}
444 
453  bool operator== (GridPointOnProbingRay const& other) const {
454  return ( (myOrigin == other.myOrigin) &&
455  (myDirection == other.myDirection) &&
456  (myIdx == other.myIdx) );
457  }
458 
465  bool operator!= (GridPointOnProbingRay const& other) const {
466  return !(*this == other);
467  }
468 
477  GridPointOnProbingRay next(const Integer& aInc) const {
479  }
480 
491  }
492 
496  Integer index() const {
497  return myIdx;
498  }
499 
505  }
506 
514  template < typename Point >
515  Point relativePoint (std::array<Point, 3> const& aM) const {
516  return gridPoint().relativePoint(aM);
517  }
518 
519 
520  private:
522  std::pair<Integer, Integer> myDirection;
525  }; //end of class GridPointOnProbingRay
526 
527  } // namespace detail
528 } // namespace DGtal
529 
531 // Includes inline functions.
532 #include "DGtal/geometry/helpers/PlaneProbingEstimatorHelper.ih"
533 
534 // //
536 
537 #endif // !defined PlaneProbingEstimatorHelper_h
538 
539 #undef PlaneProbingEstimatorHelper_RECURSES
540 #endif // else defined(PlaneProbingEstimatorHelper_RECURSES)
Aim: Represents a grid point along a discrete ray defined on a grid.
GridPointOnProbingRay next(const Integer &aInc) const
bool operator==(GridPointOnProbingRay const &other) const
GridPointOnProbingRay previous(const Integer &aDec) const
GridPoint< Integer, Index > gridPoint() const
BOOST_CONCEPT_ASSERT((concepts::CInteger< Integer >))
GridPointOnProbingRay(const GridPoint< Integer, Index > &aGridPoint, const std::pair< Integer, Integer > &aDirection, const Integer &aIdx=0)
bool operator!=(GridPointOnProbingRay const &other) const
Point relativePoint(std::array< Point, 3 > const &aM) const
A grid point consists of a couple of nonnegative coordinates and an integer index that determines a...
Vector directionVector(std::array< Vector, 3 > const &aM) const
GridPoint(std::pair< Integer, Integer > const &aDir, Index const &aK)
GridPoint(Integer const &aX, Integer const &aY, Index const &aK)
bool operator==(GridPoint const &other) const
std::pair< Integer, Integer > direction() const
bool operator!=(GridPoint const &other) const
Point relativePoint(std::array< Point, 3 > const &aM) const
GridPoint operator+(const GridPoint &other) const
std::pair< Integer, Integer > myDir
GridPoint operator*(Integer aValue) const
GridPoint getOnSameGrid(const std::pair< Integer, Integer > &aDir) const
BOOST_CONCEPT_ASSERT((concepts::CInteger< Integer >))
A ray consists of a permutation and an integer index (position on the ray). For a triplet of vector...
PointOnProbingRay next(Integer const &aInc) const
PointOnProbingRay getBase() const
Integer const & position() const
Permutation const & sigma() const
Point relativePoint(std::array< Point, 3 > const &aM) const
Index sigma(Index const &aIndex) const
BOOST_CONCEPT_ASSERT((concepts::CInteger< Integer >))
PointOnProbingRay previous(Integer const &aDec) const
bool operator!=(PointOnProbingRay const &aRay) const
bool operator==(PointOnProbingRay const &aRay) const
bool operator<=(PointOnProbingRay const &aRay) const
PointOnProbingRay(Permutation const &aSigma, Integer const &aInt=Integer(0))
DigitalPlane::Point Vector
SMesh::Index Index
std::ostream & operator<<(std::ostream &aOs, PointOnProbingRay< Integer, Index > const &aRay)
T determinant(const T aMatrix[N][N])
Point::Coordinate squaredNorm(Point const &aPoint)
bool isBasisReduced(Point const &aU, Point const &aV)
Point::Coordinate distToSphere(std::array< Point, 5 > const &aPoints)
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:88
MyPointD Point
Definition: testClone2.cpp:383
const Point aPoint(3, 4)