/* */ /* ConvexHullAlgThread.java */ import java.awt.*; import java.io.*; import java.net.*; import java.util.*; import ciips.animation.*; import ciips.animation.graph.*; public class ConvexHullAlgThread extends AlgThread { static int max_data = 20; //20 Points static String[] dataSets = {"Data 1", "Data 2"}; static String[] options = { "" }; private static String base_data_file_name = "con"; Point source[] = new Point[max_data]; AlgAnimFrame frame; DrawingPanel drawing_panel; int delay = 2000; static int N_HISTORY_PANELS = 2; static { AlgAnimFrame.COMPANEL_LINES = 5; } static { ciips.animation.UIFrame.allowUI( false ); } public ConvexHullAlgThread( AlgAnimFrame frame ) { super(); setParms( frame, N_HISTORY_PANELS ); this.frame = frame; int first = 0; System.out.println("ConvexHullAlgThread : super called"); System.out.flush(); if (frame != null && drawing_panel != null) { // graph_panel already created -> this constructor called from // clicking the run button -> use the generated data set } else { // this constructor called from AlgAnimFrame constructor // Ensures that graph is created // init( frame.algfile+first ); } System.out.println("ConvexHullAlgThread : cons complete"); System.out.flush(); } public boolean loadData(int choice) { System.out.println("ConvexHullAlgThread :loadData choice " + choice ); String fn = base_data_file_name + choice; init( fn ); return false; } public void init( String fn ) { System.out.println("ConvexHullAlgThread:init fn [" + fn + "]" ); InputStreamReader ins_r = null; try { URL dataURL = new URL(frame.getApplet().getCodeBase(), fn); ins_r = new InputStreamReader(dataURL.openConnection().getInputStream()); BufferedReader br = new BufferedReader( ins_r ); String line; String item1, item2; int source_x; int source_y; Point source_p; int index =0; if ((line = br.readLine()) != null) { System.out.println(line); StringTokenizer Data = new StringTokenizer(line, " "); while( (line = br.readLine() ) != null ) { Data = new StringTokenizer(line, " "); item1 = Data.nextToken(); item2 = Data.nextToken(); source_x = Integer.parseInt(item1); source_y = Integer.parseInt(item2); source_p = new Point(source_x, source_y); source[index] = source_p; System.out.println("Point : " + source[index].x +" "+ source[index].y); index++; } } System.out.println("ConvexHullAlgThread : init cons"); // graph_panel.setGraph( graph ); // graph_panel.repaint(); // frame.getCurrentPanel().addDrawingObj( graph ); } catch (Exception e) { System.out.println("ConvexHullAlgThread : init - file [" + fn + "] I/O error"); System.out.println(" " + e.getClass().getName() + " (" + e.getMessage() + ")"); } } public void run() { // int choice = frame.getDataChoice(); if ( drawing_panel == null ) { drawing_panel = new DrawingPanel (); drawing_panel = frame.getCurrentPanel(); } generateData(); StackConvex chainconvex = new StackConvex( this , drawing_panel ); int number; number = chainconvex.ChainHull_2D( source , max_data ); for ( int i=0 ; i < number ; i++ ) { System.out.println(chainconvex.H[i].x+" "+chainconvex.H[i].y); } frame.finishAlg(); drawing_panel.repaint(); } public void restoreDrawingPanelColor() { } }