View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

rhrserver.h
Go to the documentation of this file.
1
10#ifndef RHR_SERVER_H
11#define RHR_SERVER_H
12
13#include <vector>
14#include <deque>
15#include <string>
16#include <map>
17
18#include <boost/asio.hpp>
19
20#include <vistle/core/vector.h>
21#include <vistle/core/message.h>
24
25#include <tbb/concurrent_queue.h>
26
27#include "export.h"
28#include "compdecomp.h"
29#include "rfbext.h"
30
31namespace vistle {
32
33namespace asio = boost::asio;
34using message::RemoteRenderMessage;
35class MessageSender;
36class Module;
37
40public:
41 typedef asio::ip::tcp::socket socket;
42 typedef asio::ip::tcp::acceptor acceptor;
43 typedef asio::ip::address address;
44
45 explicit RhrServer(vistle::Module *module);
46 ~RhrServer();
47
48 int numClients() const;
49
50 bool isConnecting() const;
51 bool isConnected() const;
52
53 unsigned short port() const;
54
55 unsigned short destinationPort() const;
56 const std::string &destinationHost() const;
57
58 void setClientModuleId(int roduleId);
59
60 int width(size_t viewNum) const;
61 int height(size_t viewNum) const;
62 unsigned char *rgba(size_t viewNum);
63 const unsigned char *rgba(size_t viewNum) const;
64 float *depth(size_t viewNum);
65 const float *depth(size_t viewNum) const;
66
67 void resize(size_t viewNum, int w, int h);
68
69 void init();
70 bool startServer(unsigned short port);
71 bool makeConnection(const std::string &host, unsigned short port, int secondsToTry = -1);
72 void preFrame();
73
74 struct ViewParameters;
75 ViewParameters getViewParameters(int viewNum) const;
76 void invalidate(int viewNum, int x, int y, int w, int h, const ViewParameters &param, bool lastView);
77 void updateModificationCount();
78
79 void setColorCodec(CompressionParameters::ColorCodec value);
80 void setDepthCodec(CompressionParameters::DepthCodec value);
81 void setColorCompression(message::CompressionMode mode);
82 void setDepthPrecision(int bits);
83 void setDepthCompression(message::CompressionMode mode);
84 void setTileSize(int w, int h);
85 void setZfpMode(CompressionParameters::ZfpMode mode);
86 void setDumpImages(bool enable);
87
88 int timestep() const;
89 void setNumTimesteps(unsigned num);
90 size_t updateCount() const;
91 typedef std::map<std::string, vistle::RenderObject::InitialVariantVisibility> InitialVariantVisibilityMap;
92 typedef std::map<std::string, bool> VariantVisibilityMap;
93 const VariantVisibilityMap &getVariants() const;
94
95 bool handleMessage(const vistle::message::Message *message, const vistle::MessagePayload &payload);
96 bool handleRemoteRenderMessage(std::shared_ptr<socket> sock, const vistle::message::RemoteRenderMessage &rr);
97
98 bool handleMatrices(std::shared_ptr<socket> sock, const matricesMsg &mat);
99 bool handleLights(std::shared_ptr<socket> sock, const lightsMsg &light);
100 bool handleBounds(std::shared_ptr<socket> sock, const boundsMsg &bound);
101 bool handleAnimation(std::shared_ptr<socket> sock, const animationMsg &anim);
102 bool handleVariant(std::shared_ptr<socket> sock, const variantMsg &variant);
103
104 size_t numViews() const;
105 const vistle::Matrix4 &viewMat(size_t viewNum) const;
106 const vistle::Matrix4 &projMat(size_t viewNum) const;
107 const vistle::Matrix4 &modelMat(size_t viewNum) const;
108
109 void setBoundingSphere(const vistle::Vector3 &center, const vistle::Scalar &radius);
110
111 struct Screen {
116 };
117
118 struct Light {
119 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
120
122
126
131
135 mutable bool isDirectional;
136
137 bool operator==(const Light &rhs) const
138 {
139 if (position != rhs.position)
140 return false;
141 if (attenuation != rhs.attenuation)
142 return false;
143 if (ambient != rhs.ambient)
144 return false;
145 if (diffuse != rhs.diffuse)
146 return false;
147 if (specular != rhs.specular)
148 return false;
149 if (direction != rhs.direction)
150 return false;
151 if (spotCutoff != rhs.spotCutoff)
152 return false;
153 if (spotExponent != rhs.spotExponent)
154 return false;
155 if (enabled != rhs.enabled)
156 return false;
157
158 return true;
159 }
160
161 template<class Archive>
162 void serialize(Archive &ar, const unsigned int version)
163 {
164 ar &enabled;
165
166 ar &position;
167 ar &attenuation;
168
169 ar &ambient;
170 ar &diffuse;
171 ar &specular;
172
173 ar &direction;
174 ar &spotCutoff;
175 ar &spotExponent;
176 }
177 };
178
179 std::vector<Light> lights;
181
183 double timestepRequestTime = -1.; // time for last animationMsg, for latency measurement
184 int timestep = -1;
186#if 0
187 bool depthFloat;
188 int depthPrecision;
189 bool depthZfp;
190 bool depthQuant;
191 ZfpMode depthZfpMode;
192 message::CompressionMode depthCompress;
193#endif
195#if 0
196 bool rgbaJpeg;
197 bool rgbaChromaSubsamp;
198 message::CompressionMode rgbaCompress;
199#endif
200
201 ImageParameters(): timestep(-1)
202#if 0
203 , depthFloat(false)
204 , depthPrecision(24)
205 , depthZfp(false)
206 , depthQuant(false)
207 , depthZfpMode(ZfpAccuracy)
208 , depthCompress(message::CompressionNone)
209 , rgbaJpeg(false)
210 , rgbaChromaSubsamp(false)
211 , rgbaCompress(message::CompressionNone)
212#endif
213 {}
214 };
215
222 int width, height;
223 uint32_t frameNumber;
225 int32_t timestep = -1;
226 uint8_t eye = 0;
227
228 ViewParameters(): matrixTime(0.), width(1), height(1), frameNumber(0), requestNumber(0), timestep(-1)
229 {
230 head = vistle::Matrix4::Identity();
231 proj = vistle::Matrix4::Identity();
232 view = vistle::Matrix4::Identity();
233 model = vistle::Matrix4::Identity();
234 }
235
236 template<class Archive>
237 void serialize(Archive &ar, const unsigned int version)
238 {
239 ar &frameNumber;
240 ar &requestNumber;
241 ar &timestep;
242 ar &matrixTime;
243 ar &width;
244 ar &height;
245 ar &eye;
246
247 ar &head;
248 ar &proj;
249 ar &view;
250 ar &model;
251 }
252 };
253
254 struct ViewData {
257 int newWidth, newHeight;
258 std::vector<unsigned char> rgba;
259 std::vector<float> depth;
260
261 ViewData(): newWidth(-1), newHeight(-1) {}
262 };
263 void
264 updateVariants(const std::vector<std::pair<std::string, vistle::RenderObject::InitialVariantVisibility>> &added,
265 const std::vector<std::string> &removed);
266
267private:
268 vistle::Module *m_module;
269 asio::io_service m_io;
270 asio::ip::tcp::acceptor m_acceptorv4, m_acceptorv6;
271 bool m_listen = false;
272 std::shared_ptr<asio::ip::tcp::socket> m_clientSocket;
273 unsigned short m_port = 0;
274 unsigned short m_destPort = 0;
275 std::string m_destHost;
276 int m_clientModuleId = 0;
277
278 bool startAccept(asio::ip::tcp::acceptor &a);
279 void handleAccept(asio::ip::tcp::acceptor &a, std::shared_ptr<boost::asio::ip::tcp::socket> sock,
280 const boost::system::error_code &error);
281
282 size_t m_updateCount = 0;
283
284 int m_tileWidth, m_tileHeight;
285
286 std::vector<ViewData, Eigen::aligned_allocator<ViewData>> m_viewData;
287
288 ImageParameters m_imageParam;
289 bool m_resizeBlocked;
290
291 vistle::Vector3 m_boundCenter;
292 vistle::Scalar m_boundRadius;
293
294 unsigned m_numTimesteps;
295
296 void sendBoundsMessage(std::shared_ptr<socket> sock);
297
298 void encodeAndSend(int viewNum, int x, int y, int w, int h, const ViewParameters &param, bool lastView);
299 bool finishTiles(const ViewParameters &param, bool wait, bool sendTiles = true);
300
301 struct EncodeResult {
302 explicit EncodeResult(tileMsg *msg = nullptr): message(msg) {}
303
304 buffer payload;
305 tileMsg *message = nullptr;
306 RemoteRenderMessage *rhrMessage = nullptr;
307 };
308
309 friend struct EncodeTask;
310
311 tbb::concurrent_queue<EncodeResult> m_resultQueue;
312 size_t m_queuedTiles;
313 bool m_firstTile;
314
315 void deferredResize();
316
317 VariantVisibilityMap m_clientVariants;
318 InitialVariantVisibilityMap m_localVariants;
319
320 bool send(message::Buffer msg, const buffer *payload = nullptr);
321 bool send(const RemoteRenderMessage &msg, const buffer *payload = nullptr);
322 void resetClient();
323 int m_framecount = 0;
324 bool m_dumpImages = false;
325 size_t m_modificationCount = 0;
326};
327
328} // namespace vistle
329#endif
Implement remote hybrid rendering server.
Definition: rhrserver.h:39
std::vector< Light > lights
Definition: rhrserver.h:179
asio::ip::tcp::socket socket
Definition: rhrserver.h:41
asio::ip::tcp::acceptor acceptor
Definition: rhrserver.h:42
vistle::Scalar vsize
Definition: rhrserver.h:114
vistle::Vector3 hpr
Definition: rhrserver.h:115
vistle::Scalar hsize
Definition: rhrserver.h:112
std::map< std::string, vistle::RenderObject::InitialVariantVisibility > InitialVariantVisibilityMap
Definition: rhrserver.h:91
std::map< std::string, bool > VariantVisibilityMap
Definition: rhrserver.h:92
size_t lightsUpdateCount
Definition: rhrserver.h:180
vistle::Vector3 pos
Definition: rhrserver.h:113
asio::ip::address address
Definition: rhrserver.h:43
Definition: rhrserver.h:111
Definition: rfbext.h:307
#define V_RHREXPORT
Definition: export.h:9
bool send(socket_t &sock, const message::Message &msg, error_code &ec, const char *payload, size_t size)
std::vector< char, allocator< char > > buffer
Eigen::Matrix< Scalar, 3, 1 > Vector3
Eigen::Matrix< Scalar, 4, 1 > Vector4
float Scalar
CompressionParameters::DepthCompressionParameters DepthCompressionParameters
Definition: compdecomp.h:48
Eigen::Matrix< Scalar, 4, 4 > Matrix4
RFB protocol extensions for remote hybrid rendering (RHR)
Definition: rhrserver.h:182
DepthCompressionParameters depthParam
Definition: rhrserver.h:185
ImageParameters()
Definition: rhrserver.h:201
RgbaCompressionParameters rgbaParam
Definition: rhrserver.h:194
Definition: rhrserver.h:118
vistle::Vector3 attenuation
Definition: rhrserver.h:127
vistle::Vector3 transformedDirection
Definition: rhrserver.h:133
vistle::Scalar spotCutoff
Definition: rhrserver.h:128
vistle::Vector4 transformedPosition
Definition: rhrserver.h:132
vistle::Vector4 specular
Definition: rhrserver.h:125
bool isDirectional
Definition: rhrserver.h:135
void serialize(Archive &ar, const unsigned int version)
Definition: rhrserver.h:162
vistle::Vector3 direction
Definition: rhrserver.h:129
vistle::Vector4 ambient
Definition: rhrserver.h:123
vistle::Vector4 diffuse
Definition: rhrserver.h:124
EIGEN_MAKE_ALIGNED_OPERATOR_NEW vistle::Vector4 position
Definition: rhrserver.h:121
vistle::Scalar spotExponent
Definition: rhrserver.h:130
bool operator==(const Light &rhs) const
Definition: rhrserver.h:137
bool enabled
Definition: rhrserver.h:134
Definition: rhrserver.h:254
ViewParameters nparam
parameters for color/depth tiles currently being updated
Definition: rhrserver.h:256
std::vector< float > depth
Definition: rhrserver.h:259
int newHeight
in case resizing was blocked while message was received
Definition: rhrserver.h:257
ViewParameters param
parameters for color/depth tiles
Definition: rhrserver.h:255
ViewData()
Definition: rhrserver.h:261
std::vector< unsigned char > rgba
Definition: rhrserver.h:258
Definition: rhrserver.h:216
vistle::Matrix4 proj
Definition: rhrserver.h:218
uint32_t requestNumber
Definition: rhrserver.h:224
ViewParameters()
Definition: rhrserver.h:228
vistle::Matrix4 model
Definition: rhrserver.h:220
void serialize(Archive &ar, const unsigned int version)
Definition: rhrserver.h:237
vistle::Matrix4 head
Definition: rhrserver.h:217
int height
Definition: rhrserver.h:222
double matrixTime
Definition: rhrserver.h:221
vistle::Matrix4 view
Definition: rhrserver.h:219
uint32_t frameNumber
Definition: rhrserver.h:223
animation time step on client or no. of animation steps on server changed
Definition: rfbext.h:280
send scene bounding sphere from server to client
Definition: rfbext.h:191
send lighting parameters from client to server
Definition: rfbext.h:94
send matrices from client to server
Definition: rfbext.h:45
send image tile from server to client
Definition: rfbext.h:228
Definition: rfbext.h:289