Issues with coordinate conversion, possible VTK bugs?

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

Issues with coordinate conversion, possible VTK bugs?

Bill Q
Hello Everyone,
I encountered a weird problem in coordinate conversion.

In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:

self.world_picker = vtk.vtkWorldPointPicker()

def display_to_world(self, pt):
    self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
    picker_pt = self.world_picker.GetPickPosition()
    picker_pt = (picker_pt[0], picker_pt[1], 0)
    return picker_pt

def world_to_display(self, pt):
    if len(pt) == 3:
        pt = pt + (1.0,)
    elif len(pt) == 2:
        pt = pt + (0.0, 1.0)
    self.ren.SetWorldPoint(pt)
    self.ren.WorldToDisplay()
    pt = self.ren.GetDisplayPoint()
    pt = (pt[0], pt[1])
    return pt

pt = [5, 5]

world_pt = self. world_to_display(pt)

display_pt = self. world_to_display(world_pt)

In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).

Any ideas?


Many thanks.


Bill

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Bill Q
Ok, I might find the cause. I put some textActor at the lower left corner. So when I convert the coordinates to world, the returned coordinates are different from the ones if I take those textActor away. 

I could simply take those textActors away. But it doesn't feel like a real solution. Besides, I need to have those textActors there. 

Why putting some textActors there would change the readings of the coordinates conversion? Is there anything I can do?

Many thanks.


Bill

On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:
Hello Everyone,
I encountered a weird problem in coordinate conversion.

In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:

self.world_picker = vtk.vtkWorldPointPicker()

def display_to_world(self, pt):
    self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
    picker_pt = self.world_picker.GetPickPosition()
    picker_pt = (picker_pt[0], picker_pt[1], 0)
    return picker_pt

def world_to_display(self, pt):
    if len(pt) == 3:
        pt = pt + (1.0,)
    elif len(pt) == 2:
        pt = pt + (0.0, 1.0)
    self.ren.SetWorldPoint(pt)
    self.ren.WorldToDisplay()
    pt = self.ren.GetDisplayPoint()
    pt = (pt[0], pt[1])
    return pt

pt = [5, 5]

world_pt = self. world_to_display(pt)

display_pt = self. world_to_display(world_pt)

In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).

Any ideas?


Many thanks.


Bill


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Bill Q
In reply to this post by Bill Q
Can anybody help? Many thanks.

Many thanks.


Bill

On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:
Hello Everyone,
I encountered a weird problem in coordinate conversion.

In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:

self.world_picker = vtk.vtkWorldPointPicker()

def display_to_world(self, pt):
    self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
    picker_pt = self.world_picker.GetPickPosition()
    picker_pt = (picker_pt[0], picker_pt[1], 0)
    return picker_pt

def world_to_display(self, pt):
    if len(pt) == 3:
        pt = pt + (1.0,)
    elif len(pt) == 2:
        pt = pt + (0.0, 1.0)
    self.ren.SetWorldPoint(pt)
    self.ren.WorldToDisplay()
    pt = self.ren.GetDisplayPoint()
    pt = (pt[0], pt[1])
    return pt

pt = [5, 5]

world_pt = self. world_to_display(pt)

display_pt = self. world_to_display(world_pt)

In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).

Any ideas?


Many thanks.


Bill


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Dan Lipsa-2
Bill,
For display_to_world, the picker picks up only what is visible (closes to the camera). You might have several objects (several values in world coordinates) that end up over the same display coordinate. This might explain why adding those text actors changes what you pick.

Dan



On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]> wrote:
Can anybody help? Many thanks.

Many thanks.


Bill

On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:
Hello Everyone,
I encountered a weird problem in coordinate conversion.

In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:

self.world_picker = vtk.vtkWorldPointPicker()

def display_to_world(self, pt):
    self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
    picker_pt = self.world_picker.GetPickPosition()
    picker_pt = (picker_pt[0], picker_pt[1], 0)
    return picker_pt

def world_to_display(self, pt):
    if len(pt) == 3:
        pt = pt + (1.0,)
    elif len(pt) == 2:
        pt = pt + (0.0, 1.0)
    self.ren.SetWorldPoint(pt)
    self.ren.WorldToDisplay()
    pt = self.ren.GetDisplayPoint()
    pt = (pt[0], pt[1])
    return pt

pt = [5, 5]

world_pt = self. world_to_display(pt)

display_pt = self. world_to_display(world_pt)

In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).

Any ideas?


Many thanks.


Bill


_______________________________________________
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



_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Bill Q
Hi Dan,
Thanks a lot for the reply. Yes, that's exactly the case. If I remove the text actors, the world picker would return the correct coordinates. So, what method should I use in order to get the correct coordinates no matter how many actors I put in with the dicom image reader actor?

Many thanks.


Bill

On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa <[hidden email]> wrote:
Bill,
For display_to_world, the picker picks up only what is visible (closes to the camera). You might have several objects (several values in world coordinates) that end up over the same display coordinate. This might explain why adding those text actors changes what you pick.

Dan



On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]> wrote:
Can anybody help? Many thanks.

Many thanks.


Bill

On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:
Hello Everyone,
I encountered a weird problem in coordinate conversion.

In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:

self.world_picker = vtk.vtkWorldPointPicker()

def display_to_world(self, pt):
    self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
    picker_pt = self.world_picker.GetPickPosition()
    picker_pt = (picker_pt[0], picker_pt[1], 0)
    return picker_pt

def world_to_display(self, pt):
    if len(pt) == 3:
        pt = pt + (1.0,)
    elif len(pt) == 2:
        pt = pt + (0.0, 1.0)
    self.ren.SetWorldPoint(pt)
    self.ren.WorldToDisplay()
    pt = self.ren.GetDisplayPoint()
    pt = (pt[0], pt[1])
    return pt

pt = [5, 5]

world_pt = self. world_to_display(pt)

display_pt = self. world_to_display(world_pt)

In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).

Any ideas?


Many thanks.


Bill


_______________________________________________
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




_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Dan Lipsa-2
I think moving those text actors on a different renderer will solve your problem.

Dan


On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]> wrote:
Hi Dan,
Thanks a lot for the reply. Yes, that's exactly the case. If I remove the text actors, the world picker would return the correct coordinates. So, what method should I use in order to get the correct coordinates no matter how many actors I put in with the dicom image reader actor?

Many thanks.


Bill

On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa <[hidden email]> wrote:
Bill,
For display_to_world, the picker picks up only what is visible (closes to the camera). You might have several objects (several values in world coordinates) that end up over the same display coordinate. This might explain why adding those text actors changes what you pick.

Dan



On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]> wrote:
Can anybody help? Many thanks.

Many thanks.


Bill

On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:
Hello Everyone,
I encountered a weird problem in coordinate conversion.

In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:

self.world_picker = vtk.vtkWorldPointPicker()

def display_to_world(self, pt):
    self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
    picker_pt = self.world_picker.GetPickPosition()
    picker_pt = (picker_pt[0], picker_pt[1], 0)
    return picker_pt

def world_to_display(self, pt):
    if len(pt) == 3:
        pt = pt + (1.0,)
    elif len(pt) == 2:
        pt = pt + (0.0, 1.0)
    self.ren.SetWorldPoint(pt)
    self.ren.WorldToDisplay()
    pt = self.ren.GetDisplayPoint()
    pt = (pt[0], pt[1])
    return pt

pt = [5, 5]

world_pt = self. world_to_display(pt)

display_pt = self. world_to_display(world_pt)

In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).

Any ideas?


Many thanks.


Bill


_______________________________________________
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





_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Bill Q
I just gave it a try. But when I added another renderer into the window that I used for text actors, it overlaps and covered the first renderer. So the first renderer won't show up. Is there a solution?

Many thanks.


Bill

On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]> wrote:
I think moving those text actors on a different renderer will solve your problem.

Dan


On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]> wrote:
Hi Dan,
Thanks a lot for the reply. Yes, that's exactly the case. If I remove the text actors, the world picker would return the correct coordinates. So, what method should I use in order to get the correct coordinates no matter how many actors I put in with the dicom image reader actor?

Many thanks.


Bill

On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa <[hidden email]> wrote:
Bill,
For display_to_world, the picker picks up only what is visible (closes to the camera). You might have several objects (several values in world coordinates) that end up over the same display coordinate. This might explain why adding those text actors changes what you pick.

Dan



On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]> wrote:
Can anybody help? Many thanks.

Many thanks.


Bill

On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:
Hello Everyone,
I encountered a weird problem in coordinate conversion.

In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:

self.world_picker = vtk.vtkWorldPointPicker()

def display_to_world(self, pt):
    self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
    picker_pt = self.world_picker.GetPickPosition()
    picker_pt = (picker_pt[0], picker_pt[1], 0)
    return picker_pt

def world_to_display(self, pt):
    if len(pt) == 3:
        pt = pt + (1.0,)
    elif len(pt) == 2:
        pt = pt + (0.0, 1.0)
    self.ren.SetWorldPoint(pt)
    self.ren.WorldToDisplay()
    pt = self.ren.GetDisplayPoint()
    pt = (pt[0], pt[1])
    return pt

pt = [5, 5]

world_pt = self. world_to_display(pt)

display_pt = self. world_to_display(world_pt)

In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).

Any ideas?


Many thanks.


Bill


_______________________________________________
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






_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Dan Lipsa-2
Not sure what is going on. Do the objects you are rendering have the same world coordinates? Are both renderers added to the rendering window?
Here is an example with multiple renderer (they are over different viewports but they could have the same viewport as well)

On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]> wrote:
I just gave it a try. But when I added another renderer into the window that I used for text actors, it overlaps and covered the first renderer. So the first renderer won't show up. Is there a solution?

Many thanks.


Bill

On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]> wrote:
I think moving those text actors on a different renderer will solve your problem.

Dan


On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]> wrote:
Hi Dan,
Thanks a lot for the reply. Yes, that's exactly the case. If I remove the text actors, the world picker would return the correct coordinates. So, what method should I use in order to get the correct coordinates no matter how many actors I put in with the dicom image reader actor?

Many thanks.


Bill

On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa <[hidden email]> wrote:
Bill,
For display_to_world, the picker picks up only what is visible (closes to the camera). You might have several objects (several values in world coordinates) that end up over the same display coordinate. This might explain why adding those text actors changes what you pick.

Dan



On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]> wrote:
Can anybody help? Many thanks.

Many thanks.


Bill

On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:
Hello Everyone,
I encountered a weird problem in coordinate conversion.

In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:

self.world_picker = vtk.vtkWorldPointPicker()

def display_to_world(self, pt):
    self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
    picker_pt = self.world_picker.GetPickPosition()
    picker_pt = (picker_pt[0], picker_pt[1], 0)
    return picker_pt

def world_to_display(self, pt):
    if len(pt) == 3:
        pt = pt + (1.0,)
    elif len(pt) == 2:
        pt = pt + (0.0, 1.0)
    self.ren.SetWorldPoint(pt)
    self.ren.WorldToDisplay()
    pt = self.ren.GetDisplayPoint()
    pt = (pt[0], pt[1])
    return pt

pt = [5, 5]

world_pt = self. world_to_display(pt)

display_pt = self. world_to_display(world_pt)

In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).

Any ideas?


Many thanks.


Bill


_______________________________________________
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







_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Bill Q
Hi Dan,
Thanks a ton for the example. The example used 4 different viewports. However, for my application, I need to set all renderers under the same viewport. The problem is that if I add a second renderer into the render window and using the default viewport, it will cover the first renderer and nothing on the first renderer will show up. I am wondering if I did the whole thing wrong.

My purpose is to display some DICOM images, some texts, and scales on the same screen. Also, I would like to make the scales zoom with the DICOM images but the texts stay put. Most importantly, I would like to get the world coordinates on the DICOM image when users click on the screen, so I can mark the click properly.

What should be done in order to get this working?


Many thanks.


Bill

