[vtkusers] Basic VTK Example running slow
Nathan__
reeves_nathan at hotmail.com
Wed Jul 14 03:14:29 EDT 2010
I have just created a basic example of displaying 1000 Hexahedron on an
unstructured grid. Its unstructured because thats what I will need to
display my data in the future. I would of thought 1000 cells is handled with
no problems. It takes around 10 seconds to display anything, and mouse
interaction is incredibly slow. My example just displays 1000 cubes in a
row.
What I am hoping to eventually acheive, is to display up around 1000-10000
irregular cells on an unstructured grid. I want to be able to interactivly
select cells and change propeerties.
Here is my example:
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkDataSetTriangleFilter.h"
#include "vtkUnstructuredGridVolumeMapper.h"
#include "vtkProjectedTetrahedraMapper.h"
#include "vtkFloatArray.h"
#include "vtkPointData.h"
int index=0;
int globalPointId =0;
vtkUnstructuredGrid *myGrid;
vtkRenderer *myRenderer;
vtkRenderWindow *myRendererWindow;
vtkRenderWindowInteractor *myInteractor;
vtkPoints * myVtkPoints;
vtkDataSetMapper *myMapper;
#define NUMBER_OF_SHAPES 1000
int main ()
{
float xmin = 0.0;
float xmax = 1.0;
float ymin = 0.0;
float ymax = 1.0;
float zmin = 0.0;
float zmax = 1.0;
//create points of hexahedron
vtkPoints *points = vtkPoints::New();
for (int i=0;i<NUMBER_OF_SHAPES;i++)
{
points->InsertPoint(0 + (i*8), xmin, ymin, zmin + i);
points->InsertPoint(1+ (i*8), xmax, ymin, zmin+i);
points->InsertPoint(2+ (i*8), xmax, ymax, zmin+i);
points->InsertPoint(3+ (i*8), xmin, ymax, zmin+i);
points->InsertPoint(4+ (i*8), xmin, ymin, zmax+i);
points->InsertPoint(5+ (i*8), xmax, ymin, zmax+i);
points->InsertPoint(6+ (i*8), xmax, ymax, zmax+i);
points->InsertPoint(7+ (i*8), xmin, ymax, zmax+i);
}
//create the hexahedron
vtkHexahedron *theHex[NUMBER_OF_SHAPES];
for(int i=0;i<NUMBER_OF_SHAPES;i++)
{
theHex[i] = vtkHexahedron::New();
theHex[i]->GetPointIds()->SetNumberOfIds(8); //not needed if use
insertId
for (int j = 0; j <8; j++)
{
theHex[i]->GetPointIds()->SetId(j,j+(i*8)); //this maps internal id 0-7
to global point Id
// theHex[i]->GetPointIds()->InsertId(j,j+(i*8));
}
}
//create an unstructured grid for the hexahedron
vtkUnstructuredGrid *theGrid = vtkUnstructuredGrid::New();
theGrid->Allocate(NUMBER_OF_SHAPES, NUMBER_OF_SHAPES);
for(int i =0;i<NUMBER_OF_SHAPES;i++)
{
theGrid->InsertNextCell(theHex[i]->GetCellType(),
theHex[i]->GetPointIds());
}
theGrid->SetPoints(points);
// theGrid->GetPointData()->SetScalars(scalars);
//create a mapper for the hexahedron
vtkDataSetMapper *theHexMapper;
theHexMapper = vtkDataSetMapper::New();
theHexMapper->SetInput(theGrid);
//create an actor
vtkActor * hexActor[NUMBER_OF_SHAPES];
for(int i =0;i<NUMBER_OF_SHAPES;i++)
{
hexActor[i] = vtkActor::New();
hexActor[i]->SetMapper(theHexMapper);
}
// a renderer and render window
vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
for(int i =0;i<NUMBER_OF_SHAPES;i++)
ren1->AddActor(hexActor[i]);
// an interactor
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
ren1->SetBackground(1,1,1); // Background color white
// render an image (lights and cameras are created automatically)
renWin->Render();
// begin mouse interaction
iren->Initialize();
iren->Start();
return 1;
}
--
View this message in context: http://old.nabble.com/Basic-VTK-Example-running-slow-tp28675593p28675593.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list