MantisBT - VTK
View Issue Details
0007823VTK(No Category)public2008-10-17 11:062016-08-12 09:55
Serge Lalonde 
Dave DeMarle 
normalminoralways
closedmoved 
 
 
TBD
incorrect functionality
0007823: Near plane clipping problem with vktRenderer and vtkCamera
I have noticed that it is very easy to cause the near clipping plane to cut-off the model when in parallel projection mode.

I ran into this recently when adding a vtkBoxWidget and scaling a simple cube a few times after rotating it so that one of the corners points towards the viewer.

I tried calling vtkRenderer::ResetCameraClippingRange() to no avail. vtkRenderer::ResetCamera() fixed the problem, but would lose my camera setting.

After searching fruitlessly in the vtkusers archives, I decided to trace into the code and I discovered that there is code in vtkRenderer::ResetCameraClippingRange() and vtkCamera::SetClippingRange() that modifies the near plane value to "fix" potential camera and depth buffer problems. In my opinion, these fixes are valid, but only for perspective projections. For parallel projections, they are unnecessary and in fact cause the clipping problem I was encountering. To test this, I modified the code and rebuilt and lo and behold, no more near plane clipping!

Attached is my modified version of vtkCamera.cxx and vtkRenderer.cxx along with the patch files relative to version 5.2.0 (only vtkCamera.cxx has changed since then). The changes are small and localized.
No tags attached.
cxx vtkCamera.cxx (32,507) 2008-10-17 11:06
https://www.vtk.org/Bug/file/6780/vtkCamera.cxx
cxx vtkRenderer.cxx (57,287) 2008-10-17 11:07
https://www.vtk.org/Bug/file/6781/vtkRenderer.cxx
patch vtkCamera.cxx.patch (352) 2008-10-17 11:07
https://www.vtk.org/Bug/file/6782/vtkCamera.cxx.patch
patch vtkRenderer.cxx.patch (1,166) 2008-10-17 11:07
https://www.vtk.org/Bug/file/6783/vtkRenderer.cxx.patch
? vtkCamera.cxx.patch-unified (575) 2009-11-02 23:12
https://www.vtk.org/Bug/file/7625/vtkCamera.cxx.patch-unified
? vtkRenderer.cxx.patch-unified (1,718) 2009-11-02 23:12
https://www.vtk.org/Bug/file/7626/vtkRenderer.cxx.patch-unified
? vtkCamera.cxx.patch-unified_2 (575) 2009-11-03 01:27
https://www.vtk.org/Bug/file/7627/vtkCamera.cxx.patch-unified_2
? vtkRenderer.cxx.patch-unified_2 (828) 2009-11-03 01:27
https://www.vtk.org/Bug/file/7628/vtkRenderer.cxx.patch-unified_2
Issue History
2008-10-17 11:06Serge LalondeNew Issue
2008-10-17 11:06Serge LalondeFile Added: vtkCamera.cxx
2008-10-17 11:07Serge LalondeFile Added: vtkRenderer.cxx
2008-10-17 11:07Serge LalondeFile Added: vtkCamera.cxx.patch
2008-10-17 11:07Serge LalondeFile Added: vtkRenderer.cxx.patch
2009-04-16 09:03Gerrick BivinsNote Added: 0016040
2009-06-16 10:03Ben HeldNote Added: 0016730
2009-11-02 23:12ediceNote Added: 0018324
2009-11-02 23:12ediceFile Added: vtkCamera.cxx.patch-unified
2009-11-02 23:12ediceFile Added: vtkRenderer.cxx.patch-unified
2009-11-03 01:27ediceFile Added: vtkCamera.cxx.patch-unified_2
2009-11-03 01:27ediceFile Added: vtkRenderer.cxx.patch-unified_2
2009-11-03 01:39ediceNote Added: 0018325
2010-03-17 12:45xabi riobeNote Added: 0019938
2011-06-16 13:11Zack GalbreathCategory => (No Category)
2013-08-20 15:03Serge LalondeNote Added: 0031489
2013-08-20 15:03Serge LalondeStatusexpired => backlog
2013-08-20 15:03Serge LalondeResolutionopen => reopened
2013-12-16 12:14Dave DeMarleProject => TBD
2013-12-16 12:14Dave DeMarleType => incorrect functionality
2013-12-16 12:14Dave DeMarleNote Added: 0031943
2016-07-06 16:48Berk GeveciStatusbacklog => expired
2016-07-06 16:48Berk GeveciNote Added: 0036283
2016-07-07 05:14ediceNote Added: 0036323
2016-07-07 07:56Dave DeMarleAssigned To => Dave DeMarle
2016-07-07 07:56Dave DeMarleStatusexpired => backlog
2016-08-12 09:55Kitware RobotNote Added: 0037030
2016-08-12 09:55Kitware RobotStatusbacklog => closed
2016-08-12 09:55Kitware RobotResolutionreopened => moved

