Search in sources :

Example 1 with TransparentItemPointMesh

use of uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemPointMesh in project GDSC-SMLM by aherbert.

the class ImageJ3DResultsViewer method createMesh.

@SuppressWarnings("unused")
private static CustomMesh createMesh(final ImageJ3DResultsViewerSettingsOrBuilder settings, LocalList<Point3f> points, final Point3f[] sphereSize, float transparency, float[] alpha) {
    // Coordinates + color
    int stride = 3 + 3;
    if (alpha != null) {
        // add color alpha
        stride++;
    }
    // Support drawing as points ...
    if (settings.getRendering() == 0) {
        final long arraySize = (long) points.size() * stride;
        if (arraySize > CustomContentHelper.MAX_ARRAY_SIZE) {
            final double capacity = (double) arraySize / CustomContentHelper.MAX_ARRAY_SIZE;
            // @formatter:off
            IJ.error(TITLE, TextUtils.wrap(String.format("The results will generate data of %d values. " + "This is amount of data is not supported (%.2fx capacity). " + "Please choose a different dataset with fewer points.", arraySize, capacity), 80));
            // @formatter:on
            return null;
        }
        CustomPointMesh mesh;
        if (alpha != null) {
            final TransparentItemPointMesh mesh2 = new TransparentItemPointMesh(points, null, transparency);
            mesh = mesh2;
            mesh2.setItemAlpha(alpha);
        } else {
            mesh = new ItemPointMesh(points, null, transparency);
        }
        mesh.setPointSize(sphereSize[0].x);
        return mesh;
    }
    final Rendering r = Rendering.forNumber(settings.getRendering());
    // Repeated mesh creation is much faster as the normals are cached.
    // There does not appear to be a difference in the speed the image responds
    // to user interaction between indexed or standard triangles.
    // Currently the RepeatedIndexedTriangleMesh computes the normals a different way to
    // the super class to preserve the orientation of the normals. So if the coordinates
    // are modified through the mesh then the appearance will change. For now just use
    // the RepeatedTriangleMesh.
    // TODO - check this. It may not be true if the shading mode is flat...
    // Also the IndexedTriangleMesh has one normal per vertex and this causes a colour fall-off
    // on the triangle plane towards the edges. The TriangleMesh colours the entire surface
    // of each triangle the same which looks 'normal'.
    final List<Point3f> point = Shape3DHelper.createLocalisationObject(r);
    // + normals
    stride += 3;
    final int singlePointSize = point.size();
    final long size = (long) points.size() * singlePointSize;
    final long arraySize = size * stride;
    if (arraySize > CustomContentHelper.MAX_ARRAY_SIZE) {
        final double capacity = (double) arraySize / CustomContentHelper.MAX_ARRAY_SIZE;
        // @formatter:off
        IJ.error(TITLE, TextUtils.wrap(String.format("The results will generate data of %d values. " + "This is amount of data is not supported (%.2fx capacity). " + "Please choose a different rendering model with fewer vertices.", arraySize, capacity), 80));
        // @formatter:on
        return null;
    }
    if (size > 10000000L) {
        final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE);
        egd.addMessage("The results will generate a large mesh of " + size + " vertices.\nThis may take a long time to render and may run out of memory.");
        egd.setOKLabel("Continue");
        egd.showDialog();
        if (egd.wasCanceled()) {
            return null;
        }
    }
    IJ.showStatus("Creating 3D mesh ...");
    final double creaseAngle = (r.isHighResolution()) ? 44 : 0;
    // Used for debugging construction time
    final ImageJTrackProgress progress = null;
    if (alpha != null) {
        final TransparentItemTriangleMesh mesh = new TransparentItemTriangleMesh(point.toArray(new Point3f[singlePointSize]), points.toArray(new Point3f[0]), sphereSize, null, transparency, creaseAngle, progress);
        mesh.setItemAlpha(alpha);
        return mesh;
    }
    return new ItemTriangleMesh(point.toArray(new Point3f[singlePointSize]), points.toArray(new Point3f[0]), sphereSize, null, transparency, creaseAngle, progress);
}
Also used : ItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemPointMesh) TransparentItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemPointMesh) ItemTriangleMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemTriangleMesh) TransparentItemTriangleMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemTriangleMesh) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) CustomPointMesh(customnode.CustomPointMesh) TransparentItemTriangleMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemTriangleMesh) Point3f(org.scijava.vecmath.Point3f) Rendering(uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering) ImageJTrackProgress(uk.ac.sussex.gdsc.core.ij.ImageJTrackProgress) TransparentItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemPointMesh)

