def test_canRasterizeCube(self): """ Vertex values were obtained by dumping the clip-space vertex values from the test_renderSimpleCube test in RenderTest. """ vertices = torch.FloatTensor([ -2.60648608, -3.22707772, 6.85085106, 6.85714293, -1.30324292, -0.992946863, 8.56856918, 8.5714283, -1.30324292, 3.97178817, 7.70971, 7.71428585, -2.60648608, 1.73765731, 5.991992, 6, 1.30324292, -3.97178817, 6.27827835, 6.28571415, 2.60648608, -1.73765731, 7.99599648, 8, 2.60648608, 3.22707772, 7.13713741, 7.14285707, 1.30324292, 0.992946863, 5.41941929, 5.4285717 ]).view(-1, 4) triangles = torch.LongTensor([ 0, 1, 2, 2, 3, 0, 3, 2, 6, 6, 7, 3, 7, 6, 5, 5, 4, 7, 4, 5, 1, 1, 0, 4, 5, 6, 2, 2, 1, 5, 7, 4, 0, 0, 3, 7 ]).view(-1, 3) barycentrics, _, _ = rasterize_triangles_kernels.forward_rasterize_triangles( vertices, triangles, self.image_width, self.image_height) expect_image_file_and_render_are_near( self, "Barycentrics_Cube.png", barycentrics.numpy())
def test_canRasterizeExternalTriangle(self): vertices = torch.FloatTensor([-0.5, -0.5, 0.0, 1.0, 0.0, -0.5, 0.0, -1.0, 0.5, -0.5, 0.0, 1.0]).view(-1, 4) triangles = torch.LongTensor([0, 1, 2]).view(-1, 3) barycentrics, _, _ = rasterize_triangles_kernels.forward_rasterize_triangles( vertices, triangles, self.image_width, self.image_height) expect_image_file_and_render_are_near( self, "External_Triangle.png", barycentrics.numpy())
def test_worksWhenPixelIsOnTriangleEdge(self): image_width = 641 x_pixel = int(image_width / 2) x_ndc = 0.0 yPixel = 5 vertices = torch.FloatTensor([ x_ndc, -1.0, 0.5, 1.0, x_ndc, 1.0, 0.5, 1.0, 0.5, -1.0, 0.5, 1.0 ]).view(-1, 4) triangles = torch.LongTensor([0, 1, 2]).view(-1, 3) barycentrics, _, _ = rasterize_triangles_kernels.forward_rasterize_triangles( vertices, triangles, self.image_width, self.image_height) self.expectIsCovered(barycentrics[yPixel, x_pixel, :].sum()) triangles = torch.LongTensor([2, 1, 0]).view(-1, 3) barycentrics, _, _ = rasterize_triangles_kernels.forward_rasterize_triangles( vertices, triangles, self.image_width, self.image_height) self.expectIsCovered(barycentrics[yPixel, x_pixel, :].sum())
def test_pixelOnDegenerateTriangleIsNotInside(self): """Verifies that the pixels along image edges are correct covered.""" image_width = 1 image_height = 1 vertices = torch.FloatTensor([ -1.0, -1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ]).view(-1, 4) triangles = torch.LongTensor([0, 1, 2]).view(-1, 3) barycentrics, _, _ = rasterize_triangles_kernels.forward_rasterize_triangles( vertices, triangles, image_width, image_height) self.expectIsNotCovered(barycentrics[0, 0, :].sum())
def test_canRasterizeTetrahedron(self): vertices = torch.FloatTensor([ -0.5, -0.5, 0.8, 1.0, 0.0, 0.5, 0.3, 1.0, 0.5, -0.5, 0.3, 1.0, 0.0, 0.0, 0.0, 1.0 ]).view(-1, 4) triangles = torch.LongTensor([ 0, 2, 1, 0, 1, 3, 1, 2, 3, 2, 0, 3 ]).view(-1, 3) barycentrics, _, _ = rasterize_triangles_kernels.forward_rasterize_triangles( vertices, triangles, self.image_width, self.image_height) expect_image_file_and_render_are_near( self, "Simple_Tetrahedron.png", barycentrics.numpy())
def test_coversEdgePixelsOfImage(self): """Verifies that the pixels along image edges are correct covered.""" vertices = torch.FloatTensor([ -1.0, -1.0, 0.0, 1.0, 1.0, -1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, -1.0, 1.0, 0.0, 1.0 ]).view(-1, 4) triangles = torch.LongTensor([0, 1, 2, 0, 2, 3]).view(-1, 3) barycentrics, _, _ = rasterize_triangles_kernels.forward_rasterize_triangles( vertices, triangles, self.image_width, self.image_height) self.expectIsCovered(barycentrics[0, 0, :].sum()) self.expectIsCovered(barycentrics[self.image_height - 1, 0, :].sum()) self.expectIsCovered(barycentrics[self.image_height - 1, self.image_width - 1, :].sum()) self.expectIsCovered(barycentrics[0, self.image_width - 1, :].sum())
def test_canRasterizeCameraInsideBox(self): vertices = torch.FloatTensor([ -1.0, -1.0, 0.0, 2.0, 1.0, -1.0, 0.0, 2.0, 1.0, 1.0, 0.0, 2.0, -1.0, 1.0, 0.0, 2.0, -1.0, -1.0, 0.0, -2.0, 1.0, -1.0, 0.0, -2.0, 1.0, 1.0, 0.0, -2.0, -1.0, 1.0, 0.0, -2.0 ]).view(-1, 4) triangles = torch.LongTensor([ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 2, 3, 7, 2, 7, 6, 1, 0, 4, 1, 4, 5, 0, 3, 7, 0, 7, 4, 1, 2, 6, 1, 6, 5 ]).view(-1, 3) barycentrics, _, _ = rasterize_triangles_kernels.forward_rasterize_triangles( vertices, triangles, self.image_width, self.image_height) expect_image_file_and_render_are_near( self, "Inside_Box.png", barycentrics.numpy())