static private Collection<Content> filterMeshes(final Collection contents) { final ArrayList<Content> meshes = new ArrayList<Content>(); for (final Iterator it = contents.iterator(); it.hasNext();) { final Content c = (Content) it.next(); final ContentNode node = c.getContent(); if (node instanceof voltex.VoltexGroup || node instanceof orthoslice.OrthoGroup || node instanceof surfaceplot.SurfacePlotGroup) { continue; } meshes.add(c); } return meshes; }
private static float getVolumePoint(final Content c, final Point3d p) { final Volume v = ((VoltexGroup) c.getContent()).getRenderer().getVolume(); final int ix = (int) Math.round(p.x / v.pw); final int iy = (int) Math.round(p.y / v.ph); final int iz = (int) Math.round(p.z / v.pd); if (ix < 0 || ix >= v.xDim || iy < 0 || iy >= v.yDim || iz < 0 || iz >= v.zDim) return 0; return (v.getAverage(ix, iy, iz) & 0xff); } }
static private final void smooth(final Content c, final int iterations, final Originals originals) { if (null == c) return; final ContentNode cn = c.getContent(); final Set<CustomTriangleMesh> meshes = findMeshes(c); if (meshes.isEmpty()) { IJ.log("Cannot smooth content of class " + cn.getClass()); return; } originals.add(c); // ensure it's there for (final CustomTriangleMesh tm : meshes) { smooth(tm, iterations, originals); } }
static public void writeDXF(final Collection contents, final Writer w) throws IOException { w.write("0\nSECTION\n2\nENTITIES\n"); // header of file for (final Iterator it = contents.iterator(); it.hasNext();) { final Content ob = (Content) it.next(); CustomMesh cmesh = null; if (ob.getContent() instanceof CustomMeshNode) { final CustomMeshNode cmeshnode = (CustomMeshNode) ob.getContent(); cmesh = cmeshnode.getMesh(); } else if (ob.getContent() instanceof MeshGroup) { final MeshGroup mg = (MeshGroup) ob.getContent(); cmesh = mg.getMesh(); } else continue; final List triangles = cmesh.getMesh(); final String title = ob.getName().replaceAll(" ", "_").replaceAll("#", "--"); final Mtl mat = new Mtl(1 - ob.getTransparency(), cmesh.getColor()); writeTrianglesDXF(w, triangles, title, "" + mat.getAsSingle()); } w.append("0\nENDSEC\n0\nEOF\n"); // TRAILER of the file }
public void contentProperties(final Content c) { if (!checkSel(c)) return; final Point3d min = new Point3d(); final Point3d max = new Point3d(); final Point3d center = new Point3d(); c.getContent().getMin(min); c.getContent().getMax(max); c.getContent().getCenter(center); final TextWindow tw = new TextWindow(c.getName(), " \tx\ty\tz", "min\t" + (float) min.x + "\t" + (float) min.y + "\t" + (float) min.z + "\n" + "max\t" + (float) max.x + "\t" + (float) max.y + "\t" + (float) max.z + "\n" + "cog\t" + (float) center.x + "\t" + (float) center.y + "\t" + (float) center.z + "\n\n" + "volume\t" + c.getContent().getVolume(), 512, 512); }
/** * Select the view at the selected Content. */ public void centerSelected(final Content c) { final Point3d center = new Point3d(); c.getContent().getCenter(center); final Transform3D localToVWorld = new Transform3D(); c.getContent().getLocalToVworld(localToVWorld); localToVWorld.transform(center); getViewPlatformTransformer().centerAt(center); }
/** * Make sure that the average center of all contents is visible in the canvas. */ public void addCenterOf(final Iterable<Content> contents) { final Point3d center = new Point3d(); final Point3d tmp = new Point3d(); int counter = 0; for (final Content c : contents) { final Transform3D localToVworld = new Transform3D(); c.getContent().getLocalToVworld(localToVworld); c.getContent().getMin(tmp); center.add(tmp); c.getContent().getMax(tmp); center.add(tmp); counter += 2; } center.x /= counter; center.y /= counter; center.z /= counter; add(center); }
final Content mob = (Content) it.next(); final ContentNode node = mob.getContent();
@Override public void run() { final ImageCanvas3D canvas = (ImageCanvas3D) univ.getCanvas(); ((VoltexGroup) c.getContent()).fillRoi(canvas, canvas.getRoi(), (byte) 0); univ.fireContentChanged(c); record(FILL_SELECTION); } }.start();
public void updateVolume(final Content c) { if (!checkSel(c)) return; if (c.getType() != ContentConstants.VOLUME && c.getType() != ContentConstants.ORTHO) return; if (c.getResamplingFactor() != 1) { IJ.error("Object must be loaded " + "with resamplingfactor 1"); return; } ((VoltexGroup) c.getContent()).update(); }
@Override public void run(ImageProcessor arg0) { Image3DUniverse univ = new Image3DUniverse(512, 512); Content c = univ.addVoltex(image, null, image.getTitle(), 0, new boolean[] {true, true, true}, 1); volume = ((VoltexGroup)c.getContent()).getRenderer().getVolume(); univ.show(); }
public void smoothMesh(final Content c) { if (!checkSel(c)) return; final ContentNode cn = c.getContent(); // Check multi first; it extends CustomMeshNode if (cn instanceof CustomMultiMesh) { final CustomMultiMesh multi = (CustomMultiMesh) cn; for (int i = 0; i < multi.size(); i++) { final CustomMesh m = multi.getMesh(i); if (m instanceof CustomTriangleMesh) MeshEditor.smooth2( (CustomTriangleMesh) m, 1); } } else if (cn instanceof CustomMeshNode) { final CustomMesh mesh = ((CustomMeshNode) cn).getMesh(); if (mesh instanceof CustomTriangleMesh) MeshEditor.smooth2( (CustomTriangleMesh) mesh, 1); // 0.25f); } }
public void decimateMesh() { final Content c = univ.getSelected(); if (c == null) return; CustomTriangleMesh ctm; final ContentNode n = c.getContent(); if (n instanceof CustomMeshNode) { if (((CustomMeshNode) n).getMesh() instanceof CustomTriangleMesh) ctm = (CustomTriangleMesh) ((CustomMeshNode) n).getMesh(); else return; } else if (n instanceof MeshGroup) { ctm = ((MeshGroup) n).getMesh(); } else { return; } new InteractiveMeshDecimation().run(ctm); }
public static void fillSelection() { final Image3DUniverse univ = getUniv(); if (univ != null && univ.getSelected() != null && univ.getSelected().getType() == ContentConstants.VOLUME) { final VoltexGroup vg = (VoltexGroup) univ.getSelected().getContent(); final ImageCanvas3D canvas = (ImageCanvas3D) univ.getCanvas(); vg.fillRoi(canvas, canvas.getRoi(), (byte) 0); } }
/** * Add another Content which should be completely visible in the canvas. */ public void add(final Content c) { final Transform3D localToVworld = new Transform3D(); c.getContent().getLocalToVworld(localToVworld); final Point3d min = new Point3d(); c.getContent().getMin(min); final Point3d max = new Point3d(); c.getContent().getMax(max); final Point3d tmp = new Point3d(); // transform each of the 8 corners to vworld // coordinates and feed it to add(Point3d). add(localToVworld, new Point3d(min.x, min.y, min.z)); add(localToVworld, new Point3d(max.x, min.y, min.z)); add(localToVworld, new Point3d(min.x, max.y, min.z)); add(localToVworld, new Point3d(max.x, max.y, min.z)); add(localToVworld, new Point3d(min.x, min.y, max.z)); add(localToVworld, new Point3d(max.x, min.y, max.z)); add(localToVworld, new Point3d(min.x, max.y, max.z)); add(localToVworld, new Point3d(max.x, max.y, max.z)); }
public static void setSlices(final String x, final String y, final String z) { final Image3DUniverse univ = getUniv(); if (univ != null && univ.getSelected() != null && univ.getSelected().getType() == ContentConstants.ORTHO) { final OrthoGroup vg = (OrthoGroup) univ.getSelected().getContent(); vg.setSlice(AxisConstants.X_AXIS, getInt(x)); vg.setSlice(AxisConstants.Y_AXIS, getInt(y)); vg.setSlice(AxisConstants.Z_AXIS, getInt(z)); } }
c.getContent().getCenter(contentCenter); final Point3f center = new Point3f(contentCenter);
final GenericDialog gd = new GenericDialog("Adjust slices...", univ.getWindow()); final OrthoGroup os = (OrthoGroup) c.getContent(); final int ind1 = os.getSlice(AxisConstants.X_AXIS); final int ind2 = os.getSlice(AxisConstants.Y_AXIS);
c.getContent().getCenter(contentCenter); final Point3f center = new Point3f(contentCenter);
private void changeMultiOrthslices(final Content c) { if (!checkSel(c)) return; final GenericDialog gd = new GenericDialog("Adjust slices...", univ.getWindow()); final MultiOrthoGroup os = (MultiOrthoGroup) c.getContent(); final boolean opaque = os.getTexturesOpaque(); gd.addMessage("Number of slices {x: " + os.getSliceCount(0) + ", y: " + os.getSliceCount(1) + ", z: " + os.getSliceCount(2) + "}"); gd.addStringField("x_slices (e.g. 1, 2-5, 20)", "", 10); gd.addStringField("y_slices (e.g. 1, 2-5, 20)", "", 10); gd.addStringField("z_slices (e.g. 1, 2-5, 20)", "", 10); gd.addCheckbox("Opaque textures", opaque); gd.showDialog(); if (gd.wasCanceled()) return; final int X = AxisConstants.X_AXIS; final int Y = AxisConstants.Y_AXIS; final int Z = AxisConstants.Z_AXIS; final boolean[] xAxis = new boolean[os.getSliceCount(X)]; final boolean[] yAxis = new boolean[os.getSliceCount(Y)]; final boolean[] zAxis = new boolean[os.getSliceCount(Z)]; parseRange(gd.getNextString(), xAxis); parseRange(gd.getNextString(), yAxis); parseRange(gd.getNextString(), zAxis); os.setVisible(X, xAxis); os.setVisible(Y, yAxis); os.setVisible(Z, zAxis); os.setTexturesOpaque(gd.getNextBoolean()); }