We can put model in VTK display coordinate system. The following example is based on a previous article: Show Special Character In VTK .
I add a line which start from (0,0) to left bottom corner of red string, the line is represented as 2D model.

    int *size = renderer->GetSize();
    qDebug() << size[0] << " " << size[1];
    int centerY = int(size[1] / 2.0 + 0.5);
    int centerX = int(size[0] / 2.0 + 0.5);
    double actorSize[2];
    actor->GetSize( renderer, actorSize );
    actor->SetPosition( centerX - actorSize[0] / 2, centerY - actorSize[1] / 2 );

    // ==== start to draw line ====
    vtkSmartPointer<vtkPoints> points = 
        vtkSmartPointer<vtkPoints>::New();
    points->InsertNextPoint(0, 0, 0);
    points->InsertNextPoint(centerX - actorSize[0] / 2, centerY - actorSize[1] / 2, 0);

    vtkSmartPointer<vtkCellArray> cells =
        vtkSmartPointer<vtkCellArray>::New();
    vtkIdType line[2] = {0, 1};
    cells->InsertNextCell(2, line);

    vtkSmartPointer<vtkPolyData> polydata = 
        vtkSmartPointer<vtkPolyData>::New();
    polydata->SetPoints(points);
    polydata->SetLines(cells);
    polydata->Modified();

    vtkSmartPointer<vtkPolyDataMapper> mapper =
        vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputData(polydata);
    mapper->Update();

    vtkCoordinate *coordinate = vtkCoordinate::New();
    coordinate->SetCoordinateSystemToDisplay();

    vtkSmartPointer<vtkPolyDataMapper2D> mapper2D =
        vtkSmartPointer<vtkPolyDataMapper2D>::New();
    mapper2D->SetInputData(polydata);
    mapper2D->SetTransformCoordinate(coordinate);
    mapper2D->Update();

    vtkSmartPointer<vtkActor2D> actor2D =
        vtkSmartPointer<vtkActor2D>::New();
    actor2D->SetMapper( mapper2D );

    renderer->AddActor( actor2D );
    // ==== FInish: draw line ====
Categories: VTK

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x