Search in sources :

Example 6 with Appearance

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

the class ItemTriangleMesh method setTransparency.

@Override
public void setTransparency(final float transparency) {
    // We want to use a different transparency from the ij3d default which is FASTEST
    // so override this method.
    final Appearance appearance = getAppearance();
    final TransparencyAttributes ta = appearance.getTransparencyAttributes();
    if (transparency <= .01f) {
        this.transparency = 0.0f;
        ta.setTransparencyMode(TransparencyAttributes.NONE);
    } else {
        this.transparency = transparency;
        ta.setTransparencyMode(transparencyMode);
    }
    ta.setTransparency(this.transparency);
}
Also used : TransparencyAttributes(org.scijava.java3d.TransparencyAttributes) Appearance(org.scijava.java3d.Appearance)

Example 7 with Appearance

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

the class ItemGeometryGroup method createDefaultAppearance.

/**
 * Create a default Appearance object. This will have the correct attributes and capability bits
 * set to manipulate the material and transparency.
 *
 * @param appearance the appearance
 * @param ga the geometry array
 * @return the appearance
 */
private static Appearance createDefaultAppearance(Appearance appearance, GeometryArray ga) {
    if (appearance == null) {
        appearance = new Appearance();
    }
    appearance.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
    appearance.setCapability(Appearance.ALLOW_MATERIAL_READ);
    if (ga instanceof PointArray) {
        appearance.setPolygonAttributes(null);
        appearance.setMaterial(null);
        PointAttributes pointAttributes = appearance.getPointAttributes();
        if (pointAttributes == null) {
            pointAttributes = new PointAttributes();
            pointAttributes.setPointAntialiasingEnable(true);
            appearance.setPointAttributes(pointAttributes);
        }
        pointAttributes.setCapability(PointAttributes.ALLOW_ANTIALIASING_WRITE);
        pointAttributes.setCapability(PointAttributes.ALLOW_SIZE_WRITE);
        // We use the coordinates for the colour
        ga.setCapability(GeometryArray.ALLOW_COLOR_WRITE);
    } else {
        appearance.setPointAttributes(null);
        // These are the defaults. We may need them if we want to support mesh
        // display when the polygon mode is Line
        PolygonAttributes polygonAttributes = appearance.getPolygonAttributes();
        if (polygonAttributes == null) {
            polygonAttributes = new PolygonAttributes();
            appearance.setPolygonAttributes(polygonAttributes);
        }
        polygonAttributes.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
        polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL);
        // We require material attributes for colour
        Material material = appearance.getMaterial();
        if (material == null) {
            material = new Material();
            material.setDiffuseColor(DEFAULT_COLOUR);
            appearance.setMaterial(material);
        }
        material.setCapability(Material.ALLOW_COMPONENT_WRITE);
    }
    // We require transparency attributes for global transparency
    TransparencyAttributes tr = appearance.getTransparencyAttributes();
    if (tr == null) {
        tr = new TransparencyAttributes();
        tr.setTransparencyMode(TransparencyAttributes.NONE);
        tr.setTransparency(0f);
        appearance.setTransparencyAttributes(tr);
    }
    tr.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
    tr.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    return appearance;
}
Also used : PointAttributes(org.scijava.java3d.PointAttributes) Material(org.scijava.java3d.Material) TransparencyAttributes(org.scijava.java3d.TransparencyAttributes) Appearance(org.scijava.java3d.Appearance) PointArray(org.scijava.java3d.PointArray) PolygonAttributes(org.scijava.java3d.PolygonAttributes)

Example 8 with Appearance

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

the class ImageJ3DResultsViewer method createItemMesh.

