Search in sources :

Example 31 with GeometryArray

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

the class ReferenceItemMesh method setItemColor.

@Override
public void setItemColor(Color3f[] color) {
    if (!hasColor()) {
        setItemColor(color[0]);
        return;
    }
    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;
    if (hasColor3()) {
        colors = new float[size() * n];
        for (int i = 0; i < color.length; i++) {
            System.arraycopy(colorUpdater.getColors(color[i]), 0, colors, i * n, n);
        }
    } else {
        // Preserve alpha
        colors = ga.getColorRefFloat().clone();
        for (int i = 0; i < color.length; i++) {
            final int offset = i * n;
            colorUpdater.getColors(color[i], colors[offset + 3]);
            System.arraycopy(colorUpdater.pointColor, 0, colors, offset, n);
        }
    }
    ga.setColorRefFloat(colors);
    changed = true;
}
Also used : IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray)

Example 32 with GeometryArray

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

the class ReferenceItemMesh method getItemAlpha.

@Override
public void getItemAlpha(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();
    final float[] colors = ga.getColorRefFloat();
    for (int i = 0; i < size; i++) {
        // Get only alpha
        alpha[i] = colors[i * n + 3];
    }
}
Also used : IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray)

Example 33 with GeometryArray

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

the class ReferenceItemMesh method reorderFast.

@SuppressWarnings("null")
@Override
public void reorderFast(int[] indices) {
    changed = true;
    final int oldSize = size();
    final int size = (indices == null) ? 0 : Math.min(oldSize, indices.length);
    if (size == 0) {
        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, indices, strip counts are are unchanged.
    int countPerObject = vertexCount * 3;
    final float[] oldCoords = ga.getCoordRefFloat();
    final float[] coords = new float[size * countPerObject];
    for (int i = 0; i < size; i++) {
        final int j = indices[i];
        final int ii = i * countPerObject;
        final int jj = j * countPerObject;
        System.arraycopy(oldCoords, jj, coords, ii, countPerObject);
    }
    final float[] colors;
    if (hasColor()) {
        countPerObject = colorUpdater.size();
        final float[] oldColors = ga.getColorRefFloat();
        colors = new float[size * countPerObject];
        for (int i = 0; i < size; i++) {
            final int j = indices[i];
            final int ii = i * countPerObject;
            final int jj = j * countPerObject;
            System.arraycopy(oldColors, jj, colors, ii, countPerObject);
        }
    } else {
        colors = null;
    }
    ga.updateData(geometry -> {
        final GeometryArray geom = (GeometryArray) geometry;
        // We re-use the geometry and just truncate the vertex count
        geom.setCoordRefFloat(coords);
        if (colors != null) {
            geom.setColorRefFloat(colors);
        }
        if (size != oldSize) {
            if (isIndexGeometryArray()) {
                if (isStripGeometryArray()) {
                    int[] indices2 = new int[indexCount * oldSize];
                    ((IndexedGeometryStripArray) geom).getStripIndexCounts(indices2);
                    indices2 = Arrays.copyOf(indices2, indexCount * size);
                    ((IndexedGeometryStripArray) geom).setStripIndexCounts(indices2);
                } else {
                    ((IndexedGeometryArray) geom).setValidIndexCount(size * indexCount);
                }
            } else if (isStripGeometryArray()) {
                int[] indices2 = new int[vertexCount * oldSize];
                ((GeometryStripArray) geom).getStripVertexCounts(indices2);
                indices2 = Arrays.copyOf(indices2, vertexCount * size);
                ((GeometryStripArray) geom).setStripVertexCounts(indices2);
            } else {
                geom.setValidVertexCount(size * vertexCount);
            }
        }
    });
}
Also used : IndexedGeometryStripArray(org.scijava.java3d.IndexedGeometryStripArray) IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray)

Example 34 with GeometryArray

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

the class TransparentItemTriangleMesh method setItemColor.

@Override
public void setItemColor(Color3f color) {
    if (color == null) {
        color = DEFAULT_COLOR;
    }
    this.color = color;
    final int size = size();
    final GeometryArray ga = (GeometryArray) getGeometry();
    if (ga == null) {
        return;
    }
    final int objectSize = objectVertices.length;
    final int N = objectSize * size;
    final float[] colors = new float[N * 4];
    ga.getColors(0, colors);
    int index = 0;
    while (index < colors.length) {
        colors[index++] = color.x;
        colors[index++] = color.y;
        colors[index++] = color.z;
        // Skip over alpha
        index++;
    }
    ga.setColors(0, colors);
    changed = true;
}
Also used : GeometryArray(org.scijava.java3d.GeometryArray)

Example 35 with GeometryArray

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

the class TransparentItemTriangleMesh 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 * 4];
    ga.getColors(0, oldColors);
    final Point3f[] coords = new Point3f[size * objectSize];
    final float[] colors = new float[coords.length * 4];
    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 * 4, colors, ii * 4, objectSize * 4);
    }
    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