00001
00002
00003
00004
00005
00006
00007 #pragma once
00008
00009 #include "Listfixed.h"
00010 #include "QEM_Quadric.h"
00011
00012 namespace QEM {
00013
00014
00015 class Edge;
00016 class EdgeList;
00017
00018
00019 class FaceArray;
00020
00025 class Edge
00026 {
00027 public:
00028
00029 Edge (int FaceIndex1, int whichEdge, int VertexIndex1, int VertexIndex2);
00030
00031
00032 void assertValid();
00033 void printDebugString();
00034
00035
00036 int edgeIndexFirst () const;
00037 int edgeIndexSecond () const;
00038 int faceIndexFirst () const;
00039 int faceIndexSecond () const;
00040 bool hasFirstNeighbor () const;
00041 bool hasSecondNeighbor() const;
00042 bool hasFace (int faceIndex) const;
00043 bool isBorder () const;
00044
00045
00046 bool hasVertex (int vertexIndex) const;
00047 int getV1 () const;
00048 int getV2 () const;
00049
00050
00051 bool operator< (const Edge &e) const;
00052 bool operator== (const Edge &e) const;
00053 bool operator!= (const Edge &e) const;
00054 mfloat getCachedCost () const;
00055
00056
00057 void setFace1 (int faceIndex, int whichEdge);
00058 void setFace2 (int faceIndex, int whichEdge);
00059 void removeFace1 ();
00060 void removeFace2 ();
00061 void setCachedCost (mfloat cost);
00062 bool swapVertexIndex (int from1, int from2, int to);
00063
00064
00065
00066
00067
00068 static VertexArray *varray;
00069
00070 private:
00071 int v1;
00072 int v2;
00073
00074 mfloat cachedCost;
00075 int face1;
00076 int face2;
00077 };
00078
00079
00080
00081
00082
00083 class EdgeList : public listFixed< Edge >
00084 {
00085 public:
00086 typedef listFixed< Edge > parentClass;
00087 void sort (VertexArray *varray)
00088 {
00089 Edge::varray = varray;
00090 parentClass::sort();
00091 }
00092 };
00093
00094
00095 typedef EdgeList::iterator EdgePtr;
00096 typedef std::pair< EdgePtr, EdgePtr > EdgePair;
00097
00098
00099
00100
00101
00102 inline bool Edge::hasFace (int faceIndex) const
00103 { return ((face1/3) == faceIndex || (face2/3) == faceIndex); }
00104
00105 inline bool Edge::hasVertex (int vertexIndex) const
00106 { return (v1 == vertexIndex || v2 == vertexIndex); }
00107
00108 inline bool Edge::hasFirstNeighbor() const
00109 { assert (face1 >= -1); return (face1 >= 0); }
00110
00111 inline bool Edge::hasSecondNeighbor() const
00112 { assert (face2 >= -1); return (face2 >= 0); }
00113
00114 inline bool Edge::isBorder() const
00115 {
00116 if (face1 == -1 || face2 == -1)
00117 return true;
00118 assert(face1 >= -1 && face2 >= -1 && "Edge::isBorder(): one of our faces is invalid.");
00119 return false;
00120 }
00121
00122 inline mfloat Edge::getCachedCost() const
00123 { assert (cachedCost != -1); return cachedCost; }
00124
00125 inline void Edge::setCachedCost(mfloat cost)
00126 { cachedCost = fabs(cost);}
00127
00128 inline int Edge::getV1 () const
00129 { return v1; }
00130
00131 inline int Edge::getV2 () const
00132 { return v2; }
00133
00134 }