[vtkusers] Positioning titles within vtkAxis

Frese Daniel Dr. frese at heidenhain.de
Wed Dec 8 06:48:20 EST 2010


Hi Eric,

thanks for pointing me to vtkScalarsToColorsItem. This looks like a much more natural solution
than stitching everything together, as I did. I tried it and it works - thanks to Marcus's last addition
to the vtkChartXY (vtkChartsXY::SetAutoSize I am even able to control the size of the chart for e.g.
reserving some space for a separate colorbar. And in this case the axes titles are placed correctly.

I do have however one problem remaining. Obviously the chart takes some space for its axes labels,
ticks and titles, so the displayed image actually takes less space than I assign to the whole chart via SetSize().
Further, the space for the image could change in dependence of the axes labels, so the mapping from
pixel coordinates to plot coordinates is not always the same, but has offsets depending on
e.g. the label font size, length of number notation etc.
But I would like to know (and control) the exact  position of the displayed image in pixels:
First it makes data analysis using the rubber band interactor easier, since as far as I understand I get the
coordinates of the drawn rectangles in pixels coordinates, but not in plot coordinates (as I understand,
this can not be different, as the interactor is tied to the render window, not to the chart).
Second (less important) in my application it just looks better if the position of the axes does change
from shot to shot (arguably this is a matter personal preferences...)

So is there a way to find out the space for the axes labels/ticks/titles for a given chart ? I tried to read out
the "Point1" of the axes, but unfortunately this seems to be given in local coordinates and not in
respect to the overall scene. Methods like MapTo/FromParent/Scene sound like they should do the
trick (the doc is not exactly extensive on those...), but they did not return me anything usable. Also I tried to find
the place where this is calculated in the source, but failed miserably. If you (or anybody else) could give
me some hints on this, that would be really great.

Daniel



Von: Eric E. Monson [mailto:emonson at cs.duke.edu]
Gesendet: Dienstag, 7. Dezember 2010 19:06
An: Frese Daniel Dr.
Cc: Marcus D. Hanwell; vtkusers at vtk.org
Betreff: Re: AW: AW: [vtkusers] Positioning titles within vtkAxis

Hey Daniel,

There seems to be something wrong with the painting for vtkAxis when used by itself in a scene. I'm not sure why we don't see this behavior when these axes are used within the charts. Hopefully Marcus will be able to take a look. You can see the problem even in the attached simple Python script.

One thing I noticed that maybe Marcus can comment on: Things like vtkChartXY do an Update on themselves before Paint. If in this script you don't call Update explicitly on the axis objects they paint the axis line and title, but not the ticks and their labels. Maybe it would be good to add and Update call at the beginning of vtkAxis::Paint?

Daniel, something you might want to consider instead of the method you're using now is a trick others are using for vtkScalarsToColorsItem and its subclasses: they make a subclass of vtkPlot which has a vtkImageData as a private Texture variable, and then paints the texture within the plot's bounds. This way they can instantiate a vtkChartXY and use AddPlot() to add what is basically an image painter, and then vtkChartXY takes care of the axes internally. Just an idea that I've seen the developers using.

Anyway, hopefully Marcus or someone else will be able to take a look at this sometime soon, but I know he's very busy right now.

Talk to you later,
-Eric

# =======
import vtk

view = vtk.vtkContextView()
view.GetRenderWindow().SetSize(400, 300)

axis1 = vtk.vtkAxis()
axis1.SetPoint1(75,75)
axis1.SetPoint2(75,225)
axis1.SetPosition(vtk.vtkAxis.LEFT)
axis1.SetTitle('YAxis')
axis1.Update()
view.GetScene().AddItem(axis1)

axis2 = vtk.vtkAxis()
axis2.SetPoint1(75,75)
axis2.SetPoint2(325,75)
axis2.SetPosition(vtk.vtkAxis.BOTTOM)
axis2.SetTitle('XAxis')
axis2.Update()
view.GetScene().AddItem(axis2)

view.Render()
view.GetInteractor().Start()
# =======

[cid:image001.png at 01CB96CB.2DB6BFF0]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101208/e6324a07/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 16550 bytes
Desc: image001.png
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101208/e6324a07/attachment.png>
-------------- next part --------------
</PRE><p>
------------------------------------------------------------------------------------------------------ <br>
Registergericht: Traunstein / Registry Court: HRB 275 - Sitz / Head Office: Traunreut <br>
Aufsichtsratsvorsitzender / Chairman of Supervisory Board: Rainer Burkhard <br>
Gesch?ftsf?hrung / Management Board: Thomas Sesselmann (Vorsitzender / Chairman),<br>
Michael Grimm, Matthias Fauser, Sebastian Tondorf<br><br>
<a href="http://www.heidenhain.de/disclaimer" target="_blank">E-Mail Haftungsausschluss / E-Mail Disclaimer</a><br><pre>


More information about the vtkusers mailing list