//=========================================================================== // 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. //=========================================================================== 00019 #ifndef _REGULARMESH_H 00020 #define _REGULARMESH_H 00021 00022 #include "GoTools/tesselator/GeneralMesh.h" 00023 #include <vector> 00024 00028 namespace Go 00029 { 00030 00031 class Triangle 00032 { 00033 public: 00034 explicit Triangle(int index) : index_(index) {} 00035 void setIndex(int i) { index_ = i; } 00036 int index() const { return index_; } 00037 private: 00038 int index_; 00039 }; 00040 00047 class GO_API RegularMesh : public GeneralMesh 00048 { 00049 public: 00056 RegularMesh(int m = 20, int n = 20, 00057 bool use_normals = true, 00058 bool use_texcoords = false); 00059 00060 virtual ~RegularMesh(); 00061 00062 bool useNormals() 00063 { return use_norm_; } 00064 00065 bool useTexCoords() 00066 { return use_texc_; } 00067 00069 int numStrips() 00070 { return num_strips_; } 00071 00074 int stripLength() 00075 { return strip_length_; } 00076 00078 virtual int numTriangles() 00079 { return triangles_.size(); } 00080 00082 virtual int numVertices() 00083 { return vert_.size()/3; } 00084 00085 void resize(int m, int n); 00086 00087 00088 virtual double* vertexArray() { return &vert_[0]; } 00089 virtual double* paramArray() { return ¶m_[0]; } 00090 virtual int atBoundary(int idx); 00091 double* normalArray() { return &norm_[0]; } 00092 double* texcoordArray() { return &texc_[0]; } 00093 unsigned int* stripArray() { return &strips_[0]; } 00094 Triangle* triangleArray() { return &triangles_[0]; } 00095 virtual unsigned int* triangleIndexArray() { return &triangle_index_[0]; } 00096 00097 virtual RegularMesh* asRegularMesh(); 00098 00099 00100 private: 00101 bool use_norm_; 00102 bool use_texc_; 00103 int num_strips_; 00104 int strip_length_; 00105 00106 typedef std::vector<double> Vd; 00107 Vd vert_; 00108 Vd param_; 00109 Vd norm_; 00110 Vd texc_; 00111 std::vector<unsigned int> strips_; 00112 std::vector<Triangle> triangles_; 00113 std::vector<unsigned int> triangle_index_; 00114 00118 void calculateIndices() 00119 { 00124 strips_.resize(num_strips_*strip_length_); 00125 int last = 0; 00134 int m = strip_length_/2; // number of vertices along strip 00135 int i; 00136 for ( i = 0; i < num_strips_; ++i ) { 00137 for ( int j = 0; j < m; ++j ) { 00138 strips_[last++] = (i+1)*m+j ; 00139 strips_[last++] = i*m+j; 00140 } 00141 } 00146 triangles_.reserve(num_strips_*(strip_length_-2)); 00147 triangles_.clear(); 00148 triangle_index_.reserve(3*(num_strips_*(strip_length_-2))); 00149 for (i = 0; i < num_strips_; ++i) { 00150 for (int j = 0; j < strip_length_-2; ++j) { 00151 triangles_.push_back(Triangle(i*strip_length_ + j)); 00152 for (int h=0; h<3; ++h) 00153 triangle_index_.push_back(strips_[i*strip_length_ + j + h]); 00154 } 00155 } 00156 } 00157 00158 }; 00159 00160 } // namespace Go 00161 00162 00163 #endif // _REGULARMESH_H 00164