MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stack.hpp
1 #ifndef STACK_HPP
2 #define STACK_HPP
3 
4 #include <Config.hpp>
5 #include <GL.hpp>
6 
7 #include <Geometry.hpp>
8 #include <MGXViewer/qglviewer.h>
9 #include <Store.hpp>
10 
11 namespace mgx {
12 
13 namespace process {
14 class SetupProcess;
15 } // namespace process
16 
25 class mgx_EXPORT Stack {
26  friend class process::SetupProcess;
27 
28 public:
32  Stack(int id);
33 
37  Stack(const Stack& copy);
38 
42  ~Stack();
43 
49  int id() const {
50  return _id;
51  }
52 
58  void setId(int i) {
59  _id = i;
60  }
61 
67  int userId() const {
68  return _id + 1;
69  }
70 
74  const Store* main() const {
75  return _main;
76  }
80  Store* main() {
81  return _main;
82  }
88  void setMain(Store* m);
89 
93  const Store* work() const {
94  return _work;
95  }
99  Store* work() {
100  return _work;
101  }
107  void setWork(Store* w);
108 
112  const Store* currentStore() const {
113  return _current;
114  }
119  return _current;
120  }
121 
125  Point3u size() const {
126  return _size;
127  }
132  return BoundingBox3i(Point3i(), Point3i(size()));
133  }
134 
138  Point3f step() const
139  {
140  return multiply(_step, scale());
141  }
142  // Point3f step() const { return _step * scale(); }// old
146  size_t storeSize() const {
147  return size_t(_size.x()) * _size.y() * _size.z();
148  }
152  bool empty() const {
153  return _size == Point3u();
154  }
155 
159  Point3f scale() const {
160  return (_showScale ? _scale : Point3f(1.0, 1.0, 1.0));
161  }
162  // float scale() const { return (_showScale ? _scale : 1.0f); }
166  Point3f origin() const {
167  return multiply(scale(), _origin);
168  }
169  // Point3f origin() const { return scale()*_origin; }
173  void setScale(Point3f s) {
174  _scale = s;
175  }
176  // void setScale(float s) { _scale = s; }
180  void setOrigin(const Point3f& s);
181 
187  void setSize(const Point3u& s);
191  void setStep(const Point3f& s);
192 
196  bool showScale() const {
197  return _showScale;
198  }
202  void setShowScale(bool s) {
203  _showScale = s;
204  }
205 
209  bool tieScales() const {
210  return _tieScales;
211  }
215  void setTieScales(bool s) {
216  _tieScales = s;
217  }
218 
222  bool showTrans() const {
223  return _showTrans;
224  }
228  void setShowTrans(bool s) {
229  _showTrans = s;
230  }
231 
235  bool showBBox() const {
236  return _showBBox;
237  }
241  void setShowBBox(bool s) {
242  _showBBox = s;
243  }
244 
246  Matrix4f worldToImage() const;
247 
249  Matrix4f imageToWorld() const;
250 
252  Matrix4f worldToImageVector() const;
253 
255  Matrix4f imageToWorldVector() const;
256 
258  template <typename T> Point3f imageToWorld(const util::Vector<3, T>& img) const
259  {
260  return multiply(Point3f(img) + Point3f(.5f, .5f, .5f), step()) + origin();
261  }
262 
264  template <typename T> util::Vector<3, T> worldToImage(Point3f wrld) const
265  {
266  return util::Vector<3, T>((wrld - origin()) / step() - Point3f(.5f, .5f, .5f));
267  }
268 
270  template <typename T> Point3f imageToWorldVector(const util::Vector<3, T>& img) const
271  {
272  return multiply(Point3f(img), step());
273  }
274 
276  template <typename T> util::Vector<3, T> worldToImageVector(Point3f wrld) const
277  {
278  return util::Vector<3, T>(wrld / step());
279  }
280 
282  template <typename T> BoundingBox3f imageToWorld(const util::BoundingBox<3, T>& img) const
283  {
284  return BoundingBox3f(imageToWorld(img.pmin()), imageToWorld(img.pmax()));
285  }
286 
288  template <typename T> util::BoundingBox<3, T> worldToImage(const BoundingBox3f& wrld) const
289  {
290  return util::BoundingBox<3, T>(worldToImage<T>(wrld.pmin()), worldToImage<T>(wrld.pmax()));
291  }
292 
293  Point3f worldToImagef(const Point3f& a) const {
294  return worldToImage<float>(a);
295  }
296  Point3i worldToImagei(const Point3f& a) const {
297  return worldToImage<int>(a);
298  }
299  Point3u worldToImageu(const Point3f& a) const {
300  return worldToImage<uint>(a);
301  }
302 
303  BoundingBox3f worldToImagef(const BoundingBox3f& a) const {
304  return worldToImage<float>(a);
305  }
306  BoundingBox3i worldToImagei(const BoundingBox3f& a) const {
307  return worldToImage<int>(a);
308  }
309  BoundingBox3u worldToImageu(const BoundingBox3f& a) const {
310  return worldToImage<uint>(a);
311  }
312 
313  Point3f worldToImageVectorf(const Point3f& a) const {
314  return worldToImageVector<float>(a);
315  }
316  Point3i worldToImageVectori(const Point3f& a) const {
317  return worldToImageVector<int>(a);
318  }
319  Point3u worldToImageVectoru(const Point3f& a) const {
320  return worldToImageVector<uint>(a);
321  }
322 
329  {
330  return divide(p, scale()) * _texScale;
331  }
332 
336  Point3f worldSize() const {
337  return imageToWorldVector(_size);
338  }
339 
341  bool boundsOK(int x, int y, int z) const
342  {
343  if(x < 0 or y < 0 or z < 0 or x >= int(_size.x()) or y >= int(_size.y()) or z >= int(_size.z()))
344  return false;
345  else
346  return true;
347  }
348 
350  size_t offset(uint x, uint y, uint z) const {
351  return (size_t(z) * _size.y() + y) * _size.x() + x;
352  }
353 
357  size_t offset(Point3i ipos) const {
358  return (size_t(ipos.z()) * _size.y() + ipos.y()) * _size.x() + ipos.x();
359  }
360 
362  Point3u position(size_t offset) const
363  {
364  uint x = offset % _size.x();
365  offset = (offset - x) / _size.x();
366  uint y = offset % _size.y();
367  uint z = (offset - y) / _size.y();
368  return Point3u(x, y, z);
369  }
370 
374  void center();
375 
380  return _frame;
381  }
382 
387  return _frame;
388  }
389 
394  return _trans;
395  }
400  return _trans;
401  }
402 
410  return (_showTrans ? _trans : _frame);
411  }
412 
420  return (_showTrans ? _trans : _frame);
421  }
422 
426  int viewLabel() const {
427  return _CurrLabel;
428  }
432  void setLabel(int l)
433  {
434  changed_label = true;
435  _CurrLabel = l;
436  }
440  int nextLabel()
441  {
442  changed_label = true;
443  _CurrLabel++;
444  if(_CurrLabel > ((1 << 16) - 1))
445  _CurrLabel = 1;
446  return _CurrLabel;
447  }
451  bool labelChanged() const {
452  return changed_label;
453  }
454 
455  void setMainAsCurrent() {
456  _current = _main;
457  }
458  void setWorkAsCurrent() {
459  _current = _work;
460  }
461  void setNoneAsCurrent() {
462  _current = 0;
463  }
464 
465  void setCurrentStore(Store* store) {
466  _current = (store == _main or store == _work) ? store : 0;
467  }
468 
472  void reset();
473 
474 private:
475  void resetModified();
476  void updateSizes();
477  void resetCurrent();
478  Store* _main, *_work, *_current;
479  Point3f _scale;
480  // float _scale;
481  Point3f _origin;
482  float _texScale;
483  Point3u _size;
484  Point3f _step;
487  bool changed_frame, changed_trans, changed_label;
488  int _id;
489  int _CurrLabel;
490  bool _showScale, _showTrans, _showBBox, _tieScales;
491 };
492 } // namespace mgx
493 
494 #endif // STACK_HPP
int nextLabel()
Return the next label to be used and change it so successive calls return successive labels...
Definition: Stack.hpp:440
Store * work()
Access the work store.
Definition: Stack.hpp:99
const qglviewer::ManipulatedFrame & frame() const
Returns the manipulated frame.
Definition: Stack.hpp:379
Store * currentStore()
Returns the current store.
Definition: Stack.hpp:118
const qglviewer::ManipulatedFrame & trans() const
Returns the transformation frame.
Definition: Stack.hpp:393
util::Vector< 3, T > worldToImageVector(Point3f wrld) const
Go from world coordinates to image coordinates (for a vector)
Definition: Stack.hpp:276
int id() const
Id of a stack.
Definition: Stack.hpp:49
const qglviewer::ManipulatedFrame & getFrame() const
Returns the active frame (i.e.
Definition: Stack.hpp:419
size_t offset(Point3i ipos) const
Returns the position, in the image, of the point of image coordinate ipos.
Definition: Stack.hpp:357
Point3u position(size_t offset) const
Compute the position from the offset.
Definition: Stack.hpp:362
const Store * currentStore() const
Returns the current store.
Definition: Stack.hpp:112
void setShowTrans(bool s)
Set if the stack should be transformed.
Definition: Stack.hpp:228
Store * main()
Access the main store.
Definition: Stack.hpp:80
CU_HOST_DEVICE void x(const T &v)
Short access to the first element.
Definition: Vector.hpp:651
BoundingBox3i boundingBox() const
Returns the bounding box, in voxels, of the stores.
Definition: Stack.hpp:131
qglviewer::ManipulatedFrame & getFrame()
Returns the active frame (i.e.
Definition: Stack.hpp:409
void setShowScale(bool s)
Set if the stack should be scaled.
Definition: Stack.hpp:202
void setTieScales(bool s)
Set if the scales should be tied.
Definition: Stack.hpp:215
Point3f step() const
Returns the size, in micro-meters, of a voxel.
Definition: Stack.hpp:138
void setId(int i)
Change the id of the stack.
Definition: Stack.hpp:58
The Store class holds the actual 3D data and properties specific to it.
Definition: Store.hpp:25
Point3f imageToWorld(const util::Vector< 3, T > &img) const
Go from image coordinates to world coordinates (for a point)
Definition: Stack.hpp:258
bool tieScales() const
True if the 3 scaling axis are tied together.
Definition: Stack.hpp:209
Point3f scale() const
Scaling factor to apply, if scaled.
Definition: Stack.hpp:159
util::Vector< 3, T > worldToImage(Point3f wrld) const
Go from world coordinates to image coordinates (for a point)
Definition: Stack.hpp:264
BoundingBox3f imageToWorld(const util::BoundingBox< 3, T > &img) const
Go from image coordinates to world coordinates (for a point)
Definition: Stack.hpp:282
qglviewer::ManipulatedFrame & frame()
Returns the manipulated frame.
Definition: Stack.hpp:386
Common definitions and utilities for all geometry algorithms This file is shared by cuda...
CU_HOST_DEVICE void y(const T &v)
Short access to the second element.
Definition: Vector.hpp:660
int viewLabel() const
Return the label to be used.
Definition: Stack.hpp:426
void setScale(Point3f s)
Set the scaling factor of the stack.
Definition: Stack.hpp:173
Point3f worldSize() const
Size of the image, in world coordinate.
Definition: Stack.hpp:336
size_t offset(uint x, uint y, uint z) const
Compute offset for image data.
Definition: Stack.hpp:350
bool showBBox() const
True if the Bounding Box of the stack is shown.
Definition: Stack.hpp:235
Point3f origin() const
Position of the point (0,0,0) of the image, in world coordinate.
Definition: Stack.hpp:166
Point3f abstractToWorld(const Point3f &p) const
Go from abstract unit to world unit.
Definition: Stack.hpp:328
qglviewer::ManipulatedFrame & trans()
Returns the transformation frame.
Definition: Stack.hpp:399
The Stack class represent the dimensions of the 3D data, and the frames transformations.
Definition: Stack.hpp:25
util::BoundingBox< 3, T > worldToImage(const BoundingBox3f &wrld) const
Go from world coordinates to image coordinates (for a point)
Definition: Stack.hpp:288
void setShowBBox(bool s)
Set if the bounding box of the stack should be visible.
Definition: Stack.hpp:241
Class representing a fixed-size matrix.
Definition: Matrix.hpp:34
CU_HOST_DEVICE void z(const T &v)
Short access to the third element.
Definition: Vector.hpp:669
bool showScale() const
True if the stack is scaled.
Definition: Stack.hpp:196
bool boundsOK(int x, int y, int z) const
Check if (x,y,z) is in the image.
Definition: Stack.hpp:341
const Store * work() const
Access the work store.
Definition: Stack.hpp:93
Point3u size() const
Returns the size, in voxels, of the stores.
Definition: Stack.hpp:125
void setLabel(int l)
Change the label to be used.
Definition: Stack.hpp:432
size_t storeSize() const
Returns the size, in number of elements, of the stores.
Definition: Stack.hpp:146
int userId() const
Id as seen by the user.
Definition: Stack.hpp:67
const Store * main() const
Access the main store.
Definition: Stack.hpp:74
bool labelChanged() const
Returns true if the label changed during this process.
Definition: Stack.hpp:451
Point3f imageToWorldVector(const util::Vector< 3, T > &img) const
Go from image coordinates to world coordinates (for a vector)
Definition: Stack.hpp:270
bool empty() const
True if the stack is empty (i.e.
Definition: Stack.hpp:152
bool showTrans() const
True if the stack is shown transformed.
Definition: Stack.hpp:222