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> 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(); \ 19 return make_object<object_type>(::type, copy); \ 22 SCM polyhedron_##name##_self(SCM object) { \ 23 auto* wrapper = get_wrapper<object_type>(object); \ 24 wrapper->get()->name(); \ 25 return SCM_UNSPECIFIED; \ 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); \ 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; \ 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); \ 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; \ 60 template <> SCM traits_type::type() { return ::type; }
69 VTB_POLYHEDRON_WRAP_VOID_FUNC(reorder)
78 VTB_POLYHEDRON_WRAP_VOID_FUNC(normalise)
87 VTB_POLYHEDRON_WRAP_VOID_FUNC(unique)
96 VTB_POLYHEDRON_WRAP_VOID_FUNC_1_ARG(move, to_vector<VTB_REAL_TYPE,3>)
105 VTB_POLYHEDRON_WRAP_VOID_FUNC_1_ARG(scale, to_vector<VTB_REAL_TYPE,3>)
114 VTB_POLYHEDRON_WRAP_VOID_FUNC_1_ARG(flip, scm_to_int)
123 VTB_POLYHEDRON_WRAP_VOID_FUNC_1_ARG(mirror, scm_to_int)
133 VTB_POLYHEDRON_WRAP_VOID_FUNC_2_ARG(rotate, scm_to_int, scm_to_int)
143 auto* wrapper = get_wrapper<object_type>(
object);
144 return scm_from_bool(wrapper->get()->empty());
155 auto* wrapper = get_wrapper<object_type>(
object);
156 return scm_from_double(signed_volume(*wrapper->get()));
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));
181 auto* wrapper = get_wrapper<object_type>(
object);
182 return scm_from_double(volume(*wrapper->get()));
193 auto* wrapper = get_wrapper<object_type>(
object);
194 return to_scm(centroid(*wrapper->get()));
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()));
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()));
232 traits_type::define() {
233 ::type = define_type<object_type>(
"<polyhedron>");
234 define_procedure(
"make-polyhedron", 0, 0, 0, VTB_GUILE_0(
make_polyhedron));
236 define_procedure(
"polyhedron-reorder!", 1, 0, 0,
238 define_procedure(
"polyhedron-normalise", 1, 0, 0,
240 define_procedure(
"polyhedron-normalise!", 1, 0, 0,
243 define_procedure(
"polyhedron-unique!", 1, 0, 0,
245 define_procedure(
"polyhedron-empty?", 1, 0, 0, VTB_GUILE_1(
polyhedron_empty));
246 define_procedure(
"polyhedron-signed-volume", 1, 0, 0,
248 define_procedure(
"polyhedron-signed-volume-below", 3, 0, 0,
252 define_procedure(
"polyhedron-bounding-box", 1, 0, 0,
255 define_procedure(
"polyhedron-move", 2, 0, 0, VTB_GUILE_2(
polyhedron_move));
257 define_procedure(
"polyhedron-scale", 2, 0, 0, VTB_GUILE_2(
polyhedron_scale));
259 define_procedure(
"polyhedron-flip", 2, 0, 0, VTB_GUILE_2(
polyhedron_flip));
262 define_procedure(
"polyhedron-mirror!", 2, 0, 0,
265 define_procedure(
"polyhedron-rotate!", 3, 0, 0,
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 ...
SCM polyhedron_centroid(SCM object)
Compute centroid of the polyhedron.
SCM polyhedron_unique(SCM object)
Remove redundant vertices and faces.
SCM polyhedron_unique_self(SCM object)
Remove redundant vertices and faces.
Three-dimensional polyhedron.
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.