0029975: Visualization - Graphic3d_ClipPlane::ProbeBox() returns Out for fully In box
authorkgv <kgv@opencascade.com>
Fri, 20 Jul 2018 07:40:14 +0000 (10:40 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 27 Jul 2018 13:19:04 +0000 (16:19 +0300)
src/Graphic3d/Graphic3d_ClipPlane.hxx
tests/v3d/glsl/clipping1

index 388ae39..b185760 100755 (executable)
@@ -255,58 +255,40 @@ public:
   //! Check if the given point is outside / inside / on section.
   Graphic3d_ClipState ProbePoint (const Graphic3d_Vec4d& thePoint) const
   {
+    Graphic3d_ClipState aState = Graphic3d_ClipState_Out;
     for (const Graphic3d_ClipPlane* aPlaneIter = this; aPlaneIter != NULL; aPlaneIter = aPlaneIter->myNextInChain.get())
     {
       Graphic3d_ClipState aPlnState = aPlaneIter->ProbePointHalfspace (thePoint);
-      if (aPlnState == Graphic3d_ClipState_On)
+      if (aPlnState == Graphic3d_ClipState_In)
       {
-        return Graphic3d_ClipState_On;
+        return Graphic3d_ClipState_In;
       }
-      else if (aPlnState == Graphic3d_ClipState_Out
-            && aPlaneIter->myNextInChain.IsNull())
+      else if (aPlnState != Graphic3d_ClipState_Out)
       {
-        return Graphic3d_ClipState_Out;
+        aState = Graphic3d_ClipState_On;
       }
     }
-    return Graphic3d_ClipState_In;
+    return aState;
   }
 
   //! Check if the given bounding box is fully outside / fully inside.
   Graphic3d_ClipState ProbeBox (const Graphic3d_BndBox3d& theBox) const
   {
-    Graphic3d_ClipState aPrevState = Graphic3d_ClipState_On;
+    Graphic3d_ClipState aState = Graphic3d_ClipState_Out;
     for (const Graphic3d_ClipPlane* aPlaneIter = this; aPlaneIter != NULL; aPlaneIter = aPlaneIter->myNextInChain.get())
     {
-      if (aPlaneIter->IsBoxFullOutHalfspace (theBox))
+      if (aPlaneIter->IsBoxFullInHalfspace (theBox))
       {
-        if (aPlaneIter->myNextInChain.IsNull())
-        {
-          return Graphic3d_ClipState_Out;
-        }
-        else if (aPrevState == Graphic3d_ClipState_In)
-        {
-          return Graphic3d_ClipState_On;
-        }
-        aPrevState = Graphic3d_ClipState_Out;
+        // within union operation, if box is entirely inside at least one half-space, others can be ignored
+        return Graphic3d_ClipState_In;
       }
-      else if (aPlaneIter->IsBoxFullInHalfspace (theBox))
+      else if (!aPlaneIter->IsBoxFullOutHalfspace (theBox))
       {
-        if (aPlaneIter->myNextInChain.IsNull())
-        {
-          return Graphic3d_ClipState_In;
-        }
-        else if (aPrevState == Graphic3d_ClipState_Out)
-        {
-          return Graphic3d_ClipState_On;
-        }
-        aPrevState = Graphic3d_ClipState_In;
-      }
-      else
-      {
-        return Graphic3d_ClipState_On;
+        // if at least one full out test fail, clipping state is inconclusive (partially clipped)
+        aState = Graphic3d_ClipState_On;
       }
     }
-    return Graphic3d_ClipState_On;
+    return aState;
   }
 
 public:
index 126b99b..271a73a 100644 (file)
@@ -19,6 +19,7 @@ box b2 20 40 0 20 10 70
 box b3 0  40 0 20 10 70
 box b4 0  10 0 10 30 70
 box b5 0   0 0 30 10 70
+box bb 10 -10 0 20 10 10
 
 set aNbParts 6
 set aColors { RED YELLOW GREEN GRAY MAGENTA1 ORANGE }
@@ -32,6 +33,8 @@ vinit name=View1 w=512 h=512
 vviewparams -scale 4.66737 -proj 0.465292 -0.577133 0.671134 -up -0.46873 0.482524 0.739907 -at 15.807 37.1157 21.9799
 
 vpoint p0 0 0 0
+vdisplay -dispMode 1 bb
+vaspects -noupdate bb -setColor CYAN1
 vzbufftrihedron
 
 puts "Display the geometry as dedicated objects"
@@ -74,6 +77,7 @@ vfit
 vdisplay pp1 pp2
 
 vclipplane pln -set {*}$aCapParams -equation1 0 0 -1 40 -equation2  0 1 0 -15
+if { [vreadpixel 200 360 rgb name] != "DARKTURQUOISE" } { puts "Error: bb should NOT be clipped" }
 vdump $::imagedir/${::casename}_2.png
 
 vclipplane pln -set {*}$aCapParams -equation1 0 0 -1 40 -equation2  0 1 0 -15 -equation3 -1 0 0 5