00001 #ifndef __MESH_H
00002 #define __MESH_H
00003
00004 #include <stdlib.h>
00005 #include <esg/Definitions.h>
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 namespace esg {
00026
00027 class OGSCENE_EXPORT Mesh {
00028 public:
00029
00030 struct Vert;
00031 struct Edge;
00032 struct Plane;
00033 struct Solid;
00034
00035
00036 struct MiniMax { float xmin, xmax, ymin, ymax, zmin, zmax; };
00037
00038 struct Vert {
00039 int jmeno_vrcholu;
00040 float fxyz;
00041 int qi;
00042 int valid;
00043 struct Vert *next_vertex;
00044 struct Vert *previous_vertex;
00045 float x,y,z;
00046 Vector3 normal;
00047
00048 bool hasValidNormal (void) const
00049 {
00050 if (normal.x!=0 || normal.y!=0 || normal.z!=0) return true;
00051 else return false;
00052 }
00053 };
00054
00055 enum EdgeType{
00056 ZAKRYTA = 1,
00057 OBRYSOVA = 2,
00058 VNITRNI = 4,
00059 ODPADOVA = 8,
00060 NULOVA = 0x10,
00061 TELESOVA = 0x20
00062 };
00063
00064 struct Edge {
00065 int jmeno_hrany;
00066 enum EdgeType druh_hrany;
00067 struct Edge *next_edge;
00068 struct Edge *previous_edge;
00069 struct Vert *V1;
00070 struct Vert *V2;
00071 struct Plane *LeftLoop;
00072 struct Plane *RightLoop;
00073 struct Edge *LeftIn;
00074 struct Edge *RightOut;
00075 struct Edge *LeftOut;
00076 struct Edge *RightIn;
00077 };
00078
00079 struct Plane {
00080 int jmeno_roviny;
00081 struct Plane *next_plane;
00082 struct Plane *previous_plane;
00083 struct Edge *any_edge;
00084 float a,b,c,d;
00085 float skalar;
00086 };
00087
00088 struct Solid {
00089 int solid_name;
00090 struct Vert *first_vertex;
00091 struct Edge *first_edge;
00092 struct Plane *first_plane;
00093 struct Solid *next_solid;
00094 struct Solid *previous_solid;
00095 struct MiniMax cover;
00096 Solid (int n = 0)
00097 : solid_name(n),
00098 first_vertex(NULL),
00099 first_edge(NULL),
00100 first_plane(NULL),
00101 next_solid(NULL),
00102 previous_solid(NULL) {}
00103 };
00104
00105
00106
00107 protected:
00108 int pocet_vrcholu;
00109 int pocet_hran;
00110 int pocet_rovin;
00111 struct Solid* pSolid;
00112 bool outwardNormals;
00113
00114
00115 Vert* pActVert;
00116 Edge* pActEdge;
00117 Plane* pActPlane;
00118 Solid* pActSolid;
00119
00120 protected:
00121
00122 void AppendVertex (Solid *S, Vert *V);
00123 void AppendEdge (Solid *S, Edge *E);
00124 void AppendFace (Solid *S, Plane *NP);
00125 void DeleteVertex (Solid *S, Vert *V);
00126 void DeleteEdge (Solid *S, Edge *E);
00127 void DeleteFace (Solid *S, Plane *NP);
00128 void MoveVertex (Solid *S, Solid *SM, Vert *V);
00129 void MoveEdge (Solid *S, Solid *SM, Edge *E);
00130 void MoveFace (Solid *S, Solid *SM, Plane *NP);
00131
00132
00133 Vert *NewVertex (Solid *S, float xp, float yp, float zp);
00134 Edge *NewEdge (Solid *S, Vert *V1p, Vert *V2p, Plane *P1p, Plane *P2p);
00135 Plane *NewPlane (Solid *S, float a1, float b1, float c1, float d1);
00136
00137
00138 void Copy_solid (Solid *Sorigin, Solid *Scopy);
00139 void Delete_solid (Solid **S);
00140
00141
00142 int Paralel_planes (float a,
00143 float b,
00144 float c,
00145 float ar,
00146 float br,
00147 float cr,
00148 int& same_orientation);
00149
00150 void Vertex_Plane_position (struct Solid& S,
00151 float ar,
00152 float br,
00153 float cr,
00154 float dr,
00155 int& Pozitiv,
00156 int& Negativ);
00157
00158 void Orient_Edge (Edge *E, Plane *F, Vert **Vin, Vert **Vout);
00159 Edge* Next_Edge_in_loop (Edge *CE, Vert **Vin, Vert **Vout);
00160 Edge* Previous_Edge_in_loop (Edge *CE, Vert **Vin, Vert **Vout);
00161 void ClasifyEdges (Solid *S);
00162
00163
00164
00165 Vert* MV (float xp, float yp, float zp);
00166 Plane* MF (float a1, float b1, float c1, float d1);
00167 Solid* MVSF (Plane* F, Vert* V);
00168 void MEV (Solid *S, Vert* V1p, Vert* V2p, Edge** E, Plane* F);
00169
00170
00171 void ReplaceEdge (Edge* E1, Edge* E, Edge* E2);
00172
00173
00174 void SEMV (Solid *S, Edge* E1, Vert* V, Edge** E2);
00175 void MEF (Solid *S,Vert* V1p,Vert* V2p,Plane* F1,Plane* F2,Edge** E);
00176 void MEnotF (Solid *S,Vert* V1p,Vert* V2p,Plane* F1,Plane* F2,Edge** E);
00177
00178 Vert* Vertex_of_cut (Vert* V1, Vert* V2);
00179 Plane* This_loop (Edge* E, Vert* V);
00180 void ConnectEdge (Edge* E1, Edge* E, Edge* E2, Plane* P);
00181 void KE (Edge* E, Vert* Vin, Plane* P1,Plane* P2);
00182 void SeparateSolids (Solid** NS, Solid** Odpad);
00183
00184
00185
00186 public:
00187 Mesh (bool n = true) {
00188 pocet_vrcholu = 0; pocet_hran = 0; pocet_rovin = 0;
00189 pSolid = NULL; outwardNormals = n;
00190 }
00191 virtual ~Mesh() { if (pSolid) Delete_solid(&pSolid); }
00192
00193 virtual void rotate (const Matrix3&);
00194 virtual void translate (const Vector3&);
00195 virtual void transform (const Matrix4&);
00196 virtual void scale (float, float, float);
00197
00198 virtual void resetActSolid();
00199 virtual int goToNextSolid();
00200 virtual void resetActPlane();
00201 virtual Plane* getActPlane();
00202 virtual int goToNextPlane();
00203 virtual void resetActEdge();
00204 virtual int goToNextEdge();
00205
00206
00207
00208
00209 virtual Vertex3 getActVert1(bool);
00210 virtual Vertex3 getActVert2(bool);
00211 virtual Vertex3 getActVert();
00212 virtual Vertex3 getActVertNormal1(bool);
00213 virtual Vertex3 getActVertNormal2(bool);
00214 virtual Vertex3 getActVertNormal();
00215
00216 virtual int getActVertID1(bool);
00217 virtual int getActVertID2(bool);
00218 virtual int getActVertID();
00219
00220 virtual int getActPlaneID();
00221 virtual Vertex3 getActPlaneNormal() const;
00222 virtual Vector3 getActPlaneCentroid();
00223 virtual double getActPlaneArea();
00224
00225 virtual void resetEdgeWalkInSolid();
00226 virtual int stepInEdgeWalkInSolid();
00227
00228 virtual void resetVertWalkInSolid();
00229 virtual bool stepInVertWalkInSolid();
00230
00231 virtual int numberOfVertices (void) const { return pocet_vrcholu; }
00232 virtual int numberOfEdges (void) const { return pocet_hran; }
00233
00234 virtual bool hasOutwardNormals (void) const { return outwardNormals; }
00235
00236 virtual void turnInsideOut (void);
00237 };
00238
00239 };
00240
00241 #endif // __MESH_H