[Insight-users] Saving seed points in ImagePlaneWidget

Xiaopeng Yang yxp233 at postech.ac.kr
Mon Nov 1 21:10:45 EDT 2010


Hi Luis,

 

Thank you very much for your help. I added the code you suggested. However, the picker seemed not work. Since when I clicked a point, nothing happened. The pickedPoint is always 0, 0, 0. Could you please spare me some time to check my code?

 

Regards,

Xiaopeng

 

int main(int argc, char * argv [] )

{  

 

  try

    {

    typedef signed short  InputPixelType;

 

    const unsigned int Dimension = 3;

    typedef itk::Image< InputPixelType, Dimension > InputImageType;

    

    typedef itk::ImageFileReader< InputImageType > ReaderType;

 

    ReaderType::Pointer reader  = ReaderType::New();

    reader->SetFileName( "D:/Hybrid Method/Hybrid/984251/Diffusion_filter/3D.dcm" );

    reader->Update();

 

    InputImageType::Pointer inputImage = reader->GetOutput();

    InputImageType::SizeType  size  = inputImage->GetBufferedRegion().GetSize();

    InputImageType::IndexType start = inputImage->GetBufferedRegion().GetIndex();

    

    typedef itk::VTKImageExport< InputImageType > ExportFilterType;

 

    ExportFilterType::Pointer itkExporter = ExportFilterType::New();

    

    itkExporter->SetInput( reader->GetOutput() );

 

    vtkImageImport* vtkImporter = vtkImageImport::New();  

    ConnectPipelines(itkExporter, vtkImporter);

  

    vtkImporter->Update();

     

    vtkRenderer* renderer = vtkRenderer::New();

    vtkRenderWindow* renWin = vtkRenderWindow::New();

    vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();

 

    renWin->SetSize(600, 600);

    renWin->AddRenderer(renderer);

    iren->SetRenderWindow(renWin);

 

    vtkCellPicker * picker = vtkCellPicker::New();

    picker->SetTolerance(0.005);

 

    vtkProperty * ipwProp = vtkProperty::New();

 

    vtkImagePlaneWidget * xImagePlaneWidget =  vtkImagePlaneWidget::New();

    vtkImagePlaneWidget * yImagePlaneWidget =  vtkImagePlaneWidget::New();

    vtkImagePlaneWidget * zImagePlaneWidget =  vtkImagePlaneWidget::New();

 

    xImagePlaneWidget->DisplayTextOn();

    xImagePlaneWidget->SetInput(vtkImporter->GetOutput());

    xImagePlaneWidget->SetPlaneOrientationToXAxes();

    xImagePlaneWidget->SetSliceIndex(size[0]/2);

    xImagePlaneWidget->SetPicker(picker);

    xImagePlaneWidget->RestrictPlaneToVolumeOn();

    xImagePlaneWidget->SetKeyPressActivationValue('x');

    xImagePlaneWidget->GetPlaneProperty()->SetColor(1, 0, 0);

    xImagePlaneWidget->SetTexturePlaneProperty(ipwProp);

    xImagePlaneWidget->SetResliceInterpolateToNearestNeighbour();

 

    yImagePlaneWidget->DisplayTextOn();

    yImagePlaneWidget->SetInput(vtkImporter->GetOutput());

    yImagePlaneWidget->SetPlaneOrientationToYAxes();

    yImagePlaneWidget->SetSliceIndex(size[1]/2);

    yImagePlaneWidget->SetPicker(picker);

    yImagePlaneWidget->RestrictPlaneToVolumeOn();

    yImagePlaneWidget->SetKeyPressActivationValue('y');

    yImagePlaneWidget->GetPlaneProperty()->SetColor(1, 1, 0);

    yImagePlaneWidget->SetTexturePlaneProperty(ipwProp);

    yImagePlaneWidget->SetLookupTable(xImagePlaneWidget->GetLookupTable());

 

    zImagePlaneWidget->DisplayTextOn();

    zImagePlaneWidget->SetInput(vtkImporter->GetOutput());

    zImagePlaneWidget->SetPlaneOrientationToZAxes();

    zImagePlaneWidget->SetSliceIndex(size[2]/2);

    zImagePlaneWidget->SetPicker(picker);

    zImagePlaneWidget->SetKeyPressActivationValue('z');

    zImagePlaneWidget->GetPlaneProperty()->SetColor(0, 0, 1);

    zImagePlaneWidget->SetTexturePlaneProperty(ipwProp);

    zImagePlaneWidget->SetLookupTable(xImagePlaneWidget->GetLookupTable());

 

    xImagePlaneWidget->SetInteractor( iren );

    xImagePlaneWidget->On();

     

    yImagePlaneWidget->SetInteractor( iren );

    yImagePlaneWidget->On();

    

    zImagePlaneWidget->SetInteractor( iren );

    zImagePlaneWidget->On();

 

      double data[3];

      picker->GetPickPosition(data);

 

      itk::Point<double, 3>pickedPoint;

      pickedPoint[0]=data[0];

      pickedPoint[1]=data[1];

      pickedPoint[2]=data[2];

      std::cout<<"pickedPoint"<<": " <<pickedPoint[0] <<" " <<pickedPoint[1] <<" "<<pickedPoint[2] <<std::endl;

 

    renderer->ResetCamera();

    renWin->Render();

    iren->Start();

 

    picker->Delete();

    ipwProp->Delete();

    vtkImporter->Delete();

    xImagePlaneWidget->Delete();

    yImagePlaneWidget->Delete();

    zImagePlaneWidget->Delete();

    //property->Delete();

    //polyMapper->Delete();

    renWin->Delete();

    renderer->Delete();

    iren->Delete();

    }

 

  catch( itk::ExceptionObject & e )

    {

    std::cerr << "Exception catched !! " << e << std::endl;

    }

 

  return 0;

}

 

