Пример #1
0
    def test_clone(self):
        # Should be able to clone an instance, modify either and NOT see the
        # change in the other
        l1 = Landmark([1, 2, 3], 4)
        l2 = l1.clone()

        # They should be the same at this point
        numpy.testing.assert_equal(l1.loc, [[1],
                                            [2],
                                            [3]])
        nose.tools.assert_equal(l1.scale, 4)
        numpy.testing.assert_equal(l2.loc, l1.loc)
        nose.tools.assert_equal(l1.scale, l2.scale)

        l1.loc = [[5],
                  [6],
                  [7]]
        numpy.testing.assert_equal(l1.loc, [[5],
                                            [6],
                                            [7]])
        numpy.testing.assert_equal(l2.loc, [[1],
                                            [2],
                                            [3]])

        l2.scale = 8
        nose.tools.assert_equal(l1.scale, 4)
        nose.tools.assert_equal(l2.scale, 8)
Пример #2
0
    def test_type_name(self):
        # Double default
        nose.tools.assert_equal(Landmark().type_name, 'd')
        nose.tools.assert_equal(Landmark(ctype='f').type_name, 'f')

        nose.tools.assert_equal(Landmark([1, 2, 2]).type_name, 'd')
        nose.tools.assert_equal(Landmark([1, 2, 2], ctype='f').type_name, 'f')
Пример #3
0
    def test_get_loc(self):
        for ct in self.C_TYPES:
            print(ct)

            l = Landmark(c_type=ct)
            numpy.testing.assert_equal(l.loc, [[0], [0], [0]])

            l = Landmark([1, 2, 3], c_type=ct)
            numpy.testing.assert_equal(l.loc, [[1], [2], [3]])
Пример #4
0
    def test_get_loc(self):
        for ct in self.ctypeS:
            print(ct)

            l = Landmark(ctype=ct)
            numpy.testing.assert_equal(l.loc, [0,0,0])

            l = Landmark([1, 2, 3], ctype=ct)
            numpy.testing.assert_equal(l.loc, [1,2,3])
Пример #5
0
    def test_set_loc(self):
        for ct in self.C_TYPES:
            print(ct)

            l = Landmark(c_type=ct)
            l.loc = [[1], [1], [1]]
            numpy.testing.assert_equal(l.loc, [[1], [1], [1]])

            l.loc = [[9.12], [4.1], [8.3]]
            numpy.testing.assert_almost_equal(l.loc, [[9.12], [4.1], [8.3]], 6)
Пример #6
0
    def test_normal(self):
        for ct in self.C_TYPES:
            print(ct)
            l = Landmark(c_type=ct)

            # check default
            numpy.testing.assert_equal(l.normal, [[0], [0], [0]])

            l.normal = [[0], [1], [0]]
            numpy.testing.assert_equal(l.normal, [[0], [1], [0]])
Пример #7
0
    def test_observations(self):
        for ct in self.ctypeS:
            print(ct)
            l = Landmark(ctype=ct)

            # default
            nose.tools.assert_equal(l.observations, 0)

            l.observations = 42
            nose.tools.assert_equal(l.observations, 42)
Пример #8
0
    def test_normal(self):
        for ct in self.ctypeS:
            print(ct)
            l = Landmark(ctype=ct)

            # check default
            numpy.testing.assert_equal(l.normal, [0,0,0])

            l.normal = [0,1,0]
            numpy.testing.assert_equal(l.normal, [0,1,0])
Пример #9
0
    def test_covariance(self):
        for ct in self.ctypeS:
            print(ct)
            l = Landmark(ctype=ct)

            # check default
            #nose.tools.assert_equal(l.covariance, Covariance.new_covar(3))

            # set type-aligned covariance
            c = Covariance.new_covar(3, ct, 7)
            l.covariance = c
Пример #10
0
    def test_observations(self):
        for ct in self.C_TYPES:
            print ct
            l = Landmark(c_type=ct)

            # default
            nose.tools.assert_equal(l.observations, 0)

            l.observations = 42
            nose.tools.assert_equal(l.observations, 42)

            def t():
                l.observations = -6
            nose.tools.assert_raises(ValueError, t)
Пример #11
0
    def test_set_loc(self):
        for ct in self.ctypeS:
            print(ct)

            l = Landmark(ctype=ct)
            l.loc = [1,1,1]
            numpy.testing.assert_equal(l.loc, [1, 1, 1])

            l.loc = [9.12,
                     4.1,
                     8.3]
            numpy.testing.assert_almost_equal(l.loc, [9.12,
                                                      4.1,
                                                      8.3], 6)
Пример #12
0
    def test_color(self):
        for ct in self.ctypeS:
            print(ct)
            l = Landmark(ctype=ct)

            # default
            nose.tools.assert_equal(l.color, RGBColor())

            c = RGBColor(0, 0, 0)
            l.color = c
            nose.tools.assert_equal(l.color, c)

            c = RGBColor(12, 240, 120)
            l.color = c
            nose.tools.assert_equal(l.color, c)
Пример #13
0
    def test_get_scale(self):
        for ct in self.ctypeS:
            l = Landmark(ctype=ct)
            print(ct)

            nose.tools.assert_equal(l.scale, 1)

            l = Landmark(scale=17, ctype=ct)
            nose.tools.assert_equal(l.scale, 17)

            l = Landmark(scale=2.22, ctype=ct)
            nose.tools.assert_almost_equal(l.scale, 2.22, 6)

            l = Landmark([3, 4, 5], 44.5, ct)
            nose.tools.assert_almost_equal(l.scale, 44.5, 6)
