summaryrefslogtreecommitdiff
path: root/parsecalldata.pde
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-02-09 17:41:22 +0000
committerTim Redfern <tim@eclectronics.org>2012-02-09 17:41:22 +0000
commitc7284a5e4f7a1ed2846344d7b221ad74db8d0334 (patch)
treef674cbb231cbece5af08a584b7af7b0f1e45acfa /parsecalldata.pde
parente515983033bbd6f2619962c31e34b825a1068309 (diff)
loading bitmap into country
Diffstat (limited to 'parsecalldata.pde')
-rw-r--r--parsecalldata.pde93
1 files changed, 85 insertions, 8 deletions
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&&searching<tries) {
np=new RPoint(random(tl.x,br.x),random(tl.y,br.y));
if(outline.contains(np)) searching=0;
- if (DEBUG) println(name+"; try "+searching+": "+np.x+","+np.y+" bounds: "+tl.x+","+tl.y+" - "+br.x+","+br.y+": "+(searching>0));
+ //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<weightedpixel> points = new Vector<weightedpixel>();
+ 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<brp.x-tlp.x;i++) {
+ for (int j=0;j<brp.y-tlp.y;j++) {
+ RPoint pn=new RPoint(tl.x+(i*pixstep),tl.y+(j*pixstep));
+ if(outline.contains(pn)) {
+ float bn=brightness(lightmap.get((int)brp.x+i,(int)brp.y+j));
+ points.add(new weightedpixel(normalise(pn),bn));
+ totalbright +=bn;
+ }
+ }
+ }
+ float runbright=0;
+ float bfactor=1.0/totalbright;
+ for (int i=0;i<points.size();i++) {
+ runbright+=points.get(i).bright*bfactor;
+ points.get(i).index=runbright;
+ }
+ if (DEBUG) println(name+"; bounds: "+tl.x+","+tl.y+" - "+points.size()+" pixels");
+
+ }
+ RPoint normalise(RPoint p) {
+ float px=(((p.x-xo)/xs)-0.5)*PI*2; //26)/736);
+ float py=(((p.y-yo)/ys)-0.5)*PI; //90)/390);
+
+ return new RPoint(px,py);
+ }
+ RPoint normpix(RPoint p) {
+ float px=((p.x-xo)/xs)*lightmap.width;
+ float py=((p.y-yo)/ys)*lightmap.height;
+
+ return new RPoint(px,py);
+ }
+}
+
class calldata {
- Vector<country> countries = new Vector<country>();
+ Vector<bitmapcountry> countries = new Vector<bitmapcountry>();
HashMap<String, Integer> outlines = new HashMap<String, Integer>();
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);