Search in sources :

Example 6 with Point3d

use of org.scijava.vecmath.Point3d in project TrakEM2 by trakem2.

the class Compare method createOrigin.

public static Vector3d[] createOrigin(final VectorString3D x, final VectorString3D y, final VectorString3D z, final int transform_type, final Vector3d[] o_ref) {
    // Aproximate an origin of coordinates
    final VectorString3D[] vs = new VectorString3D[] { z, y, x };
    final ArrayList<Point3d> ps = new ArrayList<Point3d>();
    final int[] dir = new int[] { 1, 1, 1 };
    for (int i = 0; i < vs.length; i++) {
        for (int k = i + 1; k < vs.length; k++) {
            double min_dist = Double.MAX_VALUE;
            int ia = 0, ib = 0;
            for (int a = 0; a < vs[i].length(); a++) {
                for (int b = 0; b < vs[k].length(); b++) {
                    final double d = VectorString3D.distance(vs[i], a, vs[k], b);
                    if (d < min_dist) {
                        min_dist = d;
                        ia = a;
                        ib = b;
                    }
                }
            }
            ps.add(new Point3d((vs[i].getPoint(0, ia) + vs[k].getPoint(0, ib)) / 2, (vs[i].getPoint(1, ia) + vs[k].getPoint(1, ib)) / 2, (vs[i].getPoint(2, ia) + vs[k].getPoint(2, ib)) / 2));
            // determine orientation of the VectorString3D relative to the origin
            if (ia > vs[i].length() / 2)
                dir[i] = -1;
            if (ib > vs[k].length() / 2)
                dir[k] = -1;
        // WARNING: we don't check for the case where it contradicts
        }
    }
    final Vector3d origin = new Vector3d();
    final int len = ps.size();
    for (final Point3d p : ps) {
        p.x /= len;
        p.y /= len;
        p.z /= len;
    }
    for (final Point3d p : ps) origin.add(p);
    // aproximate a vector for each axis
    final Vector3d vz = z.sumVector();
    final Vector3d vy = y.sumVector();
    final Vector3d vx = x.sumVector();
    // adjust orientation, so vectors point away from the origin towards the other end of the vectorstring
    vz.scale(dir[0]);
    vy.scale(dir[1]);
    vx.scale(dir[2]);
    /*
		Utils.log2("dir[0]=" + dir[0]);
		Utils.log2("dir[1]=" + dir[1]);
		Utils.log2("dir[2]=" + dir[2]);
		*/
    Vector3d v1 = vx, v2 = vy;
    final Vector3d v3 = vz;
    if (Compare.TRANS_ROT == transform_type || Compare.TRANS_ROT_SCALE == transform_type) {
        // 1 - compute MEDIAL vector: perpendicular to the plane made by peduncle and dorsal lobe
        final Vector3d vc_medial = new Vector3d();
        vc_medial.cross(vz, vy);
        /* // OLD WAY
			// check orientation:
			Vector3d vc_med = new Vector3d(vc_medial);
			vc_med.normalize();
			Vector3d vx_norm = new Vector3d(vx);
			vx_norm.normalize();
			vc_med.add(vx_norm); // adding the actual medial lobe vector
			// if the sum is smaller, then it means it should be inverted (it was the other side)
			if (vc_med.length() < vx_norm.length()) {
				vc_medial.scale(-1);
				Utils.log2("Mirroring X axis");
			}
			*/
        // 2 - compute DORSAL vector: perpedicular to the plane made by v1 and vc_medial
        final Vector3d vc_dorsal = new Vector3d();
        vc_dorsal.cross(vz, vc_medial);
        // check orientation
        final Vector3d vc_dor = new Vector3d(vc_dorsal);
        vc_dor.add(vy);
        // if the sum is smaller, invert
        if (vc_dor.length() < vy.length()) {
            vc_dorsal.scale(-1);
            Utils.log("Mirroring Y axis");
        }
        /*
			if (Compare.TRANS_ROT == transform_type) {
				// just in case, for rounding issues
				vc_medial.normalize();
				vc_dorsal.normalize();
			}
			*/
        v1 = vc_medial;
        v2 = vc_dorsal;
        if (Compare.TRANS_ROT == transform_type && null != o_ref) {
            // Scale each query axis to length of the reference one
            // so that there are no scaling differences.
            v1.normalize();
            v1.scale(o_ref[0].length());
            v2.normalize();
            v2.scale(o_ref[1].length());
            v3.normalize();
            v3.scale(o_ref[2].length());
        }
    }
    return new Vector3d[] { // X axis : medial lobe
    v1, // Y axis : dorsal lobe
    v2, // Z axis : peduncle
    v3, // x,y,z origin of coordinates
    origin };
}
Also used : VectorString3D(ini.trakem2.vector.VectorString3D) Vector3d(org.scijava.vecmath.Vector3d) Point3d(org.scijava.vecmath.Point3d) ArrayList(java.util.ArrayList)

