[vtkusers] Color each object independantly with vtkProgrammableGlyphFilter
robert09
robertgreen at gigacomp.co.za
Sun Jun 7 04:01:08 EDT 2015
Hi,
I would like to use VTk for the visualisation of an Octree containing both
occupancy and NDT data. The main problem that I am having is that I cannot
seem to get each voxel (cuboid) coloured independently. All cuboids are
shown at the correct position and is the correct size. My Code is structured
as follows.
cubedata = []
points = vtk.vtkPoints()
colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(3)
colors.SetName("Colors")
index = 0
for k, node in enumerate(tree):
if (node.occupancy > 0) and node.isLeaf:
node.get_cube_display_data(minHeight,
maxHeigth,index,points,colors,cubedata)
index+=1
def Glyph():
ptId = glypher.GetPointId()
xyz = glypher.GetPoint()
cube.SetCenter(xyz)
cube.SetXLength(cubedata[ptId][0])
cube.SetYLength(cubedata[ptId][1])
cube.SetZLength(cubedata[ptId][2])
polydata = vtk.vtkPolyData()
polydata.SetPoints(points)
colors.SetNumberOfTuples(polydata.GetNumberOfPoints())
polydata.GetPointData().SetScalars(colors)
cube = vtk.vtkCubeSource()
glypher = vtk.vtkProgrammableGlyphFilter()
glypher.SetColorModeToColorByInput()
glypher.SetInput(polydata)
glypher.SetSource(cube.GetOutput())
glypher.SetGlyphMethod(Glyph)
glyphMapper = vtk.vtkPolyDataMapper()
glyphMapper.SetInputConnection(glypher.GetOutputPort())
glyphActor = vtk.vtkActor()
glyphActor.SetMapper(glyphMapper)
# Create the rendering stuff
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
ren1.AddActor(glyphActor)
ren1.SetBackground(1, 1, 1)
renWin.SetSize(450, 450)
renWin.Render()
In the code given above the "get_cube_display_data function looks" like
this:
def get_cube_display_data(self, _minHeight, _maxHeigth, _index, _points,
_colors, _cube_data):
h = (float(self.position[2]-_minHeight) / (_maxHeigth-_minHeight))
r,g,b = colorsys.hsv_to_rgb(h, 1., 1.)
col = (int(r*255),int(g*255),int(b*255))
_points.InsertNextPoint(self.position[0], self.position[1],
self.position[2])
_colors.InsertNextTupleValue(col)
_cube_data.append((self.size,self.size,self.size))
So basically for each leaf node in the octree I add its position to the
points and its colour (determined by height) to the color char array. Even
if I set to "col" variable in the get_cube_display_data to (0,255,0), I
still get random coloured cuboids.
Any help would be greatly appreciated.
Regards
--
View this message in context: http://vtk.1045678.n5.nabble.com/Color-each-object-independantly-with-vtkProgrammableGlyphFilter-tp5732192.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list