From 87cc565c1ac7105c12880be1d21f49b3cea31dc7 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 20 Nov 2014 18:16:57 -0800 Subject: [PATCH] I believe this should be a better hash function for the voxel coordinates. --- interface/src/MetavoxelSystem.cpp | 6 +++--- interface/src/MetavoxelSystem.h | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index 7129ac4e88..b0a5d3324c 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -1011,7 +1011,7 @@ void VoxelPoint::setNormal(const glm::vec3& normal) { } VoxelBuffer::VoxelBuffer(const QVector& vertices, const QVector& indices, const QVector& hermite, - const QMultiHash& quadIndices, int size, const QVector& materials) : + const QMultiHash& quadIndices, int size, const QVector& materials) : _vertices(vertices), _indices(indices), _hermite(hermite), @@ -1056,7 +1056,7 @@ bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::ve int max = _size - 2; int x = qMin((int)floors.x, max), y = qMin((int)floors.y, max), z = qMin((int)floors.z, max); forever { - for (QMultiHash::const_iterator it = _quadIndices.constFind(qRgb(x + 1, y + 1, z + 1)); + for (QMultiHash::const_iterator it = _quadIndices.constFind(qRgb(x + 1, y + 1, z + 1)); it != _quadIndices.constEnd(); it++) { const int* indices = _indices.constData() + *it; if (findRayTriangleIntersection(origin, direction, _vertices.at(indices[0]).vertex, @@ -1311,7 +1311,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { QVector vertices; QVector indices; QVector hermiteSegments; - QMultiHash quadIndices; + QMultiHash quadIndices; // see http://www.frankpetterson.com/publications/dualcontour/dualcontour.pdf for a description of the // dual contour algorithm for generating meshes from voxel data using Hermite-tagged edges diff --git a/interface/src/MetavoxelSystem.h b/interface/src/MetavoxelSystem.h index 90a04ae417..dfbabbb2bf 100644 --- a/interface/src/MetavoxelSystem.h +++ b/interface/src/MetavoxelSystem.h @@ -308,12 +308,27 @@ public: void setNormal(const glm::vec3& normal); }; +/// A container for a coordinate within a voxel block. +class VoxelCoord { +public: + QRgb encoded; + + VoxelCoord(QRgb encoded) : encoded(encoded) { } + + bool operator==(const VoxelCoord& other) const { return encoded == other.encoded; } +}; + +inline uint qHash(const VoxelCoord& coord, uint seed) { + // 31 is just an arbitrary prime number + return qHash(qRed(coord.encoded) + 31 * (qGreen(coord.encoded) + 31 * qBlue(coord.encoded)), seed); +} + /// Contains the information necessary to render a voxel block. class VoxelBuffer : public BufferData { public: VoxelBuffer(const QVector& vertices, const QVector& indices, const QVector& hermite, - const QMultiHash& quadIndices, int size, const QVector& materials = + const QMultiHash& quadIndices, int size, const QVector& materials = QVector()); /// Finds the first intersection between the described ray and the voxel data. @@ -328,7 +343,7 @@ private: QVector _vertices; QVector _indices; QVector _hermite; - QMultiHash _quadIndices; + QMultiHash _quadIndices; int _size; int _vertexCount; int _indexCount;