Browse Source

MeshTools: using new type aliases in whole MeshTools namespace.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
32b783505f
  1. 10
      src/MeshTools/Clean.h
  2. 24
      src/MeshTools/CombineIndexedArrays.h
  3. 20
      src/MeshTools/CompressIndices.cpp
  4. 8
      src/MeshTools/CompressIndices.h
  5. 2
      src/MeshTools/FlipNormals.cpp
  6. 8
      src/MeshTools/FlipNormals.h
  7. 6
      src/MeshTools/GenerateFlatNormals.cpp
  8. 6
      src/MeshTools/GenerateFlatNormals.h
  9. 12
      src/MeshTools/Subdivide.h
  10. 6
      src/MeshTools/Test/CleanTest.cpp
  11. 34
      src/MeshTools/Test/CombineIndexedArraysTest.cpp
  12. 6
      src/MeshTools/Test/CompressIndicesTest.cpp
  13. 6
      src/MeshTools/Test/FlipNormalsTest.cpp
  14. 6
      src/MeshTools/Test/GenerateFlatNormalsTest.cpp
  15. 32
      src/MeshTools/Test/InterleaveTest.cpp
  16. 8
      src/MeshTools/Test/SubdivideTest.cpp
  17. 12
      src/MeshTools/Test/TipsifyTest.cpp
  18. 30
      src/MeshTools/Tipsify.cpp
  19. 12
      src/MeshTools/Tipsify.h

10
src/MeshTools/Clean.h

