[Insight-users] ResampleImageFilter crashes in release mode
Michael Schildt
michael.schildt at ifn-magdeburg.de
Mon Jul 6 05:39:51 EDT 2009
Hello Luis,
I checked your points 1) and 3) to 5) but had no luck.
But with 2) i have tracked down the problem to be an interplay of ITK
and wxWidgets and found a workaround too.
Basically, when i use an wxSplitterWindow ITK crashes, when commenting
the wxSlitterWindow stuff out ITK works as expected. I used ITK 3.14,
wxPack 2.8.9 and Visual Studio 2008 Express Edition.
I have created a minimal example application (main.cpp, CMakeLists.txt)
attched at the end of the message that makes this problem reproducable
without additional dependencies. Running in Release or RelWithDebInfo
will crash under Windows XP at resampler->Update(). Commenting out line
36 (m_splitter2 = new wxSplitterWindow( this, wxID_ANY,
wxDefaultPosition, wxDefaultSize, 0 );) will make ITK running smooth
without a crash.
And, a workaround was found while trying program on an other PC. By
using wxPack 2.8.8 instead of wxPack 2.8.9 the problem is gone. So, a
downgrade to prior minor Version of wxWidgets is sufficient.
But, i have not really an exmplaination for that. Especially the fact
that the splitter in not instanciated before ITK runs. Would be nice to
find how wxWidgets influences ITK!
Best reguards,
Michael Schildt
///////////////////////////////////////////////////////////// main.cpp
//////////////////////////////////////////////////////////
#include "wx/wx.h"
#include <wx/splitter.h>
#include "itkImage.h"
#include "itkArray.h"
#include "itkPoint.h"
#include "itkImportImageFilter.h"
#include "itkImageFileWriter.h"
#include "itkResampleImageFilter.h"
#include "itkLinearInterpolateImageFunction.h"
#include "itkVersorRigid3DTransform.h"
#include "itkRigid3DTransform.h"
#include "itkAffineTransform.h"
#include "itkCommand.h"
#include <math.h>
#include <sstream>
#include <fstream>
#include <stdio.h>
class brainPanel : public wxPanel
{
public:
brainPanel( wxWindow* parent )
: wxPanel( parent ) {
}
~brainPanel() {}
};
class brainFrame : public wxFrame
{
public:
brainFrame( wxWindow *parent = NULL, int id = -1 )
: wxFrame( parent, id , wxT("Test"), wxDefaultPosition, wxDefaultSize)
{
m_splitter2 = new wxSplitterWindow( this, wxID_ANY,
wxDefaultPosition, wxDefaultSize, 0 );
}
~brainFrame()
{
}
protected:
wxSplitterWindow* m_splitter2;
};
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
template<typename dType> typename itk::Image<dType,3>::Pointer
dataInterface2itk()
{
typedef itk::Image<dType,3> Image3DType;
typename Image3DType::Pointer image = Image3DType::New();
typedef itk::ImportImageFilter<dType,3> ImportFilterImage3DType;
typename ImportFilterImage3DType::Pointer import =
ImportFilterImage3DType::New();
typename ImportFilterImage3DType::SizeType size;
size[0] = 256;
size[1] = 256;
size[2] = 256;
typename ImportFilterImage3DType::IndexType start;
start.Fill( 0 );
typename ImportFilterImage3DType::RegionType region;
region.SetIndex( start );
region.SetSize( size );
import->SetRegion( region );
double spacing[ 3 ];
// hier sollte noch das gap mit beachtet werden, welches es nicht in
itk gibt
spacing[0] = 1.0;
spacing[1] = 1.0;
spacing[2] = 1.0;
import->SetSpacing( spacing );
double origin[ 3 ];
origin[0] = 0.0;
origin[1] = 0.0;
origin[2] = 0.0;
import->SetOrigin( origin );
const unsigned int numberOfPixels = 16777216; // diImage->getSize();
dType* data = new dType[numberOfPixels]; // diImage->getData();
import->SetImportPointer( data, numberOfPixels, false );
import->Update();
return import->GetOutput();
}
typedef itk::Image<float,3> FloatImage3DType;
template <typename dataT, typename TrfType>
typename itk::Image<dataT,3>::Pointer transformImage(typename
itk::Image<dataT,3>::Pointer fixedIm,
typename
itk::Image<dataT,3>::Pointer movingIm,
typename
TrfType::ConstPointer transform)
{
//std::ofstream fout("c:\\temp\\fout.txt");
//fout << "--------------------------- fixedIm
-------------------------------" << std::endl << fixedIm << std::endl;
//fout << "--------------------------- movingIm
------------------------------" << std::endl << movingIm << std::endl;
//fout.flush();
//fout.close();
//itk::ImageFileWriter<FloatImage3DType>::Pointer writerfixedImage;
//writerfixedImage = itk::ImageFileWriter<FloatImage3DType>::New();
//writerfixedImage->SetInput (fixedIm);
//writerfixedImage->SetFileName( "c:\\temp\\fixedImage.hdr" );
//writerfixedImage->Update();
//itk::ImageFileWriter<FloatImage3DType>::Pointer writermovingImage;
//writermovingImage = itk::ImageFileWriter<FloatImage3DType>::New();
//writermovingImage->SetInput (movingIm);
//writermovingImage->SetFileName( "c:\\temp\\movingImage.hdr" );
//writermovingImage->Update();
typedef itk::Image<dataT, 3> ImageType;
typedef TrfType TransformType;
typedef itk::LinearInterpolateImageFunction<ImageType,double>
InterpolatorType;
typedef itk::ResampleImageFilter<ImageType,ImageType> ResamplerType;
typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
typename ResamplerType::Pointer resampler = ResamplerType::New();
resampler->SetInput( movingIm );
resampler->SetTransform( transform );
resampler->SetInterpolator( interpolator );
resampler->SetSize( fixedIm->GetLargestPossibleRegion().GetSize() );
resampler->SetOutputOrigin( fixedIm->GetOrigin() );
resampler->SetOutputSpacing( fixedIm->GetSpacing() );
resampler->SetDefaultPixelValue( 0 );
resampler->Update();
//fout.open("c:\\temp\\fout.txt",std::ios_base::app);
//fout << "--------------------------- resampler
------------------------------" << std::endl << resampler << std::endl;
//fout.flush();
//fout.close();
return resampler->GetOutput();
}
void itkTest() {
FloatImage3DType::Pointer fixedImage = dataInterface2itk<float>();
FloatImage3DType::Pointer movingImage = dataInterface2itk<float>();
typedef itk::VersorRigid3DTransform< double > TransformType;
TransformType::ParametersType finalParameters;
finalParameters.SetSize(6);
finalParameters[0] = 0.0174496;
finalParameters[1] = -0.000605184;
finalParameters[2] = -0.034913;
finalParameters[3] = 6.07665;
finalParameters[4] = 29.5602;
finalParameters[5] = 3.04588;
TransformType::Pointer versor = TransformType::New();
versor->SetParameters(finalParameters);
TransformType::Pointer iversor = TransformType::New();
if (!versor->GetInverse(iversor)) {
std::cout << "Could not inverse transform";
assert(false);
}
finalParameters = iversor->GetParameters();
FloatImage3DType::Pointer outIm;
TransformType::ConstPointer cversor = iversor;
outIm = transformImage<float,TransformType>(fixedImage, movingImage,
cversor);
}
IMPLEMENT_APP( MyApp );
bool MyApp::OnInit()
{
itkTest();
brainFrame* frame = new brainFrame();
frame->Centre();
frame->Show();
return true;
}
/////////////////////////////////////// CMakeLists.txt
///////////////////////////////////////////////////////////////
More information about the Insight-users
mailing list