Files Classes Functions Hierarchy
00001 #ifndef BSPTREED2DISPREGIONS01_H 00002 #define BSPTREED2DISPREGIONS01_H 00003 00004 #include <bsptreeD2.h> 00005 #include <gobj.h> 00006 #include <graphmisc.h> 00007 #include <pointsdisplay.h> 00008 #include <treeindexedD2iter.h> 00009 00013 template< typename PT, typename PD, typename INDX > 00014 class bsptreeD2dispregions01 : public gobjContainer 00015 { 00016 public: 00017 00020 PD delta; 00021 00023 bsptreeD2<PT,PD,INDX> & bsp; 00025 bsptreeD2dispregions01( bsptreeD2<PT,PD,INDX> & bsp_ ) 00026 : gobjContainer(true), delta(0.2), bsp(bsp_) {} 00027 00029 void update(); 00030 00031 }; 00032 00033 //--------------------------------------------------------- 00034 // Implementation 00035 00036 template< typename PT, typename PD, typename INDX > 00037 void bsptreeD2dispregions01<PT,PD,INDX>::update() 00038 { 00039 nuke(); 00040 00041 if (bsp.empty()) 00042 return; 00043 00044 uint sz; 00045 00046 INDX region; 00047 00048 INDX hpindex; 00049 INDX hindex; 00050 00051 00052 // gobjQuadric * q2 = new gobjQuadric(); 00053 // q2->radius = 0.05; 00054 // q2->slices=30; 00055 // q2->loops=7; 00056 00057 PT parentnormal; 00058 PT hnormal; 00059 00060 vector<PT> ptlist; 00061 vector<string> ptlabels; 00062 00063 for ( treeindexedD2iterleaf<INDX> i1(bsp.tree); !i1; ++i1) 00064 { 00065 00066 region = i1()->index; 00067 00068 //cout << SHOW(region) << endl; 00069 00070 sz = i1.path.size(); 00071 if (sz<3) 00072 { 00073 if (sz!=2) 00074 continue; 00075 00076 hindex = i1.path[0]->index; 00077 //cout << SHOW(hindex) << endl; 00078 //cout << SHOW(bsp.vi.size()) << endl; 00079 00080 assert(hindex<bsp.vi.size()); 00081 halfspaceD2<PT,PD> & h( bsp.vi[ hindex ] ); 00082 00083 PT p0 = (h.p0 + h.p1)*0.5; 00084 parentnormal=h.normal; 00085 //cout << SHOW(parentnormal) << endl; 00086 parentnormal.normalize(); 00087 parentnormal *= delta; 00088 //cout << SHOW(parentnormal) << endl; 00089 if (i1.path[0]->isright(region)) 00090 parentnormal *= -1; 00091 00092 //cout << SHOW(p0) << endl; 00093 p0 += parentnormal; 00094 //cout << SHOW(p0) << endl; 00095 00096 ptlist.push_back(p0); 00097 00098 { 00099 stringstream ss; 00100 ss << region; 00101 ptlabels.push_back(ss.str()); 00102 } 00103 00104 continue; 00105 } 00106 00107 hpindex = i1.path[sz-3]->index; 00108 hindex = i1.path[sz-2]->index; 00109 // h2 is the parent half-space of h1. 00110 halfspaceD2<PT,PD> & hp( bsp.vi[ hpindex ] ); 00111 halfspaceD2<PT,PD> & h( bsp.vi[ hindex ] ); 00112 00113 //cout << SHOW(region) << " " << SHOW(hpindex) << " " << SHOW(hindex) << endl; 00114 //cout << "hp: " << hp.print() << endl; 00115 //cout << "h: " << h.print() << endl; 00116 00117 PT p0; 00118 h.intersection(p0,hp.p0,hp.p1); 00119 00120 parentnormal=hp.normal; 00121 parentnormal.normalize(); 00122 parentnormal *= delta; 00123 //cout << SHOW(parentnormal) << endl; 00124 //cout << SHOW(i1.path[sz-3]->isrightinternal(hindex)) << endl; 00125 00126 if (i1.path[sz-3]->isrightinternal(hindex)) 00127 parentnormal *= -1; 00128 //cout << SHOW(parentnormal) << endl; 00129 00130 p0 += parentnormal; 00131 //cout << SHOW(p0) << endl; 00132 00133 hnormal = h.normal; 00134 hnormal.normalize(); 00135 hnormal *= delta; 00136 00137 if (i1.path[sz-2]->isright(region)) 00138 hnormal *= -1; 00139 00140 //cout << SHOW(hnormal) << endl; 00141 00142 p0 += hnormal; 00143 00144 //cout << SHOW(p0) << endl; 00145 //cout << endl; 00146 00147 ptlist.push_back(p0); 00148 00149 { 00150 stringstream ss; 00151 ss << region; 00152 ptlabels.push_back(ss.str()); 00153 } 00154 00155 // push(new gobjMySphereDraw(p0,q2)); 00156 00157 } 00158 00159 push(new gobjglPushAttrib(GL_LIGHTING)); 00160 push(new gobjglPushAttrib(GL_CURRENT_BIT)); 00161 00162 push(new gobjglDisable(GL_LIGHTING)); 00163 00164 push(new gobjglColor3f(1.0,0.0,0.0)); 00165 00166 pointsdisplay2D< PT > pd( *this, ptlist, ptlabels ); 00167 00168 push(new gobjglPopAttrib()); 00169 push(new gobjglPopAttrib()); 00170 } 00171 00172 00173 #endif 00174
1.5.8