[Paraview] JPEG to vtkPolyData (sphere), python programmable filter

Habbinga, Sonja s.habbinga at fz-juelich.de
Fri Jan 13 03:05:36 EST 2012


Hello,

I'm trying to write a filter to produce a vtkPolyData (a sphere) out of a JPEG (2048x1024) using python programmable filter. I tried to write the filter according to the example "Changing Datatype" from http://www.cmake.org/Wiki/Python_Programmable_Filter but my filter doesn't seem to do anything:

#create a vtkPolyData output
#and populate its cells with the point centered
#scalars of the input dataset

inputImage = self.GetInput()
output = self.GetOutput()

numPts = inputImage.GetNumberOfPoints()

lat = 1024
lon = 2048
PI = math.atan2( 0, -1 )

dlat = 180/(lat - 1)
dlon = 360/(lon - 1)
lon = lon + 1
nrpoints = lon*lat

points = vtk.vtkPoints()
polygons = vtk.vtkCellArray()
points.SetDataTypeToFloat()
points.SetNumberOfPoints( nrpoints )
num = 0

for  i in range(0,  lat) :
        for j in range(0, lon) :
                x = math.cos( j*dlon / 180*PI ) * math.cos( (90/i*dlat)/180*PI)
                y = math.sin( j*dlon / 180*PI ) * math.cos( (90/i*dlat)/180*PI)
                z = math.sin( (90-i*dlat)/180*PI)

                num = i*lon+j
                points.SetPoint( num, x, y, z )

for  i in range(0,  lat) :
        for j in range(0, lon) :
                polygons.InsertNextCell( 4 )
                polygons.InsertCellPoint( i * lon + j )
                polygons.InsertCellPoint((i + 1) * lon + j)
                polygons.InsertCellPoint( (i + 1) * lon + j + 1)
                polygons.InsertCellPoint(i * j + j + 1) )

output.SetPoints( points )
output.SetPolys( polygons )
output.AllocateScalars()


#add the new array to the output
output.GetCellData().AddArray(input.GetPointData().GetScalars())




What am I doing wrong?  Paraview says, that the output has 0 cells and 0 points...

How can I produce some debut-output in the filter?

Thanks for your help!

Sonja

------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
Forschungszentrum Juelich GmbH
52425 Juelich
Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzender des Aufsichtsrats: MinDir Dr. Karl Eugen Huthmacher
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
Karsten Beneke (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
Prof. Dr. Sebastian M. Schmidt
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------

Kennen Sie schon unsere app? http://www.fz-juelich.de/app


More information about the ParaView mailing list