1. 前言

在一个项目中,需要用鼠标和键盘完成对模型旋转操作和移动操作。
实现中,对鼠标的操作虚函数进行了重写,完成左右键点击,对模型正负方向旋转。

2.代码

#include "InitInclude.h"
#include "CreateSphere.h"
#include "thr.h"
#include "2D.h"
#include "2DplatformTexture.h"
#include "3DGammaKnife.h"
#include "2D(nei_qianghou).h"
#include "MouseInteractorHighLightActor.h"
#include "MouseInter.h"
#include "duobianxing.h"
#include "duobianxingzhuose(shiyongqianghoudiban).h"
#include "MouseInteractorStyle6 .h"
#include "testAdd.h"
#include <vtkImageImport.h>
#include <vtkImageActor.h>
#include <vtkInteractorStyleImage.h>
#include <vtkInteractorStyleUser.h>
#include <vtkObjectFactory.h>
#include "my3DCameraStyle.h"
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCylinderSource.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include "MouseInteractorStyle2.h"
#include "MouseIntr922.h"
#include <vtkInteractorStyleTrackballActor.h>//另一种交互方式,操纵演员
#include <vtkInteractorStyleTrackballCamera.h>
// Handle mouse events
class MouseInteractorHighLightActor222 : public vtkInteractorStyleTrackballCamera
{
public:static MouseInteractorHighLightActor222* New();vtkTypeMacro(MouseInteractorHighLightActor222, vtkInteractorStyleTrackballCamera);MouseInteractorHighLightActor222(){m_RotateZStep = 0.0;LastPickedActor = NULL;LastPickedProperty = vtkProperty::New();}virtual ~MouseInteractorHighLightActor222(){LastPickedProperty->Delete();}//左键按下执行以下操作virtual void OnLeftButtonDown(){ this->LastPickedActor = tActor;if (this->LastPickedActor){// Save the property of the picked actor so that we can// restore it next timethis->LastPickedProperty->DeepCopy(this->LastPickedActor->GetProperty());// Highlight the picked actor by changing its propertiesm_RotateZStep += 10.05;this->LastPickedActor->RotateZ(m_RotateZStep);}// Forward eventsvtkInteractorStyleTrackballCamera::OnLeftButtonDown();}//右键按下执行以下操作virtual void OnRightButtonDown(){this->LastPickedActor = tActor;if (this->LastPickedActor){// Save the property of the picked actor so that we can// restore it next timethis->LastPickedProperty->DeepCopy(this->LastPickedActor->GetProperty());// Highlight the picked actor by changing its propertiesm_RotateZStep += 10.05;this->LastPickedActor->RotateZ(m_RotateZStep);}// Forward eventsvtkInteractorStyleTrackballCamera::OnRightButtonDown();}virtual void OnChar(){this->LastPickedActor = tActor;switch (this->Interactor->GetKeyCode()){case VK_SPACE:{//if (this->LastPickedActor){// Save the property of the picked actor so that we can// restore it next timethis->LastPickedProperty->DeepCopy(this->LastPickedActor->GetProperty());// Highlight the picked actor by changing its propertiesm_RotateZStep += 10.05;this->LastPickedActor->RotateZ(m_RotateZStep);}cout << "sssssss38up " << endl;break;}case 26:{cout << "wertyuio " << endl;break;}}//vtkInteractorStyleTrackballCamera::OnRightButtonDown();}vtkActor    *tActor;double m_RotateZStep;
private:vtkActor    *LastPickedActor;vtkProperty *LastPickedProperty;
};vtkStandardNewMacro(MouseInteractorHighLightActor222);int main(int, char *[])
{ // This creates a polygonal cylinder model with eight circumferential facets// (i.e, in practice an octagonal prism).vtkNew<vtkCylinderSource> cylinder;cylinder->SetResolution(8);// The mapper is responsible for pushing the geometry into the graphics// library. It may also do color mapping, if scalars or other attributes are// defined.vtkSmartPointer<vtkPolyDataMapper> cylinderMapper = vtkSmartPointer<vtkPolyDataMapper>::New();cylinderMapper->SetInputConnection(cylinder->GetOutputPort());// The actor is a grouping mechanism: besides the geometry (mapper), it// also has a property, transformation matrix, and/or texture map.// Here we set its color and rotate it around the X and Y axes.vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::New();{cylinderActor->SetMapper(cylinderMapper);cylinderActor->RotateX(0);cylinderActor->RotateY(-0);cylinderActor->RotateZ(-0.0);cylinderActor->SetOrigin(0, 0, 0); }//vtkSmartPointer<vtkActor> cylinderActor1 = vtkSmartPointer<vtkActor>::New();//{//  cylinderActor1->SetMapper(cylinderMapper); //  double xx = 20;//     cylinderActor1->RotateX(xx);//  cylinderActor1->RotateY(-120.0);//  cylinderActor1->RotateZ(-40.0);//  cylinderActor1->SetOrigin(1, 1, 1);//} vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();//vtkSmartPointer<MouseInteractorStyle2> StyleActor = vtkSmartPointer<MouseInteractorStyle2>::New();vtkSmartPointer<MouseInteractorHighLightActor222> style = vtkSmartPointer<MouseInteractorHighLightActor222>::New();style->SetDefaultRenderer(renderer);style->tActor = cylinderActor;renderWindowInteractor->SetInteractorStyle(style);//style->SetActor(cylinderActor);//renderWindowInteractor->SetInteractorStyle(style);//StyleActor->SetDefaultRenderer(renderer);//StyleActor->ActorA = cylinderActor;//StyleActor->ActorB = cylinderActor1;//renderWindowInteractor->SetInteractorStyle(StyleActor);// The renderer generates the image// which is then displayed on the render window.// It can be thought of as a scene to which the actor is added renderer->AddActor(cylinderActor);//renderer->AddActor(cylinderActor1);// Zoom in a little by accessing the camera and invoking its "Zoom" method.renderer->ResetCamera();renderer->GetActiveCamera()->Zoom(1.5);// The render window is the actual GUI window// that appears on the computer screenvtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();renderWindow->SetSize(900, 900);renderWindow->AddRenderer(renderer);renderWindow->SetWindowName("Cylinder");// The render window interactor captures mouse events// and will perform appropriate camera or actor manipulation// depending on the nature of the events.renderWindowInteractor->SetRenderWindow(renderWindow);// This starts the event loop and as a side effect causes an initial render.renderWindow->Render();renderWindowInteractor->Start();
}

