[vtkusers] vtkImageReader - stumped on extents!

dean.inglis at on.aibn.com dean.inglis at on.aibn.com
Tue Feb 25 13:44:37 EST 2003


Ok, I'm stumped...

I've tried the archives but can't seem to find a closely related discussion.
I've tried reading most of the relevant class hierarchies but that is just 
sending me round in circles. So, I'll relate my coding attempts that fail:
the pipeline:
vtkImageReader---->vtkImageShiftScale---->vtkImageActor---->vtkRenderer

the reader is initialized at app start up to read a given 2D square image from 
a binary file having a fixed header.  The extents depend on the file size:

void my_app_vtk_init_fn()
{
  m_reader->SetDataScalarTypeToShort();
  m_reader->SetDataByteOrderToLittleEndian();
  m_reader->SetFileDimensionality(2);
  m_reader->FileLowerLeftOff();
  m_reader->SetDataOrigin(0,0,0);
  m_reader->SetHeaderSize(1609);            
  m_reader->SetDataSpacing (0.2, 0.2, 1.0); 

<snip>

The file name is retrieved from a file dialogue. The extents are calculated
and set:

void m_app_open_file(string FileName)
{
   struct stat statbuf;
   FILE *stream;

   if ((stream = fopen(FileName.c_str(), "rb"))
       == NULL)
   {
      return;
   }

  fstat(fileno(stream), &statbuf);
  fclose(stream);

  int extent = static_cast<int>(sqrt((statbuf.st_size - 1609)/2))-1;

  m_reader->SetFileName(OpenDlg->FileName.c_str());
  m_reader->SetDataExtent(0,extent,0,extent,0,0);
  m_reader->Modified();
  m_reader->UpdateWholeExtent();

<snip>

Then the display is set up:

void my_app_init_display()
{
  float range[2];
  m_reader->GetOutput()->GetScalarRange(range);
  float slope = 255.0f/(range[1] - range[0]);
  float intercept = -slope*range[0];
  float shift = intercept/slope;

  m_shift->SetShift(shift);
  m_shift->SetScale(slope);
  m_shift->SetInput(m_reader->GetOutput());
  m_shift->UpdateWholeExtent();

  m_imageActor1->SetInput(m_shift->GetOutput());
  m_imageActor1->InterpolateOff();
  m_imageActor1->VisibilityOn();

  vtkRenderer* ren = RenderWindow1->GetRenderer();
  if(!CameraCheckBox->Checked){ ren->ResetCamera(); }
  RenderWindow1->Invalidate();
}

All is well if the first image read in is smaller than any
subsequent images.  However, if I read in  larger image and
then attempt to read in a smaller image, debug activated for
the m_reader and its output shows (small is 503 x 503, large is 
578 x 578):

Debug: In c:\Builder\Sources\VTK\Common\vtkDataObject.h, line 255
vtkImageData (01BEE1F4): vtkImageData (01BEE1F4): returning RequestExactExtent of 0


ERROR: In c:\Builder\Sources\VTK\Common\vtkDataObject.cxx, line 548
vtkImageData (01BEE1F4): Update extent does not lie within whole extent


ERROR: In c:\Builder\Sources\VTK\Common\vtkDataObject.cxx, line 555
vtkImageData (01BEE1F4): Update extent is: 0, 577, 0, 577, 0, 0


ERROR: In c:\Builder\Sources\VTK\Common\vtkDataObject.cxx, line 562
vtkImageData (01BEE1F4): Whole extent is: 0, 502, 0, 502, 0, 0


I have tried m_reader->Update(), I have tried getting the output
ahead of setting up the new extents:


if(m_reader->GetOutput() != NULL)
  {
  vtkImageData* ptr = m_reader->GetOutput();
  ptr->PrepareForNewData();
  ptr->SetWholeExtent(0,extent,0,extent,0,0);
  ptr->SetExtent(0,extent,0,extent,0,0);
  ptr->SetUpdateExtent(0,extent,0,extent,0,0);
  ptr->AllocateScalars();
  }


with variants thereof but none work!


What am I missing here? Before the errors in the debug log, it
appeared that the reader (and its output) was setting the extents 
properly, executed, but then the extents in the image were somehow
overwritten to those of the previous image ....


Dean




More information about the vtkusers mailing list