use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ItemTriangleMesh method createGeometry.
@Override
protected GeometryArray createGeometry() {
if (mesh == null || mesh.size() < 3) {
return null;
}
final int vertexCount = mesh.size();
final Point3f[] coords = new Point3f[vertexCount];
mesh.toArray(coords);
// Do not try to get the colour back from the geometry as is done
// in the super-class. That will only work if the size is the same
// and this method is likely to be called when the size changes.
final Color3f[] colors = new Color3f[vertexCount];
Arrays.fill(colors, (color == null) ? DEFAULT_COLOR : color);
final GeometryArray ta = new TriangleArray(vertexCount, GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.NORMALS);
ta.setCoordinates(0, coords);
ta.setColors(0, colors);
// generate normals
final GeometryArray result;
if (dirty) {
final GeometryInfo gi = new GeometryInfo(ta);
final NormalGenerator ng = new NormalGenerator();
ng.generateNormals(gi);
result = gi.getGeometryArray();
} else {
// Use the same normals for each repeated object
final Vector3f[] normals = new Vector3f[vertexCount];
// Binary fill
int fill = objectNormals.length;
System.arraycopy(objectNormals, 0, normals, 0, fill);
for (int i = 2; i < points.length; i *= 2) {
System.arraycopy(normals, 0, normals, fill, fill);
fill *= 2;
}
// Final fill
System.arraycopy(normals, 0, normals, fill, normals.length - fill);
ta.setNormals(0, normals);
result = ta;
}
result.setCapability(GeometryArray.ALLOW_NORMAL_WRITE);
result.setCapability(GeometryArray.ALLOW_COLOR_WRITE);
result.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
result.setCapability(GeometryArray.ALLOW_COUNT_WRITE);
result.setCapability(GeometryArray.ALLOW_COUNT_READ);
result.setCapability(GeometryArray.ALLOW_FORMAT_READ);
result.setCapability(Geometry.ALLOW_INTERSECT);
result.setValidVertexCount(vertexCount);
return result;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class TransparentItemTriangleMesh method createGeometry.
@Override
protected GeometryArray createGeometry() {
if (mesh == null || mesh.size() < 3) {
return null;
}
final int vertexCount = mesh.size();
final Point3f[] coords = new Point3f[vertexCount];
mesh.toArray(coords);
final Color4f[] colors = new Color4f[vertexCount];
if (color == null) {
color = DEFAULT_COLOR;
}
Arrays.fill(colors, new Color4f(color.x, color.y, color.z, 1));
final GeometryArray ta = new TriangleArray(vertexCount, GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS);
ta.setCoordinates(0, coords);
ta.setColors(0, colors);
// generate normals
final GeometryArray result;
if (dirty) {
final GeometryInfo gi = new GeometryInfo(ta);
final NormalGenerator ng = new NormalGenerator();
ng.generateNormals(gi);
result = gi.getGeometryArray();
} else {
// Use the same normals for each repeated object
final Vector3f[] normals = new Vector3f[vertexCount];
// Binary fill
int fill = objectNormals.length;
System.arraycopy(objectNormals, 0, normals, 0, fill);
for (int i = 2; i < points.length; i *= 2) {
System.arraycopy(normals, 0, normals, fill, fill);
fill *= 2;
}
// Final fill
System.arraycopy(normals, 0, normals, fill, normals.length - fill);
ta.setNormals(0, normals);
result = ta;
}
result.setCapability(GeometryArray.ALLOW_NORMAL_WRITE);
result.setCapability(GeometryArray.ALLOW_COLOR_WRITE);
result.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
result.setCapability(GeometryArray.ALLOW_COUNT_WRITE);
result.setCapability(GeometryArray.ALLOW_COUNT_READ);
result.setCapability(GeometryArray.ALLOW_FORMAT_READ);
result.setCapability(Geometry.ALLOW_INTERSECT);
result.setValidVertexCount(vertexCount);
return result;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class TransparentItemTriangleMesh method setItemAlpha.
@Override
public void setItemAlpha(float alpha) {
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 = 3;
while (size-- > 0) {
for (int j = objectSize; j-- > 0; ) {
colors[index] = alpha;
index += 4;
}
}
ga.setColors(0, colors);
changed = true;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class TransparentItemTriangleMesh method setItemAlpha.
@Override
public void setItemAlpha(float[] alpha) {
final int size = size();
ItemHelper.checkSize(alpha.length, 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 = 3;
for (final float f : alpha) {
for (int j = objectSize; j-- > 0; ) {
colors[index] = f;
index += 4;
}
}
ga.setColors(0, colors);
changed = true;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class TransparentItemTriangleMesh method setItemColor.
@Override
public void setItemColor(Color3f[] color) {
this.color = null;
final int size = size();
ItemHelper.checkSize(color.length, 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;
for (final Color3f c : color) {
for (int j = objectSize; j-- > 0; ) {
colors[index++] = c.x;
colors[index++] = c.y;
colors[index++] = c.z;
// Skip over alpha
index++;
}
}
ga.setColors(0, colors);
changed = true;
}
Aggregations