DGtal  0.9.2
COBANaivePlaneComputer.h
1 
17 #pragma once
18 
33 #if defined(COBANaivePlaneComputer_RECURSES)
34 #error Recursive header files inclusion detected in COBANaivePlaneComputer.h
35 #else // defined(COBANaivePlaneComputer_RECURSES)
36 
37 #define COBANaivePlaneComputer_RECURSES
38 
39 #if !defined COBANaivePlaneComputer_h
40 
41 #define COBANaivePlaneComputer_h
42 
44 // Inclusions
45 #include <iostream>
46 #include <set>
47 #include "DGtal/base/Common.h"
48 #include "DGtal/kernel/CInteger.h"
49 #include "DGtal/kernel/CSpace.h"
50 #include "DGtal/kernel/SpaceND.h"
51 #include "DGtal/kernel/PointVector.h"
52 #include "DGtal/arithmetic/IntegerComputer.h"
53 #include "DGtal/arithmetic/LatticePolytope2D.h"
54 #include "DGtal/geometry/surfaces/ParallelStrip.h"
56 
57 namespace DGtal
58 {
59 
61  // template class COBANaivePlaneComputer
127  template < typename TSpace,
128  typename TInternalInteger >
130  {
131 
134  BOOST_STATIC_ASSERT(( TSpace::dimension == 3 ));
135 
136  // ----------------------- public types ------------------------------
137  public:
138  typedef TSpace Space;
139  typedef typename Space::Point Point;
140  typedef std::set< Point > PointSet;
141  typedef typename PointSet::size_type Size;
142  typedef typename PointSet::const_iterator ConstIterator;
143  typedef typename PointSet::iterator Iterator;
144  typedef TInternalInteger InternalInteger;
148 
149  // ----------------------- std public types ------------------------------
150  public:
151  typedef typename PointSet::const_iterator const_iterator;
152  typedef typename PointSet::const_pointer const_pointer;
153  typedef typename PointSet::const_reference const_reference;
154  typedef typename PointSet::value_type value_type;
155  typedef typename PointSet::difference_type difference_type;
156  typedef typename PointSet::size_type size_type;
157 
158  // ----------------------- internal types ------------------------------
159  private:
165 
171  struct State {
172  InternalInteger max;
173  InternalInteger min;
174  Point ptMax;
175  Point ptMin;
176  ConvexPolygonZ2 cip;
177  InternalPoint3 centroid;
178  InternalPoint3 N;
179  };
180 
181  // ----------------------- Standard services ------------------------------
182  public:
183 
188 
194 
200 
207 
211  MyIntegerComputer & ic() const;
212 
217  void clear();
218 
238  void init( Dimension axis, InternalInteger diameter,
239  InternalInteger widthNumerator = NumberTraits< InternalInteger >::ONE,
240  InternalInteger widthDenominator = NumberTraits< InternalInteger >::ONE );
241 
245  Size complexity() const;
246 
247  //-------------------- model of ForwardContainer -----------------------------
248  public:
249 
253  Size size() const;
254 
258  bool empty() const;
259 
263  ConstIterator begin() const;
264 
268  ConstIterator end() const;
269 
275  Size max_size() const;
276 
281  Size maxSize() const;
282 
283 
284  //-------------------- model of concepts::CPointPredicate -----------------------------
285  public:
286 
296  bool operator()( const Point & p ) const;
297 
298  //-------------------- model of CIncrementalPrimitiveComputer -----------------------------
299  public:
300 
310  bool extendAsIs( const Point & p );
311 
322  bool extend( const Point & p );
323 
334  bool isExtendable( const Point & p ) const;
335 
336  //-------------------- model of CAdditivePrimitiveComputer -----------------------------
337  public:
338 
352  template <typename TInputIterator>
353  bool extend( TInputIterator it, TInputIterator itE );
354 
369  template <typename TInputIterator>
370  bool isExtendable( TInputIterator it, TInputIterator itE ) const;
371 
372  //-------------------- Primitive services -----------------------------
373  public:
374 
385  Primitive primitive() const;
386 
387  //-------------------- Parameters services -----------------------------
388  public:
389 
396  template <typename Vector3D>
397  void getNormal( Vector3D & normal ) const;
398 
402  const IntegerVector3 & exactNormal() const;
403 
410  template <typename Vector3D>
411  void getUnitNormal( Vector3D & normal ) const;
412 
420  void getBounds( double & min, double & max ) const;
421 
428  const Point & minimalPoint() const;
429 
436  const Point & maximalPoint() const;
437 
438  // ----------------------- Interface --------------------------------------
439  public:
440 
445  void selfDisplay ( std::ostream & out ) const;
446 
451  bool isValid() const;
452 
453  // ------------------------- Private Datas --------------------------------
454  private:
456  InternalInteger myG;
457  InternalPoint2 myWidth;
458  PointSet myPointSet;
459  State myState;
460  InternalInteger myCst1;
461  InternalInteger myCst2;
462  mutable InternalInteger _v;
463  mutable State _state;
464  mutable InternalPoint2 _grad;
465  // ------------------------- Hidden services ------------------------------
466  protected:
467 
468 
469  // ------------------------- Internals ------------------------------------
470  private:
471 
480  void computeCentroidAndNormal( State & state ) const;
481 
495  void doubleCut( InternalPoint2 & grad, State & state ) const;
496 
510  template <typename TInputIterator>
511  void computeMinMax( State & state, TInputIterator itB, TInputIterator itE ) const;
512 
530  template <typename TInputIterator>
531  bool updateMinMax( State & state, TInputIterator itB, TInputIterator itE ) const;
532 
542  bool checkPlaneWidth( const State & state ) const;
543 
551  void computeGradient( InternalPoint2 & grad, const State & state ) const;
552 
553  }; // end of class COBANaivePlaneComputer
554 
555 
562  template <typename TSpace, typename TInternalInteger>
563  std::ostream&
564  operator<< ( std::ostream & out, const COBANaivePlaneComputer<TSpace, TInternalInteger> & object );
565 
566 } // namespace DGtal
567 
568 
570 // Includes inline functions.
571 #include "DGtal/geometry/surfaces/COBANaivePlaneComputer.ih"
572 
573 // //
575 
576 #endif // !defined COBANaivePlaneComputer_h
577 
578 #undef COBANaivePlaneComputer_RECURSES
579 #endif // else defined(COBANaivePlaneComputer_RECURSES)
PointVector< 3, InternalInteger > InternalPoint3
void init(Dimension axis, InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE)
void getBounds(double &min, double &max) const
const IntegerVector3 & exactNormal() const
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
ConvexPolygonZ2::HalfSpace HalfSpace
DGtal::uint32_t Dimension
Definition: Common.h:113
bool extendAsIs(const Point &p)
Aim: A parallel strip in the space is the intersection of two parallel half-planes such that each hal...
Definition: ParallelStrip.h:90
void computeGradient(InternalPoint2 &grad, const State &state) const
BOOST_STATIC_ASSERT((TSpace::dimension==3))
ConstIterator begin() const
IntegerComputer< InternalInteger > MyIntegerComputer
bool isExtendable(const Point &p) const
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
bool updateMinMax(State &state, TInputIterator itB, TInputIterator itE) const
bool operator()(const Point &p) const
Aim: This class gathers several types and methods to make computation with integers.
PointSet::const_iterator ConstIterator
bool extend(const Point &p)
LatticePolytope2D< InternalSpace2 > ConvexPolygonZ2
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines...
Definition: CSpace.h:105
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:69
COBANaivePlaneComputer & operator=(const COBANaivePlaneComputer &other)
PointSet::const_reference const_reference
Aim: A class that contains the COBA algorithm (Emilie Charrier, Lilian Buzer, DGCI2008) for recognizi...
MyIntegerComputer & ic() const
void getNormal(Vector3D &normal) const
void selfDisplay(std::ostream &out) const
SpaceND< 2, InternalInteger > InternalSpace2
void computeMinMax(State &state, TInputIterator itB, TInputIterator itE) const
ConstIterator end() const
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: A half-space specified by a vector N and a constant c. The half-space is the set ...
PointSet::const_pointer const_pointer
void doubleCut(InternalPoint2 &grad, State &state) const
bool checkPlaneWidth(const State &state) const
void getUnitNormal(Vector3D &normal) const
const Point & maximalPoint() const
PointSet::difference_type difference_type
PointSet::const_iterator const_iterator
ParallelStrip< Space, true, true > Primitive
PointVector< 3, InternalInteger > IntegerVector3
void computeCentroidAndNormal(State &state) const
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Primitive primitive() const
const Point & minimalPoint() const