def get_plotting_vtx(vertex_lst):
    leftmost, rightmost, top, bottom = Point_2(), Point_2(), Point_2(
    ), Point_2()
    CGAL_Convex_hull_2.ch_n_point(vertex_lst, top)  # maximal y coordinate.
    CGAL_Convex_hull_2.ch_e_point(vertex_lst,
                                  rightmost)  # maximal x coordinate.
    CGAL_Convex_hull_2.ch_s_point(vertex_lst, bottom)  # minimal y coordinates
    CGAL_Convex_hull_2.ch_w_point(vertex_lst, leftmost)  # minimal x coordinate

    lt, rt = leftmost.x(), rightmost.x()
    tp, btm = top.y(), bottom.y()

    draw_pt_list = []
    for pair in product([lt, rt], [tp, btm]):
        draw_pt_list.append(pair)

    # left_btm_x, left_btm_y= draw_pt_list[1]

    delta_x = (lt + rt) / 2 - 0
    delta_y = (tp + btm) / 2 - 0

    ch_height = tp - btm
    ch_width = rt - lt

    return ch_height, ch_width, delta_x, delta_y
예제 #2
0
파일: mesh.py 프로젝트: FDiot/code_tympan
def to_cgal_point(pt):
    if isinstance(pt, Point_2):
        return pt
    elif isinstance(pt, Point):
        return Point_2(pt.x, pt.y)
    elif isinstance(pt, (tuple, list)):
        assert len(pt) == 2
        return Point_2(*pt)
    else:
        raise TypeError("Don't know how to make a CGAL Point_2 from", pt)
예제 #3
0
def point_location(sector, target):
    try:
        points = []
        for p in sector[::-1]:
            points.append(Point_2(p[0],p[1]))
        target = Point_2(targets[0], targets[1])

        v = bounded_side_2(points, target)
        return v
    except:
        return -1
예제 #4
0
    def create():
        DT = Constrained_Delaunay_triangulation_2()

        pnts = [Point_2(0.0, 0.0), Point_2(1.0, 0.0), Point_2(1.0, 1.0)]

        vhs = [DT.insert(pnt) for pnt in pnts]

        DT.insert_constraint(vhs[0], vhs[1])
        DT.insert_constraint(vhs[1], vhs[2])

        DT.remove_incident_constraints(vhs[1])

        return DT
    def main():
        # Construct two non-intersecting nested polygons
        polygon1 = [
            Point_2(0, 0),
            Point_2(2, 0),
            Point_2(2, 2),
            Point_2(0, 2)
        ]

        polygon2 = [
            Point_2(0.5, 0.5),
            Point_2(1.5, 0.5),
            Point_2(1.5, 1.5),
            Point_2(0.5, 1.5)
        ]

        # Insert the polygons into a constrained triangulation
        cdt = Constrained_Delaunay_triangulation_2()
        insert_polygon(cdt, polygon1)
        insert_polygon(cdt, polygon2)

        # Mark facest that are inside the domain bounded by the polygon
        face_info = mark_domain(cdt)

        plot_triangulated_polygon(cdt, face_info)
예제 #6
0
def to_CGAL_points(points):
    CGAL_pts = []
    for pt in points:
        CGAL_pt = Point_2(pt[0], pt[1])
        CGAL_pts.append(CGAL_pt)

    return CGAL_pts
예제 #7
0
def test_cgal_link_walk():
    DT = Constrained_Delaunay_triangulation_2()

    xys = np.array([[0, 0], [1, 0], [0, 1], [1, 2]], 'f8')
    # in some versions, Point_2 is picky that it gets doubles,
    # not ints.
    pnts = [Point_2(xy[0], xy[1]) for xy in xys]

    vhs = [DT.insert(p) for p in pnts]

    DT.insert_constraint(vhs[0], vhs[2])

    ##

    res0 = cgal_line_walk.line_walk(DT, vhs[0], vhs[1])

    assert not DT.is_constrained(res0[0][1])
    res1 = cgal_line_walk.line_walk(DT, vhs[0], vhs[2])

    assert DT.is_constrained(res1[0][1])

    assert len(cgal_line_walk.line_conflicts(DT, p1=[5, 5], p2=[5, 6])) == 0

    assert len(cgal_line_walk.line_conflicts(DT, p1=[0.5, -0.5],
                                             p2=[0.5, 0.5])) == 0

    assert len(cgal_line_walk.line_conflicts(DT, p1=[-0.5, 0.5], p2=[0.5, 0.5
                                                                     ])) > 0

    res3 = cgal_line_walk.line_conflicts(DT, p1=[0, -1], p2=[2, 1])
    assert len(res3) > 0
    assert res3[0][0] == 'v'
