[vtkusers] vtkImagePlaneWidget, segmentation fault

Eric Pichon eric at ece.gatech.edu
Wed Oct 8 11:14:03 EDT 2003


On Wed, 8 Oct 2003, Mathieu Malaterre wrote:

> Eric Pichon wrote:
> > Hi All,
> >
> > image->GetPointData()->SetActiveScalars( "1" );
>
> Just a guess did you do first :
>
> array1->SetName( "1" );
>
> otherwise I need more details...

Thanks Mathieu. The arrays are named so the problem must lie elsewhere.

Here is a more detailed description of what I do. This is still a somwehat
stripped down version of the complete program but should really contain
everything you want ot know.

If someone still wants more details I would be happy to send the complete
source tree along with the data...

Again, the behaviour is the following: if my first user interaction with
the vtkPlaneImageWidget is to try to translate it (by moving the mouse
while holding the middle button) then the program crashes with a
segmentation fault.

ddd says:
Program received signal SIGSEGV, Segmentation fault.
0x4031943a in vtable for vtkTimeStamp () from
/scratch/VTK/bin/libvtkCommon.so
at some point in the past, it also said that the problem was in
vtkFieldData::SetArray( int i )

If instead I first rotate the plane slightly then everything goes fine and
I can later translate it as much as I want.

If the vtkImageData is built with only one vtkFloatArray, i.e. if I
comment out:

// pd->AddArray( fractionalAnisotropy );

Then everything is also fine (the program never crashes).

Details about the build environement are at the bottom of this message.

I will be gratefull for any help or idea !

Have a good day,

Eric

-----------------------------------------------------------------
This is how the image is created. It will then be saved as in xml format
and read by another program
-----------------------------------------------------------------

  int nPoints = dim[0]*dim[1]*dim[2];

  [ int dim[3] and float spacing[3] defined somewhere else ]

  vtkImageData *outimage;
  outimage = vtkImageData::New();

  outimage->SetDimensions( dim );
  outimage->SetSpacing( spacing );

  vtkPointData *pd;
  pd = outimage->GetPointData();

  vtkFloatArray *traceArray;
  traceArray = vtkFloatArray::New();
  traceArray->SetNumberOfComponents( 1 );
  traceArray->SetNumberOfTuples( nPoints );
  traceArray->SetName( "trace" );

  vtkFloatArray *fractionalAnisotropy;
  fractionalAnisotropy = vtkFloatArray::New();
  fractionalAnisotropy->SetNumberOfComponents( 1 );
  fractionalAnisotropy->SetNumberOfTuples( nPoints );
  fractionalAnisotropy->SetName( "fractionalAnisotropy" );

  [ float trace[nPoints] and FA[nPoints] defined somewhere else ]

  for(int k=0;k<nPoints;k++)
    {
      traceArray->SetTuple1(k, trace[k]);
      fractionalAnisotropy->SetTuple1(k, FA[k]);
    }

  pd->AddArray( fractionalAnisotropy );
  pd->AddArray( traceArray );
  pd->SetActiveScalars( "trace" );

  [ then the image is saved to a file as an XML file ]

  vtkXMLImageDataWriter *writer;
  writer = vtkXMLImageDataWriter::New();
  writer->SetInput( outimage );
  writer->SetDataModeToBinary();
  // ok because endianess is now encoded in the file
  writer->SetFileName( outfile );
  writer->EncodeAppendedDataOff();
  // so it will not be valid XML but faster.

  if( writer->Write()==0 )
    {
      cerr << "error when writting the object !" << endl;
      exit( -1 );
    }

  cout << "done" << endl;

