def get_plotter(start=0, stop=0):
        plot_range = ()

        if not start < stop:
            plot_range = (0, len(zone_dict.keys()))  # Plot all
            ch_height, ch_width, delta_x, delta_y = get_plotting_vtx(
                vertex_lst)
            cplot = CarioPlotting(ch_height, ch_width, delta_x, delta_y,
                                  plot_range)
        else:
            plot_range = (start, stop)

            # zone_level = stop - 1  # The most external zone plotted

            pt_lst = []
            vtx_lst = []
            for level in range(start, stop):
                for ch in zone_dict.get(level):
                    pt_lst += ch.get_vertex_list(
                    )  # all points belong to the most external zone

            CGAL_Convex_hull_2.convex_hull_2(pt_lst, vtx_lst)

            ch_height, ch_width, delta_x, delta_y = get_plotting_vtx(vtx_lst)
            cplot = CarioPlotting(ch_height, ch_width, delta_x, delta_y,
                                  plot_range)

        return cplot
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
Beispiel #3
0
    def edges(self, exm_pnt_lst):

        #  generates the counterclockwise sequence of extreme points of the points in the hull

        CGAL_Convex_hull_2.ch_akl_toussaint(exm_pnt_lst, self.pnt_list)

        self.polygon = Polygon_2(self.pnt_list)

        lst_cycle = cycle(self.pnt_list)
        next_elem = next(lst_cycle)

        for i in range(len(self.pnt_list)):
            this_elem, next_elem = next_elem, next(lst_cycle)
            self.edge_list.append(Segment_2(this_elem, next_elem))

            pt_set = {(round(this_elem.x(), 13), round(this_elem.y(), 13)),
                      (round(next_elem.x(), 13), round(next_elem.y(), 13))}  # The two vertexes making up an edge
            self.edge_set_list.append(pt_set)
def convex_hull_2d():
    """Convex hull for two dimensions
    """
    points = []
    points.append(kernel.Point_2(0, 0))
    points.append(kernel.Point_2(1, 0))
    points.append(kernel.Point_2(0, 1))
    points.append(kernel.Point_2(1, 1,))
    points.append(kernel.Point_2(0.5, 0.5))
    points.append(kernel.Point_2(0.25, 0.25))

    result = []
    CGAL_Convex_hull_2.convex_hull_2(points, result)

    for p in result:
        print(p)
    
    points.append(kernel.Point_2(2, 2))
    n = kernel.Point_2()

    CGAL_Convex_hull_2.ch_n_point(points, n)
    print(n)
Beispiel #5
0
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(
        GL_LINES
    )  #untuk membuat garis sumbu x dan y dari x=-1 sampai x=5 dan y=-1 sampai y=5
    glColor3f(0.0, 0.0, 0.0)  #warna garis sumbu x dan y berwarna hitam
    glVertex3f(-1.0, 0.0, 0.0)
    glVertex3f(5.0, 0.0, 0.0)
Beispiel #6
0
from __future__ import print_function
from CGAL.CGAL_Kernel import Point_2
from CGAL import CGAL_Convex_hull_2

L = []
L.append(Point_2(0, 0))
L.append(Point_2(1, 0))
L.append(Point_2(0, 1))
L.append(Point_2(1, 1))
L.append(Point_2(0.5, 0.5))
L.append(Point_2(0.25, 0.25))

result = []
CGAL_Convex_hull_2.convex_hull_2(L, result)

for p in result:
    print(p)

L.append(Point_2(2, 2))
n = Point_2()

CGAL_Convex_hull_2.ch_n_point(L, n)
print(n)
from __future__ import print_function
from CGAL.CGAL_Kernel import Point_2
from CGAL import CGAL_Convex_hull_2

L=[]
L.append( Point_2(0,0) )
L.append( Point_2(1,0) )
L.append( Point_2(0,1) )
L.append( Point_2(1,1) )
L.append( Point_2(0.5,0.5) )
L.append( Point_2(0.25,0.25) )

result = []
CGAL_Convex_hull_2.convex_hull_2(L, result)

for  p in  result:
  print(p)


L.append( Point_2(2,2) )
n=Point_2()