예제 #8
0
def get_sub_segments(p0, p1):
    cdt = Constrained_Delaunay_triangulation_2()
    for s0, s1 in zip(p0, p1):
        cdt.insert_constraint(Point_2(s0[0], s0[1]), Point_2(s1[0], s1[1]))

    d = {v: i for i, v in enumerate(cdt.finite_vertices())}
    subsegments = []
    for edge in cdt.finite_edges():
        if cdt.is_constrained(edge):
            v0 = edge[0].vertex(cdt.ccw(edge[1]))
            v1 = edge[0].vertex(cdt.cw(edge[1]))
            subsegments.append((d[v0], d[v1]))

    points = [(p.x(), p.y()) for p in cdt.points()]

    return points, subsegments
예제 #9
0
def graphWithOpenCV(G, pos, k, extraPt):
    title = "2D Lattice and a Single Voronoi Domain using OpenCV"
    vorPts = []
    img = np.ones((int(W * 0.65), int(W * 0.85), 3), dtype=np.uint8) * 255
    j = W // (np.ceil(np.sqrt(k)).astype(int) * 1.6)
    center = _center(k)
    x = (pos[(center, center)][0] + extraPt.x())
    y = (pos[(center, center)][1] + extraPt.y())
    pts = getVoronoiDomainVertices(G, pos, Point_2(float(x), float(y)))

    for e in G.edges:
        start = (int(j * pos[e[0]][0]), int(j * pos[e[0]][1]))
        end = (int(j * pos[e[1]][0]), int(j * pos[e[1]][1]))
        _drawEdge(img, start, end)

    for n in G.nodes:
        _drawNode(img, (int(j * pos[n][0]), int(j * pos[n][1])))

    _drawNode(img, (int(j * x), int(j * y)), True)
    var = {vorPts.append((int(j * p.x()), int(j * p.y()))) for p in pts}
    cv.polylines(img, [np.array(vorPts)], True, (255, 165, 0), 2)

    img = img[::-1, :, :]
    cv.imwrite(title + '.png', img)
    cv.imshow(title, img)
예제 #10
0
    def after_add_node(self, g, func_name, return_value, **k):
        n = return_value
        my_k = {}
        # re: _index

        xy = k['x']
        pnt = Point_2(k['x'][0], k['x'][1])
        vh = self.g.nodes['vh'][n] = self.DT.insert(pnt)
        self.vh_info[vh] = n
예제 #11
0
def np2cgal(numpy_point):
    from CGAL.CGAL_Kernel import \
        Segment_2,\
        Polygon_2,\
        Point_2,\
        Bbox_2,\
        Iso_rectangle_2,\
        do_intersect
    return Point_2(numpy_point[0], numpy_point[1])
