CDMS/src/CDMS/ImageNavigatorII
diff -N Tiler.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Tiler.java 28 Jul 2010 17:41:37 -0000 1.1
@@ -0,0 +1,94 @@
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.image.*;
+import java.io.*;
+
+import javax.imageio.ImageIO;
+import java.util.*;
+
+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)+"}");
+ }
+ }
+ }
+ ImageIO.write(toStore, "PNG", new File(path+"/tiles/detectorTiles/"+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);
+}
+}