1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: contour.h,v 1.17 2004/04/22 10:08:19 oliver Exp $
//
#ifndef BALL_DATATYPE_CONTOUR_H
#define BALL_DATATYPE_CONTOUR_H
#ifndef BALL_DATATYPE_REGULARDATA2D_H
# include <BALL/DATATYPE/regularData2D.h>
#endif
#ifndef BALL_DATATYPE_CONTOURLINE_H
# include <BALL/DATATYPE/contourLine.h>
#endif
#include <vector>
namespace BALL
{
/** This class is intended to create and store ContourLines belonging to the same data-set.
\ingroup DatatypeMiscellaneous
*/
template <typename T>
class TContour
{
public:
// macro for create method
BALL_CREATE(TContour<T>)
/** @name Constructors and Destructors
*/
//@{
/// Default constructor
TContour(Size num_lines=0, double start=0, double end=0);
/// Copy constructor
TContour(const TContour& contour);
/// Destructor
virtual ~TContour();
//@}
/** @name Accessors
*/
//@{
/// Gives access to the next ContourLine. Returns false if we had already returned the last line.
bool getNextContourLine(TContourLine<T>& contour);
//@}
/** @name Assignment
*/
//@{
/// Assignment operator
TContour& operator = (const TContour& rhs);
/**
*/
void apply(TRegularData2D<T>& data);
/// Clear method
virtual void clear();
/// Reset the ContourLine-counter.
void resetCounter();
//@}
/** @name Predicates
*/
//@{
/// Equality operator
bool operator == (const TContour& contour) const;
//@}
protected:
std::vector< TContourLine<T> > lines_;
Size num_lines_;
double start_;
double end_;
typename std::vector<TContourLine<T> >::const_iterator it_;
Position index_;
};
/** Default type
\ingroup DatatypeMiscellaneous
*/
typedef TContour<float> Contour;
template <typename T>
TContour<T>::TContour(Size num_lines, double start, double end) : lines_(num_lines), num_lines_(num_lines), start_(start), end_(end), index_(0)
{
}
template <typename T>
TContour<T>::TContour(const TContour& copyTContour) : lines_(copyTContour.lines_), num_lines_(copyTContour.num_lines_), start_(copyTContour.start_), end_(copyTContour.end_), index_(copyTContour.index_)
{
}
template <typename T>
TContour<T>::~TContour()
{
}
template <typename T>
TContour<T>& TContour<T>::operator = (const TContour& rhs)
{
start_ = rhs.start_;
end_ = rhs.end_;
num_lines_ = rhs.num_lines_;
it_ = rhs.it_;
}
template <typename T>
void TContour<T>::clear()
{
start_ = 0;
end_ = 0;
num_lines_ = 0;
lines_ = std::vector< TContourLine<T> >(0);
index_ = 0;
}
template <typename T>
bool TContour<T>::operator == (const TContour& compTContour) const
{
return ((start_ == compTContour.start_) && (end_ == compTContour.end_) && (lines_ == compTContour.lines_)
&& (num_lines_ == compTContour.num_lines_) && (it_ == compTContour.it_) && (index_ == compTContour.index_));
}
template <typename T>
void TContour<T>::apply(TRegularData2D<T>& data)
{
Position i;
double step = (end_ - start_) / num_lines_;
for (i=0; i<num_lines_; i++)
{
TContourLine<T> con(start_ + i*step);
con.createContourLine(data);
lines_[i]=con;
};
if (num_lines_ > 0)
{
it_ = lines_.begin();
index_ = 0;
};
}
template <typename T>
bool TContour<T>::getNextContourLine(TContourLine<T>& cont)
{
if (index_<num_lines_)
{
cont = *it_;
it_++;
index_++;
return (true);
} else {
return false;
};
}
template <typename T>
void TContour<T>::resetCounter()
{
it_ = lines_.begin();
index_ = 0;
}
} // namespace BALL
#endif
|