DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
DGtal::NGon2D< TSpace > Class Template Reference

#include <NGon2D.h>

Inheritance diagram for DGtal::NGon2D< TSpace >:
Inheritance graph
[legend]
Collaboration diagram for DGtal::NGon2D< TSpace >:
Collaboration graph
[legend]

Public Types

typedef TSpace Space
typedef Space::Point Point
typedef Space::RealPoint RealPoint2D
typedef Space::RealVector RealVector2D
- Public Types inherited from DGtal::StarShaped2D< TSpace >
typedef Space::RealPoint RealPoint

Public Member Functions

 ~NGon2D ()
 NGon2D (const double x0, const double y0, const double r, const unsigned int k, const double phi)
 NGon2D (const RealPoint2D &aPoint, const double r, const unsigned int k, const double phi)
 NGon2D (const Point &aPoint, const double r, const unsigned int k, const double phi)
RealPoint2D getLowerBound () const
RealPoint2D getUpperBound () const
RealPoint2D center () const
double parameter (const RealPoint2D &p) const
RealPoint2D x (const double t) const
RealVector2D xp (const double t) const
RealVector2D xpp (const double t) const
void selfDisplay (std::ostream &out) const
bool isValid () const
- Public Member Functions inherited from DGtal::StarShaped2D< TSpace >
 StarShaped2D ()
 ~StarShaped2D ()
virtual RealPoint interiorPoint () const
bool isInside (const RealPoint &p) const
bool isInside (const Point &p) const
Orientation orientation (const RealPoint &p) const
RealPoint tangent (double t) const
RealPoint normal (double t) const
double curvature (double t) const
double arclength (double t1, double t2, unsigned int nb) const

Protected Member Functions

 NGon2D ()

Private Member Functions

NGon2Doperator= (const NGon2D &other)

Private Attributes

RealPoint2D myCenter
double myRadius
unsigned int myK
double myPhi

Detailed Description

template<typename TSpace>
class DGtal::NGon2D< TSpace >

Aim: Model of the concept StarShaped represents any regular k-gon in the plane.

Description of template class 'NGon2D'

NB: A backport from ImaGene.

Definition at line 63 of file NGon2D.h.


Member Typedef Documentation

template<typename TSpace>
typedef Space::Point DGtal::NGon2D< TSpace >::Point

Reimplemented from DGtal::StarShaped2D< TSpace >.

Definition at line 69 of file NGon2D.h.

template<typename TSpace>
typedef Space::RealPoint DGtal::NGon2D< TSpace >::RealPoint2D

Definition at line 70 of file NGon2D.h.

template<typename TSpace>
typedef Space::RealVector DGtal::NGon2D< TSpace >::RealVector2D

Definition at line 71 of file NGon2D.h.

template<typename TSpace>
typedef TSpace DGtal::NGon2D< TSpace >::Space

Reimplemented from DGtal::StarShaped2D< TSpace >.

Definition at line 68 of file NGon2D.h.


Constructor & Destructor Documentation

template<typename T >
DGtal::NGon2D< T >::~NGon2D ( )
inline

Destructor.

Definition at line 48 of file NGon2D.ih.

{
}
template<typename T >
DGtal::NGon2D< T >::NGon2D ( const double  x0,
const double  y0,
const double  r,
const unsigned int  k,
const double  phi 
)
inline

Constructor.

Parameters:
x0the x-coordinate of the circle center.
y0the y-coordinate of the circle center.
rthe radius of the circle.
kthe number of faces of the k-gon.
phithe phase of the ngon (radian).

Definition at line 54 of file NGon2D.ih.

:
myCenter(x0,y0), myRadius(radius), myK(k), myPhi(phi)
{}
template<typename T >
DGtal::NGon2D< T >::NGon2D ( const RealPoint2D aPoint,
const double  r,
const unsigned int  k,
const double  phi 
)
inline

Constructor.

Parameters:
aPointthe circle center.
rthe radius of the circle.
kthe number of faces of the k-gon.
phithe phase of the ngon (radian).

Definition at line 63 of file NGon2D.ih.

:
myCenter(aPoint), myRadius(radius) , myK(k), myPhi(phi)
{}
template<typename T >
DGtal::NGon2D< T >::NGon2D ( const Point aPoint,
const double  r,
const unsigned int  k,
const double  phi 
)
inline

