]> SALOME platform Git repositories - modules/gui.git/blobdiff - src/SVTK/SVTK_RectPicker.cxx
Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/gui.git] / src / SVTK / SVTK_RectPicker.cxx
index fb5ced7f2d69f69b7189c30c00af63869f90ff85..77640da9dfb25848443216f8087ca546e09b232b 100644 (file)
@@ -1,30 +1,30 @@
-//  SALOME VTKViewer : build VTK viewer into Salome desktop
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
 //  File   : SVTK_RectPicker.cxx
 //  Author : 
 //  Module : SALOME
-
+//
 #include "SVTK_RectPicker.h"
 
 #include <set>
@@ -65,11 +65,11 @@ namespace
   inline
   int
   Check(float* theZPtr,
-       int theSelection[4],
-       vtkFloatingPointType theTolerance,
-       vtkFloatingPointType theDZ,
-       int theDX,
-       int theDY)
+        int theSelection[4],
+        vtkFloatingPointType theTolerance,
+        vtkFloatingPointType theDZ,
+        int theDX,
+        int theDY)
   {
     int aRet = 0;
     vtkFloatingPointType aZ = -1.0;
@@ -81,7 +81,7 @@ namespace
       // the selection window.
       aZ = GetZ(theZPtr,theSelection,theDX,theDY);
       if(aZ > theTolerance && aZ < 1.0 - theTolerance){
-       aRet = fabs(aZ - theDZ) <= theTolerance;
+        aRet = fabs(aZ - theDZ) <= theTolerance;
       }
     }
 
@@ -93,11 +93,11 @@ namespace
   //----------------------------------------------------------------------------
   void
   SelectVisiblePoints(int theSelection[4],
-                     vtkRenderer *theRenderer,
-                     vtkDataSet *theInput,
-                     SVTK_RectPicker::TVectorIds& theVisibleIds,
-                     SVTK_RectPicker::TVectorIds& theInVisibleIds,
-                     vtkFloatingPointType theTolerance)
+                      vtkRenderer *theRenderer,
+                      vtkDataSet *theInput,
+                      SVTK_RectPicker::TVectorIds& theVisibleIds,
+                      SVTK_RectPicker::TVectorIds& theInVisibleIds,
+                      vtkFloatingPointType theTolerance)
   {
     theVisibleIds.clear();
     theInVisibleIds.clear();
@@ -116,7 +116,7 @@ namespace
     // and handle the transformation ourselves.
     vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
     aMatrix->DeepCopy( theRenderer->GetActiveCamera()->
-                      GetCompositePerspectiveTransformMatrix( theRenderer->GetTiledAspectRatio(), 0, 1 ) );
+                       GetCompositeProjectionTransformMatrix( theRenderer->GetTiledAspectRatio(), 0, 1 ) );
 
     // We grab the z-buffer for the selection region all at once and probe the resulting array.
     float *aZPtr = theRenderer->GetRenderWindow()->
@@ -133,7 +133,7 @@ namespace
     for(int iY = theSelection[1]; iY <= theSelection[3];  iY++){
       //cout<<iY<<"\t";
       for(int iX = theSelection[0]; iX <= theSelection[2];  iX++){
-       //cout<<std::setprecision(4)<<GetZ(aZPtr,theSelection,iX,iY)<<"\t";
+        //cout<<std::setprecision(4)<<GetZ(aZPtr,theSelection,iX,iY)<<"\t";
       }
       //cout<<endl;
     }
@@ -146,10 +146,10 @@ namespace
       vtkFloatingPointType aView[4];
       aMatrix->MultiplyPoint(aX,aView);
       if(aView[3] == 0.0)
-       continue;
+        continue;
       theRenderer->SetViewPoint(aView[0]/aView[3], 
-                               aView[1]/aView[3],
-                               aView[2]/aView[3]);
+                                aView[1]/aView[3],
+                                aView[2]/aView[3]);
       theRenderer->ViewToDisplay();
 
       vtkFloatingPointType aDX[3];
