我是ITK,VTK和Qt的初学者。我使用visual studio 9。 我正在尝试用ITK阅读DICOM系列,并在QVTKWidget(Qt)中使用VTK进行显示。我基于此代码http://www.itk.org/Wiki/VTK/Examples/Cxx/IO/ReadDICOMSeries,并根据我的需要进行了修改。
当我用VTK阅读DICOM系列并在QVTKWidget中显示它时,它可以工作,但是当我想用ITK阅读这个系列并在QVTKWidget中用VTK显示时,程序会显示系列的第一个图像,当我转到使用鼠标滚轮的下一个图像,程序崩溃。
当我调试时,我收到了这个错误:
void VTKImageExportBase::UpdateInformationCallbackFunction(void *userData)
{
static_cast< VTKImageExportBase * >
( userData )->UpdateInformationCallback();//the error is here
}
我尝试了ausssi ImageToVTKImageFilter类,但遇到了同样的问题。
这是我的代码:
void essaieAppQtVTK::drawDCMSeries(std::string folderDCM)
{
typedef unsigned short PixelType;
const unsigned int Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::VTKImageExport<ImageType> ImageExportType;
typedef itk::ImageSeriesReader< ImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer dicomIO = ImageIOType::New();
reader->SetImageIO( dicomIO );
typedef itk::GDCMSeriesFileNames NamesGeneratorType;
NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
nameGenerator->SetUseSeriesDetails( true );
nameGenerator->AddSeriesRestriction("0008|0021" );
nameGenerator->SetDirectory( folderDCM);
typedef std::vector< std::string > SeriesIdContainer;
const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
std::cout << seriesUID.size() << std::endl;
SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
while( seriesItr != seriesEnd )
{
std::cout << seriesItr->c_str() << std::endl;
seriesItr++;
}
std::string seriesIdentifier;
seriesIdentifier = seriesUID.begin()->c_str();
std::cout << seriesIdentifier.c_str() << std::endl;
typedef std::vector< std::string > FileNamesContainer;
FileNamesContainer fileNames;
fileNames = nameGenerator->GetFileNames( seriesIdentifier );
reader->SetFileNames( fileNames );
try
{
reader->Update();
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex << std::endl;
}
//------------------------------------------------------------------------
// ITK to VTK pipeline connection.
//------------------------------------------------------------------------
// Create the itk::VTKImageExport instance and connect it to the
// itk::CurvatureFlowImageFilter.
ImageExportType::Pointer exporter = ImageExportType::New();
exporter->SetInput(reader->GetOutput());
// Create the vtkImageImport and connect it to the
// itk::VTKImageExport instance.
vtkImageImport* importer = vtkImageImport::New();
ConnectPipelines(exporter, importer);
//------------------------------------------------------------------------
// VTK pipeline.
//------------------------------------------------------------------------
this->imageViewer= vtkImageViewer2::New();
imageViewer->SetInput(importer->GetOutput());
// slice status message
//******same code *****//
// usage hint message
//******same code *****//
// create an interactor with our own style (inherit from vtkInteractorStyleImage)
// in order to catch mousewheel and key events
//******same code *****//
// add slice status message and usage hint message to the renderer
//******same code *****//
//to display the result:
ui.qvtkWidget->SetRenderWindow(imageViewer->GetRenderWindow());
ui.qvtkWidget->GetRenderWindow()->GetInteractor()- >SetInteractorStyle(myInteractorStyle);
imageViewer->Render();
ui.qvtkWidget->update();
}
可选:我的导出器和导入器如下所示:
template <typename ITK_Exporter, typename VTK_Importer>
void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)
{
importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
importer->SetSpacingCallback(exporter->GetSpacingCallback());
importer->SetOriginCallback(exporter->GetOriginCallback());
importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
importer->SetPropagateUpdateExtentCallback(exporter- >GetPropagateUpdateExtentCallback());
importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
importer->SetCallbackUserData(exporter->GetCallbackUserData());
}
/**
* This function will connect the given vtkImageExport filter to
* the given itk::VTKImageImport filter.
*/
template <typename VTK_Exporter, typename ITK_Importer>
void ConnectPipelines(VTK_Exporter* exporter, ITK_Importer importer)
{
importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
importer->SetSpacingCallback(exporter->GetSpacingCallback());
importer->SetOriginCallback(exporter->GetOriginCallback());
importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
importer->SetCallbackUserData(exporter->GetCallbackUserData());
}
也许在ITK和VTK之间的Pipline有一个错误,请帮我找到解决这个问题的方法,我花了两周的时间寻找解决方案,但是所有的方法都失败了,也许还有另一种方法可以绑定ITK和VTK分开ImageToVTKImageFilter类。我指望你的帮助。提前谢谢你。
答案 0 :(得分:1)
我在使用VTKImageExportBase::UpdateInformationCallbackFunction
转换的ImageToVTKImageFilter
函数中显示的同一点上遇到了同样的错误。我缺少的是在将其连接到VTK查看器之前更新ITK管道。在ITK to VTK pipeline connection
部分,您的代码也缺少相同的内容。所以使用:
exporter->SetInput(reader->GetOutput());
exporter->Update();
然后继续前进。