示例#1
0
 def test_makestraight(self):
     pos = np.array(
         [
             10 * (random.random() - 0.5),
             10 * (random.random() - 0.5),
             10 * (random.random() - 0.5),
         ]
     )
     for (heading, principal) in permutations(self.dirs, 2):
         if heading != principal:
             vox = vxl.Voxel(
                 pos,
                 self.dirs[heading],
                 self.dirs[principal],
                 self.dirs[heading],
                 self.dirs[principal],
             )
             self.assertEqual(vox.type, self.types["straight"], "straight")
示例#2
0
 def test_makestraighttwist(self):
     pos = np.array(
         [
             10 * (random.random() - 0.5),
             10 * (random.random() - 0.5),
             10 * (random.random() - 0.5),
         ]
     )
     for (heading, principal) in permutations(self.dirs, 2):
         if heading != principal:
             d = "xyz".replace(heading, "").replace(principal, "")
             outPrincipal = self.dirs[d]
             vox = vxl.Voxel(
                 pos,
                 self.dirs[heading],
                 self.dirs[principal],
                 self.dirs[heading],
                 outPrincipal,
             )
             self.assertEqual(vox.type, self.types["straighttwist"], "straighttwist")
示例#3
0
    def test_angles_turn2(self):
        newVoxel = vxl.Voxel(
            np.array([0, 0, 0]),
            self.dirs["z"],
            self.dirs["x"],
            self.dirs["y"],
            self.dirs["x"],
        )
        angles = np.around(np.array([0.0, 0.0, np.pi / 2.0]), 8)
        voxelAngles = np.around(
            np.array([newVoxel.psi, newVoxel.theta, newVoxel.phi]), 8
        )
        self.assertTrue(
            (angles == voxelAngles).all(),
            "voxel has incorrect "
            + "euler angles, \nExpected: "
            + str(angles)
            + "\nFound:   "
            + str(voxelAngles),
        )

        return None
示例#4
0
 def test_turns(self):
     pos = np.array(
         [
             10 * (random.random() - 0.5),
             10 * (random.random() - 0.5),
             10 * (random.random() - 0.5),
         ]
     )
     for (inh, inp, outh, outp) in permutations(self.dirs, 4):
         valid = (inh != outh) and (inh != inp) and (outh != outp)
         if valid:
             vox = vxl.Voxel(
                 pos,
                 self.dirs[inh],
                 self.dirs[inp],
                 self.dirs[outh],
                 self.dirs[outp],
             )
             if inp == outp:
                 self.assertEqual(vox.type, self.types["turn"], "turn")
             else:
                 self.assertEqual(vox.type, self.types["turntwist"], "turntwist")
示例#5
0
class TestVoxFractalMakeVoxelMethod(unittest.TestCase):
    """
    Test when voxels are made within the VoxelisedFractal class as part of the
    makeVoxel static method

    No rotation matrix tests are implemented yet, but these are tested
    under the VoxelisedFractal tests
    """

    xdir = np.array([1, 0, 0])
    ydir = np.array([0, 1, 0])
    zdir = np.array([0, 0, 1])
    dirs = {"x": xdir, "y": ydir, "z": zdir}
    types = vxl.Voxel.types
    reverseTypes = {val: key for (key, val) in types.items()}
    pos1 = np.array([0, 0, 0])
    vox1 = vxl.Voxel(pos1, dirs["x"], dirs["y"], dirs["x"], dirs["y"])

    def test_straight(self):
        currpos = self.pos1 + self.dirs["x"]
        nextpos = currpos + self.dirs["x"]
        newVoxel = vxl.VoxelisedFractal._makeVoxel(self.vox1, currpos, nextpos)
        self.assertTrue((newVoxel.pos == currpos).all(), "newVoxel position mismatch")
        self.assertTrue(
            (newVoxel.inHeading == self.dirs["x"]).all(), "newVoxel inHeading mismatch"
        )
        self.assertTrue(
            (newVoxel.outHeading == self.dirs["x"]).all(),
            "newVoxel outHeading mismatch",
        )
        self.assertTrue(
            (newVoxel.inPrincipal == self.dirs["y"]).all(),
            "newVoxel inPrincipal mismatch",
        )
        self.assertTrue(
            (newVoxel.outPrincipal == self.dirs["y"]).all(),
            "newVoxel outPrincipal mismatch",
        )
        self.assertEqual(
            newVoxel.type,
            self.types["straight"],
            "expected " + "straight, got " + self.reverseTypes[newVoxel.type],
        )

        return None

    def test_turn(self):
        currpos = self.pos1 + self.dirs["x"]
        nextpos = currpos + self.dirs["z"]
        newVoxel = vxl.VoxelisedFractal._makeVoxel(self.vox1, currpos, nextpos)
        self.assertTrue((newVoxel.pos == currpos).all(), "newVoxel position mismatch")
        self.assertTrue(
            (newVoxel.inHeading == self.dirs["x"]).all(), "newVoxel inHeading mismatch"
        )
        self.assertTrue(
            (newVoxel.outHeading == self.dirs["z"]).all(),
            "newVoxel outHeading mismatch",
        )
        self.assertTrue(
            (newVoxel.inPrincipal == self.dirs["y"]).all(),
            "newVoxel inPrincipal mismatch: " + str(newVoxel.inPrincipal),
        )
        self.assertTrue(
            (newVoxel.outPrincipal == -self.dirs["y"]).all(),
            "newVoxel outPrincipal mismatch: " + str(newVoxel.outPrincipal),
        )
        self.assertEqual(
            newVoxel.type,
            self.types["turn"],
            "expected turn, " "got " + self.reverseTypes[newVoxel.type],
        )

        return None

    def test_turntwist(self):
        currpos = self.pos1 + self.dirs["x"]
        nextpos = currpos + self.dirs["y"]
        newVoxel = vxl.VoxelisedFractal._makeVoxel(self.vox1, currpos, nextpos)
        self.assertTrue((newVoxel.pos == currpos).all(), "newVoxel position mismatch")
        self.assertTrue(
            (newVoxel.inHeading == self.dirs["x"]).all(), "newVoxel inHeading mismatch"
        )
        self.assertTrue(
            (newVoxel.outHeading == self.dirs["y"]).all(),
            "newVoxel outHeading mismatch",
        )
        self.assertTrue(
            (newVoxel.inPrincipal == self.dirs["y"]).all(),
            "newVoxel inPrincipal mismatch: " + str(newVoxel.inPrincipal),
        )
        self.assertTrue(
            (newVoxel.outPrincipal == self.dirs["z"]).all(),
            "newVoxel outPrincipal mismatch: " + str(newVoxel.outPrincipal),
        )
        self.assertEqual(
            newVoxel.type,
            self.types["turntwist"],
            "expected " + "turntwist, got " + self.reverseTypes[newVoxel.type],
        )

        return None
