How can I disable automatic reset of camera clipping range?

I am working on some endoscopic type visualizations where the camera is often quite close to surfaces (models or volume renderings). These are automatically removed because they are too close to the camera’s close clipping plane, but I would like them to remain visible. I can set the clipping range I want with code like


However, as soon as I interact with the view with the mouse in any way (click and drag to rotate view, scroll wheel to zoom, middle click to translate) the clipping range is automatically reset to the values generated by


Is there a way I can prevent this from happening? Thanks!

Near clipping distance is almost set to 0 automatically when you are inside any rendered object. It is not set to as low as 0.001 to avoid various inaccuracies and instabilities. See VTK’s clipping range setting implementation here. You can ask experts on VTK forum about the details of this algorithm.

In practice, the automatically set near clipping distance should be sufficient (and you should be able to achieve the desired behavior by adjusting the camera position and view angle). What near clipping distance do you get by default? Do you use parallel projection? What view angle value do you use? Can you post a few screenshots?

You may experiment with adding an observer to the camera (with low priority, so it is called after default clipping range setting code is executed) and adjust the clipping range after each motion.

Thanks for your help. I am using a camera with a wide view angle (100 deg) to simulate an endoscopy camera. The default clipping range the camera is reset to depends on the view, but is typically something like (0.3157, 315.7), with the far plane distance 100x the close plane distance. With those default values, the view looks like this:

The camera is located entirely within the yellow structure, so the purple/blue exterior should not be visible. If I manually set the clipping range to (0.01,100), this is what I see instead:

I see from the vtk default clipping range code you sent that the problem for me is that the default range is limited to be a factor of at most 100 between the near clipping plane and the far clipping plane (unless the zBuffer depth is >16bit). I understand that the rationale for limiting the range is effective use of the zBuffer resolution, but because I am inside a small and curving tube, I do not need anything more than ~50 mm away to be rendered, and do want it to be clear the the camera is inside a tube.

I will look into how to add a low-priority observer to the camera to apply my own clipping range. Thanks.

It is very important to limit the far/near distance ratio to keep the Z buffer functional, otherwise all features that rely on the z buffer may malfunction (picking, occlusion, depth peeling, etc.).

I could not reproduce problem of seeing outside a tube when being inside the tube. Could you share your scene?

Here is a scene that illustrates this issue.

When you open it, you should see the full 3D view showing the interior of a yellow tube. However, if you click and drag anywhere on the view, you will see that the blue background becomes visible around the edges. The camera has a view angle of 110 deg. If you set the clipping range manually as follows, the enclosed view is restored:

camNode = getNode('Camera')