points.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_POINTS_HPP
  11. #define BOOST_COMPUTE_INTEROP_VTK_POINTS_HPP
  12. #include <vector>
  13. #include <vtkPoints.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/iterator/buffer_iterator.hpp>
  18. namespace boost {
  19. namespace compute {
  20. /// Copies \p points to \p buffer.
  21. ///
  22. /// For example, to copy from a \c vtkPoints object to a \c vector<float4_>:
  23. /// \code
  24. /// vtkPoints *points = ...
  25. /// vector<float4_> vector(points->GetNumberOfPoints(), context);
  26. /// vtk_copy_points_to_buffer(points, vector.begin(), queue);
  27. /// \endcode
  28. template<class PointType>
  29. inline void vtk_copy_points_to_buffer(const vtkPoints *points,
  30. buffer_iterator<PointType> buffer,
  31. command_queue &queue = system::default_queue())
  32. {
  33. vtkPoints *points_ = const_cast<vtkPoints *>(points);
  34. // copy points to aligned buffer
  35. std::vector<PointType> tmp(points_->GetNumberOfPoints());
  36. for(vtkIdType i = 0; i < points_->GetNumberOfPoints(); i++){
  37. double *p = points_->GetPoint(i);
  38. tmp[i] = PointType(p[0], p[1], p[2], 1);
  39. }
  40. // copy data to device
  41. copy(tmp.begin(), tmp.end(), buffer, queue);
  42. }
  43. } // end compute namespace
  44. } // end boost namespace
  45. #endif // BOOST_COMPUTE_INTEROP_VTK_POINTS_HPP