Print

Print


Commit in CDMS/src/CDMS/kscheck on MAIN
CreateRoadMapFile.java+81-171.7 -> 1.8
CreateRoadMapTest.java+1-11.1 -> 1.2
+82-18
2 modified files
Fix for right angle interps. Some were not guaranteed that one image was enough. If looking at a right angle, now check explicitly that there is good overlap between the interp and the qet1 and qet2. If not, add another image to be sure. ~Might~ not be necessary, but good to be sure.

CDMS/src/CDMS/kscheck
CreateRoadMapFile.java 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- CreateRoadMapFile.java	5 Feb 2011 20:45:38 -0000	1.7
+++ CreateRoadMapFile.java	7 Feb 2011 09:20:52 -0000	1.8
@@ -1,8 +1,3 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
 package CDMS.kscheck;
 
 import java.io.FileNotFoundException;
@@ -387,6 +382,20 @@
         if(anglediff < FLAT_ANGLE_CUT)
         	return true;
     	
+        if(Math.abs(angle2-Math.PI/2) < FLAT_ANGLE_CUT && Math.abs(angle1 - Math.PI/2) < FLAT_ANGLE_CUT) // here, we're concerned about vertical lines
+        	return true;
+        if(Math.abs(angle2+Math.PI/2) < FLAT_ANGLE_CUT && Math.abs(angle1 + Math.PI/2) < FLAT_ANGLE_CUT) // here, we're concerned about vertical lines
+        	return true;
+        
+    	return false;
+    }
+    
+    private boolean isRight(double angle1, double angle2){
+    	if(Math.abs(angle1-angle2)-Math.PI/2 < FLAT_ANGLE_CUT ||
+    			Math.abs(angle1-angle2)-Math.PI/2 -Math.PI < FLAT_ANGLE_CUT)
+    		return true;
+    	
+    	
     	return false;
     }
 
@@ -431,6 +440,10 @@
         	pos[1] = (y1+y2)/2;
       	
         	interps.add(pos);
+        	
+        	if(pos[0] > 100)
+        		System.out.println("WOAH BOY");
+        	
         	return interps;
         	
         }
@@ -442,25 +455,65 @@
         	// get the point of intersection between them
         	Double[] xy = getXYIntersect(line1,line2);
         	interps.add(xy);
