From 01fbd54df87813b43c96a33c97af76556b84cb54 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 19 Jul 2012 15:14:17 +0100 Subject: objectified --- gpsviewer.pde | 159 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 98 insertions(+), 61 deletions(-) diff --git a/gpsviewer.pde b/gpsviewer.pde index 715c79f..b2a0686 100644 --- a/gpsviewer.pde +++ b/gpsviewer.pde @@ -1,87 +1,124 @@ -XMLElement kml; -ArrayList points = new ArrayList(); +p3d max=new p3d(-1000,-1000,-1000,""); +p3d min=new p3d(1000,1000,1000,""); + +float xOffset,yOffset,spanDegrees,pixelsPerDegree; + +trace pts1,pts2; class p3d { float x,y,z; - p3d(float _x,float _y,float _z) { + String time; + p3d(float _x,float _y,float _z,String _t) { x=_x; y=_y; z=_z; } } -p3d max=new p3d(-1000,-1000,-1000); -p3d min=new p3d(1000,1000,1000); - -float xOffset,yOffset,spanDegrees; - -void addPoint(String[] coord) { - p3d p; - if (coord.length>2) { - p=new p3d(float(coord[0]),float(coord[1]),float(coord[2])); - } - else p=new p3d(float(coord[0]),float(coord[1]),0.0); - points.add(p); - if (p.x>max.x) max.x=p.x; - if (p.y>max.y) max.y=p.y; - if (p.z>max.z) max.z=p.z; - if (p.x0) { //element contains a single coordinate - addPoint(kml.getChild(i).getChild("Point").getChild("coordinates").getContent().split(",")); +class trace { + ArrayList points = new ArrayList(); + PApplet parent; + trace(PApplet _this,String filename) { + parent=_this; + parseXml(filename); + } + void addPoint(float _x,float _y,float _z,String _t) { + p3d p=new p3d(_x,_y,_z,_t); + points.add(p); + if (p.x>max.x) max.x=p.x; + if (p.y>max.y) max.y=p.y; + if (p.z>max.z) max.z=p.z; + if (p.x0) { //element contains a table of coordinates - String[] coords=kml.getChild(i).getChild("coordinates").getContent().split("\\n"); - for (int j=0;jmax.y-min.y) { + //scale to X + xOffset=0; + yOffset=(height/2)-((height*((max.y-min.y)/(max.x-min.x))*0.5)); // } + else { + //scale to Y + xOffset=(width/2)-((width*((max.x-min.x)/(max.y-min.y))*0.5)); + println("ratio: "+str((max.x-min.x)/(max.y-min.y))); + yOffset=0; + } + println (_file+" "+str(pts.size())+" data points, bounds: "+str(min.x)+","+str(min.y)+" to "+str(max.x)+","+str(max.y)); } - println ("found "+str(points.size())+" data points"); - - //work out offsets - if (max.x-min.x>max.y-min.y) { - //scale to X - xOffset=0; - yOffset=(height/2)-((height*((max.y-min.y)/(max.x-min.x))*0.5)); // - } - else { - //scale to Y - xOffset=(width/2)-((width*((max.x-min.x)/(max.y-min.y))*0.5)); - println("ratio: "+str((max.x-min.x)/(max.y-min.y))); - yOffset=0; - } +} + +void setup() { + size(512,512); + pts1 = new trace(this,"2012-07-18 11-25-38-gpstrack.gpx"); + pts2 = new trace(this,"1667831-gpstrack.gpx"); background(0); stroke(255); + + spanDegrees=max(max.x-min.x,max.y-min.y); + if (max.x-min.x>max.y-min.y) pixelsPerDegree=width/spanDegrees; //maximum span of latitude/longitude + else pixelsPerDegree=height/spanDegrees; } void draw() { - spanDegrees=max(max.x-min.x,max.y-min.y); if (spanDegrees==0.0) println("no movement!"); else { - float pixelsPerDegree; - if (max.x-min.x>max.y-min.y) pixelsPerDegree=width/spanDegrees; //maximum span of latitude/longitude - else pixelsPerDegree=height/spanDegrees; - for (int i=0;i