[vtkusers] vtkCaptionWidget using world coordinates

Roberto Garrido rgarrido at emedica.es
Wed Mar 6 10:25:58 EST 2013


Hi there!

 

We need a vtkWidget that behaves in a similar way to a vtkCaptionActor2D.
And that is:

- A billboarding text

- An attachment point

- A leader to the attachment point

- Position and position2

- Translation (using dragging) functionality

- Everything must be in world coordinates (we don't want to show the text in
display coordinates)

 

We have been trying vtkCaptionWidget, that seems to be the right choice, but
are experiencing problems when we try to translate it via dragging. As we
show in the attached code, we change vtkCaptionRepresentation points one and
two, to world coordinate system. The problem is that when we move the camera
around the sphere, the background rectangle seems not to be billboarding as
the text does, and that's is causing problems when we want to drag the text.

 

We would appreciate if any of you can run the test application attached and
experience the problem.

Thanks in advance,

Robert.

 

Code and CMakeList.txt file:

#include <vtkPolyDataMapper.h>

#include <vtkActor.h>

#include <vtkRenderWindow.h>

#include <vtkRenderer.h>

#include <vtkRenderWindowInteractor.h>

#include <vtkPolyData.h>

#include <vtkSmartPointer.h>

#include <vtkSphereSource.h>

#include <vtkCaptionRepresentation.h>

#include <vtkCaptionActor2D.h>

#include <vtkTextActor.h>

#include <vtkTextProperty.h>

#include <vtkCaptionWidget.h>

#include <vtkInteractorStyleTrackballCamera.h>

int main(int, char *[])

{

  vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();

  sphereSource->Update();

  vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();

  mapper->SetInputConnection(sphereSource->GetOutputPort());

  vtkSmartPointer<vtkActor> actor =  vtkSmartPointer<vtkActor>::New();

  actor->SetMapper(mapper);

  vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();

  renderer->SetBackground(1,0,0);

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

  renderWindow->SetSize(800, 600);

  renderWindow->AddRenderer(renderer);

  renderer->AddActor(actor);

  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();

 
renderWindowInteractor->SetInteractorStyle(vtkSmartPointer<vtkInteractorStyl
eTrackballCamera>::New());

  renderWindowInteractor->SetRenderWindow(renderWindow);

 

  vtkSmartPointer<vtkCaptionRepresentation> captionRepresentation;

  vtkSmartPointer<vtkCaptionWidget> captionWidget;

 

  captionRepresentation = vtkSmartPointer<vtkCaptionRepresentation>::New();

 
captionRepresentation->GetPositionCoordinate()->SetCoordinateSystemToWorld()
;

 
captionRepresentation->GetPosition2Coordinate()->SetCoordinateSystemToWorld(
);

  captionRepresentation->GetCaptionActor2D()->SetCaption("Drag me!");

 
captionRepresentation->GetCaptionActor2D()->GetTextActor()->SetTextScaleMode
ToNone();

 
captionRepresentation->GetCaptionActor2D()->GetTextActor()->GetTextProperty(
)->SetFontSize(100);

 
captionRepresentation->GetCaptionActor2D()->GetTextActor()->GetTextProperty(
)->ItalicOff();

 
captionRepresentation->GetCaptionActor2D()->GetTextActor()->GetTextProperty(
)->ShadowOff();

 
captionRepresentation->GetCaptionActor2D()->GetTextActor()->GetTextProperty(
)->BoldOff();

 

  double anchorPos[3] = {0.5, 0.0, 0.0};

  double pos[3] = {1.0, 0.0, 0.0};

  captionRepresentation->SetAnchorPosition(anchorPos);

  captionRepresentation->SetPosition(pos);

 

  captionWidget =  vtkSmartPointer<vtkCaptionWidget>::New();

  captionWidget->SetResizable(false);

  captionWidget->SetInteractor(renderWindowInteractor);

  captionWidget->SetRepresentation(captionRepresentation);

  renderWindow->Render();

  captionWidget->On();

 

  renderWindowInteractor->Start();

  return EXIT_SUCCESS;

}

 

/////////////////////////////////////////////////

 

cmake_minimum_required(VERSION 2.8)

PROJECT(CaptionWidget)

find_package(VTK REQUIRED)

include(${VTK_USE_FILE})

message (${VTK_USE_FILE})

add_executable(CaptionWidget CaptionWidget)

target_link_libraries(CaptionWidget vtkHybrid vtkWidgets)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130306/f143eb53/attachment.htm>


More information about the vtkusers mailing list