DGtal
1.5.beta
|
Aim: A class that contains the COBA algorithm (Emilie Charrier, Lilian Buzer, DGCI2008) for recognizing pieces of digital planes of given axis width. When the width is 1, it corresponds to naive planes. The axis is specified at initialization of the object. More...
#include <DGtal/geometry/surfaces/COBANaivePlaneComputer.h>
Data Structures | |
struct | State |
Public Types | |
typedef TSpace | Space |
typedef Space::Point | Point |
typedef std::set< Point > | PointSet |
typedef PointSet::size_type | Size |
typedef PointSet::const_iterator | ConstIterator |
typedef PointSet::iterator | Iterator |
typedef TInternalInteger | InternalInteger |
typedef IntegerComputer< InternalInteger > | MyIntegerComputer |
typedef ParallelStrip< Space, true, true > | Primitive |
typedef PointVector< 3, InternalInteger > | IntegerVector3 |
typedef PointSet::const_iterator | const_iterator |
typedef PointSet::const_pointer | const_pointer |
typedef PointSet::const_reference | const_reference |
typedef PointSet::value_type | value_type |
typedef PointSet::difference_type | difference_type |
typedef PointSet::size_type | size_type |
Public Member Functions | |
~COBANaivePlaneComputer () | |
COBANaivePlaneComputer () | |
COBANaivePlaneComputer (const COBANaivePlaneComputer &other) | |
COBANaivePlaneComputer & | operator= (const COBANaivePlaneComputer &other) |
MyIntegerComputer & | ic () const |
void | clear () |
void | init (Dimension axis, InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE) |
Size | complexity () const |
Size | size () const |
bool | empty () const |
ConstIterator | begin () const |
ConstIterator | end () const |
Size | max_size () const |
Size | maxSize () const |
bool | operator() (const Point &p) const |
bool | extendAsIs (const Point &p) |
bool | extend (const Point &p) |
bool | isExtendable (const Point &p) const |
template<typename TInputIterator > | |
bool | extend (TInputIterator it, TInputIterator itE) |
template<typename TInputIterator > | |
bool | isExtendable (TInputIterator it, TInputIterator itE) const |
Primitive | primitive () const |
template<typename Vector3D > | |
void | getNormal (Vector3D &normal) const |
const IntegerVector3 & | exactNormal () const |
template<typename Vector3D > | |
void | getUnitNormal (Vector3D &normal) const |
void | getBounds (double &min, double &max) const |
const Point & | minimalPoint () const |
const Point & | maximalPoint () const |
void | selfDisplay (std::ostream &out) const |
bool | isValid () const |
Private Types | |
typedef PointVector< 3, InternalInteger > | InternalPoint3 |
typedef SpaceND< 2, InternalInteger > | InternalSpace2 |
typedef InternalSpace2::Point | InternalPoint2 |
typedef LatticePolytope2D< InternalSpace2 > | ConvexPolygonZ2 |
typedef ConvexPolygonZ2::HalfSpace | HalfSpace |
Private Member Functions | |
BOOST_CONCEPT_ASSERT ((concepts::CSpace< TSpace >)) | |
BOOST_CONCEPT_ASSERT ((concepts::CInteger< TInternalInteger >)) | |
BOOST_STATIC_ASSERT ((TSpace::dimension==3)) | |
void | computeCentroidAndNormal (State &state) const |
void | doubleCut (InternalPoint2 &grad, State &state) const |
template<typename TInputIterator > | |
void | computeMinMax (State &state, TInputIterator itB, TInputIterator itE) const |
template<typename TInputIterator > | |
bool | updateMinMax (State &state, TInputIterator itB, TInputIterator itE) const |
bool | checkPlaneWidth (const State &state) const |
void | computeGradient (InternalPoint2 &grad, const State &state) const |
Aim: A class that contains the COBA algorithm (Emilie Charrier, Lilian Buzer, DGCI2008) for recognizing pieces of digital planes of given axis width. When the width is 1, it corresponds to naive planes. The axis is specified at initialization of the object.
Description of template class 'COBANaivePlaneComputer'
As a (3D) geometric primitive, it obeys to a subset of the concept CSegmentComputer. It is copy constructible, assignable. It is iterable (inner type ConstIterator, begin(), end()). It has methods extend(), extend( InputIterator, InputIterator) and isExtendable(), isExtendable(InputIterator, InputIterator). The object stores all the distinct points p
such that 'extend( p
)' was successful. It is thus a model of boost::ForwardContainer (non mutable).
It is also a model of concepts::CPointPredicate (returns 'true' iff a point is within the current bounds).
Note on complexity: The complexity is highly dependent on the way points are added to the object. Let D be the diameter and n be the number of points already added. Assume small integers. Complexity of adding a point that do not change the normal of the plane is \( O(\log(n)) \). When it changes the normal, the number of cuts is upper bounded by some \( O(\log(D)) \), each cut costs \( O(n+m\log(D) ) \), where m is the number of sides of the convex polygon of constraints. However, when recognizing a piece of naive plane, the number of times K where the normal should be updated is rather limited to some \( O(\log(D)) \).
Note on execution times: The user should favor int64_t instead of BigInteger whenever possible (diameter smaller than 500). The speed-up is between 10 and 20 for these diameters. For greater diameters, it is necessary to use BigInteger (see below).
TSpace | specifies the type of digital space in which lies input digital points. A model of CSpace. |
TInternalInteger | specifies the type of integer used in internal computations. The type should be able to hold integers of order (2*D^3)^2 if D is the diameter of the set of digital points. In practice, diameter is limited to 20 for int32_t, diameter is approximately 500 for int64_t, and whatever with BigInteger/GMP integers. For huge diameters, the slow-down is polylogarithmic with respect to the diameter. |
Essentially a backport from ImaGene.
Model of boost::DefaultConstructible, boost::CopyConstructible, boost::Assignable, boost::ForwardContainer, concepts::CAdditivePrimitiveComputer, concepts::CPointPredicate.
Definition at line 129 of file COBANaivePlaneComputer.h.
typedef PointSet::const_iterator DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::const_iterator |
Definition at line 151 of file COBANaivePlaneComputer.h.
typedef PointSet::const_pointer DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::const_pointer |
Definition at line 152 of file COBANaivePlaneComputer.h.
typedef PointSet::const_reference DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::const_reference |
Definition at line 153 of file COBANaivePlaneComputer.h.
typedef PointSet::const_iterator DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::ConstIterator |
Definition at line 142 of file COBANaivePlaneComputer.h.
|
private |
Definition at line 163 of file COBANaivePlaneComputer.h.
typedef PointSet::difference_type DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::difference_type |
Definition at line 155 of file COBANaivePlaneComputer.h.
|
private |
Definition at line 164 of file COBANaivePlaneComputer.h.
typedef PointVector< 3, InternalInteger > DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::IntegerVector3 |
Definition at line 147 of file COBANaivePlaneComputer.h.
typedef TInternalInteger DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::InternalInteger |
Definition at line 144 of file COBANaivePlaneComputer.h.
|
private |
Definition at line 162 of file COBANaivePlaneComputer.h.
|
private |
Definition at line 160 of file COBANaivePlaneComputer.h.
|
private |
Definition at line 161 of file COBANaivePlaneComputer.h.
typedef PointSet::iterator DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::Iterator |
Definition at line 143 of file COBANaivePlaneComputer.h.
typedef IntegerComputer< InternalInteger > DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::MyIntegerComputer |
Definition at line 145 of file COBANaivePlaneComputer.h.
typedef Space::Point DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::Point |
Definition at line 139 of file COBANaivePlaneComputer.h.
typedef std::set< Point > DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::PointSet |
Definition at line 140 of file COBANaivePlaneComputer.h.
typedef ParallelStrip<Space, true, true> DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::Primitive |
Definition at line 146 of file COBANaivePlaneComputer.h.
typedef PointSet::size_type DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::Size |
Definition at line 141 of file COBANaivePlaneComputer.h.
typedef PointSet::size_type DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::size_type |
Definition at line 156 of file COBANaivePlaneComputer.h.
typedef TSpace DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::Space |
Definition at line 138 of file COBANaivePlaneComputer.h.
typedef PointSet::value_type DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::value_type |
Definition at line 154 of file COBANaivePlaneComputer.h.
DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::~COBANaivePlaneComputer | ( | ) |
Destructor.
DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::COBANaivePlaneComputer | ( | ) |
Constructor. The object is not valid and should be initialized.
DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::COBANaivePlaneComputer | ( | const COBANaivePlaneComputer< TSpace, TInternalInteger > & | other | ) |
Copy constructor.
other | the object to clone. |
ConstIterator DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::begin | ( | ) | const |
Referenced by checkPlane(), checkPlaneGroupExtension(), and main().
|
private |
|
private |
|
private |
|
private |
state | the state where the normal state.N, the scalars state.min and state.max are used in computations. |
void DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::clear | ( | ) |
Clear the object, free memory. The plane keeps its main axis, diameter and width, but contains no point.
Size DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::complexity | ( | ) | const |
Referenced by checkGenericPlane(), and checkPlane().
|
private |
Recompute centroid of polygon of solution and deduce the current normal vector. It is called after any modification of the convex polygon representing the set of solution.
state | (modified) the state where the fields state.cip are used in computation and where fields state.centroid and state.N are updated. |
|
private |
grad | (updated) the value of a gradient used to cut the polygon of solutions. |
state | the state where the iterators state.ptMin and state.ptMax are used in computations. |
|
private |
Computes the min and max values/arguments of the scalar product between the normal state.N and the points in the range [itB,itE). Overwrites state.min, state.max at the start.
TInputIterator | any model of InputIterator. |
state | (modified) the state where the normal N is used in computation and where fields state.min, state.max, state.ptMin, state.ptMax are updated. |
itB | an input iterator on the first point of the range. |
itE | an input iterator after the last point of the range. |
|
private |
Performs the double cut in parameter space according to the current gradient and width. The centroid and normals are no more valid (computeCentroidAndNormal should be called afterwards).
grad | (altered, but not modified) the gradient used to update the polygon of solutions state.cip. |
state | (modified) the state where the fields state.ptMin, state.ptMax, state.cip are used in computation and where field state.cip is updated. |
bool DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::empty | ( | ) | const |
ConstIterator DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::end | ( | ) | const |
Referenced by checkPlane(), checkPlaneGroupExtension(), and main().
const IntegerVector3& DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::exactNormal | ( | ) | const |
bool DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::extend | ( | const Point & | p | ) |
Adds the point p and checks if we have still a digital plane of specified width. The plane parameters may be updated so as to include the new point.
p | any 3D point (in the specified diameter). |
Referenced by checkGenericPlane(), checkPlane(), checkPlaneGroupExtension(), main(), testChordNaivePlaneComputer(), and testCOBANaivePlaneComputer().
bool DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::extend | ( | TInputIterator | it, |
TInputIterator | itE | ||
) |
Adds the range of points [it, itE) and checks if we have still a digital plane of specified width. The plane parameters may be updated so as to include all the new points. All points pointed by iterators should be in the diameter of this object.
TInputIterator | any model of InputIterator on Point. |
it | an iterator on the first element of the range of 3D points. |
itE | an iterator after the last element of the range of 3D points. |
bool DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::extendAsIs | ( | const Point & | p | ) |
Adds the point p to this plane if it is within the current bounds. The plane parameters are not updated.
p | any 3D point (in the specified diameter). |
void DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::getBounds | ( | double & | min, |
double & | max | ||
) | const |
If n is the unit normal to the current plane, then n.x >= min and n.x <= max are the two half-planes defining it.
min | the lower bound (corresponding to the unit vector). |
max | the upper bound (corresponding to the unit vector). |
void DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::getNormal | ( | Vector3D & | normal | ) | const |
Vector3D | any type T such that T.operator[](int i) returns a reference to a double. i ranges in 0,1,2. |
[in,out] | normal | the current normal vector |
void DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::getUnitNormal | ( | Vector3D & | normal | ) | const |
Vector3D | any type T such that T.operator[](int i) returns a reference to a double. i ranges in 0,1,2. |
[in,out] | normal | (updates) the current unit normal vector |
MyIntegerComputer& DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::ic | ( | ) | const |
void DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::init | ( | Dimension | axis, |
InternalInteger | diameter, | ||
InternalInteger | widthNumerator = NumberTraits< InternalInteger >::ONE , |
||
InternalInteger | widthDenominator = NumberTraits< InternalInteger >::ONE |
||
) |
All these parameters cannot be changed during the process. After this call, the object is in a consistent state and can accept new points for recognition. Calls clear so that the object is ready to be extended.
axis | the main axis (0,1,2) for x, y or z. |
diameter | the diameter for the set of points (maximum distance between the given points) |
widthNumerator | the maximal axis-width (x,y,or z) for the plane is defined as the rational number widthNumerator / widthDenominator (default is 1/1, i.e. naive plane). |
widthDenominator | the maximal axis-width (x,y,or z) for the plane is defined as the rational number widthNumerator / widthDenominator (default is 1/1, i.e. naive plane). |
Referenced by checkGenericPlane(), checkPlane(), checkPlaneGroupExtension(), main(), testChordNaivePlaneComputer(), and testCOBANaivePlaneComputer().
bool DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::isExtendable | ( | const Point & | p | ) | const |
Checks if we have still a digital plane of specified width when adding point p. The object is left unchanged whatever the returned value. The invariant is 'this->isExtendable( p ) == true <=> this->extend( p ) == true'.
p | any 3D point (in the specified diameter). |
Referenced by checkPlane(), and checkPlaneGroupExtension().
bool DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::isExtendable | ( | TInputIterator | it, |
TInputIterator | itE | ||
) | const |
Checks if we have still a digital plane of specified width when adding the range of points [it, itE). The object is left unchanged whatever the returned value. All points pointed by iterators should be in the diameter of this object. The invariant is 'this->isExtendable( it, itE ) == true <=> this->extend( it, itE ) == true'.
TInputIterator | any model of InputIterator on Point. |
it | an iterator on the first element of the range of 3D points. |
itE | an iterator after the last element of the range of 3D points. |
bool DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::isValid | ( | ) | const |
Checks the validity/consistency of the object.
Size DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::max_size | ( | ) | const |
NB: std version.
const Point& DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::maximalPoint | ( | ) | const |
Size DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::maxSize | ( | ) | const |
same as max_size
const Point& DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::minimalPoint | ( | ) | const |
bool DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::operator() | ( | const Point & | p | ) | const |
Checks if the point p is in the current digital plane. Therefore, a COBANaivePlaneComputer is a model of concepts::CPointPredicate.
p | any 3D point. |
COBANaivePlaneComputer& DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::operator= | ( | const COBANaivePlaneComputer< TSpace, TInternalInteger > & | other | ) |
Assignment.
other | the object to copy. |
Primitive DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::primitive | ( | ) | const |
void DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::selfDisplay | ( | std::ostream & | out | ) | const |
Writes/Displays the object on an output stream.
out | the output stream where the object is written. |
Size DGtal::COBANaivePlaneComputer< TSpace, TInternalInteger >::size | ( | ) | const |
Referenced by main().
|
private |
Updates the min and max values/arguments of the scalar product between the normal state.N and the points in the range [itB,itE). Do not overwrite state.min, state.max at the start.
TInputIterator | any model of InputIterator. |
state | (modified) the state where the normal N is used in computation and where fields state.min, state.max, state.ptMin, state.ptMax are updated. |
itB | an input iterator on the first point of the range. |
itE | an input iterator after the last point of the range. |
|
mutableprivate |
temporary variable to store the current gradient.
Definition at line 464 of file COBANaivePlaneComputer.h.
|
mutableprivate |
Temporary state used in computations.
Definition at line 463 of file COBANaivePlaneComputer.h.
|
mutableprivate |
temporary variable used in computations.
Definition at line 462 of file COBANaivePlaneComputer.h.
|
private |
the main axis used in all subsequent computations.
Definition at line 455 of file COBANaivePlaneComputer.h.
|
private |
( (int) ceil( get_si( myG ) * myWidth ) + 1 ).
Definition at line 460 of file COBANaivePlaneComputer.h.
|
private |
( (int) floor( get_si( myG ) * myWidth ) - 1 ).
Definition at line 461 of file COBANaivePlaneComputer.h.
|
private |
the grid step used in all subsequent computations.
Definition at line 456 of file COBANaivePlaneComputer.h.
|
private |
the set of points within the plane.
Definition at line 458 of file COBANaivePlaneComputer.h.
|
private |
the current state that defines the plane being recognized.
Definition at line 459 of file COBANaivePlaneComputer.h.
|
private |
the plane width as a positive rational number myWidth[0]/myWidth[1]
Definition at line 457 of file COBANaivePlaneComputer.h.