How to color vertices/lines of a vtkCellArray?

Lawrence Werner rendawg at plinet.com
Wed Sep 22 13:19:07 EDT 1999


I don't know if this is the way to do it, but I got around this problem in wire-frame viewing by including an additional set of Actors that have the same data passed through a vtkExtractEdges and then passing it through a vtkTubeFilter.

In pseudo-code:
// Cell Array and Points have already been populated (pCells and pPoints)
vtkPolyData* pPoly = vtkPolyData::New();
pPoly->SetPoints( pPoints );
pPoly->SetPolys(pCells);

vtkExtractEdges* pEdges = vtkExtractEdges::New();
pEdges->SetInput( pPoly );

vtkTubeFilter* pTubes = vtkTubeFilter::New();
pTubes->SetInput( pEdges->GetOutput() );
pTubes->SetRadius( 0.1 );  // or some similarly smallish number
pTubes->SetNumberOfSides(6);

vtkPolyDataMapper* pEdgeMapper = vtkPolyDataMapper::New();
pEdgeMapper->SetInput( pTubes->GetOutput() );

vtkActor* pEdgeActor = vtkActor::New();
pEdgeActor->SetMapper( pEdgeMapper );
// Now you can set the actor to be a specific color
pEdgeActor->GetProperty()->SetColor( 1,0,0 );

Then all you do is add both sets of Actors (the ones you have and the new ones) and override the vtkHandleMessage for 'w' and 'W' to Remove the full Actors and for 's' and 'S' to add them back in (if you still want to keep the ability to have surface viewing).

Now this is probably quite the work-around and there most likely is a better way to do it, but at least it worked for me *grin*.

Hope that this helps...

Lawrence "Renny" Werner


-----Original Message-----
From:	Mirco Mueller [SMTP:mirco at pool.informatik.rwth-aachen.de]
Sent:	Wednesday, September 22, 1999 8:09 AM
To:	VTK-Users
Subject:	Q: How to color vertices/lines of a vtkCellArray?

Greetings vtk-gurus!

    I am trying to get the actors, made of vtkCellArrays and built from
vtkPolyData, colored, the way one usually colors any object in vtk. But
somehow it does not work. I am using the method:

    actors->GetProperty()->SetColor( r, g, b );

I tried to call this method before and after I do a:

    ren->AddActor( actors );

    But it makes not difference. The drawn wireframe stays black. No
matter what I tried. Is there some special case I have to think about
and did not sofar, while working with vtkCellArrays. The code and the
colors I use for coloring are unchanged from a previous version of my
program, where I build the geometry utilising vtkUnstructuredGrid.

    I also took a look at the examples from the vtk distribution. There
is a program callced Cube.cxx. There they use vtkScalars to color the
different vertices of the geometry. But even this approach did somehow
not work for me. What general consideration are nesseccary if one wants
to color vtkCellArray objects?

Thanks in advance for your time and kind advice!

Best regards...

Mirco



-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------



-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------





More information about the vtkusers mailing list