VTK  9.1.0
vtkVRCollaborationClient.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4
5 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6 All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13=========================================================================*/
14
15// This class provides collaboration support for VR using avatars
16// It relies on ZeroMQ to communicate with a collaboration server
17// to exchance avatar names and poses and potentially other messages.
18
19#ifndef vtkVRCollaborationClient_h
20#define vtkVRCollaborationClient_h
21
22#include "vtkEventData.h" // for ivars
23#include "vtkLogger.h" // for Verbosity enum
24#include "vtkObject.h"
25#include "vtkRenderingVRModule.h" // For export macro
26#include "vtkSmartPointer.h" // method sig
27#include "vtksys/CommandLineArguments.hxx" // for method sig
28#include <array> // for ivar
29#include <functional> // for ivars
30#include <map> // for ivars
31#include <memory> // for ivars, shared_ptr
32#include <string> // for ivars
33#include <vector> // for ivars
34
36class vtkOpenGLAvatar;
39class vtkTransform;
40class vtkVRCollaborationClientInternal;
41
42class VTKRENDERINGVR_EXPORT vtkVRCollaborationClient : public vtkObject
43{
44public:
47 void PrintSelf(ostream& os, vtkIndent indent) override;
50
51 // when sending messages we have to marshal arguments so we have a simple
52 // class to encapsulate an argument. The method to send a message takes a
53 // std::vector of arguments and there is a method to return a std::vector
54 // of arguments when receiving a message
56 {
57 Double = 0,
59 String
60 };
61
62 class VTKRENDERINGVR_EXPORT Argument
63 {
64 public:
65 bool GetString(std::string& result);
66 void SetString(std::string const& in);
67 bool GetStringVector(std::vector<std::string>& result);
68 void SetStringVector(std::vector<std::string> const& in);
69
70 bool GetDoubleVector(std::vector<double>& result);
71 void SetDoubleVector(double const* in, uint16_t size);
72 void SetDouble(double val);
73 bool GetDouble(double& result);
74
75 bool GetInt32Vector(std::vector<int32_t>& result);
76 void SetInt32Vector(int32_t const* in, uint16_t size);
77 void SetInt32(int32_t val);
78 bool GetInt32(int32_t& result);
79
81 uint16_t Count = 0;
82 std::shared_ptr<void> Data;
83 };
84
86
89 void SendAMessage(std::string const& msgType);
90 void SendAMessage(std::string const& msgType, std::vector<Argument> const& args);
91 std::vector<Argument> GetMessageArguments();
92 void SendPoseMessage(std::string const& msgType, int index, double pos[3], double dir[3]);
94
95 // call during the render loop to handle collaboration messages
96 virtual void Render();
97
98 // required call, true on success, pass the renderer you want the avatars added to
100
101 // close the connection
103
104 // set the values for the collaboration connection
105 // Can be done through Set* methods or by passing in
106 // the command line arguments via AddArguments
107 virtual void AddArguments(vtksys::CommandLineArguments& arguments);
108 void SetCollabHost(std::string const& val) { this->CollabHost = val; }
109 void SetCollabSession(std::string const& val) { this->CollabSession = val; }
110 void SetCollabName(std::string const& val) { this->CollabName = val; }
111 void SetCollabPort(int val) { this->CollabPort = val; }
112
113 // to receive log/warning/error output
115 std::function<void(std::string const& data, vtkLogger::Verbosity verbosity)> cb)
116 {
117 this->Callback = cb;
118 }
119
120 // to override the default method of getting avatar scales
121 void SetScaleCallback(std::function<double()> cb) { this->ScaleCallback = cb; }
122
123 // return the renderer being used by this instance (assigned during Initialize())
124 vtkOpenGLRenderer* GetRenderer() { return this->Renderer; }
125
126 // is this instance connected to a collaboration server?
127 bool GetConnected() { return this->Connected; }
128
129protected:
132
133 void Log(vtkLogger::Verbosity verbosity, std::string const& msg);
134
135 // provided values
136 std::string CollabID;
137 std::string CollabHost;
138 std::string CollabSession;
139 std::string CollabName;
141
142 std::function<void(std::string const& data, vtkLogger::Verbosity)> Callback;
143 std::function<double()> ScaleCallback;
144
148 bool AvatarIdle(std::string id);
151 double NeedReply;
153
155
156 // get existing avatar, or create new one, if needed, and return it.
158
161
162 virtual void HandleBroadcastMessage(std::string const& otherID, std::string const& type);
163
165 static void EventCallback(
166 vtkObject* object, unsigned long event, void* clientdata, void* calldata);
168
171
173
174 // used to throttle outgoing pose messages
176 bool HasPoseForDevice[vtkEventDataNumberOfDevices];
177 struct Pose
178 {
179 std::array<double, 3> Position;
180 std::array<double, 4> Orientation;
181 };
183
184 // dynamic set of avatars, keyed on IDs sent with updates.
185 std::map<std::string, vtkSmartPointer<vtkOpenGLAvatar>> Avatars;
186 std::map<std::string, double[vtkEventDataNumberOfDevices]> AvatarUpdateTime;
187
188 // PIMPL to keep zeromq out of the interface for this class
189 vtkVRCollaborationClientInternal* Internal;
190};
191
192#endif
supports function callbacks
a simple class to control print indentation
Definition: vtkIndent.h:113
Allocate and hold a VTK object.
Definition: vtkNew.h:165
abstract base class for most VTK objects
Definition: vtkObject.h:82
OpenGL Avatar.
OpenGL rendering window.
OpenGL renderer.
Hold a reference to a vtkObjectBase instance.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:164
void SetDoubleVector(double const *in, uint16_t size)
bool GetStringVector(std::vector< std::string > &result)
bool GetDouble(double &result)
void SetStringVector(std::vector< std::string > const &in)
bool GetInt32(int32_t &result)
void SetInt32Vector(int32_t const *in, uint16_t size)
bool GetString(std::string &result)
bool GetDoubleVector(std::vector< double > &result)
void SetString(std::string const &in)
bool GetInt32Vector(std::vector< int32_t > &result)
static vtkVRCollaborationClient * New()
bool AvatarIdle(std::string id)
static void EventCallback(vtkObject *object, unsigned long event, void *clientdata, void *calldata)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SendAMessage(std::string const &msgType, std::vector< Argument > const &args)
method signatures to send messages with Arguments and extract them out of messages
std::map< std::string, double[vtkEventDataNumberOfDevices]> AvatarUpdateTime
vtkOpenGLRenderWindow * RenderWindow
vtkVRCollaborationClient & operator=(const vtkVRCollaborationClient &)=delete
vtkVRCollaborationClient(const vtkVRCollaborationClient &)=delete
~vtkVRCollaborationClient() override
void SetCollabSession(std::string const &val)
void SendAMessage(std::string const &msgType)
method signatures to send messages with Arguments and extract them out of messages
vtkVRCollaborationClientInternal * Internal
void SetCollabName(std::string const &val)
virtual bool Initialize(vtkOpenGLRenderer *)
std::function< double()> ScaleCallback
std::function< void(std::string const &data, vtkLogger::Verbosity)> Callback
virtual void HandleBroadcastMessage(std::string const &otherID, std::string const &type)
void SetCollabHost(std::string const &val)
std::map< std::string, vtkSmartPointer< vtkOpenGLAvatar > > Avatars
vtkNew< vtkTransform > TempTransform
vtkOpenGLRenderer * GetRenderer()
virtual void AddArguments(vtksys::CommandLineArguments &arguments)
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
void Log(vtkLogger::Verbosity verbosity, std::string const &msg)
std::vector< Argument > GetMessageArguments()
method signatures to send messages with Arguments and extract them out of messages
void SetScaleCallback(std::function< double()> cb)
void SetLogCallback(std::function< void(std::string const &data, vtkLogger::Verbosity verbosity)> cb)
vtkSmartPointer< vtkOpenGLAvatar > GetAvatar(std::string id)
const int vtkEventDataNumberOfDevices
Definition: vtkEventData.h:36