<div dir="ltr">Thanks Andras,<div><br></div><div>I read through the links, but I wasn't able to identify the part that is relevant to my questions.</div><div><br></div><div>Would you be more specific? </div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Many thanks.<br><br><br></div>Bill<br></div></div></div>
<br><div class="gmail_quote">On Tue, Jun 6, 2017 at 11:01 AM, Andras Lasso <span dir="ltr"><<a href="mailto:lasso@queensu.ca" target="_blank">lasso@queensu.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div class="m_-172115568071144947WordSection1">
<p class="MsoNormal">See how it is implemented 3D Slicer and MITK:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><a href="https://github.com/Slicer/Slicer/blob/master/Libs/MRML/DisplayableManager/vtkThreeDViewInteractorStyle.cxx#L812-L848" target="_blank">https://github.com/Slicer/<wbr>Slicer/blob/master/Libs/MRML/<wbr>DisplayableManager/<wbr>vtkThreeDViewInteractorStyle.<wbr>cxx#L812-L848</a><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><a href="https://github.com/MITK/MITK/blob/master/Modules/Core/src/Rendering/mitkBaseRenderer.cpp#L600-L640" target="_blank">https://github.com/MITK/MITK/<wbr>blob/master/Modules/Core/src/<wbr>Rendering/mitkBaseRenderer.<wbr>cpp#L600-L640</a><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Andras<u></u><u></u></p>
<p class="MsoNormal"><a name="m_-172115568071144947__MailEndCompose"><u></u> <u></u></a></p>
<span></span>
<p class="MsoNormal"><span class=""><b>From:</b> vtkusers [mailto:<a href="mailto:vtkusers-bounces@vtk.org" target="_blank">vtkusers-bounces@vtk.<wbr>org</a>] <b>On Behalf Of
</b>Bill Q<br>
</span><b>Sent:</b> Monday, June 5, 2017 3:56 PM<br>
<b>To:</b> Elvis Stansvik <<a href="mailto:elvis.stansvik@orexplore.com" target="_blank">elvis.stansvik@orexplore.com</a>><span class=""><br>
<b>Cc:</b> VTK Users <<a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a>><br>
<b>Subject:</b> Re: [vtkusers] Issues with coordinate conversion, possible VTK bugs?<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Hi Elvis,<u></u><u></u></p><div><div class="h5">
<div>
<p class="MsoNormal">I did give it a try. But still, it didn't work. I think I must have missed something since there mush have hundreds of people tried to do the same thing, getting the world coordinate from the vtk screen. The only way it worked so far is
 to use a world picker. All other ways would return different settings with z valued at 88 something. Where is the z value coming from? Does the actor add the z in the renderer?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Would someone know the correct way doing it give some advices?<u></u><u></u></p>
</div>
</div></div></div><div><div class="h5">
<div>
<p class="MsoNormal"><br clear="all">
<u></u><u></u></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Many thanks.<br>
<br>
<u></u><u></u></p>
</div>
<p class="MsoNormal">Bill<u></u><u></u></p>
</div>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Sat, May 27, 2017 at 4:06 AM, Elvis Stansvik <<a href="mailto:elvis.stansvik@orexplore.com" target="_blank">elvis.stansvik@orexplore.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal">2017-05-26 20:08 GMT+02:00 Bill Q <<a href="mailto:bill.q.hdp@gmail.com" target="_blank">bill.q.hdp@gmail.com</a>>:<br>
> Hi Elvis and Dan,<br>
> Thank you very much for the response. After setting the render window<br>
> SetNumberOfLayers(2) and setting the renderer with text SetLayer(1), both<br>
> the layers with the DICOM images and the layer with the text can show up.<br>
> But, the problem still persists. I still cannot get the correct world<br>
> coordinates by using the following function:<br>
><br>
> def display_to_world2(self, pt):<br>
>     worldPt = [0, 0, 0, 0]<br>
>     vtk.vtkInteractorObserver.<wbr>ComputeDisplayToWorld(self.<wbr>renderer_dicom,<br>
> pt[0], pt[1], 0, worldPt)<br>
>     return worldPt[0] / worldPt[3], worldPt[1] / worldPt[3], worldPt[2] /<br>
> worldPt[3]<br>
><br>
> The z returned is always 86.33.<br>
><br>
> Meanwhile, I cannot use the world picker either, because it still picks the<br>
> text's world coordinate.<br>
><br>
> So, either I can make the above function work on the DICOM renderer or I<br>
> have to make the world picker not picking up anything on the text renderer.<br>
> I am not sure how I can get any of these two ways done.<br>
><br>
> Any suggestions would be greatly appreciated!<br>
<br>
Could you try turning interaction off on the renderer you use for your<br>
"foreground" objects. In my code I have:<br>
<br>
    auto foregroundRenderer = vtkSmartPointer<vtkRenderer>::<wbr>New();<br>
    foregroundRenderer-><wbr>InteractiveOff();<br>
    foregroundRenderer->SetLayer(<wbr>1);<br>
    ...<br>
    GetRenderWindow()-><wbr>SetNumberOfLayers(2);<br>
