vtk二维图像鼠标控制移动

过程如下:

  • 将两次鼠标位置的显示坐标移动到世界坐标
  • 计算x、y轴的偏移量
  • 设置相机的位置和相机焦点

关键代码如下:

void OnLeftButtonDown() {
    clickPos = this->GetInteractor()->GetEventPosition();
    point1[0] = clickPos[0];
    point1[1] = clickPos[1];

    renderer->SetDisplayPoint(point1[0], point1[1], 0);
    renderer->DisplayToWorld();
    WorldPoint[0] = (renderer->GetWorldPoint())[0];
    WorldPoint[1] = (renderer->GetWorldPoint())[1];
    WorldPoint[2] = (renderer->GetWorldPoint())[2];
    btPressed = true;

}
void stVtkInteractorStyleImage::OnLeftButtonUp() {

        clickPos1 = this->GetInteractor()->GetEventPosition();
        point2[0] = clickPos1[0];
        point2[1] = clickPos1[1];

        renderer->SetDisplayPoint(point2[0], point2[1], 0);
        renderer->DisplayToWorld();
        WorldPoint1[0] = (renderer->GetWorldPoint())[0];
        WorldPoint1[1] = (renderer->GetWorldPoint())[1];
        WorldPoint1[2] = (renderer->GetWorldPoint())[2];
        //计算两点的偏移量
        double disX = WorldPoint1[0] - WorldPoint[0];
        double disY = WorldPoint1[1] - WorldPoint[1];
        vtkCamera *camera = this->renderer->GetActiveCamera();
        double* pos = camera->GetPosition();
        double* focalPos = camera->GetFocalPoint();

        camera->SetPosition(pos[0] - disX, pos[1] - disY, pos[2]);
        camera->SetFocalPoint(focalPos[0] - disX, focalPos[1] - disY, focalPos[2]);
        renderer->GetRenderWindow()->GetInteractor()->Render();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值