DGtal  1.5.beta
ChordNaivePlaneComputer.h
1 
17 #pragma once
18 
34 #if defined(ChordNaivePlaneComputer_RECURSES)
35 #error Recursive header files inclusion detected in ChordNaivePlaneComputer.h
36 #else // defined(ChordNaivePlaneComputer_RECURSES)
38 #define ChordNaivePlaneComputer_RECURSES
39 
40 #if !defined ChordNaivePlaneComputer_h
42 #define ChordNaivePlaneComputer_h
43 
45 // Inclusions
46 #include <iostream>
47 #include <set>
48 #include "DGtal/base/Common.h"
49 #include "DGtal/kernel/CSignedNumber.h"
50 #include "DGtal/kernel/CSpace.h"
51 #include "DGtal/geometry/surfaces/ParallelStrip.h"
53 
54 namespace DGtal
55 {
56 
58  // template class ChordNaivePlaneComputer
154  template < typename TSpace,
155  typename TInputPoint,
156  typename TInternalScalar >
158  {
159 
162  BOOST_STATIC_ASSERT(( TSpace::dimension == 3 ));
163  BOOST_STATIC_ASSERT(( TInputPoint::dimension == 3 ));
164 
165  // ----------------------- public types ------------------------------
166  public:
167  typedef TSpace Space;
168  typedef TInputPoint InputPoint;
169  typedef TInternalScalar InternalScalar;
171  typedef typename InputVector::Component Component;
172  typedef typename InputPoint::Coordinate Coordinate;
174 
175  typedef std::set< InputPoint > InputPointSet;
176  typedef typename InputPointSet::size_type Size;
177  typedef typename InputPointSet::const_iterator ConstIterator;
178  typedef typename InputPointSet::iterator Iterator;
179  typedef typename Space::Point Point;
181 
182  // ----------------------- std public types ------------------------------
183  public:
184  typedef typename InputPointSet::const_iterator const_iterator;
185  typedef typename InputPointSet::const_pointer const_pointer;
186  typedef typename InputPointSet::const_reference const_reference;
187  typedef typename InputPointSet::value_type value_type;
188  typedef typename InputPointSet::difference_type difference_type;
189  typedef typename InputPointSet::size_type size_type;
190 
191  // ----------------------- internal types ------------------------------
192  private:
198  struct State {
206  unsigned int nbValid;
207  };
208 
209  // ----------------------- Standard services ------------------------------
210  public:
211 
216 
222 
228 
235 
240  void clear();
241 
258  void init( Dimension axis,
261 
272  template <typename TInputIterator>
273  static
274  std::pair<InternalScalar, InternalScalar>
275  computeAxisWidth( Dimension axis, TInputIterator itB, TInputIterator itE );
276 
277 
278  //-------------------- model of ForwardContainer -----------------------------
279  public:
280 
284  Size size() const;
285 
289  bool empty() const;
290 
295 
300 
306  Size max_size() const;
307 
312  Size maxSize() const;
313 
314 
315  //-------------------- model of concepts::CPointPredicate -----------------------------
316  public:
317 
327  bool operator()( const Point & p ) const;
328 
329  //-------------------- model of CIncrementalPrimitiveComputer -----------------------------
330  public:
331 
341  bool extendAsIs( const InputPoint & p );
342 
353  bool extend( const InputPoint & p );
354 
365  bool isExtendable( const InputPoint & p ) const;
366 
367  //-------------------- model of CAdditivePrimitiveComputer -----------------------------
368  public:
369 
383  template <typename TInputIterator>
384  bool extend( TInputIterator itB, TInputIterator itE );
385 
400  template <typename TInputIterator>
401  bool isExtendable( TInputIterator itB, TInputIterator itE ) const;
402 
412  template <typename TInputIterator>
413  bool
414  satisfies( TInputIterator itB, TInputIterator itE ) const;
415 
425  template <typename TInputIterator>
426  std::pair<InternalScalar, InternalScalar>
427  axisWidth( TInputIterator itB, TInputIterator itE ) const;
428 
429  //-------------------- Primitive services -----------------------------
430  public:
431 
443 
444  //-------------------- Parameters services -----------------------------
445  public:
446 
453  template <typename Vector3D>
454  void getNormal( Vector3D & normal ) const;
455 
459  const InternalVector & exactNormal() const;
460 
467  template <typename Vector3D>
468  void getUnitNormal( Vector3D & normal ) const;
469 
477  void getBounds( double & min, double & max ) const;
478 
485  const InputPoint & minimalPoint() const;
486 
493  const InputPoint & maximalPoint() const;
494 
495  // ----------------------- Utilities --------------------------------------
496  public:
497 
503  template <typename TVector1, typename TVector2>
504  static InternalScalar internalDot( const TVector1 & u, const TVector2 & v );
505 
512  template <typename TVector1, typename TVector2>
513  static void internalCross( InternalVector & n, const TVector1 & u, const TVector2 & v );
514 
515  // ----------------------- Interface --------------------------------------
516  public:
517 
522  void selfDisplay ( std::ostream & out ) const;
523 
528  bool isValid() const;
529 
530  // ------------------------- Private Datas --------------------------------
531  private:
538  mutable State _state;
539  mutable InternalScalar _d;
540  // ------------------------- Hidden services ------------------------------
541  protected:
542 
543 
544  // ------------------------- Internals ------------------------------------
545  private:
546 
560  template <typename TInputIterator>
561  void computeMinMax( State & state, TInputIterator itB, TInputIterator itE ) const;
562 
580  template <typename TInputIterator>
581  bool updateMinMax( State & state, TInputIterator itB, TInputIterator itE ) const;
582 
592  bool checkPlaneWidth( const State & state ) const;
593 
598  bool setUp1( const InputPoint & p1 );
599 
606  void setUpNormal( State & state ) const;
607 
614  void setUpNormal1( State & state ) const;
615 
622  void setUpNormal2( State & state ) const;
623 
630  void setUpNormal3( State & state ) const;
631 
643  int signDelta( const InputPoint & A, const InputPoint & B, const InputPoint & C ) const;
644 
655  int signDelta( const InputPoint & A, const InputPoint & C ) const;
656 
675  bool newCurrentTriangle( State & state, const InputPoint & M ) const;
676 
699  template <typename TInputIterator>
700  unsigned int findTriangle( State & state, TInputIterator itB, TInputIterator itE ) const;
701 
702  template <typename TInputIterator>
703  unsigned int findTriangle1( State & state, TInputIterator itB, TInputIterator itE ) const;
704  template <typename TInputIterator>
705  unsigned int findTriangle2( State & state, TInputIterator itB, TInputIterator itE ) const;
706  template <typename TInputIterator1, typename TInputIterator2>
707  unsigned int findMixedTriangle( State & state,
708  TInputIterator1 itB1, TInputIterator1 itE1,
709  TInputIterator2 itB2, TInputIterator2 itE2 ) const;
710 
716  bool alignedAlongAxis( const InputPoint & p1, const InputPoint & p2 ) const;
717 
722  void computeHeight( State & state ) const;
723 
732  void computeNormal( State & state ) const;
733 
744  template <typename TInputIterator>
745  bool
746  satisfies( State & state, TInputIterator itB, TInputIterator itE ) const;
747 
748 
759  template <typename TInputIterator>
760  std::pair<InternalScalar, InternalScalar>
761  axisWidth( State & state, TInputIterator itB, TInputIterator itE ) const;
762 
763 
775  bool checkWidth( const State & state ) const;
776 
782  void selfDisplay ( std::ostream & out, const State & state ) const;
783 
784 
785  }; // end of class ChordNaivePlaneComputer
786 
787 
794  template <typename TSpace, typename TInputPoint, typename TInternalScalar>
795  std::ostream&
796  operator<< ( std::ostream & out,
798 
799 } // namespace DGtal
800 
801 
803 // Includes inline functions.
804 #include "DGtal/geometry/surfaces/ChordNaivePlaneComputer.ih"
805 
806 // //
808 
809 #endif // !defined ChordNaivePlaneComputer_h
810 
811 #undef ChordNaivePlaneComputer_RECURSES
812 #endif // else defined(ChordNaivePlaneComputer_RECURSES)
Aim: A class that contains the chord-based algorithm for recognizing pieces of digital planes of give...
bool extend(TInputIterator itB, TInputIterator itE)
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
std::pair< InternalScalar, InternalScalar > axisWidth(State &state, TInputIterator itB, TInputIterator itE) const
InputPointSet::const_iterator const_iterator
PointVector< 3, InternalScalar > InternalVector
bool extend(const InputPoint &p)
const InputPoint & maximalPoint() const
void selfDisplay(std::ostream &out) const
bool checkPlaneWidth(const State &state) const
void getBounds(double &min, double &max) const
void setUpNormal2(State &state) const
void getUnitNormal(Vector3D &normal) const
static void internalCross(InternalVector &n, const TVector1 &u, const TVector2 &v)
void computeMinMax(State &state, TInputIterator itB, TInputIterator itE) const
unsigned int findTriangle1(State &state, TInputIterator itB, TInputIterator itE) const
int signDelta(const InputPoint &A, const InputPoint &C) const
BOOST_STATIC_ASSERT((TInputPoint::dimension==3))
bool checkWidth(const State &state) const
bool newCurrentTriangle(State &state, const InputPoint &M) const
InputPointSet::const_pointer const_pointer
InputPointSet::difference_type difference_type
ParallelStrip< Space, true, true > Primitive
void setUpNormal3(State &state) const
bool satisfies(TInputIterator itB, TInputIterator itE) const
InputPointSet::const_iterator ConstIterator
const InputPoint & minimalPoint() const
InputPointSet::const_reference const_reference
static std::pair< InternalScalar, InternalScalar > computeAxisWidth(Dimension axis, TInputIterator itB, TInputIterator itE)
ConstIterator begin() const
void selfDisplay(std::ostream &out, const State &state) const
void setUpNormal(State &state) const
bool satisfies(State &state, TInputIterator itB, TInputIterator itE) const
bool extendAsIs(const InputPoint &p)
bool operator()(const Point &p) const
ChordNaivePlaneComputer & operator=(const ChordNaivePlaneComputer &other)
InputPointSet::value_type value_type
unsigned int findTriangle(State &state, TInputIterator itB, TInputIterator itE) const
void init(Dimension axis, InternalScalar widthNumerator=NumberTraits< InternalScalar >::ONE, InternalScalar widthDenominator=NumberTraits< InternalScalar >::ONE)
BOOST_STATIC_ASSERT((TSpace::dimension==3))
unsigned int findMixedTriangle(State &state, TInputIterator1 itB1, TInputIterator1 itE1, TInputIterator2 itB2, TInputIterator2 itE2) const
bool updateMinMax(State &state, TInputIterator itB, TInputIterator itE) const
void computeNormal(State &state) const
ChordNaivePlaneComputer(const ChordNaivePlaneComputer &other)
bool setUp1(const InputPoint &p1)
void computeHeight(State &state) const
ConstIterator end() const
bool isExtendable(const InputPoint &p) const
void setUpNormal1(State &state) const
bool alignedAlongAxis(const InputPoint &p1, const InputPoint &p2) const
static InternalScalar internalDot(const TVector1 &u, const TVector2 &v)
const InternalVector & exactNormal() const
int signDelta(const InputPoint &A, const InputPoint &B, const InputPoint &C) const
void getNormal(Vector3D &normal) const
BOOST_CONCEPT_ASSERT((concepts::CSignedNumber< TInternalScalar >))
bool isExtendable(TInputIterator itB, TInputIterator itE) const
std::pair< InternalScalar, InternalScalar > axisWidth(TInputIterator itB, TInputIterator itE) const
unsigned int findTriangle2(State &state, TInputIterator itB, TInputIterator itE) const
Aim: A parallel strip in the space is the intersection of two parallel half-planes such that each hal...
Definition: ParallelStrip.h:91
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::uint32_t Dimension
Definition: Common.h:136
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:564
Aim: Concept checking for Signed Numbers. Models of this concept should be listed in NumberTraits cla...
Definition: CSignedNumber.h:98
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:106
int max(int a, int b)