#include #include using namespace std; #include #include #include #include #include #include // VTK APPLICATION CLASS // - Change the Render method to what ever way you want //---------------------------------- class MyVTKApp { public: MyVTKApp(HWND&, int, int); ~MyVTKApp(); virtual void Render(); private: vtkRenderWindow *m_pRenWin; vtkRenderer *m_pRenderer; vtkRenderWindowInteractor *m_pIren; vtkConeSource *m_pCone; vtkPolyDataMapper *m_pConeMapper; vtkActor *m_pConeActor; }; MyVTKApp::MyVTKApp(HWND& hwnd, int width, int height) { m_pRenderer = vtkRenderer::New(); m_pIren = vtkRenderWindowInteractor::New(); m_pRenderer->DebugOff(); m_pRenderer->SetBackground( 0, 0, 0); m_pRenWin = vtkRenderWindow::New(); m_pRenWin->SetParentId( hwnd ); m_pRenWin->SetSize(width,height); m_pRenWin->AddRenderer( m_pRenderer ); m_pIren->SetRenderWindow( m_pRenWin ); m_pCone = vtkConeSource::New(); m_pCone->SetHeight( 3 ); m_pCone->SetRadius( 1 ); m_pCone->SetResolution( 10 ); m_pConeMapper = vtkPolyDataMapper::New(); m_pConeMapper->SetInput( m_pCone->GetOutput() ); m_pConeActor = vtkActor::New(); m_pConeActor->SetMapper( m_pConeMapper ); m_pRenderer->AddActor( m_pConeActor ); } MyVTKApp::~MyVTKApp() { m_pRenWin->Delete(); m_pRenderer->Delete(); m_pIren->Delete(); } void MyVTKApp::Render(void) { m_pRenWin->Render(); } // GLOBAL VARIABLE //----------------------------- MyVTKApp *g_pVTKApp = NULL; // FUNCTION PROTOTYPES //----------------------------- void PreRenderSetup(void); //Setup whatever you want before the rendering actually takes place...good way to test using CgFX files? LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ); //Main Message Processor for the main window INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInst2, LPSTR str, INT nCmdShow ); //Entry function into program // FUNCTION IMPLEMENTATION //----------------------------- void PreRenderSetup(void) { } //----------------------------- LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_DESTROY: PostQuitMessage( 0 ); return 0; delete g_pVTKApp; break; case WM_PAINT: PreRenderSetup(); if( g_pVTKApp ) g_pVTKApp->Render(); break; } return DefWindowProc( hWnd, msg, wParam, lParam ); } //----------------------------- INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpstr, INT nCmdShow ) { // Register the window class. WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "VTK for Windows", NULL }; RegisterClassEx( &wc ); printf("registered window class\n"); // Create the application's window. HWND hWnd = CreateWindow( "VTK for Windows", "VTK : VTK_1", //The first string is the window class name of the window class we want //to instantiate, the next part is what actually goes up on the title bar WS_OVERLAPPEDWINDOW, 100, 100, 1024, 768, //change 1024 and 768 values to desired width and height GetDesktopWindow(), NULL, wc.hInstance, NULL ); printf("looping\n"); //make the instance of the application g_pVTKApp = new MyVTKApp( hWnd , 1024, 768); //now the window has to actually be shown,...update will force it to pass the WM_PAINT message (i think) ShowWindow( hWnd, nCmdShow); UpdateWindow( hWnd ); // The message loop. MSG msg; while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } } // end WinMain