00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_DATATYPE_CONTOUR_H
00008 #define BALL_DATATYPE_CONTOUR_H
00009
00010 #ifndef BALL_DATATYPE_REGULARDATA2D_H
00011 # include <BALL/DATATYPE/regularData2D.h>
00012 #endif
00013
00014 #ifndef BALL_DATATYPE_CONTOURLINE_H
00015 # include <BALL/DATATYPE/contourLine.h>
00016 #endif
00017
00018 #include <vector>
00019
00020
00021 namespace BALL
00022 {
00026 template <typename T>
00027 class TContour
00028 {
00029 public:
00030
00031
00032 BALL_CREATE(TContour<T>)
00033
00034
00037
00038 TContour(Size num_lines=0, double start=0, double end=0);
00039
00041 TContour(const TContour& contour);
00042
00044 virtual ~TContour();
00045
00047
00050
00052 bool getNextContourLine(TContourLine<T>& contour);
00053
00055
00058
00060 TContour& operator = (const TContour& rhs);
00061
00064 void apply(TRegularData2D<T>& data);
00065
00067 virtual void clear();
00068
00070 void resetCounter();
00071
00073
00076
00078 bool operator == (const TContour& contour) const;
00079
00081
00082 protected:
00083
00084 std::vector< TContourLine<T> > lines_;
00085 Size num_lines_;
00086 double start_;
00087 double end_;
00088 typename std::vector<TContourLine<T> >::const_iterator it_;
00089 Position index_;
00090 };
00091
00095 typedef TContour<float> Contour;
00096
00097 template <typename T>
00098 TContour<T>::TContour(Size num_lines, double start, double end) : lines_(num_lines), num_lines_(num_lines), start_(start), end_(end), index_(0)
00099 {
00100 }
00101
00102 template <typename T>
00103 TContour<T>::TContour(const TContour& copyTContour) : lines_(copyTContour.lines_), num_lines_(copyTContour.num_lines_), start_(copyTContour.start_), end_(copyTContour.end_), index_(copyTContour.index_)
00104 {
00105 }
00106
00107 template <typename T>
00108 TContour<T>::~TContour()
00109 {
00110 }
00111
00112 template <typename T>
00113 TContour<T>& TContour<T>::operator = (const TContour& rhs)
00114 {
00115 start_ = rhs.start_;
00116 end_ = rhs.end_;
00117 num_lines_ = rhs.num_lines_;
00118 it_ = rhs.it_;
00119 }
00120
00121 template <typename T>
00122 void TContour<T>::clear()
00123 {
00124 start_ = 0;
00125 end_ = 0;
00126 num_lines_ = 0;
00127 lines_ = std::vector< TContourLine<T> >(0);
00128 index_ = 0;
00129 }
00130
00131 template <typename T>
00132 bool TContour<T>::operator == (const TContour& compTContour) const
00133 {
00134 return ((start_ == compTContour.start_) && (end_ == compTContour.end_) && (lines_ == compTContour.lines_)
00135 && (num_lines_ == compTContour.num_lines_) && (it_ == compTContour.it_) && (index_ == compTContour.index_));
00136 }
00137
00138 template <typename T>
00139 void TContour<T>::apply(TRegularData2D<T>& data)
00140 {
00141 Position i;
00142 double step = (end_ - start_) / num_lines_;
00143
00144 for (i=0; i<num_lines_; i++)
00145 {
00146 TContourLine<T> con(start_ + i*step);
00147 con.createContourLine(data);
00148 lines_[i]=con;
00149 };
00150
00151 if (num_lines_ > 0)
00152 {
00153 it_ = lines_.begin();
00154 index_ = 0;
00155 };
00156 }
00157
00158 template <typename T>
00159 bool TContour<T>::getNextContourLine(TContourLine<T>& cont)
00160 {
00161 if (index_<num_lines_)
00162 {
00163 cont = *it_;
00164 it_++;
00165 index_++;
00166 return (true);
00167 } else {
00168 return false;
00169 };
00170 }
00171
00172 template <typename T>
00173 void TContour<T>::resetCounter()
00174 {
00175 it_ = lines_.begin();
00176 index_ = 0;
00177 }
00178
00179 }
00180
00181 #endif