00001
00002
00003
00004 #ifndef Tetra_H
00005 #define Tetra_H
00006
00007
00008 #include "point3d.h"
00009 #include "util.h"
00010
00011 #include "node.h"
00012
00013 #include "nodearray.h"
00014 #include "edgearray.h"
00015 #include "facearray.h"
00016 #include "tetraarray.h"
00017
00018 class Node;
00019 class Edge;
00020 class Face;
00021 class NodeArray;
00022 class EdgeArray;
00023 class FaceArray;
00024 class TetraArray;
00025 class BoundingSphereLeaf;
00026
00027 class Tetra {
00028 private:
00029
00030 Node *node[4];
00031 Edge *edge[6];
00032 Face *face[4];
00033
00034 TetraArray* tetraarray_p;
00035
00036 int marker;
00037
00038 BoundingSphereLeaf* boundingsphere;
00039
00040 public:
00041 Tetra();
00042 ~Tetra();
00043 static const char* rcsid;
00044 static int debug;
00045
00046 void init(NodeArray* nodearray_p_in, EdgeArray* edgearray_p_in,
00047 FaceArray* facearray_p_in, TetraArray* tetraarray_p_in,
00048 int i0, int i1, int i2, int i3);
00049
00050 void init(NodeArray* nodearray_p_in, EdgeArray* edgearray_p_in,
00051 FaceArray* facearray_p_in, TetraArray* tetraarray_p_in,
00052 Node* n0, Node* n1, Node* n2, Node* n3);
00053
00054 void init();
00055
00056 int getIndex(void);
00057 TetraArray* getTetraArray();
00058
00059 BoundingSphereLeaf* getBoundingSphere();
00060 void setBoundingSphere(BoundingSphereLeaf* sphere);
00061
00062
00063 int hasNodeLink(Node* node);
00064 Node* getNodeLink(int which);
00065 Node* getOtherNode(Node* n0, Node* n1, Node* n2);
00066 void deleteNodeLink(Node* n);
00067
00068 int hasEdgeLink(Edge* edge);
00069 Edge* getEdgeLink(int which);
00070 void deleteEdgeLink(Edge* e);
00071 Edge* getEdge(int n0, int n1);
00072 int getEdgeIndex(Edge* e);
00073
00074
00075 int hasFaceLink(Face* face);
00076 Face* getFaceLink(int which);
00077 void deleteFaceLink(Face* f);
00078
00079 void unlink();
00080
00081 int isAdjacent(Tetra *t);
00082
00083 void draw(int do_texture);
00084 void drawlabel(float offset);
00085 void drawnormals();
00086
00087 void drawMarker();
00088 void setMarker(int value);
00089 int getMarker(void);
00090
00091 Point3D getCenter();
00092 double getRadius();
00093 double getAveRadius();
00094 double getVolume();
00095 void computenormals();
00096
00097 int isFacingInwards(Face* f);
00098
00099
00100 int intersectsFace(Face* f, Point3D* intPt);
00101 int intersectsEdge(Edge* e, Point3D* intPt);
00102
00103 int SanityCheck(TetraArray* real_fa_p);
00104 friend ostream& operator<<(ostream& os, const Tetra& f);
00105
00106 };
00107
00108 inline BoundingSphereLeaf* Tetra::getBoundingSphere()
00109 { return(boundingsphere); }
00110
00111 inline void Tetra::setBoundingSphere(BoundingSphereLeaf* sphere)
00112 { boundingsphere = sphere; }
00113
00114 inline Node* Tetra::getNodeLink(int which)
00115 { if ((which < 0) || (which > 4)) return(NULL);
00116 return(node[which]);
00117 }
00118
00119 inline void Tetra::deleteNodeLink(Node* n)
00120 { for (int i=0; i<4; i++)
00121 if (node[i] == n)
00122 node[i] = NULL;
00123 }
00124
00125 inline Edge* Tetra::getEdgeLink(int which)
00126 { if ((which < 0) || (which > 6)) return(NULL);
00127 return(edge[which]);
00128 }
00129
00130 inline void Tetra::deleteEdgeLink(Edge* e)
00131 { for (int i=0; i<6; i++)
00132 if (edge[i] == e)
00133 edge[i] = NULL;
00134 }
00135
00136 inline int Tetra::getEdgeIndex(Edge* e)
00137 { for (int i=0; i<6; i++)
00138 if (edge[i] == e)
00139 return i;
00140 return -1;
00141 }
00142
00143 inline Face* Tetra::getFaceLink(int which)
00144 { if ((which < 0) || (which > 4)) return(NULL);
00145 return(face[which]);
00146 }
00147
00148 inline void Tetra::deleteFaceLink(Face* f)
00149 { for (int i=0; i<4; i++)
00150 if (face[i] == f)
00151 face[i] = NULL;
00152 }
00153
00154 inline double Tetra::getRadius()
00155 { double radius = 0;
00156 Point3D cent = getCenter();
00157 for (int i=0; i<4; i++) {
00158 double currad = node[i]->p.Dist(cent);
00159 if (currad > radius)
00160 radius = currad;
00161 }
00162 return radius;
00163 }
00164
00165 inline double Tetra::getAveRadius()
00166 {
00167 double radius = 0;
00168 Point3D cent = getCenter();
00169 for(int i=0; i<4; i++) {
00170 radius += node[i]->p.Dist(cent);
00171 }
00172 radius /= 4;
00173 return radius;
00174 }
00175
00176 inline int Tetra::isAdjacent(Tetra *t)
00177 {
00178 if (node[0]->hasTetraLink(t) || node[1]->hasTetraLink(t) ||
00179 node[2]->hasTetraLink(t) || node[4]->hasTetraLink(t) )
00180 return(1);
00181 return(0);
00182 }
00183
00184 inline TetraArray* Tetra::getTetraArray()
00185 { return(tetraarray_p); }
00186
00187 inline void Tetra::setMarker(int value)
00188 { marker = value; }
00189
00190 inline int Tetra::getMarker()
00191 { return(marker); }
00192
00193 inline Point3D Tetra::getCenter()
00194 { return ((node[0]->p + node[1]->p + node[2]->p + node[3]->p)/4.0); }
00195
00196
00197
00198 #endif