zoukankan      html  css  js  c++  java
  • VTK Win32控制台项目

    1.类的定义

    myVTKapp.h

     1 #include "windows.h"
     2 #include "vtkConeSource.h"
     3 #include "vtkPolyDataMapper.h"
     4 #include "vtkRenderWindow.h"
     5 #include "vtkRenderWindowInteractor.h"
     6 #include "vtkRenderer.h"
     7  
     8 static HANDLE hinst;
     9 long FAR PASCAL WndProc (HWND,UINT,UINT,LONG);
    10  
    11 class myVTKapp
    12 {
    13 public:
    14     myVTKapp(HWND parent);
    15     ~myVTKapp();
    16 private:
    17     vtkRenderWindow *renWin;
    18     vtkRenderer *renderer;
    19     vtkRenderWindowInteractor *iren;
    20     vtkConeSource *cone;
    21     vtkPolyDataMapper *coneMapper;
    22     vtkActor *coneActor;
    23 };

    2.类的实现

    myVTKapp.ccp

     1 #include <vtkAutoInit.h>
     2 VTK_MODULE_INIT(vtkRenderingOpenGL);
     3 ///
     4 #include "myVTKcpp.h"
     5  
     6 myVTKapp::myVTKapp(HWND hwnd)
     7 {
     8     // we create the basic parts of a pipeline and connect them
     9     this->renderer = vtkRenderer::New();
    10     this->renWin = vtkRenderWindow::New();
    11     this->renWin->AddRenderer(this->renderer);
    12  
    13     // setup the parent window
    14     this->renWin->SetParentId(hwnd);
    15     this->iren = vtkRenderWindowInteractor::New();
    16     this->iren->SetRenderWindow(this->renWin);
    17  
    18     //Data
    19     this->cone = vtkConeSource::New();
    20     this->cone->SetHeight(4.0);
    21     this->cone->SetRadius(2.0);
    22     this->cone->SetResolution( 20 );//???
    23  
    24     this->coneMapper = vtkPolyDataMapper::New();
    25     this->coneMapper->SetInputConnection(this->cone->GetOutputPort());
    26     this->coneActor = vtkActor::New();
    27     this->coneActor->SetMapper(this->coneMapper);
    28     
    29     this->renderer->AddActor(this->coneActor);
    30     this->renderer->SetBackground(0.2,0.3,0.4);
    31     this->renWin->SetSize(800,800);
    32  
    33     //finally we start the interactor so that event will be handle
    34     this->renWin->Render();
    35 }
    36 myVTKapp::~myVTKapp()
    37 {
    38     renWin->Delete();
    39     renderer->Delete();
    40     iren->Delete();
    41  
    42     cone->Delete();
    43     coneMapper->Delete();
    44     coneActor->Delete();
    45  
    46 }

    3.主调函数

    myVTKapp.cpp

     1 //WinMain
     2 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
     3                     LPSTR lpszCmdParam, int nCmdShow)
     4 {
     5     static char szAppName[] = "Win32Cone";
     6     HWND hwnd ;
     7     MSG msg ;
     8     WNDCLASS wndclass ;
     9     if (!hPrevInstance)
    10     {
    11         wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    12         wndclass.lpfnWndProc = WndProc ;
    13         wndclass.cbClsExtra = 0 ;
    14         wndclass.cbWndExtra = 0 ;
    15         wndclass.hInstance = hInstance;
    16         wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
    17         wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
    18         wndclass.lpszMenuName = NULL;
    19         wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    20         wndclass.lpszClassName = szAppName;
    21         RegisterClass (&wndclass);
    22     }
    23     hinst = hInstance;
    24     hwnd = CreateWindow (    szAppName,
    25                             "Draw Window",
    26                             WS_OVERLAPPEDWINDOW,
    27                             CW_USEDEFAULT,
    28                             CW_USEDEFAULT,
    29                             800,
    30                             800,
    31                             NULL,
    32                             NULL,
    33                             hInstance,
    34                             NULL);
    35     ShowWindow (hwnd, nCmdShow);
    36     UpdateWindow (hwnd);
    37     while (GetMessage (&msg, NULL, 0, 0))
    38         {
    39             TranslateMessage (&msg);
    40             DispatchMessage (&msg);
    41         }
    42     return msg.wParam;
    43 }
    44  
    45 long FAR PASCAL WndProc (HWND hwnd, UINT message,
    46                          UINT wParam, LONG lParam)
    47 {
    48     static HWND ewin;
    49     static myVTKapp *theVTKApp;
    50     switch (message)
    51     {
    52         case WM_CREATE:
    53         {
    54             ewin = CreateWindow("button","Exit",
    55                                 WS_CHILD | WS_VISIBLE | SS_CENTER,
    56                                 0,800,800,60,
    57                                 hwnd,(HMENU)2,
    58                                 (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),
    59                                 NULL);
    60             theVTKApp = new myVTKapp(hwnd);
    61             return 0;
    62         }
    63         case WM_COMMAND:
    64             switch (wParam)
    65             {
    66                 case 2:
    67                     PostQuitMessage (0);
    68                     if (theVTKApp)
    69                     {
    70                         delete theVTKApp;
    71                         theVTKApp = NULL;
    72                     }
    73                 break;
    74             }

    4.运行结果

  • 相关阅读:
    我们可以用JAX-WS轻松实现JAVA平台与其他编程环境(.net等)的互操作
    Eclipse 枚举类报错
    eclipse 遇关键字enum编译问题解决
    接口测试框架开发(二):extentreports报告中文乱码问题
    接口测试框架开发(一):rest-Assured_接口返回数据验证
    使用ant运行testng的testng.xml并且使用testng-results.xsl美化结果
    TestNG简单的学习-TestNG运行
    ExtentReports 结合 TestNg 生成自动化 html 报告 (支持多 suite)
    TestNG+ReportNG+Maven优化测试报告
    IDEA+MAVEN+testNG(reportNG)
  • 原文地址:https://www.cnblogs.com/ybqjymy/p/14240909.html
Copyright © 2011-2022 走看看