public void addLayer(VisLayer layer, double fviewport[]) { FPosition fpos = new FPosition(); fpos.layer = layer; fpos.fviewport = LinAlg.copy(fviewport); fposes.add(fpos); vc.draw(); }
public ArrayList<VisLayerLayoutManager.Position> layout(int viewport[]) { ArrayList<VisLayerLayoutManager.Position> poses = new ArrayList<VisLayerLayoutManager.Position>(); for (FPosition fpos : fposes) { VisLayerLayoutManager.Position pos = new VisLayerLayoutManager.Position(); pos.layer = fpos.layer; pos.viewport = new int[] { (int) (viewport[2] * fpos.fviewport[0]), (int) (viewport[3] * fpos.fviewport[1]), (int) (viewport[2] * fpos.fviewport[2]), (int) (viewport[3] * fpos.fviewport[3]) }; poses.add(pos); } return poses; }
// equivalent to s.split("\ +") static final String[] fastSplit(String s) { ArrayList<String> toks = new ArrayList<String>(); StringBuilder sb = null; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == ' ') { // || c=='\n' || c=='\r' || c=='\t') { if (sb != null) { toks.add(sb.toString()); sb = null; } } else { if (sb == null) sb = new StringBuilder(); sb.append(c); } } if (sb != null) toks.add(sb.toString()); return toks.toArray(new String[toks.size()]); }
public BoxShape(double sxyz[]) { this.sxyz = LinAlg.copy(sxyz); planes = new ArrayList<double[]>(); vertices = new ArrayList<double[]>(); // create planes and vertices planes.add(new double[] {-1, 0, 0, -sxyz[0] / 2}); planes.add(new double[] {1, 0, 0, -sxyz[0] / 2}); planes.add(new double[] {0, -1, 0, -sxyz[1] / 2}); planes.add(new double[] {0, 1, 0, -sxyz[1] / 2}); planes.add(new double[] {0, 0, -1, -sxyz[2] / 2}); planes.add(new double[] {0, 0, 1, -sxyz[2] / 2}); for (int i = -1; i < 2; i += 2) for (int j = -1; j < 2; j += 2) for (int k = -1; k < 2; k += 2) vertices.add(new double[] {i * sxyz[0] / 2, j * sxyz[1] / 2, k * sxyz[2] / 2}); }
/** Call with one or more OFF model paths * */ public static void main(String args[]) { JFrame f = new JFrame("VzOFF " + args[0]); f.setLayout(new BorderLayout()); VisWorld vw = new VisWorld(); VisLayer vl = new VisLayer(vw); VisCanvas vc = new VisCanvas(vl); VzMesh.Style defaultMeshStyle = new VzMesh.Style(Color.cyan); ArrayList<VzOFF> models = new ArrayList<VzOFF>(); for (int i = 0; i < args.length; i++) { if (args[i].endsWith(".off")) { try { models.add(new VzOFF(args[i], defaultMeshStyle)); System.out.printf("Loaded: %20s (%5.2f%%)\n", args[i], i * 100.0 / args.length); } catch (IOException ex) { System.out.println("ex: " + ex); } } else { System.out.printf("Ignoring file with wrong suffix: " + args[i]); } } if (models.size() == 0) { System.out.println("No models specified\n"); return; } int rows = (int) Math.sqrt(models.size()); int cols = models.size() / rows + 1; // VzGrid.addGrid(vw); VisWorld.Buffer vb = vw.getBuffer("models"); for (int y = 0; y < rows; y++) { for (int x = 0; x < cols; x++) { int idx = y * cols + x; if (idx >= models.size()) break; VzOFF model = models.get(idx); double mx = Math.max( model.xyz_max[2] - model.xyz_min[2], Math.max(model.xyz_max[1] - model.xyz_min[1], model.xyz_max[0] - model.xyz_min[0])); vb.addBack( new VisChain( LinAlg.translate(x + .5, rows - (y + .5), 0), new VzRectangle(1, 1, new VzLines.Style(Color.white, 3)), new VisChain( LinAlg.translate(0, .4, 0), new VzText( VzText.ANCHOR.CENTER, String.format("<<sansserif-20,scale=.003>>%s", baseName(model.path)))), LinAlg.scale(.5, .5, .5), LinAlg.scale(1.0 / mx, 1.0 / mx, 1.0 / mx), LinAlg.translate( -(model.xyz_max[0] + model.xyz_min[0]) / 2.0, -(model.xyz_max[1] + model.xyz_min[1]) / 2.0, -(model.xyz_max[2] + model.xyz_min[2]) / 2.0), model)); } } vb.swap(); vl.cameraManager.fit2D(new double[] {0, 0, 0}, new double[] {cols, rows, 0}, true); ((DefaultCameraManager) vl.cameraManager).interfaceMode = 3.0; f.add(vc); f.setSize(600, 400); f.setVisible(true); }