I’m working on a project that involves loading medical image data in VTK (Visualization Toolkit), using Qt and C++, and rendering it using VTKImageViewer2. Additionally, I need to draw a line on the displayed image using VTKLineWidget2. I’ve added two renderers to the render window with layered indexing. Unfortunately, only the image is being displayed. Below, I have provided the code.
QVTKOpenGLWidget *m_pvtkWidget = new QVTKOpenGLWidget;
m_pvtkWidget->setStyleSheet("background-color: black");
vtkNew <vtkGenericOpenGLRenderWindow> m_openGlRenWin;
m_pvtkWidget->SetRenderWindow(m_openGlRenWin);
vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New();
QString filep= "path to dicom file";
reader->SetFileName(filep.toUtf8().constData());
reader->Update();
vtkSmartPointer<vtkImageData> imageData = reader->GetOutput();
vtkSmartPointer<vtkRenderer> m_rendererMainScene = vtkSmartPointer<vtkRenderer>::New();
m_rendererMainScene->GradientBackgroundOn();
m_rendererMainScene->SetLayer(0); // Layer 0 has a background
vtkSmartPointer<vtkRenderer> m_rendererForeground = vtkSmartPointer<vtkRenderer>::New();
m_rendererForeground->SetLayer(1);
m_pvtkWidget->GetRenderWindow()->AddRenderer(m_rendererMainScene);
m_pvtkWidget->GetRenderWindow()->AddRenderer(m_rendererForeground);
vtkNew<vtkImageActor> imageActor;
imageActor->GetMapper()->SetInputData(imageData );
m_rendererMainScene->AddActor(imageActor);
vtkSmartPointer<vtkLineWidget2> lineWidget = vtkSmartPointer<vtkLineWidget2>::New();
double pointPos1[3];
double pointPos2[3];
pointPos1[0]=50;
pointPos1[1]=50;
pointPos1[2]=0;
pointPos2[0]=150;
pointPos2[1]=150;
pointPos2[2]=0;
lineWidget->CreateDefaultRepresentation();
lineWidget->GetLineRepresentation()->SetLineColor(255, 0,0);
lineWidget->GetLineRepresentation()->GetLineProperty()->SetLineWidth(.25);
lineWidget->GetLineRepresentation()->SetPoint1WorldPosition(pointPos1);
lineWidget->GetLineRepresentation()->SetPoint2WorldPosition(pointPos2);
lineWidget->GetRepresentation()->SetHandleSize(0);
lineWidget->GetEventTranslator()->ClearEvents();
lineWidget->SetInteractor(m_pvtkWidget->GetRenderWindow()->GetInteractor());
m_rendererForeground->AddActor(lineWidget->GetLineRepresentation());
lineWidget->On();
m_pvtkWidget->GetRenderWindow()->Render();
m_pvtkWidget->GetRenderWindow()->GetInteractor()->Start();
Could you please take a look at it and kindly help me sort it out?