DGtal  0.9.2
StandardDSS6Computer.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 StandardDSS6Computer.ih
19  * @author Tristan Roussillon (\c tristan.roussillon@liris.cnrs.fr )
20  * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
21  *
22  * @date 2011/06/01
23  *
24  * Implementation of inline methods defined in StandardDSS6Computer.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 ///////////////////////////////////////////////////////////////////////////////
30 // IMPLEMENTATION of inline methods.
31 ///////////////////////////////////////////////////////////////////////////////
32 
33 //////////////////////////////////////////////////////////////////////////////
34 #include <cstdlib>
35 #include <boost/math/common_factor_rt.hpp>
36 #include "DGtal/io/Color.h"
37 //////////////////////////////////////////////////////////////////////////////
38 
39 
40 
41 
42 
43 ///////////////////////////////////////////////////////////////////////////////
44 // Implementation of inline methods //
45 
46 /**
47  * Default constructor.
48  * not valid
49  */
50 template <typename TIterator, typename TInteger, int connectivity>
51 inline
52 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::StandardDSS6Computer()
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 
70 /**
71  * Constructor with initialisation
72  */
73 template <typename TIterator, typename TInteger, int connectivity>
74 inline
75 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::StandardDSS6Computer(const ConstIterator& it)
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 
93 /**
94  * Initialisation.
95  * @param it an iterator on a sequence of points
96  */
97 template <typename TIterator, typename TInteger, int connectivity>
98 inline
99 void DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::init(const ConstIterator& it)
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 
120 /**
121  * Copy constructor.
122  * @param other the object to clone.
123  * Forbidden by default.
124  */
125 template <typename TIterator, typename TInteger, int connectivity>
126 inline
127 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::StandardDSS6Computer (
128  const StandardDSS6Computer<TIterator,TInteger,connectivity> & other ) :
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 
134 /**
135  * Assignment.
136  * @param other the object to copy.
137  * @return a reference on 'this'.
138  * Forbidden by default.
139  */
140 template <typename TIterator, typename TInteger, int connectivity>
141 inline
142 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity> &
143 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::operator= (
144  const StandardDSS6Computer<TIterator,TInteger,connectivity> & other )
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
161 typename DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::Self
162 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::getSelf() const {
163  return Self();
164 }
165 
166 
167 template <typename TIterator, typename TInteger, int connectivity>
168 inline
169 typename DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::Reverse
170 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::getReverse() const {
171  return Reverse();
172 }
173 
174 
175 
176 
177 
178 /**
179  * Equality operator.
180  * @param other the object to compare with.
181  * @return 'true' either if the points perfectly match
182  * or if the first points match to the last ones
183  * (same DSS scanned in the conversed way)
184  * and 'false' otherwise
185  */
186 template <typename TIterator, typename TInteger, int connectivity>
187 inline
188 bool
189 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::operator==(
190  const StandardDSS6Computer<TIterator,TInteger,connectivity>& other ) const
191 {
192  return ( ( myXYalgo == other.myXYalgo ) &&
193  ( myXZalgo == other.myXZalgo ) &&
194  ( myYZalgo == other.myYZalgo ) &&
195  (*myBegin == *other.myBegin) &&
196  (*myEnd == *other.myEnd) );
197 }
198 
199 /**
200  * Difference operator.
201  * @param other the object to compare with.
202  * @return 'false' if equal
203  * 'true' otherwise
204  */
205 template <typename TIterator, typename TInteger, int connectivity>
206 inline
207 bool
208 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::operator!=(
209  const StandardDSS6Computer<TIterator,TInteger,connectivity> & other ) const
210 {
211  return (!(*this == other));
212 }
213 
214 
215 
216 
217 /**
218  * Tests whether the union between a point
219  * (adding to the front of the DSS
220  * with respect to the scan orientaion)
221  * and a DSS is a DSS.
222  * Computes the parameters of the new DSS
223  * with the adding point if true.
224  * @param it an iterator on a sequence of points
225  * @return 'true' if the union is a DSS, 'false' otherwise.
226  */
227 template <typename TIterator, typename TInteger, int connectivity>
228 inline
229 bool
230 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::extendFront()
231 {
232  if( isExtendableFront() ) {
233 
234  bool XYflag = myXYalgo.extendFront();
235  bool XZflag = myXZalgo.extendFront();
236  bool YZflag = myYZalgo.extendFront();
237  ASSERT( (XYflag)&&(XZflag)&&(YZflag) );
238  boost::ignore_unused_variable_warning(XYflag);
239  boost::ignore_unused_variable_warning(XZflag);
240  boost::ignore_unused_variable_warning(YZflag);
241 
242  myEnd++;
243  return true;
244  } else return false;
245 }
246 
247 
248 
249 /** Tests whether the 3d DSS can be extended at the front.
250  *
251  * @return 'true' if yes, 'false' otherwise
252  */
253 template <typename TIterator, typename TInteger, int connectivity>
254 inline
255 bool
256 DGtal::StandardDSS6Computer<TIterator, TInteger,connectivity>::isExtendableFront()
257 {
258  //projection on xy-plane
259  bool XYflag = myXYalgo.isExtendableFront();
260 
261  //projection on xz-plane
262  bool XZflag = myXZalgo.isExtendableFront();
263 
264  //projection on yz-plane
265  bool YZflag = myYZalgo.isExtendableFront();
266 
267  if ( (XYflag)&&(XZflag)&&(YZflag) )
268  return true;
269  else return false;
270 }
271 
272 
273 
274 
275 template <typename TIterator, typename TInteger, int connectivity>
276 inline
277 TIterator
278 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::begin() const {
279  return myBegin;
280 }
281 
282 template <typename TIterator, typename TInteger, int connectivity>
283 inline
284 TIterator
285 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::end() const {
286  return myEnd;
287 }
288 
289 
290 
291 
292 //-----------------------------------------------------------------
293 /**
294  * Checks the validity/consistency of the object.
295  * @return 'true' if the object is valid, 'false' otherwise.
296  */
297 
298 template <typename TIterator, typename TInteger, int connectivity>
299 inline
300 bool
301 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::isValid() const
302 {
303  return ( (myXYalgo.isValid())&&
304  (myXZalgo.isValid())&&
305  (myYZalgo.isValid()) );
306 }
307 
308 
309 /**
310  * Computes the parameters
311  * (direction, intercept, thickness)
312  * of the DSS
313  * @param direction
314  * @param intercept
315  * @param thickness
316  */
317 template <typename TIterator, typename TInteger, int connectivity>
318 inline
319 void
320 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>
321 ::getParameters ( Point3d& direction, PointR3d& intercept, PointR3d& thickness ) const
322 {
323 
324  //let us take the pair of projection planes for which
325  //the common coordinate of the main vector cannot be 0
326 
327  if (myXYalgo.b() != 0) { //XY-plane, XZ-plane
328 
329  Integer a1 = myXYalgo.b();
330  Integer b1 = myXYalgo.a();
331  Integer a2 = myXZalgo.b();
332  Integer c1 = myXZalgo.a();
333 
334  direction = Point3d(a1*a2,a2*b1,a1*c1);
335 
336  Integer mu1 = myXYalgo.mu();
337  Integer mu2 = myXZalgo.mu();
338  intercept[0] = std::make_pair ( 0, 1 ); intercept[1] = std::make_pair ( -mu1, a1 ); intercept[2] = std::make_pair ( -mu2, a2 );
339 
340  Integer omega1 = myXYalgo.omega()-1;
341  Integer omega2 = myXZalgo.omega()-1;
342  thickness[0] = std::make_pair ( 0, 1 ); thickness[1] = std::make_pair ( -omega1, a1 ); thickness[2] = std::make_pair ( -omega2, a2 );
343 
344  } else {
345 
346  if (myXYalgo.a() != 0) {//XY-plane, YZ-plane
347 
348  Integer a1 = myXYalgo.b();
349  Integer b1 = myXYalgo.a();
350  Integer b2 = myYZalgo.b();
351  Integer c2 = myYZalgo.a();
352 
353  direction = Point3d(b2*a1,b1*b2,b1*c2);
354 
355  Integer mu1 = myXYalgo.mu();
356  Integer mu2 = myYZalgo.mu();
357  intercept[0] = std::make_pair ( mu1, b1 ); intercept[1] = std::make_pair ( 0, 1 ); intercept[2] = std::make_pair ( -mu2, b2 );
358 
359  Integer omega1 = myXYalgo.omega()-1;
360  Integer omega2 = myYZalgo.omega()-1;
361  thickness[0] = std::make_pair ( omega1, b1 ); thickness[1] = std::make_pair ( 0, 1 ); thickness[2] = std::make_pair ( -omega2, b2 );
362 
363  } else {
364 
365  if (myYZalgo.a() != 0) {//YZ-plane, XZ-plane
366 
367  std::cerr << "YZ-XZ" << std::endl;
368 
369  Integer b2 = myYZalgo.b();
370  Integer c2 = myYZalgo.a();
371  Integer a2 = myXZalgo.b();
372  Integer c1 = myXZalgo.a();
373 
374  direction = Point3d(c2*a2,c1*b2,c1*c2);
375 
376  Integer mu1 = myYZalgo.mu();
377  Integer mu2 = myXZalgo.mu();
378  intercept[0] = std::make_pair ( mu2, c1 ); intercept[1] = std::make_pair ( mu1, c2 ); intercept[2] = std::make_pair ( 0, 1 );
379 
380  Integer omega1 = myYZalgo.omega()-1;
381  Integer omega2 = myXZalgo.omega()-1;
382  thickness[0] = std::make_pair ( omega2, c1 ); thickness[1] = std::make_pair ( omega1, c2 ); thickness[2] = std::make_pair ( 0, 1);
383 
384  } else {//degenerated case
385  direction = Point3d(0,0,0);
386  intercept[0] = std::make_pair ( 0, 1 ); intercept[1] = std::make_pair ( 0, 1 ); intercept[2] = std::make_pair ( 0, 1 );
387  thickness[0] = std::make_pair ( 0, 1 ); thickness[1] = std::make_pair ( 0, 1 ); thickness[2] = std::make_pair ( 0, 1);
388  }
389  }
390  }
391 
392 }
393 
394 //-----------------------------------------------------------------------------
395 template <typename TIterator, typename TInteger, int connectivity>
396 inline
397 const typename DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
398 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::arithmeticalDSS2dXY() const
399 {
400  return myXYalgo;
401 }
402 //-----------------------------------------------------------------------------
403 template <typename TIterator, typename TInteger, int connectivity>
404 inline
405 const typename DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
406 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::arithmeticalDSS2dXZ() const
407 {
408  return myXZalgo;
409 }
410 //-----------------------------------------------------------------------------
411 template <typename TIterator, typename TInteger, int connectivity>
412 inline
413 const typename DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
414 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::arithmeticalDSS2dYZ() const
415 {
416  return myYZalgo;
417 }
418 //-----------------------------------------------------------------------------
419 template <typename TIterator, typename TInteger, int connectivity>
420 inline
421 const typename DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
422 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::arithmeticalDSS2d( Dimension i ) const
423 {
424  ASSERT( ( 0 <= i ) && ( i < 3 ) );
425  switch ( i ) {
426  case 0: return myYZalgo; break;
427  case 1: return myXZalgo; break;
428  default: return myXYalgo; break;
429  }
430 }
431 
432 
433 /**
434  * @return the style name used for drawing this object.
435  */
436 template <typename TIterator, typename TInteger, int connectivity>
437 inline
438 std::string
439 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::className() const
440 {
441  return "StandardDSS6Computer";
442 }
443 
444 //------------------------------------------------------------------------------
445 // TEXT DISPLAY
446 
447 /**
448  * Writes/Displays the object on an output stream.
449  * @param out the output stream where the object is written.
450  */
451 template <typename TIterator, typename TInteger, int connectivity>
452 inline
453 void
454 DGtal::StandardDSS6Computer<TIterator,TInteger,connectivity>::selfDisplay ( std::ostream & out) const
455 {
456 
457  out << "[StandardDSS6Computer]" << std::endl;
458  out << "[XYprojection]" << std::endl;
459  out << myXYalgo << std::endl;
460  out << "[XZprojection]" << std::endl;
461  out << myXZalgo << std::endl;
462  out << "[YZprojection]" << std::endl;
463  out << myYZalgo << std::endl;
464  out << "[End StandardDSS6Computer]" << std::endl;
465 
466 }
467 
468 
469 //------------------------------------------------------------------------------
470 // 3D DRAWING
471 
472