@ -32,7 +32,7 @@ namespace Implementation {
template<class Vertex, std::size_t vertexSize = Vertex::Size> class Clean {
public:
inline Clean(std::vector<std::uint32_t>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {}
inline Clean(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {}
void operator()(typename Vertex::Type epsilon = Math::MathTypeTraits<typename Vertex::Type>::epsilon()) {
if(indices.empty()) return;
@ -107,12 +107,12 @@ template<class Vertex, std::size_t vertexSize = Vertex::Size> class Clean {
};
struct HashedVertex {
std::uint32_t oldIndex, newIndex;
UnsignedInt oldIndex, newIndex;
HashedVertex(std::uint32_t oldIndex, std::uint32_t newIndex): oldIndex(oldIndex), newIndex(newIndex) {}
HashedVertex(UnsignedInt oldIndex, UnsignedInt newIndex): oldIndex(oldIndex), newIndex(newIndex) {}
};
std::vector<std::uint32_t>& indices;
std::vector<UnsignedInt>& indices;
std::vector<Vertex>& vertices;
};
@ -136,7 +136,7 @@ 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<std::uint32_t>& indices, std::vector<Vertex>& vertices, typename Vertex::Type epsilon = Math::MathTypeTraits<typename Vertex::Type>::epsilon()) {
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::MathTypeTraits<typename Vertex::Type>::epsilon()) {
Implementation::Clean<Vertex, vertexSize>(indices, vertices)(epsilon);
}

24
src/MeshTools/CombineIndexedArrays.h

@ -33,17 +33,17 @@ namespace Implementation {
class CombineIndexedArrays {
public:
template<class ...T> std::vector<std::uint32_t> operator()(const std::tuple<const std::vector<std::uint32_t>&, std::vector<T>&>&... indexedArrays) {
template<class ...T> std::vector<UnsignedInt> operator()(const std::tuple<const std::vector<UnsignedInt>&, std::vector<T>&>&... indexedArrays) {
/* Compute index count */
std::size_t _indexCount = indexCount(std::get<0>(indexedArrays)...);
/* Resulting index array */
std::vector<std::uint32_t> result;
std::vector<UnsignedInt> result;
result.resize(_indexCount);
std::iota(result.begin(), result.end(), 0);
/* All index combinations */
std::vector<Math::Vector<sizeof...(indexedArrays), std::uint32_t> > indexCombinations(_indexCount);
std::vector<Math::Vector<sizeof...(indexedArrays), UnsignedInt> > indexCombinations(_indexCount);
writeCombinedIndices(indexCombinations, std::get<0>(indexedArrays)...);
/* Make the combinations unique */
@ -56,13 +56,13 @@ class CombineIndexedArrays {
}
private:
template<class ...T> inline static std::size_t indexCount(const std::vector<std::uint32_t>& first, const std::vector<T>&... next) {
template<class ...T> inline static std::size_t indexCount(const std::vector<UnsignedInt>& first, const std::vector<T>&... next) {
CORRADE_ASSERT(sizeof...(next) == 0 || indexCount(next...) == first.size(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.", 0);
return first.size();
}
template<std::size_t size, class ...T> static void writeCombinedIndices(std::vector<Math::Vector<size, std::uint32_t>>& output, const std::vector<std::uint32_t>& first, const std::vector<T>&... next) {
template<std::size_t size, class ...T> static void writeCombinedIndices(std::vector<Math::Vector<size, UnsignedInt>>& output, const std::vector<UnsignedInt>& first, const std::vector<T>&... next) {
/* Copy the data to output */
for(std::size_t i = 0; i != output.size(); ++i)
output[i][size-sizeof...(next)-1] = first[i];
@ -70,7 +70,7 @@ class CombineIndexedArrays {
writeCombinedIndices(output, next...);
}
template<std::size_t size, class T, class ...U> static void writeCombinedArrays(const std::vector<Math::Vector<size, std::uint32_t>>& combinedIndices, std::vector<T>& first, std::vector<U>&... next) {
template<std::size_t size, class T, class ...U> static void writeCombinedArrays(const std::vector<Math::Vector<size, UnsignedInt>>& combinedIndices, std::vector<T>& first, std::vector<U>&... next) {
/* Rewrite output array */
std::vector<T> output;
for(std::size_t i = 0; i != combinedIndices.size(); ++i)
@ -82,8 +82,8 @@ class CombineIndexedArrays {
/* Terminator functions for recursive calls */
inline static std::size_t indexCount() { return 0; }
template<std::size_t size> inline static void writeCombinedIndices(std::vector<Math::Vector<size, std::uint32_t>>&) {}
template<std::size_t size> inline static void writeCombinedArrays(const std::vector<Math::Vector<size, std::uint32_t>>&) {}
template<std::size_t size> inline static void writeCombinedIndices(std::vector<Math::Vector<size, UnsignedInt>>&) {}
template<std::size_t size> inline static void writeCombinedArrays(const std::vector<Math::Vector<size, UnsignedInt>>&) {}
};
}
@ -105,13 +105,13 @@ avoid explicit verbose specification of tuple type, you can write it with help
of some STL functions like shown below. Also if one index array is shader by
more than one attribute array, just pass the index array more times. Example:
@code
std::vector<std::uint32_t> vertexIndices;
std::vector<UnsignedInt> vertexIndices;
std::vector<Vector3> positions;
std::vector<std::uint32_t> normalTextureIndices;
std::vector<UnsignedInt> normalTextureIndices;
std::vector<Vector3> normals;
std::vector<Vector2> textureCoordinates;
std::vector<std::uint32_t> indices = MeshTools::combineIndexedArrays(
std::vector<UnsignedInt> indices = MeshTools::combineIndexedArrays(
std::make_tuple(std::cref(vertexIndices), std::ref(positions)),
std::make_tuple(std::cref(normalTextureIndices), std::ref(normals)),
std::make_tuple(std::cref(normalTextureIndices), std::ref(textureCoordinates))
@ -125,7 +125,7 @@ attributes indexed with `indices`.
/* Implementation note: It's done using tuples because it is more clear which
parameter is index array and which is attribute array, mainly when both are
of the same type. */
template<class ...T> std::vector<std::uint32_t> combineIndexedArrays(const std::tuple<const std::vector<std::uint32_t>&, std::vector<T>&>&... indexedArrays) {
template<class ...T> std::vector<UnsignedInt> combineIndexedArrays(const std::tuple<const std::vector<UnsignedInt>&, std::vector<T>&>&... indexedArrays) {
return Implementation::CombineIndexedArrays()(indexedArrays...);
}

20
src/MeshTools/CompressIndices.cpp

@ -26,11 +26,11 @@ namespace Magnum { namespace MeshTools {
namespace {
template<class> constexpr Mesh::IndexType indexType();
template<> inline constexpr Mesh::IndexType indexType<GLubyte>() { return Mesh::IndexType::UnsignedByte; }
template<> inline constexpr Mesh::IndexType indexType<GLushort>() { return Mesh::IndexType::UnsignedShort; }
template<> inline constexpr Mesh::IndexType indexType<GLuint>() { return Mesh::IndexType::UnsignedInt; }
template<> inline constexpr Mesh::IndexType indexType<UnsignedByte>() { return Mesh::IndexType::UnsignedByte; }
template<> inline constexpr Mesh::IndexType indexType<UnsignedShort>() { return Mesh::IndexType::UnsignedShort; }
template<> inline constexpr Mesh::IndexType indexType<UnsignedInt>() { return Mesh::IndexType::UnsignedInt; }
template<class T> inline std::tuple<std::size_t, Mesh::IndexType, char*> compress(const std::vector<std::uint32_t>& indices) {
template<class T> inline std::tuple<std::size_t, Mesh::IndexType, char*> compress(const std::vector<UnsignedInt>& indices) {
char* buffer = new char[indices.size()*sizeof(T)];
for(std::size_t i = 0; i != indices.size(); ++i) {
T index = static_cast<T>(indices[i]);
@ -40,15 +40,15 @@ template<class T> inline std::tuple<std::size_t, Mesh::IndexType, char*> compres
return std::make_tuple(indices.size(), indexType<T>(), buffer);
}
std::tuple<std::size_t, Mesh::IndexType, char*> compressIndicesInternal(const std::vector<std::uint32_t>& indices, std::uint32_t max) {
std::tuple<std::size_t, Mesh::IndexType, char*> compressIndicesInternal(const std::vector<UnsignedInt>& indices, UnsignedInt max) {
switch(Math::log(256, max)) {
case 0:
return compress<GLubyte>(indices);
return compress<UnsignedByte>(indices);
case 1:
return compress<GLushort>(indices);
return compress<UnsignedShort>(indices);
case 2:
case 3:
return compress<GLuint>(indices);
return compress<UnsignedInt>(indices);
default:
CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << max << "elements.", {});
@ -58,11 +58,11 @@ std::tuple<std::size_t, Mesh::IndexType, char*> compressIndicesInternal(const st
}
#endif
std::tuple<std::size_t, Mesh::IndexType, char*> compressIndices(const std::vector<std::uint32_t>& indices) {
std::tuple<std::size_t, Mesh::IndexType, char*> compressIndices(const std::vector<UnsignedInt>& indices) {
return compressIndicesInternal(indices, *std::max_element(indices.begin(), indices.end()));
}
void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<std::uint32_t>& indices) {
void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<UnsignedInt>& indices) {
auto minmax = std::minmax_element(indices.begin(), indices.end());
/** @todo Performance hint when range can be represented by smaller value? */

8
src/MeshTools/CompressIndices.h

@ -49,10 +49,10 @@ std::size_t dataSize = indexCount*Mesh::indexSize(indexType);
delete[] data;
@endcode
See also compressIndices(Mesh*, Buffer*, Buffer::Usage, const std::vector<std::uint32_t>&),
See also compressIndices(Mesh*, Buffer*, Buffer::Usage, const std::vector<UnsignedInt>&),
which writes the compressed data directly into index buffer of given mesh.
*/
std::tuple<std::size_t, Mesh::IndexType, char*> MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector<std::uint32_t>& indices);
std::tuple<std::size_t, Mesh::IndexType, char*> MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector<UnsignedInt>& indices);
/**
@brief Compress vertex indices and write them to index buffer
@ -61,14 +61,14 @@ std::tuple<std::size_t, Mesh::IndexType, char*> MAGNUM_MESHTOOLS_EXPORT compress
@param usage Index buffer usage
@param indices Index array
The same as compressIndices(const std::vector<std::uint32_t>&), but this
The same as compressIndices(const std::vector<UnsignedInt>&), but this
function writes the output to given buffer, updates index count and specifies
index buffer with proper index range in the mesh, so you don't have to call
Mesh::setIndexCount() and Mesh::setIndexBuffer() on your own.
@see MeshTools::interleave()
*/
void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<std::uint32_t>& indices);
void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<UnsignedInt>& indices);
}}

2
src/MeshTools/FlipNormals.cpp

@ -19,7 +19,7 @@
namespace Magnum { namespace MeshTools {
void flipFaceWinding(std::vector<std::uint32_t>& indices) {
void flipFaceWinding(std::vector<UnsignedInt>& indices) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::flipNormals(): index count is not divisible by 3!", );
for(std::size_t i = 0; i != indices.size(); i += 3)

8
src/MeshTools/FlipNormals.h

@ -31,15 +31,15 @@ namespace Magnum { namespace MeshTools {
/**
@brief Flip face winding
The same as flipNormals(std::vector<std::uint32_t>&, std::vector<Vector3>&),
The same as flipNormals(std::vector<UnsignedInt>&, std::vector<Vector3>&),
but flips only face winding.
*/
void MAGNUM_MESHTOOLS_EXPORT flipFaceWinding(std::vector<std::uint32_t>& indices);
void MAGNUM_MESHTOOLS_EXPORT flipFaceWinding(std::vector<UnsignedInt>& indices);
/**
@brief Flip mesh normals
The same as flipNormals(std::vector<std::uint32_t>&, std::vector<Vector3>&),
The same as flipNormals(std::vector<UnsignedInt>&, std::vector<Vector3>&),
but flips only normals, not face winding.
*/
void MAGNUM_MESHTOOLS_EXPORT flipNormals(std::vector<Vector3>& normals);
@ -56,7 +56,7 @@ flipFaceWinding(), which flip normals or face winding only.
@attention The function requires the mesh to have triangle faces, thus index
count must be divisible by 3.
*/
inline void flipNormals(std::vector<std::uint32_t>& indices, std::vector<Vector3>& normals) {
inline void flipNormals(std::vector<UnsignedInt>& indices, std::vector<Vector3>& normals) {
flipFaceWinding(indices);
flipNormals(normals);
}

6
src/MeshTools/GenerateFlatNormals.cpp

@ -20,11 +20,11 @@
namespace Magnum { namespace MeshTools {
std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>> generateFlatNormals(const std::vector<std::uint32_t>& indices, const std::vector<Vector3>& positions) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>>()));
std::tuple<std::vector<UnsignedInt>, std::vector<Vector3>> generateFlatNormals(const std::vector<UnsignedInt>& indices, const std::vector<Vector3>& positions) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (std::tuple<std::vector<UnsignedInt>, std::vector<Vector3>>()));
/* Create normal for every triangle (assuming counterclockwise winding) */
std::vector<std::uint32_t> normalIndices;
std::vector<UnsignedInt> normalIndices;
normalIndices.reserve(indices.size());
std::vector<Vector3> normals;
normals.reserve(indices.size()/3);

6
src/MeshTools/GenerateFlatNormals.h

@ -38,10 +38,10 @@ namespace Magnum { namespace MeshTools {
For each face generates one normal vector, removes duplicates before
returning. Example usage:
@code
std::vector<std::uint32_t> vertexIndices;
std::vector<UnsignedInt> vertexIndices;
std::vector<Vector3> positions;
std::vector<std::uint32_t> normalIndices;
std::vector<UnsignedInt> normalIndices;
std::vector<Vector3> normals;
std::tie(normalIndices, normals) = MeshTools::generateFlatNormals(vertexIndices, positions);
@endcode
@ -51,7 +51,7 @@ use the same indices.
@attention Index count must be divisible by 3, otherwise zero length result
is generated.
*/
std::tuple<std::vector<std::uint32_t>, std::vector<Vector3>> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector<std::uint32_t>& indices, const std::vector<Vector3>& positions);
std::tuple<std::vector<UnsignedInt>, std::vector<Vector3>> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector<UnsignedInt>& indices, const std::vector<Vector3>& positions);
}}

12
src/MeshTools/Subdivide.h

@ -29,7 +29,7 @@ namespace Implementation {
template<class Vertex, class Interpolator> class Subdivide {
public:
inline Subdivide(std::vector<std::uint32_t>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {}
inline Subdivide(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {}
void operator()(Interpolator interpolator) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::subdivide(): index count is not divisible by 3!", );
@ -40,7 +40,7 @@ template<class Vertex, class Interpolator> class Subdivide {
/* Subdivide each face to four new */
for(std::size_t i = 0; i != indexCount; i += 3) {
/* Interpolate each side */
std::uint32_t newVertices[3];
UnsignedInt newVertices[3];
for(int j = 0; j != 3; ++j)
newVertices[j] = addVertex(interpolator(vertices[indices[i+j]], vertices[indices[i+(j+1)%3]]));
@ -66,15 +66,15 @@ template<class Vertex, class Interpolator> class Subdivide {
}
private:
std::vector<std::uint32_t>& indices;
std::vector<UnsignedInt>& indices;
std::vector<Vertex>& vertices;
std::uint32_t addVertex(const Vertex& v) {
UnsignedInt addVertex(const Vertex& v) {
vertices.push_back(v);
return vertices.size()-1;
}
void addFace(std::uint32_t first, std::uint32_t second, std::uint32_t third) {
void addFace(UnsignedInt first, UnsignedInt second, UnsignedInt third) {
indices.push_back(first);
indices.push_back(second);
indices.push_back(third);
@ -96,7 +96,7 @@ template<class Vertex, class Interpolator> class Subdivide {
Goes through all triangle faces and subdivides them into four new. Cleaning
duplicate vertices in the mesh is up to user.
*/
template<class Vertex, class Interpolator> inline void subdivide(std::vector<std::uint32_t>& indices, std::vector<Vertex>& vertices, Interpolator interpolator) {
template<class Vertex, class Interpolator> inline void subdivide(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices, Interpolator interpolator) {
Implementation::Subdivide<Vertex, Interpolator>(indices, vertices)(interpolator);
}

6
src/MeshTools/Test/CleanTest.cpp

@ -29,7 +29,7 @@ class CleanTest: public Corrade::TestSuite::Tester {
class Vector1 {
public:
static const std::size_t Size = 1;
typedef std::int32_t Type;
typedef Int Type;
Vector1(): data(0) {}
Vector1(Type i): data(i) {}
@ -49,12 +49,12 @@ CleanTest::CleanTest() {
void CleanTest::cleanMesh() {
std::vector<Vector1> positions{1, 2, 1, 4};
std::vector<std::uint32_t> indices{0, 1, 2, 1, 2, 3};
std::vector<UnsignedInt> indices{0, 1, 2, 1, 2, 3};
MeshTools::clean(indices, positions);
/* Verify cleanup */
CORRADE_VERIFY(positions == (std::vector<Vector1>{1, 2, 4}));
CORRADE_COMPARE(indices, (std::vector<std::uint32_t>{0, 1, 0, 1, 0, 2}));
CORRADE_COMPARE(indices, (std::vector<UnsignedInt>{0, 1, 0, 1, 0, 2}));
}
}}}

34
src/MeshTools/Test/CombineIndexedArraysTest.cpp

@ -37,29 +37,29 @@ CombineIndexedArraysTest::CombineIndexedArraysTest() {
void CombineIndexedArraysTest::wrongIndexCount() {
std::stringstream ss;
Error::setOutput(&ss);
std::vector<std::uint32_t> array;
std::vector<std::uint32_t> result = MeshTools::combineIndexedArrays(
std::tuple<const std::vector<std::uint32_t>&, std::vector<std::uint32_t>&>(std::vector<std::uint32_t>{0, 1, 0}, array),
std::tuple<const std::vector<std::uint32_t>&, std::vector<std::uint32_t>&>(std::vector<std::uint32_t>{3, 4}, array));
std::vector<UnsignedInt> array;
std::vector<UnsignedInt> result = MeshTools::combineIndexedArrays(
std::tuple<const std::vector<UnsignedInt>&, std::vector<UnsignedInt>&>(std::vector<UnsignedInt>{0, 1, 0}, array),
std::tuple<const std::vector<UnsignedInt>&, std::vector<UnsignedInt>&>(std::vector<UnsignedInt>{3, 4}, array));
CORRADE_COMPARE(result.size(), 0);
CORRADE_COMPARE(ss.str(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.\n");
}
void CombineIndexedArraysTest::combine() {
std::vector<std::uint32_t> array1{ 0, 1 };
std::vector<std::uint32_t> array2{ 0, 1, 2, 3, 4 };
std::vector<std::uint32_t> array3{ 0, 1, 2, 3, 4, 5, 6, 7 };
std::vector<std::uint32_t> result = MeshTools::combineIndexedArrays(
std::tuple<const std::vector<std::uint32_t>&, std::vector<std::uint32_t>&>(std::vector<std::uint32_t>{0, 1, 0}, array1),
std::tuple<const std::vector<std::uint32_t>&, std::vector<std::uint32_t>&>(std::vector<std::uint32_t>{3, 4, 3}, array2),
std::tuple<const std::vector<std::uint32_t>&, std::vector<std::uint32_t>&>(std::vector<std::uint32_t>{6, 7, 6}, array3));
CORRADE_COMPARE(result, (std::vector<std::uint32_t>{0, 1, 0}));
CORRADE_COMPARE(array1, (std::vector<std::uint32_t>{0, 1}));
CORRADE_COMPARE(array2, (std::vector<std::uint32_t>{3, 4}));
CORRADE_COMPARE(array3, (std::vector<std::uint32_t>{6, 7}));
std::vector<UnsignedInt> array1{ 0, 1 };
std::vector<UnsignedInt> array2{ 0, 1, 2, 3, 4 };
std::vector<UnsignedInt> array3{ 0, 1, 2, 3, 4, 5, 6, 7 };
std::vector<UnsignedInt> result = MeshTools::combineIndexedArrays(
std::tuple<const std::vector<UnsignedInt>&, std::vector<UnsignedInt>&>(std::vector<UnsignedInt>{0, 1, 0}, array1),
std::tuple<const std::vector<UnsignedInt>&, std::vector<UnsignedInt>&>(std::vector<UnsignedInt>{3, 4, 3}, array2),
std::tuple<const std::vector<UnsignedInt>&, std::vector<UnsignedInt>&>(std::vector<UnsignedInt>{6, 7, 6}, array3));
CORRADE_COMPARE(result, (std::vector<UnsignedInt>{0, 1, 0}));
CORRADE_COMPARE(array1, (std::vector<UnsignedInt>{0, 1}));
CORRADE_COMPARE(array2, (std::vector<UnsignedInt>{3, 4}));
CORRADE_COMPARE(array3, (std::vector<UnsignedInt>{6, 7}));
}
}}}

6
src/MeshTools/Test/CompressIndicesTest.cpp

@ -42,7 +42,7 @@ void CompressIndicesTest::compressChar() {
Mesh::IndexType indexType;
char* data;
std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
std::vector<std::uint32_t>{1, 2, 3, 0, 4});
std::vector<UnsignedInt>{1, 2, 3, 0, 4});
CORRADE_COMPARE(indexCount, 5);
CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedByte);
@ -57,7 +57,7 @@ void CompressIndicesTest::compressShort() {
Mesh::IndexType indexType;
char* data;
std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
std::vector<std::uint32_t>{1, 256, 0, 5});
std::vector<UnsignedInt>{1, 256, 0, 5});
CORRADE_COMPARE(indexCount, 4);
CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedShort);
@ -83,7 +83,7 @@ void CompressIndicesTest::compressInt() {
Mesh::IndexType indexType;
char* data;
std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
std::vector<std::uint32_t>{65536, 3, 2});
std::vector<UnsignedInt>{65536, 3, 2});
CORRADE_COMPARE(indexCount, 3);
CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedInt);

6
src/MeshTools/Test/FlipNormalsTest.cpp

@ -40,18 +40,18 @@ void FlipNormalsTest::wrongIndexCount() {
std::stringstream ss;
Error::setOutput(&ss);
std::vector<std::uint32_t> indices{0, 1};
std::vector<UnsignedInt> indices{0, 1};
MeshTools::flipFaceWinding(indices);
CORRADE_COMPARE(ss.str(), "MeshTools::flipNormals(): index count is not divisible by 3!\n");
}
void FlipNormalsTest::flipFaceWinding() {
std::vector<std::uint32_t> indices{0, 1, 2,
std::vector<UnsignedInt> indices{0, 1, 2,
3, 4, 5};
MeshTools::flipFaceWinding(indices);
CORRADE_COMPARE(indices, (std::vector<std::uint32_t>{0, 2, 1,
CORRADE_COMPARE(indices, (std::vector<UnsignedInt>{0, 2, 1,
3, 5, 4}));
}

6
src/MeshTools/Test/GenerateFlatNormalsTest.cpp

@ -37,7 +37,7 @@ GenerateFlatNormalsTest::GenerateFlatNormalsTest() {
void GenerateFlatNormalsTest::wrongIndexCount() {
std::stringstream ss;
Error::setOutput(&ss);
std::vector<std::uint32_t> indices;
std::vector<UnsignedInt> indices;
std::vector<Vector3> normals;
std::tie(indices, normals) = MeshTools::generateFlatNormals({
0, 1
@ -50,7 +50,7 @@ void GenerateFlatNormalsTest::wrongIndexCount() {
void GenerateFlatNormalsTest::generate() {
/* Two vertices connected by one edge, each winded in another direction */
std::vector<std::uint32_t> indices;
std::vector<UnsignedInt> indices;
std::vector<Vector3> normals;
std::tie(indices, normals) = MeshTools::generateFlatNormals({
0, 1, 2,
@ -62,7 +62,7 @@ void GenerateFlatNormalsTest::generate() {
{1.0f, 0.0f, 0.0f}
});
CORRADE_COMPARE(indices, (std::vector<std::uint32_t>{
CORRADE_COMPARE(indices, (std::vector<UnsignedInt>{
0, 0, 0,
1, 1, 1
}));

32
src/MeshTools/Test/InterleaveTest.cpp

@ -48,30 +48,30 @@ InterleaveTest::InterleaveTest() {
void InterleaveTest::attributeCount() {
std::stringstream ss;
Error::setOutput(&ss);
CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector<std::int8_t>{0, 1, 2},
std::vector<std::int8_t>{0, 1, 2, 3, 4, 5})), std::size_t(0));
CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector<Byte>{0, 1, 2},
std::vector<Byte>{0, 1, 2, 3, 4, 5})), std::size_t(0));
CORRADE_COMPARE(ss.str(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.\n");
CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector<std::int8_t>{0, 1, 2},
std::vector<std::int8_t>{3, 4, 5})), std::size_t(3));
CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector<Byte>{0, 1, 2},
std::vector<Byte>{3, 4, 5})), std::size_t(3));
}
void InterleaveTest::attributeCountGaps() {
CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector<std::int8_t>{0, 1, 2}, 3,
std::vector<std::int8_t>{3, 4, 5}, 5)), std::size_t(3));
CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector<Byte>{0, 1, 2}, 3,
std::vector<Byte>{3, 4, 5}, 5)), std::size_t(3));
/* No arrays from which to get size */
CORRADE_COMPARE(Implementation::Interleave::attributeCount(3, 5), ~std::size_t(0));
}
void InterleaveTest::stride() {
CORRADE_COMPARE(Implementation::Interleave::stride(std::vector<std::int8_t>()), std::size_t(1));
CORRADE_COMPARE(Implementation::Interleave::stride(std::vector<std::int32_t>()), std::size_t(4));
CORRADE_COMPARE((Implementation::Interleave::stride(std::vector<std::int8_t>(), std::vector<std::int32_t>())), std::size_t(5));
CORRADE_COMPARE(Implementation::Interleave::stride(std::vector<Byte>()), std::size_t(1));
CORRADE_COMPARE(Implementation::Interleave::stride(std::vector<Int>()), std::size_t(4));
CORRADE_COMPARE((Implementation::Interleave::stride(std::vector<Byte>(), std::vector<Int>())), std::size_t(5));
}
void InterleaveTest::strideGaps() {
CORRADE_COMPARE((Implementation::Interleave::stride(2, std::vector<std::int8_t>(), 1, std::vector<std::int32_t>(), 12)), std::size_t(20));
CORRADE_COMPARE((Implementation::Interleave::stride(2, std::vector<Byte>(), 1, std::vector<Int>(), 12)), std::size_t(20));
}
void InterleaveTest::write() {
@ -79,9 +79,9 @@ void InterleaveTest::write() {
std::size_t stride;
char* data;
std::tie(attributeCount, stride, data) = MeshTools::interleave(
std::vector<std::int8_t>{0, 1, 2},
std::vector<std::int32_t>{3, 4, 5},
std::vector<std::int16_t>{6, 7, 8});
std::vector<Byte>{0, 1, 2},
std::vector<Int>{3, 4, 5},
std::vector<Short>{6, 7, 8});
CORRADE_COMPARE(attributeCount, std::size_t(3));
CORRADE_COMPARE(stride, std::size_t(7));
@ -108,9 +108,9 @@ void InterleaveTest::writeGaps() {
std::size_t stride;
char* data;
std::tie(attributeCount, stride, data) = MeshTools::interleave(
std::vector<std::int8_t>{0, 1, 2}, 3,
std::vector<std::int32_t>{3, 4, 5},
std::vector<std::int16_t>{6, 7, 8}, 2);
std::vector<Byte>{0, 1, 2}, 3,
std::vector<Int>{3, 4, 5},
std::vector<Short>{6, 7, 8}, 2);
CORRADE_COMPARE(attributeCount, std::size_t(3));
CORRADE_COMPARE(stride, std::size_t(12));

8
src/MeshTools/Test/SubdivideTest.cpp

@ -33,7 +33,7 @@ class SubdivideTest: public Corrade::TestSuite::Tester {
class Vector1 {
public:
static const std::size_t Size = 1;
typedef std::int32_t Type;
typedef Int Type;
Vector1(): data(0) {}
Vector1(Type i): data(i) {}
@ -59,20 +59,20 @@ void SubdivideTest::wrongIndexCount() {
Error::setOutput(&ss);
std::vector<Vector1> positions;
std::vector<std::uint32_t> indices{0, 1};
std::vector<UnsignedInt> indices{0, 1};
MeshTools::subdivide(indices, positions, interpolator);
CORRADE_COMPARE(ss.str(), "MeshTools::subdivide(): index count is not divisible by 3!\n");
}
void SubdivideTest::subdivide() {
std::vector<Vector1> positions{0, 2, 6, 8};
std::vector<std::uint32_t> indices{0, 1, 2, 1, 2, 3};
std::vector<UnsignedInt> indices{0, 1, 2, 1, 2, 3};
MeshTools::subdivide(indices, positions, interpolator);
CORRADE_COMPARE(indices.size(), 24);
CORRADE_VERIFY(positions == (std::vector<Vector1>{0, 2, 6, 8, 1, 4, 3, 4, 7, 5}));
CORRADE_COMPARE(indices, (std::vector<std::uint32_t>{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3}));
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);

12
src/MeshTools/Test/TipsifyTest.cpp

@ -27,7 +27,7 @@ class TipsifyTest: public Corrade::TestSuite::Tester {
void tipsify();
private:
std::vector<std::uint32_t> indices;
std::vector<UnsignedInt> indices;
std::size_t vertexCount;
};
@ -75,10 +75,10 @@ TipsifyTest::TipsifyTest(): indices{
}
void TipsifyTest::buildAdjacency() {
std::vector<std::uint32_t> liveTriangleCount, neighborOffset, neighbors;
std::vector<UnsignedInt> liveTriangleCount, neighborOffset, neighbors;
Implementation::Tipsify(indices, vertexCount).buildAdjacency(liveTriangleCount, neighborOffset, neighbors);
CORRADE_COMPARE(liveTriangleCount, (std::vector<std::uint32_t>{
CORRADE_COMPARE(liveTriangleCount, (std::vector<UnsignedInt>{
1, 3, 3, 2,
4, 6, 6, 2,
2, 6, 6, 4,
@ -86,7 +86,7 @@ void TipsifyTest::buildAdjacency() {
1, 1, 1
}));
CORRADE_COMPARE(neighborOffset, (std::vector<std::uint32_t>{
CORRADE_COMPARE(neighborOffset, (std::vector<UnsignedInt>{
0, 1, 4, 7,
9, 13, 19, 25,
27, 29, 35, 41,
@ -94,7 +94,7 @@ void TipsifyTest::buildAdjacency() {
54, 55, 56, 57
}));
CORRADE_COMPARE(neighbors, (std::vector<std::uint32_t>{
CORRADE_COMPARE(neighbors, (std::vector<UnsignedInt>{
0,
0, 7, 11,
2, 7, 13,
@ -122,7 +122,7 @@ void TipsifyTest::buildAdjacency() {
void TipsifyTest::tipsify() {
MeshTools::tipsify(indices, vertexCount, 3);
CORRADE_COMPARE(indices, (std::vector<std::uint32_t>{
CORRADE_COMPARE(indices, (std::vector<UnsignedInt>{
4, 1, 0,
9, 5, 4,
1, 4, 5,

30
src/MeshTools/Tipsify.cpp

@ -22,37 +22,37 @@ namespace Magnum { namespace MeshTools { namespace Implementation {
void Tipsify::operator()(std::size_t cacheSize) {
/* Neighboring triangles for each vertex, per-vertex live triangle count */
std::vector<std::uint32_t> liveTriangleCount, neighborPosition, neighbors;
std::vector<UnsignedInt> liveTriangleCount, neighborPosition, neighbors;
buildAdjacency(liveTriangleCount, neighborPosition, neighbors);
/* Global time, per-vertex caching timestamps, per-triangle emmited flag */
std::uint32_t time = cacheSize+1;
std::vector<std::uint32_t> timestamp(vertexCount);
UnsignedInt time = cacheSize+1;
std::vector<UnsignedInt> timestamp(vertexCount);
std::vector<bool> emitted(indices.size()/3);
/* Dead-end vertex stack */
std::stack<std::uint32_t> deadEndStack;
std::stack<UnsignedInt> deadEndStack;
/* Output index buffer */
std::vector<std::uint32_t> outputIndices;
std::vector<UnsignedInt> outputIndices;
outputIndices.reserve(indices.size());
/* Starting vertex for fanning, cursor */
std::uint32_t fanningVertex = 0;
std::uint32_t i = 0;
UnsignedInt fanningVertex = 0;
UnsignedInt i = 0;
while(fanningVertex != 0xFFFFFFFFu) {
/* Array with candidates for next fanning vertex (in 1-ring around
fanning vertex) */
std::vector<std::uint32_t> candidates;
std::vector<UnsignedInt> candidates;
/* For all neighbors of fanning vertex */
for(std::uint32_t ti = neighborPosition[fanningVertex], t = neighbors[ti]; ti != neighborPosition[fanningVertex+1]; t = neighbors[++ti]) {
for(UnsignedInt ti = neighborPosition[fanningVertex], t = neighbors[ti]; ti != neighborPosition[fanningVertex+1]; t = neighbors[++ti]) {
/* Continue if already emitted */
if(emitted[t]) continue;
emitted[t] = true;
/* Write all vertices of the triangle to output buffer */
for(std::uint32_t vi = 0, v = indices[t*3]; vi != 3; v = indices[++vi+t*3]) {
for(UnsignedInt vi = 0, v = indices[t*3]; vi != 3; v = indices[++vi+t*3]) {
outputIndices.push_back(v);
/* Add to dead end stack and candidates array */
@ -73,15 +73,15 @@ void Tipsify::operator()(std::size_t cacheSize) {
fanningVertex = 0xFFFFFFFFu;
/* Go through candidates in 1-ring around fanning vertex */
std::int32_t candidatePriority = -1;
for(std::uint32_t v: candidates) {
Int candidatePriority = -1;
for(UnsignedInt v: candidates) {
/* Skip if it doesn't have any live triangles */
if(!liveTriangleCount[v]) continue;
/* Get most fresh candidate which will still be in cache even
after fanning. Every fanned triangle will generate at most
two cache misses, thus 2*liveTriangleCount */
std::int32_t priority = 0;
Int priority = 0;
if(time-timestamp[v]+2*liveTriangleCount[v] <= cacheSize)
priority = time-timestamp[v];
if(priority > candidatePriority) {
@ -117,7 +117,7 @@ void Tipsify::operator()(std::size_t cacheSize) {
std::swap(indices, outputIndices);
}
void Tipsify::buildAdjacency(std::vector<std::uint32_t>& liveTriangleCount, std::vector<std::uint32_t>& neighborOffset, std::vector<std::uint32_t>& neighbors) const {
void Tipsify::buildAdjacency(std::vector<UnsignedInt>& liveTriangleCount, std::vector<UnsignedInt>& neighborOffset, std::vector<UnsignedInt>& neighbors) const {
/* How many times is each vertex referenced == count of neighboring
triangles for each vertex */
liveTriangleCount.clear();
@ -132,7 +132,7 @@ void Tipsify::buildAdjacency(std::vector<std::uint32_t>& liveTriangleCount, std:
neighborOffset.clear();
neighborOffset.reserve(vertexCount+1);
neighborOffset.push_back(0);
std::uint32_t sum = 0;
UnsignedInt sum = 0;
for(std::size_t i = 0; i != vertexCount; ++i) {
neighborOffset.push_back(sum);
sum += liveTriangleCount[i];

12
src/MeshTools/Tipsify.h

@ -19,9 +19,9 @@
* @brief Function Magnum::MeshTools::tipsify()
*/
#include <cstdint>
#include <vector>
#include "Types.h"
#include "magnumMeshToolsVisibility.h"
namespace Magnum { namespace MeshTools {
@ -31,7 +31,7 @@ namespace Implementation {
class MAGNUM_MESHTOOLS_EXPORT Tipsify {
public:
inline Tipsify(std::vector<std::uint32_t>& indices, std::uint32_t vertexCount): indices(indices), vertexCount(vertexCount) {}
inline Tipsify(std::vector<UnsignedInt>& indices, UnsignedInt vertexCount): indices(indices), vertexCount(vertexCount) {}
void operator()(std::size_t cacheSize);
@ -42,11 +42,11 @@ class MAGNUM_MESHTOOLS_EXPORT Tipsify {
* (used internally).
* @todo Export only for unit test, hide otherwise
*/
void buildAdjacency(std::vector<std::uint32_t>& liveTriangleCount, std::vector<std::uint32_t>& neighborOffset, std::vector<std::uint32_t>& neighbors) const;
void buildAdjacency(std::vector<UnsignedInt>& liveTriangleCount, std::vector<UnsignedInt>& neighborOffset, std::vector<UnsignedInt>& neighbors) const;
private:
std::vector<std::uint32_t>& indices;
const std::uint32_t vertexCount;
std::vector<UnsignedInt>& indices;
const UnsignedInt vertexCount;
};
}
@ -64,7 +64,7 @@ array for beter usage of post-transform vertex cache. Algorithm used:
for Vertex Locality and Reduced Overdraw, SIGGRAPH 2007,
http://gfx.cs.princeton.edu/pubs/Sander_2007_%3ETR/index.php*.
*/
inline void tipsify(std::vector<std::uint32_t>& indices, std::uint32_t vertexCount, std::size_t cacheSize) {
inline void tipsify(std::vector<UnsignedInt>& indices, UnsignedInt vertexCount, std::size_t cacheSize) {
Implementation::Tipsify(indices, vertexCount)(cacheSize);
}

Loading…
Cancel
Save