Ejemplo n.º 1
0
 def test_homogenize(self):
   coords = [[1.0, 1.0], [0.5, -0.25], [100.0, -50.0]]
   hcoords = [[1.0, 1.0, 1.0], [0.5, -0.25, 1.0], [100.0, -50.0, 1.0]]
   homogenized = geometry.homogenize(tf.constant(coords))
   dehomogenized = geometry.dehomogenize(homogenized)
   scale = tf.constant([10.0, 0.2, .5], shape=[3, 1])
   dehomogenized2 = geometry.dehomogenize(homogenized * scale)
   self.assertAllClose(homogenized, hcoords)
   self.assertAllClose(dehomogenized, coords)
   self.assertAllClose(dehomogenized2, coords)
Ejemplo n.º 2
0
 def test_mat34_transform_planes(self):
     # Some planes...
     planes = tf.convert_to_tensor([[1.0, 2.0, 3.0, 4.0],
                                    [0.5, 0.3, 0.1, 0.0],
                                    [0.0, 1.0, 0.0, 100.0],
                                    [-1.0, 0.0, -1.0, 0.25]])
     # ...and some points
     points = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
     # (Since we know it's all linear, four planes and three
     # points are enough to span all possibilities!)
     i = [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0]]
     m = [[1.0, 0.0, 0.0, 4.0], [0.0, 0.0, -1.0, 5.0], [0.0, 1.0, 0.0, 6.0]]
     # Identity transform doesn't change the planes:
     input_planes = tf.constant(planes)
     identity_planes = geometry.mat34_transform_planes(
         tf.constant(i), input_planes)
     self.assertAllEqual(identity_planes, planes)
     # Transform and inverse transform is the identity:
     self.assertAllEqual(
         geometry.mat34_transform_planes(
             tf.constant(m),
             geometry.mat34_transform_planes(
                 geometry.mat34_pose_inverse(tf.constant(m)),
                 input_planes)), planes)
     # Dot products between planes and points are preserved (since
     # m doesn't change scale):
     input_points = tf.constant(points)
     dot_products = tf.matmul(geometry.homogenize(input_points),
                              planes,
                              transpose_b=True)
     transformed_planes = geometry.mat34_transform_planes(
         tf.constant(m), input_planes)
     transformed_points = geometry.mat34_transform(tf.constant(m),
                                                   input_points)
     transformed_dot_products = tf.matmul(
         geometry.homogenize(transformed_points),
         transformed_planes,
         transpose_b=True)
     self.assertAllClose(dot_products, transformed_dot_products)