DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MLPLengthEstimator.ih
1 
33 
34 #include <cstdlib>
36 
38 // IMPLEMENTATION of inline methods.
40 
42 // ----------------------- Standard services ------------------------------
43 
47 template <typename T>
48 inline
50 {
51  myIsInitBefore = false;
52 }
53 
57 template <typename T>
58 inline
60 {
61 }
62 
63 
64 
66 // Interface - public :
67 
68 
69 
70 template <typename T>
71 inline
72 void
74  const ConstIterator& itb, const ConstIterator& ite, const bool& isClosed)
75 {
76  myH = h;
77  myIsInitBefore = true;
78  myRep.clear();
79 
80  FaithfulPolygon fp( itb, ite, isClosed );
81  myRep.resize( fp.size() );
82  fp.copyMLP( myRep.begin() );
83 
84  if ( (isClosed)&&(myRep.size()!=0) )
85  myRep.push_back(myRep.front());
86 }
87 
88 template <typename T>
89 inline
92 {
93  ASSERT(myH > 0);
94  ASSERT(myIsInitBefore);
95 
96  Quantity val = 0;
97 
98  if (myRep.size() > 1) {
99 
100  typename std::vector<Point>::const_iterator i = myRep.begin();
101  typename std::vector<Point>::const_iterator j = i;
102  ++j;
103  for ( ; j != myRep.end(); ++i, ++j) {
104  Vector v( *j - *i );
105  val += v.norm(Vector::L_2);
106  }
107 
108  }
109 
110  return val*myH;
111 }
112 
113 
114 
115 
116 
121 template <typename T>
122 inline
123 void
124 DGtal::MLPLengthEstimator<T>::selfDisplay ( std::ostream & out ) const
125 {
126  out << "[MLPLengthEstimator]";
127  if (myIsInitBefore)
128  out <<" myH="<<myH;
129  else
130  out<< " not initialized";
131 }
132 
137 template <typename T>
138 inline
139 bool
141 {
142  return myIsInitBefore;
143 }
144 
145 
146 
148 // Implementation of inline functions //
149 
150 template <typename T>
151 inline
152 std::ostream&
153 DGtal::operator<< ( std::ostream & out,
154  const MLPLengthEstimator<T> & object )
155 {
156  object.selfDisplay( out );
157  return out;
158 }
159 
160 // //
162 
163