
Tue, 10/25/2022 - 11:38
Hi there,
I got a problem with interaction shapes rendered in VTK. i have followed guides (https://old.opencascade.com/doc/occt-7.5.0/overview/html/occt_user_guide...) step by step. But when I use 'Pick' function. It seems picked nothing. Here are my parts of codes.
Build info:
VTK 9.1
QT 6
OpenCASCADE 7.6
Windows10
Visual Studio 19
Codes:
// this will be called after initilized the renderer, I create a test shape here
void vtkInteractorStyle3DMain::SetPickerRenderer(vtkRenderer* renderer)
{
SetCurrentRenderer(renderer);
shapePicker->SetRenderer(renderer);
BRepPrimAPI_MakeBox mkBox(1, 2, 3);
const TopoDS_Shape& aShape = mkBox.Shape();
IVtkOCC_Shape::Handle aShapeImpl = new IVtkOCC_Shape(aShape);
vtkNew<IVtkTools_ShapeDataSource> DS;
DS->SetShape(aShapeImpl);
vtkNew<vtkPolyDataMapper> Mapper;
Mapper->SetInputConnection(DS->GetOutputPort());
vtkNew<vtkActor> Actor;
Actor->SetMapper(Mapper);
GetCurrentRenderer()->AddActor(Actor);
}
//Then I do key bind with function pick
void vtkInteractorStyle3DMain::OnLeftButtonDown()
{
shapePicker->SetSelectionMode(SM_Edge);
shapePicker->Pick(this->Interactor->GetEventPosition()[0], this->Interactor->GetEventPosition()[1], 0);
IVtk_ShapeIdList ids = shapePicker->GetPickedShapesIds(true);
vtkActorCollection* actors = shapePicker->GetPickedActors(true);
//std::cout << "clicked at: " << this->Interactor->GetEventPosition()[0] << ", " << this->Interactor->GetEventPosition()[1] << std::endl;
std::cout <<"ids: "<< ids.Size()<<" actors: "<< actors->GetNumberOfItems() << std::endl;
}
The problem is: no matter how I click, it always return 0 ids and 0 actors.
I have tried area pick, tried different shapes (SM_Edge,SM_Face,SM_Solid...). They all not work. Can someone help me with that?
Mon, 04/24/2023 - 16:15
Did you correctly register your shape picker to your vtkInteractorStyle3DMain?
After creating the shape picker and assigning a renderer to it, normally it is required to register it to your interactorStyle.