예제 #12
0
def test_2d():
    print("2D Tests")

    p1 = Point_2(0, 0)
    p2 = Point_2(1, 2)
    v1 = Vector_2(1, 1)
    v2 = Vector_2(1, 2)

    # 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_2(2, 3), 8)
    assertion(v1 - v2 == Vector_2(0, -1), 9)
    assertion(v2 * v1 == 3, 10)
    assertion(v2 * 2 == Vector_2(2, 4), 11)
    assertion(2 * v2 == Vector_2(2, 4), "11 bis")
    assertion(v1 / 2 == Vector_2(0.5, 0.5), 12)
    assertion(v1 / 2.0 == Vector_2(0.5, 0.5), 12)
    assertion(-v2 == Vector_2(-1, -2), 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_2(2, 3)
    vect_tmp -= v1
    assertion(vect_tmp == v2, 17)
예제 #13
0
 def dt_insert(self, n, x=None):
     """
     specify x to override the location, otherwise it comes from 
     the grid.
     """
     if x is None:
         x = self.g.nodes['x'][n]
     pnt = Point_2(x[0], x[1])
     assert self.g.nodes['vh'][n] in [0, None]
     vh = self.g.nodes['vh'][n] = self.DT.insert(pnt)
     self.vh_info[vh] = n
예제 #14
0
 def insert(self, *args):
     if len(args) == 2:
         x, y = args
         w = 1
     elif len(args) == 3:
         x, y, w = args
     else:
         print(args)
         return
     pt = Point_2(x, y)
     self._V.insert(Weighted_point_2(pt, w))
예제 #15
0
    def __init__(self, points, alpha):
        if len(points) < 4:
            raise ValueError('Not enough points to compute an alpha shape.')

        self.area = 0
        self.alpha = alpha
        self.points = [Point_2(*p) for p in points]
        self.tri = Delaunay_triangulation_2()
        self.tri.insert(self.points)
        self.triangles = []
        self._add_triangles(self.tri.finite_faces())
        self.saved = None
        self.points_added = False
예제 #16
0
def execute_cgal(pts, res, origin, size):
    """Performs CGAL-NN on the input points.
    First it removes any potential duplicates from the
    input points, as these would cause issues with the
    dictionary-based attribute mapping.
    Then, it creates CGAL Point_2 object from these points,
    inserts them into a CGAL Delaunay_triangulation_2, and
    performs interpolation using CGAL natural_neighbor_coordinate_2
    by finding the attributes (Z coordinates) via the dictionary
    that was created from the deduplicated points.
    """
    from CGAL.CGAL_Kernel import Point_2
    from CGAL.CGAL_Triangulation_2 import Delaunay_triangulation_2
    from CGAL.CGAL_Interpolation import natural_neighbor_coordinates_2
    s_idx = np.lexsort(pts.T); s_data = pts[s_idx,:]
    mask = np.append([True], np.any(np.diff(s_data[:,:2], axis = 0), 1))
    deduped = s_data[mask]
    cpts = list(map(lambda x: Point_2(*x), deduped[:,:2].tolist()))
    zs = dict(zip([tuple(x) for x in deduped[:,:2]], deduped[:,2]))
    tin = Delaunay_triangulation_2()
    for pt in cpts: tin.insert(pt)
    ras = np.zeros([res[1], res[0]])
    yi = 0
    for y in np.arange(origin[1], origin[1] + res[1] * size, size):
        xi = 0
        for x in np.arange(origin[0], origin[0] + res[0] * size, size):
            nbrs = [];
            qry = natural_neighbor_coordinates_2(tin, Point_2(x, y), nbrs)
            if qry[1] == True:
                z_out = 0
                for nbr in nbrs:
                    z, w = zs[(nbr[0].x(), nbr[0].y())], nbr[1] / qry[0]
                    z_out += z * w
                ras[yi, xi] = z_out
            else: ras[yi, xi] = -9999
            xi += 1
        yi += 1
    return ras
예제 #17
0
def gen_grid(ncols=10, nrows=3):
    vhs = np.zeros((nrows, ncols), object)

    DT = Constrained_Delaunay_triangulation_2()

    for row in range(nrows):
        for col in range(ncols):
            vhs[row, col] = DT.insert(Point_2(col, row))

    for row in range(nrows - 1):
        for col in range(ncols):
            DT.insert_constraint(vhs[row, col], vhs[row + 1, col])

    for row in range(nrows):
        for col in range(ncols - 1):
            DT.insert_constraint(vhs[row, col], vhs[row, col + 1])
    return vhs, DT
예제 #18
0
 def interpolate(pt):
     tr = cdt.locate(Point_2(pt[0], pt[1]))
     v1 = tr.vertex(0).point().x(), tr.vertex(0).point().y()
     v2 = tr.vertex(1).point().x(), tr.vertex(1).point().y()
     v3 = tr.vertex(2).point().x(), tr.vertex(2).point().y()
     vxs = [v1, v2, v3]
     if (pt[0], pt[1]) in vxs:
         try: zs[(pt[0], pt[1])]
         except: return False
     tr_area = triangle_area(v1, v2, v3)
     if tr_area == False: return False
     ws = [triangle_area((pt[0], pt[1]), v2, v3) / tr_area,
           triangle_area((pt[0], pt[1]), v1, v3) / tr_area,
           triangle_area((pt[0], pt[1]), v2, v1) / tr_area]
     try: vx_zs = [zs[vxs[i]] for i in range(3)]
     except: return False
     return vx_zs[0] * ws[0] + vx_zs[1] * ws[1] + vx_zs[2] * ws[2]
예제 #19
0
def alpha_shape_with_cgal(coords, alpha):
    """
    Compute the alpha shape of a set of points.
    Retrieved from http://blog.thehumangeo.com/2014/05/12/drawing-boundaries-in-python/

    :param coords : Coordinates of points
    :param alpha: List of alpha values to influence the gooeyness of the border. Smaller numbers don't fall inward as much as larger numbers. 
    Too large, and you lose everything!
    :return: Shapely.MultiPolygons which is the hull of the input set of points
    """

    logger = logging.getLogger("my_hull")

    try:
        from CGAL import CGAL_Alpha_shape_2
        from CGAL.CGAL_Kernel import Point_2, Polygon_2, Vector_2
    except:
        logger.error("CGAL library must be install to use this option, use an other HULL_METHOD")
        raise
        
    alpha_value = np.mean(alpha)
    # Convert to CGAL point
    points = [Point_2(pt[0], pt[1]) for pt in coords]
    # Compute alpha shape
    a = CGAL_Alpha_shape_2.Alpha_shape_2()
    a.make_alpha_shape(points)
    a.set_alpha(alpha_value)
    a.set_mode(CGAL_Alpha_shape_2.REGULARIZED)
    alpha_shape_edges = [a.segment(it) for it in a.alpha_shape_edges()]

    alpha_shape_vertices = [(vertex.point().x(), vertex.point().y()) for vertex in a.alpha_shape_vertices()]

    if len(alpha_shape_vertices) == 0:
        poly_shp = Polygon()
    else:
        rings = find_rings(alpha_shape_vertices, alpha_shape_edges)
        polygons_list = find_polygons(rings)
    
        if not polygons_list:
            poly_shp = Polygon()
        elif len(polygons_list) > 1 :
            poly_shp = MultiPolygon(polygons_list)
        else :
            poly_shp = Polygon(polygons_list[0])

    return poly_shp
예제 #20
0
    def main():
        # Construct two non-intersecting nested polygons
        polygon1 = [Point_2(0, 0), Point_2(2, 0), Point_2(2, 2), Point_2(0, 2)]

        polygon2 = [
            Point_2(0.5, 0.5),
            Point_2(1.5, 0.5),
            Point_2(1.5, 1.5),
            Point_2(0.5, 1.5)
        ]

        polyhedron1 = [
            Point_3(1, 1, -1),
            Point_3(1, -1, -1),
            Point_3(-1, -1, -1),
            Point_3(-1, -1, 1),
            Point_3(-1, 1, 1),
            Point_3(-1, 1, -1),
            Point_3(1, 1, 1),
            Point_3(1, -1, 1)
        ]

        # Insert the polygons into a constrained triangulation
        cdt = Constrained_Delaunay_triangulation_2()
        insert_polygon(cdt, polygon1)
        insert_polygon(cdt, polygon2)

        # Insert the polyhedron into a triangulation
        cdt2 = Delaunay_triangulation_3()
        insert_polyhedron(cdt2, polyhedron1)

        # Mark facest that are inside the domain bounded by the polygon
        face_info = mark_domain(cdt)

        #plot_triangulated_polygon(cdt, face_info)
        fig = plt.figure(figsize=(10, 10))
        ax = fig.gca(projection='3d')
        ax.set_xlim3d(-1.1, 1.1)
        ax.set_ylim3d(-1.1, 1.1)
        ax.set_zlim3d(-1.1, 1.1)
        plot_triangulated_polyhedron(ax, cdt2)
예제 #21
0
def getVoronoiDomainVertices(G, pos, extraLoc):
    points, vert = [], []

    for n in G.nodes:
        points.append(Point_2(pos[n][0], pos[n][1]))
    points.append(extraLoc)
    vd = Voronoi_diagram_2(points)
    assert (vd.is_valid())

    lr = vd.locate(extraLoc)
    if lr.is_face_handle():
        ec_start = lr.get_face_handle().outer_ccb()
        if ec_start.hasNext():
            done = ec_start.next()
            while 1:
                i = ec_start.next()
                v = _getNextVoronoiVertex(i, False)
                if v is not False:
                    vert.append(v)
                if i == done:
                    break
    return np.array(vert)
예제 #22
0
    def build_cgal_cdt(self):
        """
        Builds the constrained delaunay triangulation in CGAL
        """
        # Now find the real triangulation using CGAL
        print "Building constrained Delaunay triangulation"
        DT = Constrained_Delaunay_triangulation_2()
        self.DT = DT

        #dtri.x = self.X[:,0]
        #dtri.y = self.X[:,1]

        vh = np.zeros((len(self.X), ), 'object')
        self.vh_info = {}

        print "Adding points"
        for n, xy in enumerate(self.X):  #range(len(dtri.x)):
            pnt = Point_2(xy[0], xy[1])  # dtri.x[n], dtri.y[n]
            vh[n] = DT.insert(pnt)
            self.vh_info[vh[n]] = n

        print "Adding constraints"
        for a, b in self.edges:
            DT.insert_constraint(vh[a], vh[b])

        # Now populate tri with the triangulation that's in DT
        if cgal_bindings == 'old':
            self.DT_Nedges = len(DT.edges)
            self.DT_Nfaces = len(DT.faces)
        else:
            # New bindings don't explicitly expose number_of_edges because
            # it's actually part of the triangulation datastructure.
            # naive approach:
            self.DT_Nedges = 0
            for e in DT.finite_edges():
                self.DT_Nedges += 1
            self.DT_Nfaces = DT.number_of_faces()
예제 #23
0
from __future__ import print_function
from CGAL.CGAL_Kernel import Point_2
from CGAL.CGAL_Triangulation_2 import Triangulation_2
from CGAL.CGAL_Triangulation_2 import Triangulation_2_Vertex_circulator
from CGAL.CGAL_Triangulation_2 import Triangulation_2_Vertex_handle

points = []
points.append(Point_2(1, 0))
points.append(Point_2(3, 2))
points.append(Point_2(4, 5))
points.append(Point_2(9, 8))
points.append(Point_2(7, 4))
points.append(Point_2(5, 2))
points.append(Point_2(6, 3))
points.append(Point_2(10, 1))

t = Triangulation_2()
t.insert(points)

vc = t.incident_vertices(t.infinite_vertex())

if vc.hasNext():
    done = vc.next()
    iter = Triangulation_2_Vertex_handle()
    while (1):
        iter = vc.next()
        print(iter.point())
        if iter == done:
            break
예제 #24
0
import matplotlib.pyplot as plt
from fealpy.mesh.TriangleMesh import TriangleMesh
from CGAL.CGAL_Kernel import Point_2, Segment_2
from CGAL.CGAL_Triangulation_2 import Constrained_Delaunay_triangulation_2
import meshio


def insert_segments(cdt, segs):
    '''Insert some segments into cdt, here the segs maybe instected
    '''
    pass


p0 = Point_2(0.1, 0.1)
p1 = Point_2(0.8, 0.9)
p2 = Point_2(0.1, 0.8)
p3 = Point_2(0.8, 0.2)
cdt = Constrained_Delaunay_triangulation_2()

cdt.insert_constraint(p0, p1)
cdt.insert_constraint(p2, p3)
d = {j: i for i, j in enumerate(cdt.finite_vertices())}
vs = [v for v in cdt.finite_vertices()]

for edge in cdt.finite_edges():
    if cdt.is_constrained(edge):
        v0 = edge[0].vertex(cdt.ccw(edge[1]))
        v1 = edge[0].vertex(cdt.cw(edge[1]))
        print((d[v0], d[v1]))
예제 #25
0
def compute_alpha_shape(points, alpha):
    """
    Uses CGAL to compute the alpha shape (a concave hull) of a set of points.
    The alpha shape will not contain any interiors.

    Parameters
    ----------
    points : (Mx2) array
        The x and y coordinates of the points
    alpha : float
        Influences the shape of the alpha shape. Higher values lead to more
        edges being deleted.

    Returns
    -------
    alpha_shape : polygon
        The computed alpha shape as a shapely polygon
    """
    points_cgal = [Point_2(*p) for p in points]

    as2 = Alpha_shape_2(points_cgal, 0, REGULAR)
    as2.set_alpha(alpha)

    edges = []
    for e in as2.alpha_shape_edges():
        segment = as2.segment(e)
        edges.append([[segment.vertex(0).x(),
                       segment.vertex(0).y()],
                      [segment.vertex(1).x(),
                       segment.vertex(1).y()]])
    edges = np.array(edges)

    e1s = edges[:, 0].tolist()
    e2s = edges[:, 1].tolist()
    polygons = []

    while len(e1s) > 0:
        polygon = []
        current_point = e2s[0]
        polygon.append(current_point)
        del e1s[0]
        del e2s[0]

        while True:
            try:
                i = e1s.index(current_point)
            except ValueError:
                break

            current_point = e2s[i]
            polygon.append(current_point)
            del e1s[i]
            del e2s[i]

        polygons.append(polygon)

    polygons = [Polygon(p) for p in polygons if len(p) > 2]
    #    largest_polygon = max(polygons, key=lambda p: p.area)
    #    alpha_shapes = [{'exterior': largest_polygon, 'interiors': []}]
    #
    #    for p in polygons:
    #        for a in alpha_shapes:
    #            if a['exterior'] != p and a['exterior'].contains(p):
    #                a['interiors'].append(p)
    #            elif a['exterior'] != p:
    #                alpha_shape.append({'exterior': p, 'interiors': []})

    alpha_shape = MultiPolygon(polygons).buffer(0)

    return alpha_shape
예제 #26
0
    Constrained_Delaunay_triangulation_2_Edge)

