Commit in CDMS/src/CDMS/kscheck on MAIN
CreateRoadMapTest.java+20added 1.1
MapUtil.java+121added 1.1
+141
2 added files
Add new test class for roadmaps, and new MapUtil base class for SortCoordsFile and CreateRoadMapFile. MapUtil implements all common methods, variables shared between the two, allowing for easier maitenance of code.

CDMS/src/CDMS/kscheck
CreateRoadMapTest.java added at 1.1
diff -N CreateRoadMapTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CreateRoadMapTest.java	5 Feb 2011 06:14:44 -0000	1.1
@@ -0,0 +1,20 @@
+package CDMS.kscheck;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+public class CreateRoadMapTest {
+
+	/**
+	 * @param args
+	 * @throws IOException 
+	 * @throws FileNotFoundException 
+	 */
+	public static void main(String[] args) throws FileNotFoundException, IOException {
+		CreateRoadMapFile roadmap1 = new CreateRoadMapFile("/Users/maxinion/Documents/Work/CDMS/code/imaging/testfiles1-30/sortedCoords_test_beta.txt","/Users/maxinion/Documents/Work/CDMS/code/imaging/testfiles2-4/test_long.csv",1);
+		if(roadmap1.getInputStatus()){
+			roadmap1.printOut();
+		}
+	}
+
+}

CDMS/src/CDMS/kscheck
MapUtil.java added at 1.1
diff -N MapUtil.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MapUtil.java	5 Feb 2011 06:14:44 -0000	1.1
@@ -0,0 +1,121 @@
+package CDMS.kscheck;
+
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.StreamTokenizer;
+import java.util.ArrayList;
+import java.util.List;
+
+public class MapUtil {
+
+	protected static double FLAT_ANGLE_CUT = 0.1;
+	protected static double FLAT_XY_CUT = 100;  
+
+	// returns 0 if not straight
+	// returns -1 if horizontal
+	// returns 1 if vertical
+	protected int isStraight(Double[] coords1, Double[] coords2){
+		Double x1 = coords1[0];
+		Double x2 = coords2[0];
+		Double y1 = coords1[1];
+		Double y2 = coords2[1];
+		Double angle1 = coords1[2];
+		Double angle2 = coords2[2];
+
+		//double piremain1 = Math.abs(angle1)%Math.PI;
+		//double piremain2 = Math.abs(angle2)%Math.PI;
+
+		//if((piremain1 < FLAT_ANGLE_CUT || piremain1 > Math.PI-FLAT_ANGLE_CUT)
+		//		&& (piremain2 < FLAT_ANGLE_CUT || piremain2 > Math.PI-FLAT_ANGLE_CUT) ){
+		//if(Math.abs(Math.abs(angle1)-Math.PI) < FLAT_ANGLE_CUT && Math.abs(Math.abs(angle2)-Math.PI) < FLAT_ANGLE_CUT ){
+		if((Math.abs(Math.abs(angle1)-Math.PI) < FLAT_ANGLE_CUT || Math.abs(angle1) < FLAT_ANGLE_CUT) 
+				&& (Math.abs(Math.abs(angle2)-Math.PI) < FLAT_ANGLE_CUT || Math.abs(angle1) < FLAT_ANGLE_CUT)  ){
+			//both are horizontal in this case: check that they're in the same line now
+			if(Math.abs(y1-y2) < FLAT_XY_CUT){
+				// they're in the same line, and they're horizontal
+				return -1;
+			}
+		}
+		//else if(((Math.abs(angle1)%(Math.PI/2)) < FLAT_ANGLE_CUT ) && (Math.abs(angle1)%(Math.PI) > FLAT_ANGLE_CUT )
+		//		&& ((Math.abs(angle2)%(Math.PI/2)) < FLAT_ANGLE_CUT) && (Math.abs(angle2)%(Math.PI) > FLAT_ANGLE_CUT )){
+		else if(Math.abs(Math.abs(angle1)-Math.PI/2) < FLAT_ANGLE_CUT && Math.abs(Math.abs(angle2)-Math.PI/2) < FLAT_ANGLE_CUT){
+			// both are vertical.
+			if(Math.abs(x1-x2) < FLAT_XY_CUT){
+				return 1;
+			}
+		}
+
+		return 0;
+	}
+	
+    protected List<Double> getNumbersInLine(StreamTokenizer tok){
+    	try{
+        //  Create a list of numbers that the tokenizer finds
+        List<Double> nums = new ArrayList<Double>();
+
+        //  Loop looking for either end of line or end of file
+        while (tok.nextToken() != StreamTokenizer.TT_EOL) {
+            if(tok.ttype==StreamTokenizer.TT_EOF) return null; // reached EOF: get out of here!
+            												   // note we assume this is not on a line with data
+
+            //if (tok.ttype == StreamTokenizer.TT_EOL) break;
+            
+            //  Check to make sure that we have a numeric token
+            if (tok.ttype != StreamTokenizer.TT_NUMBER) continue;
+            
+            //  Found a number token - add it to the list
+            nums.add(tok.nval);
+            
+        }
+        //if(nums.size()==0 && tok.ttype==StreamTokenizer.TT_EOF) return null;
+        return nums;
+    	}
+    	catch(IOException exception){
+    		return null;
+    	}
+    }
+    
+    private FileReader fr;
+    private StreamTokenizer tok;
+    
+    protected ArrayList<Double[]> getList(String inputFile) throws FileNotFoundException{
+    	fr = new FileReader(inputFile);
+        tok = new StreamTokenizer(fr);
+        tok.resetSyntax();
+        tok.wordChars(33, 126);
+        tok.parseNumbers();
+        tok.whitespaceChars(0, 32);
+        tok.eolIsSignificant(true);
+        tok.commentChar('%');
+    	
+    	
+    	ArrayList<Double[]> _coordinates = new ArrayList<Double[]>();
+    	
+    	List<Double> args = getNumbersInLine(tok);
+
+    	while (args!=null) {
+        	System.out.println("in loop");
+            //no coordinates: means we have a blank line. (or a comment line or something similar)
+        	//continue on till we reach end of file or a real line
+            if (!args.isEmpty()){
+
+            	Double xcoord = args.get(0);
+            	Double ycoord = args.get(1);
+            	Double angle = args.get(2);
+            	Double TEStype = args.get(3);
+
+            	//add all coordinates to _coordinates ArrayList
+            	Double pos[] = {xcoord, ycoord, angle, TEStype};
+            	_coordinates.add(pos);
+            	System.out.print(pos[0]);
+            }
+            else System.out.println("blank line!");
+            args = getNumbersInLine(tok); // get the next set of args: if it's null, we're going to break out
+			  							  // if it's blank, we'll just continue on
+        }
+    	return _coordinates;
+    	
+    }
+
+}
CVSspam 0.2.8