From: apl Date: Tue, 14 Jul 2015 17:21:24 +0000 (+0300) Subject: 0026435: Visualization - V3d_View::ConvertToGrid returns wrong coordinates for non... X-Git-Tag: V7_0_0_beta~423 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=aacbabe117422d080bec7e74ae31680f7d0b4747;p=occt.git 0026435: Visualization - V3d_View::ConvertToGrid returns wrong coordinates for non-orthogonal projection --- diff --git a/src/V3d/V3d_View_4.cxx b/src/V3d/V3d_View_4.cxx index 13e68524cf..bd2fc63d21 100644 --- a/src/V3d/V3d_View_4.cxx +++ b/src/V3d/V3d_View_4.cxx @@ -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 index 0000000000..67daf76c4b --- /dev/null +++ b/tests/bugs/vis/bug26435 @@ -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