[yt-svn] commit/yt: 5 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Jun 13 20:26:46 PDT 2013


5 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/fde7e81f6a77/
Changeset:   fde7e81f6a77
Branch:      yt
User:        samskillman
Date:        2013-06-10 22:57:55
Summary:     Adding initial support for drawing r,g,b vectors on the image denoting the x,y,z
data coordinate vectors.
Affected #:  2 files

diff -r bc3f6a77ac2a5b23092c9a7aa771ac5438635b33 -r fde7e81f6a7766f62117456ffad0a077f4c8cbd4 yt/utilities/lib/misc_utilities.pyx
--- a/yt/utilities/lib/misc_utilities.pyx
+++ b/yt/utilities/lib/misc_utilities.pyx
@@ -130,7 +130,7 @@
     cdef int i, j
     cdef int dx, dy, sx, sy, e2, err
     cdef np.int64_t x0, x1, y0, y1
-    cdef int has_alpha = (image.shape[-1] == 4)
+    cdef int has_alpha = (image.shape[2] == 4)
     for j in range(0, nl, 2):
         # From wikipedia http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
         x0 = xs[j]; y0 = ys[j]; x1 = xs[j+1]; y1 = ys[j+1]
@@ -160,7 +160,7 @@
             if (x0 >=0 and x0 < nx and y0 >= 0 and y0 < ny):
                 if has_alpha:
                     for i in range(4):
-                        image[x0,y0,i] = (1.-alpha[i])*image[x0,y0,i] + alpha[i]
+                        image[x0,y0,i] = (1.-alpha[3])*image[x0,y0,i] + alpha[i]
                 else:
                     for i in range(3):
                         image[x0,y0,i] = (1.-alpha[i])*image[x0,y0,i] + alpha[i]

diff -r bc3f6a77ac2a5b23092c9a7aa771ac5438635b33 -r fde7e81f6a7766f62117456ffad0a077f4c8cbd4 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -342,6 +342,32 @@
         lines(nim, px, py, colors, 24)
         return nim
 
