diff --git a/Interaction/Style/Testing/Python/TestStyleRubberBandZoom.py b/Interaction/Style/Testing/Python/TestStyleRubberBandZoom.py index 317e84ab3073c215e7b3d9939e46cdd2e6fa5195..66e9bd34a794c2df004d1dabec3356387a3e2e99 100755 --- a/Interaction/Style/Testing/Python/TestStyleRubberBandZoom.py +++ b/Interaction/Style/Testing/Python/TestStyleRubberBandZoom.py @@ -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") diff --git a/Interaction/Style/Testing/Tcl/TestStyleRubberBandZoom.tcl b/Interaction/Style/Testing/Tcl/TestStyleRubberBandZoom.tcl index e9211917781f3da7daaf0a72f020c0b318e18a51..fc902b43502dad4c7c96ecabc64397ba11940f0b 100644 --- a/Interaction/Style/Testing/Tcl/TestStyleRubberBandZoom.tcl +++ b/Interaction/Style/Testing/Tcl/TestStyleRubberBandZoom.tcl @@ -32,6 +32,7 @@ rbz SetInteractor iren iren SetInteractorStyle rbz renWin Render +[ren GetActiveCamera] SetClippingRange 538.2413295991446 551.8332823667997 # Test style diff --git a/Rendering/Core/vtkRenderer.cxx b/Rendering/Core/vtkRenderer.cxx index 7fbb8ce1e2d58fd4d8dddc1ab7758d46f2baa053..20b2beab305e26e6361e653c2a4a2f8c846ed2a6 100644 --- a/Rendering/Core/vtkRenderer.cxx +++ b/Rendering/Core/vtkRenderer.cxx @@ -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"; diff --git a/Rendering/Core/vtkRenderer.h b/Rendering/Core/vtkRenderer.h index fe1ef3ca6e380661a6352abfbd32327cd523e87b..7684c65b951e6cf4cac828bd97dc25338f71007e 100644 --- a/Rendering/Core/vtkRenderer.h +++ b/Rendering/Core/vtkRenderer.h @@ -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.