Improved speed in FlatCAMRTreeStorage.

This commit is contained in:
jpcaram 2015-02-06 17:16:11 -05:00
parent 23b20ba716
commit 17a3316ce4
4 changed files with 34 additions and 13 deletions

View File

@ -389,11 +389,11 @@ class Geometry(object):
valid cuts. Finalizes by cutting around the inside edge of
the polygon.
:param polygon:
:param tooldia:
:param seedpoint:
:param overlap:
:return:
:param polygon: Shapely.geometry.Polygon
:param tooldia: Diameter of the tool
:param seedpoint: Shapely.geometry.Point or None
:param overlap: Tool fraction overlap bewteen passes
:return: List of toolpaths covering polygon.
"""
# Current buffer radius
@ -3480,13 +3480,21 @@ class FlatCAMRTreeStorage(FlatCAMRTree):
self.objects = []
# Optimization attempt!
self.indexes = {}
def insert(self, obj):
self.objects.append(obj)
super(FlatCAMRTreeStorage, self).insert(len(self.objects) - 1, obj)
idx = len(self.objects) - 1
self.indexes[obj] = idx
super(FlatCAMRTreeStorage, self).insert(idx, obj)
#@profile
def remove(self, obj):
# Get index in list
objidx = self.objects.index(obj)
# TODO: This is extremely expensive
#objidx = self.objects.index(obj)
objidx = self.indexes[obj]
# Remove from list
self.objects[objidx] = None

View File

@ -0,0 +1,8 @@
# Run kernprof -l -v gerber_parsing_line_profile_1.py
import sys
sys.path.append('../../')
from camlib import *
from shapely.geometry import Polygon
poly = Polygon([(0.0, 0.0), (1.0, 0.0), (1.0, 0.5), (0.0, 0.5)])
result = Geometry.clear_polygon2(poly, 0.01)

View File

@ -0,0 +1,11 @@
import cProfile
import pstats
from camlib import *
from shapely.geometry import Polygon
poly = Polygon([(0.0, 0.0), (1.0, 0.0), (1.0, 0.5), (0.0, 0.5)])
cProfile.run('result = Geometry.clear_polygon2(poly, 0.01)',
'toollist_minimization_profile', sort='cumtime')
p = pstats.Stats('toollist_minimization_profile')
p.sort_stats('cumulative').print_stats(.1)

View File

@ -1,6 +0,0 @@
import cProfile
import pstats
from camlib import *
g = Geometry()