欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

VTK修炼之道4_Win32控制台项目

发布时间:2025/3/15 编程问答 32 豆豆
生活随笔 收集整理的这篇文章主要介绍了 VTK修炼之道4_Win32控制台项目 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1.类的定义

myVTKapp.h

#include "windows.h" #include "vtkConeSource.h" #include "vtkPolyDataMapper.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkRenderer.h"static HANDLE hinst; long FAR PASCAL WndProc (HWND,UINT,UINT,LONG);class myVTKapp { public:myVTKapp(HWND parent);~myVTKapp(); private:vtkRenderWindow *renWin;vtkRenderer *renderer;vtkRenderWindowInteractor *iren;vtkConeSource *cone;vtkPolyDataMapper *coneMapper;vtkActor *coneActor; };

2.类的实现

myVTKapp.ccp #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL); /// #include "myVTKcpp.h"myVTKapp::myVTKapp(HWND hwnd) {// we create the basic parts of a pipeline and connect themthis->renderer = vtkRenderer::New();this->renWin = vtkRenderWindow::New();this->renWin->AddRenderer(this->renderer);// setup the parent windowthis->renWin->SetParentId(hwnd);this->iren = vtkRenderWindowInteractor::New();this->iren->SetRenderWindow(this->renWin);//Datathis->cone = vtkConeSource::New();this->cone->SetHeight(4.0);this->cone->SetRadius(2.0);this->cone->SetResolution( 20 );//???this->coneMapper = vtkPolyDataMapper::New();this->coneMapper->SetInputConnection(this->cone->GetOutputPort());this->coneActor = vtkActor::New();this->coneActor->SetMapper(this->coneMapper);this->renderer->AddActor(this->coneActor);this->renderer->SetBackground(0.2,0.3,0.4);this->renWin->SetSize(800,800);//finally we start the interactor so that event will be handlethis->renWin->Render(); } myVTKapp::~myVTKapp() {renWin->Delete();renderer->Delete();iren->Delete();cone->Delete();coneMapper->Delete();coneActor->Delete();}

3.主调函数

myVTKapp.cpp
/// //WinMain int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpszCmdParam, int nCmdShow) {static char szAppName[] = "Win32Cone";HWND hwnd ;MSG msg ;WNDCLASS wndclass ;if (!hPrevInstance){wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;wndclass.lpfnWndProc = WndProc ;wndclass.cbClsExtra = 0 ;wndclass.cbWndExtra = 0 ;wndclass.hInstance = hInstance;wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);wndclass.lpszMenuName = NULL;wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);wndclass.lpszClassName = szAppName;RegisterClass (&wndclass);}hinst = hInstance;hwnd = CreateWindow ( szAppName,"Draw Window",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,800,800,NULL,NULL,hInstance,NULL);ShowWindow (hwnd, nCmdShow);UpdateWindow (hwnd);while (GetMessage (&msg, NULL, 0, 0)){TranslateMessage (&msg);DispatchMessage (&msg);}return msg.wParam; }long FAR PASCAL WndProc (HWND hwnd, UINT message,UINT wParam, LONG lParam) {static HWND ewin;static myVTKapp *theVTKApp;switch (message){case WM_CREATE:{ewin = CreateWindow("button","Exit",WS_CHILD | WS_VISIBLE | SS_CENTER,0,800,800,60,hwnd,(HMENU)2,(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);theVTKApp = new myVTKapp(hwnd);return 0;}case WM_COMMAND:switch (wParam){case 2:PostQuitMessage (0);if (theVTKApp){delete theVTKApp;theVTKApp = NULL;}break;}

4.运行结果


总结

以上是生活随笔为你收集整理的VTK修炼之道4_Win32控制台项目的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。