// =======================================================================
OpenGl_BVHTreeSelector::OpenGl_BVHTreeSelector()
: myIsProjectionParallel (Standard_True),
- myCamScaleInv (1.0),
+ myCamScale (1.0),
myPixelSize (1.0)
{
//
return;
myIsProjectionParallel = theCamera->IsOrthographic();
+ const gp_Dir aCamDir = theCamera->Direction();
myCamera = theCamera;
myProjectionMat = theCamera->ProjectionMatrix();
myWorldViewMat = theCamera->OrientationMatrix();
myWorldViewProjState = theCamera->WorldViewProjState();
myCamEye.SetValues (theCamera->Eye().X(), theCamera->Eye().Y(), theCamera->Eye().Z());
- myCamScaleInv = 1.0 / myCamera->Scale();
+ myCamDir.SetValues (aCamDir.X(), aCamDir.Y(), aCamDir.Z());
+ myCamScale = theCamera->IsOrthographic()
+ ? theCamera->Scale()
+ : 2.0 * Tan (theCamera->FOVy() * M_PI / 360.0); // same as theCamera->Scale()/theCamera->Distance()
Standard_Real nLeft = 0.0, nRight = 0.0, nTop = 0.0, nBottom = 0.0;
Standard_Real fLeft = 0.0, fRight = 0.0, fTop = 0.0, fBottom = 0.0;
theCtx.SizeCull2 = -1.0;
if (theSize > 0.0 && !Precision::IsInfinite (theSize))
{
- theCtx.SizeCull2 = (myPixelSize * theSize) / myCamScaleInv;
+ theCtx.SizeCull2 = myPixelSize * theSize;
+ theCtx.SizeCull2 *= myCamScale;
theCtx.SizeCull2 *= theCtx.SizeCull2;
}
}
{
return false;
}
- return (theMaxPt - theMinPt).SquareModulus() < theCtx.SizeCull2;
+
+ const Standard_Real aBoxDiag2 = (theMaxPt - theMinPt).SquareModulus();
+ if (myIsProjectionParallel)
+ {
+ return aBoxDiag2 < theCtx.SizeCull2;
+ }
+
+ // note that distances behind the Eye (aBndDist < 0) are not scaled correctly here,
+ // but majority of such objects should be culled by frustum
+ const OpenGl_Vec3d aBndCenter = (theMinPt + theMaxPt) * 0.5;
+ const Standard_Real aBndDist = (aBndCenter - myCamEye).Dot (myCamDir);
+ return aBoxDiag2 < theCtx.SizeCull2 * aBndDist * aBndDist;
}
protected:
Graphic3d_WorldViewProjState myWorldViewProjState; //!< State of world view projection matrices.
Graphic3d_Vec3d myCamEye; //!< camera eye position for distance culling
- Standard_Real myCamScaleInv; //!< inverted camera scale for size culling
+ Graphic3d_Vec3d myCamDir; //!< camera direction for size culling
+ Standard_Real myCamScale; //!< camera scale for size culling
Standard_Real myPixelSize; //!< pixel size for size culling
};
set THE_PICK_PNTS1P { { 40 170 } { 100 200 } { 170 250 } { 250 250 } { 380 350 } }
set THE_PICK_PNTS2O { { 148 192 } { 175 200 } { 190 200 } { 200 220 } { 250 230 } }
set THE_PICK_PNTS2P { { 152 192 } { 175 200 } { 190 200 } { 220 220 } { 250 230 } }
+set THE_PICK_PNTS3P { { 90 155 } { 105 160 } { 125 170 } { 140 175 } { 160 180 } }
pload MODELING VISUALIZATION
vclear
for { set x 2 } { $x < $THE_NB_BOXES } { incr x } { if { [vreadpixel {*}[lindex $THE_PICK_PNTS2P $x] rgb name] == "BLACK" } { puts "Error: object $x is culled" } }
for { set x 0 } { $x < 2 } { incr x } { if { [vreadpixel {*}[lindex $THE_PICK_PNTS2P $x] rgb name] != "BLACK" } { puts "Error: object $x is NOT culled" } }
vdump $::imagedir/${::casename}_30p.png
+
+vviewparams -eye 16.8333 -9.08333 10.0833 -at 7.5 0.25 0.75
+for { set x 3 } { $x < $THE_NB_BOXES } { incr x } { if { [vreadpixel {*}[lindex $THE_PICK_PNTS3P $x] rgb name] == "BLACK" } { puts "Error: object $x is culled" } }
+for { set x 0 } { $x < 3 } { incr x } { if { [vreadpixel {*}[lindex $THE_PICK_PNTS3P $x] rgb name] != "BLACK" } { puts "Error: object $x is NOT culled" } }
+vdump $::imagedir/${::casename}_30p2.png