[Insight-users] Display image with ITK+VTK in VC dialog
x0_y0_0
x0_y0_0 at 126.com
Fri Mar 20 01:50:08 EDT 2009
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);
};
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090320/6b5af303/attachment-0001.htm>
More information about the Insight-users
mailing list