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 MostCenteredMaximalSegmentEstimator.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
24 * Implementation of inline methods defined in MostCenteredMaximalSegmentEstimator.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
41 // ------------------------------------------------------------------------
42 template <typename SegmentComputer, typename SCEstimator>
44 DGtal::MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator>
45 ::MostCenteredMaximalSegmentEstimator(const SegmentComputer& aSegmentComputer,
46 const SCEstimator& aSCEstimator)
47 : mySC(aSegmentComputer), mySCEstimator(aSCEstimator)
51 // ------------------------------------------------------------------------
52 template <typename SegmentComputer, typename SCEstimator>
55 DGtal::MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator>
56 ::init(const ConstIterator& itb, const ConstIterator& ite)
64 // ------------------------------------------------------------------------
65 template <typename SegmentComputer, typename SCEstimator>
68 DGtal::MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator>::isValid() const
70 return isNotEmpty(myBegin, myEnd);
73 // ------------------------------------------------------------------------
74 template <typename SegmentComputer, typename SCEstimator>
75 template <typename OutputIterator>
78 DGtal::MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator>
79 ::endEval(const ConstIterator& itb, const ConstIterator& ite, ConstIterator& itCurrent,
80 SegmentIterator& first, SegmentIterator& last,
81 OutputIterator result)
83 typedef typename IteratorCirculatorTraits<ConstIterator>::Type Type;
84 return endEval (itb, ite, itCurrent, first, last, result, Type() );
87 // ------------------------------------------------------------------------
88 template <typename SegmentComputer, typename SCEstimator>
89 template <typename OutputIterator>
92 DGtal::MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator>
93 ::endEval(const ConstIterator& /*itb*/, const ConstIterator& ite, ConstIterator& itCurrent,
94 SegmentIterator& /*first*/, SegmentIterator& last,
95 OutputIterator result, IteratorType )
97 mySCEstimator.attach( *last );
98 result = mySCEstimator.eval( itCurrent, ite, result );
102 // ------------------------------------------------------------------------
103 template <typename SegmentComputer, typename SCEstimator>
104 template <typename OutputIterator>
107 DGtal::MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator>
108 ::endEval(const ConstIterator& itb, const ConstIterator& ite, ConstIterator& itCurrent,
109 SegmentIterator& first, SegmentIterator& last,
110 OutputIterator result, CirculatorType )
112 if ( (itb == ite) && (first.intersectPrevious() && last.intersectNext() ) )
113 {//if first and last segment intersect (whole range)
115 ConstIterator itEnd = getMiddleIterator( first->begin(), last->end() );//(floor)
117 mySCEstimator.attach( *last );
118 result = mySCEstimator.eval( itCurrent, itEnd, result );
120 if (itCurrent != ite)
123 mySCEstimator.attach( *first );
124 result = mySCEstimator.eval( itCurrent, ite, result );
129 mySCEstimator.attach( *last );
130 result = mySCEstimator.eval( itCurrent, ite, result );
135 // ------------------------------------------------------------------------
136 template <typename SegmentComputer, typename SCEstimator>
137 template <typename OutputIterator>
140 DGtal::MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator>
141 ::eval(const ConstIterator& itb, const ConstIterator& ite,
142 OutputIterator result, const double h)
146 mySCEstimator.init( h, myBegin, myEnd );
148 Segmentation seg(myBegin, myEnd, mySC);
149 seg.setSubRange(itb, ite);
150 if ((myBegin != itb) || (myEnd != ite))
152 seg.setMode("MostCentered++");
156 seg.setMode("MostCentered");
159 SegmentIterator segItBegin = seg.begin();
160 SegmentIterator segItEnd = seg.end();
161 SegmentIterator segIt = segItBegin;
162 SegmentIterator nextSegIt = segIt;
164 if (nextSegIt != segItEnd )
165 { //at least one maximal segment
168 if (nextSegIt == segItEnd )
170 //only one maximal segment
171 mySCEstimator.attach( *segIt );
172 result = mySCEstimator.eval( itb, ite, result );
176 //strictly more than one maximal segment
177 ConstIterator itCurrent = itb;
180 while (nextSegIt != segItEnd)
182 ConstIterator itEnd = getMiddleIterator( nextSegIt->begin(), segIt->end() );//(floor)
185 mySCEstimator.attach( *segIt );
186 result = mySCEstimator.eval( itCurrent, itEnd, result );
194 result = endEval(itb, ite, itCurrent, segItBegin, segIt, result);
196 }//end one or more maximal segments test
197 }//end zero or one maximal segment test
204 // ------------------------------------------------------------------------
205 template <typename SegmentComputer, typename SCEstimator>
207 typename DGtal::MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator>::Quantity
208 DGtal::MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator>
209 ::eval(const ConstIterator& it, const double h)
211 ASSERT(isValid() && isNotEmpty(it,myEnd));
213 mostCenteredMaximalSegment( mySC, it, myBegin, myEnd );
214 mySCEstimator.init( h, myBegin, myEnd );
215 mySCEstimator.attach( mySC );
216 return mySCEstimator.eval( it );