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);
});
}
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];
}
}
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;
}
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;
}
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;
}
Aggregations