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 FPLengthEstimator.ih
19 * @author Tristan Roussillon (\c
20 * tristan.roussillon@liris.cnrs.fr ) Laboratoire d'InfoRmatique en
21 * Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS,
27 * Implementation of inline methods defined in FPLengthEstimator.h
29 * This file is part of the DGtal library.
33 //////////////////////////////////////////////////////////////////////////////
35 //////////////////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////////////////
38 // IMPLEMENTATION of inline methods.
39 ///////////////////////////////////////////////////////////////////////////////
41 ///////////////////////////////////////////////////////////////////////////////
42 // ----------------------- Standard services ------------------------------
49 DGtal::FPLengthEstimator<T>::FPLengthEstimator()
51 myIsInitBefore = false;
59 DGtal::FPLengthEstimator<T>::~FPLengthEstimator()
65 ///////////////////////////////////////////////////////////////////////////////
66 // Interface - public :
73 DGtal::FPLengthEstimator<T>::init(const double h,
74 const ConstIterator& itb, const ConstIterator& ite, const bool& isClosed)
77 myIsInitBefore = true;
80 //TODO deal with circulators
81 FaithfulPolygon fp( itb, ite );
82 myRep.resize( fp.size() );
83 fp.copyFP( myRep.begin() );
85 if ( (isClosed)&&(myRep.size()!=0) )
86 myRep.push_back(myRep.front());
92 typename DGtal::FPLengthEstimator<T>::Quantity
93 DGtal::FPLengthEstimator<T>::eval() const
96 ASSERT(myIsInitBefore);
100 if (myRep.size() > 1) {
102 typename std::vector<Point>::const_iterator i = myRep.begin();
103 typename std::vector<Point>::const_iterator j = i;
105 for ( ; j != myRep.end(); ++i, ++j) {
107 val += v.norm(Vector::L_2);
120 * Writes/Displays the object on an output stream.
121 * @param out the output stream where the object is written.
123 template <typename T>
126 DGtal::FPLengthEstimator<T>::selfDisplay ( std::ostream & out ) const
128 out << "[FPLengthEstimator]";
132 out<< " not initialized";
136 * Checks the validity/consistency of the object.
137 * @return 'true' if the object is valid, 'false' otherwise.
139 template <typename T>
142 DGtal::FPLengthEstimator<T>::isValid() const
144 return myIsInitBefore;
149 ///////////////////////////////////////////////////////////////////////////////
150 // Implementation of inline functions //
152 template <typename T>
155 DGtal::operator<< ( std::ostream & out,
156 const FPLengthEstimator<T> & object )
158 object.selfDisplay( out );
163 ///////////////////////////////////////////////////////////////////////////////