예제 #1
0
def test_polygon_mesh_slicer():
    print("Testing Polygon_mesh_slicer...")
    P = get_poly()
    slicer = Polygon_mesh_slicer(P)
    slice = Polylines()
    slicer.slice(Plane_3(1, 0, 0, -0.5), slice)
    assert (slice.size() == 1)
    assert (len(slice[0]) != 0)
예제 #2
0
 def _slice(zpos):
     plane_query = Plane_3(Point_3(0, 0, zpos), vec)
     intersections = list()
     tree.all_intersections(plane_query, intersections)
     if callback is not None:
         callback("Found intersections at %3.3f z" % zpos)
     return (zpos,
             self._intersection_to_segments(intersections, accuracy))
예제 #3
0
intersection = tree.any_intersection(segment_query)
if not intersection.empty():
    # gets intersection object
    op = intersection.value()
    object = op[0]
    if object.is_Point_3():
        print("intersection object is a point")


# computes all intersections with segment query (as pairs object - primitive_id)
intersections = []
tree.all_intersections(segment_query, intersections)

# computes all intersected primitives with segment query as primitive ids
primitives = []
tree.all_intersected_primitives(segment_query, primitives)

# constructs plane query
vec = Vector_3(0.0, 0.0, 1.0)
plane_query = Plane_3(a, vec)

# computes first encountered intersection with plane query
# (generally a segment)
intersection = tree.any_intersection(plane_query)
if not intersection.empty():
    # gets intersection object
    op = intersection.value()
    object = op[0]
    if object.is_Segment_3():
        print("intersection object is a segment")
pts = []
pts.append(Point_3(0, 0, 0))
pts.append(Point_3(0, 1, 0))
pts.append(Point_3(1, 1, 0))
pts.append(Point_3(1, 0, 0))
pts.append(Point_3(0, 0, 1))
pts.append(Point_3(0, 1, 1))
pts.append(Point_3(1, 1, 1))
pts.append(Point_3(1, 0, 1))

res = Polyhedron_3()

CGAL_Convex_hull_3.convex_hull_3(pts, res)

print("convex hull has ", res.size_of_vertices(), " vertices")
print("is strongly convex: ", CGAL_Convex_hull_3.is_strongly_convex_3(res))


planes = []
planes.append(Plane_3(-1, 0, 0, 0))
planes.append(Plane_3(1, 0, 0, -1))
planes.append(Plane_3(0, -1, 0, 0))
planes.append(Plane_3(0, 1, 0, -1))
planes.append(Plane_3(0, 0, -1, 0))
planes.append(Plane_3(0, 0, 1, -1))

res.clear()
CGAL_Convex_hull_3.halfspace_intersection_3(planes, res)
print("halfspace intersection has ", res.size_of_vertices(), " vertices")
예제 #5
0
def AABB_polyhedron_facet_intersection():
    """Facet intersection mode
    AABB (axis aligned bounding boxes)

    The AABB is a data structure for finding intersections

    We do the following:
        * Create a polyhedron
        * Create a segment and plane
        * Find the intersection of segment and plane with polyhedron
    """

    from CGAL.CGAL_Kernel import Point_3
    from CGAL.CGAL_Kernel import Vector_3
    from CGAL.CGAL_Kernel import Plane_3
    from CGAL.CGAL_Kernel import Segment_3
    from CGAL.CGAL_Polyhedron_3 import Polyhedron_3
    from CGAL.CGAL_AABB_tree import AABB_tree_Polyhedron_3_Facet_handle

    p = Point_3(1.0, 0.0, 0.0)
    q = Point_3(0.0, 1.0, 0.0)
    r = Point_3(0.0, 0.0, 1.0)
    s = Point_3(0.0, 0.0, 0.0)
    polyhedron = Polyhedron_3()
    polyhedron.make_tetrahedron(p, q, r, s)

    # construct the AABB tree
    tree = AABB_tree_Polyhedron_3_Facet_handle(polyhedron.facets())

    # construct segment query
    a = Point_3(-0.2, 0.2, -0.2)
    b = Point_3(1.3, 0.2, 1.3)
    segment_query = Segment_3(a,b)

    # do the intersection of segment with polyhedron
    if tree.do_intersect(segment_query):
        print("Intersection")
    else:
        print("No intersection")

    # compute the number of intersections with the segment
    print(tree.number_of_intersected_primitives(segment_query), " intersection")

    # compute first intersection with segment 
    intersection = tree.any_intersection(segment_query)
    if not intersection.empty():
        # get the intersection object
        op = intersection.value()
        object = op[0]
        if object.is_Point_3():
            print("intersection object is a point")

    # compute all intersections with the segment query
    primitives = []
    tree.all_intersected_primitives(segment_query,primitives)

    # construct plane query
    vec = Vector_3(0, 0, 1.0)
    plane_query = Plane_3(Point_3(0, 0, 0.5), vec)
    # compute first intersection of tetrahedron and plane
    intersection = tree.any_intersection(plane_query)
    if not intersection.empty():
        op = intersection.value()
        object = op[0]
        if object.is_Segment_3():
            print("intersection object is a segment")