StudyVtk(二) vtkRenderWindowInteractor 交互器

VTK 提供了多个方法来与图形对象交互,其中的一个类是 vtkRenderWindowInteractor,这是一个操作相机。

对象和拾取工具的类,提供平台独立的相应鼠标、键盘和时钟时间的交互机制,通过VTK的观察者/命令模式将监听到的特定平台的鼠标和时钟事件交由vtkInteratorObserver或其子类进行处理。

下面是一个交互器的初识Demo

/*
 * 窗口互操作
 * vtkRenderWindowInteractor
 * 属性
 * vtkProperty
 *
 *
 */

//圆锥的类 数据源
#include <vtkConeSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkInteractorStyleTrackballActor.h>
#include <vtkProperty.h>


#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2) ;
VTK_MODULE_INIT(vtkInteractionStyle) ;
VTK_MODULE_INIT(vtkRenderingFreeType);


int main_02(int argc,char* argv[])
{

    vtkConeSource* coneSource = vtkConeSource::New();
    //分辨率
    coneSource->SetResolution(100);
    //高度
    coneSource->SetHeight(5);
    //底面半径
    coneSource->SetRadius(2);

    //映射器
    vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();

    mapper->SetInputConnection(coneSource->GetOutputPort());

    vtkActor* actor = vtkActor::New();
    actor->SetMapper(mapper);

    //设置颜色
    //actor->GetProperty()->SetColor(1,0,0);
    vtkProperty* prop = vtkProperty::New();
    prop->SetColor(0,1,0);
    //关掉灯光  失去三维效果
    //prop->SetLighting(false);
    actor->SetProperty(prop);

    vtkRenderer* renderer = vtkRenderer::New();
    renderer->AddActor(actor);
    renderer->SetBackground(0.1,0.2,0.4);

    vtkRenderWindow* window = vtkRenderWindow::New();
    window->SetSize(500,500);
    window->AddRenderer(renderer);

    vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::New();
    interactor->SetRenderWindow(window);

    vtkInteractorStyleTrackballCamera* camera = vtkInteractorStyleTrackballCamera::New();

    vtkInteractorStyleTrackballActor* actorStyle = vtkInteractorStyleTrackballActor::New();


    interactor->SetInteractorStyle(actorStyle);

    window->Render();
    renderer->GetActiveCamera()->Azimuth(1);

    interactor->Initialize();
    interactor->Start();

    //实现一系列操作
    //左键(按住)旋转 右键放大缩小
    /*
        vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::New();
        interactor->SetRenderWindow(window);

        window->Render();
        renderer->GetActiveCamera()->Azimuth(1);

        interactor->Initialize();
        interactor->Start();
    */



    //实现拖动旋转、放大
    /*
        vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::New();
        interactor->SetRenderWindow(window);

        vtkInteractorStyleTrackballCamera* camera = vtkInteractorStyleTrackballCamera::New();
        interactor->SetInteractorStyle(camera);

        window->Render();
        renderer->GetActiveCamera()->Azimuth(1);

        interactor->Initialize();
        interactor->Start();
    */


    window->Delete();
    renderer->Delete();
    mapper->Delete();
    actor->Delete();
    coneSource->Delete();
    interactor->Delete();
    camera->Delete();



    return 0;
}




 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

把我格子衫拿来

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值