Virtual Testbed
Ship dynamics simulator for extreme conditions
guile/polyhedron.cc
1 #include <vtestbed/config/real_type.hh>
2 #include <vtestbed/geometry/polyhedron.hh>
3 #include <vtestbed/guile/grid.hh>
4 #include <vtestbed/guile/macros.hh>
5 #include <vtestbed/guile/traits.hh>
6 
9 
10 namespace {
11  SCM type;
12 }
13 
14 #define VTB_POLYHEDRON_WRAP_VOID_FUNC(name) \
15  SCM polyhedron_##name(SCM object) { \
16  auto* wrapper = get_wrapper<object_type>(object); \
17  auto* copy = wrapper->copy(); \
18  copy->name(); \
19  return make_object<object_type>(::type, copy); \
20  } \
21  \
22  SCM polyhedron_##name##_self(SCM object) { \
23  auto* wrapper = get_wrapper<object_type>(object); \
24  wrapper->get()->name(); \
25  return SCM_UNSPECIFIED; \
26  }
27 
28 #define VTB_POLYHEDRON_WRAP_VOID_FUNC_1_ARG(name, ...) \
29  SCM polyhedron_##name(SCM object, SCM arg) { \
30  auto* wrapper = get_wrapper<object_type>(object); \
31  auto* copy = wrapper->copy(); \
32  copy->name(__VA_ARGS__(arg)); \
33  return make_object<object_type>(::type, copy); \
34  } \
35  \
36  SCM polyhedron_##name##_self(SCM object, SCM arg) { \
37  auto* wrapper = get_wrapper<object_type>(object); \
38  wrapper->get()->name(__VA_ARGS__(arg)); \
39  return SCM_UNSPECIFIED; \
40  }
41 
42 #define VTB_POLYHEDRON_WRAP_VOID_FUNC_2_ARG(name, to_arg1, to_arg2) \
43  SCM polyhedron_##name(SCM object, SCM arg1, SCM arg2) { \
44  auto* wrapper = get_wrapper<object_type>(object); \
45  auto* copy = wrapper->copy(); \
46  copy->name(to_arg1(arg1), to_arg2(arg2)); \
47  return make_object<object_type>(::type, copy); \
48  } \
49  \
50  SCM polyhedron_##name##_self(SCM object, SCM arg1, SCM arg2) { \
51  auto* wrapper = get_wrapper<object_type>(object); \
52  wrapper->get()->name(to_arg1(arg1), to_arg2(arg2)); \
53  return SCM_UNSPECIFIED; \
54  }
55 
56 namespace vtb {
57 
58  namespace guile {
59 
60  template <> SCM traits_type::type() { return ::type; }
61 
69  VTB_POLYHEDRON_WRAP_VOID_FUNC(reorder)
70 
71 
78  VTB_POLYHEDRON_WRAP_VOID_FUNC(normalise)
79 
87  VTB_POLYHEDRON_WRAP_VOID_FUNC(unique)
88 
96  VTB_POLYHEDRON_WRAP_VOID_FUNC_1_ARG(move, to_vector<VTB_REAL_TYPE,3>)
97 
105  VTB_POLYHEDRON_WRAP_VOID_FUNC_1_ARG(scale, to_vector<VTB_REAL_TYPE,3>)
106 
114  VTB_POLYHEDRON_WRAP_VOID_FUNC_1_ARG(flip, scm_to_int)
115 
123  VTB_POLYHEDRON_WRAP_VOID_FUNC_1_ARG(mirror, scm_to_int)
124 
133  VTB_POLYHEDRON_WRAP_VOID_FUNC_2_ARG(rotate, scm_to_int, scm_to_int)
134 
142  SCM polyhedron_empty(SCM object) {
143  auto* wrapper = get_wrapper<object_type>(object);
144  return scm_from_bool(wrapper->get()->empty());
145  }
146 
154  SCM polyhedron_signed_volume(SCM object) {
155  auto* wrapper = get_wrapper<object_type>(object);
156  return scm_from_double(signed_volume(*wrapper->get()));
157  }
158 
166  SCM polyhedron_signed_volume_below(SCM object, SCM dimension, SCM level) {
167  auto* wrapper = get_wrapper<object_type>(object);
168  auto dim = scm_to_int(dimension);
169  auto lvl = scm_to_double(level);
170  return scm_from_double(wrapper->get()->signed_volume_below(dim, lvl));
171  }
172 
180  SCM polyhedron_volume(SCM object) {
181  auto* wrapper = get_wrapper<object_type>(object);
182  return scm_from_double(volume(*wrapper->get()));
183  }
184 
192  SCM polyhedron_centroid(SCM object) {
193  auto* wrapper = get_wrapper<object_type>(object);
194  return to_scm(centroid(*wrapper->get()));
195  }
196 
204  SCM polyhedron_bounding_box(SCM object) {
205  auto* wrapper = get_wrapper<object_type>(object);
206  const auto& bbox = wrapper->get()->bounding_box();
207  return scm_cons(to_scm(bbox.min()), to_scm(bbox.max()));
208  }
209 
217  SCM polyhedron_bounds(SCM object, SCM dimension) {
218  auto* wrapper = get_wrapper<object_type>(object);
219  const auto& bbox = wrapper->get()->bounds(scm_to_int(dimension));
220  return scm_cons(to_scm(bbox.min()), to_scm(bbox.max()));
221  }
222 
229  inline SCM make_polyhedron() { return traits_type::make(); }
230 
231  template <> void
232  traits_type::define() {
233  ::type = define_type<object_type>("<polyhedron>");
234  define_procedure("make-polyhedron", 0, 0, 0, VTB_GUILE_0(make_polyhedron));
235  define_procedure("polyhedron-reorder", 1, 0, 0, VTB_GUILE_1(polyhedron_reorder));
236  define_procedure("polyhedron-reorder!", 1, 0, 0,
237  VTB_GUILE_1(polyhedron_reorder_self));
238  define_procedure("polyhedron-normalise", 1, 0, 0,
239  VTB_GUILE_1(polyhedron_normalise));
240  define_procedure("polyhedron-normalise!", 1, 0, 0,
241  VTB_GUILE_1(polyhedron_normalise_self));
242  define_procedure("polyhedron-unique", 1, 0, 0, VTB_GUILE_1(polyhedron_unique));
243  define_procedure("polyhedron-unique!", 1, 0, 0,
244  VTB_GUILE_1(polyhedron_unique_self));
245  define_procedure("polyhedron-empty?", 1, 0, 0, VTB_GUILE_1(polyhedron_empty));
246  define_procedure("polyhedron-signed-volume", 1, 0, 0,
247  VTB_GUILE_1(polyhedron_signed_volume));
248  define_procedure("polyhedron-signed-volume-below", 3, 0, 0,
249  VTB_GUILE_3(polyhedron_signed_volume_below));
250  define_procedure("polyhedron-volume", 1, 0, 0, VTB_GUILE_1(polyhedron_volume));
251  define_procedure("polyhedron-centroid", 1, 0, 0, VTB_GUILE_1(polyhedron_centroid));
252  define_procedure("polyhedron-bounding-box", 1, 0, 0,
253  VTB_GUILE_1(polyhedron_bounding_box));
254  define_procedure("polyhedron-bounds", 2, 0, 0, VTB_GUILE_2(polyhedron_bounds));
255  define_procedure("polyhedron-move", 2, 0, 0, VTB_GUILE_2(polyhedron_move));
256  define_procedure("polyhedron-move!", 2, 0, 0, VTB_GUILE_2(polyhedron_move_self));
257  define_procedure("polyhedron-scale", 2, 0, 0, VTB_GUILE_2(polyhedron_scale));
258  define_procedure("polyhedron-scale!", 2, 0, 0, VTB_GUILE_2(polyhedron_scale_self));
259  define_procedure("polyhedron-flip", 2, 0, 0, VTB_GUILE_2(polyhedron_flip));
260  define_procedure("polyhedron-flip!", 2, 0, 0, VTB_GUILE_2(polyhedron_flip_self));
261  define_procedure("polyhedron-mirror", 2, 0, 0, VTB_GUILE_2(polyhedron_mirror));
262  define_procedure("polyhedron-mirror!", 2, 0, 0,
263  VTB_GUILE_2(polyhedron_mirror_self));
264  define_procedure("polyhedron-rotate", 3, 0, 0, VTB_GUILE_3(polyhedron_rotate));
265  define_procedure("polyhedron-rotate!", 3, 0, 0,
266  VTB_GUILE_3(polyhedron_rotate_self));
267  }
268 
269  }
270 
271 }
SCM polyhedron_move(SCM object, SCM arg)
Move the polyhedron to a specified amount in three dimensions.
SCM polyhedron_flip(SCM object, SCM arg)
Flip the polyhedron relative to the origin in a specified dimension.
SCM polyhedron_reorder_self(SCM object)
Fix face winding.
SCM polyhedron_move_self(SCM object, SCM arg)
Move the polyhedron to a specified amount in three dimensions.
SCM polyhedron_volume(SCM object)
Compute absolute volume of the polyhedron.
SCM polyhedron_reorder(SCM object)
Fix face winding.
SCM polyhedron_signed_volume(SCM object)
Compute signed volume of the polyhedron.
SCM polyhedron_flip_self(SCM object, SCM arg)
Flip the polyhedron relative to the origin in a specified dimension.
SCM polyhedron_rotate(SCM object, SCM arg1, SCM arg2)
Rotate the polhedron relative to the origin in a specified dimension by an angle that is multiple of ...
SCM polyhedron_empty(SCM object)
Check if polyhedron is not initialised.
SCM polyhedron_normalise_self(SCM object)
Compute vertex and face normals.
SCM polyhedron_mirror_self(SCM object, SCM arg)
Mirror the polhedron relative to the origin in a specified dimension.
SCM make_polyhedron()
Construct polyhedron.
SCM polyhedron_scale(SCM object, SCM arg)
Scale the polyhedron by a specified factor in three dimensions.
SCM polyhedron_rotate_self(SCM object, SCM arg1, SCM arg2)
Rotate the polhedron relative to the origin in a specified dimension by an angle that is multiple of ...
OBJ importer/exporter.
Definition: object.hh:28
SCM polyhedron_centroid(SCM object)
Compute centroid of the polyhedron.
Main namespace.
Definition: convert.hh:9
SCM polyhedron_unique(SCM object)
Remove redundant vertices and faces.
SCM polyhedron_unique_self(SCM object)
Remove redundant vertices and faces.
Three-dimensional polyhedron.
Definition: polyhedron.hh:43
SCM polyhedron_scale_self(SCM object, SCM arg)
Scale the polyhedron by a specified factor in three dimensions.
SCM polyhedron_normalise(SCM object)
Compute vertex and face normals.
SCM polyhedron_bounds(SCM object, SCM dimension)
Compute the extent of the polyhedron in specified dimension.
SCM polyhedron_signed_volume_below(SCM object, SCM dimension, SCM level)
Compute signed volume of the polyhedron below certain level of dimension.
SCM polyhedron_mirror(SCM object, SCM arg)
Mirror the polhedron relative to the origin in a specified dimension.
SCM polyhedron_bounding_box(SCM object)
Compute bounding box of the polyhedron.