DGtal  0.9.2
L1LengthEstimator.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 L1LengthEstimator.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
21  *
22  * @date 2011/06/27
23  *
24  * Implementation of inline methods defined in L1LengthEstimator.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 
30 //////////////////////////////////////////////////////////////////////////////
31 #include <cstdlib>
32 //////////////////////////////////////////////////////////////////////////////
33 
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
40 
41 /**
42  * Constructor.
43  */
44 template <typename T>
45 inline
46 DGtal::L1LengthEstimator<T>::L1LengthEstimator()
47 {
48  myIsInitBefore = false;
49 }
50 
51 /**
52  * Destructor.
53  */
54 template <typename T>
55 inline
56 DGtal::L1LengthEstimator<T>::~L1LengthEstimator()
57 {
58 }
59 
60 
61 
62 ///////////////////////////////////////////////////////////////////////////////
63 // Interface - public :
64 
65 
66 
67 template <typename T>
68 inline
69 void
70 DGtal::L1LengthEstimator<T>::init(const double h,
71  const ConstIterator& itb,
72  const ConstIterator& ite)
73 {
74  myH = h;
75  myBeginIt = itb;
76  myEndIt = ite;
77  myIsInitBefore = true;
78 }
79 
80 template <typename T>
81 inline
82 typename DGtal::L1LengthEstimator<T>::Quantity
83 DGtal::L1LengthEstimator<T>::eval() const
84 {
85  ASSERT(myH > 0);
86  ASSERT(myIsInitBefore);
87 
88  Quantity val = 0;
89 
90  if ( DGtal::isNotEmpty(myBeginIt,myEndIt) )
91  {
92  ConstIterator i = myBeginIt;
93  do
94  {
95  val += 1.0;
96  ++i;
97  }
98  while (i != myEndIt);
99  }
100 
101 
102  return val*myH;
103 }
104 
105 
106 
107 
108 
109 /**
110  * Writes/Displays the object on an output stream.
111  * @param out the output stream where the object is written.
112  */
113 template <typename T>
114 inline
115 void
116 DGtal::L1LengthEstimator<T>::selfDisplay ( std::ostream & out ) const
117 {
118  out << "[L1LengthEstimator]";
119  if (myIsInitBefore)
120  out <<" myH="<<myH;
121  else
122  out<< " not initialized";
123 }
124 
125 /**
126  * Checks the validity/consistency of the object.
127  * @return 'true' if the object is valid, 'false' otherwise.
128  */
129 template <typename T>
130 inline
131 bool
132 DGtal::L1LengthEstimator<T>::isValid() const
133 {
134  return myIsInitBefore;
135 }
136 
137 
138 
139 ///////////////////////////////////////////////////////////////////////////////
140 // Implementation of inline functions //
141 
142 template <typename T>
143 inline
144 std::ostream&
145 DGtal::operator<< ( std::ostream & out,
146  const L1LengthEstimator<T> & object )
147 {
148  object.selfDisplay( out );
149  return out;
150 }
151 
152 // //
153 ///////////////////////////////////////////////////////////////////////////////
154 
155