summaryrefslogtreecommitdiff
path: root/examples/viewer3DVolume.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/viewer3DVolume.py')
-rw-r--r--examples/viewer3DVolume.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/examples/viewer3DVolume.py b/examples/viewer3DVolume.py
index 7a95d8a..82022f9 100644
--- a/examples/viewer3DVolume.py
+++ b/examples/viewer3DVolume.py
@@ -101,6 +101,19 @@ def load(filename):
return data
+def default_isolevel(data):
+ """Compute a default isosurface level: mean + 1 std
+
+ :param numpy.ndarray data: The data to process
+ :rtype: float
+ """
+ data = data[numpy.isfinite(data)]
+ if len(data) == 0:
+ return 0
+ else:
+ return numpy.mean(data) + numpy.std(data)
+
+
def main(argv=None):
# Parse input arguments
parser = argparse.ArgumentParser(
@@ -171,11 +184,11 @@ def main(argv=None):
else:
# Create dummy data
_logger.warning('Not data file provided, creating dummy data')
- size = 128
- z, y, x = numpy.mgrid[0:size, 0:size, 0:size]
- data = numpy.asarray(
- size**2 - ((x-size/2)**2 + (y-size/2)**2 + (z-size/2)**2),
- dtype='float32')
+ coords = numpy.linspace(-10, 10, 64)
+ z = coords.reshape(-1, 1, 1)
+ y = coords.reshape(1, -1, 1)
+ x = coords.reshape(1, 1, -1)
+ data = numpy.sin(x * y * z) / (x * y * z)
# Set ScalarFieldView data
window.setData(data)
@@ -195,9 +208,7 @@ def main(argv=None):
window.addIsosurface(args.level, '#FF0000FF')
else:
# Add an iso-surface from a function
- window.addIsosurface(
- lambda data: numpy.mean(data) + numpy.std(data),
- '#FF0000FF')
+ window.addIsosurface(default_isolevel, '#FF0000FF')
window.show()
return app.exec_()