[ITK-users] QVtkWidget beginner questions

Ibraheem ibr_ex at yahoo.com
Wed Aug 31 03:01:30 EDT 2016


Dear all,
I am writing some ITK examples while learning it following different
tutorials . I have Ubuntu 14.04. I build these tools from the source: ITK 
4.10, VTK 7.0, QT5.7 and CMake 3.6.1
In example 2, I wrote a simple GUI application that read a DICOM volume from
a folder, displays it in a QVtkWidget, thresholds the slice and displays it
in another QVtkWidget. Save the resulted thresholded volume in a new folder.
I had some problems that I was able to solve like the dark output and the
flipping, see the bellow code comments.

My questions:
  1- Is there a way to filter and write all the images at once instead of
using the for loop?
  2- Writing the way I did make the output volume lost some origin
information i.e value, 0,0 . What did I do wrong?
  3- I read some posts about using QVtkWidget2 and  QVtkWidget3 but I
couldn't find them in my vtk build, is there some options I missed when I
built vtk?
  4- How can I display a specific plane instead of the axial slices e.g.
display a coronal slice.
  5- How can I get the voxel information when I point in the QVTkWidget? I
am not sure if the mapping I used is correct.
Here is the link to the  examples
<https://sites.google.com/site/ibraheemtutorials/classroom-news/itkexamples> 
.


Actually, I am not sure if what I did is the correct way to combine QT, VTK
and ITK so your comments are welcome .

Best regards!
Ibraheem

myDCMSeriesIO__src.zip
<http://itk-users.7.n7.nabble.com/file/n37451/myDCMSeriesIO__src.zip>  

// ================== Initialization  ==========================
typedef itk::Image< short, 3  >          InputImageType;
typedef itk::Image< short, 3 >          OutputImageType;
//----------------------------------  Reading
--------------------------------------------------
typedef itk::GDCMSeriesFileNames                 
InputFileNamesGeneratorType;
InputFileNamesGeneratorType::Pointer inputNames =
InputFileNamesGeneratorType::New();

typedef itk::GDCMImageIO                            ImageIOType;
ImageIOType::Pointer gdcmIO = ImageIOType::New();

typedef itk::ImageSeriesReader< InputImageType >  DCMReaderType;
DCMReaderType::Pointer reader =  DCMReaderType::New();
//----------------------------------  Writing
--------------------------------------------------
typedef itk::NumericSeriesFileNames OutputNamesGeneratorType;
OutputNamesGeneratorType::Pointer outputNames =
OutputNamesGeneratorType::New();

typedef itk::ImageSeriesWriter< InputImageType, InputImageType >     
DCMWriterType;
DCMWriterType::Pointer writer =  DCMWriterType::New();
//----------------------------------  Filtering
--------------------------------------------------
typedef itk::ThresholdImageFilter<  InputImageType >  ThresholdImageType;
ThresholdImageType::Pointer filterThresh =  ThresholdImageType::New();
//----------------------------------  Display
--------------------------------------------------
typedef itk::ImageToVTKImageFilter<InputImageType>    ConnectorSType;// 
ConnectorType
typedef itk::ImageToVTKImageFilter<OutputImageType>  ConnectorFType;// 
ConnectorType
int nSlices, midS; //  number of slices and middle slice
//x,y,z of Camera parameters: Position, UpView and FocapPoint
double CPx, CPy, CPz, CUx, CUy, CUz, CFx, CFy, CFz ;
int  myValue=0; // to filter the same slice from the source widget

ConnectorSType::Pointer vtkImgS = ConnectorSType::New(); // connector of the
Source itk Image
ConnectorFType::Pointer vtkImgF = ConnectorFType::New(); // connector of the
filtered itk Image

// Viewers for the source and the filtered images
 vtkSmartPointer<vtkImageViewer2> imageViewerS =
vtkSmartPointer<vtkImageViewer2>::New();
 vtkSmartPointer<vtkImageViewer2> imageViewerF =
vtkSmartPointer<vtkImageViewer2>::New();

vtkSmartPointer<vtkInteractorStyleImage> myStyleS =
vtkSmartPointer<vtkInteractorStyleImage>::New();
vtkSmartPointer<vtkInteractorStyleImage> myStyleF =
vtkSmartPointer<vtkInteractorStyleImage>::New();

void mWin::on_butF_clicked(){

  reader->SetFileName(inputNames->GetInputFileNames()[myValue]); // get one
slice
  reader->Update();

  // filtering : get threshold
  filterThresh->SetInput( reader->GetOutput() );
  QString thVals=ui->ThVal->text();
  int ut= thVals.toInt() ;

  //filterThresh->ThresholdOutside(lt,ut);
  filterThresh->ThresholdAbove(ut);
  filterThresh->SetOutsideValue(0);
  filterThresh->Update();

  // Convert to VTK image using ImageToVTKImageFilter
  vtkImgF->SetInput(filterThresh->GetOutput ());
  vtkImgF->Update(); //vtk image

  imageViewerF->SetInputData( vtkImgF->GetOutput() );  // ok but the image
currpted sometime

  CFx = ui->cFx->text().toDouble();  CFy = ui->cFy->text().toDouble();  CFz
= ui->cFz->text().toDouble();
  CPx = ui->cPx->text().toDouble();  CPy = ui->cPy->text().toDouble();  CPz
= ui->cPz->text().toDouble();
  CUx = ui->cUx->text().toDouble();  CUy = ui->cUx->text().toDouble();  CUz
= ui->cUx->text().toDouble();

  vtkCamera * cam2 = imageViewerF->GetRenderer()->GetActiveCamera();
  cam2->SetFocalPoint(CFx, CFy, CFz); //  0  0    0
  cam2->SetPosition  (CPx, CPy, CPz); //  0  0  -1
  cam2->SetViewUp    (CUx, CUy, CUz); //  -1  0    0
  imageViewerF->GetRenderer()->ResetCamera( );

  double * range = vtkImgF->GetOutput()->GetScalarRange();
  std::cout<< " color range: "<< range[0] << " , "<<range[1] <<
std::endl;
  imageViewerS->SetColorLevel( 0.5 * ( range[1]+ range[0]) );
  imageViewerS->SetColorWindow(range[1]-range[0]);

  imageViewerF->GetRenderWindow()->SetInteractor(
ui->vtkWF->GetRenderWindow()->GetInteractor() );
  imageViewerF->Render();

  //Connect to the QVTKWidget
  ui->vtkWF->SetRenderWindow(imageViewerF->GetRenderWindow());
  //ui->vtkW->GetRenderWindow()->GetInteractor()->SetInteractorStyle(0); //
3D
 
ui->vtkWF->GetRenderWindow()->GetInteractor()->SetInteractorStyle(myStyleF);
// contrast
  ui->vtkWF->update();
  qApp->processEvents();

}



--
View this message in context: http://itk-users.7.n7.nabble.com/QVtkWidget-beginner-questions-tp37451.html
Sent from the ITK - Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list