def edge_length(self):
        """
        Return: list of edge lengths (complex) in units of the CRS
        """
        edge = []
        for v in range(len(self.vertex) - 1):  # to prevent index out of range
            edge.append(Segment_3(self.vertex[v], self.vertex[v + 1]))
        edge.append(Segment_3(self.vertex[-1], self.vertex[0]))  # closing edge
        edge_length = []
        for e in edge:
            # CGAL only computes the squared length of Segment_3
            edge_length.append(sqrt(e.squared_length()))

        return edge_length
Exemple #2
0
def test_insert_from_array():
    print("test_insert_from_array")
    s1 = [1, 2, 3, 6, 4, 5]
    s2 = [1, 2, 3, 16, 41, 51]
    s3 = [1, 2, 3, 65, 45, 5]
    s4 = [1, 2, 3, 64, 44, 5]

    segments = [s1, s2, s3, s4]

    tree_seg = AABB_tree_Segment_3_soup()
    tree_seg.insert_from_array(segments)
    assert (tree_seg.size() == 4)

    s = Segment_3(Point_3(1, 2, 3), Point_3(0, 0, 0))
    assert (tree_seg.do_intersect(s))

    t1 = [0, 0, 0, 0, 0, 1, 0, 0, -1]
    t2 = [0, 0, 0, 0, 0, 1, 0, 1, -1]
    t3 = [0, 0, 0, 0, 0, 1, 0, 2, -1]
    t4 = [0, 0, 0, 0, 0, 1, 0, 3, -1]

    triangles = [t1, t2, t3, t4]

    tree_tri = AABB_tree_Triangle_3_soup()
    tree_tri.insert_from_array(triangles)
    assert (tree_tri.size() == 4)

    assert (tree_seg.do_intersect(s))
Exemple #3
0

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)

# constructs AABB tree
tree = AABB_tree_Polyhedron_3_Facet_handle(polyhedron.facets())

# constructs 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)

# tests intersections with segment query
if tree.do_intersect(segment_query):
    print("intersection(s)")
else:
    print("no intersection")

# computes #intersections with segment query
print(tree.number_of_intersected_primitives(segment_query), " intersection(s)")

# computes first encountered intersection with segment query
# (generally a point)
intersection = tree.any_intersection(segment_query)
if not intersection.empty():
    # gets intersection object
Exemple #4
0
def gen_segment_soup(vertices_cgal, edges):
    t0 = time.time()
    soup = [Segment_3(vertices_cgal[e[0]], vertices_cgal[e[1]]) for e in edges]
    print('{:<21} {:>9.5f}'.format('gen_segment_soup', time.time() - t0))
    return soup
Exemple #5
0
    print('{:<21} {:>9.5f}'.format('gen_segment_tree_Nx6', time.time() - t0))
    return tree


#end

# Set sizes.
nx = 100
ny = 100
sepstring = '*' * 31
# Set up some testing primitives
p1 = Point_3(-1, -1, -1)
p2 = Point_3(1, 1, 1)
p3 = Point_3(1, 1, -1)
tri0 = Triangle_3(p1, p2, p3)
seg0 = Segment_3(p1, p2)

# Generate an initial set of points, faces, and edges.
verts = gen_vertices(nx, ny)
faces = gen_faces(nx, ny)
edges = gen_edges(faces)

nverts = len(verts)
nfaces = len(faces)
nedges = len(edges)

# Convert points to list of CGAL Point_3 objects.
t0 = time.time()
verts_cgal = gen_vertices_cgal(verts)
tverts = time.time() - t0
assert nverts == len(verts_cgal)
Exemple #6
0
poly.make_tetrahedron(Point_3(0, 0, 0), Point_3(1, 0, 0), Point_3(0, 1, 0),
                      Point_3(0, 0, 1))
tree = AABB_tree_Polyhedron_3_Facet_handle()

lst = []
for f in poly.facets():
    lst.append(f)

tree.rebuild(lst)
tree = AABB_tree_Polyhedron_3_Facet_handle(lst)
print(tree.size())

lst = []

for f in poly.facets():
    p1 = f.halfedge().vertex().point()
    p2 = f.halfedge().next().vertex().point()
    p3 = f.halfedge().next().next().vertex().point()
    t = Triangle_3(p1, p2, p3)
    lst.append(t)

tree2 = AABB_tree_Triangle_3_soup(lst)

s = Segment_3(Point_3(-0.5, -0.5, 0.5), Point_3(0.5, 0.5, 0.5))

primitives = []
tree2.all_intersected_primitives(s, primitives)

for primitive in primitives:
    print(primitive)
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")