[vtkusers] Dicom image -vtkVolume16Reder

Michele Marco michelegr at alice.it
Tue Oct 3 16:20:10 EDT 2006


This is the code in c++ : (when i use vtkStructuredPointsReder it's all ok but, when i use vtkVolume16Reder to convert dicom image ,the result is Bad  ). I try to use  vtkImageCast *cast = vtkImageCast::New(); cast->SetInput(reder->GetOutput()); cast->SetOutputScalarTypeToUnsignedChar(); for very bed result . 

CODE:
 vtkRenderWindow *renWin = vtkRenderWindow::New();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();

iren->SetRenderWindow(renWin);

vtkRenderer *ren = vtkRenderer::New();

renWin->AddRenderer(ren);


// Read the data from a vtk file

// vtkStructuredPointsReader *reader = vtkStructuredPointsReader::New();

//reader->SetFileName("C:/ironProt.vtk");

//reader->Update();

vtkVolume16Reader *reader = vtkVolume16Reader::New();

reader->SetDataByteOrderToLittleEndian();


//reader->SetFilePattern("dcm");

reader->SetDataDimensions (512,512);

reader->SetImageRange (1,20);

reader->SetFilePrefix("C:/TAC_BODY_MOD/0001000");

reader->SetDataSpacing (2, 2, 1.5);



// Create a transfer function mapping scalar value to opacity

vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();

oTFun->AddSegment(10, 0.0, 255, 0.3);

vtkPiecewiseFunction *oTFun2 = vtkPiecewiseFunction::New();

oTFun2->AddSegment( 0, 0.0, 128, 1.0);

oTFun2->AddSegment(128, 1.0, 255, 0.0);

// Create a transfer function mapping scalar value to color (grey)

vtkPiecewiseFunction *gTFun = vtkPiecewiseFunction::New();

gTFun->AddSegment(0, 1.0, 255, 1.0);


// Create a transfer function mapping scalar value to color (color)

vtkColorTransferFunction *cTFun = vtkColorTransferFunction::New();

cTFun->AddRGBPoint( 0, 1.0, 0.0, 0.0 );

cTFun->AddRGBPoint( 64, 1.0, 1.0, 0.0 );

cTFun->AddRGBPoint( 128, 0.0, 1.0, 0.0 );

cTFun->AddRGBPoint( 192, 0.0, 1.0, 1.0 );

cTFun->AddRGBPoint( 255, 0.0, 0.0, 1.0 );

// Create a transfer function mapping magnitude of gradient to opacity

vtkPiecewiseFunction *goTFun = vtkPiecewiseFunction::New();

goTFun->AddPoint( 0, 0.0 );

goTFun->AddPoint( 30, 0.0 );

goTFun->AddPoint( 40, 1.0 );

goTFun->AddPoint( 255, 1.0 );

// Create a set of properties with varying options

vtkVolumeProperty *prop = vtkVolumeProperty::New();

prop->SetShade(1);

prop->SetAmbient(0.3);

prop->SetDiffuse(1.0);

prop->SetSpecular(0.2);

prop->SetSpecularPower(50.0);

prop->SetScalarOpacity(oTFun);

prop->SetGradientOpacity( goTFun );

prop->SetColor( gTFun );

prop->SetInterpolationTypeToNearest();

// prop->SetInterpolationTypeToLinear();

// Create mip ray functions

vtkVolumeRayCastMIPFunction *MIPFunction1 = 

vtkVolumeRayCastMIPFunction::New();

MIPFunction1->SetMaximizeMethodToScalarValue();

vtkFiniteDifferenceGradientEstimator *gradest = 

vtkFiniteDifferenceGradientEstimator::New();



vtkVolume *volume = vtkVolume::New();


ren->AddViewProp(volume);




vtkVolumeRayCastMapper *raycastMapper = vtkVolumeRayCastMapper::New();

raycastMapper->SetInputConnection(reader->GetOutputPort());

raycastMapper->SetGradientEstimator(gradest);

volume->SetMapper( raycastMapper );

volume->SetProperty( prop );

raycastMapper->SetVolumeRayCastFunction(MIPFunction1 );

renWin->SetSize(400,350);

ren->ResetCamera();

ren->GetActiveCamera()->Zoom(1.5);


renWin->Render();


// Interact with the data at 3 frames per second

iren->SetDesiredUpdateRate(3.0);

iren->SetStillUpdateRate(0.001);

iren->Start();


// Clean up

reader->Delete();

oTFun->Delete();

oTFun2->Delete();

gTFun->Delete();

cTFun->Delete();

goTFun->Delete();

prop->Delete();



MIPFunction1->Delete();

volume->Delete();


gradest->Delete();

raycastMapper->Delete();

ren->Delete();

iren->Delete();

renWin->Delete();

Thanks to help me .... Bets reguards Michele 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061003/7d10dba3/attachment.htm>


More information about the vtkusers mailing list