[Yt-svn] yt-commit r1559 - in trunk/yt: . extensions/volume_rendering lagos
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Sun Dec 20 10:02:22 PST 2009
Author: mturk
Date: Sun Dec 20 10:02:20 2009
New Revision: 1559
URL: http://yt.enzotools.org/changeset/1559
Log:
Added a TraitsUI widget for describing a transfer function (pretty busy UI
right now, but it works) and fixed up smoothed covering grid ghost zone
generation using the new integer smoothed covering grid.
Added:
trunk/yt/extensions/volume_rendering/transfer_function_widget.py
Modified:
trunk/yt/funcs.py
trunk/yt/lagos/BaseDataTypes.py
trunk/yt/lagos/BaseGridType.py
Added: trunk/yt/extensions/volume_rendering/transfer_function_widget.py
==============================================================================
--- (empty file)
+++ trunk/yt/extensions/volume_rendering/transfer_function_widget.py Sun Dec 20 10:02:20 2009
@@ -0,0 +1,224 @@
+"""
+Simple transfer function editor
+
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: KIPAC/SLAC/Stanford
+Homepage: http://yt.enzotools.org/
+License:
+ Copyright (C) 2009 Matthew Turk. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+
+import numpy as na
+import cPickle
+from TransferFunction import ColorTransferFunction
+
+from enthought.traits.api import \
+ HasTraits, Float, List, Instance, Button, Array, CArray, Range, \
+ DelegatesTo, Property, Any, Code, Callable
+from enthought.traits.ui.api import \
+ View, Item, HSplit, VSplit, ListEditor, InstanceEditor, ValueEditor, \
+ HGroup, VGroup, CodeEditor, TextEditor
+from enthought.chaco.api import Plot, ArrayPlotData
+from enthought.enable.component_editor import ComponentEditor
+import enthought.pyface.api as pyface
+
+class TFGaussian(HasTraits):
+ center = Range(low = 'left_edge',
+ high = 'right_edge')
+ left_edge = DelegatesTo('tf')
+ right_edge = DelegatesTo('tf')
+
+ tf = Any
+
+ width = Property
+ rwidth = Range(0.0, 0.5, 0.05)
+
+ red = Range(0.0, 1.0, 0.5)
+ green = Range(0.0, 1.0, 0.5)
+ blue = Range(0.0, 1.0, 0.5)
+ alpha = Range(0.0, 1.0, 1.0)
+
+ traits_view = View(VGroup(
+ HGroup(
+ Item('center'),
+ Item('rwidth', label='Width')
+ ),
+ HGroup(
+ Item('red'),
+ Item('green'),
+ Item('blue'),
+ Item('alpha')
+ ),
+ ),
+ )
+
+ def _get_width(self):
+ width = self.rwidth * (self.tf.right_edge - self.tf.left_edge)
+ return width
+
+ def _center_default(self):
+ return (self.left_edge + self.right_edge)/2.0
+
+ def _width_default(self):
+ return (self.right_edge - self.left_edge)/20.0
+
+ def _red_changed(self):
+ self.tf._redraw()
+
+ def _green_changed(self):
+ self.tf._redraw()
+
+ def _blue_changed(self):
+ self.tf._redraw()
+
+ def _alpha_changed(self):
+ self.tf._redraw()
+
+ def _center_changed(self):
+ self.tf._redraw()
+
+ def _height_changed(self):
+ self.tf._redraw()
+
+ def _rwidth_changed(self):
+ self.tf._redraw()
+
+class TFColors(HasTraits):
+ gaussians = List(Instance(TFGaussian))
+ transfer_function = Instance(ColorTransferFunction)
+
+ left_edge = Float(0.0)
+ right_edge = Float(10.0)
+
+ add_gaussian = Button
+ run_routine = Button
+ save_function = Button
+
+ routine = Callable
+
+ plot_data = Instance(ArrayPlotData)
+ image_data = Instance(ArrayPlotData)
+ vr_image_data = Instance(ArrayPlotData)
+
+ plot = Instance(Plot)
+ image_plot = Instance(Plot)
+ vr_image_plot = Instance(Plot)
+
+ traits_view = View(VGroup(
+ HGroup(
+ VGroup(
+ Item('image_plot', editor=ComponentEditor(),
+ show_label=False, resizable=True),
+ Item('plot', editor=ComponentEditor(),
+ show_label=False, resizable=True),
+ ),
+ Item('vr_image_plot', editor=ComponentEditor(),
+ show_label=False, resizable=True,
+ width=512, height=512)),
+ Item("gaussians", style='custom',
+ editor=ListEditor(style='custom'),
+ show_label=False,
+ ),
+ HGroup(Item("left_edge"), Item("right_edge")),
+ HGroup(Item("add_gaussian", show_label = False),
+ Item("run_routine", show_label = False),
+ Item("save_function", show_label = False),
+ ),
+ ),
+ width=960, height=800,
+ resizable=True)
+
+ def _plot_data_default(self):
+ return ArrayPlotData(rx = (0.0, 1.0), ry = (0.0, 0.0),
+ gx = (0.0, 1.0), gy = (0.0, 0.0),
+ bx = (0.0, 1.0), by = (0.0, 0.0),
+ ax = (0.0, 1.0), ay = (0.0, 0.0),
+ lx = (0.0, 1.0), ly = (0.0, 0.0),
+ ux = (0.0, 1.0), uy = (1.0, 1.0))
+
+ def _image_data_default(self):
+ return ArrayPlotData(image_data = na.zeros((40,256,4), dtype='uint8'))
+
+ def _vr_image_data_default(self):
+ return ArrayPlotData(vr_image_data = na.zeros((512,512,3), dtype='uint8'))
+
+ def _plot_default(self):
+ p = Plot(self.plot_data)
+ p.plot( ("rx", "ry"), type='line', color='red')
+ p.plot( ("gx", "gy"), type='line', color='green')
+ p.plot( ("bx", "by"), type='line', color='blue')
+ p.plot( ("ax", "ay"), type='line', color='black')
+ p.plot( ("lx", "ly"), type='line', color='black')
+ p.plot( ("ux", "uy"), type='line', color='black')
+ return p
+
+ def _image_plot_default(self):
+ plot = Plot(self.image_data, default_origin="top left")
+ #plot.x_axis.orientation = "top"
+ img_plot = plot.img_plot("image_data")[0]
+
+ plot.bgcolor = "black"
+ return plot
+
+ def _vr_image_plot_default(self):
+ plot = Plot(self.vr_image_data, default_origin="top left")
+ #plot.x_axis.orientation = "top"
+ img_plot = plot.img_plot("vr_image_data")[0]
+
+ plot.bgcolor = "black"
+ return plot
+
+ def _add_gaussian_fired(self):
+ self.gaussians.append(TFGaussian(tf = self))
+
+ def _redraw(self):
+ self.transfer_function = ColorTransferFunction(
+ (self.left_edge, self.right_edge))
+ for g in self.gaussians:
+ self.transfer_function.add_gaussian(g.center, g.width,
+ (g.red, g.green, g.blue, g.alpha))
+ for f, c in zip(self.transfer_function.funcs, "rgba"):
+ self.plot_data["%sx" % c] = f.x
+ self.plot_data["%sy" % c] = f.y
+
+ # Now we update the image describing the colors
+ # This makes the assumption that all the x values are the same
+ image = na.zeros((40, self.transfer_function.nbins, 4), dtype='uint8')
+ for i,f in enumerate(self.transfer_function.funcs):
+ image[:,:,i] = (f.y[None,:] * 255).astype('uint8')
+ self.image_data["image_data"] = image
+
+ def _run_routine_fired(self):
+ img_data = self.routine(self.transfer_function)
+ self.vr_image_data['vr_image_data'] = img_data
+
+ def _save_function_fired(self):
+ self._redraw()
+ dlg = pyface.FileDialog(
+ action='save as',
+ wildcard="*.ctf",
+ )
+ if dlg.open() == pyface.OK:
+ print "Saving:", dlg.path
+ tf = self.transfer_function
+ f = open(dlg.path, "wb")
+ cPickle.dump(tf, f)
+
+if __name__ == "__main__":
+ tfc = TFColors()
+ tfc.configure_traits()
Modified: trunk/yt/funcs.py
==============================================================================
--- trunk/yt/funcs.py (original)
+++ trunk/yt/funcs.py Sun Dec 20 10:02:20 2009
@@ -320,6 +320,8 @@
if EMBEDDED_MODE: return DummyProgressBar()
except:
pass
+ elif "CODENODE" in os.environ:
+ return DummyProgressBar()
widgets = [ title,
pb.Percentage(), ' ',
pb.Bar(marker=pb.RotatingMarker()),
Modified: trunk/yt/lagos/BaseDataTypes.py
==============================================================================
--- trunk/yt/lagos/BaseDataTypes.py (original)
+++ trunk/yt/lagos/BaseDataTypes.py Sun Dec 20 10:02:20 2009
@@ -28,6 +28,7 @@
data_object_registry = {}
from yt.lagos import *
+import math
def restore_grid_state(func):
"""
@@ -534,9 +535,9 @@
mask = na.zeros(grid.ActiveDimensions, dtype='int')
dts = na.zeros(grid.ActiveDimensions, dtype='float64')
ts = na.zeros(grid.ActiveDimensions, dtype='float64')
- import RTIntegrator as RT
- RT.VoxelTraversal(mask, ts, dts, grid.LeftEdge, grid.RightEdge,
- grid.dds, self.center, self.vec)
+ from yt.amr_utils import VoxelTraversal
+ VoxelTraversal(mask, ts, dts, grid.LeftEdge, grid.RightEdge,
+ grid.dds, self.center, self.vec)
self._dts[grid.id] = na.abs(dts)
self._ts[grid.id] = na.abs(ts)
return mask
@@ -1482,7 +1483,8 @@
self.dims = na.array([dims]*2)
self.ActiveDimensions = na.array([dims]*3, dtype='int32')
self.right_edge = self.left_edge + self.ActiveDimensions*self.dds
- self.global_startindex = na.rint(self.left_edge/self.dds).astype('int64')
+ self.global_startindex = na.rint((self.left_edge - self.pf["DomainLeftEdge"])
+ /self.dds).astype('int64')
self._dls = {}
self.domain_width = na.rint((self.pf["DomainRightEdge"] -
self.pf["DomainLeftEdge"])/self.dds).astype('int64')
@@ -2608,13 +2610,19 @@
self._refine(1, field)
if self.level > 0:
self[field] = self[field][1:-1,1:-1,1:-1]
+ if na.any(self[field] == -999):
+ # and self.dx < self.hierarchy.grids[0].dx:
+ n_bad = na.where(self[field]==-999)[0].size
+ mylog.error("Covering problem: %s cells are uncovered", n_bad)
+ raise KeyError(n_bad)
if self._use_pbar: pbar.finish()
def _update_level_state(self, level, field = None):
dx = self.pf.h.select_grids(level)[0].dds
for ax, v in zip('xyz', dx): self['cd%s'%ax] = v
+ LL = self.left_edge - self.pf["DomainLeftEdge"]
self._old_global_startindex = self.global_startindex
- self.global_startindex = na.array(na.floor(1.000001*self.left_edge / dx) - 1, dtype='int64')
+ self.global_startindex = na.array(na.floor(1.000001*LL / dx) - 1, dtype='int64')
self.domain_width = na.rint((self.pf["DomainRightEdge"] -
self.pf["DomainLeftEdge"])/dx).astype('int64')
if level == 0 and self.level > 0:
@@ -2622,7 +2630,8 @@
idims = na.ceil((self.right_edge-self.left_edge)/dx) + 2
self[field] = na.zeros(idims,dtype='float64')-999
elif level == 0 and self.level == 0:
- self.global_startindex = na.array(na.floor(self.left_edge / dx), dtype='int64')
+ DLE = self.pf["DomainLeftEdge"]
+ self.global_startindex = na.array(na.floor(LL/ dx), dtype='int64')
idims = na.ceil((self.right_edge-self.left_edge)/dx)
self[field] = na.zeros(idims,dtype='float64')-999
Modified: trunk/yt/lagos/BaseGridType.py
==============================================================================
--- trunk/yt/lagos/BaseGridType.py (original)
+++ trunk/yt/lagos/BaseGridType.py Sun Dec 20 10:02:20 2009
@@ -115,7 +115,7 @@
# This is only going to be raised if n_gz > 0
n_gz = ngt_exception.ghost_zones
f_gz = ngt_exception.fields
- gz_grid = self.retrieve_ghost_zones(n_gz, f_gz, smoothed=False)
+ gz_grid = self.retrieve_ghost_zones(n_gz, f_gz, smoothed=True)
temp_array = self.pf.field_info[field](gz_grid)
sl = [slice(n_gz,-n_gz)] * 3
self[field] = temp_array[sl]
@@ -414,8 +414,8 @@
# than the grid by nZones*dx in each direction
nl = self.get_global_startindex() - n_zones
nr = nl + self.ActiveDimensions + 2*n_zones
- new_left_edge = nl * self.dds
- new_right_edge = nr * self.dds
+ new_left_edge = nl * self.dds + self.pf["DomainLeftEdge"]
+ new_right_edge = nr * self.dds + self.pf["DomainLeftEdge"]
# Something different needs to be done for the root grid, though
level = self.Level
if all_levels:
@@ -425,8 +425,10 @@
'num_ghost_zones':n_zones,
'use_pbar':False, 'fields':fields}
if smoothed:
- cube = self.hierarchy.smoothed_covering_grid(
- level, new_left_edge, new_right_edge, **kwargs)
+ #cube = self.hierarchy.smoothed_covering_grid(
+ # level, new_left_edge, new_right_edge, **kwargs)
+ cube = self.hierarchy.si_covering_grid(
+ level, new_left_edge, **kwargs)
else:
cube = self.hierarchy.covering_grid(
level, new_left_edge, **kwargs)
More information about the yt-svn
mailing list