annotate grid.h @ 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 8ed7522deaaa
rev   line source
rt300@0 1 //
rt300@0 2 // grid.h
rt300@0 3 // oscSenderExample
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 03/10/2012.
rt300@0 6 //
rt300@0 7 // This is the view onto the zoomable movable grid
rt300@0 8
rt300@0 9 #ifndef __oscSenderExample__grid__
rt300@0 10 #define __oscSenderExample__grid__
rt300@0 11
rt300@0 12 #include <iostream>
rt300@0 13 #include "2dvector.h"
rt300@3 14 #include "ofMain.h"
rt300@3 15 #include "eventLogger.h"
rt300@3 16 #include "presetManager.h"
rt300@34 17 #include "hilbert.h"
rt300@0 18 using namespace std;
rt300@7 19 class Preset;
rt300@0 20
rt300@0 21 class Grid {
rt300@24 22
rt300@24 23 public:
rt300@24 24 bool snapped;
rt300@24 25
rt300@24 26
rt300@24 27 Grid();
rt300@24 28 ~Grid();
rt300@24 29 void init();
rt300@24 30 void move(TwoVector moveP); // shift view by pixels
rt300@24 31 void zoom(float factor);
rt300@24 32
rt300@24 33
rt300@24 34 void snapCheck();
rt300@24 35 void shiftCentreToSnapped();
rt300@24 36 void draw(); // draw lines
rt300@24 37
rt300@24 38 void update(); // change according to zoom
rt300@24 39
rt300@24 40 vector<int> getParams();
rt300@24 41 TwoVector getCoord();
rt300@24 42 void setMinZoom();
rt300@24 43 void setMaxZoom();
rt300@24 44
rt300@35 45 // HILBERT now does each coord for this
rt300@24 46 vector<int> calculateParamsFromCoord(TwoVector coord) const;
rt300@24 47 TwoVector calculateCoordFromParams(vector<int> params) const;
rt300@35 48
rt300@24 49 TwoVector coordToPixel(TwoVector coord);
rt300@24 50
rt300@24 51 // the inverse stuff
rt300@24 52 void setParams(vector<int>);
rt300@24 53
rt300@0 54 private:
rt300@24 55 double scale; // surface units per pixel GUI
rt300@0 56
rt300@3 57 const double maxValue; // width of entire space
rt300@3 58 const double minValue; // smallest zoom
rt300@35 59 int paramsPerDim; // no of parameters per dimension (
rt300@35 60 int paramBitDepth; // number of bits for the parameter control data - i.e. always 7 for midi CC
rt300@35 61 /* HILBERT
rt300@35 62
rt300@3 63 int codeLength; // the 1d size of the code, determines max extent of single tile, related to params per dim
rt300@3 64
rt300@35 65 */
rt300@5 66
rt300@5 67
rt300@24 68 TwoVector topLeft; // top left corner of view, surface coords GUI
rt300@0 69 TwoVector bottomRight;
rt300@0 70 TwoVector size; // size of view, surface coords
rt300@0 71 TwoVector pixSize; // size of view pixels (ie screen size!)
rt300@24 72
rt300@0 73 TwoVector centre;
rt300@5 74 TwoVector snapCentre;
rt300@24 75 TwoVector snapDist; // number of pixels to snap to GUI
rt300@7 76 Preset * closestPreset; // pointer to the currently selected (snapped to ) preset.. NULL if none.
rt300@5 77
rt300@0 78 bool maxZoom, minZoom;
rt300@3 79
rt300@35 80 /* HILBERT
rt300@0 81 vector< vector<bool> > vcode; //
rt300@0 82 vector<int> icode;
rt300@0 83 vector<int> transSeq;
rt300@35 84 */
rt300@35 85
rt300@0 86 int midiCC[10]; // the actual params SHOULD BE INITED FROM 2*paramsPerDim
rt300@0 87
rt300@0 88 // private functions
rt300@0 89
rt300@35 90 // HILBERT void makeCode();
rt300@0 91 void checkLimits();
rt300@0 92 void viewWasChanged();
rt300@0 93 void checkConsistencies();
rt300@0 94
rt300@35 95 // HILBERT vector<bool> intToGray(int num, int dimToTravel=3) const;
rt300@35 96 // HILBERT vector<int> coordTobase32(double coord) const;
rt300@35 97 // HILBERT vector<int> grayToMidi(vector<vector <bool> > grayCodes) const;
rt300@0 98
rt300@0 99 // the inverse stuff
rt300@35 100 // HILBERT int grayToInt(vector<bool>) const;
rt300@35 101 // HILBERT double base32toCoord(vector<int>) const;
rt300@35 102 // HILBERT vector<vector <bool> > midiToGray(vector<int>) const;
rt300@35 103 // HILBERT vector<int> codesToBase32(vector<vector<bool> >) const;
rt300@0 104
rt300@0 105 vector<int> walkDiff(vector<bool> left, vector<bool> right); // not used... not worth it!
rt300@0 106
rt300@0 107 void displayInfo();
rt300@3 108 void drawPresets();
rt300@0 109
rt300@0 110 void setCoord(TwoVector coord);
rt300@5 111 void drawCrossHairs();
rt300@9 112
rt300@5 113
rt300@3 114
rt300@3 115
rt300@0 116
rt300@0 117
rt300@0 118 };
rt300@0 119
rt300@0 120 #endif /* defined(__oscSenderExample__grid__) */