CDMS/src/CDMS/ImageNavigatorII
diff -u -r1.2 -r1.3
--- Tiler.java 28 Jul 2010 17:43:23 -0000 1.2
+++ Tiler.java 28 Jul 2010 22:22:34 -0000 1.3
@@ -4,91 +4,102 @@
import java.awt.geom.AffineTransform;
import java.awt.image.*;
import java.io.*;
-
import javax.imageio.ImageIO;
import java.util.*;
+/*
+ * After running Stitcher.java, this program takes the resulting image files and slices them
+ * into the appropriate 256 px square tiles needed for the Google API, and makes the tiles for
+ * different zoom levels.
+ *
+ * File Structure:
+ * >Image Set Folder
+ * >gmapviewer.htm [the website navigator file!]
+ * >original_images [place the autorun.txt file and images in this folder before running Stitcher.java]
+ * >resources [do not touch these files, they are used by the Google API for the navigator]
+ * >stitched_images [stitched images will be saved here by Stitcher.java]
+ * >tiles [when you run this program, the tiles for the navigator will be placed here.]
+ *
+ * @author Chris Wilen
+ */
+
public class Tiler {
public static void main(String[] args) throws IOException {
Date startDate = new Date();
- //try {
- String path = "/Users/chriswilen/Documents/Work/Summer_2010/IZipG18M_TB_75x3/tiles/gmapviewer/";
- int numXimgs = 7;
- int numYimgs = 10;
- int tileSize = 256;
-
- //get info on imgs
- BufferedImage img = ImageIO.read(new File(path+"/dropbox/stitched_tiles/"+"/tile0_0.png"));
- int imgW = img.getWidth();
- int imgH = img.getHeight();
-
- //find max zoom level
- double totalSize = 10000;
- int maxZoom = 0;
- while (totalSize > tileSize) {
- maxZoom++;
- totalSize = Math.max(imgW*numXimgs, imgH*numYimgs)/Math.pow(2, maxZoom);
- }
-
- //create .txt file for google maps api
- double scale = 283;//3.37085208/640;
- String scaleunit = "mm";
- try {
- FileWriter fstream = new FileWriter(path+"/tiles/detectorTiles/detectorTiles.txt");
- BufferedWriter outFile = new BufferedWriter(fstream);
- String outText = "name\tdetectorTiles"+
- "\r\nwidth\t"+(numXimgs*imgW)+
- "\r\nheight\t"+(numYimgs*imgH)+
- "\r\nmaxzoom\t"+maxZoom+
- "\r\ntilesize\t"+tileSize+
- "\r\nscale\t"+(int)scale+
- "\r\nscaleunit\t"+scaleunit+
- "\r\nformat\t"+"png";
- outFile.write(outText);
- outFile.close();
- System.out.println("Google API file created.");
- } catch (Exception e) { System.out.println("out file could not be created: " + e); }
-
- //loop through all zoom levels
- for (int zoom=0; zoom<=maxZoom; zoom++) {
- double totalW = imgW*numXimgs/Math.pow(2, maxZoom-zoom);
- double totalH = imgH*numYimgs/Math.pow(2, maxZoom-zoom);
- int numXtiles = (int)Math.ceil(totalW/tileSize);
- int numYtiles = (int)Math.ceil(totalH/tileSize);
- System.out.println(" ("+totalW+","+numXtiles+") ("+totalH+","+numYtiles+") ");
- //loop through all the tiles for specified zoom level
- for (int row=0; row<numYtiles; row++) {
- for (int col=0; col<numXtiles; col++) {
- BufferedImage toStore = new BufferedImage(tileSize,tileSize,img.getType());
- 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++) {
- for (int xImg=0; xImg<numXimgs; xImg++) {
- //does the img belong in the tile?
- double scaleFactor = 1/Math.pow(2, maxZoom-zoom);
- 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 {
- img = ImageIO.read(new File(path+"/dropbox/stitched_tiles/tile"+yImg+"_"+xImg+".png"));
- } catch (Exception e) {
- img = new BufferedImage(img.getWidth(),img.getHeight(),img.getType());
- }
- AffineTransform at = AffineTransform.getTranslateInstance(0, 0);
- at.setTransform(scaleFactor, 0, 0, scaleFactor, xpos, ypos);
- g2.drawRenderedImage(img, at);
- System.out.print("{"+(xpos+imgW*scaleFactor)+","+(ypos+imgH*scaleFactor)+"}");
- }
- }
+ String path = "/Users/chriswilen/Documents/Work/Summer_2010/IZipG18M_TB_75x3/tiles/gmapviewer/";
+ int numXimgs = 7;
+ int numYimgs = 10;
+ 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();
+
+ //find max zoom level
+ double totalSize = 10000;
+ int maxZoom = 0;
+ while (totalSize > tileSize) {
+ maxZoom++;
+ totalSize = Math.max(imgW*numXimgs, imgH*numYimgs)/Math.pow(2, maxZoom);
+ }
+
+ //create .txt file for google maps api
+ double scale = 283;//3.37085208/640;
+ String scaleunit = "mm";
+ try {
+ FileWriter fstream = new FileWriter(path+"/tiles/detectorTiles.txt");
+ BufferedWriter outFile = new BufferedWriter(fstream);
+ String outText = "name\tdetectorTiles"+
+ "\r\nwidth\t"+(numXimgs*imgW)+
+ "\r\nheight\t"+(numYimgs*imgH)+
+ "\r\nmaxzoom\t"+maxZoom+
+ "\r\ntilesize\t"+tileSize+
+ "\r\nscale\t"+(int)scale+
+ "\r\nscaleunit\t"+scaleunit+
+ "\r\nformat\t"+"png";
+ outFile.write(outText);
+ outFile.close();
+ System.out.println("Google API file created.");
+ } catch (Exception e) { System.out.println("out file could not be created: " + e); }
+
+ //loop through all zoom levels
+ for (int zoom=0; zoom<=maxZoom; zoom++) {
+ double totalW = imgW*numXimgs/Math.pow(2, maxZoom-zoom);
+ double totalH = imgH*numYimgs/Math.pow(2, maxZoom-zoom);
+ int numXtiles = (int)Math.ceil(totalW/tileSize);
+ int numYtiles = (int)Math.ceil(totalH/tileSize);
+ //loop through all the tiles for specified zoom level
+ for (int row=0; row<numYtiles; row++) {
+ for (int col=0; col<numXtiles; col++) {
+ BufferedImage toStore = new BufferedImage(tileSize,tileSize,img.getType());
+ 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++) {
+ for (int xImg=0; xImg<numXimgs; xImg++) {
+ //does the img belong in the tile?
+ double scaleFactor = 1/Math.pow(2, maxZoom-zoom);
+ 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 {
+ img = ImageIO.read(new File(path+"/stitched_images/"+yImg+"_"+xImg+".png"));
+ } catch (Exception e) {
+ img = new BufferedImage(img.getWidth(),img.getHeight(),img.getType());
+ }
+ AffineTransform at = AffineTransform.getTranslateInstance(0, 0);
+ at.setTransform(scaleFactor, 0, 0, scaleFactor, xpos, ypos);
+ g2.drawRenderedImage(img, at);
+ }
}
- ImageIO.write(toStore, "PNG", new File(path+"/tiles/detectorTiles/"+zoom+"_"+col+"_"+row+".png"));
- System.out.println(zoom+"_"+col+"_"+row);
}
+ ImageIO.write(toStore, "PNG", new File(path+"/tiles/"+zoom+"_"+col+"_"+row+".png"));
+ System.out.println(zoom+"_"+col+"_"+row);
}
- }
-
-
- //}
+ }
+ }
+
+
System.out.print((char)7);
Date endDate = new Date();
System.out.println("\nRuntime: "+(endDate.getTime()-startDate.getTime())/1000/60);