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

5
src/MeshTools/Test/TipsifyTest.h

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

Loading…
Cancel
Save