data_array.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  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
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_INTEROP_VTK_DATA_ARRAY_HPP
  11. #define BOOST_COMPUTE_INTEROP_VTK_DATA_ARRAY_HPP
  12. #include <vtkDataArray.h>
  13. #include <vtkDataArrayTemplate.h>
  14. #include <boost/compute/system.hpp>
  15. #include <boost/compute/command_queue.hpp>
  16. #include <boost/compute/algorithm/copy.hpp>
  17. #include <boost/compute/algorithm/copy_n.hpp>
  18. #include <boost/compute/iterator/buffer_iterator.hpp>
  19. namespace boost {
  20. namespace compute {
  21. /// Copies the values in \p data to \p buffer.
  22. template<class T>
  23. inline void vtk_copy_data_array_to_buffer(const vtkDataArray *data,
  24. buffer_iterator<T> buffer,
  25. command_queue &queue = system::default_queue());
  26. /// \internal_
  27. template<class T>
  28. inline void vtk_copy_data_array_to_buffer(const vtkDataArrayTemplate<T> *data,
  29. buffer_iterator<T> buffer,
  30. command_queue &queue = system::default_queue())
  31. {
  32. vtkDataArrayTemplate<T> *data_ = const_cast<vtkDataArrayTemplate<T> *>(data);
  33. const T *data_ptr = static_cast<const T *>(data_->GetVoidPointer(0));
  34. size_t data_size = data_->GetNumberOfComponents() * data_->GetNumberOfTuples();
  35. ::boost::compute::copy_n(data_ptr, data_size, buffer, queue);
  36. }
  37. /// Copies the values in the range [\p first, \p last) to \p data.
  38. template<class T>
  39. inline void vtk_copy_buffer_to_data_array(buffer_iterator<T> first,
  40. buffer_iterator<T> last,
  41. vtkDataArray *data,
  42. command_queue &queue = system::default_queue());
  43. /// \internal_
  44. template<class T>
  45. inline void vtk_copy_buffer_to_data_array(buffer_iterator<T> first,
  46. buffer_iterator<T> last,
  47. vtkDataArrayTemplate<T> *data,
  48. command_queue &queue = system::default_queue())
  49. {
  50. T *data_ptr = static_cast<T *>(data->GetVoidPointer(0));
  51. ::boost::compute::copy(first, last, data_ptr, queue);
  52. }
  53. } // end compute namespace
  54. } // end boost namespace
  55. #endif // BOOST_COMPUTE_INTEROP_VTK_DATA_ARRAY_HPP