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

Bitbucket commits-noreply at bitbucket.org
Wed Jan 23 23:06:06 PST 2013


10 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/21860a94c9bd/
changeset:   21860a94c9bd
branch:      yt
user:        samskillman
date:        2012-04-03 21:27:26
summary:     Intermediate work on the adding grids to renders.
affected #:  1 file

diff -r 9a82730088c2e0aa0b02724fb452a778b788f37b -r 21860a94c9bde9cc940b0ef2c65f3ee27558480b yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -33,11 +33,12 @@
 from yt.utilities.amr_utils import TransferFunctionProxy, VectorPlane, \
     arr_vec2pix_nest, arr_pix2vec_nest, AdaptiveRaySource, \
     arr_ang2pix_nest, arr_fisheye_vectors, rotate_vectors
-from yt.visualization.image_writer import write_bitmap
+from yt.visualization.image_writer import write_bitmap, apply_colormap
 from yt.data_objects.data_containers import data_object_registry
 from yt.utilities.parallel_tools.parallel_analysis_interface import \
     ParallelAnalysisInterface, ProcessorPool
 from yt.utilities.amr_kdtree.api import AMRKDTree
+from .blenders import line, enhance
 from numpy import pi
 
 class Camera(ParallelAnalysisInterface):
@@ -252,6 +253,109 @@
         self.front_center = self.center + 0.5*self.width[0]*self.unit_vectors[2]
         self.inv_mat = na.linalg.pinv(self.unit_vectors)
 
