<!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 frineds,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>I am working volumerendering.All three techniques
are working perfectly.But It is very slow when I drag 120 slices in one image.I
want to make it fast .I have written code as follows.Please give me
suggestion to make it fast.</FONT></DIV>
<DIV> </DIV><FONT face=Arial size=2>
<DIV><BR>void Composite(LPSTR FileName,HWND m_hWnd)<BR>{</DIV>
<DIV> </DIV>
<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->AddPoint(0,
0.0);<BR> oTFun->AddPoint(in_max, 0.2);<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);<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->SetColor(cTFun);<BR>
volumeProperty->SetScalarOpacity(oTFun);<BR>
volumeProperty->SetAmbient(0.10);<BR>
volumeProperty->SetDiffuse(0.40);<BR>
volumeProperty->SetSpecular(0.50);<BR>
volumeProperty->SetSpecularPower(1);<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());</DIV>
<DIV> </DIV>
<DIV> volumeMapper->SetVolumeRayCastFunction(Composite);///for Composite
Technique</DIV>
<DIV> </DIV>
<DIV> vtkVolume
*volume1=vtkVolume::New(); <BR> volume1->SetMapper(volumeMapper);<BR> volume1->SetProperty(volumeProperty);<BR> //Set
the volume to Volume to renderer </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> </DIV>
<DIV> </DIV>
<DIV> renderer1->AddProp(lod);<BR> //renderer1->AddVolume(volume1);<BR> renWin1->AddRenderer(renderer1);<BR> <BR> ///Client
window handle to vtk Render
window<BR> renWin1->SetParentId(m_hWnd);<BR> //set the render
window
size<BR> renWin1->SetSize(DCMReader.width+10,DCMReader.height+10);
<BR> iren1
=vtkRenderWindowInteractor::New();<BR> iren1->SetRenderWindow(renWin1);<BR> //Render
the Volume<BR> renWin1->Render(); <BR> //mouse interact the
render window<BR> iren1->Initialize();</DIV>
<DIV> </DIV>
<DIV> //clean the vtk
objects<BR> <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><BR>thanking you,</DIV>
<DIV> </DIV>
<DIV>regards,<BR>ramakrishna</FONT></DIV></BODY></HTML>