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 *) this->m_ByteArray[Get1DIndex(index) * sizeof(T)] = value;
95  return 1;
96  } else {
97  return 0;
98  }
99  }
100 
102  int GetValue(IndexType index, T & value)
103  {
104  if (Get1DIndex(index) <= GetNumberOfElements()) {
105  value = * (T *) this->m_ByteArray[Get1DIndex(index) * sizeof(T)];
106  return 1;
107  } else {
108  return 0;
109  }
110  }
111 
112 protected:
113 
115  virtual int GetElementSize() { return sizeof(T); };
116 };
117 
118 
120 {
121 public:
122 
124  enum {
125  TYPE_INT8 = 2,
126  TYPE_UINT8 = 3,
127  TYPE_INT16 = 4,
128  TYPE_UINT16 = 5,
129  TYPE_INT32 = 6,
130  TYPE_UINT32 = 7,
131  TYPE_FLOAT32 = 10,
132  TYPE_FLOAT64 = 11,
133  TYPE_COMPLEX = 13,
134  };
135 
136 public:
141 
144 
145 public:
146 
148  int SetArray(int type, ArrayBase * a);
149 
151  ArrayBase * GetArray() { return this->m_Array; };
152 
154  int GetType() { return this->m_Type; } ;
155 
156 protected:
157  NDArrayMessage();
158  ~NDArrayMessage();
159 
160 protected:
161 
162  virtual int GetBodyPackSize();
163  virtual int PackBody();
164  virtual int UnpackBody();
165 
168 
170  int m_Type;
171 
172 };
173 
174 
175 } // namespace igtl
176 
177 #endif // _igtlNDArrayMessage_h
178 
179 
180 
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
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 Mon Nov 11 2013 05:19:48 for OpenIGTLink by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2012