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