DGtal 1.4.0
Loading...
Searching...
No Matches
Naive3DDSSComputer.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 Naive3DDSSComputer.ih
19 * @author Kacper Pluta (\c kacper.pluta@esiee.fr )
20 * Laboratoire d'Informatique Gaspard-Monge - LIGM, A3SI, France
21 *
22 * @date 2014/10/07
23 *
24 * Implementation of inline methods defined in Naive3DDSSComputer.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29///////////////////////////////////////////////////////////////////////////////
30// IMPLEMENTATION of inline methods.
31///////////////////////////////////////////////////////////////////////////////
32
33
34///////////////////////////////////////////////////////////////////////////////
35// Implementation of inline methods //
36/**
37 * Default constructor.
38 * not valid
39 */
40template <typename TIterator, typename TInteger, int connectivity>
41inline
42DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::Naive3DDSSComputer()
43{
44 //projections
45 std::vector<DGtal::Dimension> v1,v2,v3;
46 v1.push_back(0);
47 v1.push_back(1);
48 v2.push_back(0);
49 v2.push_back(2);
50 v3.push_back(1);
51 v3.push_back(2);
52 myProjXY.init(v1.begin(),v1.end());
53 myProjXZ.init(v2.begin(),v2.end());
54 myProjYZ.init(v3.begin(),v3.end());
55 blockXY = blockXZ = blockYZ = false;
56}
57
58/**
59 * Constructor with initialisation
60 */
61template <typename TIterator, typename TInteger, int connectivity>
62inline
63DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::Naive3DDSSComputer(const ConstIterator& it)
64{
65 //projections
66 std::vector<DGtal::Dimension> v1,v2,v3;
67 v1.push_back(0);
68 v1.push_back(1);
69 v2.push_back(0);
70 v2.push_back(2);
71 v3.push_back(1);
72 v3.push_back(2);
73 myProjXY.init(v1.begin(),v1.end());
74 myProjXZ.init(v2.begin(),v2.end());
75 myProjYZ.init(v3.begin(),v3.end());
76
77 init(it);
78}
79
80/**
81 * Initialisation.
82 * @param it an iterator on a sequence of points
83 */
84template <typename TIterator, typename TInteger, int connectivity>
85inline
86void DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::init ( const ConstIterator& it )
87{
88 //begin and end iterators
89 myBegin = it;
90 myEnd = it;
91 myEnd++;
92 //adapters and projections
93 IteratorAdapter XYit(it,myProjXY);
94 myXYalgo.init(XYit);
95 IteratorAdapter XZit(it,myProjXZ);
96 myXZalgo.init(XZit);
97 IteratorAdapter YZit(it,myProjYZ);
98 myYZalgo.init(YZit);
99 blockXY = blockXZ = blockYZ = false;
100}
101
102/**
103 * Copy constructor.
104 * @param other the object to clone.
105 * Forbidden by default.
106 */
107template <typename TIterator, typename TInteger, int connectivity>
108inline
109DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::Naive3DDSSComputer (
110 const Naive3DDSSComputer<TIterator,TInteger,connectivity> & other ) :
111 myProjXY(other.myProjXY), myProjXZ(other.myProjXZ), myProjYZ(other.myProjYZ),
112 myXYalgo(other.myXYalgo), myXZalgo(other.myXZalgo), myYZalgo(other.myYZalgo),
113 myBegin(other.myBegin), myEnd(other.myEnd)
114{
115 blockXY = other.blockXY;
116 blockXZ = other.blockXZ;
117 blockYZ = other.blockYZ;
118}
119
120/**
121 * Assignment.
122 * @param other the object to copy.
123 * @return a reference on 'this'.
124 * Forbidden by default.
125 */
126template <typename TIterator, typename TInteger, int connectivity>
127inline
128DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity> &
129DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::operator= (
130 const Naive3DDSSComputer<TIterator,TInteger,connectivity> & other )
131{
132 myProjXY = other.myProjXY;
133 myProjXZ = other.myProjXZ;
134 myProjYZ = other.myProjYZ;
135 myXYalgo = other.myXYalgo;
136 myXZalgo = other.myXZalgo;
137 myYZalgo = other.myYZalgo;
138 myBegin = other.myBegin;
139 myEnd = other.myEnd;
140 blockXY = other.blockXY;
141 blockXZ = other.blockXZ;
142 blockYZ = other.blockYZ;
143 return *this;
144}
145
146template <typename TIterator, typename TInteger, int connectivity>
147inline
148typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::Self
149DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::getSelf() const
150{
151 return Self();
152}
153
154template <typename TIterator, typename TInteger, int connectivity>
155inline
156typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::Reverse
157DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::getReverse() const
158{
159 return Reverse();
160}
161
162template <typename TIterator, typename TInteger, int connectivity>
163inline
164bool
165DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::isInDSS ( const Point3d & point) const
166{
167 char test = 0;
168 if ( myXYalgo.isInDSS ( myProjXY ( point ) ) ) test++;
169 if ( myXZalgo.isInDSS ( myProjXZ ( point ) ) ) test++;
170 if ( myYZalgo.isInDSS ( myProjYZ ( point ) ) ) test++;
171 return test >= 2 ? true : false;
172}
173
174template <typename TIterator, typename TInteger, int connectivity>
175inline
176bool
177DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::isInDSS ( const ConstIterator & it) const
178{
179 char test = 0;
180 if ( myXYalgo.isInDSS ( myProjXY ( *it ) ) ) test++;
181 if ( myXZalgo.isInDSS ( myProjXZ ( *it ) ) ) test++;
182 if ( myYZalgo.isInDSS ( myProjYZ ( *it ) ) ) test++;
183 return test >= 2 ? true : false;
184}
185
186/**
187 * Equality operator.
188 * @param other the object to compare with.
189 * @return 'true' either if the points perfectly match
190 * or if the first points match to the last ones
191 * (same DSS scanned in the conversed way)
192 * and 'false' otherwise
193 */
194template <typename TIterator, typename TInteger, int connectivity>
195inline
196bool
197DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::operator==(
198 const Naive3DDSSComputer<TIterator,TInteger,connectivity>& other ) const
199{
200 return ( ( ( myXYalgo == other.myXYalgo ) &&
201 ( myXZalgo == other.myXZalgo ) &&
202 ( myYZalgo == other.myYZalgo ) ) ||
203 ( (*myBegin == *other.myBegin) &&
204 (*myEnd == *other.myEnd) ) );
205}
206
207/**
208 * Difference operator.
209 * @param other the object to compare with.
210 * @return 'false' if equal
211 * 'true' otherwise
212 */
213template <typename TIterator, typename TInteger, int connectivity>
214inline
215bool
216DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::operator!=(
217 const Naive3DDSSComputer<TIterator,TInteger,connectivity> & other ) const
218{
219 return (!(*this == other));
220}
221
222/**
223 * Tests whether the union between a point
224 * (add to the front of the DSS
225 * with respect to the scan orientation)
226 * and a DSS is a DSS.
227 * Computes the parameters of the new DSS
228 * with the added point if true.
229 * @return 'true' if the union is a DSS, 'false' otherwise.
230 */
231template <typename TIterator, typename TInteger, int connectivity>
232inline
233bool
234DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::extendFront()
235{
236 if ( !isExtendableFront() ) return false;
237
238 char test = 0;
239 if ( extendFront ( myXYalgo, blockXY ) ) test++;
240 if ( extendFront ( myXZalgo, blockXZ ) ) test++;
241 if ( extendFront ( myYZalgo, blockYZ ) ) test++;
242 if ( test >= 2 )
243 {
244 myEnd++;
245 return true;
246 }
247 return test == 1;
248}
249
250template <typename TIterator, typename TInteger, int connectivity>
251inline
252bool
253DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::extendFront ( ArithmeticalDSSComputer2d & DSS2D, bool & blocked )
254{
255 if ( DSS2D.isExtendableFront() && !blocked )
256 {
257 Point2d p = DSS2D.front();
258 DSS2D.extendFront();
259 if ( DSS2D.front() != p )
260 return true;
261 else
262 {
263 DSS2D.retractFront();
264 blocked = true;
265 return false;
266 }
267 }
268 return false;
269}
270
271/** Tests whether the 3D DSS can be extended at the front.
272 *
273 * @return 'true' if yes, 'false' otherwise
274 */
275template <typename TIterator, typename TInteger, int connectivity>
276inline
277bool
278DGtal::Naive3DDSSComputer<TIterator, TInteger,connectivity>::isExtendableFront()
279{
280 char test = 0;
281 if ( myXYalgo.isExtendableFront() && !blockXY ) test++;
282 if ( myXZalgo.isExtendableFront() && !blockXZ ) test++;
283 if ( myYZalgo.isExtendableFront() && !blockYZ ) test++;
284 return test >= 2;
285}
286
287template <typename TIterator, typename TInteger, int connectivity>
288inline
289TIterator
290DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::begin() const {
291 return myBegin;
292}
293
294template <typename TIterator, typename TInteger, int connectivity>
295inline
296TIterator
297DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::end() const {
298 return myEnd;
299}
300
301//-----------------------------------------------------------------
302/**
303 * Checks the validity/consistency of the object.
304 * @return 'true' if the object is valid, 'false' otherwise.
305 */
306
307template <typename TIterator, typename TInteger, int connectivity>
308inline
309bool
310DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::isValid() const
311{
312 return ( ( myXYalgo.isValid() ) &&
313 ( myXZalgo.isValid() ) &&
314 ( myYZalgo.isValid() ) );
315}
316
317/**
318 * Computes the parameters
319 * (direction, intercept, thickness)
320 * of the DSS
321 */
322template <typename TIterator, typename TInteger, int connectivity>
323inline
324void
325DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>
326::getParameters ( Point3d& direction, PointR3d& intercept, PointR3d& thickness ) const
327{
328 auto lenXY = std::distance ( myXYalgo.begin(), myXYalgo.end() );
329 auto lenXZ = std::distance ( myXZalgo.begin(), myXZalgo.end() );
330 auto lenYZ = std::distance ( myYZalgo.begin(), myYZalgo.end() );
331 if ( lenXY > lenYZ && lenXZ > lenYZ )
332 { //XY-plane, XZ-plane
333
334 Integer a1 = myXYalgo.b();
335 Integer b1 = myXYalgo.a();
336 Integer a2 = myXZalgo.b();
337 Integer c1 = myXZalgo.a();
338
339 if ( c1 == 0 || ( a1 == 0 && a2 == 0 ) )
340 direction = Point3d ( a1, b1, c1 );
341 else
342 {
343 if ( b1 == 0 )
344 direction = Point3d ( a2, b1, c1 );
345 else
346 {
347 direction = Point3d ( a1 * a2 , a2 * b1 , a1 * c1 );
348 }
349 }
350
351 Integer mu1 = myXYalgo.mu();
352 Integer mu2 = myXZalgo.mu();
353 intercept[0] = std::make_pair ( 0, 1 ); intercept[1] = std::make_pair ( -mu1, a1 ); intercept[2] = std::make_pair ( -mu2, a2 );
354
355 Integer omega1 = myXYalgo.omega()-1;
356 Integer omega2 = myXZalgo.omega()-1;
357 thickness[0] = std::make_pair ( 0, 1 ); thickness[1] = std::make_pair ( -omega1, a1 ); thickness[2] = std::make_pair ( -omega2, a2 );
358
359 }
360 else
361 {
362 if ( lenYZ > lenXZ && lenXY > lenXZ )
363 { //XY-plane, YZ-plane
364
365 Integer a1 = myXYalgo.b();
366 Integer b1 = myXYalgo.a();
367 Integer b2 = myYZalgo.b();
368 Integer c2 = myYZalgo.a();
369
370 if ( a1 == 0 || ( b2 == 0 && b1 == 0 ) )
371 direction = Point3d ( a1, b2, c2 );
372 else
373 {
374 if ( c2 == 0 )
375 direction = Point3d ( a1, b1, c2 );
376 else
377 {
378 direction = Point3d ( b2 * a1 , b1 * b2 , b1 * c2 );
379 }
380 }
381
382 Integer mu1 = myXYalgo.mu();
383 Integer mu2 = myYZalgo.mu();
384 intercept[0] = std::make_pair ( mu1, b1 ); intercept[1] = std::make_pair ( 0, 1 ); intercept[2] = std::make_pair ( -mu2, b2 );
385
386 Integer omega1 = myXYalgo.omega()-1;
387 Integer omega2 = myYZalgo.omega()-1;
388 thickness[0] = std::make_pair ( omega1, b1 ); thickness[1] = std::make_pair ( 0, 1 ); thickness[2] = std::make_pair ( -omega2, b2 );
389
390 }
391 else
392 { //YZ-plane, XZ-plane
393 Integer b2 = myYZalgo.b();
394 Integer c2 = myYZalgo.a();
395 Integer a2 = myXZalgo.b();
396 Integer c1 = myXZalgo.a();
397
398 if ( a2 == 0 || ( c2 == 0 && c1 == 0 ) )
399 direction = Point3d ( a2, b2, c2 );
400 else
401 {
402 if ( b2 == 0 )
403 direction = Point3d ( a2, b2, c1 );
404 else
405 {
406 direction = Point3d ( c2 * a2, c1 * b2, c1 * c2 );
407 }
408 }
409
410 Integer mu1 = myYZalgo.mu();
411 Integer mu2 = myXZalgo.mu();
412 intercept[0] = std::make_pair ( mu2, c1 ); intercept[1] = std::make_pair ( mu1, c2 ); intercept[2] = std::make_pair ( 0, 1 );
413
414 Integer omega1 = myYZalgo.omega()-1;
415 Integer omega2 = myXZalgo.omega()-1;
416 thickness[0] = std::make_pair ( omega2, c1 ); thickness[1] = std::make_pair ( omega1, c2 ); thickness[2] = std::make_pair ( 0, 1);
417 }
418 }
419}
420
421//-----------------------------------------------------------------------------
422template <typename TIterator, typename TInteger, int connectivity>
423inline
424const typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
425DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::arithmeticalDSS2dXY() const
426{
427 return myXYalgo;
428}
429//-----------------------------------------------------------------------------
430template <typename TIterator, typename TInteger, int connectivity>
431inline
432const typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
433DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::arithmeticalDSS2dXZ() const
434{
435 return myXZalgo;
436}
437//-----------------------------------------------------------------------------
438template <typename TIterator, typename TInteger, int connectivity>
439inline
440const typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
441DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::arithmeticalDSS2dYZ() const
442{
443 return myYZalgo;
444}
445//-----------------------------------------------------------------------------
446template <typename TIterator, typename TInteger, int connectivity>
447inline
448const typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
449DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::arithmeticalDSS2d( Dimension i ) const
450{
451 ASSERT( i < 3 );
452 switch ( i ) {
453 case 0: return myYZalgo; break;
454 case 1: return myXZalgo; break;
455 default: return myXYalgo; break;
456 }
457}
458
459template <typename TIterator, typename TInteger, int connectivity>
460inline
461bool
462DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::validArithmeticalDSS2d( Dimension i ) const
463{
464 ASSERT( i < 3 );
465 auto lenXY = std::distance ( myXYalgo.begin(), myXYalgo.end() );
466 auto lenXZ = std::distance ( myXZalgo.begin(), myXZalgo.end() );
467 auto lenYZ = std::distance ( myYZalgo.begin(), myYZalgo.end() );
468 if ( i == 0 && ( lenYZ >= lenXZ || lenYZ >= lenXY ) )
469 return true;
470 else if ( i == 1 && ( lenXZ >= lenXY || lenXZ >= lenYZ ) )
471 return true;
472 else if ( i == 2 && ( lenXY >= lenXZ || lenXY >= lenYZ ) )
473 return true;
474 return false;
475}
476
477/**
478 * @return the style name used for drawing this object.
479 */
480template <typename TIterator, typename TInteger, int connectivity>
481inline
482std::string
483DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::className() const
484{
485 return "Naive3DDSSComputer";
486}
487
488
489///////////////////////////////////////////////////////////////////////////////
490// Implementation of inline functions and external operators //
491
492//------------------------------------------------------------------------------
493// TEXT DISPLAY
494
495/**
496 * Writes/Displays the object on an output stream.
497 * @param out the output stream where the object is written.
498 */
499template <typename TIterator, typename TInteger, int connectivity>
500inline
501void
502DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::selfDisplay ( std::ostream & out)
503{
504 out << "[Naive3DDSSComputer] " << " [XYprojection] " << myXYalgo << " [XZprojection] ";
505 out << myXZalgo << " [YZprojection] " << myYZalgo << " [End Naive3DDSSComputer]" << std::endl;
506}
507// //
508///////////////////////////////////////////////////////////////////////////////
509
510