On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <[hidden email]> wrote:
Not sure what is going on. Do the objects you are rendering have the same world coordinates? Are both renderers added to the rendering window?
Here is an example with multiple renderer (they are over different viewports but they could have the same viewport as well)

On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]> wrote:
I just gave it a try. But when I added another renderer into the window that I used for text actors, it overlaps and covered the first renderer. So the first renderer won't show up. Is there a solution?

Many thanks.


Bill

On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]> wrote:
I think moving those text actors on a different renderer will solve your problem.

Dan


On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]> wrote:
Hi Dan,
Thanks a lot for the reply. Yes, that's exactly the case. If I remove the text actors, the world picker would return the correct coordinates. So, what method should I use in order to get the correct coordinates no matter how many actors I put in with the dicom image reader actor?

Many thanks.


Bill

On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa <[hidden email]> wrote:
Bill,
For display_to_world, the picker picks up only what is visible (closes to the camera). You might have several objects (several values in world coordinates) that end up over the same display coordinate. This might explain why adding those text actors changes what you pick.

Dan



On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]> wrote:
Can anybody help? Many thanks.

Many thanks.


Bill

On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:
Hello Everyone,
I encountered a weird problem in coordinate conversion.

In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:

self.world_picker = vtk.vtkWorldPointPicker()

def display_to_world(self, pt):
    self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
    picker_pt = self.world_picker.GetPickPosition()
    picker_pt = (picker_pt[0], picker_pt[1], 0)
    return picker_pt

def world_to_display(self, pt):
    if len(pt) == 3:
        pt = pt + (1.0,)
    elif len(pt) == 2:
        pt = pt + (0.0, 1.0)
    self.ren.SetWorldPoint(pt)
    self.ren.WorldToDisplay()
    pt = self.ren.GetDisplayPoint()
    pt = (pt[0], pt[1])
    return pt

pt = [5, 5]

world_pt = self. world_to_display(pt)

display_pt = self. world_to_display(world_pt)

In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).

Any ideas?


Many thanks.


Bill


_______________________________________________
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








_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Dan Lipsa-2
Bill,
Try using SetLayer(1) for the renderer that has the text.

Dan


On Wed, May 24, 2017 at 10:34 AM, Bill Q <[hidden email]> wrote:
Hi Dan,
Thanks a ton for the example. The example used 4 different viewports. However, for my application, I need to set all renderers under the same viewport. The problem is that if I add a second renderer into the render window and using the default viewport, it will cover the first renderer and nothing on the first renderer will show up. I am wondering if I did the whole thing wrong.

My purpose is to display some DICOM images, some texts, and scales on the same screen. Also, I would like to make the scales zoom with the DICOM images but the texts stay put. Most importantly, I would like to get the world coordinates on the DICOM image when users click on the screen, so I can mark the click properly.

What should be done in order to get this working?


Many thanks.


Bill

On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <[hidden email]> wrote:
Not sure what is going on. Do the objects you are rendering have the same world coordinates? Are both renderers added to the rendering window?
Here is an example with multiple renderer (they are over different viewports but they could have the same viewport as well)

On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]> wrote:
I just gave it a try. But when I added another renderer into the window that I used for text actors, it overlaps and covered the first renderer. So the first renderer won't show up. Is there a solution?

Many thanks.


Bill

On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]> wrote:
I think moving those text actors on a different renderer will solve your problem.

Dan


On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]> wrote:
Hi Dan,
Thanks a lot for the reply. Yes, that's exactly the case. If I remove the text actors, the world picker would return the correct coordinates. So, what method should I use in order to get the correct coordinates no matter how many actors I put in with the dicom image reader actor?

Many thanks.


Bill

On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa <[hidden email]> wrote:
Bill,
For display_to_world, the picker picks up only what is visible (closes to the camera). You might have several objects (several values in world coordinates) that end up over the same display coordinate. This might explain why adding those text actors changes what you pick.

Dan



On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]> wrote:
Can anybody help? Many thanks.

Many thanks.


Bill

On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:
Hello Everyone,
I encountered a weird problem in coordinate conversion.

In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:

self.world_picker = vtk.vtkWorldPointPicker()

def display_to_world(self, pt):
    self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
    picker_pt = self.world_picker.GetPickPosition()
    picker_pt = (picker_pt[0], picker_pt[1], 0)
    return picker_pt

def world_to_display(self, pt):
    if len(pt) == 3:
        pt = pt + (1.0,)
    elif len(pt) == 2:
        pt = pt + (0.0, 1.0)
    self.ren.SetWorldPoint(pt)
    self.ren.WorldToDisplay()
    pt = self.ren.GetDisplayPoint()
    pt = (pt[0], pt[1])
    return pt

pt = [5, 5]

world_pt = self. world_to_display(pt)

display_pt = self. world_to_display(world_pt)

In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).

Any ideas?


Many thanks.


Bill


_______________________________________________
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









_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Bill Q
Hi Dan,
After set the layer, I got this error: 

VTK-7.1.0\Rendering\Core\vtkRendererCollection.cxx, line 61 vtkRendererCollection (000000001192E3A0): Invalid layer for renderer: not rendered.

And the text renderer didn't show up.

Many thanks.


Bill

On Wed, May 24, 2017 at 11:06 PM, Dan Lipsa <[hidden email]> wrote:
Bill,
Try using SetLayer(1) for the renderer that has the text.

Dan


On Wed, May 24, 2017 at 10:34 AM, Bill Q <[hidden email]> wrote:
Hi Dan,
Thanks a ton for the example. The example used 4 different viewports. However, for my application, I need to set all renderers under the same viewport. The problem is that if I add a second renderer into the render window and using the default viewport, it will cover the first renderer and nothing on the first renderer will show up. I am wondering if I did the whole thing wrong.

My purpose is to display some DICOM images, some texts, and scales on the same screen. Also, I would like to make the scales zoom with the DICOM images but the texts stay put. Most importantly, I would like to get the world coordinates on the DICOM image when users click on the screen, so I can mark the click properly.

What should be done in order to get this working?


Many thanks.


Bill

On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <[hidden email]> wrote:
Not sure what is going on. Do the objects you are rendering have the same world coordinates? Are both renderers added to the rendering window?
Here is an example with multiple renderer (they are over different viewports but they could have the same viewport as well)

On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]> wrote:
I just gave it a try. But when I added another renderer into the window that I used for text actors, it overlaps and covered the first renderer. So the first renderer won't show up. Is there a solution?

Many thanks.


Bill

On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]> wrote:
I think moving those text actors on a different renderer will solve your problem.

Dan


On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]> wrote:
Hi Dan,
Thanks a lot for the reply. Yes, that's exactly the case. If I remove the text actors, the world picker would return the correct coordinates. So, what method should I use in order to get the correct coordinates no matter how many actors I put in with the dicom image reader actor?

Many thanks.


Bill

On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa <[hidden email]> wrote:
Bill,
For display_to_world, the picker picks up only what is visible (closes to the camera). You might have several objects (several values in world coordinates) that end up over the same display coordinate. This might explain why adding those text actors changes what you pick.

Dan



On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]> wrote:
Can anybody help? Many thanks.

Many thanks.


Bill

On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:
Hello Everyone,
I encountered a weird problem in coordinate conversion.

In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:

self.world_picker = vtk.vtkWorldPointPicker()

def display_to_world(self, pt):
    self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
    picker_pt = self.world_picker.GetPickPosition()
    picker_pt = (picker_pt[0], picker_pt[1], 0)
    return picker_pt

def world_to_display(self, pt):
    if len(pt) == 3:
        pt = pt + (1.0,)
    elif len(pt) == 2:
        pt = pt + (0.0, 1.0)
    self.ren.SetWorldPoint(pt)
    self.ren.WorldToDisplay()
    pt = self.ren.GetDisplayPoint()
    pt = (pt[0], pt[1])
    return pt

pt = [5, 5]

world_pt = self. world_to_display(pt)

display_pt = self. world_to_display(world_pt)

In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).

Any ideas?


Many thanks.


Bill


_______________________________________________
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










_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Elvis Stansvik

Den 24 maj 2017 5:27 em skrev "Bill Q" <[hidden email]>:
>
> Hi Dan,
> After set the layer, I got this error: 
>
> VTK-7.1.0\Rendering\Core\vtkRendererCollection.cxx, line 61 vtkRendererCollection (000000001192E3A0): Invalid layer for renderer: not rendered.
>
> And the text renderer didn't show up.

You'll need to call SetNumberOfLayers(2) on your render window first I think.

Elvis

>
> Many thanks.
>
>
> Bill
>
> On Wed, May 24, 2017 at 11:06 PM, Dan Lipsa <[hidden email]> wrote:
>>
>> Bill,
>> Try using SetLayer(1) for the renderer that has the text.
>>
>> Dan
>>
>>
>> On Wed, May 24, 2017 at 10:34 AM, Bill Q <[hidden email]> wrote:
>>>
>>> Hi Dan,
>>> Thanks a ton for the example. The example used 4 different viewports. However, for my application, I need to set all renderers under the same viewport. The problem is that if I add a second renderer into the render window and using the default viewport, it will cover the first renderer and nothing on the first renderer will show up. I am wondering if I did the whole thing wrong.
>>>
>>> My purpose is to display some DICOM images, some texts, and scales on the same screen. Also, I would like to make the scales zoom with the DICOM images but the texts stay put. Most importantly, I would like to get the world coordinates on the DICOM image when users click on the screen, so I can mark the click properly.
>>>
>>> What should be done in order to get this working?
>>>
>>>
>>> Many thanks.
>>>
>>>
>>> Bill
>>>
>>> On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <[hidden email]> wrote:
>>>>
>>>> Not sure what is going on. Do the objects you are rendering have the same world coordinates? Are both renderers added to the rendering window?
>>>> Here is an example with multiple renderer (they are over different viewports but they could have the same viewport as well)
>>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/MultipleViewports
>>>>
>>>> On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]> wrote:
>>>>>
>>>>> I just gave it a try. But when I added another renderer into the window that I used for text actors, it overlaps and covered the first renderer. So the first renderer won't show up. Is there a solution?
>>>>>
>>>>> Many thanks.
>>>>>
>>>>>
>>>>> Bill
>>>>>
>>>>> On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]> wrote:
>>>>>>
>>>>>> I think moving those text actors on a different renderer will solve your problem.
>>>>>>
>>>>>> Dan
>>>>>>
>>>>>>
>>>>>> On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]> wrote:
>>>>>>>
>>>>>>> Hi Dan,
>>>>>>> Thanks a lot for the reply. Yes, that's exactly the case. If I remove the text actors, the world picker would return the correct coordinates. So, what method should I use in order to get the correct coordinates no matter how many actors I put in with the dicom image reader actor?
>>>>>>>
>>>>>>> Many thanks.
>>>>>>>
>>>>>>>
>>>>>>> Bill
>>>>>>>
>>>>>>> On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa <[hidden email]> wrote:
>>>>>>>>
>>>>>>>> Bill,
>>>>>>>> For display_to_world, the picker picks up only what is visible (closes to the camera). You might have several objects (several values in world coordinates) that end up over the same display coordinate. This might explain why adding those text actors changes what you pick.
>>>>>>>>
>>>>>>>> Dan
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]> wrote:
>>>>>>>>>
>>>>>>>>> Can anybody help? Many thanks.
>>>>>>>>>
>>>>>>>>> Many thanks.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Bill
>>>>>>>>>
>>>>>>>>> On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:
>>>>>>>>>>
>>>>>>>>>> Hello Everyone,
>>>>>>>>>> I encountered a weird problem in coordinate conversion.
>>>>>>>>>>
>>>>>>>>>> In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:
>>>>>>>>>>
>>>>>>>>>> self.world_picker = vtk.vtkWorldPointPicker()
>>>>>>>>>>
>>>>>>>>>> def display_to_world(self, pt):
>>>>>>>>>>     self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
>>>>>>>>>>     picker_pt = self.world_picker.GetPickPosition()
>>>>>>>>>>     picker_pt = (picker_pt[0], picker_pt[1], 0)
>>>>>>>>>>     return picker_pt
>>>>>>>>>>
>>>>>>>>>> def world_to_display(self, pt):
>>>>>>>>>>     if len(pt) == 3:
>>>>>>>>>>         pt = pt + (1.0,)
>>>>>>>>>>     elif len(pt) == 2:
>>>>>>>>>>         pt = pt + (0.0, 1.0)
>>>>>>>>>>     self.ren.SetWorldPoint(pt)
>>>>>>>>>>     self.ren.WorldToDisplay()
>>>>>>>>>>     pt = self.ren.GetDisplayPoint()
>>>>>>>>>>     pt = (pt[0], pt[1])
>>>>>>>>>>     return pt
>>>>>>>>>>
>>>>>>>>>> pt = [5, 5]
>>>>>>>>>>
>>>>>>>>>> world_pt = self. world_to_display(pt)
>>>>>>>>>>
>>>>>>>>>> display_pt = self. world_to_display(world_pt)
>>>>>>>>>>
>>>>>>>>>> In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).
>>>>>>>>>>
>>>>>>>>>> Any ideas?
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Many thanks.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Bill
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> 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
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
>
> _______________________________________________
> 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
>


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Andras Lasso
In reply to this post by Bill Q

