[vtkusers] Adding chars to 3D char array in python or how to add colors to array?

lynx.abraxas at freenet.de lynx.abraxas at freenet.de
Mon Dec 21 02:18:22 EST 2009


Hello!


I've  got  the  problem  now that colors.InsertNextTupleValue(color) yields an
attribute    error     in     my     python     code     (translation     from
http://www.vtk.org/Wiki/VTK_Examples_Color_a_mesh_by_height).

It would need a pointeerr that again does not exist in python but there seems no
function like InsertNextTupleValue(color[0],color[1],color[2]).  SetTuple3  of
vtkArray  wouldn't  do  because  the  colours  need  to  be  chars (if I'm not
mistaken).
It works with colors.InsertNextValue(int(dc)) (see code below and pic) but  it
seems to me that only one of rgb is added that way or is that just the default
lookuptabel?
Is there a documentation for the wrapper API of vtk somewhere?

Thanks for any help or hints.
Lynx


_______________________

    smoother= vtk.vtkWindowedSincPolyDataFilter()
    smoother.SetInput(contour.GetOutput());
    smoother.SetNumberOfIterations(20);
    #smoother.BoundarySmoothingOff();
    #smoother.FeatureEdgeSmoothingOff();
    #smoother.SetFeatureAngle(120.0);
    #smoother.SetPassBand(.001);
    smoother.NonManifoldSmoothingOn();
    smoother.NormalizeCoordinatesOn();
    smoother.GenerateErrorScalarsOn(); #GenerateErrorVectorsOn ();
    smoother.Update();

    smoothed_polys= smoother.GetOutput()


    ## colouring of verts according to displacement of smoother

    smoother_error= smoothed_polys.GetPointData().GetScalars()

    ##Find min and max z
    se_range= smoother_error.GetRange ()
    minz= se_range[0] #min(smoother_error)
    maxz= se_range[1] #max(smoother_error)
    print "min/max", minz, maxz
    minz= -1 #this way colours of different particles are comparable
    maxz=  1
 
    ## Create the color map
    colorLookupTable= vtk.vtkLookupTable()
    colorLookupTable.SetTableRange(minz, maxz)
    colorLookupTable.Build()
 
    ## Generate the colors for each point based on the color map
    colors= vtk.vtkUnsignedCharArray()
    colors.SetNumberOfComponents ( 3 )
    colors.SetName ( "Colors" );
 
    color= [0] * 3
    #color= [0, 0, 0]
    for i in range(0, smoothed_polys.GetNumberOfPoints()):
        #p= smoothed_polys.GetPoint(i)
        cp= smoother_error.GetTuple1(i)
        #dcolor= colorLookupTable.GetColor(cp)
        dcolor= colorLookupTable.GetTableValue(cp) #rgba
        #print "dcolor", dcolor
        for j in range(0, 3): #using only rgb
            dc= 255 * dcolor[j]
            #print j, color
            color[j]= int(dc)
            colors.InsertNextValue(int(dc))
        #colors.InsertNextTupleValue(color)

    ##assign colours
    smoothed_polys.GetPointData().AddArray(colors);





-------------- next part --------------
A non-text attachment was scrubbed...
Name: smooth_test_01_01.jpg
Type: image/jpeg
Size: 41431 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091221/dd0108c7/attachment.jpg>


More information about the vtkusers mailing list