Search in sources :

Example 1 with TransparencyAttributes

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

the class ItemMesh 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;
        // a scene then the transparency cannot be adjusted. So set to FASTEST.
        if (ta.isLive()) {
            ta.setTransparencyMode(TransparencyAttributes.NONE);
        } else {
            ta.setTransparencyMode(TransparencyAttributes.FASTEST);
        }
    } else {
        this.transparency = transparency;
        ta.setTransparencyMode(transparencyMode);
    // ta.setTransparencyMode(TransparencyAttributes.BLENDED);
    }
    ta.setTransparency(this.transparency);
}
Also used : TransparencyAttributes(org.scijava.java3d.TransparencyAttributes) Appearance(org.scijava.java3d.Appearance)

Example 2 with TransparencyAttributes

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

the class ItemMesh method createAppearance.

/**
 * Creates the appearance.
 *
 * @param appearance the appearance
 * @param ga the geometry array
 * @return the appearance
 */
protected Appearance createAppearance(Appearance appearance, GeometryArray ga) {
    // Create a suitable appearance for points or 3D shapes.
    if (appearance == null) {
        appearance = new Appearance();
    }
    appearance.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
    appearance.setCapability(Appearance.ALLOW_MATERIAL_READ);
    appearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
    // Ensure we have the ability to colour the object
    if (!hasColor()) {
        isColorByMaterial = !isPointArray;
    }
    if (isPointArray) {
        shaded = false;
        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);
        if (hasColor()) {
            // We use the coordinates for the colour
            appearance.setColoringAttributes(null);
        } else {
            ColoringAttributes ca = appearance.getColoringAttributes();
            if (ca == null) {
                ca = new ColoringAttributes();
                ca.setShadeModel(ColoringAttributes.SHADE_FLAT);
                appearance.setColoringAttributes(ca);
            }
            ca.setCapability(ColoringAttributes.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();
            polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL);
            appearance.setPolygonAttributes(polygonAttributes);
            shaded = true;
        } else {
            shaded = polygonAttributes.getPolygonMode() == PolygonAttributes.POLYGON_FILL;
        }
        polygonAttributes.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
        ColoringAttributes ca = appearance.getColoringAttributes();
        if (ca == null) {
            ca = new ColoringAttributes();
            ca.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
            appearance.setColoringAttributes(ca);
        }
        ca.setCapability(ColoringAttributes.ALLOW_SHADE_MODEL_WRITE);
        Material material = appearance.getMaterial();
        if (material == null) {
            material = new Material();
            material.setAmbientColor(0.1f, 0.1f, 0.1f);
            material.setSpecularColor(0.1f, 0.1f, 0.1f);
            material.setDiffuseColor(DEFAULT_COLOR);
            appearance.setMaterial(material);
        }
        // Ensure per vertex colours replace the diffuse colour
        material.setColorTarget(Material.DIFFUSE);
        if (isColorByMaterial) {
            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) ColoringAttributes(org.scijava.java3d.ColoringAttributes) Material(org.scijava.java3d.Material) TransparencyAttributes(org.scijava.java3d.TransparencyAttributes) Appearance(org.scijava.java3d.Appearance) PolygonAttributes(org.scijava.java3d.PolygonAttributes)

Example 3 with TransparencyAttributes

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

the class ItemTriangleMesh method createAppearance.

@Override
protected Appearance createAppearance() {
    final Appearance appearance = super.createAppearance();
    // Update the transparency to the default mode
    final TransparencyAttributes ta = appearance.getTransparencyAttributes();
    if (ta.getTransparencyMode() != TransparencyAttributes.NONE) {
        ta.setTransparencyMode(transparencyMode);
    }
    return appearance;
}
Also used : TransparencyAttributes(org.scijava.java3d.TransparencyAttributes) Appearance(org.scijava.java3d.Appearance)

Example 4 with TransparencyAttributes

use of org.scijava.java3d.TransparencyAttributes 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 5 with TransparencyAttributes

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

Aggregations

TransparencyAttributes (org.scijava.java3d.TransparencyAttributes)9 Appearance (org.scijava.java3d.Appearance)7 Material (org.scijava.java3d.Material)2 PointAttributes (org.scijava.java3d.PointAttributes)2 PolygonAttributes (org.scijava.java3d.PolygonAttributes)2 Shape3D (org.scijava.java3d.Shape3D)2 Point3f (org.scijava.vecmath.Point3f)2 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)2 ItemGeometryGroup (uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemGeometryGroup)2 Rendering (uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering)2 CustomMesh (customnode.CustomMesh)1 ContentInstant (ij3d.ContentInstant)1 Image3DUniverse (ij3d.Image3DUniverse)1 ImageWindow3D (ij3d.ImageWindow3D)1 ColoringAttributes (org.scijava.java3d.ColoringAttributes)1 GeometryArray (org.scijava.java3d.GeometryArray)1 IndexedGeometryArray (org.scijava.java3d.IndexedGeometryArray)1 PointArray (org.scijava.java3d.PointArray)1 View (org.scijava.java3d.View)1 Sphere (org.scijava.java3d.utils.geometry.Sphere)1