[vtkusers] Draw a 2D line?
chasank
chasank at gmail.com
Tue Mar 25 11:27:30 EDT 2014
Use the following code block;
vtkPoints *points = vtkPoints::New();
points->SetNumberOfPoints(2);
points->Allocate(2);
points->InsertPoint(0, x_0, y_0, z_0);
points->InsertPoint(1, x_1, y_1, z_1);
vtkCellArray *cells = vtkCellArray::New();
cells->Initialize();
vtkLine *line = vtkLine::New();
line->GetPointIds()->SetId(0, 0);
line->GetPointIds()->SetId(1, 1);
cells->InsertNextCell(line);
vtkPolyData *poly = vtkPolyData::New();
poly->Initialize();
poly->SetPoints(points);
poly->SetLines(cells);
poly->Modified();
vtkCoordinate *coordinate = vtkCoordinate::New();
coordinate->SetCoordinateSystemToWorld();
vtkPolyDataMapper2D *mapper = vtkPolyDataMapper2D::New();
mapper->SetInputData(poly);
mapper->SetTransformCoordinate(coordinate);
mapper->ScalarVisibilityOn();
mapper->SetScalarModeToUsePointData();
mapper->Update();
vtkActor2D *actor = vtkActor2D::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetLineWidth(2.0); // Line Width
vtkRenderer *renderer = vtkRenderer::New();
renderer->AddViewProp(this->distanceActor);
--
View this message in context: http://vtk.1045678.n5.nabble.com/Draw-a-2D-line-tp5726509p5726512.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list