diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index fdd5c552f..26583743c 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -33,7 +33,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 = TypeTraits::epsilon()) { if(indices.empty()) return; @@ -108,12 +108,12 @@ template class Clean { }; struct HashedVertex { - unsigned int oldIndex, newIndex; + std::uint32_t oldIndex, newIndex; - HashedVertex(unsigned int oldIndex, unsigned int newIndex): oldIndex(oldIndex), newIndex(newIndex) {} + HashedVertex(std::uint32_t oldIndex, std::uint32_t newIndex): oldIndex(oldIndex), newIndex(newIndex) {} }; - std::vector& indices; + std::vector& indices; std::vector& vertices; }; @@ -137,7 +137,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 = TypeTraits::epsilon()) { +template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = TypeTraits::epsilon()) { Implementation::Clean(indices, vertices)(epsilon); } diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index 39110a722..a5d229614 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)) @@ -127,7 +127,7 @@ attributes indexed with `indices`. 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 213760226..fc028355b 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -46,7 +46,7 @@ void CompressIndices::operator()(IndexedMesh* mesh, Buffer::Usage usage) const { delete[] data; } -template std::tuple CompressIndices::Compressor::run(const std::vector& indices) { +template std::tuple CompressIndices::Compressor::run(const std::vector& indices) { /* Create smallest possible version of index buffer */ char* buffer = new char[indices.size()*sizeof(IndexType)]; for(size_t i = 0; i != indices.size(); ++i) { diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index c4ea6c0c0..d86dc154c 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -37,7 +37,7 @@ namespace Implementation { class MESHTOOLS_EXPORT CompressIndices { public: - CompressIndices(const std::vector& indices): indices(indices) {} + CompressIndices(const std::vector& indices): indices(indices) {} std::tuple operator()() const; @@ -45,10 +45,10 @@ class MESHTOOLS_EXPORT CompressIndices { private: struct Compressor { - template static std::tuple run(const std::vector& indices); + template static std::tuple run(const std::vector& indices); }; - const std::vector& indices; + const std::vector& indices; }; } @@ -62,9 +62,9 @@ class MESHTOOLS_EXPORT CompressIndices { This function takes index array and outputs them compressed to smallest possible size. For example when your indices have maximum number 463, it's -wasteful to store them in array of `unsigned int`s, array of `unsigned short`s -is sufficient. Size of the buffer can be computed from index count and type, -as shown below. Example usage: +wasteful to store them in array of 32bit integers, array of 16bit integers is +sufficient. Size of the buffer can be computed from index count and type, as +shown below. Example usage: @code std::size_t indexCount; Type indexType; @@ -75,10 +75,10 @@ std::size_t dataSize = indexCount*TypeInfo::sizeOf(indexType); delete[] data; @endcode -See also compressIndices(IndexedMesh*, Buffer::Usage, const std::vector&), +See also compressIndices(IndexedMesh*, Buffer::Usage, const std::vector&), which writes the compressed data directly into index buffer of given mesh. */ -inline std::tuple compressIndices(const std::vector& indices) { +inline std::tuple compressIndices(const std::vector& indices) { return Implementation::CompressIndices{indices}(); } @@ -88,14 +88,14 @@ inline std::tuple compressIndices(const std::vector&), but this +The same as compressIndices(const std::vector&), but this function writes the output to mesh's index buffer and updates index count and type in the mesh accordingly, so you don't have to call Mesh::setIndexCount() and Mesh::setIndexType() on your own. @see MeshTools::interleave() */ -inline void compressIndices(IndexedMesh* mesh, Buffer::Usage usage, const std::vector& indices) { +inline void compressIndices(IndexedMesh* mesh, Buffer::Usage usage, const std::vector& indices) { return Implementation::CompressIndices{indices}(mesh, usage); } diff --git a/src/MeshTools/FlipNormals.cpp b/src/MeshTools/FlipNormals.cpp index ddfe16dd0..859f90306 100644 --- a/src/MeshTools/FlipNormals.cpp +++ b/src/MeshTools/FlipNormals.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace MeshTools { -void flipFaceWinding(vector& indices) { +void flipFaceWinding(vector& indices) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::flipNormals(): index count is not divisible by 3!", ); for(size_t i = 0; i != indices.size(); i += 3) diff --git a/src/MeshTools/FlipNormals.h b/src/MeshTools/FlipNormals.h index 673b43a32..c113e908d 100644 --- a/src/MeshTools/FlipNormals.h +++ b/src/MeshTools/FlipNormals.h @@ -19,6 +19,7 @@ * @brief Function Magnum::MeshTools::flipNormals() */ +#include #include #include "Magnum.h" @@ -30,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 MESHTOOLS_EXPORT flipFaceWinding(std::vector& indices); +void 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 MESHTOOLS_EXPORT flipNormals(std::vector& normals); @@ -55,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 5d4868a3b..b223eefb1 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -22,11 +22,11 @@ using namespace std; namespace Magnum { namespace MeshTools { -tuple, vector> generateFlatNormals(const vector& indices, const vector& positions) { - CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (tuple, vector>())); +tuple, vector> generateFlatNormals(const vector& indices, const vector& positions) { + CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (tuple, vector>())); /* Create normal for every triangle (assuming counterclockwise winding) */ - vector normalIndices; + vector normalIndices; normalIndices.reserve(indices.size()); vector normals; normals.reserve(indices.size()/3); diff --git a/src/MeshTools/GenerateFlatNormals.h b/src/MeshTools/GenerateFlatNormals.h index bdbcca05a..2e23dfa5e 100644 --- a/src/MeshTools/GenerateFlatNormals.h +++ b/src/MeshTools/GenerateFlatNormals.h @@ -19,6 +19,7 @@ * @brief Function Magnum::MeshTools::generateFlatNormals() */ +#include #include #include @@ -37,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 @@ -50,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> MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); +std::tuple, std::vector> MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); }} diff --git a/src/MeshTools/Subdivide.h b/src/MeshTools/Subdivide.h index 690362362..8993bb4da 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 */ - unsigned int newVertices[3]; + std::uint32_t 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; - unsigned int addVertex(const Vertex& v) { + std::uint32_t addVertex(const Vertex& v) { vertices.push_back(v); return vertices.size()-1; } - void addFace(unsigned int first, unsigned int second, unsigned int third) { + void addFace(std::uint32_t first, std::uint32_t second, std::uint32_t 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 55f8b1bfc..a180be5f3 100644 --- a/src/MeshTools/Test/CleanTest.cpp +++ b/src/MeshTools/Test/CleanTest.cpp @@ -29,12 +29,12 @@ CleanTest::CleanTest() { void CleanTest::cleanMesh() { vector positions{1, 2, 1, 4}; - vector indices{0, 1, 2, 1, 2, 3}; + vector indices{0, 1, 2, 1, 2, 3}; MeshTools::clean(indices, positions); /* Verify cleanup */ CORRADE_VERIFY(positions == (vector{1, 2, 4})); - CORRADE_COMPARE(indices, (vector{0, 1, 0, 1, 0, 2})); + CORRADE_COMPARE(indices, (vector{0, 1, 0, 1, 0, 2})); } }}} diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.cpp b/src/MeshTools/Test/CombineIndexedArraysTest.cpp index 9cbdcc542..57211078b 100644 --- a/src/MeshTools/Test/CombineIndexedArraysTest.cpp +++ b/src/MeshTools/Test/CombineIndexedArraysTest.cpp @@ -33,29 +33,29 @@ CombineIndexedArraysTest::CombineIndexedArraysTest() { void CombineIndexedArraysTest::wrongIndexCount() { stringstream ss; Error::setOutput(&ss); - vector array; - vector result = MeshTools::combineIndexedArrays( - tuple&, vector&>(vector{0, 1, 0}, array), - tuple&, vector&>(vector{3, 4}, array)); + vector array; + vector result = MeshTools::combineIndexedArrays( + tuple&, vector&>(vector{0, 1, 0}, array), + tuple&, vector&>(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() { - vector array1{ 0, 1 }; - vector array2{ 0, 1, 2, 3, 4 }; - vector array3{ 0, 1, 2, 3, 4, 5, 6, 7 }; - - vector result = MeshTools::combineIndexedArrays( - tuple&, vector&>(vector{0, 1, 0}, array1), - tuple&, vector&>(vector{3, 4, 3}, array2), - tuple&, vector&>(vector{6, 7, 6}, array3)); - - CORRADE_COMPARE(result, (vector{0, 1, 0})); - CORRADE_COMPARE(array1, (vector{0, 1})); - CORRADE_COMPARE(array2, (vector{3, 4})); - CORRADE_COMPARE(array3, (vector{6, 7})); + vector array1{ 0, 1 }; + vector array2{ 0, 1, 2, 3, 4 }; + vector array3{ 0, 1, 2, 3, 4, 5, 6, 7 }; + + vector result = MeshTools::combineIndexedArrays( + tuple&, vector&>(vector{0, 1, 0}, array1), + tuple&, vector&>(vector{3, 4, 3}, array2), + tuple&, vector&>(vector{6, 7, 6}, array3)); + + CORRADE_COMPARE(result, (vector{0, 1, 0})); + CORRADE_COMPARE(array1, (vector{0, 1})); + CORRADE_COMPARE(array2, (vector{3, 4})); + CORRADE_COMPARE(array3, (vector{6, 7})); } }}} diff --git a/src/MeshTools/Test/CompressIndicesTest.cpp b/src/MeshTools/Test/CompressIndicesTest.cpp index 905918f1c..f50b7ce49 100644 --- a/src/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/MeshTools/Test/CompressIndicesTest.cpp @@ -37,7 +37,7 @@ void CompressIndicesTest::compressChar() { Type indexType; char* data; tie(indexCount, indexType, data) = MeshTools::compressIndices( - vector{1, 2, 3, 0, 4}); + vector{1, 2, 3, 0, 4}); CORRADE_COMPARE(indexCount, 5); CORRADE_VERIFY(indexType == Type::UnsignedByte); @@ -52,7 +52,7 @@ void CompressIndicesTest::compressShort() { Type indexType; char* data; tie(indexCount, indexType, data) = MeshTools::compressIndices( - vector{1, 256, 0, 5}); + vector{1, 256, 0, 5}); CORRADE_COMPARE(indexCount, 4); CORRADE_VERIFY(indexType == Type::UnsignedShort); @@ -78,7 +78,7 @@ void CompressIndicesTest::compressInt() { Type indexType; char* data; tie(indexCount, indexType, data) = MeshTools::compressIndices( - vector{65536, 3, 2}); + vector{65536, 3, 2}); CORRADE_COMPARE(indexCount, 3); CORRADE_VERIFY(indexType == Type::UnsignedInt); diff --git a/src/MeshTools/Test/FlipNormalsTest.cpp b/src/MeshTools/Test/FlipNormalsTest.cpp index 59f3a757d..b900f39d5 100644 --- a/src/MeshTools/Test/FlipNormalsTest.cpp +++ b/src/MeshTools/Test/FlipNormalsTest.cpp @@ -36,19 +36,19 @@ void FlipNormalsTest::wrongIndexCount() { stringstream ss; Error::setOutput(&ss); - vector indices{0, 1}; + vector indices{0, 1}; MeshTools::flipFaceWinding(indices); CORRADE_COMPARE(ss.str(), "MeshTools::flipNormals(): index count is not divisible by 3!\n"); } void FlipNormalsTest::flipFaceWinding() { - vector indices{0, 1, 2, + vector indices{0, 1, 2, 3, 4, 5}; MeshTools::flipFaceWinding(indices); - CORRADE_COMPARE(indices, (vector{0, 2, 1, - 3, 5, 4})); + CORRADE_COMPARE(indices, (vector{0, 2, 1, + 3, 5, 4})); } void FlipNormalsTest::flipNormals() { diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp index 1de255976..8cd88d313 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp @@ -34,7 +34,7 @@ GenerateFlatNormalsTest::GenerateFlatNormalsTest() { void GenerateFlatNormalsTest::wrongIndexCount() { stringstream ss; Error::setOutput(&ss); - vector indices; + vector indices; vector normals; tie(indices, normals) = MeshTools::generateFlatNormals({ 0, 1 @@ -47,7 +47,7 @@ void GenerateFlatNormalsTest::wrongIndexCount() { void GenerateFlatNormalsTest::generate() { /* Two vertices connected by one edge, each winded in another direction */ - vector indices; + vector indices; vector normals; tie(indices, normals) = MeshTools::generateFlatNormals({ 0, 1, 2, @@ -59,7 +59,7 @@ void GenerateFlatNormalsTest::generate() { {1.0f, 0.0f, 0.0f} }); - CORRADE_COMPARE(indices, (vector{ + CORRADE_COMPARE(indices, (vector{ 0, 0, 0, 1, 1, 1 })); diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 2e7153ef9..965c3ad36 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -36,20 +36,20 @@ void SubdivideTest::wrongIndexCount() { Error::setOutput(&ss); vector positions; - vector indices{0, 1}; + 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() { vector positions{0, 2, 6, 8}; - vector indices{0, 1, 2, 1, 2, 3}; + vector indices{0, 1, 2, 1, 2, 3}; MeshTools::subdivide(indices, positions, interpolator); CORRADE_COMPARE(indices.size(), 24); CORRADE_VERIFY(positions == (vector{0, 2, 6, 8, 1, 4, 3, 4, 7, 5})); - CORRADE_COMPARE(indices, (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, (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 a44a26507..67bcd4212 100644 --- a/src/MeshTools/Test/TipsifyTest.cpp +++ b/src/MeshTools/Test/TipsifyTest.cpp @@ -114,7 +114,7 @@ void TipsifyTest::buildAdjacency() { void TipsifyTest::tipsify() { MeshTools::tipsify(indices, vertexCount, 3); - CORRADE_COMPARE(indices, (vector{ + CORRADE_COMPARE(indices, (vector{ 4, 1, 0, 9, 5, 4, 1, 4, 5, diff --git a/src/MeshTools/Test/TipsifyTest.h b/src/MeshTools/Test/TipsifyTest.h index 12928f852..37ca6d4fb 100644 --- a/src/MeshTools/Test/TipsifyTest.h +++ b/src/MeshTools/Test/TipsifyTest.h @@ -27,7 +27,7 @@ class TipsifyTest: public Corrade::TestSuite::Tester { void tipsify(); private: - std::vector indices; + std::vector indices; std::size_t vertexCount; }; diff --git a/src/MeshTools/Tipsify.cpp b/src/MeshTools/Tipsify.cpp index 5f19c1f92..7b5b6c00b 100644 --- a/src/MeshTools/Tipsify.cpp +++ b/src/MeshTools/Tipsify.cpp @@ -17,42 +17,44 @@ #include +using namespace std; + #ifndef DOXYGEN_GENERATING_OUTPUT namespace Magnum { namespace MeshTools { namespace Implementation { void Tipsify::operator()(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 */ - unsigned int time = cacheSize+1; - std::vector timestamp(vertexCount); + uint32_t 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 */ - unsigned int fanningVertex = 0; - unsigned int i = 0; + uint32_t fanningVertex = 0; + uint32_t 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(unsigned int ti = neighborPosition[fanningVertex], t = neighbors[ti]; ti != neighborPosition[fanningVertex+1]; t = neighbors[++ti]) { + for(uint32_t 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(unsigned int vi = 0, v = indices[t*3]; vi != 3; v = indices[++vi+t*3]) { + for(uint32_t 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 +75,15 @@ void Tipsify::operator()(size_t cacheSize) { fanningVertex = 0xFFFFFFFFu; /* Go through candidates in 1-ring around fanning vertex */ - int candidatePriority = -1; - for(unsigned int v: candidates) { + int32_t candidatePriority = -1; + for(uint32_t 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 */ - int priority = 0; + int32_t priority = 0; if(time-timestamp[v]+2*liveTriangleCount[v] <= cacheSize) priority = time-timestamp[v]; if(priority > candidatePriority) { @@ -117,12 +119,12 @@ void Tipsify::operator()(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(); liveTriangleCount.resize(vertexCount); - for(unsigned int i = 0; i != indices.size(); ++i) + for(size_t i = 0; i != indices.size(); ++i) ++liveTriangleCount[indices[i]]; /* Building offset array from counts. Neighbors for i-th vertex will at @@ -132,8 +134,8 @@ void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std:: neighborOffset.clear(); neighborOffset.reserve(vertexCount+1); neighborOffset.push_back(0); - unsigned int sum = 0; - for(unsigned int i = 0; i != vertexCount; ++i) { + uint32_t sum = 0; + for(size_t i = 0; i != vertexCount; ++i) { neighborOffset.push_back(sum); sum += liveTriangleCount[i]; } @@ -142,7 +144,7 @@ void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std:: positioning */ neighbors.clear(); neighbors.resize(sum); - for(unsigned int i = 0; i != indices.size(); ++i) + for(size_t i = 0; i != indices.size(); ++i) neighbors[neighborOffset[indices[i]+1]++] = i/3; } diff --git a/src/MeshTools/Tipsify.h b/src/MeshTools/Tipsify.h index 39b3ed092..0d0a28ff8 100644 --- a/src/MeshTools/Tipsify.h +++ b/src/MeshTools/Tipsify.h @@ -19,7 +19,7 @@ * @brief Function Magnum::MeshTools::tipsify() */ -#include +#include #include #include "magnumMeshToolsVisibility.h" @@ -31,7 +31,7 @@ namespace Implementation { class MESHTOOLS_EXPORT Tipsify { public: - inline Tipsify(std::vector& indices, unsigned int vertexCount): indices(indices), vertexCount(vertexCount) {} + inline Tipsify(std::vector& indices, std::uint32_t vertexCount): indices(indices), vertexCount(vertexCount) {} void operator()(std::size_t cacheSize); @@ -41,11 +41,11 @@ class MESHTOOLS_EXPORT Tipsify { * Computes count and indices of adjacent triangles for each vertex * (used internally). */ - 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 unsigned int vertexCount; + std::vector& indices; + const std::uint32_t vertexCount; }; } @@ -63,7 +63,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, unsigned int vertexCount, std::size_t cacheSize) { +inline void tipsify(std::vector& indices, std::uint32_t vertexCount, std::size_t cacheSize) { Implementation::Tipsify(indices, vertexCount)(cacheSize); } diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index d339f04f5..fb89c75f1 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -22,7 +22,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { +Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", ); GLfloat height = 2.0f+length; @@ -50,7 +50,7 @@ Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsig topFaceRing(); } -Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} +Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); @@ -128,11 +128,11 @@ void Capsule::faceRings(unsigned int count, unsigned int offset) { for(unsigned int i = 0; i != count; ++i) { for(unsigned int j = 0; j != segments; ++j) { - unsigned int bottomLeft = i*vertexSegments+j+offset; - unsigned int bottomRight = ((j != segments-1 || textureCoords == TextureCoords::Generate) ? + uint32_t bottomLeft = i*vertexSegments+j+offset; + uint32_t bottomRight = ((j != segments-1 || textureCoords == TextureCoords::Generate) ? i*vertexSegments+j+1+offset : i*segments+offset); - unsigned int topLeft = bottomLeft+vertexSegments; - unsigned int topRight = bottomRight+vertexSegments; + uint32_t topLeft = bottomLeft+vertexSegments; + uint32_t topRight = bottomRight+vertexSegments; indices()->push_back(bottomLeft); indices()->push_back(bottomRight); diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index 48b99c491..ed6d47217 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ +Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ 0, 2, 1, 2, 3, 1, 1, 3, 5, diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index f2ee23068..379365e18 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Icosphere<0>::Icosphere(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ +Icosphere<0>::Icosphere(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ 1, 2, 6, 1, 7, 2, 3, 4, 5, diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index 7d95515c3..1f6fb6183 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -90,7 +90,7 @@ void CapsuleTest::withoutTextureCoords() { {0.0f, 1.0f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*capsule.indices(), (vector{ + CORRADE_COMPARE_AS(*capsule.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 8, 4, 8, 7, 5, 6, 9, 5, 9, 8, 6, 4, 7, 6, 7, 9, @@ -165,7 +165,7 @@ void CapsuleTest::withTextureCoords() { {0.5f, 1.0f} }), Container); - CORRADE_COMPARE_AS(*capsule.indices(), (vector{ + CORRADE_COMPARE_AS(*capsule.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, 12, 11, diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp index cb94fa6d7..f7f919cae 100644 --- a/src/Primitives/Test/CylinderTest.cpp +++ b/src/Primitives/Test/CylinderTest.cpp @@ -63,7 +63,7 @@ void CylinderTest::withoutAnything() { {-0.866025f, 0.0f, -0.5f} }), Container); - CORRADE_COMPARE_AS(*cylinder.indices(), (vector{ + CORRADE_COMPARE_AS(*cylinder.indices(), (vector{ 0, 1, 4, 0, 4, 3, 1, 2, 5, 1, 5, 4, 2, 0, 3, 2, 3, 5, 3, 4, 7, 3, 7, 6, 4, 5, 8, 4, 8, 7, 5, 3, 6, 5, 6, 8 }), Container); @@ -165,7 +165,7 @@ void CylinderTest::withTextureCoordsAndCaps() { {0.5f, 1.0f} }), Container); - CORRADE_COMPARE_AS(*cylinder.indices(), (vector{ + CORRADE_COMPARE_AS(*cylinder.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index cff3f77b9..1599eeb0d 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -63,7 +63,7 @@ void UVSphereTest::withoutTextureCoords() { {0.0f, 1.0f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*sphere.indices(), (vector{ + CORRADE_COMPARE_AS(*sphere.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 7, 5, 6, 7, 6, 4, 7 @@ -105,7 +105,7 @@ void UVSphereTest::withTextureCoords() { {0.5f, 1.0f} }), Container); - CORRADE_COMPARE_AS(*sphere.indices(), (vector{ + CORRADE_COMPARE_AS(*sphere.indices(), (vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 9, 6, 7, 9, 7, 8, 9 diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h index cc650a213..6a594fd7c 100644 --- a/src/Trade/MeshData2D.h +++ b/src/Trade/MeshData2D.h @@ -51,7 +51,7 @@ class MAGNUM_EXPORT MeshData2D { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData2D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} + inline MeshData2D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} /** @brief Destructor */ ~MeshData2D(); @@ -66,8 +66,8 @@ class MAGNUM_EXPORT MeshData2D { * @brief Indices * @return Indices or nullptr if the mesh is not indexed. */ - inline std::vector* indices() { return _indices; } - inline const std::vector* indices() const { return _indices; } /**< @overload */ + inline std::vector* indices() { return _indices; } + inline const std::vector* indices() const { return _indices; } /**< @overload */ /** @brief Count of vertex position arrays */ inline unsigned int positionArrayCount() const { return _positions.size(); } @@ -96,7 +96,7 @@ class MAGNUM_EXPORT MeshData2D { private: std::string _name; Mesh::Primitive _primitive; - std::vector* _indices; + std::vector* _indices; std::vector*> _positions; std::vector*> _textureCoords2D; }; diff --git a/src/Trade/MeshData3D.h b/src/Trade/MeshData3D.h index 159a6ebcf..fcfb08107 100644 --- a/src/Trade/MeshData3D.h +++ b/src/Trade/MeshData3D.h @@ -52,7 +52,7 @@ class MAGNUM_EXPORT MeshData3D { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData3D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} + inline MeshData3D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} /** @brief Destructor */ ~MeshData3D(); @@ -67,8 +67,8 @@ class MAGNUM_EXPORT MeshData3D { * @brief Indices * @return Indices or nullptr if the mesh is not indexed. */ - inline std::vector* indices() { return _indices; } - inline const std::vector* indices() const { return _indices; } /**< @overload */ + inline std::vector* indices() { return _indices; } + inline const std::vector* indices() const { return _indices; } /**< @overload */ /** @brief Count of vertex position arrays */ inline unsigned int positionArrayCount() const { return _positions.size(); } @@ -109,7 +109,7 @@ class MAGNUM_EXPORT MeshData3D { private: std::string _name; Mesh::Primitive _primitive; - std::vector* _indices; + std::vector* _indices; std::vector*> _positions; std::vector*> _normals; std::vector*> _textureCoords2D;