Search in sources :

Example 1 with PointAttributes

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

the class Shape3DHelper method createShape.

/**
 * Creates the shape.
 *
 * @param rendering the rendering
 * @param colorDepth the color depth
 * @return the shape
 */
public static Shape3D createShape(Rendering rendering, int colorDepth) {
    GeometryArray ga;
    final Appearance appearance = new Appearance();
    int vertexFormat = GeometryArray.COORDINATES;
    if (colorDepth == 3) {
        vertexFormat |= GeometryArray.COLOR_3;
    } else if (colorDepth == 4) {
        vertexFormat |= GeometryArray.COLOR_4;
    }
    // Support drawing as points ...
    if (rendering == Rendering.POINT) {
        ga = new PointArray(1, vertexFormat);
        final PointAttributes pa = new PointAttributes();
        pa.setPointAntialiasingEnable(true);
        appearance.setPointAttributes(pa);
    } else {
        ga = createGeometryArray(rendering, colorDepth);
        // // Test using the geometry from a sphere primitive
        // switch (r)
        // {
        // case HIGH_RES_SPHERE:
        // ga = ItemGeometryGroup.createSphere(50);
        // break;
        // case LOW_RES_SPHERE:
        // ga = ItemGeometryGroup.createSphere(16);
        // break;
        // }
        final PolygonAttributes pa = new PolygonAttributes();
        pa.setPolygonMode(PolygonAttributes.POLYGON_FILL);
        if (rendering.is2D()) {
            pa.setCullFace(PolygonAttributes.CULL_NONE);
            pa.setBackFaceNormalFlip(true);
        } else {
            pa.setCullFace(PolygonAttributes.CULL_BACK);
            pa.setBackFaceNormalFlip(false);
        }
        appearance.setPolygonAttributes(pa);
        final ColoringAttributes ca = new ColoringAttributes();
        // if (rendering.isHighResolution() || rendering.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);
        // For indexed models (with 1 normal per vertex) always use smooth shading
        ca.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
        appearance.setColoringAttributes(ca);
        final Material m = new Material();
        m.setShininess(128f);
        m.setAmbientColor(0.1f, 0.1f, 0.1f);
        if (rendering.isHighResolution()) {
            // Allow shiny highlights on balls
            m.setSpecularColor(0.1f, 0.1f, 0.1f);
        } else {
            // For flat appearance
            m.setSpecularColor(0, 0, 0);
        }
        appearance.setMaterial(m);
    }
    return new Shape3D(ga, appearance);
}
Also used : GeometryArray(org.scijava.java3d.GeometryArray) PointAttributes(org.scijava.java3d.PointAttributes) ColoringAttributes(org.scijava.java3d.ColoringAttributes) Material(org.scijava.java3d.Material) Shape3D(org.scijava.java3d.Shape3D) Appearance(org.scijava.java3d.Appearance) PointArray(org.scijava.java3d.PointArray) PolygonAttributes(org.scijava.java3d.PolygonAttributes)

Example 2 with PointAttributes

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

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

the class ItemPointMesh method createAppearance.

@Override
protected Appearance createAppearance() {
    final Appearance appearance = super.createAppearance();
    final PointAttributes pointAttributes = appearance.getPointAttributes();
    // This allows points to support transparency
    pointAttributes.setPointAntialiasingEnable(true);
    return appearance;
}
Also used : PointAttributes(org.scijava.java3d.PointAttributes) Appearance(org.scijava.java3d.Appearance)

Example 4 with PointAttributes

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

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

the class ItemGroup method setPointSize.

/**
 * Sets the pointSize.
 *
 * @param pointSize the new pointSize
 */
public void setPointSize(float pointSize) {
    final PointAttributes pa = getPointAttributes();
    if (pa == null) {
        return;
    }
    pa.setPointSize(pointSize);
}
Also used : PointAttributes(org.scijava.java3d.PointAttributes)

Aggregations

PointAttributes (org.scijava.java3d.PointAttributes)5 Appearance (org.scijava.java3d.Appearance)4 Material (org.scijava.java3d.Material)3 PolygonAttributes (org.scijava.java3d.PolygonAttributes)3 ColoringAttributes (org.scijava.java3d.ColoringAttributes)2 PointArray (org.scijava.java3d.PointArray)2 TransparencyAttributes (org.scijava.java3d.TransparencyAttributes)2 GeometryArray (org.scijava.java3d.GeometryArray)1 Shape3D (org.scijava.java3d.Shape3D)1