Commit in CDMS/src/CDMS/ImageNavigatorII on MAIN
Tiler.java+48-101.4 -> 1.5
now reads from info.txt instead of having to set a lot of info.  also deletes emty tiles.

CDMS/src/CDMS/ImageNavigatorII
Tiler.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- Tiler.java	30 Jul 2010 00:08:00 -0000	1.4
+++ Tiler.java	30 Jul 2010 23:32:09 -0000	1.5
@@ -4,6 +4,7 @@
 import java.awt.geom.AffineTransform;
 import java.awt.image.*;
 import java.io.*;
+
 import javax.imageio.ImageIO;
 import java.util.*;
  
@@ -12,6 +13,13 @@
  * into the appropriate 256 px square tiles needed for the Google API, and makes the tiles for
  * different zoom levels.
  * 
+ * Two or three arguments can be added when this program is called: java Tiler [#threads thread] [startZoomLevel]
+ * If you have multiple processors, the processing time can be sped up by splitting the program into 
+ * multiple threads, specified by the #threads (Ex: 2 if you have two cores).  The thread must also then 
+ * be specified, or it will default to 0 (Ex: if your processor has two cores, you would call both 
+ * "java Tiler 2 0" and "java Tiler 2 1".  A third argument can be set to start a minimum zoom level 
+ * to start the program running at.
+ * 
  * File Structure:
  * 	>Image Set Folder
  * 		>gmapviewer.htm	[the website navigator file!]
@@ -26,10 +34,17 @@
 public class Tiler {
     public static void main(String[] args) throws IOException {
     	Date startDate = new Date();
+
+	    String[] lines = getLines("./info.txt");
+	    int numXimgs = Integer.parseInt(lines[0]);
+	    int numYimgs = Integer.parseInt(lines[1]);
+	    int imgW = Integer.parseInt(lines[2]);
+	    int imgH = Integer.parseInt(lines[3]);
+	    String path = lines[4];
     	
-	    String path = "/nfs/farm/g/ee/u15/cdms/CDMS_ImageNavigatorII/wilenc/IZipG47_Side1_Al/";
+	    /*String path = "/nfs/farm/g/ee/u15/cdms/CDMS_ImageNavigatorII/wilenc/IZipG47_Side1_Al/";
 	    int numXimgs = 27;
-	    int numYimgs = 37;
+	    int numYimgs = 37;*/
 	    
 	    int numThreads = 1;
 	    int thread = 0;
@@ -49,10 +64,11 @@
 	    
 	    int tileSize = 256;
 	    
+	    
 	    //get info on imgs
-	    BufferedImage img = ImageIO.read(new File(path+"/stitched_images/"+"/0_0.png"));
-	    int imgW = img.getWidth();
-	    int imgH = img.getHeight();
+	    //BufferedImage img = ImageIO.read(new File(path+"/stitched_images/"+"/0_0.png"));
+	    //int imgW = img.getWidth();
+	    //int imgH = img.getHeight();
 	    
 	    //find max zoom level
 	    double totalSize = 10000;
@@ -61,6 +77,7 @@
 	    	maxZoom++;
 	    	totalSize = Math.max(imgW*numXimgs, imgH*numYimgs)/Math.pow(2, maxZoom);
 	    }
+	    System.out.println("Max Zoom Level: "+maxZoom);
 	    
 	    //create .txt file for google maps api
 	    double scale = 283;//3.37085208/640;
@@ -92,7 +109,8 @@
 	    	int upperThreadLimit = (int)Math.floor((thread+1)*numYtiles/numThreads);
 	    	for (int row=lowerThreadLimit; row<upperThreadLimit; row++) {
 	    		for (int col=0; col<numXtiles; col++) {
-        	    	BufferedImage toStore = new BufferedImage(tileSize,tileSize,img.getType());
+	    			boolean draw = false;
+        	    	BufferedImage toStore = new BufferedImage(tileSize,tileSize,BufferedImage.TYPE_INT_RGB);
         	    	Graphics2D g2 = toStore.createGraphics();
         	    	//loop through each image, test if it is in tile, and draw it if it is
         	    	for (int yImg=0; yImg<numYimgs; yImg++) {
@@ -102,10 +120,12 @@
         	    			int xpos = (int)Math.ceil(xImg*imgW*scaleFactor)-col*tileSize;
         	    			int ypos = (int)Math.ceil(yImg*imgH*scaleFactor)-row*tileSize;
     	    				if (xpos>=(-imgW*scaleFactor) && xpos<tileSize && ypos>=(-imgH*scaleFactor) && ypos<tileSize) {
-        	    				try {
+        	    				BufferedImage img;
+    	    					try {
         	    					img = ImageIO.read(new File(path+"/stitched_images/"+yImg+"_"+xImg+".png"));
+        	    					draw = true;
         	    				} catch (Exception e) {
-        	    					img = new BufferedImage(img.getWidth(),img.getHeight(),img.getType());
+        	    					img = new BufferedImage(imgW,imgH,BufferedImage.TYPE_INT_RGB);
         	    				}
         	    				AffineTransform at = AffineTransform.getTranslateInstance(0, 0);
         	    				at.setTransform(scaleFactor, 0, 0, scaleFactor, xpos, ypos);
@@ -113,8 +133,11 @@
         	    			}
             	    	}
         	    	}
-        	    	ImageIO.write(toStore, "PNG", new File(path+"/tiles/"+zoom+"_"+col+"_"+row+".png"));
-        	    	System.out.println(zoom+"_"+col+"_"+row);
+        	    	if (draw==true) {
+        	    		ImageIO.write(toStore, "PNG", new File(path+"/tiles/"+zoom+"_"+col+"_"+row+".png"));
+        	    		System.out.println(zoom+"_"+col+"_"+row);
+        	    	}
+        	    	else System.out.println(zoom+"_"+col+"_"+row+" blank");
     	    	}
 	    	}
 	    }
@@ -124,4 +147,19 @@
     Date endDate = new Date();
 	System.out.println("\nRuntime: "+(endDate.getTime()-startDate.getTime())/1000/60);
 }
+    
+  //takes an input path and returns a list of values split by the SET_PART-REPEAT
+    public static String[] getLines(String path) {
+    	try {
+	    	BufferedReader in = new BufferedReader(new FileReader(path));
+		    String str;
+		    String text = "";
+		    while ((str = in.readLine()) != null) {
+		        text += "\n"+str;
+		    }
+		    in.close();
+		    String[] lines = text.split("SET_PART_REPEAT");
+		    return lines;
+    	} catch (IOException e) {System.out.println("File could not be read"); return null;}
+    }
 }
CVSspam 0.2.8