From 32b783505fe6fc31dcc50e7870a74e72145a67bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 22:53:59 +0100 Subject: [PATCH] MeshTools: using new type aliases in whole MeshTools namespace. --- src/MeshTools/Clean.h | 10 +++--- src/MeshTools/CombineIndexedArrays.h | 24 ++++++------- src/MeshTools/CompressIndices.cpp | 20 +++++------ src/MeshTools/CompressIndices.h | 8 ++--- src/MeshTools/FlipNormals.cpp | 2 +- src/MeshTools/FlipNormals.h | 8 ++--- src/MeshTools/GenerateFlatNormals.cpp | 6 ++-- src/MeshTools/GenerateFlatNormals.h | 6 ++-- src/MeshTools/Subdivide.h | 12 +++---- src/MeshTools/Test/CleanTest.cpp | 6 ++-- .../Test/CombineIndexedArraysTest.cpp | 34 +++++++++---------- src/MeshTools/Test/CompressIndicesTest.cpp | 6 ++-- src/MeshTools/Test/FlipNormalsTest.cpp | 6 ++-- .../Test/GenerateFlatNormalsTest.cpp | 6 ++-- src/MeshTools/Test/InterleaveTest.cpp | 32 ++++++++--------- src/MeshTools/Test/SubdivideTest.cpp | 8 ++--- src/MeshTools/Test/TipsifyTest.cpp | 12 +++---- src/MeshTools/Tipsify.cpp | 30 ++++++++-------- src/MeshTools/Tipsify.h | 12 +++---- 19 files changed, 124 insertions(+), 124 deletions(-) diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index 60c940282..df6f1f5c2 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -32,7 +32,7 @@ namespace Implementation { template class Clean { public: - inline Clean(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} + inline Clean(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} void operator()(typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { if(indices.empty()) return; @@ -107,12 +107,12 @@ template class Clean { }; 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& indices; + std::vector& indices; std::vector& vertices; }; @@ -136,7 +136,7 @@ Removes duplicate vertices from the mesh. @todo Interpolate vertices, not collapse them to first in the cell @todo Ability to specify other attributes for interpolation */ -template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { +template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { Implementation::Clean(indices, vertices)(epsilon); } diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index 07cef4980..528d3cd43 100644 --- a/src/MeshTools/CombineIndexedArrays.h +++ b/src/MeshTools/CombineIndexedArrays.h @@ -33,17 +33,17 @@ namespace Implementation { class CombineIndexedArrays { public: - template std::vector operator()(const std::tuple&, std::vector&>&... indexedArrays) { + template std::vector operator()(const std::tuple&, std::vector&>&... indexedArrays) { /* Compute index count */ std::size_t _indexCount = indexCount(std::get<0>(indexedArrays)...); /* Resulting index array */ - std::vector result; + std::vector result; result.resize(_indexCount); std::iota(result.begin(), result.end(), 0); /* All index combinations */ - std::vector > indexCombinations(_indexCount); + std::vector > indexCombinations(_indexCount); writeCombinedIndices(indexCombinations, std::get<0>(indexedArrays)...); /* Make the combinations unique */ @@ -56,13 +56,13 @@ class CombineIndexedArrays { } private: - template inline static std::size_t indexCount(const std::vector& first, const std::vector&... next) { + template inline static std::size_t indexCount(const std::vector& first, const std::vector&... next) { 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(); } - template static void writeCombinedIndices(std::vector>& output, const std::vector& first, const std::vector&... next) { + template static void writeCombinedIndices(std::vector>& output, const std::vector& first, const std::vector&... next) { /* Copy the data to output */ for(std::size_t i = 0; i != output.size(); ++i) output[i][size-sizeof...(next)-1] = first[i]; @@ -70,7 +70,7 @@ class CombineIndexedArrays { writeCombinedIndices(output, next...); } - template static void writeCombinedArrays(const std::vector>& combinedIndices, std::vector& first, std::vector&... next) { + template static void writeCombinedArrays(const std::vector>& combinedIndices, std::vector& first, std::vector&... next) { /* Rewrite output array */ std::vector output; for(std::size_t i = 0; i != combinedIndices.size(); ++i) @@ -82,8 +82,8 @@ class CombineIndexedArrays { /* Terminator functions for recursive calls */ inline static std::size_t indexCount() { return 0; } - template inline static void writeCombinedIndices(std::vector>&) {} - template inline static void writeCombinedArrays(const std::vector>&) {} + template inline static void writeCombinedIndices(std::vector>&) {} + template inline static void writeCombinedArrays(const std::vector>&) {} }; } @@ -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 more than one attribute array, just pass the index array more times. Example: @code -std::vector vertexIndices; +std::vector vertexIndices; std::vector positions; -std::vector normalTextureIndices; +std::vector normalTextureIndices; std::vector normals; std::vector textureCoordinates; -std::vector indices = MeshTools::combineIndexedArrays( +std::vector indices = MeshTools::combineIndexedArrays( 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(textureCoordinates)) @@ -125,7 +125,7 @@ attributes indexed with `indices`. /* 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 of the same type. */ -template std::vector combineIndexedArrays(const std::tuple&, std::vector&>&... indexedArrays) { +template std::vector combineIndexedArrays(const std::tuple&, std::vector&>&... indexedArrays) { return Implementation::CombineIndexedArrays()(indexedArrays...); } diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index b76c5af3e..e100078c3 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -26,11 +26,11 @@ namespace Magnum { namespace MeshTools { namespace { template constexpr Mesh::IndexType indexType(); -template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedByte; } -template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedShort; } -template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedInt; } +template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedByte; } +template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedShort; } +template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedInt; } -template inline std::tuple compress(const std::vector& indices) { +template inline std::tuple compress(const std::vector& indices) { char* buffer = new char[indices.size()*sizeof(T)]; for(std::size_t i = 0; i != indices.size(); ++i) { T index = static_cast(indices[i]); @@ -40,15 +40,15 @@ template inline std::tuple compres return std::make_tuple(indices.size(), indexType(), buffer); } -std::tuple compressIndicesInternal(const std::vector& indices, std::uint32_t max) { +std::tuple compressIndicesInternal(const std::vector& indices, UnsignedInt max) { switch(Math::log(256, max)) { case 0: - return compress(indices); + return compress(indices); case 1: - return compress(indices); + return compress(indices); case 2: case 3: - return compress(indices); + return compress(indices); default: CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << max << "elements.", {}); @@ -58,11 +58,11 @@ std::tuple compressIndicesInternal(const st } #endif -std::tuple compressIndices(const std::vector& indices) { +std::tuple compressIndices(const std::vector& indices) { return compressIndicesInternal(indices, *std::max_element(indices.begin(), indices.end())); } -void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices) { +void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices) { auto minmax = std::minmax_element(indices.begin(), indices.end()); /** @todo Performance hint when range can be represented by smaller value? */ diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index ac67d5849..2b5d029ad 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -49,10 +49,10 @@ std::size_t dataSize = indexCount*Mesh::indexSize(indexType); delete[] data; @endcode -See also compressIndices(Mesh*, Buffer*, Buffer::Usage, const std::vector&), +See also compressIndices(Mesh*, Buffer*, Buffer::Usage, const std::vector&), which writes the compressed data directly into index buffer of given mesh. */ -std::tuple MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector& indices); +std::tuple MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector& indices); /** @brief Compress vertex indices and write them to index buffer @@ -61,14 +61,14 @@ std::tuple MAGNUM_MESHTOOLS_EXPORT compress @param usage Index buffer usage @param indices Index array -The same as compressIndices(const std::vector&), but this +The same as compressIndices(const std::vector&), but this 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 Mesh::setIndexCount() and Mesh::setIndexBuffer() on your own. @see MeshTools::interleave() */ -void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices); +void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices); }} diff --git a/src/MeshTools/FlipNormals.cpp b/src/MeshTools/FlipNormals.cpp index 596dfb4a3..5dda1adc2 100644 --- a/src/MeshTools/FlipNormals.cpp +++ b/src/MeshTools/FlipNormals.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace MeshTools { -void flipFaceWinding(std::vector& indices) { +void flipFaceWinding(std::vector& indices) { 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) diff --git a/src/MeshTools/FlipNormals.h b/src/MeshTools/FlipNormals.h index 98d71eb08..c0f6f5519 100644 --- a/src/MeshTools/FlipNormals.h +++ b/src/MeshTools/FlipNormals.h @@ -31,15 +31,15 @@ namespace Magnum { namespace MeshTools { /** @brief Flip face winding -The same as flipNormals(std::vector&, std::vector&), +The same as flipNormals(std::vector&, std::vector&), but flips only face winding. */ -void MAGNUM_MESHTOOLS_EXPORT flipFaceWinding(std::vector& indices); +void MAGNUM_MESHTOOLS_EXPORT flipFaceWinding(std::vector& indices); /** @brief Flip mesh normals -The same as flipNormals(std::vector&, std::vector&), +The same as flipNormals(std::vector&, std::vector&), but flips only normals, not face winding. */ void MAGNUM_MESHTOOLS_EXPORT flipNormals(std::vector& 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 count must be divisible by 3. */ -inline void flipNormals(std::vector& indices, std::vector& normals) { +inline void flipNormals(std::vector& indices, std::vector& normals) { flipFaceWinding(indices); flipNormals(normals); } diff --git a/src/MeshTools/GenerateFlatNormals.cpp b/src/MeshTools/GenerateFlatNormals.cpp index 2c5195728..dcc00bc5f 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -20,11 +20,11 @@ namespace Magnum { namespace MeshTools { -std::tuple, std::vector> generateFlatNormals(const std::vector& indices, const std::vector& positions) { - CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (std::tuple, std::vector>())); +std::tuple, std::vector> generateFlatNormals(const std::vector& indices, const std::vector& positions) { + CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (std::tuple, std::vector>())); /* Create normal for every triangle (assuming counterclockwise winding) */ - std::vector normalIndices; + std::vector normalIndices; normalIndices.reserve(indices.size()); std::vector normals; normals.reserve(indices.size()/3); diff --git a/src/MeshTools/GenerateFlatNormals.h b/src/MeshTools/GenerateFlatNormals.h index cdccb6d7e..b9060b292 100644 --- a/src/MeshTools/GenerateFlatNormals.h +++ b/src/MeshTools/GenerateFlatNormals.h @@ -38,10 +38,10 @@ namespace Magnum { namespace MeshTools { For each face generates one normal vector, removes duplicates before returning. Example usage: @code -std::vector vertexIndices; +std::vector vertexIndices; std::vector positions; -std::vector normalIndices; +std::vector normalIndices; std::vector normals; std::tie(normalIndices, normals) = MeshTools::generateFlatNormals(vertexIndices, positions); @endcode @@ -51,7 +51,7 @@ use the same indices. @attention Index count must be divisible by 3, otherwise zero length result is generated. */ -std::tuple, std::vector> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); +std::tuple, std::vector> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); }} diff --git a/src/MeshTools/Subdivide.h b/src/MeshTools/Subdivide.h index 8993bb4da..d98823267 100644 --- a/src/MeshTools/Subdivide.h +++ b/src/MeshTools/Subdivide.h @@ -29,7 +29,7 @@ namespace Implementation { template class Subdivide { public: - inline Subdivide(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} + inline Subdivide(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} void operator()(Interpolator interpolator) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::subdivide(): index count is not divisible by 3!", ); @@ -40,7 +40,7 @@ template class Subdivide { /* Subdivide each face to four new */ for(std::size_t i = 0; i != indexCount; i += 3) { /* Interpolate each side */ - std::uint32_t newVertices[3]; + UnsignedInt newVertices[3]; for(int j = 0; j != 3; ++j) newVertices[j] = addVertex(interpolator(vertices[indices[i+j]], vertices[indices[i+(j+1)%3]])); @@ -66,15 +66,15 @@ template class Subdivide { } private: - std::vector& indices; + std::vector& indices; std::vector& vertices; - std::uint32_t addVertex(const Vertex& v) { + UnsignedInt addVertex(const Vertex& v) { vertices.push_back(v); 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(second); indices.push_back(third); @@ -96,7 +96,7 @@ template class Subdivide { Goes through all triangle faces and subdivides them into four new. Cleaning duplicate vertices in the mesh is up to user. */ -template inline void subdivide(std::vector& indices, std::vector& vertices, Interpolator interpolator) { +template inline void subdivide(std::vector& indices, std::vector& vertices, Interpolator interpolator) { Implementation::Subdivide(indices, vertices)(interpolator); } diff --git a/src/MeshTools/Test/CleanTest.cpp b/src/MeshTools/Test/CleanTest.cpp index c26413082..658c1296f 100644 --- a/src/MeshTools/Test/CleanTest.cpp +++ b/src/MeshTools/Test/CleanTest.cpp @@ -29,7 +29,7 @@ class CleanTest: public Corrade::TestSuite::Tester { class Vector1 { public: static const std::size_t Size = 1; - typedef std::int32_t Type; + typedef Int Type; Vector1(): data(0) {} Vector1(Type i): data(i) {} @@ -49,12 +49,12 @@ CleanTest::CleanTest() { void CleanTest::cleanMesh() { std::vector positions{1, 2, 1, 4}; - std::vector indices{0, 1, 2, 1, 2, 3}; + std::vector indices{0, 1, 2, 1, 2, 3}; MeshTools::clean(indices, positions); /* Verify cleanup */ CORRADE_VERIFY(positions == (std::vector{1, 2, 4})); - CORRADE_COMPARE(indices, (std::vector{0, 1, 0, 1, 0, 2})); + CORRADE_COMPARE(indices, (std::vector{0, 1, 0, 1, 0, 2})); } }}} diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.cpp b/src/MeshTools/Test/CombineIndexedArraysTest.cpp index ade28f47c..edd14e225 100644 --- a/src/MeshTools/Test/CombineIndexedArraysTest.cpp +++ b/src/MeshTools/Test/CombineIndexedArraysTest.cpp @@ -37,29 +37,29 @@ CombineIndexedArraysTest::CombineIndexedArraysTest() { void CombineIndexedArraysTest::wrongIndexCount() { std::stringstream ss; Error::setOutput(&ss); - std::vector array; - std::vector result = MeshTools::combineIndexedArrays( - std::tuple&, std::vector&>(std::vector{0, 1, 0}, array), - std::tuple&, std::vector&>(std::vector{3, 4}, array)); + std::vector array; + std::vector result = MeshTools::combineIndexedArrays( + std::tuple&, std::vector&>(std::vector{0, 1, 0}, array), + std::tuple&, std::vector&>(std::vector{3, 4}, array)); CORRADE_COMPARE(result.size(), 0); CORRADE_COMPARE(ss.str(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.\n"); } void CombineIndexedArraysTest::combine() { - std::vector array1{ 0, 1 }; - std::vector array2{ 0, 1, 2, 3, 4 }; - std::vector array3{ 0, 1, 2, 3, 4, 5, 6, 7 }; - - std::vector result = MeshTools::combineIndexedArrays( - std::tuple&, std::vector&>(std::vector{0, 1, 0}, array1), - std::tuple&, std::vector&>(std::vector{3, 4, 3}, array2), - std::tuple&, std::vector&>(std::vector{6, 7, 6}, array3)); - - CORRADE_COMPARE(result, (std::vector{0, 1, 0})); - CORRADE_COMPARE(array1, (std::vector{0, 1})); - CORRADE_COMPARE(array2, (std::vector{3, 4})); - CORRADE_COMPARE(array3, (std::vector{6, 7})); + std::vector array1{ 0, 1 }; + std::vector array2{ 0, 1, 2, 3, 4 }; + std::vector array3{ 0, 1, 2, 3, 4, 5, 6, 7 }; + + std::vector result = MeshTools::combineIndexedArrays( + std::tuple&, std::vector&>(std::vector{0, 1, 0}, array1), + std::tuple&, std::vector&>(std::vector{3, 4, 3}, array2), + std::tuple&, std::vector&>(std::vector{6, 7, 6}, array3)); + + CORRADE_COMPARE(result, (std::vector{0, 1, 0})); + CORRADE_COMPARE(array1, (std::vector{0, 1})); + CORRADE_COMPARE(array2, (std::vector{3, 4})); + CORRADE_COMPARE(array3, (std::vector{6, 7})); } }}} diff --git a/src/MeshTools/Test/CompressIndicesTest.cpp b/src/MeshTools/Test/CompressIndicesTest.cpp index da0459b2c..417f7dda2 100644 --- a/src/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/MeshTools/Test/CompressIndicesTest.cpp @@ -42,7 +42,7 @@ void CompressIndicesTest::compressChar() { Mesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices( - std::vector{1, 2, 3, 0, 4}); + std::vector{1, 2, 3, 0, 4}); CORRADE_COMPARE(indexCount, 5); CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedByte); @@ -57,7 +57,7 @@ void CompressIndicesTest::compressShort() { Mesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices( - std::vector{1, 256, 0, 5}); + std::vector{1, 256, 0, 5}); CORRADE_COMPARE(indexCount, 4); CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedShort); @@ -83,7 +83,7 @@ void CompressIndicesTest::compressInt() { Mesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices( - std::vector{65536, 3, 2}); + std::vector{65536, 3, 2}); CORRADE_COMPARE(indexCount, 3); CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedInt); diff --git a/src/MeshTools/Test/FlipNormalsTest.cpp b/src/MeshTools/Test/FlipNormalsTest.cpp index 6fc61d1ca..a38a832e7 100644 --- a/src/MeshTools/Test/FlipNormalsTest.cpp +++ b/src/MeshTools/Test/FlipNormalsTest.cpp @@ -40,18 +40,18 @@ void FlipNormalsTest::wrongIndexCount() { std::stringstream ss; Error::setOutput(&ss); - std::vector indices{0, 1}; + std::vector indices{0, 1}; MeshTools::flipFaceWinding(indices); CORRADE_COMPARE(ss.str(), "MeshTools::flipNormals(): index count is not divisible by 3!\n"); } void FlipNormalsTest::flipFaceWinding() { - std::vector indices{0, 1, 2, + std::vector indices{0, 1, 2, 3, 4, 5}; MeshTools::flipFaceWinding(indices); - CORRADE_COMPARE(indices, (std::vector{0, 2, 1, + CORRADE_COMPARE(indices, (std::vector{0, 2, 1, 3, 5, 4})); } diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp index 25a867e82..f476452a1 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp @@ -37,7 +37,7 @@ GenerateFlatNormalsTest::GenerateFlatNormalsTest() { void GenerateFlatNormalsTest::wrongIndexCount() { std::stringstream ss; Error::setOutput(&ss); - std::vector indices; + std::vector indices; std::vector normals; std::tie(indices, normals) = MeshTools::generateFlatNormals({ 0, 1 @@ -50,7 +50,7 @@ void GenerateFlatNormalsTest::wrongIndexCount() { void GenerateFlatNormalsTest::generate() { /* Two vertices connected by one edge, each winded in another direction */ - std::vector indices; + std::vector indices; std::vector normals; std::tie(indices, normals) = MeshTools::generateFlatNormals({ 0, 1, 2, @@ -62,7 +62,7 @@ void GenerateFlatNormalsTest::generate() { {1.0f, 0.0f, 0.0f} }); - CORRADE_COMPARE(indices, (std::vector{ + CORRADE_COMPARE(indices, (std::vector{ 0, 0, 0, 1, 1, 1 })); diff --git a/src/MeshTools/Test/InterleaveTest.cpp b/src/MeshTools/Test/InterleaveTest.cpp index 6939fb96a..fde0b5bd6 100644 --- a/src/MeshTools/Test/InterleaveTest.cpp +++ b/src/MeshTools/Test/InterleaveTest.cpp @@ -48,30 +48,30 @@ InterleaveTest::InterleaveTest() { void InterleaveTest::attributeCount() { std::stringstream ss; Error::setOutput(&ss); - CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, - std::vector{0, 1, 2, 3, 4, 5})), std::size_t(0)); + CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, + std::vector{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((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, - std::vector{3, 4, 5})), std::size_t(3)); + CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, + std::vector{3, 4, 5})), std::size_t(3)); } void InterleaveTest::attributeCountGaps() { - CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, 3, - std::vector{3, 4, 5}, 5)), std::size_t(3)); + CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, 3, + std::vector{3, 4, 5}, 5)), std::size_t(3)); /* No arrays from which to get size */ CORRADE_COMPARE(Implementation::Interleave::attributeCount(3, 5), ~std::size_t(0)); } void InterleaveTest::stride() { - CORRADE_COMPARE(Implementation::Interleave::stride(std::vector()), std::size_t(1)); - CORRADE_COMPARE(Implementation::Interleave::stride(std::vector()), std::size_t(4)); - CORRADE_COMPARE((Implementation::Interleave::stride(std::vector(), std::vector())), std::size_t(5)); + CORRADE_COMPARE(Implementation::Interleave::stride(std::vector()), std::size_t(1)); + CORRADE_COMPARE(Implementation::Interleave::stride(std::vector()), std::size_t(4)); + CORRADE_COMPARE((Implementation::Interleave::stride(std::vector(), std::vector())), std::size_t(5)); } void InterleaveTest::strideGaps() { - CORRADE_COMPARE((Implementation::Interleave::stride(2, std::vector(), 1, std::vector(), 12)), std::size_t(20)); + CORRADE_COMPARE((Implementation::Interleave::stride(2, std::vector(), 1, std::vector(), 12)), std::size_t(20)); } void InterleaveTest::write() { @@ -79,9 +79,9 @@ void InterleaveTest::write() { std::size_t stride; char* data; std::tie(attributeCount, stride, data) = MeshTools::interleave( - std::vector{0, 1, 2}, - std::vector{3, 4, 5}, - std::vector{6, 7, 8}); + std::vector{0, 1, 2}, + std::vector{3, 4, 5}, + std::vector{6, 7, 8}); CORRADE_COMPARE(attributeCount, std::size_t(3)); CORRADE_COMPARE(stride, std::size_t(7)); @@ -108,9 +108,9 @@ void InterleaveTest::writeGaps() { std::size_t stride; char* data; std::tie(attributeCount, stride, data) = MeshTools::interleave( - std::vector{0, 1, 2}, 3, - std::vector{3, 4, 5}, - std::vector{6, 7, 8}, 2); + std::vector{0, 1, 2}, 3, + std::vector{3, 4, 5}, + std::vector{6, 7, 8}, 2); CORRADE_COMPARE(attributeCount, std::size_t(3)); CORRADE_COMPARE(stride, std::size_t(12)); diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 8409f2a59..bbbab9e79 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -33,7 +33,7 @@ class SubdivideTest: public Corrade::TestSuite::Tester { class Vector1 { public: static const std::size_t Size = 1; - typedef std::int32_t Type; + typedef Int Type; Vector1(): data(0) {} Vector1(Type i): data(i) {} @@ -59,20 +59,20 @@ void SubdivideTest::wrongIndexCount() { Error::setOutput(&ss); std::vector positions; - std::vector indices{0, 1}; + std::vector indices{0, 1}; MeshTools::subdivide(indices, positions, interpolator); CORRADE_COMPARE(ss.str(), "MeshTools::subdivide(): index count is not divisible by 3!\n"); } void SubdivideTest::subdivide() { std::vector positions{0, 2, 6, 8}; - std::vector indices{0, 1, 2, 1, 2, 3}; + std::vector indices{0, 1, 2, 1, 2, 3}; MeshTools::subdivide(indices, positions, interpolator); CORRADE_COMPARE(indices.size(), 24); CORRADE_VERIFY(positions == (std::vector{0, 2, 6, 8, 1, 4, 3, 4, 7, 5})); - CORRADE_COMPARE(indices, (std::vector{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{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); diff --git a/src/MeshTools/Test/TipsifyTest.cpp b/src/MeshTools/Test/TipsifyTest.cpp index a62159947..38177e80e 100644 --- a/src/MeshTools/Test/TipsifyTest.cpp +++ b/src/MeshTools/Test/TipsifyTest.cpp @@ -27,7 +27,7 @@ class TipsifyTest: public Corrade::TestSuite::Tester { void tipsify(); private: - std::vector indices; + std::vector indices; std::size_t vertexCount; }; @@ -75,10 +75,10 @@ TipsifyTest::TipsifyTest(): indices{ } void TipsifyTest::buildAdjacency() { - std::vector liveTriangleCount, neighborOffset, neighbors; + std::vector liveTriangleCount, neighborOffset, neighbors; Implementation::Tipsify(indices, vertexCount).buildAdjacency(liveTriangleCount, neighborOffset, neighbors); - CORRADE_COMPARE(liveTriangleCount, (std::vector{ + CORRADE_COMPARE(liveTriangleCount, (std::vector{ 1, 3, 3, 2, 4, 6, 6, 2, 2, 6, 6, 4, @@ -86,7 +86,7 @@ void TipsifyTest::buildAdjacency() { 1, 1, 1 })); - CORRADE_COMPARE(neighborOffset, (std::vector{ + CORRADE_COMPARE(neighborOffset, (std::vector{ 0, 1, 4, 7, 9, 13, 19, 25, 27, 29, 35, 41, @@ -94,7 +94,7 @@ void TipsifyTest::buildAdjacency() { 54, 55, 56, 57 })); - CORRADE_COMPARE(neighbors, (std::vector{ + CORRADE_COMPARE(neighbors, (std::vector{ 0, 0, 7, 11, 2, 7, 13, @@ -122,7 +122,7 @@ void TipsifyTest::buildAdjacency() { void TipsifyTest::tipsify() { MeshTools::tipsify(indices, vertexCount, 3); - CORRADE_COMPARE(indices, (std::vector{ + CORRADE_COMPARE(indices, (std::vector{ 4, 1, 0, 9, 5, 4, 1, 4, 5, diff --git a/src/MeshTools/Tipsify.cpp b/src/MeshTools/Tipsify.cpp index 803304daf..497f74890 100644 --- a/src/MeshTools/Tipsify.cpp +++ b/src/MeshTools/Tipsify.cpp @@ -22,37 +22,37 @@ namespace Magnum { namespace MeshTools { namespace Implementation { void Tipsify::operator()(std::size_t cacheSize) { /* Neighboring triangles for each vertex, per-vertex live triangle count */ - std::vector liveTriangleCount, neighborPosition, neighbors; + std::vector liveTriangleCount, neighborPosition, neighbors; buildAdjacency(liveTriangleCount, neighborPosition, neighbors); /* Global time, per-vertex caching timestamps, per-triangle emmited flag */ - std::uint32_t time = cacheSize+1; - std::vector timestamp(vertexCount); + UnsignedInt time = cacheSize+1; + std::vector timestamp(vertexCount); std::vector emitted(indices.size()/3); /* Dead-end vertex stack */ - std::stack deadEndStack; + std::stack deadEndStack; /* Output index buffer */ - std::vector outputIndices; + std::vector outputIndices; outputIndices.reserve(indices.size()); /* Starting vertex for fanning, cursor */ - std::uint32_t fanningVertex = 0; - std::uint32_t i = 0; + UnsignedInt fanningVertex = 0; + UnsignedInt i = 0; while(fanningVertex != 0xFFFFFFFFu) { /* Array with candidates for next fanning vertex (in 1-ring around fanning vertex) */ - std::vector candidates; + std::vector candidates; /* 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 */ if(emitted[t]) continue; emitted[t] = true; /* 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); /* Add to dead end stack and candidates array */ @@ -73,15 +73,15 @@ void Tipsify::operator()(std::size_t cacheSize) { fanningVertex = 0xFFFFFFFFu; /* Go through candidates in 1-ring around fanning vertex */ - std::int32_t candidatePriority = -1; - for(std::uint32_t v: candidates) { + Int candidatePriority = -1; + for(UnsignedInt v: candidates) { /* Skip if it doesn't have any live triangles */ if(!liveTriangleCount[v]) continue; /* Get most fresh candidate which will still be in cache even after fanning. Every fanned triangle will generate at most two cache misses, thus 2*liveTriangleCount */ - std::int32_t priority = 0; + Int priority = 0; if(time-timestamp[v]+2*liveTriangleCount[v] <= cacheSize) priority = time-timestamp[v]; if(priority > candidatePriority) { @@ -117,7 +117,7 @@ void Tipsify::operator()(std::size_t cacheSize) { std::swap(indices, outputIndices); } -void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const { +void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const { /* How many times is each vertex referenced == count of neighboring triangles for each vertex */ liveTriangleCount.clear(); @@ -132,7 +132,7 @@ void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std: neighborOffset.clear(); neighborOffset.reserve(vertexCount+1); neighborOffset.push_back(0); - std::uint32_t sum = 0; + UnsignedInt sum = 0; for(std::size_t i = 0; i != vertexCount; ++i) { neighborOffset.push_back(sum); sum += liveTriangleCount[i]; diff --git a/src/MeshTools/Tipsify.h b/src/MeshTools/Tipsify.h index 69d65082e..30ef00526 100644 --- a/src/MeshTools/Tipsify.h +++ b/src/MeshTools/Tipsify.h @@ -19,9 +19,9 @@ * @brief Function Magnum::MeshTools::tipsify() */ -#include #include +#include "Types.h" #include "magnumMeshToolsVisibility.h" namespace Magnum { namespace MeshTools { @@ -31,7 +31,7 @@ namespace Implementation { class MAGNUM_MESHTOOLS_EXPORT Tipsify { public: - inline Tipsify(std::vector& indices, std::uint32_t vertexCount): indices(indices), vertexCount(vertexCount) {} + inline Tipsify(std::vector& indices, UnsignedInt vertexCount): indices(indices), vertexCount(vertexCount) {} void operator()(std::size_t cacheSize); @@ -42,11 +42,11 @@ class MAGNUM_MESHTOOLS_EXPORT Tipsify { * (used internally). * @todo Export only for unit test, hide otherwise */ - void buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const; + void buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const; private: - std::vector& indices; - const std::uint32_t vertexCount; + std::vector& indices; + 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, http://gfx.cs.princeton.edu/pubs/Sander_2007_%3ETR/index.php*. */ -inline void tipsify(std::vector& indices, std::uint32_t vertexCount, std::size_t cacheSize) { +inline void tipsify(std::vector& indices, UnsignedInt vertexCount, std::size_t cacheSize) { Implementation::Tipsify(indices, vertexCount)(cacheSize); }