DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FPLengthEstimator.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.copyFP( myRep.begin() );
83 
84  if ( (isClosed)&&(myRep.size()!=0) )
85  myRep.push_back(myRep.front());
86 
87 }
88 
89 template <typename T>
90 inline
93 {
94  ASSERT(myH > 0);
95  ASSERT(myIsInitBefore);
96 
97  Quantity val = 0;
98 
99  if (myRep.size() > 1) {
100 
101  typename std::vector<Point>::const_iterator i = myRep.begin();
102  typename std::vector<Point>::const_iterator j = i;
103  ++j;
104  for ( ; j != myRep.end(); ++i, ++j) {
105  Vector v( *j - *i );
106  val += v.norm(Vector::L_2);
107  }
108 
109  }
110 
111  return val*myH;
112 }
113 
114 
115 
116 
117 
122 template <typename T>
123 inline
124 void
125 DGtal::FPLengthEstimator<T>::selfDisplay ( std::ostream & out ) const
126 {
127  out << "[FPLengthEstimator]";
128  if (myIsInitBefore)
129  out <<" myH="<<myH;
130  else
131  out<< " not initialized";
132 }
133 
138 template <typename T>
139 inline
140 bool
142 {
143  return myIsInitBefore;
144 }
145 
146 
147 
149 // Implementation of inline functions //
150 
151 template <typename T>
152 inline
153 std::ostream&
154 DGtal::operator<< ( std::ostream & out,
155  const FPLengthEstimator<T> & object )
156 {
157  object.selfDisplay( out );
158  return out;
159 }
160 
161 // //
163 
164