[vtkusers] Newbie question about VTK speed
Hughes, Mike
msh at cmrl.wustl.edu
Fri Jan 4 22:06:53 EST 2008
I've just started using VTK to do image processing. I wrote the program
below (Vol-r5) to test the frame rate for writing different images to the
screen of my computer (Dual dual-core Xeons with and VCQFX1500-PCIE-PB Nvidia
1500 video adapter running Ubuntu linux with working OpenGL drivers
installed).
When I run the program I get the following output:
$ ./Vol-r5
dt= 2.57 for: 180 frames
Where dt is the execution time to compute and display 180 frames.
This seems to be astoundingly slow for a machine with working OpenGL drivers
installed. I've explored the VTK class hierarchy and it seems that if OpenGL
is available it should be automatically used. I hope that I'm mistaken on
this.
Is there a way to display frames at a higher rate? I would ultmately like to
display 512x512 images (which takes about 9 sec with the program below).
Vol-r5.cpp listing....
#include "vtkImageWriter.h"
#include "vtkImageReader.h"
#include "vtkPointData.h"
#include "vtkRenderer.h"
//#include "vtkRenderWindow.h"
//#include <vtkXOpenGLRenderWindow.h>
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkStructuredPoints.h"
#include "vtkFloatArray.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkImageCast.h"
#include <time.h>
const float Pi=3.14159;
const int NumberOfFrames=180;
int main ()
{
float sp, z, y, x, s, dx,dy,scale;
int i, j, k, ii, kOffset, jOffset, offset,h;
int xSize=255;
int ySize=255;
int zSize=0;
clock_t start, stop;
dx=1.0/((double)xSize);
dy=1.0/((double)ySize);
vtkImageData *image = vtkImageData::New();
image->SetDimensions(xSize+1,ySize+1,zSize+1);
image->SetScalarTypeToFloat();
image->AllocateScalars();
float *ptr = static_cast<float*>(image->GetScalarPointer());
float *startptr;
startptr = ptr;
vtkImageViewer *viewer = vtkImageViewer::New();
viewer->SetInput(image);
viewer->SetColorWindow(20.0);
viewer->SetColorLevel(0.0);
start=clock();
for(scale=1.0,k=0;k<NumberOfFrames;k++,scale+=0.1)
{
ptr=startptr;
for(x=0.0,i=0;i<xSize+1;i++,x+=dx)
for(y=0.0,j=0;j<ySize+1;j++,y+=dy)
*ptr++ = scale*sin(8.0*Pi*x)*sin(8.0*Pi*y);
viewer->Render();
}
stop=clock();
cout << " dt= " << ((double)(stop-start))/((double)CLOCKS_PER_SEC) <<
" for: " << NumberOfFrames << " frames" << endl;
viewer->Delete();
image->Delete();
// Clean up
return 1;
}
More information about the vtkusers
mailing list