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.
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.
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/>.
18 * @file Naive3DDSSComputer.ih
19 * @author Kacper Pluta (\c kacper.pluta@esiee.fr )
20 * Laboratoire d'Informatique Gaspard-Monge - LIGM, A3SI, France
24 * Implementation of inline methods defined in Naive3DDSSComputer.h
26 * This file is part of the DGtal library.
29///////////////////////////////////////////////////////////////////////////////
30// IMPLEMENTATION of inline methods.
31///////////////////////////////////////////////////////////////////////////////
34///////////////////////////////////////////////////////////////////////////////
35// Implementation of inline methods //
37 * Default constructor.
40template <typename TIterator, typename TInteger, int connectivity>
42DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::Naive3DDSSComputer()
45 std::vector<DGtal::Dimension> v1,v2,v3;
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;
59 * Constructor with initialisation
61template <typename TIterator, typename TInteger, int connectivity>
63DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::Naive3DDSSComputer(const ConstIterator& it)
66 std::vector<DGtal::Dimension> v1,v2,v3;
73 myProjXY.init(v1.begin(),v1.end());
74 myProjXZ.init(v2.begin(),v2.end());
75 myProjYZ.init(v3.begin(),v3.end());
82 * @param it an iterator on a sequence of points
84template <typename TIterator, typename TInteger, int connectivity>
86void DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::init ( const ConstIterator& it )
88 //begin and end iterators
92 //adapters and projections
93 IteratorAdapter XYit(it,myProjXY);
95 IteratorAdapter XZit(it,myProjXZ);
97 IteratorAdapter YZit(it,myProjYZ);
99 blockXY = blockXZ = blockYZ = false;
104 * @param other the object to clone.
105 * Forbidden by default.
107template <typename TIterator, typename TInteger, int connectivity>
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)
115 blockXY = other.blockXY;
116 blockXZ = other.blockXZ;
117 blockYZ = other.blockYZ;
122 * @param other the object to copy.
123 * @return a reference on 'this'.
124 * Forbidden by default.
126template <typename TIterator, typename TInteger, int connectivity>
128DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity> &
129DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::operator= (
130 const Naive3DDSSComputer<TIterator,TInteger,connectivity> & other )
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;
140 blockXY = other.blockXY;
141 blockXZ = other.blockXZ;
142 blockYZ = other.blockYZ;
146template <typename TIterator, typename TInteger, int connectivity>
148typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::Self
149DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::getSelf() const
154template <typename TIterator, typename TInteger, int connectivity>
156typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::Reverse
157DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::getReverse() const
162template <typename TIterator, typename TInteger, int connectivity>
165DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::isInDSS ( const Point3d & point) const
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;
174template <typename TIterator, typename TInteger, int connectivity>
177DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::isInDSS ( const ConstIterator & it) const
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;
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
194template <typename TIterator, typename TInteger, int connectivity>
197DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::operator==(
198 const Naive3DDSSComputer<TIterator,TInteger,connectivity>& other ) const
200 return ( ( ( myXYalgo == other.myXYalgo ) &&
201 ( myXZalgo == other.myXZalgo ) &&
202 ( myYZalgo == other.myYZalgo ) ) ||
203 ( (*myBegin == *other.myBegin) &&
204 (*myEnd == *other.myEnd) ) );
208 * Difference operator.
209 * @param other the object to compare with.
210 * @return 'false' if equal
213template <typename TIterator, typename TInteger, int connectivity>
216DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::operator!=(
217 const Naive3DDSSComputer<TIterator,TInteger,connectivity> & other ) const
219 return (!(*this == other));
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.
231template <typename TIterator, typename TInteger, int connectivity>
234DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::extendFront()
236 if ( !isExtendableFront() ) return false;
239 if ( extendFront ( myXYalgo, blockXY ) ) test++;
240 if ( extendFront ( myXZalgo, blockXZ ) ) test++;
241 if ( extendFront ( myYZalgo, blockYZ ) ) test++;
250template <typename TIterator, typename TInteger, int connectivity>
253DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::extendFront ( ArithmeticalDSSComputer2d & DSS2D, bool & blocked )
255 if ( DSS2D.isExtendableFront() && !blocked )
257 Point2d p = DSS2D.front();
259 if ( DSS2D.front() != p )
263 DSS2D.retractFront();
271/** Tests whether the 3D DSS can be extended at the front.
273 * @return 'true' if yes, 'false' otherwise
275template <typename TIterator, typename TInteger, int connectivity>
278DGtal::Naive3DDSSComputer<TIterator, TInteger,connectivity>::isExtendableFront()
281 if ( myXYalgo.isExtendableFront() && !blockXY ) test++;
282 if ( myXZalgo.isExtendableFront() && !blockXZ ) test++;
283 if ( myYZalgo.isExtendableFront() && !blockYZ ) test++;
287template <typename TIterator, typename TInteger, int connectivity>
290DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::begin() const {
294template <typename TIterator, typename TInteger, int connectivity>
297DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::end() const {
301//-----------------------------------------------------------------
303 * Checks the validity/consistency of the object.
304 * @return 'true' if the object is valid, 'false' otherwise.
307template <typename TIterator, typename TInteger, int connectivity>
310DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::isValid() const
312 return ( ( myXYalgo.isValid() ) &&
313 ( myXZalgo.isValid() ) &&
314 ( myYZalgo.isValid() ) );
318 * Computes the parameters
319 * (direction, intercept, thickness)
322template <typename TIterator, typename TInteger, int connectivity>
325DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>
326::getParameters ( Point3d& direction, PointR3d& intercept, PointR3d& thickness ) const
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
334 Integer a1 = myXYalgo.b();
335 Integer b1 = myXYalgo.a();
336 Integer a2 = myXZalgo.b();
337 Integer c1 = myXZalgo.a();
339 if ( c1 == 0 || ( a1 == 0 && a2 == 0 ) )
340 direction = Point3d ( a1, b1, c1 );
344 direction = Point3d ( a2, b1, c1 );
347 direction = Point3d ( a1 * a2 , a2 * b1 , a1 * c1 );
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 );
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 );
362 if ( lenYZ > lenXZ && lenXY > lenXZ )
363 { //XY-plane, YZ-plane
365 Integer a1 = myXYalgo.b();
366 Integer b1 = myXYalgo.a();
367 Integer b2 = myYZalgo.b();
368 Integer c2 = myYZalgo.a();
370 if ( a1 == 0 || ( b2 == 0 && b1 == 0 ) )
371 direction = Point3d ( a1, b2, c2 );
375 direction = Point3d ( a1, b1, c2 );
378 direction = Point3d ( b2 * a1 , b1 * b2 , b1 * c2 );
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 );
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 );
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();
398 if ( a2 == 0 || ( c2 == 0 && c1 == 0 ) )
399 direction = Point3d ( a2, b2, c2 );
403 direction = Point3d ( a2, b2, c1 );
406 direction = Point3d ( c2 * a2, c1 * b2, c1 * c2 );
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 );
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);
421//-----------------------------------------------------------------------------
422template <typename TIterator, typename TInteger, int connectivity>
424const typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
425DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::arithmeticalDSS2dXY() const
429//-----------------------------------------------------------------------------
430template <typename TIterator, typename TInteger, int connectivity>
432const typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
433DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::arithmeticalDSS2dXZ() const
437//-----------------------------------------------------------------------------
438template <typename TIterator, typename TInteger, int connectivity>
440const typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
441DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::arithmeticalDSS2dYZ() const
445//-----------------------------------------------------------------------------
446template <typename TIterator, typename TInteger, int connectivity>
448const typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
449DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::arithmeticalDSS2d( Dimension i ) const
453 case 0: return myYZalgo; break;
454 case 1: return myXZalgo; break;
455 default: return myXYalgo; break;
459template <typename TIterator, typename TInteger, int connectivity>
462DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::validArithmeticalDSS2d( Dimension i ) const
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 ) )
470 else if ( i == 1 && ( lenXZ >= lenXY || lenXZ >= lenYZ ) )
472 else if ( i == 2 && ( lenXY >= lenXZ || lenXY >= lenYZ ) )
478 * @return the style name used for drawing this object.
480template <typename TIterator, typename TInteger, int connectivity>
483DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::className() const
485 return "Naive3DDSSComputer";
489///////////////////////////////////////////////////////////////////////////////
490// Implementation of inline functions and external operators //
492//------------------------------------------------------------------------------
496 * Writes/Displays the object on an output stream.
497 * @param out the output stream where the object is written.
499template <typename TIterator, typename TInteger, int connectivity>
502DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::selfDisplay ( std::ostream & out)
504 out << "[Naive3DDSSComputer] " << " [XYprojection] " << myXYalgo << " [XZprojection] ";
505 out << myXZalgo << " [YZprojection] " << myYZalgo << " [End Naive3DDSSComputer]" << std::endl;
508///////////////////////////////////////////////////////////////////////////////