Esempio n. 1
0
 def get_slice(self, z_level):
     """Calculates the polygons in the slice for a plane."""
     unsorted_lines = []
     for triangle in self.triangles:
         if (triangle[0, 2] < z_level) and (triangle[2, 2] > z_level):
             intersection = self.get_z_intersect(triangle, z_level)
             unsorted_lines.append(intersection)
         elif (triangle[0, 2] == z_level) and (triangle[2, 2] == z_level):
             print "WARNING: Triangle in z_level!"
     if not unsorted_lines == []:
         # Arrange the line segments so that each segment leads to the
         # nearest available segment. This is accomplished by using two
         # list of lines, and at each step moving the nearest available
         # line segment from the unsorted pile to the next slot in the
         # sorted pile.
         epsilon = 1e-9
         polygons = []
         point1, point2 = unsorted_lines[0]
         polygon = [point1, point2]
         unsorted_lines.pop(0)
         while unsorted_lines:
             last_point = polygon[-1]
             do_flip, new_line = False, True
             for i, (point1, point2) in enumerate(unsorted_lines):
                 if calc.distance2(last_point, point1) < epsilon:
                     do_flip, new_line = False, False
                     break
                 if calc.distance2(last_point, point2) < epsilon:
                     do_flip, new_line = True, False
                     break
                 new_line = True
             point1, point2 = unsorted_lines[i]
             unsorted_lines.pop(i)
             if new_line:
                 polygons.append(np.array(polygon))
                 polygon = [point1, point2]
             else:
                 if do_flip:
                     if not (calc.distance2(polygon[-1], point1) < epsilon):
                         polygon.append(point1)
                 else:
                     if not (calc.distance2(polygon[-1], point2) < epsilon):
                         polygon.append(point2)
         polygons.append(np.array(polygon))
         return [
             filter_polyline(polygon, dist=0, angl=0)
             for polygon in polygons
         ]  # Polygons filter
     else:
         return None
Esempio n. 2
0
 def get_slice(self, z_level):
     """Calculates the polygons in the slice for a plane."""
     unsorted_lines = []
     for triangle in self.triangles:
         if (triangle[0, 2] < z_level) and (triangle[2, 2] > z_level):
             intersection = self.get_z_intersect(triangle, z_level)
             unsorted_lines.append(intersection)
         elif (triangle[0, 2] == z_level) and (triangle[2, 2] == z_level):
             print "WARNING: Triangle in z_level!"
     if not unsorted_lines == []:
         # Arrange the line segments so that each segment leads to the
         # nearest available segment. This is accomplished by using two
         # list of lines, and at each step moving the nearest available
         # line segment from the unsorted pile to the next slot in the
         # sorted pile.
         epsilon = 1e-9
         polygons = []
         point1, point2 = unsorted_lines[0]
         polygon = [point1, point2]
         unsorted_lines.pop(0)
         while unsorted_lines:
             last_point = polygon[-1]
             do_flip, new_line = False, True
             for i, (point1, point2) in enumerate(unsorted_lines):
                 if calc.distance2(last_point, point1) < epsilon:
                     do_flip, new_line = False, False
                     break
                 if calc.distance2(last_point, point2) < epsilon:
                     do_flip, new_line = True, False
                     break
                 new_line = True
             point1, point2 = unsorted_lines[i]
             unsorted_lines.pop(i)
             if new_line:
                 polygons.append(np.array(polygon))
                 polygon = [point1, point2]
             else:
                 if do_flip:
                     if not (calc.distance2(polygon[-1], point1) < epsilon):
                         polygon.append(point1)
                 else:
                     if not (calc.distance2(polygon[-1], point2) < epsilon):
                         polygon.append(point2)
         polygons.append(np.array(polygon))
         return [filter_polyline(polygon, dist=0,
                                 angl=0) for polygon in polygons]  # Polygons filter
     else:
         return None
Esempio n. 3
0
def filter_polyline(points, dist=0.1, angl=0.01):
    if len(points) > 3:
        pnts = [points[0]]
        ang_min, ang_max = np.pi - angl, np.pi + angl
        for k in range(len(points)):
            point1, point2, point3 = pnts[-1], points[k-1], points[k]
            d12 = calc.distance2(point1, point2)
            #d23 = calc.distance2(point2, point3)
            if d12 <= dist:
                continue
            else:
                a123 = calc.angle(point1, point2, point3)
                if (a123 >= ang_min and a123 <= ang_max):
                    continue
            pnts.append(point2)
        pnts.append(points[-1])
        points = np.array(pnts)
    return points