DGtal 1.3.0
Loading...
Searching...
No Matches
FPLengthEstimator.ih
1/**
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.
6 *
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.
11 *
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/>.
14 *
15 **/
16
17/**
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,
22 * France
23 *
24 *
25 * @date 2011/07/07
26 *
27 * Implementation of inline methods defined in FPLengthEstimator.h
28 *
29 * This file is part of the DGtal library.
30 */
31
32
33//////////////////////////////////////////////////////////////////////////////
34#include <cstdlib>
35//////////////////////////////////////////////////////////////////////////////
36
37///////////////////////////////////////////////////////////////////////////////
38// IMPLEMENTATION of inline methods.
39///////////////////////////////////////////////////////////////////////////////
40
41///////////////////////////////////////////////////////////////////////////////
42// Interface - public :
43
44template <typename T>
45inline
46typename DGtal::FPLengthEstimator<T>::Quantity
47DGtal::FPLengthEstimator<T>::eval(const ConstIterator& itb,
48 const ConstIterator& ite, const double h) const
49{
50 ASSERT(h > 0.);
51
52 Quantity val = 0.;
53 if ( isEmpty(itb,ite) )
54 return val;
55
56 FaithfulPolygon fp( itb, ite );
57 std::vector<Point> points(fp.size());
58 fp.copyFP( points.begin() );
59
60 typename std::vector<Point>::const_iterator i = points.begin();
61 typename std::vector<Point>::const_iterator j = i;
62 ++j;
63 const typename std::vector<Point>::const_iterator end = points.end();
64
65 for ( ; j != end; ++i, ++j )
66 {
67 Vector v( *j - *i );
68 val += v.norm(Vector::L_2);
69 }
70 if ( IsCirculator<ConstIterator>::value )
71 {
72 Vector v( points.front() - *i );
73 val += v.norm(Vector::L_2);
74 }
75
76 return val*h;
77}
78
79
80
81
82
83
84// ------------------------------------------------------------------------
85template <typename T>
86inline
87void
88DGtal::FPLengthEstimator<T>::selfDisplay ( std::ostream & out ) const
89{
90 out << "[FPLengthEstimator]";
91 if (isValid())
92 out <<" initialized";
93 else
94 out<< " not initialized";
95}
96
97// ------------------------------------------------------------------------
98template <typename T>
99inline
100bool
101DGtal::FPLengthEstimator<T>::isValid() const
102{
103 return true;
104}
105
106
107
108///////////////////////////////////////////////////////////////////////////////
109// Implementation of inline functions //
110
111template <typename T>
112inline
113std::ostream&
114DGtal::operator<< ( std::ostream & out,
115 const FPLengthEstimator<T> & object )
116{
117 object.selfDisplay( out );
118 return out;
119}
120
121// //
122///////////////////////////////////////////////////////////////////////////////
123
124