-        	
-        	// make a double check that we actually intersect properly with 
-        	if(!goodOverlapSingle(xy,coords1)){
+        	        	
+        	if(xy[0]> 100)
+        		System.out.println("WOAH BOY");
+        	
+        	// make a double check that we actually intersect properly with
+        	// only care to do this on right-angles: everything else is guaranteed essentially to work
+        	// since we did a check before we entered here that overlap in each direction > -1 
+        	if(!goodOverlapSingle(xy,coords1) && isRight(angle1,angle2)){
         		Double[] pos1 = new Double[2];
-        		double newx = xy[0] - (line1[0]*xDim)/2;
+        		int sign;
+        		if(0.001*coords1[0] > xy[0])
+        			sign = 1;
+        		else
+        			sign = -1;
+        		double newx = xy[0] + sign*(yDim)/(2*Math.abs(line1[0]));
         		double newy = newx*line1[0] + line1[1];
         		pos1[0]=newx;
         		pos1[1]=newy;
         		
+        		System.out.println("real poor interp");
+        		System.out.println(x1 + " " + y1 + " " + angle1);
+    			System.out.println(x2 + " " + y2 + " " + angle2);
+        		
+        		if(newx > 100){
+        			System.out.println("WOAH BOY1 " + newx + " " + newy + " around " + xy[0] + " " +xy[1]);
+        			System.out.println("line 1: " + line1[0] + " " + line1[1]);
+        			System.out.println("line 2: " + line2[0] + " " + line2[1]);
+        			System.out.println(x1 + " " + y1 + " " + angle1);
+        			System.out.println(x2 + " " + y2 + " " + angle2);
+
+        		}
+        		
+        		
         		interps.add(pos1);
+        		
         	}
-        	if(!goodOverlapSingle(xy,coords2)){
+        	// same, but check in the other direction that overlap is good
+        	if(!goodOverlapSingle(xy,coords2) && isRight(angle1,angle2)){
         		Double[] pos2 = new Double[2];
-        		double newx = xy[0] + (line2[0]*xDim)/2;
+        		int sign;
+        		if(0.001*coords2[0] > xy[0])
+        			sign = 1;
+        		else
+        			sign = -1;
+        		//double newx = xy[0] + sign*(line2[0]*xDim)/2;
+        		double newx = xy[0] + sign*(yDim)/(2*Math.abs(line2[0]));
         		double newy = newx*line2[0] + line2[1];
         		
         		pos2[0] = newx;
-        		pos2[0] = newy;
+        		pos2[1] = newy;
         		interps.add(pos2);
+        		
+        		System.out.println("real poor interp");
+        		System.out.println(x1 + " " + y1 + " " + angle1);
+    			System.out.println(x2 + " " + y2 + " " + angle2);
+        		
+        		if(newx > 100){
+        			System.out.println("WOAH BOY2 " + newx + " " + newy + " around " + xy[0] + " " +xy[1]);
+        		}
         	}
         	
         	return interps;
@@ -468,8 +521,8 @@
     }
     
     private boolean goodOverlapSingle(Double[] xy, Double[] coords1){
-    	Double x = 0.001*xy[0]; //coords are given in um, OGP routine needs them in mm
-        Double y = 0.001*xy[1];
+    	Double x = xy[0]; //coords are given in um, OGP routine needs them in mm
+        Double y = xy[1];
         Double angle = coords1[2];
         Double x1 = 0.001*coords1[0];
         Double y1 = 0.001*coords1[1];
@@ -508,6 +561,13 @@
     		double leftmostRight = Math.min(right1,right);
     		
     		xOverlap = (leftmostRight - rightmostLeft)/xDim;// calculate overlap, normalized by xDim
+    		
+    		if(xOverlap < -1){
+    			System.out.println("weird one, xy is " + xy[0] + " " + xy[1]);
+    			System.out.println("leftmostRight = " + Math.min(right1,right) + " rightmostLef = " 
+    					+ Math.max(left1,left));
+    			System.out.println("xPics1 = " + xPics1 + "from " + x1 + ", xDim = " +xDim);
+    		}
     	}
     	if (y1-y==0){
     		yOverlap = 1; // same for y now
@@ -519,13 +579,13 @@
     		yOverlap = (bottommostTop - topmostBottom)/yDim;
     	}
     	
-    	if(Math.max(yOverlap, xOverlap) > OVERLAP_FRAC-0.5 && Math.min(yOverlap,xOverlap) > 0){
+    	if(Math.max(yOverlap, xOverlap) > 0 && Math.min(yOverlap,xOverlap) > 0){
     		return true;
     	}
     	else{
     		
-        	System.out.println("poor overlap on single, interping! yOverlap is " + yOverlap + " xOverlap is " + xOverlap);
-    		
+        	//System.out.println("poor overlap on single, interping! yOverlap is " + yOverlap + " xOverlap is " + xOverlap);
+    		//System.out.println(xy[0] + " " + xy[1]);
     		return false;
     	}
         
@@ -626,6 +686,10 @@
         
         Double m = Math.tan(angle); // find the slope using the angle
         
+//        if(Math.abs(angle+Math.PI/2) < 0.01*FLAT_ANGLE_CUT || Math.abs(angle-Math.PI/2) < 0.01*FLAT_ANGLE_CUT){
+//        	m = 0.0;
+//        }
+        
         Double b = y - m*x; // use the x-y data to find b
         
         Double[] line = new Double[2];

CDMS/src/CDMS/kscheck
CreateRoadMapTest.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- CreateRoadMapTest.java	5 Feb 2011 06:14:44 -0000	1.1
+++ CreateRoadMapTest.java	7 Feb 2011 09:20:52 -0000	1.2
@@ -11,7 +11,7 @@
 	 * @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);
+		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.txt",0);
 		if(roadmap1.getInputStatus()){
 			roadmap1.printOut();
 		}
CVSspam 0.2.8