There are many free, open-source, VTK-based medical image computing software applications that do exactly these and much more (3D Slicer, ITK-Snap, MITK, etc). Just have a look at their source code and copy-paste what you need (at least from 3D Slicer and MITK, as they have BSD-type license).

 

Or, even better, save yourself a couple of years of work and implement your application as custom plugins in one of these applications. The advantage of building on an existing application framework is that all the features that you don’t even know that your users will request, are already implemented, documented, and tested by thousands of users. It made sense 10-15 years ago to develop medical applications from scratch, but now that there are very good, established platforms, you should build on top of those.

 

Andras

 

From: vtkusers [mailto:[hidden email]] On Behalf Of Bill Q
Sent: Wednesday, May 24, 2017 10:35 AM
To: Dan Lipsa <[hidden email]>
Cc: VTK Users <[hidden email]>
Subject: Re: [vtkusers] Issues with coordinate conversion, possible VTK bugs?

 

Hi Dan,

Thanks a ton for the example. The example used 4 different viewports. However, for my application, I need to set all renderers under the same viewport. The problem is that if I add a second renderer into the render window and using the default viewport, it will cover the first renderer and nothing on the first renderer will show up. I am wondering if I did the whole thing wrong.

 

My purpose is to display some DICOM images, some texts, and scales on the same screen. Also, I would like to make the scales zoom with the DICOM images but the texts stay put. Most importantly, I would like to get the world coordinates on the DICOM image when users click on the screen, so I can mark the click properly.

 

What should be done in order to get this working?

 


Many thanks.

Bill

 

On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <[hidden email]> wrote:

Not sure what is going on. Do the objects you are rendering have the same world coordinates? Are both renderers added to the rendering window?

Here is an example with multiple renderer (they are over different viewports but they could have the same viewport as well)

 

On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]> wrote:

I just gave it a try. But when I added another renderer into the window that I used for text actors, it overlaps and covered the first renderer. So the first renderer won't show up. Is there a solution?


Many thanks.

Bill

 

On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]> wrote:

I think moving those text actors on a different renderer will solve your problem.

 

Dan

 

 

On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]> wrote:

Hi Dan,

Thanks a lot for the reply. Yes, that's exactly the case. If I remove the text actors, the world picker would return the correct coordinates. So, what method should I use in order to get the correct coordinates no matter how many actors I put in with the dicom image reader actor?


Many thanks.

Bill

 

On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa <[hidden email]> wrote:

Bill,

For display_to_world, the picker picks up only what is visible (closes to the camera). You might have several objects (several values in world coordinates) that end up over the same display coordinate. This might explain why adding those text actors changes what you pick.

 

Dan

 

 

 

On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]> wrote:

Can anybody help? Many thanks.


Many thanks.

Bill

 

On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:

Hello Everyone,

I encountered a weird problem in coordinate conversion.

 

In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:

self.world_picker = vtk.vtkWorldPointPicker()

def display_to_world(self, pt):
    self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
    picker_pt = self.world_picker.GetPickPosition()
    picker_pt = (picker_pt[0], picker_pt[1], 0)
    return picker_pt

def world_to_display(self, pt):
    if len(pt) == 3:
        pt = pt + (1.0,)
    elif len(pt) == 2:
        pt = pt + (0.0, 1.0)
    self.ren.SetWorldPoint(pt)
    self.ren.WorldToDisplay()
    pt = self.ren.GetDisplayPoint()
    pt = (pt[0], pt[1])
    return pt

pt = [5, 5]

world_pt = self. world_to_display(pt)

display_pt = self. world_to_display(world_pt)

In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).

 

Any ideas?

 

 

Many thanks.

Bill

 

 

_______________________________________________
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

 

 

 

 

 

 


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Bill Q
In reply to this post by Elvis Stansvik
Hi Elvis and Dan,
Thank you very much for the response. After setting the render window SetNumberOfLayers(2) and setting the renderer with text SetLayer(1), both the layers with the DICOM images and the layer with the text can show up. But, the problem still persists. I still cannot get the correct world coordinates by using the following function:

def display_to_world2(self, pt):
   
worldPt = [0, 0, 0, 0]
   
vtk.vtkInteractorObserver.ComputeDisplayToWorld(self.renderer_dicom, pt[0], pt[1], 0, worldPt)
    return worldPt[0] / worldPt[3], worldPt[1] / worldPt[3], worldPt[2] / worldPt[3]

The z returned is always 86.33.

Meanwhile, I cannot use the world picker either, because it still picks the text's world coordinate.

So, either I can make the above function work on the DICOM renderer or I have to make the world picker not picking up anything on the text renderer. I am not sure how I can get any of these two ways done.

Any suggestions would be greatly appreciated!


Many thanks.


Bill

On Thu, May 25, 2017 at 12:14 AM, Elvis Stansvik <[hidden email]> wrote:

Den 24 maj 2017 5:27 em skrev "Bill Q" <[hidden email]>:
>
> Hi Dan,
> After set the layer, I got this error: 
>
> VTK-7.1.0\Rendering\Core\vtkRendererCollection.cxx, line 61 vtkRendererCollection (000000001192E3A0): Invalid layer for renderer: not rendered.
>
> And the text renderer didn't show up.

You'll need to call SetNumberOfLayers(2) on your render window first I think.

Elvis

>
> Many thanks.
>
>
> Bill
>
> On Wed, May 24, 2017 at 11:06 PM, Dan Lipsa <[hidden email]> wrote:
>>
>> Bill,
>> Try using SetLayer(1) for the renderer that has the text.
>>
>> Dan
>>
>>
>> On Wed, May 24, 2017 at 10:34 AM, Bill Q <[hidden email]> wrote:
>>>
>>> Hi Dan,
>>> Thanks a ton for the example. The example used 4 different viewports. However, for my application, I need to set all renderers under the same viewport. The problem is that if I add a second renderer into the render window and using the default viewport, it will cover the first renderer and nothing on the first renderer will show up. I am wondering if I did the whole thing wrong.
>>>
>>> My purpose is to display some DICOM images, some texts, and scales on the same screen. Also, I would like to make the scales zoom with the DICOM images but the texts stay put. Most importantly, I would like to get the world coordinates on the DICOM image when users click on the screen, so I can mark the click properly.
>>>
>>> What should be done in order to get this working?
>>>
>>>
>>> Many thanks.
>>>
>>>
>>> Bill
>>>
>>> On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <[hidden email]> wrote:
>>>>
>>>> Not sure what is going on. Do the objects you are rendering have the same world coordinates? Are both renderers added to the rendering window?
>>>> Here is an example with multiple renderer (they are over different viewports but they could have the same viewport as well)
>>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/MultipleViewports
>>>>
>>>> On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]> wrote:
>>>>>
>>>>> I just gave it a try. But when I added another renderer into the window that I used for text actors, it overlaps and covered the first renderer. So the first renderer won't show up. Is there a solution?
>>>>>
>>>>> Many thanks.
>>>>>
>>>>>
>>>>> Bill
>>>>>
>>>>> On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]> wrote:
>>>>>>
>>>>>> I think moving those text actors on a different renderer will solve your problem.
>>>>>>
>>>>>> Dan
>>>>>>
>>>>>>
>>>>>> On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]> wrote:
>>>>>>>
>>>>>>> Hi Dan,
>>>>>>> Thanks a lot for the reply. Yes, that's exactly the case. If I remove the text actors, the world picker would return the correct coordinates. So, what method should I use in order to get the correct coordinates no matter how many actors I put in with the dicom image reader actor?
>>>>>>>
>>>>>>> Many thanks.
>>>>>>>
>>>>>>>
>>>>>>> Bill
>>>>>>>
>>>>>>> On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa <[hidden email]> wrote:
>>>>>>>>
>>>>>>>> Bill,
>>>>>>>> For display_to_world, the picker picks up only what is visible (closes to the camera). You might have several objects (several values in world coordinates) that end up over the same display coordinate. This might explain why adding those text actors changes what you pick.
>>>>>>>>
>>>>>>>> Dan
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]> wrote:
>>>>>>>>>
>>>>>>>>> Can anybody help? Many thanks.
>>>>>>>>>
>>>>>>>>> Many thanks.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Bill
>>>>>>>>>
>>>>>>>>> On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]> wrote:
>>>>>>>>>>
>>>>>>>>>> Hello Everyone,
>>>>>>>>>> I encountered a weird problem in coordinate conversion.
>>>>>>>>>>
>>>>>>>>>> In order to check the accuracy, I converted from display to world, and from world back to display. Using the following ways:
>>>>>>>>>>
>>>>>>>>>> self.world_picker = vtk.vtkWorldPointPicker()
>>>>>>>>>>
>>>>>>>>>> def display_to_world(self, pt):
>>>>>>>>>>     self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
>>>>>>>>>>     picker_pt = self.world_picker.GetPickPosition()
>>>>>>>>>>     picker_pt = (picker_pt[0], picker_pt[1], 0)
>>>>>>>>>>     return picker_pt
>>>>>>>>>>
>>>>>>>>>> def world_to_display(self, pt):
>>>>>>>>>>     if len(pt) == 3:
>>>>>>>>>>         pt = pt + (1.0,)
>>>>>>>>>>     elif len(pt) == 2:
>>>>>>>>>>         pt = pt + (0.0, 1.0)
>>>>>>>>>>     self.ren.SetWorldPoint(pt)
>>>>>>>>>>     self.ren.WorldToDisplay()
>>>>>>>>>>     pt = self.ren.GetDisplayPoint()
>>>>>>>>>>     pt = (pt[0], pt[1])
>>>>>>>>>>     return pt
>>>>>>>>>>
>>>>>>>>>> pt = [5, 5]
>>>>>>>>>>
>>>>>>>>>> world_pt = self. world_to_display(pt)
>>>>>>>>>>
>>>>>>>>>> display_pt = self. world_to_display(world_pt)
>>>>>>>>>>
>>>>>>>>>> In some cases, it's quite accurate, which means pt equals display_pt. But, in some cases, the result is simply wrong. For example, for (5, 5), after conversions back to display, the coordinate becomes (20.89, 20.89).
>>>>>>>>>>
>>>>>>>>>> Any ideas?
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Many thanks.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Bill
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> 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
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
>
> _______________________________________________
> 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
>



_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Elvis Stansvik
2017-05-26 20:08 GMT+02:00 Bill Q <[hidden email]>:

