JEMRIS  2.8.1
open-source MRI simulations
KSpace.h
Go to the documentation of this file.
1 
5 /*
6  * JEMRIS Copyright (C)
7  * 2006-2015 Tony Stoecker
8  * 2007-2015 Kaveh Vahedipour
9  * 2009-2015 Daniel Pflugfelder
10  *
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  */
26 
27 #ifndef __K_SPACE_H__
28 #define __K_SPACE_H__
29 
30 #include "NDData.h"
31 #include "BinaryContext.h"
32 
33 #include <cstddef>
34 #include <vector>
35 
36 
40 template <class T, unsigned D = 3>
41 class KSpace {
42 
43 public:
44 
45  struct KPoint {
46 
47  T _data[D];
48 
49  inline KPoint () {};
50 
51  inline
52  KPoint (const KPoint& kp) {
53  *this = kp;
54  }
55 
56  inline KPoint&
57  operator= (const KPoint& kp) {
58  std::copy (kp.begin(), kp.end(), this->Ptr());
59  return *this;
60  }
61 
62  inline T*
63  Ptr (const size_t n = 0) {
64  return &_data[n];
65  }
66 
67  inline const T*
68  Ptr (const size_t n = 0) const {
69  return &_data[n];
70  }
71 
72  inline const T
73  operator[] (const size_t n) const {
74  return _data[n];
75  }
76 
77  inline T
78  operator[] (const size_t n) {
79  return _data[n];
80  }
81 
82  inline T* begin () { return &_data[0]; }
83  inline const T* begin () const { return &_data[0]; }
84  inline T* end () { return &_data[D-1]; }
85  inline const T* end () const { return &_data[D-1]; }
86 
87  };
88 
92  KSpace () {}
93 
97  KSpace (const KSpace& ks) {
98  *this = ks;
99  }
100 
104  KSpace& operator= (const KSpace& k) {
105  _k = k._k;
106  return *this;
107  }
108 
112  ~KSpace () {};
113 
117  void PushBack (const KPoint& p) {
118  _k.push_back(p);
119  }
120 
124  void Write (const std::string& fname, const std::string& urn, const std::string& url = "") {
125 
126  if (_k.empty())
127  return;
128 
129  NDData<T> data (D,_k.size());
130  for (size_t i = 0; i < _k.size(); ++i)
131  std::copy (_k[i].begin(), _k[i].end(), &data[i*D]);
132  BinaryContext bc (fname, IO::APPEND);
133  bc.Write(data, urn, url);
134  }
135 
136 
137 private:
138 
139  std::vector<KPoint> _k;
140 
141 };
142 
143 #endif
K-space.
Definition: KSpace.h:41
void Write(const std::string &fname, const std::string &urn, const std::string &url="")
Write k-space to file.
Definition: KSpace.h:124
IO::Status Write(const NDData< T > &data, const std::string &urn, const std::string &url="")
Write data from container to file.
Definition: BinaryContext.h:58
~KSpace()
Default destructor.
Definition: KSpace.h:112
KSpace()
Default constructor.
Definition: KSpace.h:92
Simple nd-data structure.
Definition: NDData.h:53
Implementation of JEMRIS Sample.
Definition: BinaryContext.h:41
void PushBack(const KPoint &p)
Append element to end.
Definition: KSpace.h:117
KSpace(const KSpace &ks)
Copy constructor.
Definition: KSpace.h:97
Definition: KSpace.h:45

-- last change 17.06.2016 | Tony Stoecker | Imprint --