Browse Source

MeshTools: add std::vector overload to combineIndexArrays().

So the functions can *really* be used at runtime.
pull/51/head
Vladimír Vondruš 12 years ago
parent
commit
dee57c4479
  1. 16
      src/Magnum/MeshTools/CombineIndexedArrays.cpp
  2. 13
      src/Magnum/MeshTools/CombineIndexedArrays.h

16
src/Magnum/MeshTools/CombineIndexedArrays.cpp

@ -56,26 +56,24 @@ std::pair<std::vector<UnsignedInt>, std::vector<UnsignedInt>> interleaveAndCombi
/* Combine them */
std::vector<UnsignedInt> combinedIndices;
std::tie(combinedIndices, interleavedArrays) = combineIndexArrays(interleavedArrays, stride);
std::tie(combinedIndices, interleavedArrays) = MeshTools::combineIndexArrays(interleavedArrays, stride);
return {combinedIndices, interleavedArrays};
}
}
std::vector<UnsignedInt> combineIndexArrays(const std::initializer_list<std::reference_wrapper<std::vector<UnsignedInt>>> arrays) {
std::vector<UnsignedInt> combineIndexArrays(const std::reference_wrapper<std::vector<UnsignedInt>>* const begin, const std::reference_wrapper<std::vector<UnsignedInt>>* const end) {
/* Interleave and combine the arrays */
std::vector<UnsignedInt> combinedIndices;
std::vector<UnsignedInt> interleavedCombinedArrays;
std::tie(combinedIndices, interleavedCombinedArrays) = Implementation::interleaveAndCombineIndexArrays(
/* This will bite me hard once. */
reinterpret_cast<const std::reference_wrapper<const std::vector<UnsignedInt>>*>(arrays.begin()),
reinterpret_cast<const std::reference_wrapper<const std::vector<UnsignedInt>>*>(arrays.end()));
reinterpret_cast<const std::reference_wrapper<const std::vector<UnsignedInt>>*>(begin),
reinterpret_cast<const std::reference_wrapper<const std::vector<UnsignedInt>>*>(end));
/* Update the original indices */
const UnsignedInt stride = arrays.size();
const UnsignedInt stride = end - begin;
const UnsignedInt outputSize = interleavedCombinedArrays.size()/stride;
for(UnsignedInt offset = 0; offset != stride; ++offset) {
auto& array = (arrays.begin()+offset)->get();
auto& array = (begin+offset)->get();
CORRADE_INTERNAL_ASSERT(array.size() >= outputSize);
array.resize(outputSize);
for(UnsignedInt i = 0; i != outputSize; ++i)
@ -85,6 +83,8 @@ std::vector<UnsignedInt> combineIndexArrays(const std::initializer_list<std::ref
return combinedIndices;
}
}
namespace {
class IndexHash {

13
src/Magnum/MeshTools/CombineIndexedArrays.h

@ -42,6 +42,10 @@
namespace Magnum { namespace MeshTools {
namespace Implementation {
MAGNUM_MESHTOOLS_EXPORT std::vector<UnsignedInt> combineIndexArrays(const std::reference_wrapper<std::vector<UnsignedInt>>* begin, const std::reference_wrapper<std::vector<UnsignedInt>>* end);
}
/**
@brief Combine index arrays
@ -81,7 +85,14 @@ This function calls @ref combineIndexArrays(const std::vector<UnsignedInt>&, Uns
internally. See also @ref combineIndexedArrays() which does the vertex data
reordering automatically.
*/
MAGNUM_MESHTOOLS_EXPORT std::vector<UnsignedInt> combineIndexArrays(std::initializer_list<std::reference_wrapper<std::vector<UnsignedInt>>> arrays);
inline std::vector<UnsignedInt> combineIndexArrays(const std::vector<std::reference_wrapper<std::vector<UnsignedInt>>>& arrays) {
return Implementation::combineIndexArrays(&arrays[0], &arrays[0] + arrays.size());
}
/** @overload */
inline std::vector<UnsignedInt> combineIndexArrays(std::initializer_list<std::reference_wrapper<std::vector<UnsignedInt>>> arrays) {
return Implementation::combineIndexArrays(arrays.begin(), arrays.end());
}
/**
@brief Combine index arrays

Loading…
Cancel
Save