<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt">I think I have it working now.<br><br>Set opacity for 2d image to 1.0 (removed SetOpacity(0.5) call)<br><br>Changed image data of 3d tiff image into unsigned char (vtkShiftScale) and called tiffactor->SetOpacity(0.5).<br><br>Order of loading actors into renderer doesn't seem to be an issue.<br>I am not using my custom addalpha algorithm, so the tiff image has one component.<br><br>Not sure I fully understand... <br>The HasTransparency() function of vtkImageActor requires uchar data and 2 or 4 components in order to return 1...<br><br>Anyway - I go into the weekend happily.<br>Thanks again for all your time.<br><br>Maarten<div><span></span></div><div style="display: block;" class="yahoo_quoted"> <br> <br> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande,
sans-serif; font-size: 12pt;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> On Friday, January 17, 2014 3:10:33 PM, David Gobbi <david.gobbi@gmail.com> wrote:<br> </font> </div> <div class="y_msg_container">You would have to turn depth peeling on explicitly in order to enable<br clear="none">it, so if you haven't turned it on, we can be pretty sure that it<br clear="none">isn't being used.<br clear="none"><br clear="none">So I can't understand why the translucency isn't working for you.<br clear="none">I've done translucency in VTK quite a bit (and I still do). I've done<br clear="none">it with vtkActor and vtkTexture, with vtkImageActor, and with<br clear="none">vtkImageSliceMapper. The only trick I've ever had to use is that with<br clear="none">vtkTexture and vtkImageActor, the alpha component of the image is<br
clear="none">ignored unless I set the opacity to a value less than 1.0.<br clear="none"><br clear="none">There are even VTK regression tests for image alpha blending:<br clear="none">TestTranslucentImageActorAlphaBlending, TestImageSliceMapperAlpha.<br clear="none"><br clear="none"> David<br clear="none"><div class="yqt8959363614" id="yqtfd28191"><br clear="none">On Fri, Jan 17, 2014 at 12:51 PM, Maarten Beek <<a shape="rect" ymailto="mailto:beekmaarten@yahoo.com" href="mailto:beekmaarten@yahoo.com">beekmaarten@yahoo.com</a>> wrote:<br clear="none">> no - at least not intentionally.<br clear="none">><br clear="none">><br clear="none">><br clear="none">><br clear="none">> On Friday, January 17, 2014 2:50:04 PM, David Gobbi <<a shape="rect" ymailto="mailto:david.gobbi@gmail.com" href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>><br clear="none">> wrote:<br clear="none">> Are you doing anything that
would interfere with the alpha blending,<br clear="none">> like using depth peeling?<br clear="none">><br clear="none">> On Fri, Jan 17, 2014 at 12:26 PM, Maarten Beek <<a shape="rect" ymailto="mailto:beekmaarten@yahoo.com" href="mailto:beekmaarten@yahoo.com">beekmaarten@yahoo.com</a>><br clear="none">> wrote:<br clear="none">>> Setting the opacity in the callback would enable me to check the order in<br clear="none">>> which they were added to the renderer:<br clear="none">>><br clear="none">>> if( m_pWidget->m_pDrrActor && m_pWidget->m_pTIFFActor )<br clear="none">>> {<br clear="none">>> vtkPropCollection* props =<br clear="none">>> m_pWidget->m_pRenderer->GetViewProps();<br clear="none">>>
props->InitTraversal();<br clear="none">>> vtkProp* prop = NULL;<br clear="none">>> while( prop = props->GetNextProp() )<br clear="none">>> {<br clear="none">>> if( prop ==<br clear="none">>> vtkProp::SafeDownCast(m_pWidget->m_pDrrActor) )<br clear="none">>> {<br clear="none">>> m_pWidget->m_pDrrActor->SetOpacity(1.0);<br clear="none">>> m_pWidget->m_pTIFFActor->SetOpacity(0.5);<br clear="none">>>
break;<br clear="none">>> }<br clear="none">>> if( prop ==<br clear="none">>> vtkProp::SafeDownCast(m_pWidget->m_pTIFFActor) )<br clear="none">>> {<br clear="none">>> m_pWidget->m_pTIFFActor->SetOpacity(1.0);<br clear="none">>> m_pWidget->m_pDrrActor->SetOpacity(0.5);<br clear="none">>> break;<br clear="none">>>
}<br clear="none">>> }<br clear="none">>> }<br clear="none">>><br clear="none">>> Didn't solve to problem though....<br clear="none">>><br clear="none">>> I have made an algorithm that adds an alpha value to the tiff image:<br clear="none">>><br clear="none">>> vtkImageIterator<T> inIt(inData, outExt);<br clear="none">>> vtkImageIterator<float> outIt(outData, outExt);<br clear="none">>> int numIn = inData->GetNumberOfScalarComponents();<br clear="none">>> float alpha = self->GetAlpha();<br clear="none">>><br clear="none">>> // Loop through ouput pixels<br clear="none">>> while( !outIt.IsAtEnd() )<br clear="none">>> {<br clear="none">>>
T* inSI = inIt.BeginSpan();<br clear="none">>> float* outSI = outIt.BeginSpan();<br clear="none">>> float* outSIEnd = outIt.EndSpan();<br clear="none">>> while( outSI < outSIEnd )<br clear="none">>> {<br clear="none">>> // now process the components<br clear="none">>> for( int i = 0; i < numIn; ++i )<br clear="none">>> {<br clear="none">>> *outSI = static_cast<float>(*inSI);<br clear="none">>> ++outSI;<br clear="none">>> ++inSI;<br clear="none">>>
}<br clear="none">>> *outSI = alpha;<br clear="none">>> ++outSI;<br clear="none">>> }<br clear="none">>> inIt.NextSpan();<br clear="none">>> outIt.NextSpan();<br clear="none">>> }<br clear="none">>><br clear="none">>> in order to go through vtkImageActor::HasTranslucentPolygonalGeometry()<br clear="none">>> successfully.<br clear="none">>><br clear="none">>> Didn't solve it either.<br clear="none">>><br clear="none">>> I checked an older app of me in which I overlayed a transparent binary<br clear="none">>> image<br clear="none">>> on top of its original image. This worked fine using vtkActors. But in the<br clear="none">>> example both images had the same extent
and the order of the actors was<br clear="none">>> predetermined.<br clear="none">>><br clear="none">>> Maarten<br clear="none">>><br clear="none">>><br clear="none">>> On Thursday, January 16, 2014 5:30:47 PM, David Gobbi<br clear="none">>> <<a shape="rect" ymailto="mailto:david.gobbi@gmail.com" href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<br clear="none">>> On Thu, Jan 16, 2014 at 3:13 PM, Maarten Beek <<a shape="rect" ymailto="mailto:beekmaarten@yahoo.com" href="mailto:beekmaarten@yahoo.com">beekmaarten@yahoo.com</a>><br clear="none">>> wrote:<br clear="none">>>> I think I want to blend 50/50, so I could set the opacity accordingly in<br clear="none">>>> a<br clear="none">>>> callback initiated by a StartRender event?<br clear="none">>><br clear="none">>> You can set the opacity anywhere. You just have to make sure
that the<br clear="none">>> opacity<br clear="none">>> is set correctly, and you have to make sure that the images are in the<br clear="none">>> correct order. The thing about the images being in the correct order<br clear="none">>> is non-negotiable. You have to do it. Playing with depth isn't going<br clear="none">>> to help. The images actually have to be rendered in the right order<br clear="none">>> (an opaque image first, and a 50% opacity image after).<br clear="none">>><br clear="none">>>> I have played around with vtkImageStack; I seemed to get only the first<br clear="none">>>> (or<br clear="none">>>> last) image of the stack or (with transparency) all images blended<br clear="none">>>> together... I want one image of the stack blended with another (2d)<br clear="none">>>> image.<br clear="none">>>> Secondly, I thought creating 100
actors and adding them to a stack was<br clear="none">>>> quite<br clear="none">>>> slow.<br clear="none">>><br clear="none">>> Were you setting layer numbers (in the vtkImageProperty) for the images<br clear="none">>> that<br clear="none">>> you added to the stack? Were you setting VisibilityOff for the images<br clear="none">>> that<br clear="none">>> you<br clear="none">>> didn't want to show, and setting the correct Opacity for the images that<br clear="none">>> you<br clear="none">>> wanted to blend?<br clear="none">>><br clear="none">>> David<br clear="none">>><br clear="none">>><br clear="none">>><br clear="none">>><br clear="none">>>> On Thursday, January 16, 2014 4:58:53 PM, David Gobbi<br clear="none">>>> <<a shape="rect" ymailto="mailto:david.gobbi@gmail.com"
href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<br clear="none">>>> On Thu, Jan 16, 2014 at 2:45 PM, Maarten Beek <<a shape="rect" ymailto="mailto:beekmaarten@yahoo.com" href="mailto:beekmaarten@yahoo.com">beekmaarten@yahoo.com</a>><br clear="none">>>> wrote:<br clear="none">>>>> vtkImageActor::HasTranslucentPolygonalGeometry() seems to want image<br clear="none">>>>> data<br clear="none">>>>> of<br clear="none">>>>> type unsigned char and 2 or 4 components in order to do transparency.<br clear="none">>>>> I'm<br clear="none">>>>> using vtkImageShiftScale to get unsigned char and am working on an<br clear="none">>>>> algorithm<br clear="none">>>>> to add an alpha component to my one component tiff data. Curious if this<br clear="none">>>>> does the trick.<br clear="none">>>><br
clear="none">>>> I strongly suggest that you use vtkImageSliceMapper and vtkImageSlice<br clear="none">>>> to display your images instead of using vtkImageActor.<br clear="none">>>><br clear="none">>>>> I can understand the order is important if one of the actor is opaque,<br clear="none">>>>> but<br clear="none">>>>> why would this still be important when both are 50% transparent.<br clear="none">>>><br clear="none">>>> That's not how alpha-blending works. If both images are 50%, then the<br clear="none">>>> frontmost image is displayed at 50%, and the second image gets 25%,<br clear="none">>>> and the background gets the remaining 25%. That's how translucency<br clear="none">>>> works, both in real-life and in computer graphics.<br clear="none">>>><br clear="none">>>> If you want to blend images 50/50, then the
frontmost image should have<br clear="none">>>> 50% opacity and the backmost image should have 100% opacity.<br clear="none">>>><br clear="none">>>>> In my app the loading of each image is initiated through a button. I<br clear="none">>>>> would<br clear="none">>>>> like to create an app which is independent of the order in which the<br clear="none">>>>> user<br clear="none">>>>> clicks these buttons.<br clear="none">>>><br clear="none">>>> Order is crucial. That's why I recommend that you use vtkImageStack.<br clear="none">>>> It makes it possible to explicitly set the layer number for each image.<br clear="none">>>><br clear="none">>>> - David<br clear="none">>>><br clear="none">>>><br clear="none">>>><br clear="none">>>>> On Thursday, January 16, 2014 3:25:11 PM, David Gobbi<br
clear="none">>>>> <<a shape="rect" ymailto="mailto:david.gobbi@gmail.com" href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<br clear="none">>>>> Are you using vtk-master (or perhaps a vtk 6.1 release candidate)?<br clear="none">>>>> The TIFF reader had a serious multi-frame bug in older versions.<br clear="none">>>>><br clear="none">>>>> First, note that the vtkTIFFReader doesn't just give you the raw data<br clear="none">>>>> from the files, it seems to pass it through a lookup table sometimes.<br clear="none">>>>> And I'm not sure exactly how it deals with alpha, and to be honest,<br clear="none">>>>> I wouldn't trust it.<br clear="none">>>>><br clear="none">>>>> I'm really not sure what you mean when you say "The order of adding<br clear="none">>>>> the actors to the renderer matters, but I try
to avoid this by using<br clear="none">>>>> transparency." The order in which you add images is _crucial_ when<br clear="none">>>>> you are using transparency.<br clear="none">>>>><br clear="none">>>>> Are you using the vtkImageStack? It's a class that is designed<br clear="none">>>>> specifically to handle layered rendering of images.<br clear="none">>>>><br clear="none">>>>> David<br clear="none">>>>><br clear="none">>>>><br clear="none">>>>><br clear="none">>>>> On Thu, Jan 16, 2014 at 12:40 PM, Maarten Beek <<a shape="rect" ymailto="mailto:beekmaarten@yahoo.com" href="mailto:beekmaarten@yahoo.com">beekmaarten@yahoo.com</a>><br clear="none">>>>> wrote:<br clear="none">>>>>> Hi David,<br clear="none">>>>>><br clear="none">>>>>> Is it possible
to show all images in a multi-paged tiff transparently?<br clear="none">>>>>><br clear="none">>>>>> Only when I show the 1st image (page), I see a 2nd 2d image (both are<br clear="none">>>>>> transparent).<br clear="none">>>>>> As soon as I move to another tiff image (page), the 2d image<br clear="none">>>>>> disappears.<br clear="none">>>>>> It<br clear="none">>>>>> returns when I move back to the 1st tiff page.<br clear="none">>>>>><br clear="none">>>>>> The multi-paged tiff is one component, and I am thinking of an<br clear="none">>>>>> algorithm<br clear="none">>>>>> to<br clear="none">>>>>> add an alpha component, but can hardly believe this would be<br clear="none">>>>>> required...<br clear="none">>>>>><br clear="none">>>>>>
The order of adding the actors to the renderer matters, but I try to<br clear="none">>>>>> avoid<br clear="none">>>>>> this by using transparency.<br clear="none">>>>>><br clear="none">>>>>> Moving one image in front of the other by changing its z-coordinate<br clear="none">>>>>> using<br clear="none">>>>>> vtkImageActor::SetPosition() doesn't help.<br clear="none">>>>>><br clear="none">>>>>> Maarten<br clear="none">>>>>><br clear="none">>>>>><br clear="none">>>>>><br clear="none">>>>>> On Friday, November 8, 2013 4:36:06 PM, Maarten Beek<br clear="none">>>>>> <<a shape="rect" ymailto="mailto:beekmaarten@yahoo.com" href="mailto:beekmaarten@yahoo.com">beekmaarten@yahoo.com</a>><br clear="none">>>>>> wrote:<br clear="none">>>>>>
Hi David,<br clear="none">>>>>><br clear="none">>>>>> Using VTK 6.0.0, sorry ;-)<br clear="none">>>>>><br clear="none">>>>>> Should I send you the tiff file so you can play with it?<br clear="none">>>>>><br clear="none">>>>>> Now I seem to have your attention:<br clear="none">>>>>><br clear="none">>>>>> - How do I display a multi-page tif? I don't seem to see the different<br clear="none">>>>>> images using a vtkImageSlice.<br clear="none">>>>>><br clear="none">>>>>> - What would be good values for the window and level parameters? I am<br clear="none">>>>>> using<br clear="none">>>>>> window = range[1]-range[0] and level = 0.5*(range[0]+range[1]) which<br clear="none">>>>>> works<br clear="none">>>>>> ok for this multi-page tif, but
gets me nowhere when I try to display a<br clear="none">>>>>> drr.<br clear="none">>>>>><br clear="none">>>>>> Thanks - Maarten<br clear="none">>>>>><br clear="none">>>>>><br clear="none">>>>>><br clear="none">>>>>><br clear="none">>>>>><br clear="none">>>>>> On Friday, November 8, 2013 4:23:23 PM, David Gobbi<br clear="none">>>>>> <<a shape="rect" ymailto="mailto:david.gobbi@gmail.com" href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>><br clear="none">>>>>> wrote:<br clear="none">>>>>> Hi Maarten,<br clear="none">>>>>><br clear="none">>>>>> Which version of VTK are you using? I believe that this bug has been<br clear="none">>>>>> fixed in the master branch by a commits in the following topic merge:<br
clear="none">>>>>> <a shape="rect" href="http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=7e3d5270" target="_blank">http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=7e3d5270</a><br clear="none">>>>>><br clear="none">>>>>> It was not fixed in time for VTK 5.10, however.<br clear="none">>>>>><br clear="none">>>>>> David<br clear="none">>>>>><br clear="none">>>>>><br clear="none">>>>>> On Fri, Nov 8, 2013 at 2:12 PM, Maarten Beek <<a shape="rect" ymailto="mailto:beekmaarten@yahoo.com" href="mailto:beekmaarten@yahoo.com">beekmaarten@yahoo.com</a>><br clear="none">>>>>> wrote:<br clear="none">>>>>>> Hi all,<br clear="none">>>>>>><br clear="none">>>>>>> vtkTIFFReader crashed for me while loading a multi-paged tiff file.<br clear="none">>>>>>><br
clear="none">>>>>>> The crash occured in vtkTIFFReader::ReadGenericImage(), because<br clear="none">>>>>>> this->OutputExtent was not set (still NULL).<br clear="none">>>>>>> The scalar type for the image I was loading was unsigned short, so it<br clear="none">>>>>>> happened at line 1368.<br clear="none">>>>>>><br clear="none">>>>>>> I changed void vtkTIFFReader::ReadVolume(void* buffer) into void<br clear="none">>>>>>> vtkTIFFReader::ReadVolume(void* buffer, int outExt[6]) and added the<br clear="none">>>>>>> line<br clear="none">>>>>>> this->outputExtent = outExt.<br clear="none">>>>>>><br clear="none">>>>>>> This solved my crash.<br clear="none">>>>>>> I am not sure I am on to something, but thought to let you know.<br
clear="none">>>>>>><br clear="none">>>>>>> Maarten<br clear="none">>>>><br clear="none">>>>><br clear="none">>>><br clear="none">>>><br clear="none">>><br clear="none">>><br clear="none">><br clear="none">><br clear="none"></div><br><br></div> </div> </div> </div> </div></body></html>