from CGAL.CGAL_Kernel import (Point_2, Segment_2)

# 1. The CGAL constrained delaunay triangulation wrapped in the bindings
#    appears to allow intersections, constructing an approximate new vertex

##

# Do I get access to the intersection flag?
# probably not, it's a template parameter

DT = Constrained_Delaunay_triangulation_2()

xy = [[0, 0], [1, 0], [1, 1], [0, -1], [2, 0], [2, 1], [2, 2]]
points = [Point_2(x, y) for x, y in xy]
vh = [DT.insert(p) for p in points]

DT.insert_constraint(vh[0], vh[1])
DT.insert_constraint(vh[1], vh[2])
DT.insert_constraint(vh[1], vh[4])

# DT.insert_constraint(vh3,vh2) # causes a new vertex to be created

# #


def plot_dt(DT, ax=None):
    segs = []

    weights = []
예제 #27
0
from __future__ import print_function
from CGAL.CGAL_Kernel import Point_2
from CGAL.CGAL_Triangulation_2 import Constrained_Delaunay_triangulation_2
from CGAL.CGAL_Triangulation_2 import Constrained_Delaunay_triangulation_2_Vertex_handle
from CGAL import CGAL_Mesh_2

cdt = Constrained_Delaunay_triangulation_2()

#construct a constrained triangulation
va = cdt.insert(Point_2(5., 5.))
vb = cdt.insert(Point_2(-5., 5.))
vc = cdt.insert(Point_2(4., 3.))
vd = cdt.insert(Point_2(5., -5.))
ve = cdt.insert(Point_2(6., 6.))
vf = cdt.insert(Point_2(-6., 6.))
vg = cdt.insert(Point_2(-6., -6.))
vh = cdt.insert(Point_2(6., -6.))

