[vtkusers] Rendering large polydata, inconsistent frame rate

Bill Lorensen bill.lorensen at gmail.com
Mon Apr 27 08:05:57 EDT 2015


What version of VTK are you using. I do not see and degradation when I
run on my Mac with the latest VTK.

On Mon, Apr 27, 2015 at 7:11 AM,  <javier.maestro at nabla-designs.es> wrote:
> The code appeared a little messed up, sorry about that. I attached the code
> on the ColoredPoints.cxx file.
>
>
>
>
>
> El 27-04-2015 09:59, javier.maestro at nabla-designs.es escribió:
>
> 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;
> }
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list