+    def draw_coordinate_vectors(self, im):
+        center = self.origin
+        width = self.width
+        length = 0.05*self.resolution[0]
+        # Put the starting point in the lower left
+        px0 = int(0.05 * self.resolution[0])
+        py0 = int(0.95 * self.resolution[1])
+
+        alpha = im[:,:,3].max()
+        if alpha == 0.0:
+            alpha = 1.0
+
+        coord_vectors = [np.array([length, 0.0, 0.0]),
+                         np.array([0.0, length, 0.0]),
+                         np.array([0.0, 0.0, length])]
+        colors = [np.array([1.0, 0.0, 0.0, alpha]),
+                  np.array([0.0, 1.0, 0.0, alpha]),
+                  np.array([0.0, 0.0, 1.0, alpha])]
+
+        for vec, color in zip(coord_vectors, colors):
+            dx = int(np.dot(vec, self.orienter.unit_vectors[0]))
+            dy = int(np.dot(vec, self.orienter.unit_vectors[1]))
+            print px0, py0, dx, dy, color
+            lines(im, np.array([px0, px0+dx]), np.array([py0, py0+dy]), 
+                  np.array([color, color]))
+
     def draw_line(self, im, x0, x1, color=None):
         r"""Draws a line on an existing volume rendering.
 


https://bitbucket.org/yt_analysis/yt/commits/c6fb84547b7a/
Changeset:   c6fb84547b7a
Branch:      yt
User:        samskillman
Date:        2013-06-13 01:18:57
Summary:     Adding ability to draw thick lines.
Affected #:  2 files

diff -r fde7e81f6a7766f62117456ffad0a077f4c8cbd4 -r c6fb84547b7af13bb6dafa1c82b77e5d4858c262 yt/utilities/lib/misc_utilities.pyx
--- a/yt/utilities/lib/misc_utilities.pyx
+++ b/yt/utilities/lib/misc_utilities.pyx
@@ -121,7 +121,8 @@
           np.ndarray[np.int64_t, ndim=1] xs,
           np.ndarray[np.int64_t, ndim=1] ys,
           np.ndarray[np.float64_t, ndim=2] colors,
-          int points_per_color=1):
+          int points_per_color=1,
+          int thick=1):
 
     cdef int nx = image.shape[0]
     cdef int ny = image.shape[1]
@@ -153,17 +154,21 @@
         else:
             sy = -1
         while(1):
-            if (x0 < 0 and sx == -1): break
-            elif (x0 >= nx and sx == 1): break
-            elif (y0 < 0 and sy == -1): break
-            elif (y0 >= nx and sy == 1): break
-            if (x0 >=0 and x0 < nx and y0 >= 0 and y0 < ny):
+            if (x0 < thick and sx == -1): break
+            elif (x0 >= nx-thick+1 and sx == 1): break
+            elif (y0 < thick and sy == -1): break
+            elif (y0 >= ny-thick+1 and sy == 1): break
+            if (x0 >=thick and x0 < nx-thick and y0 >= thick and y0 < ny-thick):
                 if has_alpha:
                     for i in range(4):
-                        image[x0,y0,i] = (1.-alpha[3])*image[x0,y0,i] + alpha[i]
+                        image[x0-thick/2:x0+(1+thick)/2, 
+                              y0-thick/2:y0+(1+thick)/2,i] = \
+                                (1.-alpha[3])*image[x0,y0,i] + alpha[i]
                 else:
                     for i in range(3):
-                        image[x0,y0,i] = (1.-alpha[i])*image[x0,y0,i] + alpha[i]
+                        image[x0-thick/2:x0+(1+thick)/2, 
+                              y0-thick/2:y0+(1+thick)/2,i] = \
+                                (1.-alpha[i])*image[x0,y0,i] + alpha[i]
 
             if (x0 == x1 and y0 == y1):
                 break

diff -r fde7e81f6a7766f62117456ffad0a077f4c8cbd4 -r c6fb84547b7af13bb6dafa1c82b77e5d4858c262 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -342,21 +342,20 @@
         lines(nim, px, py, colors, 24)
         return nim
 
-    def draw_coordinate_vectors(self, im):
-        center = self.origin
-        width = self.width
-        length = 0.05*self.resolution[0]
+    def draw_coordinate_vectors(self, im, length=0.05, thickness=1):
+        length_pixels = length * self.resolution[0]
         # Put the starting point in the lower left
-        px0 = int(0.05 * self.resolution[0])
-        py0 = int(0.95 * self.resolution[1])
+        px0 = int(length * self.resolution[0])
+        # CS coordinates!
+        py0 = int((1.0-length) * self.resolution[1])
 
-        alpha = im[:,:,3].max()
+        alpha = im[:, :, 3].max()
         if alpha == 0.0:
             alpha = 1.0
 
-        coord_vectors = [np.array([length, 0.0, 0.0]),
-                         np.array([0.0, length, 0.0]),
-                         np.array([0.0, 0.0, length])]
+        coord_vectors = [np.array([length_pixels, 0.0, 0.0]),
+                         np.array([0.0, length_pixels, 0.0]),
+                         np.array([0.0, 0.0, length_pixels])]
         colors = [np.array([1.0, 0.0, 0.0, alpha]),
                   np.array([0.0, 1.0, 0.0, alpha]),
                   np.array([0.0, 0.0, 1.0, alpha])]
@@ -366,7 +365,7 @@
             dy = int(np.dot(vec, self.orienter.unit_vectors[1]))
             print px0, py0, dx, dy, color
             lines(im, np.array([px0, px0+dx]), np.array([py0, py0+dy]), 
-                  np.array([color, color]))
+                  np.array([color, color]), 1, thickness)
 
     def draw_line(self, im, x0, x1, color=None):
         r"""Draws a line on an existing volume rendering.


https://bitbucket.org/yt_analysis/yt/commits/cf52f60523b1/
Changeset:   cf52f60523b1
Branch:      yt
User:        samskillman
Date:        2013-06-13 20:27:49
Summary:     Adding docstrings to coordinate vector drawing.
Affected #:  1 file

