[yt-svn] commit/yt: ngoldbaum: Merged in atmyers/yt (pull request #1792)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Oct 14 14:05:39 PDT 2015


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/f5b180206fa3/
Changeset:   f5b180206fa3
Branch:      yt
User:        ngoldbaum
Date:        2015-10-14 21:05:27+00:00
Summary:     Merged in atmyers/yt (pull request #1792)

[Experimental] [Bugfix] Fixing the add operation of Zbuffer
Affected #:  2 files

diff -r d3ba9ef67a78946c1a0afe6a455310991a228f9f -r f5b180206fa30adb2213221a3e09a96e99bb866e yt/visualization/volume_rendering/tests/test_zbuff.py
--- a/yt/visualization/volume_rendering/tests/test_zbuff.py
+++ b/yt/visualization/volume_rendering/tests/test_zbuff.py
@@ -10,15 +10,15 @@
 # The full license is in the file COPYING.txt, distributed with this software.
 #-----------------------------------------------------------------------------
 
-import yt
 from yt.testing import fake_random_ds
-from yt.visualization.volume_rendering.api import Scene, Camera, ZBuffer, \
-    VolumeSource, OpaqueSource, LineSource, BoxSource
-from yt.utilities.lib.misc_utilities import lines
-from yt.data_objects.api import ImageArray
+from yt.visualization.volume_rendering.api import \
+    Scene, Camera, ZBuffer, \
+    VolumeSource, OpaqueSource
+from yt.testing import assert_almost_equal
 import numpy as np
 np.random.seed(0)
 
+
 def test_composite_vr():
     ds = fake_random_ds(64)
     dd = ds.sphere(ds.domain_center, 0.45*ds.domain_width[0])
@@ -53,5 +53,55 @@
     im.write_png("composite.png")
     return im
 
+
+def test_nonrectangular_add():
+    rgba1 = np.ones((64, 1, 4))
+    z1 = np.expand_dims(np.arange(64.), 1)
+
+    rgba2 = np.zeros((64, 1, 4))
+    z2 = np.expand_dims(np.arange(63., -1., -1.), 1)
+
+    exact_rgba = np.concatenate((np.ones(32), np.zeros(32)))
+    exact_rgba = np.expand_dims(exact_rgba, 1)
+    exact_rgba = np.dstack((exact_rgba, exact_rgba, exact_rgba, exact_rgba))
+
+    exact_z = np.concatenate((np.arange(32.), np.arange(31.,-1.,-1.)))
+    exact_z = np.expand_dims(exact_z, 1)
+
+    buff1 = ZBuffer(rgba1, z1)
+    buff2 = ZBuffer(rgba2, z2)
+
+    buff = buff1 + buff2
+
+    assert_almost_equal(buff.rgba, exact_rgba)
+    assert_almost_equal(buff.z, exact_z)
+
+
+def test_rectangular_add():
+    rgba1 = np.ones((8, 8, 4))
+    z1 = np.arange(64.)
+    z1 = z1.reshape((8, 8))
+    buff1 = ZBuffer(rgba1, z1)
+
+    rgba2 = np.zeros((8, 8, 4))
+    z2 = np.arange(63., -1., -1.)
+    z2 = z2.reshape((8, 8))
+    buff2 = ZBuffer(rgba2, z2)
+
+    buff = buff1 + buff2
+
+    exact_rgba = np.empty((8, 8, 4), dtype=np.float64)
+    exact_rgba[0:4,0:8,:] = 1.0
+    exact_rgba[4:8,0:8,:] = 0.0
+
+    exact_z = np.concatenate((np.arange(32.), np.arange(31., -1., -1.)))
+    exact_z = np.expand_dims(exact_z, 1)
+    exact_z = exact_z.reshape(8, 8)
+
+    assert_almost_equal(buff.rgba, exact_rgba)
+    assert_almost_equal(buff.z, exact_z)
+
 if __name__ == "__main__":
     im = test_composite_vr()
+    test_nonrectangular_add()
+    test_rectangular_add()

diff -r d3ba9ef67a78946c1a0afe6a455310991a228f9f -r f5b180206fa30adb2213221a3e09a96e99bb866e yt/visualization/volume_rendering/zbuffer_array.py
--- a/yt/visualization/volume_rendering/zbuffer_array.py
+++ b/yt/visualization/volume_rendering/zbuffer_array.py
@@ -28,13 +28,16 @@
 
     def __add__(self, other):
         assert(self.shape == other.shape)
-        f_or_b = self.z < other.z
+        f = self.z < other.z
         if self.z.shape[1] == 1:
             # Non-rectangular
-            rgba = (self.rgba * f_or_b[:,None,:])
-            rgba += (other.rgba * (1.0 - f_or_b)[:,None,:])
+            rgba = (self.rgba * f[:,None,:])
+            rgba += (other.rgba * (1.0 - f)[:,None,:])
         else:
-            rgba = (self.rgba.T * f_or_b).T + (other.rgba.T * (1 - f_or_b)).T
+            b = self.z > other.z
+            rgba = np.empty(self.rgba.shape)
+            rgba[f] = self.rgba[f]
+            rgba[b] = other.rgba[b]
         z = np.min([self.z, other.z], axis=0)
         return ZBuffer(rgba, z)

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list