Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __igtlNDArrayMessage_h
00018 #define __igtlNDArrayMessage_h
00019
00020 #include <string>
00021
00022 #include "igtlObject.h"
00023 #include "igtlMath.h"
00024 #include "igtlMessageBase.h"
00025 #include "igtlTypes.h"
00026
00027 #define IGTL_STRING_MESSAGE_DEFAULT_ENCODING 3
00028
00029 namespace igtl
00030 {
00031
00032 class IGTLCommon_EXPORT ArrayBase
00033 {
00034 public:
00035 typedef std::vector<igtlUint16> IndexType;
00036
00037 protected:
00038 ArrayBase();
00039 ~ArrayBase();
00040
00041 public:
00042
00043 int SetSize(IndexType size);
00044 IndexType GetSize() { return this->m_Size; };
00045 int GetDimension() { return this->m_Size.size(); };
00046
00047 int SetArray(void * array);
00048 igtlUint64 GetRawArraySize();
00049 void * GetRawArray() { return this->m_ByteArray; };
00050
00051 protected:
00052 virtual int GetElementSize() = 0;
00053 igtlUint32 GetNumberOfElements();
00054 igtlUint32 Get1DIndex(IndexType index);
00055
00056 private:
00057 IndexType m_Size;
00058 void * m_ByteArray;
00059
00060 };
00061
00062
00063 template <typename T>
00064 class IGTLCommon_EXPORT Array : public ArrayBase
00065 {
00066 public:
00067 int SetValue(IndexType index, T value)
00068 {
00069 if (Get1DIndex(index) <= GetNumberOfElements()) {
00070 * (T *) this->m_ByteArray[Get1DIndex(index) * sizeof(T)] = value;
00071 return 1;
00072 } else {
00073 return 0;
00074 }
00075 }
00076 int GetValue(IndexType index, T & value)
00077 {
00078 if (Get1DIndex(index) <= GetNumberOfElements()) {
00079 value = * (T *) this->m_ByteArray[Get1DIndex(index) * sizeof(T)];
00080 return 1;
00081 } else {
00082 return 0;
00083 }
00084 }
00085
00086 protected:
00087 virtual int GetElementSize() { return sizeof(T); };
00088 };
00089
00090
00091 class IGTLCommon_EXPORT NDArrayMessage: public MessageBase
00092 {
00093 public:
00094 enum {
00095 TYPE_INT8 = 2,
00096 TYPE_UINT8 = 3,
00097 TYPE_INT16 = 4,
00098 TYPE_UINT16 = 5,
00099 TYPE_INT32 = 6,
00100 TYPE_UINT32 = 7,
00101 TYPE_FLOAT32 = 10,
00102 TYPE_FLOAT64 = 11,
00103 TYPE_COMPLEX = 13,
00104 };
00105
00106 public:
00107 typedef NDArrayMessage Self;
00108 typedef MessageBase Superclass;
00109 typedef SmartPointer<Self> Pointer;
00110 typedef SmartPointer<const Self> ConstPointer;
00111
00112 igtlTypeMacro(igtl::NDArrayMessage, igtl::MessageBase);
00113 igtlNewMacro(igtl::NDArrayMessage);
00114
00115 public:
00116
00117 int SetArray(int type, ArrayBase * a);
00118 ArrayBase * GetArray();
00119 int GetType();
00120
00121 protected:
00122 NDArrayMessage();
00123 ~NDArrayMessage();
00124
00125 protected:
00126
00127 virtual int GetBodyPackSize();
00128 virtual int PackBody();
00129 virtual int UnpackBody();
00130
00131 ArrayBase * m_Array;
00132 int m_Type;
00133
00134 };
00135
00136
00137 }
00138
00139 #endif // _igtlNDArrayMessage_h
00140
00141
00142
00143