[vtkusers] Re: vtk and python for large amout of data
Marcus Stojek
stojek at part-gmbh.de
Mon Dec 9 16:56:15 EST 2002
Hi,
thanks a lot for the answers. Understanding this SetVoidArray function
helps. Now I am pretty close to what I need, but still there is a small
problem with vtkPoints.SetData()
Although I think I did everything correct, there seems to be a problem
with NumberOfPoints(). With GetPoint(id) I get the right coordinates for
all Points, but still NumberOfPoints is 1. Below you will find my small
example code. Any idea?
Thanks,
marcus
Python 2.2.1
Numeric 21.0b1
Windows NT
#----snip-------------------------------------------------------------------
import Numeric
narray = Numeric.array((0,0,0, 4,0,0, 0,4,0, 0,0,4
,3,8,0),Numeric.Float32)
nnum = 5
earray = Numeric.array((4,0,1,2,3, 4,4,2,3,1),Numeric.Int32)
ctarray = Numeric.array((10,10),'char')
locarray = Numeric.array((0,5),Numeric.Int32)
enumber = 2
#idtypes
IdTArray=vtkIdTypeArray()
IdTArray.SetVoidArray(earray,enumber,1)
#celltypes
cidTArray=vtkUnsignedCharArray()
cidTArray.SetVoidArray(ctarray,enumber,1)
#cell array
vtkCArray=vtkCellArray()
vtkCArray.SetCells(enumber,IdTArray)
#cell location
vtkLocArray=vtkIntArray()
vtkLocArray.SetVoidArray(locarray,enumber,1)
#grid
grid=vtkUnstructuredGrid()
grid.SetCells(cidTArray,vtkLocArray,vtkCArray)
#points
vpoints=vtkFloatArray()
vpoints.SetNumberOfComponents(3)
vpoints.SetVoidArray(narray,nnum,1)
##########################
# # #### # ####
# # # # # #
#### #### # ####
# # # # #
# # #### #### #
pointe = vtkPoints()
#This does not work because NumberOfPoints is wrong
pointe.SetData(vpoints)
#This does work:
#pointe.SetNumberOfPoints(5)
#pointe.SetPoint(0, 0,0,0)
#pointe.SetPoint(1, 4,0,0)
#pointe.SetPoint(2, 0,4,0)
#pointe.SetPoint(3, 0,0,4)
#pointe.SetPoint(4, 3,8,0)
print 'Number of points',pointe.GetNumberOfPoints()
print 'Probe point',pointe.GetPoint(2)
###########################
grid.SetPoints(pointe)
win = wxMDIChildFrame(self.parent, -1, 'test')
widget = wxVTKRenderWindow.wxVTKRenderWindow(win, -1)
MapperSurf=vtkDataSetMapper()
MapperSurf.SetInput(grid)
MapperSurf.ScalarVisibilityOff()
ActorSurf=vtkActor()
ActorSurf.SetMapper(MapperSurf)
PropSurf=vtkProperty()
PropSurf.SetDiffuseColor(0.7,0.7,0.7)
PropSurf.SetRepresentationToSurface()
PropSurf.BackfaceCullingOff()
PropSurf.FrontfaceCullingOff()
ActorSurf.SetProperty(PropSurf)
ren = vtkRenderer()
widget.GetRenderWindow().AddRenderer(ren)
ren.AddActor(ActorSurf)
widget.Render()
widget.Show(true)
#--snip---------------------------------------------------------------------
>Unfortunately, to create an unstructured grid, you have to use the
>following method:
>
>void vtkUnstructuredGrid::SetCells(vtkUnsignedCharArray *cellTypes,
> vtkIntArray *cellLocations,
> vtkCellArray *cells);
>
>This means that you have to compute cellTypes, cellLocations and cells.
>This is because the following is not wrapped:
>
>void vtkUnstructuredGrid::SetCells(int *types, vtkCellArray *cells);
>
>(since it takes a pointer to a variable length in array).
>
>-Berk
More information about the vtkusers
mailing list