[vtkusers] Label vtkActor

joaoroberto88 joaorobertojr88 at gmail.com
Wed Sep 23 09:32:50 EDT 2015


Hi Cory,

Thanks for your reply. I tried to use vtkTextActor, but I'm having some
issue about positioning it near to the station icon actor (see attached
image and code below). As you can see I'm using the same station icon
coordinate and the label "Station #1" isn't positioned correctly. Do you
have any clues? Also, since vtkTextActor is two-dimesional I think the text
won't follow the image actor while the user interacts with the rendered map.

Here is the main code that creates both actors:

    vtkSmartPointer<vtkPNGReader> iconReader =
vtkSmartPointer<vtkPNGReader>::New();
    iconReader->SetFileName("~/station.png");
    iconReader->Update();
    
    vtkSmartPointer<vtkImageData> imageData = iconReader->GetOutput();
    imageData->SetOrigin(station->getUtmX(), station->getUtmY(), 0);  // the
UTM-X and UTM-Y from UI
    
    vtkSmartPointer<vtkImageChangeInformation> imageResize =
vtkSmartPointer<vtkImageChangeInformation>::New();
    imageResize->SetInputData(imageData);
    imageResize->SetOutputSpacing(2, 2, 1); // Resizes the image
    imageResize->Update();
    
    vtkSmartPointer<vtkDataSetMapper> iconMapper =
vtkSmartPointer<vtkDataSetMapper>::New();
    iconMapper->SetInputData(imageResize->GetOutput());
    
    vtkSmartPointer<vtkActor> iconActor = vtkSmartPointer<vtkActor>::New();
    iconActor->SetMapper(iconMapper);
    
    vtkSmartPointer<vtkTextActor> textActor =
vtkSmartPointer<vtkTextActor>::New();
    textActor->GetTextProperty()->SetFontSize ( 12 );
    textActor->SetPosition2 ( iconActor->GetPosition()[0],
iconActor->GetPosition()[1] - 20 );
    renderer->AddActor2D ( textActor );
    textActor->SetInput( station->getName().toStdString().c_str() );
    textActor->GetTextProperty()->SetColor ( 1.0,0.0,0.0 );
    
    renderer->AddActor(textActor);
    renderer->AddActor(iconActor);

Thanks,

Joao.



--
View this message in context: http://vtk.1045678.n5.nabble.com/Label-vtkActor-tp5734069p5734072.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list