[vtkusers] Positioning text

Bruce Clay bruce_clay at qualia-computing.com
Mon Oct 7 13:52:49 EDT 2002


I am working on a program the allows the user to reconfigure multiple screens (views) using splitter windows.  In one configuration a VTK window is used to draw 2D text.  When the text is displayed, it is drawn as expected  at the lower left corner of the screen.  I have tried various methods to set the origin to the top left for user convinience.  The only method I can find that works is SetPosition.  To make this effective I need to get the height of the text then use the window height to calculate the offset.  GetHeight returns 0.0 so that doesn't work.

The rest of the text in embedded in the code below.

		text_ = vtkActor2D::New();

		vtk_renderer_->AddActor( text_ );
		text_mapper_ = vtkTextMapper::New();

		text_->SetMapper(text_mapper_);

		vtk_renderer_->AddActor(text_);
	
		vtk_renderer_->SetBackground(0.0,0.0,0.0);

		text_mapper_->SetFontSize(12);
		text_mapper_->BoldOn();

If I use any of the next four lines the text does not show up at all

		text_mapper_->SetVerticalJustificationToTop();
		text_mapper_->SetVerticalJustification(VTK_TEXT_TOP);
		text_mapper_->SetJustification(VTK_TEXT_CENTERED);
		text_mapper_->SetJustificationToCentered ();
		}

	text_mapper_->SetInput(str_ptr);

the line belows always returns 0.0

	float height = text_mapper_->GetHeight(this);

The line below works but is not flexible enough to handle different string lengths

	text_->SetPosition(10.0, 80.0);


There is another GetHeight that from the description might work but it requires the address of a vtkViewport.  How do I get one of these??

Is there a more flexible way to get the text origin to be the top keft corner of the window??

Did I use the set justification methods incorrectly?

Thanks for your help in advance

Bruce Clay




More information about the vtkusers mailing list