use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ReferenceItemMesh method setItemAlpha.
@Override
public void setItemAlpha(float alpha) {
checkPerItemAlpha();
final int size = size();
final GeometryArray ga = (GeometryArray) getGeometry();
if (ga == null) {
return;
}
final int n = colorUpdater.size();
// Preserve color
final float[] colors = ga.getColorRefFloat().clone();
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.setColorRefFloat(colors);
changed = true;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ReferenceItemMesh method setItemColor4.
@Override
public void setItemColor4(Color4f[] color) {
checkPerItemAlpha();
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 = new float[size() * n];
for (int i = 0; i < color.length; i++) {
System.arraycopy(colorUpdater.getColors(color[i]), 0, colors, i * n, n);
}
ga.setColorRefFloat(colors);
changed = true;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class ReferenceItemMesh method setItemAlpha.
@Override
public void setItemAlpha(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();
// Preserve color
final float[] colors = ga.getColorRefFloat().clone();
for (int i = 0; i < size; i++) {
final int offset = i * n;
for (int j = 3; j < n; j += 4) {
colors[j + offset] = alpha[i];
}
}
ga.setColorRefFloat(colors);
changed = true;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class Shape3DHelper method createGeometryArray.
/**
* Creates the object used to draw a single localisation.
*
* @param rendering the rendering
* @param colorDepth the color depth
* @return the geometry array
*/
public static GeometryArray createGeometryArray(Rendering rendering, int colorDepth) {
final GeometryInfo gi = createGeometryInfo(rendering, colorDepth);
final boolean useCoordIndexOnly = gi.getUseCoordIndexOnly();
final GeometryArray ga = (rendering.is2D()) ? gi.getGeometryArray() : gi.getIndexedGeometryArray(false, false, false, useCoordIndexOnly, false);
return ga;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class Shape3DHelper method createShape.
/**
* Creates the shape.
*
* @param rendering the rendering
* @param colorDepth the color depth
* @return the shape
*/
public static Shape3D createShape(Rendering rendering, int colorDepth) {
GeometryArray ga;
final Appearance appearance = new Appearance();
int vertexFormat = GeometryArray.COORDINATES;
if (colorDepth == 3) {
vertexFormat |= GeometryArray.COLOR_3;
} else if (colorDepth == 4) {
vertexFormat |= GeometryArray.COLOR_4;
}
// Support drawing as points ...
if (rendering == Rendering.POINT) {
ga = new PointArray(1, vertexFormat);
final PointAttributes pa = new PointAttributes();
pa.setPointAntialiasingEnable(true);
appearance.setPointAttributes(pa);
} else {
ga = createGeometryArray(rendering, colorDepth);
// // Test using the geometry from a sphere primitive
// switch (r)
// {
// case HIGH_RES_SPHERE:
// ga = ItemGeometryGroup.createSphere(50);
// break;
// case LOW_RES_SPHERE:
// ga = ItemGeometryGroup.createSphere(16);
// break;
// }
final PolygonAttributes pa = new PolygonAttributes();
pa.setPolygonMode(PolygonAttributes.POLYGON_FILL);
if (rendering.is2D()) {
pa.setCullFace(PolygonAttributes.CULL_NONE);
pa.setBackFaceNormalFlip(true);
} else {
pa.setCullFace(PolygonAttributes.CULL_BACK);
pa.setBackFaceNormalFlip(false);
}
appearance.setPolygonAttributes(pa);
final ColoringAttributes ca = new ColoringAttributes();
// if (rendering.isHighResolution() || rendering.is2D())
// // Smooth across vertices. Required to show 2D surfaces smoothly
// ca.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
// else
// // Faster polygon rendering with flat shading
// ca.setShadeModel(ColoringAttributes.SHADE_FLAT);
// For indexed models (with 1 normal per vertex) always use smooth shading
ca.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
appearance.setColoringAttributes(ca);
final Material m = new Material();
m.setShininess(128f);
m.setAmbientColor(0.1f, 0.1f, 0.1f);
if (rendering.isHighResolution()) {
// Allow shiny highlights on balls
m.setSpecularColor(0.1f, 0.1f, 0.1f);
} else {
// For flat appearance
m.setSpecularColor(0, 0, 0);
}
appearance.setMaterial(m);
}
return new Shape3D(ga, appearance);
}
Aggregations