[vtkusers] Volume Rendering

anast.jm at pg.com anast.jm at pg.com
Fri Oct 12 17:50:11 EDT 2001


Massimiliano,

Perhaps if you posted an image of the render window on a website somewhere (I
don't think you can attach and image to the users group mailing list) someone
could spot the problem. Its hard to tell what your problem could be from the
code. You may also want to run your volume read from bmp (imagein) through
vtkImageLuminance. That helped when I got an ugly render trying to work with bmp
images...I think I was trying to render the indexed color values instead of the
intensity. Hope this helps, john


                                                                
 Internet Mail Message                                          
 Received from host:      public.kitware.com                    
 [208.136.18.25]                                                
                                                                


From: "lappadj at libero.it" <lappadj at libero.it>@public.kitware.com on 10/12/2001
10:38 PM ZE2
                                                                                             
                    "lappadj at libero.it"           To:   "vtkusers"                           
 <lappadj at libero.it>@public.kitware.com        <vtkusers at public.kitware.com>                 
                                                  Cc:    (bcc: John Anast-JM/PGI)            
                                          Subject:      [vtkusers] Volume Rendering          
                               Sent by:                                                      
      vtkusers-admin at public.kitware.com                                                      
                    10/12/2001 04:38 PM                                                      
                                                                                             
                                                                                             




Hi,
i utilize this code for rendering one volume of Bmp slices from MRI
scan,but the effect of the rendering is not good,the resultant image
appear split in two half,is possible to be one error on the slices
format,because i convert dicom images into bmp images?Can you help me?
Thanks a lot

Massimiliano La Paglia

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkStructuredPointsReader.h"
#include "vtkPiecewiseFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkBMPReader.h"

#include "SaveImage.h"

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);

 //Legge bmp file
     vtkBMPReader *imagein=vtkBMPReader::New();
     imagein->SetFilePrefix ("C:/vtkdata/knee/pat");
     imagein->SetDataExtent(0, 255, 0, 255,1,64);


     // 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(imagein->GetOutput());
    volumeMapper->SetVolumeRayCastFunction(compositeFunction);

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

  // Add this volume to the renderer and get a closer look
  ren1->AddVolume(volume);
  ren1->GetActiveCamera()->Azimuth(20.0);
  ren1->GetActiveCamera()->Dolly(1.60);
  ren1->ResetCameraClippingRange();

  renWin->SetSize(300,300);

  renWin->Render();

  SAVEIMAGE( renWin );

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

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





_______________________________________________
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://public.kitware.com/mailman/listinfo/vtkusers






More information about the vtkusers mailing list