def build_volume_bvh(self): """ This constructs the mesh that will be ray-traced. """ ftype, fname = self.field mesh_id = int(ftype[-1]) - 1 index = self.data_source.ds.index offset = index.meshes[mesh_id]._index_offset field_data = self.data_source[self.field].d # strip units vertices = index.meshes[mesh_id].connectivity_coords indices = index.meshes[mesh_id].connectivity_indices - offset # if this is an element field, promote to 2D here if len(field_data.shape) == 1: field_data = np.expand_dims(field_data, 1) # Here, we decide whether to render based on high-order or # low-order geometry. if indices.shape[1] == 27: # hexahedral mylog.warning("27-node hexes not yet supported, " + "dropping to 1st order.") field_data = field_data[:, 0:8] indices = indices[:, 0:8] elif indices.shape[1] == 10: # tetrahedral mylog.warning("10-node tetrahedral elements not yet supported, " + "dropping to 1st order.") field_data = field_data[:, 0:4] indices = indices[:, 0:4] self.volume = BVH(vertices, indices, field_data)
def test_bounding_volume_hierarchy(): ds = yt.load(fn) vertices = ds.index.meshes[0].connectivity_coords indices = ds.index.meshes[0].connectivity_indices - 1 ad = ds.all_data() field_data = ad["connect1", "diffused"] bvh = BVH(vertices, indices, field_data) sc = Scene() cam = Camera(sc) cam.set_position(np.array([8.0, 8.0, 8.0])) cam.focus = np.array([0.0, 0.0, 0.0]) origins, direction = get_rays(cam) image = np.empty(800 * 800, np.float64) test_ray_trace(image, origins, direction, bvh) image = image.reshape((800, 800)) return image