File: igtlPositionMessage.h

package info (click to toggle)
openigtlink 3.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,080 kB
  • sloc: cpp: 20,076; ansic: 6,704; sh: 227; perl: 74; makefile: 46
file content (124 lines) | stat: -rw-r--r-- 4,244 bytes parent folder | download
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
/*=========================================================================

  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 __igtlPositionMessage_h
#define __igtlPositionMessage_h

#include "igtlObject.h"
#include "igtlMath.h"
#include "igtlMessageBase.h"
#include "igtlTypes.h"

namespace igtl
{

/// The POSITION data type is used to transfer position and orientation information.
/// The data are a combination of 3-dimensional vector for the position and quaternion
/// for the orientation. Although equivalent position and orientation can be described
/// with the TRANSFORM data type, the POSITION data type has the advantage of smaller
/// data size (19%). It is therefore more suitable for pushing high frame-rate data
/// from tracking devices.
class IGTLCommon_EXPORT PositionMessage: public MessageBase
{
public:

  /// Types of message formats. The format of the POSITION message type can contain
  /// only a 3-element position vector (POSITION_ONLY), a combination of 3-element
  /// position vector and 3-element quaternion (WITH_QUATERNION3), or a combination
  /// of 3-element position vector and 4-element quaternion (ALL). 
  enum {
    POSITION_ONLY =  1,
    WITH_QUATERNION3,
    ALL,
  };

public:
  typedef PositionMessage                Self;
  typedef MessageBase                    Superclass;
  typedef SmartPointer<Self>             Pointer;
  typedef SmartPointer<const Self>       ConstPointer;

  igtlTypeMacro(igtl::PositionMessage, igtl::MessageBase);
  igtlNewMacro(igtl::PositionMessage);

public:

  /// Initializes the class.
  void         Init();

  /// Sets the type of the pack. 't' must be either POSITION_ONLY, WITH_QUATERNION3, or ALL.
  void         SetPackType(int t); /* POSITION_ONLY / WITH_QUATERNION3 / ALL */

  /// Gets the type of the pack. The returned value must be either POSITION_ONLY, WITH_QUATERNION3, or ALL.
  int          GetPackType()  { return  m_PackType; };

  /// Specifies the pack type by body size (in most case obtained from general header).
  int          SetPackTypeByContentSize(int s);

  /// Sets the position by 3-element array of x, y, and z coordinates.
  void         SetPosition(const float* pos);

  /// Sets the position by x, y, and z coordinates.
  void         SetPosition(float x, float y, float z);

  /// Sets the quaternion by 4-element array.
  void         SetQuaternion(const float* quat);

  /// Sets the quaternion by elements of the quaternion (ox, oy, oz and w).
  void         SetQuaternion(float ox, float oy, float oz, float w);

  /// Gets the position. The function substitutes 3-element array of x, y and z coordinates in 'pos'.
  void         GetPosition(float* pos);

  /// Gets the position. The function substitutes the coordinates in 'x', 'y', and 'z'.
  void         GetPosition(float* x, float* y, float* z);

  /// Gets the quaternion. The function substitutes the array of elements of the quaternion in 'quat'.
  void         GetQuaternion(float* quat);

  /// Gets the quaternion. The function substitutes the elements of the quaternion in 'ox', 'oy', 'oz' and 'w'.
  void         GetQuaternion(float* ox, float* oy, float* oz, float* w);

  /// Sets the message header.
  // TODO: Is this needed or integrated in igtlMessageBase?
  virtual int SetMessageHeader(const MessageHeader* mb);

protected:
  PositionMessage();
  ~PositionMessage();
  
protected:

  virtual int  CalculateContentBufferSize();
  virtual int  PackContent();
  virtual int  UnpackContent();

  /// The type of message formats (either POSITION_ONLY, WITH_QUATERNION3, or ALL).
  igtlInt32    m_PackType;

  /// An array of x, y, and z coordinates for the position.
  igtlFloat32  m_Position[3];

  /// An array of ox, oy, oz, and w elements for the quaternion.
  igtlFloat32  m_Quaternion[4];

};


} // namespace igtl

#endif // _igtlPositionMessage_h