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++;
249 * Ensure that the last segment is maximal in 2D,
250 * so that the corresponding 3D segment results from
251 * the intersection of two maximal 2D segments.
253 while (extendFront ( myXYalgo, blockXY ) );;
254 while (extendFront ( myXZalgo, blockXZ ) );;
255 while (extendFront ( myYZalgo, blockYZ ) );;
260template <typename TIterator, typename TInteger, int connectivity>
263DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::extendFront ( ArithmeticalDSSComputer2d & DSS2D, bool & blocked )
265 if ( DSS2D.isExtendableFront() && !blocked )
267 Point2d p = DSS2D.front();
269 if ( DSS2D.front() != p )
273 DSS2D.retractFront();
281/** Tests whether the 3D DSS can be extended at the front.
283 * @return 'true' if yes, 'false' otherwise
285template <typename TIterator, typename TInteger, int connectivity>
288DGtal::Naive3DDSSComputer<TIterator, TInteger,connectivity>::isExtendableFront()
291 if ( myXYalgo.isExtendableFront() && !blockXY ) test++;
292 if ( myXZalgo.isExtendableFront() && !blockXZ ) test++;
293 if ( myYZalgo.isExtendableFront() && !blockYZ ) test++;
297template <typename TIterator, typename TInteger, int connectivity>
300DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::begin() const {
304template <typename TIterator, typename TInteger, int connectivity>
307DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::end() const {
311//-----------------------------------------------------------------
313 * Checks the validity/consistency of the object.
314 * @return 'true' if the object is valid, 'false' otherwise.
317template <typename TIterator, typename TInteger, int connectivity>
320DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::isValid() const
322 return ( ( myXYalgo.isValid() ) &&
323 ( myXZalgo.isValid() ) &&
324 ( myYZalgo.isValid() ) );
328 * Computes the parameters
329 * (direction, intercept, thickness)
332template <typename TIterator, typename TInteger, int connectivity>
335DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>
336::getParameters ( Point3d& direction, PointR3d& intercept, PointR3d& thickness ) const
338 auto lenXY = std::distance ( myXYalgo.begin(), myXYalgo.end() );
339 auto lenXZ = std::distance ( myXZalgo.begin(), myXZalgo.end() );
340 auto lenYZ = std::distance ( myYZalgo.begin(), myYZalgo.end() );
341 if ( lenXY > lenYZ && lenXZ > lenYZ )
342 { //XY-plane, XZ-plane
344 Integer a1 = myXYalgo.b();
345 Integer b1 = myXYalgo.a();
346 Integer a2 = myXZalgo.b();
347 Integer c1 = myXZalgo.a();
349 if ( c1 == 0 || ( a1 == 0 && a2 == 0 ) )
350 direction = Point3d ( a1, b1, c1 );
354 direction = Point3d ( a2, b1, c1 );
357 direction = Point3d ( a1 * a2 , a2 * b1 , a1 * c1 );
361 Integer mu1 = myXYalgo.mu();
362 Integer mu2 = myXZalgo.mu();
363 intercept[0] = std::make_pair ( 0, 1 ); intercept[1] = std::make_pair ( -mu1, a1 ); intercept[2] = std::make_pair ( -mu2, a2 );
365 Integer omega1 = myXYalgo.omega()-1;
366 Integer omega2 = myXZalgo.omega()-1;
367 thickness[0] = std::make_pair ( 0, 1 ); thickness[1] = std::make_pair ( -omega1, a1 ); thickness[2] = std::make_pair ( -omega2, a2 );
372 if ( lenYZ > lenXZ && lenXY > lenXZ )
373 { //XY-plane, YZ-plane
375 Integer a1 = myXYalgo.b();
376 Integer b1 = myXYalgo.a();
377 Integer b2 = myYZalgo.b();
378 Integer c2 = myYZalgo.a();
380 if ( a1 == 0 || ( b2 == 0 && b1 == 0 ) )
381 direction = Point3d ( a1, b2, c2 );
385 direction = Point3d ( a1, b1, c2 );
388 direction = Point3d ( b2 * a1 , b1 * b2 , b1 * c2 );
392 Integer mu1 = myXYalgo.mu();
393 Integer mu2 = myYZalgo.mu();
394 intercept[0] = std::make_pair ( mu1, b1 ); intercept[1] = std::make_pair ( 0, 1 ); intercept[2] = std::make_pair ( -mu2, b2 );
396 Integer omega1 = myXYalgo.omega()-1;
397 Integer omega2 = myYZalgo.omega()-1;
398 thickness[0] = std::make_pair ( omega1, b1 ); thickness[1] = std::make_pair ( 0, 1 ); thickness[2] = std::make_pair ( -omega2, b2 );
402 { //YZ-plane, XZ-plane
403 Integer b2 = myYZalgo.b();
404 Integer c2 = myYZalgo.a();
405 Integer a2 = myXZalgo.b();
406 Integer c1 = myXZalgo.a();
408 if ( a2 == 0 || ( c2 == 0 && c1 == 0 ) )
409 direction = Point3d ( a2, b2, c2 );
413 direction = Point3d ( a2, b2, c1 );
416 direction = Point3d ( c2 * a2, c1 * b2, c1 * c2 );
420 Integer mu1 = myYZalgo.mu();
421 Integer mu2 = myXZalgo.mu();
422 intercept[0] = std::make_pair ( mu2, c1 ); intercept[1] = std::make_pair ( mu1, c2 ); intercept[2] = std::make_pair ( 0, 1 );
424 Integer omega1 = myYZalgo.omega()-1;
425 Integer omega2 = myXZalgo.omega()-1;
426 thickness[0] = std::make_pair ( omega2, c1 ); thickness[1] = std::make_pair ( omega1, c2 ); thickness[2] = std::make_pair ( 0, 1);
431//-----------------------------------------------------------------------------
432template <typename TIterator, typename TInteger, int connectivity>
434const typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
435DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::arithmeticalDSS2dXY() const
439//-----------------------------------------------------------------------------
440template <typename TIterator, typename TInteger, int connectivity>
442const typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
443DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::arithmeticalDSS2dXZ() const
447//-----------------------------------------------------------------------------
448template <typename TIterator, typename TInteger, int connectivity>
450const typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
451DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::arithmeticalDSS2dYZ() const
455//-----------------------------------------------------------------------------
456template <typename TIterator, typename TInteger, int connectivity>
458const typename DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::ArithmeticalDSSComputer2d &
459DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::arithmeticalDSS2d( Dimension i ) const
463 case 0: return myYZalgo; break;
464 case 1: return myXZalgo; break;
465 default: return myXYalgo; break;
469template <typename TIterator, typename TInteger, int connectivity>
472DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::validArithmeticalDSS2d( Dimension i ) const
475 auto lenXY = std::distance ( myXYalgo.begin(), myXYalgo.end() );
476 auto lenXZ = std::distance ( myXZalgo.begin(), myXZalgo.end() );
477 auto lenYZ = std::distance ( myYZalgo.begin(), myYZalgo.end() );
478 if ( i == 0 && ( lenYZ >= lenXZ || lenYZ >= lenXY ) )
480 else if ( i == 1 && ( lenXZ >= lenXY || lenXZ >= lenYZ ) )
482 else if ( i == 2 && ( lenXY >= lenXZ || lenXY >= lenYZ ) )
488 * @return the style name used for drawing this object.
490template <typename TIterator, typename TInteger, int connectivity>
493DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::className() const
495 return "Naive3DDSSComputer";
499///////////////////////////////////////////////////////////////////////////////
500// Implementation of inline functions and external operators //
502//------------------------------------------------------------------------------
506 * Writes/Displays the object on an output stream.
507 * @param out the output stream where the object is written.
509template <typename TIterator, typename TInteger, int connectivity>
512DGtal::Naive3DDSSComputer<TIterator,TInteger,connectivity>::selfDisplay ( std::ostream & out)
514 out << "[Naive3DDSSComputer] " << " [XYprojection] " << myXYalgo << " [XZprojection] ";
515 out << myXZalgo << " [YZprojection] " << myYZalgo << " [End Naive3DDSSComputer]" << std::endl;
518///////////////////////////////////////////////////////////////////////////////