From 794b3d89365744983166c7fab8e8d17814c5a3f2 Mon Sep 17 00:00:00 2001
From: kgv <kgv@opencascade.com>
Date: Tue, 9 Nov 2021 15:17:43 +0300
Subject: [PATCH] 0032652: Visualization - Select3D_SensitiveCylinder returns
 wrong 3D point on transformed shape

SelectMgr_RectangularFrustum::OverlapsCylinder() - added missing 3D point transformation.
StdSelect_BRepSelectionTool::ComputeSensitive() - fixed cylinder height computation on TopoDS_Shape with scale transformation.
SelectMgr_AxisIntersector::OverlapsCylinder(),::OverlapsSphere() - added missing computations of surface normal.
---
 src/SelectMgr/SelectMgr_AxisIntersector.cxx   | 19 ++++++++
 .../SelectMgr_RectangularFrustum.cxx          | 16 ++++---
 src/StdSelect/StdSelect_BRepSelectionTool.cxx | 26 ++++++-----
 tests/vselect/cone_cylinder/begin             |  2 -
 tests/vselect/cone_cylinder/check_depth       |  3 ++
 tests/vselect/cone_cylinder/detecting         |  3 ++
 tests/vselect/cone_cylinder/generate_images   |  3 ++
 tests/vselect/cone_cylinder/polygon_selection |  3 ++
 .../vselect/cone_cylinder/rectangle_selection |  3 ++
 .../cone_cylinder/single_click_selection_cone |  3 ++
 .../single_click_selection_cylinder           |  3 ++
 .../single_click_selection_trunc_cone         |  3 ++
 tests/vselect/cone_cylinder/trsf_cone         | 40 +++++++++++++++++
 tests/vselect/cone_cylinder/trsf_cyl          | 40 +++++++++++++++++
 tests/vselect/sphere/begin                    |  2 -
 tests/vselect/sphere/check_depth              |  3 ++
 tests/vselect/sphere/detecting                |  3 ++
 tests/vselect/sphere/generate_images          |  3 ++
 tests/vselect/sphere/polygon_selection        |  3 ++
 tests/vselect/sphere/rectangle_selection      |  3 ++
 tests/vselect/sphere/single_click_selection   |  3 ++
 tests/vselect/sphere/trsf                     | 43 +++++++++++++++++++
 22 files changed, 209 insertions(+), 21 deletions(-)
 delete mode 100644 tests/vselect/cone_cylinder/begin
 create mode 100644 tests/vselect/cone_cylinder/trsf_cone
 create mode 100644 tests/vselect/cone_cylinder/trsf_cyl
 delete mode 100644 tests/vselect/sphere/begin
 create mode 100644 tests/vselect/sphere/trsf

diff --git a/src/SelectMgr/SelectMgr_AxisIntersector.cxx b/src/SelectMgr/SelectMgr_AxisIntersector.cxx
index ec27694381..f6660a035d 100644
--- a/src/SelectMgr/SelectMgr_AxisIntersector.cxx
+++ b/src/SelectMgr/SelectMgr_AxisIntersector.cxx
@@ -543,7 +543,11 @@ Standard_Boolean SelectMgr_AxisIntersector::OverlapsSphere (const gp_Pnt& theCen
     return Standard_False;
   }
 
+  const gp_Pnt aPntOnSphere (myAxis.Location().XYZ() + myAxis.Direction().XYZ() * aDepth);
+  const gp_Vec aNormal (aPntOnSphere.XYZ() - theCenter.XYZ());
   thePickResult.SetDepth (aDepth);
+  thePickResult.SetPickedPoint (aPntOnSphere);
+  thePickResult.SetSurfaceNormal (aNormal);
   return Standard_True;
 }
 
