[vtkusers] A question about displaying Image using VTK

15891495523 at 126.com 15891495523 at 126.com
Fri Jul 10 02:55:40 EDT 2015


Dear Cory

       I am sorry, but those code doesn't work. 
    
       And the complete code is :
void main()
{
   vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New();
  reader->SetDirectoryName("G:\\Perfusion Project\\Perfusion_MIP\\MIP\\TimePhase\\Time2");
  reader->SetDataByteOrderToBigEndian();
  reader->Update();


vtkSmartPointer<vtkImageShiftScale> shift = vtkSmartPointer<vtkImageShiftScale>::New();
shift->SetInputConnection(reader->GetOutputPort());
shift->SetOutputScalarTypeToUnsignedShort();
shift->Update();

vtkSmartPointer<vtkImageReslice> reslice = vtkSmartPointer<vtkImageReslice>::New();
reslice->SetInputData(shift->GetOutput());
reslice->SetOutputDimensionality(3);
reslice->Update();

vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New();
image=reslice->GetOutput();

vtkSmartPointer<vtkImageWriter> writer = vtkSmartPointer<vtkImageWriter>::New();
writer->SetInputData(image);
writer->SetFileName("C:\\Users\\zhq\\Desktop\\VolumeData.vtk");
writer->Update();

vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();

renWin->AddRenderer(ren);
renWin->SetInteractor(iren);
iren->SetInteractorStyle(style);

vtkSmartPointer<vtkPiecewiseFunction> opacityTransferFunction = vtkSmartPointer<vtkPiecewiseFunction>::New();
opacityTransferFunction->AddPoint(0,1200);
opacityTransferFunction->AddPoint(1200,0.4);
opacityTransferFunction->AddPoint(2000,0.2);

/*vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkSmartPointer<vtkColorTransferFunction>::New();
colorTransferFunction->AddRGBPoint(0,0,0.5,0);
colorTransferFunction->AddRGBPoint(60,1,0,0);
colorTransferFunction->AddRGBPoint(255,0.8,0.8,0.8);*/

vtkSmartPointer<vtkDiscretizableColorTransferFunction > colorTransferFunction = vtkSmartPointer<vtkDiscretizableColorTransferFunction >::New(); 
colorTransferFunction->AddRGBPoint(0,0,0.5,0); 
colorTransferFunction->AddRGBPoint(60,1,0,0); 
colorTransferFunction->AddRGBPoint(255,0.8,0.8,0.8);
colorTransferFunction->SetScalarOpacityFunction(opacityTransferFunction);
colorTransferFunction->EnableOpacityMappingOn();

vtkSmartPointer<vtkVolumeProperty> volumeProperty = vtkSmartPointer<vtkVolumeProperty>::New();
volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetScalarOpacity(opacityTransferFunction);
volumeProperty->ShadeOn();
volumeProperty->SetInterpolationTypeToLinear();
volumeProperty->SetAmbient(0.2);

vtkSmartPointer<vtkVolumeRayCastMIPFunction> mipRayCastFunction = vtkSmartPointer<vtkVolumeRayCastMIPFunction>::New();
vtkSmartPointer<vtkVolumeRayCastCompositeFunction> compositeFunction = vtkSmartPointer<vtkVolumeRayCastCompositeFunction>::New();
vtkSmartPointer<vtkVolumeRayCastMapper> volumeMapper = vtkSmartPointer<vtkVolumeRayCastMapper>::New();

volumeMapper->SetVolumeRayCastFunction(compositeFunction);
volumeMapper->SetInputData(image);

vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New();
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);

ren->AddVolume(volume);
ren->SetBackground(1,1,1);
renWin->Render();
iren->Initialize();
iren->Start();
}
    
        Thank you very much!

ZhangQiang




 
From: Cory Quammen
Date: 2015-07-10 00:42
To: 15891495523 at 126.com
CC: vtkusers
Subject: Re: [vtkusers] A question about displaying Image using VTK
Instead of using a vtkColorTransferFunction, try using a vtkDiscretizableColorTransferFunction and setting the opacity function via SetScalarOpacityFunction(), e.g.

vtkSmartPointer<vtkDiscretizableColorTransferFunction > colorTransferFunction = vtkSmartPointer<vtkDiscretizableColorTransferFunction >::New(); 
colorTransferFunction->AddRGBPoint(0,0,0.5,0); 
colorTransferFunction->AddRGBPoint(60,1,0,0); 
colorTransferFunction->AddRGBPoint(255,0.8,0.8,0.8);
colorTransferFunction->SetScalarOpacityFunction(opacityTransferFunction);

then enable opacity mapping with

colorTransferFunction->EnableOpacityMappingOn();

HTH,
Cory

On Thu, Jul 9, 2015 at 9:51 AM, 15891495523 at 126.com <15891495523 at 126.com> wrote:
Dear all 

    I feel confused when display a CT image using VTK. How can I make those black and gray part in the following picture invisible ? 
    The key part of my code is : 

vtkSmartPointer<vtkPiecewiseFunction> opacityTransferFunction = vtkSmartPointer<vtkPiecewiseFunction>::New(); 
        opacityTransferFunction->AddPoint(0,1200); 
        opacityTransferFunction->AddPoint(1200,0.4); 
        opacityTransferFunction->AddPoint(2000,0.2); 

        vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkSmartPointer<vtkColorTransferFunction>::New(); 
        colorTransferFunction->AddRGBPoint(0,0,0.5,0); 
        colorTransferFunction->AddRGBPoint(60,1,0,0); 
        colorTransferFunction->AddRGBPoint(255,0.8,0.8,0.8); 


Thank you in advanced! 

ZhangQiang






_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers




-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
邮件带有附件预览链接,若您转发或回复此邮件时不希望对方预览附件,建议您手动删除链接。
共有 1 个附件
InsertPic_.jpg(99K) 极速下载 在线预览 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150710/7d14e770/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: InsertPic_(07-10-14-55-37).jpg
Type: image/jpeg
Size: 22021 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150710/7d14e770/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: InsertPic_(07-10(07-10-14-55-37).jpg
Type: image/jpeg
Size: 100667 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150710/7d14e770/attachment-0003.jpg>


More information about the vtkusers mailing list