+    def project_to_plane(self, pos):
+        dx = na.dot(pos - self.origin, self.unit_vectors[1])
+        dy = na.dot(pos - self.origin, self.unit_vectors[0])
+        # Transpose into image coords.
+        py = (self.resolution[0]*(dx/self.width[0])).astype('int')
+        px = (self.resolution[1]*(dy/self.width[1])).astype('int')
+        return px, py
+
+    def draw_line(self, im, x0, x1, color=na.array([1.0,1.0,1.0,1.0])):
+        #print ' '
+        #print self.origin
+        #print self.unit_vectors
+        #print x0, x1, na.abs(x1-x0).sum()
+        dx0 = ((x0-self.origin)*self.unit_vectors[1]).sum()
+        dx1 = ((x1-self.origin)*self.unit_vectors[1]).sum()
+        dy0 = ((x0-self.origin)*self.unit_vectors[0]).sum()
+        dy1 = ((x1-self.origin)*self.unit_vectors[0]).sum()
+        #print dx0, dx1, dy0, dy1
+        py0 = int(self.resolution[0]*(dx0/self.width[0]))
+        py1 = int(self.resolution[0]*(dx1/self.width[0]))
+        px0 = int(self.resolution[1]*(dy0/self.width[1]))
+        px1 = int(self.resolution[1]*(dy1/self.width[1]))
+        #print 'Drawing line from', px0, px1, py0, py1 
+        line(im, px0, py0, px1, py1, color=color)
+
+    def add_grids(self, im, alpha=0.2, cmap='algae'):
+        levels = self.pf.h.grid_levels[:,0]
+        colors = apply_colormap(levels*1.0,
+                                color_bounds=[0,self.pf.h.max_level],
+                                cmap_name=cmap)*1.0/255.
+        colors = colors[0,:,:]
+        colors[:,3] = alpha
+        print 'c shapes:', colors.shape
+        #balls
+        for color, le, re in zip(colors, self.pf.h.grid_left_edge,
+                self.pf.h.grid_right_edge):
+            self.draw_box(im, le, re, color=color)
+
+    def draw_grids(self,im, alpha=0.3):
+        enhance(im)
+        #alpha = im.max()*alpha
+        print 'Setting alpha to %e' % alpha
+        self.add_grids(im, alpha=alpha, cmap='idl16')
+        #enhance(im)
+
+    def draw_domain(self,im,alpha=0.5):
+        alpha = im.max()*alpha
+        self.draw_box(im, self.pf.domain_left_edge, self.pf.domain_right_edge,
+                        color=na.array([1.0,1.0,1.0,alpha]))
+        
+
+    def draw_box(self, im, le, re, color=na.array([1.0,1.0,1.0,1.0])):
+        self.draw_line(im, 
+                na.array((le[0], le[1], le[2])),
+                na.array((re[0], le[1], le[2])),
+                color=color)
+        self.draw_line(im, 
+                na.array((re[0], le[1], le[2])),
+                na.array((re[0], le[1], re[2])),
+                color=color)
+        self.draw_line(im, 
+                na.array((re[0], le[1], re[2])),
+                na.array((le[0], le[1], re[2])),
+                color=color)
+        self.draw_line(im, 
+                na.array((le[0], le[1], re[2])),
+                na.array((le[0], le[1], le[2])),
+                color=color)
+                    
+        self.draw_line(im, 
+                na.array((le[0], re[1], le[2])),
+                na.array((re[0], re[1], le[2])),
+                color=color)
+        self.draw_line(im, 
+                na.array((re[0], re[1], le[2])),
+                na.array((re[0], re[1], re[2])),
+                color=color)
+        self.draw_line(im, 
+                na.array((re[0], re[1], re[2])),
+                na.array((le[0], re[1], re[2])),
+                color=color)
+        self.draw_line(im, 
+                na.array((le[0], re[1], re[2])),
+                na.array((le[0], re[1], le[2])),
+                color=color)
+
+        self.draw_line(im, 
+                na.array((le[0], le[1], le[2])),
+                na.array((le[0], re[1], le[2])),
+                color=color)
+        self.draw_line(im, 
+                na.array((re[0], le[1], le[2])),
+                na.array((re[0], re[1], le[2])),
+                color=color)
+        self.draw_line(im, 
+                na.array((le[0], le[1], re[2])),
+                na.array((le[0], re[1], re[2])),
+                color=color)
+        self.draw_line(im, 
+                na.array((re[0], le[1], re[2])),
+                na.array((re[0], re[1], re[2])),
+                color=color)
+
     def look_at(self, new_center, north_vector = None):
         r"""Change the view direction based on a new focal point.
 


https://bitbucket.org/yt_analysis/yt/commits/2d944938d65a/
changeset:   2d944938d65a
branch:      yt
user:        samskillman
date:        2012-05-01 21:44:22
summary:     Transposing image so that the camera north vector works as expected.  This is caused by the standard of having an image (0,0) being in the upper right
affected #:  1 file

diff -r 21860a94c9bde9cc940b0ef2c65f3ee27558480b -r 2d944938d65ac6af62802ee89ebb7c0e9edc065e yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -150,6 +150,8 @@
         s1, s2 = bitmap_array.shape[:2]
         alpha_channel = 255*na.ones((s1,s2,1), dtype='uint8')
         bitmap_array = na.concatenate([bitmap_array, alpha_channel], axis=-1)
+    for channel in range(bitmap_array.shape[2]):
+        bitmap_array[:,:,channel] = bitmap_array[:,:,channel].T
     au.write_png(bitmap_array.copy(), filename)
     return bitmap_array
 


https://bitbucket.org/yt_analysis/yt/commits/606c5668fcfc/
changeset:   606c5668fcfc
branch:      yt
user:        samskillman
date:        2012-05-04 21:56:15
summary:     Start of an attempt at drawing grid boundaries
affected #:  3 files

diff -r 2d944938d65ac6af62802ee89ebb7c0e9edc065e -r 606c5668fcfc049b7606ce429c0a589bcbe91e62 yt/data_objects/hierarchy.py
--- a/yt/data_objects/hierarchy.py
+++ b/yt/data_objects/hierarchy.py
@@ -382,11 +382,11 @@
           [self.grid_left_edge[:,0], self.grid_left_edge[:,1], self.grid_left_edge[:,2]],
           [self.grid_right_edge[:,0], self.grid_left_edge[:,1], self.grid_left_edge[:,2]],
           [self.grid_right_edge[:,0], self.grid_right_edge[:,1], self.grid_left_edge[:,2]],
+          [self.grid_left_edge[:,0], self.grid_right_edge[:,1], self.grid_left_edge[:,2]],
+          [self.grid_left_edge[:,0], self.grid_left_edge[:,1], self.grid_right_edge[:,2]],
+          [self.grid_right_edge[:,0], self.grid_left_edge[:,1], self.grid_right_edge[:,2]],
           [self.grid_right_edge[:,0], self.grid_right_edge[:,1], self.grid_right_edge[:,2]],
           [self.grid_left_edge[:,0], self.grid_right_edge[:,1], self.grid_right_edge[:,2]],
-          [self.grid_left_edge[:,0], self.grid_left_edge[:,1], self.grid_right_edge[:,2]],
-          [self.grid_right_edge[:,0], self.grid_left_edge[:,1], self.grid_right_edge[:,2]],
-          [self.grid_left_edge[:,0], self.grid_right_edge[:,1], self.grid_left_edge[:,2]],
         ], dtype='float64')
 
     def print_stats(self):

diff -r 2d944938d65ac6af62802ee89ebb7c0e9edc065e -r 606c5668fcfc049b7606ce429c0a589bcbe91e62 yt/utilities/_amr_utils/misc_utilities.pyx
--- a/yt/utilities/_amr_utils/misc_utilities.pyx
+++ b/yt/utilities/_amr_utils/misc_utilities.pyx
@@ -117,6 +117,59 @@
 @cython.boundscheck(False)
 @cython.wraparound(False)
 @cython.cdivision(True)
+def lines(np.ndarray[np.float64_t, ndim=3] image, 
+          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):
+    
+    cdef int nx = image.shape[0]
+    cdef int ny = image.shape[1]
+    cdef int nl = xs.shape[0]
+    cdef np.float64_t alpha[3], nalpha 
+    cdef int i, j
+    cdef int dx, dy, sx, sy, e2, err
+    cdef np.int64_t x0, x1, y0, y1
+    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]
+        dx = abs(x1-x0)
+        dy = abs(y1-y0)
+        err = dx - dy
+        for i in range(3):
+            alpha[i] = colors[j/points_per_color,3]*colors[j/points_per_color,i]
+        nalpha = 1.0-colors[j/points_per_color,3]
+        if x0 < x1: 
+            sx = 1
+        else:
+            sx = -1
+        if y0 < y1:
+            sy = 1
+        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):
+                for i in range(3):
+                    image[x0,y0,i] = (1.-alpha[i])*image[x0,y0,i] + alpha[i]
+            if (x0 == x1 and y0 == y1):
+                break
+            e2 = 2*err
+            if e2 > -dy:
+                err = err - dy
+                x0 += sx
+            if e2 < dx :
+                err = err + dx
+                y0 += sy
+    return 
+
+
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+ at cython.cdivision(True)
 def get_color_bounds(np.ndarray[np.float64_t, ndim=1] px,
                      np.ndarray[np.float64_t, ndim=1] py,
                      np.ndarray[np.float64_t, ndim=1] pdx,

diff -r 2d944938d65ac6af62802ee89ebb7c0e9edc065e -r 606c5668fcfc049b7606ce429c0a589bcbe91e62 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -32,14 +32,27 @@
 
 from yt.utilities.amr_utils import TransferFunctionProxy, VectorPlane, \
     arr_vec2pix_nest, arr_pix2vec_nest, AdaptiveRaySource, \
-    arr_ang2pix_nest, arr_fisheye_vectors, rotate_vectors
+    arr_ang2pix_nest, arr_fisheye_vectors, rotate_vectors, lines
 from yt.visualization.image_writer import write_bitmap, apply_colormap
 from yt.data_objects.data_containers import data_object_registry
 from yt.utilities.parallel_tools.parallel_analysis_interface import \
     ParallelAnalysisInterface, ProcessorPool
 from yt.utilities.amr_kdtree.api import AMRKDTree
-from .blenders import line, enhance
+from .blenders import  enhance
 from numpy import pi
+from time import time
+
+def get_corners(le, re):
+    return na.array([
+      [le[0], le[1], le[2]],
+      [re[0], le[1], le[2]],
+      [re[0], re[1], le[2]],
+      [le[0], re[1], le[2]],
+      [le[0], le[1], re[2]],
+      [re[0], le[1], re[2]],
+      [re[0], re[1], re[2]],
+      [le[0], re[1], re[2]],
+    ], dtype='float64')
 
 class Camera(ParallelAnalysisInterface):
     def __init__(self, center, normal_vector, width,
@@ -253,108 +266,75 @@
         self.front_center = self.center + 0.5*self.width[0]*self.unit_vectors[2]
         self.inv_mat = na.linalg.pinv(self.unit_vectors)
 
-    def project_to_plane(self, pos):
+    def project_to_plane(self, pos, res=None):
+        if res is None: 
+            res = self.resolution
         dx = na.dot(pos - self.origin, self.unit_vectors[1])
         dy = na.dot(pos - self.origin, self.unit_vectors[0])
+        dz = na.dot(pos - self.center, self.unit_vectors[2])
         # Transpose into image coords.
-        py = (self.resolution[0]*(dx/self.width[0])).astype('int')
-        px = (self.resolution[1]*(dy/self.width[1])).astype('int')
-        return px, py
+        py = (res[0]*(dx/self.width[0])).astype('int')
+        px = (res[1]*(dy/self.width[1])).astype('int')
+        return px, py, dz
+
+    def add_grids(self, im, alpha=0.2, cmap='algae'):
+        corners = self.pf.h.grid_corners
+        levels = self.pf.h.grid_levels[:,0]
+        colors = apply_colormap(levels*1.0,
+                                color_bounds=[0,self.pf.h.max_level],
+                                cmap_name=cmap)[0,:,:]*1.0/255.
+        colors[:,3] = alpha
+
+                
+        order  = [0, 1, 1, 2, 2, 3, 3, 0]
+        order += [4, 5, 5, 6, 6, 7, 7, 4]
+        order += [0, 4, 1, 5, 2, 6, 3, 7]
+        
+        vertices = na.empty([corners.shape[2]*2*12,3])
+        for i in xrange(3):
+            vertices[:,i] = corners[order,i,:].ravel(order='F')
+
+        px, py, dz = self.project_to_plane(vertices, res=im.shape[:2])
+       
+        lines(im, px, py, colors, 24)
 
     def draw_line(self, im, x0, x1, color=na.array([1.0,1.0,1.0,1.0])):
-        #print ' '
-        #print self.origin
-        #print self.unit_vectors
-        #print x0, x1, na.abs(x1-x0).sum()
         dx0 = ((x0-self.origin)*self.unit_vectors[1]).sum()
         dx1 = ((x1-self.origin)*self.unit_vectors[1]).sum()
         dy0 = ((x0-self.origin)*self.unit_vectors[0]).sum()
         dy1 = ((x1-self.origin)*self.unit_vectors[0]).sum()
-        #print dx0, dx1, dy0, dy1
         py0 = int(self.resolution[0]*(dx0/self.width[0]))
         py1 = int(self.resolution[0]*(dx1/self.width[0]))
         px0 = int(self.resolution[1]*(dy0/self.width[1]))
         px1 = int(self.resolution[1]*(dy1/self.width[1]))
-        #print 'Drawing line from', px0, px1, py0, py1 
-        line(im, px0, py0, px1, py1, color=color)
+        lines(im, na.array([px0,px1]), na.array([py0,py1]), color=na.array([color,color]))
 
-    def add_grids(self, im, alpha=0.2, cmap='algae'):
-        levels = self.pf.h.grid_levels[:,0]
-        colors = apply_colormap(levels*1.0,
-                                color_bounds=[0,self.pf.h.max_level],
-                                cmap_name=cmap)*1.0/255.
-        colors = colors[0,:,:]
-        colors[:,3] = alpha
-        print 'c shapes:', colors.shape
-        #balls
-        for color, le, re in zip(colors, self.pf.h.grid_left_edge,
-                self.pf.h.grid_right_edge):
-            self.draw_box(im, le, re, color=color)
-
-    def draw_grids(self,im, alpha=0.3):
-        enhance(im)
-        #alpha = im.max()*alpha
-        print 'Setting alpha to %e' % alpha
-        self.add_grids(im, alpha=alpha, cmap='idl16')
-        #enhance(im)
+    def draw_grids(self,im, alpha=0.1):
+        ma = im.max()
+        if ma > 0.0: 
+            enhance(im)
+        self.add_grids(im, alpha=alpha, cmap='algae')
 
     def draw_domain(self,im,alpha=0.5):
-        alpha = im.max()*alpha
+        ma = im.max()
+        if ma > 0.0: 
+            enhance(im)
         self.draw_box(im, self.pf.domain_left_edge, self.pf.domain_right_edge,
                         color=na.array([1.0,1.0,1.0,alpha]))
-        
 
     def draw_box(self, im, le, re, color=na.array([1.0,1.0,1.0,1.0])):
-        self.draw_line(im, 
-                na.array((le[0], le[1], le[2])),
-                na.array((re[0], le[1], le[2])),
-                color=color)
-        self.draw_line(im, 
-                na.array((re[0], le[1], le[2])),
-                na.array((re[0], le[1], re[2])),
-                color=color)
-        self.draw_line(im, 
-                na.array((re[0], le[1], re[2])),
-                na.array((le[0], le[1], re[2])),
-                color=color)
-        self.draw_line(im, 
-                na.array((le[0], le[1], re[2])),
-                na.array((le[0], le[1], le[2])),
-                color=color)
-                    
-        self.draw_line(im, 
-                na.array((le[0], re[1], le[2])),
-                na.array((re[0], re[1], le[2])),
-                color=color)
-        self.draw_line(im, 
-                na.array((re[0], re[1], le[2])),
-                na.array((re[0], re[1], re[2])),
-                color=color)
-        self.draw_line(im, 
-                na.array((re[0], re[1], re[2])),
-                na.array((le[0], re[1], re[2])),
-                color=color)
-        self.draw_line(im, 
-                na.array((le[0], re[1], re[2])),
-                na.array((le[0], re[1], le[2])),
-                color=color)
+        corners = get_corners(le,re)
+        order  = [0, 1, 1, 2, 2, 3, 3, 0]
+        order += [4, 5, 5, 6, 6, 7, 7, 4]
+        order += [0, 4, 1, 5, 2, 6, 3, 7]
+        
+        vertices = na.empty([24,3])
+        for i in xrange(3):
+            vertices[:,i] = corners[order,i,:].ravel(order='F')
 
-        self.draw_line(im, 
-                na.array((le[0], le[1], le[2])),
-                na.array((le[0], re[1], le[2])),
-                color=color)
-        self.draw_line(im, 
-                na.array((re[0], le[1], le[2])),
-                na.array((re[0], re[1], le[2])),
-                color=color)
-        self.draw_line(im, 
-                na.array((le[0], le[1], re[2])),
-                na.array((le[0], re[1], re[2])),
-                color=color)
-        self.draw_line(im, 
-                na.array((re[0], le[1], re[2])),
-                na.array((re[0], re[1], re[2])),
-                color=color)
+        px, py, dz = self.project_to_plane(vertices, res=im.shape[:2])
+       
+        lines(im, px, py, color.reshape(1,4), 24)
 
     def look_at(self, new_center, north_vector = None):
         r"""Change the view direction based on a new focal point.


