Search in sources :

Example 46 with GeometryArray

use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.

the class ItemGeometryGroup method createSphere.

/**
 * Creates the geometry for a sphere using the given number of divisions.
 *
 * @param divisions the divisions
 * @return the geometry array
 */
public static GeometryArray createSphere(int divisions) {
    final int flags = Primitive.GENERATE_NORMALS | Primitive.ENABLE_APPEARANCE_MODIFY | Primitive.ENABLE_GEOMETRY_PICKING;
    final Sphere sphere = new Sphere(1, flags, divisions, null);
    return (GeometryArray) sphere.getShape(0).getGeometry();
}
Also used : Sphere(org.scijava.java3d.utils.geometry.Sphere) GeometryArray(org.scijava.java3d.GeometryArray)

Example 47 with GeometryArray

use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.

the class ItemPointMesh method setItemColor.

@Override
public void setItemColor(Color3f[] color) {
    this.color = null;
    if (color.length != size()) {
        throw new IllegalArgumentException("list of size " + size() + " expected");
    }
    final GeometryArray ga = (GeometryArray) getGeometry();
    if (ga == null) {
        return;
    }
    ga.setColors(0, color);
    changed = true;
}
Also used : GeometryArray(org.scijava.java3d.GeometryArray)

Example 48 with GeometryArray

use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.

the class ItemPointMesh method reorderFast.

@Override
public void reorderFast(int[] indices) {
    changed = true;
    final int oldSize = size();
    final int size = (indices == null) ? 0 : Math.min(oldSize, indices.length);
    if (size == 0 || indices == null) {
        mesh.clear();
        this.setGeometry(null);
        return;
    }
    // From here on we assume the current geometry will not be null
    // as this only happens when the original size is zero. Size has
    // been checked at this point to be the smaller of new and old.
    final GeometryArray ga = (GeometryArray) getGeometry();
    // Reorder all things in the geometry: coordinates and colour
    final Point3f[] oldCoords = mesh.toArray(new Point3f[oldSize]);
    final float[] oldColors = new float[oldSize * 3];
    ga.getColors(0, oldColors);
    final Point3f[] coords = new Point3f[size];
    final float[] colors = new float[size * 3];
    for (int i = 0; i < size; i++) {
        final int j = indices[i];
        coords[i] = oldCoords[j];
        System.arraycopy(oldColors, j * 3, colors, i * 3, 3);
    }
    mesh = Arrays.asList(coords);
    ga.updateData(new GeometryUpdater() {

        @Override
        public void updateData(Geometry geometry) {
            final GeometryArray ga = (GeometryArray) geometry;
            // We re-use the geometry and just truncate the vertex count
            ga.setCoordinates(0, coords);
            ga.setColors(0, colors);
            ga.setValidVertexCount(coords.length);
        }
    });
// this.setGeometry(ga);
}
Also used : GeometryUpdater(org.scijava.java3d.GeometryUpdater) Geometry(org.scijava.java3d.Geometry) Point3f(org.scijava.vecmath.Point3f) GeometryArray(org.scijava.java3d.GeometryArray)

Example 49 with GeometryArray

use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.

the class ItemTriangleMesh method setItemColor.

@Override
public void setItemColor(Color3f[] color) {
    this.color = null;
    final int size = size();
    if (color.length != size) {
        throw new IllegalArgumentException("list of size " + size + " expected");
    }
    final GeometryArray ga = (GeometryArray) getGeometry();
    if (ga == null) {
        return;
    }
    final int objectSize = objectVertices.length;
    final int N = objectSize * size;
    final Color3f[] colors = new Color3f[N];
    int index = 0;
    for (final Color3f c : color) {
        for (int j = objectSize; j-- > 0; ) {
            colors[index++] = c;
        }
    }
    ga.setColors(0, colors);
    changed = true;
}
Also used : Color3f(org.scijava.vecmath.Color3f) GeometryArray(org.scijava.java3d.GeometryArray)