3.效果

https://www.bilibili.com/video/BV1Wq4y1o7KN/

鼠标和VTK模型交互,通过左右键实现对模型的两个方向旋转


http://www.taodudu.cc/news/show-1639474.html

相关文章:

  • (2)通过输入参数(测量数据)构建三维体模型(01)
  • (01)VTK读取OBJ格式模型
  • (02)vtk 绘制模型的外轮廓线 模型轮廓线
  • (03)两个模型的交集、并集、差集
  • (04)VTK移动模型,判断是否相交
  • (05)vtk通过多边形构建矩形,并拉伸成立方体,两个立方体独立操作
  • (06)vtk修改默认鼠标操作,实现鼠标按键控制模型旋转
  • who i am !
  • (01)OpenGL es中只在指定区域渲染view
  • (01)C++之设计模式演变
  • C++设计模式(全网最通俗易懂的设计模式进阶)
  • c++工程模式+配置文件+动态调用类
  • 读书感悟之,从术到道
  • 因果否?
  • (01)数据库及相关
  • avg最多用多少列 mysql_40斤一桶水,最多用多少克磷酸二氢钾?打几次增产效果最好...
  • 用单片机测量流体流速的_旋进旋涡流量计的测量原理及优点
  • 文字加减前后缀lisp_日本搞笑艺人催泪讲授汉字课堂告诉你文字背后的意义!...
  • 幼儿园调查过程怎么写_幼儿园对孩子的重要性你真的清楚吗?
  • 三星oneui主屏幕费电_这或许是单手握持手感最佳的手机 三星Galaxy S20上手体验...
  • 麦克纳姆轮运动原理怎么安装_家用中央空调水系统原理是什么?怎么样安装比较好呢?...
  • redis 判断存在性_一口气说出四种幂等性解决方案,面试官露出了姨母笑~
  • python心跳包原理_Python 用心跳(UDP包)探测不活动主机
  • pin码计算器网页版_快对作业APP下载手机版电脑版官方正式上线
  • 进入已经打开的pyrebox_PyREBox-可用Python编写脚本的逆向工程沙盒
  • idea redis图形化_5.13redis图形化工具---idea中配置redis密码
  • oem718d 基准站设置_诺瓦泰NovAtel OEM718D全系统多频单机测向板卡
  • 常见的预设分栏包括_计算机应用基础_实训项目二Word综合应用
  • 嵌入式linux系统移植的四大步骤_嵌入式 Linux 产品技术评估之系统裁剪与启动速度...
  • centos 卸载_9个Linux发行版本,教你如何分别使用命令行卸载安装包

