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.
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.
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/>.
21 * @author Anis Benyoub (\c anis.benyoub@liris.cnrs.fr )
22 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
26 * Header file for module Ball3D.cpp
28 * This file is part of the DGtal library.
32 //////////////////////////////////////////////////////////////////////////////
37 //////////////////////////////////////////////////////////////////////////////
39 #define BALL3D_2_PI (2. * M_PI)
41 ///////////////////////////////////////////////////////////////////////////////
42 // IMPLEMENTATION of inline methods.
43 ///////////////////////////////////////////////////////////////////////////////
45 ///////////////////////////////////////////////////////////////////////////////
46 // ----------------------- Standard services ------------------------------
50 DGtal::Ball3D<T>::Ball3D(const double x0, const double y0, const double z0, const double radius):
51 myRadius(radius), myCenter(x0,y0,z0)
57 DGtal::Ball3D<T>::Ball3D(const RealPoint &aPoint, const double radius):
58 myRadius(radius), myCenter(aPoint)
63 DGtal::Ball3D<T>::Ball3D(const Ball3D& other):
64 myCenter(other.myCenter), myRadius(other.myRadius)
67 /////////////////////////////////////////////////////////////////////////////
68 // ------------- Implementation of 'StarShaped' services ------------------
71 * @param pp any point in the plane.
73 * @return the couple of angle parameters (Teta,Phi) respectivly between [0,2PI] and [0,Pi] corresponding to
74 * this point for the shape.
79 DGtal::Ball3D<T>::parameter( const RealPoint & pp ) const
81 const RealPoint p( pp - myCenter );
82 AngularCoordinates angle;
84 angle.first = atan2( p[1], p[0] );
85 const double tmp = std::min( std::abs(p[2]), 1. );
86 const double pn = p.norm();
87 angle.second = pn > 0. ? acos(tmp/pn) : 0.;
89 angle.first = ( angle.first < 0. ) ? angle.first + BALL3D_2_PI : angle.first;
90 angle.second = ( angle.second < 0. ) ? angle.second + M_PI : angle.second;
96 * @param t any angle between 0 and 2*Pi.
98 * @return the vector (x(t),y(t),z(t)) which is the position on the
101 template <typename T>
103 typename DGtal::Ball3D<T>::RealPoint
104 DGtal::Ball3D<T>::x( const AngularCoordinates& t ) const
107 myRadius * cos(t.first) * sin(t.second) + myCenter[0],
108 myRadius * sin(t.first) * sin(t.second) + myCenter[1],
109 myRadius * cos(t.second) + myCenter[2]
116 * @param t is a couple of Teta && Phi wich are angles respectivly betweend [0,2PI] and [0,Pi].
118 * @return the vector (gradf(M)).
120 template <typename T>
122 typename DGtal::Ball3D<T>::RealPoint
123 DGtal::Ball3D<T>::gradient( const AngularCoordinates& t ) const
125 return 2 * (x(t) - myCenter);
129 * @param t is a couple of Teta && Phi wich are angles respectivly betweend [0,2PI] and [0,Pi].
131 * @return the vector (rt(M)) wich is the first partial derivative with respect to Teta.
133 template <typename T>
135 typename DGtal::Ball3D<T>::RealPoint
136 DGtal::Ball3D<T>::rt( const AngularCoordinates& t ) const
139 -myRadius * sin(t.first) * sin(t.second),
140 myRadius * cos(t.first) * sin(t.second),
148 * @param t is a couple of Teta && Phi wich are angles respectivly betweend [-Pi/2,Pi/2) and [-Pi,Pi].
150 * @return the vector (rp(M)) wich is the first partial derivative with respect to Phi.
152 template <typename T>
154 typename DGtal::Ball3D<T>::RealPoint
155 DGtal::Ball3D<T>::rp( const AngularCoordinates& t ) const
158 myRadius * cos(t.first) * cos(t.second),
159 myRadius * sin(t.first) * cos(t.second),
160 -myRadius * sin(t.second)
166 * @param t is a couple of Teta && Phi wich are angles respectivly betweend [0,2PI] and [0,Pi].
168 * @return the vector (rtt(M)) wich is second the second partial derivative with respect to Teta(twice).
170 template <typename T>
172 typename DGtal::Ball3D<T>::RealPoint
173 DGtal::Ball3D<T>::rtt( const AngularCoordinates& t ) const
176 -myRadius * cos(t.first) * sin(t.second),
177 -myRadius * sin(t.first) * sin(t.second),
185 * @param t is a couple of Teta && Phi wich are angles respectivly betweend [0,2PI] and [0,Pi].
187 * @return the vector (rpp(M)) wich is second the partial derivatif with respect to Phi(twice).
189 template <typename T>
191 typename DGtal::Ball3D<T>::RealPoint
192 DGtal::Ball3D<T>::rpp( const AngularCoordinates& t ) const
195 -myRadius * cos(t.first) * sin(t.second),
196 -myRadius * sin(t.first) * sin(t.second),
197 -myRadius * cos(t.second)
202 * @param t is a couple of Teta && Phi wich are angles respectivly betweend [0,2PI] and [0,Pi]
204 * @return the vector (rtp(M)) wich is second the partial derivatif with respect to Teta then Phi.
206 template <typename T>
208 typename DGtal::Ball3D<T>::RealPoint
209 DGtal::Ball3D<T>::rtp( const AngularCoordinates& t ) const
212 -myRadius * sin(t.first) * cos(t.second),
213 myRadius * cos(t.first) * cos(t.second),
221 ///////////////////////////////////////////////////////////////////////////////
222 // Interface - public :
225 * Writes/Displays the object on an output stream.
226 * @param out the output stream where the object is written.
228 template <typename T>
231 DGtal::Ball3D<T>::selfDisplay ( std::ostream & out ) const
233 out << "[Ball3D] center= " << myCenter
234 << " radius=" << myRadius;
238 * Checks the validity/consistency of the object.
239 * @return 'true' if the object is valid, 'false' otherwise.
241 template <typename T>
244 DGtal::Ball3D<T>::isValid() const
253 ///////////////////////////////////////////////////////////////////////////////
254 // Implementation of inline functions //
256 template <typename T>
259 DGtal::operator<< ( std::ostream & out,
260 const Ball3D<T> & object )
262 object.selfDisplay( out );
267 ///////////////////////////////////////////////////////////////////////////////