Search in sources :

Example 6 with Point3D

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

the class SymmetryFilter method computeBins.

private void computeBins() {
    ImageHandler img = edges[0];
    bin1 = new ImageFloat("bin1", img.sizeX, img.sizeY, img.sizeZ);
    bin2 = new ImageFloat("bin2", img.sizeX, img.sizeY, img.sizeZ);
    for (int z = 0; z < img.sizeZ; z++) {
        IJ.showStatus("Symmetry " + z + "/" + img.sizeZ);
        for (int x = 0; x < img.sizeX; x++) {
            for (int y = 0; y < img.sizeY; y++) {
                double ex = edges[0].getPixel(x, y, z);
                double ey = edges[1].getPixel(x, y, z);
                double ez = edges[2].getPixel(x, y, z);
                double ee = Math.sqrt(ex * ex + ey * ey + ez * ez);
                // bin
                Vector3D grad = new Vector3D(ex, ey, ez);
                grad.normalize();
                if (grad.getLength() == 0) {
                    continue;
                }
                Point3D pos = new Vector3D(x, y, z);
                for (int d = 0; d < radius; d++) {
                    pos.translate(grad);
                    if ((d > 0) && (img.contains(pos.getRoundX(), pos.getRoundY(), pos.getRoundZ()))) {
                        bin1.setPixelIncrement(pos, 1);
                        if (improved) {
                            bin2.setPixelIncrement(pos, (float) (d * ee));
                        } else {
                            bin2.setPixelIncrement(pos, (float) (ee));
                        }
                    }
                }
            }
        }
    }
}
Also used : ImageHandler(mcib3d.image3d.ImageHandler) Vector3D(mcib3d.geom.Vector3D) Point3D(mcib3d.geom.Point3D) ImageFloat(mcib3d.image3d.ImageFloat)

Example 7 with Point3D

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

the class DeformableMesh method getBestDisplacement.

private Vector3D getBestDisplacement(int i) {
    Point3D P = new Point3D(getUniqueVertex(i));
    Point3D closestPlus = getClosestEdge(i, true);
    Point3D closestMinus = getClosestEdge(i, false);
    double distPlus, distMinus;
    Vector3D displ;
    if (closestPlus != null) {
        distPlus = closestPlus.distance(P);
    } else {
        distPlus = Double.MAX_VALUE;
    }
    if (closestMinus != null) {
        distMinus = closestMinus.distance(P);
    } else {
        distMinus = Double.MAX_VALUE;
    }
    if ((distPlus < distMinus) && (closestPlus != null)) {
        displ = new Vector3D(P, closestPlus);
    } else if ((distPlus > distMinus) && (closestMinus != null)) {
        displ = new Vector3D(P, closestMinus);
    } else {
        displ = null;
    }
    return displ;
}
Also used : Vector3D(mcib3d.geom.Vector3D) Point3D(mcib3d.geom.Point3D)

Example 8 with Point3D

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

the class DeformableMesh method getClosestEdge.

private Point3D getClosestEdge(int i, boolean forward) {
    int border = 1;
    ArrayUtil der = new ArrayUtil(computeEdgeDeriche(i, border, forward));
    int pos = der.getFirstLocalExtrema(thresholdMax, thresholdMin);
    if (pos < border) {
        return null;
    }
    double ratio = (pos - border) / (der.getSize() - 2.0 * border);
    Point3D P = new Point3D(vertices.get(i));
    int dir = forward ? 1 : -1;
    P.translate(verticesNormals.get(i).multiply(dir * ratio * maxDistance));
    return P;
}
Also used : Point3D(mcib3d.geom.Point3D) ArrayUtil(mcib3d.utils.ArrayUtil)

Example 9 with Point3D

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

the class DeformableMesh method getOrientedScaling.

public double getOrientedScaling(Vector3D dir) {
    Point3D center = this.getCenterAsVector();
    Vector3D dirN = dir.getNormalizedVector();
    double ratio = 0;
    double r;
    double cpt = 0;
    for (int i = 0; i < forces.size(); i++) {
        Point3D P0 = new Point3D(this.getUniqueVertex(i));
        Point3D P1 = new Point3D(this.getUniqueVertex(i));
        Vector3D force = forces.get(i);
        // IJ.log("Force " + i + " " + force);
        if (force != null) {
            double orient = Math.abs(force.getNormalizedVector().dotProduct(dirN));
            double rat = orient * orient;
            P1.translate(force);
            Vector3D V0 = new Vector3D(center, P0);
            Vector3D V1 = new Vector3D(center, P1);
            r = V1.getLength() / V0.getLength();
            ratio += rat * r;
            cpt += rat;
            if (r > 100) {
                IJ.log("scale " + i + " " + r + " " + orient + " " + force.getLength() + " " + V0.getLength() + " " + V1.getLength() + " " + center + " " + P0 + " " + P1);
            }
        }
    }
    if (cpt > 0) {
        ratio /= cpt;
    } else {
        ratio = 1;
    }
    return ratio;
}
Also used : Vector3D(mcib3d.geom.Vector3D) Point3D(mcib3d.geom.Point3D)

Example 10 with Point3D

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

the class ImageHandler method getHistogram.

public int[] getHistogram(ArrayList<? extends Point3D> mask, int nBins, double min, double max) {
    int[] histo = new int[nBins];
    double coeff = nBins / (max - min);
    int idx;
    for (Point3D p : mask) {
        idx = (int) ((getPixel(p) - min) * coeff);
        if (idx >= 255) {
            histo[255]++;
        } else {
            histo[idx]++;
        }
    }
    return histo;
}
Also used : Point3D(mcib3d.geom.Point3D)

Aggregations

Point3D (mcib3d.geom.Point3D)10 Vector3D (mcib3d.geom.Vector3D)4 Random (java.util.Random)2 Objects3DPopulation (mcib3d.geom.Objects3DPopulation)2 Voxel3D (mcib3d.geom.Voxel3D)2 ImageInt (mcib3d.image3d.ImageInt)2 ObjectCreator3D (mcib3d.geom.ObjectCreator3D)1 ImageFloat (mcib3d.image3d.ImageFloat)1 ImageHandler (mcib3d.image3d.ImageHandler)1 ArrayUtil (mcib3d.utils.ArrayUtil)1