Search in sources :

Example 51 with GeometryArray

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

the class ImageJ3DResultsViewer method createShape.

@SuppressWarnings("unused")
private static Shape3D createShape(Builder settings) {
    final LocalList<Point3f> points = new LocalList<>(1);
    points.push(new Point3f());
    // We try and match the geometry and appearance of the standard mesh.
    // Do this by creating a mesh with a single point and get the Geometry and Appearance.
    GeometryArray ga;
    CustomMesh mesh;
    final float transparency = getTransparency(settings);
    // Support drawing as points ...
    if (settings.getRendering() == 0) {
        mesh = new TransparentItemPointMesh(points, null, transparency);
        ((ItemPointMesh) mesh).setPointSize((float) settings.getPixelSize());
        updateAppearance(mesh, settings);
        // Assume the TransparentItemPointMesh sets COLOR_4
        ga = (GeometryArray) mesh.getGeometry();
    } else {
        final Rendering r = Rendering.forNumber(settings.getRendering());
        final List<Point3f> point = Shape3DHelper.createLocalisationObject(r);
        final Point3f[] vertices = point.toArray(new Point3f[1]);
        // Correct the direction
        ItemTriangleMesh.checkFacets(vertices);
        final double creaseAngle = (r.isHighResolution()) ? 44 : 0;
        mesh = new ItemTriangleMesh(vertices, points.toArray(new Point3f[1]), null, null, transparency, creaseAngle, null);
        updateAppearance(mesh, settings);
        final int nVertices = vertices.length;
        ga = new TriangleArray(nVertices, GeometryArray.COORDINATES | GeometryArray.NORMALS);
        // Copy the coords and normals. We don't require the vertex colours.
        final float[] coords = new float[nVertices * 3];
        final float[] normals = new float[nVertices * 3];
        final GeometryArray gaToCopy = (GeometryArray) mesh.getGeometry();
        gaToCopy.getCoordinates(0, coords);
        gaToCopy.getNormals(0, normals);
        ga.setCoordinates(0, coords);
        ga.setNormals(0, normals);
        ga.setValidVertexCount(nVertices);
    }
    return new Shape3D(ga, mesh.getAppearance());
}
Also used : ItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemPointMesh) TransparentItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemPointMesh) ItemTriangleMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemTriangleMesh) TransparentItemTriangleMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemTriangleMesh) IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray) TriangleArray(org.scijava.java3d.TriangleArray) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) Point3f(org.scijava.vecmath.Point3f) Rendering(uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering) CustomMesh(customnode.CustomMesh) Shape3D(org.scijava.java3d.Shape3D) TransparentItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemPointMesh)

Example 52 with GeometryArray

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

the class ImageJ3DResultsViewer method createItemGroup.

private static ItemGeometryGroup createItemGroup(final ImageJ3DResultsViewerSettings.Builder settings, final Point3f[] sphereSize, final LocalList<Point3f> points, float[] alpha, float transparency, Color3f[] colors) {
    final Rendering rendering = Rendering.forNumber(settings.getRendering());
    // All objects have colour using the appearance not per vertex colours.
    // The exception is points which do not support colour from appearance.
    final int colorDepth = (rendering == Rendering.POINT) ? 4 : 0;
    final Shape3D shape = Shape3DHelper.createShape(rendering, colorDepth);
    // Use max so that points get a value of 1
    final int triangles = Math.max(Shape3DHelper.getNumberOfTriangles(rendering), 1);
    final GeometryArray ga = (GeometryArray) shape.getGeometry();
    final long size = (long) points.size() * triangles;
    if (size > 10000000L) {
        final String name = (rendering == Rendering.POINT) ? "points" : "triangles";
        final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE);
        egd.addMessage("The results will generate a large dataset of " + size + " " + name + ".\nThis may take a long time to render and may run out of memory.");
        egd.setOKLabel("Continue");
        egd.showDialog();
        if (egd.wasCanceled()) {
            return null;
        }
    }
    final Appearance appearance = shape.getAppearance();
    final TransparencyAttributes ta = new TransparencyAttributes();
    ta.setTransparency(transparency);
    ta.setTransparencyMode((transparency == 0) ? TransparencyAttributes.NONE : TransparencyAttributes.FASTEST);
    appearance.setTransparencyAttributes(ta);
    if (rendering == Rendering.POINT) {
        appearance.getPointAttributes().setPointSize(sphereSize[0].x);
    }
    if (settings.getSupportDynamicTransparency()) {
        return new ItemGeometryGroup(points.toArray(new Point3f[0]), ga, appearance, sphereSize, colors, alpha);
    }
    return new OrderedItemGeometryGroup(points.toArray(new Point3f[0]), ga, appearance, sphereSize, colors, alpha);
}
Also used : ItemGeometryGroup(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemGeometryGroup) OrderedItemGeometryGroup(uk.ac.sussex.gdsc.smlm.ij.ij3d.OrderedItemGeometryGroup) Point3f(org.scijava.vecmath.Point3f) Rendering(uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering) OrderedItemGeometryGroup(uk.ac.sussex.gdsc.smlm.ij.ij3d.OrderedItemGeometryGroup) IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray) Shape3D(org.scijava.java3d.Shape3D) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) TransparencyAttributes(org.scijava.java3d.TransparencyAttributes) Appearance(org.scijava.java3d.Appearance)

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