<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi All</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>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. </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I have some question:</FONT></DIV>
<DIV><FONT face=Arial size=2>1. Why after I close the dialog, there is an error
occurs? When I trace, it goes to smartpointer source .... </FONT></DIV>
<DIV><FONT face=Arial size=2>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. </FONT></DIV>
<DIV><FONT face=Arial size=2>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.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Thank you in advance</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Greeting</FONT></DIV>
<DIV><FONT face=Arial size=2>Paulus</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>// BinaryThresholdDlg.h : Header
file<BR></DIV></FONT><FONT face=Arial size=2></FONT>
<DIV><FONT face=Arial size=2>#if
!defined(AFX_BINARYTHRESHOLDDLG1_H__2D2E73F5_F350_4BC6_A757_586AE2651DBF__INCLUDED_)<BR>#define
AFX_BINARYTHRESHOLDDLG1_H__2D2E73F5_F350_4BC6_A757_586AE2651DBF__INCLUDED_</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>#if _MSC_VER > 1000<BR>#pragma once<BR>#endif //
_MSC_VER > 1000</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>//itk and vtk <BR>#include
"itkBinaryThresholdImageFilter.h"<BR>#include "itkImage.h"<BR>#include
"itkImageFileReader.h"<BR>#include "vtkImageActor.h"<BR>#include
"vtkImageViewer.h"<BR>#include "vtkRenderer.h"<BR>#include
"vtkRenderWindow.h"<BR>#include "vtkRenderWindowInteractor.h"<BR>#include
"itkImageToVTKImageFilter.h"<BR>#include "vtkImageShiftScale.h"</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>//#define Dimension 2</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV><FONT face=Arial size=2>
<DIV><BR>// BinaryThresholdDlg1.h : header file<BR>//</DIV>
<DIV> </DIV>
<DIV>/////////////////////////////////////////////////////////////////////////////<BR>//
CBinaryThresholdDlg dialog</DIV>
<DIV> </DIV>
<DIV>class CBinaryThresholdDlg : public CDialog<BR>{<BR>//
Construction<BR>public:<BR> CBinaryThresholdDlg(CWnd* pParent =
NULL); // standard
constructor<BR> //~CBinaryThresholdDlg(); // standard
destructor</DIV>
<DIV> </DIV>
<DIV> typedef int integer;<BR> typedef unsigned
short PixelType;</DIV>
<DIV> </DIV>
<DIV> typedef unsigned char InputPixelType;<BR>
typedef unsigned char OutputPixelType;<BR> typedef
itk::Image< InputPixelType, 2 >
InputImageType;<BR> typedef itk::Image< OutputPixelType, 2
> OutputImageType;<BR> typedef
itk::BinaryThresholdImageFilter<InputImageType, OutputImageType >
FilterType;<BR> typedef itk::ImageFileReader< InputImageType >
ReaderType;<BR> typedef itk::ImageToVTKImageFilter< InputImageType >
ConnectorType;</DIV>
<DIV> </DIV>
<DIV> ReaderType::Pointer reader;<BR> ConnectorType::Pointer
connector;</DIV>
<DIV> </DIV>
<DIV> vtkRenderer *ren1,*ren2;<BR> vtkRenderWindow
*renWin;<BR> vtkRenderWindowInteractor *iren;<BR> vtkImageActor
*imageInActor,*imageOutActor;<BR> vtkImageShiftScale
*shiftScale;</DIV>
<DIV> </DIV>
<DIV> OutputPixelType outsideValue;<BR> OutputPixelType
insideValue;<BR> InputPixelType lowerThreshold;<BR> InputPixelType
upperThreshold;<BR> FilterType::Pointer filter; <BR></DIV>
<DIV>// Dialog Data<BR> //{{AFX_DATA(CBinaryThresholdDlg)<BR> enum {
IDD = IDD_BYNARYTHRESHOLDDLG
};<BR> CSliderCtrl m_SliderOutsideOutput;<BR> CSliderCtrl m_SliderInsideOutput;<BR> CSliderCtrl m_SliderOutsideInput;<BR> CSliderCtrl m_SliderInsideInput;<BR> CSpinButtonCtrl m_SpinOutsideOutput;<BR> CSpinButtonCtrl m_SpinInsideOutput;<BR> CSpinButtonCtrl m_SpinOutsideInput;<BR> CSpinButtonCtrl m_SpinInsideInput;<BR> CEdit m_fileName;<BR> //}}AFX_DATA</DIV>
<DIV> </DIV>
<DIV><BR>// Overrides<BR> // ClassWizard generated virtual function
overrides<BR> //{{AFX_VIRTUAL(CBinaryThresholdDlg)<BR> protected:<BR> virtual
void DoDataExchange(CDataExchange* pDX); // DDX/DDV
support<BR> //}}AFX_VIRTUAL</DIV>
<DIV> </DIV>
<DIV>// Implementation</DIV>
<DIV> </DIV>
<DIV>protected:</DIV>
<DIV> </DIV>
<DIV> // Generated message map
functions<BR> //{{AFX_MSG(CBinaryThresholdDlg)<BR> afx_msg void
OnLoad();<BR> afx_msg int OnCreate(LPCREATESTRUCT
lpCreateStruct);<BR> afx_msg void OnPaint();<BR> virtual BOOL
OnInitDialog();<BR> afx_msg void OnHScroll(UINT nSBCode, UINT nPos,
CScrollBar*
pScrollBar);<BR> //}}AFX_MSG<BR> DECLARE_MESSAGE_MAP()<BR>};</DIV>
<DIV> </DIV>
<DIV>//{{AFX_INSERT_LOCATION}}<BR>// Microsoft Visual C++ will insert additional
declarations immediately before the previous line.</DIV>
<DIV> </DIV>
<DIV>#endif //
!defined(AFX_BINARYTHRESHOLDDLG1_H__2D2E73F5_F350_4BC6_A757_586AE2651DBF__INCLUDED_)<BR></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>// BinaryThresholdDlg.cpp : implementation file<BR>//</DIV>
<DIV> </DIV>
<DIV>#include "resource.h"<BR>#include "stdafx.h"<BR>#include
"Uias3D.h"<BR>#include "BinaryThresholdDlg.h"</DIV>
<DIV> </DIV>
<DIV>#ifdef _DEBUG<BR>#define new DEBUG_NEW<BR>#undef THIS_FILE<BR>static char
THIS_FILE[] = __FILE__;<BR>#endif</DIV>
<DIV> </DIV>
<DIV>/////////////////////////////////////////////////////////////////////////////<BR>//
CBinaryThresholdDlg dialog</DIV>
<DIV> </DIV>
<DIV><BR>CBinaryThresholdDlg::CBinaryThresholdDlg(CWnd* pParent
/*=NULL*/)<BR> : CDialog(CBinaryThresholdDlg::IDD,
pParent)<BR>{<BR> //{{AFX_DATA_INIT(CBinaryThresholdDlg)<BR> //}}AFX_DATA_INIT<BR>
reader = ReaderType::New();<BR> connector =
ConnectorType::New();<BR> ren1 = vtkRenderer::New();<BR> ren2 =
vtkRenderer::New();<BR> renWin = vtkRenderWindow::New();<BR> iren =
vtkRenderWindowInteractor::New();<BR> imageInActor =
vtkImageActor::New();<BR> imageOutActor = vtkImageActor::New();<BR>
shiftScale=vtkImageShiftScale ::New();<BR> filter =
FilterType::New();<BR>}</DIV>
<DIV> </DIV>
<DIV><BR>CBinaryThresholdDlg::~CBinaryThresholdDlg()<BR>{<BR>
reader->Delete();<BR> connector->Delete();<BR>
ren1->Delete();<BR> ren2->Delete();<BR>
renWin->Delete();<BR> iren->Delete();<BR>
imageInActor->Delete();<BR> imageOutActor->Delete();<BR>
shiftScale->Delete();<BR> filter->Delete();<BR>}</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>void CBinaryThresholdDlg::DoDataExchange(CDataExchange*
pDX)<BR>{<BR> CDialog::DoDataExchange(pDX);<BR> //{{AFX_DATA_MAP(CBinaryThresholdDlg)<BR> DDX_Control(pDX,
IDC_SLIDEROUTSIDEOUTPUT, m_SliderOutsideOutput);<BR> DDX_Control(pDX,
IDC_SLIDEROUTSIDEINPUT, m_SliderInsideOutput);<BR> DDX_Control(pDX,
IDC_SLIDERINSIDEOUTPUT, m_SliderOutsideInput);<BR> DDX_Control(pDX,
IDC_SLIDERINSIDEINPUT, m_SliderInsideInput);<BR> DDX_Control(pDX,
IDC_SPINOUTSIDEOUTPUT, m_SpinOutsideOutput);<BR> DDX_Control(pDX,
IDC_SPINOUTSIDEINPUT, m_SpinInsideOutput);<BR> DDX_Control(pDX,
IDC_SPININSIDEOUTPUT, m_SpinOutsideInput);<BR> DDX_Control(pDX,
IDC_SPININSIDEINPUT, m_SpinInsideInput);<BR> //}}AFX_DATA_MAP<BR>}</DIV>
<DIV> </DIV>
<DIV><BR>BEGIN_MESSAGE_MAP(CBinaryThresholdDlg,
CDialog)<BR> //{{AFX_MSG_MAP(CBinaryThresholdDlg)<BR> ON_BN_CLICKED(IDC_LOAD,
OnLoad)<BR> ON_WM_CREATE()<BR> ON_WM_PAINT()<BR> ON_WM_HSCROLL()<BR> //}}AFX_MSG_MAP<BR>END_MESSAGE_MAP()</DIV>
<DIV> </DIV>
<DIV>/////////////////////////////////////////////////////////////////////////////<BR>//
CBinaryThresholdDlg message handlers</DIV>
<DIV> </DIV>
<DIV>void CBinaryThresholdDlg::OnLoad() <BR>{ // this code is called
when the load button is pushed</DIV>
<DIV><BR> // TODO: Add your control notification handler code
here<BR> reader->SetFileName("brain.png");<BR></DIV>
<DIV> this->ren1->SetViewport(0.0,0.0,0.5,0.5);<BR>
this->ren1->SetBackground(0.2,0.3,0.3); </DIV>
<DIV> </DIV>
<DIV> this->ren2->SetViewport(0.5,0.0,1.0,0.5);<BR>
this->ren2->SetBackground(0.4,0.5,0.6); </DIV>
<DIV> </DIV>
<DIV> this->connector->SetInput(this->reader->GetOutput());
<BR>
this->shiftScale->SetInput(this->connector->GetOutput());<BR>
this->shiftScale->SetOutputScalarTypeToUnsignedChar();<BR>
this->imageInActor->SetInput(this->shiftScale->GetOutput());<BR> </DIV>
<DIV> // Actors are added to the renderer. <BR>
this->ren1->AddActor(this->imageInActor);<BR>
this->ren2->AddActor(this->imageOutActor);</DIV>
<DIV> </DIV>
<DIV> //writer->SetInput( filter->GetOutput() );<BR>
this->renWin->AddRenderer(this->ren1);<BR>
this->renWin->AddRenderer(this->ren2);<BR>
//this->iren->SetRenderWindow(this->renWin);</DIV>
<DIV> </DIV>
<DIV> renWin->Render();<BR>}</DIV>
<DIV> </DIV>
<DIV>int CBinaryThresholdDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
<BR>{<BR> if (CDialog::OnCreate(lpCreateStruct) ==
-1)<BR> return -1;<BR> <BR> // setup the parent
window<BR> this->renWin->SetParentId(this->m_hWnd);<BR>
this->renWin->SetPosition(250,0);<BR>
this->renWin->SetSize(1024,1024);<BR> return 0;<BR>}</DIV>
<DIV> </DIV>
<DIV><BR>void CBinaryThresholdDlg::OnPaint() <BR>{<BR> CPaintDC dc(this);
// device context for painting<BR> <BR> // TODO: Add your message
handler code here<BR> <BR> // Do not call CDialog::OnPaint() for
painting messages<BR>
this->filter->SetInput(this->reader->GetOutput() );<BR>
this->filter->SetOutsideValue(outsideValue );<BR>
this->filter->SetInsideValue(insideValue );<BR>
this->filter->SetLowerThreshold(lowerThreshold );<BR>
this->filter->SetUpperThreshold(upperThreshold );<BR>
//this->filter->Update();</DIV>
<DIV> </DIV>
<DIV> this->connector->SetInput(this->filter->GetOutput());
<BR>
this->shiftScale->SetInput(this->connector->GetOutput());<BR>
this->shiftScale->SetOutputScalarTypeToUnsignedChar();<BR>
this->imageOutActor->SetInput(this->shiftScale->GetOutput());</DIV>
<DIV> </DIV>
<DIV> this->renWin->Render();</DIV>
<DIV> </DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV>BOOL CBinaryThresholdDlg::OnInitDialog()
<BR>{<BR> CDialog::OnInitDialog();<BR> <BR> // TODO: Add extra
initialization
here<BR> m_SpinInsideInput.SetRange(0,255);<BR> m_SpinOutsideInput.SetRange(0,255);<BR> m_SpinInsideOutput.SetRange(0,255);<BR> m_SpinOutsideOutput.SetRange(0,255);</DIV>
<DIV> </DIV>
<DIV> m_SliderInsideInput.SetRange(0,255);<BR> m_SliderOutsideInput.SetRange(0,255);<BR> m_SliderInsideOutput.SetRange(0,255);<BR> m_SliderOutsideOutput.SetRange(0,255);</DIV>
<DIV> </DIV>
<DIV> m_SliderInsideInput.SetPos(0);<BR> m_SliderOutsideInput.SetPos(255);<BR> m_SliderInsideOutput.SetPos(0);<BR> m_SliderOutsideOutput.SetPos(255);</DIV>
<DIV> </DIV>
<DIV><BR> return TRUE; // return TRUE unless you set the focus to a
control<BR>
// EXCEPTION: OCX Property Pages should return FALSE<BR>}</DIV>
<DIV> </DIV>
<DIV>void CBinaryThresholdDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*
pScrollBar) <BR>{<BR> // TODO: Add your message handler code here and/or
call default<BR> lowerThreshold =
m_SliderInsideInput.GetPos();<BR> upperThreshold =
m_SliderOutsideInput.GetPos();<BR> insideValue =
m_SliderInsideOutput.GetPos();<BR> outsideValue =
m_SliderOutsideOutput.GetPos();<BR> InvalidateRect(NULL,FALSE);</DIV>
<DIV> </DIV>
<DIV> CDialog::OnHScroll(nSBCode, nPos,
pScrollBar);<BR>}<BR></DIV></FONT></BODY></HTML>