Commit 4283fb82 authored by Ken Martin's avatar Ken Martin Committed by Kitware Robot

Merge topic 'better_clipping_range'

79cafcfc tcl test as well
51f7345f better and tighter options for clipping range
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1258
parents 6e95c1c1 79cafcfc
...@@ -27,6 +27,7 @@ rbz = vtk.vtkInteractorStyleRubberBandZoom() ...@@ -27,6 +27,7 @@ rbz = vtk.vtkInteractorStyleRubberBandZoom()
rbz.SetInteractor(iren) rbz.SetInteractor(iren)
iren.SetInteractorStyle(rbz) iren.SetInteractorStyle(rbz)
renWin.Render() renWin.Render()
ren.GetActiveCamera().SetClippingRange(538.2413295991446, 551.8332823667997)
# Test style # Test style
iren.SetEventInformationFlipY(250,250,0,0,"0",0,"0") iren.SetEventInformationFlipY(250,250,0,0,"0",0,"0")
iren.InvokeEvent("LeftButtonPressEvent") iren.InvokeEvent("LeftButtonPressEvent")
......
...@@ -32,6 +32,7 @@ rbz SetInteractor iren ...@@ -32,6 +32,7 @@ rbz SetInteractor iren
iren SetInteractorStyle rbz iren SetInteractorStyle rbz
renWin Render renWin Render
[ren GetActiveCamera] SetClippingRange 538.2413295991446 551.8332823667997
# Test style # Test style
......
...@@ -106,6 +106,8 @@ vtkRenderer::vtkRenderer() ...@@ -106,6 +106,8 @@ vtkRenderer::vtkRenderer()
// a value of 0 indicates it is uninitialized // a value of 0 indicates it is uninitialized
this->NearClippingPlaneTolerance = 0; this->NearClippingPlaneTolerance = 0;
this->ClippingRangeExpansion = 0.5;
this->Erase = 1; this->Erase = 1;
this->Draw = 1; this->Draw = 1;
...@@ -1148,6 +1150,25 @@ void vtkRenderer::ResetCameraClippingRange( double bounds[6] ) ...@@ -1148,6 +1150,25 @@ void vtkRenderer::ResetCameraClippingRange( double bounds[6] )
} }
} }
// do not let far - near be less than 0.1 of the window height
// this is for cases such as 2D images which may have zero range
double minGap = 0.0;
if(this->ActiveCamera->GetParallelProjection())
{
minGap = 0.1*this->ActiveCamera->GetParallelScale();
}
else
{
double angle=vtkMath::RadiansFromDegrees(this->ActiveCamera->GetViewAngle());
minGap = 0.2*tan(angle/2.0)*range[1];
}
if (range[1] - range[0] < minGap)
{
minGap = minGap - range[1] + range[0];
range[1] += minGap/2.0;
range[0] -= minGap/2.0;
}
// Do not let the range behind the camera throw off the calculation. // Do not let the range behind the camera throw off the calculation.
if (range[0] < 0.0) if (range[0] < 0.0)
{ {
...@@ -1155,8 +1176,8 @@ void vtkRenderer::ResetCameraClippingRange( double bounds[6] ) ...@@ -1155,8 +1176,8 @@ void vtkRenderer::ResetCameraClippingRange( double bounds[6] )
} }
// Give ourselves a little breathing room // Give ourselves a little breathing room
range[0] = 0.99*range[0] - (range[1] - range[0])*0.5; range[0] = 0.99*range[0] - (range[1] - range[0])*this->ClippingRangeExpansion;
range[1] = 1.01*range[1] + (range[1] - range[0])*0.5; range[1] = 1.01*range[1] + (range[1] - range[0])*this->ClippingRangeExpansion;
// Make sure near is not bigger than far // Make sure near is not bigger than far
range[0] = (range[0] >= range[1])?(0.01*range[1]):(range[0]); range[0] = (range[0] >= range[1])?(0.01*range[1]):(range[0]);
...@@ -1360,6 +1381,9 @@ void vtkRenderer::PrintSelf(ostream& os, vtkIndent indent) ...@@ -1360,6 +1381,9 @@ void vtkRenderer::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "Near Clipping Plane Tolerance: " os << indent << "Near Clipping Plane Tolerance: "
<< this->NearClippingPlaneTolerance << "\n"; << this->NearClippingPlaneTolerance << "\n";
os << indent << "ClippingRangeExpansion: "
<< this->ClippingRangeExpansion << "\n";
os << indent << "Ambient: (" << this->Ambient[0] << ", " os << indent << "Ambient: (" << this->Ambient[0] << ", "
<< this->Ambient[1] << ", " << this->Ambient[2] << ")\n"; << this->Ambient[1] << ", " << this->Ambient[2] << ")\n";
......
...@@ -288,6 +288,13 @@ public: ...@@ -288,6 +288,13 @@ public:
vtkSetClampMacro(NearClippingPlaneTolerance,double,0,0.99); vtkSetClampMacro(NearClippingPlaneTolerance,double,0,0.99);
vtkGetMacro(NearClippingPlaneTolerance,double); vtkGetMacro(NearClippingPlaneTolerance,double);
// Description:
// Specify enlargement of bounds when resetting the
// camera clipping range. By default the range is not expanded by
// any percent of the (far - near) on the near and far sides
vtkSetClampMacro(ClippingRangeExpansion,double,0,0.99);
vtkGetMacro(ClippingRangeExpansion,double);
// Description: // Description:
// Automatically set up the camera based on the visible actors. // Automatically set up the camera based on the visible actors.
// The camera will reposition itself to view the center point of the actors, // The camera will reposition itself to view the center point of the actors,
...@@ -590,6 +597,11 @@ protected: ...@@ -590,6 +597,11 @@ protected:
// with low z-buffer resolution. // with low z-buffer resolution.
double NearClippingPlaneTolerance; double NearClippingPlaneTolerance;
// Description:
// Specify enlargement of bounds when resetting the
// camera clipping range.
double ClippingRangeExpansion;
// Description: // Description:
// When this flag is off, the renderer will not erase the background // When this flag is off, the renderer will not erase the background
// or the Zbuffer. It is used to have overlapping renderers. // or the Zbuffer. It is used to have overlapping renderers.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment