DGtal 1.3.0
Loading...
Searching...
No Matches
Ball3D.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#pragma once
18
19/**
20 * @file Ball3D.ih
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
23 *
24 * @date 2012/06/05
25 *
26 * Header file for module Ball3D.cpp
27 *
28 * This file is part of the DGtal library.
29 */
30
31
32//////////////////////////////////////////////////////////////////////////////
33#include <cstdlib>
34#include <algorithm>
35
36
37//////////////////////////////////////////////////////////////////////////////
38
39#define BALL3D_2_PI (2. * M_PI)
40
41///////////////////////////////////////////////////////////////////////////////
42// IMPLEMENTATION of inline methods.
43///////////////////////////////////////////////////////////////////////////////
44
45///////////////////////////////////////////////////////////////////////////////
46// ----------------------- Standard services ------------------------------
47
48template <typename T>
49inline
50DGtal::Ball3D<T>::Ball3D(const double x0, const double y0, const double z0, const double radius):
51 myRadius(radius), myCenter(x0,y0,z0)
52{}
53
54
55template <typename T>
56inline
57DGtal::Ball3D<T>::Ball3D(const RealPoint &aPoint, const double radius):
58 myRadius(radius), myCenter(aPoint)
59{}
60
61template <typename T>
62inline
63DGtal::Ball3D<T>::Ball3D(const Ball3D& other):
64 myCenter(other.myCenter), myRadius(other.myRadius)
65{}
66
67/////////////////////////////////////////////////////////////////////////////
68// ------------- Implementation of 'StarShaped' services ------------------
69
70/**
71 * @param pp any point in the plane.
72 *
73 * @return the couple of angle parameters (Teta,Phi) respectivly between [0,2PI] and [0,Pi] corresponding to
74 * this point for the shape.
75 */
76template <typename T>
77inline
78AngularCoordinates
79DGtal::Ball3D<T>::parameter( const RealPoint & pp ) const
80{
81 const RealPoint p( pp - myCenter );
82 AngularCoordinates angle;
83
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.;
88
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;
91
92 return angle;
93}
94
95/**
96 * @param t any angle between 0 and 2*Pi.
97 *
98 * @return the vector (x(t),y(t),z(t)) which is the position on the
99 * shape boundary.
100 */
101template <typename T>
102inline
103typename DGtal::Ball3D<T>::RealPoint
104DGtal::Ball3D<T>::x( const AngularCoordinates& t ) const
105{
106 return RealPoint(
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]
110 );
111}
112
113
114
115/**
116 * @param t is a couple of Teta && Phi wich are angles respectivly betweend [0,2PI] and [0,Pi].
117 *
118 * @return the vector (gradf(M)).
119 */
120template <typename T>
121inline
122typename DGtal::Ball3D<T>::RealPoint
123DGtal::Ball3D<T>::gradient( const AngularCoordinates& t ) const
124{
125 return 2 * (x(t) - myCenter);
126}
127
128/**
129 * @param t is a couple of Teta && Phi wich are angles respectivly betweend [0,2PI] and [0,Pi].
130 *
131 * @return the vector (rt(M)) wich is the first partial derivative with respect to Teta.
132 */
133template <typename T>
134inline
135typename DGtal::Ball3D<T>::RealPoint
136DGtal::Ball3D<T>::rt( const AngularCoordinates& t ) const
137{
138 return RealPoint(
139 -myRadius * sin(t.first) * sin(t.second),
140 myRadius * cos(t.first) * sin(t.second),
141 0
142 );
143}
144
145
146
147/**
148 * @param t is a couple of Teta && Phi wich are angles respectivly betweend [-Pi/2,Pi/2) and [-Pi,Pi].
149 *
150 * @return the vector (rp(M)) wich is the first partial derivative with respect to Phi.
151 */
152template <typename T>
153inline
154typename DGtal::Ball3D<T>::RealPoint
155DGtal::Ball3D<T>::rp( const AngularCoordinates& t ) const
156{
157 return RealPoint(
158 myRadius * cos(t.first) * cos(t.second),
159 myRadius * sin(t.first) * cos(t.second),
160 -myRadius * sin(t.second)
161 );
162}
163
164
165/**
166 * @param t is a couple of Teta && Phi wich are angles respectivly betweend [0,2PI] and [0,Pi].
167 *
168 * @return the vector (rtt(M)) wich is second the second partial derivative with respect to Teta(twice).
169 */
170template <typename T>
171inline
172typename DGtal::Ball3D<T>::RealPoint
173DGtal::Ball3D<T>::rtt( const AngularCoordinates& t ) const
174{
175 return RealPoint(
176 -myRadius * cos(t.first) * sin(t.second),
177 -myRadius * sin(t.first) * sin(t.second),
178 0.
179 );
180}
181
182
183
184/**
185 * @param t is a couple of Teta && Phi wich are angles respectivly betweend [0,2PI] and [0,Pi].
186 *
187 * @return the vector (rpp(M)) wich is second the partial derivatif with respect to Phi(twice).
188 */
189template <typename T>
190inline
191typename DGtal::Ball3D<T>::RealPoint
192DGtal::Ball3D<T>::rpp( const AngularCoordinates& t ) const
193{
194 return RealPoint(
195 -myRadius * cos(t.first) * sin(t.second),
196 -myRadius * sin(t.first) * sin(t.second),
197 -myRadius * cos(t.second)
198 );
199}
200
201/**
202 * @param t is a couple of Teta && Phi wich are angles respectivly betweend [0,2PI] and [0,Pi]
203 *
204 * @return the vector (rtp(M)) wich is second the partial derivatif with respect to Teta then Phi.
205 */
206template <typename T>
207inline
208typename DGtal::Ball3D<T>::RealPoint
209DGtal::Ball3D<T>::rtp( const AngularCoordinates& t ) const
210{
211 return RealPoint(
212 -myRadius * sin(t.first) * cos(t.second),
213 myRadius * cos(t.first) * cos(t.second),
214 0.
215 );
216}
217
218
219
220
221///////////////////////////////////////////////////////////////////////////////
222// Interface - public :
223
224/**
225 * Writes/Displays the object on an output stream.
226 * @param out the output stream where the object is written.
227 */
228template <typename T>
229inline
230void
231DGtal::Ball3D<T>::selfDisplay ( std::ostream & out ) const
232{
233 out << "[Ball3D] center= " << myCenter
234 << " radius=" << myRadius;
235}
236
237/**
238 * Checks the validity/consistency of the object.
239 * @return 'true' if the object is valid, 'false' otherwise.
240 */
241template <typename T>
242inline
243bool
244DGtal::Ball3D<T>::isValid() const
245{
246 return true;
247}
248
249
250
251
252
253///////////////////////////////////////////////////////////////////////////////
254// Implementation of inline functions //
255
256template <typename T>
257inline
258std::ostream&
259DGtal::operator<< ( std::ostream & out,
260 const Ball3D<T> & object )
261{
262 object.selfDisplay( out );
263 return out;
264}
265
266// //
267///////////////////////////////////////////////////////////////////////////////