32 #include <boost/lexical_cast.hpp>
45 template <
typename I, DGtal::u
int32_t p,
typename IntShort>
48 const IntShort defaultBackground):
49 myForegroundValue(defaultForeground),
50 myBackgroundValue(defaultBackground)
58 template <
typename I, DGtal::u
int32_t p,
typename IntShort>
65 template <
typename I, DGtal::u
int32_t p,
typename IntShort>
71 myLowerBoundCopy =
Point();
72 myUpperBoundCopy = aImage.domain().upperBound() - aImage.domain().lowerBound();
73 myDisplacementVector = aImage.domain().lowerBound();
74 myExtent = myUpperBoundCopy - myLowerBoundCopy;
77 I output (
typename I::Domain(myLowerBoundCopy, myUpperBoundCopy));
78 I swap (
typename I::Domain(myLowerBoundCopy, myUpperBoundCopy));
80 bool isSwap = reconstructionInternal(aImage,output,swap);
85 return castValues(swap);
90 return castValues(output);
94 template <
typename I, DGtal::u
int32_t p,
typename IntShort>
95 template <
typename Set>
104 myLowerBoundCopy =
Point();
105 myUpperBoundCopy = aImage.domain().upperBound() - aImage.domain().lowerBound();
106 myDisplacementVector = aImage.domain().lowerBound();
107 myExtent = myUpperBoundCopy - myLowerBoundCopy;
109 typename I::Domain domain(myLowerBoundCopy,myUpperBoundCopy);
111 I output (
typename I::Domain(myLowerBoundCopy, myUpperBoundCopy ));
112 I swap (
typename I::Domain( myLowerBoundCopy, myUpperBoundCopy ));
114 bool isSwap = reconstructionInternal(aImage,output,swap);
116 for(
typename I::Domain::ConstIterator it=domain.begin(),
117 itend = domain.end();
122 if ( output(*it) > 0)
123 aSet.insertNew((*it) + myDisplacementVector);
128 aSet.insertNew((*it) + myDisplacementVector);
133 template <
typename I, DGtal::u
int32_t p,
typename IntShort>
140 typename I::Iterator ito=output.begin();
142 for(
typename I::ConstIterator it=aImage.begin(), itend = aImage.end();
150 for (
Dimension dim = 0; dim < I::dimension ; dim++ )
153 computeSteps ( output, swap, dim );
155 computeSteps ( swap, output, dim );
166 template <
typename I, DGtal::u
int32_t p,
typename IntShort>
174 for(
typename I::ConstIterator it=input.begin(),
179 (*ito) = myForegroundValue;
181 (*ito) = myBackgroundValue;
187 template <
typename I, DGtal::u
int32_t p,
typename IntShort>
194 std::string title =
"RDT dimension " + boost::lexical_cast<
string>( dim ); ;
197 typedef typename Domain::ConstSubRange::ConstIterator ConstDomIt;
203 std::vector<Size> subdomain;
204 subdomain.reserve(I::dimension - 1);
205 for (
unsigned int k = 0; k < I::dimension ; k++)
206 if ( (I::dimension - 1 - k) != dim)
207 subdomain.push_back( I::dimension - 1 - k );
209 Domain localDomain(myLowerBoundCopy, myUpperBoundCopy);
210 Size maxSize = myExtent.normInfinity();
220 for (ConstDomIt it = localDomain.subRange( subdomain ).begin(),
221 itend = localDomain.subRange( subdomain ).end(); it != itend; ++it)
223 computeSteps1D ( input, output, (*it), dim, s, t );
235 template <
typename I, DGtal::u
int32_t p,
typename IntShort>
239 const Point &startingPoint,
247 Point sQ = startingPoint;
248 Point pU = startingPoint;
253 pU[dim] = myLowerBoundCopy[dim];
254 while ((pU[dim] <= myUpperBoundCopy[dim])
255 && (input ( pU ) == 0))
258 if ( pU[dim] > myUpperBoundCopy[dim] )
260 for(
typename I::SpanIterator it= output.spanBegin(startingPoint,dim),
261 itend=output.spanEnd(startingPoint,dim);
263 output.setValue(it, 0);
270 t[q] = myLowerBoundCopy[dim];
274 for (
int u = pU[dim] + 1; u <= myUpperBoundCopy[dim] ; u++ )
277 if ( input( pU ) == 0 )
283 while ( ( q >= 0 ) &&
284 ( myMetric.reversedF ( t[q], s[q], (
const int)input ( sQ ) ) <
285 myMetric.reversedF ( t[q], u, (
const int)input ( pU ) ) ) )
297 t[0] = myLowerBoundCopy[dim];
303 w = 1 + myMetric.reversedSep ( s[q],
304 (
const int)input ( sQ ),
306 (
const int)input ( pU ) );
308 if (( w <= myUpperBoundCopy[dim] ) && (w>= myLowerBoundCopy[dim]))
318 Point last = startingPoint;
323 for (last[dim] = myUpperBoundCopy[dim];
324 last[dim] >= myLowerBoundCopy[dim] ;
327 if (myMetric.reversedF ( last[dim] , s[q], (
const int)input ( sQ )) > 0 )
328 output.setValue ( last, myMetric.reversedF ( last[dim] , s[q], (
const int)input ( sQ ) ) );
330 output.setValue ( last, 0 );
332 if (( last[dim] == t[q] ) && (q > 0))