[vtkusers] Show edges with picker

nmitreski nimitreski at gmail.com
Mon Jan 21 10:48:41 EST 2008


Thanks for advice. You give me some direction for solving problem. It has
some little problem in line

vtkIdType ids[2];
ids[0] = pts[0]; ids[1] = pts[1];

when debugging the code, I receive error message in this line, maybe
previous command

 mesh->GetCellPoints( cell_id, npts, pts );

did not give wanted values for npts and pts.

Bob-139 wrote:
> 
> 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.
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 
> 

-- 
View this message in context: http://www.nabble.com/Show-edges-with-picker-tp14803681p15000213.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list