[Insight-users] How to convert VTK example (console based) to MFC based

Luis Ibanez luis.ibanez at kitware.com
Wed Jun 16 13:03:39 EDT 2004


Hi Paulus,

VisualStudio does not allow you to initialize constants
on the declaration of classes.  That is, the expression


     class AA
      {
      const unsigned int K = 0;
      };


is considered invalid, despite the fact that it is legal C++.

In order to go around this we use in ITK the itkStaticConstMacro()
like:

     class AA
      {
      itkStaticConstMacro( K, unsigned int, 0);
      };

This macro is defined in

    Insight/Code/Common/itkMacro.h

as

#ifdef ITK_NO_INCLASS_MEMBER_INITIALIZATION
#   define itkStaticConstMacro(name,type,value) enum { name = value }
#else
#   define itkStaticConstMacro(name,type,value) static const type name = 
value
#endif


Note that Borland 5.5 on the other hand, does not support the
use of enums {} since it doesn't initialize them at compilation
time, and therefore they cannot be used as numeric arguments of
templates.


To be short, your best option is to use the itkStaticConstMacro().


Note also that there is a demo MFC app under


         InsightApplications/
                          itkMFC


Please let us know if you find further problems,



    Regards,



       Luis





-------------
paulus joo wrote:

> Hi Luis and ITK Mania
>  
> The problem I mentioned n my previous example is answered.
> I change the line
>   const   unsigned int        Dimension = 2;
> into
>   #define  Dimension  2
>  
> It work but I don't know whwther this is the right way to do it.
>  
> Regards
>  
>  
>  
> My previous mail :
> 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);
> }
>  
> 
>  
>  
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users





More information about the Insight-users mailing list