I have an array of glm::vec3
with count * 3
elements. I have another array which contains int
indices of the elements to copy. An example:
thrust::device_vector<glm::vec3> vals(9);
// vals contains 9 vec3, which represent 3 "items"
// vals[0], vals[1], vals[2] are the first "item",
// vals[3], vals[4], vals[5] are the second "item"...
int idcs[] = {0, 2};
// index 0 and 2 should be copied, i.e.
// vals[0..2] and vals[6..8]
I tried to use permutation iterators, but I cannot get it to work. My approach is:
thrust::copy(
thrust::make_permutation_iterator(vals, idcs),
thrust::make_permutation_iterator(vals, idcs + 2),
target.begin()
);
But of course this will only copy vals[0]
and vals[2]
instead of vals[0] vals[1] vals[2]
and vals[6] vals[7] vals[8]
.
Is it possible to copy the desired values from one buffer to another with Thrust?
We can combine the idea of strided ranges with your permutation iterator approach to achieve what you want, I think.
The basic idea is to use your permutation iterator method to select the "groups" of items to copy, and we will select the 3 items in each group using a set of 3 strided range iterators combined into a zip iterator. We need a zip iterator for the input, and a zip iterator for the output. Here is a fully worked example, using
uint3
as a proxy forglm::vec3
: