Search in sources :

Example 26 with Voxel3D

use of mcib3d.geom.Voxel3D in project mcib3d-core by mcib3d.

the class Segment3DSpots method segmentSpotTemplate.

/**
 * @param xdep
 * @param ydep
 * @param zdep
 * @param lcThreshold
 * @param val
 * @return
 */
private ArrayList<Voxel3D> segmentSpotTemplate(int xdep, int ydep, int zdep, int lcThreshold, int val) {
    boolean changement = true;
    int xfin = xdep + 1;
    int yfin = ydep + 1;
    int zfin = zdep + 1;
    int sens = 1;
    if (labelImage == null) {
        this.createLabelImage();
    }
    // pixel already segmented ?
    if (labelImage.getPixel(xdep, ydep, zdep) > 0) {
        return null;
    }
    labelImage.setPixel(xdep, ydep, zdep, val);
    ArrayList<Voxel3D> object = new ArrayList<Voxel3D>();
    object.add(new Voxel3D(xdep, ydep, zdep, val));
    int volume = 1;
    int i;
    int j;
    int k;
    int l;
    int m;
    int n;
    ImageHandler original = rawImage;
    ArrayList<Voxel3D> neigh;
    Iterator it;
    Voxel3D tmpneigh;
    while (changement) {
        changement = false;
        for (k = sens == 1 ? zdep : zfin; ((sens == 1 && k <= zfin) || (sens == -1 && k >= zdep)); k += sens) {
            for (j = sens == 1 ? ydep : yfin; ((sens == 1 && j <= yfin) || (sens == -1 && j >= ydep)); j += sens) {
                for (i = sens == 1 ? xdep : xfin; ((sens == 1 && i <= xfin) || (sens == -1 && i >= xdep)); i += sens) {
                    if (labelImage.getPixel(i, j, k) == val) {
                        // create neighbors list
                        neigh = new ArrayList<Voxel3D>();
                        for (n = k - 1; n < k + 2; n++) {
                            for (m = j - 1; m < j + 2; m++) {
                                for (l = i - 1; l < i + 2; l++) {
                                    if (labelImage.getPixel(l, m, n) == 0) {
                                        neigh.add(new Voxel3D(l, m, n, original.getPixel(l, m, n)));
                                    }
                                }
                            }
                        }
                        // analyse list
                        it = neigh.iterator();
                        while (it.hasNext()) {
                            tmpneigh = (Voxel3D) it.next();
                            // CLASSICAL
                            if (tmpneigh.getValue() >= lcThreshold) {
                                l = tmpneigh.getRoundX();
                                m = tmpneigh.getRoundY();
                                n = tmpneigh.getRoundZ();
                                labelImage.setPixel(l, m, n, val);
                                object.add(new Voxel3D(l, m, n, val));
                                volume++;
                                if (volume > volMax) {
                                    if (show) {
                                        IJ.log("VOL :" + volume);
                                    }
                                    return null;
                                }
                                // update min-max
                                if (l < xdep) {
                                    xdep--;
                                }
                                if (l > xfin) {
                                    xfin++;
                                }
                                if (m < ydep) {
                                    ydep--;
                                }
                                if (m > yfin) {
                                    yfin++;
                                }
                                if (n < zdep) {
                                    zdep--;
                                }
                                if (n > zfin) {
                                    zfin++;
                                }
                                changement = true;
                            }
                        }
                    }
                }
            }
        }
        sens *= -1;
    }
    return object;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Voxel3D(mcib3d.geom.Voxel3D)

Example 27 with Voxel3D

use of mcib3d.geom.Voxel3D in project mcib3d-core by mcib3d.

the class FHTImage3D method getTranslation.

/**
 * Gets the translation attribute of the FHTImage3D class
 *
 * @param xcorr Description of the Parameter
 * @param RmaxX Description of the Parameter
 * @param RmaxY Description of the Parameter
 * @param RmaxZ Description of the Parameter
 * @return The translation value
 */
public static Voxel3D getTranslation(FHTImage3D xcorr, int RmaxX, int RmaxY, int RmaxZ) {
    int sizex = xcorr.sizex;
    int sizey = xcorr.sizey;
    int sizez = xcorr.sizez;
    int centerx = (int) ((sizex) / 2.0F);
    int centery = (int) ((sizey) / 2.0F);
    int centerz = (int) ((sizez) / 2.0F);
    if (xcorr.centered) {
        centerx = 0;
        centery = 0;
        centerz = 0;
    }
    Voxel3D max = new Voxel3D(centerx, centery, centerz, xcorr.getPixel(centerx, centery, centerz));
    for (int k = 0; k < sizez; k++) {
        int dz = (k >= sizez - centerz) ? k - sizez : k;
        for (int j = 0; j < sizey; j++) {
            int dy = (j >= sizey - centery) ? j - sizey : j;
            for (int i = 0; i < sizex; i++) {
                int dx = (i >= sizex - centerx) ? i - sizex : i;
                if (Math.abs(dx) <= RmaxX && Math.abs(dy) <= RmaxY && Math.abs(dz) <= RmaxZ) {
                    double val = xcorr.getPixel(i, j, k);
                    if (val > max.getValue()) {
                        max.setVoxel(dx, dy, dz, val);
                    }
                }
            }
        }
    }
    return max;
}
Also used : Voxel3D(mcib3d.geom.Voxel3D)

Example 28 with Voxel3D

use of mcib3d.geom.Voxel3D in project mcib3d-core by mcib3d.

the class Mesh method computeConvexHull3D.

public ArrayList<Point3f> computeConvexHull3D() {
    QuickHull3D hull = new QuickHull3D();
    System.out.println("Computing 3d convex hull...");
    Object3DSurface o = new Object3DSurface(vertices);
    ArrayList<Voxel3D> pointsList = o.getContours();
    Point3d[] points = new Point3d[pointsList.size()];
    for (int ve = 0; ve < points.length; ve++) {
        points[ve] = new Point3d(pointsList.get(ve).getX(), pointsList.get(ve).getY(), pointsList.get(ve).getZ());
    }
    System.out.println("done 1st for");
    hull.build(points);
    hull.triangulate();
    ArrayList<Point3f> convex = new ArrayList<Point3f>();
    int[][] faceIndices = hull.getFaces();
    Point3d[] verticesHull = hull.getVertices();
    for (int k = 0; k < faceIndices.length; k++) {
        for (int ve = 0; ve < 3; ve++) {
            Point3d point = verticesHull[faceIndices[k][ve]];
            convex.add(new Point3f((float) point.x, (float) point.y, (float) point.z));
        }
    }
    return convex;
}
Also used : Point3f(org.scijava.vecmath.Point3f) QuickHull3D(com.github.quickhull3d.QuickHull3D) Point3d(com.github.quickhull3d.Point3d) ArrayList(java.util.ArrayList) Voxel3D(mcib3d.geom.Voxel3D) Object3DSurface(mcib3d.geom.Object3DSurface)

Aggregations

Voxel3D (mcib3d.geom.Voxel3D)28 ArrayList (java.util.ArrayList)11 Object3DVoxels (mcib3d.geom.Object3DVoxels)6 Iterator (java.util.Iterator)3 Voxel3DComparable (mcib3d.geom.Voxel3DComparable)3 ImagePlus (ij.ImagePlus)2 ImageProcessor (ij.process.ImageProcessor)2 Random (java.util.Random)2 Objects3DPopulation (mcib3d.geom.Objects3DPopulation)2 Point3D (mcib3d.geom.Point3D)2 ImageInt (mcib3d.image3d.ImageInt)2 ImageShort (mcib3d.image3d.ImageShort)2 FHTImage3D (mcib3d.image3d.legacy.FHTImage3D)2 ArrayUtil (mcib3d.utils.ArrayUtil)2 Point3d (com.github.quickhull3d.Point3d)1 QuickHull3D (com.github.quickhull3d.QuickHull3D)1 Roi (ij.gui.Roi)1 RoiManager (ij.plugin.frame.RoiManager)1 Rectangle (java.awt.Rectangle)1 Date (java.util.Date)1