import controlP5.*; import java.util.*; import java.io.*; import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*; import javax.media.opengl.GL; import processing.opengl.*; import controlP5.*; //import demos.common.TextureReader; import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; import javax.media.opengl.glu.GLU; import java.io.IOException; ControlP5 controlP5; //for GUI PMatrix3D currCameraMatrix; ControlGroup l; Slider s; controlP5.Button b; // Code: Eliza S. Bradley // MAT 259 - Project #2 Integrator slide; PGraphics3D g3; Textlabel mySmallTextlabel; float cLength = 70; PImage world; // NOTES: utilizes Quarks' shapes3d library, adapted from example of earth //http://processing.org/discourse/yabb2/YaBB.pl?num=1259917547/15 // Thanks to Reza Ali (http://www.syedrezaali.com/blog/) for the 3D axis example and the orb code //import shapes3d.*; //import shapes3d.utils.*; PImage orb; PeasyCam cam; int squareSize = 30; int gridInterval = 30; int PLOTX1, PLOTX2; int PLOTY1, PLOTY2; int PLOTZ1, PLOTZ2; int DATAMIN, DATAMAX; int DATAMINZ, DATAMAXZ; int XMIN, XMAX; int XINTERVAL; int YINTERVAL; int ZINTERVAL; float[] rotations = new float[3]; float angNS, angEW; float x0,y0,z0; float earthRadius=200; float lat0=47.6; float lng0=-122.3; //From Hashmap Exercise HashMap geodata=new HashMap(); // HashMap object String[] lines; int counter; int index=0; int geolength=406; String[] geolist=new String[geolength]; //NUMBER OF GEO ELEMENTS! ArrayList transactions = null; //global List of the data float[] out_lat=new float[5760]; float[] out_lng=new float[5760]; int[] out_hr=new int[5760]; int[] out_type=new int[5760]; int[] out_index=new int[5760]; int n=0; int alphavalue=255; int alpha_labels; int alpha_map; int alpha_grid; int alpha_obj; int alpha_labels_start=149;//60; int alpha_map_start=118;//30; int alpha_grid_start=133;//5; int alpha_obj_start=20; controlP5.Label label; Textarea myTextarea; Textarea myTextarea2; boolean view_map = true; boolean view_grid = true; boolean view_labels = true; boolean fade_alpha = true; boolean t_graphic=true; PGraphicsOpenGL pgl; GL gl; PFont font_map; PFont font_sliders; void setup(){ size(900,600,OPENGL); hint(DISABLE_OPENGL_2X_SMOOTH); hint(ENABLE_OPENGL_4X_SMOOTH); hint(ENABLE_DEPTH_SORT); smooth(); frameRate(1000); //set the frameRate of the Visualization font_map = loadFont("ArialNarrow-Bold-14.vlw"); font_sliders=loadFont("Calibri-16.vlw"); orb = loadImage("orb.png"); alpha_labels=alpha_labels_start; alpha_map=alpha_map_start; alpha_grid=alpha_grid_start; alpha_obj=alpha_obj_start; PLOTX1 = -180; PLOTX2 = 180; PLOTY1 = -90; PLOTY2 = 90; PLOTZ1 = 0; PLOTZ2 = 140; DATAMIN = -90; DATAMAX = 90; DATAMINZ = 9; DATAMAXZ = 23; XMIN = -180; XMAX = 180; XINTERVAL = 30; YINTERVAL = 30; ZINTERVAL = 3; // println("KEY CONTROLS:"); // println("-view grid \t\tg"); // println("-view map \t\t\tm"); // println("-view labels \t\tl"); // println("-start animation \t\ts"); // println("-color fade \t\tf"); world = loadImage("world.png"); //Load CSV file w/ place name & lat & lng lines = loadStrings("geodata.csv"); int geotype=0; while (index < geolength) { String[] pieces = split(lines[index], ','); if (pieces.length == 3) { String placename=pieces[0]; float latval = float(pieces[1]); float lngval = float(pieces[2]); geolist[index]=placename; if(index==50) geotype++; if(index==306) geotype++; Geo g = new Geo(placename,latval,lngval,geotype, index); geodata.put(placename,g); } // Go to the next line for the next run through draw() index = index + 1; } //FIND GEO MATCHES AND UPDATE HASHMAP WITH COUNT this.transactions = loadTransactions("splxmldata.txt"); Transaction t; int n=0; for(int i=0; i=0) { Geo g=(Geo) geodata.get(geolist[j]); g.count(titletext); //println(i+","+j+","+geolist[j]+","+ckoday+","+ckohr+","+g.lat+","+g.lng); out_lat[n]=g.lat; out_lng[n]=g.lng; out_hr[n]=ckohr; out_index[n]=g.index; out_type[n]=g.type; // colorMode(HSB); n=n+1; } } } cam = new PeasyCam(this,(PLOTX1+PLOTX2)*.5,(PLOTY1+PLOTY2)*.5,(PLOTZ1+PLOTZ2)*.5, 500); cam.setMinimumDistance(1); cam.setMaximumDistance(5000); slide = new Integrator(700, 0.3, 0.8); setupGUI(); } void draw(){ slide.update(); background(0); //this moves the interface up and down if(mouseY > 500) { slide.target(500); cam.setMouseControlled(false); } else { slide.target(580); cam.setMouseControlled(true); } if(l.position().y != slide.value) { l.position().y = slide.value; } rotations = cam.getRotations(); pgl = (PGraphicsOpenGL) g; gl = pgl.gl; pgl.beginGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glEnable (GL.GL_LINE_SMOOTH); gl.glHint (GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST); gl.glDepthMask(false); gl.glDisable(GL.GL_DEPTH_TEST); gl.glEnable ( GL.GL_LINE_SMOOTH ); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE); if(fade_alpha){ alphavalue_dec(); } if(view_map){ tint(255,255,255,alpha_map); image(world,-180,-90,360,180); } axis(); if(view_grid){ drawGrid(); } if(view_labels){ drawAxisLabels(); drawXLabels(); drawYLabels(); drawZLabels(); } drawPlot(); drawTitle(); int maxval=700; drawBox(); pgl.endGL(); gui(); } void alphavalue_dec() { alphavalue=round(alphavalue-1); } void axis() { strokeWeight(2); int a= alpha_grid;; stroke(255,a); line(PLOTX1,PLOTY1,PLOTZ1,PLOTX2,PLOTY1,PLOTZ1); stroke(255,a); line(PLOTX1,PLOTY1,PLOTZ1,PLOTX1,PLOTY2,PLOTZ1); stroke(255,a); line(PLOTX1,PLOTY1,PLOTZ1,PLOTX1,PLOTY1,PLOTZ2); } void drawBox() { for(int j=1; j<=n; j++){ stroke(255,50); //point(out_lat[n],out_lng[n],10*out_hr[n]); pushMatrix(); translate(out_lng[j],-out_lat[j],10*out_hr[j]-90); noStroke(); if(out_index[j]==332){ //stroke(255,255,0); fill(255,255,255,alpha_obj); } else { fill(255,10,10,alpha_obj); } rotateX(rotations[0]); rotateY(rotations[1]); rotateZ(rotations[2]); if(t_graphic){ imageMode(CENTER); tint(255,0,0,alpha_obj); image(orb,0,0,50,50); tint(255,alpha_obj/4); image(orb,0,0,40,40); imageMode(CORNER); tint(255,255); } else{ box(8); tint(255,255); } popMatrix(); } if(n<5759){n=n+1;} } public float[] calcXYZ(float lat, float lng){ float angNS, angEW; float x,y,z; float r=earthRadius; angNS = radians(lat); angEW = radians(lng); y = - r * sin(angNS); x = - r * cos(angNS) * cos(angEW); z = r * sin(angEW) * cos(angNS); float [] xyz={x,y,z}; return xyz; } public float[] calcMid(float lat, float lng, float lat2, float lng2, float r){ float angNS, angEW; float x,y,z; angNS = radians((lat+lat2)/2); angEW = radians((lng+lng2)/2); y = - r * sin(angNS); x = - r * cos(angNS) * cos(angEW); z = r * sin(angEW) * cos(angNS); float [] xyz={x,y,z}; return xyz; } class Geo { int count; float lat; float lng; String name; String title; int type; int index; Geo(String s, float latval, float lngval, int gtype, int indx) { name = s; count = 0; lat = latval; lng=lngval; title=""; type=gtype; index=indx; } void count(String titletext) { count++; title=titletext; } }