Mercurial > hg > soniczoomios
diff hilbert.cpp @ 43:b91a1859829a
used UIkit sliders
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Fri, 19 Apr 2013 18:50:04 +0100 |
parents | a42903c61558 |
children |
line wrap: on
line diff
--- a/hilbert.cpp Wed Apr 17 13:44:05 2013 +0100 +++ b/hilbert.cpp Fri Apr 19 18:50:04 2013 +0100 @@ -7,8 +7,8 @@ // #include "hilbert.h" -Hilbert hilbert; +// UTILS //-------------------------------------------------------------------- unsigned int rotl(unsigned int value, int shift, int digits) { unsigned int ones = (1 << digits) - 1; @@ -74,32 +74,77 @@ } //-------------------------------------------------------------------- -void Hilbert::init(int aN, int aP){ +//==================================================================== +//-------------------------------------------------------------------- + +Hilbert::Hilbert(){ + N = 7; + P = 5; + codeLength = (int)pow(2.0,P); + + + makeCode(); + makeRotationRules(); + +} + +//-------------------------------------------------------------------- + +Hilbert::Hilbert(int aN, int aP){ N = aN; P = aP; codeLength = (int)pow(2.0,P); + + makeCode(); makeRotationRules(); +} +//-------------------------------------------------------------------- + +void Hilbert::changeCurve(int aN, int aP){ + N = aN; + P = aP; + codeLength = (int)pow(2.0,P); - // whole process unit test(?) - unsigned long long inCoord = 982635920; - vector<int> checkParam; - checkParam = calculateParamsFromIndex(inCoord); - cout << "PARAMS: "; - for(int i=0; i<P;i++){ - cout << checkParam[i] << " "; - } - cout << '\n'; - unsigned long long outCoord = calculateIndexFromParams(checkParam); - cout << "UNIT TEST COORD = " << outCoord << "\n"; - + makeCode(); + makeRotationRules(); } //-------------------------------------------------------------- void Hilbert::makeRotationRules(){ + theRotations.clear(); + theEntryVertices.clear(); + const int *rp; + const int *ep; + if(P == 5){ + rp = rotations5; + ep = entryVertices5; + }else if(P == 4){ + rp = rotations4; + ep = entryVertices4; + }else if(P == 3){ + rp = rotations3; + ep = entryVertices3; + }else if(P == 2){ + rp = rotations2; + ep = entryVertices2; + }else if(P == 1){ // will this even work? + rp = rotations1; + ep = entryVertices1; + }else{ + cout << "ERROR: makeRotationRules: bad numb of MIDI params"; + return; + } + + for(int i=0; i < codeLength; i++){ // fill vector + + theEntryVertices.push_back(ep[i]); + theRotations.push_back(rp[i]); + + } } //-------------------------------------------------------------- @@ -109,29 +154,40 @@ ////////// gray code generation ////// /// - // TODO 5bit specific - // transition sequence.... what a palaver! only need to do once though. + // choose the gray code sequence and rotation based on the numnber of dimensions P // ALL SEQUENCES SHOULD END WITH 1 0 0 ... i.e. MSB changes // max MRL 5 digit - int trans[] = {2,3,4,0,2,1,4,3,2,0,4,3,2,1,4,0,2,3,4,0,2,1,4,3,2,0,4,3,2,1,4,0}; + + theGrayCode.clear(); + theGrayCodeD.clear(); + + int trans5[] = {2,3,4,0,2,1,4,3,2,0,4,3,2,1,4,0,2,3,4,0,2,1,4,3,2,0,4,3,2,1,4,0}; // other ones int trans4[] = {1,2,0,3,0,2,1,2,3,0,3,2,1,3,1,0}; int trans3[] = {1,2,1,0,1,2,1,0}; int trans2[] = {1,0,1,0}; + int trans1[] = {0,0}; // balanced 5 int transB5[] = {1,2,3,4,5,1,5,2,3,5,2,4,2,3,4,1,4,3,2,3,1,5,3,4,1,5,2,5,3,4,1,3}; + int *tp; + if(P == 5){ - - }else{ - cout << "Only 5 digit supported now\n"; - return; + tp = trans5; + }else if(P == 4){ + tp = trans4; + }else if(P == 3){ + tp = trans3; + }else if(P == 2){ + tp = trans2; + }else if(P == 1){ // will this even work? + tp = trans1; } - + int code[codeLength][P]; // start with normal array for(int j=0; j<P; j++){ @@ -140,7 +196,7 @@ for(int i=0; i < codeLength-1; i++){ // don't need last 3 for(int j=0; j<P; j++){ - if (j == abs(trans[i])){ + if (j == abs(tp[i])){ code[i+1][j] = !code[i][j]; }else{ code[i+1][j] = code[i][j]; @@ -217,10 +273,11 @@ params[j] += ((vertex >> P-j-1) & 1)*(1<<blev); } - if(P==5){ - newe = entryVertices5[subindex]; - newd = rotations5[subindex]; + if(subindex > theEntryVertices.size()){ + cout << "ERROR: subindex too large for theEntryVertices\n"; } + newe = theEntryVertices[subindex]; + newd = theRotations[subindex]; // next rotations... int lse2 = rotr(newe, P-direction-1,P); entryPoint = entryPoint ^ lse2; @@ -280,8 +337,11 @@ } //cout << "INV subindex: " << subindex << "\n"; // work out next rotations - newe = entryVertices5[subindex]; - newd = rotations5[subindex]; + if(subindex > theEntryVertices.size()){ + cout << "ERROR: subindex too large for theEntryVertices\n"; + } + newe = theEntryVertices[subindex]; + newd = theRotations[subindex]; // next rotations... int lse2 = rotr(newe, P-direction-1,P);