Search in sources :

Example 6 with Transform3D

use of org.scijava.java3d.Transform3D in project TrakEM2 by trakem2.

the class Compare method testCreateOrigin.

public static void testCreateOrigin(final LayerSet ls, final VectorString3D vs1, final VectorString3D vs2, final VectorString3D vs3) {
    try {
        // create vectors
        final double delta = (vs1.getAverageDelta() + vs2.getAverageDelta() + vs3.getAverageDelta()) / 3;
        vs1.resample(delta);
        vs2.resample(delta);
        vs3.resample(delta);
        // 
        final Vector3d[] o = createOrigin(vs1, vs2, vs3, Compare.TRANS_ROT);
        Display3D.addMesh(ls, makeVSFromP(o[0], o[3]), "v1", Color.green);
        Display3D.addMesh(ls, makeVSFromP(o[1], o[3]), "v2", Color.orange);
        Display3D.addMesh(ls, makeVSFromP(o[2], o[3]), "v3", Color.red);
        System.out.println("v1:" + o[0]);
        System.out.println("v2:" + o[1]);
        System.out.println("v3:" + o[2]);
        // create matrix:
        final Matrix3d rotm = new Matrix3d(o[0].x, o[1].x, o[2].x, o[0].y, o[1].y, o[2].y, o[0].z, o[1].z, o[2].z);
        final Transform3D rot = new Transform3D(rotm, new Vector3d(), 1.0);
        rot.invert();
        // DOESN'T WORK // Transform3D trans =  new Transform3D(new Matrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1), new Vector3d(-o[3].x, -o[3].y, -o[3].z), 1.0);
        System.out.println("o3: " + o[3].toString());
        // test:
        for (int i = 0; i < 3; i++) {
            o[i].x += o[3].x;
            o[i].y += o[3].y;
            o[i].z += o[3].z;
        }
        for (int i = 0; i < 3; i++) {
            // can't use translation matrix: doesn't work
            o[i].sub(o[3]);
            // trans.transform(o[i]);
            rot.transform(o[i]);
        }
        // expect: 1, 0, 0
        System.out.println("v1:" + o[0]);
        // expect: 0, 1, 0
        System.out.println("v2:" + o[1]);
        // expect: 0, 0, 1
        System.out.println("v3:" + o[2]);
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : Matrix3d(org.scijava.vecmath.Matrix3d) Vector3d(org.scijava.vecmath.Vector3d) Transform3D(org.scijava.java3d.Transform3D)

Aggregations

Transform3D (org.scijava.java3d.Transform3D)6 Calibration (ij.measure.Calibration)4 Vector3d (org.scijava.vecmath.Vector3d)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Content (ij3d.Content)1 Project (ini.trakem2.Project)1 Line3D (ini.trakem2.display.Line3D)1 ProjectThing (ini.trakem2.tree.ProjectThing)1 VectorString3D (ini.trakem2.vector.VectorString3D)1 Color (java.awt.Color)1 Point (java.awt.Point)1 Point2D (java.awt.geom.Point2D)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 AxisAngle4f (org.scijava.vecmath.AxisAngle4f)1 Color3f (org.scijava.vecmath.Color3f)1 Matrix3d (org.scijava.vecmath.Matrix3d)1 Point3d (org.scijava.vecmath.Point3d)1 Point3f (org.scijava.vecmath.Point3f)1