[Insight-developers] RFC: patch for making itkVTKImageExport and Import more robust
Charl P. Botha
c.p.botha at ewi.tudelft.nl
15 Mar 2004 19:08:52 +0100
--=-7TKMoOiE29C6JS0OvzMG
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Dear developers,
This time, I've actually attached the patch. :)
Thanks,
Charl
--
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/
--=-7TKMoOiE29C6JS0OvzMG
Content-Disposition: attachment; filename=itkVTKImageExportImport20040315.diff
Content-Type: text/x-patch; name=itkVTKImageExportImport20040315.diff; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
diff --exclude=CVS* -urN Insight-1-6/Code/BasicFilters/itkVTKImageExport.txx Insight/Code/BasicFilters/itkVTKImageExport.txx
--- Insight-1-6/Code/BasicFilters/itkVTKImageExport.txx Sat Mar 6 00:11:42 2004
+++ Insight/Code/BasicFilters/itkVTKImageExport.txx Mon Mar 15 17:55:50 2004
at at -116,6 +116,13 at at
int* VTKImageExport<TInputImage>::WholeExtentCallback()
{
InputImagePointer input = this->GetInput();
+ if (!input)
+ {
+ m_WholeExtent[0] = m_WholeExtent[2] = m_WholeExtent[4] = 0;
+ m_WholeExtent[1] = m_WholeExtent[3] = m_WholeExtent[5] = -1;
+ return m_WholeExtent;
+ }
+
InputRegionType region = input->GetLargestPossibleRegion();
InputSizeType size = region.GetSize();
InputIndexType index = region.GetIndex();
at at -145,6 +152,12 at at
double* VTKImageExport<TInputImage>::SpacingCallback()
{
InputImagePointer input = this->GetInput();
+ if (!input)
+ {
+ m_DataSpacing[0] = m_DataSpacing[1] = m_DataSpacing[2] = 0.0;
+ return m_DataSpacing;
+ }
+
const typename TInputImage::SpacingType& spacing = input->GetSpacing();
unsigned int i=0;
at at -169,6 +182,13 at at
float* VTKImageExport<TInputImage>::FloatSpacingCallback()
{
InputImagePointer input = this->GetInput();
+ if (!input)
+ {
+ m_FloatDataSpacing[0] = m_FloatDataSpacing[1] = m_FloatDataSpacing[2] =
+ 0.0;
+ return m_FloatDataSpacing;
+ }
+
const typename TInputImage::SpacingType& spacing = input->GetSpacing();
unsigned int i=0;
at at -194,6 +214,13 at at
double* VTKImageExport<TInputImage>::OriginCallback()
{
InputImagePointer input = this->GetInput();
+ if (!input)
+ {
+ // nothing much we can do about this...
+ m_DataOrigin[0] = m_DataOrigin[1] = m_DataOrigin[2] = 0.0;
+ return m_DataOrigin;
+ }
+
const typename TInputImage::PointType& origin = input->GetOrigin();
unsigned int i=0;
at at -218,6 +245,13 at at
float* VTKImageExport<TInputImage>::FloatOriginCallback()
{
InputImagePointer input = this->GetInput();
+ if (!input)
+ {
+ m_FloatDataOrigin[0] = m_FloatDataOrigin[1] = m_FloatDataOrigin[2] =
+ 0.0;
+ return m_FloatDataOrigin;
+ }
+
const typename TInputImage::PointType& origin = input->GetOrigin();
unsigned int i=0;
at at -282,6 +316,11 at at
region.SetIndex(index);
InputImagePointer input = this->GetInput();
+ if (!input)
+ {
+ return;
+ }
+
input->SetRequestedRegion(region);
}
at at -296,6 +335,13 at at
int* VTKImageExport<TInputImage>::DataExtentCallback()
{
InputImagePointer input = this->GetInput();
+ if (!input)
+ {
+ m_DataExtent[0] = m_DataExtent[2] = m_DataExtent[4] = 0;
+ m_DataExtent[1] = m_DataExtent[3] = m_DataExtent[5] = -1;
+ return m_DataExtent;
+ }
+
InputRegionType region = input->GetBufferedRegion();
InputSizeType size = region.GetSize();
InputIndexType index = region.GetIndex();
at at -323,6 +369,11 at at
void* VTKImageExport<TInputImage>::BufferPointerCallback()
{
InputImagePointer input = this->GetInput();
+ if (!input)
+ {
+ return (void*)NULL;
+ }
+
return input->GetBufferPointer();
}
diff --exclude=CVS* -urN Insight-1-6/Code/BasicFilters/itkVTKImageExportBase.cxx Insight/Code/BasicFilters/itkVTKImageExportBase.cxx
--- Insight-1-6/Code/BasicFilters/itkVTKImageExportBase.cxx Sat Mar 6 00:11:42 2004
+++ Insight/Code/BasicFilters/itkVTKImageExportBase.cxx Mon Mar 15 17:56:54 2004
at at -133,6 +133,13 at at
int VTKImageExportBase::PipelineModifiedCallback()
{
DataObjectPointer input = this->GetInput(0);
+ if (!input)
+ {
+ // if we have no input, the pipeline can't have changed,
+ // so we just return 0 instead of throwing an exception.
+ return 0;
+ }
+
unsigned long pipelineMTime = input->GetPipelineMTime();
if(pipelineMTime > m_LastPipelineMTime)
{
at at -154,6 +161,11 at at
{
// Get the input.
DataObjectPointer input = this->GetInput(0);
+ if (!input)
+ {
+ return;
+ }
+
// Notify start event observers
this->InvokeEvent( StartEvent() );
diff --exclude=CVS* -urN Insight-1-6/Code/BasicFilters/itkVTKImageImport.txx Insight/Code/BasicFilters/itkVTKImageImport.txx
--- Insight-1-6/Code/BasicFilters/itkVTKImageImport.txx Sat Mar 6 00:11:42 2004
+++ Insight/Code/BasicFilters/itkVTKImageImport.txx Mon Mar 15 18:21:42 2004
at at -280,6 +280,12 at at
output->Allocate();
void* data = (m_BufferPointerCallback)(m_CallbackUserData);
+ if (!data)
+ {
+ // if we have no buffer pointer, we really can't continue
+ itkExceptionMacro(<<"No input set.");
+ }
+
OutputPixelType* importPointer = reinterpret_cast<OutputPixelType*>(data);
OutputPixelType* bufferPointer =
output->GetPixelContainer()->GetBufferPointer();
--=-7TKMoOiE29C6JS0OvzMG--