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
27namespace igtl
28{
29
31{
32public:
33
35 typedef std::vector<igtlUint16> IndexType;
36
37protected:
40
41public:
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
62protected:
63
65 virtual int GetElementSize() = 0;
66
68 igtlUint32 GetNumberOfElements();
69
73 igtlUint32 Get1DIndex(IndexType index);
74
75private:
76
78 IndexType m_Size;
79
81 void * m_ByteArray;
82
83};
84
85
86template <typename T>
88{
89public:
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
114protected:
115
117 virtual int GetElementSize() { return sizeof(T); };
118};
119
120
122{
123public:
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
138public:
143
146
147public:
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
158protected:
161
162protected:
163
164 virtual int GetBodyPackSize();
165 virtual int PackBody();
166 virtual int UnpackBody();
167
170
173
174};
175
176
177} // namespace igtl
178
179#endif // _igtlNDArrayMessage_h
180
181
182
virtual int GetElementSize()=0
Gets the size of a element of the array.
igtlUint32 GetNumberOfElements()
Gets the number of elements in the array.
std::vector< igtlUint16 > IndexType
Vector type for an index of N-D array.
IndexType GetSize()
Gets the size of the N-D array.
int SetSize(IndexType size)
Sets the size of the N-D array. Returns non-zero value, if success.
void * GetRawArray()
Gets the raw byte array stored in the class.
int GetDimension()
Gets the dimension of the N-D array.
int SetArray(void *array)
igtlUint64 GetRawArraySize()
Gets the size of the raw byte array stored in the class.
igtlUint32 Get1DIndex(IndexType index)
int SetValue(IndexType index, T value)
Sets a value of the element specified by 'index'.
virtual int GetElementSize()
Gets the size of elements (e.g. 1 byte in case of 8-bit integer)
int GetValue(IndexType index, T &value)
Gets a value of the element specified by 'index'.
int SetArray(int type, ArrayBase *a)
Sets an array with an element type.
int m_Type
A variable for the type of the N-D array.
ArrayBase * GetArray()
Gets a pointer to the array.
SmartPointer< Self > Pointer
ArrayBase * m_Array
A pointer to the N-D array.
virtual int GetBodyPackSize()
Gets the size of the serialized body.
igtlNewMacro(igtl::NDArrayMessage)
int GetType()
Gets the type of elements of the array. (e.g. TYPE_INT8)
virtual int UnpackBody()
Unpacks (deserialize) the body. Must be implemented in a child class.
virtual int PackBody()
Packs (serialize) the body. Must be implemented in a child class.
igtlTypeMacro(igtl::NDArrayMessage, igtl::MessageBase)
SmartPointer< const Self > ConstPointer
Implements transparent reference counting.
#define IGTLCommon_EXPORT
The "igtl" namespace contains all OpenIGTLink classes. There are several nested namespaces within the...

Generated for OpenIGTLink by Doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2012