1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_INTEROP_VTK_BOUNDS_HPP
12 #define BOOST_COMPUTE_INTEROP_VTK_BOUNDS_HPP
17 #include <boost/compute/system.hpp>
18 #include <boost/compute/command_queue.hpp>
19 #include <boost/compute/algorithm/copy_n.hpp>
20 #include <boost/compute/algorithm/reduce.hpp>
21 #include <boost/compute/container/array.hpp>
26 /// Calculates the bounds for the points in the range [\p first, \p last) and
27 /// stores the result in \p bounds.
29 /// For example, this can be used to implement the GetBounds() method for a
30 /// vtkMapper subclass.
31 template<class PointIterator>
32 inline void vtk_compute_bounds(PointIterator first,
35 command_queue &queue = system::default_queue())
37 typedef typename std::iterator_traits<PointIterator>::value_type T;
39 const context &context = queue.get_context();
41 // compute min and max point
42 array<T, 2> extrema(context);
43 reduce(first, last, extrema.begin() + 0, min<T>(), queue);
44 reduce(first, last, extrema.begin() + 1, max<T>(), queue);
46 // copy results to host buffer
47 std::vector<T> buffer(2);
48 copy_n(extrema.begin(), 2, buffer.begin(), queue);
50 // copy to vtk-style bounds
51 bounds[0] = buffer[0][0]; bounds[1] = buffer[1][0];
52 bounds[2] = buffer[0][1]; bounds[3] = buffer[1][1];
53 bounds[4] = buffer[0][2]; bounds[5] = buffer[1][2];
56 } // end compute namespace
57 } // end boost namespace
59 #endif // BOOST_COMPUTE_INTEROP_VTK_BOUNDS_HPP