]> OCCT Git - occt.git/commitdiff
0032366: Visualization, SelectMgr_ViewerSelector3d::ToPixMap() - add option dumping...
authormkrylova <mkrylova@opencascade.com>
Fri, 14 May 2021 09:58:43 +0000 (12:58 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 21 May 2021 16:00:57 +0000 (19:00 +0300)
- extended functionality to dump surface normals
- added new option to vseldump command
- added tests

src/SelectMgr/SelectMgr_SelectionImageFiller.cxx
src/StdSelect/StdSelect_TypeOfSelectionImage.hxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/vselect/grids.list
tests/vselect/sphere/begin [new file with mode: 0644]
tests/vselect/sphere/generate_images [new file with mode: 0644]
tests/vselect/sphere/rectangle_selection [new file with mode: 0644]
tests/vselect/sphere/single_click_selection [new file with mode: 0644]

index 2f4db469e86a2a7637a96e7bc920833393fee73e..9093884dee3b19c6bf49b723cb24ea0664d326ac 100644 (file)
@@ -319,6 +319,37 @@ namespace
       myImage->SetPixelColor (theCol, theRow, aColor);
     }
   };
+
+  //! Help class for filling pixel with normal direction value.
+  class SurfaceNormalFiller : public SelectMgr_SelectionImageFiller
+  {
+  public:
+    SurfaceNormalFiller (Image_PixMap& thePixMap,
+                         SelectMgr_ViewerSelector* theSelector)
+    : SelectMgr_SelectionImageFiller (thePixMap, theSelector) {}
+
+    virtual void Fill (const Standard_Integer theCol,
+                       const Standard_Integer theRow,
+                       const Standard_Integer thePicked) Standard_OVERRIDE
+    {
+      if (thePicked <= 0
+       || thePicked > myMainSel->NbPicked())
+      {
+        myImage->SetPixelColor (theCol, theRow, Quantity_NOC_BLACK);
+      }
+      else
+      {
+        const Handle(Select3D_SensitiveEntity)& aPickedEntity = myMainSel->PickedEntity (thePicked);
+        SelectBasics_PickResult aPickResult;
+        aPickedEntity->Matches (myMainSel->GetManager(), aPickResult);
+        Graphic3d_Vec3 aNormal = aPickResult.SurfaceNormal();
+        aNormal.Normalize();
+        myImage->SetPixelColor (theCol, theRow, Quantity_ColorRGBA (aNormal.x() * 0.5f + 0.5f, 
+                                                                    aNormal.y() * 0.5f + 0.5f,
+                                                                    aNormal.z() * 0.5f + 0.5f, 1.0f));
+      }
+    }
+  };
 }
 
 // =======================================================================
@@ -356,6 +387,10 @@ Handle(SelectMgr_SelectionImageFiller) SelectMgr_SelectionImageFiller::CreateFil
     {
       return new GeneratedSelModeColorFiller (thePixMap, theSelector);
     }
+    case StdSelect_TypeOfSelectionImage_SurfaceNormal:
+    {
+      return new SurfaceNormalFiller (thePixMap, theSelector);
+    }
   }
   return Handle(SelectMgr_SelectionImageFiller)();
 }
index d071e396b8c8ca39b57a58989a9bec65cf4efa52..52c64307d987d250ec8d7080ee8d4a13f0cd7e6b 100644 (file)
@@ -24,7 +24,8 @@ enum StdSelect_TypeOfSelectionImage
   StdSelect_TypeOfSelectionImage_ColoredDetectedObject,   //!< color of detected object
   StdSelect_TypeOfSelectionImage_ColoredEntity,           //!< random color for each entity
   StdSelect_TypeOfSelectionImage_ColoredOwner,            //!< random color for each owner
-  StdSelect_TypeOfSelectionImage_ColoredSelectionMode     //!< color of selection mode
+  StdSelect_TypeOfSelectionImage_ColoredSelectionMode,    //!< color of selection mode
+  StdSelect_TypeOfSelectionImage_SurfaceNormal            //!< normal direction values
 };
 
 #endif
index f9d99c16de0b50226a8db3f84fa955eeb64703a0..82160b8bf9d59da87d103c2b23bdef02be9d17f5 100644 (file)
@@ -13550,6 +13550,12 @@ static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
       {
         aType = StdSelect_TypeOfSelectionImage_ColoredSelectionMode;
       }
