[vtkusers] Help writing a vtkStructurePointsSource subclass

Kevin Teich kteich at cortechs.net
Tue Feb 26 15:10:39 EST 2002


(I'm reposting this question with some added information.)

I'm writing a subclass of vtkStructuredPointsSource that will copy an
input SP and pass it along to output. It has a vtkImageData as member
data to hold the image. It has one function to copy the input:

void vtkMutableStructuredPointsSource::CopyInput(vtkImageData *input)
{
  if (this->ImageData == NULL)
    {
      this->ImageData = vtkImageData::New();
    }

  this->ImageData->DeepCopy( input );

  // Make sure we got good data.
  int coords[3] = { 128, 128, 128 };
  void* scalarPtr = this->ImageData->GetScalarPointer( coords );
  if( scalarPtr == NULL )
    {
      vtkErrorMacro( << "Didn't get ptr" );
    }
}

That works fine.

In Execute(), I do this:

void vtkMutableStructuredPointsSource::Execute()
{
  // Make sure we have good data.
  int coords[3] = { 128, 128, 128 };
  void* scalarPtr = this->ImageData->GetScalarPointer( coords );
  if( scalarPtr == NULL )
    {
      vtkErrorMacro( << "Didn't get ptr" );
    }

  output->SetWholeExtent(this->ImageData->GetWholeExtent());
  output->SetNumberOfScalarComponents
        (this->ImageData->GetNumberOfScalarComponents());
  output->SetSpacing(this->ImageData->GetSpacing());
  output->SetOrigin(this->ImageData->GetOrigin());

  output->GetPointData()->SetScalars
	(this->ImageData->GetPointData()->GetScalars() );
}

ExecuteInformation() does the same thing except it doesnt set the scalar
data at the end. This is very similar to the code I use for a custom
volume reader that works.

This doesn't work. When I hook it up as the source to a
VolumeRaycastMapper and then to a Volume, nothing gets rendered. When I
hook it up to an ImageReslice, I get this error:

vtkStructuredPoints (0x8137e58): GetScalarPointer: Pixel (0, 0, 0) not in
memory.
 Current extent= (0, -1, 0, -1, 0, -1)

I've added this check at the end of the Execute() function:

  // Make sure we have good data.
  scalarPtr = output->GetScalarPointer( coords );
  if( scalarPtr == NULL )
    {
      vtkErrorMacro( << "Didn't get ptr" );
    }

And this gives me an error. So, somewhere along the line, the scalars
are not being copied to the output.

I know I'm missing something obvious. Any pointers? Thanks.


-- 
Kevin Teich




More information about the vtkusers mailing list