cdt.insert_constraint(va, vb)
cdt.insert_constraint(vb, vc)
cdt.insert_constraint(vc, vd)
cdt.insert_constraint(vd, va)
cdt.insert_constraint(ve, vf)
cdt.insert_constraint(vf, vg)
cdt.insert_constraint(vg, vh)
cdt.insert_constraint(vh, ve)

print("Number of vertices before: ", cdt.number_of_vertices())

#make it conforming Delaunay
CGAL_Mesh_2.make_conforming_Delaunay_2(cdt)
from __future__ import print_function

from CGAL.CGAL_Kernel import Polygon_2
from CGAL.CGAL_Kernel import Point_2

from CGAL import CGAL_Polyline_simplification_2
from CGAL.CGAL_Polyline_simplification_2 import Stop_below_count_ratio_threshold
from CGAL.CGAL_Polyline_simplification_2 import Squared_distance_cost
from CGAL.CGAL_Polyline_simplification_2 import PS2_Constrained_Delaunay_triangulation_plus_2
from CGAL.CGAL_Polyline_simplification_2 import PS2_Constrained_Delaunay_triangulation_plus_2_Constraint_id
from CGAL.CGAL_Polyline_simplification_2 import PS2_Constrained_Delaunay_triangulation_plus_2_Vertex_handle

