DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ArithmeticalDSS3d.ih
1 
29 
30 // IMPLEMENTATION of inline methods.
32 
34 #include <cstdlib>
35 #include <boost/math/common_factor_rt.hpp>
36 #include "DGtal/io/Color.h"
38 
39 
40 
41 
42 
44 // Implementation of inline methods //
45 
50 template <typename TIterator, typename TInteger, int connectivity>
51 inline
53 {
54 
55  //projections
56  std::vector<DGtal::Dimension> v1,v2,v3;
57  v1.push_back(0);
58  v1.push_back(1);
59  v2.push_back(0);
60  v2.push_back(2);
61  v3.push_back(1);
62  v3.push_back(2);
63 
64  myProjXY.init(v1.begin(),v1.end());
65  myProjXZ.init(v2.begin(),v2.end());
66  myProjYZ.init(v3.begin(),v3.end());
67 
68 }
69 
73 template <typename TIterator, typename TInteger, int connectivity>
74 inline
76 {
77  //projections
78  std::vector<DGtal::Dimension> v1,v2,v3;
79  v1.push_back(0);
80  v1.push_back(1);
81  v2.push_back(0);
82  v2.push_back(2);
83  v3.push_back(1);
84  v3.push_back(2);
85 
86  myProjXY.init(v1.begin(),v1.end());
87  myProjXZ.init(v2.begin(),v2.end());
88  myProjYZ.init(v3.begin(),v3.end());
89 
90  init(it);
91 }
92 
97 template <typename TIterator, typename TInteger, int connectivity>
98 inline
100 {
101 
102  //begin and end iterators
103  myBegin = it;
104  myEnd = it;
105 
106  myEnd++;
107 
108  //adapters and projections
109  IteratorAdapter XYit(it,myProjXY);
110  myXYalgo.init(XYit);
111 
112  IteratorAdapter XZit(it,myProjXZ);
113  myXZalgo.init(XZit);
114 
115  IteratorAdapter YZit(it,myProjYZ);
116  myYZalgo.init(YZit);
117 
118 }
119 
125 template <typename TIterator, typename TInteger, int connectivity>
126 inline
129  myProjXY(other.myProjXY), myProjXZ(other.myProjXZ), myProjYZ(other.myProjYZ),
130  myXYalgo(other.myXYalgo), myXZalgo(other.myXZalgo), myYZalgo(other.myYZalgo),
131  myBegin(other.myBegin), myEnd(other.myEnd) {}
132 
133 
140 template <typename TIterator, typename TInteger, int connectivity>
141 inline
145 {
146 
147  myProjXY = other.myProjXY;
148  myProjXZ = other.myProjXZ;
149  myProjYZ = other.myProjYZ;
150  myXYalgo = other.myXYalgo;
151  myXZalgo = other.myXZalgo;
152  myYZalgo = other.myYZalgo;
153  myBegin = other.myBegin;
154  myEnd = other.myEnd;
155 
156  return *this;
157 }
158 
159 template <typename TIterator, typename TInteger, int connectivity>
160 inline
163  return Self();
164 }
165 
166 
167 template <typename TIterator, typename TInteger, int connectivity>
168 inline
171  return Reverse();
172 }
173 
174 
175 
176 
177 
186 template <typename TIterator, typename TInteger, int connectivity>
187 inline
188 bool
191 {
192  return ( ( myXYalgo == other.myXYalgo ) &&
193  ( myXZalgo == other.myXZalgo ) &&
194  ( myYZalgo == other.myYZalgo ) &&
195  (*myBegin == *other.myBegin) &&
196  (*myEnd == *other.myEnd) );
197 }
198 
205 template <typename TIterator, typename TInteger, int connectivity>
206 inline
207 bool
210 {
211  return (!(*this == other));
212 }
213 
214 
215 
216 
227 template <typename TIterator, typename TInteger, int connectivity>
228 inline
229 bool
231 {
232  if( isExtendableForward() ) {
233 
234  bool XYflag = myXYalgo.extendForward();
235  bool XZflag = myXZalgo.extendForward();
236  bool YZflag = myYZalgo.extendForward();
237  ASSERT( (XYflag)&&(XZflag)&&(YZflag) );
238 
239  myEnd++;
240  return true;
241  } else return false;
242 }
243 
244 
245 
250 template <typename TIterator, typename TInteger, int connectivity>
251 inline
252 bool
254 {
255  //projection on xy-plane
256  bool XYflag = myXYalgo.isExtendableForward();
257 
258  //projection on xz-plane
259  bool XZflag = myXZalgo.isExtendableForward();
260 
261  //projection on yz-plane
262  bool YZflag = myYZalgo.isExtendableForward();
263 
264  if ( (XYflag)&&(XZflag)&&(YZflag) )
265  return true;
266  else return false;
267 }
268 
269 
270 
271 
272 template <typename TIterator, typename TInteger, int connectivity>
273 inline
274 TIterator
276  return myBegin;
277 }
278 
279 template <typename TIterator, typename TInteger, int connectivity>
280 inline
281 TIterator
283  return myEnd;
284 }
285 
286 
287 
288 
289 //-----------------------------------------------------------------
295 template <typename TIterator, typename TInteger, int connectivity>
296 inline
297 bool
299 {
300  return ( (myXYalgo.isValid())&&
301  (myXZalgo.isValid())&&
302  (myYZalgo.isValid()) );
303 }
304 
305 
314 template <typename TIterator, typename TInteger, int connectivity>
315 inline
316 void
319  PointD3d& intercept,
320  PointD3d& thickness) const
321 {
322 
323  //let us take the pair of projection planes for which
324  //the common coordinate of the main vector cannot be 0
325 
326  if (myXYalgo.getB() != 0) { //XY-plane, XZ-plane
327 
328  Integer a1 = myXYalgo.getB();
329  Integer b1 = myXYalgo.getA();
330  Integer a2 = myXZalgo.getB();
331  Integer c1 = myXZalgo.getA();
332 
333  direction = Point3d(a1*a2,a2*b1,a1*c1);
334 
335  Integer mu1 = myXYalgo.getMu();
336  Integer mu2 = myXZalgo.getMu();
337  double y = (double) -NumberTraits<TInteger>::castToInt64_t(mu1) / a1;
338  double z = (double) -NumberTraits<TInteger>::castToInt64_t(mu2) / a2;
339  intercept = PointD3d(0,y,z);
340 
341  Integer omega1 = myXYalgo.getOmega()-1;
342  Integer omega2 = myXZalgo.getOmega()-1;
343  double ty = (double) -NumberTraits<TInteger>::castToInt64_t(omega1) / a1;
344  double tz = (double) -NumberTraits<TInteger>::castToInt64_t(omega2) / a2;
345  thickness = PointD3d(0,ty,tz);
346 
347  } else {
348 
349  if (myXYalgo.getA() != 0) {//XY-plane, YZ-plane
350 
351  Integer a1 = myXYalgo.getB();
352  Integer b1 = myXYalgo.getA();
353  Integer b2 = myYZalgo.getB();
354  Integer c2 = myYZalgo.getA();
355 
356  direction = Point3d(b1*a1,b1*b2,b2*c2);
357 
358  Integer mu1 = myXYalgo.getMu();
359  Integer mu2 = myYZalgo.getMu();
360  double x = (double) NumberTraits<TInteger>::castToInt64_t(mu1) / b1;
361  double z = (double) -NumberTraits<TInteger>::castToInt64_t(mu2) / b2;
362  intercept = PointD3d(x,0,z);
363 
364  Integer omega1 = myXYalgo.getOmega()-1;
365  Integer omega2 = myYZalgo.getOmega()-1;
366  double tx = (double) NumberTraits<TInteger>::castToInt64_t(omega1) / b1;
367  double tz = (double) -NumberTraits<TInteger>::castToInt64_t(omega2) / b2;
368  thickness = PointD3d(tx,0,tz);
369 
370  } else {
371 
372  if (myYZalgo.getA() != 0) {//YZ-plane, XZ-plane
373 
374  Integer b2 = myYZalgo.getB();
375  Integer c2 = myYZalgo.getA();
376  Integer a2 = myXZalgo.getB();
377  Integer c1 = myXZalgo.getA();
378 
379  direction = Point3d(c2*a2,c1*b2,c1*c2);
380 
381  Integer mu1 = myYZalgo.getMu();
382  Integer mu2 = myXZalgo.getMu();
383  double y = (double) NumberTraits<TInteger>::castToInt64_t(mu1) / c2;
384  double x = (double) NumberTraits<TInteger>::castToInt64_t(mu2) / c1;
385  intercept = PointD3d(x,y,0);
386 
387  Integer omega1 = myYZalgo.getOmega()-1;
388  Integer omega2 = myXZalgo.getOmega()-1;
389  double ty = (double) NumberTraits<TInteger>::castToInt64_t(omega1) / c2;
390  double tx = (double) NumberTraits<TInteger>::castToInt64_t(omega2) / c1;
391  thickness = PointD3d(tx,ty,0);
392 
393  } else {//degenerated case
394  direction = Point3d(0,0,0);
395  intercept = PointD3d(0,0,0);
396  thickness = PointD3d(0,0,0);
397  }
398  }
399  }
400 
401 }
405 template <typename TIterator, typename TInteger, int connectivity>
406 inline
407 std::string
409 {
410  return "ArithmeticalDSS3d";
411 }
412 
413 //------------------------------------------------------------------------------
414 // TEXT DISPLAY
415 
420 template <typename TIterator, typename TInteger, int connectivity>
421 inline
422 void
424 {
425 
426  out << "[ArithmeticalDSS3d]" << endl;
427  out << "[XYprojection]" << endl;
428  out << myXYalgo << endl;
429  out << "[XZprojection]" << endl;
430  out << myXZalgo << endl;
431  out << "[YZprojection]" << endl;
432  out << myYZalgo << endl;
433  out << "[End ArithmeticalDSS3d]" << endl;
434 
435 }
436 
437 
438 //------------------------------------------------------------------------------
439 // 3D DRAWING
440 
441