summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--geometry.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/geometry.py b/geometry.py
index cccf516..1b1f004 100644
--- a/geometry.py
+++ b/geometry.py
@@ -12,6 +12,7 @@ import gzip
standard_wavelengths = np.arange(200, 810, 20).astype(np.float32)
class Mesh(object):
+ "Triangle mesh object."
def __init__(self, vertices, triangles, remove_duplicate_vertices=False):
vertices = np.asarray(vertices, dtype=np.float32)
triangles = np.asarray(triangles, dtype=np.int32)
@@ -74,6 +75,8 @@ class Mesh(object):
return Mesh(np.concatenate((self.vertices, other.vertices)), np.concatenate((self.triangles, other.triangles + len(self.vertices))))
class Solid(object):
+ """Solid object attaches materials, surfaces, and colors to each triangle
+ in a Mesh object."""
def __init__(self, mesh, material1=None, material2=None, surface=None, color=0xffffff):
self.mesh = mesh
@@ -194,27 +197,34 @@ def morton_order(mesh, bits):
return interleave(mean_positions, bits)
class Geometry(object):
+ "Geometry object."
def __init__(self, detector_material=None):
self.detector_material = detector_material
self.solids = []
self.solid_rotations = []
self.solid_displacements = []
- def add_solid(self, solid, rotation=np.identity(3), displacement=(0,0,0)):
+ def add_solid(self, solid, rotation=None, displacement=None):
"""
Add the solid `solid` to the geometry. When building the final triangle
mesh, `solid` will be placed by rotating it with the rotation matrix
`rotation` and displacing it by the vector `displacement`.
"""
- rotation = np.asarray(rotation, dtype=np.float32)
+ if rotation is None:
+ rotation = np.identity(3)
+ else:
+ rotation = np.asarray(rotation, dtype=np.float32)
if rotation.shape != (3,3):
raise ValueError('rotation matrix has the wrong shape.')
self.solid_rotations.append(rotation.astype(np.float32))
- displacement = np.asarray(displacement, dtype=np.float32)
+ if displacement is None:
+ displacement = np.zeros(3)
+ else:
+ displacement = np.asarray(displacement, dtype=np.float32)
if displacement.shape != (3,):
raise ValueError('displacement vector has the wrong shape.')