<div dir="ltr">Hi Magnus,<div> These examples may help:</div><div><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/NamedColors">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/NamedColors</a> <br></div><div><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/AssignColorsFromLUT">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/AssignColorsFromLUT</a> </div><div><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/ElevationBandsWithGlyphs">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/ElevationBandsWithGlyphs</a> <br></div><div><br></div><div>For example in the first link,a colour called "My Red" is created with an alpha of 0.5.</div><div><span class="gmail-br0" style="font-family:monospace,monospace;font-size:1em;line-height:1.2em;color:rgb(0,128,0)">////////////</span></div><pre class="gmail-de1" style="font-family:monospace,monospace;padding:0px;border:0px none white;color:rgb(0,0,0);line-height:1.2em;font-stretch:normal;font-size:1em;margin-top:0px;margin-bottom:0px;vertical-align:top;background-image:none;background-color:rgb(249,249,249);background-position:initial;background-repeat:initial"> <span class="gmail-kw4" style="color:rgb(0,0,255)">double</span> rgba<span class="gmail-br0" style="color:rgb(0,128,0)">[</span><span class="gmail-nu0" style="color:rgb(0,0,221)">4</span><span class="gmail-br0" style="color:rgb(0,128,0)">]</span><span class="gmail-sy4" style="color:rgb(0,128,128)">;</span>
<span class="gmail-co1" style="color:rgb(102,102,102)">// Test setting and getting colors here.</span>
<span class="gmail-co1" style="color:rgb(102,102,102)">// We are also modifying alpha.</span>
namedColors<span class="gmail-sy2" style="color:rgb(0,0,64)">-</span><span class="gmail-sy1" style="color:rgb(0,0,128)">></span>GetColor<span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-st0" style="color:rgb(255,0,0)">"Red"</span>,rgba<span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-sy4" style="color:rgb(0,128,128)">;</span>
rgba<span class="gmail-br0" style="color:rgb(0,128,0)">[</span><span class="gmail-nu0" style="color:rgb(0,0,221)">3</span><span class="gmail-br0" style="color:rgb(0,128,0)">]</span> <span class="gmail-sy1" style="color:rgb(0,0,128)">=</span> <span class="gmail-nu16" style="color:rgb(128,0,128)">0.5</span><span class="gmail-sy4" style="color:rgb(0,128,128)">;</span>
namedColors<span class="gmail-sy2" style="color:rgb(0,0,64)">-</span><span class="gmail-sy1" style="color:rgb(0,0,128)">></span>SetColor<span class="gmail-br0" style="color:rgb(0,128,0)">(</span><span class="gmail-st0" style="color:rgb(255,0,0)">"My Red"</span>,rgba<span class="gmail-br0" style="color:rgb(0,128,0)">)</span><span class="gmail-sy4" style="color:rgb(0,128,128)">;</span> </pre><div><span class="gmail-br0" style="font-family:monospace,monospace;font-size:1em;line-height:1.2em;color:rgb(0,128,0)"><span style="color:rgb(0,0,0);font-size:1em;line-height:1.2em;background-color:rgb(249,249,249)"> namedColors</span><span class="gmail-sy2" style="font-size:1em;line-height:1.2em;color:rgb(0,0,64)">-</span><span class="gmail-sy1" style="font-size:1em;line-height:1.2em;color:rgb(0,0,128)">></span><span style="color:rgb(0,0,0);font-size:1em;line-height:1.2em;background-color:rgb(249,249,249)">GetColor</span><span class="gmail-br0" style="font-size:1em;line-height:1.2em">(</span><span class="gmail-st0" style="font-size:1em;line-height:1.2em;color:rgb(255,0,0)">"My Red"</span><span style="color:rgb(0,0,0);font-size:1em;line-height:1.2em;background-color:rgb(249,249,249)">,rgba</span><span class="gmail-br0" style="font-size:1em;line-height:1.2em">)</span><span class="gmail-sy4" style="font-size:1em;line-height:1.2em;color:rgb(0,128,128)">;</span></span></div><div><span class="gmail-br0" style="font-family:monospace,monospace;font-size:1em;line-height:1.2em;color:rgb(0,128,0)">////////////</span></div><div>In the lookup table "My Red" is added, then "<span style="color:rgb(255,0,0);font-family:monospace,monospace;font-size:1em;line-height:1.2em;background-color:rgb(249,249,249)">DarkGreen</span>"with an opacity of 0.3.<br></div><div>You could create a colour called "My Black"in a similar fashion with an alpha of 0.</div><div>Then that example and the other ones should demonstrate how to create lookup tables.</div><div><br></div><div>I hope this helps.</div><div><br></div><div>Regards</div><div> Andrew<br><div class="gmail_extra"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>---------- Forwarded message ----------<br>From: Magnus Elden <<a href="mailto:magnus_elden@hotmail.com">magnus_elden@hotmail.com</a>><br>To: <<a href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a>><br>Cc: <br>Date: Sun, 24 Jul 2016 06:36:46 +0200<br>Subject: [vtkusers] How to set opacity of a certain color to 0?<br><div lang="EN-US"><div><p class="gmail-MsoNormal">I am cutting a volume using vtkCutter and I want to remove everything that is black or close to black. Normally this would be done using a transfer function, but I can not seem to find where to put it.<u></u><u></u></p><p class="gmail-MsoNormal">This is the flow of my program(shortened):<u></u><u></u></p><p class="gmail-MsoNormal"><u></u> <u></u></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkPiecewiseFunction</span><span style="font-size:9.5pt;font-family:consolas;color:black"> *opacityFun = </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkPiecewiseFunction</span><span style="font-size:9.5pt;font-family:consolas;color:black">::New();<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> <u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkDataSet</span><span style="font-size:9.5pt;font-family:consolas;color:black"> *dataSet;<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkSmartPointer</span><span style="font-size:9.5pt;font-family:consolas;color:black"><</span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkXMLImageDataReader</span><span style="font-size:9.5pt;font-family:consolas;color:black">> reader =<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkSmartPointer</span><span style="font-size:9.5pt;font-family:consolas;color:black"><</span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkXMLImageDataReader</span><span style="font-size:9.5pt;font-family:consolas;color:black">>::New();<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> dataSet = </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkDataSet</span><span style="font-size:9.5pt;font-family:consolas;color:black">::SafeDownCast(reader</span><span style="font-size:9.5pt;font-family:consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:consolas;color:black">GetOutput());<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> <u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> <u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> reader</span><span style="font-size:9.5pt;font-family:consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:consolas;color:black">GetOutput()->GetBounds(bounds);<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> <u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkSmartPointer</span><span style="font-size:9.5pt;font-family:consolas;color:black"><</span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkPlane</span><span style="font-size:9.5pt;font-family:consolas;color:black">> plane =<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkSmartPointer</span><span style="font-size:9.5pt;font-family:consolas;color:black"><</span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkPlane</span><span style="font-size:9.5pt;font-family:consolas;color:black">>::New();<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"><u></u> <u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"><u></u> <u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:green">// Create cutter</span><span style="font-size:9.5pt;font-family:consolas;color:black"><u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:blue">double</span><span style="font-size:9.5pt;font-family:consolas;color:black"> high = plane</span><span style="font-size:9.5pt;font-family:consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:consolas;color:black">EvaluateFunction((bounds[1] + bounds[0]) / 2.0,<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> (bounds[3] + bounds[2]) / 2.0,<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> bounds[5]);<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"><u></u> <u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkSmartPointer</span><span style="font-size:9.5pt;font-family:consolas;color:black"><</span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkCutter</span><span style="font-size:9.5pt;font-family:consolas;color:black">> cutter =<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkSmartPointer</span><span style="font-size:9.5pt;font-family:consolas;color:black"><</span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkCutter</span><span style="font-size:9.5pt;font-family:consolas;color:black">>::New();<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> cutter</span><span style="font-size:9.5pt;font-family:consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:consolas;color:black">SetInputConnection(reader</span><span style="font-size:9.5pt;font-family:consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:consolas;color:black">GetOutputPort());<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> cutter</span><span style="font-size:9.5pt;font-family:consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:consolas;color:black">SetCutFunction(plane);<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> cutter</span><span style="font-size:9.5pt;font-family:consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:consolas;color:black">GenerateValues(<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> numberOfCuts,<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> 0.9,<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> 0.9*high);<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"><u></u> <u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkSmartPointer</span><span style="font-size:9.5pt;font-family:consolas;color:black"><</span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkPolyDataMapper</span><span style="font-size:9.5pt;font-family:consolas;color:black">> cutterMapper =<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkSmartPointer</span><span style="font-size:9.5pt;font-family:consolas;color:black"><</span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkPolyDataMapper</span><span style="font-size:9.5pt;font-family:consolas;color:black">>::New();<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> cutterMapper</span><span style="font-size:9.5pt;font-family:consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:consolas;color:black">SetInputConnection(cutter</span><span style="font-size:9.5pt;font-family:consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:consolas;color:black">GetOutputPort());<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"><u></u> <u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"><u></u> <u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:green">// Create cut actor</span><span style="font-size:9.5pt;font-family:consolas;color:black"><u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkSmartPointer</span><span style="font-size:9.5pt;font-family:consolas;color:black"><</span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkActor</span><span style="font-size:9.5pt;font-family:consolas;color:black">> cutterActor =<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkSmartPointer</span><span style="font-size:9.5pt;font-family:consolas;color:black"><</span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkActor</span><span style="font-size:9.5pt;font-family:consolas;color:black">>::New();<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> cutterActor</span><span style="font-size:9.5pt;font-family:consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:consolas;color:black">GetProperty()->SetLineWidth(2);<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> cutterActor</span><span style="font-size:9.5pt;font-family:consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:consolas;color:black">SetMapper(cutterMapper);<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"><u></u> <u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:green">// Create renderers and add actors of plane and model</span><span style="font-size:9.5pt;font-family:consolas;color:black"><u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkSmartPointer</span><span style="font-size:9.5pt;font-family:consolas;color:black"><</span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkRenderer</span><span style="font-size:9.5pt;font-family:consolas;color:black">> renderer =<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkSmartPointer</span><span style="font-size:9.5pt;font-family:consolas;color:black"><</span><span style="font-size:9.5pt;font-family:consolas;color:rgb(43,145,175)">vtkRenderer</span><span style="font-size:9.5pt;font-family:consolas;color:black">>::New();<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> renderer</span><span style="font-size:9.5pt;font-family:consolas;color:teal">-></span><span style="font-size:9.5pt;font-family:consolas;color:black">AddActor(cutterActor);<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"><u></u> <u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:black"> </span><span style="font-size:9.5pt;font-family:consolas;color:green">//Code to render and interact with the cuts.<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas;color:green"><u></u> <u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas"><u></u> <u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas">Where in this code do I apply the transfer function? Do I use a lookup table? For now I want all colours to have opacity of 1 except for black that should have opacity = 0. How can this be done? I am using C++ and none of the examples seem to fit with the flow of my program. They either work only on volumes, which my poly data cut is not, or the function they use does not exist in any of the classes I am using. I tried setting a lookuptable with opacity ranges, I tried using a vtkPiecewiseFunction, but nothing seems to work. <u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas"><u></u> <u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas">Thank you for your help.<u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas">Yours, <u></u><u></u></span></p><p class="gmail-MsoNormal"><span style="font-size:9.5pt;font-family:consolas">Magnus Elden</span><u></u><u></u></p></div></div><br><br></blockquote></div>-- <br><div class="gmail_signature">___________________________________________<br>Andrew J. P. Maclean<br><br>___________________________________________</div>
</div></div></div>