[yt-svn] commit/yt: 4 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Oct 17 14:25:47 PDT 2016
4 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/635abea514ad/
Changeset: 635abea514ad
Branch: yt
User: EGaraldi
Date: 2016-09-30 23:15:28+00:00
Summary: Added a radii field to PointSource and zpoints to allow variable sizes of
the point sources in 3D rendering. The radius may be different for each
source. It is in units of pixels in the rendered image, as this change
is primarily made in order to avoid point sources getting lost in
high-resolution images.
Affected #: 2 files
diff -r 1d70bf4124996d584483c173e37f29670a73db99 -r 635abea514add1de3613d6d8ba10864a523c8136 yt/utilities/lib/misc_utilities.pyx
--- a/yt/utilities/lib/misc_utilities.pyx
+++ b/yt/utilities/lib/misc_utilities.pyx
@@ -415,6 +415,7 @@
np.ndarray[np.int64_t, ndim=1] ys,
np.ndarray[np.float64_t, ndim=1] zs,
np.ndarray[np.float64_t, ndim=2] colors,
+ np.ndarray[np.int64_t, ndim=1] radii, #pixels
int points_per_color=1,
int thick=1,
int flip=0):
@@ -425,37 +426,45 @@
cdef np.float64_t[:] alpha
cdef np.float64_t talpha
cdef int i, j, c
+ cdef int kx, ky, r
+ cdef np.int64_t[:] idx
cdef np.int64_t x0, y0, yi0
cdef np.float64_t z0
alpha = np.zeros(4)
- for j in range(0, nl):
- x0 = xs[j]
- y0 = ys[j]
- z0 = zs[j]
- if (x0 < 0 or x0 >= nx): continue
- if (y0 < 0 or y0 >= ny): continue
- c = j/points_per_color
- for i in range(3):
- alpha[i] = colors[c, i] * colors[c, 3]
- alpha[3] = colors[c, 3]
- if flip:
- yi0 = ny - y0
- else:
- yi0 = y0
+ #the sources must be ordered along z to avoid edges when two overlap
+ idx = np.argsort(zs)
+ for j in idx: #range(0, nl):
+ r = radii[j]
+ for kx in range(-r,r+1):
+ for ky in range(-r,r+1):
+ if (kx**2 + ky**2 > (r+0.3)**2): continue
+ x0 = xs[j]+kx
+ y0 = ys[j]+ky
+ z0 = zs[j]
+ if (x0 < 0 or x0 >= nx): continue
+ if (y0 < 0 or y0 >= ny): continue
+ c = j/points_per_color
+ for i in range(3):
+ alpha[i] = colors[c, i] * colors[c, 3]
+ alpha[3] = colors[c, 3]
+ if flip:
+ yi0 = ny - y0
+ else:
+ yi0 = y0
- if z0 < zbuffer[x0, yi0]:
- if alpha[3] != 1.0:
- talpha = image[x0, yi0, 3]
- image[x0, yi0, 3] = alpha[3] + talpha * (1 - alpha[3])
- for i in range(3):
- image[x0, yi0, i] = (alpha[3]*alpha[i] + image[x0, yi0, i]*talpha*(1.0-alpha[3]))/image[x0,yi0,3]
- if image[x0, yi0, 3] == 0.0:
- image[x0, yi0, i] = 0.0
- else:
- for i in range(4):
- image[x0, yi0, i] = alpha[i]
- if (1.0 - image[x0, yi0, 3] < 1.0e-4):
- zbuffer[x0, yi0] = z0
+ if z0 < zbuffer[x0, yi0]:
+ if alpha[3] != 1.0:
+ talpha = image[x0, yi0, 3]
+ image[x0, yi0, 3] = alpha[3] + talpha * (1 - alpha[3])
+ for i in range(3):
+ image[x0, yi0, i] = (alpha[3]*alpha[i] + image[x0, yi0, i]*talpha*(1.0-alpha[3]))/image[x0,yi0,3]
+ if image[x0, yi0, 3] == 0.0:
+ image[x0, yi0, i] = 0.0
+ else:
+ for i in range(4):
+ image[x0, yi0, i] = alpha[i]
+ if (1.0 - image[x0, yi0, 3] < 1.0e-4):
+ zbuffer[x0, yi0] = z0
return
diff -r 1d70bf4124996d584483c173e37f29670a73db99 -r 635abea514add1de3613d6d8ba10864a523c8136 yt/visualization/volume_rendering/render_source.py
--- a/yt/visualization/volume_rendering/render_source.py
+++ b/yt/visualization/volume_rendering/render_source.py
@@ -819,6 +819,8 @@
color_stride : int, optional
The stride with which to access the colors when putting them on the
scene.
+ radii : array, shape (N), optional
+ The radii of the points in the final image, in pixels (int)
Examples
--------
@@ -850,17 +852,24 @@
_image = None
data_source = None
- def __init__(self, positions, colors=None, color_stride=1):
+ def __init__(self, positions, colors=None, color_stride=1, radii=None):
assert(positions.ndim == 2 and positions.shape[1] == 3)
if colors is not None:
assert(colors.ndim == 2 and colors.shape[1] == 4)
assert(colors.shape[0] == positions.shape[0])
+ if radii is not None:
+ assert(radii.ndim == 1)
+ assert(radii.shape[0] == positions.shape[0])
self.positions = positions
# If colors aren't individually set, make black with full opacity
if colors is None:
colors = np.ones((len(positions), 4))
self.colors = colors
self.color_stride = color_stride
+ # If radii aren't individually set, we default to 1 pixel
+ if radii is None:
+ radii = np.ones(len(positions)).astype(int)
+ self.radii = radii
def render(self, camera, zbuffer=None):
"""Renders an image using the provided camera
@@ -895,8 +904,8 @@
# DRAW SOME POINTS
camera.lens.setup_box_properties(camera)
px, py, dz = camera.lens.project_to_plane(camera, vertices)
-
- zpoints(empty, z, px, py, dz, self.colors, self.color_stride)
+
+ zpoints(empty, z, px, py, dz, self.colors, self.radii, self.color_stride)
self.zbuffer = zbuffer
return zbuffer
https://bitbucket.org/yt_analysis/yt/commits/a4ba8ab740cf/
Changeset: a4ba8ab740cf
Branch: yt
User: EGaraldi
Date: 2016-10-01 09:48:35+00:00
Summary: Optimized the loop inside zpoints. Bugfix: set default radius of PointSource
to 0 (previously 1), i.e. points will be 1 pixel if a radius is not set.
Affected #: 1 file
diff -r 635abea514add1de3613d6d8ba10864a523c8136 -r a4ba8ab740cf23e134861e68e2705de455f0bc0d yt/utilities/lib/misc_utilities.pyx
--- a/yt/utilities/lib/misc_utilities.pyx
+++ b/yt/utilities/lib/misc_utilities.pyx
@@ -426,23 +426,26 @@
cdef np.float64_t[:] alpha
cdef np.float64_t talpha
cdef int i, j, c
- cdef int kx, ky, r
- cdef np.int64_t[:] idx
+ cdef np.int64_t kx, ky, r, r2
+ cdef np.int64_t[:] idx, ks
cdef np.int64_t x0, y0, yi0
cdef np.float64_t z0
alpha = np.zeros(4)
#the sources must be ordered along z to avoid edges when two overlap
idx = np.argsort(zs)
- for j in idx: #range(0, nl):
+ for j in idx:
r = radii[j]
- for kx in range(-r,r+1):
- for ky in range(-r,r+1):
- if (kx**2 + ky**2 > (r+0.3)**2): continue
- x0 = xs[j]+kx
+ r2 = int((r+0.3)*(r+0.3)) #0.3 to get nicer shape
+ ks = np.arange(-r,r+1,dtype=int)
+ z0 = zs[j]
+ for kx in ks:
+ x0 = xs[j]+kx
+ if (x0 < 0 or x0 >= nx): continue
+ for ky in ks:
y0 = ys[j]+ky
- z0 = zs[j]
- if (x0 < 0 or x0 >= nx): continue
if (y0 < 0 or y0 >= ny): continue
+ if (kx*kx + ky*ky > r2): continue
+
c = j/points_per_color
for i in range(3):
alpha[i] = colors[c, i] * colors[c, 3]
https://bitbucket.org/yt_analysis/yt/commits/81539ecf2999/
Changeset: 81539ecf2999
Branch: yt
User: EGaraldi
Date: 2016-10-06 08:48:29+00:00
Summary: Add ability to broadcast a single radii value to the correct shape in render_source.
Affected #: 1 file
diff -r a4ba8ab740cf23e134861e68e2705de455f0bc0d -r 81539ecf299953255b7c991653563f5250438091 yt/visualization/volume_rendering/render_source.py
--- a/yt/visualization/volume_rendering/render_source.py
+++ b/yt/visualization/volume_rendering/render_source.py
@@ -15,7 +15,7 @@
from functools import wraps
from yt.config import \
ytcfg
-from yt.funcs import mylog, ensure_numpy_array
+from yt.funcs import mylog, ensure_numpy_array, iterable
from yt.utilities.parallel_tools.parallel_analysis_interface import \
ParallelAnalysisInterface
from yt.utilities.amr_kdtree.api import AMRKDTree
@@ -857,7 +857,12 @@
if colors is not None:
assert(colors.ndim == 2 and colors.shape[1] == 4)
assert(colors.shape[0] == positions.shape[0])
- if radii is not None:
+ if not iterable(radii):
+ if radii is not None: #broadcast the value
+ radii = radii*np.ones(positions.shape[0], dtype='int64')
+ else: #default radii to 0 pixels (i.e. point is 1 pixel wide)
+ radii = np.zeros(positions.shape[0], dtype='int64')
+ else:
assert(radii.ndim == 1)
assert(radii.shape[0] == positions.shape[0])
self.positions = positions
@@ -866,9 +871,6 @@
colors = np.ones((len(positions), 4))
self.colors = colors
self.color_stride = color_stride
- # If radii aren't individually set, we default to 1 pixel
- if radii is None:
- radii = np.ones(len(positions)).astype(int)
self.radii = radii
def render(self, camera, zbuffer=None):
https://bitbucket.org/yt_analysis/yt/commits/060539ec8b44/
Changeset: 060539ec8b44
Branch: yt
User: ngoldbaum
Date: 2016-10-17 21:24:58+00:00
Summary: merging PR 2404 (https://bitbucket.org/yt_analysis/yt/pull-requests/2404)
clear conflicts
Affected #: 2 files
diff -r 2e22db274f5d828ac7ab9ee0a6d92bfaa4adfca1 -r 060539ec8b44431127640887a5b93c23d5643266 yt/utilities/lib/misc_utilities.pyx
--- a/yt/utilities/lib/misc_utilities.pyx
+++ b/yt/utilities/lib/misc_utilities.pyx
@@ -415,6 +415,7 @@
np.ndarray[np.int64_t, ndim=1] ys,
np.ndarray[np.float64_t, ndim=1] zs,
np.ndarray[np.float64_t, ndim=2] colors,
+ np.ndarray[np.int64_t, ndim=1] radii, #pixels
int points_per_color=1,
int thick=1,
int flip=0):
@@ -425,37 +426,48 @@
cdef np.float64_t[:] alpha
cdef np.float64_t talpha
cdef int i, j, c
+ cdef np.int64_t kx, ky, r, r2
+ cdef np.int64_t[:] idx, ks
cdef np.int64_t x0, y0, yi0
cdef np.float64_t z0
alpha = np.zeros(4)
- for j in range(0, nl):
- x0 = xs[j]
- y0 = ys[j]
+ #the sources must be ordered along z to avoid edges when two overlap
+ idx = np.argsort(zs)
+ for j in idx:
+ r = radii[j]
+ r2 = int((r+0.3)*(r+0.3)) #0.3 to get nicer shape
+ ks = np.arange(-r,r+1,dtype=int)
z0 = zs[j]
- if (x0 < 0 or x0 >= nx): continue
- if (y0 < 0 or y0 >= ny): continue
- c = j/points_per_color
- for i in range(3):
- alpha[i] = colors[c, i] * colors[c, 3]
- alpha[3] = colors[c, 3]
- if flip:
- yi0 = ny - y0
- else:
- yi0 = y0
+ for kx in ks:
+ x0 = xs[j]+kx
+ if (x0 < 0 or x0 >= nx): continue
+ for ky in ks:
+ y0 = ys[j]+ky
+ if (y0 < 0 or y0 >= ny): continue
+ if (kx*kx + ky*ky > r2): continue
- if z0 < zbuffer[x0, yi0]:
- if alpha[3] != 1.0:
- talpha = image[x0, yi0, 3]
- image[x0, yi0, 3] = alpha[3] + talpha * (1 - alpha[3])
+ c = j/points_per_color
for i in range(3):
- image[x0, yi0, i] = (alpha[3]*alpha[i] + image[x0, yi0, i]*talpha*(1.0-alpha[3]))/image[x0,yi0,3]
- if image[x0, yi0, 3] == 0.0:
- image[x0, yi0, i] = 0.0
- else:
- for i in range(4):
- image[x0, yi0, i] = alpha[i]
- if (1.0 - image[x0, yi0, 3] < 1.0e-4):
- zbuffer[x0, yi0] = z0
+ alpha[i] = colors[c, i] * colors[c, 3]
+ alpha[3] = colors[c, 3]
+ if flip:
+ yi0 = ny - y0
+ else:
+ yi0 = y0
+
+ if z0 < zbuffer[x0, yi0]:
+ if alpha[3] != 1.0:
+ talpha = image[x0, yi0, 3]
+ image[x0, yi0, 3] = alpha[3] + talpha * (1 - alpha[3])
+ for i in range(3):
+ image[x0, yi0, i] = (alpha[3]*alpha[i] + image[x0, yi0, i]*talpha*(1.0-alpha[3]))/image[x0,yi0,3]
+ if image[x0, yi0, 3] == 0.0:
+ image[x0, yi0, i] = 0.0
+ else:
+ for i in range(4):
+ image[x0, yi0, i] = alpha[i]
+ if (1.0 - image[x0, yi0, 3] < 1.0e-4):
+ zbuffer[x0, yi0] = z0
return
diff -r 2e22db274f5d828ac7ab9ee0a6d92bfaa4adfca1 -r 060539ec8b44431127640887a5b93c23d5643266 yt/visualization/volume_rendering/render_source.py
--- a/yt/visualization/volume_rendering/render_source.py
+++ b/yt/visualization/volume_rendering/render_source.py
@@ -15,7 +15,7 @@
from functools import wraps
from yt.config import \
ytcfg
-from yt.funcs import mylog, ensure_numpy_array
+from yt.funcs import mylog, ensure_numpy_array, iterable
from yt.utilities.parallel_tools.parallel_analysis_interface import \
ParallelAnalysisInterface
from yt.utilities.amr_kdtree.api import AMRKDTree
@@ -807,6 +807,8 @@
color_stride : int, optional
The stride with which to access the colors when putting them on the
scene.
+ radii : array, shape (N), optional
+ The radii of the points in the final image, in pixels (int)
Examples
--------
@@ -838,17 +840,26 @@
_image = None
data_source = None
- def __init__(self, positions, colors=None, color_stride=1):
+ def __init__(self, positions, colors=None, color_stride=1, radii=None):
assert(positions.ndim == 2 and positions.shape[1] == 3)
if colors is not None:
assert(colors.ndim == 2 and colors.shape[1] == 4)
assert(colors.shape[0] == positions.shape[0])
+ if not iterable(radii):
+ if radii is not None: #broadcast the value
+ radii = radii*np.ones(positions.shape[0], dtype='int64')
+ else: #default radii to 0 pixels (i.e. point is 1 pixel wide)
+ radii = np.zeros(positions.shape[0], dtype='int64')
+ else:
+ assert(radii.ndim == 1)
+ assert(radii.shape[0] == positions.shape[0])
self.positions = positions
# If colors aren't individually set, make black with full opacity
if colors is None:
colors = np.ones((len(positions), 4))
self.colors = colors
self.color_stride = color_stride
+ self.radii = radii
def render(self, camera, zbuffer=None):
"""Renders an image using the provided camera
@@ -883,8 +894,8 @@
# DRAW SOME POINTS
camera.lens.setup_box_properties(camera)
px, py, dz = camera.lens.project_to_plane(camera, vertices)
-
- zpoints(empty, z, px, py, dz, self.colors, self.color_stride)
+
+ zpoints(empty, z, px, py, dz, self.colors, self.radii, self.color_stride)
self.zbuffer = zbuffer
return zbuffer
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