DGtal  1.5.beta
DSSLengthEstimator.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 DSSLengthEstimator.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 DSSLengthEstimator.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 
44 template <typename T>
45 inline
46 typename DGtal::DSSLengthEstimator<T>::Quantity
47 DGtal::DSSLengthEstimator<T>::eval( const ConstIterator& itb,
48  const ConstIterator& ite, const double h ) const
49 {
50  ASSERT(h > 0.);
51 
52  if ( isEmpty(itb, ite) )
53  return 0.;
54 
55  //segments into DSSs
56  DSSComputer computer;
57  GreedySegmentation<DSSComputer> decomposition( itb, ite, computer );
58 
59  typename GreedySegmentation<DSSComputer>::SegmentComputerIterator i = decomposition.begin();
60  const typename GreedySegmentation<DSSComputer>::SegmentComputerIterator end = decomposition.end();
61 
62  Quantity val = 0.;
63 
64  for ( ; i != end; ++i )
65  {
66  Vector v( i->front() - i->back() );
67  val += v.norm(Vector::L_2);
68  }
69  if ( IsCirculator<ConstIterator>::value )
70  {
71  Vector v( decomposition.begin()->back() - i->front() );
72  val += v.norm(Vector::L_2);
73  }
74 
75  return val*h;
76 }
77 
78 
79 
80 
81 
82 
83 // ------------------------------------------------------------------------
84 template <typename T>
85 inline
86 void
87 DGtal::DSSLengthEstimator<T>::selfDisplay ( std::ostream & out ) const
88 {
89  out << "[DSSLengthEstimator]";
90  if (isValid())
91  out <<" initialized";
92  else
93  out<< " not initialized";
94 }
95 
96 // ------------------------------------------------------------------------
97 template <typename T>
98 inline
99 bool
100 DGtal::DSSLengthEstimator<T>::isValid() const
101 {
102  return true;
103 }
104 
105 
106 
107 ///////////////////////////////////////////////////////////////////////////////
108 // Implementation of inline functions //
109 
110 template <typename T>
111 inline
112 std::ostream&
113 DGtal::operator<< ( std::ostream & out,
114  const DSSLengthEstimator<T> & object )
115 {
116  object.selfDisplay( out );
117  return out;
118 }
119 
120 // //
121 ///////////////////////////////////////////////////////////////////////////////
122 
123