Difference between revisions of "ParaView/Python/Programmable Filters"

From KitwarePublic
Jump to: navigation, search
(New page: * Convert float colors to unsigned char colors The Transform filter converts any colors to floats, which Paraview cannot handle. To convert them back, you can use this: <sourc lang=text> i...)
 
m
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
* Convert float colors to unsigned char colors
+
==Convert float colors to unsigned char colors==
 
The Transform filter converts any colors to floats, which Paraview cannot handle. To convert them back, you can use this:
 
The Transform filter converts any colors to floats, which Paraview cannot handle. To convert them back, you can use this:
<sourc lang=text>
+
<source lang="python">
 
inp = self.GetInput()
 
inp = self.GetInput()
 
out = self.GetOutput()
 
out = self.GetOutput()
Line 16: Line 16:
 
out.GetCellData().AddArray(newData)
 
out.GetCellData().AddArray(newData)
 
</source>
 
</source>
 +
 +
{{ParaView/Template/Footer}}

Latest revision as of 20:30, 14 June 2011

Convert float colors to unsigned char colors

The Transform filter converts any colors to floats, which Paraview cannot handle. To convert them back, you can use this:

inp = self.GetInput()
out = self.GetOutput()
 
numCells  = inp.GetNumberOfCells()
data = inp.GetCellData().GetArray("Colors")
 
newData = vtk.vtkUnsignedCharArray()
newData.SetName('Colors_converted')
newData.SetNumberOfComponents(3)
for i in range(0, 3*numCells):
 val = int(data.GetValue(i))
 newData.InsertNextValue(val)
out.GetCellData().AddArray(newData)



ParaView: [Welcome | Site Map]