[Insight-users] How to convert VTK example (console based) to MFC
based
paulus joo
paulusjoo at hotmail.com
Tue Jun 15 07:16:12 EDT 2004
Hi Luis and ITK Mania
I run the ITKImage2VTKImage.cxx with MSVC in console mode. It work fine but when I tried to convert it to MFC based, it fail in compilation stage. I plan to display the image in a Dialog. Below are the codes.
What part should I bring to constructor, destructor and so on..
Thank you in advance.
Best Regards
//--- Console mode ---
/*===================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: ITKImage2VTKImage.cxx,v $
Language: C++
=================================================================*/
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileReader.h"
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"
#include "itkImageToVTKImageFilter.h"
int main( int argc, char ** argv )
{
typedef unsigned short PixelType;
const unsigned int Dimension = 2;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageToVTKImageFilter< ImageType > ConnectorType;
ReaderType::Pointer reader = ReaderType::New();
ConnectorType::Pointer connector = ConnectorType::New();
reader->SetFileName( argv[1] );
//reader->Update();
connector->SetInput(reader->GetOutput());
vtkImageViewer *viewer=vtkImageViewer::New();
vtkRenderWindowInteractor *renderWindowInteractor=vtkRenderWindowInteractor ::New();
viewer->SetupInteractor(renderWindowInteractor);
viewer->SetInput(connector->GetOutput());
viewer->Render();
viewer->SetColorWindow(255);
viewer->SetColorLevel(128);
//renderWindowInteractor->Start();
return 0;
}
//--- MFC based
#if !defined(AFX_BINARYTHRESHOLDDLG1_H__2D2E73F5_F350_4BC6_A757_586AE2651DBF__INCLUDED_)
#define AFX_BINARYTHRESHOLDDLG1_H__2D2E73F5_F350_4BC6_A757_586AE2651DBF__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//itk and vtk
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileReader.h"
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"
#include "itkImageToVTKImageFilter.h"
// BinaryThresholdDlg1.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CBinaryThresholdDlg dialog (BinaryThreshold.h)
class CBinaryThresholdDlg : public CDialog
{
// Construction
public:
CBinaryThresholdDlg(CWnd* pParent = NULL); // standard constructor
typedef unsigned short PixelType; // <---- error in this part (illegal pure syntax, must be '= 0')
const unsigned int Dimension = 2; // <---- error in this part (Dimension' : pure specifier can only be specified for functions)
typedef itk::Image< PixelType, Dimension > ImageType; //
typedef itk::ImageFileReader< ImageType > ReaderType; //
typedef itk::ImageToVTKImageFilter< ImageType > ConnectorType; //
ReaderType::Pointer reader;
ConnectorType::Pointer connector;
// Dialog Data
//{{AFX_DATA(CBinaryThresholdDlg)
enum { IDD = IDD_BYNARYTHRESHOLDDLG };
CEdit m_fileName;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBinaryThresholdDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CBinaryThresholdDlg)
afx_msg void OnLoad();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_BINARYTHRESHOLDDLG1_H__2D2E73F5_F350_4BC6_A757_586AE2651DBF__INCLUDED_)
// BinaryThresholdDlg.cpp : implementation file
//
#include "resource.h"
#include "stdafx.h"
#include "Uias3D.h"
#include "BinaryThresholdDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBinaryThresholdDlg dialog
CBinaryThresholdDlg::CBinaryThresholdDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBinaryThresholdDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBinaryThresholdDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
reader = ReaderType::New();
connector = ConnectorType::New();
}
void CBinaryThresholdDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBinaryThresholdDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBinaryThresholdDlg, CDialog)
//{{AFX_MSG_MAP(CBinaryThresholdDlg)
ON_BN_CLICKED(IDC_LOAD, OnLoad)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBinaryThresholdDlg message handlers
void CBinaryThresholdDlg::OnLoad()
{
reader->SetFileName("brain.png");
connector->SetInput(reader->GetOutput());
vtkImageViewer *viewer=vtkImageViewer::New();
vtkRenderWindowInteractor *renderWindowInteractor=vtkRenderWindowInteractor ::New();
viewer->SetupInteractor(renderWindowInteractor);
viewer->SetInput(connector->GetOutput());
viewer->Render();
viewer->SetColorWindow(255);
viewer->SetColorLevel(128);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20040615/10f4e64a/attachment.htm
More information about the Insight-users
mailing list