@@ -159,52 +159,52 @@ namespace
       if(aDX[0] >= theSelection[0] && aDX[0] <= theSelection[2] &&
          aDX[1] >= theSelection[1] && aDX[1] <= theSelection[3])
       {
-       //cout<<"aPntId "<<aPntId<<"; aDX = {"<<aDX[0]<<", "<<aDX[1]<<", "<<aDX[2]<<"}\n";
-       int aDX0 = int(aDX[0]);
-       int aDX1 = int(aDX[1]);
-
-       int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aDX0,aDX1);
-       if(aRet > 0)
-         goto ADD_VISIBLE;
-       if(aRet < 0)
-         goto ADD_INVISIBLE;
-
-       static int aMaxRadius = 5;
-       for(int aRadius = 1; aRadius < aMaxRadius; aRadius++){
-         int aStartDX[2] = {aDX0 - aRadius, aDX1 - aRadius};
-         for(int i = 0; i <= aRadius; i++){
-           int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0]++,aStartDX[1]);
-           if(aRet > 0)
-             goto ADD_VISIBLE;
-           if(aRet < 0)
-             goto ADD_INVISIBLE;
-         }
-         for(int i = 0; i <= aRadius; i++){
-           int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0],aStartDX[1]++);
-           if(aRet > 0)
-             goto ADD_VISIBLE;
-           if(aRet < 0)
-             goto ADD_INVISIBLE;
-         }
-         for(int i = 0; i <= aRadius; i++){
-           int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0]--,aStartDX[1]);
-           if(aRet > 0)
-             goto ADD_VISIBLE;
-           if(aRet < 0)
-             goto ADD_INVISIBLE;
-         }
-         for(int i = 0; i <= aRadius; i++){
-           int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0],aStartDX[1]--);
-           if(aRet > 0)
-             goto ADD_VISIBLE;
-           if(aRet < 0)
-             goto ADD_INVISIBLE;
-         }
-       }
-       if(false)
-         ADD_VISIBLE : theVisibleIds.push_back(aPntId);
-       if(false)
-         ADD_INVISIBLE : theInVisibleIds.push_back(aPntId);
+        //cout<<"aPntId "<<aPntId<<"; aDX = {"<<aDX[0]<<", "<<aDX[1]<<", "<<aDX[2]<<"}\n";
+        int aDX0 = int(aDX[0]);
+        int aDX1 = int(aDX[1]);
+
+        int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aDX0,aDX1);
+        if(aRet > 0)
+          goto ADD_VISIBLE;
+        if(aRet < 0)
+          goto ADD_INVISIBLE;
+
+        static int aMaxRadius = 5;
+        for(int aRadius = 1; aRadius < aMaxRadius; aRadius++){
+          int aStartDX[2] = {aDX0 - aRadius, aDX1 - aRadius};
+          for(int i = 0; i <= aRadius; i++){
+            int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0]++,aStartDX[1]);
+            if(aRet > 0)
+              goto ADD_VISIBLE;
+            if(aRet < 0)
+              goto ADD_INVISIBLE;
+          }
+          for(int i = 0; i <= aRadius; i++){
+            int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0],aStartDX[1]++);
+            if(aRet > 0)
+              goto ADD_VISIBLE;
+            if(aRet < 0)
+              goto ADD_INVISIBLE;
+          }
+          for(int i = 0; i <= aRadius; i++){
+            int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0]--,aStartDX[1]);
+            if(aRet > 0)
+              goto ADD_VISIBLE;
+            if(aRet < 0)
+              goto ADD_INVISIBLE;
+          }
+          for(int i = 0; i <= aRadius; i++){
+            int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0],aStartDX[1]--);
+            if(aRet > 0)
+              goto ADD_VISIBLE;
+            if(aRet < 0)
+              goto ADD_INVISIBLE;
+          }
+        }
+        if(false)
+          ADD_VISIBLE : theVisibleIds.push_back(aPntId);
+        if(false)
+          ADD_INVISIBLE : theInVisibleIds.push_back(aPntId);
       }
     }//for all points
 
@@ -219,7 +219,7 @@ namespace
   inline
   void
   GetCenter(const vtkFloatingPointType theBounds[6],
-           vtkFloatingPointType theCenter[3])
+            vtkFloatingPointType theCenter[3])
   {
     theCenter[0] = (theBounds[1] + theBounds[0]) / 2.0;
     theCenter[1] = (theBounds[3] + theBounds[2]) / 2.0;
@@ -228,10 +228,10 @@ namespace
 
   void
   SelectVisibleCells(int theSelection[4],
-                    vtkRenderer *theRenderer,
-                    vtkDataSet *theInput,
-                    SVTK_RectPicker::TVectorIds& theVectorIds,
-                    vtkFloatingPointType theTolerance)
+                     vtkRenderer *theRenderer,
+                     vtkDataSet *theInput,
+                     SVTK_RectPicker::TVectorIds& theVectorIds,
+                     vtkFloatingPointType theTolerance)
   {
     theVectorIds.clear();
 
@@ -244,11 +244,11 @@ namespace
     SVTK_RectPicker::TVectorIds aVisiblePntIds;
     SVTK_RectPicker::TVectorIds anInVisiblePntIds;
     SelectVisiblePoints(theSelection,
-                       theRenderer,
-                       theInput,
-                       aVisiblePntIds,
-                       anInVisiblePntIds,
-                       theTolerance);
+                        theRenderer,
+                        theInput,
+                        aVisiblePntIds,
+                        anInVisiblePntIds,
+                        theTolerance);
 
     typedef std::set<vtkIdType> TIdsSet;
     TIdsSet aVisibleIds(aVisiblePntIds.begin(),aVisiblePntIds.end());
