[vtkusers] Actors in front of camera clipped despite ResetCameraClippingRange()

Elvis Stansvik elvis.stansvik at orexplore.com
Tue Jun 21 14:00:32 EDT 2016


2016-06-21 19:33 GMT+02:00 Ken Martin <ken.martin at kitware.com>:

> Thanks for the example. From what I can see everything is working
> correctly.  To be more specific, in your example your position is
>
> 3, 10, 0
>
> and your direction of projection is
>
> -0.29 -0.96, 0
>
> so z distance will be   (conepos - cam_pos) dot DOP
>
> taking the cone at 0, 20, 0 for example would give
>
> -3, 10, 0 dot -0.3 -0.96 0  which is about 1.0 - 9.6 or -8.6 which is far
> behind the camera. Parallel projection is tricky because without the
> perspective clues it can be hard to judge how close items are to you.
>
> If you want to avoid this issue just move your camera farther back. With
> parallel projection, the camera being farther back is not a problem as the
> size of the cones will not change.  If I change your example from
>
> camera.SetPosition(3.0, 10.0, 0.0)
>
> to
>
> camera.SetPosition(30.0, 100.0, 0.0)
>
> everything looks fine as the camera is far enough away that the stack of
> cones never moves behind it and yet the direction of projection and
> parallel scale are unchanged.  Hope that helps.
>

Thanks a lot for the detailed explanation. It makes perfect sense now.

I'll have to be careful then and take the size of my subjects into account
when placing the camera. The reason I picked such a short distance was that
I started out using a quite small factor when multiplying the dy of the
mouse movement when moving the camera up and down in my interactor style,
and then it was necessary to place the camera quite close to get a good
reaction when looking up and down. I'll just have to do things in the right
order: First determine an appropriate distance for the camera from the
subject (to avoid any clipping), then based on that distance, determine a
factor that "feels" good.

Elvis


