From 114e7a902217ad12c8a8033b6d8e0d1db964c323 Mon Sep 17 00:00:00 2001 From: mkrylova Date: Fri, 14 May 2021 12:58:43 +0300 Subject: [PATCH] 0032366: Visualization, SelectMgr_ViewerSelector3d::ToPixMap() - add option dumping surface normals - extended functionality to dump surface normals - added new option to vseldump command - added tests --- .../SelectMgr_SelectionImageFiller.cxx | 35 ++++++++++++ .../StdSelect_TypeOfSelectionImage.hxx | 3 +- src/ViewerTest/ViewerTest_ViewerCommands.cxx | 9 ++- tests/vselect/grids.list | 1 + tests/vselect/sphere/begin | 2 + tests/vselect/sphere/generate_images | 13 +++++ tests/vselect/sphere/rectangle_selection | 56 +++++++++++++++++++ tests/vselect/sphere/single_click_selection | 22 ++++++++ 8 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 tests/vselect/sphere/begin create mode 100644 tests/vselect/sphere/generate_images create mode 100644 tests/vselect/sphere/rectangle_selection create mode 100644 tests/vselect/sphere/single_click_selection diff --git a/src/SelectMgr/SelectMgr_SelectionImageFiller.cxx b/src/SelectMgr/SelectMgr_SelectionImageFiller.cxx index 2f4db469e8..9093884dee 100644 --- a/src/SelectMgr/SelectMgr_SelectionImageFiller.cxx +++ b/src/SelectMgr/SelectMgr_SelectionImageFiller.cxx @@ -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)(); } diff --git a/src/StdSelect/StdSelect_TypeOfSelectionImage.hxx b/src/StdSelect/StdSelect_TypeOfSelectionImage.hxx index d071e396b8..52c64307d9 100644 --- a/src/StdSelect/StdSelect_TypeOfSelectionImage.hxx +++ b/src/StdSelect/StdSelect_TypeOfSelectionImage.hxx @@ -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 diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index f9d99c16de..82160b8bf9 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -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", diff --git a/tests/vselect/grids.list b/tests/vselect/grids.list index 31a9dfa0e2..a0ebf3c690 100644 --- a/tests/vselect/grids.list +++ b/tests/vselect/grids.list @@ -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 index 0000000000..0442e42a99 --- /dev/null +++ b/tests/vselect/sphere/begin @@ -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 index 0000000000..929fbff633 --- /dev/null +++ b/tests/vselect/sphere/generate_images @@ -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 index 0000000000..87d7555d4e --- /dev/null +++ b/tests/vselect/sphere/rectangle_selection @@ -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 index 0000000000..d65469b7a1 --- /dev/null +++ b/tests/vselect/sphere/single_click_selection @@ -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" }