[vtk-developers] new vtkTextActor class and slight mapper changes
John Biddiscombe
jbiddiscombe at skippingmouse.co.uk
Tue Jun 4 12:38:13 EDT 2002
A new class vtkTextActor has been added. It basically performs the same
function as
vtkActor2D + vtkTextMapper
and
vtkScaledTextActor + vtkTextMapper
It is a scaled - or not scaled - text actor. No mapper is required as it
will create one internally (but you can supply one if you wish). This means
that existing code that uses either a vtkActor2D or a vtkScaledTextActor
can be switch to the new vtkTextActor class with zero fuss.
All the vtkTextMapper functions are pushed through or "promoted" into the
vtkTextActor class, so that where you once said
myTextMapper->setInput("Hello World");
myTextMapper->setJustificationTo(...);
myActor->SetMapper(myMapper);
etc
you now say
myTextActor->setInput("Hello World");
myTextActor->setJustificationTo(...);
and skip the mapper altogether. You can continue to use vtkTextMapper and
vtkActor2D together if you wish.
New Options are
vtkTextActor->ScaledText
if false you have an old style textmapper/actor combo
if true you have an old style ScaledTextActor/textmapper combo
vtkTextActor->SetAlignmentPoint
// Description:
// Set/Get the Alignment point for unscaled (fixed fontsize) text
// if zero (default), the text aligns itself to the bottom left corner
// (which is defined by the PositionCoordinate)
// otherwise the text aligns itself to corner/midpoint or centre
// 6 7 8 of the box defined by the position 1 & 2 coordinates
// 3 4 5 according to the diagram on the left.
// 0 1 2
Developers Note : * * * Change to Mappers * * *
vtkScaledTextActor created another vtkActor2D inside it and passed the
render calls through to it. This was necessary to allow vtkScaledTextActor
to alter the position coordinate of the internal actor and make the text
appear at some shifted position other than the nominal position of the
ScaledTextActor. (ScaledTextActor would adjust its position and size and
move itself around to fit the correct box, but if it altered its own
position, it'd get into a kind of feedback loop and problems would occur,
so a seperate actor was held inside). This is somewhat wasteful and so
the solution I've implemented is that the (Text)mappers used to call
actor->GetPositionCoordinate()...
but now they call
actor->GetActualPositionCoordinate()...
and by default vtkActor2D return PositionCoordinate, but vtkTextActor
overrides the GetActualPositionCoordinate call and instead returns a
vtkCoordinate object called AdjustedPositionCoordinate. The textactor can
compute the correct position of the text and place it in its
AdjustedPositionCoordinate which is then used by the mappers.
I suspect other vtkActor2D subclasses can also benefit from this fix and
should anyone find themselves altering any Actor2D classes - Please make a
mental note of the changes - (also note I've added in
GetActualPosition2Coordinate() just in case it can be used at a later date).
NB. I've changed
vtkCarbonTextMapper
vtkCocoaTextMapper
vtkWin32OpenGlTextMapper
vtkXMesaTextMapper
vtkXOpenGLTextMapper
if I've missed any please inform me ASAP as I cannot test on all platforms.
ttfn
John B
Any Queries/Problems with this, please let me know. I'll post this message
to the Users' list in a few days if I get no adverse feedback. I'll also add
a note to the faq.
More information about the vtk-developers
mailing list