[vtkusers] vtkImageActor shearing distortion

Dean Inglis dean.inglis at camris.ca
Thu Nov 20 11:25:27 EST 2003


I am observing some strange behaviour with vtkImageActor.
Whenever I input an image of the same extent (2D) as a
previously loaded image, the new image is displayed sheared:
each row starting from the top is shifted to the left. It seems
as though the reader(?) is skipping ahead a number of bytes and then
reading.  The first image reads and displays fine.  If I input
an image with a different extent, the new image is displayed fine.
But again if I input a subsequent image with the same (different) extent
the distortion occurs.

My pipeline consists of

vtkImageReader     reader
vtkImageShiftScale scale
vtkImageActor      actor

the image data is 2D and the setup code is:

<snip> // init vtk objects
  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);
  m_reader->ReleaseDataFlagOn();

  m_imageActor1->VisibilityOff();
  m_imageActor1->InterpolateOff();
<snip>


<snip> //read the data from a file input dialogue

   struct stat statbuf;
   FILE *stream;

   /* open a file for update */
   if ((stream = fopen(OpenDlg->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_currentProcess = m_reader;
  m_reader->UpdateWholeExtent();
  m_currentProcess = NULL;

<snip>

<snip> // init the display
  m_reader->GetOutput()->GetOrigin(m_dataOrigin);
  m_reader->GetOutput()->GetSpacing(m_dataSpacing);
  m_reader->GetOutput()->GetExtent(m_dataExtent);
  m_reader->GetOutput()->GetBounds(m_dataBounds);

  m_ruler->ProjectToPlaneOff();
  m_ruler->PlaceWidget(m_dataBounds);
  m_ruler->ProjectToPlaneOn();
  m_ruler->SetProjectionPosition(0.0);

  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;

  vtkImageShiftScale* m_shift = vtkImageShiftScale::New();
  m_shift->ReleaseDataFlagOn();
  m_shift->SetOutputScalarTypeToUnsignedChar();
  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->VisibilityOn();

m_imageActor1->SetDisplayExtent(m_imageActor1->GetInput()->GetUpdateExtent()
);

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

  m_shift->UnRegisterAllOutputs();
  m_shift->Delete();
<snip>


If I modify the last initialization to remove the image actor from
the renderer, release its grpahics resources and then re-add to the
renderer, this behaviour does not occur.

<snip>
  vtkRenderer* ren = this->RenderWindow1->GetRenderer();
  ren->RemoveProp(m_imageActor1);

  vtkRenderWindow* renwin = RenderWindow1->GetRenderWindow();
  m_imageActor1->ReleaseGraphicsResources(renwin);

  this->RenderWindow1->Repaint();

  // ... do the previous code snip but

  ren->AddProp(m_imageActor1);

  if(!this->CameraCheckBox->Checked){ ren->ResetCamera(); }
  this->RenderWindow1->Repaint();

  m_shift->UnRegisterAllOutputs();
  m_shift->Delete();
<snip>

I noticed this behaviour a while back after D. Gobbi made changes to the
texture mapping code for vtkImageActor, but I just got around to
bringing this up today.  Any insight as to why this is happening
or why I now have to remove the image actor and then re-add it???

Using Borland C++ builder, vtkBorlandRenderWindow component, VTK nightly
cvs,
shared libs, CMake 1.8.1, Windows 2000, Intel Pentium IV HT

Dean





More information about the vtkusers mailing list