ptlst = []
ptlst.append(Point_2(0, 0))
ptlst.append(Point_2(0, 1))
ptlst.append(Point_2(1, 1))

# test polygon function
poly = Polygon_2(ptlst)
poly_simplified = CGAL_Polyline_simplification_2.simplify(
    poly, Squared_distance_cost(), Stop_below_count_ratio_threshold(0.5))

# test point version
outlist = []
CGAL_Polyline_simplification_2.simplify(ptlst, Squared_distance_cost(),
                                        Stop_below_count_ratio_threshold(0.5),
                                        outlist)

# test cdt version
polyline1 = []
polyline1.append(Point_2(0, 0))
예제 #29
0
from CGAL.CGAL_Kernel import Point_2
from CGAL import CGAL_Convex_hull_2
from OpenGL.GLUT import *
from OpenGL.GL import *
from OpenGL.GLU import *

Titik = []
Titik.append(Point_2(0, 0))
Titik.append(Point_2(0, 1))
Titik.append(Point_2(1, 0))
Titik.append(Point_2(1, 1))
Titik.append(Point_2(1, 2))
Titik.append(Point_2(2, 0))
Titik.append(Point_2(2, 1))
Titik.append(Point_2(2, 2))
Titik.append(Point_2(3, 0))
Titik.append(Point_2(3, 1))
Titik.append(Point_2(4, 0))