https://bitbucket.org/yt_analysis/yt/commits/c104f0bb2e41/
changeset:   c104f0bb2e41
branch:      yt
user:        samskillman
date:        2012-05-04 21:56:35
summary:     Adding the blenders file. This may be short lived
affected #:  1 file

diff -r 606c5668fcfc049b7606ce429c0a589bcbe91e62 -r c104f0bb2e410d25a75e59ba28779df48cbf5807 yt/visualization/volume_rendering/blenders.py
--- /dev/null
+++ b/yt/visualization/volume_rendering/blenders.py
@@ -0,0 +1,22 @@
+import numpy as na
+from yt.mods import *
+
+def enhance(im, stdval=6.0, just_alpha=True):
+    if just_alpha:
+        nz = im[im>0.0]
+        im[:] = im[:]/(nz.mean()+stdval*na.std(nz))
+        im[im>1.0]=1.0
+        im[im<0.0]=0.0
+    else:
+        for c in range(3):
+            nz = im[:,:,c][im[:,:,c]>0.0]
+            im[:,:,c] = im[:,:,c]/(nz.mean()+stdval*na.std(nz))
+            del nz
+        im[:,:][im>1.0]=1.0
+        im[:,:][im<0.0]=0.0
+
+if __name__ == 'main':
+    im = na.zeros((256,256,3))
+    line(im, 50,60,150,200)
+    write_bitmap(im,'test_line.png')
+


