[vtkusers] Help On Win32

brylee at fumbo.com brylee at fumbo.com
Tue Jun 8 15:20:24 EDT 2004


Hello Every body, I Wonder if is there any one that can help me on this,

Im trying to implement a sub fuction under win32 prog, but im having problems 
on defining properly the prototypes and functions to transfer the vtk functions 
and properties, my code is attached

the problem is with the function

BOOL CALLBACK Proc1 (HWND hwnd, char fc[])
 
Thanks
Lee
//----
/*=========================================================================

  
  
=========================================================================*/
//

// first include the required header files for the vtk classes we are using

// Privimitive libraries
#include "vtkConeSource.h"
#include "vtkSphereSource.h"
#include "vtkCylinderSource.h"

// Mapper libraries
#include "vtkPolyDataMapper.h"

//Actor Libraries
#include "vtkActor.h"

//Window, Render and Interactor Libraries
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"

// Other Vtk Libraries
#include "vtkCamera.h"
#include "vtkWindowToImageFilter.h" //write to Images
#include "vtkJPEGWriter.h" //Images to Jpeg Files


static HANDLE hinst; 


long FAR PASCAL WndProc(HWND, UINT, UINT, LONG);

// define the vtk part as a simple c++ class 
class myVTKApp   
{
public: 
  myVTKApp(HWND parent);     
  ~myVTKApp();
private:

		// *** Window and Window Interactors ***
  vtkRenderWindow *renWin;
  vtkRenderer *ren1;
  vtkRenderWindowInteractor *iren;
	// *** Primitives ***
  vtkConeSource *cone;
  vtkCylinderSource *cylinder;
  vtkSphereSource *sphere;
  vtkCylinderSource *cylengines;
  // *** Mappers ***
  vtkPolyDataMapper *coneMapper;
  vtkPolyDataMapper *cylinderMapper;
  vtkPolyDataMapper *sphereMapper;
  vtkPolyDataMapper *cylenginesMapper;
  // *** Actors ***
  vtkActor *coneActor;
  vtkActor *cylinderActor;
  vtkActor *sphereActor;
  vtkActor *sphereActor2;
  vtkActor *cylenginesActor;
  vtkActor *cylenginesActor2;

  // *** Writers ***
  vtkWindowToImageFilter *w2i;
  vtkJPEGWriter *jpegw;
  	

};

// BOOL    CALLBACK Proc1 (HWND, vtkRenderer) ;
//BOOL    CALLBACK Proc1 (HWND, vtkRenderer) ;
BOOL    CALLBACK Proc1 (HWND, char fc[]) ;

LRESULT CALLBACK HelloWndProc  (HWND, UINT, WPARAM, LPARAM) ;

