DGtal  0.9.2
TwoStepLocalLengthEstimator.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 TwoStepLocalLengthEstimator.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 TwoStepLocalLengthEstimator.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 
43 /**
44  * Destructor.
45  */
46 template <typename T>
47 inline
48 DGtal::TwoStepLocalLengthEstimator<T>::~TwoStepLocalLengthEstimator()
49 {
50 }
51 
52 
53 
54 ///////////////////////////////////////////////////////////////////////////////
55 // Interface - public :
56 
57 
58 
59 template <typename T>
60 inline
61 void
62 DGtal::TwoStepLocalLengthEstimator<T>::init(const double h,
63  const ConstIterator& itb,
64  const ConstIterator& ite,
65  const bool& )
66 {
67  myH = h;
68  myBeginIt = itb;
69  myEndIt = ite;
70  myIsInitBefore = true;
71 }
72 
73 template <typename T>
74 inline
75 typename DGtal::TwoStepLocalLengthEstimator<T>::Quantity
76 DGtal::TwoStepLocalLengthEstimator<T>::eval() const
77 {
78  ASSERT(myH > 0);
79  ASSERT(myIsInitBefore);
80  ASSERT(myBeginIt != myEndIt);
81 
82  unsigned int nbDirect=0;
83  unsigned int nbDiag=0;
84 
85  ConstIterator i = myBeginIt, ii = myBeginIt;
86  ++ii;
87 
88  while (( i != myEndIt) && (ii != myEndIt))
89  {
90  if (((*i).second).dot((*ii).second) == 0)
91  nbDiag++;
92  else
93  nbDirect+=2;
94 
95  ++i;
96  if (i == myEndIt)
97  continue;
98  ++i;
99 
100  ++ii;
101  if (ii == myEndIt)
102  continue;
103  ++ii;
104  }
105 
106  if ( i!= myEndIt)
107  nbDirect ++;
108 
109  return (nbDiag*myWeightDiagonal + nbDirect*myWeightDirect)*myH;
110 }
111 
112 
113 
114 
115 
116 
117 
118 /**
119  * Writes/Displays the object on an output stream.
120  * @param out the output stream where the object is written.
121  */
122 template <typename T>
123 inline
124 void
125 DGtal::TwoStepLocalLengthEstimator<T>::selfDisplay ( std::ostream & out ) const
126 {
127  out << "[TwoStepLocalLengthEstimator]";
128  if (myIsInitBefore)
129  out <<" myH="<<myH;
130  else
131  out<< " not initialized";
132 }
133 
134 /**
135  * Checks the validity/consistency of the object.
136  * @return 'true' if the object is valid, 'false' otherwise.
137  */
138 template <typename T>
139 inline
140 bool
141 DGtal::TwoStepLocalLengthEstimator<T>::isValid() const
142 {
143  return myIsInitBefore;
144 }
145 
146 
147 
148 ///////////////////////////////////////////////////////////////////////////////
149 // Implementation of inline functions //
150 
151 template <typename T>
152 inline
153 std::ostream&
154 DGtal::operator<< ( std::ostream & out,
155  const TwoStepLocalLengthEstimator<T> & object )
156 {
157  object.selfDisplay( out );
158  return out;
159 }
160 
161 // //
162 ///////////////////////////////////////////////////////////////////////////////
163 
164