Browse Source

MeshTools: using new type aliases in whole MeshTools namespace.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
32b783505f
  1. 10
      src/MeshTools/Clean.h
  2. 24
      src/MeshTools/CombineIndexedArrays.h
  3. 20
      src/MeshTools/CompressIndices.cpp
  4. 8
      src/MeshTools/CompressIndices.h
  5. 2
      src/MeshTools/FlipNormals.cpp
  6. 8
      src/MeshTools/FlipNormals.h
  7. 6
      src/MeshTools/GenerateFlatNormals.cpp
  8. 6
      src/MeshTools/GenerateFlatNormals.h
  9. 12
      src/MeshTools/Subdivide.h
  10. 6
      src/MeshTools/Test/CleanTest.cpp
  11. 34
      src/MeshTools/Test/CombineIndexedArraysTest.cpp
  12. 6
      src/MeshTools/Test/CompressIndicesTest.cpp
  13. 6
      src/MeshTools/Test/FlipNormalsTest.cpp
  14. 6
      src/MeshTools/Test/GenerateFlatNormalsTest.cpp
  15. 32
      src/MeshTools/Test/InterleaveTest.cpp
  16. 8
      src/MeshTools/Test/SubdivideTest.cpp
  17. 12
      src/MeshTools/Test/TipsifyTest.cpp
  18. 30
      src/MeshTools/Tipsify.cpp
  19. 12
      src/MeshTools/Tipsify.h

10
src/MeshTools/Clean.h

