[vtkusers] Why does function exit automatic call itk again?

cvinllen cvinllen at gmail.com
Fri Dec 26 21:19:05 EST 2014


I write a simple code : use itk to read dicom serise and use vtk to 
visualize. But when i use gdb to debug, some strange thing happen:
128        piecewiseFunction->Delete();
(gdb)
129        colorTransferFunction->Delete();
(gdb)
130        volumeProperty->Delete();
(gdb)
131        compositeFunction->Delete();
(gdb)
132        volumeMapper->Delete();
(gdb)
133        volume->Delete();
(gdb)
134        ren->Delete();
(gdb)
135        renWin->Delete();
(gdb)
136        iren->Delete();
(gdb)
61        FilterType::Pointer connect = FilterType::New();
(gdb)
54        FileNamesContainerDICOMFiles fileNamesDICOMFiles;
(gdb)
51        NamesGeneratorType::Pointer nameGenerator = 
NamesGeneratorType::New();
(gdb)
48        ImageIOType::Pointer dicomIO = ImageIOType::New();
(gdb)
46        ReaderTypeDICOMFiles::Pointer readerDICOMFiles = 
ReaderTypeDICOMFiles::New();
(gdb)
136        iren->Delete();
(gdb)
138    }

look at the gdb 61 54 48 46, they are itk reader, why the function will 
call this ? Why they run again when main() exit ???? Here comes my code:

typedef itk::Image<unsigned char, 3> ImageTypeDICOMFiles;
typedef std::vector<std::string> FileNamesContainerDICOMFiles;
typedef itk::ImageSeriesReader<ImageTypeDICOMFiles> ReaderTypeDICOMFiles;
typedef itk::GDCMSeriesFileNames  NamesGeneratorType;
typedef itk::GDCMImageIO  ImageIOType;
typedef itk::ImageToVTKImageFilter<ImageTypeDICOMFiles> ConnectorType;

int main()
{
     std::string path = "/home/vinllen/code/itk_vtk/nlm/data";
     ReaderTypeDICOMFiles::Pointer readerDICOMFiles = 
ReaderTypeDICOMFiles::New();

     ImageIOType::Pointer dicomIO = ImageIOType::New();
     readerDICOMFiles->SetImageIO(dicomIO);

     NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
     nameGenerator->SetInputDirectory(path);

     FileNamesContainerDICOMFiles fileNamesDICOMFiles;
     fileNamesDICOMFiles = nameGenerator->GetInputFileNames();

     readerDICOMFiles->SetFileNames(fileNamesDICOMFiles);
     readerDICOMFiles->Update();

     typedef itk::ImageToVTKImageFilter<ImageTypeDICOMFiles> FilterType ;
     FilterType::Pointer connect = FilterType::New();
     connect->SetInput(readerDICOMFiles->GetOutput());
     connect->Update();

     vtkImageData *imageData = vtkImageData::New();
     imageData = connect->GetOutput();

     vtkImageCast *cast = vtkImageCast::New();
     cast->SetInputData(imageData);
     cast->ClampOverflowOn();
     cast->SetOutputScalarTypeToUnsignedShort();
     cast->Update();

     vtkPiecewiseFunction * piecewiseFunction = vtkPiecewiseFunction::New();
     piecewiseFunction->RemoveAllPoints();
     piecewiseFunction->AddPoint(0,0.0);
     piecewiseFunction->AddPoint(255, 1);

     vtkColorTransferFunction *colorTransferFunction = 
vtkColorTransferFunction::New();
     colorTransferFunction->RemoveAllPoints();
     colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
     colorTransferFunction->AddRGBPoint(255, 1.0, 1.0, 1.0);

     vtkVolumeProperty * volumeProperty = vtkVolumeProperty::New();
     volumeProperty->SetScalarOpacity(piecewiseFunction);
     volumeProperty->SetColor(colorTransferFunction);
     volumeProperty->ShadeOff();
     volumeProperty->SetInterpolationTypeToLinear();


     vtkVolumeRayCastCompositeFunction * compositeFunction = 
vtkVolumeRayCastCompositeFunction::New();
     vtkVolumeRayCastMapper * volumeMapper = vtkVolumeRayCastMapper::New();
     volumeMapper->SetVolumeRayCastFunction(compositeFunction);
     volumeMapper->SetInputData(cast->GetOutput());
     volumeMapper->Update();

     vtkVolume * volume = vtkVolume::New();
     volume->SetMapper(volumeMapper);
     volume->SetProperty(volumeProperty);

     vtkRenderer * ren = vtkRenderer::New();
     vtkRenderWindow * renWin = vtkRenderWindow::New();
     vtkRenderWindowInteractor * iren = vtkRenderWindowInteractor::New();

     ren->AddVolume(volume);
     renWin->AddRenderer(ren);
     renWin->SetInteractor(iren);
     ren->SetBackground(0, 0, 0);
     renWin->SetSize(600,600);
     renWin->Render();
     iren->Initialize();
     iren->Start();

     piecewiseFunction->Delete();
     colorTransferFunction->Delete();
     volumeProperty->Delete();
     compositeFunction->Delete();
     volumeMapper->Delete();
     volume->Delete();
     ren->Delete();
     renWin->Delete();
     iren->Delete();

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20141227/dedce519/attachment.html>


More information about the vtkusers mailing list