[vtkusers] QVTKWidget with vtk actor and mouserelease

Abdelkhalek Bakkari bakkari.abdelkhalek at hotmail.fr
Thu Dec 28 05:28:10 EST 2017


Dear All,


I am trying to add a seed point by a mouse release event. But, I've got an issue, the window/level (intercept/slope) parameters of the image visualization is changed. Maybe adding a red circle into the visualization window affected the parameters?


Below is my code :


void MainWindow::myMouseReleaseEvent (QMouseEvent * event)
{


const unsigned int InputDimension = 3;//Dimension of image
typedef short InputPixelType;//Pixel Type
typedef itk::Image< InputPixelType, InputDimension > InputImageType;//Image Type


//Set input image to VTK viewer
double* range = image_vtk->GetScalarRange();
image_view->SetInputData(image_vtk);
image_view->SetColorLevel(0.5*(range[0]+range[1]));
image_view->SetColorWindow(range[1] - range[0]);

mMinSliderX = image_view->GetSliceMin();
mMaxSliderX = image_view->GetSliceMax();
ui->horizontalSlider->setMinimum(mMinSliderX);
ui->horizontalSlider->setMaximum(mMaxSliderX);
Hori_slider_position = 0;

int sliceNumber = currentSlice;

vtkSmartPointer<vtkExtractVOI> extractVOI = vtkSmartPointer<vtkExtractVOI>::New();
extractVOI->SetInputData(image_vtk);
extractVOI->SetSampleRate(1,1,1);


extractVOI-> SetVOI ( 0, image_vtk-> GetExtent () [1],
0, image_vtk-> GetExtent () [3],
sliceNumber, sliceNumber
);

extractVOI->Update();

vtkImageData* extracted = extractVOI->GetOutput();

vtkSmartPointer<vtkImageCast> extractedCastFilter = vtkSmartPointer<vtkImageCast>::New();
extractedCastFilter->SetInputData(extracted);
extractedCastFilter->SetOutputScalarTypeToUnsignedShort();
extractedCastFilter->Update();


vtkSmartPointer<vtkImageActor> imageActor = vtkSmartPointer<vtkImageActor>::New();
imageActor->GetMapper()->SetInputConnection( extractedCastFilter->GetOutputPort());
// Setup renderer

vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(imageActor);

if (event->button() == Qt::LeftButton )
{

QPointF currPos = event->windowPos();
currPos.setX(currPos.x());
currPos.setY(ui->qVTK1->height() - currPos.y());
// Seed points visualization

vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(0.0, 0.0, 0.0);
sphereSource->SetRadius(10.0);

sphereSource->Update();

vtkSmartPointer<vtkPolyDataMapper2D> sphereMapper = vtkSmartPointer<vtkPolyDataMapper2D>::New();
sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
sphereMapper->Update();

vtkSmartPointer<vtkActor2D> sphereActor = vtkSmartPointer<vtkActor2D>::New();
               sphereActor->SetMapper(sphereMapper);
sphereActor->GetProperty()->SetColor(1.0, 0.0, 0.0);
sphereActor->GetProperty()->SetPointSize(5);
sphereActor->SetPosition( currPos.x(), currPos.y() );
renderer->AddActor(sphereActor);
renderer->ResetCamera();
}
ui-> qVTK1-> GetRenderWindow () -> AddRenderer (renderer);
ui-> qVTK1-> GetRenderWindow () -> render ();
ui->qVTK1->update();
}



Kind regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20171228/fb341212/attachment.html>


More information about the vtkusers mailing list