Quantcast

How to show lots labels using vtkLabeledDataMapper while the performance is still good?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to show lots labels using vtkLabeledDataMapper while the performance is still good?

informan
This post has NOT been accepted by the mailing list yet.
Dear vtkGuys:

I encounter a performance issue while using vtkLabeledDataMapper.
I want to show more than 5K labels with smoothly zoom in or zoom out. I use vtkLabeledDataMapper, the program is very slow. While replacing with vtkLabelPlacementMapper, it looks the same as before.

Does anyone know how to increase the performance? or how to implement my requirement?
Thanks.

Here is my simple program:
#include <vtkSmartPointer.h>
#include <vtkPointSource.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkActor.h>
#include <vtkActor2D.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include "vtkStringArray.h"
#include "vtkPointData.h"
#include "vtkTextProperty.h"
#include <sstream>
#include "vtkProperty2D.h"
#include "vtkTextMapper.h"
#include "vtkLabeledDataMapper.h"

int main(int, char *[])
{
        vtkSmartPointer<vtkPointSource> lPlanePts = vtkSmartPointer<vtkPointSource>::New();
        lPlanePts->SetNumberOfPoints(1000);
       
        // Create a mapper and actor
        vtkSmartPointer<vtkPolyDataMapper> pointMapper =
                vtkSmartPointer<vtkPolyDataMapper>::New();
        pointMapper->SetInputConnection(lPlanePts->GetOutputPort());

        vtkSmartPointer<vtkActor> pointActor =
                vtkSmartPointer<vtkActor>::New();
        pointActor->SetMapper(pointMapper);
        pointActor->GetProperty()->SetPointSize(5);
        pointActor->GetProperty()->SetColor(1, 0, 0);

        //label
        vtkSmartPointer<vtkLabeledDataMapper> labelMapper =
                vtkSmartPointer<vtkLabeledDataMapper>::New();
        labelMapper->SetInputConnection(lPlanePts->GetOutputPort());
        labelMapper->GetLabelTextProperty()->ShadowOff();

        vtkSmartPointer<vtkActor2D> labelActor =
                vtkSmartPointer<vtkActor2D>::New();
        labelActor->SetMapper(labelMapper);
       
        // Create a renderer, render window, and interactor
        vtkSmartPointer<vtkRenderer> renderer =
                vtkSmartPointer<vtkRenderer>::New();
        vtkSmartPointer<vtkRenderWindow> renderWindow =
                vtkSmartPointer<vtkRenderWindow>::New();
        renderWindow->AddRenderer(renderer);
        vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
                vtkSmartPointer<vtkRenderWindowInteractor>::New();
        renderWindowInteractor->SetRenderWindow(renderWindow);

        // Add the actor to the scene
        renderer->AddActor(pointActor);
        renderer->AddActor(labelActor);

        renderer->SetBackground(.1, .3, .2); // Background color green
                                                                                 // Render and interact
        renderWindow->Render();
        renderWindowInteractor->Start();

        return EXIT_SUCCESS;
}
Loading...