<div dir="ltr">Hi,<div><br></div><div>Thank you for including your code. That makes it much easier to help.<br><div><br></div><div>In your code, your opacity function has value 1200 at data value 0. The opacities between data value 0 and data value 1200 are linear interpolated, and I think having that high opacity at data value 0 made most of the opacities > 1.0 for values between 0 and 1200.</div><div><br></div><div>Try changing this line</div><div><br></div><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px">opacityTransferFunction-></span><span style="color:rgb(80,0,80);font-size:12.8000001907349px">AddPoint(0,1200);</span><br></div><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px">to</span></div><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px">opacityTransferFunction-></span><span style="color:rgb(80,0,80);font-size:12.8000001907349px">AddPoint(0,0);</span><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px">This should solve your problem. It does on tests on my system.</span></div><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px"><br></span></div><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px">Best regards,</span></div><div><span style="color:rgb(80,0,80);font-size:12.8000001907349px">Cory</span></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 10, 2015 at 2:55 AM, <a href="mailto:15891495523@126.com">15891495523@126.com</a> <span dir="ltr"><<a href="mailto:15891495523@126.com" target="_blank">15891495523@126.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<div><span></span>Dear Cory</div><div><br></div><div> I am sorry, but those code doesn't work. </div><div><img src="cid:_Foxmail.1@96ec3b24-9d57-747f-a17f-06ade71d1bc0" border="0"></div><div><span style="color:rgb(0,0,0);background-color:rgba(0,0,0,0)"> </span></div><div><span style="color:rgb(0,0,0);background-color:rgba(0,0,0,0)"> </span><span style="background-color:rgba(0,0,0,0);font-size:10.5pt;line-height:1.5"> And the complete code is :</span></div><div><span style="color:rgb(0,0,0);background-color:rgba(0,0,0,0)">void main()<br>{<br> <span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New();<br> <span style="white-space:pre-wrap"> </span>reader->SetDirectoryName("G:\\Perfusion Project\\Perfusion_MIP\\MIP\\TimePhase\\Time2");<br> <span style="white-space:pre-wrap"> </span>reader->SetDataByteOrderToBigEndian();<br> <span style="white-space:pre-wrap"> </span>reader->Update();<br><br><br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkImageShiftScale> shift = vtkSmartPointer<vtkImageShiftScale>::New();<br><span style="white-space:pre-wrap"> </span>shift->SetInputConnection(reader->GetOutputPort());<br><span style="white-space:pre-wrap"> </span>shift->SetOutputScalarTypeToUnsignedShort();<br><span style="white-space:pre-wrap"> </span>shift->Update();<br><br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkImageReslice> reslice = vtkSmartPointer<vtkImageReslice>::New();<br><span style="white-space:pre-wrap"> </span>reslice->SetInputData(shift->GetOutput());<br><span style="white-space:pre-wrap"> </span>reslice->SetOutputDimensionality(3);<br><span style="white-space:pre-wrap"> </span>reslice->Update();<br><span style="white-space:pre-wrap"> </span><br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New();<br><span style="white-space:pre-wrap"> </span>image=reslice->GetOutput();<br><br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkImageWriter> writer = vtkSmartPointer<vtkImageWriter>::New();<br><span style="white-space:pre-wrap"> </span>writer->SetInputData(image);<br><span style="white-space:pre-wrap"> </span>writer->SetFileName("C:\\Users\\zhq\\Desktop\\VolumeData.vtk");<br><span style="white-space:pre-wrap"> </span>writer->Update();<br><br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();<br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();<br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();<br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();<br><br><span style="white-space:pre-wrap"> </span>renWin->AddRenderer(ren);<br><span style="white-space:pre-wrap"> </span>renWin->SetInteractor(iren);<br><span style="white-space:pre-wrap"> </span>iren->SetInteractorStyle(style);<span class=""><br><br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkPiecewiseFunction> opacityTransferFunction = vtkSmartPointer<vtkPiecewiseFunction>::New();<br><span style="white-space:pre-wrap"> </span>opacityTransferFunction->AddPoint(0,1200);<br><span style="white-space:pre-wrap"> </span>opacityTransferFunction->AddPoint(1200,0.4);<br><span style="white-space:pre-wrap"> </span>opacityTransferFunction->AddPoint(2000,0.2);<br><br><span style="white-space:pre-wrap"> </span></span>/*vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkSmartPointer<vtkColorTransferFunction>::New();<br><span style="white-space:pre-wrap"> </span>colorTransferFunction->AddRGBPoint(0,0,0.5,0);<br><span style="white-space:pre-wrap"> </span>colorTransferFunction->AddRGBPoint(60,1,0,0);<br><span style="white-space:pre-wrap"> </span>colorTransferFunction->AddRGBPoint(255,0.8,0.8,0.8);*/<span class=""><br><br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkDiscretizableColorTransferFunction > colorTransferFunction = vtkSmartPointer<vtkDiscretizableColorTransferFunction >::New(); <br><span style="white-space:pre-wrap"> </span>colorTransferFunction->AddRGBPoint(0,0,0.5,0); <br><span style="white-space:pre-wrap"> </span>colorTransferFunction->AddRGBPoint(60,1,0,0); <br><span style="white-space:pre-wrap"> </span>colorTransferFunction->AddRGBPoint(255,0.8,0.8,0.8);<br><span style="white-space:pre-wrap"> </span>colorTransferFunction->SetScalarOpacityFunction(opacityTransferFunction);<br><span style="white-space:pre-wrap"> </span></span>colorTransferFunction->EnableOpacityMappingOn();<br><br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkVolumeProperty> volumeProperty = vtkSmartPointer<vtkVolumeProperty>::New();<br><span style="white-space:pre-wrap"> </span>volumeProperty->SetColor(colorTransferFunction);<br><span style="white-space:pre-wrap"> </span>volumeProperty->SetScalarOpacity(opacityTransferFunction);<br><span style="white-space:pre-wrap"> </span>volumeProperty->ShadeOn();<br><span style="white-space:pre-wrap"> </span>volumeProperty->SetInterpolationTypeToLinear();<br><span style="white-space:pre-wrap"> </span>volumeProperty->SetAmbient(0.2);<br><br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkVolumeRayCastMIPFunction> mipRayCastFunction = vtkSmartPointer<vtkVolumeRayCastMIPFunction>::New();<br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkVolumeRayCastCompositeFunction> compositeFunction = vtkSmartPointer<vtkVolumeRayCastCompositeFunction>::New();<br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkVolumeRayCastMapper> volumeMapper = vtkSmartPointer<vtkVolumeRayCastMapper>::New();<br><br><span style="white-space:pre-wrap"> </span>volumeMapper->SetVolumeRayCastFunction(compositeFunction);<br><span style="white-space:pre-wrap"> </span>volumeMapper->SetInputData(image);<br><br><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New();<br><span style="white-space:pre-wrap"> </span>volume->SetMapper(volumeMapper);<br><span style="white-space:pre-wrap"> </span>volume->SetProperty(volumeProperty);<br><br><span style="white-space:pre-wrap"> </span>ren->AddVolume(volume);<br><span style="white-space:pre-wrap"> </span>ren->SetBackground(1,1,1);<br><span style="white-space:pre-wrap"> </span>renWin->Render();<br><span style="white-space:pre-wrap"> </span>iren->Initialize();<br><span style="white-space:pre-wrap"> </span>iren->Start();<br>}</span></div><div><span style="color:rgb(0,0,0);background-color:rgba(0,0,0,0)"> </span></div><div><span style="color:rgb(0,0,0);background-color:rgba(0,0,0,0)"> </span><span style="background-color:rgba(0,0,0,0);font-size:10.5pt;line-height:1.5"> Thank you very much!</span></div><div><span style="background-color:rgba(0,0,0,0);font-size:10.5pt;line-height:1.5"><br></span></div><div><span style="background-color:rgba(0,0,0,0);font-size:10.5pt;line-height:1.5">ZhangQiang</span></div>
<div><br></div><hr style="WIDTH:210px;min-height:1px" color="#b5c4df" size="1" align="left">
<div><span><div style="MARGIN:10px;FONT-FAMILY:verdana;FONT-SIZE:10pt"><br></div></span></div>
<blockquote style="margin-top:0px;margin-bottom:0px;margin-left:0.5em"><div> </div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style="PADDING-RIGHT:8px;PADDING-LEFT:8px;FONT-SIZE:12px;FONT-FAMILY:tahoma;COLOR:#000000;BACKGROUND:#efefef;PADDING-BOTTOM:8px;PADDING-TOP:8px"><div><b>From:</b> <a href="mailto:cory.quammen@kitware.com" target="_blank">Cory Quammen</a></div><div><b>Date:</b> 2015-07-10 00:42</div><div><b>To:</b> <a href="mailto:15891495523@126.com" target="_blank">15891495523@126.com</a></div><div><b>CC:</b> <a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers</a></div><div><b>Subject:</b> Re: [vtkusers] A question about displaying Image using VTK</div></div></div><div><div><div><div class="h5">
<div dir="ltr">Instead of using a vtkColorTransferFunction, try using a vtkDiscretizableColorTransferFunction and setting the opacity function via SetScalarOpacityFunction(), e.g.<div><br></div>vtkSmartPointer<vtkDiscretizableColorTransferFunction > colorTransferFunction = vtkSmartPointer<vtkDiscretizableColorTransferFunction >::New(); <br>colorTransferFunction->AddRGBPoint(0,0,0.5,0); <br>colorTransferFunction->AddRGBPoint(60,1,0,0); <br>colorTransferFunction->AddRGBPoint(255,0.8,0.8,0.8);<div>colorTransferFunction->SetScalarOpacityFunction(opacityTransferFunction);</div><div><br></div><div>then enable opacity mapping with</div><div><br></div><div>colorTransferFunction->EnableOpacityMappingOn();</div><div><br></div><div>HTH,</div><div>Cory</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 9, 2015 at 9:51 AM, <a href="mailto:15891495523@126.com" target="_blank">15891495523@126.com</a> <span dir="ltr"><<a href="mailto:15891495523@126.com" target="_blank">15891495523@126.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.5em;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>
<div><span></span><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal">Dear all </span><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"> I feel confused when display a CT image using VTK. How can I make those black and gray part in the following picture invisible ? </span><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"> The key part of my code is : </span><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal">vtkSmartPointer<vtkPiecewiseFunction> opacityTransferFunction = vtkSmartPointer<vtkPiecewiseFunction>::New(); </span><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"> opacityTransferFunction->AddPoint(0,1200); </span><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"> opacityTransferFunction->AddPoint(1200,0.4); </span><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"> opacityTransferFunction->AddPoint(2000,0.2); </span><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"> vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkSmartPointer<vtkColorTransferFunction>::New(); </span><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"> colorTransferFunction->AddRGBPoint(0,0,0.5,0); </span><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"> colorTransferFunction->AddRGBPoint(60,1,0,0); </span><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"> colorTransferFunction->AddRGBPoint(255,0.8,0.8,0.8); </span></div><div><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><br></span></div><div><img src="cid:_Foxmail.1@7049523a-942f-3525-866a-34507c0a5ffb" border="0"></div><div><br></div><div><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal">Thank you in advanced! </span><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><br style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal">ZhangQiang</span></div><div><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13.4399995803833px;line-height:normal"><br></span></div>
<div><br></div><hr style="width:210px;min-height:1px" color="#b5c4df" size="1" align="left">
<div><span><div style="MARGIN:10px;FONT-FAMILY:verdana;FONT-SIZE:10pt"><br></div></span></div>
</div><br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Cory Quammen<br>R&D Engineer<br>Kitware, Inc.</div>
</div>
</div></div><div style="width:430px;min-height:auto;background-color:rgb(246,249,252);border:1px solid rgb(197,210,218);padding:12px;line-height:160%;font-size:12px;white-space:nowrap;font-family:Verdana">
<div style="padding-bottom:5px;white-space:normal"><img src="http://mimg.127.net/xm/all/attpreview/img/ico_notice.gif" alt="提示图标" style="vertical-align:middle"> 邮件带有附件预览链接,若您转发或回复此邮件时不希望对方预览附件,建议您手动删除链接。</div>
<div style="color:rgb(160,160,160)">共有 <strong style="color:rgb(0,128,0)">1</strong> 个附件</div>
<dl style="margin:0px;padding:0px;width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
<dt title="InsertPic_.jpg" style="margin:8px 0px 0px;padding:0px;width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-weight:bold;color:rgb(51,51,51)">InsertPic_.jpg<span style="color:rgb(153,153,153);font-weight:normal">(99K)</span></dt>
<dd style="margin:0px;padding:0px;width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
<a href="http://preview.mail.126.com/xdownload?filename=InsertPic_.jpg&mid=1tbi5RkySFUw0mtsvwAAsJ&part=3&sign=fb3a712652d3c40c438e729aae49e4be&time=1436460555&uid=15891495523%40126.com" style="color:rgb(6,105,178)" target="_blank">极速下载</a>
<a href="http://preview.mail.126.com/preview?mid=1tbi5RkySFUw0mtsvwAAsJ&part=3&sign=fb3a712652d3c40c438e729aae49e4be&time=1436460555&uid=15891495523%40126.com" style="color:rgb(6,105,178)" target="_blank">在线预览</a>
</dd>
</dl>
</div>
</div></div></blockquote>
</div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Cory Quammen<br>R&D Engineer<br>Kitware, Inc.</div>
</div>