comparison hilbert.cpp @ 35:790939017078

V0.5. Now uses new continuous hilbert curve. HOORAY.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Mon, 08 Apr 2013 17:23:13 +0100
parents 94df2cd72d7b
children a42903c61558
comparison
equal deleted inserted replaced
34:94df2cd72d7b 35:790939017078
56 for(i=0;i<size;i++){ 56 for(i=0;i<size;i++){
57 pwr = size-i; 57 pwr = size-i;
58 bin[i] = (number/(1 << pwr)) % 2; 58 bin[i] = (number/(1 << pwr)) % 2;
59 bin.push_back(0); 59 bin.push_back(0);
60 } 60 }
61 61 return bin;
62 62
63 63
64 } 64 }
65 //--------------------------------------------------------------------
65 void printBool(vector <bool> vcode){ 66 void printBool(vector <bool> vcode){
66 vector<bool>::iterator bit; 67 vector<bool>::iterator bit;
67 68
68 for(bit=vcode.begin(); bit!=vcode.end() ; bit++){ 69 for(bit=vcode.begin(); bit!=vcode.end() ; bit++){
69 70
81 makeRotationRules(); 82 makeRotationRules();
82 83
83 84
84 // whole process unit test(?) 85 // whole process unit test(?)
85 86
86 unsigned long long inCoord = 888999777; 87 unsigned long long inCoord = 982635920;
87 vector<int> checkParam; 88 vector<int> checkParam;
88 checkParam = calculateParamsFromIndex(inCoord); 89 checkParam = calculateParamsFromIndex(inCoord);
89 cout << "PARAMS: "; 90 cout << "PARAMS: ";
90 for(int i=0; i<P;i++){ 91 for(int i=0; i<P;i++){
91 cout << checkParam[i] << " "; 92 cout << checkParam[i] << " ";
92 } 93 }
93 cout << '\n'; 94 cout << '\n';
94 unsigned long long outCoord = calculateIndexFromParams(checkParam); 95 unsigned long long outCoord = calculateIndexFromParams(checkParam);
95 cout << "Unit TEst coord = " << outCoord << "\n"; 96 cout << "UNIT TEST COORD = " << outCoord << "\n";
96 97
97 98
98 } 99 }
99 //-------------------------------------------------------------- 100 //--------------------------------------------------------------
100 void Hilbert::makeRotationRules(){ 101 void Hilbert::makeRotationRules(){
194 // get next highest bits of index 195 // get next highest bits of index
195 196
196 subindex = index >> blev*P; 197 subindex = index >> blev*P;
197 subindex = mask & subindex; 198 subindex = mask & subindex;
198 199
199 cout << "subindex: " << subindex << "\n"; 200 //cout << "subindex: " << subindex << "\n";
200 // which vertex corresponds to this index? 201 // which vertex corresponds to this index?
201 if(subindex < theGrayCode.size()) vertex = theGrayCodeD[subindex]; 202 if(subindex < theGrayCode.size()) vertex = theGrayCodeD[subindex];
202 203
203 cout << "rotated: " << vertex << "\n"; 204 //cout << "rotated: " << vertex << "\n";
204 205
205 206
206 //% inverse rotate this T_e,d 207 //% inverse rotate this T_e,d
207 entryPointInv = rotr(entryPoint, direction+1,P); 208 entryPointInv = rotr(entryPoint, direction+1,P);
208 directionInv = (P - direction - 2); 209 directionInv = (P - direction - 2);
209 vertex = rotate(vertex,entryPointInv,directionInv); 210 vertex = rotate(vertex,entryPointInv,directionInv);
210 211
211 cout << "vertex: " << vertex << "\n"; 212 //cout << "vertex: " << vertex << "\n";
212 213
213 //% build up bits of params 214 //% build up bits of params
214 215
215 for(int j=0;j<P;j++){ 216 for(int j=0;j<P;j++){
216 217
222 } 223 }
223 // next rotations... 224 // next rotations...
224 int lse2 = rotr(newe, P-direction-1,P); 225 int lse2 = rotr(newe, P-direction-1,P);
225 entryPoint = entryPoint ^ lse2; 226 entryPoint = entryPoint ^ lse2;
226 direction = (direction + newd + 1) % P; 227 direction = (direction + newd + 1) % P;
227 cout << "------------\n"; 228 //cout << "------------\n";
228 } 229 }
229 230
230 return params; 231 return params;
231 } 232 }
232 //-------------------------------------------------------------------- 233 //--------------------------------------------------------------------
237 } 238 }
238 //-------------------------------------------------------------------- 239 //--------------------------------------------------------------------
239 240
240 241
241 //-------------------------------------------------------------------- 242 //--------------------------------------------------------------------
242 long long Hilbert::calculateIndexFromParams(vector<int> params){ 243 unsigned long long Hilbert::calculateIndexFromParams(vector<int> params){
243 // set %set start and direction of biggest cube 244 // set %set start and direction of biggest cube
244 245
245 long long h = 0; 246 unsigned long long h = 0;
246 247
247 unsigned int i; 248 unsigned int i;
248 unsigned int entryPoint = 0; 249 unsigned int entryPoint = 0;
249 int direction = P - 1; 250 int direction = P - 1;
250 unsigned int vertex=0, subindex=0, newe=0, newd=0; 251 unsigned int vertex=0, newe=0, newd=0;
251 252 unsigned long long subindex; // needs to be long cos we lewt shift by alot
252 vector<int> subindices; 253 vector<int> subindices;
253 254
254 255
255 // for loop thru bit levels 256 // for loop thru bit levels
256 i=0; 257 i=0;
260 vector<bool> vertexb; 261 vector<bool> vertexb;
261 for(i=0;i<P;i++){ 262 for(i=0;i<P;i++){
262 vertexb.push_back((params[i]/(1 << blev)) % 2); 263 vertexb.push_back((params[i]/(1 << blev)) % 2);
263 264
264 } 265 }
265 printBool(vertexb); 266 //printBool(vertexb);
266 vertex = bin2dec(vertexb); 267 vertex = bin2dec(vertexb);
267 cout << "INV vertex: " << vertex << "\n"; 268 //cout << "INV vertex: " << vertex << "\n";
268 // rotate it 269 // rotate it
269 vertex = rotate(vertex,entryPoint,direction); 270 vertex = rotate(vertex,entryPoint,direction);
270 271
271 // % get new index of thisun 272 // % get new index of thisun
272 cout << "INV rotated: " << vertex << "\n"; 273 //cout << "INV rotated: " << vertex << "\n";
273 274
274 275
275 for(i=0;i<codeLength;i++){ 276 for(i=0;i<codeLength;i++){
276 if(vertex == theGrayCodeD[i]){ 277 if(vertex == theGrayCodeD[i]){
277 subindex = i; 278 subindex = i;
278 } 279 }
279 } 280 }
280 cout << "INV subindex: " << subindex << "\n"; 281 //cout << "INV subindex: " << subindex << "\n";
281 // work out next rotations 282 // work out next rotations
282 newe = entryVertices5[subindex]; 283 newe = entryVertices5[subindex];
283 newd = rotations5[subindex]; 284 newd = rotations5[subindex];
284 285
285 // next rotations... 286 // next rotations...
287 entryPoint = entryPoint ^ lse2; 288 entryPoint = entryPoint ^ lse2;
288 direction = (direction + newd + 1) % P; 289 direction = (direction + newd + 1) % P;
289 290
290 // now build up h from subindices 291 // now build up h from subindices
291 h += subindex << (blev*P); 292 h += subindex << (blev*P);
292 cout << "------------\n"; 293 //cout << "------------\n";
293 } 294 }
294 295
295 return h; 296 return h;
296 } 297 }
297 //-------------------------------------------------------------------- 298 //--------------------------------------------------------------------