CGAL_Convex_hull_2.ch_n_point(L,n)
print(n)
        planeQuery = Plane_3(newNode[1], planeNormal)
        newIntersections = [newObj.get_Point_3() for newObj in [intersection(planeQuery, newSegment) for newSegment in SurfaceInfo] if (not newObj.empty()) and newObj.is_Point_3()]
        if len(newIntersections) == 0 : 
            print 'big opps!'
        allCrossSectionPoints = []
        maxDist = newNode[2] * 1.2
        for newPt in newIntersections : 
            if squared_distance(newPt, newNode[1]) > maxDist : continue
            if cosinXY != 0 : 
                allCrossSectionPoints.append(Point_2(newPt.x(), newPt.y()))
            elif cosinXZ != 0 : 
                allCrossSectionPoints.append(Point_2(newPt.x(), newPt.z()))
            else : 
                allCrossSectionPoints.append(Point_2(newPt.y(), newPt.z()))
        convexPoints = []
        CGAL_Convex_hull_2.convex_hull_2(allCrossSectionPoints, convexPoints)
        AAA = Polygon_2(convexPoints)
        AAA.edges_circulator
        convexArea = abs(Polygon_2(convexPoints).area())
        if cosinXY != 0 : convexArea /= cosinXY
        elif cosinXZ != 0 : convexArea /= cosinXZ
        else : convexArea /= cosinYZ
        areaMap[newNode[0]] = int(math.sqrt(convexArea / math.pi) * pixelWidth + 0.5)
        normalMap[newNode[0]] = math.acos(cosinXY)
    setArea(newTree, areaMap, parentMap, childrenMap, normalMap)
    print newTree.get('oid') + ' Done!'
    
headerStr = getProjectHeaderString(xmlFile)

print "writing cross sectioned project to", saveFile
writeProject(saveFile, headerStr, mainRoot)
def start_algo(base_pt_list, d_1, d_2, e1_range, e2_range, START, STOP,
               image_name, center_idx):

    # Initialize
    global center, center_x, center_y

    c_1 = (e1_range - 1) / 2
    c_2 = (e2_range - 1) / 2

    for base in base_pt_list:

        for e_1 in range(0, e1_range, 1):

            v_1 = np.dot(d_1, e_1)

            for e_2 in range(0, e2_range, 1):
                v_2 = np.dot(d_2, e_2)

                if e_1 == c_1 and e_2 == c_2 and base_pt_list.index(
                        base) == center_idx:  # all points but center
                    pt = np.add(base, (v_1 + v_2))

                    center_x, center_y = tuple(pt.tolist())

                else:

                    pt = np.add(base, (v_1 + v_2))

                    x, y = tuple(pt.tolist())
                    point_list.append((x, y))
                    pnt_obj_list.append(Point_2(x, y))
                    # print(x, y)

    point_list_bkup = point_list + [(center_x, center_y)]

    center = Point_2(center_x, center_y)
    vertex_lst = []
    CGAL_Convex_hull_2.convex_hull_2(
        pnt_obj_list,
        vertex_lst)  # This function returns a list of all points of the hull

    ch_lhn = ConvexHullLhn(vertex_lst)  # To get the list of edges
    ch_list.append(ch_lhn)  # The first convex hull is added to the list

    cloest_pt_dict = get_closest_pt_dict()

    # Dividing, replacing and tracking
    for layer in cloest_pt_dict.keys()[:]:
        print('Find the ' + str(layer + 1) + '-closest points to center')
        clost_pt_lst = cloest_pt_dict.get(
            layer)  # Get the list of points of this layer

        # This loop handle the first layer
        for closest_pt in clost_pt_lst:  # range(len(closest_pnt_idx))

            bisector_line = get_bisector(center, closest_pt)
            divide_and_replace(bisector_line)

    print("\nDividing, replacing and tracking done.")

    zone_dict = {}
    for ch in ch_list:
        level = ch.get_zone_level()
        if zone_dict.get(level) is None:
            zone_dict[level] = [ch]
        else:
            zone_dict.get(level).append(ch)

    print('\nHOW MANY POLYGONS: ', len(ch_list))
    print('HOW MANY ZONES: ', len(zone_dict.keys()))

    def get_plotter(start=0, stop=0):
        plot_range = ()

        if not start < stop:
            plot_range = (0, len(zone_dict.keys()))  # Plot all
            ch_height, ch_width, delta_x, delta_y = get_plotting_vtx(
                vertex_lst)
            cplot = CarioPlotting(ch_height, ch_width, delta_x, delta_y,
                                  plot_range)
        else:
            plot_range = (start, stop)

            # zone_level = stop - 1  # The most external zone plotted

            pt_lst = []
            vtx_lst = []
            for level in range(start, stop):
                for ch in zone_dict.get(level):
                    pt_lst += ch.get_vertex_list(
                    )  # all points belong to the most external zone

            CGAL_Convex_hull_2.convex_hull_2(pt_lst, vtx_lst)

            ch_height, ch_width, delta_x, delta_y = get_plotting_vtx(vtx_lst)
            cplot = CarioPlotting(ch_height, ch_width, delta_x, delta_y,
                                  plot_range)

        return cplot

    plotter = get_plotter(START, STOP)

    plotter.plot(zone_dict, image_name, 'center_' + str(
        (center.x(), center.y())), point_list_bkup)

    del pnt_obj_list[:]
    del point_list[:]
    del ch_list[:]