37 #include "DGtal/topology/SCellsFunctors.h"
46 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
51 : myImage( aImg ), myAcceptedPoints( aSet ),
53 myFlagIsOwning( true ),
54 myPointPredicate( aPointPredicate ),
55 myAreaThreshold( std::numeric_limits<
Area>::max() ),
56 myValueThreshold( std::numeric_limits<
Value>::max() )
63 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
68 const Area& aAreaThreshold,
69 const Value& aValueThreshold)
70 : myImage( aImg ), myAcceptedPoints( aSet ),
72 myFlagIsOwning( true ),
73 myPointPredicate( aPointPredicate ),
74 myAreaThreshold( aAreaThreshold ),
75 myValueThreshold( aValueThreshold )
82 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
88 : myImage( aImg ), myAcceptedPoints( aSet ),
89 myPointFunctorPtr( &aPointFunctor ),
90 myFlagIsOwning(
false ),
91 myPointPredicate( aPointPredicate ),
92 myAreaThreshold( std::numeric_limits<
Area>::max() ),
93 myValueThreshold( std::numeric_limits<
Value>::max() )
100 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
105 const Area& aAreaThreshold,
106 const Value& aValueThreshold,
108 : myImage( aImg ), myAcceptedPoints( aSet ),
109 myPointFunctorPtr( &aPointFunctor ),
110 myFlagIsOwning(
false ),
111 myPointPredicate( aPointPredicate ),
112 myAreaThreshold( aAreaThreshold ),
113 myValueThreshold( aValueThreshold )
120 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
125 delete myPointFunctorPtr;
132 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
133 template <
typename TIteratorOnPo
ints>
142 for (TIteratorOnPoints it = itb; it != ite; ++it)
148 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
149 template <
typename KSpace,
typename TIteratorOnBels>
153 const TIteratorOnBels& itb,
const TIteratorOnBels& ite,
156 bool aFlagIsPositive)
159 if (aFlagIsPositive) k = 1;
162 for (TIteratorOnBels it = itb; it != ite; ++it)
173 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
174 template <
typename KSpace,
typename TIteratorOnBels,
typename TImplicitFunction>
178 const TIteratorOnBels& itb,
const TIteratorOnBels& ite,
179 const TImplicitFunction& aF,
181 bool aFlagIsPositive)
184 if (aFlagIsPositive) k = 1;
187 typedef typename KSpace::Cell Bel;
188 typedef typename TImplicitFunction::Value
Value;
189 typedef std::pair<const Bel, Value> BelValue;
190 typedef std::map<Bel, Value> Buffer;
193 typedef std::vector<Pair> IncidentPoints;
198 IncidentPoints incidentPoints;
200 for (TIteratorOnBels it = itb; it != ite; ++it)
203 Pair points = getIncidentPoints( *it );
204 incidentPoints.push_back( points );
207 Value vin = aF( points.first );
208 Value vout = aF( points.second );
211 Value e = std::max(vin, vout) - std::min(vin, vout);
214 buffer.insert( BelValue( aK.unsigns( *it ), v ) );
222 Computer4InnerPts computerIn(aK, buffer);
223 Computer4OuterPts computerOut(aK, buffer);
224 for (
typename IncidentPoints::const_iterator it = incidentPoints.begin();
225 it != incidentPoints.end(); ++it)
228 Value vin = computerIn( it->first );
229 Value vout = computerOut( it->second );
237 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
238 template <
typename TIteratorOnPairs>
244 bool aFlagIsPositive)
247 if (aFlagIsPositive) k = 1;
250 for (TIteratorOnPairs it = itb; it != ite; ++it)
261 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
266 Point p = Point::diagonal(0);
268 while ( addNewAcceptedPoint( p, d ) )
272 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
278 return addNewAcceptedPoint(aPoint, aValue);
281 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
289 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
297 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
303 ASSERT(
set.size() >= 1 );
305 typename AcceptedPointSet::ConstIterator it =
set.begin();
306 typename AcceptedPointSet::ConstIterator itEnd =
set.end();
307 Value vmin = myImage( *it );
308 for (++it; it != itEnd; ++it)
310 Value v = myImage( *it );
311 if (v < vmin) vmin = v;
316 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
322 ASSERT(
set.size() >= 1 );
324 typename AcceptedPointSet::ConstIterator it =
set.begin();
325 typename AcceptedPointSet::ConstIterator itEnd =
set.end();
326 Value vmax = myImage( *it );
327 for (++it; it != itEnd; ++it)
329 Value v = myImage( *it );
330 if (v > vmax) vmax = v;
335 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
341 if ( (myAcceptedPoints.size() <= 0)
342 || (myAcceptedPoints.size() >= myAreaThreshold) )
return false;
345 if ( ( getMin() != min() ) || ( getMax() != max() ) )
return false;
346 if ( (std::abs(getMin()) >= myValueThreshold)
347 || (getMax() >= myValueThreshold) )
return false;
350 bool flagIsOk =
true;
352 typename AcceptedPointSet::ConstIterator it =
set.begin();
353 typename AcceptedPointSet::ConstIterator itEnd =
set.end();
354 for ( ; ( (it != itEnd)&&(flagIsOk ==
true) ); ++it)
356 if (myPointPredicate( *it ) ==
false) flagIsOk =
false;
358 if (!flagIsOk)
return false;
363 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
368 out <<
"[FMM " << dimension <<
"d] ";
369 out << myAcceptedPoints.size() <<
" accepted points (< " << myAreaThreshold <<
")";
370 out <<
" and " << myCandidatePoints.size() <<
" candidates. ";
371 out <<
"dmin: " << min() <<
", dmax: " << max();
372 out <<
" (abs < " << myValueThreshold <<
")";
379 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
385 myCandidatePoints.clear();
387 typename AcceptedPointSet::Iterator it = myAcceptedPoints.begin();
388 typename AcceptedPointSet::Iterator itEnd = myAcceptedPoints.end();
389 for ( ; it != itEnd; ++it)
394 myMinValue = getMin();
395 myMaxValue = getMax();
399 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
406 if ( (myAcceptedPoints.size()+1) < myAreaThreshold )
409 bool flagStop =
false;
410 typename CandidatePointSet::iterator it = myCandidatePoints.begin();
411 typename CandidatePointSet::iterator itEnd = myCandidatePoints.end();
412 while ( (it != itEnd) && (!flagStop) )
418 if ( std::abs(minPair.second) < myValueThreshold )
422 myCandidatePoints.erase(*it);
425 minPair.first, minPair.second ) )
429 aPoint = minPair.first;
430 aValue = minPair.second;
431 if (aValue > myMaxValue) myMaxValue = aValue;
432 if (aValue < myMinValue) myMinValue = aValue;
440 it = myCandidatePoints.begin();
454 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
461 Point neighbor = aPoint;
462 for (
Dimension k = 0; k < dimension; ++k)
464 typename Point::Coordinate c = neighbor.at(k);
465 neighbor.at(k) = (c+1);
466 addNewCandidate(neighbor);
467 neighbor.at(k) = (c-1);
468 addNewCandidate(neighbor);
473 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
481 if ( (myPointPredicate(aPoint) )
482 && ( myAcceptedPoints.find(aPoint) == myAcceptedPoints.end() ) )
484 ASSERT( myPointFunctorPtr );
485 Value d = myPointFunctorPtr->operator()( aPoint );
488 myCandidatePoints.insert(newPair);
498 template <
typename TImage,
typename TSet,
typename TPo
intPredicate,
typename TPo
intFunctor >
504 object.selfDisplay( out );