> Hi Elvis and Dan,
> Thank you very much for the response. After setting the render window
> SetNumberOfLayers(2) and setting the renderer with text SetLayer(1), both
> the layers with the DICOM images and the layer with the text can show up.
> But, the problem still persists. I still cannot get the correct world
> coordinates by using the following function:
>
> def display_to_world2(self, pt):
>     worldPt = [0, 0, 0, 0]
>     vtk.vtkInteractorObserver.ComputeDisplayToWorld(self.renderer_dicom,
> pt[0], pt[1], 0, worldPt)
>     return worldPt[0] / worldPt[3], worldPt[1] / worldPt[3], worldPt[2] /
> worldPt[3]
>
> The z returned is always 86.33.
>
> Meanwhile, I cannot use the world picker either, because it still picks the
> text's world coordinate.
>
> So, either I can make the above function work on the DICOM renderer or I
> have to make the world picker not picking up anything on the text renderer.
> I am not sure how I can get any of these two ways done.
>
> Any suggestions would be greatly appreciated!

Could you try turning interaction off on the renderer you use for your
"foreground" objects. In my code I have:

    auto foregroundRenderer = vtkSmartPointer<vtkRenderer>::New();
    foregroundRenderer->InteractiveOff();
    foregroundRenderer->SetLayer(1);
    ...
    GetRenderWindow()->SetNumberOfLayers(2);

Hope that helps, it's the last idea I have :p

Elvis

>
>
> Many thanks.
>
>
> Bill
>
> On Thu, May 25, 2017 at 12:14 AM, Elvis Stansvik
> <[hidden email]> wrote:
>>
>> Den 24 maj 2017 5:27 em skrev "Bill Q" <[hidden email]>:
>> >
>> > Hi Dan,
>> > After set the layer, I got this error:
>> >
>> > VTK-7.1.0\Rendering\Core\vtkRendererCollection.cxx, line 61
>> > vtkRendererCollection (000000001192E3A0): Invalid layer for renderer: not
>> > rendered.
>> >
>> > And the text renderer didn't show up.
>>
>> You'll need to call SetNumberOfLayers(2) on your render window first I
>> think.
>>
>> Elvis
>>
>> >
>> > Many thanks.
>> >
>> >
>> > Bill
>> >
>> > On Wed, May 24, 2017 at 11:06 PM, Dan Lipsa <[hidden email]>
>> > wrote:
>> >>
>> >> Bill,
>> >> Try using SetLayer(1) for the renderer that has the text.
>> >>
>> >> Dan
>> >>
>> >>
>> >> On Wed, May 24, 2017 at 10:34 AM, Bill Q <[hidden email]> wrote:
>> >>>
>> >>> Hi Dan,
>> >>> Thanks a ton for the example. The example used 4 different viewports.
>> >>> However, for my application, I need to set all renderers under the same
>> >>> viewport. The problem is that if I add a second renderer into the render
>> >>> window and using the default viewport, it will cover the first renderer and
>> >>> nothing on the first renderer will show up. I am wondering if I did the
>> >>> whole thing wrong.
>> >>>
>> >>> My purpose is to display some DICOM images, some texts, and scales on
>> >>> the same screen. Also, I would like to make the scales zoom with the DICOM
>> >>> images but the texts stay put. Most importantly, I would like to get the
>> >>> world coordinates on the DICOM image when users click on the screen, so I
>> >>> can mark the click properly.
>> >>>
>> >>> What should be done in order to get this working?
>> >>>
>> >>>
>> >>> Many thanks.
>> >>>
>> >>>
>> >>> Bill
>> >>>
>> >>> On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <[hidden email]>
>> >>> wrote:
>> >>>>
>> >>>> Not sure what is going on. Do the objects you are rendering have the
>> >>>> same world coordinates? Are both renderers added to the rendering window?
>> >>>> Here is an example with multiple renderer (they are over different
>> >>>> viewports but they could have the same viewport as well)
>> >>>>
>> >>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/MultipleViewports
>> >>>>
>> >>>> On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]>
>> >>>> wrote:
>> >>>>>
>> >>>>> I just gave it a try. But when I added another renderer into the
>> >>>>> window that I used for text actors, it overlaps and covered the first
>> >>>>> renderer. So the first renderer won't show up. Is there a solution?
>> >>>>>
>> >>>>> Many thanks.
>> >>>>>
>> >>>>>
>> >>>>> Bill
>> >>>>>
>> >>>>> On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]>
>> >>>>> wrote:
>> >>>>>>
>> >>>>>> I think moving those text actors on a different renderer will solve
>> >>>>>> your problem.
>> >>>>>>
>> >>>>>> Dan
>> >>>>>>
>> >>>>>>
>> >>>>>> On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]>
>> >>>>>> wrote:
>> >>>>>>>
>> >>>>>>> Hi Dan,
>> >>>>>>> Thanks a lot for the reply. Yes, that's exactly the case. If I
>> >>>>>>> remove the text actors, the world picker would return the correct
>> >>>>>>> coordinates. So, what method should I use in order to get the correct
>> >>>>>>> coordinates no matter how many actors I put in with the dicom image reader
>> >>>>>>> actor?
>> >>>>>>>
>> >>>>>>> Many thanks.
>> >>>>>>>
>> >>>>>>>
>> >>>>>>> Bill
>> >>>>>>>
>> >>>>>>> On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa
>> >>>>>>> <[hidden email]> wrote:
>> >>>>>>>>
>> >>>>>>>> Bill,
>> >>>>>>>> For display_to_world, the picker picks up only what is visible
>> >>>>>>>> (closes to the camera). You might have several objects (several values in
>> >>>>>>>> world coordinates) that end up over the same display coordinate. This might
>> >>>>>>>> explain why adding those text actors changes what you pick.
>> >>>>>>>>
>> >>>>>>>> Dan
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>> On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]>
>> >>>>>>>> wrote:
>> >>>>>>>>>
>> >>>>>>>>> Can anybody help? Many thanks.
>> >>>>>>>>>
>> >>>>>>>>> Many thanks.
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> Bill
>> >>>>>>>>>
>> >>>>>>>>> On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]>
>> >>>>>>>>> wrote:
>> >>>>>>>>>>
>> >>>>>>>>>> Hello Everyone,
>> >>>>>>>>>> I encountered a weird problem in coordinate conversion.
>> >>>>>>>>>>
>> >>>>>>>>>> In order to check the accuracy, I converted from display to
>> >>>>>>>>>> world, and from world back to display. Using the following ways:
>> >>>>>>>>>>
>> >>>>>>>>>> self.world_picker = vtk.vtkWorldPointPicker()
>> >>>>>>>>>>
>> >>>>>>>>>> def display_to_world(self, pt):
>> >>>>>>>>>>     self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
>> >>>>>>>>>>     picker_pt = self.world_picker.GetPickPosition()
>> >>>>>>>>>>     picker_pt = (picker_pt[0], picker_pt[1], 0)
>> >>>>>>>>>>     return picker_pt
>> >>>>>>>>>>
>> >>>>>>>>>> def world_to_display(self, pt):
>> >>>>>>>>>>     if len(pt) == 3:
>> >>>>>>>>>>         pt = pt + (1.0,)
>> >>>>>>>>>>     elif len(pt) == 2:
>> >>>>>>>>>>         pt = pt + (0.0, 1.0)
>> >>>>>>>>>>     self.ren.SetWorldPoint(pt)
>> >>>>>>>>>>     self.ren.WorldToDisplay()
>> >>>>>>>>>>     pt = self.ren.GetDisplayPoint()
>> >>>>>>>>>>     pt = (pt[0], pt[1])
>> >>>>>>>>>>     return pt
>> >>>>>>>>>>
>> >>>>>>>>>> pt = [5, 5]
>> >>>>>>>>>>
>> >>>>>>>>>> world_pt = self. world_to_display(pt)
>> >>>>>>>>>>
>> >>>>>>>>>> display_pt = self. world_to_display(world_pt)
>> >>>>>>>>>>
>> >>>>>>>>>> In some cases, it's quite accurate, which means pt equals
>> >>>>>>>>>> display_pt. But, in some cases, the result is simply wrong. For example, for
>> >>>>>>>>>> (5, 5), after conversions back to display, the coordinate becomes (20.89,
>> >>>>>>>>>> 20.89).
>> >>>>>>>>>>
>> >>>>>>>>>> Any ideas?
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Many thanks.
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Bill
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> _______________________________________________
>> >>>>>>>>> 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
>> >>>>>>>>>
>> >>>>>>>>
>> >>>>>>>
>> >>>>>>
>> >>>>>
>> >>>>
>> >>>
>> >>
>> >
>> >
>> > _______________________________________________
>> > 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
>> >
>
>
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Bill Q
Hi Elvis,
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?

Would someone know the correct way doing it give some advices?

Many thanks.


Bill

On Sat, May 27, 2017 at 4:06 AM, Elvis Stansvik <[hidden email]> wrote:
2017-05-26 20:08 GMT+02:00 Bill Q <[hidden email]>:
> Hi Elvis and Dan,
> Thank you very much for the response. After setting the render window
> SetNumberOfLayers(2) and setting the renderer with text SetLayer(1), both
> the layers with the DICOM images and the layer with the text can show up.
> But, the problem still persists. I still cannot get the correct world
> coordinates by using the following function:
>
> def display_to_world2(self, pt):
>     worldPt = [0, 0, 0, 0]
>     vtk.vtkInteractorObserver.ComputeDisplayToWorld(self.renderer_dicom,
> pt[0], pt[1], 0, worldPt)
>     return worldPt[0] / worldPt[3], worldPt[1] / worldPt[3], worldPt[2] /
> worldPt[3]
>
> The z returned is always 86.33.
>
> Meanwhile, I cannot use the world picker either, because it still picks the
> text's world coordinate.
>
> So, either I can make the above function work on the DICOM renderer or I
> have to make the world picker not picking up anything on the text renderer.
> I am not sure how I can get any of these two ways done.
>
> Any suggestions would be greatly appreciated!

Could you try turning interaction off on the renderer you use for your
"foreground" objects. In my code I have:

    auto foregroundRenderer = vtkSmartPointer<vtkRenderer>::New();
    foregroundRenderer->InteractiveOff();
    foregroundRenderer->SetLayer(1);
    ...
    GetRenderWindow()->SetNumberOfLayers(2);

Hope that helps, it's the last idea I have :p

Elvis

