forked from openigtlink/OpenIGTLink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathigtlPolyDataMessage.h
434 lines (318 loc) · 13.2 KB
/
igtlPolyDataMessage.h
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
/*=========================================================================
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.
=========================================================================*/
#ifndef __igtlPolyDataMessage_h
#define __igtlPolyDataMessage_h
#include <string>
#include "igtlObject.h"
#include "igtlMacro.h"
#include "igtlMath.h"
#include "igtlMessageBase.h"
#include "igtlTypes.h"
namespace igtl
{
/// A class for the GET_POLYDATA message type.
class IGTLCommon_EXPORT GetPolyDataMessage: public MessageBase
{
public:
igtlTypeMacro(igtl::GetPolyDataMessage, igtl::MessageBase);
igtlNewMacro(igtl::GetPolyDataMessage);
protected:
GetPolyDataMessage();
~GetPolyDataMessage() {};
protected:
virtual int CalculateContentBufferSize() { return 0; };
virtual int PackContent() { AllocateBuffer(); return 1; };
virtual int UnpackContent() { return 1; };
};
/// A class for the RTS_POLYDATA message type.
class IGTLCommon_EXPORT RTSPolyDataMessage : public MessageBase
{
public:
igtlTypeMacro(igtl::RTSPolyDataMessage, igtl::MessageBase);
igtlNewMacro(igtl::RTSPolyDataMessage);
bool GetStatus() const;
void SetStatus(bool status);
protected:
RTSPolyDataMessage() : MessageBase() { this->m_SendMessageType = "RTS_POLYDATA"; };
~RTSPolyDataMessage() {};
protected:
virtual int CalculateContentBufferSize();
virtual int PackContent();
virtual int UnpackContent();
protected:
/// Result of the previous GET_POLYDATA/POLYDATA message
igtl_uint8 m_Status;
};
/// A class for the STP_POLYDATA message type.
class IGTLCommon_EXPORT StopPolyDataMessage: public MessageBase
{
public:
igtlTypeMacro(igtl::StopPolyDataMessage, igtl::MessageBase);
igtlNewMacro(igtl::StopPolyDataMessage);
protected:
StopPolyDataMessage() : MessageBase() { this->m_SendMessageType = "STP_POLYDATA"; };
~StopPolyDataMessage() {};
protected:
virtual int GetBodyPackSize() { return 0; };
virtual int PackBody() { AllocatePack(); return 1; };
virtual int UnpackBody() { return 1; };
};
/// A class for the STT_POLYDATA message type.
class IGTLCommon_EXPORT StartPolyDataMessage : public MessageBase
{
public:
igtlTypeMacro(igtl::StartPolyDataMessage, igtl::MessageBase);
igtlNewMacro(igtl::StartPolyDataMessage);
protected:
StartPolyDataMessage() : MessageBase() { this->m_SendMessageType = "STT_POLYDATA"; };
~StartPolyDataMessage() {};
protected:
virtual int GetBodyPackSize() { return 0; };
virtual int PackBody() { AllocatePack(); return 1; };
virtual int UnpackBody() { return 1; };
};
// A class to manage a point array.
class IGTLCommon_EXPORT PolyDataPointArray : public Object {
public:
/// A vector to represent coordinates of a point.
typedef std::vector<igtlFloat32> Point;
public:
igtlTypeMacro(igtl::PolyDataPointArray, igtl::Object);
igtlNewMacro(igtl::PolyDataPointArray);
protected:
PolyDataPointArray();
~PolyDataPointArray();
public:
/// Clears the all points in the list.
void Clear();
/// Sets the number of points. This function will change the size of the list.
void SetNumberOfPoints(int n);
/// Gets the number of points in the list.
int GetNumberOfPoints();
/// Substitutes the point specified by 'id' with a point specified by 'point'.
/// The 'point' contains the x, y, and z coordinates of the point.
int SetPoint(unsigned int id, igtlFloat32 * point);
/// Substitutes the point specified by 'id' with a point specified by 'x', 'y' and 'z'.
int SetPoint(unsigned int id, igtlFloat32 x, igtlFloat32 y, igtlFloat32 z);
/// Adds a point specified by 'point' to the list.
/// The 'point' contains the x, y, and z coordinates of the point.
int AddPoint(igtlFloat32 * point);
/// Adds a point 'point' specified by 'x', 'y' and 'z'.
int AddPoint(igtlFloat32 x, igtlFloat32 y, igtlFloat32 z);
/// Gets the coordinates of the point specified by 'id'
int GetPoint(unsigned int id, igtlFloat32 & x, igtlFloat32 & y, igtlFloat32 & z);
/// Gets the coordinates of the point specified by 'id'
int GetPoint(unsigned int id, igtlFloat32 * point);
/// Implement support for C++11 ranged for loops
igtlRangeBasedForHeaderMemberMacro(std::vector<Point>);
private:
/// A list of the points.
std::vector< Point > m_Data;
};
igtlRangeBasedForHeaderExternalMacro(PolyDataPointArray, std::vector<PolyDataPointArray::Point>, IGTLCommon_EXPORT);
// The PolyDataCellArray class is used to pass vertices, lines, polygons, and triangle strips
class IGTLCommon_EXPORT PolyDataCellArray : public Object {
public:
typedef std::list<igtlUint32> Cell;
enum {
NULL_POINT = 0xFFFFFFFF,
};
public:
igtlTypeMacro(igtl::PolyDataCellArray, igtl::Object);
igtlNewMacro(igtl::PolyDataCellArray);
protected:
PolyDataCellArray();
~PolyDataCellArray();
public:
/// Clears the cell array.
void Clear();
/// Gets the number of cells in the array.
igtlUint32 GetNumberOfCells();
/// Adds an array of cells stored in 'cell'. The number of cells is specified by 'n'.
void AddCell(int n, igtlUint32 * cell);
/// Adds an array of cells stored in 'cell'.
void AddCell(const Cell& cell);
/// GetTotalSize() returns the total memory size of the cell data array in
/// POLYDATA message. Cell data array is array of cell data, consisting of
/// <number of points> and array of <point indecies>. Both <number of points>
/// and <point indecies> are unsigned 32-bit integer.
/// Consequently, the total size can be calculated by:
/// sizeof(igtlUint32) * (number of points for 0th cell + 1) + (number of points for 1th cell + 1)
/// ... + (number of points for (N-1)th cell + 1). Note that this includes the first igtlUint32 value
/// that specifies the number of points in each cell.
igtlUint32 GetTotalSize();
/// Gets the size of the cell specified by 'id'.
igtlUint32 GetCellSize(unsigned int id);
/// Gets the cell specified by the 'id'. A list of points in the cell will be stored in the
/// 'cell'. A memory area sufficient to store the points in the cell must be allocated
/// before calling GetCell() function, and specified as 'cell'.
int GetCell(unsigned int id, igtlUint32 * cell);
/// Gets the cell specified by the 'id'. A list of points in the cell will be stored in the 'cell'.
int GetCell(unsigned int id, Cell& cell);
/// Implement support for C++11 ranged for loops
igtlRangeBasedForHeaderMemberMacro(std::vector<Cell>);
private:
/// A lists of the cells. Each cell consists of multiple points.
std::vector<Cell> m_Data;
};
/// Implement support for C++11 ranged for loops
igtlRangeBasedForHeaderExternalMacro(PolyDataCellArray, std::vector<PolyDataCellArray::Cell>, IGTLCommon_EXPORT);
/// Attribute class used for passing attribute data.
class IGTLCommon_EXPORT PolyDataAttribute : public Object {
public:
/// Point and cell types.
enum {
POINT_SCALAR = 0x00,
POINT_VECTOR = 0x01,
POINT_NORMAL = 0x02,
POINT_TENSOR = 0x03,
POINT_RGBA = 0x04,
POINT_TCOORDS = 0x05,
CELL_SCALAR = 0x10,
CELL_VECTOR = 0x11,
CELL_NORMAL = 0x12,
CELL_TENSOR = 0x13,
CELL_RGBA = 0x14,
CELL_TCOORDS = 0x15
};
public:
igtlTypeMacro(igtl::PolyDataAttribute, igtl::Object);
igtlNewMacro(igtl::PolyDataAttribute);
protected:
PolyDataAttribute();
~PolyDataAttribute();
public:
/// Clears the attributes
void Clear();
/// SetType() is used to set the attribute type. If the attribute is set properly,
/// the function returns the type value (POINT_* or CELL_*). Otherwise
/// the function returns negative value. The second argument will be ignored
/// if 't' is neither POINT_SCALAR nor CELL_SCALAR.
/// If the POINT_SCALAR and CELL_SCALAR is specified as 't', the number of
/// components can be specified as the second argument. The number of
/// components must be 0 < n < 128.
int SetType(int t, int n=1);
/// Gets the attribute type.
igtlUint8 GetType() { return this->m_Type; };
/// Gets the number of components. The number depends on the type of the points/cells e.g.
/// 3 in case of POINT_VECTOR.
igtlUint32 GetNumberOfComponents();
/// Sets the size of the attribute.
igtlUint32 SetSize(igtlUint32 size);
/// Gets the size of the attribute.
igtlUint32 GetSize();
/// Sets the name of the attribute.
void SetName(const char * name);
/// Gets the name of the attribute.
const char* GetName() { return this->m_Name.c_str(); };
/// Sets the attribute by byte array.
int SetData(igtlFloat32 * data);
/// Gets the attribute as a byte array.
int GetData(igtlFloat32 * data);
/// Sets the Nth data.
int SetNthData(unsigned int n, igtlFloat32 * data);
/// Gets the Nth data.
int GetNthData(unsigned int n, igtlFloat32 * data);
/// Gets the Nth data.
int GetNthData(unsigned int n, std::vector<igtlFloat32>& data);
/// Implement support for C++11 ranged for loops
std::vector<igtlFloat32>::iterator begin();
std::vector<igtlFloat32>::iterator end();
std::vector<igtlFloat32>::const_iterator begin() const;
std::vector<igtlFloat32>::const_iterator end() const;
std::vector<igtlFloat32>::reverse_iterator rbegin();
std::vector<igtlFloat32>::reverse_iterator rend();
std::vector<igtlFloat32>::const_reverse_iterator rbegin() const;
std::vector<igtlFloat32>::const_reverse_iterator rend() const;
private:
/// The attribute type.
igtlUint8 m_Type;
/// The number of components.
igtlUint8 m_NComponents;
/// The size of the attribute.
igtlUint32 m_Size;
/// The name of the attribute.
std::string m_Name;
/// The list of attributes.
std::vector<igtlFloat32> m_Data;
};
/// Implement support for C++11 ranged for loops
IGTLCommon_EXPORT std::vector<igtlFloat32>::iterator begin(PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::iterator end(PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::const_iterator begin(const PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::const_iterator end(const PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::reverse_iterator rbegin(PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::reverse_iterator rend(PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::const_reverse_iterator rbegin(const PolyDataAttribute& list);
IGTLCommon_EXPORT std::vector<igtlFloat32>::const_reverse_iterator rend(const PolyDataAttribute& list);
/// A class for the POLYDATA message type.
class IGTLCommon_EXPORT PolyDataMessage: public MessageBase
{
public:
typedef std::vector<PolyDataAttribute::Pointer> AttributeList;
igtlTypeMacro(igtl::PolyDataMessage, igtl::MessageBase);
igtlNewMacro(igtl::PolyDataMessage);
public:
/// Clears the polydata.
void Clear();
/// Sets an array of points.
igtlSetObjectMacro(Points, PolyDataPointArray);
/// Gets an array of points.
igtlGetObjectMacro(Points, PolyDataPointArray);
/// Sets an array of vertices.
igtlSetObjectMacro(Vertices, PolyDataCellArray);
/// Gets an array of vertices.
igtlGetObjectMacro(Vertices, PolyDataCellArray);
/// Sets an array of lines.
igtlSetObjectMacro(Lines, PolyDataCellArray);
/// Gets an array of lines.
igtlGetObjectMacro(Lines, PolyDataCellArray);
/// Sets an array of polygons.
igtlSetObjectMacro(Polygons, PolyDataCellArray);
/// Gets an array of polygons.
igtlGetObjectMacro(Polygons, PolyDataCellArray);
/// Sets an array of triangle strips.
igtlSetObjectMacro(TriangleStrips, PolyDataCellArray);
/// Gets an array of triangle strips.
igtlGetObjectMacro(TriangleStrips, PolyDataCellArray);
/// Clears the attributes.
void ClearAttributes();
/// Adds an attribute.
void AddAttribute(PolyDataAttribute * att);
/// Gets the number of attributes.
int GetNumberOfAttributes();
/// Gets an attribute specified by 'id'.
PolyDataAttribute * GetAttribute(AttributeList::size_type id);
/// Gets an attribute specified by 'name'.
PolyDataAttribute * GetAttribute(const std::string& name);
/// Gets an attribute specified by 'type'.
PolyDataAttribute * GetAttribute(int type);
protected:
PolyDataMessage();
~PolyDataMessage();
protected:
virtual int CalculateContentBufferSize();
virtual int PackContent();
virtual int UnpackContent();
/// A pointer to the array of points.
PolyDataPointArray::Pointer m_Points;
/// A pointer to the array of vertices.
PolyDataCellArray::Pointer m_Vertices;
/// A pointer to the array of lines.
PolyDataCellArray::Pointer m_Lines;
/// A pointer to the array of polygons.
PolyDataCellArray::Pointer m_Polygons;
/// A pointer to the array of triangle strips.
PolyDataCellArray::Pointer m_TriangleStrips;
/// A list of pointers to the attributes.
AttributeList m_Attributes;
};
} // namespace igtl
#endif // _igtlPolyDataMessage_h