[vtkusers] Problem in ITK & VTK

paulus joo paulusjoo at hotmail.com
Tue Jun 15 12:08:14 EDT 2004


Hi All


I want to display the original image in one renderer and the other renderer to display the image already filtered. I use ITK to read and filter the image, then display it using VTK. It can run but doesn't work properly. Below are the problems and the codes both of header file and implementation file. 

I have some question:
1. Why after I close the dialog, there is an error occurs? When I trace, it goes to smartpointer source .... 
2. Why each time I open the dialog, it also appear the image inside the dialog. I mean to display the image after the Load button is pressed. 
3. I want to display the original image in renderer ren1 and the filtered image in renderer ren2. But it doesn't work. When I change the value of threshold value both image also change.

Thank you in advance

Greeting
Paulus


// BinaryThresholdDlg.h : Header file

#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 "itkBinaryThresholdImageFilter.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "vtkImageActor.h"
#include "vtkImageViewer.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "itkImageToVTKImageFilter.h"
#include "vtkImageShiftScale.h"

//#define Dimension 2


// BinaryThresholdDlg1.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CBinaryThresholdDlg dialog

class CBinaryThresholdDlg : public CDialog
{
// Construction
public:
 CBinaryThresholdDlg(CWnd* pParent = NULL);   // standard constructor
 //~CBinaryThresholdDlg();   // standard destructor

 typedef int integer;
  typedef unsigned short      PixelType;

  typedef  unsigned char  InputPixelType;
  typedef  unsigned char  OutputPixelType;
  typedef itk::Image< InputPixelType,  2 >   InputImageType;
  typedef itk::Image< OutputPixelType, 2 >   OutputImageType;
  typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType >  FilterType;
  typedef itk::ImageFileReader< InputImageType >  ReaderType;
  typedef itk::ImageToVTKImageFilter< InputImageType > ConnectorType;

  ReaderType::Pointer reader;
  ConnectorType::Pointer connector;

  vtkRenderer *ren1,*ren2;
  vtkRenderWindow *renWin;
  vtkRenderWindowInteractor *iren;
  vtkImageActor *imageInActor,*imageOutActor;
  vtkImageShiftScale  *shiftScale;

  OutputPixelType outsideValue;
  OutputPixelType insideValue;
  InputPixelType lowerThreshold;
  InputPixelType upperThreshold;
  FilterType::Pointer filter; 

// Dialog Data
 //{{AFX_DATA(CBinaryThresholdDlg)
 enum { IDD = IDD_BYNARYTHRESHOLDDLG };
 CSliderCtrl m_SliderOutsideOutput;
 CSliderCtrl m_SliderInsideOutput;
 CSliderCtrl m_SliderOutsideInput;
 CSliderCtrl m_SliderInsideInput;
 CSpinButtonCtrl m_SpinOutsideOutput;
 CSpinButtonCtrl m_SpinInsideOutput;
 CSpinButtonCtrl m_SpinOutsideInput;
 CSpinButtonCtrl m_SpinInsideInput;
 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 int OnCreate(LPCREATESTRUCT lpCreateStruct);
 afx_msg void OnPaint();
 virtual BOOL OnInitDialog();
 afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
 //}}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)
 //}}AFX_DATA_INIT
  reader = ReaderType::New();
  connector = ConnectorType::New();
  ren1 = vtkRenderer::New();
  ren2 = vtkRenderer::New();
  renWin = vtkRenderWindow::New();
  iren = vtkRenderWindowInteractor::New();
  imageInActor = vtkImageActor::New();
  imageOutActor = vtkImageActor::New();
  shiftScale=vtkImageShiftScale ::New();
  filter = FilterType::New();
}


CBinaryThresholdDlg::~CBinaryThresholdDlg()
{
  reader->Delete();
  connector->Delete();
  ren1->Delete();
  ren2->Delete();
  renWin->Delete();
  iren->Delete();
  imageInActor->Delete();
  imageOutActor->Delete();
  shiftScale->Delete();
  filter->Delete();
}



void CBinaryThresholdDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CBinaryThresholdDlg)
 DDX_Control(pDX, IDC_SLIDEROUTSIDEOUTPUT, m_SliderOutsideOutput);
 DDX_Control(pDX, IDC_SLIDEROUTSIDEINPUT, m_SliderInsideOutput);
 DDX_Control(pDX, IDC_SLIDERINSIDEOUTPUT, m_SliderOutsideInput);
 DDX_Control(pDX, IDC_SLIDERINSIDEINPUT, m_SliderInsideInput);
 DDX_Control(pDX, IDC_SPINOUTSIDEOUTPUT, m_SpinOutsideOutput);
 DDX_Control(pDX, IDC_SPINOUTSIDEINPUT, m_SpinInsideOutput);
 DDX_Control(pDX, IDC_SPININSIDEOUTPUT, m_SpinOutsideInput);
 DDX_Control(pDX, IDC_SPININSIDEINPUT, m_SpinInsideInput);
 //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBinaryThresholdDlg, CDialog)
 //{{AFX_MSG_MAP(CBinaryThresholdDlg)
 ON_BN_CLICKED(IDC_LOAD, OnLoad)
 ON_WM_CREATE()
 ON_WM_PAINT()
 ON_WM_HSCROLL()
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBinaryThresholdDlg message handlers

void CBinaryThresholdDlg::OnLoad() 
{  // this code is called when the load button is pushed

 // TODO: Add your control notification handler code here
  reader->SetFileName("brain.png");

  this->ren1->SetViewport(0.0,0.0,0.5,0.5);
  this->ren1->SetBackground(0.2,0.3,0.3); 

  this->ren2->SetViewport(0.5,0.0,1.0,0.5);
  this->ren2->SetBackground(0.4,0.5,0.6); 

  this->connector->SetInput(this->reader->GetOutput());    
  this->shiftScale->SetInput(this->connector->GetOutput());
  this->shiftScale->SetOutputScalarTypeToUnsignedChar();
  this->imageInActor->SetInput(this->shiftScale->GetOutput());
  
  // Actors are added to the renderer. 
  this->ren1->AddActor(this->imageInActor);
  this->ren2->AddActor(this->imageOutActor);

  //writer->SetInput( filter->GetOutput() );
  this->renWin->AddRenderer(this->ren1);
  this->renWin->AddRenderer(this->ren2);
  //this->iren->SetRenderWindow(this->renWin);

  renWin->Render();
}

int CBinaryThresholdDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
 if (CDialog::OnCreate(lpCreateStruct) == -1)
  return -1;
 
  // setup the parent window
  this->renWin->SetParentId(this->m_hWnd);
  this->renWin->SetPosition(250,0);
  this->renWin->SetSize(1024,1024);
  return 0;
}


void CBinaryThresholdDlg::OnPaint() 
{
 CPaintDC dc(this); // device context for painting
 
 // TODO: Add your message handler code here
 
 // Do not call CDialog::OnPaint() for painting messages
  this->filter->SetInput(this->reader->GetOutput() );
  this->filter->SetOutsideValue(outsideValue );
  this->filter->SetInsideValue(insideValue  );
  this->filter->SetLowerThreshold(lowerThreshold );
  this->filter->SetUpperThreshold(upperThreshold );
  //this->filter->Update();

  this->connector->SetInput(this->filter->GetOutput());    
  this->shiftScale->SetInput(this->connector->GetOutput());
  this->shiftScale->SetOutputScalarTypeToUnsignedChar();
  this->imageOutActor->SetInput(this->shiftScale->GetOutput());

  this->renWin->Render();

}

BOOL CBinaryThresholdDlg::OnInitDialog() 
{
 CDialog::OnInitDialog();
 
 // TODO: Add extra initialization here
 m_SpinInsideInput.SetRange(0,255);
 m_SpinOutsideInput.SetRange(0,255);
 m_SpinInsideOutput.SetRange(0,255);
 m_SpinOutsideOutput.SetRange(0,255);

 m_SliderInsideInput.SetRange(0,255);
 m_SliderOutsideInput.SetRange(0,255);
 m_SliderInsideOutput.SetRange(0,255);
 m_SliderOutsideOutput.SetRange(0,255);

 m_SliderInsideInput.SetPos(0);
 m_SliderOutsideInput.SetPos(255);
 m_SliderInsideOutput.SetPos(0);
 m_SliderOutsideOutput.SetPos(255);


 return TRUE;  // return TRUE unless you set the focus to a control
               // EXCEPTION: OCX Property Pages should return FALSE
}

void CBinaryThresholdDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
 // TODO: Add your message handler code here and/or call default
   lowerThreshold = m_SliderInsideInput.GetPos();
 upperThreshold = m_SliderOutsideInput.GetPos();
 insideValue    = m_SliderInsideOutput.GetPos();
 outsideValue   = m_SliderOutsideOutput.GetPos();
 InvalidateRect(NULL,FALSE);

 CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040615/f9fe65c6/attachment.htm>


More information about the vtkusers mailing list