Example 7 with Point3d

use of org.scijava.vecmath.Point3d in project TrakEM2 by trakem2.

the class VectorString3D method computeCenterOfMass.

/*
	static private void transform(Transform3D trans, Transform3D rot, Vector3d v) {
		trans.transform(v);
		rot.transform(v);
	}
	*/
public Point3d computeCenterOfMass() {
    final Point3d v = new Point3d();
    for (int i = 0; i < length; i++) {
        v.x += x[i] / length;
        v.y += y[i] / length;
        v.z += z[i] / length;
    }
    return v;
}
Also used : Point3d(org.scijava.vecmath.Point3d)

Example 8 with Point3d

use of org.scijava.vecmath.Point3d in project TrakEM2 by trakem2.

the class ControlClickBehavior method doProcess.

@Override
public void doProcess(final MouseEvent e) {
    if (!e.isControlDown() || e.getID() != MouseEvent.MOUSE_PRESSED) {
        super.doProcess(e);
        return;
    }
    final Picker picker = universe.getPicker();
    final Content content = picker.getPickedContent(e.getX(), e.getY());
    if (content == null)
        return;
    final Point3d p = picker.getPickPointGeometry(content, e);
    if (p == null) {
        Utils.log("No point was found on content " + content);
        return;
    }
    final Display display = Display.getFront(ls.getProject());
    if (display == null) {
        // If there's no Display, just return...
        return;
    }
    if (display.getLayerSet() != ls) {
        Utils.log("The LayerSet instances do not match");
        return;
    }
    if (ls == null) {
        Utils.log("No LayerSet was found for the Display");
        return;
    }
    final Calibration cal = ls.getCalibration();
    if (cal == null) {
        Utils.log("No calibration information was found for the LayerSet");
        return;
    }
    final double scaledZ = p.z / cal.pixelWidth;
    final Layer l = ls.getNearestLayer(scaledZ);
    if (l == null) {
        Utils.log("No layer was found nearest to " + scaledZ);
        return;
    }
    final Coordinate<?> coordinate = new Coordinate<Object>(p.x / cal.pixelWidth, p.y / cal.pixelHeight, l, null);
    display.center(coordinate);
}
Also used : Coordinate(ini.trakem2.display.Coordinate) Content(ij3d.Content) Point3d(org.scijava.vecmath.Point3d) Picker(ij3d.behaviors.Picker) Calibration(ij.measure.Calibration) Layer(ini.trakem2.display.Layer) Display(ini.trakem2.display.Display)

Aggregations

Point3d (org.scijava.vecmath.Point3d)8 ArrayList (java.util.ArrayList)3 Vector3d (org.scijava.vecmath.Vector3d)2 Calibration (ij.measure.Calibration)1 Content (ij3d.Content)1 Picker (ij3d.behaviors.Picker)1 Ball (ini.trakem2.display.Ball)1 Coordinate (ini.trakem2.display.Coordinate)1 Display (ini.trakem2.display.Display)1 Layer (ini.trakem2.display.Layer)1 ProjectThing (ini.trakem2.tree.ProjectThing)1 VectorString3D (ini.trakem2.vector.VectorString3D)1 HashMap (java.util.HashMap)1 Transform3D (org.scijava.java3d.Transform3D)1 Tuple3d (org.scijava.vecmath.Tuple3d)1