Esempio n. 1
0
    def _shape_similarity(self, element1, element2):
        """
        Similarity function that compares the bounding boxes of
        <element1> and <element2>

        Inputs:
        element1 (ProjectObject)
        element2 (ProjectObject)

        Return:
        float - bounding box IoU (Equation 1 in SUMO white paper)
        """

        # quick intersection test.  If bounding boxes don't overlap on any single axis,
        # then the enclosed object cannot overlap
        bbox1 = element1.posed_bbox
        bbox2 = element2.posed_bbox
        for axis in range(3):
            if (bbox1.min_corner[axis] > bbox2.max_corner[axis]) or \
               (bbox2.min_corner[axis] > bbox1.max_corner[axis]):
                return 0

        box1 = _bbox2pymesh(element1)
        box2 = _bbox2pymesh(element2)
        inter = pymesh.boolean(box1, box2, operation='intersection')
        ivert, ifaces, _ = remove_duplicated_vertices_raw(
            inter.vertices, inter.faces)
        inter_mesh = pymesh.form_mesh(ivert, ifaces)

        # Note: pymesh may give -volume depending on surface normals
        # or maybe vertex ordering
        intersection = abs(inter_mesh.volume)
        union = abs(box1.volume) + abs(box2.volume) - intersection
        return intersection / union
Esempio n. 2
0
    def _shape_similarity(self, element1, element2):
        """
        Similarity function that compares the bounding boxes of
        <element1> and <element2>

        Inputs:
        element1 (ProjectObject)
        element2 (ProjectObject)

        Return:
        float - bounding box IoU (Equation 1 in SUMO white paper)
        """
        box1 = _bbox2pymesh(element1)
        box2 = _bbox2pymesh(element2)
        inter = pymesh.boolean(box1,
                               box2,
                               operation='intersection',
                               engine='cgal')
        ivert, ifaces, _ = remove_duplicated_vertices_raw(
            inter.vertices, inter.faces)
        inter_mesh = pymesh.form_mesh(ivert, ifaces)

        # Note: pymesh may give -volume depending on surface normals
        # or maybe vertex ordering
        intersection = abs(inter_mesh.volume)
        union = abs(box1.volume) + abs(box2.volume) - intersection
        return intersection / union
    def test_simple_removal(self):
        vertices = np.array([
            [0.0, 0.0, 0.0],
            [0.0, 0.0, 0.0],
            [1.0, 0.0, 0.0],
            [0.0, 1.0, 0.0],
        ],
                            dtype=float)
        faces = np.array([[0, 2, 3], [1, 2, 3]], dtype=int)

        out_vertices, out_faces, __ = remove_duplicated_vertices_raw(
            vertices, faces)

        self.assertEqual(3, len(out_vertices))
        self.assert_array_equal([[0, 1, 2], [0, 1, 2]], out_faces)
    def test_no_removal(self):
        vertices = np.array([
            [ 0.0, 0.0, 0.0],
            [ 1.0, 0.0, 0.0],
            [ 0.0, 1.0, 0.0],
            ], dtype=float)
        faces = np.array([
            [0, 1, 2],
            ], dtype=int)

        out_vertices, out_faces, __ = remove_duplicated_vertices_raw(
                vertices, faces)

        self.assert_array_equal(vertices, out_vertices)
        self.assert_array_equal(faces, out_faces)
    def test_tiny_triangle(self):
        vertices = np.array([
            [ 0.0, 0.0, 0.0],
            [ 0.1, 0.0, 0.0],
            [ 0.0, 0.1, 0.0],
            ], dtype=float)
        faces = np.array([
            [0, 1, 2],
            ], dtype=int)

        out_vertices, out_faces, __ = remove_duplicated_vertices_raw(
                vertices, faces, 1.0)

        self.assertEqual(1, len(out_vertices))
        self.assert_array_equal([[0, 0, 0]], out_faces)