[cig-commits] r5542 - in mc/3D/CitcomS/trunk/visual/Mayavi2: .
citcoms_plugins citcoms_plugins/plugins
citcoms_plugins/plugins/filter
luis at geodynamics.org
luis at geodynamics.org
Fri Dec 8 09:40:08 PST 2006
Author: luis
Date: 2006-12-08 09:40:08 -0800 (Fri, 08 Dec 2006)
New Revision: 5542
Added:
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/Citcoms_HdfDisplay.py
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/__init__.py
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomSHDFUgrid.py
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomS_hdf_file_reader.py
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/OpenCitcomSFILES.py
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/__init__.py
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSFilterActions.py
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSSphere.py
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSreduce.py
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSshowCaps.py
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSshowSurface.py
mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/__init__.py
Log:
Forking original plugins
Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/Citcoms_HdfDisplay.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/Citcoms_HdfDisplay.py 2006-12-08 17:32:25 UTC (rev 5541)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/Citcoms_HdfDisplay.py 2006-12-08 17:40:08 UTC (rev 5542)
@@ -0,0 +1,147 @@
+#! /usr/bin/env python
+try:
+ import wxversion
+ wxversion.ensureMinimal('2.6')
+except ImportError:
+ pass
+
+from enthought.mayavi.app import Mayavi
+import sys
+from os.path import isfile
+from getopt import getopt, GetoptError
+
+class HdfDisplay(Mayavi):
+
+ filename = None
+ timestep = 0
+ nx_redu = 0
+ ny_redu = 0
+ nz_redu = 0
+
+ def run(self):
+
+ from enthought.mayavi.sources.vtk_file_reader import VTKFileReader
+ #import modules here
+ from enthought.mayavi.modules import surface, glyph , axes, outline, orientation_axes, scalar_cut_plane
+ from enthought.mayavi.sources.vtk_data_source import VTKDataSource
+ from enthought.tvtk.api import tvtk
+ #citcomS Filter and Modules
+ from plugins.CitcomSHDFUgrid import CitcomSHDFUgrid
+ from plugins.filter.CitcomSshowCaps import CitcomSshowCaps
+ from plugins.filter.CitcomSreduce import CitcomSreduce
+
+ import re
+
+
+ script = self.script
+
+ #DEFINES
+ orange = (1.0,0.5,0)
+ reduce_factor = 2
+
+
+ #Read Hdf file
+ src_hdf = CitcomSHDFUgrid()
+ hexgrid = src_hdf.initialize(self.filename,self.timestep,self.nx_redu,self.ny_redu,self.nz_redu)
+ radius_inner = src_hdf._radius_inner
+ data = VTKDataSource()
+ data.data = hexgrid
+
+
+ ###########Display Data############
+ #Create new scene
+ script.new_scene()
+ script.add_source(data)
+
+ scap = CitcomSshowCaps()
+ script.add_filter(scap)
+
+
+ #Show ScalarCutPlane
+ scp = scalar_cut_plane.ScalarCutPlane()
+ script.add_module(scp)
+
+ #Add filter for a reduce grid
+ redu = CitcomSreduce()
+ #redu.setvalues(nx,ny,nz)
+ script.add_filter(redu)
+
+ gly = glyph.Glyph()
+ gly.glyph.glyph_source.scale = 0.082
+ gly.glyph.scale_mode = 'scale_by_scalar'
+ gly.glyph.color_mode = 'color_by_scalar'
+ script.add_module(gly)
+ mm = gly.module_manager
+ mm.scalar_lut_manager.use_default_range = False
+ mm.scalar_lut_manager.data_range = 0.0, 1.0
+ ################### Create CORE ################################
+ #Load VTK Data Sets
+ sphere = tvtk.SphereSource()
+ sphere.radius = radius_inner
+ sphere.theta_resolution = 24
+ sphere.phi_resolution = 24
+
+ # Create a mesh from the data created above.
+ src = VTKDataSource()
+ src.data = sphere.output
+ script.add_source(src)
+
+ #Show Surface
+ surf_module = surface.Surface()
+ surf_module.actor.property.color = orange
+ script.add_module(surf_module)
+
+
+ # to create the rendering scene
+ ## your stuff here
+
+if __name__ == '__main__':
+ mc = HdfDisplay()
+ if len(sys.argv)>=3:
+ mc.filename = sys.argv[1]
+ try:
+ mc.timestep = int(sys.argv[2])
+ except ValueError:
+ print "Timestep is not a number."
+ sys.exit(1)
+ if not isfile(mc.filename):
+ print "File not found."
+ sys.exit(1)
+
+ else:
+ print "[filename] [timestep] -x [Reduce Grid Size X] -y [Reduce Grid Size X] -z [Reduce Grid Size Z]"
+ sys.exit(0)
+ ##parse for reduction factors
+ try:
+ opts, args = getopt(sys.argv[3:], "x:y:z:", ['x=','y=','z='])
+ except GetoptError, msg:
+ print "Error: %s" % msg
+ sys.exit(1)
+
+ for opt,arg in opts:
+ if opt in ('-x','--nx_redu'):
+ try:
+ mc.nx_redu = int(arg)
+ print "Reducing Grid Size to x:",mc.nx_redu
+ except ValueError:
+ print "x is not a number..."
+ sys.exit(1)
+
+ if opt in ('-y','--ny_redu'):
+ try:
+ mc.ny_redu = int(arg)
+ print "Reducing Grid Size to y:",mc.ny_redu
+ except ValueError:
+ print "y is not a number..."
+ sys.exit(1)
+
+ if opt in ('-z','--nz_redu'):
+ try:
+ mc.nz_redu = int(arg)
+ print "Reducing Grid Size to z:",mc.nz_redu
+
+ except ValueError:
+ print "z is not a number..."
+ sys.exit(1)
+
+ mc.main()
Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/__init__.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/__init__.py 2006-12-08 17:32:25 UTC (rev 5541)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/__init__.py 2006-12-08 17:40:08 UTC (rev 5542)
@@ -0,0 +1 @@
+# Author: Martin Weier
Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomSHDFUgrid.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomSHDFUgrid.py 2006-12-08 17:32:25 UTC (rev 5541)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomSHDFUgrid.py 2006-12-08 17:40:08 UTC (rev 5542)
@@ -0,0 +1,253 @@
+# Script to generate VTKUnstructuredGrid objects from CitcomS hdf files
+# author: Martin Weier
+# Copyright (C) 2006 California Institue of Technology
+#
+# This program 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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+
+from enthought.tvtk.api import tvtk
+import tables #For HDF support
+import numpy
+from math import *
+from datetime import datetime
+
+class CitcomSHDFUgrid:
+
+ """This Class converts CitcomS hdf files to tvtk UnstructuredGrid Dataset Objects """
+
+ data = None
+ _nx = None
+ _ny = None
+ _nz = None
+ _nx_redu = None
+ _ny_redu = None
+ _nz_redu = None
+ _radius_inner = None
+ _radius_outer = None
+ timesteps = None
+ frequency = None
+
+ progress = 0
+
+ #Global because a Unstructured Grid can only hold one scalar value at a time
+ #but our hdf file reader plugin wants to be able to read both
+ __vtkordered_visc = tvtk.FloatArray()
+ __vtkordered_temp = tvtk.FloatArray()
+
+
+ def vtk_iter(self,nx,ny,nz):
+ """Iterator for CitcomDataRepresentation(yxz) to VTK(xyz)"""
+ for i in xrange(nx):
+ for j in xrange(ny):
+ for k in xrange(nz):
+ yield k + nz * i + nz * nx * j
+
+
+ def reduce_iter(self,n,nredu):
+ """Iterator to reduce the CitcomS grid"""
+ i=0
+ n_f=float(n)
+ nredu_f=float(nredu)
+ fl=(n_f-1)/nredu_f
+ redu = 0
+ for i in xrange(nredu+1):
+ yield int(round(redu))
+ redu = redu + fl
+
+
+ def velocity2cart(self,vel_colat,vel_long,r, x, y, z):
+ """Converts vectors in spherical to cartesian coordiantes"""
+ x1 = r*sin(x)*cos(y)+vel_colat*cos(x)*cos(y)-vel_long*sin(y)
+ y1 = r*sin(x)*sin(y)+vel_colat*cos(x)*sin(y)+vel_long*cos(y)
+ z1 = r*cos(x)-vel_colat*sin(x)
+ return x1, y1, z1
+
+
+ #Converts Spherical to Cartesian Coordinates
+ def RTF2XYZ(self,thet, phi, r):
+ """Converts points from spherical to cartesian coordinates"""
+ x = r * sin(thet) * cos(phi)
+ y = r * sin(thet) * sin(phi)
+ z = r * cos(thet)
+ return x, y, z
+
+
+
+ def __citcom2vtk(self,t,f,nproc_surf,nx_redu,ny_redu,nz_redu):
+ """Method to convert one timestep from a hdf file to a Vtk file. This Method is used
+ by the method initialize. Initialize reads the necessary meta information from the hdf file"""
+
+ hexagrid = tvtk.UnstructuredGrid()
+ hexagrid.allocate(1,1)
+
+ vtkordered_velo = tvtk.FloatArray()
+
+ nx = self._nx
+ ny = self._ny
+ nz = self._nz
+ counter = 0
+ el_nx_redu = nx_redu + 1
+ el_ny_redu = ny_redu + 1
+ el_nz_redu = nz_redu + 1
+
+ ordered_points = [] #reset Sequences for points
+ ordered_temperature = []
+ ordered_velocity = []
+ ordered_viscosity = []
+
+ for capnr in xrange(nproc_surf):
+
+
+ cap = f.root._f_getChild("cap%02d" % capnr)
+
+ temp_coords = [] # reset Coordinates, Velocity, Temperature Sequence
+ temp_vel = []
+ temp_temp = []
+ temp_visc = []
+
+ #Information from hdf
+ hdf_coords = cap.coord[:]
+ hdf_velocity = cap.velocity[t]
+ hdf_temperature = cap.temperature[t]
+ hdf_viscosity = cap.viscosity[t]
+
+
+ #Create Iterator to change data representation
+ nx_redu_iter = self.reduce_iter(nx,nx_redu)
+ ny_redu_iter = self.reduce_iter(ny,ny_redu)
+ nz_redu_iter = self.reduce_iter(nz,nz_redu)
+
+ #vtk_i = self.vtk_iter(el_nx_redu,el_ny_redu,el_nz_redu)
+
+
+ # read citcom data - zxy (z fastest)
+ for j in xrange(el_ny_redu):
+ j_redu = ny_redu_iter.next()
+ nx_redu_iter = self.reduce_iter(nx,nx_redu)
+ for i in xrange(el_nx_redu):
+ i_redu = nx_redu_iter.next()
+ nz_redu_iter = self.reduce_iter(nz,nz_redu)
+ for k in xrange(el_nz_redu):
+ k_redu = nz_redu_iter.next()
+
+ colat, lon, r = map(float,hdf_coords[i_redu,j_redu,k_redu])
+ x_coord, y_coord, z_coord = self.RTF2XYZ(colat,lon,r)
+ ordered_points.append((x_coord,y_coord,z_coord))
+
+ ordered_temperature.append(float(hdf_temperature[i_redu,j_redu,k_redu]))
+ ordered_viscosity.append(float(hdf_viscosity[i_redu,j_redu,k_redu]))
+
+
+ vel_colat, vel_lon , vel_r = map(float,hdf_velocity[i_redu,j_redu,k_redu])
+ x_velo, y_velo, z_velo = self.velocity2cart(vel_colat,vel_lon,vel_r, colat,lon , r)
+
+ ordered_velocity.append((x_velo,y_velo,z_velo))
+
+
+ ##Delete Objects for GC
+ del hdf_coords
+ del hdf_velocity
+ del hdf_temperature
+ del hdf_viscosity
+
+
+
+ #Create Connectivity info
+ if counter==0:
+ i=1 #Counts X Direction
+ j=1 #Counts Y Direction
+ k=1 #Counts Z Direction
+
+ for n in xrange((el_nx_redu*el_ny_redu*el_nz_redu)-(el_nz_redu*el_nx_redu)):
+ if (i%el_nz_redu)==0: #X-Values!!!
+ j+=1 #Count Y-Values
+
+ if (j%el_nx_redu)==0:
+ k+=1 #Count Z-Values
+
+ if i%el_nz_redu!=0 and j%el_nx_redu!=0: #Check if Box can be created
+ #Get Vertnumbers
+ n0 = n+(capnr*(el_nx_redu*el_ny_redu*el_nz_redu))
+ n1 = n0+el_nz_redu
+ n2 = n1+el_nz_redu*el_nx_redu
+ n3 = n0+el_nz_redu*el_nx_redu
+ n4 = n0+1
+ n5 = n4+el_nz_redu
+ n6 = n5+el_nz_redu*el_nx_redu
+ n7 = n4+el_nz_redu*el_nx_redu
+ #Created Polygon Box
+ hexagrid.insert_next_cell(12,[n0,n1,n2,n3,n4,n5,n6,n7])
+
+ i+=1
+
+
+ #Store Arrays in Vtk conform Datastructures
+ self.__vtkordered_temp.from_array(ordered_temperature)
+ self.__vtkordered_visc.from_array(ordered_viscosity)
+ vtkordered_velo.from_array(ordered_velocity)
+
+ self.__vtkordered_temp.name = 'Temperature'
+ self.__vtkordered_visc.name = 'Viscosity'
+ hexagrid.point_data.scalars = self.__vtkordered_temp
+ vtkordered_velo.name = 'Velocity'
+ hexagrid.point_data.vectors = vtkordered_velo
+ hexagrid.points = ordered_points
+
+ self.progress += 1
+
+ return hexagrid
+
+
+ def initialize(self,filename,timestep,nx_redu,ny_redu,nz_redu):
+ """Call this method to convert a Citcoms Hdf file to a Vtk file"""
+
+ #Read meta-inforamtion
+ hdf=tables.openFile(filename,'r')
+ self._nx = int(hdf.root.input._v_attrs.nodex)
+ self._ny = int(hdf.root.input._v_attrs.nodey)
+ self._nz = int(hdf.root.input._v_attrs.nodez)
+
+ #Clip against boundaries
+ if nx_redu>=0 or nx_redu>=self._nx:
+ nx_redu = self._nx-1
+ if ny_redu==0 or ny_redu>=self._ny:
+ ny_redu = self._ny-1
+ if nz_redu==0 or nz_redu>=self._nz:
+ nz_redu = self._nz-1
+
+ #Make reduction factors global
+ self._nx_redu = nx_redu
+ self._ny_redu = ny_redu
+ self._nz_redu = nz_redu
+
+ #Number of Timesteps in scene
+ self.timesteps = int(hdf.root.time.nrows)
+ #Number of caps
+ nproc_surf = int(hdf.root.input._v_attrs.nproc_surf)
+ #Store the Inner Radius. Import if we want to create a core
+ self._radius_inner = self._radius_inner = float(hdf.root.input._v_attrs.radius_inner)
+ #start computation
+ hexgrid = self.__citcom2vtk(timestep,hdf,nproc_surf,nx_redu,ny_redu,nz_redu)
+
+ hdf.close()
+ self.progress = -1
+ return hexgrid
+
+ def get_vtk_viscosity(self):
+ return self.__vtkordered_visc
+
+ def get_vtk_temperature(self):
+ return self.__vtkordered_temp
Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomS_hdf_file_reader.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomS_hdf_file_reader.py 2006-12-08 17:32:25 UTC (rev 5541)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomS_hdf_file_reader.py 2006-12-08 17:40:08 UTC (rev 5542)
@@ -0,0 +1,313 @@
+"""This source manages a CitcomS Hdf file given to it.
+"""
+# Author: Martin Weier
+# Copyright (c) 2006, California Institute of Technology
+# License: GPL Style
+
+# Enthought library imports.
+from enthought.traits import Trait, TraitPrefixList, Instance, Int, Str, Button
+from enthought.traits.ui import View, Group, Item
+from enthought.traits.ui.menu import OKButton
+from enthought.persistence.state_pickler \
+ import gzip_string, gunzip_string, set_state
+from enthought.tvtk.api import tvtk
+from enthought.mayavi.plugins.CitcomSHDFUgrid import CitcomSHDFUgrid
+from CitcomHDFThread import *
+
+# Local imports.
+from enthought.mayavi.core.source import Source
+from enthought.mayavi.core.common import handle_children_state
+from enthought.mayavi.sources.vtk_xml_file_reader import get_all_attributes
+from CitcomHDFThread import *
+
+import tables
+import re
+
+
+######################################################################
+# `CitcomSVTKDataSource` class
+######################################################################
+class CitcomSHDFFileReader(Source):
+
+ """This source manages a CitcomS Hdf file given to it. """
+
+ # The version of this class. Used for persistence.
+ __version__ = 0
+
+ # The VTK dataset to manage.
+ data = Instance(tvtk.DataSet)
+ # Class to convert Hdf to Vtk Unstructured Grid Objects
+ citcomshdftougrid = CitcomSHDFUgrid()
+ current_timestep = Int(0)
+ #To support changing the Scalar values in Mayavi2
+ temperature = Instance(tvtk.FloatArray())
+ viscosity = Instance(tvtk.FloatArray())
+
+ #Resolution comming from Hdf file
+ nx = Int()
+ ny = Int()
+ nz = Int()
+
+ #Current reduced resolution. User defined
+ nx_redu = Int()
+ ny_redu = Int()
+ nz_redu = Int()
+
+ #Number of timesteps in Hdf
+ timesteps = Int()
+
+ #Button to trigger the process of reading a timestep
+ read_timestep = Button('Read timestep')
+ filename = Str()
+
+ ########################################
+ # Dynamic traits: These traits are dummies and are dynamically
+ # updated depending on the contents of the file.
+
+ # The active point scalar name.
+ point_scalars_name = Trait('', TraitPrefixList(['']))
+ # The active point vector name.
+ point_vectors_name = Trait('', TraitPrefixList(['']))
+ # The active point tensor name.
+ point_tensors_name = Trait('', TraitPrefixList(['']))
+
+ # The active cell scalar name.
+ cell_scalars_name = Trait('', TraitPrefixList(['']))
+ # The active cell vector name.
+ cell_vectors_name = Trait('', TraitPrefixList(['']))
+ # The active cell tensor name.
+ cell_tensors_name = Trait('', TraitPrefixList(['']))
+ ########################################
+
+ # Our view.
+ view = View(Group(Item(name='current_timestep'),
+ Item(name='nx_redu'),
+ Item(name='ny_redu'),
+ Item(name='nz_redu'),
+ Item(name='read_timestep', style='simple', label='Simple'),
+ Item(name='point_scalars_name'),
+ Item(name='point_vectors_name'),
+ Item(name='point_tensors_name'),
+ Item(name='cell_scalars_name'),
+ Item(name='cell_vectors_name'),
+ Item(name='cell_tensors_name'),
+
+ ),
+
+ )
+
+ ######################################################################
+ # `object` interface
+ ######################################################################
+ #Invoked during process of saving the visualization to a file
+ def __get_pure_state__(self):
+ d = super(CitcomSHDFFileReader, self).__get_pure_state__()
+ output = "Filename: " +self.filename+ "NX:%d NY:%d NZ:%d" %(self.nx_redu,self.ny_redu,self.nz_redu)
+ z = gzip_string(output)
+ d['data'] = z
+ return d
+
+ #When the Visualisation is opened again this Method is called
+ def __set_pure_state__(self, state):
+ z = state.data
+ if z:
+ d = gunzip_string(z)
+ m = re.search('(?<=Filename:)\w+', header)
+ file_name = m.group(0)
+ m = re.search('(?<=NX:)\w+', d)
+ self.nx_redu = int(m.group(0))
+ m = re.search('(?<=NX:)\w+', d)
+ self.ny_redu = int(m.group(0))
+ m = re.search('(?<=NX:)\w+', d)
+ self.nz_redu = int(m.group(0))
+
+ if not isfile(file_name):
+ msg = 'Could not find file at %s\n'%file_name
+ msg += 'Please move the file there and try again.'
+ raise IOError, msg
+
+ self.filename = file_name
+
+ #self.data = self.citcomshdftougrid.initialize(self.filename,0,0,0,0,False,False)
+ f = tables.openFile(file_name,'r')
+ self.nx = int(f.root.input._v_attrs.nodex)
+ self.ny = int(f.root.input._v_attrs.nodey)
+ self.nz = int(f.root.input._v_attrs.nodez)
+
+ self.timesteps = int(f.root.time.nrows)
+ f.close()
+ self.data = self.citcomshdftougrid.initialize(self.filename,self.current_timestep,self.nx_redu,self.ny_redu,self.nz_redu)
+ self.data_changed = True
+ self._update_data()
+ # Now set the remaining state without touching the children.
+ set_state(self, state, ignore=['children', '_file_path'])
+ # Setup the children.
+ handle_children_state(self.children, state.children)
+ # Setup the children's state.
+ set_state(self, state, first=['children'], ignore=['*'])
+
+ ######################################################################
+ # `Base` interface
+ ######################################################################
+ def start(self):
+ """This is invoked when this object is added to the mayavi
+ pipeline.
+ """
+ # Do nothing if we are already running.
+ if self.running:
+ return
+
+ # Update the data just in case.
+ self._update_data()
+
+ # Call the parent method to do its thing. This will typically
+ # start all our children.
+ super(CitcomSHDFFileReader, self).start()
+
+ def update(self):
+ """Invoke this to flush data changes downstream."""
+ self.data_changed = True
+
+
+ def initialize(self,file_name):
+ """This Methods initializes the reader and reads the meta-information from the Hdf file """
+ self.filename = file_name
+
+ #self.data = self.citcomshdftougrid.initialize(self.filename,0,0,0,0,False,False)
+ f = tables.openFile(file_name,'r')
+ self.nx = int(f.root.input._v_attrs.nodex)
+ self.ny = int(f.root.input._v_attrs.nodey)
+ self.nz = int(f.root.input._v_attrs.nodez)
+
+ self.nx_redu = self.nx
+ self.ny_redu = self.ny
+ self.nz_redu = self.nz
+
+ self.timesteps = int(f.root.time.nrows)
+ f.close()
+
+
+ ######################################################################
+ # `TreeNodeObject` interface
+ ######################################################################
+ def tno_get_label(self, node):
+ """ Gets the label to display for a specified object.
+ """
+ ret = "CitcomS HDF Data (uninitialized)"
+ if self.data:
+ typ = self.data.__class__.__name__
+ ret = "CitcomS HDF Data (%d)"%self.current_timestep
+ return ret
+
+ ######################################################################
+ # Non-public interface
+ ######################################################################
+ def _data_changed(self, data):
+ """Invoked when the upsteam data sends an data_changed event"""
+ self._update_data()
+ self.outputs = [data]
+ self.data_changed = True
+ # Fire an event so that our label on the tree is updated.
+ self.trait_property_changed('name', '',
+ self.tno_get_label(None))
+
+ ##Callbacks for our traits
+ def _current_timestep_changed(self,new_value):
+ """Callback for the current timestep input box"""
+ if new_value < 0:
+ self.current_timestep = 0
+ if new_value > self.timesteps:
+ self.current_timestep = self.timesteps-1
+
+ def _read_timestep_fired(self):
+ """Callback for the Button to read one timestep"""
+
+
+ self.data = self.citcomshdftougrid.initialize(self.filename,self.current_timestep,self.nx_redu,self.ny_redu,self.nz_redu)
+ self.temperature = self.citcomshdftougrid.get_vtk_temperature()
+ self.viscosity = self.citcomshdftougrid.get_vtk_viscosity()
+
+ ##New Thread Code
+ #thread1 = CitcomSHdf2UGridThread()
+ #thread2 = CitcomSProgressBar()
+
+ #thread1.set_citcomsreader(self.filename,self.current_timestep,self.nx_redu,self.ny_redu,self.nz_redu,self.thread_callback)
+ #progress = thread1.get_ref()
+ #thread1.start()
+ #thread2.set_ref(progress)
+ #thread2.start()
+
+ self.data_changed = True
+ self._update_data()
+
+ def _nx_redu_changed(self, new_value):
+ """callback for the nx_redu input box"""
+ if new_value < 1:
+ self.nx_redu = 1
+ if new_value > self.nx:
+ self.nx_redu = self.nx
+
+ def _ny_redu_changed(self, new_value):
+ """callback for the ny_redu input box"""
+ if new_value < 1:
+ self.ny_redu = 1
+ if new_value > self.ny:
+ self.ny_redu = self.ny
+
+
+ def _nz_redu_changed(self, new_value):
+ """callback for the nz_redu input box"""
+ if new_value < 1:
+ self.nz_redu = 1
+ if new_value > self.nz:
+ self.nz_redu = self.nz
+
+ def _point_scalars_name_changed(self, value):
+ if value == "Temperature":
+ self.data.point_data.scalars = self.temperature
+ if value == "Viscosity":
+ self.data.point_data.scalars = self.viscosity
+ self.data_changed = True
+ self._set_data_name('scalars', 'point', value)
+
+ def _point_vectors_name_changed(self, value):
+ self._set_data_name('vectors', 'point', value)
+
+ def _point_tensors_name_changed(self, value):
+ self._set_data_name('tensors', 'point', value)
+
+
+ ########################Non Public##############################
+ def _set_data_name(self, data_type, attr_type, value):
+ if not value:
+ return
+ dataset = self.data
+ data = None
+ if attr_type == 'point':
+ data = dataset.point_data
+ elif attr_type == 'cell':
+ data = dataset.cell_data
+ meth = getattr(data, 'set_active_%s'%data_type)
+ meth(value)
+ self.update()
+ # Fire an event, so the changes propagate.
+ self.data_changed = True
+
+
+ def _update_data(self):
+ if not self.data:
+ return
+ else:
+ trait = Trait('Temperature', TraitPrefixList('Temperature','Viscosity'))
+ self.add_trait('point_scalars_name', trait)
+ trait = Trait('Velocity', TraitPrefixList('Velocity'))
+ self.add_trait('point_vectors_name', trait)
+
+ def thread_callback(self,hexagrid,vtk_viscosity,vtk_temperature):
+ hexagrid.print_traits()
+ self.data = hexagrid
+ self.temperature = vtk_temperature
+ self.viscosity = vtk_temperature
+
+
+
Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/OpenCitcomSFILES.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/OpenCitcomSFILES.py 2006-12-08 17:32:25 UTC (rev 5541)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/OpenCitcomSFILES.py 2006-12-08 17:40:08 UTC (rev 5542)
@@ -0,0 +1,66 @@
+# Standard library imports.
+from os.path import isfile
+
+# Enthought library imports.
+from enthought.pyface import FileDialog, OK
+
+# Local imports
+from enthought.mayavi.script import get_imayavi
+from enthought.mayavi.core.common import error
+from enthought.mayavi.action.common import WorkbenchAction, get_imayavi
+
+######################################################################
+# `OpenCitcomSVtkFile` class.
+######################################################################
+class OpenCitcomSVTKFILE(WorkbenchAction):
+ """ An action that opens a new VTK file. """
+
+ ###########################################################################
+ # 'Action' interface.
+ ###########################################################################
+
+ def perform(self):
+ """ Performs the action. """
+ wildcard = 'VTK files (*.vtk)|*.vtk|' + FileDialog.WILDCARD_ALL
+ parent = self.window.control
+ dialog = FileDialog(parent=parent,
+ title='Open CitcomS VTK file',
+ action='open', wildcard=wildcard
+ )
+ if dialog.open() == OK:
+ if not isfile(dialog.path):
+ error("File '%s' does not exist!"%dialog.path, parent)
+ return
+ from enthought.mayavi.plugins.CitcomS_vtk_file_reader import CitcomSVTKFileReader
+ r = CitcomSVTKFileReader()
+ r.initialize(dialog.path)
+ mv = get_imayavi(self.window)
+ mv.add_source(r)
+
+######################################################################
+# `OpenCitcomSVtkFile` class.
+######################################################################
+class OpenCitcomSHDFFILE(WorkbenchAction):
+ """ An action that opens a new VTK file. """
+
+ ###########################################################################
+ # 'Action' interface.
+ ###########################################################################
+
+ def perform(self):
+ """ Performs the action. """
+ wildcard = 'HDF files (*.h5)|*.h5|' + FileDialog.WILDCARD_ALL
+ parent = self.window.control
+ dialog = FileDialog(parent=parent,
+ title='Open CitcomS H5 file',
+ action='open', wildcard=wildcard
+ )
+ if dialog.open() == OK:
+ if not isfile(dialog.path):
+ error("File '%s' does not exist!"%dialog.path, parent)
+ return
+ from enthought.mayavi.plugins.CitcomS_hdf_file_reader import CitcomSHDFFileReader
+ r = CitcomSHDFFileReader()
+ r.initialize(dialog.path)
+ mv = get_imayavi(self.window)
+ mv.add_source(r)
Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/__init__.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/__init__.py 2006-12-08 17:32:25 UTC (rev 5541)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/__init__.py 2006-12-08 17:40:08 UTC (rev 5542)
@@ -0,0 +1 @@
+# Author: Martin Weier
Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSFilterActions.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSFilterActions.py 2006-12-08 17:32:25 UTC (rev 5541)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSFilterActions.py 2006-12-08 17:40:08 UTC (rev 5542)
@@ -0,0 +1,48 @@
+"""Actions to start the CitcomS filter.
+
+"""
+#Author: Martin Weier
+#Copyright (C) 2006 California Institute of Technology
+#This program 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 2 of the License, or
+#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, write to the Free Software
+#Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+# Enthought library imports.
+# Local imports.
+from enthought.mayavi.action.common import WorkbenchAction, get_imayavi
+
+class CitcomSreduce(WorkbenchAction):
+ """ An action that starts a delaunay 2d filter. """
+
+ ###########################################################################
+ # 'Action' interface.
+ ###########################################################################
+
+ def perform(self):
+ """ Performs the action. """
+ from CitcomSreduce import CitcomSreduce
+ f = CitcomSreduce()
+ mv = get_imayavi(self.window)
+ mv.add_filter(f)
+
+class CitcomSshowCaps(WorkbenchAction):
+ """ An action that starts a delaunay 2d filter. """
+
+ ###########################################################################
+ # 'Action' interface.
+ ###########################################################################
+
+ def perform(self):
+ """ Performs the action. """
+ from CitcomSshowCaps import CitcomSshowCaps
+ f = CitcomSshowCaps()
+ mv = get_imayavi(self.window)
+ mv.add_filter(f)
Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSSphere.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSSphere.py 2006-12-08 17:32:25 UTC (rev 5541)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSSphere.py 2006-12-08 17:40:08 UTC (rev 5542)
@@ -0,0 +1,159 @@
+"""Creates points os a specified cap with a specified resolution.
+"""
+
+# Author: Martin Weier
+#Copyright (C) 2006 California Institute of Technology
+#This program 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 2 of the License, or
+#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, write to the Free Software
+#Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+from math import sqrt,acos,pi,atan, atan2, sin, cos
+
+
+class CitcomSSphere:
+ #Cointains corner points for each cap.
+ lookup_table = [( (0.013497673906385899, 0.0, 0.54983437061309814) ,
+ (0.0077419690787792206, 0.4505336582660675, 0.31537202000617981) ,
+ (0.45813989639282227, 0.0, 0.30431538820266724) ,
+ (0.38879159092903137, 0.3889087438583374, -0.0095440549775958061) ),
+
+ ( (0.0077419690787792206, 0.4505336582660675, 0.31537202000617981) ,
+ (-0.38879168033599854, 0.38890865445137024, 0.0095444004982709885) ,
+ (0.38879159092903137, 0.3889087438583374, -0.0095440549775958061) ,
+ (-0.007742113433778286, 0.45053350925445557, -0.31537219882011414) ),
+
+ ( (-0.38879168033599854, 0.38890865445137024, 0.0095444004982709885) ,
+ (-0.45813983678817749, -1.4928090763532964e-07, -0.3043154776096344) ,
+ (-0.007742113433778286, 0.45053350925445557, -0.31537219882011414) ,
+ (-0.013497666455805302, -4.3980978858826347e-09, -0.54983437061309814) ),
+
+ ( (0.013497673906385899, 0.0, 0.54983437061309814) ,
+ (-0.44265598058700562, -1.4423562788579147e-07, 0.32642868161201477) ,
+ (0.0077419690787792206, 0.4505336582660675, 0.31537202000617981) ,
+ (-0.38879168033599854, 0.38890865445137024, 0.0095444004982709885) ),
+
+ ( (-0.44265598058700562, -1.4423562788579147e-07, 0.32642868161201477) ,
+ (-0.38879179954528809, -0.38890856504440308, 0.0095444004982709885) ,
+ (-0.38879168033599854, 0.38890865445137024, 0.0095444004982709885) ,
+ (-0.45813983678817749, -1.4928090763532964e-07, -0.3043154776096344) ),
+
+ ( (-0.38879179954528809, -0.38890856504440308, 0.0095444004982709885) ,
+ (-0.0077417660504579544, -0.45053350925445557, -0.31537219882011414) ,
+ (-0.45813983678817749, -1.4928090763532964e-07, -0.3043154776096344) ,
+ (-0.013497666455805302, -4.3980978858826347e-09, -0.54983437061309814) ),
+
+ ( (0.013497673906385899, 0.0, 0.54983437061309814) ,
+ (0.0077417795546352863, -0.4505336582660675, 0.31537202000617981) ,
+ (-0.44265598058700562, -1.4423562788579147e-07, 0.32642868161201477) ,
+ (-0.38879179954528809, -0.38890856504440308, 0.0095444004982709885) ),
+
+ ( (0.0077417795546352863, -0.4505336582660675, 0.31537202000617981) ,
+ (0.38879171013832092, -0.38890862464904785, -0.0095440549775958061) ,
+ (-0.38879179954528809, -0.38890856504440308, 0.0095444004982709885) ,
+ (-0.0077417660504579544, -0.45053350925445557, -0.31537219882011414) ),
+
+ ( (0.38879171013832092, -0.38890862464904785, -0.0095440549775958061) ,
+ (0.44265609979629517, -1.3367842655043205e-07, -0.32642853260040283) ,
+ (-0.0077417660504579544, -0.45053350925445557, -0.31537219882011414) ,
+ (-0.013497666455805302, -4.3980978858826347e-09, -0.54983437061309814) ),
+
+ ( (0.013497673906385899, 0.0, 0.54983437061309814) ,
+ (0.45813989639282227, -1.3835439460763155e-07, 0.30431538820266724) ,
+ (0.0077417795546352863, -0.4505336582660675, 0.31537202000617981) ,
+ (0.38879171013832092, -0.38890862464904785, -0.0095440549775958061) ),
+
+ ( (0.45813989639282227, -1.3835439460763155e-07, 0.30431538820266724) ,
+ (0.38879159092903137, 0.3889087438583374, -0.0095440549775958061) ,
+ (0.38879171013832092, -0.38890862464904785, -0.0095440549775958061) ,
+ (0.44265609979629517, -1.3367842655043205e-07, -0.32642853260040283) ),
+
+ ( (0.38879159092903137, 0.3889087438583374, -0.0095440549775958061) ,
+ (-0.007742113433778286, 0.45053350925445557, -0.31537219882011414) ,
+ (0.44265609979629517, 0.0, -0.32642853260040283) ,
+ (-0.013497666455805302, -4.3980978858826347e-09, -0.54983437061309814) )]
+
+
+ def cart2spherical(self,x,y,z):
+ xypow = x**x+y**y
+ r = sqrt(xypow+z**z)
+ if y >= 0:
+ phi = acos(x/sqrt(x/xypow))
+ else:
+ phi = 2*pi-acos(x/sqrt(xypow))
+ theta = pi/2-atan(z/sqrt(xypow))
+ return r,phi,theta
+
+
+ def coords_of_cap(self,radius,resolution_x,resolution_y,cap):
+ coords = []
+ #radius = sqrt(c1x**2+c1y**2+c1z**2)
+
+
+ c1x = self.lookup_table[cap][0][0]
+ c1y = self.lookup_table[cap][0][1]
+ c1z = self.lookup_table[cap][0][2]
+
+ c2x = self.lookup_table[cap][1][0]
+ c2y = self.lookup_table[cap][1][1]
+ c2z = self.lookup_table[cap][1][2]
+
+ c3x = self.lookup_table[cap][2][0]
+ c3y = self.lookup_table[cap][2][1]
+ c3z = self.lookup_table[cap][2][2]
+
+ c4x = self.lookup_table[cap][3][0]
+ c4y = self.lookup_table[cap][3][1]
+ c4z = self.lookup_table[cap][3][2]
+
+ coords1,theta,phi = self.evenly_divide_arc(resolution_x, c1x, c1y, c1z, c2x, c2y, c2z)
+ coords2,theta,phi = self.evenly_divide_arc(resolution_x, c3x, c3y, c3z, c4x, c4y, c4z)
+
+
+
+ for i in xrange(len(coords1)):
+ temp,theta,phi = self.evenly_divide_arc(resolution_y, coords1[i][0],coords1[i][1],coords1[i][2], coords2[i][0],coords2[i][1],coords2[i][2])
+
+ for j in xrange(len(theta)):
+ x,y,z = self.RTF2XYZ(theta[j],phi[j],radius)
+ coords.append((x,y,z))
+ return coords
+
+ def evenly_divide_arc(self,elx,x1,y1,z1,x2,y2,z2):
+ nox=elx+1
+ dx = (x2-x1)/elx
+ dy = (y2-y1)/elx
+ dz = (z2-z1)/elx
+ theta = []
+ phi = []
+ coords = []
+ for j in xrange(1,nox+1):
+ x_temp = x1 + dx * (j-1) + 5.0e-32
+ y_temp = y1 + dy * (j-1)
+ z_temp = z1 + dz * (j-1)
+ coords.append((x_temp,y_temp,z_temp))
+ theta.append(acos(z_temp/sqrt(x_temp**2+y_temp**2+z_temp**2)))
+ phi.append(self.myatan(y_temp,x_temp))
+ return coords,theta,phi
+
+ def RTF2XYZ(self,thet, phi, r):
+ x = r * sin(thet) * cos(phi)
+ y = r * sin(thet) * sin(phi)
+ z = r * cos(thet)
+ return x, y, z
+
+ def myatan(self,y,x):
+ fi = atan2(y,x)
+ if fi<0.0:
+ fi += 2*pi
+ return fi
+
+
+
\ No newline at end of file
Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSreduce.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSreduce.py 2006-12-08 17:32:25 UTC (rev 5541)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSreduce.py 2006-12-08 17:40:08 UTC (rev 5542)
@@ -0,0 +1,224 @@
+"""A filter that reduces CitcomS vtk input data.
+"""
+
+#Author: Martin Weier
+#Copyright (C) 2006 California Institute of Technology
+#This program 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 2 of the License, or
+#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, write to the Free Software
+#Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+# Enthought library imports.
+from enthought.traits import Instance, Range, Int, Float, Enum, Trait, Button
+from enthought.traits.ui import View, Group, Item
+from enthought.tvtk.api import tvtk
+
+# Local imports
+from enthought.mayavi.core.filter import Filter
+
+from CitcomSSphere import *
+
+######################################################################
+# `Threshold` class.
+######################################################################
+class CitcomSreduce(Filter):
+
+ # The version of this class. Used for persistence.
+ __version__ = 0
+
+ # The threshold filter.
+
+ probe_filter = Instance(tvtk.ProbeFilter, ())
+
+ citcomsgrid = CitcomSSphere()
+ sphere = Instance(tvtk.SphereSource,())
+
+ # Upper threshold (this is a dynamic trait that is changed when
+ # input data changes).
+ Radius = Range(0.0, 1.0, 0.0, desc='adjust radius')
+
+ theta = Range(3, 40, 3, desc='the theta resolution')
+ phi = Range(3, 40, 3, desc='the upper threshold of the filter')
+
+ Selected_Source = Enum( 'Sphere','CitcomSGrid',)
+
+ radius_max = Float(1.0)
+ set_radius_max = Button('Set Radius Max')
+ # Our view.
+ view = View(Item(name="Selected_Source"),
+ Group(Item(name='Radius'),
+ Item(name='theta'),
+ Item(name='phi'),
+ Item(name='radius_max'),
+ Item(name='set_radius_max', style='simple', label='Simple'),
+ show_border = True
+ ),
+ )
+
+ grid_source = True
+
+ ######################################################################
+ # `Filter` interface.
+ ######################################################################
+
+ def setup_pipeline(self):
+ """Override this method so that it *creates* its tvtk
+ pipeline.
+
+ This method is invoked when the object is initialized via
+ `__init__`. Note that at the time this method is called, the
+ tvtk data pipeline will *not* yet be setup. So upstream data
+ will not be available. The idea is that you simply create the
+ basic objects and setup those parts of the pipeline not
+ dependent on upstream sources and filters.
+ """
+ # Just setup the default output of this filter.
+ s = self.sphere
+ s.set(radius=0.0,theta_resolution=20,phi_resolution=20)
+ self.probe_filter.input = s.output
+ self.outputs = [self.probe_filter.output]
+
+ def update_pipeline(self):
+ """Override this method so that it *updates* the tvtk pipeline
+ when data upstream is known to have changed.
+
+ This method is invoked (automatically) when the input fires a
+ `pipeline_changed` event.
+ """
+ # By default we set the input to the first output of the first
+ # input.
+ fil = self.probe_filter
+
+ fil.source = self.inputs[0].outputs[0]
+
+
+ self._calc_grid(0,self.theta,self.phi)
+ fil.update()
+
+ self.outputs[0] = fil.output
+ self.pipeline_changed = True
+
+ def update_data(self):
+ """Override this method to do what is necessary when upstream
+ data changes.
+
+ This method is invoked (automatically) when any of the inputs
+ sends a `data_changed` event.
+ """
+
+ self.probe_filter.source = self.inputs[0].outputs[0]
+ self.probe_filter.update()
+ # Propagate the data_changed event.
+ self.data_changed = True
+
+
+ def _calc_grid(self,radius,resolution_x,resolution_y):
+
+ fil = self.probe_filter
+
+ coords = []
+
+ if self.Selected_Source == 'CitcomSGrid':
+
+ for i in xrange(12):
+
+ coords += self.citcomsgrid.coords_of_cap(radius,self.theta,self.phi,i)
+
+ grid = tvtk.UnstructuredGrid()
+
+ #Connectivity for 2d-Data
+ #There is no need to interpolate with the CitcomS grid surface. If this is however
+ #wanted uncomment this code to create the CitcomS surface information
+ #for capnr in xrange(12):
+ # i=1
+ # for n in xrange((resolution_x+1)*(resolution_y+1) - (resolution_x+1)):
+ # if i%(resolution_x+1)!=0 :
+ # n0 = n+(capnr*((resolution_x+1)*(resolution_y+1)))
+ # n1 = n0+1
+ # n2 = n0+resolution_y+1
+ # n3 = n2+1
+ # grid.insert_next_cell(8,[n0,n1,n2,n3])
+ # i+=1
+
+ ##
+
+ grid.points = coords
+ fil.input = grid
+
+ if self.Selected_Source == 'Sphere':
+ sphere = tvtk.SphereSource()
+ sphere.radius = radius
+ sphere.theta_resolution = resolution_x
+ sphere.phi_resolution = resolution_y
+
+ #Rotate the Sphere so that the poles are at the right location
+ transL = tvtk.Transform()
+ trans1 = tvtk.TransformPolyDataFilter()
+ trans2 = tvtk.TransformPolyDataFilter()
+ trans1.input = sphere.output
+ transL.rotate_y(90)
+ transL.update()
+ trans1.transform = transL
+ trans1.update()
+ trans2.input = trans1.output
+ transL.rotate_z(90)
+ transL.update()
+ trans2.transform = transL
+ trans2.update()
+
+ fil.input = trans2.output
+
+
+
+ fil.update()
+
+
+ ######################################################################
+ # Non-public interface
+ ######################################################################
+ def _Radius_changed(self, new_value):
+ fil = self.probe_filter
+ #self.sphere.radius = new_value
+ self._calc_grid(new_value,self.theta,self.phi)
+ fil.update()
+ self.data_changed = True
+
+
+ def _theta_changed(self, new_value):
+ fil = self.probe_filter
+ self._calc_grid(self.Radius,new_value,self.phi)
+ fil.update()
+ self.data_changed = True
+
+
+ def _phi_changed(self, new_value):
+ fil = self.probe_filter
+ self._calc_grid(self.Radius,self.theta,new_value)
+ fil.update()
+ self.data_changed = True
+
+ def _Selected_Source_changed(self,new_value):
+ self._calc_grid(self.Radius, self.theta, self.phi)
+ self.outputs[0] = self.probe_filter.output
+ self.data_changed = True
+ self.pipeline_changed = True
+
+ def _radius_max_changed(self,new_value):
+ if self.Radius > new_value:
+ self.Radius = new_value
+ if new_value <= 0.0:
+ self.radius_max = 0.0
+
+ def _set_radius_max_fired(self):
+ trait = Range(0.0, self.radius_max, self.Radius,
+ desc='adjust radius')
+ self.add_trait('Radius', trait)
+
Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSshowCaps.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSshowCaps.py 2006-12-08 17:32:25 UTC (rev 5541)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSshowCaps.py 2006-12-08 17:40:08 UTC (rev 5542)
@@ -0,0 +1,130 @@
+"""A simple filter that thresholds CitcomS Caps from input data."""
+
+# Author: Martin Weier
+#
+#Copyright (C) 2006 California Institute of Technology
+#This program 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 2 of the License, or
+#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, write to the Free Software
+#Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+# Enthought library imports.
+from enthought.traits import Instance, Range, Int
+from enthought.traits.ui import View, Group, Item
+from enthought.tvtk.api import tvtk
+
+# Local imports
+from enthought.mayavi.core.filter import Filter
+
+
+######################################################################
+# `Threshold` class.
+######################################################################
+class CitcomSshowCaps(Filter):
+
+ # The version of this class. Used for persistence.
+ __version__ = 0
+
+ # The threshold filter.
+ ugrid_filter = Instance(tvtk.ExtractUnstructuredGrid, ())
+
+ # Lower threshold (this is a dynamic trait that is changed when
+ # input data changes).
+ lower_threshold = Range(0, 12, 0,
+ desc='the lower threshold of the filter')
+
+ # Upper threshold (this is a dynamic trait that is changed when
+ # input data changes).
+ upper_threshold = Range(0, 12, 12,
+ desc='the upper threshold of the filter')
+
+ # Our view.
+ view = View(Group(Item(name='lower_threshold'),
+ Item(name='upper_threshold'))
+ )
+
+
+ n = Int()
+ caps = Int()
+
+
+
+ ######################################################################
+ # `Filter` interface.
+ ######################################################################
+ def setup_pipeline(self):
+ """Override this method so that it *creates* its tvtk
+ pipeline.
+
+ This method is invoked when the object is initialized via
+ `__init__`. Note that at the time this method is called, the
+ tvtk data pipeline will *not* yet be setup. So upstream data
+ will not be available. The idea is that you simply create the
+ basic objects and setup those parts of the pipeline not
+ dependent on upstream sources and filters.
+ """
+ # Just setup the default output of this filter.
+ self.ugrid_filter.point_clipping = 1
+ self.ugrid_filter.merging = 0
+ self.outputs = [self.ugrid_filter.output]
+
+ def update_pipeline(self):
+ """Override this method so that it *updates* the tvtk pipeline
+ when data upstream is known to have changed.
+
+ This method is invoked (automatically) when the input fires a
+ `pipeline_changed` event.
+ """
+ # By default we set the input to the first output of the first
+ # input.
+ fil = self.ugrid_filter
+ fil.input = self.inputs[0].outputs[0]
+
+ #Than we calculate how many points belong to one cap
+ self.caps = 12
+ self.n = self.inputs[0].outputs[0].number_of_points/12
+
+ #Than we set the output of the filter
+ self.outputs[0] = fil.output
+ self.outputs.append(self.inputs[0].outputs[0])
+ self.pipeline_changed = True
+
+ def update_data(self):
+ """Override this method to do what is necessary when upstream
+ data changes.
+
+ This method is invoked (automatically) when any of the inputs
+ sends a `data_changed` event.
+ """
+ fil = self.ugrid_filter
+ fil.update()
+ # Propagate the data_changed event.
+ self.data_changed = True
+
+ ######################################################################
+ # Non-public interface
+ ######################################################################
+ def _lower_threshold_changed(self,old_value, new_value):
+ """Callback interface for the lower threshold slider"""
+ fil = self.ugrid_filter
+ fil.point_minimum = (self.lower_threshold)*(self.n)
+ fil.update()
+ self.data_changed = True
+
+
+ def _upper_threshold_changed(self, old_value, new_value):
+ """Callback interface for the upper threshold slider"""
+ fil = self.ugrid_filter
+ fil.point_maximum = self.upper_threshold*(self.n)
+ fil.update()
+ self.data_changed = True
+
+
Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSshowSurface.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSshowSurface.py 2006-12-08 17:32:25 UTC (rev 5541)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/CitcomSshowSurface.py 2006-12-08 17:40:08 UTC (rev 5542)
@@ -0,0 +1,191 @@
+"""A that shows a slice at a specified radius
+
+"""
+# Author: Martin Weier
+#Copyright (C) 2006 California Institute of Technology
+#This program 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 2 of the License, or
+#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, write to the Free Software
+#Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+# Enthought library imports.
+from enthought.traits import Instance, Range, Int, Float
+from enthought.traits.ui import View, Group, Item
+from enthought.tvtk import tvtk
+
+# Local imports
+from enthought.mayavi.core.filter import Filter
+
+
+######################################################################
+# `ShowSurface` class.
+######################################################################
+class ShowSurface(Filter):
+
+ # The version of this class. Used for persistence.
+ __version__ = 0
+
+ # The threshold filter.
+
+ prog_filter = Instance(tvtk.ProgrammableFilter, ())
+
+
+ # Upper threshold (this is a dynamic trait that is changed when
+ # input data changes).
+ surfacelevel = Range(1, 17, 1,
+ desc='the surface filter')
+
+ # Our view.
+ view = View(Group(Item(name='surfacelevel')
+ ))
+
+ current_level=Int()
+ nx = Int()
+ ny = Int()
+ nz = Int()
+
+
+
+
+ def setvalues(self,nx,ny,nz,level):
+ """This Method needs to be set before the execution of the filter
+ it accepts nx,ny,nz,level"""
+ self.nx = nx
+ self.ny = ny
+ self.nz = nz
+ self.current_level = level
+ ######################################################################
+ # `Filter` interface.
+ ######################################################################
+ def setup_pipeline(self):
+ """Override this method so that it *creates* its tvtk
+ pipeline.
+
+ This method is invoked when the object is initialized via
+ `__init__`. Note that at the time this method is called, the
+ tvtk data pipeline will *not* yet be setup. So upstream data
+ will not be available. The idea is that you simply create the
+ basic objects and setup those parts of the pipeline not
+ dependent on upstream sources and filters.
+ """
+ # Just setup the default output of this filter.
+ self.prog_filter.set_execute_method(self._showsurface)
+ self.outputs = [self.prog_filter.output]
+
+ def update_pipeline(self):
+ """Override this method so that it *updates* the tvtk pipeline
+ when data upstream is known to have changed.
+
+ This method is invoked (automatically) when the input fires a
+ `pipeline_changed` event.
+ """
+ # By default we set the input to the first output of the first
+ # input.
+ fil = self.prog_filter
+ fil.input = self.inputs[0].outputs[0]
+
+ # We force the ranges to be reset to the limits of the data.
+ # This is because if the data has changed upstream, then the
+ # limits of the data must be changed.
+ #self._update_ranges(reset=True)
+
+ #fil.threshold_between(self.lower_threshold, self.upper_threshold)
+ #fil.update()
+ self.outputs[0] = fil.output
+ self.pipeline_changed = True
+
+ def update_data(self):
+ """Override this method to do what is necessary when upstream
+ data changes.
+
+ This method is invoked (automatically) when any of the inputs
+ sends a `data_changed` event.
+ """
+
+ #self._update_ranges(reset=True)
+
+
+ # Propagate the data_changed event.
+ self.prog_filter.set_execute_method(self._showsurface)
+ self.outputs = [self.prog_filter.output]
+ self.data_changed = True
+
+
+ def _showsurface(self):
+ print "showsurface update"
+ print self.current_level
+ input = self.prog_filter.unstructured_grid_input
+ numCells = input.number_of_cells
+ quadgrid = tvtk.UnstructuredGrid()
+ quadgrid.allocate(1,1)
+
+ reduced_points = []
+ reduced_scalars = []
+ reduced_vectors = []
+ j = 1
+ cell_count=0
+ for i in xrange(numCells):
+ if j==self.current_level:
+ cell = input.get_cell(i)
+ scalars = input.point_data.scalars
+ vectors = input.point_data.vectors
+ point_ids = cell.point_ids
+ points = cell.points
+ reduced_points.append(points[2])
+ reduced_points.append(points[1])
+ reduced_points.append(points[5])
+ reduced_points.append(points[6])
+
+ reduced_scalars.append(scalars[point_ids[2]])
+ reduced_scalars.append(scalars[point_ids[1]])
+ reduced_scalars.append(scalars[point_ids[5]])
+ reduced_scalars.append(scalars[point_ids[6]])
+
+
+ reduced_vectors.append(vectors[point_ids[2]])
+ reduced_vectors.append(vectors[point_ids[1]])
+ reduced_vectors.append(vectors[point_ids[5]])
+ reduced_vectors.append(vectors[point_ids[6]])
+
+ quadgrid.insert_next_cell(9,[cell_count,cell_count+1,cell_count+2,cell_count+3])
+ cell_count+=4
+
+ if j == self.nx:
+ j=1
+
+ j+=1
+
+ vtkReduced_vectors = tvtk.FloatArray()
+ vtkReduced_scalars = tvtk.FloatArray()
+ vtkReduced_vectors.from_array(reduced_vectors)
+ vtkReduced_scalars.from_array(reduced_scalars)
+
+ vtkReduced_scalars.name = 'Scalars'
+ vtkReduced_vectors.name = 'Vectors'
+
+ #showsurfF.unstructured_grid_output = quadgrid
+ self.prog_filter.unstructured_grid_output.set_cells(9,quadgrid.get_cells())
+ self.prog_filter.unstructured_grid_output.point_data.scalars = vtkReduced_scalars
+ self.prog_filter.unstructured_grid_output.point_data.vectors = vtkReduced_vectors
+ self.prog_filter.unstructured_grid_output.points = reduced_points
+
+
+ ######################################################################
+ # Non-public interface
+ ######################################################################
+ def _surfacelevel_changed(self, new_value):
+ fil = self.prog_filter
+ print self.current_level
+ self.current_level = new_value-1
+ self._showsurface()
+ fil.update()
+ self.data_changed = True
+
+
Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/__init__.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/__init__.py 2006-12-08 17:32:25 UTC (rev 5541)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/filter/__init__.py 2006-12-08 17:40:08 UTC (rev 5542)
@@ -0,0 +1 @@
+# Author: Martin Weier
More information about the cig-commits
mailing list