00001
00002
00003
00004
00005
00006 #ifndef meshImport3D_hh
00007 #define meshImport3D_hh
00008
00009 #include <vector>
00010 #include <map>
00011
00012 #if __ICC == 800
00013 # include <hash_map>
00014 # define __gnu_cxx std
00015 #else
00016 # if __GNUC__ > 2
00017 # include <ext/hash_map>
00018 # if __GNUC__ == 3 &&__GNUC_MINOR__ < 1
00019 # define __gnu_cxx std
00020 # endif
00021 # else
00022 # include <hash_map>
00023 # define __gnu_cxx std
00024 # endif
00025 #endif
00026
00027 #include "mesh.hh"
00028 #include "toolbox/array.hh"
00029
00030 namespace concepts {
00036 struct Index {
00038 Array<uint> n_;
00046 void sort_();
00047
00048 Index(const uint n0);
00049 Index(const uint n0, const uint n1);
00051 Index(const uint n0, const uint n1, const uint n2);
00053 Index(const uint n0, const uint n1, const uint n2, const uint n3);
00055 Index(const Index& i) : n_(i.n_) {}
00057 uint size() const { return n_.size(); }
00059 uint operator[](const uint i) const { return n_[i]; }
00061 uint& operator[](const uint i) { return n_[i]; }
00063 bool operator<(const concepts::Index& y) const;
00065 bool operator==(const concepts::Index& y) const;
00066 };
00067 }
00068
00069 namespace __gnu_cxx {
00071 size_t hash_value(const concepts::Index& i);
00072
00074 template<>
00075 struct hash<concepts::Index> {
00077 size_t operator()(const concepts::Index& x) const {
00078 return hash_value(x); }
00079 };
00080
00082 struct IndexEqual {
00083 bool operator()(const concepts::Index& x, const concepts::Index& y) const {
00084 return x == y;
00085 }
00086 };
00087 }
00088
00089 namespace concepts {
00090
00091
00092
00107 class Import3dMesh : public Mesh3 {
00108 public:
00149 Import3dMesh(const std::string coord, const std::string elms,
00150 const std::string boundary, const uint idxStart = 1,
00151 const bool leftHand = false, const uint elmtyp = 0);
00152 virtual ~Import3dMesh();
00153 virtual uint ncell() const { return cell_.size(); }
00154 virtual Scan3* scan() { return new S(cell_); }
00155
00156 class NodeCell;
00157 class NodeTetrahedron;
00158 class NodeHexahedron;
00159 protected:
00160 virtual std::ostream& info(std::ostream& os) const;
00161 private:
00163 class S : public Scan<Cell3> {
00164 public:
00165 inline S(std::vector<Cell3*>& cell) :
00166 idx_(cell.begin()), cell_(cell) {}
00167 inline S(const S& scan) : idx_(scan.idx_), cell_(scan.cell_) {}
00168 inline bool eos() const { return idx_ == cell_.end(); }
00169 inline Cell3& operator++(int) { return *(*idx_++); }
00170 inline Scan3* clone() const { return new S(*this); }
00171 private:
00172 std::vector<Cell3*>::iterator idx_;
00173 std::vector<Cell3*>& cell_;
00174 };
00176 std::vector<Vertex*> vtx_;
00178 std::vector<Edge*> edg_;
00180 __gnu_cxx::hash_map<Index, Triangle*, __gnu_cxx::hash<Index>,
00181 __gnu_cxx::IndexEqual> tri_;
00183 __gnu_cxx::hash_map<Index, Quad*, __gnu_cxx::hash<Index>,
00184 __gnu_cxx::IndexEqual> quad_;
00186 std::vector<Cell3*> cell_;
00187
00191 uint readInts_(const std::string& i, std::vector<int>& v) const;
00192
00194 void clear_(std::vector<NodeCell*>& cells) const;
00195
00206 void createEdge_(uint ix, uint iy,
00207 std::map<uint, std::map<uint, Edge*> >& edges,
00208 Attribute attr = 0, Edge** e = 0);
00216 Triangle* createTriangle_(const Index& I,
00217 std::map<uint, std::map<uint, Edge*> >& edges,
00218 Attribute attr = 0);
00226 Quad* createQuad_(const Index& I,
00227 std::map<uint, std::map<uint, Edge*> >& edges,
00228 Attribute attr = 0);
00229 };
00230
00234 class Import3dMesh::NodeCell {
00235 protected:
00237 Array<uint> nodes_;
00238 public:
00243 NodeCell(const uint size) : nodes_(size) {}
00244 virtual ~NodeCell();
00246 uint operator[](const uint i) const { return nodes_[i]; }
00248 uint size() const { return nodes_.size(); }
00249
00251 virtual uint nofaces() const = 0;
00253 virtual Index faceIndex(const uint i) = 0;
00255 virtual Quad** quad(const uint i) = 0;
00257 virtual Triangle** triangle(const uint i) = 0;
00259 virtual Cell3* cell(const std::vector<Real3d>& vertices) const = 0;
00260 };
00261
00265 class Import3dMesh::NodeTetrahedron : public Import3dMesh::NodeCell {
00266 private:
00268 Array<Triangle*> faces_;
00269 public:
00273 NodeTetrahedron(const uint one, const uint two, const uint three,
00274 const uint four, const bool leftHand = false);
00275 virtual ~NodeTetrahedron();
00276 virtual uint nofaces() const { return 4; }
00277 virtual Index faceIndex(const uint i);
00278 virtual Tetrahedron3d* cell(const std::vector<Real3d>& vertices) const;
00279 virtual Quad** quad(const uint i) { return 0; }
00280 virtual Triangle** triangle(const uint i) { return &(faces_[i]); }
00281 };
00282
00286 class Import3dMesh::NodeHexahedron : public Import3dMesh::NodeCell {
00287 private:
00289 Array<Quad*> faces_;
00291 uint elmType_;
00292 public:
00296 NodeHexahedron(const uint one, const uint two, const uint three,
00297 const uint four, const uint five, const uint six,
00298 const uint seven, const uint eight, const uint elmType = 0);
00299 virtual ~NodeHexahedron();
00300 virtual uint nofaces() const { return 6; }
00301 virtual Index faceIndex(const uint i);
00302 virtual Cell3* cell(const std::vector<Real3d>& vertices) const;
00303 virtual Quad** quad(const uint i) { return &(faces_[i]); }
00304 virtual Triangle** triangle(const uint i) { return 0; }
00305 };
00306
00307 }
00308
00309 #endif // meshImport3D_hh