Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  
igtlNDArrayMessage.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: The OpenIGTLink Library
4  Language: C++
5  Web page: http://openigtlink.org/
6 
7  Copyright (c) Insight Software Consortium. All rights reserved.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notices for more information.
12 
13 =========================================================================*/
14 
15 #ifndef __igtlNDArrayMessage_h
16 #define __igtlNDArrayMessage_h
17 
18 #include <string>
19 
20 #include "igtlObject.h"
21 #include "igtlMath.h"
22 #include "igtlMessageBase.h"
23 #include "igtlTypes.h"
24 
25 #define IGTL_STRING_MESSAGE_DEFAULT_ENCODING 3 /* Default encoding -- ANSI-X3.5-1968 */
26 
27 namespace igtl
28 {
29 
31 {
32 public:
33 
35  typedef std::vector<igtlUint16> IndexType;
36 
37 protected:
38  ArrayBase();
39  ~ArrayBase();
40 
41 public:
42 
44  int SetSize(IndexType size);
45 
47  IndexType GetSize() { return this->m_Size; };
48 
50  int GetDimension() { return this->m_Size.size(); };
51 
54  int SetArray(void * array);
55 
57  igtlUint64 GetRawArraySize();
58 
60  void * GetRawArray() { return this->m_ByteArray; };
61 
62 protected:
63 
65  virtual int GetElementSize() = 0;
66 
68  igtlUint32 GetNumberOfElements();
69 
73  igtlUint32 Get1DIndex(IndexType index);
74 
75 private:
76 
78  IndexType m_Size;
79 
81  void * m_ByteArray;
82 
83 };
84 
85 
86 template <typename T>
88 {
89 public:
91  int SetValue(IndexType index, T value)
92  {
93  if (Get1DIndex(index) <= GetNumberOfElements()) {
94  T* ByteArray = (T*)GetRawArray();
95  ByteArray[Get1DIndex(index) * sizeof(T)] = value;
96  return 1;
97  } else {
98  return 0;
99  }
100  }
101 
103  int GetValue(IndexType index, T & value)
104  {
105  if (Get1DIndex(index) <= GetNumberOfElements()) {
106  T* ByteArray = (T*)GetRawArray();
107  value = ByteArray[Get1DIndex(index) * sizeof(T)];
108  return 1;
109  } else {
110  return 0;
111  }
112  }
113 
114 protected:
115 
117  virtual int GetElementSize() { return sizeof(T); };
118 };
119 
120 
122 {
123 public:
124 
126  enum {
127  TYPE_INT8 = 2,
128  TYPE_UINT8 = 3,
129  TYPE_INT16 = 4,
130  TYPE_UINT16 = 5,
131  TYPE_INT32 = 6,
132  TYPE_UINT32 = 7,
133  TYPE_FLOAT32 = 10,
134  TYPE_FLOAT64 = 11,
135  TYPE_COMPLEX = 13,
136  };
137 
138 public:
143 
146 
147 public:
148 
150  int SetArray(int type, ArrayBase * a);
151 
153  ArrayBase * GetArray() { return this->m_Array; };
154 
156  int GetType() { return this->m_Type; } ;
157 
158 protected:
159  NDArrayMessage();
160  ~NDArrayMessage();
161 
162 protected:
163 
164  virtual int GetBodyPackSize();
165  virtual int PackBody();
166  virtual int UnpackBody();
167 
170 
172  int m_Type;
173 
174 };
175 
176 
177 } // namespace igtl
178 
179 #endif // _igtlNDArrayMessage_h
180 
181 
182 
ArrayBase * m_Array
A pointer to the N-D array.
std::vector< igtlUint16 > IndexType
Vector type for an index of N-D array.
SmartPointer< const Self > ConstPointer
#define igtlTypeMacro(thisClass, superclass)
Definition: igtlMacro.h:486
The "igtl" namespace contains all OpenIGTLink classes. There are several nested namespaces within the...
ArrayBase * GetArray()
Gets a pointer to the array.
int GetValue(IndexType index, T &value)
Gets a value of the element specified by &#39;index&#39;.
#define IGTLCommon_EXPORT
int GetDimension()
Gets the dimension of the N-D array.
SmartPointer< Self > Pointer
int SetValue(IndexType index, T value)
Sets a value of the element specified by &#39;index&#39;.
void * GetRawArray()
Gets the raw byte array stored in the class.
IndexType GetSize()
Gets the size of the N-D array.
virtual int GetElementSize()
Gets the size of elements (e.g. 1 byte in case of 8-bit integer)
#define igtlNewMacro(x)
Definition: igtlMacro.h:431
int GetType()
Gets the type of elements of the array. (e.g. TYPE_INT8)
int m_Type
A variable for the type of the N-D array.

Generated at Sat Apr 15 2017 02:30:07 for OpenIGTLink by doxygen 1.8.13 written by Dimitri van Heesch, © 1997-2012