visualization_meshcat.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef EXOTICA_CORE_VISUALIZATION_MESHCAT_H_
31 #define EXOTICA_CORE_VISUALIZATION_MESHCAT_H_
32 
33 #include <memory>
34 #include <zmq.hpp>
35 
36 #include <exotica_core/scene.h>
38 
39 namespace exotica
40 {
42 {
43 public:
44  VisualizationMeshcat(ScenePtr scene, const std::string& url, bool use_mesh_materials = true, const std::string& file_url = "");
45  virtual ~VisualizationMeshcat();
46 
47  void Initialize(bool use_mesh_materials);
48 
49  void DisplayScene(bool use_mesh_materials = true);
50  void DisplayState(Eigen::VectorXdRefConst state, double t = 0.0);
52  void Delete(const std::string& path = "");
53  void SetProperty(const std::string& path, const std::string& property, const double& value);
54  void SetProperty(const std::string& path, const std::string& property, const std::string& value);
55  void SetProperty(const std::string& path, const std::string& property, const bool& value);
56  void SetProperty(const std::string& path, const std::string& property, const Eigen::Vector3d& value);
57  void SetProperty(const std::string& path, const std::string& property, const Eigen::Vector4d& value);
58  std::string GetWebURL();
59  std::string GetFileURL();
60 
61 private:
62  ScenePtr scene_ = std::make_shared<Scene>(nullptr);
63 
64  void ConnectZMQ();
65  void SendZMQ(const std::string& data);
66  std::string ReceiveZMQ();
67  std::string RequestWebURL();
68 
69  template <typename T>
70  void SendMsg(T msg);
71 
72  std::string zmq_url_;
73  std::string web_url_;
74  std::string file_url_;
75 
76  std::string path_prefix_;
77 
78  zmq::context_t context_;
79  std::unique_ptr<zmq::socket_t> socket_;
80 };
81 } // namespace exotica
82 
83 #endif // EXOTICA_CORE_VISUALIZATION_MESHCAT_H_
std::unique_ptr< zmq::socket_t > socket_
void DisplayScene(bool use_mesh_materials=true)
void Initialize(bool use_mesh_materials)
std::shared_ptr< Scene > ScenePtr
Definition: scene.h:246
VisualizationMeshcat(ScenePtr scene, const std::string &url, bool use_mesh_materials=true, const std::string &file_url="")
const Eigen::Ref< const Eigen::MatrixXd > & MatrixXdRefConst
Definition: conversions.h:53
robot_trajectory::RobotTrajectory trajectory(rmodel,"right_arm")
void DisplayState(Eigen::VectorXdRefConst state, double t=0.0)
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Convenience wrapper for storing references to sub-matrices/vectors.
Definition: conversions.h:52
void SendZMQ(const std::string &data)
void Delete(const std::string &path="")
void SetProperty(const std::string &path, const std::string &property, const double &value)
void DisplayTrajectory(Eigen::MatrixXdRefConst trajectory, double dt=1.0)


exotica_core
Author(s): Yiming Yang, Michael Camilleri
autogenerated on Sat Apr 10 2021 02:34:49