<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4134.600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Dear Friends,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>I am working on volume rendering.I am using
composite technique.It is working fine.But I want make it fast.<BR>It is too
slow when I rendered large volume(around 120 slices).I have written code
as follows.Please give me suggestion.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>void Composite(LPSTR FileName,HWND
m_hWnd)<BR>{</FONT></DIV>
<DIV> </DIV><FONT face=Arial size=2>
<DIV><BR> DICOMReader DCMReader;<BR> DCMReader.StaticVarInit();
<BR> ///Read the Dicom file<BR> BOOL
flag=DCMReader.ReadDicomImage(FileName); <BR> //samples per
pixel<BR> const char
*samples=DCMReader.GetDicomInfo(cs_samples_pixel);</DIV>
<DIV> </DIV>
<DIV> float VoxelDepth = 1;<BR> double VoxelWidth = 1,VoxelHeight =
1;<BR> //dataspacing in x,y direction <BR> char *Spacing =
DCMReader.GetDicomInfo(cs_pixel_spacing);<BR> //dataspacing in z
direction<BR> char *ChrVDepth =
DCMReader.GetDicomInfo(cs_slice_thickness);<BR> <BR> if(strcmp(ChrVDepth,"
") != 0)<BR> VoxelDepth = atof(ChrVDepth);</DIV>
<DIV> </DIV>
<DIV> if(strcmp(Spacing," ") !=
0)<BR> GetVoxelSpacing(Spacing,VoxelWidth,VoxelHeight);<BR> <BR> ///get
image data pointer<BR> unsigned char* Buffer = (unsigned char *)
DCMReader.GetAllImageData(); <BR> int
spp=atoi(samples);<BR> ///calculating the volume size<BR> long ImageSz
= DCMReader.width * DCMReader.height *DCMReader.Slices;<BR> long
in_max,in_min;<BR> <BR> renderer1
=vtkRenderer::New();<BR> renWin1=vtkRenderWindow::New();<BR> <BR> //
Vtk Class to import the Buffer for furthur operations on
volume.<BR> <BR> vtkImageImport *Importer =
vtkImageImport::New();<BR> <BR> Importer->SetDataExtent(0,
DCMReader.width - 1, 0, DCMReader.height- 1, 0, DCMReader.Slices -
1);<BR> Importer->SetWholeExtent(0, DCMReader.width - 1, 0,
DCMReader.height- 1, 0, DCMReader.Slices -
1);<BR> Importer->SetDataSpacing((float)VoxelWidth,(float)VoxelHeight,(float)VoxelDepth);<BR> Importer->SetNumberOfScalarComponents(spp);<BR> //
Set the Appropriate Data Type to the Importer
Object<BR> if(DCMReader.DataType==DCMUShort)
<BR> {<BR> <BR> //Find the max,min values of Input
Images<BR> FindMinMax((unsigned
short*)Buffer,ImageSz,&in_max,&in_min);<BR> Importer->SetDataScalarTypeToUnsignedShort();<BR> <BR> }</DIV>
<DIV> </DIV>
<DIV> if(DCMReader.DataType==DCMShort)
<BR> {<BR> <BR> //Find the max,min values of Input
Images<BR> FindMinMax((short
*)Buffer,ImageSz,&in_max,&in_min);<BR> Importer->SetDataScalarTypeToUnsignedShort();<BR> }</DIV>
<DIV> </DIV>
<DIV> if(DCMReader.DataType==DCMUChar) <BR> {<BR> //Find
the max,min values of Input Images<BR> FindMinMax((unsigned char
*)Buffer,ImageSz,&in_max,&in_min);<BR> Importer->SetDataScalarTypeToUnsignedChar();<BR> }</DIV>
<DIV> </DIV>
<DIV> if(DCMReader.DataType==DCMChar) <BR> {<BR> //Find the
max,min values of Input Images <BR> FindMinMax((char
*)Buffer,ImageSz,&in_max,&in_min);<BR> Importer->SetDataScalarTypeToUnsignedChar();<BR> }</DIV>
<DIV> </DIV>
<DIV><BR> Importer->SetImportVoidPointer(Buffer); //
Importing the Buffer<BR> <BR> //to get first image display once again
flip the image<BR> vtkImageFlip
*upsidedownflip=vtkImageFlip::New();<BR> upsidedownflip->SetInput(Importer->GetOutput());<BR> upsidedownflip->SetFilteredAxes(2);</DIV>
<DIV> </DIV>
<DIV> vtkImageFlip
*fronttobackflip=vtkImageFlip::New();<BR> fronttobackflip->SetInput(upsidedownflip->GetOutput());<BR> fronttobackflip->SetFilteredAxes(1);</DIV>
<DIV> </DIV>
<DIV> //Create a transfer function mapping scalar value to
opacity<BR> vtkPiecewiseFunction *oTFun =
vtkPiecewiseFunction::New();<BR> oTFun->AddSegment(0, 0.0, in_max,
1.0);<BR> </DIV>
<DIV> </DIV>
<DIV> //Create a transfer function mapping scalar value to color
(grey)<BR> vtkPiecewiseFunction *cTFun =
vtkPiecewiseFunction::New();<BR> cTFun->AddSegment(0, 0.5, in_max,
1.0);<BR> <BR> <BR> // Create a property for
the volume and set the transfer functions.<BR> // Turn shading on
and use trilinear interpolation<BR> vtkVolumeProperty *volumeProperty =
vtkVolumeProperty::New();<BR> volumeProperty->SetScalarOpacity(oTFun);<BR> volumeProperty->SetAmbient(0.10);<BR> volumeProperty->SetDiffuse(0.40);<BR> volumeProperty->SetSpecular(0.50);<BR> volumeProperty->SetSpecularPower(100);<BR> volumeProperty->SetInterpolationTypeToLinear();<BR>
volumeProperty->ShadeOn();</DIV>
<DIV> </DIV>
<DIV> <BR> vtkVolumeRayCastMapper
*volumeMapper=vtkVolumeRayCastMapper::New(); <BR> vtkVolumeRayCastCompositeFunction
*Composite=vtkVolumeRayCastCompositeFunction::New();
<BR> Composite->SetCompositeMethodToClassifyFirst();<BR> volumeMapper->SetInput(fronttobackflip->GetOutput());<BR> volumeMapper->SetVolumeRayCastFunction(Composite);///for
Composite Technique</DIV>
<DIV> </DIV>
<DIV> vtkLODProp3D
*lod=vtkLODProp3D::New();<BR> lod->AddLOD(volumeMapper,volumeProperty,0.0);<BR> lod->SetPosition(0,1,2);<BR> lod->SetScale(3,3,3);<BR> renderer1->AddProp(lod);</DIV>
<DIV> </DIV>
<DIV> renWin1->AddRenderer(renderer1);<BR> ///Client window handle
to vtk Render
window<BR> renWin1->SetParentId(m_hWnd);<BR> renderer1->GetActiveCamera()->Azimuth(20.0);<BR> renderer1->GetActiveCamera()->Dolly(1.60);<BR> renderer1->ResetCameraClippingRange();<BR> <BR> renWin1->SetSize(DCMReader.width-10,DCMReader.height-10);
<BR> float
rate=renWin1->GetDesiredUpdateRate();<BR> renWin1->SetDesiredUpdateRate(2.0);<BR> renWin1->Render();
<BR> <BR> iren1 =vtkRenderWindowInteractor::New();<BR> //
Interact with the data at 2 frames per
second<BR> iren1->SetRenderWindow(renWin1);<BR> iren1->SetDesiredUpdateRate(2.0);<BR> iren1->SetStillUpdateRate(0.001);<BR> iren1->Initialize();<BR> //clean
the vtk
objects<BR> Importer->Delete();<BR> fronttobackflip->Delete();<BR> upsidedownflip->Delete();<BR> Composite->Delete();<BR> oTFun->Delete();<BR> cTFun->Delete();<BR> volumeProperty->Delete();<BR> volumeMapper->Delete();<BR> volume1->Delete();<BR>}</DIV>
<DIV> </DIV>
<DIV>thanking you,</DIV>
<DIV> </DIV>
<DIV>Regards,<BR>Ramakrishna</FONT></DIV></BODY></HTML>