Search in sources :

Example 1 with Color4f

use of org.scijava.vecmath.Color4f 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;
}
Also used : Point3f(org.scijava.vecmath.Point3f) Color4f(org.scijava.vecmath.Color4f) Vector3f(org.scijava.vecmath.Vector3f) GeometryInfo(org.scijava.java3d.utils.geometry.GeometryInfo) GeometryArray(org.scijava.java3d.GeometryArray) NormalGenerator(org.scijava.java3d.utils.geometry.NormalGenerator) TriangleArray(org.scijava.java3d.TriangleArray)

Example 2 with Color4f

use of org.scijava.vecmath.Color4f in project GDSC-SMLM by aherbert.

the class TransparentItemTriangleMesh 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;
    }
    final int objectSize = objectVertices.length;
    final int N = objectSize * size;
    final Color4f[] colors = new Color4f[N];
    int index = 0;
    for (final Color4f c : color) {
        for (int j = objectSize; j-- > 0; ) {
            colors[index++] = c;
        }
    }
    ga.setColors(0, colors);
    changed = true;
}
Also used : Color4f(org.scijava.vecmath.Color4f) GeometryArray(org.scijava.java3d.GeometryArray)

Example 3 with Color4f

use of org.scijava.vecmath.Color4f 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;
}
Also used : Point3f(org.scijava.vecmath.Point3f) Color4f(org.scijava.vecmath.Color4f) GeometryArray(org.scijava.java3d.GeometryArray) PointArray(org.scijava.java3d.PointArray)

Aggregations

GeometryArray (org.scijava.java3d.GeometryArray)3 Color4f (org.scijava.vecmath.Color4f)3 Point3f (org.scijava.vecmath.Point3f)2 PointArray (org.scijava.java3d.PointArray)1 TriangleArray (org.scijava.java3d.TriangleArray)1 GeometryInfo (org.scijava.java3d.utils.geometry.GeometryInfo)1 NormalGenerator (org.scijava.java3d.utils.geometry.NormalGenerator)1 Vector3f (org.scijava.vecmath.Vector3f)1