DGtal  1.0.0
AccFlower2D.ih
1 /**
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.
6  *
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.
11  *
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/>.
14  *
15  **/
16 
17 /**
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
23  *
24  * @date 2011/04/12
25  *
26  * Implementation of inline methods defined in AccFlower2D.h
27  *
28  * This file is part of the DGtal library.
29  */
30 
31 
32 //////////////////////////////////////////////////////////////////////////////
33 #include <cstdlib>
34 //////////////////////////////////////////////////////////////////////////////
35 
36 ///////////////////////////////////////////////////////////////////////////////
37 // IMPLEMENTATION of inline methods.
38 ///////////////////////////////////////////////////////////////////////////////
39 
40 ///////////////////////////////////////////////////////////////////////////////
41 // ----------------------- Standard services ------------------------------
42 
43 /**
44  * Destructor.
45  */
46 template <typename T>
47 inline
48 DGtal::AccFlower2D<T>::~AccFlower2D()
49 {
50 }
51 
52 template <typename T>
53 inline
54 DGtal::AccFlower2D<T>::AccFlower2D(const double x0, const double y0,
55  const double radius, const double smallRadius,
56  const unsigned int k, const double phi)
57  : myCenter(x0,y0), myRadius(radius), myVarRadius(smallRadius),
58  myK(k), myPhi(phi)
59 {
60  myKp = 2 * myK/ ( M_PI * M_PI );
61 }
62 
63 
64 template <typename T>
65 inline
66 DGtal::AccFlower2D<T>::AccFlower2D(const RealPoint2D &aPoint, const double radius,
67  const double smallRadius,
68  const unsigned int k, const double phi)
69  : myCenter(aPoint), myRadius(radius), myVarRadius(smallRadius),
70  myK(k), myPhi(phi)
71 {
72  myKp = 2 * myK/ ( M_PI * M_PI );
73 }
74 
75 template <typename T>
76 inline
77 DGtal::AccFlower2D<T>::AccFlower2D(const Point &aPoint, const double radius,
78  const double smallRadius,
79  const unsigned int k, const double phi)
80  : myRadius(radius), myVarRadius(smallRadius), myK(k), myPhi(phi)
81 {
82  myCenter = aPoint;
83  myKp = 2 * myK/ ( M_PI * M_PI );
84 }
85 
86 /////////////////////////////////////////////////////////////////////////////
87 // ------------- Implementation of 'StarShaped' services ------------------
88 
89 /**
90  * @param p any point in the plane.
91  *
92  * @return the angle parameter between 0 and 2*Pi corresponding to
93  * this point for the shape.
94  */
95 template <typename T>
96 inline
97 double
98 DGtal::AccFlower2D<T>::parameter( const RealPoint2D & pp ) const
99 {
100  RealPoint2D p( pp );
101  p -= myCenter;
102 
103  double angle = atan2( p[1], p[0] );
104  angle = ( angle < 0.0 ) ? angle + 2 * M_PI : angle;
105 
106  return angle;
107 }
108 
109 /**
110  * @param t any angle between 0 and 2*Pi.
111  *
112  * @return the vector (x(t),y(t)) which is the position on the
113  * shape boundary.
114  */
115 template <typename T>
116 inline
117 typename DGtal::AccFlower2D<T>::RealPoint2D
118 DGtal::AccFlower2D<T>::x(const double t ) const
119 {
120  double tt =t;
121  while ( tt >= M_PI ) tt -= 2 * M_PI;
122  while ( tt < -M_PI ) tt += 2 * M_PI;
123 
124  double ktn = myKp * tt * tt * tt;
125  double r = myRadius + myVarRadius * cos( ktn );
126  RealPoint2D c( r * cos( tt ), r * sin( tt ) );
127  c += myCenter;
128  return c;
129 }
130 
131 
132 /**
133  * @param t any angle between 0 and 2*Pi.
134  *
135  * @return the vector (x'(t),y'(t)) which is the tangent to the
136  * shape boundary.
137  */
138 template <typename T>
139 inline
140 typename DGtal::AccFlower2D<T>::RealVector2D
141 DGtal::AccFlower2D<T>::xp( const double tt ) const
142 {
143  double t= tt;
144  while ( t >= M_PI ) t -= 2 * M_PI;
145  while ( t < -M_PI ) t += 2 * M_PI;
146 
147  double ktn = myKp * t * t * t;
148  double ktnp = 3 * myKp * t * t ;
149 
150  double r = myRadius + myVarRadius * cos( ktn );
151  double rp = - myVarRadius * sin( ktn ) * ktnp;
152  RealPoint2D c( rp * cos( t ) - r * sin( t ),
153  rp * sin( t ) + r * cos( t ) );
154  return c;
155 }
156 
157 /**
158  * @param t any angle between 0 and 2*Pi.
159  *
160  * @return the vector (x''(t),y''(t)).
161  */
162 template <typename T>
163 inline
164 typename DGtal::AccFlower2D<T>::RealVector2D
165 DGtal::AccFlower2D<T>::xpp( const double tt ) const
166 {
167  double t=tt;
168  while ( t >= M_PI ) t -= 2 * M_PI;
169  while ( t < -M_PI ) t += 2 * M_PI;
170 
171  double ktn = myKp * t * t * t;
172  double ktnp = 3 * myKp * t * t;
173  double ktnpp = 6 * myKp * t;
174 
175  double r = myRadius + myVarRadius * cos( ktn );
176  double rp = - myVarRadius * sin( ktn ) * ktnp;
177  double rpp = - myVarRadius * cos( ktn ) * ktnp * ktnp -
178  myVarRadius * sin( ktn ) * ktnpp;
179 
180  RealPoint2D c( rpp * cos( t ) - 2 * rp * sin( t ) - r * cos( t ),
181  rpp * sin( t ) + 2 * rp * cos( t ) - r * sin( t ) );
182  return c;
183 }
184 
185 
186 ///////////////////////////////////////////////////////////////////////////////
187 // Interface - public :
188 
189 /**
190  * Writes/Displays the object on an output stream.
191  * @param out the output stream where the object is written.
192  */
193 template <typename T>
194 inline
195 void
196 DGtal::AccFlower2D<T>::selfDisplay ( std::ostream & out ) const
197 {
198  out << "[AccFlower2D] center= "<<myCenter<<" radius="<<myRadius<<" smallradius="<<myVarRadius
199  <<" myK="<<myK<<" phase-shift="<<myPhi;
200 }
201 
202 /**
203  * Checks the validity/consistency of the object.
204  * @return 'true' if the object is valid, 'false' otherwise.
205  */
206 template <typename T>
207 inline
208 bool
209 DGtal::AccFlower2D<T>::isValid() const
210 {
211  return true;
212 }
213 
214 
215 
216 ///////////////////////////////////////////////////////////////////////////////
217 // Implementation of inline functions //
218 
219 template <typename T>
220 inline
221 std::ostream&
222 DGtal::operator<< ( std::ostream & out,
223  const AccFlower2D<T> & object )
224 {
225  object.selfDisplay( out );
226  return out;
227 }
228 
229 // //
230 ///////////////////////////////////////////////////////////////////////////////
231 
232