//BT IRELAND MTM,Destination CID Name,VIA,Calls,MINS,ALOC,% User,ASR,NER 02 boolean DEBUG=true; import proxml.*; //java.io.NotSerializableException: geomerative.RShape // ATTEMPT TO SERIALISE COUNTRY DATA.. unfinished // // use proxml manually // class country{ String name; float calls,mins,aloc,user,asr,ner; int networks; transient RShape outline; country(String n,float c,float m,float al,float u,float as,float ne,RShape shp){ name=n; calls=c; mins=m; aloc=al; user=u; asr=as; ner=ne; outline=shp; networks=1; } void addnetwork(float c,float m,float al,float u,float as,float ne) { calls+=c; mins+=m; aloc+=al; user+=u; asr+=as; ner+=ne; networks++; } void getavgs() { aloc/=networks; user/=networks; asr/=networks; ner/=networks; } void printOut() { println(name+" "+calls+" "+mins); } RPoint getpoint(int tries){ RPoint tl=outline.getTopLeft(); RPoint br=outline.getBottomRight(); RPoint np= new RPoint(0,0); int searching =1; while (searching>0&&searching0)); 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); } } if (searching==0) return np; else return new RPoint(0,0); } RPoint getcentre(){ RPoint tl=outline.getTopLeft(); RPoint br=outline.getBottomRight(); return new RPoint((tl.x+br.x)*0.5,(tl.y+br.y)*0.5); } } class weightedpixel { float bright; RPoint pt; float index; //index weighted from 0-1 weightedpixel(RPoint _p,float _b) { pt=_p; bright=_b; } RPoint randompt(float r) { return new RPoint(pt.x+random(r),pt.y+random(r)); } } 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; float btotal,bavg,bmin,bmax; Vector points = new Vector(); bitmapcountry(String n,float c,float m,float al,float u,float as,float ne,RShape shp) { super(n,c,m,al,u,as,ne,shp); } void analyse(float _xo,float _xs,float _yo,float _ys) { int step=2; //speedup 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 xstep=xs/lightmap.width; float ystep=ys/lightmap.height; btotal=0; bmin=255; bmax=0; println("searching "+tl.x+","+tl.y+" -> "+(tl.x+(xstep*(brp.x-tlp.x)))+","+(tl.y+(ystep*(brp.y-tlp.y)))+" by "+xstep+","+ystep); for (int i=0;ibmax) bmax=bn; if (bn countries = new Vector(); HashMap outlines = new HashMap(); proxml.XMLElement xmlcountries; XMLInOut xmlInOut; PApplet pApplet; boolean loaded; country getcountry(int w) { return countries.get(w); } void loadxml(proxml.XMLElement element) { xmlcountries = element; //reconstruct countries from xml data including attaching shapes proxml.XMLElement country; proxml.XMLElement pt; int pts=0; for(int i = 0; i < xmlcountries.countChildren();i++){ country = xmlcountries.getChild(i); String name=country.getAttribute("name"); if (outlines.containsKey(name.substring(0, 3))) { bitmapcountry c=new bitmapcountry(name,country.getFloatAttribute("calls"),country.getFloatAttribute("mins"),country.getFloatAttribute("aloc"),country.getFloatAttribute("user"),country.getFloatAttribute("asr"),country.getFloatAttribute("ner"),shp.children[outlines.get(name.substring(0, 3))]); for(int j = 0; j < country.countChildren();j++){ pt = country.getChild(j); weightedpixel p=new weightedpixel(new RPoint(pt.getFloatAttribute("x"),pt.getFloatAttribute("y")),pt.getFloatAttribute("b")); p.index=pt.getFloatAttribute("i"); c.points.add(p); } c.btotal=country.getFloatAttribute("btotal"); c.bmax=country.getFloatAttribute("bmax"); c.bmin=country.getFloatAttribute("bmin"); c.bavg=c.btotal/c.points.size(); pts+=country.countChildren(); countries.add(c); } } println("loaded "+countries.size()+" countries, "+pts+" data points in "+((millis()-start)*.001)+"secs"); loaded=true; } calldata(String[][] data,RShape shp,String filename,PApplet _pApplet) { start=millis(); boolean parsedata=true; pApplet=_pApplet; loaded=false; /* try { //to deserialise File file = new File("countries.dat"); ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); Vector countries = (Vector) in.readObject(); in.close(); parsedata=false; } catch (ClassNotFoundException e) { println("problem parsing countries.dat"); e.printStackTrace(); } catch (IOException e) { println("problem loading countries.dat"); } if (parsedata) { */ for (int i=0;i