hasil = []
CGAL_Convex_hull_2.ch_graham_andrew(Titik, hasil)

print('Titik yang convexhull :')
for i in hasil:
    print('(', i.x(), ',', i.y(), ')')


def display():
    glClear(GL_COLOR_BUFFER_BIT)  #utk clear semua pixel

    glBegin(
예제 #30
0
from __future__ import print_function
from CGAL.CGAL_HalfedgeDS import HalfedgeDS_modifier
from CGAL.CGAL_HalfedgeDS import HalfedgeDS
from CGAL.CGAL_HalfedgeDS import HalfedgeDS_decorator
from CGAL.CGAL_HalfedgeDS import ABSOLUTE_INDEXING
from CGAL.CGAL_Kernel import Point_2

# declare a modifier interfacing the incremental_builder
m = HalfedgeDS_modifier()

# define a triangle
m.begin_surface(3, 1)
m.add_vertex(Point_2(0, 0))
m.add_vertex(Point_2(0, 1))
m.add_vertex(Point_2(1, 0.5))
m.begin_facet()
m.add_vertex_to_facet(0)
m.add_vertex_to_facet(1)
m.add_vertex_to_facet(2)
m.end_facet()

hds = HalfedgeDS()
# create the triangle in P
hds.delegate(m)
print("(v,f,e) = ", hds.size_of_vertices(), hds.size_of_faces(),
      divmod(hds.size_of_halfedges(), 2)[0])

# clear the modifier
m.clear()

# define another triangle, reusing vertices in the polyhedron