//=========================================================================== // GoTools Core - SINTEF Geometry Tools Core library, version 2.0.1 // // Copyright (C) 2000-2007, 2010 SINTEF ICT, Applied Mathematics, Norway. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation version 2 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., // 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // Contact information: E-mail: tor.dokken@sintef.no // SINTEF ICT, Department of Applied Mathematics, // P.O. Box 124 Blindern, // 0314 Oslo, Norway. // // Other licenses are also available for this software, notably licenses // for: // - Building commercial software. // - Building software whose source code you wish to keep private. //=========================================================================== 00015 #ifndef _POINTCLOUD_H 00016 #define _POINTCLOUD_H 00017 00018 00019 #include "GoTools/utils/errormacros.h" 00020 #include "GoTools/geometry/GeomObject.h" 00021 #include "GoTools/utils/Array.h" 00022 #include <vector> 00023 00024 00025 namespace Go { 00026 00027 // NB! This class is now a template. The dimension is the template 00028 // parameter. Typedefs are provided for ease of use. Thus, what used 00029 // to be a "PointCloud" is now a "PointCloud3D". @@@jbt 00030 00034 template <int Dim> 00035 class PointCloud : public GeomObject { 00036 public: 00039 PointCloud() 00040 {}; 00041 00044 00050 template <typename ForwardIterator> 00051 PointCloud(ForwardIterator start, int numpoints) 00052 : points_(numpoints) 00053 { 00054 #ifndef _MSC_VER // Getting rid of warning C4996 on Windows 00055 std::copy(start, start + Dim * numpoints, points_[0].begin()); 00056 #else 00057 stdext::unchecked_copy(start, start + Dim * numpoints, points_[0].begin()); 00058 #endif // _MSC_VER 00059 } 00060 00062 PointCloud(std::vector<Array<double, Dim> >& points) 00063 : points_(points) 00064 {} 00065 00067 virtual ~PointCloud() 00068 {} 00069 00070 // inherited from GeomObject 00071 virtual BoundingBox boundingBox() const 00072 { 00073 BoundingBox box; 00074 box.setFromArray(points_[0].begin(), points_.back().end(), Dim); 00075 return box; 00076 } 00077 00079 virtual int dimension() const 00080 { return Dim; } 00081 00082 // inherited from GeomObject 00083 virtual ClassType instanceType() const 00084 { return PointCloud::classType(); } 00085 00086 // inherited from GeomObject 00087 static ClassType classType() 00088 { return Class_PointCloud; } 00089 00090 // inherited from GeomObject 00091 // #ifdef _MSC_VER 00092 // #if _MSC_VER < 1300 00093 // virtual GeomObject* clone() const 00094 // { return new PointCloud(*this); } 00095 // #else 00096 // virtual PointCloud* clone() const 00097 // { return new PointCloud(*this); } 00098 // #endif // _MSC_VER < 1300 00099 // #else 00100 virtual PointCloud* clone() const 00101 { return new PointCloud(*this); } 00102 // #endif 00103 00106 int numPoints() const 00107 { return points_.size(); } 00108 00113 Array<double, Dim>& point(int i) 00114 { return points_[i]; } 00115 00120 const Array<double, Dim>& point(int i) const 00121 { return points_[i]; } 00122 00126 double* rawData() 00127 { return points_[0].begin(); } 00128 00132 const double* rawData() const 00133 { return points_[0].begin(); } 00134 00137 const std::vector<Array<double, Dim> >& pointVector() 00138 { return points_; } 00139 00140 // inherited from Streamable 00141 virtual void read (std::istream& is) 00142 { 00143 bool is_good = is.good(); 00144 if (!is_good) { 00145 THROW("Invalid geometry file!"); 00146 } 00147 int nump; 00148 is >> nump; 00149 ALWAYS_ERROR_IF(nump < 1, "Less than one point in cloud."); 00150 is_good = is.good(); 00151 if (!is_good) { 00152 THROW("Invalid geometry file!"); 00153 } 00154 points_.resize(nump); 00155 for (int i = 0; i < nump; ++i) { 00156 for (int d = 0; d < Dim; ++d) { 00157 is >> points_[i][d]; 00158 } 00159 } 00160 00161 is_good = is.good(); 00162 if (!is_good) { 00163 THROW("Invalid geometry file!"); 00164 } 00165 } 00166 00167 // inherited from Streamable 00168 virtual void write (std::ostream& os) const 00169 { 00170 os << std::setprecision(15); 00171 00172 int nump = points_.size(); 00173 os << nump << '\n'; 00174 for(int i = 0; i < nump; ++i) { 00175 os << points_[i][0]; 00176 for (int d = 1; d < Dim; ++d) { 00177 os << ' ' << points_[i][d]; 00178 } 00179 os << '\n'; 00180 } 00181 os << std::endl; 00182 } 00183 00184 private: 00185 std::vector<Array<double, Dim> > points_; 00186 00187 }; 00188 00189 00190 typedef PointCloud<3> PointCloud3D; 00191 typedef PointCloud<4> PointCloud4D; 00192 00193 00194 } // namespace Go 00195 00196 00197 00198 00199 #endif // _POINTCLOUD_H 00200
Generated on Tue Sep 21 15:44:17 2010 for GoTools Core by  doxygen 1.6.3