0025624: Visualization - selection is incorrect in perspective mode in a specific...
authorvpa <vpa@opencascade.com>
Thu, 12 Feb 2015 08:48:05 +0000 (11:48 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 12 Feb 2015 12:45:58 +0000 (15:45 +0300)
Corrected computation of picking line for perspective camera;
Test case for issue 25624.

src/Select3D/Select3D_Projector.cdl
src/Select3D/Select3D_Projector.cxx
src/StdSelect/StdSelect_ViewerSelector3d.cxx
tests/bugs/vis/bug25624 [new file with mode: 0644]

index b821f14..ca37598 100644 (file)
@@ -127,9 +127,13 @@ is
     returns Projector from Select3D;
 
     Create (theViewTrsf : Mat4d from Graphic3d;
     returns Projector from Select3D;
 
     Create (theViewTrsf : Mat4d from Graphic3d;
-            theProjTrsf : Mat4d from Graphic3d)
+            theProjTrsf : Mat4d from Graphic3d;
+            theZNear    : Real from Standard = 0.0;
+            theZFar     : Real from Standard = 10.0)
     ---Purpose: Builds the Projector from the passed model-view <theViewTrsf>
     ---Purpose: Builds the Projector from the passed model-view <theViewTrsf>
-    -- and projection <theProjTrsf> transformation matrices.
+    -- and projection <theProjTrsf> transformation matrices. Parameters <theZNear>
+    -- and <theZFar> are passed to define view frustum depth for further projection
+    -- line computation using perspective projection.
     returns Projector from Select3D;
 
     Set (me : mutable;
     returns Projector from Select3D;
 
     Set (me : mutable;
@@ -140,7 +144,9 @@ is
 
     Set (me : mutable;
          theViewTrsf : Mat4d from Graphic3d;
 
     Set (me : mutable;
          theViewTrsf : Mat4d from Graphic3d;
-         theProjTrsf : Mat4d from Graphic3d);
+         theProjTrsf : Mat4d from Graphic3d;
+         theZNear    : Real from Standard;
+         theZFar     : Real from Standard);
     ---Purpose: Sets new parameters for the Projector.
 
     SetView (me : mutable;
     ---Purpose: Sets new parameters for the Projector.
 
     SetView (me : mutable;
@@ -245,5 +251,7 @@ fields
     myInvTrsf    : GTrsf   from gp is protected;
     myScaledTrsf : Trsf    from gp is protected;
     myProjTrsf   : Mat4d   from Graphic3d is protected;
     myInvTrsf    : GTrsf   from gp is protected;
     myScaledTrsf : Trsf    from gp is protected;
     myProjTrsf   : Mat4d   from Graphic3d is protected;
+    myZNear      : Real    from Standard is protected;
+    myZFar       : Real    from Standard is protected;
 
 end Projector;
 
 end Projector;
index 50cc4a9..f7975cb 100644 (file)
@@ -107,6 +107,8 @@ namespace
 Select3D_Projector::Select3D_Projector (const Handle(V3d_View)& theView)
 : myPersp (Standard_False),
   myFocus (0.0),
 Select3D_Projector::Select3D_Projector (const Handle(V3d_View)& theView)
 : myPersp (Standard_False),
   myFocus (0.0),
+  myZNear (0.0),
+  myZFar (10.0),
   myType (-1)
 {
   SetView (theView);
   myType (-1)
 {
   SetView (theView);
@@ -119,6 +121,8 @@ Select3D_Projector::Select3D_Projector (const Handle(V3d_View)& theView)
 Select3D_Projector::Select3D_Projector()
 : myPersp (Standard_False),
   myFocus (0.0),
 Select3D_Projector::Select3D_Projector()
 : myPersp (Standard_False),
   myFocus (0.0),
+  myZNear (0.0),
+  myZFar (10.0),
   myType (-1)
 {
   Scaled();
   myType (-1)
 {
   Scaled();
@@ -131,6 +135,8 @@ Select3D_Projector::Select3D_Projector()
 Select3D_Projector::Select3D_Projector (const gp_Ax2& theCS)
 : myPersp (Standard_False),
   myFocus (0.0),
 Select3D_Projector::Select3D_Projector (const gp_Ax2& theCS)
 : myPersp (Standard_False),
   myFocus (0.0),
+  myZNear (0.0),
+  myZFar (10.0),
   myType (-1)
 {
   myScaledTrsf.SetTransformation (theCS);
   myType (-1)
 {
   myScaledTrsf.SetTransformation (theCS);
@@ -145,6 +151,8 @@ Select3D_Projector::Select3D_Projector (const gp_Ax2& theCS)
 Select3D_Projector::Select3D_Projector (const gp_Ax2& theCS, const Standard_Real theFocus)
 : myPersp (Standard_True),
   myFocus (theFocus),
 Select3D_Projector::Select3D_Projector (const gp_Ax2& theCS, const Standard_Real theFocus)
 : myPersp (Standard_True),
   myFocus (theFocus),
+  myZNear (0.0),
+  myZFar (10.0),
   myType (-1)
 {
   myScaledTrsf.SetTransformation (theCS);
   myType (-1)
 {
   myScaledTrsf.SetTransformation (theCS);
@@ -163,6 +171,8 @@ Select3D_Projector::Select3D_Projector (const gp_Trsf& theViewTrsf,
   myFocus (theFocus),
   myGTrsf (theViewTrsf),
   myScaledTrsf (theViewTrsf),
   myFocus (theFocus),
   myGTrsf (theViewTrsf),
   myScaledTrsf (theViewTrsf),
+  myZNear (0.0),
+  myZFar (10.0),
   myType (-1)
 {
   Scaled();
   myType (-1)
 {
   Scaled();
@@ -179,6 +189,8 @@ Select3D_Projector::Select3D_Projector (const gp_GTrsf& theViewTrsf,
   myFocus (theFocus),
   myGTrsf (theViewTrsf),
   myScaledTrsf (theViewTrsf.Trsf()),
   myFocus (theFocus),
   myGTrsf (theViewTrsf),
   myScaledTrsf (theViewTrsf.Trsf()),
+  myZNear (0.0),
+  myZFar (10.0),
   myType (-1)
 {
   Scaled();
   myType (-1)
 {
   Scaled();
@@ -189,12 +201,14 @@ Select3D_Projector::Select3D_Projector (const gp_GTrsf& theViewTrsf,
 //purpose  :
 //=======================================================================
 Select3D_Projector::Select3D_Projector (const Graphic3d_Mat4d& theViewTrsf,
 //purpose  :
 //=======================================================================
 Select3D_Projector::Select3D_Projector (const Graphic3d_Mat4d& theViewTrsf,
-                                        const Graphic3d_Mat4d& theProjTrsf)
+                                        const Graphic3d_Mat4d& theProjTrsf,
+                                        const Standard_Real theZNear,
+                                        const Standard_Real theZFar)
 : myPersp (Standard_False),
   myFocus (0.0),
   myType (-1)
 {
 : myPersp (Standard_False),
   myFocus (0.0),
   myType (-1)
 {
-  Set (theViewTrsf, theProjTrsf);
+  Set (theViewTrsf, theProjTrsf, theZNear, theZFar);
 }
 
 //=======================================================================
 }
 
 //=======================================================================
@@ -217,7 +231,9 @@ void Select3D_Projector::Set (const gp_Trsf& theViewTrsf,
 //purpose  :
 //=======================================================================
 void Select3D_Projector::Set (const Graphic3d_Mat4d& theViewTrsf,
 //purpose  :
 //=======================================================================
 void Select3D_Projector::Set (const Graphic3d_Mat4d& theViewTrsf,
-                              const Graphic3d_Mat4d& theProjTrsf)
+                              const Graphic3d_Mat4d& theProjTrsf,
+                              const Standard_Real theZNear,
+                              const Standard_Real theZFar)
 {
   // Copy elements corresponding to common view-transformation
   for (Standard_Integer aRowIt = 0; aRowIt < 3; ++aRowIt)
 {
   // Copy elements corresponding to common view-transformation
   for (Standard_Integer aRowIt = 0; aRowIt < 3; ++aRowIt)
@@ -239,6 +255,8 @@ void Select3D_Projector::Set (const Graphic3d_Mat4d& theViewTrsf,
   myPersp    = Standard_False;
   myFocus    = 0.0;
   myProjTrsf = theProjTrsf;
   myPersp    = Standard_False;
   myFocus    = 0.0;
   myProjTrsf = theProjTrsf;
+  myZNear    = theZNear;
+  myZFar     = theZFar;
   Scaled();
 }
 
   Scaled();
 }
 
@@ -258,7 +276,10 @@ void Select3D_Projector::SetView (const Handle(V3d_View)& theView)
   aScale.ChangeValue (2, 2) = aFrameScale.Z();
   Graphic3d_Mat4d aScaledProjTrsf = aScale * aProjTrsf;
 
   aScale.ChangeValue (2, 2) = aFrameScale.Z();
   Graphic3d_Mat4d aScaledProjTrsf = aScale * aProjTrsf;
 
-  Set (aViewTrsf, aScaledProjTrsf);
+  Set (aViewTrsf,
+       aScaledProjTrsf,
+       theView->Camera()->ZNear(),
+       theView->Camera()->ZFar());
 }
 
 //=======================================================================
 }
 
 //=======================================================================
@@ -454,8 +475,8 @@ gp_Lin Select3D_Projector::Shoot (const Standard_Real theX, const Standard_Real
       return gp_Lin();
     }
 
       return gp_Lin();
     }
 
-    Graphic3d_Vec4d aVPnt1 = aProjInv * Graphic3d_Vec4d (theX, theY,  0.0, 1.0);
-    Graphic3d_Vec4d aVPnt2 = aProjInv * Graphic3d_Vec4d (theX, theY, 10.0, 1.0);
+    Graphic3d_Vec4d aVPnt1 = aProjInv * Graphic3d_Vec4d (theX, theY, myZNear, 1.0);
+    Graphic3d_Vec4d aVPnt2 = aProjInv * Graphic3d_Vec4d (theX, theY, myZFar, 1.0);
     aVPnt1 /= aVPnt1.w();
     aVPnt2 /= aVPnt2.w();
 
     aVPnt1 /= aVPnt1.w();
     aVPnt2 /= aVPnt2.w();
 
index 27a053c..e7128bc 100644 (file)
@@ -475,7 +475,10 @@ Standard_Boolean StdSelect_ViewerSelector3d::UpdateProj (const Handle(V3d_View)&
       aScaledProj.ChangeValue (2, 2) = aViewDimensions.Z();
       Graphic3d_Mat4d aScaledProjMatrix = aScaledProj * aProjMatrix;
 
       aScaledProj.ChangeValue (2, 2) = aViewDimensions.Z();
       Graphic3d_Mat4d aScaledProjMatrix = aScaledProj * aProjMatrix;
 
-      myProjector = new Select3D_Projector (aMVMatrix, aScaledProjMatrix);
+      Standard_Real aZNear = theView->Camera()->ZNear();
+      Standard_Real aZFar  = theView->Camera()->ZFar();
+
+      myProjector = new Select3D_Projector (aMVMatrix, aScaledProjMatrix, aZNear, aZFar);
     }
   }
 
     }
   }
 
diff --git a/tests/bugs/vis/bug25624 b/tests/bugs/vis/bug25624
new file mode 100644 (file)
index 0000000..65b9347
--- /dev/null
@@ -0,0 +1,29 @@
+puts "========"
+puts "OCC25624"
+puts "========"
+puts ""
+############################################################################
+puts "Visualization - selection is incorrect in perspective mode in a specific case"
+############################################################################
+
+pload MODELING VISUALIZATION
+box a 0.0 0.0 0.0 0.1 0.1 0.1
+box b 0.0 0.0 0.5 0.1 0.1 0.1
+box c 0.0 0.0 1.0 0.1 0.1 0.1
+
+vinit View1
+vautozfit 1
+vclear
+vtop
+vsetdispmode 0
+vcamera -persp
+vdisplay a b c
+vfit
+vselect 210 210
+
+# check if the closest box is selected
+checkcolor 170 10 0.8 0.8 0.8
+
+# check if the farthest box is displayed
+# without any highlighting
+checkcolor 210 184 1 1 0