use of org.scijava.java3d.PointArray 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);
}
use of org.scijava.java3d.PointArray 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.PointArray in project GDSC-SMLM by aherbert.
the class ItemGeometryGroup method createDefaultAppearance.
/**
* Create a default Appearance object. This will have the correct attributes and capability bits
* set to manipulate the material and transparency.
*
* @param appearance the appearance
* @param ga the geometry array
* @return the appearance
*/
private static Appearance createDefaultAppearance(Appearance appearance, GeometryArray ga) {
if (appearance == null) {
appearance = new Appearance();
}
appearance.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
appearance.setCapability(Appearance.ALLOW_MATERIAL_READ);
if (ga instanceof PointArray) {
appearance.setPolygonAttributes(null);
appearance.setMaterial(null);
PointAttributes pointAttributes = appearance.getPointAttributes();
if (pointAttributes == null) {
pointAttributes = new PointAttributes();
pointAttributes.setPointAntialiasingEnable(true);
appearance.setPointAttributes(pointAttributes);
}
pointAttributes.setCapability(PointAttributes.ALLOW_ANTIALIASING_WRITE);
pointAttributes.setCapability(PointAttributes.ALLOW_SIZE_WRITE);
// We use the coordinates for the colour
ga.setCapability(GeometryArray.ALLOW_COLOR_WRITE);
} else {
appearance.setPointAttributes(null);
// These are the defaults. We may need them if we want to support mesh
// display when the polygon mode is Line
PolygonAttributes polygonAttributes = appearance.getPolygonAttributes();
if (polygonAttributes == null) {
polygonAttributes = new PolygonAttributes();
appearance.setPolygonAttributes(polygonAttributes);
}
polygonAttributes.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL);
// We require material attributes for colour
Material material = appearance.getMaterial();
if (material == null) {
material = new Material();
material.setDiffuseColor(DEFAULT_COLOUR);
appearance.setMaterial(material);
}
material.setCapability(Material.ALLOW_COMPONENT_WRITE);
}
// We require transparency attributes for global transparency
TransparencyAttributes tr = appearance.getTransparencyAttributes();
if (tr == null) {
tr = new TransparencyAttributes();
tr.setTransparencyMode(TransparencyAttributes.NONE);
tr.setTransparency(0f);
appearance.setTransparencyAttributes(tr);
}
tr.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
tr.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
return appearance;
}
use of org.scijava.java3d.PointArray in project GDSC-SMLM by aherbert.
the class TransparentItemPointMesh 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 Color4f[] colors = new Color4f[size];
if (color == null) {
color = DEFAULT_COLOR;
}
Arrays.fill(colors, new Color4f(color.x, color.y, color.z, 1));
final GeometryArray ta = new PointArray(size, GeometryArray.COORDINATES | GeometryArray.COLOR_4);
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;
}
Aggregations