Commit 51f7345f authored by Ken Martin's avatar Ken Martin

better and tighter options for clipping range

The old automatic clipping range code always grew
the bounds to be double the required bounds. With the
zbuffer being so heavily nonlinear this was not a good
for many situations. This topic alows you to control
the bounds expansion to it can be much tighter which
if you are calling ResetCameraClippiNgRange every time
the camera changes it should be set to 0.0 not the default
of 0.5.
parent 392555e8
......@@ -27,6 +27,7 @@ rbz = vtk.vtkInteractorStyleRubberBandZoom()
rbz.SetInteractor(iren)
iren.SetInteractorStyle(rbz)
renWin.Render()
ren.GetActiveCamera().SetClippingRange(538.2413295991446, 551.8332823667997)
# Test style
iren.SetEventInformationFlipY(250,250,0,0,"0",0,"0")
iren.InvokeEvent("LeftButtonPressEvent")
......
......@@ -106,6 +106,8 @@ vtkRenderer::vtkRenderer()
// a value of 0 indicates it is uninitialized
this->NearClippingPlaneTolerance = 0;
this->ClippingRangeExpansion = 0.5;
this->Erase = 1;
this->Draw = 1;
......@@ -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.
if (range[0] < 0.0)
{
......@@ -1155,8 +1176,8 @@ void vtkRenderer::ResetCameraClippingRange( double bounds[6] )
}
// Give ourselves a little breathing room
range[0] = 0.99*range[0] - (range[1] - range[0])*0.5;
range[1] = 1.01*range[1] + (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])*this->ClippingRangeExpansion;
// Make sure near is not bigger than far
range[0] = (range[0] >= range[1])?(0.01*range[1]):(range[0]);
......@@ -1360,6 +1381,9 @@ void vtkRenderer::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "Near Clipping Plane Tolerance: "
<< this->NearClippingPlaneTolerance << "\n";
os << indent << "ClippingRangeExpansion: "
<< this->ClippingRangeExpansion << "\n";
os << indent << "Ambient: (" << this->Ambient[0] << ", "
<< this->Ambient[1] << ", " << this->Ambient[2] << ")\n";
......
......@@ -288,6 +288,13 @@ public:
vtkSetClampMacro(NearClippingPlaneTolerance,double,0,0.99);
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:
// Automatically set up the camera based on the visible actors.
// The camera will reposition itself to view the center point of the actors,
......@@ -590,6 +597,11 @@ protected:
// with low z-buffer resolution.
double NearClippingPlaneTolerance;
// Description:
// Specify enlargement of bounds when resetting the
// camera clipping range.
double ClippingRangeExpansion;
// Description:
// When this flag is off, the renderer will not erase the background
// 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