MorphoGraphX
Stack.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 STACK_HPP
12 #define STACK_HPP
13 
14 #include <Config.hpp>
15 #include <GL.hpp>
16 
17 #include <Geometry.hpp>
18 #include <MGXViewer/qglviewer.h>
19 #include <Store.hpp>
20 
21 namespace mgx {
22 
23 namespace process {
24 class SetupProcess;
25 } // namespace process
26 
35 class mgx_EXPORT Stack {
36  friend class process::SetupProcess;
37 
38 public:
42  Stack(int id);
43 
47  Stack(const Stack& copy);
48 
52  ~Stack();
53 
59  int id() const {
60  return _id;
61  }
62 
68  void setId(int i) {
69  _id = i;
70  }
71 
77  int userId() const {
78  return _id + 1;
79  }
80 
84  const Store* main() const {
85  return _main;
86  }
90  Store* main() {
91  return _main;
92  }
98  void setMain(Store* m);
99 
103  const Store* work() const {
104  return _work;
105  }
109  Store* work() {
110  return _work;
111  }
117  void setWork(Store* w);
118 
122  const Store* currentStore() const {
123  return _current;
124  }
129  return _current;
130  }
131 
135  Point3u size() const {
136  return _size;
137  }
142  return BoundingBox3i(Point3i(), Point3i(size()));
143  }
144 
148  Point3f step() const
149  {
150  return multiply(_step, scale());
151  }
152  // Point3f step() const { return _step * scale(); }// old
156  size_t storeSize() const {
157  return size_t(_size.x()) * _size.y() * _size.z();
158  }
162  bool empty() const {
163  return _size == Point3u();
164  }
165 
169  Point3f scale() const {
170  return (_showScale ? _scale : Point3f(1.0, 1.0, 1.0));
171  }
172  // float scale() const { return (_showScale ? _scale : 1.0f); }
176  Point3f origin() const {
177  return multiply(scale(), _origin);
178  }
179  // Point3f origin() const { return scale()*_origin; }
183  void setScale(Point3f s) {
184  _scale = s;
185  }
186  // void setScale(float s) { _scale = s; }
190  void setOrigin(const Point3f& s);
191 
197  void setSize(const Point3u& s);
201  void setStep(const Point3f& s);
202 
206  bool showScale() const {
207  return _showScale;
208  }
212  void setShowScale(bool s) {
213  _showScale = s;
214  }
215 
219  bool tieScales() const {
220  return _tieScales;
221  }
225  void setTieScales(bool s) {
226  _tieScales = s;
227  }
228 
232  bool showTrans() const {
233  return _showTrans;
234  }
238  void setShowTrans(bool s) {
239  _showTrans = s;
240  }
241 
245  bool showBBox() const {
246  return _showBBox;
247  }
251  void setShowBBox(bool s) {
252  _showBBox = s;
253  }
254 
256  Matrix4f worldToImage() const;
257 
259  Matrix4f imageToWorld() const;
260 
262  Matrix4f worldToImageVector() const;
263 
265  Matrix4f imageToWorldVector() const;
266 
268  template <typename T> Point3f imageToWorld(const util::Vector<3, T>& img) const
269  {
270  return multiply(Point3f(img) + Point3f(.5f, .5f, .5f), step()) + origin();
271  }
272 
274  template <typename T> util::Vector<3, T> worldToImage(Point3f wrld) const
275  {
276  return util::Vector<3, T>((wrld - origin()) / step() - Point3f(.5f, .5f, .5f));
277  }
278 
280  template <typename T> Point3f imageToWorldVector(const util::Vector<3, T>& img) const
281  {
282  return multiply(Point3f(img), step());
283  }
284 
286  template <typename T> util::Vector<3, T> worldToImageVector(Point3f wrld) const
287  {
288  return util::Vector<3, T>(wrld / step());
289  }
290 
292  template <typename T> BoundingBox3f imageToWorld(const util::BoundingBox<3, T>& img) const
293  {
294  return BoundingBox3f(imageToWorld(img.pmin()), imageToWorld(img.pmax()));
295  }
296 
298  template <typename T> util::BoundingBox<3, T> worldToImage(const BoundingBox3f& wrld) const
299  {
300  return util::BoundingBox<3, T>(worldToImage<T>(wrld.pmin()), worldToImage<T>(wrld.pmax()));
301  }
302 
303  Point3f worldToImagef(const Point3f& a) const {
304  return worldToImage<float>(a);
305  }
306  Point3i worldToImagei(const Point3f& a) const {
307  return worldToImage<int>(a);
308  }
309  Point3u worldToImageu(const Point3f& a) const {
310  return worldToImage<uint>(a);
311  }
312 
313  BoundingBox3f worldToImagef(const BoundingBox3f& a) const {
314  return worldToImage<float>(a);
315  }
316  BoundingBox3i worldToImagei(const BoundingBox3f& a) const {
317  return worldToImage<int>(a);
318  }
319  BoundingBox3u worldToImageu(const BoundingBox3f& a) const {
320  return worldToImage<uint>(a);
321  }
322 
323  Point3f worldToImageVectorf(const Point3f& a) const {
324  return worldToImageVector<float>(a);
325  }
326  Point3i worldToImageVectori(const Point3f& a) const {
327  return worldToImageVector<int>(a);
328  }
329  Point3u worldToImageVectoru(const Point3f& a) const {
330  return worldToImageVector<uint>(a);
331  }
332 
339  {
340  return divide(p, scale()) * _texScale;
341  }
342 
346  Point3f worldSize() const {
347  return imageToWorldVector(_size);
348  }
349 
351  bool boundsOK(int x, int y, int z) const
352  {
353  if(x < 0 or y < 0 or z < 0 or x >= int(_size.x()) or y >= int(_size.y()) or z >= int(_size.z()))
354  return false;
355  else
356  return true;
357  }
358 
360  size_t offset(uint x, uint y, uint z) const {
361  return (size_t(z) * _size.y() + y) * _size.x() + x;
362  }
363 
367  size_t offset(Point3i ipos) const {
368  return (size_t(ipos.z()) * _size.y() + ipos.y()) * _size.x() + ipos.x();
369  }
370 
372  Point3u position(size_t offset) const
373  {
374  uint x = offset % _size.x();
375  offset = (offset - x) / _size.x();
376  uint y = offset % _size.y();
377  uint z = (offset - y) / _size.y();
378  return Point3u(x, y, z);
379  }
380 
384  void center();
385 
390  return _frame;
391  }
392 
397  return _frame;
398  }
399 
404  return _trans;
405  }
410  return _trans;
411  }
412 
420  return (_showTrans ? _trans : _frame);
421  }
422 
430  return (_showTrans ? _trans : _frame);
431  }
432 
436  int viewLabel() const {
437  return _CurrLabel;
438  }
442  void setLabel(int l)
443  {
444  changed_label = true;
445  _CurrLabel = l;
446  }
450  int nextLabel()
451  {
452  changed_label = true;
453  _CurrLabel++;
454  if(_CurrLabel > ((1 << 16) - 1))
455  _CurrLabel = 1;
456  return _CurrLabel;
457  }
461  bool labelChanged() const {
462  return changed_label;
463  }
464 
465  void setMainAsCurrent() {
466  _current = _main;
467  }
468  void setWorkAsCurrent() {
469  _current = _work;
470  }
471  void setNoneAsCurrent() {
472  _current = 0;
473  }
474 
475  void setCurrentStore(Store* store) {
476  _current = (store == _main or store == _work) ? store : 0;
477  }
478 
482  void reset();
483 
484 private:
485  void resetModified();
486  void updateSizes();
487  void resetCurrent();
488  Store* _main, *_work, *_current;
489  Point3f _scale;
490  // float _scale;
491  Point3f _origin;
492  float _texScale;
493  Point3u _size;
494  Point3f _step;
497  bool changed_frame, changed_trans, changed_label;
498  int _id;
499  int _CurrLabel;
500  bool _showScale, _showTrans, _showBBox, _tieScales;
501 };
502 } // namespace mgx
503 
504 #endif // STACK_HPP
int nextLabel()
Return the next label to be used and change it so successive calls return successive labels...
Definition: Stack.hpp:450
Store * work()
Access the work store.
Definition: Stack.hpp:109
const qglviewer::ManipulatedFrame & frame() const
Returns the manipulated frame.
Definition: Stack.hpp:389
Store * currentStore()
Returns the current store.
Definition: Stack.hpp:128
const qglviewer::ManipulatedFrame & trans() const
Returns the transformation frame.
Definition: Stack.hpp:403
util::Vector< 3, T > worldToImageVector(Point3f wrld) const
Go from world coordinates to image coordinates (for a vector)
Definition: Stack.hpp:286
int id() const
Id of a stack.
Definition: Stack.hpp:59
const qglviewer::ManipulatedFrame & getFrame() const
Returns the active frame (i.e.
Definition: Stack.hpp:429
size_t offset(Point3i ipos) const
Returns the position, in the image, of the point of image coordinate ipos.
Definition: Stack.hpp:367
Point3u position(size_t offset) const
Compute the position from the offset.
Definition: Stack.hpp:372
const Store * currentStore() const
Returns the current store.
Definition: Stack.hpp:122
void setShowTrans(bool s)
Set if the stack should be transformed.
Definition: Stack.hpp:238
Store * main()
Access the main store.
Definition: Stack.hpp:90
CU_HOST_DEVICE void x(const T &v)
Short access to the first element.
Definition: Vector.hpp:661
BoundingBox3i boundingBox() const
Returns the bounding box, in voxels, of the stores.
Definition: Stack.hpp:141
qglviewer::ManipulatedFrame & getFrame()
Returns the active frame (i.e.
Definition: Stack.hpp:419
void setShowScale(bool s)
Set if the stack should be scaled.
Definition: Stack.hpp:212
void setTieScales(bool s)
Set if the scales should be tied.
Definition: Stack.hpp:225
Point3f step() const
Returns the size, in micro-meters, of a voxel.
Definition: Stack.hpp:148
void setId(int i)
Change the id of the stack.
Definition: Stack.hpp:68
The Store class holds the actual 3D data and properties specific to it.
Definition: Store.hpp:35
Point3f imageToWorld(const util::Vector< 3, T > &img) const
Go from image coordinates to world coordinates (for a point)
Definition: Stack.hpp:268
bool tieScales() const
True if the 3 scaling axis are tied together.
Definition: Stack.hpp:219
Point3f scale() const
Scaling factor to apply, if scaled.
Definition: Stack.hpp:169
util::Vector< 3, T > worldToImage(Point3f wrld) const
Go from world coordinates to image coordinates (for a point)
Definition: Stack.hpp:274
BoundingBox3f imageToWorld(const util::BoundingBox< 3, T > &img) const
Go from image coordinates to world coordinates (for a point)
Definition: Stack.hpp:292
qglviewer::ManipulatedFrame & frame()
Returns the manipulated frame.
Definition: Stack.hpp:396
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:670
int viewLabel() const
Return the label to be used.
Definition: Stack.hpp:436
void setScale(Point3f s)
Set the scaling factor of the stack.
Definition: Stack.hpp:183
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
Point3f worldSize() const
Size of the image, in world coordinate.
Definition: Stack.hpp:346
size_t offset(uint x, uint y, uint z) const
Compute offset for image data.
Definition: Stack.hpp:360
bool showBBox() const
True if the Bounding Box of the stack is shown.
Definition: Stack.hpp:245
Point3f origin() const
Position of the point (0,0,0) of the image, in world coordinate.
Definition: Stack.hpp:176
Point3f abstractToWorld(const Point3f &p) const
Go from abstract unit to world unit.
Definition: Stack.hpp:338
qglviewer::ManipulatedFrame & trans()
Returns the transformation frame.
Definition: Stack.hpp:409
The Stack class represent the dimensions of the 3D data, and the frames transformations.
Definition: Stack.hpp:35
util::BoundingBox< 3, T > worldToImage(const BoundingBox3f &wrld) const
Go from world coordinates to image coordinates (for a point)
Definition: Stack.hpp:298
void setShowBBox(bool s)
Set if the bounding box of the stack should be visible.
Definition: Stack.hpp:251
Class representing a fixed-size matrix.
Definition: Matrix.hpp:44
This namespace contains all the classes needed to define processes.
CU_HOST_DEVICE void z(const T &v)
Short access to the third element.
Definition: Vector.hpp:679
bool showScale() const
True if the stack is scaled.
Definition: Stack.hpp:206
bool boundsOK(int x, int y, int z) const
Check if (x,y,z) is in the image.
Definition: Stack.hpp:351
const Store * work() const
Access the work store.
Definition: Stack.hpp:103
Point3u size() const
Returns the size, in voxels, of the stores.
Definition: Stack.hpp:135
void setLabel(int l)
Change the label to be used.
Definition: Stack.hpp:442
size_t storeSize() const
Returns the size, in number of elements, of the stores.
Definition: Stack.hpp:156
int userId() const
Id as seen by the user.
Definition: Stack.hpp:77
const Store * main() const
Access the main store.
Definition: Stack.hpp:84
bool labelChanged() const
Returns true if the label changed during this process.
Definition: Stack.hpp:461
Point3f imageToWorldVector(const util::Vector< 3, T > &img) const
Go from image coordinates to world coordinates (for a vector)
Definition: Stack.hpp:280
bool empty() const
True if the stack is empty (i.e.
Definition: Stack.hpp:162
bool showTrans() const
True if the stack is shown transformed.
Definition: Stack.hpp:232