00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _GOPOINTCLOUD_H
00034 #define _GOPOINTCLOUD_H
00035
00036
00037 #include "errormacros.h"
00038 #include "GeomObject.h"
00039 #include "Array.h"
00040 #include <vector>
00041
00042
00043 namespace Go {
00046
00047
00048
00049
00050
00051
00055 template <int Dim>
00056 class PointCloud : public GeomObject {
00057 public:
00060 PointCloud()
00061 {};
00062
00065
00071 template <typename ForwardIterator>
00072 PointCloud(ForwardIterator start, int numpoints)
00073 : points_(numpoints)
00074 {
00075 std::copy(start, start + Dim * numpoints, points_[0].begin());
00076 }
00077
00079 PointCloud(std::vector<Array<double, Dim> >& points)
00080 : points_(points)
00081 {}
00082
00084 virtual ~PointCloud()
00085 {}
00086
00087
00088 virtual BoundingBox boundingBox() const
00089 {
00090 BoundingBox box;
00091 box.setFromArray(points_[0].begin(), points_.back().end(), Dim);
00092 return box;
00093 }
00094
00096 virtual int dimension() const
00097 { return Dim; }
00098
00099
00100 virtual ClassType instanceType() const
00101 { return PointCloud::classType(); }
00102
00103
00104 static ClassType classType()
00105 { return Class_PointCloud; }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 virtual PointCloud* clone() const
00118 { return new PointCloud(*this); }
00119
00120
00123 int numPoints() const
00124 { return points_.size(); }
00125
00130 Array<double, Dim>& point(int i)
00131 { return points_[i]; }
00132
00137 const Array<double, Dim>& point(int i) const
00138 { return points_[i]; }
00139
00143 double* rawData()
00144 { return points_[0].begin(); }
00145
00149 const double* rawData() const
00150 { return points_[0].begin(); }
00151
00154 const std::vector<Array<double, Dim> >& pointVector()
00155 { return points_; }
00156
00157
00158 virtual void read (std::istream& is)
00159 {
00160 bool is_good = is.good();
00161 if (!is_good) {
00162 THROW("Invalid geometry file!");
00163 }
00164 int nump;
00165 is >> nump;
00166 ALWAYS_ERROR_IF(nump < 1, "Less than one point in cloud.");
00167 is_good = is.good();
00168 if (!is_good) {
00169 THROW("Invalid geometry file!");
00170 }
00171 points_.resize(nump);
00172 for (int i = 0; i < nump; ++i) {
00173 for (int d = 0; d < Dim; ++d) {
00174 is >> points_[i][d];
00175 }
00176 }
00177
00178 is_good = is.good();
00179 if (!is_good) {
00180 THROW("Invalid geometry file!");
00181 }
00182 }
00183
00184
00185 virtual void write (std::ostream& os) const
00186 {
00187 os << std::setprecision(15);
00188
00189 int nump = points_.size();
00190 os << nump << '\n';
00191 for(int i = 0; i < nump; ++i) {
00192 os << points_[i][0];
00193 for (int d = 1; d < Dim; ++d) {
00194 os << ' ' << points_[i][d];
00195 }
00196 os << '\n';
00197 }
00198 os << std::endl;
00199 }
00200
00201 private:
00202 std::vector<Array<double, Dim> > points_;
00203
00204 };
00205
00206
00207 typedef PointCloud<3> PointCloud3D;
00208 typedef PointCloud<4> PointCloud4D;
00209
00210
00212 }
00213
00214
00215
00216
00217 #endif // _GOPOINTCLOUD_H
00218
00219