00001
00009 #ifndef MESHIO_H
00010 #define MESHIO_H
00011
00012 #include <vector>
00013
00014 #include "globals.h"
00015 #include "hash_classes.h"
00016 #include "hash_map.h"
00017 #include "util.h"
00018 #include "cell.h"
00019
00020
00021 class Simulation;
00022 class BoundaryMesh;
00023 class BezierMesh;
00024
00031 class MeshInput {
00032 private:
00033 FILE *node_file;
00034 FILE *ele_file;
00035 FILE *edge_file;
00036 FILE *bdry_file;
00037
00038
00039
00040
00041 struct Node {
00042 int num;
00043 bool added;
00044 Point2D p;
00045 LinearData d;
00046 Node( char *node_file_line );
00047 void print();
00048 };
00049
00050
00051
00052
00053
00054 hashers::hash_map<unsigned, BoundaryVertex*> bdry_verts;
00055 hashers::hash_map<unsigned, BoundaryEdge*> bdry_edges;
00056 hashers::hash_map<unsigned, BoundaryFace*> bdry_faces;
00057 hashers::hash_map<unsigned, BezierVertex*> bez_verts;
00058 hashers::hash_map<unsigned, BezierEdge*> bez_edges;
00059
00060 struct BoundaryVertexData {
00061 unsigned idx;
00062 unsigned node;
00063 };
00064
00065 struct BoundaryEdgeData {
00066 unsigned idx;
00067 unsigned v0, v1;
00068 bool closed;
00069 double restlength;
00070 int fixed;
00071 int color;
00072 std::vector<Point2D> d;
00073 std::vector<double> k;
00074 };
00075
00076 struct BoundaryFaceData {
00077 unsigned idx;
00078 double min_angle;
00079 int color;
00080 std::vector<BoundaryEdge*> edges;
00081 };
00082
00083 struct BezierEdgeData {
00084 unsigned idx;
00085 unsigned v0, v1, v2;
00086 bool is_bdry;
00087 int bdry;
00088 double u0, u1;
00089 };
00090
00091 struct BezierTriangleData {
00092 unsigned idx;
00093 bool inverted;
00094 unsigned bdry_face;
00095 unsigned e0, e1, e2;
00096 };
00097
00098 int read_boundary_vertex_data( BoundaryVertexData *data );
00099 int read_boundary_edge_data( BoundaryEdgeData *data );
00100 int read_boundary_face_data( BoundaryFaceData *data );
00101 int read_bezier_edge_data( BezierEdgeData *data );
00102 int read_bezier_triangle_data( BezierTriangleData *data );
00103
00104 BezierMesh *bezier_mesh;
00105 BoundaryMesh *bdry_mesh;
00106
00107 public:
00108 MeshInput(BezierMesh* _bezier_mesh, BoundaryMesh* _bdry_mesh) :
00109 bezier_mesh(_bezier_mesh), bdry_mesh(_bdry_mesh) {}
00110
00111 bool read(const char *filename);
00112 };
00113
00120 class MeshOutput{
00121 private:
00122 FILE *node_file;
00123 FILE *ele_file;
00124 FILE *edge_file;
00125 FILE *bdry_file;
00126
00127
00128 hashers::hash_map<ControlPoint, unsigned, ControlPointHasher> node_hash;
00129 hashers::hash_map<BezierEdge*, unsigned> bez_edge_hash;
00130 hashers::hash_map<BoundaryVertex*, unsigned> bdry_vert_hash;
00131 hashers::hash_map<BoundaryEdge*, unsigned> bdry_edge_hash;
00132 hashers::hash_map<BoundaryFace*, unsigned> bdry_face_hash;
00133
00134
00135
00136
00137 int node_to_file( ControlPoint cp, DataPoint dp );
00138 int edge_to_file( BezierEdge *edge );
00139 int ele_to_file( BezierTriangle *tri, BezierMesh *bezier_mesh );
00140 int bdry_vert_to_file( BoundaryVertex *vert );
00141 int bdry_edge_to_file( BoundaryEdge *edge );
00142 int bdry_face_to_file( BoundaryFace *face );
00143
00144 BezierMesh *bezier_mesh;
00145 BoundaryMesh *bdry_mesh;
00146 public:
00147 MeshOutput(BezierMesh* _bezier_mesh, BoundaryMesh* _bdry_mesh) :
00148 bezier_mesh(_bezier_mesh), bdry_mesh(_bdry_mesh) {}
00149
00150 bool write(const char *filename);
00151 };
00152
00153
00160 class MeshBinaryInput
00161 {
00162 public:
00163 MeshBinaryInput(Simulation* _sim);
00164 bool read(const char *filename);
00165
00166 private:
00167 Simulation *sim;
00168 BezierMesh *bezier_mesh;
00169 BoundaryMesh *bdry_mesh;
00170 };
00171
00172
00179 class MeshBinaryOutput
00180 {
00181 public:
00182 MeshBinaryOutput(Simulation* _sim);
00183 MeshBinaryOutput(BezierMesh *_bezier_mesh, BoundaryMesh *_bdry_mesh);
00184 bool write(const char *filename);
00185
00186 static bool write(const char *filename, BezierMesh *bez,
00187 BoundaryMesh *bdry);
00188 static bool write(const char *filename, Simulation *sim);
00189
00190
00191 private:
00192 Simulation *sim;
00193 BezierMesh *bezier_mesh;
00194 BoundaryMesh *bdry_mesh;
00195
00196 };
00197
00198 #endif
00199
00200