@@ -261,7 +261,7 @@ namespace
     // and handle the transformation ourselves.
     vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
     aMatrix->DeepCopy(theRenderer->GetActiveCamera()->
-                     GetCompositePerspectiveTransformMatrix(1,0,1));
+                      GetCompositeProjectionTransformMatrix( theRenderer->GetTiledAspectRatio(), 0, 1 ) );
 
     for(vtkIdType aCellId = 0; aCellId < aNumCells; aCellId++){
       vtkCell* aCell = theInput->GetCell(aCellId);
@@ -277,11 +277,11 @@ namespace
       aMatrix->MultiplyPoint(aX,aView);
 
       if(aView[3] == 0.0)
-       continue;
+        continue;
 
       theRenderer->SetViewPoint(aView[0]/aView[3], 
-                               aView[1]/aView[3],
-                               aView[2]/aView[3]);
+                                aView[1]/aView[3],
+                                aView[2]/aView[3]);
       theRenderer->ViewToDisplay();
 
       vtkFloatingPointType aDX[3];
@@ -292,19 +292,19 @@ namespace
          aDX[1] >= theSelection[1] && aDX[1] <= theSelection[3])
       {
 
-       //cout<<"aCellId = "<<aCellId<<": ";
-       vtkIdType aNumPts = aCell->GetNumberOfPoints();
-       bool anIsVisible = true;
-       for(vtkIdType anId = 0; anId < aNumPts; anId++){
-         vtkIdType aPntId = aCell->GetPointId(anId);
-         //cout<<aPntId<<"; ";
-         anIsVisible = aVisibleIds.find(aPntId) != aVisibleIds.end();
-         if(!anIsVisible)
-           break;
-       }
-       //cout<<"\t"<<anIsVisible<<"\n";
-       if(anIsVisible)
-         theVectorIds.push_back(aCellId);
+        //cout<<"aCellId = "<<aCellId<<": ";
+        vtkIdType aNumPts = aCell->GetNumberOfPoints();
+        bool anIsVisible = true;
+        for(vtkIdType anId = 0; anId < aNumPts; anId++){
+          vtkIdType aPntId = aCell->GetPointId(anId);
+          //cout<<aPntId<<"; ";
+          anIsVisible = aVisibleIds.find(aPntId) != aVisibleIds.end();
+          if(!anIsVisible)
+            break;
+        }
+        //cout<<"\t"<<anIsVisible<<"\n";
+        if(anIsVisible)
+          theVectorIds.push_back(aCellId);
       }
     }//for all parts
   }
@@ -312,10 +312,10 @@ namespace
   //----------------------------------------------------------------------------
   void
   CalculatePickPosition(vtkRenderer *theRenderer,
-                       vtkFloatingPointType theSelectionX, 
-                       vtkFloatingPointType theSelectionY, 
-                       vtkFloatingPointType theSelectionZ,
-                       vtkFloatingPointType thePickPosition[3])
+                        vtkFloatingPointType theSelectionX, 
+                        vtkFloatingPointType theSelectionY, 
+                        vtkFloatingPointType theSelectionZ,
+                        vtkFloatingPointType thePickPosition[3])
   {
     // Convert the selection point into world coordinates.
     //
@@ -324,7 +324,7 @@ namespace
     vtkFloatingPointType* aWorldCoords = theRenderer->GetWorldPoint();
     if ( aWorldCoords[3] != 0.0 ) {
       for (int i=0; i < 3; i++) {
-       thePickPosition[i] = aWorldCoords[i] / aWorldCoords[3];
+        thePickPosition[i] = aWorldCoords[i] / aWorldCoords[3];
       }
     }
   }
@@ -360,8 +360,8 @@ SVTK_RectPicker
        vtkRenderer *theRenderer)
 {
   return Pick(theSelection[0], theSelection[1], theSelection[2], 
-             theSelection2[0], theSelection2[1], theSelection2[2],
-             theRenderer);
+              theSelection2[0], theSelection2[1], theSelection2[2],
+              theRenderer);
 }
 
 int 
