use of org.scijava.java3d.IndexedGeometryStripArray in project GDSC-SMLM by aherbert.
the class ItemMesh 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 || indices == null) {
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 objectSize = vertexCount;
int countPerObject = vertexCount * 3;
final float[] oldCoords = new float[oldSize * countPerObject];
ga.getCoordinates(0, oldCoords);
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 int colorSize = oldSize * countPerObject;
final float[] oldColors = (colorSize < oldCoords.length) ? oldCoords : new float[colorSize];
ga.getColors(0, oldColors);
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(new GeometryUpdater() {
@Override
public void updateData(Geometry geometry) {
final GeometryArray ga = (GeometryArray) geometry;
// We re-use the geometry and just truncate the vertex count
ga.setCoordinates(0, coords);
if (colors != null) {
ga.setColors(0, colors);
}
if (size != oldSize) {
if (isIndexGeometryArray()) {
if (isStripGeometryArray()) {
int[] indices = new int[indexCount * oldSize];
((IndexedGeometryStripArray) ga).getStripIndexCounts(indices);
indices = Arrays.copyOf(indices, indexCount * size);
((IndexedGeometryStripArray) ga).setStripIndexCounts(indices);
} else {
((IndexedGeometryArray) ga).setValidIndexCount(size * indexCount);
}
} else if (isStripGeometryArray()) {
int[] indices = new int[vertexCount * oldSize];
((GeometryStripArray) ga).getStripVertexCounts(indices);
indices = Arrays.copyOf(indices, vertexCount * size);
((GeometryStripArray) ga).setStripVertexCounts(indices);
} else {
ga.setValidVertexCount(size * vertexCount);
}
}
}
});
}
use of org.scijava.java3d.IndexedGeometryStripArray 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);
}
}
});
}
use of org.scijava.java3d.IndexedGeometryStripArray 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;
}
Aggregations