# HG changeset patch # User Robert Tubb # Date 1365422301 -3600 # Node ID 94df2cd72d7be811ce43bd653985a0e597223b08 # Parent 92dba082d957a7a291a08de73bf5e6fdfab85ed0 New hilbert code - does rotations! diff -r 92dba082d957 -r 94df2cd72d7b eventLogger.h --- a/eventLogger.h Tue Mar 26 18:41:42 2013 +0000 +++ b/eventLogger.h Mon Apr 08 12:58:21 2013 +0100 @@ -33,7 +33,7 @@ #define UPLOAD_CHUNK_SIZE 1000 #define APP_CREATION_TIME 381429000000 // milliseconds to the time i wrote this wee blighter. saves digits #define SCROLL_TRAIL_LENGTH 200 -#define PROGRAM_VERSION 0.3 // IMPORTANT TOCHNAGE! +#define PROGRAM_VERSION 0.4 // IMPORTANT TOCHNAGE! #define SUPERVISED // this def will save files diff -r 92dba082d957 -r 94df2cd72d7b grid.h --- a/grid.h Tue Mar 26 18:41:42 2013 +0000 +++ b/grid.h Mon Apr 08 12:58:21 2013 +0100 @@ -14,6 +14,7 @@ #include "ofMain.h" #include "eventLogger.h" #include "presetManager.h" +#include "hilbert.h" using namespace std; class Preset; diff -r 92dba082d957 -r 94df2cd72d7b grid.mm --- a/grid.mm Tue Mar 26 18:41:42 2013 +0000 +++ b/grid.mm Mon Apr 08 12:58:21 2013 +0100 @@ -13,6 +13,7 @@ extern PresetManager presetManager; extern EventLogger eventLogger; +extern Hilbert hilbert; //-------------------------------------------------------------- Grid::Grid(): maxValue(pow(32.0,7.0)-1), minValue(60), paramsPerDim(5), paramBitDepth(7){ @@ -23,8 +24,7 @@ } void Grid::init(){ - //maxValue = pow(32.0,7.0)-1; - //minValue = 60; // number of 1-size divisions at smallest scale + maxZoom = false; minZoom = false; @@ -40,7 +40,8 @@ size.setCoord(pixSize.x*scale, pixSize.y*scale); centre.setCoord(maxValue/2 , maxValue/2); topLeft.setCoord(centre.x - size.x/2, centre.y - size.y/2); - + + hilbert.init(paramBitDepth, paramsPerDim); makeCode(); diff -r 92dba082d957 -r 94df2cd72d7b hilbert.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hilbert.cpp Mon Apr 08 12:58:21 2013 +0100 @@ -0,0 +1,297 @@ +// +// hilbert.cpp +// sonicZoom +// +// Created by Robert Tubb on 04/04/2013. +// +// + +#include "hilbert.h" +Hilbert hilbert; + +//-------------------------------------------------------------------- +unsigned int rotl(unsigned int value, int shift, int digits) { + unsigned int ones = (1 << digits) - 1; + if(shift >= digits) + shift -= digits; + + unsigned int out = (value << shift) | (value >> (digits - shift)); + return out & ones; +} +//-------------------------------------------------------------------- +unsigned int rotr(unsigned int value, int shift, int digits) { + int ones = (1 << digits) - 1; + // can only handle -digits to 2*digits-1 + if(shift >= digits) shift = shift - digits; + if(shift < 0) shift = digits + shift; + unsigned int out = (value >> shift) | (value << (digits - shift)); + return out & ones; +} +//-------------------------------------------------------------------- +unsigned int bin2dec(vector binary){ + // takes in a vector of booleans. we assume that the leftmost bool (highest index) is the MSB + unsigned int dec = 0; + int i,pwr; + int N = binary.size(); + + for (i = 0; i dec2bin(unsigned int number, unsigned int size){ + vector bin; + int i, pwr; + for(i=0;i= (1 << size)){ + cout << " bad size for Hilbert::dec2bin" << "\n"; + return bin; + } + for(i=0;i vcode){ + vector::iterator bit; + + for(bit=vcode.begin(); bit!=vcode.end() ; bit++){ + + cout << *bit; + } + cout << "\n"; + +} +//-------------------------------------------------------------------- +void Hilbert::init(int aN, int aP){ + N = aN; + P = aP; + codeLength = (int)pow(2.0,P); + makeCode(); + makeRotationRules(); + + + // whole process unit test(?) + + unsigned long long inCoord = 888999777; + vector checkParam; + checkParam = calculateParamsFromIndex(inCoord); + cout << "PARAMS: "; + for(int i=0; i()); + + for(int j=0; j Hilbert::calculateParamsFromIndex(unsigned long long index){ + // set %set start and direction of biggest cube + unsigned int i; + unsigned int mask = (1 << P) - 1; + unsigned int entryPoint = 0; + int direction = P - 1, directionInv = P-1; + unsigned int vertex=0, subindex=0, newe=0, newd=0, entryPointInv = 0; + + unsigned int pbin[N]; + + vector params; + for(i=0; i= 0; blev--){ + // get next highest bits of index + + subindex = index >> blev*P; + subindex = mask & subindex; + + cout << "subindex: " << subindex << "\n"; + // which vertex corresponds to this index? + if(subindex < theGrayCode.size()) vertex = theGrayCodeD[subindex]; + + cout << "rotated: " << vertex << "\n"; + + + //% inverse rotate this T_e,d + entryPointInv = rotr(entryPoint, direction+1,P); + directionInv = (P - direction - 2); + vertex = rotate(vertex,entryPointInv,directionInv); + + cout << "vertex: " << vertex << "\n"; + + //% build up bits of params + + for(int j=0;j> P-j-1) & 1)*(1< params){ + // set %set start and direction of biggest cube + + long long h = 0; + + unsigned int i; + unsigned int entryPoint = 0; + int direction = P - 1; + unsigned int vertex=0, subindex=0, newe=0, newd=0; + + vector subindices; + + + // for loop thru bit levels + i=0; + for(int blev = N-1; blev >= 0; blev--){ + //% get next highest bit of param + + vector vertexb; + for(i=0;i +#include +#include "ofMain.h" +#include "rot_rules.h" +#endif /* defined(__sonicZoom__hilbert__) */ + + + +class Hilbert{ +private: + +public: + int P; // dimensionas of high D space + int N; // number of resolution bits + int codeLength; + vector > cubeStartVertices; + vector cubeRotations; + vector > theGrayCode; + vector theGrayCodeD; + + void init(int N, int P); + void makeCode(); + vector calculateParamsFromIndex(unsigned long long coord); + long long calculateIndexFromParams(vector params); + void makeRotationRules(); + int rotate(int vertex, int entryPoint, int direction); + int rotateInverse(int vertex, int entryPoint, int direction) ; +}; + + + diff -r 92dba082d957 -r 94df2cd72d7b rot_rules.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rot_rules.h Mon Apr 08 12:58:21 2013 +0100 @@ -0,0 +1,26 @@ +/******************************************************************************* + * FILENAME + * rot_rules.h + * + * DESCRIPTION + * Header File for table of rotation rules for hilbert + * + *******************************************************************************/ + +#ifndef ROTRULES_TABLE_H +#define ROTRULES_TABLE_H + + +//const bool entryVertices[] = {0,0,0,0,0,10,10,10,30,6,15,5,9,9,17,23,18,18,6,12,15,15,15,15,10,18,18,17,5,9,17,3}; +//const int rotations[] = {1,2,3,4,3,0,3,0,0,1,1,1,1,1,2,2,1,0,1,3,1,0,3,4,0,4,4,0,2,1,0,3}; + +const int entryVertices5[] = {0,0,0,0,0,5,5,5,3,3,27,10,0,5,29,29,9,9,27,10,18,20,20,5,5,3,3,18,18,20,24,17}; +const int rotations5[] = {2,1,0,4,0,3,0,2,2,3,4,3,0,4,0,2,2,4,4,3,1,3,4,1,1,4,4,1,1,2,3,0}; + +const int entryVertices4[] = {0,0,0,0,0,9,15,15,12,5,5,6,6,10,9,12}; +const int rotations4[] = {2,1,3,0,0,2,2,0,3,3,1,1,3,1,0,2}; + +#endif +/*-----------------------------------------------------------------------*/ +/* End of rot_rules.h */ +/*-----------------------------------------------------------------------*/