+      else if (aValue == "surfnormal"
+            || aValue == "surfacenormal"
+            || aValue == "normal")
+      {
+        aType = StdSelect_TypeOfSelectionImage_SurfaceNormal;
+      }
     }
     else if (aParam == "-picked"
           || aParam == "-pickeddepth"
@@ -14946,7 +14952,8 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
                    "\n\t\t:   object      color of detected object"
                    "\n\t\t:   owner       color of detected owner"
                    "\n\t\t:   selMode     color of selection mode"
-                   "\n\t\t:   entity      color of etected entity",
+                   "\n\t\t:   entity      color of etected entity"
+                   "\n\t\t:   surfNormal  normal direction values",
                    __FILE__, VDumpSelectionImage, group);
 
   theCommands.Add ("vviewcube",
index 31a9dfa0e20234eb2124ca78bc1b730ae479f5a3..a0ebf3c69002093831a38fe6e670f390ea9adc22 100644 (file)
@@ -11,3 +11,4 @@
 011 vertex_wire
 012 wire
 013 wire_solid
+014 sphere
diff --git a/tests/vselect/sphere/begin b/tests/vselect/sphere/begin
new file mode 100644 (file)
index 0000000..0442e42
--- /dev/null
@@ -0,0 +1,2 @@
+vinit View1 -height 400 -width 600
+set subgroup "sphere"
diff --git a/tests/vselect/sphere/generate_images b/tests/vselect/sphere/generate_images
new file mode 100644 (file)
index 0000000..929fbff
--- /dev/null
@@ -0,0 +1,13 @@
+puts "================================="
+puts "000032366: Visualization, SelectMgr_ViewerSelector3d::ToPixMap() - add option dumping surface normals"
+puts "Generating images based on detection of Select3D_SenstiveSphere"
+puts "================================="
+
+psphere s 1
+vdisplay -dispMode 1 s
+vfit
+vseldump $imagedir/${casename}_selmode_0.png  -type surfNormal
+vselmode 1 1
+vseldump $imagedir/${casename}_selmode_1.png  -type surfNormal
+vselmode 4 1
+vseldump $imagedir/${casename}_selmode_4.png  -type surfNormal
diff --git a/tests/vselect/sphere/rectangle_selection b/tests/vselect/sphere/rectangle_selection
new file mode 100644 (file)
index 0000000..87d7555
--- /dev/null
@@ -0,0 +1,56 @@
+puts "================================="
+puts "0032182: Visualization - add Select3D_SensitiveSphere"
+puts "Tests rectangular selection of Select3D_SenstiveSphere"
+puts "================================="
+
+psphere s1 1
+psphere s2 1
+psphere s3 1
+psphere s4 1
+ttranslate s1 2 2 0
+ttranslate s2 2 -2 0
+ttranslate s3 -2 2 0
+ttranslate s4 -2 -2 0
+vdisplay -dispMode 1 s1 s2 s3 s4
+vfit
+vselect 15 15 585 385
+if { ![string match "*Selected*" [vstate s1]] ||
+     ![string match "*Selected*" [vstate s2]] ||
+     ![string match "*Selected*" [vstate s3]] ||
+     ![string match "*Selected*" [vstate s4]]} { puts "Error: all spheres should be selected" }
+vselect 15 15 585 385 -allowoverlap 1
+if { ![string match "*Selected*" [vstate s1]] ||
+     ![string match "*Selected*" [vstate s2]] ||
+     ![string match "*Selected*" [vstate s3]] ||
+     ![string match "*Selected*" [vstate s4]]} { puts "Error: all spheres should be selected" }
+vselect 50 135 300 400
+if { [string match "*Selected*" [vstate s1]] ||
+     [string match "*Selected*" [vstate s2]] ||
+     [string match "*Selected*" [vstate s3]] ||
+     ![string match "*Selected*" [vstate s4]]} { puts "Error: only sphere s4 should be selected" }
+vselect 0 0 300 400 -allowoverlap 1
+if { [string match "*Selected*" [vstate s1]] ||
+     ![string match "*Selected*" [vstate s2]] ||
+     ![string match "*Selected*" [vstate s3]] ||
+     ![string match "*Selected*" [vstate s4]]} { puts "Error: spheres s2, s3 and s4 should be selected" }
+vright
+vselect 80 100 300 300
+if { [string match "*Selected*" [vstate s1]] ||
+     ![string match "*Selected*" [vstate s2]] ||
+     [string match "*Selected*" [vstate s3]] ||
+     ![string match "*Selected*" [vstate s4]]} { puts "Error: spheres s1 and s3 should be unselected" }
+vselect 380 170 451 241 -allowoverlap 1
+if { ![string match "*Selected*" [vstate s1]] ||
+     [string match "*Selected*" [vstate s2]] ||
+     ![string match "*Selected*" [vstate s3]] ||
+     [string match "*Selected*" [vstate s4]]} { puts "Error: spheres s1 and s3 should be selected" }
+vselect 0 400 600 200
+if { [string match "*Selected*" [vstate s1]] ||
+     [string match "*Selected*" [vstate s2]] ||
+     [string match "*Selected*" [vstate s3]] ||
+     [string match "*Selected*" [vstate s4]]} { puts "Error: all spheres should be unselected" }
+vselect 0 400 600 200 -allowoverlap 1
+if { ![string match "*Selected*" [vstate s1]] ||
+     ![string match "*Selected*" [vstate s2]] ||
+     ![string match "*Selected*" [vstate s3]] ||
+     ![string match "*Selected*" [vstate s4]]} { puts "Error: all spheres should be selected" }
diff --git a/tests/vselect/sphere/single_click_selection b/tests/vselect/sphere/single_click_selection
new file mode 100644 (file)
index 0000000..d65469b
--- /dev/null
@@ -0,0 +1,22 @@
+puts "================================="
+puts "0032182: Visualization - add Select3D_SensitiveSphere"
+puts "Tests selection of Select3D_SenstiveSphere"
+puts "================================="
+
+psphere s 1
+vdisplay -dispMode 1 s
+vfit
+vselect 300 200
+if { ![string match "*Selected*" [vstate s]] } { puts "Error: sphere should be selected" }
+vselect 195 110
+if { [string match "*Selected*" [vstate s]] } { puts "Error: sphere should be unselected" } 
+vselect 390 110
+if { [string match "*Selected*" [vstate s]] } { puts "Error: sphere should be unselected" }
+vselect 390 282
+if { [string match "*Selected*" [vstate s]] } { puts "Error: sphere should be unselected" }
+vselect 213 291
+if { [string match "*Selected*" [vstate s]] } { puts "Error: sphere should be unselected" }
+vselect 300 200 -allowoverlap 1
+if { ![string match "*Selected*" [vstate s]] } { puts "Error: sphere should be selected" }
+vselect 195 110 -allowoverlap 1
+if { [string match "*Selected*" [vstate s]] } { puts "Error: sphere should be unselected" }