]> OCCT Git - occt.git/commitdiff
0026435: Visualization - V3d_View::ConvertToGrid returns wrong coordinates for non...
authorapl <apl@opencascade.com>
Tue, 14 Jul 2015 17:21:24 +0000 (20:21 +0300)
committerbugmaster <bugmaster@opencascade.com>
Tue, 21 Jul 2015 08:37:51 +0000 (11:37 +0300)
src/V3d/V3d_View_4.cxx
tests/bugs/vis/bug26435 [new file with mode: 0644]

index 13e68524cf3ebd6e86eca37db37777b776277964..bd2fc63d211e2b64b9dea23ac5cbf27b20f80018 100644 (file)
@@ -195,20 +195,12 @@ Graphic3d_Vertex V3d_View::Compute (const Graphic3d_Vertex & AVertex) const
   AVertex.Coord (x1, y1, z1);
     
   // project ray from camera onto grid plane
-  if (!myCamera->IsOrthographic())
-  {
-    gp_Vec aDirCamera2Point       = gp_Vec (myCamera->Eye(), gp_Pnt (x1, y1, z1)).Normalized();
-    gp_Vec aVecCamera2Orig        = gp_Vec (myCamera->Eye(), gp_Pnt (x0, y0, z0));
-    Standard_Real aDistPointPlane = aVecCamera2Orig.Dot (aPlaneNormal) / aDirCamera2Point.Dot (aPlaneNormal);
-    aPointOnPlane = gp_Vec (myCamera->Eye().XYZ()) + aDirCamera2Point * aDistPointPlane;
-  }
-  else
-  {
-    gp_Vec aDirCamera             = myCamera->Direction();
-    gp_Vec aVecOrig2Point         = gp_Vec (gp_Pnt (x0, y0, z0), gp_Pnt (x1, y1, z1));
-    Standard_Real aDistPointPlane = aVecOrig2Point.Dot (aPlaneNormal) / aDirCamera.Dot (aPlaneNormal);
-    aPointOnPlane = gp_Vec (x1, y1, z1) + aDirCamera * aDistPointPlane;
-  }
+  gp_Vec aProjection  = myCamera->IsOrthographic()
+                      ? gp_Vec (myCamera->Direction())
+                      : gp_Vec (myCamera->Eye(), gp_Pnt (x1, y1, z1)).Normalized();
+  gp_Vec aPointOrigin = gp_Vec (gp_Pnt (x1, y1, z1), gp_Pnt (x0, y0, z0));
+  Standard_Real aT    = aPointOrigin.Dot (aPlaneNormal) / aProjection.Dot (aPlaneNormal);
+  aPointOnPlane       = gp_Vec (x1, y1, z1) + aProjection * aT;
 
   if (IsRectangular) {
     Standard_Real XS, YS;
diff --git a/tests/bugs/vis/bug26435 b/tests/bugs/vis/bug26435
new file mode 100644 (file)
index 0000000..67daf76
--- /dev/null
@@ -0,0 +1,47 @@
+puts "============"
+puts "CR26435"
+puts "============"
+puts ""
+#######################################################################
+# Visualization - V3d_View::ConvertToGrid returns wrong coordinates for non-orthogonal projection
+#######################################################################
+
+vinit View1 w=400 h=400
+vgrid r l 0 0 5 5 0
+
+# 1. Check convert to grid for axonometric projection. Grid is at origin.
+vaxo
+set output [vconvert 200 200 grid]
+
+checkreal "vconvert axo - grid origin" [lindex $output 2]  5.0 1e-7 0.0
+checkreal "vconvert axo - grid origin" [lindex $output 3] -5.0 1e-7 0.0
+checkreal "vconvert axo - grid origin" [lindex $output 4]  0.0 1e-7 0.0
+
+# 2. Check convert to grid for top projection. Grid is at origin.
+vtop
+set output [vconvert 200 200 grid]
+
+checkreal "vconvert top - grid origin" [lindex $output 2]  0.0 1e-7 0.0
+checkreal "vconvert top - grid origin" [lindex $output 3] -5.0 1e-7 0.0
+checkreal "vconvert top - grid origin" [lindex $output 4]  0.0 1e-7 0.0
+
+# 3. Check convert to grid for axonometric projection. Grid is not at origin.
+vpriviledgedplane 0.0 0.0 10.0 0 0 1 1 0 0
+
+vaxo
+set output [vconvert 200 200 grid]
+
+checkreal "vconvert axo - grid lifted" [lindex $output 2]  15.0 1e-7 0.0
+checkreal "vconvert axo - grid lifted" [lindex $output 3] -15.0 1e-7 0.0
+checkreal "vconvert axo - grid lifted" [lindex $output 4]  10.0 1e-7 0.0
+
+# 4. Check convert to grid for top projection. Grid is not at origin.
+vtop
+set output [vconvert 200 200 grid]
+
+checkreal "vconvert top - grid lifted" [lindex $output 2]  0.0 1e-7 0.0
+checkreal "vconvert top - grid lifted" [lindex $output 3] -5.0 1e-7 0.0
+checkreal "vconvert top - grid lifted" [lindex $output 4] 10.0 1e-7 0.0
+
+# do not save any image
+set only_screen 0