/** * Loads into a double[][] a plain text file of numbers, with newlines dividing the numbers into * rows and tabs or spaces delimiting columns. The Y dimension is not flipped. */ public static double[][] loadTextFile(InputStream stream) throws IOException { Scanner scan = new Scanner(stream); ArrayList rows = new ArrayList(); int width = -1; while (scan.hasNextLine()) { String srow = scan.nextLine().trim(); if (srow.length() > 0) { int w = 0; if (width == -1) // first time compute width { ArrayList firstRow = new ArrayList(); Scanner rowScan = new Scanner(new StringReader(srow)); while (rowScan.hasNextDouble()) { firstRow.add(new Double(rowScan.nextDouble())); // ugh, boxed w++; } width = w; double[] row = new double[width]; for (int i = 0; i < width; i++) row[i] = ((Double) (firstRow.get(i))).doubleValue(); rows.add(row); } else { double[] row = new double[width]; Scanner rowScan = new Scanner(new StringReader(srow)); while (rowScan.hasNextDouble()) { if (w == width) // uh oh throw new IOException("Row lengths do not match in text file"); row[w] = rowScan.nextDouble(); w++; } if (w < width) // uh oh throw new IOException("Row lengths do not match in text file"); rows.add(row); } } } if (width == -1) // got nothing return new double[0][0]; double[][] fieldTransposed = new double[rows.size()][]; for (int i = 0; i < rows.size(); i++) fieldTransposed[i] = ((double[]) (rows.get(i))); // now transpose because we have width first double[][] field = new double[width][fieldTransposed.length]; for (int i = 0; i < field.length; i++) for (int j = 0; j < field[i].length; j++) field[i][j] = fieldTransposed[j][i]; return field; }
public void loadView(String filename) { Point3 point; Vector3 tvec; double radius; double azimuth; double elevation; double scale; double x, y, z; double vx, vy, vz; try { if (_ipg == null) throw new Exception("Must load a cube first!"); Scanner s = new Scanner(new File(filename)); radius = s.nextDouble(); x = s.nextDouble(); y = s.nextDouble(); z = s.nextDouble(); point = new Point3(x, y, z); azimuth = s.nextDouble(); elevation = s.nextDouble(); scale = s.nextDouble(); vx = s.nextDouble(); vy = s.nextDouble(); vz = s.nextDouble(); tvec = new Vector3(vx, vy, vz); Iterator<ImagePanel> itr = _ipg.getImagePanels(); while (itr.hasNext()) { ImagePanel ip = itr.next(); AxisAlignedFrame aaf = ip.getFrame(); double lx = s.nextDouble(); double ly = s.nextDouble(); double lz = s.nextDouble(); double mx = s.nextDouble(); double my = s.nextDouble(); double mz = s.nextDouble(); Point3 min = new Point3(lx, ly, lz); Point3 max = new Point3(mx, my, mz); aaf.setCorners(min, max); } _pmax = s.nextFloat(); int code = s.nextInt(); _color = ColorList.getMatch(code); setColorMap(); _view.setWorldSphere(new BoundingSphere(point, radius)); _view.setTranslate(tvec); _view.setAzimuth(azimuth); _view.setElevation(elevation); _view.setScale(scale); _ipg.setPercentiles(_pmin, _pmax); } catch (Exception e) { System.out.println("Failed to load view point!"); System.out.println(e); } }