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();
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;
}
}
ga.setColors(0, colors);
changed = true;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ItemGeometryGroup method setItemAlpha.
/**
* Sets the item alpha and the global transparency in one operation.
*
* @param alpha the alpha
* @param transparency the transparency
* @throws IllegalArgumentException the illegal argument exception
* @see #setItemAlpha(float)
*/
public void setItemAlpha(float alpha, float transparency) {
// Reuse current alpha storage
if (alphas == null) {
alphas = new float[size()];
}
Arrays.fill(alphas, alpha);
if (isPointArray) {
// PointArray alpha must be updated
for (int i = 0; i < geometryArray.length; i++) {
final GeometryArray ga = geometryArray[i];
ga.getColors(0, pointArrayColorUpdater.pointColor);
pointArrayColorUpdater.getColors(alpha);
ga.setColors(0, pointArrayColorUpdater.pointColor);
}
}
setTransparency(transparency);
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ItemPointMesh method createGeometry.
@Override
protected GeometryArray createGeometry() {
if (mesh == null || mesh.isEmpty()) {
return null;
}
final int size = size();
final Point3f[] coords = new Point3f[size];
mesh.toArray(coords);
final Color3f[] colors = new Color3f[size];
Arrays.fill(colors, (color == null) ? DEFAULT_COLOR : color);
final GeometryArray ta = new PointArray(size, GeometryArray.COORDINATES | GeometryArray.COLOR_3);
ta.setValidVertexCount(size);
ta.setCoordinates(0, coords);
ta.setColors(0, colors);
ta.setCapability(GeometryArray.ALLOW_COLOR_WRITE);
ta.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
ta.setCapability(GeometryArray.ALLOW_COUNT_WRITE);
ta.setCapability(GeometryArray.ALLOW_COUNT_READ);
ta.setCapability(Geometry.ALLOW_INTERSECT);
return ta;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ItemTriangleMesh method getNormals.
/**
* Gets the normals assuming triangle vertices.
*
* @param vertices the vertices
* @param creaseAngle the crease angle (in degrees)
* @return the normals
*/
public static Vector3f[] getNormals(Point3f[] vertices, double creaseAngle) {
final int nVertices = vertices.length;
final Vector3f[] normals = new Vector3f[nVertices];
final GeometryArray ta = new TriangleArray(nVertices, GeometryArray.COORDINATES | GeometryArray.NORMALS);
ta.setCoordinates(0, vertices);
final GeometryInfo gi = new GeometryInfo(ta);
final NormalGenerator ng = new NormalGenerator();
if (creaseAngle >= 0 && creaseAngle <= 180) {
ng.setCreaseAngle(Math.toRadians(creaseAngle));
}
ng.generateNormals(gi);
final Vector3f[] n = gi.getNormals();
final int[] indices = gi.getNormalIndices();
for (int i = 0; i < nVertices; i++) {
normals[i] = n[indices[i]];
}
return normals;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ItemTriangleMesh 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 * 3];
ga.getColors(0, oldColors);
final Point3f[] coords = new Point3f[size * objectSize];
final float[] colors = new float[coords.length * 3];
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 * 3, colors, ii * 3, objectSize * 3);
}
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