示例#6
0
    def test_angles_straights(self):
        origin = np.array([0, 0, 0])
        # Positive Z
        newVoxel = vxl.Voxel(
            origin, self.dirs["z"], self.dirs["x"], self.dirs["z"], self.dirs["x"]
        )
        angles = np.around(np.array([0.0, 0.0, 0.0]), 8)
        voxelAngles = np.around(
            np.array([newVoxel.psi, newVoxel.theta, newVoxel.phi]), 8
        )
        self.assertTrue(
            (angles == voxelAngles).all(),
            "voxel has incorrect "
            + "euler angles, \nExpected: "
            + str(angles)
            + "\nFound:   "
            + str(voxelAngles),
        )

        # Negative Z
        newVoxel = vxl.Voxel(
            origin, -self.dirs["z"], self.dirs["x"], -self.dirs["z"], self.dirs["x"]
        )
        angles = np.around(np.array([np.pi, 0.0, 0.0]), 8)
        voxelAngles = np.around(
            np.array([newVoxel.psi, newVoxel.theta, newVoxel.phi]), 8
        )
        self.assertTrue(
            (angles == voxelAngles).all(),
            "voxel has incorrect "
            + "euler angles, \nExpected: "
            + str(angles)
            + "\nFound:   "
            + str(voxelAngles),
        )

        # Positive X
        newVoxel = vxl.Voxel(
            origin, self.dirs["x"], self.dirs["y"], self.dirs["x"], self.dirs["y"]
        )
        angles = np.around(np.array([np.pi / 2.0, 0, np.pi / 2.0]), 8)
        voxelAngles = np.around(
            np.array([newVoxel.psi, newVoxel.theta, newVoxel.phi]), 8
        )
        self.assertTrue(
            ((angles == voxelAngles).all() or (angles == -voxelAngles).all()),
            "voxel has incorrect "
            + "euler angles,"
            + "\nExpected: "
            + str(angles)
            + "\nFound:   "
            + str(voxelAngles),
        )

        # Negative X
        newVoxel = vxl.Voxel(
            origin, -self.dirs["x"], self.dirs["y"], -self.dirs["x"], self.dirs["y"]
        )
        angles = np.around(np.array([-np.pi / 2.0, 0, np.pi / 2.0]), 8)
        voxelAngles = np.around(
            np.array([newVoxel.psi, newVoxel.theta, newVoxel.phi]), 8
        )
        self.assertTrue(
            (angles == voxelAngles).all() or (angles == -voxelAngles).all(),
            "voxel has incorrect "
            + "euler angles,"
            + "\nExpected: "
            + str(angles)
            + "\nFound:   "
            + str(voxelAngles),
        )

        # Positive Y
        newVoxel = vxl.Voxel(
            origin, self.dirs["y"], self.dirs["x"], self.dirs["y"], self.dirs["x"]
        )
        angles = np.around(np.array([-np.pi / 2.0, 0.0, 0.0]), 8)
        voxelAngles = np.around(
            np.array([newVoxel.psi, newVoxel.theta, newVoxel.phi]), 8
        )
        self.assertTrue(
            (angles == voxelAngles).all(),
            "voxel has incorrect "
            + "euler angles, \nExpected: "
            + str(angles)
            + "\nFound:   "
            + str(voxelAngles),
        )

        # Negative Y
        newVoxel = vxl.Voxel(
            origin, -self.dirs["y"], self.dirs["x"], -self.dirs["y"], self.dirs["x"]
        )
        angles = np.around(np.array([+np.pi / 2.0, 0.0, 0.0]), 8)
        voxelAngles = np.around(
            np.array([newVoxel.psi, newVoxel.theta, newVoxel.phi]), 8
        )
        self.assertTrue(
            (angles == voxelAngles).all(),
            "voxel has incorrect "
            + "euler angles, \nExpected: "
            + str(angles)
            + "\nFound:   "
            + str(voxelAngles),
        )