Go to the documentation of this file.
30 #ifndef EXOTICA_CORE_VISUALIZATION_MESHCAT_TYPES_H_
31 #define EXOTICA_CORE_VISUALIZATION_MESHCAT_TYPES_H_
33 #define MSGPACK_USE_DEFINE_MAP
36 #include <msgpack.hpp>
38 #include <geometric_shapes/shapes.h>
44 #if (MSGPACK_VERSION_MAJOR >= 2)
50 #define MSGPACK_FEATURE_NOT_SUPPORTED
55 namespace visualization
57 inline long RGB(
double R,
double G,
double B)
59 return static_cast<long>(std::min(std::max(R, 0.0), 1.0) * 255) * 65536L +
static_cast<long>(std::min(std::max(G, 0.0), 1.0) * 255) * 256L +
static_cast<long>(std::min(std::max(B, 0.0), 1.0) * 255);
64 std::random_device rd;
65 std::mt19937 gen(rd());
66 std::uniform_int_distribution<> dis(0, 255);
67 return static_cast<unsigned char>(dis(gen));
73 for (
auto i = 0; i < len; ++i)
76 std::stringstream hexstream;
77 hexstream << std::hex << int(rc);
78 auto hex = hexstream.str();
79 ss << (hex.length() < 2 ?
'0' + hex : hex);
92 Base(
const std::string& type_in,
const std::string& path_in) :
type(type_in),
path(path_in){};
101 Property(
const std::string& path_in,
const std::string& property_in,
const T& value_in) :
Base(
"set_property", path_in),
property(property_in),
value(value_in){};
118 Material(
long color_in,
double opacity_in = 1.0,
const std::string& type_in =
"MeshPhongMaterial",
const std::string& uuid_in =
"") :
color(color_in),
opacity(opacity_in),
uuid(uuid_in),
type(type_in)
124 uuid =
"0000-0000-0000-0000";
127 std::string
type =
"MeshPhongMaterial";
142 ObjectData(
const std::string& type_in,
const std::string& uuid_in,
143 const std::string& geometry_in,
const std::string& material_in) :
type(type_in),
uuid(uuid_in),
geometry(geometry_in),
material(material_in){};
148 std::vector<double>
matrix = {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0};
152 template <
typename T>
162 template <
typename T>
172 template <
typename T>
183 template <
typename T>
192 Geometry(
const std::string& type_in,
const std::string& uuid_in =
"") :
type(type_in),
uuid(uuid_in)
203 GeometryBox(
double width_in,
double height_in,
double depth_in,
const std::string& uuid_in =
"") :
Geometry(
"BoxGeometry", uuid_in),
width(width_in),
height(height_in),
depth(depth_in){};
235 GeometryMesh(
const std::string& file_name_in,
const std::string& url_in =
"",
const std::string& format_in =
"",
const std::string& uuid_in =
"") :
Geometry(
"_meshfile_geometry", uuid_in),
format(format_in)
240 std::string::size_type pos =
file_name.rfind(
".");
241 if (pos != std::string::npos)
248 std::ifstream file(
file_name, std::ios::binary | std::ios::ate);
249 std::streamsize size = file.tellg();
250 file.seekg(0, std::ios::beg);
253 file.read(
buffer.data(), size);
293 std::vector<double>
matrix = {1.0, 0.0, 0.0, 0.0,
308 for (
unsigned int i = 0; i < size; ++i)
309 data[i] =
static_cast<float>(data_in[i]);
310 #ifdef MSGPACK_FEATURE_NOT_SUPPORTED
312 WARNING(
"MSGPACK version does not support sending this type of data. Ignoring.");
323 #ifdef MSGPACK_FEATURE_NOT_SUPPORTED
331 std::string
type =
"Float32Array";
346 for (
unsigned int i = 0; i < size; ++i)
351 std::string
type =
"Uint32Array";
363 std::shared_ptr<shapes::Mesh> shape = std::static_pointer_cast<shapes::Mesh>(shape_in);
364 attributes.insert(std::make_pair<std::string, ArrayFloat>(
"position",
ArrayFloat(shape->vertices, shape->vertex_count * 3)));
365 if (shape->vertex_normals)
366 attributes.insert(std::make_pair<std::string, ArrayFloat>(
"normal",
ArrayFloat(shape->vertex_normals, shape->vertex_count * 3)));
367 index =
ArrayInt(shape->triangles, shape->triangle_count * 3);
386 std::vector<double>
matrix = {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0};
390 template <
typename T>
403 template <
typename T>
408 ret.
object.type =
"_meshfile_object";
425 Key(
double time_in,
const std::vector<double>& value_in) :
time(time_in),
value(value_in){};
434 Track(
const std::string& name_in,
const std::string& type_in) :
name(name_in),
type(type_in){};
444 Clip(
double fps_in,
const std::string& name_in) :
fps(fps_in),
name(name_in){};
471 std::string
type =
"set_animation";
488 #endif // EXOTICA_CORE_VISUALIZATION_MESHCAT_TYPES_H_
bool normalized
Definition: visualization_meshcat_types.h:332
T value
Definition: visualization_meshcat_types.h:103
MSGPACK_DEFINE(type, path)
Definition: visualization_meshcat_types.h:358
GeometryMesh(const std::string &file_name_in, const std::string &url_in="", const std::string &format_in="", const std::string &uuid_in="")
Definition: visualization_meshcat_types.h:235
int widthSegments
Definition: visualization_meshcat_types.h:226
Definition: visualization_meshcat_types.h:89
Object< T > CreateGeometryObject(const T &geometry_in, const Material &material_in=Material(), const std::string &uuid_in="")
Definition: visualization_meshcat_types.h:391
double time
Definition: visualization_meshcat_types.h:425
std::string type
Definition: visualization_meshcat_types.h:482
MSGPACK_DEFINE(type, path, animations, options)
std::string type
Definition: visualization_meshcat_types.h:351
Definition: visualization_meshcat_types.h:339
Definition: visualization_meshcat_types.h:478
Material()
Definition: visualization_meshcat_types.h:122
msgpack::type::raw_ref msgpack_raw_ref
Definition: visualization_meshcat_types.h:48
MSGPACK_DEFINE(metadata, geometries, materials, object)
std::string path
Definition: visualization_meshcat_types.h:483
double opacity
Definition: visualization_meshcat_types.h:133
MSGPACK_DEFINE(time, value)
MetaData metadata
Definition: visualization_meshcat_types.h:155
double fps
Definition: visualization_meshcat_types.h:444
std::string file_name
Definition: visualization_meshcat_types.h:288
std::string path
Definition: visualization_meshcat_types.h:94
bool wireframe
Definition: visualization_meshcat_types.h:135
std::vector< double > matrix
Definition: visualization_meshcat_types.h:148
Definition: visualization_meshcat_types.h:210
std::string generate_uuid()
Definition: visualization_meshcat_types.h:84
bool transparent
Definition: visualization_meshcat_types.h:134
Property()
Definition: visualization_meshcat_types.h:100
Definition: visualization_meshcat_types.h:468
std::string type
Definition: visualization_meshcat_types.h:127
bool normalized
Definition: visualization_meshcat_types.h:352
GeometryMeshBuffer(shapes::ShapePtr shape_in, const std::string &uuid_in="")
Definition: visualization_meshcat_types.h:380
Definition: visualization_meshcat_types.h:221
ArrayInt(unsigned int *data, unsigned int size)
Definition: visualization_meshcat_types.h:343
std::vector< Track > tracks
Definition: visualization_meshcat_types.h:447
std::vector< float > data
Definition: visualization_meshcat_types.h:333
unsigned char random_char()
Definition: visualization_meshcat_types.h:62
std::string type
Definition: visualization_meshcat_types.h:176
ObjectData object
Definition: visualization_meshcat_types.h:156
Clip clip
Definition: visualization_meshcat_types.h:456
Definition: cartpole_dynamics_solver.h:38
long color
Definition: visualization_meshcat_types.h:128
long ambient
Definition: visualization_meshcat_types.h:129
std::string type
Definition: visualization_meshcat_types.h:331
int radialSegments
Definition: visualization_meshcat_types.h:217
std::string material
Definition: visualization_meshcat_types.h:147
double radiusBottom
Definition: visualization_meshcat_types.h:216
MetaData metadata
Definition: visualization_meshcat_types.h:165
std::string name
Definition: visualization_meshcat_types.h:434
GeometryMesh()
Definition: visualization_meshcat_types.h:233
GeometryMesh & operator=(const GeometryMesh &other)
Definition: visualization_meshcat_types.h:270
Definition: visualization_meshcat_types.h:163
T object
Definition: visualization_meshcat_types.h:179
double height
Definition: visualization_meshcat_types.h:205
MSGPACK_DEFINE(type, path, object)
ArrayFloat(double *data_in, unsigned int size)
Definition: visualization_meshcat_types.h:305
std::vector< uint32_t > array
Definition: visualization_meshcat_types.h:353
std::string path
Definition: visualization_meshcat_types.h:178
double shininess
Definition: visualization_meshcat_types.h:132
MSGPACK_DEFINE(play, repetitions)
GeometryMeshBuffer()
Definition: visualization_meshcat_types.h:378
SetObjectType< T > SetObject(const std::string &path_in, const T &object_in)
Definition: visualization_meshcat_types.h:184
std::vector< double > matrix
Definition: visualization_meshcat_types.h:386
std::string path
Definition: visualization_meshcat_types.h:454
Definition: visualization_meshcat_types.h:422
msgpack_raw_ref data
Definition: visualization_meshcat_types.h:290
std::string type
Definition: visualization_meshcat_types.h:143
Material(long color_in, double opacity_in=1.0, const std::string &type_in="MeshPhongMaterial", const std::string &uuid_in="")
Definition: visualization_meshcat_types.h:118
std::vector< Key > keys
Definition: visualization_meshcat_types.h:437
int heightSegments
Definition: visualization_meshcat_types.h:227
std::string property
Definition: visualization_meshcat_types.h:101
MSGPACK_DEFINE(type, path, property, value)
std::string uuid
Definition: visualization_meshcat_types.h:126
std::string generate_hex(const unsigned int len)
Definition: visualization_meshcat_types.h:70
Definition: visualization_meshcat_types.h:153
double depth
Definition: visualization_meshcat_types.h:206
Definition: visualization_meshcat_types.h:189
MSGPACK_DEFINE(uuid, type, color, ambient, emissive, specular, shininess, opacity, transparent, wireframe)
std::vector< T > geometries
Definition: visualization_meshcat_types.h:158
std::string geometry
Definition: visualization_meshcat_types.h:146
std::string ParsePath(const std::string &path)
bool play
Definition: visualization_meshcat_types.h:463
GeometryMeshBufferData data
Definition: visualization_meshcat_types.h:383
double radiusTop
Definition: visualization_meshcat_types.h:215
GeometryCylinder()
Definition: visualization_meshcat_types.h:212
MSGPACK_DEFINE(path, clip)
ArrayInt index
Definition: visualization_meshcat_types.h:371
Definition: visualization_meshcat_types.h:451
std::string type
Definition: visualization_meshcat_types.h:471
std::vector< float > msgpack_ext
Definition: visualization_meshcat_types.h:49
Definition: visualization_meshcat_types.h:441
Geometry(const std::string &type_in, const std::string &uuid_in="")
Definition: visualization_meshcat_types.h:192
std::string type
Definition: visualization_meshcat_types.h:92
std::vector< T > geometries
Definition: visualization_meshcat_types.h:168
GeometryMeshBufferData()=default
GeometryBox()
Definition: visualization_meshcat_types.h:202
std::string type
Definition: visualization_meshcat_types.h:436
int itemSize
Definition: visualization_meshcat_types.h:330
Definition: visualization_meshcat_types.h:300
std::string uuid
Definition: visualization_meshcat_types.h:195
std::vector< double > matrix
Definition: visualization_meshcat_types.h:293
Delete(const std::string &path_in)
Definition: visualization_meshcat_types.h:481
MeshObject< T > CreateMeshObject(const T &geometry_in, const Material &material_in=Material(), const std::string &uuid_in="")
Definition: visualization_meshcat_types.h:404
std::vector< char > buffer
Definition: visualization_meshcat_types.h:287
std::map< std::string, std::string > resources
Definition: visualization_meshcat_types.h:292
double height
Definition: visualization_meshcat_types.h:213
std::vector< Animation > animations
Definition: visualization_meshcat_types.h:473
#define WARNING(x)
With endline.
Definition: printable.h:56
MSGPACK_DEFINE(name, type, keys)
std::string type
Definition: visualization_meshcat_types.h:197
double width
Definition: visualization_meshcat_types.h:203
Definition: visualization_meshcat_types.h:200
std::string name
Definition: visualization_meshcat_types.h:446
Definition: visualization_meshcat_types.h:116
Track(const std::string &name_in, const std::string &type_in)
Definition: visualization_meshcat_types.h:434
std::string path
Definition: visualization_meshcat_types.h:472
std::string url
Definition: visualization_meshcat_types.h:291
MSGPACK_DEFINE(type, uuid, geometry, material, matrix)
std::vector< double > value
Definition: visualization_meshcat_types.h:427
std::map< std::string, ArrayFloat > attributes
Definition: visualization_meshcat_types.h:370
MSGPACK_DEFINE(metadata, geometries, materials, object)
std::string uuid
Definition: visualization_meshcat_types.h:145
ObjectData(const std::string &type_in, const std::string &uuid_in, const std::string &geometry_in, const std::string &material_in)
Definition: visualization_meshcat_types.h:142
AnimationOption options
Definition: visualization_meshcat_types.h:474
long specular
Definition: visualization_meshcat_types.h:131
GeometryMesh(const GeometryMesh &other)
Definition: visualization_meshcat_types.h:259
GeometrySphere()
Definition: visualization_meshcat_types.h:223
std::string format
Definition: visualization_meshcat_types.h:289
Definition: visualization_meshcat_types.h:98
long emissive
Definition: visualization_meshcat_types.h:130
Definition: visualization_meshcat_types.h:231
Definition: visualization_meshcat_types.h:431
Definition: visualization_meshcat_types.h:139
double radius
Definition: visualization_meshcat_types.h:224
long RGB(double R, double G, double B)
Definition: visualization_meshcat_types.h:57
int itemSize
Definition: visualization_meshcat_types.h:350
std::vector< Material > materials
Definition: visualization_meshcat_types.h:157
MSGPACK_DEFINE(fps, name, tracks)
msgpack_ext array
Definition: visualization_meshcat_types.h:334
Definition: visualization_meshcat_types.h:460
GeometryMeshBufferData(shapes::ShapePtr shape_in)
Definition: visualization_meshcat_types.h:361
AnimationOption()=default
ArrayFloat(const ArrayFloat &other)
Definition: visualization_meshcat_types.h:318
std::vector< Material > materials
Definition: visualization_meshcat_types.h:167
Definition: visualization_meshcat_types.h:173
T object
Definition: visualization_meshcat_types.h:166
int repetitions
Definition: visualization_meshcat_types.h:464
Definition: visualization_meshcat_types.h:376