Skip to content

Commit f87d3d8

Browse files
committed
Test updated and reformatted with black
1 parent c8e643d commit f87d3d8

2 files changed

Lines changed: 124 additions & 116 deletions

File tree

gridData/OpenVDB.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class OpenVDBField(object):
101101
102102
"""
103103

104-
def __init__(self, grid, origin, delta, name='density', tolerance=1e-10):
104+
def __init__(self, grid, origin, delta, name="density", tolerance=1e-10):
105105
"""Initialize an OpenVDB field.
106106
107107
Parameters
@@ -157,30 +157,29 @@ def _populate(self, grid, origin, delta):
157157
"""
158158
grid = numpy.asarray(grid)
159159
if grid.ndim != 3:
160-
raise ValueError(
161-
f"OpenVDB only supports 3D grids, got {grid.ndim}D")
160+
raise ValueError(f"OpenVDB only supports 3D grids, got {grid.ndim}D")
162161

163162
self.grid = grid.astype(numpy.float32)
164-
self.grid=numpy.ascontiguousarray(self.grid, dtype=numpy.float32)
165-
163+
self.grid = numpy.ascontiguousarray(self.grid, dtype=numpy.float32)
164+
166165
self.origin = numpy.asarray(origin)
167166

168167
# Handle delta: could be 1D array or diagonal matrix
169168
delta = numpy.asarray(delta)
170169
if delta.ndim == 2:
171-
if (delta.shape != (3,3)):
170+
if delta.shape != (3, 3):
172171
raise ValueError("delta as a matrix must be 3x3")
173-
172+
174173
if not numpy.allclose(delta, numpy.diag(numpy.diag(delta))):
175174
raise ValueError("Non-orthorhombic cells are not supported")
176-
175+
177176
self.delta = numpy.diag(delta)
178-
177+
179178
elif delta.ndim == 1:
180-
if (len(delta) != 3):
179+
if len(delta) != 3:
181180
raise ValueError("delta must have length-3 for 3D grids")
182-
self.delta=delta
183-
181+
self.delta = delta
182+
184183
else:
185184
raise ValueError(
186185
"delta must be either a length-3 vector or a 3x3 diagonal matrix"
@@ -194,26 +193,26 @@ def write(self, filename):
194193
filename : str
195194
Output filename (should end in .vdb)
196195
197-
"""
198-
196+
"""
197+
199198
vdb_grid = vdb.FloatGrid()
200199
vdb_grid.name = self.name
201200

202201
# this is an explicit linear transform using per-axis voxel sizes
203202
# world = diag(delta) * index + corner_origin
204-
corner_origin = (self.origin - 0.5 * self.delta)
203+
corner_origin = self.origin - 0.5 * self.delta
205204

206205
matrix = [
207206
[self.delta[0], 0.0, 0.0, 0.0],
208207
[0.0, self.delta[1], 0.0, 0.0],
209208
[0.0, 0.0, self.delta[2], 0.0],
210-
[corner_origin[0], corner_origin[1], corner_origin[2], 1.0]
209+
[corner_origin[0], corner_origin[1], corner_origin[2], 1.0],
211210
]
212211

213212
vdb_grid.background = 0.0
214213
vdb_grid.transform = vdb.createLinearTransform(matrix)
215-
214+
216215
vdb_grid.copyFromArray(self.grid, tolerance=self.tolerance)
217216
vdb_grid.prune()
218217

219-
vdb.write(filename, grids=[vdb_grid])
218+
vdb.write(filename, grids=[vdb_grid])

0 commit comments

Comments
 (0)