jay3sh / cadmium

Python library for Solid Modelling
http://jay3sh.github.com/cadmium
Other
59 stars 15 forks source link

Memory leak #1

Open DeltaFlight opened 12 years ago

DeltaFlight commented 12 years ago

Union consumes about 500 Kb per sphere, though not producing new vertices. Following program was run on a machine with 512Mb memory limit, crashed after making union of 800 identical spheres.

!/usr/bin/python

import sys import math

from cadmium import *

def memory_usage(): """Memory usage of the current process in MB.""" status = None result = {'peak': 0, 'rss': 0} try: status = open('/proc/self/status') for line in status: parts = line.split() key = parts[0][2:-1].lower() if key in result: result[key] = int(parts[1]) / 1024 finally: if status is not None:

        status.close()
return result

s = Sphere(r = 5, center = True) a = s

n = int(sys.argv[1]) for i in xrange(0, n): s = s + a if (i % 100) == 0: print "i =", i, "mem usage", memory_usage()

s.toSTL("1.stl")

Output was:

deltaflight@natty32:~$ time python loop.py 900 i = 0 mem usage {'peak': 148, 'rss': 79} i = 100 mem usage {'peak': 197, 'rss': 127} i = 200 mem usage {'peak': 247, 'rss': 176} i = 300 mem usage {'peak': 297, 'rss': 225} i = 400 mem usage {'peak': 350, 'rss': 277} i = 500 mem usage {'peak': 400, 'rss': 325} i = 600 mem usage {'peak': 450, 'rss': 374} i = 700 mem usage {'peak': 499, 'rss': 422} i = 800 mem usage {'peak': 554, 'rss': 462} Killed

real 2m6.949s user 0m25.714s sys 1m10.208s

deltaflight@natty32:~$ dmesg |tail -2 [ 3123.445580] Out of memory: Kill process 1101 (python) score 934 or sacrifice child [ 3123.445833] Killed process 1101 (python) total-vm:607704kB, anon-rss:474520kB, file-rss:24kB

jay3sh commented 12 years ago

That's a nice experiment. I suspect this is expected behavior though. The library that we use for boolean operations (OpenCASCADE), is not so scalable for long series of boolean operations. To the best of my knowledge, this a known problem in the area of CAD algorithms and it doesn't have perfect solution. Fortunately, a typical design scenario does not require long series of boolean operations. Therefore we can live with the performance

issues for now.

Jayesh http://www.3dtin.com

On Sun, Sep 11, 2011 at 10:50 PM, Alexander Makarov < reply@reply.github.com>wrote:

Union consumes about 500 Kb per sphere, though not producing new vertices. Following program was run on a machine with 512Mb memory limit, crashed after making union of 800 identical spheres.

!/usr/bin/python

import sys import math

from cadmium import *

def memory_usage(): """Memory usage of the current process in MB.""" status = None result = {'peak': 0, 'rss': 0} try: status = open('/proc/self/status') for line in status: parts = line.split() key = parts[0][2:-1].lower() if key in result: result[key] = int(parts[1]) / 1024 finally: if status is not None:

       status.close()

return result

s = Sphere(r = 5, center = True) a = s

n = int(sys.argv[1]) for i in xrange(0, n): s = s + a if (i % 100) == 0: print "i =", i, "mem usage", memory_usage()

s.toSTL("1.stl")

Output was:

deltaflight@natty32:~$ time python loop.py 900 i = 0 mem usage {'peak': 148, 'rss': 79} i = 100 mem usage {'peak': 197, 'rss': 127} i = 200 mem usage {'peak': 247, 'rss': 176} i = 300 mem usage {'peak': 297, 'rss': 225} i = 400 mem usage {'peak': 350, 'rss': 277} i = 500 mem usage {'peak': 400, 'rss': 325} i = 600 mem usage {'peak': 450, 'rss': 374} i = 700 mem usage {'peak': 499, 'rss': 422} i = 800 mem usage {'peak': 554, 'rss': 462} Killed

real 2m6.949s user 0m25.714s sys 1m10.208s

deltaflight@natty32:~$ dmesg |tail -2 [ 3123.445580] Out of memory: Kill process 1101 (python) score 934 or sacrifice child [ 3123.445833] Killed process 1101 (python) total-vm:607704kB, anon-rss:474520kB, file-rss:24kB

