Search in sources :

Example 41 with GeometryArray

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

the class TransparentItemPointMesh method reorderFast.

@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) {
        mesh.clear();
        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();
    // Reorder all things in the geometry: coordinates and colour
    final Point3f[] oldCoords = mesh.toArray(new Point3f[oldSize]);
    final float[] oldColors = new float[oldSize * 4];
    ga.getColors(0, oldColors);
    final Point3f[] coords = new Point3f[size];
    final float[] colors = new float[size * 4];
    for (int i = 0; i < size; i++) {
        final int j = indices[i];
        coords[i] = oldCoords[j];
        System.arraycopy(oldColors, j * 4, colors, i * 4, 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)

Example 42 with GeometryArray

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

the class ItemMesh method getItemAlpha.

@Override
public void getItemAlpha(float[] alpha) {
    if (!hasColor4()) {
        throw new IllegalArgumentException("Per-item alpha not supported");
    }
    final int size = size();
    if (alpha.length != size) {
        throw new IllegalArgumentException("list of size " + size + " expected");
    }
    final GeometryArray ga = (GeometryArray) getGeometry();
    if (ga == null) {
        return;
    }
    final int n = colorUpdater.size();
    final float[] colors = new float[size * n];
    ga.getColors(0, colors);
    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 43 with GeometryArray

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

the class ItemMesh method createGeometryArray.

/**
 * Creates the geometry array.
 *
 * @param sourceGa the source geometry array
 * @param format the format
 * @return the geometry array
 */
protected GeometryArray createGeometryArray(GeometryArray sourceGa, int format) {
    // Create using reflection
    final GeometryArray ga;
    try {
        final Class<?> clazz = sourceGa.getClass();
        // clazz = clazz.asSubclass(clazz);
        final LocalList<Class<?>> paramTypes = new LocalList<>(4);
        final LocalList<Object> paramValues = new LocalList<>(4);
        paramTypes.add(int.class);
        paramTypes.add(int.class);
        paramValues.add(vertexCount * points.length);
        paramValues.add(vertexFormat | format);
        if (isIndexGeometryArray()) {
            paramTypes.add(int.class);
            paramValues.add(indexCount * points.length);
        }
        // Handle strips
        int numStrips = 0;
        int[] objectStripCounts = null;
        int[] allStripCounts = null;
        if (sourceGa instanceof IndexedGeometryStripArray) {
            final IndexedGeometryStripArray igsa = (IndexedGeometryStripArray) sourceGa;
            numStrips = igsa.getNumStrips();
            objectStripCounts = new int[numStrips];
            igsa.getStripIndexCounts(objectStripCounts);
        } else if (sourceGa instanceof GeometryStripArray) {
            final GeometryStripArray gsa = (GeometryStripArray) sourceGa;
            numStrips = gsa.getNumStrips();
            objectStripCounts = new int[numStrips];
            gsa.getStripVertexCounts(objectStripCounts);
        }
        if (objectStripCounts != null) {
            allStripCounts = new int[numStrips * points.length];
            duplicate(objectStripCounts, 0, numStrips, points.length, allStripCounts, 0);
            paramTypes.add(int[].class);
            paramValues.add(allStripCounts);
        }
        final Class<?>[] paramTypes2 = paramTypes.toArray(new Class<?>[0]);
        final Object[] paramValues2 = paramValues.toArray();
        ga = (GeometryArray) clazz.getConstructor(paramTypes2).newInstance(paramValues2);
    } catch (final Exception ex) {
        ex.printStackTrace();
        return null;
    }
    ga.setCapability(GeometryArray.ALLOW_COUNT_WRITE);
    ga.setCapability(GeometryArray.ALLOW_COUNT_READ);
    ga.setCapability(GeometryArray.ALLOW_FORMAT_READ);
    ga.setCapability(Geometry.ALLOW_INTERSECT);
    return ga;
}
Also used : IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray) NotImplementedException(uk.ac.sussex.gdsc.core.data.NotImplementedException) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) IndexedGeometryStripArray(org.scijava.java3d.IndexedGeometryStripArray) GeometryStripArray(org.scijava.java3d.GeometryStripArray) IndexedGeometryStripArray(org.scijava.java3d.IndexedGeometryStripArray)

Example 44 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();
    if (alpha.length != size) {
        throw new IllegalArgumentException("list of size " + size + " expected");
    }
    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[i];
        }
    }
    ga.setColors(0, colors);
    changed = true;
}
Also used : IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray)

Example 45 with GeometryArray

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

the class ItemMesh method setItemColor.

@Override
public void setItemColor(Color3f[] color) {
    if (!hasColor()) {
        setItemColor(color[0]);
        return;
    }
    this.color = null;
    final int size = size();
    if (color.length != size) {
        throw new IllegalArgumentException("list of size " + size + " expected");
    }
    final GeometryArray ga = (GeometryArray) getGeometry();
    if (ga == null) {
        return;
    }
    final int n = colorUpdater.size();
    final float[] colors = new float[size * n];
    if (hasColor3()) {
        for (int i = 0; i < color.length; i++) {
            System.arraycopy(colorUpdater.getColors(color[i]), 0, colors, i * n, n);
        }
        ga.setColors(0, colors);
    } else {
        // Preserve alpha
        ga.getColors(0, colors);
        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.setColors(0, colors);
    }
    changed = true;
}
Also used : IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) 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