<br>
Hope that helps, it's the last idea I have :p<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><br>
Elvis<br>
<br>
><br>
><br>
> Many thanks.<br>
><br>
><br>
> Bill<br>
><br>
> On Thu, May 25, 2017 at 12:14 AM, Elvis Stansvik<br>
> <<a href="mailto:elvis.stansvik@orexplore.com" target="_blank">elvis.stansvik@orexplore.com</a>> wrote:<br>
>><br>
>> Den 24 maj 2017 5:27 em skrev "Bill Q" <<a href="mailto:bill.q.hdp@gmail.com" target="_blank">bill.q.hdp@gmail.com</a>>:<br>
>> ><br>
>> > Hi Dan,<br>
>> > After set the layer, I got this error:<br>
>> ><br>
>> > VTK-7.1.0\Rendering\Core\<wbr>vtkRendererCollection.cxx, line 61<br>
>> > vtkRendererCollection (000000001192E3A0): Invalid layer for renderer: not<br>
>> > rendered.<br>
>> ><br>
>> > And the text renderer didn't show up.<br>
>><br>
>> You'll need to call SetNumberOfLayers(2) on your render window first I<br>
>> think.<br>
>><br>
>> Elvis<br>
>><br>
>> ><br>
>> > Many thanks.<br>
>> ><br>
>> ><br>
>> > Bill<br>
>> ><br>
>> > On Wed, May 24, 2017 at 11:06 PM, Dan Lipsa <<a href="mailto:dan.lipsa@kitware.com" target="_blank">dan.lipsa@kitware.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> Bill,<br>
>> >> Try using SetLayer(1) for the renderer that has the text.<br>
>> >><br>
>> >> Dan<br>
>> >><br>
>> >><br>
>> >> On Wed, May 24, 2017 at 10:34 AM, Bill Q <<a href="mailto:bill.q.hdp@gmail.com" target="_blank">bill.q.hdp@gmail.com</a>> wrote:<br>
>> >>><br>
>> >>> Hi Dan,<br>
>> >>> Thanks a ton for the example. The example used 4 different viewports.<br>
>> >>> However, for my application, I need to set all renderers under the same<br>
>> >>> viewport. The problem is that if I add a second renderer into the render<br>
>> >>> window and using the default viewport, it will cover the first renderer and<br>
>> >>> nothing on the first renderer will show up. I am wondering if I did the<br>
>> >>> whole thing wrong.<br>
>> >>><br>
>> >>> My purpose is to display some DICOM images, some texts, and scales on<br>
>> >>> the same screen. Also, I would like to make the scales zoom with the DICOM<br>
>> >>> images but the texts stay put. Most importantly, I would like to get the<br>
>> >>> world coordinates on the DICOM image when users click on the screen, so I<br>
>> >>> can mark the click properly.<br>
>> >>><br>
>> >>> What should be done in order to get this working?<br>
>> >>><br>
>> >>><br>
>> >>> Many thanks.<br>
>> >>><br>
>> >>><br>
>> >>> Bill<br>
>> >>><br>
>> >>> On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <<a href="mailto:dan.lipsa@kitware.com" target="_blank">dan.lipsa@kitware.com</a>><br>
>> >>> wrote:<br>
>> >>>><br>
>> >>>> Not sure what is going on. Do the objects you are rendering have the<br>
>> >>>> same world coordinates? Are both renderers added to the rendering window?<br>
>> >>>> Here is an example with multiple renderer (they are over different<br>
>> >>>> viewports but they could have the same viewport as well)<br>
>> >>>><br>
>> >>>> <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/MultipleViewports" target="_blank">
http://www.vtk.org/Wiki/VTK/<wbr>Examples/Cxx/Visualization/<wbr>MultipleViewports</a><br>
>> >>>><br>
>> >>>> On Tue, May 23, 2017 at 11:39 AM, Bill Q <<a href="mailto:bill.q.hdp@gmail.com" target="_blank">bill.q.hdp@gmail.com</a>><br>
>> >>>> wrote:<br>
>> >>>>><br>
>> >>>>> I just gave it a try. But when I added another renderer into the<br>
>> >>>>> window that I used for text actors, it overlaps and covered the first<br>
>> >>>>> renderer. So the first renderer won't show up. Is there a solution?<br>
>> >>>>><br>
>> >>>>> Many thanks.<br>
>> >>>>><br>
>> >>>>><br>
>> >>>>> Bill<br>
>> >>>>><br>
>> >>>>> On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <<a href="mailto:dan.lipsa@kitware.com" target="_blank">dan.lipsa@kitware.com</a>><br>
>> >>>>> wrote:<br>
>> >>>>>><br>
>> >>>>>> I think moving those text actors on a different renderer will solve<br>
>> >>>>>> your problem.<br>
>> >>>>>><br>
>> >>>>>> Dan<br>
>> >>>>>><br>
>> >>>>>><br>
>> >>>>>> On Tue, May 23, 2017 at 9:40 AM, Bill Q <<a href="mailto:bill.q.hdp@gmail.com" target="_blank">bill.q.hdp@gmail.com</a>><br>
>> >>>>>> wrote:<br>
>> >>>>>>><br>
>> >>>>>>> Hi Dan,<br>
>> >>>>>>> Thanks a lot for the reply. Yes, that's exactly the case. If I<br>
>> >>>>>>> remove the text actors, the world picker would return the correct<br>
>> >>>>>>> coordinates. So, what method should I use in order to get the correct<br>
>> >>>>>>> coordinates no matter how many actors I put in with the dicom image reader<br>
>> >>>>>>> actor?<br>
>> >>>>>>><br>
>> >>>>>>> Many thanks.<br>
>> >>>>>>><br>
>> >>>>>>><br>
>> >>>>>>> Bill<br>
>> >>>>>>><br>
>> >>>>>>> On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa<br>
>> >>>>>>> <<a href="mailto:dan.lipsa@kitware.com" target="_blank">dan.lipsa@kitware.com</a>> wrote:<br>
>> >>>>>>>><br>
>> >>>>>>>> Bill,<br>
>> >>>>>>>> For display_to_world, the picker picks up only what is visible<br>
>> >>>>>>>> (closes to the camera). You might have several objects (several values in<br>
>> >>>>>>>> world coordinates) that end up over the same display coordinate. This might<br>
>> >>>>>>>> explain why adding those text actors changes what you pick.<br>
>> >>>>>>>><br>
>> >>>>>>>> Dan<br>
>> >>>>>>>><br>
>> >>>>>>>><br>
>> >>>>>>>><br>
>> >>>>>>>> On Sun, May 21, 2017 at 5:25 AM, Bill Q <<a href="mailto:bill.q.hdp@gmail.com" target="_blank">bill.q.hdp@gmail.com</a>><br>
>> >>>>>>>> wrote:<br>
>> >>>>>>>>><br>
>> >>>>>>>>> Can anybody help? Many thanks.<br>
>> >>>>>>>>><br>
>> >>>>>>>>> Many thanks.<br>
>> >>>>>>>>><br>
>> >>>>>>>>><br>
>> >>>>>>>>> Bill<br>
>> >>>>>>>>><br>
>> >>>>>>>>> On Fri, May 19, 2017 at 11:20 PM, Bill Q <<a href="mailto:bill.q.hdp@gmail.com" target="_blank">bill.q.hdp@gmail.com</a>><br>
>> >>>>>>>>> wrote:<br>
>> >>>>>>>>>><br>
>> >>>>>>>>>> Hello Everyone,<br>
>> >>>>>>>>>> I encountered a weird problem in coordinate conversion.<br>
>> >>>>>>>>>><br>
>> >>>>>>>>>> In order to check the accuracy, I converted from display to<br>
>> >>>>>>>>>> world, and from world back to display. Using the following ways:<br>
>> >>>>>>>>>><br>
>> >>>>>>>>>> self.world_picker = vtk.vtkWorldPointPicker()<br>
>> >>>>>>>>>><br>
>> >>>>>>>>>> def display_to_world(self, pt):<br>
>> >>>>>>>>>>     self.world_picker.Pick(pt[0], pt[1], 0, self.ren)<br>
>> >>>>>>>>>>     picker_pt = self.world_picker.<wbr>GetPickPosition()<br>
>> >>>>>>>>>>     picker_pt = (picker_pt[0], picker_pt[1], 0)<br>
>> >>>>>>>>>>     return picker_pt<br>
>> >>>>>>>>>><br>
>> >>>>>>>>>> def world_to_display(self, pt):<br>
>> >>>>>>>>>>     if len(pt) == 3:<br>
>> >>>>>>>>>>         pt = pt + (1.0,)<br>
>> >>>>>>>>>>     elif len(pt) == 2:<br>
>> >>>>>>>>>>         pt = pt + (0.0, 1.0)<br>
>> >>>>>>>>>>     self.ren.SetWorldPoint(pt)<br>
>> >>>>>>>>>>     self.ren.WorldToDisplay()<br>
>> >>>>>>>>>>     pt = self.ren.GetDisplayPoint()<br>
>> >>>>>>>>>>     pt = (pt[0], pt[1])<br>
>> >>>>>>>>>>     return pt<br>
>> >>>>>>>>>><br>
>> >>>>>>>>>> pt = [5, 5]<br>
>> >>>>>>>>>><br>
>> >>>>>>>>>> world_pt = self. world_to_display(pt)<br>
>> >>>>>>>>>><br>
>> >>>>>>>>>> display_pt = self. world_to_display(world_pt)<br>
>> >>>>>>>>>><br>
>> >>>>>>>>>> In some cases, it's quite accurate, which means pt equals<br>
>> >>>>>>>>>> display_pt. But, in some cases, the result is simply wrong. For example, for<br>
>> >>>>>>>>>> (5, 5), after conversions back to display, the coordinate becomes (20.89,<br>
>> >>>>>>>>>> 20.89).<br>
>> >>>>>>>>>><br>
>> >>>>>>>>>> Any ideas?<br>
>> >>>>>>>>>><br>
>> >>>>>>>>>><br>
>> >>>>>>>>>> Many thanks.<br>
>> >>>>>>>>>><br>
>> >>>>>>>>>><br>
>> >>>>>>>>>> Bill<br>
>> >>>>>>>>><br>
>> >>>>>>>>><br>
>> >>>>>>>>><br>
>> >>>>>>>>> ______________________________<wbr>_________________<br>
>> >>>>>>>>> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> >>>>>>>>><br>
>> >>>>>>>>> Visit other Kitware open-source projects at<br>
>> >>>>>>>>> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">
http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
>> >>>>>>>>><br>
>> >>>>>>>>> Please keep messages on-topic and check the VTK FAQ at:<br>
>> >>>>>>>>> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_<wbr>FAQ</a><br>
>> >>>>>>>>><br>
>> >>>>>>>>> Search the list archives at:<br>
>> >>>>>>>>> <a href="http://markmail.org/search/?q=vtkusers" target="_blank">http://markmail.org/search/?q=<wbr>vtkusers</a><br>
>> >>>>>>>>><br>
>> >>>>>>>>> Follow this link to subscribe/unsubscribe:<br>
>> >>>>>>>>> <a href="http://public.kitware.com/mailman/listinfo/vtkusers" target="_blank">
http://public.kitware.com/<wbr>mailman/listinfo/vtkusers</a><br>
>> >>>>>>>>><br>
>> >>>>>>>><br>
>> >>>>>>><br>
>> >>>>>><br>
>> >>>>><br>
>> >>>><br>
>> >>><br>
>> >><br>
>> ><br>
>> ><br>
>> > ______________________________<wbr>_________________<br>
>> > Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>> ><br>
>> > Visit other Kitware open-source projects at<br>
>> > <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">
http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
>> ><br>
>> > Please keep messages on-topic and check the VTK FAQ at:<br>
>> > <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_<wbr>FAQ</a><br>
>> ><br>
>> > Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" target="_blank">
http://markmail.org/search/?q=<wbr>vtkusers</a><br>
>> ><br>
>> > Follow this link to subscribe/unsubscribe:<br>
>> > <a href="http://public.kitware.com/mailman/listinfo/vtkusers" target="_blank">
http://public.kitware.com/<wbr>mailman/listinfo/vtkusers</a><br>
>> ><br>
><br>
><u></u><u></u></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div>
</div>

</blockquote></div><br></div>