DGtal  0.9.2
Ball2D.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 Ball2D.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  *
22  * @date 2011/04/12
23  *
24  * Implementation of inline methods defined in Ball2D.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 
30 //////////////////////////////////////////////////////////////////////////////
31 #include <cstdlib>
32 //////////////////////////////////////////////////////////////////////////////
33 
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
40 
41 /**
42  * Destructor.
43  */
44 template <typename T>
45 inline
46 DGtal::Ball2D<T>::~Ball2D()
47 {
48 }
49 
50 template <typename T>
51 inline
52 DGtal::Ball2D<T>::Ball2D(const double x0, const double y0, const double radius):
53  myRadius(radius), myCenter(x0,y0)
54 {}
55 
56 
57 template <typename T>
58 inline
59 DGtal::Ball2D<T>::Ball2D(const RealPoint2D &aPoint, const double radius):
60  myRadius(radius), myCenter(aPoint)
61 {}
62 
63 template <typename T>
64 inline
65 DGtal::Ball2D<T>::Ball2D(const Point &aPoint, const double radius):
66  myRadius(radius)
67 {
68  myCenter = aPoint;
69 }
70 
71 /////////////////////////////////////////////////////////////////////////////
72 // ------------- Implementation of 'StarShaped' services ------------------
73 
74 /**
75  * @param p any point in the plane.
76  *
77  * @return the angle parameter between 0 and 2*Pi corresponding to
78  * this point for the shape.
79  */
80 template <typename T>
81 inline
82 double
83 DGtal::Ball2D<T>::parameter( const RealPoint2D & pp ) const
84 {
85  RealPoint2D p( pp );
86  p -= myCenter;
87 
88  double angle = atan2( p[1], p[0] );
89  angle = ( angle < 0.0 ) ? angle + 2*M_PI : angle;
90 
91  return angle;
92 }
93 
94 /**
95  * @param t any angle between 0 and 2*Pi.
96  *
97  * @return the vector (x(t),y(t)) which is the position on the
98  * shape boundary.
99  */
100 template <typename T>
101 inline
102 typename DGtal::Ball2D<T>::RealPoint2D
103 DGtal::Ball2D<T>::x( double t ) const
104 {
105  RealPoint2D c( myRadius*cos(t), myRadius*sin(t) );
106  c += myCenter;
107  return c;
108 }
109 
110 
111 /**
112  * @param t any angle between 0 and 2*Pi.
113  *
114  * @return the vector (x'(t),y'(t)) which is the tangent to the
115  * shape boundary.
116  */
117 template <typename T>
118 inline
119 typename DGtal::Ball2D<T>::RealVector2D
120 DGtal::Ball2D<T>::xp( const double t ) const
121 {
122  RealVector2D c( -myRadius*sin(t), myRadius*cos(t) );
123  return c;
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::Ball2D<T>::RealVector2D
134 DGtal::Ball2D<T>::xpp( const double t ) const
135 {
136  RealVector2D c( -myRadius*cos(t), -myRadius*sin(t) );
137  return c;
138 }
139 
140 
141 ///////////////////////////////////////////////////////////////////////////////
142 // Interface - public :
143 
144 /**
145  * Writes/Displays the object on an output stream.
146  * @param out the output stream where the object is written.
147  */
148 template <typename T>
149 inline
150 void
151 DGtal::Ball2D<T>::selfDisplay ( std::ostream & out ) const
152 {
153  out << "[Ball2D] center= "<<myCenter<<" radius="<<myRadius;
154 }
155 
156 /**
157  * Checks the validity/consistency of the object.
158  * @return 'true' if the object is valid, 'false' otherwise.
159  */
160 template <typename T>
161 inline
162 bool
163 DGtal::Ball2D<T>::isValid() const
164 {
165  return true;
166 }
167 
168 
169 
170 ///////////////////////////////////////////////////////////////////////////////
171 // Implementation of inline functions //
172 
173 template <typename T>
174 inline
175 std::ostream&
176 DGtal::operator<< ( std::ostream & out,
177  const Ball2D<T> & object )
178 {
179  object.selfDisplay( out );
180  return out;
181 }
182 
183 // //
184 ///////////////////////////////////////////////////////////////////////////////
185 
186