diff --git a/src/Magnum/MeshTools/GenerateIndices.cpp b/src/Magnum/MeshTools/GenerateIndices.cpp index d6d61323a..00b7f98f3 100644 --- a/src/Magnum/MeshTools/GenerateIndices.cpp +++ b/src/Magnum/MeshTools/GenerateIndices.cpp @@ -83,13 +83,13 @@ UnsignedInt primitiveCount(const MeshPrimitive primitive, const UnsignedInt elem CORRADE_ASSERT_UNREACHABLE("MeshTools::primitiveCount(): invalid primitive" << primitive, {}); } -void generateLineStripIndicesInto(const UnsignedInt vertexCount, const Containers::StridedArrayView1D& indices) { +void generateLineStripIndicesInto(const UnsignedInt vertexCount, const Containers::StridedArrayView1D& output) { CORRADE_ASSERT(vertexCount == 0 || vertexCount >= 2, "MeshTools::generateLineStripIndicesInto(): expected either zero or at least two vertices, got" << vertexCount, ); const UnsignedInt iMax = Math::max(vertexCount, 1u) - 1; - CORRADE_ASSERT(indices.size() == 2*iMax, - "MeshTools::generateLineStripIndicesInto(): bad output size, expected" << 2*iMax << "but got" << indices.size(), ); + CORRADE_ASSERT(output.size() == 2*iMax, + "MeshTools::generateLineStripIndicesInto(): bad output size, expected" << 2*iMax << "but got" << output.size(), ); /* 1 --- 2 1 2 --- 3 4 @@ -99,22 +99,22 @@ void generateLineStripIndicesInto(const UnsignedInt vertexCount, const Container 0 3 0 5 */ for(std::size_t i = 0; i != iMax; ++i) { - indices[i*2 + 0] = i; - indices[i*2 + 1] = i + 1; + output[i*2 + 0] = i; + output[i*2 + 1] = i + 1; } } Containers::Array generateLineStripIndices(const UnsignedInt vertexCount) { - Containers::Array indices{NoInit, 2*(Math::max(vertexCount, 1u) - 1)}; - generateLineStripIndicesInto(vertexCount, indices); - return indices; + Containers::Array output{NoInit, 2*(Math::max(vertexCount, 1u) - 1)}; + generateLineStripIndicesInto(vertexCount, output); + return output; } -void generateLineLoopIndicesInto(const UnsignedInt vertexCount, const Containers::StridedArrayView1D& indices) { +void generateLineLoopIndicesInto(const UnsignedInt vertexCount, const Containers::StridedArrayView1D& output) { CORRADE_ASSERT(vertexCount == 0 || vertexCount >= 2, "MeshTools::generateLineLoopIndicesInto(): expected either zero or at least two vertices, got" << vertexCount, ); - CORRADE_ASSERT(indices.size() == 2*vertexCount, - "MeshTools::generateLineLoopIndicesInto(): bad output size, expected" << 2*vertexCount << "but got" << indices.size(), ); + CORRADE_ASSERT(output.size() == 2*vertexCount, + "MeshTools::generateLineLoopIndicesInto(): bad output size, expected" << 2*vertexCount << "but got" << output.size(), ); /* Same as with line strip, with one additional line segment at the end. @@ -126,28 +126,28 @@ void generateLineLoopIndicesInto(const UnsignedInt vertexCount, const Containers 0 ----------- 3 0 7 ----------- 6 5 */ for(std::size_t i = 0, iMax = Math::max(vertexCount, 1u) - 1; i != iMax; ++i) { - indices[i*2 + 0] = i; - indices[i*2 + 1] = i + 1; + output[i*2 + 0] = i; + output[i*2 + 1] = i + 1; } if(vertexCount >= 2) { - indices[2*vertexCount - 2] = vertexCount - 1; - indices[2*vertexCount - 1] = 0; + output[2*vertexCount - 2] = vertexCount - 1; + output[2*vertexCount - 1] = 0; } } Containers::Array generateLineLoopIndices(const UnsignedInt vertexCount) { - Containers::Array indices{NoInit, 2*vertexCount}; - generateLineLoopIndicesInto(vertexCount, indices); - return indices; + Containers::Array output{NoInit, 2*vertexCount}; + generateLineLoopIndicesInto(vertexCount, output); + return output; } -void generateTriangleStripIndicesInto(const UnsignedInt vertexCount, const Containers::StridedArrayView1D& indices) { +void generateTriangleStripIndicesInto(const UnsignedInt vertexCount, const Containers::StridedArrayView1D& output) { CORRADE_ASSERT(vertexCount == 0 || vertexCount >= 3, "MeshTools::generateTriangleStripIndicesInto(): expected either zero or at least three vertices, got" << vertexCount, ); const UnsignedInt iMax = Math::max(vertexCount, 2u) - 2; - CORRADE_ASSERT(indices.size() == 3*iMax, - "MeshTools::generateTriangleStripIndicesInto(): bad output size, expected" << 3*iMax << "but got" << indices.size(), ); + CORRADE_ASSERT(output.size() == 3*iMax, + "MeshTools::generateTriangleStripIndicesInto(): bad output size, expected" << 3*iMax << "but got" << output.size(), ); /* Triangles starting with odd vertices (marked with !) have the first two @@ -160,25 +160,25 @@ void generateTriangleStripIndicesInto(const UnsignedInt vertexCount, const Conta 1 ----- 3 ----- 5 1 4 ----- 5 7 10 ---- 11 */ for(std::size_t i = 0; i != iMax; ++i) { - indices[i*3 + 0] = i % 2 ? i + 1 : i; - indices[i*3 + 1] = i % 2 ? i : i + 1; - indices[i*3 + 2] = i + 2; + output[i*3 + 0] = i % 2 ? i + 1 : i; + output[i*3 + 1] = i % 2 ? i : i + 1; + output[i*3 + 2] = i + 2; } } Containers::Array generateTriangleStripIndices(const UnsignedInt vertexCount) { - Containers::Array indices{NoInit, 3*(Math::max(vertexCount, 2u) - 2u)}; - generateTriangleStripIndicesInto(vertexCount, indices); - return indices; + Containers::Array output{NoInit, 3*(Math::max(vertexCount, 2u) - 2u)}; + generateTriangleStripIndicesInto(vertexCount, output); + return output; } -void generateTriangleFanIndicesInto(const UnsignedInt vertexCount, const Containers::StridedArrayView1D& indices) { +void generateTriangleFanIndicesInto(const UnsignedInt vertexCount, const Containers::StridedArrayView1D& output) { CORRADE_ASSERT(vertexCount == 0 || vertexCount >= 3, "MeshTools::generateTriangleFanIndicesInto(): expected either zero or at least three vertices, got" << vertexCount, ); const UnsignedInt iMax = Math::max(vertexCount, 2u) - 2; - CORRADE_ASSERT(indices.size() == 3*iMax, - "MeshTools::generateTriangleFanIndicesInto(): bad output size, expected" << 3*iMax << "but got" << indices.size(), ); + CORRADE_ASSERT(output.size() == 3*iMax, + "MeshTools::generateTriangleFanIndicesInto(): bad output size, expected" << 3*iMax << "but got" << output.size(), ); /* 10 8 ----- 7 5 4 ----- 3 / \ \ / / \ @@ -192,25 +192,25 @@ void generateTriangleFanIndicesInto(const UnsignedInt vertexCount, const Contain 1 1 */ for(std::size_t i = 0; i != iMax; ++i) { - indices[i*3 + 0] = 0; - indices[i*3 + 1] = i + 1; - indices[i*3 + 2] = i + 2; + output[i*3 + 0] = 0; + output[i*3 + 1] = i + 1; + output[i*3 + 2] = i + 2; } } Containers::Array generateTriangleFanIndices(const UnsignedInt vertexCount) { - Containers::Array indices{NoInit, 3*(Math::max(vertexCount, 2u) - 2)}; - generateTriangleFanIndicesInto(vertexCount, indices); - return indices; + Containers::Array output{NoInit, 3*(Math::max(vertexCount, 2u) - 2)}; + generateTriangleFanIndicesInto(vertexCount, output); + return output; } namespace { -template inline void generateQuadIndicesIntoImplementation(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& into) { +template inline void generateQuadIndicesIntoImplementation(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& output) { CORRADE_ASSERT(quads.size() % 4 == 0, "MeshTools::generateQuadIndicesInto(): quad index count" << quads.size() << "not divisible by 4", ); - CORRADE_ASSERT(quads.size()*6/4 == into.size(), - "MeshTools::generateQuadIndicesInto(): bad output size, expected" << quads.size()*6/4 << "but got" << into.size(), ); + CORRADE_ASSERT(quads.size()*6/4 == output.size(), + "MeshTools::generateQuadIndicesInto(): bad output size, expected" << quads.size()*6/4 << "but got" << output.size(), ); for(std::size_t i = 0, max = quads.size()/4; i != max; ++i) { auto get = [&](UnsignedInt j) -> const Vector3& { @@ -243,7 +243,7 @@ template inline void generateQuadIndicesIntoImplementation(const Contai /* Assign the two triangles */ for(std::size_t j = 0; j != 6; ++j) - into[6*i + j] = quads[4*i + split[j]]; + output[6*i + j] = quads[4*i + split[j]]; } } @@ -292,16 +292,16 @@ Containers::Array generateQuadIndices(const Containers::StridedArra return out; } -void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& into) { - return generateQuadIndicesIntoImplementation(positions, quads, into); +void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& output) { + return generateQuadIndicesIntoImplementation(positions, quads, output); } -void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& into) { - return generateQuadIndicesIntoImplementation(positions, quads, into); +void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& output) { + return generateQuadIndicesIntoImplementation(positions, quads, output); } -void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& into) { - return generateQuadIndicesIntoImplementation(positions, quads, into); +void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& output) { + return generateQuadIndicesIntoImplementation(positions, quads, output); } Trade::MeshData generateIndices(Trade::MeshData&& data) { diff --git a/src/Magnum/MeshTools/GenerateIndices.h b/src/Magnum/MeshTools/GenerateIndices.h index 6e8c49436..48b727e0e 100644 --- a/src/Magnum/MeshTools/GenerateIndices.h +++ b/src/Magnum/MeshTools/GenerateIndices.h @@ -68,10 +68,10 @@ MAGNUM_MESHTOOLS_EXPORT Containers::Array generateLineStripIndices( A variant of @ref generateLineStripIndicesInto() that fills existing memory instead of allocating a new array. The @p vertexCount is expected to be either -@cpp 0 @ce or at least @cpp 2 @ce, the @p indices array is expected to have a +@cpp 0 @ce or at least @cpp 2 @ce, the @p output array is expected to have a size of @cpp 2*(vertexCount - 1) @ce. Primitive restart is not supported. */ -MAGNUM_MESHTOOLS_EXPORT void generateLineStripIndicesInto(UnsignedInt vertexCount, const Containers::StridedArrayView1D& indices); +MAGNUM_MESHTOOLS_EXPORT void generateLineStripIndicesInto(UnsignedInt vertexCount, const Containers::StridedArrayView1D& output); /** @brief Create index buffer for a line loop primitive @@ -92,10 +92,10 @@ MAGNUM_MESHTOOLS_EXPORT Containers::Array generateLineLoopIndices(U A variant of @ref generateLineLoopIndicesInto() that fills existing memory instead of allocating a new array. The @p vertexCount is expected to be either -@cpp 0 @ce or at least @cpp 2 @ce, the @p indices array is expected to have a +@cpp 0 @ce or at least @cpp 2 @ce, the @p output array is expected to have a size of @cpp 2*vertexCount @ce. Primitive restart is not supported. */ -MAGNUM_MESHTOOLS_EXPORT void generateLineLoopIndicesInto(UnsignedInt vertexCount, const Containers::StridedArrayView1D& into); +MAGNUM_MESHTOOLS_EXPORT void generateLineLoopIndicesInto(UnsignedInt vertexCount, const Containers::StridedArrayView1D& output); /** @brief Create index buffer for a triangle strip primitive @@ -116,10 +116,10 @@ MAGNUM_MESHTOOLS_EXPORT Containers::Array generateTriangleStripIndi A variant of @ref generateTriangleStripIndicesInto() that fills existing memory instead of allocating a new array. The @p vertexCount is expected to be either -@cpp 0 @ce or at least @cpp 3 @ce, the @p indices array is expected to have a +@cpp 0 @ce or at least @cpp 3 @ce, the @p output array is expected to have a size of @cpp 3*(vertexCount - 2) @ce. Primitive restart is not supported. */ -MAGNUM_MESHTOOLS_EXPORT void generateTriangleStripIndicesInto(UnsignedInt vertexCount, const Containers::StridedArrayView1D& into); +MAGNUM_MESHTOOLS_EXPORT void generateTriangleStripIndicesInto(UnsignedInt vertexCount, const Containers::StridedArrayView1D& output); /** @brief Create index buffer for a triangle fan primitive @@ -140,10 +140,10 @@ MAGNUM_MESHTOOLS_EXPORT Containers::Array generateTriangleFanIndice A variant of @ref generateTriangleFanIndicesInto() that fills existing memory instead of allocating a new array. The @p vertexCount is expected to be either -@cpp 0 @ce or at least @cpp 3 @ce, the @p indices array is expected to have a +@cpp 0 @ce or at least @cpp 3 @ce, the @p output array is expected to have a size of @cpp 3*(vertexCount - 2) @ce. Primitive restart is not supported. */ -MAGNUM_MESHTOOLS_EXPORT void generateTriangleFanIndicesInto(UnsignedInt vertexCount, const Containers::StridedArrayView1D& into); +MAGNUM_MESHTOOLS_EXPORT void generateTriangleFanIndicesInto(UnsignedInt vertexCount, const Containers::StridedArrayView1D& output); /** @brief Create a triangle index buffer for quad primitives @@ -191,22 +191,22 @@ MAGNUM_MESHTOOLS_EXPORT Containers::Array generateQuadIndices(const @m_since_latest A variant of @ref generateQuadIndices() that fills existing memory instead of -allocating a new array. Size of @p quads is expected to be divisible by @cpp 4 @ce -and @p into should have a size that's @cpp quads.size()*6/4 @ce. +allocating a new array. Size of @p quads is expected to be divisible by +@cpp 4 @ce and @p output should have a size that's @cpp quads.size()*6/4 @ce. */ -MAGNUM_MESHTOOLS_EXPORT void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& into); +MAGNUM_MESHTOOLS_EXPORT void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& output); /** * @overload * @m_since_latest */ -MAGNUM_MESHTOOLS_EXPORT void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& into); +MAGNUM_MESHTOOLS_EXPORT void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& output); /** * @overload * @m_since_latest */ -MAGNUM_MESHTOOLS_EXPORT void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& into); +MAGNUM_MESHTOOLS_EXPORT void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& output); /** @brief Convert a mesh to plain indexed lines or triangles diff --git a/src/Magnum/MeshTools/Test/GenerateIndicesTest.cpp b/src/Magnum/MeshTools/Test/GenerateIndicesTest.cpp index ca8087881..074ffa72e 100644 --- a/src/Magnum/MeshTools/Test/GenerateIndicesTest.cpp +++ b/src/Magnum/MeshTools/Test/GenerateIndicesTest.cpp @@ -320,12 +320,12 @@ void GenerateIndicesTest::generateLineStripIndicesWrongVertexCount() { void GenerateIndicesTest::generateLineStripIndicesIntoWrongSize() { CORRADE_SKIP_IF_NO_ASSERT(); - UnsignedInt indices[7]; + UnsignedInt output[7]; std::ostringstream out; Error redirectError{&out}; - MeshTools::generateLineStripIndicesInto(0, indices); - MeshTools::generateLineStripIndicesInto(5, indices); + MeshTools::generateLineStripIndicesInto(0, output); + MeshTools::generateLineStripIndicesInto(5, output); CORRADE_COMPARE(out.str(), "MeshTools::generateLineStripIndicesInto(): bad output size, expected 0 but got 7\n" "MeshTools::generateLineStripIndicesInto(): bad output size, expected 8 but got 7\n"); @@ -379,12 +379,12 @@ void GenerateIndicesTest::generateLineLoopIndicesWrongVertexCount() { void GenerateIndicesTest::generateLineLoopIndicesIntoWrongSize() { CORRADE_SKIP_IF_NO_ASSERT(); - UnsignedInt indices[9]; + UnsignedInt output[9]; std::ostringstream out; Error redirectError{&out}; - MeshTools::generateLineLoopIndicesInto(0, indices); - MeshTools::generateLineLoopIndicesInto(5, indices); + MeshTools::generateLineLoopIndicesInto(0, output); + MeshTools::generateLineLoopIndicesInto(5, output); CORRADE_COMPARE(out.str(), "MeshTools::generateLineLoopIndicesInto(): bad output size, expected 0 but got 9\n" "MeshTools::generateLineLoopIndicesInto(): bad output size, expected 10 but got 9\n"); @@ -437,12 +437,12 @@ void GenerateIndicesTest::generateTriangleStripIndicesWrongVertexCount() { void GenerateIndicesTest::generateTriangleStripIndicesIntoWrongSize() { CORRADE_SKIP_IF_NO_ASSERT(); - UnsignedInt indices[8]; + UnsignedInt output[8]; std::ostringstream out; Error redirectError{&out}; - MeshTools::generateTriangleStripIndicesInto(0, indices); - MeshTools::generateTriangleStripIndicesInto(5, indices); + MeshTools::generateTriangleStripIndicesInto(0, output); + MeshTools::generateTriangleStripIndicesInto(5, output); CORRADE_COMPARE(out.str(), "MeshTools::generateTriangleStripIndicesInto(): bad output size, expected 0 but got 8\n" "MeshTools::generateTriangleStripIndicesInto(): bad output size, expected 9 but got 8\n"); @@ -495,12 +495,12 @@ void GenerateIndicesTest::generateTriangleFanIndicesWrongVertexCount() { void GenerateIndicesTest::generateTriangleFanIndicesIntoWrongSize() { CORRADE_SKIP_IF_NO_ASSERT(); - UnsignedInt indices[8]; + UnsignedInt output[8]; std::ostringstream out; Error redirectError{&out}; - MeshTools::generateTriangleFanIndicesInto(0, indices); - MeshTools::generateTriangleFanIndicesInto(5, indices); + MeshTools::generateTriangleFanIndicesInto(0, output); + MeshTools::generateTriangleFanIndicesInto(5, output); CORRADE_COMPARE(out.str(), "MeshTools::generateTriangleFanIndicesInto(): bad output size, expected 0 but got 8\n" "MeshTools::generateTriangleFanIndicesInto(): bad output size, expected 9 but got 8\n");