VTK: Rendering/VR/vtkVRCollaborationClient.h Source File

| VTK 9.3.1

vtkVRCollaborationClient.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3
4 // This class provides collaboration support for VR using avatars
5 // It relies on ZeroMQ to communicate with a collaboration server
6 // to exchange avatar names and poses and potentially other messages.
7
8 #ifndef vtkVRCollaborationClient_h
9 #define vtkVRCollaborationClient_h
10
11 #include "vtkEventData.h" // for ivars
12 #include "vtkLogger.h" // for Verbosity enum
13 #include "vtkObject.h"
14 #include "vtkRenderingVRModule.h" // For export macro
15 #include "vtkSmartPointer.h" // method sig
16 #include "vtksys/CommandLineArguments.hxx" // for method sig
17 #include <array> // for ivar
18 #include <functional> // for ivars
19 #include <map> // for ivars
20 #include <memory> // for ivars, shared_ptr
21 #include <string> // for ivars
22 #include <vector> // for ivars
23
24 VTK_ABI_NAMESPACE_BEGIN
25 class vtkCallbackCommand;
26 class vtkOpenGLAvatar;
27 class vtkOpenGLRenderer;
28 class vtkOpenGLRenderWindow;
29 class vtkTransform;
30 class vtkVRCollaborationClientInternal;
31
32 class VTKRENDERINGVR_EXPORT vtkVRCollaborationClient : public vtkObject
33 {
34 public:
35 static vtkVRCollaborationClient* New();
36 vtkTypeMacro(vtkVRCollaborationClient, vtkObject);
37 void PrintSelf(ostream& os, vtkIndent indent) override;
38 vtkVRCollaborationClient(const vtkVRCollaborationClient&) = delete;
39 vtkVRCollaborationClient& operator=(const vtkVRCollaborationClient&) = delete;
40
41 // when sending messages we have to marshal arguments so we have a simple
42 // class to encapsulate an argument. The method to send a message takes a
43 // std::vector of arguments and there is a method to return a std::vector
44 // of arguments when receiving a message
45 enum ArgumentType
46 {
47 Double = 0,
48 Int32,
49 String
50 };
51
52 class VTKRENDERINGVR_EXPORT Argument
53 {
54 public:
55 bool GetString(std::string& result);
56 void SetString(std::string const& in);
57 bool GetStringVector(std::vector<std::string>& result);
58 void SetStringVector(std::vector<std::string> const& in);
59
60 bool GetDoubleVector(std::vector<double>& result);
61 void SetDoubleVector(double const* in, uint16_t size);
62 void SetDouble(double val);
63 bool GetDouble(double& result);
64
65 bool GetInt32Vector(std::vector<int32_t>& result);
66 void SetInt32Vector(int32_t const* in, uint16_t size);
67 void SetInt32(int32_t val);
68 bool GetInt32(int32_t& result);
69
70 ArgumentType Type;
71 uint16_t Count = 0;
72 std::shared_ptr<void> Data;
73 };
74
76
79 void SendAMessage(std::string const& msgType);
80 void SendAMessage(std::string const& msgType, std::vector<Argument> const& args);
81 std::vector<Argument> GetMessageArguments();
82 void SendPoseMessage(std::string const& msgType, int index, double pos[3], double dir[3]);
84
85 // call during the render loop to handle collaboration messages
86 virtual void Render();
87
88 // required call, true on success, pass the renderer you want the avatars added to
89 virtual bool Initialize(vtkOpenGLRenderer*);
90
91 // close the connection
92 void Disconnect();
93
94 // set the values for the collaboration connection
95 // Can be done through Set* methods or by passing in
96 // the command line arguments via AddArguments
97 virtual void AddArguments(vtksys::CommandLineArguments& arguments);
98 void SetCollabHost(std::string const& val) { this->CollabHost = val; }
99 void SetCollabSession(std::string const& val) { this->CollabSession = val; }
100 void SetCollabName(std::string const& val) { this->CollabName = val; }
101 void SetCollabPort(int val) { this->CollabPort = val; }
102
103 // to receive log/warning/error output
104 void SetLogCallback(
105 std::function<void(std::string const& data, vtkLogger::Verbosity verbosity)> cb)
106 {
107 this->Callback = cb;
108 }
109
110 // to override the default method of getting avatar scales
111 void SetScaleCallback(std::function<double()> cb) { this->ScaleCallback = cb; }
112
113 // return the renderer being used by this instance (assigned during Initialize())
114 vtkOpenGLRenderer* GetRenderer() { return this->Renderer; }
115
116 // is this instance connected to a collaboration server?
117 bool GetConnected() { return this->Connected; }
118
119 protected:
120 vtkVRCollaborationClient();
121 ~vtkVRCollaborationClient() override;
122
123 void Log(vtkLogger::Verbosity verbosity, std::string const& msg);
124
125 // provided values
126 std::string CollabID;
127 std::string CollabHost;
128 std::string CollabSession;
129 std::string CollabName;
130 int CollabPort;
131
132 std::function<void(std::string const& data, vtkLogger::Verbosity)> Callback;
133 std::function<double()> ScaleCallback;
134
135 bool DisplayOwnAvatar;
136 bool PublishAvailable;
137 void HandleCollabMessage();
138 bool AvatarIdle(std::string id);
139 void EraseIdleAvatars();
140 double NeedHeartbeat;
141 double NeedReply;
142 int RetryCount;
143
144 bool Connected;
145
146 // get existing avatar, or create new one, if needed, and return it.
147 vtkSmartPointer<vtkOpenGLAvatar> GetAvatar(std::string id);
148
149 void SendLatestDevicePoses();
150 void UpdateAvatarPoseFromCamera();
151
152 virtual void HandleBroadcastMessage(std::string const& otherID, std::string const& type);
153
154 vtkCallbackCommand* EventCommand;
155 static void EventCallback(
156 vtkObject* object, unsigned long event, void* clientdata, void* calldata);
157 long MoveObserver;
158
159 vtkOpenGLRenderer* Renderer;
160 vtkOpenGLRenderWindow* RenderWindow;
161
162 vtkNew<vtkTransform> TempTransform;
163
164 // used to throttle outgoing pose messages
165 double YourLastAvatarUpdateTime;
166 bool HasPoseForDevice[vtkEventDataNumberOfDevices];
167 struct Pose
168 {
169 std::array<double, 3> Position;
170 std::array<double, 4> Orientation;
171 };
172 Pose DevicePoses[vtkEventDataNumberOfDevices];
173
174 // dynamic set of avatars, keyed on IDs sent with updates.
175 std::map<std::string, vtkSmartPointer<vtkOpenGLAvatar>> Avatars;
176 std::map<std::string, double[vtkEventDataNumberOfDevices]> AvatarUpdateTime;
177
178 // PIMPL to keep zeromq out of the interface for this class
179 vtkVRCollaborationClientInternal* Internal;
180 };
181
182 VTK_ABI_NAMESPACE_END
183 #endif
vtkCallbackCommand
supports function callbacks
Definition: vtkCallbackCommand.h:49
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkLogger::Verbosity
Verbosity
Definition: vtkLogger.h:185
vtkNew< vtkTransform >
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkOpenGLAvatar
OpenGL Avatar.
Definition: vtkOpenGLAvatar.h:27
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:53
vtkOpenGLRenderer
OpenGL renderer.
Definition: vtkOpenGLRenderer.h:52
vtkSmartPointer
Hold a reference to a vtkObjectBase instance.
Definition: vtkSmartPointer.h:41
vtkTransform
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:59
vtkVRCollaborationClient::Argument
Definition: vtkVRCollaborationClient.h:53
vtkVRCollaborationClient::Argument::SetDoubleVector
void SetDoubleVector(double const *in, uint16_t size)
vtkVRCollaborationClient::Argument::Type
ArgumentType Type
Definition: vtkVRCollaborationClient.h:70
vtkVRCollaborationClient::Argument::GetStringVector
bool GetStringVector(std::vector< std::string > &result)
vtkVRCollaborationClient::Argument::GetDouble
bool GetDouble(double &result)
vtkVRCollaborationClient::Argument::Data
std::shared_ptr< void > Data
Definition: vtkVRCollaborationClient.h:72
vtkVRCollaborationClient::Argument::SetStringVector
void SetStringVector(std::vector< std::string > const &in)
vtkVRCollaborationClient::Argument::GetInt32
bool GetInt32(int32_t &result)
vtkVRCollaborationClient::Argument::SetInt32Vector
void SetInt32Vector(int32_t const *in, uint16_t size)
vtkVRCollaborationClient::Argument::GetString
bool GetString(std::string &result)
vtkVRCollaborationClient::Argument::SetInt32
void SetInt32(int32_t val)
vtkVRCollaborationClient::Argument::GetDoubleVector
bool GetDoubleVector(std::vector< double > &result)
vtkVRCollaborationClient::Argument::SetDouble
void SetDouble(double val)
vtkVRCollaborationClient::Argument::SetString
void SetString(std::string const &in)
vtkVRCollaborationClient::Argument::GetInt32Vector
bool GetInt32Vector(std::vector< int32_t > &result)
vtkVRCollaborationClient
Definition: vtkVRCollaborationClient.h:33
vtkVRCollaborationClient::Render
virtual void Render()
vtkVRCollaborationClient::AvatarIdle
bool AvatarIdle(std::string id)
vtkVRCollaborationClient::EventCallback
static void EventCallback(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
vtkVRCollaborationClient::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkVRCollaborationClient::NeedReply
double NeedReply
Definition: vtkVRCollaborationClient.h:141
vtkVRCollaborationClient::SendAMessage
void SendAMessage(std::string const &msgType, std::vector< Argument > const &args)
method signatures to send messages with Arguments and extract them out of messages
vtkVRCollaborationClient::Connected
bool Connected
Definition: vtkVRCollaborationClient.h:144
vtkVRCollaborationClient::AvatarUpdateTime
std::map< std::string, double[vtkEventDataNumberOfDevices]> AvatarUpdateTime
Definition: vtkVRCollaborationClient.h:176
vtkVRCollaborationClient::RenderWindow
vtkOpenGLRenderWindow * RenderWindow
Definition: vtkVRCollaborationClient.h:160
vtkVRCollaborationClient::DisplayOwnAvatar
bool DisplayOwnAvatar
Definition: vtkVRCollaborationClient.h:135
vtkVRCollaborationClient::HandleCollabMessage
void HandleCollabMessage()
vtkVRCollaborationClient::PublishAvailable
bool PublishAvailable
Definition: vtkVRCollaborationClient.h:136
vtkVRCollaborationClient::CollabName
std::string CollabName
Definition: vtkVRCollaborationClient.h:129
vtkVRCollaborationClient::vtkVRCollaborationClient
vtkVRCollaborationClient()
vtkVRCollaborationClient::vtkVRCollaborationClient
vtkVRCollaborationClient(const vtkVRCollaborationClient &)=delete
vtkVRCollaborationClient::SetCollabPort
void SetCollabPort(int val)
Definition: vtkVRCollaborationClient.h:101
vtkVRCollaborationClient::~vtkVRCollaborationClient
~vtkVRCollaborationClient() override
vtkVRCollaborationClient::SetCollabSession
void SetCollabSession(std::string const &val)
Definition: vtkVRCollaborationClient.h:99
vtkVRCollaborationClient::SendAMessage
void SendAMessage(std::string const &msgType)
method signatures to send messages with Arguments and extract them out of messages
vtkVRCollaborationClient::CollabID
std::string CollabID
Definition: vtkVRCollaborationClient.h:126
vtkVRCollaborationClient::Internal
vtkVRCollaborationClientInternal * Internal
Definition: vtkVRCollaborationClient.h:179
vtkVRCollaborationClient::operator=
vtkVRCollaborationClient & operator=(const vtkVRCollaborationClient &)=delete
vtkVRCollaborationClient::SetCollabName
void SetCollabName(std::string const &val)
Definition: vtkVRCollaborationClient.h:100
vtkVRCollaborationClient::Initialize
virtual bool Initialize(vtkOpenGLRenderer *)
vtkVRCollaborationClient::ArgumentType
ArgumentType
Definition: vtkVRCollaborationClient.h:46
vtkVRCollaborationClient::Int32
@ Int32
Definition: vtkVRCollaborationClient.h:48
vtkVRCollaborationClient::Renderer
vtkOpenGLRenderer * Renderer
Definition: vtkVRCollaborationClient.h:159
vtkVRCollaborationClient::Disconnect
void Disconnect()
vtkVRCollaborationClient::ScaleCallback
std::function< double()> ScaleCallback
Definition: vtkVRCollaborationClient.h:133
vtkVRCollaborationClient::Callback
std::function< void(std::string const &data, vtkLogger::Verbosity)> Callback
Definition: vtkVRCollaborationClient.h:132
vtkVRCollaborationClient::YourLastAvatarUpdateTime
double YourLastAvatarUpdateTime
Definition: vtkVRCollaborationClient.h:165
vtkVRCollaborationClient::HandleBroadcastMessage
virtual void HandleBroadcastMessage(std::string const &otherID, std::string const &type)
vtkVRCollaborationClient::SetCollabHost
void SetCollabHost(std::string const &val)
Definition: vtkVRCollaborationClient.h:98
vtkVRCollaborationClient::New
static vtkVRCollaborationClient * New()
vtkVRCollaborationClient::NeedHeartbeat
double NeedHeartbeat
Definition: vtkVRCollaborationClient.h:140
vtkVRCollaborationClient::CollabHost
std::string CollabHost
Definition: vtkVRCollaborationClient.h:127
vtkVRCollaborationClient::CollabSession
std::string CollabSession
Definition: vtkVRCollaborationClient.h:128
vtkVRCollaborationClient::Avatars
std::map< std::string, vtkSmartPointer< vtkOpenGLAvatar > > Avatars
Definition: vtkVRCollaborationClient.h:175
vtkVRCollaborationClient::RetryCount
int RetryCount
Definition: vtkVRCollaborationClient.h:142
vtkVRCollaborationClient::TempTransform
vtkNew< vtkTransform > TempTransform
Definition: vtkVRCollaborationClient.h:162
vtkVRCollaborationClient::GetAvatar
vtkSmartPointer< vtkOpenGLAvatar > GetAvatar(std::string id)
vtkVRCollaborationClient::AddArguments
virtual void AddArguments(vtksys::CommandLineArguments &arguments)
vtkVRCollaborationClient::EventCommand
vtkCallbackCommand * EventCommand
Definition: vtkVRCollaborationClient.h:154
vtkVRCollaborationClient::SendPoseMessage
void SendPoseMessage(std::string const &msgType, int index, double pos[3], double dir[3])
method signatures to send messages with Arguments and extract them out of messages
vtkVRCollaborationClient::CollabPort
int CollabPort
Definition: vtkVRCollaborationClient.h:130
vtkVRCollaborationClient::MoveObserver
long MoveObserver
Definition: vtkVRCollaborationClient.h:157
vtkVRCollaborationClient::UpdateAvatarPoseFromCamera
void UpdateAvatarPoseFromCamera()
vtkVRCollaborationClient::Log
void Log(vtkLogger::Verbosity verbosity, std::string const &msg)
vtkVRCollaborationClient::GetRenderer
vtkOpenGLRenderer * GetRenderer()
Definition: vtkVRCollaborationClient.h:114
vtkVRCollaborationClient::EraseIdleAvatars
void EraseIdleAvatars()
vtkVRCollaborationClient::SendLatestDevicePoses
void SendLatestDevicePoses()
vtkVRCollaborationClient::SetScaleCallback
void SetScaleCallback(std::function< double()> cb)
Definition: vtkVRCollaborationClient.h:111
vtkVRCollaborationClient::SetLogCallback
void SetLogCallback(std::function< void(std::string const &data, vtkLogger::Verbosity verbosity)> cb)
Definition: vtkVRCollaborationClient.h:104
vtkVRCollaborationClient::GetMessageArguments
std::vector< Argument > GetMessageArguments()
method signatures to send messages with Arguments and extract them out of messages
vtkVRCollaborationClient::GetConnected
bool GetConnected()
Definition: vtkVRCollaborationClient.h:117
vtkX3D::function
@ function
Definition: vtkX3D.h:249
vtkX3D::dir
@ dir
Definition: vtkX3D.h:324
vtkX3D::type
@ type
Definition: vtkX3D.h:516
vtkX3D::size
@ size
Definition: vtkX3D.h:253
vtkX3D::index
@ index
Definition: vtkX3D.h:246
vtkX3D::data
@ data
Definition: vtkX3D.h:315
vtkX3D::string
@ string
Definition: vtkX3D.h:490
vtkVRCollaborationClient::Pose
Definition: vtkVRCollaborationClient.h:168
vtkVRCollaborationClient::Pose::Orientation
std::array< double, 4 > Orientation
Definition: vtkVRCollaborationClient.h:170
vtkVRCollaborationClient::Pose::Position
std::array< double, 3 > Position
Definition: vtkVRCollaborationClient.h:169
vtkEventData.h
vtkEventDataNumberOfDevices
const int vtkEventDataNumberOfDevices
Definition: vtkEventData.h:25
vtkLogger.h
vtkObject.h
vtkSmartPointer.h