>
>
> Many thanks.
>
>
> Bill
>
> On Thu, May 25, 2017 at 12:14 AM, Elvis Stansvik
> <[hidden email]> wrote:
>>
>> Den 24 maj 2017 5:27 em skrev "Bill Q" <[hidden email]>:
>> >
>> > Hi Dan,
>> > After set the layer, I got this error:
>> >
>> > VTK-7.1.0\Rendering\Core\vtkRendererCollection.cxx, line 61
>> > vtkRendererCollection (000000001192E3A0): Invalid layer for renderer: not
>> > rendered.
>> >
>> > And the text renderer didn't show up.
>>
>> You'll need to call SetNumberOfLayers(2) on your render window first I
>> think.
>>
>> Elvis
>>
>> >
>> > Many thanks.
>> >
>> >
>> > Bill
>> >
>> > On Wed, May 24, 2017 at 11:06 PM, Dan Lipsa <[hidden email]>
>> > wrote:
>> >>
>> >> Bill,
>> >> Try using SetLayer(1) for the renderer that has the text.
>> >>
>> >> Dan
>> >>
>> >>
>> >> On Wed, May 24, 2017 at 10:34 AM, Bill Q <[hidden email]> wrote:
>> >>>
>> >>> Hi Dan,
>> >>> Thanks a ton for the example. The example used 4 different viewports.
>> >>> However, for my application, I need to set all renderers under the same
>> >>> viewport. The problem is that if I add a second renderer into the render
>> >>> window and using the default viewport, it will cover the first renderer and
>> >>> nothing on the first renderer will show up. I am wondering if I did the
>> >>> whole thing wrong.
>> >>>
>> >>> My purpose is to display some DICOM images, some texts, and scales on
>> >>> the same screen. Also, I would like to make the scales zoom with the DICOM
>> >>> images but the texts stay put. Most importantly, I would like to get the
>> >>> world coordinates on the DICOM image when users click on the screen, so I
>> >>> can mark the click properly.
>> >>>
>> >>> What should be done in order to get this working?
>> >>>
>> >>>
>> >>> Many thanks.
>> >>>
>> >>>
>> >>> Bill
>> >>>
>> >>> On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <[hidden email]>
>> >>> wrote:
>> >>>>
>> >>>> Not sure what is going on. Do the objects you are rendering have the
>> >>>> same world coordinates? Are both renderers added to the rendering window?
>> >>>> Here is an example with multiple renderer (they are over different
>> >>>> viewports but they could have the same viewport as well)
>> >>>>
>> >>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/MultipleViewports
>> >>>>
>> >>>> On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]>
>> >>>> wrote:
>> >>>>>
>> >>>>> I just gave it a try. But when I added another renderer into the
>> >>>>> window that I used for text actors, it overlaps and covered the first
>> >>>>> renderer. So the first renderer won't show up. Is there a solution?
>> >>>>>
>> >>>>> Many thanks.
>> >>>>>
>> >>>>>
>> >>>>> Bill
>> >>>>>
>> >>>>> On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]>
>> >>>>> wrote:
>> >>>>>>
>> >>>>>> I think moving those text actors on a different renderer will solve
>> >>>>>> your problem.
>> >>>>>>
>> >>>>>> Dan
>> >>>>>>
>> >>>>>>
>> >>>>>> On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]>
>> >>>>>> wrote:
>> >>>>>>>
>> >>>>>>> Hi Dan,
>> >>>>>>> Thanks a lot for the reply. Yes, that's exactly the case. If I
>> >>>>>>> remove the text actors, the world picker would return the correct
>> >>>>>>> coordinates. So, what method should I use in order to get the correct
>> >>>>>>> coordinates no matter how many actors I put in with the dicom image reader
>> >>>>>>> actor?
>> >>>>>>>
>> >>>>>>> Many thanks.
>> >>>>>>>
>> >>>>>>>
>> >>>>>>> Bill
>> >>>>>>>
>> >>>>>>> On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa
>> >>>>>>> <[hidden email]> wrote:
>> >>>>>>>>
>> >>>>>>>> Bill,
>> >>>>>>>> For display_to_world, the picker picks up only what is visible
>> >>>>>>>> (closes to the camera). You might have several objects (several values in
>> >>>>>>>> world coordinates) that end up over the same display coordinate. This might
>> >>>>>>>> explain why adding those text actors changes what you pick.
>> >>>>>>>>
>> >>>>>>>> Dan
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>> On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]>
>> >>>>>>>> wrote:
>> >>>>>>>>>
>> >>>>>>>>> Can anybody help? Many thanks.
>> >>>>>>>>>
>> >>>>>>>>> Many thanks.
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> Bill
>> >>>>>>>>>
>> >>>>>>>>> On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]>
>> >>>>>>>>> wrote:
>> >>>>>>>>>>
>> >>>>>>>>>> Hello Everyone,
>> >>>>>>>>>> I encountered a weird problem in coordinate conversion.
>> >>>>>>>>>>
>> >>>>>>>>>> In order to check the accuracy, I converted from display to
>> >>>>>>>>>> world, and from world back to display. Using the following ways:
>> >>>>>>>>>>
>> >>>>>>>>>> self.world_picker = vtk.vtkWorldPointPicker()
>> >>>>>>>>>>
>> >>>>>>>>>> def display_to_world(self, pt):
>> >>>>>>>>>>     self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
>> >>>>>>>>>>     picker_pt = self.world_picker.GetPickPosition()
>> >>>>>>>>>>     picker_pt = (picker_pt[0], picker_pt[1], 0)
>> >>>>>>>>>>     return picker_pt
>> >>>>>>>>>>
>> >>>>>>>>>> def world_to_display(self, pt):
>> >>>>>>>>>>     if len(pt) == 3:
>> >>>>>>>>>>         pt = pt + (1.0,)
>> >>>>>>>>>>     elif len(pt) == 2:
>> >>>>>>>>>>         pt = pt + (0.0, 1.0)
>> >>>>>>>>>>     self.ren.SetWorldPoint(pt)
>> >>>>>>>>>>     self.ren.WorldToDisplay()
>> >>>>>>>>>>     pt = self.ren.GetDisplayPoint()
>> >>>>>>>>>>     pt = (pt[0], pt[1])
>> >>>>>>>>>>     return pt
>> >>>>>>>>>>
>> >>>>>>>>>> pt = [5, 5]
>> >>>>>>>>>>
>> >>>>>>>>>> world_pt = self. world_to_display(pt)
>> >>>>>>>>>>
>> >>>>>>>>>> display_pt = self. world_to_display(world_pt)
>> >>>>>>>>>>
>> >>>>>>>>>> In some cases, it's quite accurate, which means pt equals
>> >>>>>>>>>> display_pt. But, in some cases, the result is simply wrong. For example, for
>> >>>>>>>>>> (5, 5), after conversions back to display, the coordinate becomes (20.89,
>> >>>>>>>>>> 20.89).
>> >>>>>>>>>>
>> >>>>>>>>>> Any ideas?
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Many thanks.
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Bill
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> _______________________________________________
>> >>>>>>>>> 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
>> >>>>>>>>>
>> >>>>>>>>
>> >>>>>>>
>> >>>>>>
>> >>>>>
>> >>>>
>> >>>
>> >>
>> >
>> >
>> > _______________________________________________
>> > 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
>> >
>
>


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Andras Lasso

See how it is implemented 3D Slicer and MITK:

 

https://github.com/Slicer/Slicer/blob/master/Libs/MRML/DisplayableManager/vtkThreeDViewInteractorStyle.cxx#L812-L848

 

https://github.com/MITK/MITK/blob/master/Modules/Core/src/Rendering/mitkBaseRenderer.cpp#L600-L640

 

Andras

 

From: vtkusers [mailto:[hidden email]] On Behalf Of Bill Q
Sent: Monday, June 5, 2017 3:56 PM
To: Elvis Stansvik <[hidden email]>
Cc: VTK Users <[hidden email]>
Subject: Re: [vtkusers] Issues with coordinate conversion, possible VTK bugs?

 

Hi Elvis,

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?

 

Would someone know the correct way doing it give some advices?


Many thanks.

Bill

 

On Sat, May 27, 2017 at 4:06 AM, Elvis Stansvik <[hidden email]> wrote:

2017-05-26 20:08 GMT+02:00 Bill Q <[hidden email]>:
> Hi Elvis and Dan,
> Thank you very much for the response. After setting the render window
> SetNumberOfLayers(2) and setting the renderer with text SetLayer(1), both
> the layers with the DICOM images and the layer with the text can show up.
> But, the problem still persists. I still cannot get the correct world
> coordinates by using the following function:
>
> def display_to_world2(self, pt):
>     worldPt = [0, 0, 0, 0]
>     vtk.vtkInteractorObserver.ComputeDisplayToWorld(self.renderer_dicom,
> pt[0], pt[1], 0, worldPt)
>     return worldPt[0] / worldPt[3], worldPt[1] / worldPt[3], worldPt[2] /
> worldPt[3]
>
> The z returned is always 86.33.
>
> Meanwhile, I cannot use the world picker either, because it still picks the
> text's world coordinate.
>
> So, either I can make the above function work on the DICOM renderer or I
> have to make the world picker not picking up anything on the text renderer.
> I am not sure how I can get any of these two ways done.
>
> Any suggestions would be greatly appreciated!

Could you try turning interaction off on the renderer you use for your
"foreground" objects. In my code I have:

    auto foregroundRenderer = vtkSmartPointer<vtkRenderer>::New();
    foregroundRenderer->InteractiveOff();
    foregroundRenderer->SetLayer(1);
    ...
    GetRenderWindow()->SetNumberOfLayers(2);

Hope that helps, it's the last idea I have :p


Elvis

>
>
> Many thanks.
>
>
> Bill
>
> On Thu, May 25, 2017 at 12:14 AM, Elvis Stansvik
> <[hidden email]> wrote:
>>
>> Den 24 maj 2017 5:27 em skrev "Bill Q" <[hidden email]>:
>> >
>> > Hi Dan,
>> > After set the layer, I got this error:
>> >
>> > VTK-7.1.0\Rendering\Core\vtkRendererCollection.cxx, line 61
>> > vtkRendererCollection (000000001192E3A0): Invalid layer for renderer: not
>> > rendered.
>> >
>> > And the text renderer didn't show up.
>>
>> You'll need to call SetNumberOfLayers(2) on your render window first I
>> think.
>>
>> Elvis
>>
>> >
>> > Many thanks.
>> >
>> >
>> > Bill
>> >
>> > On Wed, May 24, 2017 at 11:06 PM, Dan Lipsa <[hidden email]>
>> > wrote:
>> >>
>> >> Bill,
>> >> Try using SetLayer(1) for the renderer that has the text.
>> >>
>> >> Dan
>> >>
>> >>
>> >> On Wed, May 24, 2017 at 10:34 AM, Bill Q <[hidden email]> wrote:
>> >>>
>> >>> Hi Dan,
>> >>> Thanks a ton for the example. The example used 4 different viewports.
>> >>> However, for my application, I need to set all renderers under the same
>> >>> viewport. The problem is that if I add a second renderer into the render
>> >>> window and using the default viewport, it will cover the first renderer and
>> >>> nothing on the first renderer will show up. I am wondering if I did the
>> >>> whole thing wrong.
>> >>>
>> >>> My purpose is to display some DICOM images, some texts, and scales on
>> >>> the same screen. Also, I would like to make the scales zoom with the DICOM
>> >>> images but the texts stay put. Most importantly, I would like to get the
>> >>> world coordinates on the DICOM image when users click on the screen, so I
>> >>> can mark the click properly.
>> >>>
>> >>> What should be done in order to get this working?
>> >>>
>> >>>
>> >>> Many thanks.
>> >>>
>> >>>
>> >>> Bill
>> >>>
>> >>> On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <[hidden email]>
>> >>> wrote:
>> >>>>
>> >>>> Not sure what is going on. Do the objects you are rendering have the
>> >>>> same world coordinates? Are both renderers added to the rendering window?
>> >>>> Here is an example with multiple renderer (they are over different
>> >>>> viewports but they could have the same viewport as well)
>> >>>>
>> >>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/MultipleViewports
>> >>>>
>> >>>> On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]>
>> >>>> wrote:
>> >>>>>
>> >>>>> I just gave it a try. But when I added another renderer into the
>> >>>>> window that I used for text actors, it overlaps and covered the first
>> >>>>> renderer. So the first renderer won't show up. Is there a solution?
>> >>>>>
>> >>>>> Many thanks.
>> >>>>>
>> >>>>>
>> >>>>> Bill
>> >>>>>
>> >>>>> On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]>
>> >>>>> wrote:
>> >>>>>>
>> >>>>>> I think moving those text actors on a different renderer will solve
>> >>>>>> your problem.
>> >>>>>>
>> >>>>>> Dan
>> >>>>>>
>> >>>>>>
>> >>>>>> On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]>
>> >>>>>> wrote:
>> >>>>>>>
>> >>>>>>> Hi Dan,
>> >>>>>>> Thanks a lot for the reply. Yes, that's exactly the case. If I
>> >>>>>>> remove the text actors, the world picker would return the correct
>> >>>>>>> coordinates. So, what method should I use in order to get the correct
>> >>>>>>> coordinates no matter how many actors I put in with the dicom image reader
>> >>>>>>> actor?
>> >>>>>>>
>> >>>>>>> Many thanks.
>> >>>>>>>
>> >>>>>>>
>> >>>>>>> Bill
>> >>>>>>>
>> >>>>>>> On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa
>> >>>>>>> <[hidden email]> wrote:
>> >>>>>>>>
>> >>>>>>>> Bill,
>> >>>>>>>> For display_to_world, the picker picks up only what is visible
>> >>>>>>>> (closes to the camera). You might have several objects (several values in
>> >>>>>>>> world coordinates) that end up over the same display coordinate. This might
>> >>>>>>>> explain why adding those text actors changes what you pick.
>> >>>>>>>>
>> >>>>>>>> Dan
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>> On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]>
>> >>>>>>>> wrote:
>> >>>>>>>>>
>> >>>>>>>>> Can anybody help? Many thanks.
>> >>>>>>>>>
>> >>>>>>>>> Many thanks.
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> Bill
>> >>>>>>>>>
>> >>>>>>>>> On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]>
>> >>>>>>>>> wrote:
>> >>>>>>>>>>
>> >>>>>>>>>> Hello Everyone,
>> >>>>>>>>>> I encountered a weird problem in coordinate conversion.
>> >>>>>>>>>>
>> >>>>>>>>>> In order to check the accuracy, I converted from display to
>> >>>>>>>>>> world, and from world back to display. Using the following ways:
>> >>>>>>>>>>
>> >>>>>>>>>> self.world_picker = vtk.vtkWorldPointPicker()
>> >>>>>>>>>>
>> >>>>>>>>>> def display_to_world(self, pt):
>> >>>>>>>>>>     self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
>> >>>>>>>>>>     picker_pt = self.world_picker.GetPickPosition()
>> >>>>>>>>>>     picker_pt = (picker_pt[0], picker_pt[1], 0)
>> >>>>>>>>>>     return picker_pt
>> >>>>>>>>>>
>> >>>>>>>>>> def world_to_display(self, pt):
>> >>>>>>>>>>     if len(pt) == 3:
>> >>>>>>>>>>         pt = pt + (1.0,)
>> >>>>>>>>>>     elif len(pt) == 2:
>> >>>>>>>>>>         pt = pt + (0.0, 1.0)
>> >>>>>>>>>>     self.ren.SetWorldPoint(pt)
>> >>>>>>>>>>     self.ren.WorldToDisplay()
>> >>>>>>>>>>     pt = self.ren.GetDisplayPoint()
>> >>>>>>>>>>     pt = (pt[0], pt[1])
>> >>>>>>>>>>     return pt
>> >>>>>>>>>>
>> >>>>>>>>>> pt = [5, 5]
>> >>>>>>>>>>
>> >>>>>>>>>> world_pt = self. world_to_display(pt)
>> >>>>>>>>>>
>> >>>>>>>>>> display_pt = self. world_to_display(world_pt)
>> >>>>>>>>>>
>> >>>>>>>>>> In some cases, it's quite accurate, which means pt equals
>> >>>>>>>>>> display_pt. But, in some cases, the result is simply wrong. For example, for
>> >>>>>>>>>> (5, 5), after conversions back to display, the coordinate becomes (20.89,
>> >>>>>>>>>> 20.89).
>> >>>>>>>>>>
>> >>>>>>>>>> Any ideas?
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Many thanks.
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Bill
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> _______________________________________________
>> >>>>>>>>> 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
>> >>>>>>>>>
>> >>>>>>>>
>> >>>>>>>
>> >>>>>>
>> >>>>>
>> >>>>
>> >>>
>> >>
>> >
>> >
>> > _______________________________________________
>> > 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
>> >
>
>

 


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Bill Q
Thanks Andras,

