MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CuttingSurface.hpp
1 #ifndef CUTTINGSURFACE_HPP
2 #define CUTTINGSURFACE_HPP
3 
4 #include <Config.hpp>
5 
6 #include <Geometry.hpp>
7 #include <MGXViewer/qglviewer.h>
8 
9 namespace mgx {
10 
11 namespace process {
12 class SetupProcess;
13 } // namespace process
14 
15 typedef util::Vector<2, int> Point2i;
16 typedef util::Vector<3, float> Point3f;
17 
18 class mgx_EXPORT CuttingSurface : public QObject {
19  Q_OBJECT
20  friend class process::SetupProcess;
21 
22 public:
24  ~CuttingSurface();
25 
26  enum Mode { PLANE, THREE_AXIS, BEZIER };
27 
28  bool threeAxis() const {
29  return _mode == THREE_AXIS;
30  }
31  bool plane() const {
32  return _mode == PLANE;
33  }
34  bool bezier() const {
35  return _mode == BEZIER;
36  }
37  Mode mode() const {
38  return _mode;
39  }
40  void setMode(Mode m)
41  {
42  if(m != _mode) {
43  _mode = m;
44  hasChanged();
45  }
46  }
47 
48  bool drawGrid() const {
49  return _drawGrid;
50  }
51  void showGrid()
52  {
53  if(!_drawGrid) {
54  _drawGrid = true;
55  hasChanged();
56  }
57  }
58  void hideGrid()
59  {
60  if(_drawGrid) {
61  _drawGrid = false;
62  hasChanged();
63  }
64  }
65 
66  void show()
67  {
68  if(!_draw) {
69  _draw = true;
70  hasChanged();
71  }
72  }
73  void hide()
74  {
75  if(_draw) {
76  _draw = false;
77  hasChanged();
78  }
79  }
80  bool isVisible() const {
81  return _draw;
82  }
83 
84  const Point3f& size() const {
85  return _size;
86  }
87  void setSize(const Point3f& s)
88  {
89  if(s != _size) {
90  _size = s;
91  hasChanged();
92  }
93  }
94 
95  const Point2i& surfSize() const {
96  return _surfSize;
97  }
98  void setSurfSize(const Point2i& s)
99  {
100  if(s != _surfSize) {
101  _surfSize = s;
102  hasChanged();
103  }
104  }
105 
106  uint bezPoints() const {
107  return _bezPoints;
108  }
109  void setBezPoints(uint n)
110  {
111  if(n != _bezPoints) {
112  _bezPoints = n;
113  hasChanged();
114  }
115  }
116 
117  void setBezierV(const std::vector<Point3f>& points)
118  {
119  if(points.size() == _bezierV.size()) {
120  _bezierV = points;
121  hasChanged();
122  }
123  }
124  const std::vector<Point3f>& bezierV() const {
125  return _bezierV;
126  }
127  std::vector<Point3f>& bezierV() {
128  return _bezierV;
129  }
130 
131  Point3f& bezierV(uint u, uint v) {
132  return _bezierV[idx(u, v)];
133  }
134  const Point3f& bezierV(uint u, uint v) const {
135  return _bezierV[idx(u, v)];
136  }
137 
138  // Get frame
139  qglviewer::ManipulatedFrame& frame() {
140  return _frame;
141  }
142  const qglviewer::ManipulatedFrame& frame() const {
143  return _frame;
144  }
145 
146  // Get cutting plane rectangle
147  void getSurfPoints(const qglviewer::Frame* stk_frame, std::vector<Point3f>& points, int& uSize, int& vSize);
148 
149  // Evaluate bezier
150  Point3f evalCoord(float u, float v) const;
151  Point3f evalNormal(float u, float v) const;
152 
153  void hasChanged() {
154  _changed = true;
155  }
156  bool changed() const {
157  return _changed;
158  }
159 
160  void initBez();
161 
162  uint idx(uint u, uint v) const {
163  return (u * _bezPoints + v);
164  }
165 
166  // Binomial cooef
167  int choose(int i, int j) const;
168 
169 protected:
170  void resetModified() {
171  _changed = false;
172  }
173 
174  Mode _mode;
175  bool _drawGrid;
176  Point3f _size;
177 
178  bool _draw;
179  std::vector<Point3f> _bezierV;
180  Point2i _surfSize;
181  uint _bezPoints;
182  std::vector<uint> _chooseV;
183 
184  bool _changed;
185 
186  // Clipping plane frame
188 };
189 } // namespace mgx
190 
191 #endif // CUTTINGSURFACE_HPP
Definition: CuttingSurface.hpp:18
Common definitions and utilities for all geometry algorithms This file is shared by cuda...