DGtal  1.1.0
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;
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:
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)
DGtal::ChordNaivePlaneComputer
Aim: A class that contains the chord-based algorithm for recognizing pieces of digital planes of give...
Definition: ChordNaivePlaneComputer.h:158
DGtal::ChordNaivePlaneComputer::computeMinMax
void computeMinMax(State &state, TInputIterator itB, TInputIterator itE) const
DGtal::ChordNaivePlaneComputer::axisWidth
std::pair< InternalScalar, InternalScalar > axisWidth(State &state, TInputIterator itB, TInputIterator itE) const
DGtal::ChordNaivePlaneComputer::max_size
Size max_size() const
DGtal::ChordNaivePlaneComputer::InputPointSet
std::set< InputPoint > InputPointSet
Definition: ChordNaivePlaneComputer.h:175
DGtal::ChordNaivePlaneComputer::State::C
InputPoint C
Definition: ChordNaivePlaneComputer.h:200
DGtal::ChordNaivePlaneComputer::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CSignedNumber< TInternalScalar >))
DGtal::concepts::CSpace
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:106
DGtal::ChordNaivePlaneComputer::value_type
InputPointSet::value_type value_type
Definition: ChordNaivePlaneComputer.h:187
DGtal::ChordNaivePlaneComputer::isExtendable
bool isExtendable(const InputPoint &p) const
max
int max(int a, int b)
Definition: testArithmeticalDSS.cpp:1108
DGtal::ChordNaivePlaneComputer::computeHeight
void computeHeight(State &state) const
DGtal::ChordNaivePlaneComputer::Component
InputVector::Component Component
Definition: ChordNaivePlaneComputer.h:171
DGtal::ChordNaivePlaneComputer::size_type
InputPointSet::size_type size_type
Definition: ChordNaivePlaneComputer.h:189
DGtal::NumberTraits
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:533
DGtal::ChordNaivePlaneComputer::operator()
bool operator()(const Point &p) const
DGtal::ChordNaivePlaneComputer::ChordNaivePlaneComputer
ChordNaivePlaneComputer(const ChordNaivePlaneComputer &other)
DGtal::ChordNaivePlaneComputer::myPointSet
InputPointSet myPointSet
Definition: ChordNaivePlaneComputer.h:536
DGtal::ChordNaivePlaneComputer::BOOST_STATIC_ASSERT
BOOST_STATIC_ASSERT((TSpace::dimension==3))
DGtal::ChordNaivePlaneComputer::myWidth0
InternalScalar myWidth0
Definition: ChordNaivePlaneComputer.h:534
DGtal::ChordNaivePlaneComputer::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
DGtal::ChordNaivePlaneComputer::init
void init(Dimension axis, InternalScalar widthNumerator=NumberTraits< InternalScalar >::ONE, InternalScalar widthDenominator=NumberTraits< InternalScalar >::ONE)
DGtal::ChordNaivePlaneComputer::satisfies
bool satisfies(State &state, TInputIterator itB, TInputIterator itE) const
DGtal::ChordNaivePlaneComputer::InternalScalar
TInternalScalar InternalScalar
Definition: ChordNaivePlaneComputer.h:169
DGtal::ChordNaivePlaneComputer::end
ConstIterator end() const
DGtal::ChordNaivePlaneComputer::State::nbValid
unsigned int nbValid
Definition: ChordNaivePlaneComputer.h:206
DGtal::Dimension
DGtal::uint32_t Dimension
Definition: Common.h:133
DGtal::ChordNaivePlaneComputer::internalCross
static void internalCross(InternalVector &n, const TVector1 &u, const TVector2 &v)
DGtal::ChordNaivePlaneComputer::const_reference
InputPointSet::const_reference const_reference
Definition: ChordNaivePlaneComputer.h:186
DGtal::ChordNaivePlaneComputer::Space
TSpace Space
Definition: ChordNaivePlaneComputer.h:167
DGtal::ChordNaivePlaneComputer::State::ptMax
InputPoint ptMax
Definition: ChordNaivePlaneComputer.h:202
DGtal::ChordNaivePlaneComputer::maximalPoint
const InputPoint & maximalPoint() const
DGtal::ChordNaivePlaneComputer::axisWidth
std::pair< InternalScalar, InternalScalar > axisWidth(TInputIterator itB, TInputIterator itE) const
DGtal::ChordNaivePlaneComputer::newCurrentTriangle
bool newCurrentTriangle(State &state, const InputPoint &M) const
DGtal::ChordNaivePlaneComputer::isValid
bool isValid() const
DGtal::ChordNaivePlaneComputer::setUpNormal
void setUpNormal(State &state) const
DGtal::ChordNaivePlaneComputer::signDelta
int signDelta(const InputPoint &A, const InputPoint &C) const
DGtal::concepts::CSignedNumber
Aim: Concept checking for Signed Numbers. Models of this concept should be listed in NumberTraits cla...
Definition: CSignedNumber.h:98
DGtal::ChordNaivePlaneComputer::checkPlaneWidth
bool checkPlaneWidth(const State &state) const
DGtal::ChordNaivePlaneComputer::setUpNormal3
void setUpNormal3(State &state) const
DGtal::ChordNaivePlaneComputer::z
Dimension z
Definition: ChordNaivePlaneComputer.h:532
DGtal::ChordNaivePlaneComputer::setUp1
bool setUp1(const InputPoint &p1)
DGtal::ChordNaivePlaneComputer::satisfies
bool satisfies(TInputIterator itB, TInputIterator itE) const
DGtal::ChordNaivePlaneComputer::isExtendable
bool isExtendable(TInputIterator itB, TInputIterator itE) const
DGtal::ChordNaivePlaneComputer::State::A
InputPoint A
Definition: ChordNaivePlaneComputer.h:200
DGtal::ChordNaivePlaneComputer::ConstIterator
InputPointSet::const_iterator ConstIterator
Definition: ChordNaivePlaneComputer.h:177
DGtal::ChordNaivePlaneComputer::State::ptMin
InputPoint ptMin
Definition: ChordNaivePlaneComputer.h:203
DGtal::ChordNaivePlaneComputer::extendAsIs
bool extendAsIs(const InputPoint &p)
DGtal::ChordNaivePlaneComputer::begin
ConstIterator begin() const
DGtal::ChordNaivePlaneComputer::exactNormal
const InternalVector & exactNormal() const
DGtal::ChordNaivePlaneComputer::InternalVector
PointVector< 3, InternalScalar > InternalVector
Definition: ChordNaivePlaneComputer.h:173
DGtal::ChordNaivePlaneComputer::y
Dimension y
Definition: ChordNaivePlaneComputer.h:533
DGtal::ChordNaivePlaneComputer::_d
InternalScalar _d
Definition: ChordNaivePlaneComputer.h:539
DGtal::ChordNaivePlaneComputer::x
Dimension x
Definition: ChordNaivePlaneComputer.h:533
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::ChordNaivePlaneComputer::myState
State myState
Definition: ChordNaivePlaneComputer.h:537
DGtal::ChordNaivePlaneComputer::_state
State _state
Definition: ChordNaivePlaneComputer.h:538
DGtal::ChordNaivePlaneComputer::minimalPoint
const InputPoint & minimalPoint() const
DGtal::ChordNaivePlaneComputer::InputVector
InputPoint InputVector
Definition: ChordNaivePlaneComputer.h:170
DGtal::ChordNaivePlaneComputer::extend
bool extend(TInputIterator itB, TInputIterator itE)
DGtal::ChordNaivePlaneComputer::setUpNormal2
void setUpNormal2(State &state) const
DGtal::ChordNaivePlaneComputer::State::B
InputPoint B
Definition: ChordNaivePlaneComputer.h:200
DGtal::ChordNaivePlaneComputer::internalDot
static InternalScalar internalDot(const TVector1 &u, const TVector2 &v)
DGtal::ChordNaivePlaneComputer::Point
Space::Point Point
Definition: ChordNaivePlaneComputer.h:179
DGtal::ChordNaivePlaneComputer::signDelta
int signDelta(const InputPoint &A, const InputPoint &B, const InputPoint &C) const
DGtal::ChordNaivePlaneComputer::getUnitNormal
void getUnitNormal(Vector3D &normal) const
DGtal::ChordNaivePlaneComputer::State
Definition: ChordNaivePlaneComputer.h:198
DGtal::ChordNaivePlaneComputer::const_iterator
InputPointSet::const_iterator const_iterator
Definition: ChordNaivePlaneComputer.h:184
DGtal::ChordNaivePlaneComputer::State::height
InternalScalar height
Definition: ChordNaivePlaneComputer.h:199
DGtal::ChordNaivePlaneComputer::getNormal
void getNormal(Vector3D &normal) const
DGtal::ChordNaivePlaneComputer::computeNormal
void computeNormal(State &state) const
DGtal::ChordNaivePlaneComputer::Iterator
InputPointSet::iterator Iterator
Definition: ChordNaivePlaneComputer.h:178
DGtal::ChordNaivePlaneComputer::operator=
ChordNaivePlaneComputer & operator=(const ChordNaivePlaneComputer &other)
DGtal::ChordNaivePlaneComputer::Coordinate
InputPoint::Coordinate Coordinate
Definition: ChordNaivePlaneComputer.h:172
DGtal::ChordNaivePlaneComputer::getBounds
void getBounds(double &min, double &max) const
DGtal::ChordNaivePlaneComputer::clear
void clear()
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::ChordNaivePlaneComputer::findTriangle
unsigned int findTriangle(State &state, TInputIterator itB, TInputIterator itE) const
DGtal::ChordNaivePlaneComputer::extend
bool extend(const InputPoint &p)
DGtal::ChordNaivePlaneComputer::Size
InputPointSet::size_type Size
Definition: ChordNaivePlaneComputer.h:176
DGtal::ChordNaivePlaneComputer::State::min
InternalScalar min
Definition: ChordNaivePlaneComputer.h:205
DGtal::ChordNaivePlaneComputer::InputPoint
TInputPoint InputPoint
Definition: ChordNaivePlaneComputer.h:168
DGtal::ChordNaivePlaneComputer::findMixedTriangle
unsigned int findMixedTriangle(State &state, TInputIterator1 itB1, TInputIterator1 itE1, TInputIterator2 itB2, TInputIterator2 itE2) const
DGtal::ParallelStrip
Aim: A parallel strip in the space is the intersection of two parallel half-planes such that each hal...
Definition: ParallelStrip.h:91
DGtal::ChordNaivePlaneComputer::setUpNormal1
void setUpNormal1(State &state) const
DGtal::ChordNaivePlaneComputer::computeAxisWidth
static std::pair< InternalScalar, InternalScalar > computeAxisWidth(Dimension axis, TInputIterator itB, TInputIterator itE)
DGtal::ChordNaivePlaneComputer::ChordNaivePlaneComputer
ChordNaivePlaneComputer()
DGtal::ChordNaivePlaneComputer::difference_type
InputPointSet::difference_type difference_type
Definition: ChordNaivePlaneComputer.h:188
DGtal::PointVector< 3, InternalScalar >
DGtal::ChordNaivePlaneComputer::myWidth1
InternalScalar myWidth1
Definition: ChordNaivePlaneComputer.h:535
DGtal::ChordNaivePlaneComputer::BOOST_STATIC_ASSERT
BOOST_STATIC_ASSERT((TInputPoint::dimension==3))
DGtal::ChordNaivePlaneComputer::const_pointer
InputPointSet::const_pointer const_pointer
Definition: ChordNaivePlaneComputer.h:185
DGtal::ChordNaivePlaneComputer::size
Size size() const
DGtal::ChordNaivePlaneComputer::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::ChordNaivePlaneComputer::alignedAlongAxis
bool alignedAlongAxis(const InputPoint &p1, const InputPoint &p2) const
DGtal::ChordNaivePlaneComputer::State::N
InternalVector N
Definition: ChordNaivePlaneComputer.h:201
DGtal::ChordNaivePlaneComputer::~ChordNaivePlaneComputer
~ChordNaivePlaneComputer()
DGtal::ChordNaivePlaneComputer::findTriangle2
unsigned int findTriangle2(State &state, TInputIterator itB, TInputIterator itE) const
DGtal::ChordNaivePlaneComputer::empty
bool empty() const
DGtal::ChordNaivePlaneComputer::findTriangle1
unsigned int findTriangle1(State &state, TInputIterator itB, TInputIterator itE) const
DGtal::ChordNaivePlaneComputer::checkWidth
bool checkWidth(const State &state) const
DGtal::ChordNaivePlaneComputer::updateMinMax
bool updateMinMax(State &state, TInputIterator itB, TInputIterator itE) const
DGtal::ChordNaivePlaneComputer::selfDisplay
void selfDisplay(std::ostream &out, const State &state) const
DGtal::ChordNaivePlaneComputer::State::max
InternalScalar max
Definition: ChordNaivePlaneComputer.h:204
DGtal::ChordNaivePlaneComputer::Primitive
ParallelStrip< Space, true, true > Primitive
Definition: ChordNaivePlaneComputer.h:180
DGtal::ChordNaivePlaneComputer::maxSize
Size maxSize() const
DGtal::ChordNaivePlaneComputer::primitive
Primitive primitive() const