From 3cb882ce91b9247319fc3937f70d60e687722b7d Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Tue, 24 Sep 2013 10:05:47 +0900 Subject: [PATCH] fix darkroom: add make_object_list --- example/darkroom/two_spheres.hpp | 2 +- sprout/darkroom/access.hpp | 1 + sprout/darkroom/access/access.hpp | 1 + sprout/darkroom/access/traits.hpp | 45 +++++++++++++++++++++ sprout/darkroom/lights/light_list.hpp | 1 + sprout/darkroom/lights/parallel_light.hpp | 2 +- sprout/darkroom/lights/point_light.hpp | 2 +- sprout/darkroom/objects.hpp | 1 + sprout/darkroom/objects/intersect.hpp | 42 +++++++++++++++---- sprout/darkroom/objects/object_list.hpp | 32 +++++++++++++++ sprout/darkroom/renderers/whitted_style.hpp | 2 +- testspr/test.sh | 2 +- tools/darkroom/darkcult.sh | 9 ++++- 13 files changed, 128 insertions(+), 14 deletions(-) create mode 100644 sprout/darkroom/access/traits.hpp create mode 100644 sprout/darkroom/objects/object_list.hpp diff --git a/example/darkroom/two_spheres.hpp b/example/darkroom/two_spheres.hpp index 7a370ff2..cd2fa5e5 100644 --- a/example/darkroom/two_spheres.hpp +++ b/example/darkroom/two_spheres.hpp @@ -16,7 +16,7 @@ namespace darkcult { // // object // - SPROUT_STATIC_CONSTEXPR auto object = sprout::make_tuple( + SPROUT_STATIC_CONSTEXPR auto object = objects::make_object_list( objects::make_aa_plane( objects::aa_plane_direction::y, -2.0, diff --git a/sprout/darkroom/access.hpp b/sprout/darkroom/access.hpp index 0fe79f61..1eeb2d40 100644 --- a/sprout/darkroom/access.hpp +++ b/sprout/darkroom/access.hpp @@ -9,6 +9,7 @@ #define SPROUT_DARKROOM_ACCESS_HPP #include +#include #include #endif // #ifndef SPROUT_DARKROOM_ACCESS_HPP diff --git a/sprout/darkroom/access/access.hpp b/sprout/darkroom/access/access.hpp index c9ca64db..0ff50a14 100644 --- a/sprout/darkroom/access/access.hpp +++ b/sprout/darkroom/access/access.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace sprout { diff --git a/sprout/darkroom/access/traits.hpp b/sprout/darkroom/access/traits.hpp new file mode 100644 index 00000000..02f13fd6 --- /dev/null +++ b/sprout/darkroom/access/traits.hpp @@ -0,0 +1,45 @@ +/*============================================================================= + Copyright (c) 2011-2013 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_DARKROOM_ACCESS_TRAITS_HPP +#define SPROUT_DARKROOM_ACCESS_TRAITS_HPP + +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace access { + // + // is_tuple + // + template + struct is_tuple + : public std::false_type + {}; + template + struct is_tuple + : public sprout::darkroom::access::is_tuple + {}; + template + struct is_tuple + : public sprout::darkroom::access::is_tuple + {}; + template + struct is_tuple + : public sprout::darkroom::access::is_tuple + {}; + template + struct is_tuple > + : public std::true_type + {}; + } // namespace access + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_ACCESS_TRAITS_HPP diff --git a/sprout/darkroom/lights/light_list.hpp b/sprout/darkroom/lights/light_list.hpp index f3709184..2ae7bf78 100644 --- a/sprout/darkroom/lights/light_list.hpp +++ b/sprout/darkroom/lights/light_list.hpp @@ -61,6 +61,7 @@ namespace sprout { return shade_1(inter, objs, sprout::index_pack::make()); } }; + // // make_light_list // diff --git a/sprout/darkroom/lights/parallel_light.hpp b/sprout/darkroom/lights/parallel_light.hpp index e75d81ea..cab2069a 100644 --- a/sprout/darkroom/lights/parallel_light.hpp +++ b/sprout/darkroom/lights/parallel_light.hpp @@ -77,7 +77,7 @@ namespace sprout { operator()(Intersection const& inter, Objects const& objs) const { return shade_1( inter, - sprout::darkroom::objects::intersect_list( + sprout::darkroom::objects::intersect( objs, sprout::darkroom::rays::make_ray( sprout::darkroom::coords::add( diff --git a/sprout/darkroom/lights/point_light.hpp b/sprout/darkroom/lights/point_light.hpp index 3d77cf48..e5c20474 100644 --- a/sprout/darkroom/lights/point_light.hpp +++ b/sprout/darkroom/lights/point_light.hpp @@ -81,7 +81,7 @@ namespace sprout { inter, diff, direction, - sprout::darkroom::objects::intersect_list( + sprout::darkroom::objects::intersect( objs, sprout::darkroom::rays::make_ray( sprout::darkroom::coords::add( diff --git a/sprout/darkroom/objects.hpp b/sprout/darkroom/objects.hpp index 687f9a76..d9e2233c 100644 --- a/sprout/darkroom/objects.hpp +++ b/sprout/darkroom/objects.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include diff --git a/sprout/darkroom/objects/intersect.hpp b/sprout/darkroom/objects/intersect.hpp index 44bdddf4..7caf7688 100644 --- a/sprout/darkroom/objects/intersect.hpp +++ b/sprout/darkroom/objects/intersect.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -19,15 +20,19 @@ namespace sprout { // // intersect // - template + template< + typename Object, typename Ray, + typename sprout::enabler_if::value>::type = sprout::enabler + > inline SPROUT_CONSTEXPR typename Object::template intersection::type - intersect(Object const& obj, Ray const& ray) { - return obj.intersect(ray); - } + intersect(Object const& obj, Ray const& ray); + template< + typename Object, typename Ray, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename Object::template intersection::type + intersect(Object const& obj, Ray const& ray); - // - // intersect_list - // namespace detail { template struct intersect_list_impl { @@ -65,6 +70,9 @@ namespace sprout { } }; } // namespace detail + // + // intersect_list + // template inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type::template intersection::type intersect_list(Objects const& objs, Ray const& ray) { @@ -72,6 +80,26 @@ namespace sprout { sprout::darkroom::access::size::value - 1 >()(objs, ray); } + + // + // intersect + // + template< + typename Object, typename Ray, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename Object::template intersection::type + intersect(Object const& obj, Ray const& ray) { + return obj.intersect(ray); + } + template< + typename Object, typename Ray, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit::type::template intersection::type + intersect(Object const& obj, Ray const& ray) { + return sprout::darkroom::objects::intersect_list(obj, ray); + } } // namespace objects } // namespace darkroom } // namespace sprout diff --git a/sprout/darkroom/objects/object_list.hpp b/sprout/darkroom/objects/object_list.hpp new file mode 100644 index 00000000..f1bfbaf1 --- /dev/null +++ b/sprout/darkroom/objects/object_list.hpp @@ -0,0 +1,32 @@ +/*============================================================================= + Copyright (c) 2011-2013 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_DARKROOM_OBJECTS_OBJECT_LIST_HPP +#define SPROUT_DARKROOM_OBJECTS_OBJECT_LIST_HPP + +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace objects { + // + // make_object_list + // + template + inline SPROUT_CONSTEXPR auto + make_object_list(Objects&&... objs) + -> decltype(sprout::make_tuple(sprout::forward(objs)...)) + { + return sprout::make_tuple(sprout::forward(objs)...); + } + } // namespace objects + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_OBJECTS_OBJECT_LIST_HPP diff --git a/sprout/darkroom/renderers/whitted_style.hpp b/sprout/darkroom/renderers/whitted_style.hpp index e3baed97..ae90675b 100644 --- a/sprout/darkroom/renderers/whitted_style.hpp +++ b/sprout/darkroom/renderers/whitted_style.hpp @@ -186,7 +186,7 @@ namespace sprout { return color_1( camera, objs, lights, ray, depth_max, - sprout::darkroom::objects::intersect_list(objs, ray) + sprout::darkroom::objects::intersect(objs, ray) ); } }; diff --git a/testspr/test.sh b/testspr/test.sh index 75ad798b..8604f458 100755 --- a/testspr/test.sh +++ b/testspr/test.sh @@ -41,7 +41,7 @@ execute() { args=`getopt -o S:D:I:f -l stagedir:,gcc-version:,clang-version:,define:,include:,force,help -- "$@"` if [ "$?" -ne 0 ]; then - echo >&2 "error: options parse error. see 'test.sh --help'" + echo >&2 "error: options parse error. See 'test.sh --help'" exit 1 fi eval set -- ${args} diff --git a/tools/darkroom/darkcult.sh b/tools/darkroom/darkcult.sh index d4f68118..d604382c 100755 --- a/tools/darkroom/darkcult.sh +++ b/tools/darkroom/darkcult.sh @@ -26,7 +26,7 @@ use_help=0 args=`getopt -o s:S:o:C:w:h:W:H:D:I:f -l source:,stagedir:,output:,compiler:,width:,height:,tile-width:,tile-height:,define:,include:,force,help -- "$@"` if [ "$?" -ne 0 ]; then - echo >&2 "error: options parse error. see 'darkcult.sh --help'" + echo >&2 "error: options parse error. See 'darkcult.sh --help'" exit 1 fi eval set -- ${args} @@ -148,7 +148,12 @@ for ((y=0; y ${stagedir}/${y}/${x}.ppm + $(cd $(dirname $0); pwd)/darkcult.cpp + if [ $? -ne 0 ]; then + echo >&2 "error: compile failed." + exit 1 + fi + ${binname} > ${stagedir}/${y}/${x}.ppm done echo ""