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