Constructor.

Parameters:
aPointthe circle center.
rthe radius of the circle.
kthe number of faces of the k-gon.
phithe phase of the ngon (radian).

Definition at line 71 of file NGon2D.ih.

References DGtal::NGon2D< TSpace >::myCenter.

:
myRadius(radius), myK(k), myPhi(phi)
{
myCenter = aPoint;
}
template<typename TSpace>
DGtal::NGon2D< TSpace >::NGon2D ( )
protected

Constructor. Forbidden by default (protected to avoid g++ warnings).


Member Function Documentation

template<typename TSpace>
RealPoint2D DGtal::NGon2D< TSpace >::center ( ) const
inlinevirtual
Returns:
the center of the star-shaped object.

Implements DGtal::StarShaped2D< TSpace >.

Definition at line 134 of file NGon2D.h.

References DGtal::NGon2D< TSpace >::myCenter.

{
return myCenter;
}
template<typename TSpace>
RealPoint2D DGtal::NGon2D< TSpace >::getLowerBound ( ) const
inlinevirtual
Returns:
the lower bound of the shape bounding box.

Implements DGtal::StarShaped2D< TSpace >.

Definition at line 117 of file NGon2D.h.

References DGtal::NGon2D< TSpace >::myCenter, and DGtal::NGon2D< TSpace >::myRadius.

{
}
template<typename TSpace>
RealPoint2D DGtal::NGon2D< TSpace >::getUpperBound ( ) const
inlinevirtual
Returns:
the upper bound of the shape bounding box.

Implements DGtal::StarShaped2D< TSpace >.

Definition at line 126 of file NGon2D.h.

References DGtal::NGon2D< TSpace >::myCenter, and DGtal::NGon2D< TSpace >::myRadius.

{
}
template<typename T >
bool DGtal::NGon2D< T >::isValid ( ) const
inline

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.

Reimplemented from DGtal::StarShaped2D< TSpace >.

Definition at line 229 of file NGon2D.ih.

{
return true;
}
template<typename TSpace>
NGon2D& DGtal::NGon2D< TSpace >::operator= ( const NGon2D< TSpace > &  other)
private

Copy constructor.

Parameters:
otherthe object to clone. Forbidden by default. Assignment.
otherthe object to copy.
Returns:
a reference on 'this'. Forbidden by default.
template<typename T >
double DGtal::NGon2D< T >::parameter ( const RealPoint2D pp) const
inlinevirtual
Parameters:
pany point in the plane.
Returns:
the angle parameter between 0 and 2*Pi corresponding to this point for the shape.

Implements DGtal::StarShaped2D< TSpace >.

Definition at line 91 of file NGon2D.ih.

References M_PI.

{
RealPoint2D p( pp );
p -= myCenter;
double t = atan2( p[ 1 ], p[ 0 ] );
return ( t < 0.0 ) ? ( t + 2.0 * M_PI ) : t;
// double angle = 0.0;
// if ( p[0] == 0.0 )
// {
// if ( p[1] >0 )
// angle = M_PI/2.0;
// else
// angle = 1.5*M_PI;
// }
// else if ( ( p[0] > 0.0 ) && ( p[1] >= 0.0 ) )
// angle = atan(p[1]/p[0]);
// else if ( ( p[0] > 0.0 ) && ( p[1] <= 0.0 ) )
// angle = 2*M_PI + atan(p[1]/p[0]);
// else if ( ( p[0] < 0.0 ) && ( p[1] >= 0.0 ) )
// angle = atan(p[1]/p[0]) + M_PI;
// else // ( ( p[0] < 0.0 ) && ( p[1] <= 0.0 ) )
// angle = atan(p[1]/p[0]) + M_PI;
// return angle;
}
template<typename T >
void DGtal::NGon2D< T >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Reimplemented from DGtal::StarShaped2D< TSpace >.

Definition at line 216 of file NGon2D.ih.

{
out << "[NGon2D] center= "<<myCenter<<" radius="<<myRadius<<" number of sides="<<myK
<< " phase-shift="<<myPhi;
}
template<typename T >
DGtal::NGon2D< T >::RealPoint2D DGtal::NGon2D< T >::x ( const double  t) const
inlinevirtual
Parameters:
tany angle between 0 and 2*Pi.
Returns:
the vector (x(t),y(t)) which is the position on the shape boundary.

