[vtkusers] do2ds StructuredGrid problem

Simon Allfrey simon.allfrey at epfl.ch
Mon Jan 20 11:36:06 EST 2003


I'm trying to use vtkDataObjectToDataSetFilter to generate a structured 
grid of some external data mapped onto a disc. The problem seems to be
shifting the x,y,z data into the correct section of the structured grid
object. The below works fine with structured points (i.e. no 
SetPointComponent lines), but not for the grid.

I'd be very grateful to anyone who could tell me how to do this...
Simon.

===================================================================================
package require vtk
package require vtkinteraction
package require vtktesting

vtkProgrammableDataObjectSource dos
dos SetExecuteMethod parseFile

proc parseFile {} {
     set pi [expr 4*atan(1)]
     set nr     64
     set ntheta 256
     set nrnt   [expr $nr*$ntheta]
     set nsteps 800
     #
     set file [open "~/matlab/janusl.dat" r]
     fconfigure $file -translation binary
     #read 4 bytes
     set data [read $file 4]
     binary scan $data i val
     #this is the byte count of the fortran write
     #we use this to read in the data
     set data [read $file $val];
     #the data are double-precision (64bit) floats in native (LE) format
     close $file
     binary scan $data d[expr $val / 8] a;
     unset data
     #
     set fieldData [[dos GetOutput] GetFieldData]
     $fieldData AllocateArrays 4
     #
     #coordinates
     vtkFloatArray x;    vtkFloatArray y;    vtkFloatArray z
     x SetName X;        y SetName Y;        z SetName Z
     for {set rho 0} {$rho < $nr} {incr rho} {
	for {set theta 0} {$theta < $ntheta} {incr theta} {
	    set t [expr 2*$pi*$theta/$ntheta]
	    set r [expr $rho/$nr]
	    x InsertNextValue [expr $r*sin($t)]
	    y InsertNextValue [expr $r*cos($t)]
	    z InsertNextValue 0
	}
     }
     $fieldData AddArray x;    $fieldData AddArray y;    $fieldData 
AddArray z
     #
     #now extract phi(:,:,100)
     vtkFloatArray phi
     phi SetName PHI
     set tstep 100
     for {set j [expr $nrnt*$tstep]} {$j < $nrnt*($tstep+1)} {incr j} {
	phi InsertNextValue [lindex $a $j]
     }
     $fieldData AddArray phi
}
}

vtkDataObjectToDataSetFilter do2ds
do2ds SetInput [dos GetOutput]
do2ds SetDataSetTypeToStructuredGrid
do2ds DefaultNormalizeOn
do2ds SetDimensions 64 256 1
do2ds SetPointComponent 0 X 0
do2ds SetPointComponent 1 Y 0
do2ds SetPointComponent 2 Z 0



vtkRearrangeFields rf
rf SetInput [do2ds GetOutput]
rf AddOperation MOVE PHI DATA_OBJECT POINT_DATA


vtkAssignAttribute aa
aa SetInput [rf GetOutput]
aa Assign PHI SCALARS POINT_DATA
aa Update

-- 
====================================================
From: Simon Allfrey
PPB 114
Centre de Recherches en Physique des Plasmas
Association Euratom - Confédération Suisse
Ecole Polytechnique Fédérale de Lausanne
CH-1015 Lausanne, Switzerland
Tel. (+41 21) 6933464 ---- Fax. (+41 21) 6935176
email: Simon.Allfrey at epfl.ch
====================================================

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

mQGiBD2ar0URBACJQGMhID9FQgmgbnlZdhzz3x9qsI8ykXPZY+B/tVC5oYB161eX
4qZ56U1mGydf7TTunsCnm4WkPCK9XnoKOP/bIxpo0MjNY3A2cJR8efmG0+mTW8zN
XvTzu4KbPJhfOrxyQWK84ppCvI41s+kIWbDP08LsSOGBIa6CzOjEHn97EwCg8ZDM
ViB3Qn1MFaZN8Z3M3Lzu/k0D/1aqyabMjR9AIom+qP4tr1J7kDXzBdaetTwvcj9w
Y6s16cvO6E828l3ljo32id+WzPNEZWlXTKe3GOLkA+3xEtKQiThtdPj6rU7d0+hi
YtZH9qnx8LhS2wtigMsym+9Y+Ovzgj9He9AM5l1pOIiNYtgDMyuiwXbIPDOmVCH4
ysH3A/9UiTTAnIS59oWolCmW32oiIoo6eqHTYPBVEcbi6ylxgGT6SjQee050x8o4
pZ28//gjVtTBThMGy65455hvo/1NadZsGeNnfZGHL/Uj9iS/1odeYK+QVedPI0PP
X0RnFwW78f7uYMn6QNOk5syjtCtn0BKcD9EGGOA6ReNOwNCZCbQlU2ltb24gQWxs
ZnJleSA8c2ltb24uYWxsZnJleUBlcGZsLmNoPohXBBMRAgAXBQI9mq9FBQs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