/
igtlColorTableMessage.cxx
105 lines (73 loc) · 2.61 KB
/
igtlColorTableMessage.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*=========================================================================
Program: The OpenIGTLink Library
Language: C++
Web page: http://openigtlink.org/
Copyright (c) Insight Software Consortium. All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "igtlColorTableMessage.h"
#include "igtl_header.h"
#include "igtl_colortable.h"
namespace igtl {
ColorTableMessage::ColorTableMessage():
MessageBase()
{
indexType = INDEX_UINT8;
mapType = MAP_UINT8;
m_ColorTableHeader = NULL;
m_ColorTable = NULL;
m_SendMessageType = "COLORT";
/// ColorTableMessage stay the same as previous versions, set m_Version = 1
/// to make the pack and unpack procedures the same as OpenIGTLink_PROTOCOL_VERSION 1
#if OpenIGTLink_HEADER_VERSION >= 2
m_HeaderVersion = IGTL_HEADER_VERSION_1;
#endif
}
ColorTableMessage::~ColorTableMessage()
{
}
void ColorTableMessage::AllocateTable()
{
// Memory area to store image scalar is allocated with
// message and image header, by using AllocatePack() implemented
// in the parent class.
AllocateBuffer();
m_ColorTableHeader = m_Content;
m_ColorTable = &m_ColorTableHeader[IGTL_COLORTABLE_HEADER_SIZE];
}
void* ColorTableMessage::GetTablePointer()
{
return (void*)m_ColorTable;
}
int ColorTableMessage::GetColorTableSize()
{
igtl_colortable_header header;
header.indexType = this->indexType;
header.mapType = this->mapType;
return (int) igtl_colortable_get_table_size(&header);
}
igtlUint64 ColorTableMessage::CalculateContentBufferSize()
{
return GetColorTableSize() + IGTL_COLORTABLE_HEADER_SIZE;
}
int ColorTableMessage::PackContent()
{
igtl_colortable_header* colortable_header = (igtl_colortable_header*)m_ColorTableHeader;
colortable_header->indexType = this->indexType;
colortable_header->mapType = this->mapType;
igtl_colortable_convert_byte_order(colortable_header, (void*)m_ColorTable);
return 1;
}
int ColorTableMessage::UnpackContent()
{
this->m_ColorTableHeader = this->m_Content;
this->m_ColorTable = &(this->m_Content[IGTL_COLORTABLE_HEADER_SIZE]);
igtl_colortable_header* colortable_header = (igtl_colortable_header*)this->m_ColorTableHeader;
igtl_colortable_convert_byte_order(colortable_header, (void*)this->m_ColorTable);
this->indexType = colortable_header->indexType;
this->mapType = colortable_header->mapType;
return 1;
}
} // namespace igtl