[vtkusers] Volume rendering using VTKImageImport instead of VtkVolume16Reader...

cspl affable at hd2.dot.net.in
Mon Nov 25 07:04:53 EST 2002


Dear friends,

I want to show volume raycast output.Earlier I used vtkVolume16Reader class.Now I am using vtkImageImport to read buffer slice by slice and display volume.I have written code as follows.But I am not getting exact volume.Please give me suggestion.

void Raycast(LPSTR FileName,HWND m_hWnd,double in_max,double in_min)
{

 
 DICOMReader TempReader1;
 //creating objects 
 TempReader1.StaticVarInit(); 
 BOOL flag=TempReader1.ReadDicomImage(FileName); 
 char *acquistion=TempReader1.GetDicomInfo(cs_modality); 
 const char  *samples=TempReader1.GetDicomInfo(cs_samples_pixel);
 char *Spacing = TempReader1.GetDicomInfo(cs_pixel_spacing);
 char *ChrVDepth = TempReader1.GetDicomInfo(cs_slice_thickness);
 float VoxelDepth = atof(ChrVDepth);
 //double in_max,in_min;
 double VoxelWidth, VoxelHeight;

 GetVoxelSpacing(Spacing,VoxelWidth,VoxelHeight);
 
 // Vtk Class to import the Buffer for furthur operations on volume.
 unsigned short *Buffer=NULL;
 if(strcmp(acquistion,"MR")==0)
 {
  //FindVolumeMaxMin(FileName,&in_max,&in_min);
  LPSTR File=new char [100];
    File=IntensityScaleVolume(FileName,in_max,in_min,750,300);
  TempReader1.StaticVarInit(); 
  BOOL flag=TempReader1.ReadDicomImage(File); 
  Buffer = (unsigned short *) TempReader1.GetAllImageData();  
  samples=TempReader1.GetDicomInfo(cs_samples_pixel);
 }
 else
  Buffer = (unsigned short *) TempReader1.GetAllImageData();  

 int spp=atoi(samples);
 
 renderer1 =vtkRenderer::New();
 renWin1=vtkRenderWindow::New();
 
 Importer = vtkImageImport::New();
 
 Importer->SetDataExtent(0, TempReader1.width - 1, 0, TempReader1.height- 1, 0,  TempReader1.Slices - 1);
 Importer->SetWholeExtent(0, TempReader1.width - 1, 0, TempReader1.height- 1, 0,  TempReader1.Slices - 1);
 Importer->SetDataSpacing((float)VoxelWidth,(float)VoxelHeight,(float)VoxelDepth);
 
 Importer->SetNumberOfScalarComponents(spp);
 Importer->SetDataScalarTypeToUnsignedShort();
 Importer->SetImportVoidPointer(Buffer);   // Importing the Buffer
 
 //flip the image into z axis 

 flip=vtkImageFlip::New();
 flip->SetInput(Importer->GetOutput());
 flip->SetFilteredAxes(2);

 //to get first image display once again flip the image
 flip1=vtkImageFlip::New();
 flip1->SetInput(flip->GetOutput());
 flip1->SetFilteredAxes(1);
 
 //ray cast composition function 
 compositeFunction=vtkVolumeRayCastCompositeFunction::New();
 volume1=vtkVolume::New();
 
 //opacity transfer functio
 
 opacityTransferFunction=vtkPiecewiseFunction::New();
                  opacityTransferFunction->AddPoint(0,0.0);
 opacityTransferFunction->AddPoint(127,1.0);
 opacityTransferFunction->AddPoint(255,2.0);
 opacityTransferFunction->AddPoint(383,3.0);
 opacityTransferFunction->AddPoint(511,4.0);

 
     
 
 volumeProperty=vtkVolumeProperty::New();
 volumeProperty->SetScalarOpacity(opacityTransferFunction);
 volumeProperty->SetAmbient(0.10);
 volumeProperty->SetDiffuse(0.50);
 volumeProperty->SetSpecular(0.40);
 volumeProperty->SetSpecularPower(100);
 volumeProperty->SetInterpolationTypeToLinear();
                  volumeProperty->ShadeOn();

 volumeMapper=vtkVolumeRayCastMapper::New(); 
 volumeMapper->SetVolumeRayCastFunction(compositeFunction);///for Raycast Technique
 volumeMapper->SetInput(flip1->GetOutput());
 
 volume1->SetMapper(volumeMapper);
 volume1->SetProperty(volumeProperty);
  
 renderer1->AddVolume(volume1);
 renWin1->AddRenderer(renderer1);
 renWin1->SetParentId(m_hWnd);
 iren1 =vtkRenderWindowInteractor::New();
 iren1->SetRenderWindow(renWin1);
 renWin1->Render();  
 iren1->Initialize();
}

Regards,
Ramakrishna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20021125/0d6d895e/attachment.htm>


More information about the vtkusers mailing list