Print

Print


Commit in CDMS/src/CDMS/kscheck on MAIN
CreateRoadMapFile.java+136-271.2 -> 1.3
SortCoordsTest.java+1-11.2 -> 1.3
+137-28
2 modified files
One bugfix, two new features.

Bugfix: Change size of qet_width to .307, as measured in an image sent by Scott.

Feature: Check for overlap before interpolating. If overlap 80% of image size in one direction, and any at all in other direction, then we have very good overlap that includes the center area. 80% is a value that's up for debate; I'd rather be a bit conservative so I set it high-ish.

Feature: Added output option to CreateRoadMapFile(..., int outputType). When outputType = 0, output the normal txt with full commands. When outputType = 1, output a csv, with comma separated x, y coordinates, and flags on interpolated values. Useful for debugging and viewing charts in Numbers, etc.

Known issues: changing the qet size has triggered massive over imaging in diagonal regions, with qets that were previously well imaged by 2x3 grids going to 3x3. 

CDMS/src/CDMS/kscheck
CreateRoadMapFile.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- CreateRoadMapFile.java	22 Jan 2011 19:08:28 -0000	1.2
+++ CreateRoadMapFile.java	25 Jan 2011 02:06:47 -0000	1.3
@@ -30,13 +30,28 @@
  */
 public class CreateRoadMapFile {
 
-    public List<Double[]> _coordinates;
+    private List<Double[]> _coordinates;
 //    public BasicMatrix XcoordsMatrix;
 //    public BasicMatrix YcoordsVector;
 //    public BasicMatrix functionVector;
+    
+    
+    // lots of parameters
+    private static double TESlength = 0.7; //length in mm
+    private double TESwidth = 0.307907; //width in mm, originally .22 mm
+    //private static double TESwidth = 0.27;
+    private static double nPixX = 620; //number of pixels in horizontal direction = 640 add overlap explicitly here: 620/460
+    private static double nPixY = 460; //number of pixels in vertical direction = 480
 
-    public CreateRoadMapFile(String inputCoordsFile, String outputOGPscript, double pixelSize) throws FileNotFoundException, IOException {
-        
+    private static double xDim;
+    private static double yDim;
+    
+    private static boolean CHECK_OVERLAP = true; // flag for whether we check for overlap before interpolating
+    
+    public CreateRoadMapFile(String inputCoordsFile, String outputOGPscript, double pixelSize, int outputType) throws FileNotFoundException, IOException {
+        // outputType = 0 should be default: normal commands file
+    	// outputType = 1 is for csv output, for examining in excel/numbers/neooffice
+    	
         FileReader fr = new FileReader(inputCoordsFile);
         StreamTokenizer tok = new StreamTokenizer(fr);
         tok.resetSyntax();
@@ -50,10 +65,8 @@
 
         _coordinates = new ArrayList<Double[]>();
 
-        double TESlength = 0.7; //length in mm
-        double TESwidth = 0.22; //width in mm
-        double xDim = (620)*pixelSize; //number of pixels in horizontal direction = 640 add overlap explicitly here: 620/460
-        double yDim = (460)*pixelSize; //number of pixels in vertical direction = 480
+        xDim = nPixX*pixelSize; 
+        yDim = nPixY*pixelSize; 
         
 
         //  Loop over the input coordinate file entries
@@ -77,12 +90,15 @@
         }
 
         int ncoords = _coordinates.size();
-
-        output.write("BEGIN_RUN\n");
-        output.write("MM\n");
-        output.write("SET_DATUM\n");
-        output.write("c:\\Partrtn\\IZipDatum_PeaceSide1_x2_5.RTN\n");
-
+        
+        // before headers, check we want them
+        if(outputType==0){
+        	output.write("BEGIN_RUN\n");
+        	output.write("MM\n");
+        	output.write("SET_DATUM\n");
+        	output.write("c:\\Partrtn\\IZipDatum_PeaceSide1_x2_5.RTN\n");
+        }
+        
         for(int i = 0; i<ncoords; i++){
             Double [] coords1 = _coordinates.get(i);
 
@@ -91,14 +107,14 @@
             Double angle1 = coords1[2];
 
             //lengths in mm
-            double length_x = Math.abs(TESlength*Math.cos(angle1))+Math.abs(TESwidth*Math.sin(angle1));
-            double length_y = Math.abs(TESlength*Math.sin(angle1))+Math.abs(TESwidth*Math.cos(angle1));
+            double length_x = getILengthX(angle1);
+            double length_y = getILengthY(angle1);
 
             //take m by n array of pictures to cover entire TES
 
             //find m (horizontal number of pics) and n (vertical number of pics)
-            int m = (int) Math.ceil(length_x/xDim);
-            int n = (int) Math.ceil(length_y/yDim);
+            int m = getXPics(length_x);
+            int n = getYPics(length_y);
 
             //write proper commands to output autorun file
             for(int j = 0; j < m; j++){
@@ -108,8 +124,8 @@
                     fmt1.format("%.6f", x1-(0.5*(m-1))*xDim+j*xDim); // very clever: "extra" pixels go on either side of
                     fmt2.format("%.6f", y1-(0.5*(n-1))*yDim+k*yDim); // the QET by the 0.5*(m-1) offset here
                     												 // will we need to include explicit overlap?
-                    output.write("c:\\Partrtn\\IZipOriginTakePicture_x2_5.RTN,"+fmt1+","+fmt2+",0,0,0,0\n");
-                    //output.write(fmt1+","+fmt2+"\n");
+                    if(outputType==0) output.write("c:\\Partrtn\\IZipOriginTakePicture_x2_5.RTN,"+fmt1+","+fmt2+",0,0,0,0\n");
+                    else if(outputType==1) output.write(fmt1+","+fmt2+"\n");
                 }
                 
             }
@@ -118,28 +134,41 @@
             if(i != ncoords-1){
 
                 Double[] coords2 = _coordinates.get(i+1);
-        
-
-                // also only do this if the distance is not too great
-                
+                        
                 Double[] interp = getInterpolatedImagePosition(coords1,coords2);
-                if(interp!=null){ // null means we don't want an interpolated picture, prolly cause of jump
+                if(interp!=null){ // null means we don't want an interpolated picture
                 	Formatter fmt1 = new Formatter();
                 	Formatter fmt2 = new Formatter();
                 	fmt1.format("%.6f", interp[0]);
                 	fmt2.format("%.6f", interp[1]);
-                	output.write("c:\\Partrtn\\IZipOriginTakePicture_x2_5.RTN,"+fmt1+","+fmt2+",0,0,0,0\n");
-                    //output.write(fmt1+","+fmt2+",%interp\n");
+                	if(outputType==0) output.write("c:\\Partrtn\\IZipOriginTakePicture_x2_5.RTN,"+fmt1+","+fmt2+",0,0,0,0\n");
+                	else if(outputType==1) output.write(fmt1+","+fmt2+",%interp\n");
                 }
             }
 
         }
 
-        output.write("END_RUN\n");
+        if(outputType==0) output.write("END_RUN\n");
         
         output.close();
     }
 
+    private int getXPics(double length){
+    	return (int) Math.ceil(length/xDim);
+    }
+    
+    private int getYPics(double length){
+    	return (int) Math.ceil(length/yDim);
+    }
+    
+    private double getILengthX(double angle){
+    	return Math.abs(TESlength*Math.cos(angle))+Math.abs(TESwidth*Math.sin(angle));
+    }
+    
+    private double getILengthY(double angle){
+        return Math.abs(TESlength*Math.sin(angle))+Math.abs(TESwidth*Math.cos(angle));
+    }
+    
 
         /**
      * Get a list of numbers in a line on the input stream
@@ -194,6 +223,9 @@
         Double y2 = 0.001*coords2[1];
         Double angle2 = coords2[2];
 
+        // more checks: first (really first) check if we really need to interpolate
+        if(goodOverlap(coords1, coords2)) // if there's good overlap, return null interpolation position
+        	return null;
         
         // checks: for large angle and large jumps
         // first: large jump check. if the jump is too big, don't interpolate
@@ -292,6 +324,83 @@
 //    	return pos;
     }
     
+    private boolean goodOverlap(Double[] coords1, Double[] coords2){
+    
+    	Double x1 = 0.001*coords1[0]; //coords are given in um, OGP routine needs them in mm
+        Double y1 = 0.001*coords1[1];
+        Double angle1 = coords1[2];
+        Double x2 = 0.001*coords2[0];
+        Double y2 = 0.001*coords2[1];
+        Double angle2 = coords2[2];
+    	
+        if(CHECK_OVERLAP){ // check global flag that enables overlap detection
+        	
+        	// init overlap counters
+        	double xOverlap = 0;
+        	double yOverlap = 0;
+        	
+        	// first set up number of images, and lengths we're dealing with
+        	double lx1 = getILengthX(angle1);
+        	double ly1 = getILengthY(angle1);
+        	
+        	double lx2 = getILengthX(angle2);
+        	double ly2 = getILengthY(angle2);
+        	
+        	int xPics1 = getXPics(lx1);
+        	int xPics2 = getXPics(lx2);
+        	
+        	// calculate the x coordinates of the left and right ends of the pictures we're taking, for both
+        	// sensors (the current and the next)
+        	//double left1 = x1-(0.5*(xPics1-1))*xDim-0.5*xDim; // use the same calc as for center of images
+        	//double left2 = x2-(0.5*(xPics2-1))*xDim-0.5*xDim; // but then offset by half the width of the image
+        	//double right1 = x1+(0.5*(xPics1-1))*xDim+0.5*xDim; // this way we find the edge, not the center
+        	//double right2 = x2+(0.5*(xPics2-1))*xDim+0.5*xDim;
+        	// simplifying the above calculation a bit:
+        	double left1 = x1 - xDim*(0.5*xPics1);
+        	double left2 = x2 - xDim*(0.5*xPics2);
+        	double right1 = x1 + xDim*0.5*xPics1;
+        	double right2 = x2 + xDim*0.5*xPics2;
+        	
+        	
+        	int yPics1 = getYPics(ly1);
+        	int yPics2 = getYPics(ly2);
+        	
+        	double top1 = y1+(0.5*(yPics1-1))*yDim;
+        	double top2 = y2+(0.5*(yPics2-1))*yDim;
+        	double bot1 = y1-(0.5*(yPics1-1))*yDim;
+        	double bot2 = y2-(0.5*(yPics2-1))*yDim;
+        	
+        	if(x1-x2==0){
+        		xOverlap = 1; // flag that we have good x overlap, don't bother with anything else
+        	}
+        	else{ // if not simple, check for the real amount of overlap        		
+        		double rightmostLeft = Math.max(left1,left2);
+        		double leftmostRight = Math.min(right1,right2);
+        		
+        		xOverlap = (leftmostRight - rightmostLeft)/xDim;// calculate overlap, normalized by xDim
+        	}
+        	if (y1-y2==0){
+        		yOverlap = 1; // same for y now
+        	}
+        	else{
+        		double topmostBottom = Math.max(bot1,bot2);
+        		double bottommostTop = Math.max(top1, top2);
+        		
+        		yOverlap = (bottommostTop - topmostBottom)/yDim;
+        	}
+        	
+        	// if 80% overlap in one direction, and > 0 overlap in another direction, we can be pretty sure
+        	// we don't need overlap. but otherwise, let's say bad overlap, take another picture.
+        	if(Math.max(yOverlap, xOverlap) > 0.8 && Math.min(yOverlap,xOverlap) > 0)
+        		return true;
+        	else
+        		return false;
+        	
+        }
+        else 
+        	return false; // if we don't enable the check, just return false, bad overlap, force interp
+    }
+    
     //get y = mx + b line from a qet. (extrapolate using x,y,angle coordinates)
     //returns independent of units... be sure to use them right!
     //returns line[], with line[0] = m, line[1] = b

CDMS/src/CDMS/kscheck
SortCoordsTest.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- SortCoordsTest.java	22 Jan 2011 19:08:28 -0000	1.2
+++ SortCoordsTest.java	25 Jan 2011 02:06:47 -0000	1.3
@@ -18,7 +18,7 @@
     public static void main(String[] args) throws FileNotFoundException, IOException {
     	System.out.println("testing!");
         //SortCoordsFile pcfile = new SortCoordsFile("side1_copy.txt","sortedCoords.txt");
-        CreateRoadMapFile roadmap1 = new CreateRoadMapFile("sortedCoords_medium.txt","autorun_medium_test.txt",0.00059);
+        CreateRoadMapFile roadmap1 = new CreateRoadMapFile("/Users/maxinion/Documents/Work/CDMS/code/imaging/sortedCoords_short.txt","/Users/maxinion/Documents/Work/CDMS/code/imaging/autorun_test_interp_true_26size.csv",0.00059,1);
         //CreateRoadMapFile roadmap2 = new CreateRoadMapFile("shortTest2.txt","testautorun2.txt",0.00067);
         //CreateRoadMapFile roadmap3 = new CreateRoadMapFile("longTest.txt","testautorun3.txt",0.00067);
         //SplitSortedFile splitfile = new SplitSortedFile("sortedCoords.txt","splittest.txt");
CVSspam 0.2.8