Commit 32855e03 authored by sumpfralle's avatar sumpfralle

added "__slots__" definitions to memory-relevant classes

* this decreases memory consumption significantly
* see http://docs.python.org/release/2.5.2/ref/slots.html


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1241 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent e3a6a053
...@@ -21,7 +21,7 @@ You should have received a copy of the GNU General Public License ...@@ -21,7 +21,7 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>. along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
from pycam.Geometry import TransformableContainer from pycam.Geometry import TransformableContainer, IDGenerator
from pycam.Geometry.Point import Point from pycam.Geometry.Point import Point
from pycam.Geometry.Plane import Plane from pycam.Geometry.Plane import Plane
from pycam.Geometry.utils import epsilon, sqrt from pycam.Geometry.utils import epsilon, sqrt
...@@ -36,13 +36,13 @@ except ImportError: ...@@ -36,13 +36,13 @@ except ImportError:
GL_enabled = False GL_enabled = False
class Line(TransformableContainer): class Line(IDGenerator, TransformableContainer):
id = 0
__slots__ = ["id", "p1", "p2", "_vector", "_minx", "_maxx", "_miny",
"_maxy", "_minz", "_maxz"]
def __init__(self, p1, p2): def __init__(self, p1, p2):
super(Line, self).__init__() super(Line, self).__init__()
self.id = Line.id
Line.id += 1
self.p1 = p1 self.p1 = p1
self.p2 = p2 self.p2 = p2
self.reset_cache() self.reset_cache()
......
...@@ -20,19 +20,19 @@ You should have received a copy of the GNU General Public License ...@@ -20,19 +20,19 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>. along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
from pycam.Geometry import TransformableContainer from pycam.Geometry import TransformableContainer, IDGenerator
from pycam.Geometry.utils import INFINITE, epsilon from pycam.Geometry.utils import INFINITE, epsilon
from pycam.Geometry.Point import Vector from pycam.Geometry.Point import Vector
# "Line" is imported later to avoid circular imports # "Line" is imported later to avoid circular imports
#from pycam.Geometry.Line import Line #from pycam.Geometry.Line import Line
class Plane(TransformableContainer): class Plane(IDGenerator, TransformableContainer):
id = 0
__slots__ = ["id", "p", "n"]
def __init__(self, point, normal=None): def __init__(self, point, normal=None):
super(Plane, self).__init__() super(Plane, self).__init__()
self.id = Plane.id
Plane.id += 1
if normal is None: if normal is None:
normal = Vector(0, 0, 1) normal = Vector(0, 0, 1)
self.p = point self.p = point
......
...@@ -22,17 +22,19 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -22,17 +22,19 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
from pycam.Geometry.utils import epsilon, sqrt, number from pycam.Geometry.utils import epsilon, sqrt, number
from pycam.Geometry import IDGenerator
def _is_near(x, y): def _is_near(x, y):
return abs(x - y) < epsilon return abs(x - y) < epsilon
class Point(object): class Point(IDGenerator):
id = 0
__slots__ = ["id", "x", "y", "z", "_norm", "_normsq"]
def __init__(self, x, y, z): def __init__(self, x, y, z):
self.id = Point.id super(Point, self).__init__()
Point.id += 1
self.x = number(x) self.x = number(x)
self.y = number(y) self.y = number(y)
self.z = number(z) self.z = number(z)
...@@ -147,6 +149,8 @@ class Vector(Point): ...@@ -147,6 +149,8 @@ class Vector(Point):
is necessary for normals (e.g. of Triangles or Planes). is necessary for normals (e.g. of Triangles or Planes).
""" """
__slots__ = []
def transform_by_matrix(self, matrix, transformed_list=None, callback=None): def transform_by_matrix(self, matrix, transformed_list=None, callback=None):
x = self.x * matrix[0][0] + self.y * matrix[0][1] \ x = self.x * matrix[0][0] + self.y * matrix[0][1] \
+ self.z * matrix[0][2] + self.z * matrix[0][2]
......
...@@ -24,7 +24,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -24,7 +24,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
from pycam.Geometry.Point import Point, Vector from pycam.Geometry.Point import Point, Vector
from pycam.Geometry.Plane import Plane from pycam.Geometry.Plane import Plane
from pycam.Geometry.Line import Line from pycam.Geometry.Line import Line
from pycam.Geometry import TransformableContainer from pycam.Geometry import TransformableContainer, IDGenerator
import pycam.Utils.log import pycam.Utils.log
...@@ -37,13 +37,15 @@ except ImportError: ...@@ -37,13 +37,15 @@ except ImportError:
GL_enabled = False GL_enabled = False
class Triangle(TransformableContainer): class Triangle(IDGenerator, TransformableContainer):
id = 0
__slots__ = ["id", "p1", "p2", "p3", "normal", "minx", "maxx", "miny",
"maxy", "minz", "maxz", "e1", "e2", "e3", "normal", "center",
"radius", "radiussq", "middle"]
# points are expected to be in ClockWise order
def __init__(self, p1=None, p2=None, p3=None, n=None): def __init__(self, p1=None, p2=None, p3=None, n=None):
self.id = Triangle.id # points are expected to be in ClockWise order
Triangle.id += 1 super(Triangle, self).__init__()
self.p1 = p1 self.p1 = p1
self.p2 = p2 self.p2 = p2
self.p3 = p3 self.p3 = p3
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment