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) {
if (alpha != null) {
final int size = size();
if (alpha.length != size) {
throw new IllegalArgumentException("list of size " + size + " expected");
}
this.alphas = alpha.clone();
} else {
this.alphas = null;
}
if (isPointArray) {
// PointArray alpha must be updated
if (alpha != null) {
for (int i = 0; i < geometryArray.length; i++) {
final GeometryArray ga = geometryArray[i];
ga.getColors(0, pointArrayColorUpdater.pointColor);
pointArrayColorUpdater.getColors(alpha[i]);
ga.setColors(0, pointArrayColorUpdater.pointColor);
}
} else {
for (int i = 0; i < geometryArray.length; i++) {
final GeometryArray ga = geometryArray[i];
ga.getColors(0, pointArrayColorUpdater.pointColor);
pointArrayColorUpdater.getColors(1f);
ga.setColors(0, pointArrayColorUpdater.pointColor);
}
}
}
setTransparency(transparency);
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ItemGeometryGroup method setItemAlpha.
@Override
public void setItemAlpha(float[] alpha) {
if (alpha != null) {
final int size = size();
if (alpha.length != size) {
throw new IllegalArgumentException("list of size " + size + " expected");
}
this.alphas = alpha.clone();
} else {
this.alphas = null;
}
if (isPointArray) {
// PointArray alpha must be updated
if (alpha != null) {
for (int i = 0; i < geometryArray.length; i++) {
final GeometryArray ga = geometryArray[i];
ga.getColors(0, pointArrayColorUpdater.pointColor);
pointArrayColorUpdater.getColors(alpha[i]);
ga.setColors(0, pointArrayColorUpdater.pointColor);
}
} else {
for (int i = 0; i < geometryArray.length; i++) {
final GeometryArray ga = geometryArray[i];
ga.getColors(0, pointArrayColorUpdater.pointColor);
pointArrayColorUpdater.getColors(1f);
ga.setColors(0, pointArrayColorUpdater.pointColor);
}
}
} else {
// Global transparency is merged with alpha
setTransparency(this.transparency);
}
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ImageJ3DResultsViewer method createItemMesh.
private static ItemMesh createItemMesh(final ImageJ3DResultsViewerSettingsOrBuilder settings, LocalList<Point3f> points, final Point3f[] sphereSize, float transparency, float[] alpha) {
final Rendering rendering = Rendering.forNumber(settings.getRendering());
final int colorDepth = (alpha != null) ? 4 : 3;
final Shape3D shape = Shape3DHelper.createShape(rendering, colorDepth);
final GeometryArray ga = (GeometryArray) shape.getGeometry();
final Appearance appearance = shape.getAppearance();
// Estimate the largest array required for the data.
// The mesh is created by reference using an array for coords, normals and colors.
final int singlePointVertexSize = ga.getValidVertexCount();
int singlePointIndexSize = 0;
final int stride = Math.max(3, colorDepth);
if (ga instanceof IndexedGeometryArray) {
// Indexed arrays may have much larger index array than the vertex array
singlePointIndexSize = ((IndexedGeometryArray) ga).getIndexCount();
}
final int singlePointSize = Math.max(singlePointIndexSize, stride * singlePointVertexSize);
final long arraySize = (long) points.size() * singlePointSize;
if (arraySize > CustomContentHelper.MAX_ARRAY_SIZE) {
final double capacity = (double) arraySize / CustomContentHelper.MAX_ARRAY_SIZE;
// @formatter:off
IJ.error(TITLE, TextUtils.wrap(String.format("The results will generate data of %d values. " + "This is amount of data is not supported (%.2fx capacity). " + "Please choose a different dataset with fewer points or " + "different rendering model.", arraySize, capacity), 80));
// @formatter:on
return null;
}
// Support drawing as points ...
if (settings.getRendering() == 0) {
final ItemMesh mesh = new ReferenceItemMesh(points.toArray(new Point3f[0]), ga, appearance, null, null, transparency);
if (alpha != null) {
mesh.setItemAlpha(alpha);
}
mesh.getAppearance().getPointAttributes().setPointSize(sphereSize[0].x);
return mesh;
}
final int triangles = Shape3DHelper.getNumberOfTriangles(rendering);
final long size = (long) points.size() * triangles;
if (size > 10000000L) {
final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE);
egd.addMessage("The results will generate a large mesh of " + size + " triangles.\nThis may take a long time to render and may run out of memory.");
egd.setOKLabel("Continue");
egd.showDialog();
if (egd.wasCanceled()) {
return null;
}
}
IJ.showStatus("Creating 3D mesh ...");
final ItemMesh mesh = new ReferenceItemMesh(points.toArray(new Point3f[0]), ga, appearance, sphereSize, null, transparency);
if (alpha != null) {
mesh.setItemAlpha(alpha);
}
return mesh;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ReferenceItemMesh method setItemColor.
@Override
public void setItemColor(Color3f color) {
if (color == null) {
color = DEFAULT_COLOR;
}
this.color = color;
if (!hasColor()) {
if (isColorByMaterial) {
getAppearance().getMaterial().setDiffuseColor(color);
} else {
getAppearance().getColoringAttributes().setColor(color);
}
return;
}
final GeometryArray ga = (GeometryArray) getGeometry();
if (ga == null) {
return;
}
final float[] colors;
if (hasColor3()) {
colors = new float[size() * colorUpdater.size()];
final float[] tmp = new float[3];
color.get(tmp);
duplicate(tmp, 0, 3, colors.length / 3, colors, 0);
} else {
// Preserve alpha
colors = ga.getColorRefFloat().clone();
for (int i = 0; i < colors.length; i += 4) {
colors[i] = color.x;
colors[i + 1] = color.y;
colors[i + 2] = color.z;
}
}
ga.setColorRefFloat(colors);
changed = true;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ReferenceItemMesh method createGeometry.
@Override
protected GeometryArray createGeometry(float[] coords, GeometryArray sourceGa) {
final GeometryArray ga = createGeometryArray(sourceGa, GeometryArray.BY_REFERENCE);
ga.setCoordRefFloat(coords);
ga.setCapability(GeometryArray.ALLOW_REF_DATA_READ);
ga.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);
// Handle indexed array
if (isIndexGeometryArray()) {
final IndexedGeometryArray sourceIga = (IndexedGeometryArray) sourceGa;
final IndexedGeometryArray iga = (IndexedGeometryArray) ga;
final int objectIndexCount = sourceIga.getValidIndexCount();
final int[] objectIndices = new int[objectIndexCount];
final int[] allIndices = new int[objectIndices.length * points.length];
sourceIga.getCoordinateIndices(0, objectIndices);
duplicateIndices(objectIndices, allIndices);
iga.setCoordinateIndices(0, allIndices);
// Check if we need the color and normal indices
if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0) {
// Duplicate the other indices
if (hasNormals()) {
sourceIga.getNormalIndices(0, objectIndices);
duplicateIndices(objectIndices, allIndices);
iga.setNormalIndices(0, allIndices);
}
if (hasColor()) {
sourceIga.getColorIndices(0, objectIndices);
duplicateIndices(objectIndices, allIndices);
iga.setColorIndices(0, allIndices);
}
}
}
// Handle normals
if (hasNormals()) {
final float[] objectNormals = new float[vertexCount * 3];
sourceGa.getNormals(0, objectNormals);
final float[] allNormals = new float[objectNormals.length * points.length];
duplicate(objectNormals, 0, objectNormals.length, points.length, allNormals, 0);
ga.setNormalRefFloat(allNormals);
}
// Handle colors
if (hasColor()) {
colorUpdater = ArrayColorUpdater.create(vertexCount, hasColor4());
ga.setColorRefFloat(new float[colorUpdater.size() * size()]);
}
return ga;
}
Aggregations