QEM_Edge.h

00001 // QEM_Edge.h: interface for the Edge class.
00002 //
00003 // Author: Matt Loper
00004 // $Revision: 1.2 $
00005 // $Date: 2002/05/12 22:31:53 $
00006 
00007 #pragma once
00008 
00009 #include "Listfixed.h"
00010 #include "QEM_Quadric.h"
00011 
00012 namespace QEM {
00013 
00014 // CLASSES DECLARED IN THIS FILE
00015 class Edge;
00016 class EdgeList;
00017 
00018 // not declared in this file -- just used by a method
00019 class FaceArray;
00020 
00025 class Edge
00026 {
00027     public:
00028         // constructor
00029             Edge (int FaceIndex1, int whichEdge, int VertexIndex1, int VertexIndex2);
00030 
00031             // methods
00032             void assertValid();
00033             void printDebugString();
00034 
00035             // accessors (face-related)
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         // accessors (vertex-related)
00046         bool   hasVertex        (int vertexIndex)   const;
00047         int    getV1            ()                  const;
00048         int    getV2            ()                  const;
00049 
00050         // accessors (comparison-related)
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             // mutators
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         // when edges are compared, sometimes we need to compare
00065         // their lengths, which requires getting at their vertices.
00066         // [note: I'd prefer this not be static, but given the state
00067         // of std::list.sort(pred), I think this is the only way]
00068         static VertexArray *varray;
00069 
00070     private:
00071             int v1; // index of vertex 1
00072             int v2; // index of vertex 2
00073 
00074             mfloat cachedCost; // quadric cost
00075             int face1; // face index
00076             int face2; // face index
00077 };
00078 
00079 
00080 
00081 // list::sort has a bug (with sorting > 32767 elements). 
00082 // the "listFixed" template fixes that.
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 //                  inlined methods (Edge)
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 } // namespace QEM

Generated on Tue May 21 03:34:51 2002 for Archimedes by doxygen1.2.15