annotate grid.h @ 37:8ed7522deaaa

Interpolation.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 09 Apr 2013 17:14:31 +0100
parents 790939017078
children 0dfe9e0c01aa
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@37 18
rt300@0 19 using namespace std;
rt300@7 20 class Preset;
rt300@0 21
rt300@37 22
rt300@37 23
rt300@0 24 class Grid {
rt300@24 25
rt300@24 26 public:
rt300@24 27 bool snapped;
rt300@24 28
rt300@24 29
rt300@24 30 Grid();
rt300@24 31 ~Grid();
rt300@24 32 void init();
rt300@24 33 void move(TwoVector moveP); // shift view by pixels
rt300@24 34 void zoom(float factor);
rt300@24 35
rt300@37 36 typedef enum{NO_INTERPOLATION, INTERPOLATE_GRID, INTERPOLATE_PRESET} interpolateModeType;
rt300@37 37 interpolateModeType interpolateMode;
rt300@24 38 void snapCheck();
rt300@24 39 void shiftCentreToSnapped();
rt300@37 40 void draw();
rt300@37 41 void drawGridLines();
rt300@24 42 void update(); // change according to zoom
rt300@37 43 int interpLevel;
rt300@37 44 int smallestGridSpacing; // number of pixels when small grid dissappears from view
rt300@24 45 vector<int> getParams();
rt300@24 46 TwoVector getCoord();
rt300@24 47 void setMinZoom();
rt300@24 48 void setMaxZoom();
rt300@24 49
rt300@35 50 // HILBERT now does each coord for this
rt300@37 51 vector<int> calculateParamsFromCoord(TwoVector coord);
rt300@37 52 TwoVector calculateCoordFromParams(vector<int> params);
rt300@37 53 vector<int> calculateInterpolatedParamsFromCoord(TwoVector coord);
rt300@24 54 TwoVector coordToPixel(TwoVector coord);
rt300@24 55
rt300@24 56 // the inverse stuff
rt300@24 57 void setParams(vector<int>);
rt300@24 58
rt300@0 59 private:
rt300@24 60 double scale; // surface units per pixel GUI
rt300@0 61
rt300@3 62 const double maxValue; // width of entire space
rt300@3 63 const double minValue; // smallest zoom
rt300@35 64 int paramsPerDim; // no of parameters per dimension (
rt300@35 65 int paramBitDepth; // number of bits for the parameter control data - i.e. always 7 for midi CC
rt300@35 66 /* HILBERT
rt300@35 67
rt300@3 68 int codeLength; // the 1d size of the code, determines max extent of single tile, related to params per dim
rt300@3 69
rt300@35 70 */
rt300@5 71
rt300@5 72
rt300@24 73 TwoVector topLeft; // top left corner of view, surface coords GUI
rt300@0 74 TwoVector bottomRight;
rt300@0 75 TwoVector size; // size of view, surface coords
rt300@0 76 TwoVector pixSize; // size of view pixels (ie screen size!)
rt300@24 77
rt300@0 78 TwoVector centre;
rt300@5 79 TwoVector snapCentre;
rt300@24 80 TwoVector snapDist; // number of pixels to snap to GUI
rt300@7 81 Preset * closestPreset; // pointer to the currently selected (snapped to ) preset.. NULL if none.
rt300@5 82
rt300@0 83 bool maxZoom, minZoom;
rt300@3 84
rt300@35 85 /* HILBERT
rt300@0 86 vector< vector<bool> > vcode; //
rt300@0 87 vector<int> icode;
rt300@0 88 vector<int> transSeq;
rt300@35 89 */
rt300@35 90
rt300@0 91 int midiCC[10]; // the actual params SHOULD BE INITED FROM 2*paramsPerDim
rt300@0 92
rt300@0 93 // private functions
rt300@0 94
rt300@35 95 // HILBERT void makeCode();
rt300@0 96 void checkLimits();
rt300@0 97 void viewWasChanged();
rt300@0 98 void checkConsistencies();
rt300@0 99
rt300@35 100 // HILBERT vector<bool> intToGray(int num, int dimToTravel=3) const;
rt300@35 101 // HILBERT vector<int> coordTobase32(double coord) const;
rt300@35 102 // HILBERT vector<int> grayToMidi(vector<vector <bool> > grayCodes) const;
rt300@0 103
rt300@0 104 // the inverse stuff
rt300@35 105 // HILBERT int grayToInt(vector<bool>) const;
rt300@35 106 // HILBERT double base32toCoord(vector<int>) const;
rt300@35 107 // HILBERT vector<vector <bool> > midiToGray(vector<int>) const;
rt300@35 108 // HILBERT vector<int> codesToBase32(vector<vector<bool> >) const;
rt300@0 109
rt300@0 110 vector<int> walkDiff(vector<bool> left, vector<bool> right); // not used... not worth it!
rt300@0 111
rt300@0 112 void displayInfo();
rt300@3 113 void drawPresets();
rt300@0 114
rt300@0 115 void setCoord(TwoVector coord);
rt300@5 116 void drawCrossHairs();
rt300@9 117
rt300@37 118 int calculateInterpolateLevel();
rt300@37 119 vector<int> interpVector(vector<int> upper, vector<int> lower, float frac);
rt300@3 120
rt300@0 121
rt300@0 122
rt300@0 123 };
rt300@0 124
rt300@0 125 #endif /* defined(__oscSenderExample__grid__) */