> Thanks
> Ken
>
>
>
>
>
>
> On Tue, Jun 21, 2016 at 12:27 PM, Elvis Stansvik <
> elvis.stansvik at orexplore.com> wrote:
>
>> 2016-06-21 18:25 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:
>>
>>> 2016-06-21 17:44 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>
>>> :
>>>
>>>> Den 21 juni 2016 4:45 em skrev "Ken Martin" <ken.martin at kitware.com>:
>>>> >
>>>> > That image doesn't match what I think you are saying, so maybe you
>>>> can help me understand.  You mention the camera is positioned on a cylinder
>>>> of radius 3.0 and from your code it looks like the focal point is not
>>>> changing.
>>>> >
>>>> > If that is true then at some point some of the cones will be behind
>>>> your camera. For example if your focal point was (0,0,0) and your camera
>>>> was at (3,10,0) then you would be looking mostly down the y axis and from
>>>> your code you have a cone positioned at (0,20,0) which would be behind you.
>>>> >
>>>> > Having said all that your image looks funny anyhow.  With a parallel
>>>> projection all the cones should look the exact same aside from clipping but
>>>> the first cone really looks off from the rest and the others are all
>>>> identical so something is off.
>>>> >
>>>> > I did look through that code and it looks reasonable to me (the patch
>>>> referenced is not correct BTW, parallel projection still requires proper z
>>>> buffer scaling and clipping)  If you could provide a few more images from
>>>> different viewpoints, ideally with the resulting camera
>>>> >
>>>> > clipping range
>>>> > parallel scale
>>>> > position
>>>> > focal point
>>>> >
>>>> > for those images that would help me see what is going on.
>>>>
>>>> Thanks a lot for taking the time Ken. You're right of course about
>>>> cones being behind me. I think what I meant was I'm never inside a cone.
>>>>
>>>> I'll try to make a minimal test case when I get home, as I'm on the bus
>>>> and only have my phone right now.
>>>>
>>> Here's a minimal test case where the camera is positioned to look "down"
>>> on the stack of cones, the stack is cut off due to clipping (see attached
>>> .png):
>>>
>>> from vtk import vtkRenderer, vtkRenderWindow, vtkRenderWindowInteractor
>>> from vtk import vtkConeSource, vtkActor, vtkPolyDataMapper
>>>
>>> renderer = vtkRenderer()
>>> renderWindow = vtkRenderWindow()
>>> renderWindow.SetSize(500, 1000)
>>> renderWindow.AddRenderer(renderer)
>>>
>>> interactor = vtkRenderWindowInteractor()
>>> interactor.SetRenderWindow(renderWindow)
>>>
>>> # Create a stack of 40 cones along the Y axis
>>> for i in range(-20, 20):
>>>     coneSource = vtkConeSource()
>>>     coneSource.SetDirection(0, 1, 0)
>>>     coneSource.SetResolution(8)
>>>     coneSource.SetCenter(0, i, 0)
>>>
>>>     coneMapper = vtkPolyDataMapper()
>>>     coneMapper.SetInputConnection(coneSource.GetOutputPort())
>>>
>>>     coneActor = vtkActor()
>>>     coneActor.SetMapper(coneMapper)
>>>
>>>     renderer.AddActor(coneActor)
>>>
>>> # Position camera at (3.0, 10.0, 0), looking "down" along the stack
>>> camera = renderer.GetActiveCamera()
>>> camera.SetParallelProjection(True)
>>> camera.SetPosition(3.0, 10.0, 0.0)
>>> camera.SetFocalPoint(0.0, 0.0, 0.0)
>>> camera.SetParallelScale(5.0)
>>>
>>> # Reset camera clipping range
>>> renderer.ResetCameraClippingRange()
>>>
>>> # Print some camera info
>>> print(camera)
>>>
>>> interactor.Start()
>>>
>>
>> Forgot to include the output from the test (the printing of the camera):
>>
>> vtkOpenGLCamera (0x2130810)
>>   Debug: Off
>>   Modified Time: 17946
>>   Reference Count: 2
>>   Registered Events: (none)
>>   ClippingRange: (0.0531862, 53.1862)
>>   DirectionOfProjection: (-0.287348, -0.957826, 0)
>>   Distance: 10.4403
>>   EyeAngle: 2
>>   FocalDisk: 1
>>   FocalPoint: (0, 0, 0)
>>   ViewShear: (0, 0, 1)
>>   ParallelProjection: On
>>   ParallelScale: 5
>>   Position: (3, 10, 0)
>>   Stereo: Off
>>   Left Eye: 1
>>   Thickness: 53.133
>>   ViewAngle: 30
>>   UseHorizontalViewAngle: 0
>>   UserTransform: (none)
>> (none)
>>   FreezeFocalPoint: (none)
>>   ViewPlaneNormal: (0.287348, 0.957826, -0)
>>   ViewUp: (0, 1, 0)
>>   WindowCenter: (0, 0)
>>   UseOffAxisProjection: (0)
>>   ScreenBottomLeft: (-0.5, -0.5, -0.5)
>>   ScreenBottomRight: (0.5, -0.5, -0.5)
>>   ScreenTopRight: (0.5, 0.5, -0.5)
>>   EyeSeparation: (0.06)
>>   WorldToScreenMatrix: (0x2130a50
>>     Debug: Off
>>     Modified Time: 12739
>>     Reference Count: 1
>>     Registered Events: (none)
>>     Elements:
>>         1 0 0 0
>>         0 1 0 0
>>         0 0 1 0
>>         0 0 0 1
>>   )
>>   EyeTransformMatrix: (0x2130b40
>>     Debug: Off
>>     Modified Time: 12741
>>     Reference Count: 1
>>     Registered Events: (none)
>>     Elements:
>>         1 0 0 0
>>         0 1 0 0
>>         0 0 1 0
>>         0 0 0 1
>>   )
>>   ModelTransformMatrix: (0x2130c30
>>     Debug: Off
>>     Modified Time: 12743
>>     Reference Count: 1
>>     Registered Events: (none)
>>     Elements:
>>         1 0 0 0
>>         0 1 0 0
>>         0 0 1 0
>>         0 0 0 1
>>   )
>>   ProjectionTransform: (0x2131170
>>     Debug: Off
>>     Modified Time: 12748
>>     Reference Count: 1
>>     Registered Events: (none)
>>     Inverse: (0)
>>     Matrix: (0x21312a0)
>>       Debug: Off
>>       Modified Time: 17947
>>       Reference Count: 1
>>       Registered Events: (none)
>>       Elements:
>>             1 0 0 0
>>             0 1 0 0
>>             0 0 1 0
>>             0 0 0 1
>>     Input: (0)
>>     InverseFlag: 0
>>     NumberOfConcatenatedTransforms: 0
>>   )
>>
>> Elvis
>>
>>
>>>
>>> But I'm beginning to think this is maybe just a misunderstanding on my
>>> part. Perhaps this clipping is inevitable and expected when using parallel
>>> projection?
>>>
>>> Thanks in advance,
>>> Elvis
>>>
>>> Elvis
>>>>
>>>> >
>>>> > Thanks
>>>> > Ken
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> > On Tue, Jun 21, 2016 at 7:06 AM, Elvis Stansvik <
>>>> elvis.stansvik at orexplore.com> wrote:
>>>> >>
>>>> >> Hi all,
>>>> >>
>>>> >> I have a setup where the camera always moves on a cylinder of radius
>>>> 3.0 around my subject (just testing with a stack of cones at the moment).
>>>> The focal point is always positioned along the Y axis, and the camera may
>>>> be moved up and down independent of the focus point, but the camera is
>>>> always at a distance of 3 from the Y axis.
>>>> >>
>>>> >> As soon as the user moves the camera, I reset the camera clipping
>>>> range with ResetCameraClippingRange(). Despite this, when the camera and
>>>> the focal point are far away from eachother, the actors (my stack of cones)
>>>> get clipped by the near plane for some reason.
>>>> >>
>>>> >> See the attached screenshot which shows the clipping.
>>>> >>
>>>> >> What I'm doing to my camera (in response to Shift+mouse drag in my
>>>> custom interactor) to end up in this situation is just:
>>>> >>
>>>> >>         camera = renderer.GetActiveCamera()
>>>> >>         (x, y, z) = camera.GetPosition()
>>>> >>         camera.SetPosition(x, y - self.PanningFactor * dy, z)
>>>> >>         renderer.ResetCameraClippingRange()
>>>> >>
>>>> >> and I've verified that the camera is always at a distance of 3.0
>>>> from the Y axis.
>>>> >>
>>>> >> The cones I'm using in this test were created with:
>>>> >>
>>>> >>     for i in range(-10, 20):
>>>> >>         coneSource = vtkConeSource()
>>>> >>         coneSource.SetDirection(0, 1, 0)
>>>> >>         coneSource.SetResolution(8)
>>>> >>         coneSource.SetCenter(0, i, 0)
>>>> >>
>>>> >>         coneMapper = vtkPolyDataMapper()
>>>> >>         coneMapper.SetInputConnection(coneSource.GetOutputPort())
>>>> >>
>>>> >>         coneActor = vtkActor()
>>>> >>         coneActor.SetMapper(coneMapper)
>>>> >>
>>>> >>         widget.renderer.AddActor(coneActor)
>>>> >>
>>>> >> I don't understand why I see clipping occur here, since I'm using
>>>> ResetCameraClippingRange, and nothing is behind the camera. The radius of
>>>> these cones is the default (0.5).
>>>> >>
>>>> >> It's probably something stupid, but any advice is much appreciated.
>>>> >>
>>>> >> Elvis
>>>> >>
>>>> >> _______________________________________________
>>>> >> 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
>>>> >>
>>>> >
>>>> >
>>>> >
>>>> > --
>>>> > Ken Martin PhD
>>>> > Chairman & CFO
>>>> > Kitware Inc.
>>>> > 28 Corporate Drive
>>>> > Clifton Park NY 12065
>>>> > 518 371 3971
>>>> >
>>>> > This communication, including all attachments, contains confidential
>>>> and legally privileged information, and it is intended only for the use of
>>>> the addressee.  Access to this email by anyone else is unauthorized. If you
>>>> are not the intended recipient, any disclosure, copying, distribution or
>>>> any action taken in reliance on it is prohibited and may be unlawful. If
>>>> you received this communication in error please notify us immediately and
>>>> destroy the original message.  Thank you.
>>>>
>>>
>>>
>>
>
>
> --
> Ken Martin PhD
> Chairman & CFO
> Kitware Inc.
> 28 Corporate Drive
> Clifton Park NY 12065
> 518 371 3971
>
> This communication, including all attachments, contains confidential and
> legally privileged information, and it is intended only for the use of the
> addressee.  Access to this email by anyone else is unauthorized. If you are
> not the intended recipient, any disclosure, copying, distribution or any
> action taken in reliance on it is prohibited and may be unlawful. If you
> received this communication in error please notify us immediately and
> destroy the original message.  Thank you.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160621/d8c50849/attachment.html>


More information about the vtkusers mailing list