Skip to content

Commit

Permalink
Merge pull request #4877 from biboyd/no_opacity_reduce
Browse files Browse the repository at this point in the history
Reduce rendered images without considering opacity
  • Loading branch information
chrishavlin authored May 15, 2024
2 parents de552c6 + a104859 commit bdef0b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 6 additions & 1 deletion yt/utilities/amr_kdtree/amr_kdtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
from yt.funcs import mylog


def receive_and_reduce(comm, incoming_rank, image, add_to_front):
def receive_and_reduce(comm, incoming_rank, image, add_to_front, *, use_opacity=True):
mylog.debug("Receiving image from %04i", incoming_rank)
# mylog.debug( '%04i receiving image from %04i'%(self.comm.rank,back.owner))
arr2 = comm.recv_array(incoming_rank, incoming_rank).reshape(
(image.shape[0], image.shape[1], image.shape[2])
)

if not use_opacity:
np.add(image, arr2, image)
return image

if add_to_front:
front = arr2
back = image
Expand All @@ -31,6 +35,7 @@ def receive_and_reduce(comm, incoming_rank, image, add_to_front):
for i in range(4):
np.multiply(image[:, :, i], ta, image[:, :, i])
np.add(image, front, image)

return image


Expand Down
8 changes: 6 additions & 2 deletions yt/utilities/amr_kdtree/amr_kdtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def get_reduce_owners(self):
owners[temp.node_id] = owners[temp.left.node_id]
return owners

def reduce_tree_images(self, image, viewpoint):
def reduce_tree_images(self, image, viewpoint, *, use_opacity=True):
if self.comm.size <= 1:
return image
myrank = self.comm.rank
Expand All @@ -307,7 +307,11 @@ def reduce_tree_images(self, image, viewpoint):
split_pos = node.parent.get_split_pos()
add_to_front = viewpoint[split_dim] >= split_pos
image = receive_and_reduce(
self.comm, owners[node.parent.right.node_id], image, add_to_front
self.comm,
owners[node.parent.right.node_id],
image,
add_to_front,
use_opacity=use_opacity,
)
if node.parent.node_id == 1:
break
Expand Down
6 changes: 5 additions & 1 deletion yt/visualization/volume_rendering/render_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,11 @@ def render(self, camera, zbuffer=None):

def finalize_image(self, camera, image):
if self._volume is not None:
image = self.volume.reduce_tree_images(image, camera.lens.viewpoint)
image = self.volume.reduce_tree_images(
image,
camera.lens.viewpoint,
use_opacity=self.transfer_function.grey_opacity,
)

return super().finalize_image(camera, image)

Expand Down

0 comments on commit bdef0b6

Please sign in to comment.