[vtkusers] vtkTrivialProducer/vtkXMLImageDataReader question cont'd

Dean Inglis dean.inglis at camris.ca
Fri Mar 23 11:56:31 EDT 2007


this follows with the previous posting.
I am still experiencing application crashes
when passing data obtained from vtkXMLImageDataReader
but not any readers inherited from vtkImageReader.
It seems that the extents are not being maintained
and are being reverted back to uninitialized extents,
but I don't know why.  Here is the code where
the image display pipeline is modified to accept
new data from the reader:

//--------------------------------------------------------------------------
--
void vtkKWTestWindow::DisplayOpenedImageFile()
{
  vtkImageData* input;

  if ( this->ImageReaderWriter->IsA("vtkXMLImageDataReader" ))
    {
    input = (vtkXMLImageDataReader::SafeDownCast(
this->ImageReaderWriter ))->GetOutput();
    }
  else if( this->ImageReaderWriter->IsA("vtkDICOMImageReader" ))
    {
    input =
(vtkDICOMImageReader::SafeDownCast(this->ImageReaderWriter))->GetOutput();
    }
  else
    {
    input =
(vtkMetaImageReader::SafeDownCast(this->ImageReaderWriter))->GetOutput();
     }
  if ( !input ){ return; }

  input->Update();  // pull data from disk using the assigned reader

  if ( this->ImageData ){ this->ImageData->Delete(); }
  this->ImageData = input->NewInstance();
  this->ImageData->DeepCopy( input );  // copy the new data

//*******extents are correct at this point

  // one way to set the data to the viewer, but makes no difference to
  // correcting the extent error
   //this->ImageViewer->SetInputConnection(
this->ImageData->GetProducerPort() );

  this->ImageViewer->SetInput( this->ImageData );
  this->ImageViewer->UpdateDisplayExtent();

  double *range = this->ImageData->GetScalarRange();
  this->ImageViewer->SetColorWindow( range[1] - range[0] );
  this->ImageViewer->SetColorLevel( 0.5 * (range[1] + range[0]) );
  this->RenderWidget->ResetCamera();
  this->ImageViewer->Render();

//*******extents are now incorrect and the app crashes.

Why does this happen and only with vtkXMLImageDataReader output?
Is there a method call or other setup connection that I am missing?

Dean

//////////////////////////////////////////////////

scenario:

vtkXMLImageDataReader* reader;

vtkImageData* myStandAloneData;

//initialize data and reader, and read in file
// then later:

reader->ReleaseDataFlagOn();
reader->Update();

myStandAloneData->DeepCopy( reader->GetOutput() );
myStandAloneData->Update();

reader->Delete();
reader = NULL;

At some point down my visualization pipeline,
I am running into an error with the
extents of the image data reported as being 0,-1,0,-1,0,-1:

ERROR: In vtkImageData.cxx line 1460
vtkImageData (071B3F58): GetScalarPointer: Pixel (0, 0, 15) not in memory.
Current extent = (0,-1,0,-1,0,-1)

this error does not happen if I use vtkMetaImageReader as
the reader.  Build is Windows 2000, CMake 2.4, VTK CVS, KWWidgets CVS,
Visual Studio Express 2005, static Release build.
I have tried adding a trivial producer to myStandAloneData
as in producer->SetOutput(myStandAloneData), but this does not
correct the pipeline error.  Any idea what is happening here?
The image actually displays in a vtkImageViewer2 but immediately
after rendering, the app crashes.



More information about the vtkusers mailing list