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

Isidro Moreno morenoisidro at yahoo.com.ar
Tue Jul 3 20:27:41 EDT 2007

```Hi Dean, thanks for your time.

Why should I change "reference coordinate" to NULL? In fact, position2 is
relative to position...

actor->GetPosition2Coordinate->SetValue(double width, double height) THIS
METHOD AND IT'S FAMILY DON'T WORK!!"
I wrote "width" and "height" in order to make the things easier to read
and understand, since I had put "x" & "y" instead of "width" and "height"
and someone had asked what was that... Well, "x" & "y" or "width" and
"height" are dimensions of the rectangle in which the actor (in this case, a
line) is drawn. As you might have seen,
actor->GetPosition2Coordinate->SetValue(...) difines the upper-right corner
of the mentioned rectangle, and theese values are distances relative to
"Position" (actor->GetPositionCoordinate->GetValue()  ) coordinates
(lower-left corner of the rectangle) - what I've told the paragraph above.

2nd) I don't use another 2D soft because I'm working on simple codes for VTK
teaching purposes. And I think drawing on the plane would be the best way to
start for the students.

So, I've seen vtkActor2D.h and vtkXYPlotActor.h but I don't understand what
you're trying to tell me, could you be more clear?. Everything should work
fine.. HOWEVER, I found there is no definition of GetPositionCoordinates()
and GetPosition2Coordinates() methods in vtkActor2D.h . Where are them
defined in?

Finally I tried with actor->PrintSelf(cout,0) and everything seemed to be
OK...

Thanks, very much! Isidro.

About: "doing 2D XY plots with VTK from scratch is a bit like hammering a
thumbtack with a sledgehammer" I think this, doesn't match with "VTK's
flexibility".

----- Original Message -----
From: "Dean Inglis" <dean.inglis at camris.ca>
To: "vtkusers archive" <vtkusers at vtk.org>
Cc: <morenoisidro at yahoo.com.ar>
Sent: Tuesday, July 03, 2007 3:56 PM
Subject: [vtkusers] Drawing a simple line graph (CONTINUES...)

> 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
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.476 / Virus Database: 269.9.12/878 - Release Date: 28/6/2007
> 17:57
>

```