@ -32,7 +32,7 @@ namespace Implementation {
template<class Vertex, std::size_t vertexSize = Vertex::Size> class Clean { template<class Vertex, std::size_t vertexSize = Vertex::Size> class Clean {
public: public:
inline Clean(std::vector<std::uint32_t>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {} inline Clean(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {}
void operator()(typename Vertex::Type epsilon = Math::MathTypeTraits<typename Vertex::Type>::epsilon()) { void operator()(typename Vertex::Type epsilon = Math::MathTypeTraits<typename Vertex::Type>::epsilon()) {
if(indices.empty()) return; if(indices.empty()) return;
@ -107,12 +107,12 @@ template<class Vertex, std::size_t vertexSize = Vertex::Size> class Clean {
}; };
struct HashedVertex { struct HashedVertex {
std::uint32_t oldIndex, newIndex; UnsignedInt oldIndex, newIndex;
HashedVertex(std::uint32_t oldIndex, std::uint32_t newIndex): oldIndex(oldIndex), newIndex(newIndex) {} HashedVertex(UnsignedInt oldIndex, UnsignedInt newIndex): oldIndex(oldIndex), newIndex(newIndex) {}
}; };
std::vector<std::uint32_t>& indices; std::vector<UnsignedInt>& indices;
std::vector<Vertex>& vertices; std::vector<Vertex>& vertices;
}; };
@ -136,7 +136,7 @@ Removes duplicate vertices from the mesh.
@todo Interpolate vertices, not collapse them to first in the cell @todo Interpolate vertices, not collapse them to first in the cell
@todo Ability to specify other attributes for interpolation @todo Ability to specify other attributes for interpolation
*/ */
template<class Vertex, std::size_t vertexSize = Vertex::Size> inline void clean(std::vector<std::uint32_t>& indices, std::vector<Vertex>& vertices, typename Vertex::Type epsilon = Math::MathTypeTraits<typename Vertex::Type>::epsilon()) { template<class Vertex, std::size_t vertexSize = Vertex::Size> inline void clean(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices, typename Vertex::Type epsilon = Math::MathTypeTraits<typename Vertex::Type>::epsilon()) {
Implementation::Clean<Vertex, vertexSize>(indices, vertices)(epsilon); Implementation::Clean<Vertex, vertexSize>(indices, vertices)(epsilon);
} }

24
src/MeshTools/CombineIndexedArrays.h

@ -33,17 +33,17 @@ namespace Implementation {
class CombineIndexedArrays { class CombineIndexedArrays {
public: public:
template<class ...T> std::vector<std::uint32_t> operator()(const std::tuple<const std::vector<std::uint32_t>&, std::vector<T>&>&... indexedArrays) { template<class ...T> std::vector<UnsignedInt> operator()(const std::tuple<const std::vector<UnsignedInt>&, std::vector<T>&>&... indexedArrays) {
/* Compute index count */ /* Compute index count */
std::size_t _indexCount = indexCount(std::get<0>(indexedArrays)...); std::size_t _indexCount = indexCount(std::get<0>(indexedArrays)...);
/* Resulting index array */ /* Resulting index array */
std::vector<std::uint32_t> result; std::vector<UnsignedInt> result;
result.resize(_indexCount); result.resize(_indexCount);
std::iota(result.begin(), result.end(), 0); std::iota(result.begin(), result.end(), 0);
/* All index combinations */ /* All index combinations */
std::vector<Math::Vector<sizeof...(indexedArrays), std::uint32_t> > indexCombinations(_indexCount); std::vector<Math::Vector<sizeof...(indexedArrays), UnsignedInt> > indexCombinations(_indexCount);
writeCombinedIndices(indexCombinations, std::get<0>(indexedArrays)...); writeCombinedIndices(indexCombinations, std::get<0>(indexedArrays)...);
/* Make the combinations unique */ /* Make the combinations unique */
@ -56,13 +56,13 @@ class CombineIndexedArrays {
} }
private: private:
template<class ...T> inline static std::size_t indexCount(const std::vector<std::uint32_t>& first, const std::vector<T>&... next) { template<class ...T> inline static std::size_t indexCount(const std::vector<UnsignedInt>& first, const std::vector<T>&... next) {
CORRADE_ASSERT(sizeof...(next) == 0 || indexCount(next...) == first.size(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.", 0); CORRADE_ASSERT(sizeof...(next) == 0 || indexCount(next...) == first.size(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.", 0);
return first.size(); return first.size();
} }
template<std::size_t size, class ...T> static void writeCombinedIndices(std::vector<Math::Vector<size, std::uint32_t>>& output, const std::vector<std::uint32_t>& first, const std::vector<T>&... next) { template<std::size_t size, class ...T> static void writeCombinedIndices(std::vector<Math::Vector<size, UnsignedInt>>& output, const std::vector<UnsignedInt>& first, const std::vector<T>&... next) {
/* Copy the data to output */ /* Copy the data to output */
for(std::size_t i = 0; i != output.size(); ++i) for(std::size_t i = 0; i != output.size(); ++i)
output[i][size-sizeof...(next)-1] = first[i]; output[i][size-sizeof...(next)-1] = first[i];
@ -70,7 +70,7 @@ class CombineIndexedArrays {
writeCombinedIndices(output, next...); writeCombinedIndices(output, next...);
} }
template<std::size_t size, class T, class ...U> static void writeCombinedArrays(const std::vector<Math::Vector<size, std::uint32_t>>& combinedIndices, std::vector<T>& first, std::vector<U>&... next) { template<std::size_t size, class T, class ...U> static void writeCombinedArrays(const std::vector<Math::Vector<size, UnsignedInt>>& combinedIndices, std::vector<T>& first, std::vector<U>&... next) {
/* Rewrite output array */ /* Rewrite output array */
std::vector<T> output; std::vector<T> output;
for(std::size_t i = 0; i != combinedIndices.size(); ++i) for(std::size_t i = 0; i != combinedIndices.size(); ++i)
@ -82,8 +82,8 @@ class CombineIndexedArrays {
/* Terminator functions for recursive calls */ /* Terminator functions for recursive calls */
inline static std::size_t indexCount() { return 0; } inline static std::size_t indexCount() { return 0; }
template<std::size_t size> inline static void writeCombinedIndices(std::vector<Math::Vector<size, std::uint32_t>>&) {} template<std::size_t size> inline static void writeCombinedIndices(std::vector<Math::Vector<size, UnsignedInt>>&) {}
template<std::size_t size> inline static void writeCombinedArrays(const std::vector<Math::Vector<size, std::uint32_t>>&) {} template<std::size_t size> inline static void writeCombinedArrays(const std::vector<Math::Vector<size, UnsignedInt>>&) {}
}; };
} }
@ -105,13 +105,13 @@ avoid explicit verbose specification of tuple type, you can write it with help
of some STL functions like shown below. Also if one index array is shader by of some STL functions like shown below. Also if one index array is shader by
more than one attribute array, just pass the index array more times. Example: more than one attribute array, just pass the index array more times. Example:
@code @code
std::vector<std::uint32_t> vertexIndices; std::vector<UnsignedInt> vertexIndices;
std::vector<Vector3> positions; std::vector<Vector3> positions;
std::vector<std::uint32_t> normalTextureIndices; std::vector<UnsignedInt> normalTextureIndices;
std::vector<Vector3> normals; std::vector<Vector3> normals;
std::vector<Vector2> textureCoordinates; std::vector<Vector2> textureCoordinates;
std::vector<std::uint32_t> indices = MeshTools::combineIndexedArrays( std::vector<UnsignedInt> indices = MeshTools::combineIndexedArrays(
std::make_tuple(std::cref(vertexIndices), std::ref(positions)), std::make_tuple(std::cref(vertexIndices), std::ref(positions)),
std::make_tuple(std::cref(normalTextureIndices), std::ref(normals)), std::make_tuple(std::cref(normalTextureIndices), std::ref(normals)),
std::make_tuple(std::cref(normalTextureIndices), std::ref(textureCoordinates)) std::make_tuple(std::cref(normalTextureIndices), std::ref(textureCoordinates))
@ -125,7 +125,7 @@ attributes indexed with `indices`.
/* Implementation note: It's done using tuples because it is more clear which /* Implementation note: It's done using tuples because it is more clear which
parameter is index array and which is attribute array, mainly when both are parameter is index array and which is attribute array, mainly when both are
of the same type. */ of the same type. */
template<class ...T> std::vector<std::uint32_t> combineIndexedArrays(const std::tuple<const std::vector<std::uint32_t>&, std::vector<T>&>&... indexedArrays) { template<class ...T> std::vector<UnsignedInt> combineIndexedArrays(const std::tuple<const std::vector<UnsignedInt>&, std::vector<T>&>&... indexedArrays) {
return Implementation::CombineIndexedArrays()(indexedArrays...); return Implementation::CombineIndexedArrays()(indexedArrays...);
} }

20
src/MeshTools/CompressIndices.cpp

@ -26,11 +26,11 @@ namespace Magnum { namespace MeshTools {
namespace { namespace {
template<class> constexpr Mesh::IndexType indexType(); template<class> constexpr Mesh::IndexType indexType();
template<> inline constexpr Mesh::IndexType indexType<GLubyte>() { return Mesh::IndexType::UnsignedByte; } template<> inline constexpr Mesh::IndexType indexType<UnsignedByte>() { return Mesh::IndexType::UnsignedByte; }
template<> inline constexpr Mesh::IndexType indexType<GLushort>() { return Mesh::IndexType::UnsignedShort; } template<> inline constexpr Mesh::IndexType indexType<UnsignedShort>() { return Mesh::IndexType::UnsignedShort; }
template<> inline constexpr Mesh::IndexType indexType<GLuint>() { return Mesh::IndexType::UnsignedInt; } template<> inline constexpr Mesh::IndexType indexType<UnsignedInt>() { return Mesh::IndexType::UnsignedInt; }
template<class T> inline std::tuple<std::size_t, Mesh::IndexType, char*> compress(const std::vector<std::uint32_t>& indices) { template<class T> inline std::tuple<std::size_t, Mesh::IndexType, char*> compress(const std::vector<UnsignedInt>& indices) {
char* buffer = new char[indices.size()*sizeof(T)]; char* buffer = new char[indices.size()*sizeof(T)];
for(std::size_t i = 0; i != indices.size(); ++i) { for(std::size_t i = 0; i != indices.size(); ++i) {
T index = static_cast<T>(indices[i]); T index = static_cast<T>(indices[i]);
@ -40,15 +40,15 @@ template<class T> inline std::tuple<std::size_t, Mesh::IndexType, char*> compres
return std::make_tuple(indices.size(), indexType<T>(), buffer); return std::make_tuple(indices.size(), indexType<T>(), buffer);
} }
std::tuple<std::size_t, Mesh::IndexType, char*> compressIndicesInternal(const std::vector<std::uint32_t>& indices, std::uint32_t max) { std::tuple<std::size_t, Mesh::IndexType, char*> compressIndicesInternal(const std::vector<UnsignedInt>& indices, UnsignedInt max) {
switch(Math::log(256, max)) { switch(Math::log(256, max)) {
case 0: case 0:
return compress<GLubyte>(indices); return compress<UnsignedByte>(indices);
case 1: case 1:
return compress<GLushort>(indices); return compress<UnsignedShort>(indices);
case 2: case 2:
case 3: case 3:
return compress<GLuint>(indices); return compress<UnsignedInt>(indices);
default: default:
CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << max << "elements.", {}); CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << max << "elements.", {});
@ -58,11 +58,11 @@ std::tuple<std::size_t, Mesh::IndexType, char*> compressIndicesInternal(const st
} }
#endif #endif
std::tuple<std::size_t, Mesh::IndexType, char*> compressIndices(const std::vector<std::uint32_t>& indices) { std::tuple<std::size_t, Mesh::IndexType, char*> compressIndices(const std::vector<UnsignedInt>& indices) {
return compressIndicesInternal(indices, *std::max_element(indices.begin(), indices.end())); return compressIndicesInternal(indices, *std::max_element(indices.begin(), indices.end()));
} }
void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<std::uint32_t>& indices) { void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<UnsignedInt>& indices) {
auto minmax = std::minmax_element(indices.begin(), indices.end()); auto minmax = std::minmax_element(indices.begin(), indices.end());
/** @todo Performance hint when range can be represented by smaller value? */ /** @todo Performance hint when range can be represented by smaller value? */

8
src/MeshTools/CompressIndices.h

@ -49,10 +49,10 @@ std::size_t dataSize = indexCount*Mesh::indexSize(indexType);
delete[] data; delete[] data;
@endcode @endcode
See also compressIndices(Mesh*, Buffer*, Buffer::Usage, const std::vector<std::uint32_t>&), See also compressIndices(Mesh*, Buffer*, Buffer::Usage, const std::vector<UnsignedInt>&),
which writes the compressed data directly into index buffer of given mesh. which writes the compressed data directly into index buffer of given mesh.
*/ */
std::tuple<std::size_t, Mesh::IndexType, char*> MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector<std::uint32_t>& indices); std::tuple<std::size_t, Mesh::IndexType, char*> MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector<UnsignedInt>& indices);
/** /**
@brief Compress vertex indices and write them to index buffer @brief Compress vertex indices and write them to index buffer
@ -61,14 +61,14 @@ std::tuple<std::size_t, Mesh::IndexType, char*> MAGNUM_MESHTOOLS_EXPORT compress
@param usage Index buffer usage @param usage Index buffer usage
@param indices Index array @param indices Index array
The same as compressIndices(const std::vector<std::uint32_t>&), but this The same as compressIndices(const std::vector<UnsignedInt>&), but this
function writes the output to given buffer, updates index count and specifies function writes the output to given buffer, updates index count and specifies
index buffer with proper index range in the mesh, so you don't have to call index buffer with proper index range in the mesh, so you don't have to call
Mesh::setIndexCount() and Mesh::setIndexBuffer() on your own. Mesh::setIndexCount() and Mesh::setIndexBuffer() on your own.
@see MeshTools::interleave() @see MeshTools::interleave()
*/ */
void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<std::uint32_t>& indices); void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<UnsignedInt>& indices);
}} }}

2
src/MeshTools/FlipNormals.cpp

@ -19,7 +19,7 @@
namespace Magnum { namespace MeshTools { namespace Magnum { namespace MeshTools {
void flipFaceWinding(std::vector<std::uint32_t>& indices) { void flipFaceWinding(std::vector<UnsignedInt>& indices) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::flipNormals(): index count is not divisible by 3!", ); CORRADE_ASSERT(!(indices.size()%3), "MeshTools::flipNormals(): index count is not divisible by 3!", );
for(std::size_t i = 0; i != indices.size(); i += 3) for(std::size_t i = 0; i != indices.size(); i += 3)

8
src/MeshTools/FlipNormals.h

@ -31,15 +31,15 @@ namespace Magnum { namespace MeshTools {
/** /**
@brief Flip face winding @brief Flip face winding
The same as flipNormals(std::vector<std::uint32_t>&, std::vector<Vector3>&), The same as flipNormals(std::vector<UnsignedInt>&, std::vector<Vector3>&),
but flips only face winding. but flips only face winding.
*/ */
void MAGNUM_MESHTOOLS_EXPORT flipFaceWinding(std::vector<std::uint32_t>& indices); void MAGNUM_MESHTOOLS_EXPORT flipFaceWinding(std::vector<UnsignedInt>& indices);
/** /**
@brief Flip mesh normals @brief Flip mesh normals
The same as flipNormals(std::vector<std::uint32_t>&, std::vector<Vector3>&), The same as flipNormals(std::vector<UnsignedInt>&, std::vector<Vector3>&),
but flips only normals, not face winding. but flips only normals, not face winding.
*/ */
void MAGNUM_MESHTOOLS_EXPORT flipNormals(std::vector<Vector3>& normals); void MAGNUM_MESHTOOLS_EXPORT flipNormals(std::vector<Vector3>& normals);
@ -56,7 +56,7 @@ flipFaceWinding(), which flip normals or face winding only.
@attention The function requires the mesh to have triangle faces, thus index @attention The function requires the mesh to have triangle faces, thus index
count must be divisible by 3. count must be divisible by 3.
*/ */
inline void flipNormals(std::vector<std::uint32_t>& indices, std::vector<Vector3>& normals) { inline void flipNormals(std::vector<UnsignedInt>& indices, std::vector<Vector3>& normals) {
flipFaceWinding(indices); flipFaceWinding(indices);
flipNormals(normals); flipNormals(normals);
} }

6
src/MeshTools/GenerateFlatNormals.cpp

@ -20,11 +20,11 @@
namespace Magnum { namespace MeshTools { namespace Magnum { namespace MeshTools {
std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>> generateFlatNormals(const std::vector<std::uint32_t>& indices, const std::vector<Vector3>& positions) { std::tuple<std::vector<UnsignedInt>, std::vector<Vector3>> generateFlatNormals(const std::vector<UnsignedInt>& indices, const std::vector<Vector3>& positions) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>>())); CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (std::tuple<std::vector<UnsignedInt>, std::vector<Vector3>>()));
/* Create normal for every triangle (assuming counterclockwise winding) */ /* Create normal for every triangle (assuming counterclockwise winding) */
std::vector<std::uint32_t> normalIndices; std::vector<UnsignedInt> normalIndices;
normalIndices.reserve(indices.size()); normalIndices.reserve(indices.size());
std::vector<Vector3> normals; std::vector<Vector3> normals;
normals.reserve(indices.size()/3); normals.reserve(indices.size()/3);

6
src/MeshTools/GenerateFlatNormals.h

@ -38,10 +38,10 @@ namespace Magnum { namespace MeshTools {
For each face generates one normal vector, removes duplicates before For each face generates one normal vector, removes duplicates before
returning. Example usage: returning. Example usage:
@code @code
std::vector<std::uint32_t> vertexIndices; std::vector<UnsignedInt> vertexIndices;
std::vector<Vector3> positions; std::vector<Vector3> positions;
std::vector<std::uint32_t> normalIndices; std::vector<UnsignedInt> normalIndices;
std::vector<Vector3> normals; std::vector<Vector3> normals;
std::tie(normalIndices, normals) = MeshTools::generateFlatNormals(vertexIndices, positions); std::tie(normalIndices, normals) = MeshTools::generateFlatNormals(vertexIndices, positions);
@endcode @endcode
@ -51,7 +51,7 @@ use the same indices.
@attention Index count must be divisible by 3, otherwise zero length result @attention Index count must be divisible by 3, otherwise zero length result
is generated. is generated.
*/ */
std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector<std::uint32_t>& indices, const std::vector<Vector3>& positions); std::tuple<std::vector<UnsignedInt>, std::vector<Vector3>> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector<UnsignedInt>& indices, const std::vector<Vector3>& positions);
}} }}

12
src/MeshTools/Subdivide.h

@ -29,7 +29,7 @@ namespace Implementation {
template<class Vertex, class Interpolator> class Subdivide { template<class Vertex, class Interpolator> class Subdivide {
public: public:
inline Subdivide(std::vector<std::uint32_t>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {} inline Subdivide(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {}
void operator()(Interpolator interpolator) { void operator()(Interpolator interpolator) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::subdivide(): index count is not divisible by 3!", ); CORRADE_ASSERT(!(indices.size()%3), "MeshTools::subdivide(): index count is not divisible by 3!", );
@ -40,7 +40,7 @@ template<class Vertex, class Interpolator> class Subdivide {
/* Subdivide each face to four new */ /* Subdivide each face to four new */
for(std::size_t i = 0; i != indexCount; i += 3) { for(std::size_t i = 0; i != indexCount; i += 3) {
/* Interpolate each side */ /* Interpolate each side */
std::uint32_t newVertices[3]; UnsignedInt newVertices[3];
for(int j = 0; j != 3; ++j) for(int j = 0; j != 3; ++j)
newVertices[j] = addVertex(interpolator(vertices[indices[i+j]], vertices[indices[i+(j+1)%3]])); newVertices[j] = addVertex(interpolator(vertices[indices[i+j]], vertices[indices[i+(j+1)%3]]));
@ -66,15 +66,15 @@ template<class Vertex, class Interpolator> class Subdivide {
} }
private: private:
std::vector<std::uint32_t>& indices; std::vector<UnsignedInt>& indices;
std::vector<Vertex>& vertices; std::vector<Vertex>& vertices;
std::uint32_t addVertex(const Vertex& v) { UnsignedInt addVertex(const Vertex& v) {
vertices.push_back(v); vertices.push_back(v);
return vertices.size()-1; return vertices.size()-1;
} }
void addFace(std::uint32_t first, std::uint32_t second, std::uint32_t third) { void addFace(UnsignedInt first, UnsignedInt second, UnsignedInt third) {
indices.push_back(first); indices.push_back(first);
indices.push_back(second); indices.push_back(second);
indices.push_back(third); indices.push_back(third);
@ -96,7 +96,7 @@ template<class Vertex, class Interpolator> class Subdivide {
Goes through all triangle faces and subdivides them into four new. Cleaning Goes through all triangle faces and subdivides them into four new. Cleaning
duplicate vertices in the mesh is up to user. duplicate vertices in the mesh is up to user.
*/ */
template<class Vertex, class Interpolator> inline void subdivide(std::vector<std::uint32_t>& indices, std::vector<Vertex>& vertices, Interpolator interpolator) { template<class Vertex, class Interpolator> inline void subdivide(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices, Interpolator interpolator) {
Implementation::Subdivide<Vertex, Interpolator>(indices, vertices)(interpolator); Implementation::Subdivide<Vertex, Interpolator>(indices, vertices)(interpolator);
} }

6
src/MeshTools/Test/CleanTest.cpp

@ -29,7 +29,7 @@ class CleanTest: public Corrade::TestSuite::Tester {
class Vector1 { class Vector1 {
public: public:
static const std::size_t Size = 1; static const std::size_t Size = 1;
typedef std::int32_t Type; typedef Int Type;
Vector1(): data(0) {} Vector1(): data(0) {}
Vector1(Type i): data(i) {} Vector1(Type i): data(i) {}
@ -49,12 +49,12 @@ CleanTest::CleanTest() {
void CleanTest::cleanMesh() { void CleanTest::cleanMesh() {
std::vector<Vector1> positions{1, 2, 1, 4}; std::vector<Vector1> positions{1, 2, 1, 4};
std::vector<std::uint32_t> indices{0, 1, 2, 1, 2, 3}; std::vector<UnsignedInt> indices{0, 1, 2, 1, 2, 3};
MeshTools::clean(indices, positions); MeshTools::clean(indices, positions);
/* Verify cleanup */ /* Verify cleanup */
CORRADE_VERIFY(positions == (std::vector<Vector1>{1, 2, 4})); CORRADE_VERIFY(positions == (std::vector<Vector1>{1, 2, 4}));
CORRADE_COMPARE(indices, (std::vector<std::uint32_t>{0, 1, 0, 1, 0, 2})); CORRADE_COMPARE(indices, (std::vector<UnsignedInt>{0, 1, 0, 1, 0, 2}));
} }
}}} }}}

34
src/MeshTools/Test/CombineIndexedArraysTest.cpp

@ -37,29 +37,29 @@ CombineIndexedArraysTest::CombineIndexedArraysTest() {
void CombineIndexedArraysTest::wrongIndexCount() { void CombineIndexedArraysTest::wrongIndexCount() {
std::stringstream ss; std::stringstream ss;
Error::setOutput(&ss); Error::setOutput(&ss);
std::vector<std::uint32_t> array; std::vector<UnsignedInt> array;
std::vector<std::uint32_t> result = MeshTools::combineIndexedArrays( std::vector<UnsignedInt> result = MeshTools::combineIndexedArrays(
std::tuple<const std::vector<std::uint32_t>&, std::vector<std::uint32_t>&>(std::vector<std::uint32_t>{0, 1, 0}, array), std::tuple<const std::vector<UnsignedInt>&, std::vector<UnsignedInt>&>(std::vector<UnsignedInt>{0, 1, 0}, array),
std::tuple<const std::vector<std::uint32_t>&, std::vector<std::uint32_t>&>(std::vector<std::uint32_t>{3, 4}, array)); std::tuple<const std::vector<UnsignedInt>&, std::vector<UnsignedInt>&>(std::vector<UnsignedInt>{3, 4}, array));
CORRADE_COMPARE(result.size(), 0); CORRADE_COMPARE(result.size(), 0);
CORRADE_COMPARE(ss.str(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.\n"); CORRADE_COMPARE(ss.str(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.\n");
} }
void CombineIndexedArraysTest::combine() { void CombineIndexedArraysTest::combine() {
std::vector<std::uint32_t> array1{ 0, 1 }; std::vector<UnsignedInt> array1{ 0, 1 };
std::vector<std::uint32_t> array2{ 0, 1, 2, 3, 4 }; std::vector<UnsignedInt> array2{ 0, 1, 2, 3, 4 };
std::vector<std::uint32_t> array3{ 0, 1, 2, 3, 4, 5, 6, 7 }; std::vector<UnsignedInt> array3{ 0, 1, 2, 3, 4, 5, 6, 7 };
std::vector<std::uint32_t> result = MeshTools::combineIndexedArrays( std::vector<UnsignedInt> result = MeshTools::combineIndexedArrays(
std::tuple<const std::vector<std::uint32_t>&, std::vector<std::uint32_t>&>(std::vector<std::uint32_t>{0, 1, 0}, array1), std::tuple<const std::vector<UnsignedInt>&, std::vector<UnsignedInt>&>(std::vector<UnsignedInt>{0, 1, 0}, array1),
std::tuple<const std::vector<std::uint32_t>&, std::vector<std::uint32_t>&>(std::vector<std::uint32_t>{3, 4, 3}, array2), std::tuple<const std::vector<UnsignedInt>&, std::vector<UnsignedInt>&>(std::vector<UnsignedInt>{3, 4, 3}, array2),
std::tuple<const std::vector<std::uint32_t>&, std::vector<std::uint32_t>&>(std::vector<std::uint32_t>{6, 7, 6}, array3)); std::tuple<const std::vector<UnsignedInt>&, std::vector<UnsignedInt>&>(std::vector<UnsignedInt>{6, 7, 6}, array3));
CORRADE_COMPARE(result, (std::vector<std::uint32_t>{0, 1, 0})); CORRADE_COMPARE(result, (std::vector<UnsignedInt>{0, 1, 0}));
CORRADE_COMPARE(array1, (std::vector<std::uint32_t>{0, 1})); CORRADE_COMPARE(array1, (std::vector<UnsignedInt>{0, 1}));
CORRADE_COMPARE(array2, (std::vector<std::uint32_t>{3, 4})); CORRADE_COMPARE(array2, (std::vector<UnsignedInt>{3, 4}));
CORRADE_COMPARE(array3, (std::vector<std::uint32_t>{6, 7})); CORRADE_COMPARE(array3, (std::vector<UnsignedInt>{6, 7}));
} }
}}} }}}

6
src/MeshTools/Test/CompressIndicesTest.cpp

@ -42,7 +42,7 @@ void CompressIndicesTest::compressChar() {
Mesh::IndexType indexType; Mesh::IndexType indexType;
char* data; char* data;
std::tie(indexCount, indexType, data) = MeshTools::compressIndices( std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
std::vector<std::uint32_t>{1, 2, 3, 0, 4}); std::vector<UnsignedInt>{1, 2, 3, 0, 4});
CORRADE_COMPARE(indexCount, 5); CORRADE_COMPARE(indexCount, 5);
CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedByte); CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedByte);
@ -57,7 +57,7 @@ void CompressIndicesTest::compressShort() {
Mesh::IndexType indexType; Mesh::IndexType indexType;
char* data; char* data;
std::tie(indexCount, indexType, data) = MeshTools::compressIndices( std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
std::vector<std::uint32_t>{1, 256, 0, 5}); std::vector<UnsignedInt>{1, 256, 0, 5});
CORRADE_COMPARE(indexCount, 4); CORRADE_COMPARE(indexCount, 4);
CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedShort); CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedShort);
@ -83,7 +83,7 @@ void CompressIndicesTest::compressInt() {
Mesh::IndexType indexType; Mesh::IndexType indexType;
char* data; char* data;
std::tie(indexCount, indexType, data) = MeshTools::compressIndices( std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
std::vector<std::uint32_t>{65536, 3, 2}); std::vector<UnsignedInt>{65536, 3, 2});
CORRADE_COMPARE(indexCount, 3); CORRADE_COMPARE(indexCount, 3);
CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedInt); CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedInt);

6
src/MeshTools/Test/FlipNormalsTest.cpp

@ -40,18 +40,18 @@ void FlipNormalsTest::wrongIndexCount() {
std::stringstream ss; std::stringstream ss;
Error::setOutput(&ss); Error::setOutput(&ss);
std::vector<std::uint32_t> indices{0, 1}; std::vector<UnsignedInt> indices{0, 1};
MeshTools::flipFaceWinding(indices); MeshTools::flipFaceWinding(indices);
CORRADE_COMPARE(ss.str(), "MeshTools::flipNormals(): index count is not divisible by 3!\n"); CORRADE_COMPARE(ss.str(), "MeshTools::flipNormals(): index count is not divisible by 3!\n");
} }
void FlipNormalsTest::flipFaceWinding() { void FlipNormalsTest::flipFaceWinding() {
std::vector<std::uint32_t> indices{0, 1, 2, std::vector<UnsignedInt> indices{0, 1, 2,
3, 4, 5}; 3, 4, 5};
MeshTools::flipFaceWinding(indices); MeshTools::flipFaceWinding(indices);
CORRADE_COMPARE(indices, (std::vector<std::uint32_t>{0, 2, 1, CORRADE_COMPARE(indices, (std::vector<UnsignedInt>{0, 2, 1,
3, 5, 4})); 3, 5, 4}));
} }

6
src/MeshTools/Test/GenerateFlatNormalsTest.cpp

@ -37,7 +37,7 @@ GenerateFlatNormalsTest::GenerateFlatNormalsTest() {
void GenerateFlatNormalsTest::wrongIndexCount() { void GenerateFlatNormalsTest::wrongIndexCount() {
std::stringstream ss; std::stringstream ss;
Error::setOutput(&ss); Error::setOutput(&ss);
std::vector<std::uint32_t> indices; std::vector<UnsignedInt> indices;
std::vector<Vector3> normals; std::vector<Vector3> normals;
std::tie(indices, normals) = MeshTools::generateFlatNormals({ std::tie(indices, normals) = MeshTools::generateFlatNormals({
0, 1 0, 1
@ -50,7 +50,7 @@ void GenerateFlatNormalsTest::wrongIndexCount() {
void GenerateFlatNormalsTest::generate() { void GenerateFlatNormalsTest::generate() {
/* Two vertices connected by one edge, each winded in another direction */ /* Two vertices connected by one edge, each winded in another direction */
std::vector<std::uint32_t> indices; std::vector<UnsignedInt> indices;
std::vector<Vector3> normals; std::vector<Vector3> normals;
std::tie(indices, normals) = MeshTools::generateFlatNormals({ std::tie(indices, normals) = MeshTools::generateFlatNormals({
0, 1, 2, 0, 1, 2,
@ -62,7 +62,7 @@ void GenerateFlatNormalsTest::generate() {
{1.0f, 0.0f, 0.0f} {1.0f, 0.0f, 0.0f}
}); });
CORRADE_COMPARE(indices, (std::vector<std::uint32_t>{ CORRADE_COMPARE(indices, (std::vector<UnsignedInt>{
0, 0, 0, 0, 0, 0,
1, 1, 1 1, 1, 1
})); }));

32
src/MeshTools/Test/InterleaveTest.cpp

@ -48,30 +48,30 @@ InterleaveTest::InterleaveTest() {
void InterleaveTest::attributeCount() { void InterleaveTest::attributeCount() {
std::stringstream ss; std::stringstream ss;
Error::setOutput(&ss); Error::setOutput(&ss);
CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector<std::int8_t>{0, 1, 2}, CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector<Byte>{0, 1, 2},
std::vector<std::int8_t>{0, 1, 2, 3, 4, 5})), std::size_t(0)); std::vector<Byte>{0, 1, 2, 3, 4, 5})), std::size_t(0));
CORRADE_COMPARE(ss.str(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.\n"); CORRADE_COMPARE(ss.str(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.\n");
CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector<std::int8_t>{0, 1, 2}, CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector<Byte>{0, 1, 2},
std::vector<std::int8_t>{3, 4, 5})), std::size_t(3)); std::vector<Byte>{3, 4, 5})), std::size_t(3));
} }
void InterleaveTest::attributeCountGaps() { void InterleaveTest::attributeCountGaps() {
CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector<std::int8_t>{0, 1, 2}, 3, CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector<Byte>{0, 1, 2}, 3,
std::vector<std::int8_t>{3, 4, 5}, 5)), std::size_t(3)); std::vector<Byte>{3, 4, 5}, 5)), std::size_t(3));
/* No arrays from which to get size */ /* No arrays from which to get size */
CORRADE_COMPARE(Implementation::Interleave::attributeCount(3, 5), ~std::size_t(0)); CORRADE_COMPARE(Implementation::Interleave::attributeCount(3, 5), ~std::size_t(0));
} }
void InterleaveTest::stride() { void InterleaveTest::stride() {
CORRADE_COMPARE(Implementation::Interleave::stride(std::vector<std::int8_t>()), std::size_t(1)); CORRADE_COMPARE(Implementation::Interleave::stride(std::vector<Byte>()), std::size_t(1));
CORRADE_COMPARE(Implementation::Interleave::stride(std::vector<std::int32_t>()), std::size_t(4)); CORRADE_COMPARE(Implementation::Interleave::stride(std::vector<Int>()), std::size_t(4));
CORRADE_COMPARE((Implementation::Interleave::stride(std::vector<std::int8_t>(), std::vector<std::int32_t>())), std::size_t(5)); CORRADE_COMPARE((Implementation::Interleave::stride(std::vector<Byte>(), std::vector<Int>())), std::size_t(5));
} }
void InterleaveTest::strideGaps() { void InterleaveTest::strideGaps() {
CORRADE_COMPARE((Implementation::Interleave::stride(2, std::vector<std::int8_t>(), 1, std::vector<std::int32_t>(), 12)), std::size_t(20)); CORRADE_COMPARE((Implementation::Interleave::stride(2, std::vector<Byte>(), 1, std::vector<Int>(), 12)), std::size_t(20));
} }
void InterleaveTest::write() { void InterleaveTest::write() {
@ -79,9 +79,9 @@ void InterleaveTest::write() {
std::size_t stride; std::size_t stride;
char* data; char* data;
std::tie(attributeCount, stride, data) = MeshTools::interleave( std::tie(attributeCount, stride, data) = MeshTools::interleave(
std::vector<std::int8_t>{0, 1, 2}, std::vector<Byte>{0, 1, 2},
std::vector<std::int32_t>{3, 4, 5}, std::vector<Int>{3, 4, 5},
std::vector<std::int16_t>{6, 7, 8}); std::vector<Short>{6, 7, 8});
CORRADE_COMPARE(attributeCount, std::size_t(3)); CORRADE_COMPARE(attributeCount, std::size_t(3));
CORRADE_COMPARE(stride, std::size_t(7)); CORRADE_COMPARE(stride, std::size_t(7));
@ -108,9 +108,9 @@ void InterleaveTest::writeGaps() {
std::size_t stride; std::size_t stride;
char* data; char* data;
std::tie(attributeCount, stride, data) = MeshTools::interleave( std::tie(attributeCount, stride, data) = MeshTools::interleave(
std::vector<std::int8_t>{0, 1, 2}, 3, std::vector<Byte>{0, 1, 2}, 3,
std::vector<std::int32_t>{3, 4, 5}, std::vector<Int>{3, 4, 5},
std::vector<std::int16_t>{6, 7, 8}, 2); std::vector<Short>{6, 7, 8}, 2);
CORRADE_COMPARE(attributeCount, std::size_t(3)); CORRADE_COMPARE(attributeCount, std::size_t(3));
CORRADE_COMPARE(stride, std::size_t(12)); CORRADE_COMPARE(stride, std::size_t(12));

8
src/MeshTools/Test/SubdivideTest.cpp

@ -33,7 +33,7 @@ class SubdivideTest: public Corrade::TestSuite::Tester {
class Vector1 { class Vector1 {
public: public:
static const std::size_t Size = 1; static const std::size_t Size = 1;
typedef std::int32_t Type; typedef Int Type;
Vector1(): data(0) {} Vector1(): data(0) {}
Vector1(Type i): data(i) {} Vector1(Type i): data(i) {}
@ -59,20 +59,20 @@ void SubdivideTest::wrongIndexCount() {
Error::setOutput(&ss); Error::setOutput(&ss);
std::vector<Vector1> positions; std::vector<Vector1> positions;
std::vector<std::uint32_t> indices{0, 1}; std::vector<UnsignedInt> indices{0, 1};
MeshTools::subdivide(indices, positions, interpolator); MeshTools::subdivide(indices, positions, interpolator);
CORRADE_COMPARE(ss.str(), "MeshTools::subdivide(): index count is not divisible by 3!\n"); CORRADE_COMPARE(ss.str(), "MeshTools::subdivide(): index count is not divisible by 3!\n");
} }
void SubdivideTest::subdivide() { void SubdivideTest::subdivide() {
std::vector<Vector1> positions{0, 2, 6, 8}; std::vector<Vector1> positions{0, 2, 6, 8};
std::vector<std::uint32_t> indices{0, 1, 2, 1, 2, 3}; std::vector<UnsignedInt> indices{0, 1, 2, 1, 2, 3};
MeshTools::subdivide(indices, positions, interpolator); MeshTools::subdivide(indices, positions, interpolator);
CORRADE_COMPARE(indices.size(), 24); CORRADE_COMPARE(indices.size(), 24);
CORRADE_VERIFY(positions == (std::vector<Vector1>{0, 2, 6, 8, 1, 4, 3, 4, 7, 5})); CORRADE_VERIFY(positions == (std::vector<Vector1>{0, 2, 6, 8, 1, 4, 3, 4, 7, 5}));
CORRADE_COMPARE(indices, (std::vector<std::uint32_t>{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3})); CORRADE_COMPARE(indices, (std::vector<UnsignedInt>{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3}));
MeshTools::clean(indices, positions); MeshTools::clean(indices, positions);

12
src/MeshTools/Test/TipsifyTest.cpp

@ -27,7 +27,7 @@ class TipsifyTest: public Corrade::TestSuite::Tester {
void tipsify(); void tipsify();
private: private:
std::vector<std::uint32_t> indices; std::vector<UnsignedInt> indices;
std::size_t vertexCount; std::size_t vertexCount;
}; };
@ -75,10 +75,10 @@ TipsifyTest::TipsifyTest(): indices{
} }
void TipsifyTest::buildAdjacency() { void TipsifyTest::buildAdjacency() {
std::vector<std::uint32_t> liveTriangleCount, neighborOffset, neighbors; std::vector<UnsignedInt> liveTriangleCount, neighborOffset, neighbors;
Implementation::Tipsify(indices, vertexCount).buildAdjacency(liveTriangleCount, neighborOffset, neighbors); Implementation::Tipsify(indices, vertexCount).buildAdjacency(liveTriangleCount, neighborOffset, neighbors);
CORRADE_COMPARE(liveTriangleCount, (std::vector<std::uint32_t>{ CORRADE_COMPARE(liveTriangleCount, (std::vector<UnsignedInt>{
1, 3, 3, 2, 1, 3, 3, 2,
4, 6, 6, 2, 4, 6, 6, 2,
2, 6, 6, 4, 2, 6, 6, 4,
@ -86,7 +86,7 @@ void TipsifyTest::buildAdjacency() {
1, 1, 1 1, 1, 1
})); }));
CORRADE_COMPARE(neighborOffset, (std::vector<std::uint32_t>{ CORRADE_COMPARE(neighborOffset, (std::vector<UnsignedInt>{
0, 1, 4, 7, 0, 1, 4, 7,
9, 13, 19, 25, 9, 13, 19, 25,
27, 29, 35, 41, 27, 29, 35, 41,
@ -94,7 +94,7 @@ void TipsifyTest::buildAdjacency() {
54, 55, 56, 57 54, 55, 56, 57
})); }));
CORRADE_COMPARE(neighbors, (std::vector<std::uint32_t>{ CORRADE_COMPARE(neighbors, (std::vector<UnsignedInt>{
0, 0,
0, 7, 11, 0, 7, 11,
2, 7, 13, 2, 7, 13,
@ -122,7 +122,7 @@ void TipsifyTest::buildAdjacency() {
void TipsifyTest::tipsify() { void TipsifyTest::tipsify() {
MeshTools::tipsify(indices, vertexCount, 3); MeshTools::tipsify(indices, vertexCount, 3);
CORRADE_COMPARE(indices, (std::vector<std::uint32_t>{ CORRADE_COMPARE(indices, (std::vector<UnsignedInt>{
4, 1, 0, 4, 1, 0,
9, 5, 4, 9, 5, 4,
1, 4, 5, 1, 4, 5,

30
src/MeshTools/Tipsify.cpp

@ -22,37 +22,37 @@ namespace Magnum { namespace MeshTools { namespace Implementation {
void Tipsify::operator()(std::size_t cacheSize) { void Tipsify::operator()(std::size_t cacheSize) {
/* Neighboring triangles for each vertex, per-vertex live triangle count */ /* Neighboring triangles for each vertex, per-vertex live triangle count */
std::vector<std::uint32_t> liveTriangleCount, neighborPosition, neighbors; std::vector<UnsignedInt> liveTriangleCount, neighborPosition, neighbors;
buildAdjacency(liveTriangleCount, neighborPosition, neighbors); buildAdjacency(liveTriangleCount, neighborPosition, neighbors);
/* Global time, per-vertex caching timestamps, per-triangle emmited flag */ /* Global time, per-vertex caching timestamps, per-triangle emmited flag */
std::uint32_t time = cacheSize+1; UnsignedInt time = cacheSize+1;
std::vector<std::uint32_t> timestamp(vertexCount); std::vector<UnsignedInt> timestamp(vertexCount);
std::vector<bool> emitted(indices.size()/3); std::vector<bool> emitted(indices.size()/3);
/* Dead-end vertex stack */ /* Dead-end vertex stack */
std::stack<std::uint32_t> deadEndStack; std::stack<UnsignedInt> deadEndStack;
/* Output index buffer */ /* Output index buffer */
std::vector<std::uint32_t> outputIndices; std::vector<UnsignedInt> outputIndices;
outputIndices.reserve(indices.size()); outputIndices.reserve(indices.size());
/* Starting vertex for fanning, cursor */ /* Starting vertex for fanning, cursor */
std::uint32_t fanningVertex = 0; UnsignedInt fanningVertex = 0;
std::uint32_t i = 0; UnsignedInt i = 0;
while(fanningVertex != 0xFFFFFFFFu) { while(fanningVertex != 0xFFFFFFFFu) {
/* Array with candidates for next fanning vertex (in 1-ring around /* Array with candidates for next fanning vertex (in 1-ring around
fanning vertex) */ fanning vertex) */
std::vector<std::uint32_t> candidates; std::vector<UnsignedInt> candidates;
/* For all neighbors of fanning vertex */ /* For all neighbors of fanning vertex */
for(std::uint32_t ti = neighborPosition[fanningVertex], t = neighbors[ti]; ti != neighborPosition[fanningVertex+1]; t = neighbors[++ti]) { for(UnsignedInt ti = neighborPosition[fanningVertex], t = neighbors[ti]; ti != neighborPosition[fanningVertex+1]; t = neighbors[++ti]) {
/* Continue if already emitted */ /* Continue if already emitted */
if(emitted[t]) continue; if(emitted[t]) continue;
emitted[t] = true; emitted[t] = true;
/* Write all vertices of the triangle to output buffer */ /* Write all vertices of the triangle to output buffer */
for(std::uint32_t vi = 0, v = indices[t*3]; vi != 3; v = indices[++vi+t*3]) { for(UnsignedInt vi = 0, v = indices[t*3]; vi != 3; v = indices[++vi+t*3]) {
outputIndices.push_back(v); outputIndices.push_back(v);
/* Add to dead end stack and candidates array */ /* Add to dead end stack and candidates array */
@ -73,15 +73,15 @@ void Tipsify::operator()(std::size_t cacheSize) {
fanningVertex = 0xFFFFFFFFu; fanningVertex = 0xFFFFFFFFu;
/* Go through candidates in 1-ring around fanning vertex */ /* Go through candidates in 1-ring around fanning vertex */
std::int32_t candidatePriority = -1; Int candidatePriority = -1;
for(std::uint32_t v: candidates) { for(UnsignedInt v: candidates) {
/* Skip if it doesn't have any live triangles */ /* Skip if it doesn't have any live triangles */
if(!liveTriangleCount[v]) continue; if(!liveTriangleCount[v]) continue;
/* Get most fresh candidate which will still be in cache even /* Get most fresh candidate which will still be in cache even
after fanning. Every fanned triangle will generate at most after fanning. Every fanned triangle will generate at most
two cache misses, thus 2*liveTriangleCount */ two cache misses, thus 2*liveTriangleCount */
std::int32_t priority = 0; Int priority = 0;
if(time-timestamp[v]+2*liveTriangleCount[v] <= cacheSize) if(time-timestamp[v]+2*liveTriangleCount[v] <= cacheSize)
priority = time-timestamp[v]; priority = time-timestamp[v];
if(priority > candidatePriority) { if(priority > candidatePriority) {
@ -117,7 +117,7 @@ void Tipsify::operator()(std::size_t cacheSize) {
std::swap(indices, outputIndices); std::swap(indices, outputIndices);
} }
void Tipsify::buildAdjacency(std::vector<std::uint32_t>& liveTriangleCount, std::vector<std::uint32_t>& neighborOffset, std::vector<std::uint32_t>& neighbors) const { void Tipsify::buildAdjacency(std::vector<UnsignedInt>& liveTriangleCount, std::vector<UnsignedInt>& neighborOffset, std::vector<UnsignedInt>& neighbors) const {
/* How many times is each vertex referenced == count of neighboring /* How many times is each vertex referenced == count of neighboring
triangles for each vertex */ triangles for each vertex */
liveTriangleCount.clear(); liveTriangleCount.clear();
@ -132,7 +132,7 @@ void Tipsify::buildAdjacency(std::vector<std::uint32_t>& liveTriangleCount, std:
neighborOffset.clear(); neighborOffset.clear();
neighborOffset.reserve(vertexCount+1); neighborOffset.reserve(vertexCount+1);
neighborOffset.push_back(0); neighborOffset.push_back(0);
std::uint32_t sum = 0; UnsignedInt sum = 0;
for(std::size_t i = 0; i != vertexCount; ++i) { for(std::size_t i = 0; i != vertexCount; ++i) {
neighborOffset.push_back(sum); neighborOffset.push_back(sum);
sum += liveTriangleCount[i]; sum += liveTriangleCount[i];

12
src/MeshTools/Tipsify.h

@ -19,9 +19,9 @@
* @brief Function Magnum::MeshTools::tipsify() * @brief Function Magnum::MeshTools::tipsify()
*/ */
#include <cstdint>
#include <vector> #include <vector>
#include "Types.h"
#include "magnumMeshToolsVisibility.h" #include "magnumMeshToolsVisibility.h"
namespace Magnum { namespace MeshTools { namespace Magnum { namespace MeshTools {
@ -31,7 +31,7 @@ namespace Implementation {
class MAGNUM_MESHTOOLS_EXPORT Tipsify { class MAGNUM_MESHTOOLS_EXPORT Tipsify {
public: public:
inline Tipsify(std::vector<std::uint32_t>& indices, std::uint32_t vertexCount): indices(indices), vertexCount(vertexCount) {} inline Tipsify(std::vector<UnsignedInt>& indices, UnsignedInt vertexCount): indices(indices), vertexCount(vertexCount) {}
void operator()(std::size_t cacheSize); void operator()(std::size_t cacheSize);
@ -42,11 +42,11 @@ class MAGNUM_MESHTOOLS_EXPORT Tipsify {
* (used internally). * (used internally).
* @todo Export only for unit test, hide otherwise * @todo Export only for unit test, hide otherwise
*/ */
void buildAdjacency(std::vector<std::uint32_t>& liveTriangleCount, std::vector<std::uint32_t>& neighborOffset, std::vector<std::uint32_t>& neighbors) const; void buildAdjacency(std::vector<UnsignedInt>& liveTriangleCount, std::vector<UnsignedInt>& neighborOffset, std::vector<UnsignedInt>& neighbors) const;
private: private:
std::vector<std::uint32_t>& indices; std::vector<UnsignedInt>& indices;
const std::uint32_t vertexCount; const UnsignedInt vertexCount;
}; };
} }
@ -64,7 +64,7 @@ array for beter usage of post-transform vertex cache. Algorithm used:
for Vertex Locality and Reduced Overdraw, SIGGRAPH 2007, for Vertex Locality and Reduced Overdraw, SIGGRAPH 2007,
http://gfx.cs.princeton.edu/pubs/Sander_2007_%3ETR/index.php*. http://gfx.cs.princeton.edu/pubs/Sander_2007_%3ETR/index.php*.
*/ */
inline void tipsify(std::vector<std::uint32_t>& indices, std::uint32_t vertexCount, std::size_t cacheSize) { inline void tipsify(std::vector<UnsignedInt>& indices, UnsignedInt vertexCount, std::size_t cacheSize) {
Implementation::Tipsify(indices, vertexCount)(cacheSize); Implementation::Tipsify(indices, vertexCount)(cacheSize);
} }

Loading…
Cancel
Save