Пример #14
0
    def test_covariance(self):
        for ct in self.C_TYPES:
            print(ct)
            l = Landmark(c_type=ct)

            # check default
            nose.tools.assert_equal(l.covariance, Covariance(3))

            # set type-aligned covariance
            c = Covariance(3, ct, 7)
            l.covariance = c
            nose.tools.assert_equal(l.covariance, c)

            # set no-necessarily-aligned covariance
            c = Covariance(3, init_scalar_or_matrix=7)
            l.covariance = c
            nose.tools.assert_equal(l.covariance, c)
Пример #15
0
def init_landmarks(num_lm, c=None):
    """
    construct map of landmarks will all locations at ``c`` with IDs in range
    ``[0, num_lm]``.
    """
    if c is None:
        c = EigenArray.from_iterable([0, 0, 0])
    d = {}
    for i in xrange(num_lm):
        d[i] = Landmark(loc=c)
    return LandmarkMap.from_dict(d)
Пример #16
0
    def test_equal(self):
        for ct in self.C_TYPES:
            print(ct)

            l = Landmark(c_type=ct)
            l2 = Landmark(c_type=ct)
            nose.tools.assert_equal(l, l2)

            l = Landmark([1, 1, 1], 42.2, c_type=ct)
            l2 = Landmark([1, 1, 1], 42.2, c_type=ct)
            nose.tools.assert_equal(l, l2)

            norm = [0, 0.5, 0.5]
            covar = Covariance(3, init_scalar_or_matrix=3)
            color = RGBColor(2, 1, 5)
            obs = 43

            l.normal = l2.normal = norm
            l.covariance = l2.covariance = covar
            l.color = l2.color = color
            l.observations = l2.observations = obs
            nose.tools.assert_equal(l, l2)
Пример #17
0
    def test_new(self):
        Landmark()
        Landmark(c_type=ctypes.c_float)

        Landmark([1, 1, 1])
        Landmark([1, 1, 1], c_type=ctypes.c_float)

        Landmark(scale=10)
        Landmark(scale=10, c_type=ctypes.c_float)
Пример #18
0
    def test_new(self):
        Landmark()
        Landmark(ctype='f')

        Landmark([1, 1, 1])
        Landmark([1, 1, 1], ctype='f')

        Landmark(scale=10)
        Landmark(scale=10, ctype='f')
Пример #19
0
def cube_corners(s, c=None):
    """
    Construct map of landmarks at the corners of a cube centered on ``c`` with a
    side length of ``s``.
    :rtype: LandmarkMap
    """
    if c is None:
        c = EigenArray.from_iterable([0, 0, 0])
    s /= 2.
    # Can add lists to numpy.ndarray types
    d = {
        0: Landmark(c + EigenArray.from_iterable([-s, -s, -s])),
        1: Landmark(c + EigenArray.from_iterable([-s, -s, s])),
        2: Landmark(c + EigenArray.from_iterable([-s, s, -s])),
        3: Landmark(c + EigenArray.from_iterable([-s, s, s])),
        4: Landmark(c + EigenArray.from_iterable([s, -s, -s])),
        5: Landmark(c + EigenArray.from_iterable([s, -s, s])),
        6: Landmark(c + EigenArray.from_iterable([s, s, -s])),
        7: Landmark(c + EigenArray.from_iterable([s, s, s])),
    }
    return LandmarkMap.from_dict(d)
Пример #20
0
    def test_set_scale(self):
        for ct in self.ctypeS:
            print(ct)

            l = Landmark(ctype=ct)
            l.scale = 1
            nose.tools.assert_equal(l.scale, 1)

            l.scale = 2
            nose.tools.assert_equal(l.scale, 2)

            l.scale = 2.456
            nose.tools.assert_almost_equal(l.scale, 2.456, 6)

            l.scale = -2
            nose.tools.assert_almost_equal(l.scale, -2, 6)
Пример #21
0
    def test_set_scale(self):
        for ct in self.C_TYPES:
            print ct

            l = Landmark(c_type=ct)
            l.scale = 1
            nose.tools.assert_equal(l.scale, 1)

            l.scale = 2
            nose.tools.assert_equal(l.scale, 2)

            l.scale = 2.456
            nose.tools.assert_almost_equal(l.scale, 2.456, 6)

            l.scale = -2
            nose.tools.assert_almost_equal(l.scale, -2, 6)

            def t():
                l.scale = 'foo'
            nose.tools.assert_raises(ctypes.ArgumentError, t)
Пример #22
0
    def test_from_cptr(self):
        l = Landmark()
        l2 = Landmark(from_cptr=l.c_pointer)
        l2._destroy = lambda: None  # prevent double-free
        nose.tools.assert_equal(l.type_name, l2.type_name)
        numpy.testing.assert_equal(l.loc, l2.loc)
        nose.tools.assert_equal(l.scale, l2.scale)

        l = Landmark(c_type=ctypes.c_float)
        l2 = Landmark(from_cptr=l.c_pointer)
        l2._destroy = lambda: None  # prevent double-free
        nose.tools.assert_equal(l.type_name, l2.type_name)
        numpy.testing.assert_equal(l.loc, l2.loc)
        nose.tools.assert_equal(l.scale, l2.scale)

        l = Landmark([42.1, 234, 0.1234], scale=123.456789)
        l2 = Landmark(from_cptr=l.c_pointer)
        l2._destroy = lambda: None  # prevent double-free
        nose.tools.assert_equal(l.type_name, l2.type_name)
        numpy.testing.assert_equal(l.loc, l2.loc)
        nose.tools.assert_equal(l.scale, l2.scale)