Browse Source

MeshTools: renamed clean() to removeDuplicates().

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
1c32119058
  1. 2
      src/MeshTools/CMakeLists.txt
  2. 4
      src/MeshTools/CombineIndexedArrays.h
  3. 6
      src/MeshTools/GenerateFlatNormals.cpp
  4. 21
      src/MeshTools/RemoveDuplicates.h
  5. 2
      src/MeshTools/Subdivide.h
  6. 4
      src/MeshTools/Test/CMakeLists.txt
  7. 16
      src/MeshTools/Test/RemoveDuplicatesTest.cpp
  8. 24
      src/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp
  9. 10
      src/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.h
  10. 4
      src/MeshTools/Test/SubdivideTest.cpp
  11. 4
      src/Primitives/Icosphere.h

2
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

4
src/MeshTools/CombineIndexedArrays.h

@ -33,7 +33,7 @@
#include <tuple>
#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)...);

6
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<UnsignedInt>, std::vector<Vector3>> 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);
}

21
src/MeshTools/Clean.h → 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 <unordered_map>
#include <limits>
#include <unordered_map>
#include <vector>
#include <Utility/MurmurHash2.h>
#include "Math/Functions.h"
@ -39,9 +40,9 @@ namespace Magnum { namespace MeshTools {
namespace Implementation {
template<class Vertex, std::size_t vertexSize = Vertex::Size> class Clean {
template<class Vertex, std::size_t vertexSize = Vertex::Size> class RemoveDuplicates {
public:
Clean(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {}
RemoveDuplicates(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {}
void operator()(typename Vertex::Type epsilon = Math::TypeTraits<typename Vertex::Type>::epsilon());
@ -66,7 +67,7 @@ template<class Vertex, std::size_t vertexSize = Vertex::Size> 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<class Vertex, std::size_t vertexSize = Vertex::Size> inline void clean(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices, typename Vertex::Type epsilon = Math::TypeTraits<typename Vertex::Type>::epsilon()) {
Implementation::Clean<Vertex, vertexSize>(indices, vertices)(epsilon);
template<class Vertex, std::size_t vertexSize = Vertex::Size> inline void removeDuplicates(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices, typename Vertex::Type epsilon = Math::TypeTraits<typename Vertex::Type>::epsilon()) {
Implementation::RemoveDuplicates<Vertex, vertexSize>(indices, vertices)(epsilon);
}
namespace Implementation {
template<class Vertex, std::size_t vertexSize> void Clean<Vertex, vertexSize>::operator()(typename Vertex::Type epsilon) {
template<class Vertex, std::size_t vertexSize> void RemoveDuplicates<Vertex, vertexSize>::operator()(typename Vertex::Type epsilon) {
if(indices.empty()) return;
/* Get mesh bounds */

2
src/MeshTools/Subdivide.h

@ -68,7 +68,7 @@ template<class Vertex, class Interpolator> 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<class Vertex, class Interpolator> inline void subdivide(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices, Interpolator interpolator) {

4
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)

16
src/MeshTools/Test/CleanTest.cpp → src/MeshTools/Test/RemoveDuplicatesTest.cpp

@ -24,27 +24,27 @@
#include <TestSuite/Tester.h>
#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<Vector1> positions{1, 2, 1, 4};
std::vector<UnsignedInt> indices{0, 1, 2, 1, 2, 3};
MeshTools::clean(indices, positions);
MeshTools::removeDuplicates(indices, positions);
/* Verify cleanup */
CORRADE_VERIFY(positions == (std::vector<Vector1>{1, 2, 4}));
@ -53,4 +53,4 @@ void CleanTest::cleanMesh() {
}}}
CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CleanTest)
CORRADE_TEST_MAIN(Magnum::MeshTools::Test::RemoveDuplicatesTest)

24
src/MeshTools/Test/SubdivideCleanBenchmark.cpp → src/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp

@ -22,19 +22,19 @@
DEALINGS IN THE SOFTWARE.
*/
#include "SubdivideCleanBenchmark.h"
#include "SubdivideRemoveDuplicatesBenchmark.h"
#include <QtTest/QTest>
#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));
}
}

10
src/MeshTools/Test/SubdivideCleanBenchmark.h → 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) {

4
src/MeshTools/Test/SubdivideTest.cpp

@ -25,7 +25,7 @@
#include <sstream>
#include <TestSuite/Tester.h>
#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<Vector1>{0, 2, 6, 8, 1, 4, 3, 4, 7, 5}));
CORRADE_COMPARE(indices, (std::vector<UnsignedInt>{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3}));
MeshTools::clean(indices, positions);
MeshTools::removeDuplicates(indices, positions);
/* Positions 0, 1, 2, 3, 4, 5, 6, 7, 8 */
CORRADE_COMPARE(positions.size(), 9);

4
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<std::size_t subdivisions> 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());
}
};

Loading…
Cancel
Save