Search in sources :

Example 1 with CustomPointMesh

use of customnode.CustomPointMesh 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)

Aggregations

CustomPointMesh (customnode.CustomPointMesh)1 Point3f (org.scijava.vecmath.Point3f)1 ImageJTrackProgress (uk.ac.sussex.gdsc.core.ij.ImageJTrackProgress)1 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)1 ItemPointMesh (uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemPointMesh)1 ItemTriangleMesh (uk.ac.sussex.gdsc.smlm.ij.ij3d.ItemTriangleMesh)1 Rendering (uk.ac.sussex.gdsc.smlm.ij.ij3d.Shape3DHelper.Rendering)1 TransparentItemPointMesh (uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemPointMesh)1 TransparentItemTriangleMesh (uk.ac.sussex.gdsc.smlm.ij.ij3d.TransparentItemTriangleMesh)1