Reply to this email directly or view it on GitHub: https://github.com/jayesh3/cadmium/issues/1

DeltaFlight commented 12 years ago

You mean there is no chance of comfort rendering models like this http://www.thingiverse.com/thing:6923 ? Maybe wrong library then? I tried modeling the same in the Art Of Illusion script - and it worked in seconds, not hours. They say the same about Matlab.

jay3sh commented 12 years ago

I would like to see how Art of Illusion does it. Can you provide the script you used for it?

I've so far tested CGAL (used by OpenSCAD) and OpenCASCADE (used by cadmium), and they both consume lot of CPU and memory as number of boolean operations grow. (Also confirmed by the description provided in the thingiverse link you provided). Experience with cadmium won't be different from OpenSCAD, as far as performance is concerned.

I would like to however investigate what other projects do to speed this up,

like the one you mentioned.

Jayesh http://www.3dtin.com

On Mon, Sep 12, 2011 at 3:39 PM, Alexander Makarov < reply@reply.github.com>wrote:

You mean there is no chance of comfort rendering models like this http://www.thingiverse.com/thing:6923 ? Maybe wrong library then? I tried modeling the same in the Art Of Illusion script - and it worked in seconds, not hours. They say the same about Matlab.

Reply to this email directly or view it on GitHub: https://github.com/jayesh3/cadmium/issues/1#issuecomment-2069368

jay3sh commented 12 years ago

Also, when you said you could generate it in seconds in Art-of-Illusion and Matlab, did you mean you could generate the STL in seconds or you could only render the model in seconds?

The algorithms required for rendering are much faster than actually

generating solid models (STL files).

Jayesh http://www.3dtin.com

On Mon, Sep 12, 2011 at 5:22 PM, Jayesh Salvi jayesh@3dtin.com wrote:

I would like to see how Art of Illusion does it. Can you provide the script you used for it?

I've so far tested CGAL (used by OpenSCAD) and OpenCASCADE (used by cadmium), and they both consume lot of CPU and memory as number of boolean operations grow. (Also confirmed by the description provided in the thingiverse link you provided). Experience with cadmium won't be different from OpenSCAD, as far as performance is concerned.

I would like to however investigate what other projects do to speed this

up, like the one you mentioned.

Jayesh http://www.3dtin.com

On Mon, Sep 12, 2011 at 3:39 PM, Alexander Makarov < reply@reply.github.com>wrote:

You mean there is no chance of comfort rendering models like this http://www.thingiverse.com/thing:6923 ? Maybe wrong library then? I tried modeling the same in the Art Of Illusion script - and it worked in seconds, not hours. They say the same about Matlab.

Reply to this email directly or view it on GitHub: https://github.com/jayesh3/cadmium/issues/1#issuecomment-2069368

DeltaFlight commented 12 years ago

Here is an Art of Illusion script. Rendering is instant, converting to triangle mesh and export to stl takes a few seconds.

void knot(spheres, turns, sphereR, r1, r2, innerK, phaseN, phaseDiv) { phase = phaseN * 2 * Math.PI / phaseDiv;

    for (i = 0.0; i < Math.PI*2 * turns; i += Math.PI*2 * turns /spheres) {
            s = new Sphere(sphereR, sphereR, sphereR);
            innerAlpha = i * innerK;
            c = new Vec3(0, 0, r1);
            cs = new CoordinateSystem(c, 0, 0, 0);
            cs.transformCoordinates(Mat4.xrotation(innerAlpha + phase));
            cs.transformCoordinates(Mat4.translation(0, r2, 0));
            cs.transformCoordinates(Mat4.zrotation(i));
            script.addObject(s, cs);
    }

}

spt = 200; turns = 1; r0 = 1; r1 = 1; r2 = 22/2; k = 2; knot(spt, turns, r0, r1, r2, k, 0, 3); knot(spt, turns, r0, r1, r2, k, 1, 3); knot(spt, turns, r0, r1, r2, k, 2, 3);

knot(spt, turns, r0, r1 + r0, r2, -6, 0, 1);

DeltaFlight commented 12 years ago

However, it looks like AOI stl is not really solid, it contains all these hidden sphere parts inside. And matlab implementation does not uses spheres at all, it calculates all triangles explicitly.