def test_move_voxels_to_origin(self): voxels = self.createTestObject([5, 5, 5]) voxels.data[3:5, 3:5, 3:5] = 1.0 VoxelUtils.move_voxels_to_origin(voxels) bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [1, 1, 1])
def test_move_aabb_to_center(self): voxels = self.createTestObject([5, 5, 5]) voxels.data[0:3, 0:3, 0:3] = 1.0 # put centroid at 1, 1, 1 VoxelUtils.move_aabb_to_center(voxels) bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [1, 1, 1]) self.assertEqual(bbox['max'], [3, 3, 3])
def test_expand_voxels_to_dims(self): voxels = self.createTestObject([5, 5, 5]) voxels.data[0:2, 0:2, 0:2] = 1.0 VoxelUtils.expand_voxels_to_dims(10, 10, 10, voxels) self.assertEqual(voxels.data.shape, (10, 10, 10)) self.assertEqual(voxels.data[0, 0, 0], 1) bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [1, 1, 1])
def test_uniform_scale(self): voxels = self.createTestObject([10, 10, 10]) voxels.data[3:5, 3:5, 3:5] = 1.0 bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [3, 3, 3]) self.assertEqual(bbox['max'], [4, 4, 4]) scale = 4.0 VoxelUtils.uniform_scale(scale, voxels) bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [7, 7, 7])
def test_blit_voxels_into_target(self): target = self.createTestObject([10, 10, 10]) src = self.createTestObject([2, 2, 2]) src.data[0:2, 0:2, 0:2] = 1.0 offset = [2, 2, 2] VoxelUtils.blit_voxels_into_target(offset, src, target) self.assertEqual(target.data[2, 2, 2], 1) self.assertEqual(target.data[3, 2, 2], 1) bbox = VoxelUtils.calculate_bounding_box(target) self.assertEqual(bbox['min'], [2, 2, 2]) self.assertEqual(bbox['max'], [3, 3, 3])
def test_calculate_bounding_box(self): voxels = self.createTestObject([10, 10, 10]) voxels.data[0:2, 0:2, 0:2] = 1.0 # Slicing doesn't include the last index. bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [1, 1, 1])
def test_create_simple_grid_layout(self): target = self.createTestObject([4, 4, 4]) src2 = self.createTestObject([2, 2, 2]) src2.data[0, 0, 0] = 1.0 srcList = [src2, src2] srcDims = src2.dims VoxelUtils.create_simple_grid_layout(srcList, srcDims, target) self.assertEqual(target.data[0, 0, 0], 1) self.assertEqual(target.data[2, 0, 0], 1) self.assertEqual(target.data[0, 2, 0], 1) self.assertEqual(target.data[2, 2, 0], 1) self.assertEqual(target.data[0, 0, 2], 1) self.assertEqual(target.data[2, 0, 2], 1) self.assertEqual(target.data[0, 2, 2], 1) self.assertEqual(target.data[2, 2, 2], 1)
def test_translate_voxels(self): voxels = self.createTestObject([5, 5, 5]) voxels.data[3:5, 3:5, 3:5] = 1.0 shift = [-3, -3, -3] VoxelUtils.translate_voxels(shift, voxels) bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [1, 1, 1]) voxels = self.createTestObject([5, 5, 5]) voxels.data[0, 0, 0] = 1.0 shift = [3, 3, 3] VoxelUtils.translate_voxels(shift, voxels) bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [3, 3, 3]) self.assertEqual(bbox['max'], [3, 3, 3])
if args.addModelGeometry: datasetName = datasetName + "_model" if args.addSphereGeometry: datasetName = datasetName + "_sphere" datasetName = datasetName + args.datasetNamePostfix print("Outputting dataset '%s'" % (datasetName)) modelList = [] if args.addModelGeometry: print("using " + args.voxelPath + " for voxel data with pattern " + args.voxelNameRegex) modelListTrain = VoxelUtils.create_voxel_file_list( args.voxelPath + "/voxels_train/", args.voxelNameRegex) modelListTest = VoxelUtils.create_voxel_file_list( args.voxelPath + "/voxels_test/", args.voxelNameRegex) flags = solver.create(FlagGrid) vel = solver.create(MACGrid) velTmp = solver.create(VecGrid) # Internally a Grid<Vec3> pressure = solver.create(RealGrid) density = solver.create(RealGrid) timings = Timings() if not verbose: setDebugLevel(-1) # Disable debug printing altogether. else: setDebugLevel(10) # Print like crazy!
def test_flip_diagonal(self): # Test rotate on x plane voxels = self.createTestObject([3, 3, 3]) voxels.data[0, 0, 0] = 1.0 voxels.data[0, 1, 0] = 1.0 bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [0, 1, 0]) VoxelUtils.flip_diagonal(voxels, 0) self.assertEqual(voxels.data[0, 0, 0], 1) self.assertEqual(voxels.data[0, 0, 1], 1) bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [0, 0, 1]) # Test rotate on y plane voxels = self.createTestObject([3, 3, 3]) voxels.data[0, 0, 0] = 1.0 voxels.data[0, 0, 1] = 1.0 bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [0, 0, 1]) VoxelUtils.flip_diagonal(voxels, 1) self.assertEqual(voxels.data[1, 0, 0], 1) self.assertEqual(voxels.data[0, 0, 0], 1) bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [1, 0, 0]) # Test rotate on z plane voxels = self.createTestObject([3, 3, 3]) voxels.data[0, 0, 0] = 1.0 voxels.data[1, 0, 0] = 1.0 bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [1, 0, 0]) VoxelUtils.flip_diagonal(voxels, 2) self.assertEqual(voxels.data[0, 0, 0], 1) self.assertEqual(voxels.data[0, 1, 0], 1) bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [0, 1, 0])
def test_create_voxel_file_list(self): VoxelUtils.create_voxel_file_list("../../voxelizer/voxels/", ".*[32,64].binvox")
def test_flip_voxels(self): # Test flip on x axis voxels = self.createTestObject([3, 3, 3]) voxels.data[0, 0, 0] = 1.0 voxels.data[0, 1, 0] = 1.0 bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [0, 1, 0]) VoxelUtils.flip_voxels(voxels, 0) self.assertEqual(voxels.data[2, 0, 0], 1) self.assertEqual(voxels.data[2, 1, 0], 1) bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [2, 0, 0]) self.assertEqual(bbox['max'], [2, 1, 0]) # Test flip on y axis voxels = self.createTestObject([3, 3, 3]) voxels.data[0, 0, 0] = 1.0 voxels.data[0, 1, 0] = 1.0 bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [0, 1, 0]) VoxelUtils.flip_voxels(voxels, 1) self.assertEqual(voxels.data[0, 2, 0], 1) self.assertEqual(voxels.data[0, 1, 0], 1) bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 1, 0]) self.assertEqual(bbox['max'], [0, 2, 0]) # Test flip on z axis voxels = self.createTestObject([3, 3, 3]) voxels.data[0, 0, 0] = 1.0 voxels.data[0, 0, 1] = 1.0 bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 0]) self.assertEqual(bbox['max'], [0, 0, 1]) VoxelUtils.flip_voxels(voxels, 2) self.assertEqual(voxels.data[0, 0, 2], 1) self.assertEqual(voxels.data[0, 0, 1], 1) bbox = VoxelUtils.calculate_bounding_box(voxels) self.assertEqual(bbox['min'], [0, 0, 1]) self.assertEqual(bbox['max'], [0, 0, 2])
res = 64 bWidth = 1 gridSize = vec3(resX, resY, resZ) resV = [res, res, res] """ First, a solver object is created. Solver objects are the parent object for grids, particle systems and most other simulation objects. It requires gridSize as a parameter, for which we use the custom vec3 datatype. Most functions expecting vec3 will also accept a python tuple or sequence of 3 numbers. """ solver = FluidSolver(name="main", gridSize=gridSize, dim=args.dim) solver.timestep = args.timeStep modelListTest = VoxelUtils.create_voxel_file_list(args.voxelPath, args.voxelNameRegex) # Next, the solver object is used to create grids. In the same way, # any other object can be created with the solver as a parent. flags = solver.create( FlagGrid) # The flag grid stores cell type (Fluid/Obstacle/Air). vel = solver.create(MACGrid) density = solver.create(RealGrid) pressure = solver.create(RealGrid) gui = Gui() gui.show(True) #density.setConst(1) # As most plugins expect the outmost cells of a simulation to be obstacles,