[vtkusers] Memory leaks

janavas josenavasmolina at hotmail.com
Wed Dec 21 14:29:06 EST 2011


Hi Alex!!

Your solution works fine!! Thank you.

Another quastion related to this topic is if I can do the same if it is a
vtkImageData. Here's my code:

typedef itk::ImageToVTKImageFilter<ImageType> ConnectorItkToVtkType;
ConnectorItkToVtkType::Pointer itkConnectorItkToVtk_;
vtkImageData* loadWashed3DImage(const std::string &filename, QStatusBar *
/*statusBar*/)
{
	cout << "Loading " << filename << "..." << endl;

	vtkTimerLog* timer = vtkTimerLog::New();
	timer->StartTimer();

	typedef itk::ImageFileReader< ImageType > ReaderType;
	ReaderType::Pointer itkReader = ReaderType::New();

	itkConnectorItkToVtk_ = ConnectorItkToVtkType::New();

	typedef itk::FlipImageFilter< ImageType >  FilterType;
	FilterType::Pointer flipper = FilterType::New();

	typedef FilterType::FlipAxesArrayType FlipAxesArrayType;
	FlipAxesArrayType flipArray;

	flipArray[0] = false;
	flipArray[1] = true;
	flipArray[2] = false;

	flipper->SetFlipAxes( flipArray );

	typedef itk::ChangeInformationImageFilter< ImageType > ChangeInfoType;
	ChangeInfoType::Pointer changeInfo = ChangeInfoType::New();
	ImageType::PointType newOrigin;
	newOrigin[0] = newOrigin[1] = newOrigin[2] = 0;
	changeInfo->SetOutputOrigin( newOrigin );
	changeInfo->ChangeOriginOn();

	itkReader->SetFileName(filename.c_str());

	flipper->SetInput( itkReader->GetOutput() );
	changeInfo->SetInput( flipper->GetOutput() );
	itkConnectorItkToVtk_->GetExporter()->SetInput( changeInfo->GetOutput() );
	itkConnectorItkToVtk_->GetImporter()->Update();
	try
	{
		itkReader->Update();
	}
	catch( itk::ExceptionObject & err ) 
	{ 
		cout << "ExceptionObject caught!\n" << err << endl; 
		return NULL;
	}
	vtkImageData* imgWashedData_ =
itkConnectorItkToVtk_->GetImporter()->GetOutput();

	timer->StopTimer();

	cout << "Loaded.[ Time: " << timer->GetElapsedTime() << " seconds ]" <<
endl;
	timer->Delete();

	return imgWashedData_;
}

I tried to do this (and making itkConnectorItkToVtk_ local):

vtkImageData* imgWashedData_ =
itkConnectorItkToVtk_->GetImporter()->GetOutput();
imgWashedData_->Register(NULL);
imgWashedData_->SetSource(NULL);
timer->StopTimer();

I didn't add the Delete() calls because itk is using itkSmartPointers and if
I add this calls the application crash.


But my app directly crash when I tried to do something with
imgWashedData_...

Thank you for your help

Jose

--
View this message in context: http://vtk.1045678.n5.nabble.com/Memory-leaks-tp5037946p5092707.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list