[vtkusers] On volume rendering

Farshid Dehmeshki farshid.dehmeshki at medicsight.com
Wed Dec 11 04:32:05 EST 2002


hi;
I use composite method in volume rendering .
for images with 400 slice that is very slow so  I had to use "Volumepro100 board" for speeding up the process. 
ta farshid
 

******************************* 
Farshid  Dehmeshki 
Software Engineer
Medicsight Plc
46 Berkeley Square
London
W1J 5AT
Tel : 020 7598 4074
Fax: 020 7598 4071
Email : farshid.dehmeshki at medicsight.com
Web Site : www.medicsight.com 
******************************* 
  
The contents of this e-mail are intended for the named addressee only. It contains information which may be confidential and which may also be privileged. Unless you are the named addressee (or authorised to receive for the addressee) you may not copy or use it, or disclose it to anyone
else. If you received it in error please notify us immediately and then destroy it. Further, we make every effort to keep our network free from viruses. However, you do need to verify that this email and any attachments are free of viruses as we can take no responsibility for any computer virus which might be transferred by way of this e-mail.

-----Original Message-----
From: cspl [mailto:affable at hd2.dot.net.in]
Sent: Wednesday, December 11, 2002 6:00 AM
To: vtkusers at public.kitware.com
Subject: [vtkusers] On volume rendering


Dear  Friends,
 
I am working on volume rendering.I am using composite technique.It is working fine.But I want make it fast.
It is too slow  when I rendered large volume(around 120 slices).I have written code as follows.Please give me suggestion.
 