I read through the links, but I wasn't able to identify the part that is relevant to my questions.

Would you be more specific? 

Many thanks.


Bill

On Tue, Jun 6, 2017 at 11:01 AM, Andras Lasso <[hidden email]> wrote:

See how it is implemented 3D Slicer and MITK:

 

https://github.com/Slicer/Slicer/blob/master/Libs/MRML/DisplayableManager/vtkThreeDViewInteractorStyle.cxx#L812-L848

 

https://github.com/MITK/MITK/blob/master/Modules/Core/src/Rendering/mitkBaseRenderer.cpp#L600-L640

 

Andras

 

From: vtkusers [mailto:[hidden email]] On Behalf Of Bill Q
Sent: Monday, June 5, 2017 3:56 PM
To: Elvis Stansvik <[hidden email]>
Cc: VTK Users <[hidden email]>
Subject: Re: [vtkusers] Issues with coordinate conversion, possible VTK bugs?

 

Hi Elvis,

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?

 

Would someone know the correct way doing it give some advices?


Many thanks.

Bill

 

On Sat, May 27, 2017 at 4:06 AM, Elvis Stansvik <[hidden email]> wrote:

2017-05-26 20:08 GMT+02:00 Bill Q <[hidden email]>:
> Hi Elvis and Dan,
> Thank you very much for the response. After setting the render window
> SetNumberOfLayers(2) and setting the renderer with text SetLayer(1), both
> the layers with the DICOM images and the layer with the text can show up.
> But, the problem still persists. I still cannot get the correct world
> coordinates by using the following function:
>
> def display_to_world2(self, pt):
>     worldPt = [0, 0, 0, 0]
>     vtk.vtkInteractorObserver.ComputeDisplayToWorld(self.renderer_dicom,
> pt[0], pt[1], 0, worldPt)
>     return worldPt[0] / worldPt[3], worldPt[1] / worldPt[3], worldPt[2] /
> worldPt[3]
>
> The z returned is always 86.33.
>
> Meanwhile, I cannot use the world picker either, because it still picks the
> text's world coordinate.
>
> So, either I can make the above function work on the DICOM renderer or I
> have to make the world picker not picking up anything on the text renderer.
> I am not sure how I can get any of these two ways done.
>
> Any suggestions would be greatly appreciated!

Could you try turning interaction off on the renderer you use for your
"foreground" objects. In my code I have:

    auto foregroundRenderer = vtkSmartPointer<vtkRenderer>::New();
    foregroundRenderer->InteractiveOff();
    foregroundRenderer->SetLayer(1);
    ...
    GetRenderWindow()->SetNumberOfLayers(2);

Hope that helps, it's the last idea I have :p


Elvis

>
>
> Many thanks.
>
>
> Bill
>
> On Thu, May 25, 2017 at 12:14 AM, Elvis Stansvik
> <[hidden email]> wrote:
>>
>> Den 24 maj 2017 5:27 em skrev "Bill Q" <[hidden email]>:
>> >
>> > Hi Dan,
>> > After set the layer, I got this error:
>> >
>> > VTK-7.1.0\Rendering\Core\vtkRendererCollection.cxx, line 61
>> > vtkRendererCollection (000000001192E3A0): Invalid layer for renderer: not
>> > rendered.
>> >
>> > And the text renderer didn't show up.
>>
>> You'll need to call SetNumberOfLayers(2) on your render window first I
>> think.
>>
>> Elvis
>>
>> >
>> > Many thanks.
>> >
>> >
>> > Bill
>> >
>> > On Wed, May 24, 2017 at 11:06 PM, Dan Lipsa <[hidden email]>
>> > wrote:
>> >>
>> >> Bill,
>> >> Try using SetLayer(1) for the renderer that has the text.
>> >>
>> >> Dan
>> >>
>> >>
>> >> On Wed, May 24, 2017 at 10:34 AM, Bill Q <[hidden email]> wrote:
>> >>>
>> >>> Hi Dan,
>> >>> Thanks a ton for the example. The example used 4 different viewports.
>> >>> However, for my application, I need to set all renderers under the same
>> >>> viewport. The problem is that if I add a second renderer into the render
>> >>> window and using the default viewport, it will cover the first renderer and
>> >>> nothing on the first renderer will show up. I am wondering if I did the
>> >>> whole thing wrong.
>> >>>
>> >>> My purpose is to display some DICOM images, some texts, and scales on
>> >>> the same screen. Also, I would like to make the scales zoom with the DICOM
>> >>> images but the texts stay put. Most importantly, I would like to get the
>> >>> world coordinates on the DICOM image when users click on the screen, so I
>> >>> can mark the click properly.
>> >>>
>> >>> What should be done in order to get this working?
>> >>>
>> >>>
>> >>> Many thanks.
>> >>>
>> >>>
>> >>> Bill
>> >>>
>> >>> On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <[hidden email]>
>> >>> wrote:
>> >>>>
>> >>>> Not sure what is going on. Do the objects you are rendering have the
>> >>>> same world coordinates? Are both renderers added to the rendering window?
>> >>>> Here is an example with multiple renderer (they are over different
>> >>>> viewports but they could have the same viewport as well)
>> >>>>
>> >>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/MultipleViewports
>> >>>>
>> >>>> On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]>
>> >>>> wrote:
>> >>>>>
>> >>>>> I just gave it a try. But when I added another renderer into the
>> >>>>> window that I used for text actors, it overlaps and covered the first
>> >>>>> renderer. So the first renderer won't show up. Is there a solution?
>> >>>>>
>> >>>>> Many thanks.
>> >>>>>
>> >>>>>
>> >>>>> Bill
>> >>>>>
>> >>>>> On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]>
>> >>>>> wrote:
>> >>>>>>
>> >>>>>> I think moving those text actors on a different renderer will solve
>> >>>>>> your problem.
>> >>>>>>
>> >>>>>> Dan
>> >>>>>>
>> >>>>>>
>> >>>>>> On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]>
>> >>>>>> wrote:
>> >>>>>>>
>> >>>>>>> Hi Dan,
>> >>>>>>> Thanks a lot for the reply. Yes, that's exactly the case. If I
>> >>>>>>> remove the text actors, the world picker would return the correct
>> >>>>>>> coordinates. So, what method should I use in order to get the correct
>> >>>>>>> coordinates no matter how many actors I put in with the dicom image reader
>> >>>>>>> actor?
>> >>>>>>>
>> >>>>>>> Many thanks.
>> >>>>>>>
>> >>>>>>>
>> >>>>>>> Bill
>> >>>>>>>
>> >>>>>>> On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa
>> >>>>>>> <[hidden email]> wrote:
>> >>>>>>>>
>> >>>>>>>> Bill,
>> >>>>>>>> For display_to_world, the picker picks up only what is visible
>> >>>>>>>> (closes to the camera). You might have several objects (several values in
>> >>>>>>>> world coordinates) that end up over the same display coordinate. This might
>> >>>>>>>> explain why adding those text actors changes what you pick.
>> >>>>>>>>
>> >>>>>>>> Dan
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>> On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]>
>> >>>>>>>> wrote:
>> >>>>>>>>>
>> >>>>>>>>> Can anybody help? Many thanks.
>> >>>>>>>>>
>> >>>>>>>>> Many thanks.
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> Bill
>> >>>>>>>>>
>> >>>>>>>>> On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]>
>> >>>>>>>>> wrote:
>> >>>>>>>>>>
>> >>>>>>>>>> Hello Everyone,
>> >>>>>>>>>> I encountered a weird problem in coordinate conversion.
>> >>>>>>>>>>
>> >>>>>>>>>> In order to check the accuracy, I converted from display to
>> >>>>>>>>>> world, and from world back to display. Using the following ways:
>> >>>>>>>>>>
>> >>>>>>>>>> self.world_picker = vtk.vtkWorldPointPicker()
>> >>>>>>>>>>
>> >>>>>>>>>> def display_to_world(self, pt):
>> >>>>>>>>>>     self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
>> >>>>>>>>>>     picker_pt = self.world_picker.GetPickPosition()
>> >>>>>>>>>>     picker_pt = (picker_pt[0], picker_pt[1], 0)
>> >>>>>>>>>>     return picker_pt
>> >>>>>>>>>>
>> >>>>>>>>>> def world_to_display(self, pt):
>> >>>>>>>>>>     if len(pt) == 3:
>> >>>>>>>>>>         pt = pt + (1.0,)
>> >>>>>>>>>>     elif len(pt) == 2:
>> >>>>>>>>>>         pt = pt + (0.0, 1.0)
>> >>>>>>>>>>     self.ren.SetWorldPoint(pt)
>> >>>>>>>>>>     self.ren.WorldToDisplay()
>> >>>>>>>>>>     pt = self.ren.GetDisplayPoint()
>> >>>>>>>>>>     pt = (pt[0], pt[1])
>> >>>>>>>>>>     return pt
>> >>>>>>>>>>
>> >>>>>>>>>> pt = [5, 5]
>> >>>>>>>>>>
>> >>>>>>>>>> world_pt = self. world_to_display(pt)
>> >>>>>>>>>>
>> >>>>>>>>>> display_pt = self. world_to_display(world_pt)
>> >>>>>>>>>>
>> >>>>>>>>>> In some cases, it's quite accurate, which means pt equals
>> >>>>>>>>>> display_pt. But, in some cases, the result is simply wrong. For example, for
>> >>>>>>>>>> (5, 5), after conversions back to display, the coordinate becomes (20.89,
>> >>>>>>>>>> 20.89).
>> >>>>>>>>>>
>> >>>>>>>>>> Any ideas?
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Many thanks.
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Bill
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> _______________________________________________
>> >>>>>>>>> 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
>> >>>>>>>>>
>> >>>>>>>>
>> >>>>>>>
>> >>>>>>
>> >>>>>
>> >>>>
>> >>>
>> >>
>> >
>> >
>> > _______________________________________________
>> > 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
>> >
>
>

 