Example 50 with GeometryArray

use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.

the class ImageJ3DResultsViewer method createImage3DUniverse.

/**
 * Creates the image 3D universe with a unique name.
 *
 * @param title the title
 * @param titleList the title list (of titles to ignore)
 * @return the image 3D universe
 */
private Image3DUniverse createImage3DUniverse(String title, List<String> titleList) {
    // Get a unique name by appending numbers to the end
    String title2 = title;
    int counter = 2;
    while (titleList.contains(title2)) {
        title2 = title + " " + (counter++);
    }
    final Image3DUniverse universe = new Image3DUniverse();
    universe.addUniverseListener(new LocalUniverseListener());
    universe.setShowBoundingBoxUponSelection(false);
    universe.showAttribute(DefaultUniverse.ATTRIBUTE_SCALEBAR, false);
    // Capture a canvas mouse click/region and identify the coordinates.
    final ImageCanvas3D canvas = (ImageCanvas3D) universe.getCanvas();
    final BranchGroup scene = universe.getScene();
    final MouseListener mouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(final MouseEvent event) {
            if (!consumeEvent(event)) {
                return;
            }
            // Consume the event
            event.consume();
            // This finds the vertex indices of the rendered object.
            final Pair<Content, IntersectionInfo> pair = getPickedContent(canvas, scene, event.getX(), event.getY());
            if (pair == null) {
                // Do the same as the mouseClicked in Image3DUniverse
                universe.select(null);
                return;
            }
            // Only process content added from localisations
            final Content c = pair.getKey();
            if (!(c.getUserData() instanceof ResultsMetaData)) {
                // Do the same as the mouseClicked in Image3DUniverse
                universe.select(c);
                return;
            }
            final ResultsMetaData data = (ResultsMetaData) c.getUserData();
            final MemoryPeakResults results = data.results;
            // Look up the localisation from the clicked vertex
            final ContentInstant content = c.getCurrent();
            int index = -1;
            if (content.getContent() instanceof CustomMeshNode) {
                final CustomMeshNode node = (CustomMeshNode) content.getContent();
                final CustomMesh mesh = node.getMesh();
                int vertexCount;
                final GeometryArray ga = (GeometryArray) mesh.getGeometry();
                // Default to the number of vertices
                vertexCount = ga.getValidVertexCount();
                final int countPerLocalisation = vertexCount / results.size();
                // Determine the localisation
                final int vertexIndex = pair.getValue().getVertexIndices()[0];
                index = vertexIndex / countPerLocalisation;
            } else if (content.getContent() instanceof ItemGroupNode) {
                // All shapes have the index as the user data
                final Object o = pair.getValue().getGeometry().getUserData();
                if (o instanceof Integer) {
                    index = (Integer) pair.getValue().getGeometry().getUserData();
                }
            }
            if (index == -1) {
                return;
            }
            final PeakResult result = results.get(index);
            if (event.getClickCount() > 1) {
                // Centre on the localisation
                final Point3d coordinate = new Point3d();
                coordinate.set(data.points.get(index));
                // Handle the local transform of the content ...
                final Transform3D vWorldToLocal = getVworldToLocal(content);
                vWorldToLocal.transform(coordinate);
                universe.centerAt(coordinate);
            } else if (event.isShiftDown()) {
                // Ctrl+Shift held down to remove selected
                data.removeFromSelectionModel(result);
            } else {
                // Ctrl held down to set selection
                data.addToSelectionModel(result);
            }
        }

        private boolean consumeEvent(final MouseEvent event) {
            if (event.isConsumed() || event.getButton() != MouseEvent.BUTTON1 || !(event.isControlDown())) {
                return false;
            }
            if (event.getClickCount() == 1) {
                return true;
            }
            return (event.getClickCount() == 2);
        }
    };
    // 0 = ImageCanvas3D
    // 1 = DefaultUniverse
    // 2 = Image3DUniverse
    final MouseListener[] l = canvas.getMouseListeners();
    for (int i = 0; i < l.length; i++) {
        if (l[i].getClass().getName().contains("Image3DUniverse")) {
            // We want to be before the Image3DUniverse to allow consuming the click event.
            // Only allow the click event.
            // This disables the right-click pop-up menu.
            // It doesn't have anything of use for localisations anyway.
            canvas.removeMouseListener(l[i]);
            canvas.addMouseListener(mouseListener);
            canvas.addMouseListener(new MouseListenerWrapper(l[i], MouseListenerWrapper.MOUSE_CLICKED));
        }
    }
    // 0 = ImageCanvas3D
    // 1 = DefaultUniverse
    // 2 = Image3DUniverse
    // 3 = EventCatcher (from scijava)
    final MouseMotionListener[] ml = canvas.getMouseMotionListeners();
    for (int i = 0; i < ml.length; i++) {
        if (ml[i].getClass().getName().contains("Image3DUniverse")) {
            // Ignore this as it just shows the name in the IJ status bar
            canvas.removeMouseMotionListener(ml[i]);
        }
    }
    // Finally display the window
    universe.show();
    final ImageWindow3D window = universe.getWindow();
    GUI.center(window);
    window.setTitle(title2);
    WindowManager.addWindow(window);
    window.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent event) {
            WindowManager.removeWindow(window);
        }
    });
    // Add a new menu for SMLM functionality
    createSmlmMenuBar(universe);
    return universe;
}
Also used : CustomMeshNode(customnode.CustomMeshNode) Transform3D(org.scijava.java3d.Transform3D) ItemGroupNode(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemGroupNode) IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray) WindowAdapter(java.awt.event.WindowAdapter) MouseMotionListener(java.awt.event.MouseMotionListener) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) MouseListener(java.awt.event.MouseListener) Point3d(org.scijava.vecmath.Point3d) CustomMesh(customnode.CustomMesh) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) IntersectionInfo(org.scijava.java3d.PickInfo.IntersectionInfo) MouseEvent(java.awt.event.MouseEvent) Image3DUniverse(ij3d.Image3DUniverse) ImageCanvas3D(ij3d.ImageCanvas3D) BranchGroup(org.scijava.java3d.BranchGroup) MouseAdapter(java.awt.event.MouseAdapter) ContentInstant(ij3d.ContentInstant) CustomContentInstant(uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContentInstant) ImageWindow3D(ij3d.ImageWindow3D) Content(ij3d.Content) CustomContent(uk.ac.sussex.gdsc.smlm.ij.ij3d.CustomContent) WindowEvent(java.awt.event.WindowEvent) NamedObject(uk.ac.sussex.gdsc.smlm.data.NamedObject)

Aggregations

GeometryArray (org.scijava.java3d.GeometryArray)52 IndexedGeometryArray (org.scijava.java3d.IndexedGeometryArray)21 Point3f (org.scijava.vecmath.Point3f)11 TriangleArray (org.scijava.java3d.TriangleArray)6 GeometryInfo (org.scijava.java3d.utils.geometry.GeometryInfo)6 NormalGenerator (org.scijava.java3d.utils.geometry.NormalGenerator)5 Color3f (org.scijava.vecmath.Color3f)5 Shape3D (org.scijava.java3d.Shape3D)4 Vector3f (org.scijava.vecmath.Vector3f)4 Appearance (org.scijava.java3d.Appearance)3 IndexedGeometryStripArray (org.scijava.java3d.IndexedGeometryStripArray)3 PointArray (org.scijava.java3d.PointArray)3 Color4f (org.scijava.vecmath.Color4f)3 Rendering (uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering)3 CustomMesh (customnode.CustomMesh)2 Geometry (org.scijava.java3d.Geometry)2 GeometryStripArray (org.scijava.java3d.GeometryStripArray)2 GeometryUpdater (org.scijava.java3d.GeometryUpdater)2 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)2 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)2