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
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.Plane import Plane
from pycam.Geometry.utils import epsilon, sqrt
......@@ -36,13 +36,13 @@ except ImportError:
GL_enabled = False
class Line(TransformableContainer):
id = 0
class Line(IDGenerator, TransformableContainer):
__slots__ = ["id", "p1", "p2", "_vector", "_minx", "_maxx", "_miny",
"_maxy", "_minz", "_maxz"]
def __init__(self, p1, p2):
super(Line, self).__init__()
self.id = Line.id
Line.id += 1
self.p1 = p1
self.p2 = p2
self.reset_cache()
......
......@@ -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/>.
"""
from pycam.Geometry import TransformableContainer
from pycam.Geometry import TransformableContainer, IDGenerator
from pycam.Geometry.utils import INFINITE, epsilon
from pycam.Geometry.Point import Vector
# "Line" is imported later to avoid circular imports
#from pycam.Geometry.Line import Line
class Plane(TransformableContainer):
id = 0
class Plane(IDGenerator, TransformableContainer):
__slots__ = ["id", "p", "n"]
def __init__(self, point, normal=None):
super(Plane, self).__init__()
self.id = Plane.id
Plane.id += 1
if normal is None:
normal = Vector(0, 0, 1)
self.p = point
......
......@@ -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 import IDGenerator
def _is_near(x, y):
return abs(x - y) < epsilon
class Point(object):
id = 0
class Point(IDGenerator):
__slots__ = ["id", "x", "y", "z", "_norm", "_normsq"]
def __init__(self, x, y, z):
self.id = Point.id
Point.id += 1
super(Point, self).__init__()
self.x = number(x)
self.y = number(y)
self.z = number(z)
......@@ -147,6 +149,8 @@ class Vector(Point):
is necessary for normals (e.g. of Triangles or Planes).
"""
__slots__ = []
def transform_by_matrix(self, matrix, transformed_list=None, callback=None):
x = self.x * matrix[0][0] + self.y * matrix[0][1] \
+ self.z * matrix[0][2]
......
......@@ -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.Plane import Plane
from pycam.Geometry.Line import Line
from pycam.Geometry import TransformableContainer
from pycam.Geometry import TransformableContainer, IDGenerator
import pycam.Utils.log
......@@ -37,13 +37,15 @@ except ImportError:
GL_enabled = False
class Triangle(TransformableContainer):
id = 0
class Triangle(IDGenerator, TransformableContainer):
__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):
self.id = Triangle.id
Triangle.id += 1
# points are expected to be in ClockWise order
super(Triangle, self).__init__()
self.p1 = p1
self.p2 = p2
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