[vtkusers] 3D modeling .. some more help plzzzz ... I've put my code in the mail

Florent.Chandelier at USherbrooke.ca Florent.Chandelier at USherbrooke.ca
Tue Sep 28 16:34:30 EDT 2004


i've put my code down this mail coz the piece of code you gave me don't 
fit in my code I guess ... may you think of another idea ????
Basically, I use a threshold to extract bone structure (255) and so set 
everything but bone at 100. I'm able to reconstruct a 3D rendering of 
bone structure but not of non-bone structure ...

Here are the lines that make me mad ....
-------------------
vtkContourFilter *boneExtractor = vtkContourFilter::New();
  boneExtractor->SetInput((vtkDataSet *) binimg->GetOutput());
  boneExtractor->SetValue(0, 100); // this should extract everything but 
bone .. but doesn't work !!!
  //boneExtractor->SetValue(1,255); // this will extract bone

 
  vtkPolyDataMapper *boneMapper = vtkPolyDataMapper::New();
  boneMapper->SetInput(boneExtractor->GetOutput());
  boneMapper->ScalarVisibilityOff();
-----------------------
When I give SetValue 255 it will extract me the bone structure .. but 
when I pass 100, that should represents everything but bone, i get 
nothing in my 3D rendering !!!


Dean Inglis wrote:

>Florent,
>
>if your segmented bone is stored in an unsigned char image
>volume as 255 and background (non-bone) is 0, you
>could use vtkImageShiftScale to invert the results:
>
>  vtkImageShiftScale* m_shift =  vtkImageShiftScale::New();
>  m_shift->SetOutputScalarTypeToUnsignedChar();
>  m_shift->ClampOverflowOn();
>  m_shift->SetInput( a_segmented_bone_image );
>
>  double* r = m_shift->GetInput()->GetScalarRange();
>  double dmin = r[0];  // in your case would be 100
>  double dmax = r[1];  // in your case would be 255
>  double diff = dmax - dmin;
>  double scale = -1.0;
>  double intercept = dmin - scale*dmax;
>  double shift = intercept / scale;
>
>  m_shift->SetShift( shift );
>  m_shift->SetScale( scale );
>
>  m_shift->Update();
>
>Dean  
>
>
>
> 
>
>_______________________________________________
>This is the private VTK discussion list. 
>Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers
>
>  
>
void main( int argc, char *argv[] )
{
  // Create the renderer, render window, and interactor
  vtkRenderer *ren1 = vtkRenderer::New();
 
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);
 
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

  //read bmp file
  vtkBMPReader *imagein=vtkBMPReader::New();
  imagein->SetFilePrefix ("slices"); // name of the files to read
  imagein->SetDataExtent(0, 255, 0, 255,0,10);

  // thresholding and binarising the images

  int TissueLow;
  int TissueHigh;

  TissueLow=100;
  TissueHigh=220;

  vtkImageThreshold *binimg=vtkImageThreshold::New();
  binimg->SetInput(imagein->GetOutput());   
  binimg->ThresholdBetween(TissueLow,TissueHigh);
  binimg->SetInValue(255); // bone value -> bone will appeared bright
  binimg->SetOutValue(100); // tissue value -> tissue will be black

  
  // Create a transfer function mapping scalar value to opacity
  vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
  oTFun->AddSegment(80, 0.0, 255, 1.0);

  // Create a transfer function mapping scalar value to color (grey)
  vtkPiecewiseFunction *cTFun = vtkPiecewiseFunction::New();
  cTFun->AddSegment(0, 1.0, 255, 1.0);

  // Create a property for the volume and set the transfer functions.
  // Turn shading on and use trilinear interpolation
  vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
  volumeProperty->SetColor(cTFun);
  volumeProperty->SetScalarOpacity(oTFun);
  volumeProperty->SetInterpolationTypeToLinear();
  volumeProperty->ShadeOn();

  // Create a ray function - this is a compositing ray function
  vtkVolumeRayCastCompositeFunction *compositeFunction =
  vtkVolumeRayCastCompositeFunction::New();

  // Create the volume mapper and set the ray function and scalar input
  vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
  volumeMapper->SetInput(binimg->GetOutput());
  volumeMapper->SetVolumeRayCastFunction(compositeFunction);

  // Create the volume and set the mapper and property
  vtkVolume *volume = vtkVolume::New();
  volume->SetMapper(volumeMapper);
  volume->SetProperty(volumeProperty);

    // 3D part
  vtkRenderer *aRenderer = vtkRenderer::New();
  vtkRenderWindow *renWinf = vtkRenderWindow::New();
  renWinf->AddRenderer(aRenderer);
  vtkRenderWindowInteractor *irenf = vtkRenderWindowInteractor::New();
  irenf->SetRenderWindow(renWinf);


  vtkContourFilter *boneExtractor = vtkContourFilter::New();
  boneExtractor->SetInput((vtkDataSet *) binimg->GetOutput());
  boneExtractor->SetValue(0, 100); // this should extract everything but 
bone .. but doesn't work !!!
  //boneExtractor->SetValue(1,255); // this  extracts bone and actually 
work fine

 
  vtkPolyDataMapper *boneMapper = vtkPolyDataMapper::New();
  boneMapper->SetInput(boneExtractor->GetOutput());
  boneMapper->ScalarVisibilityOff();

 
 
  vtkActor *bone = vtkActor::New();
  bone->SetMapper(boneMapper);
  aRenderer->AddActor(bone);



   

  // Interact with the data at 3 frames per second
  irenf->SetDesiredUpdateRate(1.0);
  irenf->SetStillUpdateRate(0.001);
  irenf->Start();


  // FLO PART
  // Set the size of the render window (expressed in pixels).
  renWinf->SetSize(300, 300);
  renWinf->Render();
  // Start the Interactor
  irenf->Start();

  

  // Clean up
  ren1->Delete();
  renWin->Delete();
  iren->Delete();
  imagein->Delete();
  oTFun->Delete();
  cTFun->Delete();
  volumeProperty->Delete();
  compositeFunction->Delete();
  volumeMapper->Delete();
  volume->Delete();
 
}

-- 
Florent Chandelier - florent.chandelier at usherbrooke.ca
PhD Student at the university of Sherbrooke (QC, Canada)
Bio mechanical research department - http://www.biomec.gme.usherb.ca/

Lab Phone : (001) (819)-821-7000




More information about the vtkusers mailing list