Browse Source

MeshTools: removed dependency on MeshBuilder in Tipsify.

pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
571f41f53f
  1. 59
      src/MeshTools/Test/TipsifyTest.cpp
  2. 5
      src/MeshTools/Test/TipsifyTest.h
  3. 38
      src/MeshTools/Tipsify.h

59
src/MeshTools/Test/TipsifyTest.cpp

@ -17,7 +17,6 @@
#include <QtTest/QTest> #include <QtTest/QTest>
#include "MeshBuilder.h"
#include "MeshTools/Tipsify.h" #include "MeshTools/Tipsify.h"
QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::TipsifyTest) QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::TipsifyTest)
@ -41,38 +40,34 @@ namespace Magnum { namespace MeshTools { namespace Test {
*/ */
TipsifyTest::TipsifyTest(QObject* parent): QObject(parent) { TipsifyTest::TipsifyTest(QObject* parent): QObject(parent), indices{
unsigned int vertices[19]; /* who cares */ 4, 1, 0,
static const unsigned int indices[] = { 10, 9, 13,
4, 1, 0, 6, 3, 2,
10, 9, 13, 9, 5, 4,
6, 3, 2, 12, 9, 8,
9, 5, 4, 11, 7, 6,
12, 9, 8,
11, 7, 6, 14, 15, 11,
2, 1, 5,
14, 15, 11, 10, 6, 5,
2, 1, 5, 10, 5, 9,
10, 6, 5, 13, 14, 10,
10, 5, 9, 1, 4, 5,
13, 14, 10,
1, 4, 5, 7, 3, 6,
6, 2, 5,
7, 3, 6, 9, 4, 8,
6, 2, 5, 6, 10, 11,
9, 4, 8, 13, 9, 12,
6, 10, 11, 14, 11, 10,
13, 9, 12,
14, 11, 10, 16, 17, 18
}, vertexCount(19) {}
16, 17, 18
};
builder.setData(vertices, indices, 19, 19*3);
}
void TipsifyTest::buildAdjacency() { void TipsifyTest::buildAdjacency() {
vector<unsigned int> liveTriangleCount, neighborOffset, neighbors; vector<unsigned int> liveTriangleCount, neighborOffset, neighbors;
Tipsify(builder).buildAdjacency(liveTriangleCount, neighborOffset, neighbors); Tipsify(indices, vertexCount).buildAdjacency(liveTriangleCount, neighborOffset, neighbors);
QVERIFY((liveTriangleCount == vector<unsigned int>{ QVERIFY((liveTriangleCount == vector<unsigned int>{
1, 3, 3, 2, 1, 3, 3, 2,
@ -116,9 +111,9 @@ void TipsifyTest::buildAdjacency() {
} }
void TipsifyTest::tipsify() { void TipsifyTest::tipsify() {
MeshTools::tipsify(builder, 3); MeshTools::tipsify(indices, vertexCount, 3);
QVERIFY((builder.indices() == vector<unsigned int>{ QVERIFY((indices == vector<unsigned int>{
4, 1, 0, 4, 1, 0,
9, 5, 4, 9, 5, 4,
1, 4, 5, 1, 4, 5,

5
src/MeshTools/Test/TipsifyTest.h

@ -17,8 +17,6 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include "MeshBuilder.h"
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
class TipsifyTest: public QObject { class TipsifyTest: public QObject {
@ -32,7 +30,8 @@ class TipsifyTest: public QObject {
void tipsify(); void tipsify();
private: private:
MeshBuilder<unsigned int> builder; std::vector<unsigned int> indices;
size_t vertexCount;
}; };
}}} }}}

38
src/MeshTools/Tipsify.h

@ -19,7 +19,10 @@
* @brief Class Magnum::MeshTools::Tipsify * @brief Class Magnum::MeshTools::Tipsify
*/ */
#include "AbstractTool.h" #include <cstddef>
#include <vector>
#include "utilities.h"
namespace Magnum { namespace MeshTools { namespace Magnum { namespace MeshTools {
@ -28,13 +31,14 @@ namespace Magnum { namespace MeshTools {
See tipsify() for full documentation. See tipsify() for full documentation.
*/ */
class MESHTOOLS_EXPORT Tipsify: public AbstractIndexTool { class MESHTOOLS_EXPORT Tipsify {
public: public:
/** @copydoc AbstractIndexTool::AbstractIndexTool(MeshBuilder<Vertex>&) */ /**
template<class Vertex> inline Tipsify(MeshBuilder<Vertex>& builder): AbstractIndexTool(builder) {} * @brief Constructor
*
/** @copydoc AbstractIndexTool::AbstractIndexTool(std::vector<unsigned int>&, unsigned int) */ * See tipsify() for full documentation.
inline Tipsify(std::vector<unsigned int>& indices, unsigned int vertexCount): AbstractIndexTool(indices, vertexCount) {} */
inline Tipsify(std::vector<unsigned int>& indices, unsigned int vertexCount): indices(indices), vertexCount(vertexCount) {}
/** /**
* @brief Functor * @brief Functor
@ -50,12 +54,16 @@ class MESHTOOLS_EXPORT Tipsify: public AbstractIndexTool {
* (used internally). * (used internally).
*/ */
void buildAdjacency(std::vector<unsigned int>& liveTriangleCount, std::vector<unsigned int>& neighborOffset, std::vector<unsigned int>& neighbors) const; void buildAdjacency(std::vector<unsigned int>& liveTriangleCount, std::vector<unsigned int>& neighborOffset, std::vector<unsigned int>& neighbors) const;
private:
std::vector<unsigned int>& indices;
const unsigned int vertexCount;
}; };
/** /**
@brief %Tipsify the mesh @brief %Tipsify the mesh
@tparam Vertex Vertex data type (the same as in MeshBuilder) @param indices Indices array to operate on
@param builder %Mesh builder to operate on @param vertexCount Vertex count
@param cacheSize Post-transform vertex cache size @param cacheSize Post-transform vertex cache size
Optimizes the mesh for vertex-bound applications by rearranging its index Optimizes the mesh for vertex-bound applications by rearranging its index
@ -76,18 +84,6 @@ you can just write
MeshTools::tipsify(builder, cacheSize); MeshTools::tipsify(builder, cacheSize);
@endcode @endcode
*/ */
template<class Vertex> inline void tipsify(MeshBuilder<Vertex>& builder, size_t cacheSize) {
Tipsify{builder}(cacheSize);
}
/**
@brief %Tipsify the mesh
@param indices Indices array to operate on
@param vertexCount Vertex count
@param cacheSize Post-transform vertex cache size
See tipsify(MeshBuilder<Vertex>&, size_t) for more information.
*/
inline void tipsify(std::vector<unsigned int>& indices, unsigned int vertexCount, size_t cacheSize) { inline void tipsify(std::vector<unsigned int>& indices, unsigned int vertexCount, size_t cacheSize) {
Tipsify(indices, vertexCount)(cacheSize); Tipsify(indices, vertexCount)(cacheSize);
} }

Loading…
Cancel
Save