[vtkusers] Drawing a simple line graph (CONTINUES...)

Dean Inglis dean.inglis at camris.ca
Tue Jul 3 14:56:54 EDT 2007


Hi Isidro,

maybe you need to set the vtkCoordinate(s) scale space of your
vtkActor2D to something like

  this->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
  this->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
  this->GetPosition2Coordinate()->SetReferenceCoordinate(NULL);

and then adjust everything else accordingly.  Have a look at vtkCoordinate
and its methods.  Notice that in vtkActor2D:

  this->PositionCoordinate = vtkCoordinate::New();
  this->PositionCoordinate->SetCoordinateSystem(VTK_VIEWPORT);
  //
  this->Position2Coordinate = vtkCoordinate::New();
  this->Position2Coordinate->SetCoordinateSystemToNormalizedViewport();
  this->Position2Coordinate->SetValue(0.5, 0.5);

this->Position2Coordinate->SetReferenceCoordinate(this->PositionCoordinate);

whereas in vtkXYPlotActor, things are slightly different

  this->PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
  this->PositionCoordinate->SetValue(0.25,0.25);
  this->Position2Coordinate->SetValue(0.5, 0.5);

In your code from an earlier post:

//  actor->GetPosition2Coordinate->SetValue(double width, double height)
THIS METHOD AND IT'S FAMILY DON'T WORK!!

what are width and height?  What coordinate system do they refer
to?  If your 2D actor has both position coordinates to NormalizedViewport,
then the only valid range for SetValue is ([0,1], [0,1]).
The data that you are trying to plot has a specific domain and range
that must be scaled to whatever space you want your 2D actor to work
in (probably the easiest is normalized viewport [0,1]).  Again,
in vtkXYPlotActor, there are methods to convert data space coords
into actor 2D coords:

void vtkXYPlotActor::ViewportToPlotCoordinate(vtkViewport *viewport, double
&u, double &v)

void vtkXYPlotActor::PlotToViewportCoordinate(vtkViewport *viewport,
                                              double &u, double &v)

It isn't that VTK is somehow flawed or has "holes" since clearly
vtkXYPlotActor works and it is built from other VTK objects.
VTK is designed to be and is flexible enough to allow many complex
types of data visualization. Unfortunately, doing 2D XY plots
with VTK from scratch is a bit like hammering a thumbtack with a sledge
hammer.
Why not use a dedicated 2D graph plotter (spreadsheet or otherwise)?

Dean




Dean, vtkXYPlotActor works OK, but I think it isn't the best way to draw a
line or a polygon in the plane. The methods for adjusting vtkActor2D's
dimensions should work properly. In fact, vtkXYPlotActor inherits theese
methods from vtkActor2D. However, there might be another way to do this. I'm
a begginer, and I thought drawing a simple line would be simple to; I
wouldn't like to think that such a complex system like VTK has this type of
holes. There must be something that has to be changed in pipelines like the
one in my code, something additional... The fact that vtkActor2D doesn't use
a 4x4 matrix says somthing to me, and also the render process must have to
do something with this. I would like to know how the renderer is working...
But again, It's strange that ->GetPosition2Coordinate()->SetValue(x,y) works
for vtkXYPlotActor and not for its mother class vtkActor2D (where the method
is initially defined)...

Isidro



More information about the vtkusers mailing list