diff --git a/.DS_Store b/.DS_Store index fddd07b..16ae1e1 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/App/App.pde b/App/App.pde deleted file mode 100644 index 1386841..0000000 --- a/App/App.pde +++ /dev/null @@ -1,21 +0,0 @@ - -void setup () { - size(640, 640, P3D); -} - - -void draw () { - lights (); - background (0); - - camera (30.0, mouseY, 220.0, - 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0); - - noStroke(); - box(90); - stroke (255); - line(-100, 0, 0, 100, 0, 0); - line(0, -100, 0,0,100,0); - line(0, 0, -100, 0,0,0); -} diff --git a/App/Quaternion.pde b/App/Quaternion.pde deleted file mode 100644 index 961fc96..0000000 --- a/App/Quaternion.pde +++ /dev/null @@ -1,43 +0,0 @@ -public class Quat { - float w, x, y, z; - - //Default Constructor - public Quat () { - w = 1.0; - x = 0.0; - y = 0.0; - z = 0.0; - } - - public Quat (float w0, x0, y0, z0) { - w = w0; - x = x0; - y = y0; - z = z0; - } - - public Quat add (Quat q) { - float nw = w + q.w; - float nx = x + q.x; - float ny = y + q.y; - float nz = z + q.z; - return new Quat (nw, nx, ny, nz); - } - - public Quat mult (Quat q) { - float nw = w * q.w - (x * q.x + y * q.y + z * q.z); - float nx = w * q.w + x * q.x + y * q.y - z * q.z; - float ny = w * q.w - x * q.x + y * q.y + z * q.z; - float nz = q * q.w + x * q.x - y * q.y + z * q.z; - return new Qua (nw, nx, ny, nz); - } - - public Quat scale (float t) { - float nw = t * q; - float nx = t * x; - float ny = t * y; - float nz = t * z; - return new Quat (nw, ny, nz); - } -} - diff --git a/App/console.pde b/App/console.pde deleted file mode 100644 index 3965d13..0000000 --- a/App/console.pde +++ /dev/null @@ -1,35 +0,0 @@ -class Console { - int _textSize = 10; - int _bufferSize = 40; - int _xOffset = 20; - int _yOffset = 20; - ArrayList _stringList; - - Console() { - _stringList = new ArrayList (); - } - - void print(String s) { - _stringList.add(s); - } - - void draw() { - pushStyle(); - noStroke(); - fill(0,0,0,150); - rect(0,0,400,_yOffset + (_bufferSize + 1) * _textSize); - fill(30,250,30); - textSize(_textSize); - int index = 0; - int c = 0; - if (_stringList.size() - _bufferSize > 0) { - index = (_stringList.size() - _bufferSize) - 1; - } - while(index < _stringList.size()) { - text(_stringList.get(index), _xOffset, _yOffset + c * _textSize); - index++; - c++; - } - popStyle(); - } -} diff --git a/kdtest/BoundingBox.pde b/kdtest/BoundingBox.pde new file mode 100644 index 0000000..47c08c6 --- /dev/null +++ b/kdtest/BoundingBox.pde @@ -0,0 +1,21 @@ +class BoundingBox { + float x1, x2, y1, y2; + public BoundingBox(float _x1, float _x2, float _y1, float _y2) + { + x1 = _x1; + x2 = _x2; + y1 = _y1; + y2 = _y2; + } + void draw() + { + pushStyle(); + stroke(0); + line(x1, y1, x2, y1); + line(x1, y2, x2, y2); + line(x1, y1, x1, y2); + line(x2, y1, x2, y2); + popStyle(); + } +} + diff --git a/kdtest/Console.pde b/kdtest/Console.pde deleted file mode 100644 index 3965d13..0000000 --- a/kdtest/Console.pde +++ /dev/null @@ -1,35 +0,0 @@ -class Console { - int _textSize = 10; - int _bufferSize = 40; - int _xOffset = 20; - int _yOffset = 20; - ArrayList _stringList; - - Console() { - _stringList = new ArrayList (); - } - - void print(String s) { - _stringList.add(s); - } - - void draw() { - pushStyle(); - noStroke(); - fill(0,0,0,150); - rect(0,0,400,_yOffset + (_bufferSize + 1) * _textSize); - fill(30,250,30); - textSize(_textSize); - int index = 0; - int c = 0; - if (_stringList.size() - _bufferSize > 0) { - index = (_stringList.size() - _bufferSize) - 1; - } - while(index < _stringList.size()) { - text(_stringList.get(index), _xOffset, _yOffset + c * _textSize); - index++; - c++; - } - popStyle(); - } -} diff --git a/kdtest/Point.pde b/kdtest/Point.pde index 542edd2..a249de5 100644 --- a/kdtest/Point.pde +++ b/kdtest/Point.pde @@ -1,5 +1,5 @@ class Point { - float _r = 30; + float _r = i_pointRad; float _x; float _y; boolean _isSelected; @@ -14,7 +14,7 @@ class Point { pushStyle(); stroke(c_pointStroke); fill((_isSelected) ? c_pointSelect : c_pointDefault); - ellipse(_x, _y, _r, _r); + ellipse(_x, _y, i_pointRad, i_pointRad); popStyle(); } diff --git a/kdtest/Properties.pde b/kdtest/Properties.pde index c078119..9d68e53 100644 --- a/kdtest/Properties.pde +++ b/kdtest/Properties.pde @@ -31,18 +31,24 @@ color c_statusText = c_WHITE; color c_pointStroke = c_BLACK; color c_pointDefault = c_WHITE; color c_pointSelect = color (100, 255, 100); +int i_pointRad = 20; + +// Tree stuff +float f_INFINITY = 99999; +int i_relationWidth = 2; +int i_boundaryWidth = 3; // Help Strings int i_helpStrings = 10; String[] s_helpStrings = { "h: Toggle Help", - "t: Toggle Console", - "r: Toggle Tree", "e: Toggle Gnoman", + "k: Toggle Relations", + "j: Toggle Boundaries", "f: Scale", "d: Pan", "s: Rotate", "a: Place Point", "g: Select Point", "c: Clear Points" -}; \ No newline at end of file +}; diff --git a/kdtest/Tree.pde b/kdtest/Tree.pde index 91ad6e7..f3b35b4 100644 --- a/kdtest/Tree.pde +++ b/kdtest/Tree.pde @@ -1,41 +1,27 @@ -class BoundingBox { - float x1, x2, y1, y2; - public BoundingBox(float _x1, float _x2, float _y1, float _y2) - { - x1 = _x1; - x2 = _x2; - y1 = _y1; - y2 = _y2; - } - void draw() - { - pushStyle(); - stroke(0); - line(x1, y1, x2, y1); - line(x1, y2, x2, y2); - line(x1, y1, x1, y2); - line(x2, y1, x2, y2); - popStyle(); - } -} - class KdTree { - KdTree _left, _right; + KdTree _left, _right, _parent; Point _loc; + float _x1, _x2, _y1, _y2; int _depth; - color _c; + color _relationC; + color _boundaryC; boolean _dir; // Vertical->True, Horizontal->False + boolean _parDir; // Left->True, Right->False BoundingBox _bb; - public KdTree(Point p, boolean vert, int depth, BoundingBox bb) { + public KdTree(KdTree parent, boolean parDir, Point p, boolean vert, int depth, BoundingBox bb) { + _parent = parent; _loc = p; _dir = vert; + _parDir = parDir; _depth = depth; - _c = colorize(depth); - + _bb = bb; + _boundaryC = colorizeBoundary(depth); + _relationC = colorizeRelation(depth); _left = null; _right = null; - _bb = bb; + + calcBoundary(); } @@ -44,15 +30,19 @@ class KdTree { if(parent._dir) { // If parent is vertical if(parent._loc._x > p._x) { - parent._left = new KdTree(p, !parent._dir, parent._depth + 1, new BoundingBox(parent._bb.x1, parent._loc._x, parent._bb.y1, parent._bb.y2)); + BoundingBox bb = new BoundingBox(parent._bb.x1, parent._loc._x, parent._bb.y1, parent._bb.y2); + parent._left = new KdTree(parent, true, p, !parent._dir, parent._depth + 1, bb); } else { - parent._right = new KdTree(p, !parent._dir, parent._depth + 1, new BoundingBox(parent._loc._x, parent._bb.x2, parent._bb.y1, parent._bb.y2)); + BoundingBox bb = new BoundingBox(parent._loc._x, parent._bb.x2, parent._bb.y1, parent._bb.y2); + parent._right = new KdTree(parent, false, p, !parent._dir, parent._depth + 1, bb); } } else { if(parent._loc._y > p._y) { - parent._left = new KdTree(p, !parent._dir, parent._depth + 1, new BoundingBox(parent._bb.x1, parent._bb.x2, parent._bb.y1, parent._loc._y)); + BoundingBox bb = new BoundingBox(parent._bb.x1, parent._bb.x2, parent._bb.y1, parent._loc._y); + parent._left = new KdTree(parent, true, p, !parent._dir, parent._depth + 1, bb); } else { - parent._right = new KdTree(p, !parent._dir, parent._depth + 1, new BoundingBox(parent._bb.x1, parent._bb.x2, parent._loc._y, parent._bb.y2)); + BoundingBox bb = new BoundingBox(parent._bb.x1, parent._bb.x2, parent._loc._y, parent._bb.y2); + parent._right = new KdTree(parent, false, p, !parent._dir, parent._depth + 1, bb); } } } @@ -137,41 +127,96 @@ class KdTree { return _left==null && _right==null; } - void draw() { - _bb.draw(); + void drawRelations() { pushStyle(); - stroke(_c); - if (_left != null) { + strokeWeight(i_relationWidth); + stroke(_relationC); + if(_left != null) { line(_loc._x, _loc._y, _left._loc._x, _left._loc._y); - _left.draw(); + _left.drawRelations(); } - if (_right != null) { + if(_right != null) { line(_loc._x, _loc._y, _right._loc._x, _right._loc._y); - _right.draw(); + _right.drawRelations(); } popStyle(); } - color colorize (int depth) { + void drawBoundaries () { + pushStyle(); + strokeWeight(i_boundaryWidth); + stroke(_boundaryC); + line(_x1, _y1, _x2, _y2); + popStyle(); + if(_left != null) { + _left.drawBoundaries(); + } + if(_right != null) { + _right.drawBoundaries(); + } + } + + void calcBoundary () { + if(_parent == null) { // Has no Parent, infinite in both directions + if (_dir) { + _x1 = _loc._x; + _x2 = _loc._x; + _y1 = f_INFINITY; + _y2 = -f_INFINITY; + } else { + _x1 = f_INFINITY; + _x2 = -f_INFINITY; + _y1 = _loc._y; + _y2 = _loc._y; + } + } else { // Has a parent, half line is made + if (_dir) { + _x1 = _loc._x; + _x2 = _loc._x; + _y1 = _parent._loc._y; + if (_parDir) { + _y2 = -f_INFINITY; + } else { + _y2 = f_INFINITY; + } + } else { + _x1 = _parent._loc._x; + _y1 = _loc._y; + _y2 = _loc._y; + if(_parDir) { + _x2 = -f_INFINITY; + } else { + _x2 = f_INFINITY; + } + } + + if (_parent._parent != null && _parent._parent._parent != null) { // is depth at least depth 3, might be bounded in both dir + if (_parDir != _parent._parent._parDir) { // Will "curl" into a prev bar + if(_dir) { + _y2 = _parent._parent._parent._loc._y; + } else { + _x2 = _parent._parent._parent._loc._x; + } + } else { // Who knows? but it will share same bound as par's par + if(_dir) { + _y2 = _parent._parent._y2; + } else { + _x2 = _parent._parent._x2; + } + } + } + } + } + + color colorizeRelation (int depth) { float d = depth * 0.2; return color((int)255*cos(d) * cos(d), (int)255*abs(sin(d + PI)), (int)255*abs(sin(d+0.5))); } -} -class TreeContainer { - KdTree _tree; - TreeContainer(){ - _tree = null; - } - - void insert(Point p){ - if(_tree != null) { _tree.insert(p); } - else { _tree = new KdTree (p, true, 0, new BoundingBox(-width/2,width/2,-height/2,height/2));} + color colorizeBoundary (int depth) { + float d = depth * 0.2; + return color((int)255*abs(sin(d + 0.3)), (int)255*abs(sin(d+3.0)), (int)255*abs(sin(d+0.7))); } - - KdTree getTree(){ return _tree;} - - void clearTree(){ _tree = null; } - - void draw(){ _tree.draw(); } } + + diff --git a/kdtest/TreeContainer.pde b/kdtest/TreeContainer.pde new file mode 100644 index 0000000..30e99e1 --- /dev/null +++ b/kdtest/TreeContainer.pde @@ -0,0 +1,35 @@ +class TreeContainer { + KdTree _tree; + BoundingBox _bb; + + TreeContainer(){ + _tree = null; + _bb = new BoundingBox(-f_INFINITY, f_INFINITY, -f_INFINITY, f_INFINITY); + } + + void insert(Point p){ + if(_tree != null) { + _tree.insert(p); + } else { + _tree = new KdTree (null, true, p, true, 0, _bb); + } + } + + KdTree getTree(){ return _tree;} + + void clearTree(){ _tree = null; } + + void setTree (KdTree tree) { _tree = tree; } + + void drawRelations() { + if(_tree != null) { + _tree.drawRelations(); + } + } + + void drawBoundaries() { + if(_tree != null) { + _tree.drawBoundaries(); + } + } +} diff --git a/kdtest/kdtest.pde b/kdtest/kdtest.pde index 76facce..c4118de 100644 --- a/kdtest/kdtest.pde +++ b/kdtest/kdtest.pde @@ -1,14 +1,12 @@ -Console con; Camera cam; Mode statusLine; -//KdTree tree; TreeContainer pot;//or tree Menu menu; Point nearestNeighbor; ArrayList pointList; -boolean drawCon, drawHelp, drawTree, drawGnoman; +boolean drawCon, drawHelp, drawTreeRelations, drawTreeBoundaries, drawGnoman; float epsilon = 0.000001; int G_mode; // 1 = SCALE @@ -22,19 +20,17 @@ void setup() { background(120); ellipseMode(CENTER); menu = new Menu(); - con = new Console(); cam = new Camera(); statusLine = new Mode(); pot = new TreeContainer(); nearestNeighbor = null; - pointList = new ArrayList(); - //tree = null; drawCon = false; drawHelp = true; drawGnoman = true; - drawTree = true; + drawTreeRelations = true; + drawTreeBoundaries = true; G_mode = 1; } @@ -45,16 +41,21 @@ void draw() { pushMatrix(); cam.update(); if(drawGnoman) GnomanDraw(200); - if(drawTree && pot.getTree() != null) { - pot.draw(); + + if(drawTreeBoundaries) { + pot.drawBoundaries(); + } + + if(drawTreeRelations) { + pot.drawRelations(); } + for(Point p: pointList) { p.draw(); } popMatrix(); menu.draw(); - if(drawCon) con.draw(); if (drawHelp) { drawHelpMenu(); @@ -68,7 +69,6 @@ void keyPressed() { switch(key) { case 't': case 'T': - con.print("t"); drawCon = !drawCon; break; case 'f': @@ -100,20 +100,18 @@ void keyPressed() { case 'H': drawHelp = !drawHelp; break; - case 'r': - case 'R': - drawTree = !drawTree; + case 'k': + case 'K': + drawTreeRelations = !drawTreeRelations; + break; + case 'j': + case 'J': + drawTreeBoundaries = !drawTreeBoundaries; break; case 'e': case 'E': drawGnoman = !drawGnoman; break; - case '1': - BoundingBox test2 = new BoundingBox(-width/2,width/2,-height/2,height/2); - test2.draw(); - ArrayList pl = pot.getTree().query(test2); - println(pl.size()); - break; } } diff --git a/kdtest/web-export/kdtest.pde b/kdtest/web-export/kdtest.pde deleted file mode 100644 index c57040e..0000000 --- a/kdtest/web-export/kdtest.pde +++ /dev/null @@ -1,786 +0,0 @@ -Console con; -Camera cam; -Mode statusLine; -KdTree tree; -TreeContainer pot;//or tree -Menu menu; - -ArrayList pointList; - -boolean drawCon, drawHelp, drawTree, drawGnoman; -float epsilon = 0.000001; -int G_mode; -// 1 = SCALE -// 2 = PAN -// 3 = ROTATE -// 4 = PLACE [removed] -// 5 = SELECT - -void setup() { - size(800,800); - background(120); - ellipseMode(CENTER); - menu = new Menu(); - con = new Console(); - cam = new Camera(); - statusLine = new Mode(); - pot = new TreeContainer(); - - pointList = new ArrayList(); - //tree = null; - - drawCon = false; - drawHelp = true; - drawGnoman = true; - drawTree = true; - - G_mode = 1; -} - -void draw() { - background(c_background); - - pushMatrix(); - cam.update(); - if(drawGnoman) GnomanDraw(200); - if(drawTree && tree != null) { - pot.draw(); - } - for(Point p: pointList) { - p.draw(); - } - popMatrix(); - - menu.draw(); - if(drawCon) con.draw(); - - if (drawHelp) { - drawHelpMenu(); - } else { - statusLine.draw(); - } - -} - -void keyPressed() { - switch(key) { - case 't': - case 'T': - con.print("t"); - drawCon = !drawCon; - break; - case 'f': - case 'F': - G_mode = 1; - break; - case 'd': - case 'D': - G_mode = 2; - break; - case 's': - case 'S': - G_mode = 3; - break; - case 'a': - case 'A': - G_mode = 4; - break; - case 'g': - case 'G': - G_mode = 5; - break; - case 'c': - case 'C': - pointList.clear(); - tree = null; - break; - case 'h': - case 'H': - drawHelp = !drawHelp; - break; - case 'r': - case 'R': - drawTree = !drawTree; - break; - case 'e': - case 'E': - drawGnoman = !drawGnoman; - break; - case '1': - BoundingBox test2 = new BoundingBox(-width/2,width/2,-height/2,height/2); - test2.draw(); - ArrayList pl = tree.query(test2); - println(pl.size()); - break; - } -} - -void drawHelpMenu() { - float hwidth = 400; - float hheight = 600; - - pushStyle(); - strokeWeight (i_helpStrokeWidth); - stroke(c_helpStroke); - fill(c_helpBackground); - rect(width/2 - hwidth/2, height/2 - hheight/2, hwidth, hheight, 50, 50, 50, 50); - textSize(40); - fill(c_helpText); - text("Help:", width/2 - 50, height/2 - hheight/2 + 50); - textSize (30); - float x = width/2 - 150; - float y = height/2 - hheight/2 + 100; - for (int i = 0; i < i_helpStrings; i++) { - text(s_helpStrings[i], x, y); - y += 35; - } - popStyle(); -} - -void checkSelect() { - -} - -void GnomanDraw(int r) { - pushStyle(); - stroke(c_gnoman); - line(-r,0,r,0); - line(0,-r,0,r); - popStyle(); -} - -void mousePressed() { - if(mouseButton == LEFT){ menu.mousePressed(); } - if(mouseButton == RIGHT){ cam.mousePressed(); } -} - -void mouseDragged() { - if(mouseButton == LEFT){ menu.mouseDragged(); } - if(mouseButton == RIGHT){ cam.mouseDragged(); } -} - -void mouseReleased() { - if(mouseButton == LEFT){ menu.mouseReleased(); } - if(mouseButton == RIGHT){ cam.mouseReleased(); } -} -class Camera { - float _x; - float _y; - float _scale; - float _angle; - float _oldX; - float _oldY; - float _oldAngle; - float _oldScale; - - int _initMX; - int _initMY; - - Camera() { - _x = 0.0; - _y = 0.0; - _scale = 1.0; - _angle = 4 * PI; - } - - void update() { - translate(_x + width/2,_y + height/2); - rotate(_angle); - scale(_scale); - } - - void mousePressed() { - _initMX = mouseX; - _initMY = mouseY; - _oldScale = _scale; - _oldX = _x; - _oldY = _y; - _oldAngle = _angle; - } - - void mouseDragged() { - float difX = (float)(mouseX - _initMX); - float difY = (float)(mouseY - _initMY); - - switch(G_mode) { - case 1: - difX /= (float)(width); - difY /= (float)(height); - _scale = epsilon + abs((1 - 4*(difX + difY)) * _oldScale); - _x = _oldX * _scale; - _y = _oldY * _scale; - break; - case 2: - difX *= 1.0/_scale; - difY *= 1.0/_scale; -// _x = cos(_angle)*difX - sin(_angle)*difY + _oldX; -// _y = sin(_angle)*difX + cos(_angle)*difY + _oldY; - _x = _oldX + difX; - _y = _oldY + difY; - break; - case 3: - float initAngle = atan((_initMY - height/2)/(epsilon + _initMX - width/2)); - float newAngle = atan((mouseY - height/2)/(epsilon + mouseX - width/2)); - float delta = newAngle - initAngle; - _angle = _oldAngle + delta; - break; - } - } - - void mouseReleased() { - - } - - Point transform(Point p) { - float px = (1.0/_scale)*((p._x - width/2) - _x); - float py = (1.0/_scale)*((p._y - height/2) - _y); - float x = (cos(_angle)*px + sin(_angle)*py); - float y = (-sin(_angle)*px + cos(_angle)*py); - return new Point(x,y); - } -} -class Console { - int _textSize = 10; - int _bufferSize = 40; - int _xOffset = 20; - int _yOffset = 20; - ArrayList _stringList; - - Console() { - _stringList = new ArrayList (); - } - - void print(String s) { - _stringList.add(s); - } - - void draw() { - pushStyle(); - noStroke(); - fill(0,0,0,150); - rect(0,0,400,_yOffset + (_bufferSize + 1) * _textSize); - fill(30,250,30); - textSize(_textSize); - int index = 0; - int c = 0; - if (_stringList.size() - _bufferSize > 0) { - index = (_stringList.size() - _bufferSize) - 1; - } - while(index < _stringList.size()) { - text(_stringList.get(index), _xOffset, _yOffset + c * _textSize); - index++; - c++; - } - popStyle(); - } -} -class Menu{ - ArrayList