Search in sources :

Example 1 with PointArray

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

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

the class ItemPointMesh method createGeometry.

@Override
protected GeometryArray createGeometry() {
    if (mesh == null || mesh.isEmpty()) {
        return null;
    }
    final int size = size();
    final Point3f[] coords = new Point3f[size];
    mesh.toArray(coords);
    final Color3f[] colors = new Color3f[size];
    Arrays.fill(colors, (color == null) ? DEFAULT_COLOR : color);
    final GeometryArray ta = new PointArray(size, GeometryArray.COORDINATES | GeometryArray.COLOR_3);
    ta.setValidVertexCount(size);
    ta.setCoordinates(0, coords);
    ta.setColors(0, colors);
    ta.setCapability(GeometryArray.ALLOW_COLOR_WRITE);
    ta.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
    ta.setCapability(GeometryArray.ALLOW_COUNT_WRITE);
    ta.setCapability(GeometryArray.ALLOW_COUNT_READ);
    ta.setCapability(Geometry.ALLOW_INTERSECT);
    return ta;
}
Also used : Point3f(org.scijava.vecmath.Point3f) Color3f(org.scijava.vecmath.Color3f) GeometryArray(org.scijava.java3d.GeometryArray) PointArray(org.scijava.java3d.PointArray)

Example 3 with PointArray

use of org.scijava.java3d.PointArray 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 4 with PointArray

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

the class TransparentItemPointMesh method createGeometry.

@Override
protected GeometryArray createGeometry() {
    if (mesh == null || mesh.isEmpty()) {
        return null;
    }
    final int size = size();
    final Point3f[] coords = new Point3f[size];
    mesh.toArray(coords);
    final Color4f[] colors = new Color4f[size];
    if (color == null) {
        color = DEFAULT_COLOR;
    }
    Arrays.fill(colors, new Color4f(color.x, color.y, color.z, 1));
    final GeometryArray ta = new PointArray(size, GeometryArray.COORDINATES | GeometryArray.COLOR_4);
    ta.setValidVertexCount(size);
    ta.setCoordinates(0, coords);
    ta.setColors(0, colors);
    ta.setCapability(GeometryArray.ALLOW_COLOR_WRITE);
    ta.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
    ta.setCapability(GeometryArray.ALLOW_COUNT_WRITE);
    ta.setCapability(GeometryArray.ALLOW_COUNT_READ);
    ta.setCapability(Geometry.ALLOW_INTERSECT);
    return ta;
}
Also used : Point3f(org.scijava.vecmath.Point3f) Color4f(org.scijava.vecmath.Color4f) GeometryArray(org.scijava.java3d.GeometryArray) PointArray(org.scijava.java3d.PointArray)

Aggregations

PointArray (org.scijava.java3d.PointArray)4 GeometryArray (org.scijava.java3d.GeometryArray)3 Appearance (org.scijava.java3d.Appearance)2 Material (org.scijava.java3d.Material)2 PointAttributes (org.scijava.java3d.PointAttributes)2 PolygonAttributes (org.scijava.java3d.PolygonAttributes)2 Point3f (org.scijava.vecmath.Point3f)2 ColoringAttributes (org.scijava.java3d.ColoringAttributes)1 Shape3D (org.scijava.java3d.Shape3D)1 TransparencyAttributes (org.scijava.java3d.TransparencyAttributes)1 Color3f (org.scijava.vecmath.Color3f)1 Color4f (org.scijava.vecmath.Color4f)1