(8)VTK 鼠标左右键控制模型旋转相关推荐

  1. (06)vtk修改默认鼠标操作,实现鼠标按键控制模型旋转

    前言 通过鼠标的左右键按键,实现模型的旋转操作(在一个平面内) 方法 继承vtkInteractorStyleTrackballCamera类,重写鼠标左右键操作,完成特定功能 class Mouse ...

  2. iMouse - 快速切换鼠标左右键

    (此Blog是iMouse软件的官网) [名称]:iMouse [版本]:v1.2 (v1.2是首个公开发布版本,也是最新版,之前版本没有对外发布) [时间]:2012-01-06 [关键词]:腱鞘炎 ...

  3. linux下模仿用户左键,linux 鼠标左右键互换实现代码

    linux鼠标左右键互换脚本,作者今天, 使用 GNOME, 发现 Linux 也需要这些工具之一, 所以有了这个脚本.非常简单好用. lr="l" for id in `xinp ...

  4. 用C#实现鼠标左右键的切换

    转载地址:http://www.51test.net/show.asp?id=283640&Page=1#top 1. SwapMouseButton 根据MSDN所述,可以通过调用SwapM ...

  5. 戴记严选GM3323D 鼠标左右键失效 解决办法

    戴记严选 GM3323D 鼠标左右键失效原因分析 GM3323D软件下载 当你下载了驱动了并且使用2.4G连接鼠标时,当你修改RGB设置有几率导致左右键失效 请尝试用触摸板或者其他鼠标 重新点击修改R ...

  6. C#Winform中DataGridView控件根据鼠标左右键获取单元格值或者行列

    有多种方法可以获取单元格的值或者行列,此处选用了两种方式去获取分别用了CurrentCell方法和Rows[].Cells[]的方法去获取行列值 鼠标左键获取单独行列值 此处获取左键行列值的触发条件是 ...

  7. 转载:注册表修改--鼠标左右键菜单篇

    注册表修改--鼠标左右键菜单篇 加Apploc到右键中去: [HKEY_CLASSES_ROOT\exefile\shell\Apploc\command] 再修改其中的默认值为C:\windows\ ...

  8. linux 鼠标 反向,linux 鼠标左右键互换实现代码

    linux鼠标左右键互换脚本,作者今天, 使用 GNOME, 发现 Linux 也需要这些工具之一, 所以有了这个脚本.非常简单好用. lr="l" for id in `xinp ...

  9. c语言鼠标左右键怎么互换,用C#实现鼠标左右键的切换

    在平时用电脑的过程中,我喜欢隔段时间就把鼠标左右调换一下,一来是想让自己一侧的肩.手臂.手腕能得到休息,尽量避免因长期固定姿势使用鼠标而带来的身体不适,另一方面也因为我本来就是个左撇子,喜欢尝试给两只 ...

最新文章

  1. 谷歌让NLP模型也能debug,只要给一张「草稿纸」就行
  2. ajax实现简单计算器,一个简单的jQuery计算器实现了连续计算功能
  3. 关于《指针的艺术》看书时所遇到的问题
  4. unity 实现文本选中_Unity中如何读取TXT文本内容
  5. RNN-LSTM循环神经网络-03Tensorflow进阶实现
  6. 安装虚拟环境virtualenv与virtualenvwrapper在centos7系统上
  7. java框架之SpringBoot(5)-SpringMVC的自动配置
  8. Flask初级(十)flash与前台交互post详解
  9. 【Java学习笔记之二十六】深入理解Java匿名内部类
  10. 【热门主题】紫色梦幻天使win7主题
  11. 【实用工具】如何录制电脑屏幕gif动图?
  12. 基于c语言的象棋游戏-附带人机算法
  13. Arcscene教程
  14. MDK5.30下载来了,含镜像下载地址,ARM同时带来Cortex-M55调试展示(2020-05-05)
  15. M3U8 文件介绍 与 播放方法
  16. 马尔科夫细致平稳条件
  17. 天池数据竞赛docker提交操作学习
  18. 还要帮彬彬做课件,我苦啊
  19. Python-爬虫(xpath数据解析,爬取信息实战)
  20. rot13初学者和python的实现

热门文章

  1. [Python] 将两个列表合并为字典
  2. matlab2c使用c++实现matlab函数系列教程-sqrt函数
  3. Eclipse代码自动补全设置
  4. matlab关于向量的基本操作
  5. ajax中加html,向DIV中写入HTML(AJAX高手赐教)
  6. MySQL(四)InnoDB中一棵B+树能存多少行数据
  7. 行为驱动开发BDD和Cucunber简介
  8. spring listener监听器
  9. 设置窗体的可见性无效
  10. [转载] python十个程序_程序猿开发Python的十个基本入门技巧?