_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Andras Lasso

The highlighted code lines perform point picking in world coordinates. If you need more information then read the entire class and related classes, maybe add a breakpoint and run it step-by-step in a debugger to see how it works exactly.

 

Playing with these, learning about low-level details is fun and useful experience. However, I would strongly recommend not to develop yet another DICOM viewer from scratch. There are several existing open source medical image computing and visualization applications that are used by thousands of people worldwide, they are used in operating rooms, used as a basis of FDA-approved products, have been around for several years, stable, feature-rich, etc. that can be extended to fit your needs. Most of them use VTK!

Andras

 

From: Bill Q [mailto:[hidden email]]
Sent: Thursday, June 29, 2017 8:16 PM
To: Andras Lasso <[hidden email]>
Cc: Elvis Stansvik <[hidden email]>; VTK Users <[hidden email]>
Subject: Re: [vtkusers] Issues with coordinate conversion, possible VTK bugs?

 

Thanks Andras,

 

I read through the links, but I wasn't able to identify the part that is relevant to my questions.

 

Would you be more specific? 


Many thanks.

Bill

 

On Tue, Jun 6, 2017 at 11:01 AM, Andras Lasso <[hidden email]> wrote:

See how it is implemented 3D Slicer and MITK:

 

https://github.com/Slicer/Slicer/blob/master/Libs/MRML/DisplayableManager/vtkThreeDViewInteractorStyle.cxx#L812-L848

 

https://github.com/MITK/MITK/blob/master/Modules/Core/src/Rendering/mitkBaseRenderer.cpp#L600-L640

 

Andras

 

From: vtkusers [mailto:[hidden email]] On Behalf Of Bill Q
Sent: Monday, June 5, 2017 3:56 PM
To: Elvis Stansvik <[hidden email]>
Cc: VTK Users <[hidden email]>
Subject: Re: [vtkusers] Issues with coordinate conversion, possible VTK bugs?

 

Hi Elvis,

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?

 

Would someone know the correct way doing it give some advices?


Many thanks.

Bill

 

On Sat, May 27, 2017 at 4:06 AM, Elvis Stansvik <[hidden email]> wrote:

2017-05-26 20:08 GMT+02:00 Bill Q <[hidden email]>:
> Hi Elvis and Dan,
> Thank you very much for the response. After setting the render window
> SetNumberOfLayers(2) and setting the renderer with text SetLayer(1), both
> the layers with the DICOM images and the layer with the text can show up.
> But, the problem still persists. I still cannot get the correct world
> coordinates by using the following function:
>
> def display_to_world2(self, pt):
>     worldPt = [0, 0, 0, 0]
>     vtk.vtkInteractorObserver.ComputeDisplayToWorld(self.renderer_dicom,
> pt[0], pt[1], 0, worldPt)
>     return worldPt[0] / worldPt[3], worldPt[1] / worldPt[3], worldPt[2] /
> worldPt[3]
>
> The z returned is always 86.33.
>
> Meanwhile, I cannot use the world picker either, because it still picks the
> text's world coordinate.
>
> So, either I can make the above function work on the DICOM renderer or I
> have to make the world picker not picking up anything on the text renderer.
> I am not sure how I can get any of these two ways done.
>
> Any suggestions would be greatly appreciated!

Could you try turning interaction off on the renderer you use for your
"foreground" objects. In my code I have:

    auto foregroundRenderer = vtkSmartPointer<vtkRenderer>::New();
    foregroundRenderer->InteractiveOff();
    foregroundRenderer->SetLayer(1);
    ...
    GetRenderWindow()->SetNumberOfLayers(2);

Hope that helps, it's the last idea I have :p


Elvis

>
>
> Many thanks.
>
>
> Bill
>
> On Thu, May 25, 2017 at 12:14 AM, Elvis Stansvik
> <[hidden email]> wrote:
>>
>> Den 24 maj 2017 5:27 em skrev "Bill Q" <[hidden email]>:
>> >
>> > Hi Dan,
>> > After set the layer, I got this error:
>> >
>> > VTK-7.1.0\Rendering\Core\vtkRendererCollection.cxx, line 61
>> > vtkRendererCollection (000000001192E3A0): Invalid layer for renderer: not
>> > rendered.
>> >
>> > And the text renderer didn't show up.
>>
>> You'll need to call SetNumberOfLayers(2) on your render window first I
>> think.
>>
>> Elvis
>>
>> >
>> > Many thanks.
>> >
>> >
>> > Bill
>> >
>> > On Wed, May 24, 2017 at 11:06 PM, Dan Lipsa <[hidden email]>
>> > wrote:
>> >>
>> >> Bill,
>> >> Try using SetLayer(1) for the renderer that has the text.
>> >>
>> >> Dan
>> >>
>> >>
>> >> On Wed, May 24, 2017 at 10:34 AM, Bill Q <[hidden email]> wrote:
>> >>>
>> >>> Hi Dan,
>> >>> Thanks a ton for the example. The example used 4 different viewports.
>> >>> However, for my application, I need to set all renderers under the same
>> >>> viewport. The problem is that if I add a second renderer into the render
>> >>> window and using the default viewport, it will cover the first renderer and
>> >>> nothing on the first renderer will show up. I am wondering if I did the
>> >>> whole thing wrong.
>> >>>
>> >>> My purpose is to display some DICOM images, some texts, and scales on
>> >>> the same screen. Also, I would like to make the scales zoom with the DICOM
>> >>> images but the texts stay put. Most importantly, I would like to get the
>> >>> world coordinates on the DICOM image when users click on the screen, so I
>> >>> can mark the click properly.
>> >>>
>> >>> What should be done in order to get this working?
>> >>>
>> >>>
>> >>> Many thanks.
>> >>>
>> >>>
>> >>> Bill
>> >>>
>> >>> On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <[hidden email]>
>> >>> wrote:
>> >>>>
>> >>>> Not sure what is going on. Do the objects you are rendering have the
>> >>>> same world coordinates? Are both renderers added to the rendering window?
>> >>>> Here is an example with multiple renderer (they are over different
>> >>>> viewports but they could have the same viewport as well)
>> >>>>
>> >>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/MultipleViewports
>> >>>>
>> >>>> On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]>
>> >>>> wrote:
>> >>>>>
>> >>>>> I just gave it a try. But when I added another renderer into the
>> >>>>> window that I used for text actors, it overlaps and covered the first
>> >>>>> renderer. So the first renderer won't show up. Is there a solution?
>> >>>>>
>> >>>>> Many thanks.
>> >>>>>
>> >>>>>
>> >>>>> Bill
>> >>>>>
>> >>>>> On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]>
>> >>>>> wrote:
>> >>>>>>
>> >>>>>> I think moving those text actors on a different renderer will solve
>> >>>>>> your problem.
>> >>>>>>
>> >>>>>> Dan
>> >>>>>>
>> >>>>>>
>> >>>>>> On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]>
>> >>>>>> wrote:
>> >>>>>>>
>> >>>>>>> Hi Dan,
>> >>>>>>> Thanks a lot for the reply. Yes, that's exactly the case. If I
>> >>>>>>> remove the text actors, the world picker would return the correct
>> >>>>>>> coordinates. So, what method should I use in order to get the correct
>> >>>>>>> coordinates no matter how many actors I put in with the dicom image reader
>> >>>>>>> actor?
>> >>>>>>>
>> >>>>>>> Many thanks.
>> >>>>>>>
>> >>>>>>>
>> >>>>>>> Bill
>> >>>>>>>
>> >>>>>>> On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa
>> >>>>>>> <[hidden email]> wrote:
>> >>>>>>>>
>> >>>>>>>> Bill,
>> >>>>>>>> For display_to_world, the picker picks up only what is visible
>> >>>>>>>> (closes to the camera). You might have several objects (several values in
>> >>>>>>>> world coordinates) that end up over the same display coordinate. This might
>> >>>>>>>> explain why adding those text actors changes what you pick.
>> >>>>>>>>
>> >>>>>>>> Dan
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>> On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]>
>> >>>>>>>> wrote:
>> >>>>>>>>>
>> >>>>>>>>> Can anybody help? Many thanks.
>> >>>>>>>>>
>> >>>>>>>>> Many thanks.
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> Bill
>> >>>>>>>>>
>> >>>>>>>>> On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]>
>> >>>>>>>>> wrote:
>> >>>>>>>>>>
>> >>>>>>>>>> Hello Everyone,
>> >>>>>>>>>> I encountered a weird problem in coordinate conversion.
>> >>>>>>>>>>
>> >>>>>>>>>> In order to check the accuracy, I converted from display to
>> >>>>>>>>>> world, and from world back to display. Using the following ways:
>> >>>>>>>>>>
>> >>>>>>>>>> self.world_picker = vtk.vtkWorldPointPicker()
>> >>>>>>>>>>
>> >>>>>>>>>> def display_to_world(self, pt):
>> >>>>>>>>>>     self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
>> >>>>>>>>>>     picker_pt = self.world_picker.GetPickPosition()
>> >>>>>>>>>>     picker_pt = (picker_pt[0], picker_pt[1], 0)
>> >>>>>>>>>>     return picker_pt
>> >>>>>>>>>>
>> >>>>>>>>>> def world_to_display(self, pt):
>> >>>>>>>>>>     if len(pt) == 3:
>> >>>>>>>>>>         pt = pt + (1.0,)
>> >>>>>>>>>>     elif len(pt) == 2:
>> >>>>>>>>>>         pt = pt + (0.0, 1.0)
>> >>>>>>>>>>     self.ren.SetWorldPoint(pt)
>> >>>>>>>>>>     self.ren.WorldToDisplay()
>> >>>>>>>>>>     pt = self.ren.GetDisplayPoint()
>> >>>>>>>>>>     pt = (pt[0], pt[1])
>> >>>>>>>>>>     return pt
>> >>>>>>>>>>
>> >>>>>>>>>> pt = [5, 5]
>> >>>>>>>>>>
>> >>>>>>>>>> world_pt = self. world_to_display(pt)
>> >>>>>>>>>>
>> >>>>>>>>>> display_pt = self. world_to_display(world_pt)
>> >>>>>>>>>>
>> >>>>>>>>>> In some cases, it's quite accurate, which means pt equals
>> >>>>>>>>>> display_pt. But, in some cases, the result is simply wrong. For example, for
>> >>>>>>>>>> (5, 5), after conversions back to display, the coordinate becomes (20.89,
>> >>>>>>>>>> 20.89).
>> >>>>>>>>>>
>> >>>>>>>>>> Any ideas?
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Many thanks.
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Bill
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> _______________________________________________
>> >>>>>>>>> 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
>> >>>>>>>>>
>> >>>>>>>>
>> >>>>>>>
>> >>>>>>
>> >>>>>
>> >>>>
>> >>>
>> >>
>> >
>> >
>> > _______________________________________________
>> > 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
>> >
>
>

 

 


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Issues with coordinate conversion, possible VTK bugs?

