def test_3d():
    print("3D Tests")

    p1 = Point_3(0, 0, 0)
    p2 = Point_3(1, 2, 0)
    v1 = Vector_3(1, 1, 0)
    v2 = Vector_3(1, 2, 0)

    # operations on points
    assertion(p1 + v2 == p2, 1)
    assertion(p1 - v2 < p2, 2)
    assertion(p2 - p1 == v2, 3)
    assertion(p2 - ORIGIN == v2, 3.1)
    assertion(p2 > p1, 4)
    assertion(p2 >= p2, 5)
    assertion(p2 <= p2, 6)
    assertion(p2 != p1, 7)

    # operations on vector
    assertion(v1 + v2 == Vector_3(2, 3, 0), 8)
    assertion(v1 - v2 == Vector_3(0, -1, 0), 9)
    assertion(v2 * v1 == 3, 10)
    assertion(v2 * 2 == Vector_3(2, 4, 0), 11)
    assertion(2 * v2 == Vector_3(2, 4, 0), "11 bis")
    assertion(v1 / 2 == Vector_3(0.5, 0.5, 0), 12)
    assertion(v1 / 2.0 == Vector_3(0.5, 0.5, 0), 12)
    assertion(-v2 == Vector_3(-1, -2, 0), 13)
    assertion(v2 != v1, 14)

    # operations on ORIGIN/NULL_VECTOR
    assertion(ORIGIN - p2 == -v2, 14)
    assertion(ORIGIN + v2 == p2, 15)
    assertion(p1 == ORIGIN, 15.1)
    assertion(p1 - p1 == NULL_VECTOR, 15.2)

    # test inplace operations
    pt_tmp = p1.deepcopy()
    pt_tmp += v2
    assertion(pt_tmp == p2, 16)

    vect_tmp = Vector_3(2, 3, 0)
    vect_tmp -= v1
    assertion(vect_tmp == v2, 17)
示例#2
0
    def generate_planar_intersections(self,
                                      start_height,
                                      inc_height,
                                      max_height,
                                      accuracy=4,
                                      processes=None,
                                      callback=None):
        """Generates a series of slices from height start_height and then
        every additional inc_height units."""
        #This is a CGAL tree that makes for fast slicening!
        LOGGER.info("Start of AABB tree generation.")
        tree = AABB_tree_Polyhedron_3_Facet_handle(self.poly.facets())
        LOGGER.info("Done AABB tree generation.")
        zpos = start_height
        # This should _really_ be the max height from a bounding box eh?
        vec = Vector_3(0, 0, 1)

        def zrange(start_height, inc_height, max_height):
            positions = list()
            zpos = start_height
            while True:
                positions.append(zpos)
                zpos += inc_height
                if zpos > max_height:
                    break
            return positions

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

        #Surprise surprise, this is faster single threaded :(
        #I'll have to modify things to be runnable in a sub func,
        #Or maybe write my own process wrapper
        layers = map(_slice, zrange(start_height, inc_height, max_height))

        return layers
示例#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")
示例#4
0
# Insertions
idx = points.insert()
print("Point", idx, "inserted =", points.point(idx))
idx = points.insert(Point_3(0, 1, 2))
print("Point", idx, "inserted =", points.point(idx))
points.insert_range([2., 4., 5., 2, 3, 4])

# Iterate and display points
print("Point set:")
for p in points.points():
    print(" *", p)

# With normal
points.add_normal_map()
idx = points.insert(Point_3(6, 7, 8), Vector_3(1, 1, 1))
print("Point", idx, "inserted = (", points.point(idx), "), (",
      points.normal(idx), ")")

# Access/modification through normal map
normal_map = points.normal_map()
if normal_map.is_valid:
    print("Normal 3 =", normal_map.get(3))
    normal_map.set(2, Vector_3(1, 2, 3))
    print("Normal 2 =", normal_map.get(2))

# Iterate and display normals
print("Normal set:")
for n in points.normals():
    print(" *", n)
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")
示例#6
0
文件: mesh.py 项目: FDiot/code_tympan
    Mesh_2_Constrained_Delaunay_triangulation_plus_2 as CDT,
    Mesh_2_Constrained_Delaunay_triangulation_plus_2_Face_handle as
    Face_handle,
    Ref_Mesh_2_Constrained_Delaunay_triangulation_plus_2_Face_handle as
    Ref_Face_handle,
    Mesh_2_Constrained_Delaunay_triangulation_plus_2_Vertex_handle as
    Vertex_handle, Mesh_2_Constrained_Delaunay_triangulation_plus_2_Edge as
    Edge, Delaunay_mesh_plus_size_criteria_2 as Mesh_criteria,
    refine_Delaunay_mesh_2 as CGAL_refine_Delaunay_mesh)
from CGAL.CGAL_Triangulation_2 import (Ref_Locate_type_2 as Ref_locate_type,
                                       VERTEX, EDGE, FACE, OUTSIDE_CONVEX_HULL,
                                       OUTSIDE_AFFINE_HULL)
import collections
from functools import reduce

Z_VECTOR = Vector_3(0, 0, 1)
_PROXIMITY_THRESHOLD = 0.01

# Monkey patch Edge to work around issue
# http://code.google.com/p/cgal-bindings/issues/detail?id=48
Edge.__iter__ = lambda this: iter((this[0], this[1]))

from .datamodel import InconsistentGeometricModel, DEFAULT_MATERIAL, HIDDEN_MATERIAL

UNSPECIFIED_ALTITUDE = float('nan')
UNSPECIFIED_MATERIAL = None


def to_cgal_point(pt):
    if isinstance(pt, Point_2):
        return pt