我正在尝试可视化一个 vtk 非结构化网格。为了获得我的网格点的坐标,我使用了 vtk 交互器。我可以通过使用 OnRightButtonDown() "overrid" 选择点来获取点坐标。但是,我失去了对 window 的控制。表示我无法旋转、平移或缩放我的网格。我尝试使用 OnRightButtonDoubleClick() 但这似乎不起作用。知道如何在不影响鼠标事件行为的情况下使用交互器获取节点坐标,或者如何在鼠标按钮向上时重新初始化它...
foo
{
...
// vtk visualization
container = new QWidget(ui->graphicsView);
qvtkWidget = new QVTKOpenGLNativeWidget(container);
...
//Create and link the mapper actor and renderer together.
mapper = vtkSmartPointer<vtkDataSetMapper>::New();
actor = vtkSmartPointer<vtkActor>::New();
renderer = vtkSmartPointer<vtkRenderer>::New();
...
// add elements nodes
...
mapper->SetInputData(eleNodeIdsPtr);
actor->SetMapper(mapper);
renderer->AddActor(actor);
// ste up camera
renderer->SetBackground(0.06, 0.2, 0.5);
double pos[3] = { 0, 0.2, 1 };
double focalPoint[3] = { 0, 0, 0 };
double viewUp[3] = { 1, 1, 1 };
renderer->GetActiveCamera()->SetPosition(pos);
renderer->GetActiveCamera()->SetFocalPoint(focalPoint);
renderer->GetActiveCamera()->SetViewUp(viewUp);
renderer->GetActiveCamera()->Zoom(0.5);
//Add render
qvtkWidget->GetRenderWindow()->AddRenderer(renderer);
qvtkWidget->show();
// Select node
renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(qvtkWidget-
>GetRenderWindow());
vtkNew<InteractorStyle2> style;
renderWindowInteractor->SetInteractorStyle(style);
style->eleNodeIdsPtr = eleNodeIdsPtr;
style->xyzGlobalPtr = xyzGlobalPtr;
renderWindowInteractor->Initialize();
}
// Define interaction style
class InteractorStyle2 : public vtkInteractorStyleTrackballActor
{
public:
static InteractorStyle2* New();
vtkTypeMacro(InteractorStyle2, vtkInteractorStyleTrackballActor);
vtkNew<vtkNamedColors> color;
...
void OnLeftButtonDown() //...>>>This doesn't work!!
{
}
void OnLeftButtonDown() override // .. this work but the I can't controle the transformation anymore!!
{
this->PointPicker = vtkSmartPointer<vtkPointPicker>::New();
// Get the selected point
int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];
this->FindPokedRenderer(x, y);
this->PointPicker->Pick(this->Interactor->GetEventPosition()[0],
this->Interactor->GetEventPosition()[1],
0, // always zero.
this->Interactor->GetRenderWindow()
->GetRenderers()
->GetFirstRenderer());
if (this->PointPicker->GetPointId() >= 0)
{
this->StartPan();
this->SelectedPoint = this->PointPicker->GetPointId();
double p[3];
this->eleNodeIdsPtr->GetPoint(this->SelectedPoint, p);
std::cout << "p: " << p[0] << " " << p[1] << " " << p[2] << std::endl;
}
}
vtkSmartPointer<vtkPointPicker> PointPicker;
vtkIdType SelectedPoint;
vtkSmartPointer<vtkUnstructuredGrid> eleNodeIdsPtr;
vtkSmartPointer< vtkPoints > xyzGlobalPtr;
}
vtkStandardNewMacro(InteractorStyle2);
}