[vtkusers] Help on win32 prog - error

brylee at fumbo.com brylee at fumbo.com
Thu Jun 17 11:49:13 EDT 2004


This is my code and I am migrating the financial example from the vtk book 
from regular C++ to winprog32, and im currently getting errors :

"  this->dataSet1->SetPoints(newPts); "

that Setpoints are not a member of dataset, but the same code works for reg 
c++, any sugs.


thanks
Bryan Lee



//- Ini
/*=========================================================================

  this->dataSet1->SetPoints(newPts);



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

/*  header files for the vtk classes  */

// Privimitive libraries

#include "vtkAxes.h"
#include "vtkContourFilter.h"
#include "vtkDataSet.h"
#include "vtkFloatArray.h"
#include "vtkGaussianSplatter.h"
#include "vtkImageData.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkTubeFilter.h"
#include "vtkUnstructuredGrid.h"

// Mapper libraries
#include "vtkPolyDataMapper.h"

//Actor Libraries
#include "vtkActor.h"
#include "vtkProperty.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

/*  header files for the vtk classes  end */

/*  Definition of Prototypes and win32 instances  */

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();
  //ReadFinancialData(const char *x, const char *y, const char *z, const char 
*s);
static int ParseFile(FILE *file, const char *tag, float *data);
private:

		// *** Window and Window Interactors ***
	vtkRenderWindow *renWin;
	vtkRenderer *renderer;
	vtkRenderWindowInteractor *iren;
	// *** Primitives ***
	//- Obj 1
	vtkDataSet *dataSet;
	vtkDataSet *dataSet1;
	vtkGaussianSplatter *popSplatter;
	vtkContourFilter *popSurface;

	//- Obj 2
	vtkGaussianSplatter *lateSplatter;
	vtkContourFilter *lateSurface;

	// - Obj 3 Axes
	vtkAxes *axes;

	// - Obj 3 Axes contour thick axes
	vtkTubeFilter *axesTubes;

	vtkFloatArray *newScalars;
	vtkPoints *newPts;
	
	vtkUnstructuredGrid *dataSetU; //* dataSet
	//vtkImageData
	//vtkPointData

  // *** Mappers ***
	vtkPolyDataMapper *popMapper;
	vtkPolyDataMapper *lateMapper;
    vtkPolyDataMapper *axesMapper;
  // *** Actors ***
  vtkActor *popActor;
  vtkActor *lateActor;
  vtkActor *axesActor;

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

};

