import java.io.*; import java.util.*; import java.text.NumberFormat; public class gen_alg3{ static int count = 0; static int count1=0; static int count2=0; static int xpos,ypos; static int num_tokens; static int j=0; static int color=1; static int interval=1; static double size=0.4; static int last_gen; static String aLine, bLine ,cLine, dateString ; static int gen ; static float[] g_int=new float[10000]; static float[] x_int=new float[10000]; static float[] y_int=new float[10000]; static float[] z_int=new float[10000]; static float[] f_int=new float[10000]; static float[] g_int1=new float[10000]; static float[] x_int1=new float[10000]; static float[] y_int1=new float[10000]; static float[] z_int1=new float[10000]; static float[] f_int1=new float[10000]; static String[] g_intf=new String[10000]; static String[] x_intf=new String[10000]; static String[] y_intf=new String[10000]; static String[] z_intf=new String[10000]; static String[] f_intf=new String[10000]; static String line; static int i=0;static int k=0; static String[] g = new String[30000]; static String[] x = new String[30000]; static String[] y = new String[30000]; static String[] z = new String[30000]; static String[] f = new String[30000]; public static void main(String[] args){ try { DataInputStream dis1 = new DataInputStream( System.in ); System.out.println("Enter Your Name : "); bLine = dis1.readLine(); // DataInputStream dis2 = new DataInputStream( System.in ); // System.out.println("Enter Your NAID# : "); // cLine = dis2.readLine(); DataInputStream dis = new DataInputStream( System.in ); System.out.println("Enter the data file name : "); aLine = dis.readLine(); dateString = toDate(); System.out.println("writing a VRML file.. Please wait.."); gen_alg(); System.out.println("VRML file Gen_al.wrl file generated"); } catch(IOException ie){;} } public static String toDate () { Calendar now = Calendar.getInstance(); int month = now.get(Calendar.MONTH) + 1; int day = now.get(Calendar.DAY_OF_MONTH); int year = now.get(Calendar.YEAR); return (month+"/"+day+"/"+year); } public static void gen_alg(){ try{ FileInputStream fin = new FileInputStream(aLine); DataInputStream din = new DataInputStream(fin); NumberFormat formatter = NumberFormat.getNumberInstance(); formatter.setMaximumFractionDigits (4); while ((line=din.readLine())!=null){ StringTokenizer t = new StringTokenizer(line," "); num_tokens=t.countTokens(); g[j]=t.nextToken(); x[j]=t.nextToken(); y[j]=t.nextToken(); z[j]=t.nextToken(); f[j]=t.nextToken(); g_int[j]=(new Float(g[j])).floatValue(); x_int[j]=(new Float(x[j])).floatValue()*5; y_int[j]=(new Float(y[j])).floatValue()*5; z_int[j]=(new Float(z[j])).floatValue()*5; f_int[j]=(new Float(z[j])).floatValue()*5; g_int1[j]=(new Float(g[j])).floatValue(); x_int1[j]=(new Float(x[j])).floatValue(); y_int1[j]=(new Float(y[j])).floatValue()*(-1); z_int1[j]=(new Float(z[j])).floatValue()*(-1); f_int1[j]=(new Float(z[j])).floatValue(); g_intf[j] = formatter.format(g_int1[j]); x_intf[j] = formatter.format(x_int1[j]); y_intf[j] = formatter.format(y_int1[j]); z_intf[j] = formatter.format(z_int1[j]); f_intf[j] = formatter.format(f_int1[j]); j++; } } catch (FileNotFoundException e) { System.err.println("fnf"+e.getMessage()); } catch (IOException e) { System.err.println("io"+e.getMessage()); } catch(NoSuchElementException nse){ System.err.println("nse"+nse.getMessage()); } catch(NumberFormatException nfe){ System.err.println(nfe.getMessage()); } try{ StringBuffer buf = new StringBuffer(); FileOutputStream fout = new FileOutputStream("Gen_Alg.wrl"); DataOutputStream dout = new DataOutputStream(fout); dout.writeBytes("#VRML V2.0 utf8"); dout.writeBytes("\n"); dout.writeBytes("Background {"); dout.writeBytes("\n"); dout.writeBytes("skyAngle[1 , 1.55, 1.6]"); dout.writeBytes("\n"); dout.writeBytes("skyColor[1 1 1, .98 .98 1, .9 .9 1, .8 .8 1]"); dout.writeBytes("\n"); dout.writeBytes("}"); dout.writeBytes("\n"); dout.writeBytes("Viewpoint { "+ " position 0 0 20"+ " orientation 10 1 1 0"+ " description \"faroff\" "+ " }"+ "Viewpoint {"+ " position 10 0 20"+ " orientation 10 1 1 0"+ " description \"view1\" "+ " }"+ "Viewpoint {"+ " position 15 0 20"+ " orientation 10 1 1 0"+ " description \"view2\" "+ " }"+ "Viewpoint {"+ "position 20 0 20"+ "orientation 10 1 1 0"+ "description \"view3\" "+ " }"); dout.writeBytes("\n"); dout.writeBytes(" Transform{"); dout.writeBytes("\n"); dout.writeBytes( " translation -12 -7.5 0"); dout.writeBytes("\n"); dout.writeBytes( " children [ "); dout.writeBytes("\n"); dout.writeBytes( " Shape { "); dout.writeBytes("\n"); dout.writeBytes( " appearance Appearance{ "); dout.writeBytes("\n"); dout.writeBytes( " material Material{diffuseColor 1 0 0 }}"); dout.writeBytes( " geometry Text { "); dout.writeBytes("\n"); dout.writeBytes( "string [ \"Copyright 2000,World Wide Web Instruction Committee (WWWIC),NDSU, Fargo ND. \" ] "); dout.writeBytes("\n"); dout.writeBytes( "fontStyle FontStyle { "); dout.writeBytes("\n"); dout.writeBytes( " style \"Bold\" "); dout.writeBytes("\n"); dout.writeBytes( " size .6 }"); dout.writeBytes("\n"); dout.writeBytes( " } "); dout.writeBytes("\n"); dout.writeBytes( " }"); dout.writeBytes("\n"); dout.writeBytes( " ] "); dout.writeBytes("\n"); dout.writeBytes( " } "); dout.writeBytes("\n"); /*Name*/ dout.writeBytes("\n"); dout.writeBytes(" Transform{"); dout.writeBytes("\n"); dout.writeBytes( " translation -15 7 0"); dout.writeBytes("\n"); dout.writeBytes( " children [ "); dout.writeBytes("\n"); dout.writeBytes( " Shape { "); dout.writeBytes("\n"); dout.writeBytes( " appearance Appearance{ "); dout.writeBytes("\n"); dout.writeBytes( " material Material{diffuseColor 1 0 0 }}"); dout.writeBytes("\n"); dout.writeBytes( " geometry Text { "); dout.writeBytes("\n"); dout.writeBytes( "string [ \"Student Name: "+bLine+"\",\"Date:"+dateString+"\" ] "); dout.writeBytes("\n"); dout.writeBytes( "fontStyle FontStyle { "); dout.writeBytes("\n"); dout.writeBytes( " style \"Bold\" "); dout.writeBytes("\n"); dout.writeBytes( " size .8 }"); dout.writeBytes("\n"); dout.writeBytes( " } "); dout.writeBytes("\n"); dout.writeBytes( " }"); dout.writeBytes("\n"); dout.writeBytes( " ] "); dout.writeBytes("\n"); dout.writeBytes( " } "); dout.writeBytes("\n"); dout.writeBytes("\n"); dout.writeBytes(" DEF ball_Script Script {"); dout.writeBytes("\n"); for (int n=0;n<=j;n++){ dout.writeBytes(" eventIn SFTime message_on"+n+""); dout.writeBytes("\n"); } dout.writeBytes(" eventOut SFInt32 whichChoice"); dout.writeBytes("\n"); dout.writeBytes(" url [\"vrmlscript:"); dout.writeBytes("\n"); for (int k=0;k<=j;k++){ dout.writeBytes(" function message_on"+k+"() {"); dout.writeBytes("\n"); dout.writeBytes(" whichChoice = "+k+";}"); dout.writeBytes("\n"); } dout.writeBytes(" \", "); dout.writeBytes("\n"); dout.writeBytes(" \"javascript:"); dout.writeBytes("\n"); for (int l=0;l<=j;l++){ dout.writeBytes(" function message_on"+l+"() {"); dout.writeBytes("\n"); dout.writeBytes(" whichChoice = "+l+";}"); dout.writeBytes("\n"); } dout.writeBytes(" \"] "); dout.writeBytes("\n"); dout.writeBytes(" }"); dout.writeBytes("\n"); dout.writeBytes(" Transform {"); dout.writeBytes("\n"); dout.writeBytes(" translation 0 0 0"); dout.writeBytes("\n"); dout.writeBytes("children [ "); dout.writeBytes("\n"); String Color=" 0 "; float color_x = 1; float color_y = 0; float color_z = 0; for(int m=0;m<=j;m++){ if(g_int[m] <= 10) { color_x = g_int[m]/10; } else if(g_int[m] >10 && g_int[m] <=20) { size = 0.3; color_x = 0; color_y = g_int[m]/40; } else if(g_int[m] >= 20 && g_int[m] <30) { size = 0.2; color_x = 0; color_y = 0; color_z = g_int[m]/60; } else if(g_int[m] >= 30) { size = 0.1; color_x = 0; color_y=g_int[m]/80; color_z = g_int[m]/40; } dout.writeBytes("\n"); dout.writeBytes(" Transform{"); dout.writeBytes("\n"); dout.writeBytes( " translation "+(1)*x_int[m]+" "+(-1)*y_int[m]+" "+(-1)*z_int[m]); dout.writeBytes("\n"); dout.writeBytes( " children [ "); dout.writeBytes("\n"); dout.writeBytes( " Shape { "); dout.writeBytes("\n"); dout.writeBytes( " appearance Appearance{ "); dout.writeBytes("\n"); dout.writeBytes( " material Material{emissiveColor "+color_x +" "+color_y+" " + color_z + "}}"); dout.writeBytes("\n"); dout.writeBytes( " geometry Sphere{radius "+size+" } "); dout.writeBytes("\n"); dout.writeBytes( " } "); dout.writeBytes("\n"); dout.writeBytes( " DEF ball_sensor"+m+" TouchSensor {} "); dout.writeBytes("\n"); dout.writeBytes( " ] "); dout.writeBytes("\n"); dout.writeBytes( " } "); dout.writeBytes("\n"); } dout.writeBytes("DEF message_Switch Switch {"); dout.writeBytes( " \n "); dout.writeBytes("choice ["); dout.writeBytes( " \n "); for(int x=0;x<=j;x++){ dout.writeBytes("Transform{"); dout.writeBytes( " \n "); dout.writeBytes("translation 6 7 0"); dout.writeBytes( " \n "); dout.writeBytes("children ["); dout.writeBytes( " \n "); dout.writeBytes("Shape {"); dout.writeBytes( " \n "); dout.writeBytes( " appearance Appearance{ "); dout.writeBytes("\n"); dout.writeBytes( " material Material{diffuseColor 1 0 0 }}"); dout.writeBytes("\n"); dout.writeBytes("geometry Text {"); dout.writeBytes("\n"); dout.writeBytes( "string [\"Position:"+x_intf[x]+","+y_intf[x]+","+z_intf[x]+"\",\" Value of m:"+f_intf[x]+"\",\" Generation No:" +g_intf[x]+" \"]"); dout.writeBytes("\n"); dout.writeBytes( "fontStyle FontStyle{"); dout.writeBytes("\n"); dout.writeBytes( "style \"BOLD\""); dout.writeBytes("\n"); dout.writeBytes( "size 0.8"); dout.writeBytes("\n"); dout.writeBytes( "spacing 1.5}"); dout.writeBytes("\n"); dout.writeBytes( "}"); dout.writeBytes("\n"); dout.writeBytes( "}"); dout.writeBytes("\n"); dout.writeBytes( "]"); dout.writeBytes("\n"); dout.writeBytes( "}"); dout.writeBytes("\n"); /*dout.writeBytes( "}"); dout.writeBytes("\n");*/ } dout.writeBytes( "]"); dout.writeBytes("\n"); dout.writeBytes( "}"); dout.writeBytes("\n"); dout.writeBytes( "]"); dout.writeBytes("\n"); dout.writeBytes( "}"); dout.writeBytes("\n"); for(int y=0;y<=j;y++){ dout.writeBytes("ROUTE ball_sensor"+y+".touchTime TO ball_Script.message_on"+y+""); dout.writeBytes("\n"); } dout.writeBytes("ROUTE ball_Script.whichChoice TO message_Switch.whichChoice"); dout.writeBytes("\n"); } catch(IOException ioe){;} } // }//main }//class