DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StarShaped3D.ih
1 
30 
31 #include <cstdlib>
32 #include <iostream>
34 
36 // IMPLEMENTATION of inline methods.
38 
40 // ----------------------- Standard services ------------------------------
41 
42 typedef pair<double,double> AngularCoordinates;
44 // ------------------------- star-shaped services -------------------------
45 
46 
47 
48 
55 template<typename TSpace>
56 inline
57 bool
59 {
60  AngularCoordinates t = parameter( p );
61  RealPoint x_rel = x( t );
62  x_rel -= center();
63  double d_x = x_rel[0]*x_rel[0] + x_rel[1]*x_rel[1] + x_rel[2]*x_rel[2];
64  RealPoint p_rel( p );
65  p_rel -= center();
66  double d_p = p_rel[0]*p_rel[0] + p_rel[1]*p_rel[1]+ p_rel[2]*p_rel[2];
67 
68  return d_p <= d_x;
69 }
70 
71 
72 
73 
74 
75 
76 
77 
84 template<typename TSpace>
85 inline
88 {
89 
90 
91  AngularCoordinates t = parameter( p );
92  RealPoint x_rel = x( t );
93  x_rel -= center();
94  double d_x = x_rel[0]*x_rel[0] + x_rel[1]*x_rel[1] + x_rel[2]*x_rel[2];
95  RealPoint p_rel( p );
96  p_rel -= center();
97  double d_p = p_rel[0]*p_rel[0] + p_rel[1]*p_rel[1] + p_rel[2]*p_rel[2];
98 
99 
100  if ((d_p - d_x) > 0.0)
101  return OUTSIDE;
102  else
103  if ((d_p - d_x )< 0.0)
104  return INSIDE;
105  else
106  return ON;
107 }
108 
109 
116 template<typename TSpace>
117 inline
120 {
121  RealPoint aNormal( gradient(t));
122  double norm = sqrt(aNormal[0]*aNormal[0] + aNormal[1]*aNormal[1] +aNormal[2]*aNormal[2]);
123  return (RealPoint(aNormal[0]/norm,aNormal[1]/norm,aNormal[2]/norm));
124 }
125 
126 
134 template<typename TSpace>
135 inline
136 double
138 {
139  typedef typename Space::RealPoint RealPoint;
140 
141 
142  RealPoint art = rt(t);
143  RealPoint arp = rp(t);
144  RealPoint artt = rtt(t);
145  RealPoint arpp = rpp(t);
146  RealPoint artp = rtp(t);
147 
148  RealPoint n(art[1]*arp[2]-art[2]*arp[1],art[2]*arp[0]-art[0]*arp[2],art[0]*arp[1]-art[1]*arp[0]);
149  double norme= sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]);
150  n[0]=n[0]/norme;
151  n[1]=n[1]/norme;
152  n[2]=n[2]/norme;
153  double E = art[0] * art[0]+ art[1] * art[1]+ art[2] * art[2];
154  double F= art[0] * arp[0]+ art[1] * arp[1]+ art[2] * arp[2];
155  double G = arp[0] * arp[0]+ arp[1] * arp[1]+ arp[2] * arp[2];
156  double L = artt[0] * n[0]+ artt[1] * n[1]+ artt[2] * n[2];
157  double M = artp[0] * n[0]+ artp[1] * n[1]+ artp[2] * n[2];
158  double N = arpp[0] * n[0]+ arpp[1] * n[1]+ arpp[2] * n[2];
159  double H = (E*N-2.0f*F*M+G*L)/(2.0f*(E*G-F*F));
160 
161 
162  return H;
163 }
164 
165 
166 
167 
175 template<typename TSpace>
176 inline
177 double
179 {
180 
181  typedef typename Space::RealPoint RealPoint;
182 
183  RealPoint art = rt(t);
184  RealPoint arp = rp(t);
185  RealPoint artt = rtt(t);
186  RealPoint arpp = rpp(t);
187  RealPoint artp = rtp(t);
188 
189 
190  RealPoint n(art[1]*arp[2]-art[2]*arp[1],art[2]*arp[0]-art[0]*arp[2],art[0]*arp[1]-art[1]*arp[0]);
191  double norme= sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]);
192  n[0]=n[0]/norme;
193  n[1]=n[1]/norme;
194  n[2]=n[2]/norme;
195  double E = art[0] * art[0]+ art[1] * art[1]+ art[2] * art[2];
196  double F= art[0] * arp[0]+ art[1] * arp[1]+ art[2] * arp[2];
197  double G = arp[0] * arp[0]+ arp[1] * arp[1]+ arp[2] * arp[2];
198  double L = artt[0] * n[0]+ artt[1] * n[1]+ artt[2] * n[2];
199  double M = artp[0] * n[0]+ artp[1] * n[1]+ artp[2] * n[2];
200  double N = arpp[0] * n[0]+ arpp[1] * n[1]+ arpp[2] * n[2];
201 
202  double K = (L*N-M*M)/(E*G-F*F);
203 
204  return K;
205 }
206 
207 
208 
215 template<typename TSpace>
216 inline
217 double
219 {
220  while ( t2.first < t1.first ) t2.first += 2.0*M_PI;
221  while ( t2.second < t1.second ) t2.second += 2.0*M_PI;
222 
223  RealPoint x0( x( t1 ) );
224  double l = 0.0;
225  for ( unsigned int i = 1; i <= nb; ++i )
226  {
228  t.first = ( ( t2.first - t1.first ) * i ) / nb;
229  t.second = ( ( t2.second - t1.second ) * i ) / nb;
231  h.first=t1.first + t.first;
232  h.second=t1.second + t.second;
233  RealPoint x1( x( h ) );
234  l += sqrt( ( x1[0] - x0[0] )*( x1[0] - x0[0] )
235  + ( x1[1] - x0[1] )*( x1[1] - x0[1] ) + ( x1[2] - x0[2] )*( x1[2] - x0[2] ) );
236  x0 = x1;
237  }
238  return l;
239 }
240 
241 
248 template<typename TSpace>
249 inline
250 double
252 {
253  while ( t2.first < t1.first ) t2.first += 2.0*M_PI;
254  while ( t2.second < t1.second ) t2.second += 2.0*M_PI;
255 
256  double step1 = ( t2.first - t1.first ) / nb;
257  double step2 = ( t2.second - t1.second ) / nb;
258  AngularCoordinates t( make_pair(0.0,0.0));
259  double l = 0.0;
260  for ( unsigned int i = 0; i < nb; ++i )
261  {
262  t.first = step1 *i;
263  for ( unsigned int j = 0; j < nb; ++j )
264  {
265 
266  t.second = step2 * j;
267  RealPoint xtp (x( make_pair( t1.first + t.first - step1 ,t1.second + t.second - step2 ) ));
268  RealPoint xt1p1( x( make_pair(t1.first + t.first,t1.second + t.second) ) );
269  RealPoint xt1p( x( make_pair(t1.first + t.first,t1.second + t.second- step2 ) ) );
270  double D = sqrt( ( xt1p[0] - xtp[0] )*( xt1p[0] - xtp[0] ) +
271  ( xt1p[1] - xtp[1] )*( xt1p[1] - xtp[1] ) +
272  ( xt1p[2] - xtp[2] )*( xt1p[2] - xtp[2] ));
273  double d = sqrt( ( xt1p1[0] - xt1p[0] )*( xt1p1[0] - xt1p[0] ) +
274  ( xt1p1[1] - xt1p[1] )*( xt1p1[1] - xt1p[1] ) +
275  ( xt1p1[2] - xt1p[2] )*( xt1p1[2] - xt1p[2] ));
276 
277 
278  l += (d*D);
279  }
280  }
281  return l;
282 }
283 
284 
285 
289 template <typename T>
290 inline
292 {
293 }
294 
296 // Interface - public :
297 
302 template <typename T>
303 inline
304 void
305 DGtal::StarShaped3D<T>::selfDisplay ( std::ostream & out ) const
306 {
307  out << "[StarShaped2D]";
308 }
309 
314 template <typename T>
315 inline
316 bool
318 {
319  return true;
320 }
321 
322 
323 
325 // Implementation of inline functions //
326 
327 template <typename T>
328 inline
329 std::ostream&
330 DGtal::operator<< ( std::ostream & out,
331  const StarShaped3D<T> & object )
332 {
333  object.selfDisplay( out );
334  return out;
335 }
336 
337 // //