Search in sources :

Example 16 with Point3f

use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.

the class Object3DSurface method createSphere.

/**
 * @param transform
 * @param meridians
 * @param parallels
 * @return
 */
public static List<Point3f> createSphere(GeomTransform3D transform, final int meridians, final int parallels) {
    final double[][][] globe = generateGlobe(meridians, parallels);
    // IJ.log("Computing sphere");
    Vector3D zero_vector = new Vector3D(0, 0, 0);
    for (int j = 0; j < globe.length; j++) {
        for (int k = 0; k < globe[0].length; k++) {
            Vector3D point = new Vector3D(globe[j][k][0], globe[j][k][1], globe[j][k][2]);
            Vector3D res = transform.getVectorTransformed(point, zero_vector);
            globe[j][k][0] = res.getX();
            globe[j][k][1] = res.getY();
            globe[j][k][2] = res.getZ();
        }
    }
    // create triangular faces and add them to the list
    final ArrayList<Point3f> list = new ArrayList<Point3f>();
    for (int j = 0; j < globe.length - 1; j++) {
        // the parallels
        for (int k = 0; k < globe[0].length - 1; k++) {
            // meridian points
            if (j != globe.length - 2) {
                // half quadrant (a triangle)
                list.add(new Point3f((float) globe[j + 1][k + 1][0], (float) globe[j + 1][k + 1][1], (float) globe[j + 1][k + 1][2]));
                list.add(new Point3f((float) globe[j][k][0], (float) globe[j][k][1], (float) globe[j][k][2]));
                list.add(new Point3f((float) globe[j + 1][k][0], (float) globe[j + 1][k][1], (float) globe[j + 1][k][2]));
            }
            if (j != 0) {
                // the other half quadrant
                list.add(new Point3f((float) globe[j][k][0], (float) globe[j][k][1], (float) globe[j][k][2]));
                list.add(new Point3f((float) globe[j + 1][k + 1][0], (float) globe[j + 1][k + 1][1], (float) globe[j + 1][k + 1][2]));
                list.add(new Point3f((float) globe[j][k + 1][0], (float) globe[j][k + 1][1], (float) globe[j][k + 1][2]));
            }
        }
    }
    return list;
}
Also used : Point3f(org.scijava.vecmath.Point3f)

Example 17 with Point3f

use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.

the class Object3DSurface method scale.

public void scale(double scale, Vector3D dir) {
    Vector3D dirN = dir.getNormalizedVector();
    Point3D center = this.getCenterAsVector();
    for (int i = 0; i < faces.size(); i++) {
        Point3f P = this.getVertex(i);
        // Point3D P0 = new Vector3D(P);
        Point3D P0 = new Point3D(P);
        Vector3D V0 = new Vector3D(center, P0);
        double orient = Math.abs((V0.getNormalizedVector()).dotProduct(dirN));
        double sca = 1 + orient * orient * (scale - 1);
        Vector3D V1 = V0.multiply(sca);
        Point3D P1 = new Vector3D(center);
        P1.translate(V1);
        // IJ.log("Scale dir " + i + " " + P + " " + P1+" "+orient+" "+scale+" "+V1);
        P.set(P1.getPoint3f());
    }
    init();
// this.computeUniqueVertices();
}
Also used : Point3f(org.scijava.vecmath.Point3f)

Example 18 with Point3f

use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.

the class Object3DSurface method computeCenter.

@Override
protected void computeCenter() {
    bx = 0;
    by = 0;
    bz = 0;
    Point3f P;
    for (Point3f vertice : vertices) {
        P = vertice;
        bx += P.x;
        by += P.y;
        bz += P.z;
    }
    int nb = vertices.size();
    bx /= nb;
    by /= nb;
    bz /= nb;
    // Need to compute voxels for volume
    volume = -1;
}
Also used : Point3f(org.scijava.vecmath.Point3f)

Example 19 with Point3f

use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.

the class Object3DSurface method computeSmoothSurface_Laplace.

private void computeSmoothSurface_Laplace() {
    HashMap voisins = computeNeighorhood();
    // for (int j = 0; j < vertices.size(); j += 3) {
    // computeNeighborhoodSurface(voisins, j, 0);
    // computeNeighborhoodSurface(voisins, j, 1);
    // computeNeighborhoodSurface(voisins, j, 2);
    // }
    HashMap<Point3f, Point3f> newPoints = new HashMap();
    // Collection e = voisins.keySet();
    Iterator it = faces.iterator();
    int c = 0;
    while (it.hasNext()) {
        Point3f p = (Point3f) it.next();
        Point3f tmp = new Point3f(0, 0, 0);
        Object[] e2 = ((HashSet) voisins.get(p)).toArray();
        for (Object e21 : e2) {
            // if (c == 10) {
            // }
            tmp.add((Point3f) e21);
        }
        tmp.scale(1.0f / e2.length);
        tmp.interpolate(p, 1 - smoothing_factor);
        newPoints.put(p, tmp);
        c++;
    }
    smooth_faces = new ArrayList<Point3f>();
    for (Point3f face : faces) {
        smooth_faces.add(newPoints.get(face));
    }
}
Also used : Point3f(org.scijava.vecmath.Point3f)

Example 20 with Point3f

use of org.scijava.vecmath.Point3f in project mcib3d-core by mcib3d.

the class Object3DSurface method getNormalFace.

// private ArrayList<Vector3D> computeSurfaceNormalsFaces() {
// ArrayList<Vector3D> surf_normals = new ArrayList<Vector3D>();
// for (int i = 0; i < faces.size(); i += 3) {
// Vector3D V1 = new Vector3D(faces.get(i), faces.get(i + 1));
// Vector3D V2 = new Vector3D(faces.get(i + 1), faces.get(i + 2));
// Vector3D N = V1.crossProduct(V2);
// N.normalize();
// surf_normals.add(N);
// }
// 
// return surf_normals;
// }
public Point3f getNormalFace(int idx) {
    if (vertices_faces_index == null) {
        computeUniqueVertices();
    }
    Vector3D N;
    int ba = (idx / 3) * 3;
    Point3f P1 = faces.get(ba);
    Point3f P2 = faces.get(ba + 1);
    Point3f P3 = faces.get(ba + 2);
    // Vector3D P1P2 = new Vector3D(P1, P2);
    // Vector3D P1P3 = new Vector3D(P1, P3);
    Vector3D P1P2 = new Vector3D();
    P1P2.setVectorTwoPoint3f(P1, P2);
    Vector3D P1P3 = new Vector3D();
    P1P3.setVectorTwoPoint3f(P1, P3);
    N = P1P2.crossProduct(P1P3);
    N.normalize();
    return new Point3f((float) N.x, (float) N.y, (float) N.z);
}
Also used : Point3f(org.scijava.vecmath.Point3f)

Aggregations

Point3f (org.scijava.vecmath.Point3f)58 ArrayList (java.util.ArrayList)20 Calibration (ij.measure.Calibration)6 HashMap (java.util.HashMap)5 Color3f (org.scijava.vecmath.Color3f)5 Point (java.awt.Point)4 Color (java.awt.Color)3 Area (java.awt.geom.Area)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 Point3d (com.github.quickhull3d.Point3d)2 QuickHull3D (com.github.quickhull3d.QuickHull3D)2 PolygonRoi (ij.gui.PolygonRoi)2 Rectangle (java.awt.Rectangle)2 AffineTransform (java.awt.geom.AffineTransform)2 HashSet (java.util.HashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Vector3f (org.scijava.vecmath.Vector3f)2 CustomLineMesh (customnode.CustomLineMesh)1 CustomMesh (customnode.CustomMesh)1