@@ -401,10 +401,10 @@ SVTK_RectPicker
   // Convert the selection point into world coordinates.
   //
   CalculatePickPosition(theRenderer,
-                       theSelectionX,
-                       theSelectionY,
-                       aSelectionZ,
-                       this->PickPosition);
+                        theSelectionX,
+                        theSelectionY,
+                        aSelectionZ,
+                        this->PickPosition);
 
   this->SelectionPoint2[0] = theSelectionX2;
   this->SelectionPoint2[1] = theSelectionY2;
@@ -413,10 +413,10 @@ SVTK_RectPicker
   // Convert the selection point into world coordinates.
   //
   CalculatePickPosition(theRenderer,
-                       theSelectionX2,
-                       theSelectionY2,
-                       aSelectionZ,
-                       this->PickPosition2);
+                        theSelectionX2,
+                        theSelectionY2,
+                        aSelectionZ,
+                        this->PickPosition2);
 
   // Invoke start pick method if defined
   this->InvokeEvent(vtkCommand::StartPickEvent,NULL);
@@ -425,7 +425,7 @@ SVTK_RectPicker
   if ( this->PickFromList ) 
     aProps = this->GetPickList();
   else 
-    aProps = theRenderer->GetProps();
+    aProps = theRenderer->GetViewProps();
 
   aProps->InitTraversal();
   while ( vtkProp* aProp = aProps->GetNextProp() ) {
@@ -434,44 +434,44 @@ SVTK_RectPicker
       vtkMapper *aMapper = NULL;
       bool anIsPickable = false;
       vtkActor* anActor = NULL;
-      vtkProp *aPropCandidate = aPath->GetLastNode()->GetProp();
+      vtkProp *aPropCandidate = aPath->GetLastNode()->GetViewProp();
       if ( aPropCandidate->GetPickable() && aPropCandidate->GetVisibility() ) {
         anIsPickable = true;
-       anActor = vtkActor::SafeDownCast(aPropCandidate);
-       if ( anActor ) {
+        anActor = vtkActor::SafeDownCast(aPropCandidate);
+        if ( anActor ) {
           aMapper = anActor->GetMapper();
           if ( anActor->GetProperty()->GetOpacity() <= 0.0 )
-           anIsPickable = false;
-       }
+            anIsPickable = false;
+        }
       }
       if ( anIsPickable  &&  aMapper && aMapper->GetInput()) {
-       int aSelectionPoint[4] = {int(theSelectionX),
-                                 int(theSelectionY),
-                                 int(theSelectionX2),
-                                 int(theSelectionY2)};
-       if ( this->PickPoints ) {
-         TVectorIds& aVisibleIds = myPointIdsMap[anActor];
-         TVectorIds anInVisibleIds;
-         SelectVisiblePoints(aSelectionPoint,
-                             theRenderer,
-                             aMapper->GetInput(),
-                             aVisibleIds,
-                             anInVisibleIds,
-                             this->Tolerance);
-         if ( aVisibleIds.empty() ) {
-           myPointIdsMap.erase(myPointIdsMap.find(anActor));
-         }
-       } else {
-         TVectorIds& aVectorIds = myCellIdsMap[anActor];
-         SelectVisibleCells(aSelectionPoint,
-                            theRenderer,
-                            aMapper->GetInput(),
-                            aVectorIds,
-                            this->Tolerance);
-         if ( aVectorIds.empty() ) {
-           myCellIdsMap.erase(myCellIdsMap.find(anActor));
-         }
-       }
+        int aSelectionPoint[4] = {int(theSelectionX),
+                                  int(theSelectionY),
+                                  int(theSelectionX2),
+                                  int(theSelectionY2)};
+        if ( this->PickPoints ) {
+          TVectorIds& aVisibleIds = myPointIdsMap[anActor];
+          TVectorIds anInVisibleIds;
+          SelectVisiblePoints(aSelectionPoint,
+                              theRenderer,
+                              aMapper->GetInput(),
+                              aVisibleIds,
+                              anInVisibleIds,
+                              this->Tolerance);
+          if ( aVisibleIds.empty() ) {
+            myPointIdsMap.erase(myPointIdsMap.find(anActor));
+          }
+        } else {
+          TVectorIds& aVectorIds = myCellIdsMap[anActor];
+          SelectVisibleCells(aSelectionPoint,
+                             theRenderer,
+                             aMapper->GetInput(),
+                             aVectorIds,
+                             this->Tolerance);
+          if ( aVectorIds.empty() ) {
+            myCellIdsMap.erase(myCellIdsMap.find(anActor));
+          }
+        }
       }
     }
   }
@@ -496,4 +496,3 @@ SVTK_RectPicker
 {
   return myCellIdsMap;
 }
-