首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >[图像处理][转载]VTK安装后的测试代码

[图像处理][转载]VTK安装后的测试代码

作者头像
云未归来
发布2025-07-18 15:42:51
发布2025-07-18 15:42:51
890
举报

#include "vtkConeSource.h" #include "vtkPolyDataMapper.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkCamera.h" #include "vtkActor.h" #include "vtkRenderer.h" #include "vtkCommand.h" #include "vtkBoxWidget.h" #include "vtkTransform.h" #include "vtkInteractorStyleTrackballCamera.h"

#include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL2); VTK_MODULE_INIT(vtkInteractionStyle); class vtkMyCallback : public vtkCommand { public: static vtkMyCallback* New() { return new vtkMyCallback; } void Execute(vtkObject* caller, unsigned long, void*) VTK_OVERRIDE { vtkTransform* t = vtkTransform::New(); vtkBoxWidget* widget = reinterpret_cast<vtkBoxWidget*>(caller); widget->GetTransform(t); widget->GetProp3D()->SetUserTransform(t); t->Delete(); } };

int main() {

vtkConeSource* cone = vtkConeSource::New(); cone->SetHeight(3.0); cone->SetRadius(1.0); cone->SetResolution(10); vtkPolyDataMapper* coneMapper = vtkPolyDataMapper::New(); coneMapper->SetInputConnection(cone->GetOutputPort());

vtkActor* coneActor = vtkActor::New(); coneActor->SetMapper(coneMapper);

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

vtkRenderWindow* renWin = vtkRenderWindow::New(); renWin->AddRenderer(ren1); renWin->SetSize(300, 300);

vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin);

vtkInteractorStyleTrackballCamera* style = vtkInteractorStyleTrackballCamera::New(); iren->SetInteractorStyle(style);

vtkBoxWidget* boxWidget = vtkBoxWidget::New(); boxWidget->SetInteractor(iren); boxWidget->SetPlaceFactor(1.25); boxWidget->SetProp3D(coneActor); boxWidget->PlaceWidget(); vtkMyCallback* callback = vtkMyCallback::New(); boxWidget->AddObserver(vtkCommand::InteractionEvent, callback);

boxWidget->On();

iren->Initialize(); iren->Start();

cone->Delete(); coneMapper->Delete(); coneActor->Delete(); callback->Delete(); boxWidget->Delete(); ren1->Delete(); renWin->Delete(); iren->Delete(); style->Delete();

return 0; }

结果显示:

参看:https://blog.csdn.net/GENGXINGGUANG/article/details/106820207

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-02-23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档