From 1c32119058f1ec89ae22ad3c063e16d26ae9f5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 31 May 2013 23:12:09 +0200 Subject: [PATCH] MeshTools: renamed clean() to removeDuplicates(). --- src/MeshTools/CMakeLists.txt | 2 +- src/MeshTools/CombineIndexedArrays.h | 4 ++-- src/MeshTools/GenerateFlatNormals.cpp | 6 ++--- src/MeshTools/{Clean.h => RemoveDuplicates.h} | 21 ++++++++-------- src/MeshTools/Subdivide.h | 2 +- src/MeshTools/Test/CMakeLists.txt | 4 ++-- ...CleanTest.cpp => RemoveDuplicatesTest.cpp} | 16 ++++++------- ...=> SubdivideRemoveDuplicatesBenchmark.cpp} | 24 +++++++++---------- ...h => SubdivideRemoveDuplicatesBenchmark.h} | 10 ++++---- src/MeshTools/Test/SubdivideTest.cpp | 4 ++-- src/Primitives/Icosphere.h | 4 ++-- 11 files changed, 49 insertions(+), 48 deletions(-) rename src/MeshTools/{Clean.h => RemoveDuplicates.h} (87%) rename src/MeshTools/Test/{CleanTest.cpp => RemoveDuplicatesTest.cpp} (81%) rename src/MeshTools/Test/{SubdivideCleanBenchmark.cpp => SubdivideRemoveDuplicatesBenchmark.cpp} (77%) rename src/MeshTools/Test/{SubdivideCleanBenchmark.h => SubdivideRemoveDuplicatesBenchmark.h} (83%) diff --git a/src/MeshTools/CMakeLists.txt b/src/MeshTools/CMakeLists.txt index fc0b2cd15..ae2edb6cc 100644 --- a/src/MeshTools/CMakeLists.txt +++ b/src/MeshTools/CMakeLists.txt @@ -33,12 +33,12 @@ set(MagnumMeshTools_GracefulAssert_SRCS GenerateFlatNormals.cpp) set(MagnumMeshTools_HEADERS - Clean.h CombineIndexedArrays.h CompressIndices.h FlipNormals.h GenerateFlatNormals.h Interleave.h + RemoveDuplicates.h Subdivide.h Tipsify.h Transform.h diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index 0c97a5e64..59fa27c87 100644 --- a/src/MeshTools/CombineIndexedArrays.h +++ b/src/MeshTools/CombineIndexedArrays.h @@ -33,7 +33,7 @@ #include #include "Math/Vector.h" -#include "MeshTools/Clean.h" +#include "MeshTools/RemoveDuplicates.h" namespace Magnum { namespace MeshTools { @@ -55,7 +55,7 @@ class CombineIndexedArrays { writeCombinedIndices(indexCombinations, std::get<0>(indexedArrays)...); /* Make the combinations unique */ - MeshTools::clean(result, indexCombinations); + MeshTools::removeDuplicates(result, indexCombinations); /* Write combined arrays */ writeCombinedArrays(indexCombinations, std::get<1>(indexedArrays)...); diff --git a/src/MeshTools/GenerateFlatNormals.cpp b/src/MeshTools/GenerateFlatNormals.cpp index 64e152d1c..10a1a8de3 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -25,7 +25,7 @@ #include "GenerateFlatNormals.h" #include "Math/Vector3.h" -#include "MeshTools/Clean.h" +#include "MeshTools/RemoveDuplicates.h" namespace Magnum { namespace MeshTools { @@ -48,8 +48,8 @@ std::tuple, std::vector> generateFlatNormals(c normals.push_back(normal); } - /* Clean duplicate normals and return */ - MeshTools::clean(normalIndices, normals); + /* Remove duplicate normals and return */ + MeshTools::removeDuplicates(normalIndices, normals); return std::make_tuple(normalIndices, normals); } diff --git a/src/MeshTools/Clean.h b/src/MeshTools/RemoveDuplicates.h similarity index 87% rename from src/MeshTools/Clean.h rename to src/MeshTools/RemoveDuplicates.h index 9311cc989..c588a0e78 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/RemoveDuplicates.h @@ -1,5 +1,5 @@ -#ifndef Magnum_MeshTools_Clean_h -#define Magnum_MeshTools_Clean_h +#ifndef Magnum_MeshTools_RemoveDuplicates_h +#define Magnum_MeshTools_RemoveDuplicates_h /* This file is part of Magnum. @@ -25,11 +25,12 @@ */ /** @file - * @brief Function Magnum::MeshTools::clean() + * @brief Function Magnum::MeshTools::removeDuplicates() */ -#include #include +#include +#include #include #include "Math/Functions.h" @@ -39,9 +40,9 @@ namespace Magnum { namespace MeshTools { namespace Implementation { -template class Clean { +template class RemoveDuplicates { public: - Clean(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} + RemoveDuplicates(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} void operator()(typename Vertex::Type epsilon = Math::TypeTraits::epsilon()); @@ -66,7 +67,7 @@ template class Clean { } /** -@brief %Clean the mesh +@brief %Remove duplicate vertices from the mesh @tparam Vertex Vertex data type @tparam vertexSize How many initial vertex fields are important (for example, when dealing with perspective in 3D space, only first three @@ -82,13 +83,13 @@ 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::TypeTraits::epsilon()) { - Implementation::Clean(indices, vertices)(epsilon); +template inline void removeDuplicates(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = Math::TypeTraits::epsilon()) { + Implementation::RemoveDuplicates(indices, vertices)(epsilon); } namespace Implementation { -template void Clean::operator()(typename Vertex::Type epsilon) { +template void RemoveDuplicates::operator()(typename Vertex::Type epsilon) { if(indices.empty()) return; /* Get mesh bounds */ diff --git a/src/MeshTools/Subdivide.h b/src/MeshTools/Subdivide.h index c02ca5c79..33b8f8517 100644 --- a/src/MeshTools/Subdivide.h +++ b/src/MeshTools/Subdivide.h @@ -68,7 +68,7 @@ template class Subdivide { @param interpolator Functor or function pointer which interpolates two adjacent vertices: `Vertex interpolator(Vertex a, Vertex b)` -Goes through all triangle faces and subdivides them into four new. Cleaning +Goes through all triangle faces and subdivides them into four new. Removing duplicate vertices in the mesh is up to user. */ template inline void subdivide(std::vector& indices, std::vector& vertices, Interpolator interpolator) { diff --git a/src/MeshTools/Test/CMakeLists.txt b/src/MeshTools/Test/CMakeLists.txt index a0a5626e5..e99991d80 100644 --- a/src/MeshTools/Test/CMakeLists.txt +++ b/src/MeshTools/Test/CMakeLists.txt @@ -22,14 +22,14 @@ # DEALINGS IN THE SOFTWARE. # -corrade_add_test(MeshToolsCleanTest CleanTest.cpp) corrade_add_test(MeshToolsCombineIndexedArraysTest CombineIndexedArraysTest.cpp) corrade_add_test(MeshToolsCompressIndicesTest CompressIndicesTest.cpp LIBRARIES MagnumMeshTools) corrade_add_test(MeshToolsFlipNormalsTest FlipNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib) corrade_add_test(MeshToolsGenerateFlatNormalsTest GenerateFlatNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib) corrade_add_test(MeshToolsInterleaveTest InterleaveTest.cpp) +corrade_add_test(MeshToolsRemoveDuplicatesTest RemoveDuplicatesTest.cpp) corrade_add_test(MeshToolsSubdivideTest SubdivideTest.cpp) -# corrade_add_test(MeshToolsSubdivideCleanBenchmark SubdivideCleanBenchmark.h SubdivideCleanBenchmark.cpp MagnumPrimitives) +# corrade_add_test(MeshToolsSubdivideRemoveDuplicatesBenchmark SubdivideRemoveDuplicatesBenchmark.h SubdivideRemoveDuplicatesBenchmark.cpp MagnumPrimitives) corrade_add_test(MeshToolsTipsifyTest TipsifyTest.cpp LIBRARIES MagnumMeshTools) corrade_add_test(MeshToolsTransformTest TransformTest.cpp LIBRARIES MagnumMeshTools) diff --git a/src/MeshTools/Test/CleanTest.cpp b/src/MeshTools/Test/RemoveDuplicatesTest.cpp similarity index 81% rename from src/MeshTools/Test/CleanTest.cpp rename to src/MeshTools/Test/RemoveDuplicatesTest.cpp index 50b0a711a..2f40c9038 100644 --- a/src/MeshTools/Test/CleanTest.cpp +++ b/src/MeshTools/Test/RemoveDuplicatesTest.cpp @@ -24,27 +24,27 @@ #include -#include "MeshTools/Clean.h" +#include "MeshTools/RemoveDuplicates.h" namespace Magnum { namespace MeshTools { namespace Test { -class CleanTest: public TestSuite::Tester { +class RemoveDuplicatesTest: public TestSuite::Tester { public: - CleanTest(); + RemoveDuplicatesTest(); void cleanMesh(); }; typedef Math::Vector<1, int> Vector1; -CleanTest::CleanTest() { - addTests({&CleanTest::cleanMesh}); +RemoveDuplicatesTest::RemoveDuplicatesTest() { + addTests({&RemoveDuplicatesTest::cleanMesh}); } -void CleanTest::cleanMesh() { +void RemoveDuplicatesTest::cleanMesh() { std::vector positions{1, 2, 1, 4}; std::vector indices{0, 1, 2, 1, 2, 3}; - MeshTools::clean(indices, positions); + MeshTools::removeDuplicates(indices, positions); /* Verify cleanup */ CORRADE_VERIFY(positions == (std::vector{1, 2, 4})); @@ -53,4 +53,4 @@ void CleanTest::cleanMesh() { }}} -CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CleanTest) +CORRADE_TEST_MAIN(Magnum::MeshTools::Test::RemoveDuplicatesTest) diff --git a/src/MeshTools/Test/SubdivideCleanBenchmark.cpp b/src/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp similarity index 77% rename from src/MeshTools/Test/SubdivideCleanBenchmark.cpp rename to src/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp index 01f3ebd36..87025a70d 100644 --- a/src/MeshTools/Test/SubdivideCleanBenchmark.cpp +++ b/src/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp @@ -22,19 +22,19 @@ DEALINGS IN THE SOFTWARE. */ -#include "SubdivideCleanBenchmark.h" +#include "SubdivideRemoveDuplicatesBenchmark.h" #include #include "Primitives/Icosphere.h" -#include "MeshTools/Clean.h" +#include "MeshTools/RemoveDuplicates.h" #include "MeshTools/Subdivide.h" -QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::SubdivideCleanBenchmark) +QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::SubdivideRemoveDuplicatesBenchmark) namespace Magnum { namespace MeshTools { namespace Test { -void SubdivideCleanBenchmark::subdivide() { +void SubdivideRemoveDuplicatesBenchmark::subdivide() { QBENCHMARK { Primitives::Icosphere<0> icosphere; @@ -47,7 +47,7 @@ void SubdivideCleanBenchmark::subdivide() { } } -void SubdivideCleanBenchmark::subdivideAndCleanMeshAfter() { +void SubdivideRemoveDuplicatesBenchmark::subdivideAndRemoveDuplicatesMeshAfter() { QBENCHMARK { Primitives::Icosphere<0> icosphere; @@ -58,25 +58,25 @@ void SubdivideCleanBenchmark::subdivideAndCleanMeshAfter() { MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::clean(*icosphere.indices(), *icosphere.positions(0)); + MeshTools::removeDuplicates(*icosphere.indices(), *icosphere.positions(0)); } } -void SubdivideCleanBenchmark::subdivideAndCleanMeshBetween() { +void SubdivideRemoveDuplicatesBenchmark::subdivideAndRemoveDuplicatesMeshBetween() { QBENCHMARK { Primitives::Icosphere<0> icosphere; /* Subdivide 5 times */ MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::clean(*icosphere.indices(), *icosphere.positions(0)); + MeshTools::removeDuplicates(*icosphere.indices(), *icosphere.positions(0)); MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::clean(*icosphere.indices(), *icosphere.positions(0)); + MeshTools::removeDuplicates(*icosphere.indices(), *icosphere.positions(0)); MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::clean(*icosphere.indices(), *icosphere.positions(0)); + MeshTools::removeDuplicates(*icosphere.indices(), *icosphere.positions(0)); MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::clean(*icosphere.indices(), *icosphere.positions(0)); + MeshTools::removeDuplicates(*icosphere.indices(), *icosphere.positions(0)); MeshTools::subdivide(*icosphere.indices(), *icosphere.positions(0), interpolator); - MeshTools::clean(*icosphere.indices(), *icosphere.positions(0)); + MeshTools::removeDuplicates(*icosphere.indices(), *icosphere.positions(0)); } } diff --git a/src/MeshTools/Test/SubdivideCleanBenchmark.h b/src/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.h similarity index 83% rename from src/MeshTools/Test/SubdivideCleanBenchmark.h rename to src/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.h index 07f499732..c82cf4ddf 100644 --- a/src/MeshTools/Test/SubdivideCleanBenchmark.h +++ b/src/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.h @@ -1,5 +1,5 @@ -#ifndef Magnum_MeshTools_Test_SubdivideCleanBenchmark_h -#define Magnum_MeshTools_Test_SubdivideCleanBenchmark_h +#ifndef Magnum_MeshTools_Test_SubdivideRemoveDuplicatesBenchmark_h +#define Magnum_MeshTools_Test_SubdivideRemoveDuplicatesBenchmark_h /* This file is part of Magnum. @@ -30,13 +30,13 @@ namespace Magnum { namespace MeshTools { namespace Test { -class SubdivideCleanBenchmark: public QObject { +class SubdivideRemoveDuplicatesBenchmark: public QObject { Q_OBJECT private slots: void subdivide(); - void subdivideAndCleanMeshAfter(); - void subdivideAndCleanMeshBetween(); + void subdivideAndRemoveDuplicatesMeshAfter(); + void subdivideAndRemoveDuplicatesMeshBetween(); private: static Magnum::Vector4 interpolator(const Magnum::Vector4& a, const Magnum::Vector4& b) { diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 232db6940..2114b70c6 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -25,7 +25,7 @@ #include #include -#include "MeshTools/Clean.h" +#include "MeshTools/RemoveDuplicates.h" #include "MeshTools/Subdivide.h" namespace Magnum { namespace MeshTools { namespace Test { @@ -71,7 +71,7 @@ void SubdivideTest::subdivide() { 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})); - MeshTools::clean(indices, positions); + MeshTools::removeDuplicates(indices, positions); /* Positions 0, 1, 2, 3, 4, 5, 6, 7, 8 */ CORRADE_COMPARE(positions.size(), 9); diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index ff57f0255..748c5e52f 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -29,8 +29,8 @@ */ #include "Math/Vector3.h" +#include "MeshTools/RemoveDuplicates.h" #include "MeshTools/Subdivide.h" -#include "MeshTools/Clean.h" #include "Trade/MeshData3D.h" #include "Primitives/magnumPrimitivesVisibility.h" @@ -72,7 +72,7 @@ template class Icosphere { return (a+b).normalized(); }); - MeshTools::clean(*indices(), *normals(0)); + MeshTools::removeDuplicates(*indices(), *normals(0)); positions(0)->assign(normals(0)->begin(), normals(0)->end()); } };