void Composite(LPSTR FileName,HWND m_hWnd)
{
 


 DICOMReader DCMReader;
 DCMReader.StaticVarInit(); 
 ///Read the Dicom file
 BOOL flag=DCMReader.ReadDicomImage(FileName); 
 //samples per pixel
 const char *samples=DCMReader.GetDicomInfo(cs_samples_pixel);
 
 float VoxelDepth = 1;
 double VoxelWidth = 1,VoxelHeight = 1;
 //dataspacing in x,y direction 
 char *Spacing = DCMReader.GetDicomInfo(cs_pixel_spacing);
 //dataspacing in z direction
 char *ChrVDepth = DCMReader.GetDicomInfo(cs_slice_thickness);
 
 if(strcmp(ChrVDepth," ") != 0)
  VoxelDepth = atof(ChrVDepth);
 
 if(strcmp(Spacing," ") != 0)
  GetVoxelSpacing(Spacing,VoxelWidth,VoxelHeight);
 
 ///get image data pointer
 unsigned char* Buffer = (unsigned char *) DCMReader.GetAllImageData();  
 int spp=atoi(samples);
 ///calculating the volume size
 long ImageSz = DCMReader.width  * DCMReader.height *DCMReader.Slices;
 long in_max,in_min;
 
 renderer1 =vtkRenderer::New();
 renWin1=vtkRenderWindow::New();
 
 // Vtk Class to import the Buffer for furthur operations on volume.
 
 vtkImageImport *Importer = vtkImageImport::New();
 
 Importer->SetDataExtent(0, DCMReader.width - 1, 0, DCMReader.height- 1, 0, DCMReader.Slices - 1);
 Importer->SetWholeExtent(0, DCMReader.width - 1, 0, DCMReader.height- 1, 0, DCMReader.Slices - 1);
 Importer->SetDataSpacing((float)VoxelWidth,(float)VoxelHeight,(float)VoxelDepth);
 Importer->SetNumberOfScalarComponents(spp);
 // Set the Appropriate Data Type to the Importer Object
 if(DCMReader.DataType==DCMUShort) 
 {
  
  //Find the max,min values of Input Images
  FindMinMax((unsigned short*)Buffer,ImageSz,&in_max,&in_min);
  Importer->SetDataScalarTypeToUnsignedShort();
  
 }
 
 if(DCMReader.DataType==DCMShort) 
 {
  
  //Find the max,min values of Input Images
  FindMinMax((short *)Buffer,ImageSz,&in_max,&in_min);
  Importer->SetDataScalarTypeToUnsignedShort();
 }
 
 if(DCMReader.DataType==DCMUChar) 
 {
  //Find the max,min values of Input Images
  FindMinMax((unsigned char *)Buffer,ImageSz,&in_max,&in_min);
  Importer->SetDataScalarTypeToUnsignedChar();
 }
 
 if(DCMReader.DataType==DCMChar) 
 {
  //Find the max,min values of Input Images 
  FindMinMax((char *)Buffer,ImageSz,&in_max,&in_min);
  Importer->SetDataScalarTypeToUnsignedChar();
 }
 

 Importer->SetImportVoidPointer(Buffer);   // Importing the Buffer
 
 //to get first image display once again flip the image
 vtkImageFlip *upsidedownflip=vtkImageFlip::New();
 upsidedownflip->SetInput(Importer->GetOutput());
 upsidedownflip->SetFilteredAxes(2);
 
 vtkImageFlip *fronttobackflip=vtkImageFlip::New();
 fronttobackflip->SetInput(upsidedownflip->GetOutput());
 fronttobackflip->SetFilteredAxes(1);
 
 //Create a transfer function mapping scalar value to opacity
    vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
  oTFun->AddSegment(0, 0.0, in_max, 1.0);
 
 
   //Create a transfer function mapping scalar value to color (grey)
    vtkPiecewiseFunction *cTFun = vtkPiecewiseFunction::New();
 cTFun->AddSegment(0, 0.5, in_max, 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->SetScalarOpacity(oTFun);
 volumeProperty->SetAmbient(0.10);
 volumeProperty->SetDiffuse(0.40);
 volumeProperty->SetSpecular(0.50);
 volumeProperty->SetSpecularPower(100);
 volumeProperty->SetInterpolationTypeToLinear();
                  volumeProperty->ShadeOn();
 

 vtkVolumeRayCastMapper *volumeMapper=vtkVolumeRayCastMapper::New(); 
 vtkVolumeRayCastCompositeFunction *Composite=vtkVolumeRayCastCompositeFunction::New(); 
 Composite->SetCompositeMethodToClassifyFirst();
 volumeMapper->SetInput(fronttobackflip->GetOutput());
 volumeMapper->SetVolumeRayCastFunction(Composite);///for Composite Technique
 
 vtkLODProp3D *lod=vtkLODProp3D::New();
 lod->AddLOD(volumeMapper,volumeProperty,0.0);
 lod->SetPosition(0,1,2);
 lod->SetScale(3,3,3);
 renderer1->AddProp(lod);
 
 renWin1->AddRenderer(renderer1);
 ///Client window handle to vtk Render window
 renWin1->SetParentId(m_hWnd);
 renderer1->GetActiveCamera()->Azimuth(20.0);
 renderer1->GetActiveCamera()->Dolly(1.60);
 renderer1->ResetCameraClippingRange();
 
 renWin1->SetSize(DCMReader.width-10,DCMReader.height-10); 
 float rate=renWin1->GetDesiredUpdateRate();
 renWin1->SetDesiredUpdateRate(2.0);
 renWin1->Render();  
 
 iren1 =vtkRenderWindowInteractor::New();
  // Interact with the data at 2 frames per second
 iren1->SetRenderWindow(renWin1);
 iren1->SetDesiredUpdateRate(2.0);
 iren1->SetStillUpdateRate(0.001);
 iren1->Initialize();
 //clean the vtk objects
 Importer->Delete();
 fronttobackflip->Delete();
 upsidedownflip->Delete();
 Composite->Delete();
 oTFun->Delete();
 cTFun->Delete();
 volumeProperty->Delete();
 volumeMapper->Delete();
 volume1->Delete();
}
 
thanking you,
 
Regards,
Ramakrishna

_____________________________________________________________________
This e-mail has been scanned for viruses by the WorldCom Internet Managed Scanning Service - powered by MessageLabs. For further information visit http://www.worldcom.com


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20021211/0dab34fb/attachment.htm>


More information about the vtkusers mailing list