Search in sources :

Example 1 with GeometryArray

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

the class ReferenceItemMesh method setItemAlpha.

@Override
public void setItemAlpha(float alpha) {
    checkPerItemAlpha();
    final int size = size();
    final GeometryArray ga = (GeometryArray) getGeometry();
    if (ga == null) {
        return;
    }
    final int n = colorUpdater.size();
    // Preserve color
    final float[] colors = ga.getColorRefFloat().clone();
    for (int i = 0; i < size; i++) {
        final int offset = i * n;
        for (int j = 3; j < n; j += 4) {
            colors[j + offset] = alpha;
        }
    }
    ga.setColorRefFloat(colors);
    changed = true;
}
Also used : IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray)

Example 2 with GeometryArray

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

the class ReferenceItemMesh method setItemColor4.

@Override
public void setItemColor4(Color4f[] color) {
    checkPerItemAlpha();
    this.color = null;
    final int size = size();
    ItemHelper.checkSize(color.length, size);
    final GeometryArray ga = (GeometryArray) getGeometry();
    if (ga == null) {
        return;
    }
    final int n = colorUpdater.size();
    final float[] colors = new float[size() * n];
    for (int i = 0; i < color.length; i++) {
        System.arraycopy(colorUpdater.getColors(color[i]), 0, colors, i * n, n);
    }
    ga.setColorRefFloat(colors);
    changed = true;
}
Also used : IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray)

Example 3 with GeometryArray

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

the class ReferenceItemMesh method setItemAlpha.

@Override
public void setItemAlpha(float[] alpha) {
    checkPerItemAlpha();
    final int size = size();
    ItemHelper.checkSize(alpha.length, size);
    final GeometryArray ga = (GeometryArray) getGeometry();
    if (ga == null) {
        return;
    }
    final int n = colorUpdater.size();
    // Preserve color
    final float[] colors = ga.getColorRefFloat().clone();
    for (int i = 0; i < size; i++) {
        final int offset = i * n;
        for (int j = 3; j < n; j += 4) {
            colors[j + offset] = alpha[i];
        }
    }
    ga.setColorRefFloat(colors);
    changed = true;
}
Also used : IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray)

Example 4 with GeometryArray

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

the class Shape3DHelper method createGeometryArray.

/**
 * Creates the object used to draw a single localisation.
 *
 * @param rendering the rendering
 * @param colorDepth the color depth
 * @return the geometry array
 */
public static GeometryArray createGeometryArray(Rendering rendering, int colorDepth) {
    final GeometryInfo gi = createGeometryInfo(rendering, colorDepth);
    final boolean useCoordIndexOnly = gi.getUseCoordIndexOnly();
    final GeometryArray ga = (rendering.is2D()) ? gi.getGeometryArray() : gi.getIndexedGeometryArray(false, false, false, useCoordIndexOnly, false);
    return ga;
}
Also used : GeometryInfo(org.scijava.java3d.utils.geometry.GeometryInfo) GeometryArray(org.scijava.java3d.GeometryArray)

Example 5 with GeometryArray

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

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