Bill Q
Hi Andras,
Thanks a ton! 

We are building a software that has a very specific purpose, other than the visualization part, everything else is tailored to the demands. To make it lightweight, we have to build a custom software. That's why we have taken the more difficult approach. Otherwise, we would have chosen an open-source solution.

Thanks again for pointing out the solution.

Many thanks.


Bill

On Sat, Jul 1, 2017 at 8:36 AM, Andras Lasso <[hidden email]> wrote:

The highlighted code lines perform point picking in world coordinates. If you need more information then read the entire class and related classes, maybe add a breakpoint and run it step-by-step in a debugger to see how it works exactly.

 

Playing with these, learning about low-level details is fun and useful experience. However, I would strongly recommend not to develop yet another DICOM viewer from scratch. There are several existing open source medical image computing and visualization applications that are used by thousands of people worldwide, they are used in operating rooms, used as a basis of FDA-approved products, have been around for several years, stable, feature-rich, etc. that can be extended to fit your needs. Most of them use VTK!

Andras

 

From: Bill Q [mailto:[hidden email]]
Sent: Thursday, June 29, 2017 8:16 PM
To: Andras Lasso <[hidden email]>
Cc: Elvis Stansvik <[hidden email]>; VTK Users <[hidden email]>


Subject: Re: [vtkusers] Issues with coordinate conversion, possible VTK bugs?

 

Thanks Andras,

 

I read through the links, but I wasn't able to identify the part that is relevant to my questions.

 

Would you be more specific? 


Many thanks.

Bill

 

On Tue, Jun 6, 2017 at 11:01 AM, Andras Lasso <[hidden email]> wrote:

See how it is implemented 3D Slicer and MITK:

 

https://github.com/Slicer/Slicer/blob/master/Libs/MRML/DisplayableManager/vtkThreeDViewInteractorStyle.cxx#L812-L848

 

https://github.com/MITK/MITK/blob/master/Modules/Core/src/Rendering/mitkBaseRenderer.cpp#L600-L640

 

Andras

 

From: vtkusers [mailto:[hidden email]] On Behalf Of Bill Q
Sent: Monday, June 5, 2017 3:56 PM
To: Elvis Stansvik <[hidden email]>
Cc: VTK Users <[hidden email]>
Subject: Re: [vtkusers] Issues with coordinate conversion, possible VTK bugs?

 

Hi Elvis,

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?

 

Would someone know the correct way doing it give some advices?


Many thanks.

Bill

 

On Sat, May 27, 2017 at 4:06 AM, Elvis Stansvik <[hidden email]> wrote:

2017-05-26 20:08 GMT+02:00 Bill Q <[hidden email]>:
> Hi Elvis and Dan,
> Thank you very much for the response. After setting the render window
> SetNumberOfLayers(2) and setting the renderer with text SetLayer(1), both
> the layers with the DICOM images and the layer with the text can show up.
> But, the problem still persists. I still cannot get the correct world
> coordinates by using the following function:
>
> def display_to_world2(self, pt):
>     worldPt = [0, 0, 0, 0]
>     vtk.vtkInteractorObserver.ComputeDisplayToWorld(self.renderer_dicom,
> pt[0], pt[1], 0, worldPt)
>     return worldPt[0] / worldPt[3], worldPt[1] / worldPt[3], worldPt[2] /
> worldPt[3]
>
> The z returned is always 86.33.
>
> Meanwhile, I cannot use the world picker either, because it still picks the
> text's world coordinate.
>
> So, either I can make the above function work on the DICOM renderer or I
> have to make the world picker not picking up anything on the text renderer.
> I am not sure how I can get any of these two ways done.
>
> Any suggestions would be greatly appreciated!

Could you try turning interaction off on the renderer you use for your
"foreground" objects. In my code I have:

    auto foregroundRenderer = vtkSmartPointer<vtkRenderer>::New();
    foregroundRenderer->InteractiveOff();
    foregroundRenderer->SetLayer(1);
    ...
    GetRenderWindow()->SetNumberOfLayers(2);

Hope that helps, it's the last idea I have :p


Elvis

>
>
> Many thanks.
>
>
> Bill
>
> On Thu, May 25, 2017 at 12:14 AM, Elvis Stansvik
> <[hidden email]> wrote:
>>
>> Den 24 maj 2017 5:27 em skrev "Bill Q" <[hidden email]>:
>> >
>> > Hi Dan,
>> > After set the layer, I got this error:
>> >
>> > VTK-7.1.0\Rendering\Core\vtkRendererCollection.cxx, line 61
>> > vtkRendererCollection (000000001192E3A0): Invalid layer for renderer: not
>> > rendered.
>> >
>> > And the text renderer didn't show up.
>>
>> You'll need to call SetNumberOfLayers(2) on your render window first I
>> think.
>>
>> Elvis
>>
>> >
>> > Many thanks.
>> >
>> >
>> > Bill
>> >
>> > On Wed, May 24, 2017 at 11:06 PM, Dan Lipsa <[hidden email]>
>> > wrote:
>> >>
>> >> Bill,
>> >> Try using SetLayer(1) for the renderer that has the text.
>> >>
>> >> Dan
>> >>
>> >>
>> >> On Wed, May 24, 2017 at 10:34 AM, Bill Q <[hidden email]> wrote:
>> >>>
>> >>> Hi Dan,
>> >>> Thanks a ton for the example. The example used 4 different viewports.
>> >>> However, for my application, I need to set all renderers under the same
>> >>> viewport. The problem is that if I add a second renderer into the render
>> >>> window and using the default viewport, it will cover the first renderer and
>> >>> nothing on the first renderer will show up. I am wondering if I did the
>> >>> whole thing wrong.
>> >>>
>> >>> My purpose is to display some DICOM images, some texts, and scales on
>> >>> the same screen. Also, I would like to make the scales zoom with the DICOM
>> >>> images but the texts stay put. Most importantly, I would like to get the
>> >>> world coordinates on the DICOM image when users click on the screen, so I
>> >>> can mark the click properly.
>> >>>
>> >>> What should be done in order to get this working?
>> >>>
>> >>>
>> >>> Many thanks.
>> >>>
>> >>>
>> >>> Bill
>> >>>
>> >>> On Wed, May 24, 2017 at 12:02 AM, Dan Lipsa <[hidden email]>
>> >>> wrote:
>> >>>>
>> >>>> Not sure what is going on. Do the objects you are rendering have the
>> >>>> same world coordinates? Are both renderers added to the rendering window?
>> >>>> Here is an example with multiple renderer (they are over different
>> >>>> viewports but they could have the same viewport as well)
>> >>>>
>> >>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/MultipleViewports
>> >>>>
>> >>>> On Tue, May 23, 2017 at 11:39 AM, Bill Q <[hidden email]>
>> >>>> wrote:
>> >>>>>
>> >>>>> I just gave it a try. But when I added another renderer into the
>> >>>>> window that I used for text actors, it overlaps and covered the first
>> >>>>> renderer. So the first renderer won't show up. Is there a solution?
>> >>>>>
>> >>>>> Many thanks.
>> >>>>>
>> >>>>>
>> >>>>> Bill
>> >>>>>
>> >>>>> On Tue, May 23, 2017 at 10:16 PM, Dan Lipsa <[hidden email]>
>> >>>>> wrote:
>> >>>>>>
>> >>>>>> I think moving those text actors on a different renderer will solve
>> >>>>>> your problem.
>> >>>>>>
>> >>>>>> Dan
>> >>>>>>
>> >>>>>>
>> >>>>>> On Tue, May 23, 2017 at 9:40 AM, Bill Q <[hidden email]>
>> >>>>>> wrote:
>> >>>>>>>
>> >>>>>>> Hi Dan,
>> >>>>>>> Thanks a lot for the reply. Yes, that's exactly the case. If I
>> >>>>>>> remove the text actors, the world picker would return the correct
>> >>>>>>> coordinates. So, what method should I use in order to get the correct
>> >>>>>>> coordinates no matter how many actors I put in with the dicom image reader
>> >>>>>>> actor?
>> >>>>>>>
>> >>>>>>> Many thanks.
>> >>>>>>>
>> >>>>>>>
>> >>>>>>> Bill
>> >>>>>>>
>> >>>>>>> On Mon, May 22, 2017 at 10:04 PM, Dan Lipsa
>> >>>>>>> <[hidden email]> wrote:
>> >>>>>>>>
>> >>>>>>>> Bill,
>> >>>>>>>> For display_to_world, the picker picks up only what is visible
>> >>>>>>>> (closes to the camera). You might have several objects (several values in
>> >>>>>>>> world coordinates) that end up over the same display coordinate. This might
>> >>>>>>>> explain why adding those text actors changes what you pick.
>> >>>>>>>>
>> >>>>>>>> Dan
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>> On Sun, May 21, 2017 at 5:25 AM, Bill Q <[hidden email]>
>> >>>>>>>> wrote:
>> >>>>>>>>>
>> >>>>>>>>> Can anybody help? Many thanks.
>> >>>>>>>>>
>> >>>>>>>>> Many thanks.
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> Bill
>> >>>>>>>>>
>> >>>>>>>>> On Fri, May 19, 2017 at 11:20 PM, Bill Q <[hidden email]>
>> >>>>>>>>> wrote:
>> >>>>>>>>>>
>> >>>>>>>>>> Hello Everyone,
>> >>>>>>>>>> I encountered a weird problem in coordinate conversion.
>> >>>>>>>>>>
>> >>>>>>>>>> In order to check the accuracy, I converted from display to
>> >>>>>>>>>> world, and from world back to display. Using the following ways:
>> >>>>>>>>>>
>> >>>>>>>>>> self.world_picker = vtk.vtkWorldPointPicker()
>> >>>>>>>>>>
>> >>>>>>>>>> def display_to_world(self, pt):
>> >>>>>>>>>>     self.world_picker.Pick(pt[0], pt[1], 0, self.ren)
>> >>>>>>>>>>     picker_pt = self.world_picker.GetPickPosition()
>> >>>>>>>>>>     picker_pt = (picker_pt[0], picker_pt[1], 0)
>> >>>>>>>>>>     return picker_pt
>> >>>>>>>>>>
>> >>>>>>>>>> def world_to_display(self, pt):
>> >>>>>>>>>>     if len(pt) == 3:
>> >>>>>>>>>>         pt = pt + (1.0,)
>> >>>>>>>>>>     elif len(pt) == 2:
>> >>>>>>>>>>         pt = pt + (0.0, 1.0)
>> >>>>>>>>>>     self.ren.SetWorldPoint(pt)
>> >>>>>>>>>>     self.ren.WorldToDisplay()
>> >>>>>>>>>>     pt = self.ren.GetDisplayPoint()
>> >>>>>>>>>>     pt = (pt[0], pt[1])
>> >>>>>>>>>>     return pt
>> >>>>>>>>>>
>> >>>>>>>>>> pt = [5, 5]
>> >>>>>>>>>>
>> >>>>>>>>>> world_pt = self. world_to_display(pt)
>> >>>>>>>>>>
>> >>>>>>>>>> display_pt = self. world_to_display(world_pt)
>> >>>>>>>>>>
>> >>>>>>>>>> In some cases, it's quite accurate, which means pt equals
>> >>>>>>>>>> display_pt. But, in some cases, the result is simply wrong. For example, for
>> >>>>>>>>>> (5, 5), after conversions back to display, the coordinate becomes (20.89,
>> >>>>>>>>>> 20.89).
>> >>>>>>>>>>
>> >>>>>>>>>> Any ideas?
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Many thanks.
>> >>>>>>>>>>
>> >>>>>>>>>>
>> >>>>>>>>>> Bill
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> _______________________________________________
>> >>>>>>>>> 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
>> >>>>>>>>>
>> >>>>>>>>
>> >>>>>>>
>> >>>>>>
>> >>>>>
>> >>>>
>> >>>
>> >>
>> >
>> >
>> > _______________________________________________
>> > 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
>> >
>
>

 

 



_______________________________________________
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