如何禁用VTK的热键
how to disable vtk's hotkey
我想在vtk上禁用一些热键。 实际上我正在使用vtk.js,但是可以用正常的vtk方式告诉我。
我想在这里禁用下面的热键: "W":切换感兴趣区域 (ROI( 选择微件 "S":在体积渲染模式下切换切片平面 "V":切换为点形式 "R":重置相机
我尝试在OpenGLRenderwindow上设置InteractorStyleManipulator, 并尝试了全屏渲染方式。 但它不起作用。
我怎样才能通过它?
谢谢!
<div id="container"></div>
<script>
const container = document.querySelector('#container');
//VTK renderwindow/renderer
//const fullScreenRenderer = vtk.Rendering.Misc.vtkFullScreenRenderWindow.newInstance();
const renderWindow = vtk.Rendering.Core.vtkRenderWindow.newInstance();
const renderer = vtk.Rendering.Core.vtkRenderer.newInstance();
renderWindow.addRenderer(renderer);
//webGL/opengl impl
const openGLRenderWindow = vtk.Rendering.OpenGL.vtkRenderWindow.newInstance();
openGLRenderWindow.setContainer(container);
openGLRenderWindow.setSize(1000,1000);
renderWindow.addView(openGLRenderWindow);
//Interactor
const interactor = vtk.Rendering.Core.vtkRenderWindowInteractor.newInstance();
interactor.setView(openGLRenderWindow);
interactor.initialize();
interactor.bindEvents(container);
//Interactor style
const trackball = vtk.Interaction.Style.vtkInteractorStyleTrackballCamera.newInstance();
interactor.setInteractorStyle(trackball);
//disable_shortcuts
let interactorstyle = vtk.Interaction.Style.vtkInteractorStyleManipulator.newInstance();
interactorstyle.handleKeyPress = (callData) => {
const rwi = model.interactor;
let ac = null;
switch (callData.key) {
case 'r':
case 'R':
//callData.pokedRenderer.resetCamera();
//rwi.render();
break;
case 'w':
case 'W':
// ac = callData.pokedRenderer.getActors();
// ac.forEach((anActor) => {
// anActor.getProperty().setRepresentationToWireframe();
// });
//rwi.render();
// break;
break;
case 's':
case 'S':
// ac = callData.pokedRenderer.getActors();
// ac.forEach((anActor) => {
// anActor.getProperty().setRepresentationToSurface();
// });
//rwi.render();
break;
case 'v':
case 'V':
// ac = callData.pokedRenderer.getActors();
// ac.forEach((anActor) => {
// anActor.getProperty().setRepresentationToPoints();
// });
//rwi.render();
break;
default:
break;
}
};
//fullScreenRenderer.getInteractor().setInteractorStyle(interactorstyle);
//Pipeline
const cone = vtk.Filters.Sources.vtkConeSource.newInstance();
const actor = vtk.Rendering.Core.vtkActor.newInstance();
const mapper= vtk.Rendering.Core.vtkMapper.newInstance();
actor.setMapper(mapper);
mapper.setInputConnection(cone.getOutputPort());
renderer.addActor(actor);
//const LUT = vtk.Common.Core.vtkLookUpTable.newInstance();
//Render
renderer.resetCamera();
renderWindow.render();
我不知道js,但是C++我必须覆盖交互风格的交互类,我需要摆脱这些加速器。
例如,为了摆脱 vtkInteractorStyleTrackballCamera 的加速器,我覆盖了这个类,并重写了 OnKeyPress 处理程序。
下面是一个示例实现。
您需要创建自定义交互器样式才能实现此目的。 通过覆盖"onKeyPress(("函数来子类化交互器样式并处理按键事件,并且不转发按键事件。
如果需要转发事件,请调用父类"onKeyPress(("函数。
这里分享的代码是C++的,你可以将其转换为javascript。
// Creating the custom interaction style
class CustomInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static CustomInteractorStyle* New();
vtkTypeMacro(CustomInteractorStyle, vtkInteractorStyleTrackballCamera);
// Override onKeyPress Function
virtual void OnKeyPress() override
{
vtkRenderWindowInteractor* renderWindowInteractor = this->Interactor;
switch (rwi->GetKeySym())
{
case "w":
{
// Handle the event on 'w' key press
break;
}
case "s":
{
// Handle the event on 's' key press
break;
}
case "v":
{
// Handle the event on 'v' key press
break;
}
case "r":
{
// Handle the event on 'r' key press
break;
}
default:
break;
}
// If you still want to forward the key press events
// After handling the events. this would be like addition
// Include the below statement
// vtkInteractorStyleTrackballCamera::OnKeyPress();
}
};
vtkStandardNewMacro(CustomInteractorStyle);
要让 VTK (9.0( 在内部停止处理按键,似乎需要覆盖 OnChar(( 虚拟函数,而不是 OnKeyPress。
例如:
// Creating the custom interaction style
class CustomInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static CustomInteractorStyle* New();
vtkTypeMacro(CustomInteractorStyle, vtkInteractorStyleTrackballCamera);
// Override onChar Function
virtual void OnChar() override
{
vtkRenderWindowInteractor* renderWindowInteractor = this->Interactor;
//Disable vtk processing of 'e' press
if(ch != 'e')
{
vtkInteractorStyle::OnKeyPress();
}
}
};
vtkStandardNewMacro(CustomInteractorStyle);
相关文章:
- Qt VTK交互风格的信号到小部件
- 嵌入方指针压缩已禁用
- 函数何时会在c++中包含stack_Unwind_Resume调用
- Python中的for循环与C++有何不同
- clang格式:禁用排序包含
- 如何在C++中找到active directory中禁用和锁定的窗口帐户
- 如何在C++生成器中禁用"使用调试.dcus"
- 如何在GTK程序运行时禁用屏幕保护程序/电源管理/屏幕消隐
- 如何禁用 CPU 的无序执行
- 基类中的默认析构函数禁用子类中的移动构造函数(如果有成员)
- 在C++中释放内存期间,迭代器与指针有何不同
- 如何禁用VTK的热键
- 在C++中禁用宏中的逗号
- 禁用自动捕获 Googletest 单元测试中的C++异常
- 在VS Code中编译C / C ++时如何禁用自动创建EXE文件?
- QVTKWidget在VTK 8.1中已弃用,并将在未来的版本中删除
- 如何使用 CLANG 禁用格式安全错误?
- 如果存在从"双精度"到"T"的转换,则禁用构造函数
- 如何在 vtk Poly 数据上进行布尔运算?
- VTK:在vtkCaptionWidget中禁用锚点拾取/拖动