Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.14.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ZMQReceiver.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018-2021 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <atomic>
30 #include <mutex>
31 #include <thread>
32 
33 #include "open3d/utility/Logging.h"
34 
35 namespace zmq {
36 class message_t;
37 class socket_t;
38 class context_t;
39 } // namespace zmq
40 
41 namespace open3d {
42 namespace io {
43 namespace rpc {
44 
45 class MessageProcessorBase;
46 
47 namespace messages {
48 struct Request;
49 struct SetMeshData;
50 struct GetMeshData;
51 struct SetCameraData;
52 struct SetProperties;
53 struct SetActiveCamera;
54 struct SetTime;
55 } // namespace messages
56 
58 class ZMQReceiver {
59 public:
63  ZMQReceiver(const std::string& address = "tcp://127.0.0.1:51454",
64  int timeout = 10000);
65 
66  ZMQReceiver(const ZMQReceiver&) = delete;
67  ZMQReceiver& operator=(const ZMQReceiver&) = delete;
68 
69  virtual ~ZMQReceiver();
70 
72  void Start();
73 
77  void Stop();
78 
80  std::runtime_error GetLastError();
81 
83  void SetMessageProcessor(std::shared_ptr<MessageProcessorBase> processor);
84 
85 private:
86  void Mainloop();
87 
88  const std::string address_;
89  const int timeout_;
90  std::shared_ptr<zmq::context_t> context_;
91  std::unique_ptr<zmq::socket_t> socket_;
92  std::thread thread_;
93  std::mutex mutex_;
94  bool keep_running_;
95  std::atomic<bool> loop_running_;
96  std::atomic<int> mainloop_error_code_;
97  std::runtime_error mainloop_exception_;
98  std::shared_ptr<MessageProcessorBase> processor_;
99 };
100 
101 } // namespace rpc
102 } // namespace io
103 } // namespace open3d
bool SetMeshData(const std::string &path, int time, const std::string &layer, const core::Tensor &vertices, const std::map< std::string, core::Tensor > &vertex_attributes, const core::Tensor &faces, const std::map< std::string, core::Tensor > &face_attributes, const core::Tensor &lines, const std::map< std::string, core::Tensor > &line_attributes, const std::string &material, const std::map< std::string, float > &material_scalar_attributes, const std::map< std::string, std::array< float, 4 >> &material_vector_attributes, const std::map< std::string, t::geometry::Image > &texture_maps, const std::string &o3d_type, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:163
Definition: PinholeCameraIntrinsic.cpp:35
Definition: ConnectionBase.h:31
Class for the server side receiving requests from a client.
Definition: ZMQReceiver.h:58
bool SetTime(int time, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:371
bool SetActiveCamera(const std::string &path, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:388