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