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