Search in sources :

Example 36 with GeometryArray

use of org.scijava.java3d.GeometryArray 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 37 with GeometryArray

use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.

the class TransparentItemTriangleMesh method getItemAlpha.

@Override
public void getItemAlpha(float[] alpha) {
    final int size = size();
    ItemHelper.checkSize(alpha.length, size);
    final GeometryArray ga = (GeometryArray) getGeometry();
    if (ga == null) {
        return;
    }
    final int objectSize = objectVertices.length;
    final int N = objectSize * size;
    final float[] colors = new float[N * 4];
    ga.getColors(0, colors);
    for (int i = 0; i < size; i++) {
        // Get only alpha
        alpha[i] = colors[i * 4 * objectSize + 3];
    }
}
Also used : GeometryArray(org.scijava.java3d.GeometryArray)

Example 38 with GeometryArray

use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.

the class Shape3DHelper method getIndexedNormals.

/**
 * 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 Pair<Vector3f[], int[]> getIndexedNormals(Point3f[] vertices, double creaseAngle) {
    final int nVertices = vertices.length;
    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);
    return Pair.of(gi.getNormals(), gi.getNormalIndices());
}
Also used : 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 39 with GeometryArray

use of org.scijava.java3d.GeometryArray in project GDSC-SMLM by aherbert.

the class TransparentItemPointMesh method getItemAlpha.

@Override
public void getItemAlpha(float[] alpha) {
    final int size = size();
    ItemHelper.checkSize(alpha.length, 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++) {
        // Get only alpha
        alpha[i] = colors[i * 4 + 3];
    }
}
Also used : GeometryArray(org.scijava.java3d.GeometryArray)

Example 40 with GeometryArray

use of org.scijava.java3d.GeometryArray 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)52 IndexedGeometryArray (org.scijava.java3d.IndexedGeometryArray)21 Point3f (org.scijava.vecmath.Point3f)11 TriangleArray (org.scijava.java3d.TriangleArray)6 GeometryInfo (org.scijava.java3d.utils.geometry.GeometryInfo)6 NormalGenerator (org.scijava.java3d.utils.geometry.NormalGenerator)5 Color3f (org.scijava.vecmath.Color3f)5 Shape3D (org.scijava.java3d.Shape3D)4 Vector3f (org.scijava.vecmath.Vector3f)4 Appearance (org.scijava.java3d.Appearance)3 IndexedGeometryStripArray (org.scijava.java3d.IndexedGeometryStripArray)3 PointArray (org.scijava.java3d.PointArray)3 Color4f (org.scijava.vecmath.Color4f)3 Rendering (uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering)3 CustomMesh (customnode.CustomMesh)2 Geometry (org.scijava.java3d.Geometry)2 GeometryStripArray (org.scijava.java3d.GeometryStripArray)2 GeometryUpdater (org.scijava.java3d.GeometryUpdater)2 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)2 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)2