Notes
(0016040)
Gerrick Bivins   
2009-04-16 09:03   
I also ran into this issue. The attached patches addressed my problems using VTK 5.2.
(0016730)
Ben Held   
2009-06-16 10:03   
I ran into this as well and the attached patches solved my problem as long as I called ResetCameraClippingRange as needed. I recommend incorporating these in the next VTK release.
(0018324)
edice   
2009-11-02 23:12   
I wanted to try out this patch, but it was not in unified format and did not apply cleanly.

So, I have attempted to recreate the patch in unified format. It compiles, I assume it works.
(0018325)
edice   
2009-11-03 01:39   
I found the patches I uploaded did not allow non-parallel-projection mode to work in the same way as it used to.

I simplified the patches down to its essence, now there is the original code for perspective-projection-mode, and an else{} block for parallel-projection. I believe it now works the way the original poster intended.

I have not tested it in parallel projection mode yet. I suspect it may cause trouble with the depth buffer:

In Perspective-projection mode, there is extra logic to push the Near plane AWAY from the camera, to ensure the clipped range is not too "broad" for the depth buffer.
distance_near / distance_far >= 0.001
so 2/4 = 0.5 -- ok
but 1.5 / 10000 = 0.00015 too broad, near plane will be adjusted so its distance from the camera is 10.
This seems to be the cause of the "near objects clipped at near plane" problems. The only "solution" is to back the camera away from the near objects until the near/far ratio is smaller.

All this is not considered in the Parallel Projection code path, and as such it may cause Depth-Buffer related rendering errors.
(0019938)
xabi riobe   
2010-03-17 12:45   
I would also like to see this issue solved in the next vtk release!
(0031489)
Serge Lalonde   
2013-08-20 15:03   
This issue isn't fixed in 5.10 and I compared the code in 6.0 and it still doesn't look fixed (I can't update to 6 right now for a proper test, sorry).
If it has indeed been fixed, please go ahead and close this issue. Otherwise, there are several users (myself included) who would appreciate this fix being incorporated in the next release.
I had originally submitted the fixed code (which must be updated for the new version), but the core of the changes are there.
Thanks.
(0031943)
Dave DeMarle   
2013-12-16 12:14   
Reformatted as gerrit topic to facilitate testing and review. Please let me know if I applied patch wrong.

http://review.source.kitware.com/#/c/13823/ [^]

Appears to make these tests fail on my machine. Dashboard may turn up more or fewer.
ctest -R "vtkGeovisCoreCxx-TestLabeledGeoView2D|vtkImagingCoreCxx-FastSplatter|vtkRenderingOpenGLCxx-TestImageResliceMapperOffAxis|vtkRenderingOpenGLCxx-TestImageSliceMapperAlpha|vtkRenderingOpenGLCxx-TestImageSliceMapperInterpolation|vtkRenderingOpenGLCxx-TestImageStack|vtkViewsInfovisCxx-TestCoincidentGraphLayoutView|vtkViewsInfovisCxx-TestGraphLayoutView"
(0036283)
Berk Geveci   
2016-07-06 16:48   
Setting to status of bugs that have not been updated in the last year to expired. Please re-open if still important.
(0036323)
edice   
2016-07-07 05:14   
Please reopen until someone can review and patch the mainline.
(0037030)
Kitware Robot   
2016-08-12 09:55   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current VTK Issues page linked in the banner at the top of this page.