------------------------------------------------------------------
now we will read the image and try to visualize it.
this is a different program.
------------------------------------------------------------------

  vtkXMLImageDataReader *reader;

  reader = vtkXMLImageDataReader::New();
  reader->SetFileName( fileName );

  vtkImageData* data;
  data = reader->GetOutput();

  data->Update();

  data->GetPointData()->SetActiveScalars( "trace" );

  /*

  then, from what I understand, I should be able to choose the scalar
field used by
  the vtkImageData by calling

  data->GetPointData()->SetActiveScalars() with a different argument, for
example here
  "fractionalAnisotropy".

  */

  // now we will create the pipeline

  vtkRenderer *ren1;
  ren1 = vtkRenderer::New();

  vtkRenderWindow *renWin;
  renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);

  vtkInteractorStyleTrackballCamera *iStyle;
  iStyle = vtkInteractorStyleTrackballCamera::New();

  vtkCellPicker *picker = vtkCellPicker::New();
  picker->SetEndPickMethod( pickMethod, (void *)picker );
  picker->SetTolerance(0.001);

  vtkCallbackCommand *callBackKeyboard = vtkCallbackCommand::New();

  vtkRenderWindowInteractor *iren;
  iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);
  iren->SetInteractorStyle( iStyle );
  iren->SetPicker(picker);
  iren->AddObserver( callBackKeyboard->GetEventIdFromString("CharEvent"),
callBackKeyboard );


////////////////////////////////////////////////////////////////////////////
  // creating the slices

  vtkWindowLevelLookupTable *lookupSlices;
  lookupSlices = vtkWindowLevelLookupTable::New();

  int dim[3];
  data->GetDimensions( dim );

  // AXIAL
------------------------------------------------------------------
  vtkImagePlaneWidget *axialSlice;
  axialSlice = vtkImagePlaneWidget::New();
  axialSlice->DisplayTextOn();
  axialSlice->RestrictPlaneToVolumeOn();
  axialSlice->TextureInterpolateOff();
  axialSlice->SetResliceInterpolateToNearestNeighbour();
  // no interpolation
  axialSlice->SetInput( data );
  axialSlice->UserControlledLookupTableOn();
  axialSlice->SetLookupTable( lookupSlices );
  axialSlice->SetInteractor( iren );
  axialSlice->KeyPressActivationOn();
  axialSlice->SetKeyPressActivationValue( 'a' );
  axialSlice->SetPlaneOrientationToZAxes();
  axialSlice->SetSliceIndex( dim[2]/2 );
  axialSlice->On();

  callBackKeyboard->SetCallback( callBackFunctionKeyboard );

  // render the scene
  ren1->GetActiveCamera()->Elevation(90);
  ren1->GetActiveCamera()->SetViewUp( 0, 0, -1 );
  ren1->GetActiveCamera()->Zoom( 1.5 );

  ren1->ResetCameraClippingRange();

  renWin->Render();
  iren->Start();


On Tue, 7 Oct 2003, Eric Pichon wrote:

> Hi All,
>
> I am trying to visualize a 3D image with several scalar components using
a
> vtkImagePlaneWidget object. I would like to interactively choose the
> component that will be used by the widget.
>
> The vtkImageData is built by:
>
> vtkImageData *image;
> image = vtkImageData::New();
> image->SetDimensions( dim );
> image->SetSpacing( spacing );
> image->GetPointData->AddArray( array1 );
> image->GetPointData->AddArray( array2 );
>
> where array1 and array2 are 2 vtkFloatArray of the correct dimension.
>
> We choose the active array (the one we want the widget to use) by:
>
> image->GetPointData()->SetActiveScalars( "1" );
>
> Then the widget is set up with:
>
> vtkImagePlaneWidget *axialSlice;
> axialSlice = vtkImagePlaneWidget::New();
> axialSlice->SetInput( image );
>
> The problem is that when I try to translate the plane along the normal
> vector, the porgram will crash with a segmentation fault. However if
> instead of translating it, my first operation is to rotate it then
> subsequent translations do not pose any problem.
>
> Moreover everything goes fine if the vtkImageData contains only one
scalar
> field, i.e. if I comment out:
>
> // image->GetPointData->AddArray( array2 );
>
> Any idea ? Am I doing something wrong ? (I do not allocate anything
> explicitely for the vtkImageData, when I tried to it did not solve
> anything). Have you had more success than I did on visualizing more
> than one scalar field with a vtkPlaneWidget ?
>
> Thanks for any help,
>
> Eric
>
> PS: this is with:
>
> VTK CVS of Sep 30, 2003
> g++ (GCC) 3.2.2 20030222
> Linux, Red Hat 9.0
>



More information about the vtkusers mailing list