diff -r c6fb84547b7af13bb6dafa1c82b77e5d4858c262 -r cf52f60523b1826cfcaca7fae21c330d14a5bb81 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -343,6 +343,38 @@
         return nim
 
     def draw_coordinate_vectors(self, im, length=0.05, thickness=1):
+        r"""Draws three coordinate vectors in the corner of a rendering.
+
+        Modifies an existing image to have three lines corresponding to the
+        coordinate directions colored by {x,y,z} = {r,g,b}.  Currently only
+        functional for plane-parallel volume rendering.
+
+        Parameters
+        ----------
+        im: Numpy ndarray
+            Existing image that has the same resolution as the Camera,
+            which will be painted by grid lines.
+        length: float, optional
+            The length of the lines, as a fraction of the image size.
+            Default : 0.05
+        thickness : int, optional
+            Thickness in pixels of the line to be drawn.
+
+        Returns
+        -------
+        None
+
+        Modifies
+        --------
+        im: The original image.
+
+        Examples
+        --------
+        >>> im = cam.snapshot()
+        >>> cam.draw__coordinate_vectors(im)
+        >>> im.write_png('render_with_grids.png')
+
+        """
         length_pixels = length * self.resolution[0]
         # Put the starting point in the lower left
         px0 = int(length * self.resolution[0])
@@ -364,7 +396,7 @@
             dx = int(np.dot(vec, self.orienter.unit_vectors[0]))
             dy = int(np.dot(vec, self.orienter.unit_vectors[1]))
             print px0, py0, dx, dy, color
-            lines(im, np.array([px0, px0+dx]), np.array([py0, py0+dy]), 
+            lines(im, np.array([px0, px0+dx]), np.array([py0, py0+dy]),
                   np.array([color, color]), 1, thickness)
 
     def draw_line(self, im, x0, x1, color=None):


https://bitbucket.org/yt_analysis/yt/commits/636dc8ccfad0/
Changeset:   636dc8ccfad0
Branch:      yt
User:        samskillman
Date:        2013-06-13 20:47:40
Summary:     Removing errant print.
Affected #:  1 file

diff -r cf52f60523b1826cfcaca7fae21c330d14a5bb81 -r 636dc8ccfad05fb870397ee46d42214dd604d89c yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -395,7 +395,6 @@
         for vec, color in zip(coord_vectors, colors):
             dx = int(np.dot(vec, self.orienter.unit_vectors[0]))
             dy = int(np.dot(vec, self.orienter.unit_vectors[1]))
-            print px0, py0, dx, dy, color
             lines(im, np.array([px0, px0+dx]), np.array([py0, py0+dy]),
                   np.array([color, color]), 1, thickness)
 


https://bitbucket.org/yt_analysis/yt/commits/252591eeb6a2/
Changeset:   252591eeb6a2
Branch:      yt
User:        ngoldbaum
Date:        2013-06-14 05:26:37
Summary:     Merged in samskillman/yt (pull request #530)

Draw coordinate vectors on renders
Affected #:  2 files

diff -r c4ac1f45dff060da1de9df992eee835cdf9169ce -r 252591eeb6a2c0014ddb3a87adb04acf7eeefa97 yt/utilities/lib/misc_utilities.pyx
--- a/yt/utilities/lib/misc_utilities.pyx
+++ b/yt/utilities/lib/misc_utilities.pyx
@@ -121,7 +121,8 @@
           np.ndarray[np.int64_t, ndim=1] xs,
           np.ndarray[np.int64_t, ndim=1] ys,
           np.ndarray[np.float64_t, ndim=2] colors,
-          int points_per_color=1):
+          int points_per_color=1,
+          int thick=1):
 
     cdef int nx = image.shape[0]
     cdef int ny = image.shape[1]
@@ -130,7 +131,7 @@
     cdef int i, j
     cdef int dx, dy, sx, sy, e2, err
     cdef np.int64_t x0, x1, y0, y1
-    cdef int has_alpha = (image.shape[-1] == 4)
+    cdef int has_alpha = (image.shape[2] == 4)
     for j in range(0, nl, 2):
         # From wikipedia http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
         x0 = xs[j]; y0 = ys[j]; x1 = xs[j+1]; y1 = ys[j+1]
