// stl_scale.java read .stl file scale into new.stl file // only changes vertex x y z // set xoff, yoff, zoff xmin xmax still from old file // set xsca, ysca, zsca // x = (x+xoff)*xsca import java.io.*; import java.util.*; import java.text.*; // solid rect // facet normal 0.0 0.0 -1.0 // outer loop // vertex 1.0 1.0 1.0 // vertex 5.0 4.0 1.0 // vertex 1.0 4.0 1.0 // endloop // endfacet // facet normal 0.0 0.0 -1.0 // outer loop // vertex 1.0 1.0 1.0 // vertex 5.0 1.0 1.0 // vertex 5.0 4.0 1.0 // endloop // endfacet //... // endsolid public class stl_scale { double xoff = 0.0; // set these 6 values !!! double yoff = 0.0; double zoff = 0.0; double xsca = 1.5; double ysca = 1.5; double zsca = 1.0; boolean debug = false; int num_points = 0; double x, y, z; double xmin, xmax, ymin, ymax, zmin, zmax; // new StringTokenizer T; String token; String solid = "solid"; String facet = "facet"; String normal = "normal"; String outer = "outer"; String loop = "loop"; String vertex = "vertex"; String endloop = "endloop"; String endfacet = "endfacet"; String endsolid = "endsolid"; stl_scale(String filein, String fileout) // callable { System.out.println("stl_scale.java reading "+filein+", writing "+fileout); System.out.println("xoff="+xoff+", yoff="+yoff+", zoff="+zoff); System.out.println("xsca="+xsca+", ysca="+ysca+", zsca="+zsca); try { FileReader fin = new FileReader(filein); BufferedReader in = new BufferedReader(fin); BufferedWriter fout = new BufferedWriter(new FileWriter(fileout)); PrintWriter File_out = new PrintWriter(fout); String input_line; String line; int len; while(true) // to endsolid { input_line = in.readLine(); // len = input_line.length(); if(debug) System.out.println("input:"+input_line+" len="+len); T = new StringTokenizer(input_line," "); token = T.nextToken(); // ? if(debug) System.out.println("token:"+token); if(token.equals(endsolid)) { File_out.println(input_line); break; } if(token.equals(solid)) { File_out.println(input_line); continue; } if(token.equals(facet)) { File_out.println(input_line); continue; } if(token.equals(outer)) { File_out.println(input_line); continue; } if(token.equals(solid)) { File_out.println(input_line); continue; } if(token.equals(endloop)) { File_out.println(input_line); continue; } if(token.equals(endfacet)) { File_out.println(input_line); continue; } if(token.equals(vertex)) { token = T.nextToken(); // x if(debug) System.out.println("token:"+token); x = Double.parseDouble(token); token = T.nextToken(); // y if(debug) System.out.println("token:"+token); y = Double.parseDouble(token); token = T.nextToken(); // z if(debug) System.out.println("token:"+token); z = Double.parseDouble(token); x = (x+xoff)*xsca; y = (y+yoff)*ysca; z = (z+zoff)*zsca; num_points++; File_out.println(" vertex "+x+" "+y+" "+z+" "); } } // end while fin.close(); fout.close(); } // end try catch(IOException exception) { System.out.println("datread.java "+exception); } System.out.println("stl_scale.java finished num_points="+num_points); } // end stl_scale public static void main (String[] args) { new stl_scale(args[0],args[1]); // .stl new.stl } } // end class stl_scale