VTK修炼之道4_Win32控制台项目
生活随笔
收集整理的這篇文章主要介紹了
VTK修炼之道4_Win32控制台项目
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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.類的實(shí)現(xiàn)
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.主調(diào)函數(shù)
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.運(yùn)行結(jié)果
總結(jié)
以上是生活随笔為你收集整理的VTK修炼之道4_Win32控制台项目的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 『飞秋』关于ASP.NET MVC+Re
- 下一篇: 【飞秋】OR层代码组织介绍