2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file StarShaped2D.ih
19 * @author David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
24 * Implementation of inline methods defined in StarShaped2D.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
42 /////////////////////////////////////////////////////////////////////////////
43 // ------------------------- star-shaped services -------------------------
46 * @param p any point in the plane.
48 * @return 'true' if the point is inside the shape, 'false' if it
49 * is strictly outside.
51 template<typename TSpace>
54 DGtal::StarShaped2D<TSpace>::orientation( const RealPoint & p ) const
56 RealPoint x_rel = x( parameter( p ));
61 double d_x = x_rel.norm();
62 double d_p = p_rel.norm();
63 double diff = d_p - d_x;
67 else if ( diff < 0.0 )
75 * @param t any angle between 0 and 2*Pi.
77 * @return the vector (x'(t),y'(t)) made unitary which is the unit
78 * tangent to the shape boundary.
80 template<typename TSpace>
82 typename DGtal::StarShaped2D<TSpace>::RealPoint
83 DGtal::StarShaped2D<TSpace>::tangent( double t ) const
85 RealPoint tgt( xp( t ) );
86 double norm = tgt.norm();
93 * @param t any angle between 0 and 2*Pi.
95 * @return the vector (x''(t),y''(t)) made unitary which is the unit
96 * normal to the shape boundary looking inside the shape.
98 template<typename TSpace>
100 typename DGtal::StarShaped2D<TSpace>::RealPoint
101 DGtal::StarShaped2D<TSpace>::normal( double t ) const
103 RealPoint tgt( tangent( t ) );
104 return RealPoint( -tgt[1], tgt[0]);
109 * @param t any angle between 0 and 2*Pi.
111 * @return the algebraic curvature at point (x(t),y(t)), positive
112 * is convex, negative is concave when shape is to the left and
113 * the shape boundary is followed counterclockwise.
115 template<typename TSpace>
118 DGtal::StarShaped2D<TSpace>::curvature( double t ) const
120 RealPoint tgt( xp( t ) );
121 RealPoint dt( xpp( t ) );
122 double norm = tgt.norm();
123 double curv = ( dt[0] * tgt[1] - dt[1] * tgt[0] ) / ( norm * norm * norm );
129 * @param t1 any angle between 0 and 2*Pi.
130 * @param t2 any angle between 0 and 2*Pi, further from [t1].
131 * @param nb the number of points used to estimate the arclength between x(t1) and x(t2).
132 * @return the estimated arclength.
134 template<typename TSpace>
137 DGtal::StarShaped2D<TSpace>::arclength( double t1, double t2, unsigned int nb ) const
139 while ( t2 < t1 ) t2 += 2.0*M_PI;
141 RealPoint x0( x( t1 ) );
144 for ( unsigned int i = 1; i <= nb; ++i )
146 double t = ( ( t2 - t1 ) * i ) / nb;
147 RealPoint x1( x( t1 + t ) );
148 l += sqrt( ( x1[0] - x0[0] )*( x1[0] - x0[0] )
149 + ( x1[1] - x0[1] )*( x1[1] - x0[1] ) );
160 template <typename T>
162 DGtal::StarShaped2D<T>::~StarShaped2D()
166 ///////////////////////////////////////////////////////////////////////////////
167 // Interface - public :
170 * Writes/Displays the object on an output stream.
171 * @param out the output stream where the object is written.
173 template <typename T>
176 DGtal::StarShaped2D<T>::selfDisplay ( std::ostream & out ) const
178 out << "[StarShaped2D]";
182 * Checks the validity/consistency of the object.
183 * @return 'true' if the object is valid, 'false' otherwise.
185 template <typename T>
188 DGtal::StarShaped2D<T>::isValid() const
195 ///////////////////////////////////////////////////////////////////////////////
196 // Implementation of inline functions //
198 template <typename T>
201 DGtal::operator<< ( std::ostream & out,
202 const StarShaped2D<T> & object )
204 object.selfDisplay( out );
209 ///////////////////////////////////////////////////////////////////////////////