]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/test/extra/test_interop_vtk.cpp
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 #define BOOST_TEST_MODULE TestInteropVTK
12 #include <boost/test/unit_test.hpp>
14 #include <vtkFloatArray.h>
15 #include <vtkMatrix4x4.h>
17 #include <vtkPoints.h>
18 #include <vtkSmartPointer.h>
19 #include <vtkUnsignedCharArray.h>
21 #include <boost/compute/system.hpp>
22 #include <boost/compute/algorithm/sort.hpp>
23 #include <boost/compute/container/vector.hpp>
24 #include <boost/compute/detail/is_contiguous_iterator.hpp>
25 #include <boost/compute/interop/vtk.hpp>
27 #include "check_macros.hpp"
28 #include "context_setup.hpp"
30 namespace compute
= boost::compute
;
32 BOOST_AUTO_TEST_CASE(bounds
)
34 using compute::float4_
;
37 vtkNew
<vtkPoints
> points
;
38 points
->InsertNextPoint(0.0, 0.0, 0.0);
39 points
->InsertNextPoint(1.0, 2.0, 1.0);
40 points
->InsertNextPoint(-1.0, -3.0, -1.0);
41 points
->InsertNextPoint(0.5, 2.5, 1.5);
43 // copy points to vector on gpu
44 compute::vector
<float4_
> vector(points
->GetNumberOfPoints(), context
);
45 compute::vtk_copy_points_to_buffer(points
.GetPointer(), vector
.begin(), queue
);
49 compute::vtk_compute_bounds(vector
.begin(), vector
.end(), bounds
, queue
);
52 BOOST_CHECK_CLOSE(bounds
[0], -1.0, 1e-8);
53 BOOST_CHECK_CLOSE(bounds
[1], 1.0, 1e-8);
54 BOOST_CHECK_CLOSE(bounds
[2], -3.0, 1e-8);
55 BOOST_CHECK_CLOSE(bounds
[3], 2.5, 1e-8);
56 BOOST_CHECK_CLOSE(bounds
[4], -1.0, 1e-8);
57 BOOST_CHECK_CLOSE(bounds
[5], 1.5, 1e-8);
60 BOOST_AUTO_TEST_CASE(copy_uchar_array
)
62 // create vtk uchar vector containing 3 RGBA colors
63 vtkNew
<vtkUnsignedCharArray
> array
;
64 array
->SetNumberOfComponents(4);
66 unsigned char red
[4] = { 255, 0, 0, 255 };
67 array
->InsertNextTupleValue(red
);
68 unsigned char green
[4] = { 0, 255, 0, 255 };
69 array
->InsertNextTupleValue(green
);
70 unsigned char blue
[4] = { 0, 0, 255, 255 };
71 array
->InsertNextTupleValue(blue
);
73 // create vector<uchar4> on device and copy values from vtk array
74 compute::vector
<compute::uchar4_
> vector(3, context
);
75 compute::vtk_copy_data_array_to_buffer(
77 compute::make_buffer_iterator
<compute::uchar_
>(vector
.get_buffer(), 0),
82 std::vector
<compute::uchar4_
> host_vector(3);
84 vector
.begin(), vector
.end(), host_vector
.begin(), queue
86 BOOST_CHECK(host_vector
[0] == compute::uchar4_(255, 0, 0, 255));
87 BOOST_CHECK(host_vector
[1] == compute::uchar4_(0, 255, 0, 255));
88 BOOST_CHECK(host_vector
[2] == compute::uchar4_(0, 0, 255, 255));
91 BOOST_AUTO_TEST_CASE(sort_float_array
)
93 // create vtk float array
94 vtkNew
<vtkFloatArray
> array
;
95 array
->InsertNextValue(2.5f
);
96 array
->InsertNextValue(1.0f
);
97 array
->InsertNextValue(6.5f
);
98 array
->InsertNextValue(4.0f
);
100 // create vector on device and copy values from vtk array
101 compute::vector
<float> vector(4, context
);
102 compute::vtk_copy_data_array_to_buffer(array
.GetPointer(), vector
.begin(), queue
);
104 // sort values on the gpu
105 compute::sort(vector
.begin(), vector
.end(), queue
);
106 CHECK_RANGE_EQUAL(float, 4, vector
, (1.0f
, 2.5f
, 4.0f
, 6.5f
));
108 // copy sorted values back to the vtk array
109 compute::vtk_copy_buffer_to_data_array(
110 vector
.begin(), vector
.end(), array
.GetPointer(), queue
112 BOOST_CHECK_EQUAL(array
->GetValue(0), 1.0f
);
113 BOOST_CHECK_EQUAL(array
->GetValue(1), 2.5f
);
114 BOOST_CHECK_EQUAL(array
->GetValue(2), 4.0f
);
115 BOOST_CHECK_EQUAL(array
->GetValue(3), 6.5f
);
118 BOOST_AUTO_TEST_SUITE_END()