DGtal  0.9.2
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)
37 
38 #define ChordNaivePlaneComputer_RECURSES
39 
40 #if !defined ChordNaivePlaneComputer_h
41 
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;
170  typedef InputPoint InputVector;
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 {
199  InternalScalar height;
200  InputPoint A,B,C;
201  InternalVector N;
202  InputPoint ptMax;
203  InputPoint ptMin;
204  InternalScalar max;
205  InternalScalar min;
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,
259  InternalScalar widthNumerator = NumberTraits< InternalScalar >::ONE,
260  InternalScalar widthDenominator = NumberTraits< InternalScalar >::ONE );
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 
294  ConstIterator begin() const;
295 
299  ConstIterator end() const;
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 
442  Primitive primitive() const;
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:
534  InternalScalar myWidth0;
535  InternalScalar myWidth1;
536  mutable InputPointSet myPointSet;
537  State myState;
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)
void setUpNormal1(State &state) const
InputPointSet::value_type value_type
void computeHeight(State &state) const
bool checkPlaneWidth(const State &state) const
unsigned int findTriangle2(State &state, TInputIterator itB, TInputIterator itE) const
bool setUp1(const InputPoint &p1)
DGtal::uint32_t Dimension
Definition: Common.h:113
bool updateMinMax(State &state, TInputIterator itB, TInputIterator itE) const
Aim: A class that contains the chord-based algorithm for recognizing pieces of digital planes of give...
const InputPoint & maximalPoint() const
ConstIterator end() const
Aim: A parallel strip in the space is the intersection of two parallel half-planes such that each hal...
Definition: ParallelStrip.h:90
std::pair< InternalScalar, InternalScalar > axisWidth(TInputIterator itB, TInputIterator itE) const
void setUpNormal2(State &state) const
PointVector< 3, InternalScalar > InternalVector
const InternalVector & exactNormal() const
bool newCurrentTriangle(State &state, const InputPoint &M) const
ChordNaivePlaneComputer & operator=(const ChordNaivePlaneComputer &other)
static InternalScalar internalDot(const TVector1 &u, const TVector2 &v)
int signDelta(const InputPoint &A, const InputPoint &B, const InputPoint &C) const
void setUpNormal(State &state) const
Primitive primitive() const
bool satisfies(TInputIterator itB, TInputIterator itE) const
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines...
Definition: CSpace.h:105
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:69
bool isExtendable(const InputPoint &p) const
BOOST_STATIC_ASSERT((TSpace::dimension==3))
void selfDisplay(std::ostream &out) const
unsigned int findMixedTriangle(State &state, TInputIterator1 itB1, TInputIterator1 itE1, TInputIterator2 itB2, TInputIterator2 itE2) const
static std::pair< InternalScalar, InternalScalar > computeAxisWidth(Dimension axis, TInputIterator itB, TInputIterator itE)
void getBounds(double &min, double &max) const
Aim: Concept checking for Signed Numbers. Models of this concept should be listed in NumberTraits cla...
Definition: CSignedNumber.h:97
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
bool operator()(const Point &p) const
unsigned int findTriangle(State &state, TInputIterator itB, TInputIterator itE) const
DGtal is the top-level namespace which contains all DGtal functions and types.
unsigned int findTriangle1(State &state, TInputIterator itB, TInputIterator itE) const
bool extend(const InputPoint &p)
void init(Dimension axis, InternalScalar widthNumerator=NumberTraits< InternalScalar >::ONE, InternalScalar widthDenominator=NumberTraits< InternalScalar >::ONE)
ParallelStrip< Space, true, true > Primitive
InputPointSet::difference_type difference_type
static void internalCross(InternalVector &n, const TVector1 &u, const TVector2 &v)
void computeMinMax(State &state, TInputIterator itB, TInputIterator itE) const
bool checkWidth(const State &state) const
const InputPoint & minimalPoint() const
void getUnitNormal(Vector3D &normal) const
InputPointSet::const_iterator ConstIterator
InputPointSet::const_reference const_reference
InputPointSet::const_pointer const_pointer
bool alignedAlongAxis(const InputPoint &p1, const InputPoint &p2) const
void computeNormal(State &state) const
ConstIterator begin() const
void getNormal(Vector3D &normal) const
void setUpNormal3(State &state) const
bool extendAsIs(const InputPoint &p)
InputPointSet::const_iterator const_iterator