Example 2 with TransparentItemPointMesh

use of uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemPointMesh in project GDSC-SMLM by aherbert.

the class ImageJ3DResultsViewer method createShape.

@SuppressWarnings("unused")
private static Shape3D createShape(Builder settings) {
    final LocalList<Point3f> points = new LocalList<>(1);
    points.push(new Point3f());
    // We try and match the geometry and appearance of the standard mesh.
    // Do this by creating a mesh with a single point and get the Geometry and Appearance.
    GeometryArray ga;
    CustomMesh mesh;
    final float transparency = getTransparency(settings);
    // Support drawing as points ...
    if (settings.getRendering() == 0) {
        mesh = new TransparentItemPointMesh(points, null, transparency);
        ((ItemPointMesh) mesh).setPointSize((float) settings.getPixelSize());
        updateAppearance(mesh, settings);
        // Assume the TransparentItemPointMesh sets COLOR_4
        ga = (GeometryArray) mesh.getGeometry();
    } else {
        final Rendering r = Rendering.forNumber(settings.getRendering());
        final List<Point3f> point = Shape3DHelper.createLocalisationObject(r);
        final Point3f[] vertices = point.toArray(new Point3f[1]);
        // Correct the direction
        ItemTriangleMesh.checkFacets(vertices);
        final double creaseAngle = (r.isHighResolution()) ? 44 : 0;
        mesh = new ItemTriangleMesh(vertices, points.toArray(new Point3f[1]), null, null, transparency, creaseAngle, null);
        updateAppearance(mesh, settings);
        final int nVertices = vertices.length;
        ga = new TriangleArray(nVertices, GeometryArray.COORDINATES | GeometryArray.NORMALS);
        // Copy the coords and normals. We don't require the vertex colours.
        final float[] coords = new float[nVertices * 3];
        final float[] normals = new float[nVertices * 3];
        final GeometryArray gaToCopy = (GeometryArray) mesh.getGeometry();
        gaToCopy.getCoordinates(0, coords);
        gaToCopy.getNormals(0, normals);
        ga.setCoordinates(0, coords);
        ga.setNormals(0, normals);
        ga.setValidVertexCount(nVertices);
    }
    return new Shape3D(ga, mesh.getAppearance());
}
Also used : ItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemPointMesh) TransparentItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemPointMesh) ItemTriangleMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemTriangleMesh) TransparentItemTriangleMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemTriangleMesh) IndexedGeometryArray(org.scijava.java3d.IndexedGeometryArray) GeometryArray(org.scijava.java3d.GeometryArray) TriangleArray(org.scijava.java3d.TriangleArray) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) Point3f(org.scijava.vecmath.Point3f) Rendering(uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering) CustomMesh(customnode.CustomMesh) Shape3D(org.scijava.java3d.Shape3D) TransparentItemPointMesh(uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemPointMesh)

Aggregations

Point3f (org.scijava.vecmath.Point3f)2 ItemPointMesh (uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemPointMesh)2 ItemTriangleMesh (uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemTriangleMesh)2 Rendering (uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering)2 TransparentItemPointMesh (uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemPointMesh)2 TransparentItemTriangleMesh (uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemTriangleMesh)2 CustomMesh (customnode.CustomMesh)1 CustomPointMesh (customnode.CustomPointMesh)1 GeometryArray (org.scijava.java3d.GeometryArray)1 IndexedGeometryArray (org.scijava.java3d.IndexedGeometryArray)1 Shape3D (org.scijava.java3d.Shape3D)1 TriangleArray (org.scijava.java3d.TriangleArray)1 ImageJTrackProgress (uk.ac.sussex.gdsc.core.ij.ImageJTrackProgress)1 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)1 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)1