private static ItemMesh createItemMesh(final ImageJ3DResultsViewerSettingsOrBuilder settings, LocalList<Point3f> points, final Point3f[] sphereSize, float transparency, float[] alpha) {
    final Rendering rendering = Rendering.forNumber(settings.getRendering());
    final int colorDepth = (alpha != null) ? 4 : 3;
    final Shape3D shape = Shape3DHelper.createShape(rendering, colorDepth);
    final GeometryArray ga = (GeometryArray) shape.getGeometry();
    final Appearance appearance = shape.getAppearance();
    // Estimate the largest array required for the data.
    // The mesh is created by reference using an array for coords, normals and colors.
    final int singlePointVertexSize = ga.getValidVertexCount();
    int singlePointIndexSize = 0;
    final int stride = Math.max(3, colorDepth);
    if (ga instanceof IndexedGeometryArray) {
        // Indexed arrays may have much larger index array than the vertex array
        singlePointIndexSize = ((IndexedGeometryArray) ga).getIndexCount();
    }
    final int singlePointSize = Math.max(singlePointIndexSize, stride * singlePointVertexSize);
    final long arraySize = (long) points.size() * singlePointSize;
    if (arraySize > CustomContentHelper.MAX_ARRAY_SIZE) {
        final double capacity = (double) arraySize / CustomContentHelper.MAX_ARRAY_SIZE;
        // @formatter:off
        IJ.error(TITLE, TextUtils.wrap(String.format("The results will generate data of %d values. " + "This is amount of data is not supported (%.2fx capacity). " + "Please choose a different dataset with fewer points or " + "different rendering model.", arraySize, capacity), 80));
        // @formatter:on
        return null;
    }
    // Support drawing as points ...
    if (settings.getRendering() == 0) {
        final ItemMesh mesh = new ReferenceItemMesh(points.toArray(new Point3f[0]), ga, appearance, null, null, transparency);
        if (alpha != null) {
            mesh.setItemAlpha(alpha);
        }
        mesh.getAppearance().getPointAttributes().setPointSize(sphereSize[0].x);
        return mesh;
    }
    final int triangles = Shape3DHelper.getNumberOfTriangles(rendering);
    final long size = (long) points.size() * triangles;
    if (size > 10000000L) {
        final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE);
        egd.addMessage("The results will generate a large mesh of " + size + " triangles.\nThis may take a long time to render and may run out of memory.");
        egd.setOKLabel("Continue");
        egd.showDialog();
        if (egd.wasCanceled()) {
            return null;
        }
    }
    IJ.showStatus("Creating 3D mesh ...");
    final ItemMesh mesh = new ReferenceItemMesh(points.toArray(new Point3f[0]), ga, appearance, sphereSize, null, transparency);
    if (alpha != null) {
        mesh.setItemAlpha(alpha);
    }
    return mesh;
}
Also used : Point3f(org.scijava.vecmath.Point3f) Rendering(uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering) ReferenceItemMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ReferenceItemMesh) ItemMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemMesh) IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) ReferenceItemMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ReferenceItemMesh) IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray) Shape3D(org.scijava.java3d.Shape3D) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) Appearance(org.scijava.java3d.Appearance)

Example 9 with Appearance

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

the class ImageJ3DResultsViewer method updateAppearance.

private static void updateAppearance(CustomMesh mesh, final ImageJ3DResultsViewerSettingsOrBuilder settings) {
    mesh.setShaded(settings.getShaded());
    final Appearance appearance = mesh.getAppearance();
    final PolygonAttributes pa = appearance.getPolygonAttributes();
    // For all 3D polygons we want to support a true face orientation so transparency works
    final Rendering r = Rendering.forNumber(settings.getRendering());
    if (r.is2D()) {
        pa.setCullFace(PolygonAttributes.CULL_NONE);
        pa.setBackFaceNormalFlip(true);
    } else {
        pa.setCullFace(PolygonAttributes.CULL_BACK);
        pa.setBackFaceNormalFlip(false);
    }
    // TransparencyAttributes ta = appearance.getTransparencyAttributes();
    // ta.setSrcBlendFunction(TransparencyAttributes.BLEND_SRC_ALPHA);
    // ta.setDstBlendFunction(TransparencyAttributes.BLEND_ONE);
    // ta.setDstBlendFunction(TransparencyAttributes.BLEND_ONE_MINUS_SRC_ALPHA); // Default
    ItemTriangleMesh.setTransparencyMode(TransparencyAttributes.FASTEST);
    // ItemTriangleMesh.setTransparencyMode(TransparencyAttributes.SCREEN_DOOR);
    // ItemTriangleMesh.setTransparencyMode(TransparencyAttributes.BLENDED);
    final ColoringAttributes ca = appearance.getColoringAttributes();
    if (r.isHighResolution() || r.is2D()) {
        // Smooth across vertices. Required to show 2D surfaces smoothly
        ca.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
    } else {
        // Faster polygon rendering with flat shading
        ca.setShadeModel(ColoringAttributes.SHADE_FLAT);
    }
}
Also used : Rendering(uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering) ColoringAttributes(org.scijava.java3d.ColoringAttributes) Appearance(org.scijava.java3d.Appearance) PolygonAttributes(org.scijava.java3d.PolygonAttributes)

Example 10 with Appearance

use of org.scijava.java3d.Appearance 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

Appearance (org.scijava.java3d.Appearance)11 TransparencyAttributes (org.scijava.java3d.TransparencyAttributes)7 PointAttributes (org.scijava.java3d.PointAttributes)4 PolygonAttributes (org.scijava.java3d.PolygonAttributes)4 Shape3D (org.scijava.java3d.Shape3D)4 Rendering (uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering)4 ColoringAttributes (org.scijava.java3d.ColoringAttributes)3 GeometryArray (org.scijava.java3d.GeometryArray)3 Material (org.scijava.java3d.Material)3 Point3f (org.scijava.vecmath.Point3f)3 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)3 IndexedGeometryArray (org.scijava.java3d.IndexedGeometryArray)2 PointArray (org.scijava.java3d.PointArray)2 ItemGeometryGroup (uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemGeometryGroup)2 ItemMesh (uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemMesh)2 ReferenceItemMesh (uk.ac.sussex.gdsc.smlm.ij.ij3d.ReferenceItemMesh)2 CustomMesh (customnode.CustomMesh)1 ContentInstant (ij3d.ContentInstant)1 Image3DUniverse (ij3d.Image3DUniverse)1 ImageWindow3D (ij3d.ImageWindow3D)1