发件人: Luis Ibanez [mailto:luis.ibanez at kitware.com] 
发送时间: 2010년 10월 31일 일요일 오후 11:09
收件人: Xiaopeng Yang
抄送: vtk; itk
主题: Re: [Insight-users] Saving seed points in ImagePlaneWidget

 

Hi Xiaopen,

Capture the "EndPickEvent" with an Observer,
and in the execute method of the observer,
extract the coordinates of the point with code
similar to:

  double data[3];
  picker->GetPickPosition( data );

  itk::Point< double, 3 > pickedPoint;
  pickedPoint[0] = data[0];
  pickedPoint[1] = data[1];
  pickedPoint[2] = data[2];
  

---

See the example:

VTK/Examples/Annotation/Python/annotatePick.py


   Regards,


         Luis

----------------------------------------------------------------

On Mon, Oct 25, 2010 at 2:15 AM, Xiaopeng Yang <yxp233 at postech.ac.kr> wrote:

Hello everyone,

 

I am working on developing a simple medical image segmentation program, which provide interactive selection and automatic saving function of multiple seed points. That means when left-clicking on one of the CT slices, the 3D position of that point will be automatically saved to the code. 

 

I applied ImagePlaneWidget to pick the position of certain clicked point. The position and intensity value can be shown on the screen. But I have no idea how to program to save the position to the code. Could you give me a hand about how to solve this problem?

 

Here is the code of ImagePlaneWidget:

 

  vtkImagePlaneWidget * zImagePlaneWidget =  vtkImagePlaneWidget::New();

 

  zImagePlaneWidget->DisplayTextOn();

  zImagePlaneWidget->SetInput(vtkImporter->GetOutput());

  zImagePlaneWidget->SetPlaneOrientationToZAxes();

  zImagePlaneWidget->SetSliceIndex(size[0]/2);

  zImagePlaneWidget->SetPicker(picker);

  zImagePlaneWidget->RestrictPlaneToVolumeOn();

  zImagePlaneWidget->SetKeyPressActivationValue('y');

  zImagePlaneWidget->GetPlaneProperty()->SetColor(1, 0, 0);

  zImagePlaneWidget->SetTexturePlaneProperty(ipwProp);

  zImagePlaneWidget->SetResliceInterpolateToNearestNeighbour();

 

  zImagePlaneWidget->SetInteractor( iren );

zImagePlaneWidget->On();

 

Thanks very much.

 

Best regards,

Yang


_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.html

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-users

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101102/601c68b1/attachment.htm>


More information about the Insight-users mailing list