Visualization Library 2.0.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
WrappersCore.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, 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 
35 #include <vlX/ClassWrapper.hpp>
36 #include <vlX/Registry.hpp>
37 #include <vlX/Serializer.hpp>
38 #include <vlX/Value.hpp>
39 #include <vlX/vlxutils.hpp>
40 #include <vlX/Defines.hpp>
41 
42 #define VLX_IMPORT_CHECK_RETURN(Condition, Obj) \
43  if (!(Condition)) \
44  { \
45  s.signalImportError( vl::Say("Line %n : condition failed : %s\n\tsee %s : %n\n") << (Obj).lineNumber() << #Condition << __FILE__ << __LINE__ ); \
46  return; \
47  }
48 
49 #define VLX_IMPORT_CHECK_RETURN_NULL(Condition, Obj) \
50  if (!(Condition)) \
51  { \
52  s.signalImportError( vl::Say("Line %n : condition failed : %s\n\tsee %s : %n\n") << (Obj).lineNumber() << #Condition << __FILE__ << __LINE__ ); \
53  return NULL; \
54  }
55 
56 namespace vlX
57 {
58  inline VLXValue export_AABB(const vl::AABB& aabb)
59  {
60  VLXValue value ( new VLXStructure("<vl::AABB>") );
61  *value.getStructure() << "MinCorner" << vlx_toValue(aabb.minCorner());
62  *value.getStructure() << "MaxCorner" << vlx_toValue(aabb.maxCorner());
63  return value;
64  }
65 
66  inline vl::AABB import_AABB(const VLXStructure* vlx)
67  {
68  vl::AABB aabb;
69 
70  VL_CHECK( vlx->tag() == "<vl::AABB>" )
71 
72  for(size_t i=0; i<vlx->value().size(); ++i)
73  {
74  const std::string& key = vlx->value()[i].key();
75  const VLXValue& value = vlx->value()[i].value();
76  if (key == "MinCorner")
77  {
79  aabb.setMinCorner( vlx_vec3(value.getArrayReal()) );
80  }
81  else
82  if (key == "MaxCorner")
83  {
85  aabb.setMaxCorner( vlx_vec3(value.getArrayReal()) );
86  }
87  }
88 
89  return aabb;
90  }
91 
92  inline VLXValue export_Sphere(const vl::Sphere& sphere)
93  {
94  VLXValue value ( new VLXStructure("<vl::Sphere>") );
95  *value.getStructure() << "Center" << vlx_toValue(sphere.center());
96  *value.getStructure() << "Radius" << sphere.radius();
97  return value;
98  }
99 
101  {
102  vl::Sphere sphere;
103 
104  VL_CHECK( vlx->tag() == "<vl::Sphere>" )
105 
106  for(size_t i=0; i<vlx->value().size(); ++i)
107  {
108  const std::string& key = vlx->value()[i].key();
109  const VLXValue& value = vlx->value()[i].value();
110  if (key == "Center")
111  {
112  VL_CHECK(value.type() == VLXValue::ArrayReal)
113  sphere.setCenter( vlx_vec3(value.getArrayReal()) );
114  }
115  else
116  if (key == "Radius")
117  {
118  VL_CHECK(value.type() == VLXValue::Real)
119  sphere.setRadius( (vl::real)value.getReal() );
120  }
121  }
122 
123  return sphere;
124  }
125 }
126 
127 #endif
Wrapper for all VLX value types.
Definition: Value.hpp:240
const vec3 & center() const
Returns the center of the sphere.
Definition: Sphere.hpp:68
double getReal() const
Definition: Value.hpp:506
VLXValue export_Sphere(const vl::Sphere &sphere)
vl::vec3 vlx_vec3(const VLXArrayReal *arr)
Definition: vlxutils.hpp:56
VLXStructure * getStructure()
Definition: Value.hpp:402
real radius() const
Returns the radius of the sphere.
Definition: Sphere.hpp:74
A list of key/VLXValue pairs, can also have a tag.
Definition: Value.hpp:541
vl::Sphere import_Sphere(const VLXStructure *vlx)
The AABB class implements an axis-aligned bounding box using vl::real precision.
Definition: AABB.hpp:44
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
const std::string & tag() const
Definition: Value.hpp:63
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
std::vector< KeyValue > & value()
Definition: Value.hpp:607
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
EType type() const
Definition: Value.hpp:396
VLXValue vlx_toValue(const std::vector< int > &vec)
Definition: vlxutils.hpp:64
#define VL_CHECK(expr)
Definition: checks.hpp:73
VLXArrayReal * getArrayReal()
Definition: Value.hpp:447
vl::AABB import_AABB(const VLXStructure *vlx)
void setCenter(const vec3 &center)
Sets the center of the sphere.
Definition: Sphere.hpp:65
VLXValue export_AABB(const vl::AABB &aabb)