[Insight-users] Display image with ITK+VTK in VC dialog
Luis Ibanez
luis.ibanez at kitware.com
Sat Mar 21 12:55:31 EDT 2009
Hi x0_y0_0
Please look at the following Insight Journal paper:
"How to use ITK and MFC"
by: Su Y.
http://www.insight-journal.org/browse/publication/141
You may also find useful to look at:
InsightApplications/Auxiliary/vtk
itkReadITKImageShowVTK.cxx
Regards,
Luis
-----------------
x0_y0_0 wrote:
>
> hi,users,
> I wanted to use ITK read PNG image and segement it,then through VTK and
> show on the VC's dialog.my program can through complie but can't show
> the result.Next It is my code ./Does anybody could give me some
> help?// thanks ./
> / // sincerely
> mexiao/
> class CVTK
> {
> public:
> vtkWin32RenderWindowInteractor *iren;
> vtkImageViewer *viewer;
> typedef itk::Image< float, 2 > InternalImageType1;
>
> typedef itk::Image< unsigned char, 2 > OutputImageType1;
> typedef itk::ImageFileReader< InternalImageType1 > ReaderType1;
> typedef itk::ImageFileWriter< OutputImageType1 > WriterType1;
> typedef itk::CastImageFilter< InternalImageType1, OutputImageType1 >
> CastingFilterType;
> typedef itk::CurvatureFlowImageFilter< InternalImageType1,
> InternalImageType1 > CurvatureFlowImageFilterType;
> typedef itk::ConnectedThresholdImageFilter< InternalImageType1,
> InternalImageType1> ConnectedFilterType;
> float lowerThreshold ;
> float upperThreshold ;
> InternalImageType1::IndexType index;
> typedef itk::Image< unsigned char, 2 > ImageType;
> typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
> public:
> vtkCellPicker * picker;
> static void MyExecute(vtkObject *caller, unsigned long eid, void
> *clientdata, void *calldata);
> void BeginRenderOn(CStatic* aStatic);
> CVTK();
> virtual ~CVTK();
> };
> //////////////////////////////////////////////////////////////////////////////////////////
> CVTK::CVTK()
> {
> lowerThreshold = 150.0;
> upperThreshold = 180.0;
> index[0] =60;
> index[1] =116;
> ReaderType1::Pointer reader = ReaderType1::New();
> reader->SetFileName("G:\\ITKVTK\\test\\test\\myProject\\Debug\\BrainProtonDensitySlice.png");
> WriterType1::Pointer writer = WriterType1::New();
> writer->SetFileName("G:\\ITKVTK\\test\\test\\myProject\\Debug\\aa.png");
> CurvatureFlowImageFilterType::Pointer smoothing =
> CurvatureFlowImageFilterType::New();
> ConnectedFilterType::Pointer connectedThreshold =
> ConnectedFilterType::New();
> CastingFilterType::Pointer caster = CastingFilterType::New();
> smoothing->SetInput( reader->GetOutput() );
> connectedThreshold->SetInput( smoothing->GetOutput() );
> caster->SetInput( connectedThreshold->GetOutput() );
> writer->SetInput( caster->GetOutput() );
>
> smoothing->SetNumberOfIterations( 5 );
> smoothing->SetTimeStep( 0.125 );
> connectedThreshold->SetLower( lowerThreshold );
> connectedThreshold->SetUpper( upperThreshold );
> connectedThreshold->SetReplaceValue( 255 );
> connectedThreshold->SetSeed( index );
> ConnectorType::Pointer connector = ConnectorType::New();
> connector->SetInput( caster->GetOutput());
>
> // writer->Update();
>
> viewer = vtkImageViewer::New();
> viewer->SetInput(connector->GetOutput());
> viewer->SetColorWindow(256);
> viewer->SetColorLevel(128);
>
> iren = vtkWin32RenderWindowInteractor::New();
> viewer->SetupInteractor(iren);
> // connector->Update();
> picker=vtkCellPicker::New();
> //picker->SetTolerance(0.00001);
>
> vtkCallbackCommand * cmd = vtkCallbackCommand::New();
> cmd->SetCallback(CVTK::MyExecute);
> cmd->SetClientData( this );
> picker->AddObserver(vtkCommand::EndPickEvent, cmd);
> iren->SetPicker(picker);
> cmd->Delete();
>
> }
> /////////////////////////////////////////////////////
> BOOL CDlgVTKITKDlg::OnInitDialog()
> {
> CDialog::OnInitDialog();
> SetIcon(m_hIcon, TRUE); // Set big icon
> SetIcon(m_hIcon, FALSE); // Set small icon
> // TODO: Add extra initialization here
> this->m_vtk.BeginRenderOn(&(this->m_RenderArea));//have been defined
> CVTK m_vtk;
> UpdateData(FALSE);
>
> return TRUE; // return TRUE unless you set the focus to a control
> }
> ///////////////////////////////////////////////////////////////////////
> void CVTK::BeginRenderOn(CStatic * aStatic)
> {
> CRect rect;
> aStatic->GetClientRect(&rect);
> viewer->SetSize(rect.Width(),rect.Height());
> viewer->SetParentId(aStatic->m_hWnd);
> viewer->Render();
> // iren->Initialize();
> }
> /////////////////////////////////////////////////////////////////
> void CVTK::MyExecute(vtkObject *caller, unsigned long eid, void
> *clientdata, void *calldata)
> {
> CVTK *m_viewer = reinterpret_cast<CVTK*>(clientdata );
> if (m_viewer->picker->GetCellId()<0)
> {
> AfxMessageBox("CellID < 0");
> }
> else
> {
> AfxMessageBox("CellID > 0");
> double ScreenCoordinate[3],globalCoordinate[3];
> m_viewer->picker->GetSelectionPoint(ScreenCoordinate);
> m_viewer->picker->GetPickPosition(globalCoordinate);
> };
> }
>
>
> ------------------------------------------------------------------------
> ÍøÒ×ÓÊÏ䣬ÖйúµÚÒ»´óµç×ÓÓʼþ·þÎñÉÌ <http://www.yeah.net>
>
>
> ------------------------------------------------------------------------
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.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
More information about the Insight-users
mailing list