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 >
113  {
115 
116  // ----------------------- Public types ------------------------------
117  public:
118  using Permutation = std::array<int, 3>;
119 
120  public:
124  PointOnProbingRay () = default;
125 
132  PointOnProbingRay (Permutation const& aSigma, Integer const& aIndex = Integer(0));
133 
138 
142  Permutation const& sigma () const;
143 
148  int sigma (int aIndex) const;
149 
153  Integer const& index () const;
154 
162  template < typename Point >
163  Point relativePoint (std::array<Point, 3> const& aM) const {
164  return -aM[mySigma[0]] + aM[mySigma[1]] + aM[mySigma[2]] * myIndex;
165  }
166 
174  bool operator== (PointOnProbingRay const& aRay) const;
175 
182  bool operator!= (PointOnProbingRay const& aRay) const;
183 
193  bool operator<= (PointOnProbingRay const& aRay) const;
194 
199  PointOnProbingRay next (Integer const& aInc) const;
200 
205  PointOnProbingRay previous (Integer const& aDec) const;
206 
207  private:
210  }; // end of class PointOnProbingRay
211 
219  template < typename Integer >
220  std::ostream& operator<< (std::ostream& aOs, PointOnProbingRay<Integer> const& aRay);
221 
223  // template class GridPoint
239  template < typename Integer = int >
240  class GridPoint
241  {
243 
244  public:
245 
249  GridPoint () = default;
250 
258  GridPoint (std::pair<Integer,Integer> const& aDir, int aK ) : myDir(aDir), myK(aK) {}
259 
268  GridPoint (Integer aX, Integer aY, int aK ) : myDir(std::make_pair(aX,aY)), myK(aK) {}
269 
277  std::pair<Integer,Integer> direction() const {
278  return myDir;
279  }
280 
286  int k() const {
287  return myK;
288  }
289 
298  template < typename Vector >
299  Vector directionVector (std::array<Vector, 3> const& aM) const {
300  return aM[(myK+1)%3]*myDir.first + aM[(myK+2)%3]*myDir.second;
301  }
302 
310  template < typename Point >
311  Point relativePoint (std::array<Point, 3> const& aM) const {
312  return -aM[myK] + directionVector(aM);
313  }
314 
322  bool operator== (GridPoint const& other) const {
323  return (myDir == other.myDir) && (myK == other.myK);
324  }
325 
332  bool operator!= (GridPoint const& other) const {
333  return !(*this == other);
334  }
335 
342  GridPoint getOnSameGrid(const std::pair<Integer,Integer>& aDir) const {
343  return GridPoint(aDir,myK);
344  }
345 
352  GridPoint operator+(const GridPoint & other) const {
353  ASSERT(myK == other.myK);
354  std::pair<Integer,Integer> d = std::make_pair(myDir.first+other.myDir.first,
355  myDir.second+other.myDir.second);
356  return getOnSameGrid(d);
357  }
358 
365  GridPoint operator*(Integer aValue) const {
366  std::pair<Integer,Integer> d = std::make_pair(myDir.first*aValue,
367  myDir.second*aValue);
368  return getOnSameGrid(d);
369  }
370 
378  bool isValid() const {
379  if ( (myDir.first != 0) || (myDir.second != 0) ) { //not both null
380  return ( (myDir.first >= 0) && (myDir.second >= 0)
381  && (myK >= 0) && (myK <= 2)
382  );
383  } else {
384  return false;
385  }
386  }
387 
388  private:
389 
390  std::pair<Integer,Integer> myDir;
391  int myK;
393  }; //end of class GridPoint
394 
402  template < typename Integer >
403  std::ostream& operator<< (std::ostream& aOs, GridPoint<Integer> const& aGridPoint) {
404  aOs << "GridPoint[k=" << aGridPoint.k()
405  << ", a=" << aGridPoint.direction().first
406  << ", b=" << aGridPoint.direction().second
407  << "]";
408  return aOs;
409  }
410 
412  // template class GridPointOnProbingRay
424  template < typename Integer = int >
426  {
428 
429  public:
433  GridPointOnProbingRay () = default;
434 
443  const std::pair<Integer,Integer>& aDirection,
444  const Integer& aIdx = 0)
445  : myOrigin(aGridPoint), myDirection(aDirection), myIdx(aIdx) {}
446 
455  bool operator== (GridPointOnProbingRay const& other) const {
456  return ( (myOrigin == other.myOrigin) &&
457  (myDirection == other.myDirection) &&
458  (myIdx == other.myIdx) );
459  }
460 
467  bool operator!= (GridPointOnProbingRay const& other) const {
468  return !(*this == other);
469  }
470 
479  GridPointOnProbingRay next(const Integer& aInc) const {
481  }
482 
493  }
494 
498  Integer index() const {
499  return myIdx;
500  }
501 
507  }
508 
516  template < typename Point >
517  Point relativePoint (std::array<Point, 3> const& aM) const {
518  return gridPoint().relativePoint(aM);
519  }
520 
521 
522  private:
524  std::pair<Integer, Integer> myDirection;
527  }; //end of class GridPointOnProbingRay
528 
529  } // namespace detail
530 } // namespace DGtal
531 
533 // Includes inline functions.
534 #include "DGtal/geometry/helpers/PlaneProbingEstimatorHelper.ih"
535 
536 // //
538 
539 #endif // !defined PlaneProbingEstimatorHelper_h
540 
541 #undef PlaneProbingEstimatorHelper_RECURSES
542 #endif // else defined(PlaneProbingEstimatorHelper_RECURSES)
Aim: Represents a grid point along a discrete ray defined on a grid.
Point relativePoint(std::array< Point, 3 > const &aM) const
GridPointOnProbingRay next(const Integer &aInc) const
GridPointOnProbingRay(const GridPoint< Integer > &aGridPoint, const std::pair< Integer, Integer > &aDirection, const Integer &aIdx=0)
BOOST_CONCEPT_ASSERT((concepts::CInteger< Integer >))
bool operator!=(GridPointOnProbingRay const &other) const
bool operator==(GridPointOnProbingRay const &other) const
GridPointOnProbingRay previous(const Integer &aDec) const
A grid point consists of a couple of nonnegative coordinates and an integer index that determines a...
bool operator==(GridPoint const &other) const
BOOST_CONCEPT_ASSERT((concepts::CInteger< Integer >))
Point relativePoint(std::array< Point, 3 > const &aM) const
GridPoint operator*(Integer aValue) const
GridPoint operator+(const GridPoint &other) const
Vector directionVector(std::array< Vector, 3 > const &aM) const
std::pair< Integer, Integer > myDir
GridPoint(std::pair< Integer, Integer > const &aDir, int aK)
GridPoint getOnSameGrid(const std::pair< Integer, Integer > &aDir) const
GridPoint(Integer aX, Integer aY, int aK)
std::pair< Integer, Integer > direction() const
bool operator!=(GridPoint const &other) const
A ray consists of a permutation and an integer index (position on the ray). For a triplet of vector...
bool operator<=(PointOnProbingRay const &aRay) const
PointOnProbingRay next(Integer const &aInc) const
PointOnProbingRay previous(Integer const &aDec) const
PointOnProbingRay getBase() const
BOOST_CONCEPT_ASSERT((concepts::CInteger< Integer >))
int sigma(int aIndex) const
Integer const & index() const
Point relativePoint(std::array< Point, 3 > const &aM) const
bool operator!=(PointOnProbingRay const &aRay) const
bool operator==(PointOnProbingRay const &aRay) const
PointOnProbingRay(Permutation const &aSigma, Integer const &aIndex=Integer(0))
Permutation const & sigma() const
DigitalPlane::Point Vector
std::ostream & operator<<(std::ostream &aOs, PointOnProbingRay< Integer > 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)