@@ -576,7 +580,22 @@ Standard_Boolean SelectMgr_AxisIntersector::OverlapsCylinder (const Standard_Rea
   {
     return false;
   }
+
+  const gp_Pnt aPntOnCylinder = aLoc.XYZ() + aRayDir.XYZ() * aDepth;
   thePickResult.SetDepth (aDepth);
+  thePickResult.SetPickedPoint (aPntOnCylinder.Transformed (theTrsf));
+  if (Abs (aPntOnCylinder.Z()) < Precision::Confusion())
+  {
+    thePickResult.SetSurfaceNormal (-gp::DZ().Transformed (theTrsf));
+  }
+  else if (Abs (aPntOnCylinder.Z() - theHeight) < Precision::Confusion())
+  {
+    thePickResult.SetSurfaceNormal (gp::DZ().Transformed (theTrsf));
+  }
+  else
+  {
+    thePickResult.SetSurfaceNormal (gp_Vec (aPntOnCylinder.X(), aPntOnCylinder.Y(), 0.0).Transformed (theTrsf));
+  }
   return true;
 }
 
diff --git a/src/SelectMgr/SelectMgr_RectangularFrustum.cxx b/src/SelectMgr/SelectMgr_RectangularFrustum.cxx
index 44354f1f84..12f45aac66 100644
--- a/src/SelectMgr/SelectMgr_RectangularFrustum.cxx
+++ b/src/SelectMgr/SelectMgr_RectangularFrustum.cxx
@@ -753,20 +753,24 @@ Standard_Boolean SelectMgr_RectangularFrustum::OverlapsCylinder (const Standard_
 {
   Standard_ASSERT_RAISE (mySelectionType == SelectMgr_SelectionType_Point || mySelectionType == SelectMgr_SelectionType_Box,
     "Error! SelectMgr_RectangularFrustum::Overlaps() should be called after selection frustum initialization");
-  Standard_Real aTimeEnter = 0.0, aTimeLeave = 0.0;
+  Standard_Real aTimes[2] = { 0.0, 0.0 };
   const gp_Trsf aTrsfInv = theTrsf.Inverted();
   const gp_Pnt  aLoc     = myNearPickedPnt.Transformed (aTrsfInv);
   const gp_Dir  aRayDir  = myViewRayDir   .Transformed (aTrsfInv);
-  if (!RayCylinderIntersection (theBottomRad, theTopRad, theHeight, aLoc, aRayDir, aTimeEnter, aTimeLeave))
+  if (!RayCylinderIntersection (theBottomRad, theTopRad, theHeight, aLoc, aRayDir, aTimes[0], aTimes[1]))
   {
     return Standard_False;
   }
-  thePickResult.SetDepth (aTimeEnter * myScale);
+
+  Standard_Integer aResTime = 0;
+  thePickResult.SetDepth (aTimes[aResTime] * myScale);
   if (theClipRange.IsClipped (thePickResult.Depth()))
   {
-    thePickResult.SetDepth (aTimeLeave * myScale);
+    aResTime = 1;
+    thePickResult.SetDepth (aTimes[aResTime] * myScale);
   }
-  const gp_Pnt aPntOnCylinder (aLoc.XYZ() + aRayDir.XYZ() * thePickResult.Depth());
+
+  const gp_Pnt aPntOnCylinder = aLoc.XYZ() + aRayDir.XYZ() * aTimes[aResTime];
   if (Abs (aPntOnCylinder.Z()) < Precision::Confusion())
   {
     thePickResult.SetSurfaceNormal (-gp::DZ().Transformed (theTrsf));
@@ -779,7 +783,7 @@ Standard_Boolean SelectMgr_RectangularFrustum::OverlapsCylinder (const Standard_
   {
     thePickResult.SetSurfaceNormal (gp_Vec (aPntOnCylinder.X(), aPntOnCylinder.Y(), 0.0).Transformed (theTrsf));
   }
-  thePickResult.SetPickedPoint (aPntOnCylinder);
+  thePickResult.SetPickedPoint (aPntOnCylinder.Transformed (theTrsf));
   return !theClipRange.IsClipped (thePickResult.Depth());
 }
 
diff --git a/src/StdSelect/StdSelect_BRepSelectionTool.cxx b/src/StdSelect/StdSelect_BRepSelectionTool.cxx
index ce3ecbf5be..c62dc54462 100644
--- a/src/StdSelect/StdSelect_BRepSelectionTool.cxx
+++ b/src/StdSelect/StdSelect_BRepSelectionTool.cxx
@@ -280,11 +280,11 @@ void StdSelect_BRepSelectionTool::ComputeSensitive (const TopoDS_Shape& theShape
           &TopoDS::Face (aSubfacesMap.FindKey (2))
         };
 
-        TopLoc_Location aLocSurf;
+        TopLoc_Location aLocSurf[2];
         const Handle(Geom_Surface)* aSurfaces[2] =
         {
-          &BRep_Tool::Surface (*aFaces[0], aLocSurf),
-          &BRep_Tool::Surface (*aFaces[1], aLocSurf)
+          &BRep_Tool::Surface (*aFaces[0], aLocSurf[0]),
+          &BRep_Tool::Surface (*aFaces[1], aLocSurf[1])
         };
 
         Standard_Integer aConIndex = 0;
@@ -308,7 +308,7 @@ void StdSelect_BRepSelectionTool::ComputeSensitive (const TopoDS_Shape& theShape
           const Standard_Real aRad1 = aCone.RefRadius();
           const Standard_Real aHeight = (aRad1 != 0.0)
                                        ? aRad1 / Abs (Tan (aCone.SemiAngle()))
-                                       : aCone.Location().Distance (aGeomPln->Location());
+                                       : aCone.Location().Distance (aGeomPln->Location().Transformed (aLocSurf[aConIndex == 0 ? 1 : 0]));
           const Standard_Real aRad2 = (aRad1 != 0.0) ? 0.0 : Tan (aCone.SemiAngle()) * aHeight;
           gp_Trsf aTrsf;
           aTrsf.SetTransformation (aCone.Position(), gp_Ax3());
@@ -326,18 +326,19 @@ void StdSelect_BRepSelectionTool::ComputeSensitive (const TopoDS_Shape& theShape
           &TopoDS::Face (aSubfacesMap.FindKey (3))
         };
 
-        TopLoc_Location aLocSurf;
+        TopLoc_Location aLocSurf[3];
         const Handle(Geom_Surface)* aSurfaces[3] =
         {
-          &BRep_Tool::Surface (*aFaces[0], aLocSurf),
-          &BRep_Tool::Surface (*aFaces[1], aLocSurf),
-          &BRep_Tool::Surface (*aFaces[2], aLocSurf)
+          &BRep_Tool::Surface (*aFaces[0], aLocSurf[0]),
+          &BRep_Tool::Surface (*aFaces[1], aLocSurf[1]),
+          &BRep_Tool::Surface (*aFaces[2], aLocSurf[2])
         };
 
         Standard_Integer aConIndex = -1, aNbPlanes = 0;
         Handle(Geom_ConicalSurface) aGeomCone;
         Handle(Geom_CylindricalSurface) aGeomCyl;
         Handle(Geom_Plane) aGeomPlanes[2];
+        const TopLoc_Location* aGeomPlanesLoc[2];
         for (Standard_Integer aSurfIter = 0; aSurfIter < 3; ++aSurfIter)
         {
           const Handle(Geom_Surface)& aSurf = *aSurfaces[aSurfIter];
@@ -361,6 +362,7 @@ void StdSelect_BRepSelectionTool::ComputeSensitive (const TopoDS_Shape& theShape
             aGeomPlanes[aNbPlanes] = Handle(Geom_Plane)::DownCast (aSurf);
             if (!aGeomPlanes[aNbPlanes].IsNull())
             {
+              aGeomPlanesLoc[aNbPlanes] = &aLocSurf[aSurfIter];
               ++aNbPlanes;
             }
           }
@@ -375,7 +377,8 @@ void StdSelect_BRepSelectionTool::ComputeSensitive (const TopoDS_Shape& theShape
           {
             const gp_Cone aCone = BRepAdaptor_Surface (*aFaces[aConIndex]).Cone();
             const Standard_Real aRad1 = aCone.RefRadius();
-            const Standard_Real aHeight = aGeomPlanes[0]->Location().Distance (aGeomPlanes[1]->Location());
+            const Standard_Real aHeight = aGeomPlanes[0]->Location().Transformed (*aGeomPlanesLoc[0])
+                               .Distance (aGeomPlanes[1]->Location().Transformed (*aGeomPlanesLoc[1]));
             gp_Trsf aTrsf;
             aTrsf.SetTransformation (aCone.Position(), gp_Ax3());
             const Standard_Real aTriangleHeight = (aCone.SemiAngle() > 0.0)
@@ -398,7 +401,8 @@ void StdSelect_BRepSelectionTool::ComputeSensitive (const TopoDS_Shape& theShape
           {
             const gp_Cylinder aCyl = BRepAdaptor_Surface (*aFaces[aConIndex]).Cylinder();
             const Standard_Real aRad = aCyl.Radius();
-            const Standard_Real aHeight = aGeomPlanes[0]->Location().Distance (aGeomPlanes[1]->Location());
+            const Standard_Real aHeight = aGeomPlanes[0]->Location().Transformed (*aGeomPlanesLoc[0])
+                               .Distance (aGeomPlanes[1]->Location().Transformed (*aGeomPlanesLoc[1]));
             gp_Trsf aTrsf;
             aTrsf.SetTransformation (aCyl.Position(), gp_Ax3());
             Handle(Select3D_SensitiveCylinder) aSensSCyl = new Select3D_SensitiveCylinder (theOwner, aRad, aRad, aHeight, aTrsf);
@@ -410,7 +414,7 @@ void StdSelect_BRepSelectionTool::ComputeSensitive (const TopoDS_Shape& theShape
 
       for (Standard_Integer aShIndex = 1; aShIndex <= aSubfacesMap.Extent(); ++aShIndex)
       {
-        ComputeSensitive (aSubfacesMap (aShIndex), theOwner,
+        ComputeSensitive (aSubfacesMap.FindKey (aShIndex), theOwner,
                           theSelection,
                           theDeflection, theDeviationAngle, theNbPOnEdge, theMaxParam, isAutoTriangulation);
       }
diff --git a/tests/vselect/cone_cylinder/begin b/tests/vselect/cone_cylinder/begin
deleted file mode 100644
index 26ce00044f..0000000000
--- a/tests/vselect/cone_cylinder/begin
+++ /dev/null
@@ -1,2 +0,0 @@
-vinit View1 -height 400 -width 600
-set subgroup "cone_cylinder"
diff --git a/tests/vselect/cone_cylinder/check_depth b/tests/vselect/cone_cylinder/check_depth
index f4ba540ad1..d3d8df71f3 100644
--- a/tests/vselect/cone_cylinder/check_depth
+++ b/tests/vselect/cone_cylinder/check_depth
@@ -3,6 +3,9 @@ puts "0032281: Visualization - add Select3D_SensitiveCylinder"
 puts "Tests depth value returned by Select3D_SensitiveCylinder"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 pcylinder cyl 10 20
 vdisplay cyl -dispmode 1
 vfit
diff --git a/tests/vselect/cone_cylinder/detecting b/tests/vselect/cone_cylinder/detecting
index 0608ca670c..8372576033 100644
--- a/tests/vselect/cone_cylinder/detecting
+++ b/tests/vselect/cone_cylinder/detecting
@@ -3,6 +3,9 @@ puts "0032281: Visualization - add Select3D_SensitiveCylinder"
 puts "Tests detecting Select3D_SensitiveCylinder"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 pcylinder cyl 10 20
 vdisplay cyl -dispmode 1
 vfit
diff --git a/tests/vselect/cone_cylinder/generate_images b/tests/vselect/cone_cylinder/generate_images
index 5bc5d10b1d..787fb07c6e 100644
--- a/tests/vselect/cone_cylinder/generate_images
+++ b/tests/vselect/cone_cylinder/generate_images
@@ -3,6 +3,9 @@ puts "0032281: Visualization - add Select3D_SensitiveCylinder"
 puts "Generating images based on detection of Select3D_SensitiveCylinder"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 pcylinder cyl 10 20
 vdisplay cyl -dispmode 1
 vfit
diff --git a/tests/vselect/cone_cylinder/polygon_selection b/tests/vselect/cone_cylinder/polygon_selection
index 1f5ae6a65d..56e26fdbbf 100644
--- a/tests/vselect/cone_cylinder/polygon_selection
+++ b/tests/vselect/cone_cylinder/polygon_selection
@@ -3,6 +3,9 @@ puts "0032281: Visualization - add Select3D_SensitiveCylinder"
 puts "Tests polygon selection of Select3D_SensitiveCylinder"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 pcylinder c1 10 20
 pcone c2 10 0 20
 pcone c3 10 5 10
diff --git a/tests/vselect/cone_cylinder/rectangle_selection b/tests/vselect/cone_cylinder/rectangle_selection
index 6fa39a7877..3667a81d4f 100644
--- a/tests/vselect/cone_cylinder/rectangle_selection
+++ b/tests/vselect/cone_cylinder/rectangle_selection
@@ -3,6 +3,9 @@ puts "0032281: Visualization - add Select3D_SensitiveCylinder"
 puts "Tests rectangular selection of Select3D_SensitiveCylinder"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 pcylinder c1 10 20
 pcone c2 10 0 20
 pcone c3 10 5 10
diff --git a/tests/vselect/cone_cylinder/single_click_selection_cone b/tests/vselect/cone_cylinder/single_click_selection_cone
index 9dc996baed..bd30de6825 100644
--- a/tests/vselect/cone_cylinder/single_click_selection_cone
+++ b/tests/vselect/cone_cylinder/single_click_selection_cone
@@ -3,6 +3,9 @@ puts "0032281: Visualization - add Select3D_SensitiveCylinder"
 puts "Tests selection of Select3D_SensitiveCylinder"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 pcone cone 10 0 20
 vdisplay cone -dispmode 1
 vfit
diff --git a/tests/vselect/cone_cylinder/single_click_selection_cylinder b/tests/vselect/cone_cylinder/single_click_selection_cylinder
index 15148b8a30..f391802dad 100644
--- a/tests/vselect/cone_cylinder/single_click_selection_cylinder
+++ b/tests/vselect/cone_cylinder/single_click_selection_cylinder
@@ -3,6 +3,9 @@ puts "0032281: Visualization - add Select3D_SensitiveCylinder"
 puts "Tests selection of Select3D_SensitiveCylinder"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 pcylinder cyl 10 20
 vdisplay cyl -dispmode 1
 vfit
diff --git a/tests/vselect/cone_cylinder/single_click_selection_trunc_cone b/tests/vselect/cone_cylinder/single_click_selection_trunc_cone
index 315910e8b1..6ce8decb5b 100644
--- a/tests/vselect/cone_cylinder/single_click_selection_trunc_cone
+++ b/tests/vselect/cone_cylinder/single_click_selection_trunc_cone
@@ -3,6 +3,9 @@ puts "0032281: Visualization - add Select3D_SensitiveCylinder"
 puts "Tests selection of Select3D_SensitiveCylinder"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 pcone tr_cone 10 5 10
 vdisplay tr_cone -dispmode 1
 vfit
diff --git a/tests/vselect/cone_cylinder/trsf_cone b/tests/vselect/cone_cylinder/trsf_cone
new file mode 100644
index 0000000000..a87ecd58d4
--- /dev/null
+++ b/tests/vselect/cone_cylinder/trsf_cone
@@ -0,0 +1,40 @@
+puts "================================="
+puts "0032652: Visualization - Select3D_SensitiveCylinder returns wrong 3D point on transformed shape"
+puts "Check picking of transformed cone"
+puts "================================="
+
+pload MODELING VISUALIZATION
+pcone      c 10 5 10
+fscale     c 0 0 0 0.1
+trotate    c 0 0 0 1 1 0 25
+ttranslate c 2500 3500 1000
+
+vinit View1
+
+# check Select3D_SensitiveTriangulation
+vclear
+vaxo
+compound {*}[explode c Sh] cc
+vdisplay -dispmode 1 cc
+vfit
+vselaxis 2500 3498 1001 0 1 0 -display a -showNormal
+set aPntTris [vmoveto 200 200]
+vpoint pp {*}$aPntTris
+checkpoint aPntTris_p $aPntTris {2500.42 3499.54 1000.81} 0.1
+if { ![string match "*Select3D_SensitiveTriangulation*" [vstate -entities]] } { puts "Error: triangulation should be detected" }
+vfit
+vdump $imagedir/${casename}_prs_tris.png
+vseldump $imagedir/${casename}_selnorm_tris.png -type surfNormal
+
+# check Select3D_SensitiveCylinder
+vclear
+vdisplay -dispmode 1 c
+vfit
+vselaxis 2500 3498 1001 0 1 0 -display a -showNormal
+set aPntCone [vmoveto 200 200]
+vpoint pp {*}$aPntCone
+checkpoint aPntCone_p $aPntCone {2500.42 3499.54 1000.81} 0.1
+if { ![string match "*Select3D_SensitiveCylinder*" [vstate -entities]] } { puts "Error: cylinder should be detected" }
+vfit
+vdump $imagedir/${casename}_prs_cyl.png
+vseldump $imagedir/${casename}_selnorm_cyl.png -type surfNormal
diff --git a/tests/vselect/cone_cylinder/trsf_cyl b/tests/vselect/cone_cylinder/trsf_cyl
new file mode 100644
index 0000000000..6711eb2609
--- /dev/null
+++ b/tests/vselect/cone_cylinder/trsf_cyl
@@ -0,0 +1,40 @@
+puts "================================="
+puts "0032652: Visualization - Select3D_SensitiveCylinder returns wrong 3D point on transformed shape"
+puts "Check picking of transformed cylinder"
+puts "================================="
+
+pload MODELING VISUALIZATION
+pcylinder  c 10 20
+fscale     c 0 0 0 0.1
+trotate    c 0 0 0 1 1 0 25
+ttranslate c 2500 3500 1000
+
+vinit View1
+
+# check Select3D_SensitiveTriangulation
+vclear
+vaxo
+compound {*}[explode c Sh] cc
+vdisplay -dispmode 1 cc
+vfit
+vselaxis 2500 3498 1001 0 1 0 -display a -showNormal
+set aPntTris [vmoveto 200 200]
+vpoint pp {*}$aPntTris
+checkpoint aPntTris_p $aPntTris {2500.9 3499.0 1001.6} 0.1
+if { ![string match "*Select3D_SensitiveTriangulation*" [vstate -entities]] } { puts "Error: triangulation should be detected" }
+vfit
+vdump $imagedir/${casename}_prs_tris.png
+vseldump $imagedir/${casename}_selnorm_tris.png -type surfNormal
+
+# check Select3D_SensitiveCylinder
+vclear
+vdisplay -dispmode 1 c
+vfit
+vselaxis 2500 3498 1001 0 1 0 -display a -showNormal
+set aPntCyl [vmoveto 200 200]
+vpoint pp {*}$aPntCyl
+checkpoint aPntCyl_p $aPntCyl {2500.9 3499.0 1001.6} 0.1
+if { ![string match "*Select3D_SensitiveCylinder*" [vstate -entities]] } { puts "Error: cylinder should be detected" }
+vfit
+vdump $imagedir/${casename}_prs_cyl.png
+vseldump $imagedir/${casename}_selnorm_cyl.png -type surfNormal
diff --git a/tests/vselect/sphere/begin b/tests/vselect/sphere/begin
deleted file mode 100644
index 0442e42a99..0000000000
--- a/tests/vselect/sphere/begin
+++ /dev/null
@@ -1,2 +0,0 @@
-vinit View1 -height 400 -width 600
-set subgroup "sphere"
diff --git a/tests/vselect/sphere/check_depth b/tests/vselect/sphere/check_depth
index 6d38a5b922..4a4c0a38d3 100644
--- a/tests/vselect/sphere/check_depth
+++ b/tests/vselect/sphere/check_depth
@@ -3,6 +3,9 @@ puts "0032182: Visualization - add Select3D_SensitiveSphere"
 puts "Tests depth value returned by Select3D_SenstiveSphere"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 psphere s 1
 vdisplay -dispMode 1 s
 vfit
diff --git a/tests/vselect/sphere/detecting b/tests/vselect/sphere/detecting
index a42120b842..885b94734d 100644
--- a/tests/vselect/sphere/detecting
+++ b/tests/vselect/sphere/detecting
@@ -3,6 +3,9 @@ puts "0032182: Visualization - add Select3D_SensitiveSphere"
 puts "Tests detecting Select3D_SenstiveSphere"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 psphere s 1
 vdisplay -dispMode 1 s
 vfit
diff --git a/tests/vselect/sphere/generate_images b/tests/vselect/sphere/generate_images
index 929fbff633..407f7f09d6 100644
--- a/tests/vselect/sphere/generate_images
+++ b/tests/vselect/sphere/generate_images
@@ -3,6 +3,9 @@ puts "000032366: Visualization, SelectMgr_ViewerSelector3d::ToPixMap() - add opt
 puts "Generating images based on detection of Select3D_SenstiveSphere"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 psphere s 1
 vdisplay -dispMode 1 s
 vfit
diff --git a/tests/vselect/sphere/polygon_selection b/tests/vselect/sphere/polygon_selection
index c1cc47fe1c..733e3ce541 100644
--- a/tests/vselect/sphere/polygon_selection
+++ b/tests/vselect/sphere/polygon_selection
@@ -3,6 +3,9 @@ puts "0032182: Visualization - add Select3D_SensitiveSphere"
 puts "Tests polygon selection of Select3D_SenstiveSphere"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 psphere s1 1
 psphere s2 1
 psphere s3 1
diff --git a/tests/vselect/sphere/rectangle_selection b/tests/vselect/sphere/rectangle_selection
index 87d7555d4e..f62b221edf 100644
--- a/tests/vselect/sphere/rectangle_selection
+++ b/tests/vselect/sphere/rectangle_selection
@@ -3,6 +3,9 @@ puts "0032182: Visualization - add Select3D_SensitiveSphere"
 puts "Tests rectangular selection of Select3D_SenstiveSphere"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 psphere s1 1
 psphere s2 1
 psphere s3 1
diff --git a/tests/vselect/sphere/single_click_selection b/tests/vselect/sphere/single_click_selection
index d65469b7a1..cc216ccfb6 100644
--- a/tests/vselect/sphere/single_click_selection
+++ b/tests/vselect/sphere/single_click_selection
@@ -3,6 +3,9 @@ puts "0032182: Visualization - add Select3D_SensitiveSphere"
 puts "Tests selection of Select3D_SenstiveSphere"
 puts "================================="
 
+pload MODELING VISUALIZATION
+vinit View1 -height 400 -width 600
+
 psphere s 1
 vdisplay -dispMode 1 s
 vfit
diff --git a/tests/vselect/sphere/trsf b/tests/vselect/sphere/trsf
new file mode 100644
index 0000000000..ceefc1fd79
--- /dev/null
+++ b/tests/vselect/sphere/trsf
@@ -0,0 +1,43 @@
+puts "================================="
+puts "0032652: Visualization - Select3D_SensitiveCylinder returns wrong 3D point on transformed shape"
+puts "Check picking of transformed sphere"
+puts "================================="
+
+pload MODELING VISUALIZATION
+psphere    s 10
+fscale     s 0 0 0 0.1
+trotate    s 0 0 0 1 1 0 25
+ttranslate s 2500 3500 1000
+
+vinit View1
+vlight headlight -head 0
+
+# check Select3D_SensitiveTriangulation
+vclear
+vaxo
+tcopy s ss
+incmesh ss 1.0
+tclean  ss -geom
+vdisplay -dispmode 1 ss
+vfit
+vselaxis 2500 3498 1000 0 1 0 -display a -showNormal
+set aPntTris [vmoveto 200 200]
+vpoint pp {*}$aPntTris
+checkpoint aPntTris_p $aPntTris {2500.54 3499.41 1000.6} 0.1
+if { ![string match "*Select3D_SensitiveTriangulation*" [vstate -entities]] } { puts "Error: triangulation should be detected" }
+vfit
+vdump $imagedir/${casename}_prs_tris.png
+vseldump $imagedir/${casename}_selnorm_tris.png -type surfNormal
+
+# check Select3D_SensitiveSphere
+vclear
+vdisplay -dispmode 1 s
+vfit
+vselaxis 2500 3498 1000 0 1 0 -display a -showNormal
+set aPntSph [vmoveto 200 200]
+vpoint pp {*}$aPntSph
+checkpoint aPntSph_p $aPntSph {2500.54 3499.41 1000.6} 0.1
+if { ![string match "*Select3D_SensitiveSphere*" [vstate -entities]] } { puts "Error: sphere should be detected" }
+vfit
+vdump $imagedir/${casename}_prs_sph.png
+vseldump $imagedir/${casename}_selnorm_sph.png -type surfNormal