00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __TTree_h__
00014 #define __TTree_h__
00015
00016 #include <iterator>
00017
00018
00019 namespace subdiv {
00020
00021 template <typename V>
00022 class Averaging;
00023
00024 template <typename V>
00025 class TTree {
00026 public:
00027 TTree(V *vtx[3], int depth, TTree* parent) {
00028 _m_v[0] = vtx[0];
00029 _m_v[1] = vtx[1];
00030 _m_v[2] = vtx[2];
00031
00032 _m_p = parent;
00033
00034 _m_c[0] = NULL;
00035 _m_c[1] = NULL;
00036 _m_c[2] = NULL;
00037 _m_c[3] = NULL;
00038
00039 _m_t[0] = NULL;
00040 _m_t[1] = NULL;
00041 _m_t[2] = NULL;
00042
00043 _m_depth = depth;
00044 }
00045
00046
00047 ~TTree(void) {}
00048
00049
00050 V*& vertex(int i){return _m_v[i];}
00051
00052 TTree<V>*& neighbor(int i){return _m_t[i];}
00053 TTree<V>*& parent(void){return _m_p;}
00054 TTree<V>*& child(int i){return _m_c[i];}
00055
00056
00057 template <typename OutputIterator>
00058 void addLeafs(OutputIterator iter);
00059
00060 void subdivide(Averaging<V> *avrg);
00061 bool leaf(void ){
00062 return (!_m_c[0] && !_m_c[1] && !_m_c[2] && !_m_c[3]);
00063 }
00064
00065 private:
00066 V *_m_v[3];
00067 TTree<V> *_m_p;
00068 TTree<V> *_m_c[4];
00069 TTree<V> *_m_t[3];
00070
00071 int _m_depth;
00072
00073
00074 void newCoordEdgeVertices(V* vtx[3], Averaging<V> *avrg);
00075 void newCoordExistingVertices(Averaging<V> *avrg);
00076
00077 V* findNeighborVertex (int );
00078 V* makeOrFindVertex (int );
00079 void createNewElements(Averaging<V> *avrg);
00080 void subdivideLeaf(Averaging<V> *avrg);
00081 };
00082
00083 }
00084
00085
00086
00087 namespace subdiv {
00088
00089 template <typename V>
00090 int localVtxNumber(TTree<V> *tt, V* vtx){
00091 int j = (tt->vertex(0) == vtx) ? 0 : ((tt->vertex(1) == vtx) ? 1 :
00092 ((tt->vertex(2) == vtx) ? 2 : 3));
00093 assert(j!=3);
00094 return j;
00095 }
00096
00097 }
00098
00099
00100 #include "TTree.cc"
00101
00102
00103 #endif