Blue Brain BioExplorer
jsonSerialization.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2018, EPFL/Blue Brain Project
3  * All rights reserved. Do not distribute without permission.
4  * Responsible Author: Daniel Nachbaur <daniel.nachbaur@epfl.ch>
5  *
6  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
7  *
8  * This library is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License version 3.0 as published
10  * by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #pragma once
23 
24 #include <Defines.h>
25 #include <Version.h>
26 
48 
49 #include "ImageGenerator.h"
50 #include "SnapshotTask.h"
51 
52 #include "jsonUtils.h"
53 
54 namespace core
55 {
57 {
58  size_t modelID;
60 };
61 
63 {
64  std::string endpoint;
65 };
66 
68 {
69  std::string filename;
70 };
71 
73 {
74  bool enabled{false};
75  uint32_t kbps{5000};
76 
77  bool operator==(const VideoStreamParam& rhs) const { return enabled == rhs.enabled && kbps == rhs.kbps; }
78 
79  bool operator!=(const VideoStreamParam& rhs) const { return !(*this == rhs); }
80 };
81 
82 struct ObjectID
83 {
84  size_t id;
85 };
86 
88 {
89  size_t id;
91 };
92 
94 {
95  size_t id;
97 };
98 
99 struct RPCLight
100 {
101  size_t id;
102  std::string type;
104 };
105 
106 struct InputPath
107 {
108  std::string path;
109 };
110 
111 struct FileStats
112 {
113  std::string type;
114  long sizeBytes;
115  int error;
116  std::string message;
117 };
118 
119 struct FileType
120 {
121  std::string type;
122  int error;
123  std::string message;
124 };
125 
127 {
128  std::string content;
129  int error;
130  std::string message;
131 };
132 
133 struct FileRoot
134 {
135  std::string root;
136 };
137 
139 {
142 };
143 
145 {
148  int error;
149  std::string message;
150 };
151 
153 {
154  std::string type;
155 };
156 
158 {
159  uint32_t minutes;
160 };
161 
162 } // namespace core
163 
166 
168  {"replicated", core::MemoryMode::replicated});
169 
171  {"normals", core::TextureType::normals}, {"bump", core::TextureType::bump},
172  {"specular", core::TextureType::specular}, {"emissive", core::TextureType::emissive},
173  {"opacity", core::TextureType::opacity}, {"reflection", core::TextureType::reflection},
174  {"refraction", core::TextureType::refraction}, {"occlusion", core::TextureType::occlusion});
175 
176 // c-array to std.array: https://stackoverflow.com/questions/11205186
177 template <size_t M, typename T>
178 auto toArray(glm::vec<M, T>& vec)
179 {
180  return reinterpret_cast<std::array<T, M>*>(glm::value_ptr(vec));
181 }
182 
183 template <typename T>
184 auto toArray(glm::tquat<T>& quat)
185 {
186  return reinterpret_cast<std::array<T, 4>*>(glm::value_ptr(quat));
187 }
188 
189 template <size_t M, typename T>
190 auto toArray(std::vector<glm::vec<M, T>>& vecVec)
191 {
192  return reinterpret_cast<std::vector<std::array<T, M>>*>(&vecVec);
193 }
194 
195 namespace staticjson
196 {
197 inline void init(core::PropertyMap* /*g*/, ObjectHandler* h)
198 {
199  // beware that this should only be used for creating JSON RPC schema which
200  // uses PropertyMap as an argument and a oneOf list is not possible. To
201  // properly serialize a property map to/from JSON, use from_json/to_json
202  // from jsonPropertyMap.h directly.
203  h->set_flags(Flags::DisallowUnknownKey);
204 }
205 
206 inline void init(core::ObjectID* s, ObjectHandler* h)
207 {
208  h->add_property("id", &s->id);
209  h->set_flags(Flags::DisallowUnknownKey);
210 }
211 
212 inline void init(core::ModelProperties* s, ObjectHandler* h)
213 {
214  h->add_property("id", &s->id);
215  h->add_property("properties", &s->properties);
216  h->set_flags(Flags::DisallowUnknownKey);
217 }
218 
219 inline void init(core::ModelTransferFunction* s, ObjectHandler* h)
220 {
221  h->add_property("id", &s->id);
222  h->add_property("transfer_function", &s->transferFunction);
223  h->set_flags(Flags::DisallowUnknownKey);
224 }
225 
226 inline void init(core::GetInstances* g, ObjectHandler* h)
227 {
228  h->add_property("id", &g->modelID);
229  h->add_property("result_range", toArray<2, uint32_t>(g->resultRange), Flags::Optional);
230  h->set_flags(Flags::DisallowUnknownKey);
231 }
232 
233 inline void init(core::SchemaParam* s, ObjectHandler* h)
234 {
235  h->add_property("endpoint", &s->endpoint);
236  h->set_flags(Flags::DisallowUnknownKey);
237 }
238 
239 inline void init(core::EnvironmentMapParam* s, ObjectHandler* h)
240 {
241  h->add_property("filename", &s->filename);
242  h->set_flags(Flags::DisallowUnknownKey);
243 }
244 
245 inline void init(core::VideoStreamParam* s, ObjectHandler* h)
246 {
247  h->add_property("enabled", &s->enabled, Flags::Optional);
248  h->add_property("kbps", &s->kbps, Flags::Optional);
249  h->set_flags(Flags::DisallowUnknownKey);
250 }
251 
252 inline void init(core::Chunk* c, ObjectHandler* h)
253 {
254  h->add_property("id", &c->id, Flags::Optional);
255  h->set_flags(Flags::DisallowUnknownKey);
256 }
257 
258 inline void init(core::BinaryParam* s, ObjectHandler* h)
259 {
260  h->add_property("bounding_box", &s->_boundingBox, Flags::Optional);
261  h->add_property("chunks_id", &s->chunksID);
262  h->add_property("name", &s->_name, Flags::Optional);
263  h->add_property("path", &s->_path);
264  h->add_property("size", &s->size);
265  h->add_property("transformation", &s->_transformation, Flags::Optional);
266  h->add_property("type", &s->type);
267  h->add_property("visible", &s->_visible, Flags::Optional);
268  h->add_property("loader_name", &s->_loaderName, Flags::Optional);
269  h->add_property("loader_properties", &s->_loaderProperties, Flags::Optional);
270  h->set_flags(Flags::DisallowUnknownKey);
271 }
272 
273 inline void init(core::SnapshotParams* s, ObjectHandler* h)
274 {
275  h->add_property("animation_parameters", &s->animParams, Flags::Optional);
276  h->add_property("camera", &s->camera, Flags::Optional);
277  h->add_property("format", &s->format);
278  h->add_property("name", &s->name, Flags::Optional);
279  h->add_property("quality", &s->quality, Flags::Optional);
280  h->add_property("samples_per_pixel", &s->samplesPerPixel, Flags::Optional);
281  h->add_property("size", toArray<2, uint32_t>(s->size));
282  h->add_property("filePath", &s->filePath, Flags::Optional);
283  h->set_flags(Flags::DisallowUnknownKey);
284 }
285 
286 inline void init(core::Statistics* s, ObjectHandler* h)
287 {
288  h->add_property("fps", &s->_fps);
289  h->add_property("scene_size_in_bytes", &s->_sceneSizeInBytes);
290  h->set_flags(Flags::DisallowUnknownKey);
291 }
292 
293 inline void init(core::Renderer::PickResult* p, ObjectHandler* h)
294 {
295  h->add_property("hit", &p->hit);
296  h->add_property("position", toArray<3, double>(p->pos));
297  h->set_flags(Flags::DisallowUnknownKey);
298 }
299 
300 inline void init(core::Camera* c, ObjectHandler* h)
301 {
302  h->add_property("orientation", toArray(c->_orientation), Flags::Optional);
303  h->add_property("position", toArray<3, double>(c->_position), Flags::Optional);
304  h->add_property("target", toArray<3, double>(c->_target), Flags::Optional);
305  h->add_property("current", &c->_currentType, Flags::Optional);
306  static auto types = c->getTypes();
307  h->add_property("types", &types, Flags::IgnoreRead | Flags::Optional);
308  h->set_flags(Flags::DisallowUnknownKey);
309 }
310 
311 inline void init(core::Renderer* r, ObjectHandler* h)
312 {
313  h->add_property("head_light", &r->_headLight, Flags::Optional);
314  h->add_property("background_color", toArray<3, double>(r->_backgroundColor), Flags::Optional);
315  h->add_property("max_accum_frames", &r->_maxAccumFrames, Flags::Optional);
316  h->add_property("samples_per_pixel", &r->_spp, Flags::Optional);
317  h->add_property("subsampling", &r->_subsampling, Flags::Optional);
318  h->add_property("accumulation", &r->_accumulation, Flags::Optional);
319  h->add_property("current", &r->_currentType, Flags::Optional);
320  static auto types = r->getTypes();
321  h->add_property("types", &types, Flags::IgnoreRead | Flags::Optional);
322  h->set_flags(Flags::DisallowUnknownKey);
323 }
324 
325 inline void init(core::ImageGenerator::ImageBase64* i, ObjectHandler* h)
326 {
327  h->add_property("data", &i->data);
328  h->set_flags(Flags::DisallowUnknownKey);
329 }
330 
331 inline void init(core::ColorMap* t, ObjectHandler* h)
332 {
333  h->add_property("name", &t->name, Flags::Optional);
334  h->add_property("colors", toArray<3, float>(t->colors));
335 }
336 
337 inline void init(core::TransferFunction* t, ObjectHandler* h)
338 {
339  h->add_property("range", toArray<2, double>(t->_valuesRange), Flags::Optional);
340  h->add_property("opacity_curve", toArray<2, double>(t->_controlPoints), Flags::Optional);
341  h->add_property("colormap", &t->_colorMap, Flags::Optional);
342  h->set_flags(Flags::DisallowUnknownKey);
343 }
344 
345 inline void init(core::Boxd* b, ObjectHandler* h)
346 {
347  h->add_property("min", toArray<3, double>(b->_min));
348  h->add_property("max", toArray<3, double>(b->_max));
349  h->set_flags(Flags::DisallowUnknownKey);
350 }
351 
352 inline void init(core::Material* m, ObjectHandler* h)
353 {
354  h->add_property("name", &m->_name, Flags::Optional);
355  h->add_property("diffuse_color", toArray<3, double>(m->_diffuseColor), Flags::Optional);
356  h->add_property("specular_color", toArray<3, double>(m->_specularColor), Flags::Optional);
357  h->add_property("specular_exponent", &m->_specularExponent, Flags::Optional);
358  h->add_property("reflection_index", &m->_reflectionIndex, Flags::Optional);
359  h->add_property("opacity", &m->_opacity, Flags::Optional);
360  h->add_property("refraction_index", &m->_refractionIndex, Flags::Optional);
361  h->add_property("light_emission", &m->_emission, Flags::Optional);
362  h->add_property("glossiness", &m->_glossiness, Flags::Optional);
363  h->set_flags(Flags::DisallowUnknownKey);
364 }
365 
366 inline void init(core::Transformation* g, ObjectHandler* h)
367 {
368  h->add_property("translation", toArray<3, double>(g->_translation));
369  h->add_property("scale", toArray<3, double>(g->_scale));
370  h->add_property("rotation", toArray(g->_rotation));
371  h->add_property("rotation_center", toArray<3, double>(g->_rotationCenter), Flags::Optional);
372  h->set_flags(Flags::DisallowUnknownKey);
373 }
374 
375 inline void init(core::ModelInstance* i, ObjectHandler* h)
376 {
377  h->add_property("model_id", &i->_modelID);
378  h->add_property("instance_id", &i->_instanceID);
379  h->add_property("bounding_box", &i->_boundingBox, Flags::Optional);
380  h->add_property("transformation", &i->_transformation, Flags::Optional);
381  h->add_property("visible", &i->_visible, Flags::Optional);
382  h->set_flags(Flags::DisallowUnknownKey);
383 }
384 
385 inline void init(core::ModelParams* g, ObjectHandler* h)
386 {
387  h->add_property("bounding_box", &g->_boundingBox, Flags::Optional);
388  h->add_property("name", &g->_name, Flags::Optional);
389  h->add_property("path", &g->_path);
390  h->add_property("transformation", &g->_transformation, Flags::Optional);
391  h->add_property("visible", &g->_visible, Flags::Optional);
392  h->add_property("loader_name", &g->_loaderName, Flags::Optional);
393  h->add_property("loader_properties", &g->_loaderProperties, Flags::Optional);
394 
395  h->set_flags(Flags::DisallowUnknownKey);
396 }
397 
398 inline void init(core::ModelDescriptor* g, ObjectHandler* h)
399 {
400  h->add_property("bounding_box", &g->_boundingBox, Flags::Optional);
401  h->add_property("bounds", &g->_bounds, Flags::Optional);
402  h->add_property("id", &g->_modelID);
403  h->add_property("metadata", &g->_metadata, Flags::Optional);
404  h->add_property("name", &g->_name, Flags::Optional);
405  h->add_property("path", &g->_path, Flags::Optional);
406  h->add_property("transformation", &g->_transformation, Flags::Optional);
407  h->add_property("visible", &g->_visible, Flags::Optional);
408  h->set_flags(Flags::DisallowUnknownKey);
409 }
410 
411 inline void init(core::ClipPlane* g, ObjectHandler* h)
412 {
413  h->add_property("id", &g->_id);
414  h->add_property("plane", &g->_plane);
415  h->set_flags(Flags::DisallowUnknownKey);
416 }
417 
418 inline void init(core::Scene* s, ObjectHandler* h)
419 {
420  h->add_property("bounds", &s->_bounds, Flags::IgnoreRead | Flags::Optional);
421  h->add_property("models", &s->_modelDescriptors, Flags::Optional | Flags::IgnoreRead);
422  h->set_flags(Flags::DisallowUnknownKey);
423 }
424 
425 inline void init(core::ApplicationParameters* a, ObjectHandler* h)
426 {
427  h->add_property("engine", &a->_engine, Flags::IgnoreRead | Flags::Optional);
428  h->add_property("jpeg_compression", &a->_jpegCompression, Flags::Optional);
429  h->add_property("image_stream_fps", &a->_imageStreamFPS, Flags::Optional);
430  h->add_property("viewport", toArray<2, double>(a->_windowSize), Flags::Optional);
431  h->set_flags(Flags::DisallowUnknownKey);
432 }
433 
434 inline void init(core::RenderingParameters* r, ObjectHandler* h)
435 {
436  h->add_property("types", &r->_renderers, Flags::IgnoreRead | Flags::Optional);
437  h->add_property("variance_threshold", &r->_varianceThreshold, Flags::Optional);
438  h->add_property("num_non_denoised_frames", &r->_numNonDenoisedFrames, Flags::Optional);
439  h->add_property("denoise_blend", &r->_denoiseBlend, Flags::Optional);
440  h->add_property("tone_mapper_exposure", &r->_toneMapperExposure, Flags::Optional);
441  h->add_property("tone_mapper_gamma", &r->_toneMapperGamma, Flags::Optional);
442  h->set_flags(Flags::DisallowUnknownKey);
443 }
444 
445 inline void init(core::GeometryParameters* r, ObjectHandler* h)
446 {
447  h->add_property("sdf_epsilon", &r->_sdfEpsilon, Flags::Optional);
448  h->add_property("sdf_nb_march_iterations", &r->_sdfNbMarchIterations, Flags::Optional);
449  h->add_property("sdf_blend_factor", &r->_sdfBlendFactor, Flags::Optional);
450  h->add_property("sdf_blend_lerp_factor", &r->_sdfBlendLerpFactor, Flags::Optional);
451  h->add_property("sdf_ray_marching_omega", &r->_sdfOmega, Flags::Optional);
452  h->add_property("sdf_distance", &r->_sdfDistance, Flags::Optional);
453  h->set_flags(Flags::DisallowUnknownKey);
454 }
455 
456 inline void init(core::VolumeParameters* v, ObjectHandler* h)
457 {
458  h->add_property("volume_dimensions", toArray<3, uint32_t>(v->_dimensions), Flags::Optional);
459  h->add_property("volume_element_spacing", toArray<3, double>(v->_elementSpacing), Flags::Optional);
460  h->add_property("volume_offset", toArray<3, double>(v->_offset), Flags::Optional);
461 
462  h->add_property("gradient_shading", &v->_gradientShading, Flags::Optional);
463  h->add_property("gradient_offset", &v->_gradientOffset, Flags::Optional);
464  h->add_property("single_shade", &v->_singleShade, Flags::Optional);
465  h->add_property("pre_integration", &v->_preIntegration, Flags::Optional);
466  h->add_property("adaptive_max_sampling_rate", &v->_adaptiveMaxSamplingRate, Flags::Optional);
467  h->add_property("adaptive_sampling", &v->_adaptiveSampling, Flags::Optional);
468  h->add_property("sampling_rate", &v->_samplingRate, Flags::Optional);
469  h->add_property("specular", toArray<3, double>(v->_specular), Flags::Optional);
470  h->add_property("clip_box", &v->_clipBox, Flags::Optional);
471  h->add_property("user_parameters", toArray<3, double>(v->_userParameters), Flags::Optional);
472  h->set_flags(Flags::DisallowUnknownKey);
473 }
474 
475 inline void init(core::FieldParameters* v, ObjectHandler* h)
476 {
477  h->add_property("gradient_shading", &v->_gradientShading, Flags::Optional);
478  h->add_property("gradient_offset", &v->_gradientOffset, Flags::Optional);
479  h->add_property("sampling_rate", &v->_samplingRate, Flags::Optional);
480  h->add_property("distance", &v->_distance, Flags::Optional);
481  h->add_property("cutoff", &v->_cutoff, Flags::Optional);
482  h->add_property("epsilon", &v->_epsilon, Flags::Optional);
483  h->add_property("accumulation_steps", &v->_randomAccumulation, Flags::Optional);
484  h->add_property("use_octree", &v->_useOctree, Flags::Optional);
485  h->set_flags(Flags::DisallowUnknownKey);
486 }
487 
488 inline void init(core::AnimationParameters* a, ObjectHandler* h)
489 {
490  h->add_property("frame_count", &a->_numFrames, Flags::Optional);
491  h->add_property("current", &a->_current, Flags::Optional);
492  h->add_property("delta", &a->_delta, Flags::Optional);
493  h->add_property("dt", &a->_dt, Flags::Optional);
494  h->add_property("playing", &a->_playing, Flags::Optional);
495  h->add_property("unit", &a->_unit, Flags::Optional);
496  h->set_flags(Flags::DisallowUnknownKey);
497 }
498 
499 inline void init(core::LoaderInfo* a, ObjectHandler* h)
500 {
501  h->add_property("name", &a->name);
502  h->add_property("extensions", &a->extensions);
503  h->add_property("properties", &a->properties);
504  h->set_flags(Flags::DisallowUnknownKey);
505 }
506 
507 inline void init(core::Light* a, ObjectHandler* h)
508 {
509  h->add_property("color", toArray<3, double>(a->_color));
510  h->add_property("intensity", &a->_intensity);
511  h->add_property("is_visible", &a->_isVisible);
512  h->set_flags(Flags::DisallowUnknownKey);
513 }
514 
515 inline void init(core::DirectionalLight* a, ObjectHandler* h)
516 {
517  init(static_cast<core::Light*>(a), h);
518  h->add_property("direction", toArray<3, double>(a->_direction));
519  h->add_property("angularDiameter", &a->_angularDiameter);
520  h->set_flags(Flags::DisallowUnknownKey);
521 }
522 
523 inline void init(core::SphereLight* a, ObjectHandler* h)
524 {
525  init(static_cast<core::Light*>(a), h);
526  h->add_property("position", toArray<3, double>(a->_position));
527  h->add_property("radius", &a->_radius);
528  h->set_flags(Flags::DisallowUnknownKey);
529 }
530 
531 inline void init(core::QuadLight* a, ObjectHandler* h)
532 {
533  init(static_cast<core::Light*>(a), h);
534  h->add_property("position", toArray<3, double>(a->_position));
535  h->add_property("edge1", toArray<3, double>(a->_edge1));
536  h->add_property("edge2", toArray<3, double>(a->_edge2));
537  h->set_flags(Flags::DisallowUnknownKey);
538 }
539 
540 inline void init(core::SpotLight* a, ObjectHandler* h)
541 {
542  init(static_cast<core::Light*>(a), h);
543  h->add_property("position", toArray<3, double>(a->_position));
544  h->add_property("direction", toArray<3, double>(a->_direction));
545  h->add_property("openingAngle", &a->_openingAngle);
546  h->add_property("penumbraAngle", &a->_penumbraAngle);
547  h->add_property("radius", &a->_radius);
548  h->set_flags(Flags::DisallowUnknownKey);
549 }
550 
551 inline void init(core::AmbientLight* a, ObjectHandler* h)
552 {
553  init(static_cast<core::Light*>(a), h);
554  h->set_flags(Flags::DisallowUnknownKey);
555 }
556 
557 inline void init(core::RPCLight* a, ObjectHandler* h)
558 {
559  h->add_property("id", &a->id);
560  h->add_property("type", &a->type);
561  h->add_property("properties", &a->properties);
562  h->set_flags(Flags::DisallowUnknownKey);
563 }
564 
565 inline void init(core::InputPath* a, ObjectHandler* h)
566 {
567  h->add_property("path", &a->path);
568  h->set_flags(Flags::DisallowUnknownKey);
569 }
570 
571 inline void init(core::FileType* a, ObjectHandler* h)
572 {
573  h->add_property("type", &a->type);
574  h->add_property("error", &a->error);
575  h->add_property("message", &a->message);
576  h->set_flags(Flags::DisallowUnknownKey);
577 }
578 
579 inline void init(core::FileContent* a, ObjectHandler* h)
580 {
581  h->add_property("content", &a->content);
582  h->add_property("error", &a->error);
583  h->add_property("message", &a->message);
584  h->set_flags(Flags::DisallowUnknownKey);
585 }
586 
587 inline void init(core::FileRoot* a, ObjectHandler* h)
588 {
589  h->add_property("root", &a->root);
590  h->set_flags(Flags::DisallowUnknownKey);
591 }
592 
593 inline void init(core::DirectoryFiles* a, ObjectHandler* h)
594 {
595  h->add_property("names", &a->names);
596  h->add_property("sizes", &a->sizes);
597 }
598 
599 inline void init(core::DirectoryFileList* a, ObjectHandler* h)
600 {
601  h->add_property("files", &a->files);
602  h->add_property("dirs", &a->dirs);
603  h->add_property("error", &a->error);
604  h->add_property("message", &a->message);
605  h->set_flags(Flags::DisallowUnknownKey);
606 }
607 
608 inline void init(core::ImageStreamingMethod* a, ObjectHandler* h)
609 {
610  h->add_property("type", &a->type);
611  h->set_flags(Flags::DisallowUnknownKey);
612 }
613 
614 inline void init(core::ExitLaterSchedule* a, ObjectHandler* h)
615 {
616  h->add_property("minutes", &a->minutes);
617  h->set_flags(Flags::DisallowUnknownKey);
618 }
619 
620 } // namespace staticjson
621 
622 // for rockets::jsonrpc
623 template <class T>
624 inline std::string to_json(const T& obj)
625 {
626  return staticjson::to_json_string(obj);
627 }
628 
629 template <>
630 std::string to_json(const core::PropertyMap& obj);
631 
632 template <>
633 inline std::string to_json(const core::Version& obj)
634 {
635  return obj.toJSON();
636 }
637 
638 template <>
639 inline std::string to_json(const core::Scene& scene)
640 {
641  auto lock = scene.acquireReadAccess();
642  return staticjson::to_json_string(scene);
643 }
644 
645 template <typename T>
646 inline std::string toJSONReplacePropertyMap(const T& params, const std::string& propertyMapName,
647  const core::PropertyMap& properties)
648 {
649  const auto jsonOriginal = staticjson::to_json_string(params);
650 
651  const std::string key = "\"" + propertyMapName + "\"";
652  const std::string propertiesJson = key + ":" + to_json(properties);
653 
654  const auto result = core::string_utils::replaceFirstOccurrence(jsonOriginal, key + ":{}", propertiesJson);
655  return result;
656 }
657 
658 template <>
659 inline std::string to_json(const core::ModelProperties& props)
660 {
661  return toJSONReplacePropertyMap(props, "properties", props.properties);
662 }
663 
664 template <>
665 inline std::string to_json(const core::ModelParams& params)
666 {
667  return toJSONReplacePropertyMap(params, "loader_properties", params.getLoaderProperties());
668 }
669 
670 template <>
671 inline std::string to_json(const core::BinaryParam& params)
672 {
673  return toJSONReplacePropertyMap(params, "loader_properties", params.getLoaderProperties());
674 }
675 
676 template <>
677 inline std::string to_json(const core::RPCLight& light)
678 {
679  return toJSONReplacePropertyMap(light, "properties", light.properties);
680 }
681 
682 template <class T>
683 inline bool from_json(T& obj, const std::string& json)
684 {
685  return staticjson::from_json_string(json.c_str(), &obj, nullptr);
686 }
687 template <>
688 inline bool from_json(core::Vector2d& obj, const std::string& json)
689 {
690  return staticjson::from_json_string(json.c_str(), toArray<2, double>(obj), nullptr);
691 }
692 
693 core::PropertyMap jsonToPropertyMap(const std::string& json);
694 
695 template <typename T>
696 inline std::pair<bool, core::PropertyMap> fromJSONWithPropertyMap(T& params, const std::string& json,
697  const std::string& propertyMapName)
698 {
699  using namespace rapidjson;
700  Document document;
701  document.Parse(json.c_str());
702 
703  core::PropertyMap propertyMap;
704 
705  if (document.HasMember(propertyMapName.c_str()))
706  {
707  auto& loaderProperties = document[propertyMapName.c_str()];
708  Document propertyDoc;
709  propertyDoc.CopyFrom(loaderProperties, propertyDoc.GetAllocator());
710  rapidjson::StringBuffer buffer;
711  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
712  propertyDoc.Accept(writer);
713 
714  propertyMap = jsonToPropertyMap(buffer.GetString());
715 
716  // Clear property map to be able to parse rest of values
717  loaderProperties.SetObject();
718  }
719 
720  rapidjson::StringBuffer buffer;
721  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
722  document.Accept(writer);
723  const auto str = buffer.GetString();
724  return {staticjson::from_json_string(str, &params, nullptr), propertyMap};
725 }
726 
727 template <typename T>
728 inline bool modelBinaryParamsFromJson(T& params, const std::string& json)
729 {
730  bool success;
731  core::PropertyMap propertyMap;
732  std::tie<bool, core::PropertyMap>(success, propertyMap) =
733  fromJSONWithPropertyMap(params, json, "loader_properties");
734  params.setLoaderProperties(propertyMap);
735  return success;
736 }
737 
738 template <>
739 inline bool from_json(core::BinaryParam& params, const std::string& json)
740 {
741  return modelBinaryParamsFromJson(params, json);
742 }
743 
744 template <>
745 inline bool from_json(core::ModelParams& params, const std::string& json)
746 {
747  return modelBinaryParamsFromJson(params, json);
748 }
749 
750 template <>
751 inline bool from_json(core::RPCLight& light, const std::string& json)
752 {
753  bool success;
754  core::PropertyMap propertyMap;
755  std::tie<bool, core::PropertyMap>(success, propertyMap) = fromJSONWithPropertyMap(light, json, "properties");
756  light.properties = propertyMap;
757  return success;
758 }
The Camera class is an abstract interface for a camera in a 3D graphics application....
Definition: Camera.h:41
Vector3d _direction
Definition: Light.h:72
double _angularDiameter
Definition: Light.h:73
The Light class defines the common base class for all lights.
Definition: Light.h:43
Vector3d _color
Definition: Light.h:50
bool _isVisible
Definition: Light.h:52
double _intensity
Definition: Light.h:51
The class that represents the material object. This class is derived from PropertyObject and provides...
Definition: Material.h:47
Vector3d _diffuseColor
Definition: Material.h:256
double _refractionIndex
Definition: Material.h:261
double _opacity
Definition: Material.h:260
double _specularExponent
Definition: Material.h:258
double _glossiness
Definition: Material.h:263
double _emission
Definition: Material.h:262
std::string _name
Definition: Material.h:255
Vector3d _specularColor
Definition: Material.h:257
double _reflectionIndex
Definition: Material.h:259
The ModelDescriptor struct defines the metadata attached to a model.Model descriptor are exposed via ...
Definition: Model.h:285
A class representing an instance of a 3D model.
Definition: Model.h:80
size_t _modelID
Definition: Model.h:164
Transformation _transformation
Definition: Model.h:168
size_t _instanceID
Definition: Model.h:165
The ModelParams class represents the parameters needed for initializing a model instance.
Definition: Model.h:178
std::string _name
Definition: Model.h:265
PLATFORM_API const PropertyMap & getLoaderProperties() const
getLoaderProperties gets the loader properties of the model
Definition: Model.h:256
std::string _loaderName
Definition: Model.h:267
PropertyMap _loaderProperties
Definition: Model.h:268
std::string _path
Definition: Model.h:266
std::string _currentType
strings getTypes() const
Vector3d _position
Definition: Light.h:115
Vector3d _edge1
Definition: Light.h:116
Vector3d _edge2
Definition: Light.h:117
Renderer class inherits from PropertyObject class The Renderer class has methods to render a FrameBuf...
Definition: Renderer.h:42
Vector3d _backgroundColor
Definition: Renderer.h:144
size_t _maxAccumFrames
Definition: Renderer.h:147
bool _accumulation
Definition: Renderer.h:142
uint32_t _subsampling
Definition: Renderer.h:146
uint32_t _spp
Definition: Renderer.h:145
bool _headLight
Definition: Renderer.h:143
std::deque< std::string > _renderers
Scene object This object contains collections of geometries, materials and light sources that are use...
Definition: Scene.h:43
ModelDescriptors _modelDescriptors
Definition: Scene.h:247
Boxd _bounds
Definition: Scene.h:254
PLATFORM_API auto acquireReadAccess() const
Definition: Scene.h:217
double _radius
Definition: Light.h:93
Vector3d _position
Definition: Light.h:92
double _openingAngle
Definition: Light.h:145
Vector3d _direction
Definition: Light.h:144
double _penumbraAngle
Definition: Light.h:146
Vector3d _position
Definition: Light.h:143
double _radius
Definition: Light.h:147
Defines the translation, rotation and scale parameters to be applied to a scene asset.
bool from_json(T &obj, const std::string &json)
bool modelBinaryParamsFromJson(T &params, const std::string &json)
std::pair< bool, core::PropertyMap > fromJSONWithPropertyMap(T &params, const std::string &json, const std::string &propertyMapName)
std::string to_json(const T &obj)
STATICJSON_DECLARE_ENUM(core::GeometryQuality, {"low", core::GeometryQuality::low}, {"medium", core::GeometryQuality::medium}, {"high", core::GeometryQuality::high})
core::PropertyMap jsonToPropertyMap(const std::string &json)
std::string toJSONReplacePropertyMap(const T &params, const std::string &propertyMapName, const core::PropertyMap &properties)
auto toArray(glm::vec< M, T > &vec)
std::string replaceFirstOccurrence(std::string input, const std::string &toReplace, const std::string &replaceWith)
Definition: StringUtils.cpp:49
GeometryQuality
Definition: Types.h:222
MemoryMode
Definition: Types.h:281
glm::vec< 2, double > Vector2d
Definition: MathTypes.h:142
TextureType
Definition: Types.h:244
glm::vec< 2, uint32_t > Vector2ui
Definition: MathTypes.h:133
void init(core::Box< U > *, ObjectHandler *)
@ vector
Definition: CommonTypes.h:68
std::vector< std::string > strings
Definition: Types.h:44
std::vector< uint64_t > uint64_ts
Definition: Types.h:55
std::string type
file extension or type (MESH, POINTS, CIRCUIT)
size_t size
size in bytes of file
std::string name
std::string message
std::vector< std::string > extensions
std::string name
PropertyMap properties
TransferFunction transferFunction
PropertyMap properties
PickResult Struct containing hit boolean value and Vector3d pos PickResult struct is used to retrieve...
Definition: Renderer.h:51
std::string filePath
Definition: SnapshotTask.h:54
std::unique_ptr< AnimationParameters > animParams
Definition: SnapshotTask.h:43
std::unique_ptr< Camera > camera
Definition: SnapshotTask.h:48
std::string format
Definition: SnapshotTask.h:52
bool operator!=(const VideoStreamParam &rhs) const
bool operator==(const VideoStreamParam &rhs) const