From be791a55506c1986606c3ab6c3694484f50a2188 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 7 Feb 2012 16:42:11 +0000 Subject: still wonky paths --- parsecalldata.pde | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'parsecalldata.pde') diff --git a/parsecalldata.pde b/parsecalldata.pde index 4247041..f346381 100644 --- a/parsecalldata.pde +++ b/parsecalldata.pde @@ -64,10 +64,11 @@ class calldata { } } } - for (int i=0; i < countries.size(); i++) { - countries.get(i).printOut(); - } - + if (DEBUG) { + for (int i=0; i < countries.size(); i++) { + countries.get(i).printOut(); + } + } } country getcountry(int w) { return countries.get(w); -- cgit v1.2.3 From c7284a5e4f7a1ed2846344d7b221ad74db8d0334 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 9 Feb 2012 17:41:22 +0000 Subject: loading bitmap into country --- parsecalldata.pde | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++----- vodaviz.pde | 76 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 150 insertions(+), 19 deletions(-) (limited to 'parsecalldata.pde') diff --git a/parsecalldata.pde b/parsecalldata.pde index f346381..f82c0e3 100644 --- a/parsecalldata.pde +++ b/parsecalldata.pde @@ -1,10 +1,13 @@ //BT IRELAND MTM,Destination CID Name,VIA,Calls,MINS,ALOC,% User,ASR,NER 02 -boolean DEBUG=false; +boolean DEBUG=true; class country { String name; float calls,mins; RShape outline; + country() { + super(); + } country(String n,float c,float m,RShape shp){ name=n; calls=c; @@ -26,7 +29,7 @@ class country { while (searching>0&&searching0)); + //if (DEBUG) println(name+"; try "+searching+": "+np.x+","+np.y+" bounds: "+tl.x+","+tl.y+" - "+br.x+","+br.y+": "+(searching>0)); if (searching==10||searching==100||searching==1000||searching==10000||searching==100000) { println(name+"; try "+searching+": MISS at "+np.x+","+np.y+" bounds: "+tl.x+","+tl.y+" - "+br.x+","+br.y); } @@ -36,9 +39,82 @@ class country { } } +class weightedpixel { + float bright; + RPoint pt; + float index; //index weighted from 0-1 + weightedpixel(RPoint _p,float _b) { + pt=_p; + bright=_b; + } +} + +class bitmapcountry extends country { + //examines a bitmap + //builds a table of population desnsity + + //look at it from the POV of how its gonna be used + //getpoints(int num) should be able to return an array of points to draw from + //should be dithered + //has to distribute the points around the brightest points first + //distribute in proportion to their brightness - weighted + + //table of pixels: if within shape: + //sample brightness, keep running total and store normalised weighted index for quick searching + + float xo,xs,yo,ys; + Vector points = new Vector(); + bitmapcountry(String n,float c,float m,RShape shp) { + super(n,c,m,shp); + } + void analyse(float _xo,float _xs,float _yo,float _ys) { + xo=_xo; + xs=_xs; + yo=_yo; + ys=_ys; + //scan country outline by pixel + RPoint tl=outline.getTopLeft(); + RPoint br=outline.getBottomRight(); + RPoint tlp=normpix(tl); + RPoint brp=normpix(br); + float pixstep=(br.x-tl.x)/lightmap.width; + float totalbright=0; + for (int i=0;i countries = new Vector(); + Vector countries = new Vector(); HashMap outlines = new HashMap(); calldata(String[][] data,RShape shp) { @@ -50,7 +126,7 @@ class calldata { //detect number of countries int num=0; if (outlines.containsKey(data[0][1].substring(0, 3))) { - countries.add(new country(data[0][1],0,0,shp.children[outlines.get(data[0][1].substring(0, 3))])); + countries.add(new bitmapcountry(data[0][1],0.0,0.0,shp.children[outlines.get(data[0][1].substring(0, 3))])); } for (int i=0; i < data.length; i++) { @@ -60,15 +136,16 @@ class calldata { else { if (outlines.containsKey(data[i][1].substring(0, 3))) { - countries.add(new country(data[i][1],Float.valueOf(data[i][3].trim()).floatValue(),Float.valueOf(data[i][4].trim()).floatValue(),shp.children[outlines.get(data[i][1].substring(0, 3))])); + countries.add(new bitmapcountry(data[i][1],Float.valueOf(data[i][3].trim()).floatValue(),Float.valueOf(data[i][4].trim()).floatValue(),shp.children[outlines.get(data[i][1].substring(0, 3))])); } } } - if (DEBUG) { + for (int i=0; i < countries.size(); i++) { - countries.get(i).printOut(); + //if (DEBUG) countries.get(i).printOut(); + countries.get(i).analyse(18.279,746.302,129.314,374.293); } - } + } country getcountry(int w) { return countries.get(w); diff --git a/vodaviz.pde b/vodaviz.pde index cf7fcf7..7d4ed25 100644 --- a/vodaviz.pde +++ b/vodaviz.pde @@ -79,6 +79,9 @@ The intermediate latitude and longitude is then given by: import processing.pdf.*; import geomerative.*; +float log10 (float x) { + return (log(x) / log(10)); +} class pointNormalise { //take pixel coords and turn into lat/lng radians float xo,xs,yo,ys; @@ -130,6 +133,16 @@ class sphereMap { } } +RPoint screenMapper(RPoint p) { + p.x=((p.x*getWidth())/(PI*2))+(getWidth()/2); + p.y=((p.y*getHeight())/PI)+(getHeight()/2); + return p; +} + +RPoint plerp(RPoint s,RPoint e,float a) { + return new RPoint(lerp(s.x,e.x,a),lerp(s.y,e.y,a)); +} + float GSphereDist(RPoint p1,RPoint p2) { return acos(sin(p1.y)*sin(p2.y)+cos(p1.y)*cos(p2.y)*cos(p1.x-p2.x)); } @@ -156,21 +169,27 @@ calldata calls; country Ireland; +PImage lightmap; + void setup(){ - println("vodaviz v0.11"); + println("vodaviz v0.21"); RG.init(this); //mode="PDF"; - size(832,220); //,PDF, "testoutput.pdf"); //P3D); //832,220); //nb pdf is 800x600 + if (mode=="PDF") size(832,220,PDF, "vodaviz_test_080212.pdf"); //P3D); //832,220); //nb pdf is 800x600 + else size(832,220); //,PDF, "testoutput.pdf"); //P3D); //832,220); //nb pdf is 800x600 smooth(); float m = millis(); shp = RG.loadShape("countries_named_mercator.svg"); //test_drawing.svg"); //world_countries_outlines_split.svg"); - pnorm = new pointNormalise(26,736,90,390); + pnorm = new pointNormalise(18.279,746.302,129.314,374.293); ptrans = new pointTransform(); - smap = new sphereMap(); + smap = new sphereMap(); + + lightmap=loadImage("earthlights2_dmsp_big.jpg"); + image(lightmap,0,0,getWidth(),getHeight()); RG.ignoreStyles(); println("loaded svg in "+((millis()-m)*.001)+" seconds"); @@ -178,7 +197,7 @@ void setup(){ data=new csvloader("calls.csv"); calls=new calldata(data.data,shp); - background(0,0,0); + background(255,255,255); noFill(); stroke(255); strokeWeight(.02); @@ -191,6 +210,8 @@ void setup(){ println("40% of LAX to JFK:"+LmJ.y+","+LmJ.x+" radians"); } + + } int i=0; @@ -199,8 +220,10 @@ int j=0; void draw() { //pick a random colour - stroke(random(150)+100,random(150)+100,random(150)+100); + stroke(random(150)+100,random(150)+100,random(150)+100,10); + if (false) //draw globe + { if (true) { //draw countries beginShape(); for (int k=0;k0&&e.x>0){ //point found + RPoint Sp=screenMapper(pnorm.alise(s)); + RPoint Ep=screenMapper(pnorm.alise(e)); + RPoint Mp=plerp(Sp,Ep,0.75); + beginShape(); + //line(Sp.x+(getWidth()/2),Sp.y+(getHeight()/2),Mp.x+(getWidth()/2),Mp.y+(getHeight()/2)); + //line(Mp.x+(getWidth()/2),Mp.y+(getHeight()/2),Ep.x+(getWidth()/2),Ep.y+(getHeight()/2)); + bezier(Sp.x, Sp.y, Sp.x, Sp.y-((getHeight()-Sp.y)*.1), Ep.x, Ep.y-((getHeight()-Ep.y)*.1), Ep.x, Ep.y); + endShape(); + } + } + //println("plotting "+calls.countries.get(i).name+": "+calls.countries.get(i).calls+" calls"); + } + } - i++; + i++; //} if (i==calls.countries.size()-1) { -- cgit v1.2.3 From e22a28b930d02ac7b30fd4866bef2ec2d22a062d Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sat, 11 Feb 2012 13:18:09 +0000 Subject: bitmap lines --- parsecalldata.pde | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'parsecalldata.pde') diff --git a/parsecalldata.pde b/parsecalldata.pde index f82c0e3..5870e6d 100644 --- a/parsecalldata.pde +++ b/parsecalldata.pde @@ -77,8 +77,11 @@ class bitmapcountry extends country { RPoint br=outline.getBottomRight(); RPoint tlp=normpix(tl); RPoint brp=normpix(br); - float pixstep=(br.x-tl.x)/lightmap.width; + float pixstep=xs/lightmap.width; float totalbright=0; + float bmin=255; + float bmax=0; + println("searching "+tl.x+","+tl.y+" -> "+(tl.x+(pixstep*(brp.x-tlp.x)))+","+(tl.y+(pixstep*(brp.y-tlp.y)))); for (int i=0;ibmax) bmax=bn; + if (bn Date: Sun, 12 Feb 2012 14:53:03 +0000 Subject: good bitmap reading --- parsecalldata.pde | 7 ++++--- vodaviz.pde | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'parsecalldata.pde') diff --git a/parsecalldata.pde b/parsecalldata.pde index 5870e6d..ba6e46f 100644 --- a/parsecalldata.pde +++ b/parsecalldata.pde @@ -68,6 +68,7 @@ class bitmapcountry extends country { super(n,c,m,shp); } void analyse(float _xo,float _xs,float _yo,float _ys) { + int step=5; //speedup xo=_xo; xs=_xs; yo=_yo; @@ -82,12 +83,12 @@ class bitmapcountry extends country { float bmin=255; float bmax=0; println("searching "+tl.x+","+tl.y+" -> "+(tl.x+(pixstep*(brp.x-tlp.x)))+","+(tl.y+(pixstep*(brp.y-tlp.y)))); - for (int i=0;ibmax) bmax=bn; if (bn0&&e.x>0){ //point found RPoint sp=ptrans.form(pnorm.alise(s)); RPoint ep=ptrans.form(pnorm.alise(e)); @@ -257,7 +259,7 @@ void draw() { } } - else + else //draw 2D { if (true) { //draw countries beginShape(); @@ -272,8 +274,8 @@ void draw() { } if (true) { //draw lines for (int j=0;j0&&e.x>0){ //point found RPoint Sp=screenMapper(pnorm.alise(s)); RPoint Ep=screenMapper(pnorm.alise(e)); -- cgit v1.2.3