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 AccFlower2D.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
21 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
22 * Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
26 * Implementation of inline methods defined in AccFlower2D.h
28 * This file is part of the DGtal library.
32//////////////////////////////////////////////////////////////////////////////
34//////////////////////////////////////////////////////////////////////////////
36#define FLOWER_PI_SQUARE (M_PI * M_PI)
37#define FLOWER_2_PI (2. * M_PI)
39///////////////////////////////////////////////////////////////////////////////
40// IMPLEMENTATION of inline methods.
41///////////////////////////////////////////////////////////////////////////////
43///////////////////////////////////////////////////////////////////////////////
44// ----------------------- Standard services ------------------------------
48DGtal::AccFlower2D<T>::AccFlower2D(const double x0, const double y0,
49 const double radius, const double smallRadius,
50 const unsigned int k, const double phi)
51 : myCenter(x0,y0), myRadius(radius), myVarRadius(smallRadius),
54 myKp = 2 * myK / FLOWER_PI_SQUARE;
60DGtal::AccFlower2D<T>::AccFlower2D(const RealPoint &aPoint, const double radius,
61 const double smallRadius,
62 const unsigned int k, const double phi)
63 : myCenter(aPoint), myRadius(radius), myVarRadius(smallRadius),
66 myKp = 2 * myK/ FLOWER_PI_SQUARE;
71DGtal::AccFlower2D<T>::AccFlower2D(const AccFlower2D& other)
72 : myCenter(other.myCenter), myRadius(other.myRadius), myVarRadius(other.myVarRadius),
73 myK(other.myK), myPhi(other.myPhi)
76/////////////////////////////////////////////////////////////////////////////
77// ------------- Implementation of 'StarShaped' services ------------------
80 * @param pp any point in the plane.
82 * @return the angle parameter between 0 and 2*Pi corresponding to
83 * this point for the shape.
88DGtal::AccFlower2D<T>::parameter( const RealPoint& pp ) const
90 RealPoint p = pp - myCenter;
92 const double angle = atan2( p[1], p[0] );
94 return ( angle < 0. ) ? angle + FLOWER_2_PI : angle;
98 * @param tt any angle between 0 and 2*Pi.
100 * @return the vector (x(t),y(t)) which is the position on the
105typename DGtal::AccFlower2D<T>::RealPoint
106DGtal::AccFlower2D<T>::x( const double tt ) const
109 while ( t >= M_PI ) t -= FLOWER_2_PI;
110 while ( t < -M_PI ) t += FLOWER_2_PI;
112 const double r = myRadius + myVarRadius * cos( myKp * t * t * t );
113 return RealPoint( r * cos( t ), r * sin( t ) ) + myCenter;
118 * @param tt any angle between 0 and 2*Pi.
120 * @return the vector (x'(t),y'(t)) which is the tangent to the
125typename DGtal::AccFlower2D<T>::RealVector
126DGtal::AccFlower2D<T>::xp( const double tt ) const
129 while ( t >= M_PI ) t -= FLOWER_2_PI;
130 while ( t < -M_PI ) t += FLOWER_2_PI;
132 const double ktn = myKp * t * t * t;
133 const double ktnp = 3 * myKp * t * t ;
135 const double r = myRadius + myVarRadius * cos( ktn );
136 const double rp = - myVarRadius * sin( ktn ) * ktnp;
138 rp * cos( t ) - r * sin( t ),
139 rp * sin( t ) + r * cos( t )
144 * @param tt any angle between 0 and 2*Pi.
146 * @return the vector (x''(t),y''(t)).
150typename DGtal::AccFlower2D<T>::RealVector
151DGtal::AccFlower2D<T>::xpp( const double tt ) const
154 while ( t >= M_PI ) t -= FLOWER_2_PI;
155 while ( t < -M_PI ) t += FLOWER_2_PI;
157 const double ktn = myKp * t * t * t;
158 const double ktnp = 3 * myKp * t * t;
159 const double ktnpp = 6 * myKp * t;
161 const double r = myRadius + myVarRadius * cos( ktn );
162 const double rp = - myVarRadius * sin( ktn ) * ktnp;
163 const double rpp = - myVarRadius * cos( ktn ) * ktnp * ktnp -
164 myVarRadius * sin( ktn ) * ktnpp;
167 rpp * cos( t ) - 2 * rp * sin( t ) - r * cos( t ),
168 rpp * sin( t ) + 2 * rp * cos( t ) - r * sin( t )
173///////////////////////////////////////////////////////////////////////////////
174// Interface - public :
177 * Writes/Displays the object on an output stream.
178 * @param out the output stream where the object is written.
183DGtal::AccFlower2D<T>::selfDisplay ( std::ostream & out ) const
185 out << "[AccFlower2D] center= " << myCenter
186 << " radius=" << myRadius
187 << " smallradius=" << myVarRadius
189 << " phase-shift=" << myPhi;
193 * Checks the validity/consistency of the object.
194 * @return 'true' if the object is valid, 'false' otherwise.
199DGtal::AccFlower2D<T>::isValid() const
206///////////////////////////////////////////////////////////////////////////////
207// Implementation of inline functions //
212DGtal::operator<< ( std::ostream & out,
213 const AccFlower2D<T> & object )
215 object.selfDisplay( out );
220///////////////////////////////////////////////////////////////////////////////