From 609a350eb33e0323c187aa7d5b5614e7143d0feb Mon Sep 17 00:00:00 2001 From: ouv Date: Fri, 14 Oct 2005 07:31:09 +0000 Subject: [PATCH] Fixed bug GVIEW10216 : Incorrect selection by area --- src/SVTK/SALOME_Actor.cxx | 54 ++++++++++++++++++++++++------- src/SVTK/SVTK_InteractorStyle.cxx | 14 +------- src/SVTK/SVTK_InteractorStyle.h | 2 -- 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index afa56c42e..169342558 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -904,18 +904,16 @@ SALOME_Actor vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer(); // Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode; - float x1 = theSelectionEvent->myX; - float y1 = theSelectionEvent->myY; - float z1 = 0.0; - float x2 = theSelectionEvent->myLastX; - float y2 = theSelectionEvent->myLastY; - float z2 = 0.0; bool isShift = theSelectionEvent->myIsShift; + float x = theSelectionEvent->myX; + float y = theSelectionEvent->myY; + float z = 0.0; + if( !theSelectionEvent->myIsRectangle ) { switch(aSelectionMode){ case NodeSelection: { - myPointPicker->Pick( x1, y1, z1, aRenderer ); + myPointPicker->Pick( x, y, z, aRenderer ); int aVtkId = myPointPicker->GetPointId(); if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId, true ) ) { @@ -939,7 +937,7 @@ SALOME_Actor case FaceSelection: case VolumeSelection: { - myCellPicker->Pick( x1, y1, z1, aRenderer ); + myCellPicker->Pick( x, y, z, aRenderer ); int aVtkId = myCellPicker->GetCellId(); if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId ) ) { @@ -962,7 +960,7 @@ SALOME_Actor } case EdgeOfCellSelection: { - myCellPicker->Pick( x1, y1, z1, aRenderer ); + myCellPicker->Pick( x, y, z, aRenderer ); int aVtkId = myCellPicker->GetCellId(); if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId ) ) { @@ -997,6 +995,17 @@ SALOME_Actor break; } }else{ + float xLast = theSelectionEvent->myLastX; + float yLast = theSelectionEvent->myLastY; + float zLast = 0.0; + + float x1 = x < xLast ? x : xLast; + float y1 = y < yLast ? y : yLast; + float z1 = z < zLast ? z : zLast; + float x2 = x > xLast ? x : xLast; + float y2 = y > yLast ? y : yLast; + float z2 = z > zLast ? z : zLast; + switch(aSelectionMode){ case NodeSelection: { if( vtkDataSet* aDataSet = GetInput() ) { @@ -1010,7 +1019,7 @@ SALOME_Actor aRenderer->WorldToDisplay(); aRenderer->GetDisplayPoint( aPnt ); - if( aPnt[0] > x2 && aPnt[0] < x1 && aPnt[1] > y1 && aPnt[1] < y2 ) { + if( aPnt[0] > x1 && aPnt[0] < x2 && aPnt[1] > y1 && aPnt[1] < y2 ) { float aDisp[3]; aRenderer->SetWorldPoint( aPoint[0], aPoint[1], aPoint[2], 1.0 ); aRenderer->WorldToDisplay(); @@ -1043,7 +1052,28 @@ SALOME_Actor } case ActorSelection : { - theSelector->AddIObject( this ); + float aPnt[3]; + float* aBounds = GetBounds(); + + bool picked = true; + for( int i = 0; i <= 1; i++ ) { + for( int j = 2; j <= 3; j++ ) { + for( int k = 4; k <= 5; k++ ) { + aRenderer->SetWorldPoint( aBounds[ i ], aBounds[ j ], aBounds[ k ], 1.0 ); + aRenderer->WorldToDisplay(); + aRenderer->GetDisplayPoint( aPnt ); + + if( aPnt[0] < x1 || aPnt[0] > x2 || aPnt[1] < y1 || aPnt[1] > y2 ) { + picked = false; + break; + } + } + } + } + + if( picked ) + theSelector->AddIObject(this); + break; } case CellSelection: @@ -1052,7 +1082,7 @@ SALOME_Actor case VolumeSelection: { myCellRectPicker->SetTolerance( 0.001 ); - myCellRectPicker->Pick( x2, y2, z2, x1, y1, z1, aRenderer ); + myCellRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer ); VTKViewer_CellDataSet aCellList = myCellRectPicker->GetCellData( this ); TColStd_MapOfInteger anIndexes; diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 6e764a394..5781c9933 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -30,7 +30,6 @@ #include "SVTK_InteractorStyle.h" #include "VTKViewer_Utilities.h" -#include "VTKViewer_RectPicker.h" #include "SVTK_GenericRenderWindowInteractor.h" #include "SVTK_Selection.h" @@ -93,10 +92,8 @@ vtkStandardNewMacro(SVTK_InteractorStyle); SVTK_InteractorStyle ::SVTK_InteractorStyle(): mySelectionEvent(new SVTK_SelectionEvent()), - myRectPicker(VTKViewer_RectPicker::New()), myPicker(vtkPicker::New()) { - myRectPicker->Delete(); myPicker->Delete(); if(MYDEBUG) INFOS("SVTK_InteractorStyle() - "<ClearIObjects(); - myRectPicker->SetTolerance(0.001); - myRectPicker->Pick(aSelectionEvent->myLastX, - aSelectionEvent->myLastY, - 0.0, - aSelectionEvent->myX, - aSelectionEvent->myY, - 0.0, - GetCurrentRenderer()); - - vtkActorCollection* aListActors = myRectPicker->GetActors(); + vtkActorCollection* aListActors = GetCurrentRenderer()->GetActors(); aListActors->InitTraversal(); while(vtkActor* aActor = aListActors->GetNextActor()){ if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)){ diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index bfdd9d767..c292310fe 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -45,7 +45,6 @@ class vtkCell; class vtkPicker; -class VTKViewer_RectPicker; class SVTK_Selector; class SVTK_GenericRenderWindowInteractor; @@ -232,7 +231,6 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle PSelectionEvent mySelectionEvent; vtkSmartPointer myPicker; - vtkSmartPointer myRectPicker; }; #endif -- 2.39.2