Implements DGtal::StarShaped2D< TSpace >.

Definition at line 127 of file NGon2D.ih.

References M_PI.

{
double angle = t - myPhi;
while ( angle < 0.0 )
angle += 2.0*M_PI;
// seek the vertices between the point, then compute the vector from one vertex to the next one.
unsigned int intervale_lower = static_cast<unsigned int>( floor( ( angle )* myK / (2.0 * M_PI ) ) );
unsigned int intervale_upper = intervale_lower == ( myK -1 ) ? 0 : intervale_lower+1;
double dist = myRadius*cos ( M_PI / myK );
RealPoint2D s1 ( myRadius*cos(myPhi + intervale_lower*2.0*M_PI/myK),
myRadius*sin(myPhi + intervale_lower*2.0*M_PI/myK) );
RealPoint2D s2 ( myRadius*cos(myPhi + intervale_upper*2.0*M_PI/myK),
myRadius*sin(myPhi + intervale_upper*2.0*M_PI/myK) );
RealPoint2D s3( s2[0] - s1[0], s2[1] - s1[1]);
double line_angle = atan2f( (float)s3[ 1 ], (float)s3[ 0 ]);
double rho = dist/(cos (t - line_angle - 0.5*M_PI));
RealPoint2D c( rho*cos(t), rho*sin(t) );
c += myCenter;
return c;
}
template<typename T >
DGtal::NGon2D< T >::RealVector2D DGtal::NGon2D< T >::xp ( const double  t) const
inlinevirtual
Parameters:
tany angle between 0 and 2*Pi.
Returns:
the vector (x'(t),y'(t)) which is the tangent to the shape boundary.

Implements DGtal::StarShaped2D< TSpace >.

Definition at line 166 of file NGon2D.ih.

References M_PI.

{
// seek the vertices between the point, then compute the vector from one vertex to the next one.
// TODO check if angle equals that of a vertex ?
double angle = t - myPhi;
while ( angle < 0.0 )
angle += 2.0*M_PI;
unsigned int intervalle_lower = static_cast<unsigned int>( floor( angle * myK / (2.0 * M_PI ) ) );
unsigned int intervalle_upper = intervalle_lower == ( myK -1 ) ? 0 : intervalle_lower+1;
//float dist = myRadius*sin ( M_PI / myK );
RealPoint2D s1 ( myRadius*cos(myPhi + intervalle_lower*2.0*M_PI/myK),
myRadius*sin(myPhi + intervalle_lower*2.0*M_PI/myK) );
RealPoint2D s2 ( myRadius*cos(myPhi + intervalle_upper*2.0*M_PI/myK),
myRadius*sin(myPhi + intervalle_upper*2.0*M_PI/myK) );
s2 -= s1;
//normalize
double norm = s2.norm();
s2[0] /= norm;
s2[1] /= norm;
return s2;
}
template<typename T >
DGtal::NGon2D< T >::RealVector2D DGtal::NGon2D< T >::xpp ( const double  t) const
inlinevirtual
Parameters:
tany angle between 0 and 2*Pi.
Returns:
the vector (x''(t),y''(t)).

Implements DGtal::StarShaped2D< TSpace >.

Definition at line 199 of file NGon2D.ih.

{
RealVector2D c(0,0);
return c;
}

Field Documentation

template<typename TSpace>
RealPoint2D DGtal::NGon2D< TSpace >::myCenter
private

Center of the circle.

Definition at line 178 of file NGon2D.h.

Referenced by DGtal::NGon2D< TSpace >::center(), DGtal::NGon2D< TSpace >::getLowerBound(), DGtal::NGon2D< TSpace >::getUpperBound(), and DGtal::NGon2D< TSpace >::NGon2D().

template<typename TSpace>
unsigned int DGtal::NGon2D< TSpace >::myK
private

Definition at line 188 of file NGon2D.h.

template<typename TSpace>
double DGtal::NGon2D< TSpace >::myPhi
private

Definition at line 193 of file NGon2D.h.

template<typename TSpace>
double DGtal::NGon2D< TSpace >::myRadius
private

Radius of the circle.

Definition at line 183 of file NGon2D.h.

Referenced by DGtal::NGon2D< TSpace >::getLowerBound(), and DGtal::NGon2D< TSpace >::getUpperBound().


The documentation for this class was generated from the following files: