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  Module: $HeadURL: http://svn.na-mic.org/NAMICSandBox/trunk/OpenIGTLink2_beta/Source/igtlNDArrayMessage.h $
5  Language: C++
6  Date: $Date: 2009-12-16 23:58:02 -0500 (Wed, 16 Dec 2009) $
7  Version: $Revision: 5466 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10 
11  This software is distributed WITHOUT ANY WARRANTY; without even
12  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13  PURPOSE. See the above copyright notices for more information.
14 
15 =========================================================================*/
16 
17 #ifndef __igtlNDArrayMessage_h
18 #define __igtlNDArrayMessage_h
19 
20 #include <string>
21 
22 #include "igtlObject.h"
23 #include "igtlMath.h"
24 #include "igtlMessageBase.h"
25 #include "igtlTypes.h"
26 
27 #define IGTL_STRING_MESSAGE_DEFAULT_ENCODING 3 /* Default encoding -- ANSI-X3.5-1968 */
28 
29 namespace igtl
30 {
31 
33 {
34 public:
35  typedef std::vector<igtlUint16> IndexType;
36 
37 protected:
38  ArrayBase();
39  ~ArrayBase();
40 
41 public:
42 
43  int SetSize(IndexType size);
44  IndexType GetSize() { return this->m_Size; };
45  int GetDimension() { return this->m_Size.size(); };
46 
47  int SetArray(void * array);
48  igtlUint64 GetRawArraySize();
49  void * GetRawArray() { return this->m_ByteArray; };
50 
51 protected:
52  virtual int GetElementSize() = 0;
53  igtlUint32 GetNumberOfElements();
54  igtlUint32 Get1DIndex(IndexType index);
55 
56 private:
57  IndexType m_Size;
58  void * m_ByteArray;
59 
60 };
61 
62 
63 template <typename T>
65 {
66 public:
67  int SetValue(IndexType index, T value)
68  {
69  if (Get1DIndex(index) <= GetNumberOfElements()) {
70  * (T *) this->m_ByteArray[Get1DIndex(index) * sizeof(T)] = value;
71  return 1;
72  } else {
73  return 0;
74  }
75  }
76  int GetValue(IndexType index, T & value)
77  {
78  if (Get1DIndex(index) <= GetNumberOfElements()) {
79  value = * (T *) this->m_ByteArray[Get1DIndex(index) * sizeof(T)];
80  return 1;
81  } else {
82  return 0;
83  }
84  }
85 
86 protected:
87  virtual int GetElementSize() { return sizeof(T); };
88 };
89 
90 
92 {
93 public:
94  enum {
95  TYPE_INT8 = 2,
96  TYPE_UINT8 = 3,
97  TYPE_INT16 = 4,
98  TYPE_UINT16 = 5,
99  TYPE_INT32 = 6,
100  TYPE_UINT32 = 7,
101  TYPE_FLOAT32 = 10,
102  TYPE_FLOAT64 = 11,
103  TYPE_COMPLEX = 13,
104  };
105 
106 public:
111 
114 
115 public:
116 
117  int SetArray(int type, ArrayBase * a);
118  ArrayBase * GetArray();
119  int GetType();
120 
121 protected:
122  NDArrayMessage();
123  ~NDArrayMessage();
124 
125 protected:
126 
127  virtual int GetBodyPackSize();
128  virtual int PackBody();
129  virtual int UnpackBody();
130 
132  int m_Type;
133 
134 };
135 
136 
137 } // namespace igtl
138 
139 #endif // _igtlNDArrayMessage_h
140 
141 
142 
143 

Generated at Thu Mar 20 2014 16:32:06 for OpenIGTLink by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2000