MorphoGraphX  2.0-1-227
Stack.hpp
Go to the documentation of this file.
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  class SetupProcess;
24 
33  class mgx_EXPORT Stack {
34  friend class SetupProcess;
35 
36  public:
40  Stack(int id);
41 
45  Stack(const Stack& copy);
46 
50  ~Stack();
51 
57  int id() const {
58  return _id;
59  }
60 
66  void setId(int i) {
67  _id = i;
68  }
69 
75  int userId() const {
76  return _id + 1;
77  }
78 
82  const Store* main() const {
83  return _main;
84  }
88  Store* main() {
89  return _main;
90  }
96  void setMain(Store* m);
97 
101  const Store* work() const {
102  return _work;
103  }
107  Store* work() {
108  return _work;
109  }
115  void setWork(Store* w);
116 
120  const Store* currentStore() const {
121  return _current;
122  }
127  return _current;
128  }
129 
133  Point3u size() const {
134  return _size;
135  }
140  return BoundingBox3i(Point3i(), Point3i(size()));
141  }
142 
146  Point3f step() const
147  {
148  return multiply(_step, scale());
149  }
150  // Point3f step() const { return _step * scale(); }// old
154  size_t storeSize() const {
155  return size_t(_size.x()) * _size.y() * _size.z();
156  }
160  bool empty() const {
161  return _size == Point3u();
162  }
163 
167  Point3f scale() const {
168  return (_showScale ? _scale : Point3f(1.0, 1.0, 1.0));
169  }
170  // float scale() const { return (_showScale ? _scale : 1.0f); }
174  Point3f origin() const {
175  return multiply(scale(), _origin);
176  }
177  // Point3f origin() const { return scale()*_origin; }
181  void setScale(Point3f s) {
182  _scale = s;
183  }
184  // void setScale(float s) { _scale = s; }
188  void setOrigin(const Point3f& s);
189 
195  void setSize(const Point3u& s);
199  void setStep(const Point3f& s);
200 
204  bool showScale() const {
205  return _showScale;
206  }
210  void setShowScale(bool s) {
211  _showScale = s;
212  }
213 
217  bool tieScales() const {
218  return _tieScales;
219  }
223  void setTieScales(bool s) {
224  _tieScales = s;
225  }
226 
230  bool showTrans() const {
231  return _showTrans;
232  }
236  void setShowTrans(bool s) {
237  _showTrans = s;
238  }
242  bool showBBox() const {
243  return _showBBox;
244  }
248  void setShowBBox(bool s) {
249  _showBBox = s;
250  }
251 
253  Matrix4f worldToImage() const;
254 
256  Matrix4f imageToWorld() const;
257 
259  Matrix4f worldToImageVector() const;
260 
262  Matrix4f imageToWorldVector() const;
263 
265  template <typename T> Point3f imageToWorld(const Vector<3, T>& img) const
266  {
267  return multiply(Point3f(img) + Point3f(.5f, .5f, .5f), step()) + origin();
268  }
269 
271  template <typename T> Vector<3, T> worldToImage(Point3f wrld) const
272  {
273  return Vector<3, T>((wrld - origin()) / step() - Point3f(.5f, .5f, .5f));
274  }
275 
277  template <typename T> Point3f imageToWorldVector(const Vector<3, T>& img) const
278  {
279  return multiply(Point3f(img), step());
280  }
281 
283  template <typename T> Vector<3, T> worldToImageVector(Point3f wrld) const
284  {
285  return Vector<3, T>(wrld / step());
286  }
287 
289  template <typename T> BoundingBox3f imageToWorld(const BoundingBox<3, T>& img) const
290  {
291  return BoundingBox3f(imageToWorld(img.pmin()), imageToWorld(img.pmax()));
292  }
293 
295  template <typename T> BoundingBox<3, T> worldToImage(const BoundingBox3f& wrld) const
296  {
297  return BoundingBox<3, T>(worldToImage<T>(wrld.pmin()), worldToImage<T>(wrld.pmax()));
298  }
299 
300  Point3f worldToImagef(const Point3f& a) const {
301  return worldToImage<float>(a);
302  }
303  Point3i worldToImagei(const Point3f& a) const {
304  return worldToImage<int>(a);
305  }
306  Point3u worldToImageu(const Point3f& a) const {
307  return worldToImage<uint>(a);
308  }
309 
311  return worldToImage<float>(a);
312  }
314  return worldToImage<int>(a);
315  }
317  return worldToImage<uint>(a);
318  }
319 
321  return worldToImageVector<float>(a);
322  }
324  return worldToImageVector<int>(a);
325  }
327  return worldToImageVector<uint>(a);
328  }
329 
336  {
337  return divide(p, scale()) * _texScale;
338  }
339 
343  Point3f worldSize() const {
344  return imageToWorldVector(_size);
345  }
346 
348  bool boundsOK(int x, int y, int z) const
349  {
350  if(x < 0 or y < 0 or z < 0 or x >= int(_size.x()) or y >= int(_size.y()) or z >= int(_size.z()))
351  return false;
352  else
353  return true;
354  }
355 
357  size_t offset(uint x, uint y, uint z) const {
358  return (size_t(z) * _size.y() + y) * _size.x() + x;
359  }
360 
364  size_t offset(Point3i ipos) const {
365  return (size_t(ipos.z()) * _size.y() + ipos.y()) * _size.x() + ipos.x();
366  }
367 
369  Point3u position(size_t offset) const
370  {
371  uint x = offset % _size.x();
372  offset = (offset - x) / _size.x();
373  uint y = offset % _size.y();
374  uint z = (offset - y) / _size.y();
375  return Point3u(x, y, z);
376  }
377 
381  void center();
382 
387  return _frame;
388  }
389 
394  return _frame;
395  }
396 
401  return _trans;
402  }
407  return _trans;
408  }
409 
417  return (_showTrans ? _trans : _frame);
418  }
419 
427  return (_showTrans ? _trans : _frame);
428  }
429 
433  int viewLabel() const {
434  return _CurrLabel;
435  }
439  void setLabel(int l)
440  {
441  _CurrLabel = l;
442  }
446  int nextLabel()
447  {
448  _CurrLabel++;
449  if(_CurrLabel > ((1 << 16) - 1))
450  _CurrLabel = 1;
451  return _CurrLabel;
452  }
453 
455  _current = _main;
456  }
458  _current = _work;
459  }
461  _current = 0;
462  }
463 
464  void setCurrentStore(Store* store) {
465  _current = (store == _main or store == _work) ? store : 0;
466  }
467 
471  void reset();
472 
473  private:
474  void resetModified();
475  void updateSizes();
476  void resetCurrent();
477  Store* _main, *_work, *_current;
478  Point3f _scale;
479  // float _scale;
480  Point3f _origin;
481  float _texScale;
482  Point3u _size;
483  Point3f _step;
486  bool changed_frame, changed_trans;
487  int _id;
488  int _CurrLabel;
489  bool _showScale, _showTrans, _showBBox, _tieScales;
490  };
491 }
492 
493 #endif
mgx::worldToImage
CU_HOST_DEVICE Point3i worldToImage(const Point3f &wrld, const Point3f &step, const Point3f &shift)
Definition: Geometry.hpp:425
mgx::Stack::worldToImagei
Point3i worldToImagei(const Point3f &a) const
Definition: Stack.hpp:303
mgx::uint
unsigned int uint
Definition: Geometry.hpp:41
GL.hpp
mgx::Stack::setMainAsCurrent
void setMainAsCurrent()
Definition: Stack.hpp:454
mgx::Stack::getFrame
const qglviewer::ManipulatedFrame & getFrame() const
Returns the active frame (i.e.
Definition: Stack.hpp:426
mgx::Stack::size
Point3u size() const
Returns the size, in voxels, of the stores.
Definition: Stack.hpp:133
mgx::Stack::worldToImageVectoru
Point3u worldToImageVectoru(const Point3f &a) const
Definition: Stack.hpp:326
mgx::Stack::trans
qglviewer::ManipulatedFrame & trans()
Returns the transformation frame.
Definition: Stack.hpp:406
mgx::Stack::empty
bool empty() const
True if the stack is empty (i.e.
Definition: Stack.hpp:160
mgx::Stack::setShowScale
void setShowScale(bool s)
Set if the stack should be scaled.
Definition: Stack.hpp:210
mgx::Stack::work
const Store * work() const
Access the work store.
Definition: Stack.hpp:101
qglviewer::ManipulatedFrame
mgx::Vector::z
CU_HOST_DEVICE void z(const T &v)
Short access to the third element.
Definition: Vector.hpp:739
mgx::Stack::setTieScales
void setTieScales(bool s)
Set if the scales should be tied.
Definition: Stack.hpp:223
mgx::Stack::currentStore
const Store * currentStore() const
Returns the current store.
Definition: Stack.hpp:120
mgx::Stack::setLabel
void setLabel(int l)
Change the label to be used.
Definition: Stack.hpp:439
mgx::Stack::setNoneAsCurrent
void setNoneAsCurrent()
Definition: Stack.hpp:460
mgx::Stack::imageToWorldVector
Point3f imageToWorldVector(const Vector< 3, T > &img) const
Go from image coordinates to world coordinates (for a vector)
Definition: Stack.hpp:277
mgx::Stack::worldToImageu
BoundingBox3u worldToImageu(const BoundingBox3f &a) const
Definition: Stack.hpp:316
mgx::Stack::viewLabel
int viewLabel() const
Return the label to be used.
Definition: Stack.hpp:433
mgx::Stack::main
const Store * main() const
Access the main store.
Definition: Stack.hpp:82
mgx::Stack::setId
void setId(int i)
Change the id of the stack.
Definition: Stack.hpp:66
mgx::Stack::offset
size_t offset(Point3i ipos) const
Returns the position, in the image, of the point of image coordinate ipos.
Definition: Stack.hpp:364
mgx::Stack::showScale
bool showScale() const
True if the stack is scaled.
Definition: Stack.hpp:204
mgx::Stack::worldToImageVectori
Point3i worldToImageVectori(const Point3f &a) const
Definition: Stack.hpp:323
mgx::Stack::worldToImagei
BoundingBox3i worldToImagei(const BoundingBox3f &a) const
Definition: Stack.hpp:313
mgx::Stack
Definition: Stack.hpp:33
Geometry.hpp
mgx::Stack::imageToWorld
BoundingBox3f imageToWorld(const BoundingBox< 3, T > &img) const
Go from image coordinates to world coordinates (for a point)
Definition: Stack.hpp:289
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::BoundingBox::pmin
CU_HOST_DEVICE Point pmin()
Definition: BoundingBox.hpp:229
mgx::Stack::showTrans
bool showTrans() const
True if the stack is shown transformed.
Definition: Stack.hpp:230
mgx::Stack::storeSize
size_t storeSize() const
Returns the size, in number of elements, of the stores.
Definition: Stack.hpp:154
mgx::Stack::showBBox
bool showBBox() const
True if the Bounding Box of the stack is shown.
Definition: Stack.hpp:242
mgx::imageToWorld
CU_HOST_DEVICE Point3f imageToWorld(const Point3i &img, const Point3f &step, const Point3f &shift)
Definition: Geometry.hpp:418
mgx::BoundingBox3i
BoundingBox< 3, int > BoundingBox3i
Definition: Geometry.hpp:141
mgx::BoundingBox3f
BoundingBox< 3, float > BoundingBox3f
Definition: Geometry.hpp:142
mgx::Stack::boundingBox
BoundingBox3i boundingBox() const
Returns the bounding box, in voxels, of the stores.
Definition: Stack.hpp:139
mgx::Point3f
Vector< 3, float > Point3f
Definition: CuttingSurface.hpp:25
mgx::Stack::worldSize
Point3f worldSize() const
Size of the image, in world coordinate.
Definition: Stack.hpp:343
mgx::Stack::position
Point3u position(size_t offset) const
Compute the position from the offset.
Definition: Stack.hpp:369
mgx::Stack::setShowTrans
void setShowTrans(bool s)
Set if the stack should be transformed.
Definition: Stack.hpp:236
mgx::Stack::work
Store * work()
Access the work store.
Definition: Stack.hpp:107
mgx::Vector::y
CU_HOST_DEVICE void y(const T &v)
Short access to the second element.
Definition: Vector.hpp:730
mgx::Stack::abstractToWorld
Point3f abstractToWorld(const Point3f &p) const
Go from abstract unit to world unit.
Definition: Stack.hpp:335
mgx::Stack::main
Store * main()
Access the main store.
Definition: Stack.hpp:88
mgx::Stack::worldToImage
BoundingBox< 3, T > worldToImage(const BoundingBox3f &wrld) const
Go from world coordinates to image coordinates (for a point)
Definition: Stack.hpp:295
mgx::Stack::imageToWorld
Point3f imageToWorld(const Vector< 3, T > &img) const
Go from image coordinates to world coordinates (for a point)
Definition: Stack.hpp:265
mgx::Stack::origin
Point3f origin() const
Position of the point (0,0,0) of the image, in world coordinate.
Definition: Stack.hpp:174
mgx::Stack::frame
const qglviewer::ManipulatedFrame & frame() const
Returns the manipulated frame.
Definition: Stack.hpp:386
mgx::Stack::tieScales
bool tieScales() const
True if the 3 scaling axis are tied together.
Definition: Stack.hpp:217
mgx::Stack::offset
size_t offset(uint x, uint y, uint z) const
Compute offset for image data.
Definition: Stack.hpp:357
mgx::Stack::boundsOK
bool boundsOK(int x, int y, int z) const
Check if (x,y,z) is in the image.
Definition: Stack.hpp:348
mgx::Stack::worldToImageu
Point3u worldToImageu(const Point3f &a) const
Definition: Stack.hpp:306
mgx::Stack::trans
const qglviewer::ManipulatedFrame & trans() const
Returns the transformation frame.
Definition: Stack.hpp:400
mgx::Vector< 3, uint >
mgx::Stack::worldToImagef
Point3f worldToImagef(const Point3f &a) const
Definition: Stack.hpp:300
mgx::Point3u
Vector< 3, uint > Point3u
Definition: Geometry.hpp:75
mgx::BoundingBox::pmax
CU_HOST_DEVICE Point pmax()
Definition: BoundingBox.hpp:239
mgx::Point3i
Vector< 3, int > Point3i
Definition: Geometry.hpp:68
mgx::Stack::worldToImageVectorf
Point3f worldToImageVectorf(const Point3f &a) const
Definition: Stack.hpp:320
mgx::Stack::id
int id() const
Id of a stack.
Definition: Stack.hpp:57
mgx::Stack::frame
qglviewer::ManipulatedFrame & frame()
Returns the manipulated frame.
Definition: Stack.hpp:393
mgx::Stack::worldToImagef
BoundingBox3f worldToImagef(const BoundingBox3f &a) const
Definition: Stack.hpp:310
mgx::Stack::step
Point3f step() const
Returns the size, in micro-meters, of a voxel.
Definition: Stack.hpp:146
mgx::Stack::setScale
void setScale(Point3f s)
Set the scaling factor of the stack.
Definition: Stack.hpp:181
mgx::Vector::x
CU_HOST_DEVICE void x(const T &v)
Short access to the first element.
Definition: Vector.hpp:721
mgx::Stack::userId
int userId() const
Id as seen by the user.
Definition: Stack.hpp:75
mgx::Matrix
Definition: Matrix.hpp:39
mgx::offset
CU_HOST_DEVICE size_t offset(uint x, uint y, uint z, uint xsz, uint ysz)
Definition: Geometry.hpp:431
Store.hpp
mgx::Stack::nextLabel
int nextLabel()
Return the next label to be used and change it so successive calls return successive labels.
Definition: Stack.hpp:446
mgx::Stack::setCurrentStore
void setCurrentStore(Store *store)
Definition: Stack.hpp:464
mgx::Stack::worldToImageVector
Vector< 3, T > worldToImageVector(Point3f wrld) const
Go from world coordinates to image coordinates (for a vector)
Definition: Stack.hpp:283
mgx::Stack::setWorkAsCurrent
void setWorkAsCurrent()
Definition: Stack.hpp:457
mgx::Stack::getFrame
qglviewer::ManipulatedFrame & getFrame()
Returns the active frame (i.e.
Definition: Stack.hpp:416
mgx::BoundingBox< 3, int >
mgx::Stack::worldToImage
Vector< 3, T > worldToImage(Point3f wrld) const
Go from world coordinates to image coordinates (for a point)
Definition: Stack.hpp:271
mgx::Stack::currentStore
Store * currentStore()
Returns the current store.
Definition: Stack.hpp:126
mgx::Stack::scale
Point3f scale() const
Scaling factor to apply, if scaled.
Definition: Stack.hpp:167
mgx::Stack::setShowBBox
void setShowBBox(bool s)
Set if the bounding box of the stack should be visible.
Definition: Stack.hpp:248
mgx::Store
Definition: Store.hpp:33