DGtal  1.0.0
Flower2D.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 Flower2D.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 Flower2D.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::Flower2D<T>::~Flower2D()
49 {
50 }
51 
52 template <typename T>
53 inline
54 DGtal::Flower2D<T>::Flower2D(const double x0, const double y0,
55  const double radius, const double varRadius,
56  const unsigned int k, const double phi)
57  : myCenter(x0,y0), myRadius(radius), myVarRadius(varRadius), myK(k),myPhi(phi)
58 {}
59 
60 
61 template <typename T>
62 inline
63 DGtal::Flower2D<T>::Flower2D(const RealPoint2D &aPoint, const double radius,
64  const double varRadius,
65  const unsigned int k, const double phi)
66  : myCenter(aPoint), myRadius(radius), myVarRadius(varRadius),
67  myK(k), myPhi(phi)
68 {}
69 
70 template <typename T>
71 inline
72 DGtal::Flower2D<T>::Flower2D(const Point &aPoint, const double radius,
73  const double varRadius,
74  const unsigned int k, const double phi)
75  : myRadius(radius),myVarRadius(varRadius),myK(k),myPhi(phi)
76 {
77  myCenter = aPoint;
78 }
79 
80 /////////////////////////////////////////////////////////////////////////////
81 // ------------- Implementation of 'StarShaped' services ------------------
82 
83 /**
84  * @param p any point in the plane.
85  *
86  * @return the angle parameter between 0 and 2*Pi corresponding to
87  * this point for the shape.
88  */
89 template <typename T>
90 inline
91 double
92 DGtal::Flower2D<T>::parameter( const RealPoint2D & pp ) const
93 {
94  RealPoint2D p( pp );
95  p -= myCenter;
96 
97  double angle = atan2( p[1], p[0] );
98  angle = ( angle < 0.0 ) ? angle + 2*M_PI : angle;
99 
100  return angle;
101 }
102 
103 /**
104  * @param t any angle between 0 and 2*Pi.
105  *
106  * @return the vector (x(t),y(t)) which is the position on the
107  * shape boundary.
108  */
109 template <typename T>
110 inline
111 typename DGtal::Flower2D<T>::RealPoint2D
112 DGtal::Flower2D<T>::x( double t ) const
113 {
114  double r= myRadius+ myVarRadius*cos(myK*t + myPhi);
115  RealPoint2D c( r*cos(t), r*sin(t) );
116  c += myCenter;
117  return c;
118 }
119 
120 
121 /**
122  * @param t any angle between 0 and 2*Pi.
123  *
124  * @return the vector (x'(t),y'(t)) which is the tangent to the
125  * shape boundary.
126  */
127 template <typename T>
128 inline
129 typename DGtal::Flower2D<T>::RealVector2D
130 DGtal::Flower2D<T>::xp( const double t ) const
131 {
132  double r= myRadius+ myVarRadius*cos(myK*t + myPhi);
133  double rp = - myVarRadius * sin( myK * t + myPhi ) * myK;
134  RealVector2D c( rp*cos(t) - r*sin(t),rp*sin(t) + r*cos(t) );
135  return c;
136 }
137 
138 /**
139  * @param t any angle between 0 and 2*Pi.
140  *
141  * @return the vector (x''(t),y''(t)).
142  */
143 template <typename T>
144 inline
145 typename DGtal::Flower2D<T>::RealVector2D
146 DGtal::Flower2D<T>::xpp( const double t ) const
147 {
148  double r= myRadius+ myVarRadius*cos(myK*t + myPhi);
149  double rp = - myVarRadius * sin( myK * t + myPhi ) * myK;
150  double rpp = - myVarRadius * cos( myK * t + myPhi ) * myK * myK;
151  RealVector2D c(rpp * cos( t ) - 2 * rp * sin( t ) - r * cos( t ),
152  rpp * sin( t ) + 2 * rp * cos( t ) - r * sin( t ) );
153  return c;
154 }
155 
156 
157 ///////////////////////////////////////////////////////////////////////////////
158 // Interface - public :
159 
160 /**
161  * Writes/Displays the object on an output stream.
162  * @param out the output stream where the object is written.
163  */
164 template <typename T>
165 inline
166 void
167 DGtal::Flower2D<T>::selfDisplay ( std::ostream & out ) const
168 {
169  out << "[Flower2D] center= "<<myCenter<<" radius="<<myRadius<<" varRadius="<<myVarRadius
170  <<" myK="<<myK<<" phase-shift="<<myPhi;
171 }
172 
173 /**
174  * Checks the validity/consistency of the object.
175  * @return 'true' if the object is valid, 'false' otherwise.
176  */
177 template <typename T>
178 inline
179 bool
180 DGtal::Flower2D<T>::isValid() const
181 {
182  return true;
183 }
184 
185 
186 
187 ///////////////////////////////////////////////////////////////////////////////
188 // Implementation of inline functions //
189 
190 template <typename T>
191 inline
192 std::ostream&
193 DGtal::operator<< ( std::ostream & out,
194  const Flower2D<T> & object )
195 {
196  object.selfDisplay( out );
197  return out;
198 }
199 
200 // //
201 ///////////////////////////////////////////////////////////////////////////////
202 
203