https://bitbucket.org/yt_analysis/yt/commits/3897cac538a6/
changeset:   3897cac538a6
branch:      yt
user:        samskillman
date:        2013-01-22 17:13:45
summary:     Merging plus fixing some new imports
affected #:  496 files
Diff not available.

https://bitbucket.org/yt_analysis/yt/commits/257507583532/
changeset:   257507583532
branch:      yt
user:        samskillman
date:        2013-01-22 17:25:41
summary:     Fixing an import
affected #:  1 file
Diff not available.

https://bitbucket.org/yt_analysis/yt/commits/1811330ee394/
changeset:   1811330ee394
branch:      yt
user:        samskillman
date:        2013-01-24 07:00:38
summary:     Addressing code comments.
affected #:  2 files
Diff not available.

https://bitbucket.org/yt_analysis/yt/commits/0f9279c29ca5/
changeset:   0f9279c29ca5
branch:      yt
user:        samskillman
date:        2013-01-24 07:19:46
summary:     Adding docstrings to line/box/grids/domain drawing.
affected #:  1 file
Diff not available.

https://bitbucket.org/yt_analysis/yt/commits/22d8fea68acb/
changeset:   22d8fea68acb
branch:      yt
user:        samskillman
date:        2013-01-24 07:22:19
summary:     Changing default alpha to 0.3 for all line/grid annotations.
affected #:  1 file
Diff not available.

https://bitbucket.org/yt_analysis/yt/commits/ec2e81dc0bc3/
changeset:   ec2e81dc0bc3
branch:      yt
user:        ngoldbaum
date:        2013-01-24 08:05:59
summary:     Merged in samskillman/yt (pull request #406)

Draw domain boundary, and first pass at drawing grids in rendering.
affected #:  5 files
Diff not available.

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