[vtkusers] Show edges with picker

Bob oraciotaglia at tiscali.it
Wed Jan 16 17:17:21 EST 2008


2008/1/16, nmitreski <nimitreski at gmail.com>:
>
> Hi.
> I have some problem. I'm trying to display edges of picked cell using cell
> picker. I'm trying that on cone (vtkConeSource), and I just like to display
> edges from picked cell. (something like edges from just 1 triangle)
> Can somebody help me? If you have some working example for picking cells in
> C++, please send it to me.
>

I think that you have to add another actor to the renderer, or better
make use of a vtkAssembly. The new polydata from which you are mapping
should have only three lines contouring the cell. The actual code is
something like the following:


// mesh is the input polyData
// here picker is a vtkCellPicker instance.
// giving a cell id you want to highlight,
// picked from x, y display position.


vtkPolyData* contour= vtkPolyData::New();
vtkCellArray* lines= vtkCellArray::New();
vtkAssembly* assem= vtkAssembly::New();
vtkPolyDataMapper* mapper1= vtkPolyDataMapper::New();
vtkPolyDataMapper* mapper2= vtkPolyDataMapper::New();
vtkActor* principalActor= vtkActor::New();
vtkActor* contourActor= vtkActor::New();
principalActor->SetMapper( mapper1 );
principalActor->SetMapper( mapper2 );
mapper1->SetInput( mesh );
mapper2->SetInput( contour );

assem->AddPart( principalActor );
assem->AddPart( contourActor );

contour->SetPoints( mesh->GetPoints() );
contour->SetLines( lines );

vtkCellPicker* picker= vtkCellPicker::New();
int is_pick= picker->Pick( (float)x, (float)y, 1.0, renderer );

if( ! is_pick )
{
   return;
}

vtkIdType cell_id= picker->GetCellId();

vtkIdType npts, *pts;
mesh->BuildLinks();
mesh->GetCellPoints( cell_id, npts, pts );

assert( npts == 3 ):

vtkIdType ids[2];
ids[0]= pts[0]; ids[1]= pts[1];
lines->InsertNextCell( 2, ids );

ids[0]= pts[1]; ids[1]= pts[2];
lines->InsertNextCell( 2, ids );

ids[0]= pts[2]; ids[1]= pts[0];
lines->InsertNextCell( 2, ids );

renderer->AddActor( assem );

// then the ...->Delete() stuff

HTH.
Bob.



More information about the vtkusers mailing list