[vtkusers] Drawing a simple line graph

John Platt jcplatt at dsl.pipex.com
Fri Nov 17 06:01:59 EST 2006


Hi,

I seem to recall that the Position2 coordinate is relative to Position.

Is there any reason you cannot use vtkXYPlotActor?

John.

-----Original Message-----
From: vtkusers-bounces+jcplatt=dsl.pipex.com at vtk.org
[mailto:vtkusers-bounces+jcplatt=dsl.pipex.com at vtk.org] On Behalf Of
beth at portugalmail.pt
Sent: 16 November 2006 20:53
To: vtkusers at vtk.org
Subject: [vtkusers] Drawing a simple line graph 

Hi,
 
I'm trying to create a simple line graph. For that, I created a polyline
and 2 
axis.My piece of code looks like this:
 
// Create a polyline
 vtkPolyData* polydata = vtkPolyData::New();
 polydata->SetPoints(polyLinePoints);
 polydata->SetLines(line);
 
// Maps it to 2D
 vtkPolyDataMapper2D *mapper = vtkPolyDataMapper2D::New();
 mapper->SetInput(polydata);
 
// Creates an actor, defining its limits according the graph area
defined by 
the axes below
 vtkActor2D *actor = vtkActor2D::New();
 actor->SetMapper(mapper);
 
actor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport(
);
 actor->GetPositionCoordinate()->SetValue(0.05, 0.2);
 
actor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport
(); // it's not working properly!!!
 actor->GetPosition2Coordinate()->SetValue(0.90, 0.9); // it's not
working 
properly!!!
 actor->GetProperty()->SetColor(1, 0, 0);

// Define axes
 vtkCoordinate *coords_x1 = vtkCoordinate::New();
 coords_x1->SetValue(0.05, 0.2);
 
 vtkCoordinate *coords_x2 = vtkCoordinate::New();
 coords_x2->SetValue(0.95, 0.2);
 
 vtkCoordinate *coords_y1 = vtkCoordinate::New();
 coords_y1->SetValue(0.05, 0.2);
 
 vtkCoordinate *coords_y2 = vtkCoordinate::New();
 coords_y2->SetValue(0.05, 0.95);
 
 vtkAxisActor2D *axesX = vtkAxisActor2D::New();
 axesX->SetPoint1(coords_x1->GetValue());
 axesX->SetPoint2(coords_x2->GetValue());
 axesX->SetLabelFormat("%3.2f");
 axesX->SetFontFactor(1.2);
 axesX->SetRange(0, t); // t is the maximum x value in the polyline
points
 axesX->SetTitle("Time (s)");
 axesX->SetNumberOfLabels(10);
 axesX->AdjustLabelsOn();
 axesX->LabelVisibilityOn();
 axesX->TickVisibilityOn();
 
 vtkAxisActor2D *axesY = vtkAxisActor2D::New();
 axesY->SetPoint1(coords_y1->GetValue());
 axesY->SetPoint2(coords_y2->GetValue());
 axesY->SetLabelFormat("%3.2f");
 axesY->SetFontFactor(1);
 axesY->SetRange(0, sCardMax); // Máximum y value in polyline points
 axesY->AdjustLabelsOn();
 axesY->LabelVisibilityOn();
 axesY->TickVisibilityOn();
 
.....the usual stuff....creates the renderer...
 
rw->AddActor2D(actor);
rw->AddViewProp(axesX);
rw->AddViewProp(axesY);
 
 
Well, the line graph is drawn, but the problem is that axes values and
line 
values are not matching. 
It seems that the GetPosition2Coordinate is not working at all, because
the 
mapping of the line to the graph effective area (that is defined by the
limits 
of the axes - xmin, ymin and xmax, ymax) is not being done. It just puts
the 
polyline at the initial position defined by GetPositionCoordinate, and
draws 
it as the output given by the vtkPolyDataMapper2D.
 
What should I do?
 
Thanks for any help!
 
Regards,
 
Elizabeth

__________________________________________________________
O email preferido dos portugueses agora com
2 000 MB de espaço e acesso gratuito à Internet
http://www.portugalmail.pt/2000mb
_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers





More information about the vtkusers mailing list