use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class Shape3DHelper method getNormals.
/**
* Gets the normals assuming triangle vertices.
*
* @param vertices the vertices
* @param creaseAngle the crease angle (in degrees; 0=facet normals; 180=smooth shading)
* @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);
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 TransparentItemPointMesh 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 float[] colors = new float[4 * size];
ga.getColors(0, colors);
int index = 0;
for (final Color3f c : color) {
colors[index++] = c.x;
colors[index++] = c.y;
colors[index++] = c.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 TransparentItemPointMesh method setItemAlpha.
@Override
public void setItemAlpha(float alpha) {
final int size = size();
final GeometryArray ga = (GeometryArray) getGeometry();
if (ga == null) {
return;
}
final float[] colors = new float[4 * size];
ga.getColors(0, colors);
for (int i = 0; i < size; i++) {
// Set only alpha
colors[i * 4 + 3] = alpha;
}
ga.setColors(0, colors);
changed = true;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class TransparentItemPointMesh method setItemColor4.
@Override
public void setItemColor4(Color4f[] color) {
this.color = null;
final int size = size();
ItemHelper.checkSize(color.length, size);
final GeometryArray ga = (GeometryArray) getGeometry();
if (ga == null) {
return;
}
ga.setColors(0, color);
changed = true;
}
use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.
the class TransparentItemPointMesh 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 float[] colors = new float[4 * size];
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;
}
Aggregations