@@ -153,17 +154,21 @@
         else:
             sy = -1
         while(1):
-            if (x0 < 0 and sx == -1): break
-            elif (x0 >= nx and sx == 1): break
-            elif (y0 < 0 and sy == -1): break
-            elif (y0 >= nx and sy == 1): break
-            if (x0 >=0 and x0 < nx and y0 >= 0 and y0 < ny):
+            if (x0 < thick and sx == -1): break
+            elif (x0 >= nx-thick+1 and sx == 1): break
+            elif (y0 < thick and sy == -1): break
+            elif (y0 >= ny-thick+1 and sy == 1): break
+            if (x0 >=thick and x0 < nx-thick and y0 >= thick and y0 < ny-thick):
                 if has_alpha:
                     for i in range(4):
-                        image[x0,y0,i] = (1.-alpha[i])*image[x0,y0,i] + alpha[i]
+                        image[x0-thick/2:x0+(1+thick)/2, 
+                              y0-thick/2:y0+(1+thick)/2,i] = \
+                                (1.-alpha[3])*image[x0,y0,i] + alpha[i]
                 else:
                     for i in range(3):
-                        image[x0,y0,i] = (1.-alpha[i])*image[x0,y0,i] + alpha[i]
+                        image[x0-thick/2:x0+(1+thick)/2, 
+                              y0-thick/2:y0+(1+thick)/2,i] = \
+                                (1.-alpha[i])*image[x0,y0,i] + alpha[i]
 
             if (x0 == x1 and y0 == y1):
                 break

diff -r c4ac1f45dff060da1de9df992eee835cdf9169ce -r 252591eeb6a2c0014ddb3a87adb04acf7eeefa97 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -342,6 +342,62 @@
         lines(nim, px, py, colors, 24)
         return nim
 
+    def draw_coordinate_vectors(self, im, length=0.05, thickness=1):
+        r"""Draws three coordinate vectors in the corner of a rendering.
+
+        Modifies an existing image to have three lines corresponding to the
+        coordinate directions colored by {x,y,z} = {r,g,b}.  Currently only
+        functional for plane-parallel volume rendering.
+
+        Parameters
+        ----------
+        im: Numpy ndarray
+            Existing image that has the same resolution as the Camera,
+            which will be painted by grid lines.
+        length: float, optional
+            The length of the lines, as a fraction of the image size.
+            Default : 0.05
+        thickness : int, optional
+            Thickness in pixels of the line to be drawn.
+
+        Returns
+        -------
+        None
+
+        Modifies
+        --------
+        im: The original image.
+
+        Examples
+        --------
+        >>> im = cam.snapshot()
+        >>> cam.draw__coordinate_vectors(im)
+        >>> im.write_png('render_with_grids.png')
+
+        """
+        length_pixels = length * self.resolution[0]
+        # Put the starting point in the lower left
+        px0 = int(length * self.resolution[0])
+        # CS coordinates!
+        py0 = int((1.0-length) * self.resolution[1])
+
+        alpha = im[:, :, 3].max()
+        if alpha == 0.0:
+            alpha = 1.0
+
+        coord_vectors = [np.array([length_pixels, 0.0, 0.0]),
+                         np.array([0.0, length_pixels, 0.0]),
+                         np.array([0.0, 0.0, length_pixels])]
+        colors = [np.array([1.0, 0.0, 0.0, alpha]),
+                  np.array([0.0, 1.0, 0.0, alpha]),
+                  np.array([0.0, 0.0, 1.0, alpha])]
+
+        for vec, color in zip(coord_vectors, colors):
+            dx = int(np.dot(vec, self.orienter.unit_vectors[0]))
+            dy = int(np.dot(vec, self.orienter.unit_vectors[1]))
+            lines(im, np.array([px0, px0+dx]), np.array([py0, py0+dy]),
+                  np.array([color, color]), 1, thickness)
+
     def draw_line(self, im, x0, x1, color=None):
         r"""Draws a line on an existing volume rendering.

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