Files Classes Functions Hierarchy
00001 #ifndef CONVEXREGIONSD2_H 00002 #define CONVEXREGIONSD2_H 00003 00004 #include <cassert> 00005 #include <vector> 00006 using namespace std; 00007 00008 #include <halfspaceD2.h> 00009 #include <partitionspace.h> 00010 #include <polytopeD2linked.h> 00011 #include <typedefs.h> 00012 00019 template< typename PT, typename PD > 00020 class convexregionsD2 00021 { 00022 public: 00023 00025 vector< PT > & pts; 00027 vector< polytopeD2linked > vi; 00028 00030 convexregionsD2(vector<PT> & pts_); 00031 00033 boolc split(uintc k, halfspaceD2<PT,PD> const & h); 00034 00037 static bool splittouchesface; 00040 static bool splittouchespoint; 00043 static uint splittouchesindex; 00044 00045 }; 00046 00047 //--------------------------------------------------------- 00048 // Implementation 00049 00050 template< typename PT, typename PD > 00051 bool convexregionsD2<PT,PD>::splittouchesface=false; 00052 template< typename PT, typename PD > 00053 bool convexregionsD2<PT,PD>::splittouchespoint=false; 00054 template< typename PT, typename PD > 00055 uint convexregionsD2<PT,PD>::splittouchesindex=0; 00056 00057 template< typename PT, typename PD > 00058 convexregionsD2<PT,PD>::convexregionsD2(vector<PT> & pts_) 00059 : pts(pts_) 00060 { 00061 vi.push_back( polytopeD2linked() ); 00062 assert(pts.size()>0); 00063 } 00064 00065 00066 template< typename PT, typename PD > 00067 boolc convexregionsD2<PT,PD>::split 00068 ( 00069 uintc k, 00070 halfspaceD2<PT,PD> const & h 00071 ) 00072 { 00073 assert(k<vi.size()); 00074 00075 polytopeD2linked & x(vi[k]); 00076 00077 uintc sz = x.pi.size(); 00078 assert(sz>1); 00079 00080 uint ci[sz]; 00081 00082 PT *beg = & x.pi[0]; 00083 h.classify(ci,beg,beg+sz); 00084 00085 // The two cutting positions 00086 uint cut[2]; 00087 00088 // Problem with templates so cut and paste the type. 00089 enum { undefined, below, on, above }; 00090 00091 // cut[0] = undefined; 00092 // cut[1] = undefined; 00093 00094 uint index = 0; 00095 uint i2; 00096 00097 for (uint i=0; i<sz; ++i) 00098 { 00099 if (ci[i]==on) 00100 { 00101 cut[index] = i; 00102 ++index; 00103 if (index==2) 00104 i=sz; 00105 continue; 00106 } 00107 00108 i2 = (i+1)%sz; 00109 if (ci[i]==above) 00110 { 00111 if (ci[i2]==below) 00112 { 00113 cut[index] = i; 00114 ++index; 00115 if (index==2) 00116 i=sz; 00117 continue; 00118 } 00119 } 00120 } 00121 00122 // There should be two cuts. 00123 if (index==0) 00124 return false; 00125 00126 if (index==1) 00127 { 00128 splittouchesface=false; 00129 splittouchespoint=true; 00130 splittouchesindex = cut[0]; 00131 return false; 00132 } 00133 00134 //uint a; 00135 uint status=0; 00136 if(cut[0]==on) 00137 status += 1; 00138 if(cut[1]==on) 00139 status += 2; 00140 00141 switch (status) 00142 { 00143 // Two new points to be created. 00144 case 0: 00145 break; 00146 00147 // First on, second to be made. 00148 case 1: 00149 break; 00150 00151 // Second on, first to be made. 00152 case 2: 00153 break; 00154 00155 // No new points to be created. 00156 case 3: 00157 // Handle line cutting face by rejection. 00158 if (cut[1] == (cut[0]+1)%sz) 00159 { 00160 splittouchesface = true; 00161 splittouchespoint = false; 00162 splittouchesindex = cut[0]; 00163 return false; 00164 } 00165 if (cut[0] == (cut[1]+1)%sz) 00166 { 00167 splittouchesface = true; 00168 splittouchespoint = false; 00169 splittouchesindex = cut[1]; 00170 return false; 00171 } 00172 break; 00173 } 00174 00175 00176 return true; 00177 } 00178 00179 00180 00181 00182 #endif 00183 00184 00185 00186
1.5.8