Skip to content

Commit

Permalink
use 64-bit integers for MeshGL64
Browse files Browse the repository at this point in the history
  • Loading branch information
pca006132 committed Sep 19, 2024
1 parent 7986564 commit d75bc5d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 34 deletions.
31 changes: 11 additions & 20 deletions src/manifold/include/manifold/manifold.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,12 @@ class CsgLeafNode;
* @{
*/

template <typename Precision>
template <typename Precision, typename I = uint32_t>
struct MeshGLP {
/// Number of property vertices
uint32_t NumVert() const {
ASSERT(vertProperties.size() / numProp <
static_cast<size_t>(std::numeric_limits<uint32_t>::max()),
std::out_of_range("mesh too large for MeshGL"));
return vertProperties.size() / numProp;
};
I NumVert() const { return vertProperties.size() / numProp; };
/// Number of triangles
uint32_t NumTri() const {
ASSERT(triVerts.size() / 3 <
static_cast<size_t>(std::numeric_limits<uint32_t>::max()),
std::out_of_range("mesh too large for MeshGL"));
return triVerts.size() / 3;
};
I NumTri() const { return triVerts.size() / 3; };
/// Number of properties per vertex, always >= 3.
uint32_t numProp = 3;
/// Flat, GL-style interleaved list of all vertex properties: propVal =
Expand All @@ -61,14 +51,14 @@ struct MeshGLP {
std::vector<Precision> vertProperties;
/// The vertex indices of the three triangle corners in CCW (from the outside)
/// order, for each triangle.
std::vector<uint32_t> triVerts;
std::vector<I> triVerts;
/// Optional: A list of only the vertex indicies that need to be merged to
/// reconstruct the manifold.
std::vector<uint32_t> mergeFromVert;
std::vector<I> mergeFromVert;
/// Optional: The same length as mergeFromVert, and the corresponding value
/// contains the vertex to merge with. It will have an identical position, but
/// the other properties may differ.
std::vector<uint32_t> mergeToVert;
std::vector<I> mergeToVert;
/// Optional: Indicates runs of triangles that correspond to a particular
/// input mesh instance. The runs encompass all of triVerts and are sorted
/// by runOriginalID. Run i begins at triVerts[runIndex[i]] and ends at
Expand All @@ -95,7 +85,7 @@ struct MeshGLP {
/// supplying faceIDs, ensure that triangles with the same ID are in fact
/// coplanar and have consistent properties (within some tolerance) or the
/// output will be surprising.
std::vector<uint32_t> faceID;
std::vector<I> faceID;
/// Optional: The X-Y-Z-W weighted tangent vectors for smooth Refine(). If
/// non-empty, must be exactly four times as long as Mesh.triVerts. Indexed
/// as 4 * (3 * tri + i) + j, i < 3, j < 4, representing the tangent value
Expand All @@ -117,9 +107,10 @@ struct MeshGLP {
vertProperties[offset + 2]);
}

ivec3 GetTriVerts(size_t i) const {
glm::vec<3, I> GetTriVerts(size_t i) const {
size_t offset = 3 * i;
return ivec3(triVerts[offset], triVerts[offset + 1], triVerts[offset + 2]);
return glm::vec<3, I>(triVerts[offset], triVerts[offset + 1],
triVerts[offset + 2]);
}
};

Expand All @@ -130,7 +121,7 @@ struct MeshGLP {
* store this missing information, allowing the manifold to be reconstructed.
*/
using MeshGL = MeshGLP<float>;
using MeshGL64 = MeshGLP<double>;
using MeshGL64 = MeshGLP<double, size_t>;
/** @} */

/** @defgroup Core
Expand Down
11 changes: 6 additions & 5 deletions src/manifold/src/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ struct Manifold::Impl {
enum class Shape { Tetrahedron, Cube, Octahedron };
Impl(Shape, const mat4x3 = mat4x3(1));

template <typename Precision>
Impl(const MeshGLP<Precision>& meshGL) {
template <typename Precision, typename I>
Impl(const MeshGLP<Precision, I>& meshGL) {
const uint32_t numVert = meshGL.NumVert();
const uint32_t numTri = meshGL.NumTri();

Expand Down Expand Up @@ -169,7 +169,7 @@ struct Manifold::Impl {
for (size_t i = 0; i < numTri; ++i) {
ivec3 tri;
for (const size_t j : {0, 1, 2}) {
uint32_t vert = meshGL.triVerts[3 * i + j];
uint32_t vert = (uint32_t)meshGL.triVerts[3 * i + j];
if (vert >= numVert) {
MarkFailure(Error::VertexOutOfBounds);
return;
Expand All @@ -183,8 +183,9 @@ struct Manifold::Impl {
}
if (numProp > 0) {
meshRelation_.triProperties.push_back(
ivec3(meshGL.triVerts[3 * i], meshGL.triVerts[3 * i + 1],
meshGL.triVerts[3 * i + 2]));
ivec3((uint32_t)meshGL.triVerts[3 * i],
(uint32_t)meshGL.triVerts[3 * i + 1],
(uint32_t)meshGL.triVerts[3 * i + 2]));
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/manifold/src/manifold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ Manifold Halfspace(Box bBox, vec3 normal, double originOffset) {
return cutter.Rotate(0.0, yDeg, zDeg);
}

template <typename Precision>
MeshGLP<Precision> GetMeshGLImpl(const manifold::Manifold::Impl& impl,
ivec3 normalIdx) {
template <typename Precision, typename I>
MeshGLP<Precision, I> GetMeshGLImpl(const manifold::Manifold::Impl& impl,
ivec3 normalIdx) {
ZoneScoped;
const int numProp = impl.NumProp();
const int numVert = impl.NumPropVert();
Expand All @@ -69,7 +69,7 @@ MeshGLP<Precision> GetMeshGLImpl(const manifold::Manifold::Impl& impl,
const bool updateNormals =
!isOriginal && glm::all(glm::greaterThan(normalIdx, ivec3(2)));

MeshGLP<Precision> out;
MeshGLP<Precision, I> out;
out.precision =
std::max(impl.precision_,
std::numeric_limits<Precision>::epsilon() * impl.bBox_.Scale());
Expand Down Expand Up @@ -101,7 +101,7 @@ MeshGLP<Precision> GetMeshGLImpl(const manifold::Manifold::Impl& impl,

std::vector<mat3> runNormalTransform;
auto addRun = [updateNormals, isOriginal](
MeshGLP<Precision>& out,
MeshGLP<Precision, I>& out,
std::vector<mat3>& runNormalTransform, int tri,
const manifold::Manifold::Impl::Relation& rel) {
out.runIndex.push_back(3 * tri);
Expand Down Expand Up @@ -352,7 +352,7 @@ Mesh Manifold::GetMesh() const {
*/
MeshGL Manifold::GetMeshGL(ivec3 normalIdx) const {
const Impl& impl = *GetCsgLeafNode().GetImpl();
return GetMeshGLImpl<float>(impl, normalIdx);
return GetMeshGLImpl<float, uint32_t>(impl, normalIdx);
}

/**
Expand All @@ -370,7 +370,7 @@ MeshGL Manifold::GetMeshGL(ivec3 normalIdx) const {
*/
MeshGL64 Manifold::GetMeshGL64(ivec3 normalIdx) const {
const Impl& impl = *GetCsgLeafNode().GetImpl();
return GetMeshGLImpl<double>(impl, normalIdx);
return GetMeshGLImpl<double, size_t>(impl, normalIdx);

Check warning on line 373 in src/manifold/src/manifold.cpp

View check run for this annotation

Codecov / codecov/patch

src/manifold/src/manifold.cpp#L373

Added line #L373 was not covered by tests
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/manifold/src/sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ struct ReindexFace {
}
};

template <typename Precision>
bool MergeMeshGLP(MeshGLP<Precision>& mesh) {
template <typename Precision, typename I>
bool MergeMeshGLP(MeshGLP<Precision, I>& mesh) {
ZoneScoped;
std::multiset<std::pair<int, int>> openEdges;

Expand Down

0 comments on commit d75bc5d

Please sign in to comment.