Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:01

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_INTEROP_VTK_BOUNDS_HPP
0012 #define BOOST_COMPUTE_INTEROP_VTK_BOUNDS_HPP
0013 
0014 #include <vector>
0015 #include <iterator>
0016 
0017 #include <boost/compute/system.hpp>
0018 #include <boost/compute/command_queue.hpp>
0019 #include <boost/compute/algorithm/copy_n.hpp>
0020 #include <boost/compute/algorithm/reduce.hpp>
0021 #include <boost/compute/container/array.hpp>
0022 
0023 namespace boost {
0024 namespace compute {
0025 
0026 /// Calculates the bounds for the points in the range [\p first, \p last) and
0027 /// stores the result in \p bounds.
0028 ///
0029 /// For example, this can be used to implement the GetBounds() method for a
0030 /// vtkMapper subclass.
0031 template<class PointIterator>
0032 inline void vtk_compute_bounds(PointIterator first,
0033                                PointIterator last,
0034                                double bounds[6],
0035                                command_queue &queue = system::default_queue())
0036 {
0037     typedef typename std::iterator_traits<PointIterator>::value_type T;
0038 
0039     const context &context = queue.get_context();
0040 
0041     // compute min and max point
0042     array<T, 2> extrema(context);
0043     reduce(first, last, extrema.begin() + 0, min<T>(), queue);
0044     reduce(first, last, extrema.begin() + 1, max<T>(), queue);
0045 
0046     // copy results to host buffer
0047     std::vector<T> buffer(2);
0048     copy_n(extrema.begin(), 2, buffer.begin(), queue);
0049 
0050     // copy to vtk-style bounds
0051     bounds[0] = buffer[0][0]; bounds[1] = buffer[1][0];
0052     bounds[2] = buffer[0][1]; bounds[3] = buffer[1][1];
0053     bounds[4] = buffer[0][2]; bounds[5] = buffer[1][2];
0054 }
0055 
0056 } // end compute namespace
0057 } // end boost namespace
0058 
0059 #endif // BOOST_COMPUTE_INTEROP_VTK_BOUNDS_HPP