int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPSTR lpszCmdParam, int nCmdShow)
{
  static char szAppName[] = "Win32Financial";
  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;

  switch (message)
    {
    case WM_CREATE:
      {
      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->renderer = vtkRenderer::New();

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

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

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

  double bounds[6];
  //dataSet *dataSet1;

//-ini readfinancial Data
//ReadFinancialData
("MONTHLY_PAYMENT","INTEREST_RATE","LOAN_AMOUNT","TIME_LATE");
//ReadFinancialData(const char *x, const char *y, const char *z, const char 
*s);

	const char *x;
	const char *y;
	const char *z;
	const char *s;
	x ="MONTHLY_PAYMENT";
	y ="INTEREST_RATE";
	z ="LOAN_AMOUNT";
	s ="TIME_LATE";
	
	float xyz[3];
	FILE *file;
	int i, npts;
	char tag[80];
  
  // const char * temp=getenv("VTK_DATA_ROOT");
  //  char filename[2048];
  const char *filename;
  filename ="financial.txt";

// Reading the file if yes read it if not show can not read
  if ( (file = fopen(filename,"r")) == 0 )
    {
    cerr << "ERROR: Can't read file: " << filename << "\n";
//    return NULL;
    }
  
  fscanf (file, "%s %d", tag, &npts); // read number of points

  //End
  this ->dataSet1 = vtkUnstructuredGrid::New();
  //dataSet1 = vtkUnstructuredGrid::New();
  float *xV = new float[npts];
  float *yV = new float[npts];
  float *zV = new float[npts];
  float *sV = new float[npts];

  if ( ! ParseFile(file, x, xV) || ! ParseFile(file, y, yV) ||
  ! ParseFile(file, z, zV) || ! ParseFile(file, s, sV) )
    {
    cerr << "Couldn't read data!\n";
    delete [] xV;
    delete [] yV;
    delete [] zV;
    delete [] sV;
    dataSet->Delete();
//    return NULL;
    }

	this->newPts = vtkPoints::New();
	this->newScalars = vtkFloatArray::New();

  for (i=0; i<npts; i++)
    {
    xyz[0] = xV[i]; xyz[1] = yV[i]; xyz[2] = zV[i]; 
    this->newPts->InsertPoint(i, xyz);
    this->newScalars->InsertValue(i, sV[i]);
    }

  this->dataSet1->SetPoints(newPts);
  this->dataSet1->GetPointData()->SetScalars(this->newScalars);

  this->newPts->Delete(); //reference counted - it's okay
  this->newScalars->Delete();

  // return dataSet1;
//- end readfinancial Data
  // dataSet = vtkDataSet::New();
  // read data
//	this->dataSet = (vtkDataSet *)ReadFinancialData
("MONTHLY_PAYMENT","INTEREST_RATE","LOAN_AMOUNT","TIME_LATE");
  this->dataSet=dataSet1;

  //this->if ( ! dataSet ) exit(0);


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

  // defining the first source 
	
	 // construct pipeline for original population
  this->popSplatter = vtkGaussianSplatter::New();
    this->popSplatter->SetInput(this->dataSet);
    this->popSplatter->SetSampleDimensions(50,50,50);
    this->popSplatter->SetRadius(0.05);
    this->popSplatter->ScalarWarpingOff();

  this->popSurface = vtkContourFilter::New();
    this->popSurface->SetInput(this->popSplatter->GetOutput());
    this->popSurface->SetValue(0,0.01);

  // defining the second source 
  this->lateSplatter = vtkGaussianSplatter::New();
    this->lateSplatter->SetInput(this->dataSet);
    this->lateSplatter->SetSampleDimensions(50,50,50);
    this->lateSplatter->SetRadius(0.05);
    this->lateSplatter->SetScaleFactor(0.005);

  this->lateSurface = vtkContourFilter::New();
    this->lateSurface->SetInput(this->lateSplatter->GetOutput());
    this->lateSurface->SetValue(0,0.01);

  // defining the trird source (Axes)

	this->axes = vtkAxes::New();
    this->axes->SetOrigin(bounds[0], bounds[2], bounds[4]);
    this->axes->SetScaleFactor(popSplatter->GetOutput()->GetLength()/5);

  this->axesTubes = vtkTubeFilter::New();
    this->axesTubes->SetInput(this->axes->GetOutput());
    this->axesTubes->SetRadius(axes->GetScaleFactor()/25.0);
    this->axesTubes->SetNumberOfSides(6);

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


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

  //figure 1 map the polygonal data into graphics primitives

	this->popMapper = vtkPolyDataMapper::New();
		this->popMapper->SetInput(this->popSurface->GetOutput());
		this->popMapper->ScalarVisibilityOff();

  //figure 2 
	this->lateMapper = vtkPolyDataMapper::New();
		this->lateMapper->SetInput(this->lateSurface->GetOutput());
		this->lateMapper->ScalarVisibilityOff();

  //figure 3 
	this->axesMapper = vtkPolyDataMapper::New();
		this->axesMapper->SetInput(this->axesTubes->GetOutput());


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

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

	// First Actor 
	this->popActor = vtkActor::New();
		this->popActor->SetMapper(this->popMapper);
		this->popActor->GetProperty()->SetOpacity(0.3);
		this->popActor->GetProperty()->SetColor(.9,.9,.9);
  // Second Actor 

	this->lateActor = vtkActor::New();
		this->lateActor->SetMapper(this->lateMapper);
		this->lateActor->GetProperty()->SetColor(1.0,0.0,0.0);
	
	// third Actor 

	this->axesActor = vtkActor::New();
		this->axesActor->SetMapper(this->axesMapper);

// create axes p1
	this->popSplatter->Update();
//	this->popSplatter->GetOutput()->GetBounds(bounds);

  


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


  // ************************** Render Ini **************************

		this->renderer->AddActor(this->axesActor );
		this->renderer->AddActor(this->lateActor );
		this->renderer->AddActor(this->popActor );
		this->renderer->SetBackground (1,1,1); //( 0.2, 0.3, 0.5 );
		this->renWin->SetSize( 500, 400 );  //size of the window
		//this->ren1->GetRenderWindow();

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

  // ************************ Image Writer Ini ************************
  // ************************ Image Writer Ini ************************


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

	// iren->Initialize();

  this->renWin->Render();

  // iren->Start();
    
}

myVTKApp::~myVTKApp()
{
   renderer->Delete();
  renWin->Delete();
  iren->Delete();
  popSplatter->Delete();
  popSurface->Delete();
  popMapper->Delete();
  popActor->Delete();
  lateSplatter->Delete();
  lateSurface->Delete();
  lateMapper->Delete();
  lateActor->Delete();
  axes->Delete();
  axesTubes->Delete();
  axesMapper->Delete();
  axesActor->Delete();
  dataSet->Delete();
}


/*
myVTKApp::ReadFinancialData(const char *x, const char *y, const char *z, const 
char *s)
{ 	// -ReadFinancialData
("MONTHLY_PAYMENT","INTEREST_RATE","LOAN_AMOUNT","TIME_LATE");

  float xyz[3];
  FILE *file;
  int i, npts;
  char tag[80];
  
  // const char * temp=getenv("VTK_DATA_ROOT");
  //  char filename[2048];
  const char *filename;
  filename ="financial.txt";
// Reading the file if yes read it if not show can not read
  if ( (file = fopen(filename,"r")) == 0 )
    {
    cerr << "ERROR: Can't read file: " << filename << "\n";
    return NULL;
    }
  
  fscanf (file, "%s %d", tag, &npts); // read number of points

  //End
  this ->dataSet1 = vtkUnstructuredGrid::New();
  //dataSet1 = vtkUnstructuredGrid::New();
  float *xV = new float[npts];
  float *yV = new float[npts];
  float *zV = new float[npts];
  float *sV = new float[npts];

  if ( ! ParseFile(file, x, xV) || ! ParseFile(file, y, yV) ||
  ! ParseFile(file, z, zV) || ! ParseFile(file, s, sV) )
    {
    cerr << "Couldn't read data!\n";
    delete [] xV;
    delete [] yV;
    delete [] zV;
    delete [] sV;
    dataSet->Delete();
    return NULL;
    }

	this->newPts = vtkPoints::New();
	this->newScalars = vtkFloatArray::New();

  for (i=0; i<npts; i++)
    {
    xyz[0] = xV[i]; xyz[1] = yV[i]; xyz[2] = zV[i]; 
    this->newPts->InsertPoint(i, xyz);
    this->newScalars->InsertValue(i, sV[i]);
    }

  this->dataSet1->SetPoints(newPts);
  this->dataSet1->GetPointData()->SetScalars(this->newScalars);

  this->newPts->Delete(); //reference counted - it's okay
  this->newScalars->Delete();

  return dataSet1;

}
*/
myVTKApp::ParseFile(FILE *file, const char *tag, float *data)
{
 char tag[80];
  int i, npts, readData=0;
  float min=VTK_LARGE_FLOAT;
  float max=(-VTK_LARGE_FLOAT);

  if ( file == NULL || label == NULL ) return 0;

  rewind(file);
  
  fscanf(file, "%s %d", tag, &npts);
  
  while ( !readData && fscanf(file, "%s", tag) == 1 )
    {
    if ( ! strcmp(tag,label) )
      {
      readData = 1;
      for (i=0; i<npts; i++) 
        {
        fscanf(file, "%f", data+i);
        if ( data[i] < min ) min = data[i];
        if ( data[i] > min ) max = data[i];
        }
      // normalize data
      for (i=0; i<npts; i++) data[i] = min + data[i]/(max-min);
      }
    else
      {
      for (i=0; i<npts; i++) fscanf(file, "%*f");
      }
    }

  if ( ! readData ) return 0;
  else return 1;

}




More information about the vtkusers mailing list