Visualization Library 2.0.0-b3

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
VLXWrappers.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2017, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef VLXWrapper_Core_INCLUDE_ONCE
33 #define VLXWrapper_Core_INCLUDE_ONCE
34 
36 #include <vlCore/VLXRegistry.hpp>
37 #include <vlCore/VLXSerializer.hpp>
38 #include <vlCore/VLXValue.hpp>
39 #include <vlCore/vlxutils.hpp>
40 
41 #define VL_SERIALIZER_VERSION 100
42 
43 #define VLX_IMPORT_CHECK_RETURN(Condition, Obj) \
44  if (!(Condition)) \
45  { \
46  s.signalImportError( Say("Line %n : condition failed : %s\n\tsee %s : %n\n") << (Obj).lineNumber() << #Condition << __FILE__ << __LINE__ ); \
47  return; \
48  }
49 
50 #define VLX_IMPORT_CHECK_RETURN_NULL(Condition, Obj) \
51  if (!(Condition)) \
52  { \
53  s.signalImportError( Say("Line %n : condition failed : %s\n\tsee %s : %n\n") << (Obj).lineNumber() << #Condition << __FILE__ << __LINE__ ); \
54  return NULL; \
55  }
56 
57 namespace vl
58 {
59  inline VLXValue export_AABB(const AABB& aabb)
60  {
61  VLXValue value ( new VLXStructure("<vl::AABB>") );
62  *value.getStructure() << "MinCorner" << vlx_toValue(aabb.minCorner());
63  *value.getStructure() << "MaxCorner" << vlx_toValue(aabb.maxCorner());
64  return value;
65  }
66 
67  inline AABB import_AABB(const VLXStructure* vlx)
68  {
69  AABB aabb;
70 
71  VL_CHECK( vlx->tag() == "<vl::AABB>" )
72 
73  for(size_t i=0; i<vlx->value().size(); ++i)
74  {
75  const std::string& key = vlx->value()[i].key();
76  const VLXValue& value = vlx->value()[i].value();
77  if (key == "MinCorner")
78  {
80  aabb.setMinCorner( vlx_vec3(value.getArrayReal()) );
81  }
82  else
83  if (key == "MaxCorner")
84  {
86  aabb.setMaxCorner( vlx_vec3(value.getArrayReal()) );
87  }
88  }
89 
90  return aabb;
91  }
92 
93  inline VLXValue export_Sphere(const Sphere& sphere)
94  {
95  VLXValue value ( new VLXStructure("<vl::Sphere>") );
96  *value.getStructure() << "Center" << vlx_toValue(sphere.center());
97  *value.getStructure() << "Radius" << sphere.radius();
98  return value;
99  }
100 
101  inline Sphere import_Sphere(const VLXStructure* vlx)
102  {
103  Sphere sphere;
104 
105  VL_CHECK( vlx->tag() == "<vl::Sphere>" )
106 
107  for(size_t i=0; i<vlx->value().size(); ++i)
108  {
109  const std::string& key = vlx->value()[i].key();
110  const VLXValue& value = vlx->value()[i].value();
111  if (key == "Center")
112  {
113  VL_CHECK(value.type() == VLXValue::ArrayReal)
114  sphere.setCenter( vlx_vec3(value.getArrayReal()) );
115  }
116  else
117  if (key == "Radius")
118  {
119  VL_CHECK(value.type() == VLXValue::Real)
120  sphere.setRadius( (real)value.getReal() );
121  }
122  }
123 
124  return sphere;
125  }
126 }
127 
128 #endif
vec3 vlx_vec3(const VLXArrayReal *arr)
Definition: vlxutils.hpp:56
VLXValue export_AABB(const AABB &aabb)
Definition: VLXWrappers.hpp:59
double getReal() const
Definition: VLXValue.hpp:505
const vec3 & center() const
Returns the center of the sphere.
Definition: Sphere.hpp:68
VLXValue export_Sphere(const Sphere &sphere)
Definition: VLXWrappers.hpp:93
Visualization Library main namespace.
Sphere import_Sphere(const VLXStructure *vlx)
real radius() const
Returns the radius of the sphere.
Definition: Sphere.hpp:74
VLXStructure * getStructure()
Definition: VLXValue.hpp:401
The AABB class implements an axis-aligned bounding box using vl::real precision.
Definition: AABB.hpp:44
const std::string & tag() const
Definition: VLXValue.hpp:62
std::vector< Value > & value()
Definition: VLXValue.hpp:606
const vec3 & maxCorner() const
Returns the corner of the AABB with the maximum x y z coordinates.
Definition: AABB.hpp:193
void setMinCorner(real x, real y, real z)
Sets the corner of the AABB with the minimum x y z coordinates.
Definition: AABB.hpp:196
void setRadius(real radius)
Sets the radius of the sphere.
Definition: Sphere.hpp:71
void setMaxCorner(real x, real y, real z)
Sets the corner of the AABB with the maximum x y z coordinates.
Definition: AABB.hpp:202
EType type() const
Definition: VLXValue.hpp:395
Wrapper for all VLX value types.
Definition: VLXValue.hpp:239
AABB import_AABB(const VLXStructure *vlx)
Definition: VLXWrappers.hpp:67
VLXArrayReal * getArrayReal()
Definition: VLXValue.hpp:446
The Sphere class defines a sphere using a center and a radius using vl::real precision.
Definition: Sphere.hpp:43
const vec3 & minCorner() const
Returns the corner of the AABB with the minimum x y z coordinates.
Definition: AABB.hpp:190
A list of key/VLXValue pairs, can also have a tag.
Definition: VLXValue.hpp:540
#define VL_CHECK(expr)
Definition: checks.hpp:73
VLXValue vlx_toValue(const std::vector< int > &vec)
Definition: vlxutils.hpp:64
void setCenter(const vec3 &center)
Sets the center of the sphere.
Definition: Sphere.hpp:65