fw4spl
fwVtkCellPicker.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 /*=========================================================================
8 
9  Program: Visualization Toolkit
10  Module: $RCSfile: fwVtkCellPicker.h,v $
11 
12  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
13  All rights reserved.
14  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notice for more information.
19 
20  =========================================================================*/
21 // .NAME fwVtkCellPicker - select a cell by shooting a ray into graphics window
22 // .SECTION Description
23 // fwVtkCellPicker is used to select a cell by shooting a ray into graphics
24 // window and intersecting with actor's defining geometry - specifically
25 // its cells. Beside returning coordinates, actor and mapper, fwVtkCellPicker
26 // returns the id of the closest cell within the tolerance along the pick
27 // ray, and the dataset that was picked.
28 // .SECTION See Also
29 // fwVtkPicker vtkPointPicker
30 
31 #ifndef __FWRENDERVTK_VTK_FWVTKCELLPICKER_HPP__
32 #define __FWRENDERVTK_VTK_FWVTKCELLPICKER_HPP__
33 
34 #include "fwRenderVTK/config.hpp"
35 #include "fwRenderVTK/vtk/fwVtkPicker.hpp"
36 
37 #include <fwMath/IntrasecTypes.hpp>
38 
39 #include <vector>
40 
41 class vtkGenericCell;
42 class vtkPolyData;
43 
44 class FWRENDERVTK_CLASS_API fwVtkCellPicker : public fwVtkPicker
45 {
46 public:
47  FWRENDERVTK_API static fwVtkCellPicker* New();
48  vtkTypeMacro(fwVtkCellPicker, fwVtkPicker);
49  void PrintSelf(ostream& os, vtkIndent indent) override;
50 
51  // Description:
52  // Get the id of the picked cell. If CellId = -1, nothing was picked.
53  vtkGetMacro(CellId, vtkIdType);
54 
55  // Description:
56  // Get the subId of the picked cell. If SubId = -1, nothing was picked.
57  vtkGetMacro(SubId, int);
58 
59  // Description:
60  // Get the parametric coordinates of the picked cell. Only valid if
61  // pick was made.
62  vtkGetVectorMacro(PCoords, double, 3);
63 
64  typedef std::vector< std::pair<int, fwVec3d> > PickedCellType;
65 
66  FWRENDERVTK_API PickedCellType GetPickedCellIds( double p1[3], double p2[3], vtkPolyData *polydata);
67 
68 protected:
70  ~fwVtkCellPicker();
71 
72  vtkIdType CellId; // picked cell
73  int SubId; // picked cell subId
74  double PCoords[3]; // picked cell parametric coordinates
75 
76  virtual double IntersectWithLine(double p1[3], double p2[3], double tol,
77  vtkAssemblyPath *path, vtkProp3D *p,
78  vtkAbstractMapper3D *m) override;
79  void Initialize() override;
80 
81 private:
82  vtkGenericCell* Cell; //used to accelerate picking
83 
84 private:
85  fwVtkCellPicker(const fwVtkCellPicker&); // Not implemented.
86  void operator=(const fwVtkCellPicker&); // Not implemented.
87 };
88 
89 #endif // __FWRENDERVTK_VTK_FWVTKCELLPICKER_HPP__