- commented the camlib.alpha_shape() as it is not needed but require a huge package (scipy)

This commit is contained in:
Marius Stanciu 2019-04-23 22:03:40 +03:00
parent 1da424e9fb
commit 29d57caacd
1 changed files with 57 additions and 57 deletions

114
camlib.py
View File

@ -46,7 +46,7 @@ import ezdxf
# TODO: Commented for FlatCAM packaging with cx_freeze # TODO: Commented for FlatCAM packaging with cx_freeze
# from scipy.spatial import KDTree, Delaunay # from scipy.spatial import KDTree, Delaunay
from scipy.spatial import Delaunay # from scipy.spatial import Delaunay
from flatcamParsers.ParseSVG import * from flatcamParsers.ParseSVG import *
from flatcamParsers.ParseDXF import * from flatcamParsers.ParseDXF import *
@ -7409,62 +7409,62 @@ def parse_gerber_number(strnumber, int_digits, frac_digits, zeros):
return ret_val return ret_val
def alpha_shape(points, alpha): # def alpha_shape(points, alpha):
""" # """
Compute the alpha shape (concave hull) of a set of points. # Compute the alpha shape (concave hull) of a set of points.
#
@param points: Iterable container of points. # @param points: Iterable container of points.
@param alpha: alpha value to influence the gooeyness of the border. Smaller # @param alpha: alpha value to influence the gooeyness of the border. Smaller
numbers don't fall inward as much as larger numbers. Too large, # numbers don't fall inward as much as larger numbers. Too large,
and you lose everything! # and you lose everything!
""" # """
if len(points) < 4: # if len(points) < 4:
# When you have a triangle, there is no sense in computing an alpha # # When you have a triangle, there is no sense in computing an alpha
# shape. # # shape.
return MultiPoint(list(points)).convex_hull # return MultiPoint(list(points)).convex_hull
#
def add_edge(edges, edge_points, coords, i, j): # def add_edge(edges, edge_points, coords, i, j):
"""Add a line between the i-th and j-th points, if not in the list already""" # """Add a line between the i-th and j-th points, if not in the list already"""
if (i, j) in edges or (j, i) in edges: # if (i, j) in edges or (j, i) in edges:
# already added # # already added
return # return
edges.add( (i, j) ) # edges.add( (i, j) )
edge_points.append(coords[ [i, j] ]) # edge_points.append(coords[ [i, j] ])
#
coords = np.array([point.coords[0] for point in points]) # coords = np.array([point.coords[0] for point in points])
#
tri = Delaunay(coords) # tri = Delaunay(coords)
edges = set() # edges = set()
edge_points = [] # edge_points = []
# loop over triangles: # # loop over triangles:
# ia, ib, ic = indices of corner points of the triangle # # ia, ib, ic = indices of corner points of the triangle
for ia, ib, ic in tri.vertices: # for ia, ib, ic in tri.vertices:
pa = coords[ia] # pa = coords[ia]
pb = coords[ib] # pb = coords[ib]
pc = coords[ic] # pc = coords[ic]
#
# Lengths of sides of triangle # # Lengths of sides of triangle
a = math.sqrt((pa[0]-pb[0])**2 + (pa[1]-pb[1])**2) # a = math.sqrt((pa[0]-pb[0])**2 + (pa[1]-pb[1])**2)
b = math.sqrt((pb[0]-pc[0])**2 + (pb[1]-pc[1])**2) # b = math.sqrt((pb[0]-pc[0])**2 + (pb[1]-pc[1])**2)
c = math.sqrt((pc[0]-pa[0])**2 + (pc[1]-pa[1])**2) # c = math.sqrt((pc[0]-pa[0])**2 + (pc[1]-pa[1])**2)
#
# Semiperimeter of triangle # # Semiperimeter of triangle
s = (a + b + c)/2.0 # s = (a + b + c)/2.0
#
# Area of triangle by Heron's formula # # Area of triangle by Heron's formula
area = math.sqrt(s*(s-a)*(s-b)*(s-c)) # area = math.sqrt(s*(s-a)*(s-b)*(s-c))
circum_r = a*b*c/(4.0*area) # circum_r = a*b*c/(4.0*area)
#
# Here's the radius filter. # # Here's the radius filter.
#print circum_r # #print circum_r
if circum_r < 1.0/alpha: # if circum_r < 1.0/alpha:
add_edge(edges, edge_points, coords, ia, ib) # add_edge(edges, edge_points, coords, ia, ib)
add_edge(edges, edge_points, coords, ib, ic) # add_edge(edges, edge_points, coords, ib, ic)
add_edge(edges, edge_points, coords, ic, ia) # add_edge(edges, edge_points, coords, ic, ia)
#
m = MultiLineString(edge_points) # m = MultiLineString(edge_points)
triangles = list(polygonize(m)) # triangles = list(polygonize(m))
return cascaded_union(triangles), edge_points # return cascaded_union(triangles), edge_points
# def voronoi(P): # def voronoi(P):
# """ # """