int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPSTR lpszCmdParam, int nCmdShow) 
{
  static char szAppName[] = "Win32Program2";
  //static char var1[5] = "ren1";
  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,
                        500,
                        480,
                        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;
  static myVTKApp *dataproc;

  switch (message)
    {
    case WM_CREATE:
      {
		  	//	Proc1 (hwnd);

      return 0;

      }
    case WM_LBUTTONDOWN:
	{

		ewin = CreateWindow("button","Exit",
                          WS_CHILD | WS_VISIBLE | SS_CENTER,                   
                          0,400,500,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;
        }
      return 0;
      
    case WM_DESTROY:
      PostQuitMessage (0);
      if (theVTKApp)
        {
        delete theVTKApp;
        theVTKApp = NULL;
        }
      return 0; 
    }
  
  return DefWindowProc (hwnd, message, wParam, lParam);
}

myVTKApp::myVTKApp(HWND hwnd) 
{
  
  // ************************** R-Window, Render & Interactor Ini 
**************************
	
	this->renWin = vtkRenderWindow::New();
	this->iren = vtkRenderWindowInteractor::New();
	this->ren1 = vtkRenderer::New();

	//Seting the pipeline
	this->renWin->AddRenderer(this->ren1);
	this->iren->SetRenderWindow(this->renWin);

  // setup the parent window in Win32
	this->renWin->SetParentId(hwnd);


  // ************************** R-Window, Render & Interactor End 
**************************

  // ************************** Primitives Ini **************************

  // defining the first source (Cone)
	
	this->cone = vtkConeSource::New();
		this->cone->SetHeight( 2.0 );
		this->cone->SetRadius( 1.0 );
		this->cone->SetResolution( 100 );
  
  // defining the second source (cylinder)
	this->cylinder = vtkCylinderSource::New();
		this->cylinder->SetHeight( 4.0 );
		this->cylinder->SetRadius( 1.0 );
		this->cylinder->SetResolution(100);

  // defining the trird source (Sphere)
	this->sphere = vtkSphereSource::New();
		this->sphere->SetPhiResolution( 10);
		this->sphere->SetRadius( 0.5 );

  //defining engines
	this->cylengines = vtkCylinderSource::New();
		this->cylengines->SetHeight( 1.5 );
		this->cylengines->SetRadius( 0.5 );
		this->cylengines->SetResolution(100);

  // ************************** Primitives End **************************


  // ************************** Mappers Ini **************************

  //figure 1 Cone to map the polygonal data into graphics primitives

	this->coneMapper = vtkPolyDataMapper::New();
		this->coneMapper->SetInput(this->cone->GetOutput() );

  //figure 2 cylinder to map the polygonal data into graphics primitives

	this->cylinderMapper = vtkPolyDataMapper::New();
		this->cylinderMapper->SetInput( this->cylinder->GetOutput() );


  //figure 3 Sphere to map the polygonal data into graphics primitives

	this->sphereMapper = vtkPolyDataMapper::New();
		this->sphereMapper->SetInput( this->sphere->GetOutput() );

  //figure 4 cylinder engines to map the polygonal data into graphics primitives

	this->cylenginesMapper = vtkPolyDataMapper::New();
		this->cylenginesMapper->SetInput( this->cylengines->GetOutput
() );


  // ************************** Mappers End **************************

  // ************************** Actors Ini **************************

	this->coneActor = vtkActor::New();
		this->coneActor->SetMapper(this->coneMapper );
		this->coneActor->RotateX(0.0);
		this->coneActor->RotateY(0.0);
		this->coneActor->RotateZ(90.0);
		this->coneActor ->SetPosition(0, 3, 0);

  // Second Actor of the Cylinder Which orchestrates rendering of
  // the mapper's graphics primitives

	this->cylinderActor = vtkActor::New(); 
		this->cylinderActor ->SetMapper( this->cylinderMapper );

  // third Actor the Sphere Which orchestrates rendering of
  // the mapper's graphics primitives

	this->sphereActor = vtkActor::New();
		this->sphereActor ->SetMapper( this->sphereMapper );
		this->sphereActor ->SetPosition(1, -1, 0);

	this->sphereActor2 = vtkActor::New();
		this->sphereActor2 ->SetMapper( this->sphereMapper );
		this->sphereActor2 ->SetPosition(-1, -1, 0);

  // Engines Actor of Class Cylinder Which orchestrates rendering of // the 
mapper's graphics primitives

	this->cylenginesActor = vtkActor::New();
		this->cylenginesActor ->SetMapper( this->cylenginesMapper );
		this->cylenginesActor ->SetPosition(1, -1.75, 0);

	this->cylenginesActor2 = vtkActor::New();
		this->cylenginesActor2 ->SetMapper( this->cylenginesMapper );
		this->cylenginesActor2 ->SetPosition(-1, -1.75, 0);

  // ************************** Actors End **************************

  // ************************** Render Ini **************************
    
		this->ren1->AddActor(this->coneActor );
		this->ren1->AddActor(this->sphereActor );
		this->ren1->AddActor(this->sphereActor2 );
		this->ren1->AddActor(this->cylinderActor );
		this->ren1->AddActor(this->cylenginesActor );
	//--->>>	this->ren1->AddActor(this->cylenginesActor2 );
		this->ren1->SetBackground( 0.2, 0.3, 0.5 );
		//this->ren1->SetBackground(0.2,0.4,0.3);
		//this->renWin->SetSize(600,400);
		this->renWin->SetSize( 500, 400 );  //size of the window
		this->ren1->GetRenderWindow();

  // ************************** Render End ************************** 

char *fc[10];
  fc[1]="ren1";
/*
  MessageBox (hwnd, TEXT ("OK to close window?"),
                                  TEXT (argv[1]), 
                                  MB_ICONQUESTION | MB_OKCANCEL); 
*/

Proc1(hwnd, fc[1]);

  // Finally we start the interactor so that event will be handled

  this->renWin->Render();
    
}

myVTKApp::~myVTKApp()
{
    renWin->Delete();
    ren1->Delete();
    iren->Delete();
    cone->Delete();
    coneMapper->Delete();
    coneActor->Delete();
}

BOOL CALLBACK Proc1 (HWND hwnd, char fc[])
{

//--->>>	this->ren1->AddActor(this->cylenginesActor2 ); help here

     return TRUE ;
}



//----



More information about the vtkusers mailing list