Search in sources :

Example 1 with Matrix3d

use of org.scijava.vecmath.Matrix3d 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)1 Matrix3d (org.scijava.vecmath.Matrix3d)1 Vector3d (org.scijava.vecmath.Vector3d)1