Search in sources :

Example 16 with GeometryArray

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

the class ItemMesh method setItemAlpha.

@Override
public void setItemAlpha(float alpha) {
    if (!hasColor4()) {
        throw new IllegalArgumentException("Per-item alpha not supported");
    }
    final int size = size();
    final GeometryArray ga = (GeometryArray) getGeometry();
    if (ga == null) {
        return;
    }
    final int n = colorUpdater.size();
    final float[] colors = new float[size * n];
    // Preserve color
    ga.getColors(0, colors);
    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.setColors(0, colors);
    changed = true;
}
Also used : IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray)

Example 17 with GeometryArray

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

the class ItemGeometryGroup method setItemAlpha.

/**
 * Sets the item alpha and the global transparency in one operation.
 *
 * @param alpha the alpha
 * @param transparency the transparency
 * @throws IllegalArgumentException the illegal argument exception
 * @see #setItemAlpha(float)
 */
public void setItemAlpha(float alpha, float transparency) {
    // Reuse current alpha storage
    if (alphas == null) {
        alphas = new float[size()];
    }
    Arrays.fill(alphas, alpha);
    if (isPointArray) {
        // PointArray alpha must be updated
        for (int i = 0; i < geometryArray.length; i++) {
            final GeometryArray ga = geometryArray[i];
            ga.getColors(0, pointArrayColorUpdater.pointColor);
            pointArrayColorUpdater.getColors(alpha);
            ga.setColors(0, pointArrayColorUpdater.pointColor);
        }
    }
    setTransparency(transparency);
}
Also used : GeometryArray(org.scijava.java3d.GeometryArray)

Example 18 with GeometryArray

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

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

the class ItemTriangleMesh method getNormals.

/**
 * Gets the normals assuming triangle vertices.
 *
 * @param vertices the vertices
 * @param creaseAngle the crease angle (in degrees)
 * @return the normals
 */
public static Vector3f[] getNormals(Point3f[] vertices, double creaseAngle) {
    final int nVertices = vertices.length;
    final Vector3f[] normals = new Vector3f[nVertices];
    final GeometryArray ta = new TriangleArray(nVertices, GeometryArray.COORDINATES | GeometryArray.NORMALS);
    ta.setCoordinates(0, vertices);
    final GeometryInfo gi = new GeometryInfo(ta);
    final NormalGenerator ng = new NormalGenerator();
    if (creaseAngle >= 0 && creaseAngle <= 180) {
        ng.setCreaseAngle(Math.toRadians(creaseAngle));
    }
    ng.generateNormals(gi);
    final Vector3f[] n = gi.getNormals();
    final int[] indices = gi.getNormalIndices();
    for (int i = 0; i < nVertices; i++) {
        normals[i] = n[indices[i]];
    }
    return normals;
}
Also used : Vector3f(org.scijava.vecmath.Vector3f) GeometryInfo(org.scijava.java3d.utils.geometry.GeometryInfo) GeometryArray(org.scijava.java3d.GeometryArray) NormalGenerator(org.scijava.java3d.utils.geometry.NormalGenerator) TriangleArray(org.scijava.java3d.TriangleArray)

Example 20 with GeometryArray

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

the class ItemTriangleMesh method reorderFast.

@Override
public void reorderFast(int[] indices) {
    if (dirty) {
        throw new IllegalArgumentException("Mesh has been modified");
    }
    changed = true;
    final int oldSize = size();
    final int size = (indices == null) ? 0 : Math.min(oldSize, indices.length);
    if (size == 0) {
        mesh.clear();
        points = new Point3f[0];
        sizes = new Point3f[0];
        this.setGeometry(null);
        return;
    }
    // From here on we assume the current geometry will not be null
    // as this only happens when the original size is zero. Size has
    // been checked at this point to be the smaller of new and old.
    final GeometryArray ga = (GeometryArray) getGeometry();
    points = reorderPoints(points, indices);
    // Sizes could be null or a single size
    if (sizes != null && sizes.length == points.length) {
        sizes = reorderPoints(sizes, indices);
    }
    // Reorder all things in the geometry: coordinates and colour
    // The normals can be copied as they are unchanged.
    // The mesh should contain the same coordinates as the geometry array.
    final int objectSize = objectVertices.length;
    final Point3f[] oldCoords = mesh.toArray(new Point3f[0]);
    final float[] oldColors = new float[oldCoords.length * 3];
    ga.getColors(0, oldColors);
    final Point3f[] coords = new Point3f[size * objectSize];
    final float[] colors = new float[coords.length * 3];
    for (int i = 0; i < size; i++) {
        final int j = indices[i];
        final int ii = i * objectSize;
        final int jj = j * objectSize;
        System.arraycopy(oldCoords, jj, coords, ii, objectSize);
        System.arraycopy(oldColors, jj * 3, colors, ii * 3, objectSize * 3);
    }
    mesh = Arrays.asList(coords);
    ga.updateData(geometry -> {
        final GeometryArray geom = (GeometryArray) geometry;
        // We re-use the geometry and just truncate the vertex count
        geom.setCoordinates(0, coords);
        geom.setColors(0, colors);
        geom.setValidVertexCount(coords.length);
    });
}
Also used : Point3f(org.scijava.vecmath.Point3f) GeometryArray(org.scijava.java3d.GeometryArray)

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