Salome HOME
8a0e17cbf9a29686ca1c9c3e760c4ffda7afec09
[modules/gui.git] / src / SVTK / SVTK_AreaPicker.h
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME VTKViewer : build VTK viewer into Salome desktop
24 //  File   : SVTK_AreaPicker.h
25 //  Author : 
26 //  Module : SALOME
27 //
28 #ifndef __SVTK_AreaPicker_h
29 #define __SVTK_AreaPicker_h
30
31 #include "SVTK.h"
32 #include "VTKViewer.h"
33
34 #include <map>
35 #include <vector>
36
37 #include <vtkAbstractPropPicker.h>
38 #include <vtkDataSet.h>
39 #include <QVector>
40 #include <QPoint>
41
42 class vtkRenderer;
43
44 #ifdef WIN32
45 #pragma warning ( disable:4251 )
46 #endif
47
48 /*! \class vtkAbstractPropPicker
49  * \brief For more information see <a href="http://www.vtk.org/">VTK documentation
50  */
51 /*! \class SVTK_AreaPicker
52  * \brief Rectangular picker class.
53  */
54 class SVTK_EXPORT SVTK_AreaPicker : public vtkAbstractPropPicker
55 {
56  public:
57
58   enum SelectionMode { RectangleMode, PolygonMode };
59
60   static
61   SVTK_AreaPicker *New();
62
63   vtkTypeMacro(SVTK_AreaPicker,vtkAbstractPropPicker)
64   
65   /*! 
66     Specify tolerance for performing pick operation. Tolerance is specified
67     as fraction of rendering window size. (Rendering window size is measured
68     across diagonal.)
69   */
70   vtkSetMacro(Tolerance,double);
71   vtkGetMacro(Tolerance,double);
72
73   //! Use these methods to pick points or points and cells
74   vtkSetMacro(PickPoints,int);
75   vtkGetMacro(PickPoints,int);
76   vtkBooleanMacro(PickPoints,int);
77
78   int
79   Pick( QVector<QPoint>& thePoints,
80         vtkRenderer *theRenderer,
81         SelectionMode theMode );
82
83   int
84   Pick( double theSelectionX,
85         double theSelectionY,
86         double theSelectionX2,
87         double theSelectionY2,
88         vtkRenderer *theRenderer,
89         SelectionMode theMode );
90
91   static bool
92   isPointInPolygon( const QPoint& thePoint,const QVector<QPoint>& thePolygon );
93
94   typedef std::vector<vtkIdType> TVectorIds;
95   typedef std::map<vtkActor*,TVectorIds> TVectorIdsMap;
96
97   const TVectorIdsMap& 
98   GetPointIdsMap() const;
99
100   const TVectorIdsMap& 
101   GetCellIdsMap() const;
102
103  protected:
104   SVTK_AreaPicker();
105   ~SVTK_AreaPicker();
106
107   //! tolerance for computation (% of window)
108   double Tolerance;
109
110   //! use the following to control picking mode
111   int PickPoints;
112
113   //! coordinates of bounding box of selection
114   int mySelection[4];
115
116   TVectorIdsMap myPointIdsMap;
117   TVectorIdsMap myCellIdsMap;
118
119  private:
120   virtual 
121   int
122   Pick(double, 
123        double, 
124        double, 
125        vtkRenderer*);
126
127   void
128   SelectVisiblePoints( QVector<QPoint>& thePoints,
129                        vtkRenderer *theRenderer,
130                        vtkDataSet *theInput,
131                        SVTK_AreaPicker::TVectorIds& theVisibleIds,
132                        SVTK_AreaPicker::TVectorIds& theInVisibleIds,
133                        double theTolerance,
134                        SelectionMode theMode );
135   void
136   SelectVisibleCells( QVector<QPoint>& thePoints,
137                       vtkRenderer *theRenderer,
138                       vtkDataSet *theInput,
139                       SVTK_AreaPicker::TVectorIds& theVectorIds,
140                       double theTolerance,
141                       SelectionMode theMode );
142 };
143
144 #ifdef WIN32
145 #pragma warning ( default:4251 )
146 #endif
147
148 #endif
149
150