<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
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:<br>
128 piecewiseFunction->Delete();<br>
(gdb) <br>
129 colorTransferFunction->Delete();<br>
(gdb) <br>
130 volumeProperty->Delete();<br>
(gdb) <br>
131 compositeFunction->Delete();<br>
(gdb) <br>
132 volumeMapper->Delete();<br>
(gdb) <br>
133 volume->Delete();<br>
(gdb) <br>
134 ren->Delete();<br>
(gdb) <br>
135 renWin->Delete();<br>
(gdb) <br>
136 iren->Delete();<br>
(gdb) <br>
61 FilterType::Pointer connect = FilterType::New();<br>
(gdb) <br>
54 FileNamesContainerDICOMFiles fileNamesDICOMFiles; <br>
(gdb) <br>
51 NamesGeneratorType::Pointer nameGenerator =
NamesGeneratorType::New();<br>
(gdb) <br>
48 ImageIOType::Pointer dicomIO = ImageIOType::New();<br>
(gdb) <br>
46 ReaderTypeDICOMFiles::Pointer readerDICOMFiles =
ReaderTypeDICOMFiles::New();<br>
(gdb) <br>
136 iren->Delete();<br>
(gdb) <br>
138 }<br>
<br>
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:<br>
<br>
typedef itk::Image<unsigned char, 3> ImageTypeDICOMFiles; <br>
typedef std::vector<std::string> FileNamesContainerDICOMFiles;<br>
typedef itk::ImageSeriesReader<ImageTypeDICOMFiles>
ReaderTypeDICOMFiles;<br>
typedef itk::GDCMSeriesFileNames NamesGeneratorType;<br>
typedef itk::GDCMImageIO ImageIOType;<br>
typedef itk::ImageToVTKImageFilter<ImageTypeDICOMFiles>
ConnectorType;<br>
<br>
int main()<br>
{<br>
std::string path = "/home/vinllen/code/itk_vtk/nlm/data";<br>
ReaderTypeDICOMFiles::Pointer readerDICOMFiles =
ReaderTypeDICOMFiles::New();<br>
<br>
ImageIOType::Pointer dicomIO = ImageIOType::New();<br>
readerDICOMFiles->SetImageIO(dicomIO);<br>
<br>
NamesGeneratorType::Pointer nameGenerator =
NamesGeneratorType::New();<br>
nameGenerator->SetInputDirectory(path);<br>
<br>
FileNamesContainerDICOMFiles fileNamesDICOMFiles; <br>
fileNamesDICOMFiles = nameGenerator->GetInputFileNames();<br>
<br>
readerDICOMFiles->SetFileNames(fileNamesDICOMFiles);<br>
readerDICOMFiles->Update();<br>
<br>
typedef itk::ImageToVTKImageFilter<ImageTypeDICOMFiles>
FilterType ; <br>
FilterType::Pointer connect = FilterType::New();<br>
connect->SetInput(readerDICOMFiles->GetOutput());<br>
connect->Update();<br>
<br>
vtkImageData *imageData = vtkImageData::New();<br>
imageData = connect->GetOutput();<br>
<br>
vtkImageCast *cast = vtkImageCast::New();<br>
cast->SetInputData(imageData);<br>
cast->ClampOverflowOn();<br>
cast->SetOutputScalarTypeToUnsignedShort();<br>
cast->Update();<br>
<br>
vtkPiecewiseFunction * piecewiseFunction =
vtkPiecewiseFunction::New();<br>
piecewiseFunction->RemoveAllPoints();<br>
piecewiseFunction->AddPoint(0,0.0);<br>
piecewiseFunction->AddPoint(255, 1);<br>
<br>
vtkColorTransferFunction *colorTransferFunction =
vtkColorTransferFunction::New();<br>
colorTransferFunction->RemoveAllPoints();<br>
colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);<br>
colorTransferFunction->AddRGBPoint(255, 1.0, 1.0, 1.0);<br>
<br>
vtkVolumeProperty * volumeProperty = vtkVolumeProperty::New();<br>
volumeProperty->SetScalarOpacity(piecewiseFunction);<br>
volumeProperty->SetColor(colorTransferFunction);<br>
volumeProperty->ShadeOff();<br>
volumeProperty->SetInterpolationTypeToLinear();<br>
<br>
<br>
vtkVolumeRayCastCompositeFunction * compositeFunction =
vtkVolumeRayCastCompositeFunction::New();<br>
vtkVolumeRayCastMapper * volumeMapper =
vtkVolumeRayCastMapper::New();<br>
volumeMapper->SetVolumeRayCastFunction(compositeFunction);<br>
volumeMapper->SetInputData(cast->GetOutput());<br>
volumeMapper->Update();<br>
<br>
vtkVolume * volume = vtkVolume::New();<br>
volume->SetMapper(volumeMapper);<br>
volume->SetProperty(volumeProperty);<br>
<br>
vtkRenderer * ren = vtkRenderer::New();<br>
vtkRenderWindow * renWin = vtkRenderWindow::New();<br>
vtkRenderWindowInteractor * iren =
vtkRenderWindowInteractor::New();<br>
<br>
ren->AddVolume(volume);<br>
renWin->AddRenderer(ren);<br>
renWin->SetInteractor(iren);<br>
ren->SetBackground(0, 0, 0);<br>
renWin->SetSize(600,600);<br>
renWin->Render();<br>
iren->Initialize();<br>
iren->Start();<br>
<br>
piecewiseFunction->Delete();<br>
colorTransferFunction->Delete();<br>
volumeProperty->Delete();<br>
compositeFunction->Delete();<br>
volumeMapper->Delete();<br>
volume->Delete();<br>
ren->Delete();<br>
renWin->Delete();<br>
iren->Delete();<br>
<br>
}<br>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</body>
</html>