00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __DYNAMIC_MESH_H__
00020 #define __DYNAMIC_MESH_H__
00021
00022 #include <vector>
00023
00024 #ifdef USE_QT4
00025 #include <QtCore/QtCore>
00026 #endif
00027
00028 #include "../mesh/mesh.h"
00029 #include "../reader/parser_utils.h"
00030 #include "../reader/expatmm/ExpatXMLFileParser.h"
00031
00032
00033 namespace MeshNS {
00034
00040 class MeshSequence {
00041
00042 typedef MeshNS::SimpleVertex SimpleVertex;
00043 typedef MeshNS::SimpleFace SimpleFace;
00044 typedef MeshNS::SimpleVertices SimpleVertices;
00045 typedef MeshNS::SimpleFaces SimpleFaces;
00046 typedef ParserNS::Parser<MeshNS::SimpleVertex, MeshNS::SimpleFace> Parser;
00047
00048 public:
00049
00053 MeshSequence();
00060 MeshSequence(const std::vector<std::vector<MeshNS::SimpleVertex> > verts,
00061 const std::vector<std::vector<MeshNS::SimpleFace> >& faces,
00062 ParserNS::MeshSequenceType type);
00063
00068 MeshSequence(const std::string& filename);
00069
00070 ~MeshSequence();
00071
00077 PolyhedronPtr operator[](unsigned int i) {
00078
00079
00080
00081
00082 return _dmesh[i];
00083 }
00084
00085 inline void addPolyhedron(PolyhedronPtr poly) { _dmesh.push_back(poly);}
00086 inline void push_back(PolyhedronPtr poly) { addPolyhedron(poly); }
00092 const PolyhedronPtr operator[](unsigned int i) const {
00093
00094
00095 return _dmesh[i];
00096 }
00097
00102 PolyhedronPtr getNext() {
00103 PolyhedronPtr mesh= _dmesh[_current];
00104 _current= (_current % _last);
00105 return mesh;
00106 }
00107
00112 const PolyhedronPtr getNext() const {
00113 const PolyhedronPtr mesh= _dmesh[_current];
00114 _current= (_current % _last);
00115 return mesh;
00116 }
00117
00122 std::vector<SimpleVertices> getVertices(int index=-1) const;
00127 std::vector<SimpleFaces> getFaces(int index=-1) const;
00128
00133 size_t size() {
00134 return _dmesh.size();
00135 }
00136
00140 void invertNormal() {
00141 for (unsigned int i= 0; i < _dmesh.size(); ++i)
00142 for (MeshNS::VertexIter j= _dmesh[i]->vertices_begin(); j
00143 != _dmesh[i]->vertices_end(); ++j)
00144 _dmesh[i]->set_normal(j, -_dmesh[i]->normal(j));
00145 }
00146
00151 ParserNS::MeshSequenceType getMSType() const {
00152 return _mstype;
00153 }
00154
00158 void triangulate() {
00159 for (unsigned int i= 0; i < _dmesh.size(); ++i) {
00160 _dmesh[i]->triangulate();
00161 }
00162 }
00163
00164 private:
00165 void _loadMeshes(const std::vector<SimpleVertices> verts, const std::vector<
00166 SimpleFaces>& faces, ParserNS::MeshSequenceType type);
00167
00168 std::string _basename;
00169 std::vector<PolyhedronPtr> _dmesh;
00170 unsigned int _first;
00171 unsigned int _last;
00172 mutable unsigned int _current;
00173 ParserNS::MeshSequenceType _mstype;
00174 bool _shouldTriangulate;
00175 bool _forget;
00176 };
00177
00178 typedef boost::shared_ptr<MeshSequence> MeshSequencePtr;
00179 }
00180
00181 #endif