[vtkusers] Rendering large polydata, inconsistent frame rate

javier.maestro at nabla-designs.es javier.maestro at nabla-designs.es
Mon Apr 27 03:59:28 EDT 2015


 

Hi all, 

I'm testing VTK limits rendering a large number of points
of a vtkPolyData structure. I'm trying to determine how many points can
I use so the frame rate is fast enough for a specific application. 

As
expected, as the number of points gets bigger, the rendering takes more
time and the frame rate decreases. I expect the frame rate to decrease
but I also expect it to keep a constant value. However even though at
first it seems to be constant, sometimes the frame rate drops
drastically and it takes a while to get back to that constant rate.


I'm using a grid of points (128 x 400) just as an example. I get 6 FPS
using the program below (PC Intel Core 2 Duo 2GHz, 3GB RAM, Windows 7),
but sometimes it drops to 0 FPS and it stays in there for periods of 1
min. Is there any reason for the inconsistent frame rate? 

Thanks.


#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include
<vtkPoints.h>
#include <vtkPolyData.h>
#include
<vtkPointData.h>
#include <vtkCellArray.h>
#include
<vtkUnsignedCharArray.h>
#include <vtkPolyDataMapper.h>
#include
<vtkActor.h>
#include <vtkRenderWindow.h>
#include
<vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include
<vtkVertexGlyphFilter.h>
#include <vtkProperty.h>
#include
<vtkLookupTable.h>
#include <vtkFloatArray.h>
#include
<vtkPoints.h>
#include <vtkTextActor.h>
#include
<vtkTextProperty.h>
#include <vtkCommand.h>
#include <stdio.h>

#define
LINES_X 128
#define LINES_Y 400

/** Update callback. */
class
vtkTimerCallback : public vtkCommand{

 public:
 /** New operator. */

static vtkTimerCallback *New(){
 return (vtkTimerCallback *)new
vtkTimerCallback;
 }
 /** Callback timer. */ 
 virtual void
Execute(vtkObject *caller,
 unsigned long vtkNotUsed(eventId), void
*vtkNotUsed(callData)){

 static char value[40];
 static int counter =
0;

 vtkRenderWindowInteractor *iren = 

static_cast<vtkRenderWindowInteractor*>(caller);

 // Update frame
counter
 textActor->SetInput(value);
 textActor->Modified();

sprintf(&value[0], "%d", counter ++); 

 // Just render again (data
hasn't really changed)
 poly->Modified();
 iren->Render();
 }

 //
Access polydata and text actor
 vtkSmartPointer<vtkPolyData> poly;

vtkSmartPointer<vtkTextActor> textActor;
};

// Cell
connectivity
vtkSmartPointer<vtkCellArray> getCells(){


vtkSmartPointer<vtkCellArray> mesh = 

vtkSmartPointer<vtkCellArray>::New();

 int nx = LINES_X;
 int ny =
LINES_Y;
 for(int i=0;i<nx-1;i++){
 for(int j=0;j<ny-1;j++){

mesh->InsertNextCell(4);
 mesh->InsertCellPoint((0+j) + ny*i);

mesh->InsertCellPoint((ny+j) + ny*i);
 mesh->InsertCellPoint((ny+1+j) +
ny*i);
 mesh->InsertCellPoint((1+j)+ ny*i);
 }
 }
 return mesh;
}

int
main(int, char *[]){

 // Polydata
 vtkSmartPointer<vtkPoints> points =

 vtkSmartPointer<vtkPoints>::New();
 vtkSmartPointer<vtkFloatArray>
scalars = 
 vtkSmartPointer<vtkFloatArray>::New();

vtkSmartPointer<vtkPolyData> poly = 

vtkSmartPointer<vtkPolyData>::New();

 for(int a=0;a<LINES_X;a++){

for(int b=0;b<LINES_Y;b++){
 points->InsertNextPoint((float)a, (float)b,
0);
 float value = (float)a/(float)LINES_X;

scalars->InsertNextValue(value);
 }
 } 
 poly->SetPoints(points);

poly->GetPointData()->SetScalars(scalars);

poly->SetPolys(getCells());

 // Mapper

vtkSmartPointer<vtkPolyDataMapper> mapper =

vtkSmartPointer<vtkPolyDataMapper>::New();
 mapper->SetInputData(poly);

mapper->ScalarVisibilityOn();
 mapper->SetScalarModeToUsePointData();

mapper->SetColorModeToMapScalars();
 mapper->SetScalarRange(0, 1.0);


// Lookup Table
 vtkSmartPointer<vtkLookupTable> lookupTable = 

vtkSmartPointer<vtkLookupTable>::New();
 lookupTable->SetTableRange(0,
1.0);
 mapper->SetLookupTable(lookupTable);

mapper->ReleaseDataFlagOn();
 mapper->ImmediateModeRenderingOn();

 //
Actor
 vtkSmartPointer<vtkActor> actor =

vtkSmartPointer<vtkActor>::New();
 actor->SetMapper(mapper);

 //
Renderer
 vtkSmartPointer<vtkRenderer> renderer =

vtkSmartPointer<vtkRenderer>::New();
 vtkSmartPointer<vtkRenderWindow>
renderWindow =
 vtkSmartPointer<vtkRenderWindow>::New();

renderWindow->AddRenderer(renderer);

 // Setup the text and add it to
the window
 vtkSmartPointer<vtkTextActor> textActor = 

vtkSmartPointer<vtkTextActor>::New();

textActor->GetTextProperty()->SetFontSize ( 24 );

textActor->SetPosition2 ( 10, 40 );
 renderer->AddActor2D ( textActor
);
 textActor->SetInput ( "0" );
 textActor->GetTextProperty()->SetColor
( 1.0,0.0,0.0 );

 // Add actors
 renderer->AddActor(actor);

renderer->AddActor(textActor);

 // Interactor

vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =

vtkSmartPointer<vtkRenderWindowInteractor>::New();

renderWindowInteractor->SetRenderWindow(renderWindow);

 // Render

renderWindow->Render();
 renderWindowInteractor->Initialize(); 

 //
Sign up to receive TimerEvent (Update)

vtkSmartPointer<vtkTimerCallback> timerCallback = 

vtkSmartPointer<vtkTimerCallback>::New();
 timerCallback->poly = poly;

timerCallback->textActor = textActor;

renderWindowInteractor->AddObserver(vtkCommand::TimerEvent,
timerCallback);
 renderWindowInteractor->CreateRepeatingTimer(1);

 //
Start interactor
 renderWindowInteractor->Start(); 

 return
EXIT_SUCCESS;
}

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150427/939a9f06/attachment.html>


More information about the vtkusers mailing list