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 KanungoNoise.ih
19 * @author David Coeurjolly (\c david.coeurjolly@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 KanungoNoise.h
26 * This file is part of the DGtal library.
30//////////////////////////////////////////////////////////////////////////////
33//////////////////////////////////////////////////////////////////////////////
35///////////////////////////////////////////////////////////////////////////////
36// IMPLEMENTATION of inline methods.
37///////////////////////////////////////////////////////////////////////////////
39///////////////////////////////////////////////////////////////////////////////
40// -----------------------------------------------------
41template <typename TP, typename TD, typename TS>
43DGtal::KanungoNoise<TP,TD, TS>::KanungoNoise(ConstAlias<TP> aPredicate, ConstAlias<Domain> aDomain, const double alpha):
44 myPredicate(aPredicate), myDomain(aDomain), myAlpha(alpha)
47 std::uniform_real_distribution<double> dis(0.0, 1.0);
49 ASSERT(alpha>0 && alpha < 1);
52 //We copy the point set
53 mySet = new DigitalSet( new Domain( aDomain ) );
55 typedef ExactPredicateLpSeparableMetric< typename Domain::Space, 2> L2;
56 typedef DistanceTransformation< typename Domain::Space, PointPredicate, L2> DTPredicate;
57 typedef DistanceTransformation< typename Domain::Space, functors::NotPointPredicate<PointPredicate> , L2> DTNotPredicate;
59 //DT computation for l2metric
61 functors::NotPointPredicate<PointPredicate> negPred(myPredicate);
63 DTPredicate DTin(myDomain, myPredicate, l2);
64 DTNotPredicate DTout(myDomain, negPred, l2);
66 for(typename Domain::ConstIterator it = myDomain.begin(), itend = myDomain.end();
70 if ( myPredicate(*it) )
72 if ( p >= std::pow( alpha, 1.0+DTin(*it) ) )
73 mySet->insertNew( *it );
77 if ( p < std::pow( alpha, 1.0+DTout(*it) ) )
78 mySet->insertNew( *it );
82// -----------------------------------------------------
83template <typename TP, typename TD, typename TS>
85DGtal::KanungoNoise<TP,TD, TS>::~KanungoNoise()
89// -----------------------------------------------------
90template <typename TP, typename TD, typename TS>
92DGtal::KanungoNoise<TP,TD, TS> &
93DGtal::KanungoNoise<TP,TD, TS>::operator=( const KanungoNoise<TP,TD,TS> &other)
95 ASSERT( ( myDomain.lowerBound() <= other.myDomain.lowerBound() )
96 && ( myDomain.upperBound() >= other.myDomain.upperBound() )
97 && "This domain should include the domain of the other set in case of assignment." );
99 //We do not copy the predicate
101 myAlpha = other.myAlpha;
106// --------------------------------------------- --------
107template <typename TP, typename TD, typename TS>
110DGtal::KanungoNoise<TP,TD, TS>::operator()(const Point &aPoint) const
112 return mySet->operator()(aPoint);
114// -----------------------------------------------------
115template <typename TP, typename TD, typename TS>
118DGtal::KanungoNoise<TP,TD, TS>::selfDisplay ( std::ostream & out ) const
120 out << "[KanungoNoise] Alpha="<<myAlpha<<" Set "<< *mySet;
122// -----------------------------------------------------
123template <typename TP, typename TD, typename TS>
126DGtal::KanungoNoise<TP,TD, TS>::isValid() const
128 return mySet->isValid();
130// -----------------------------------------------------
131template <typename TP, typename TD, typename TS>
134DGtal::operator<< ( std::ostream & out,
135 const KanungoNoise<TP,TD, TS> & object )
137 object.selfDisplay( out );
142///////////////////////////////////////////////////////////////////////////////