[vtkusers] Drawing a simple line graph
beth at portugalmail.pt
beth at portugalmail.pt
Thu Nov 16 15:53:10 EST 2006
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
More information about the vtkusers
mailing list