Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Misc. changes #940

Merged
merged 7 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bindings/c/include/manifold/manifoldc.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ ManifoldManifold *manifold_as_original(void *mem, ManifoldManifold *m);

int manifold_is_empty(ManifoldManifold *m);
ManifoldError manifold_status(ManifoldManifold *m);
int manifold_num_vert(ManifoldManifold *m);
int manifold_num_edge(ManifoldManifold *m);
int manifold_num_tri(ManifoldManifold *m);
size_t manifold_num_vert(ManifoldManifold *m);
size_t manifold_num_edge(ManifoldManifold *m);
size_t manifold_num_tri(ManifoldManifold *m);
ManifoldBox *manifold_bounding_box(void *mem, ManifoldManifold *m);
double manifold_precision(ManifoldManifold *m);
int manifold_genus(ManifoldManifold *m);
Expand Down
6 changes: 3 additions & 3 deletions bindings/c/manifoldc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,9 @@
return to_c(error);
}

int manifold_num_vert(ManifoldManifold *m) { return from_c(m)->NumVert(); }
int manifold_num_edge(ManifoldManifold *m) { return from_c(m)->NumEdge(); }
int manifold_num_tri(ManifoldManifold *m) { return from_c(m)->NumTri(); }
size_t manifold_num_vert(ManifoldManifold *m) { return from_c(m)->NumVert(); }
size_t manifold_num_edge(ManifoldManifold *m) { return from_c(m)->NumEdge(); }

Check warning on line 508 in bindings/c/manifoldc.cpp

View check run for this annotation

Codecov / codecov/patch

bindings/c/manifoldc.cpp#L507-L508

Added lines #L507 - L508 were not covered by tests
size_t manifold_num_tri(ManifoldManifold *m) { return from_c(m)->NumTri(); }
int manifold_genus(ManifoldManifold *m) { return from_c(m)->Genus(); }

ManifoldProperties manifold_get_properties(ManifoldManifold *m) {
Expand Down
50 changes: 21 additions & 29 deletions src/manifold/include/manifold/manifold.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once
#include <functional>
#include <memory>
#include <optional>

#include "manifold/common.h"
#include "manifold/vec_view.h"
Expand All @@ -37,46 +38,36 @@ class CsgLeafNode;
* @{
*/

template <typename Precision>
template <typename Precision, typename I = uint32_t>
pca006132 marked this conversation as resolved.
Show resolved Hide resolved
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;
I numProp = 3;
/// Flat, GL-style interleaved list of all vertex properties: propVal =
/// vertProperties[vert * numProp + propIdx]. The first three properties are
/// always the position x, y, z.
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
/// triVerts[runIndex[i+1]]. All runIndex values are divisible by 3. Returned
/// runIndex will always be 1 longer than runOriginalID, but same length is
/// also allowed as input: triVerts.size() will be automatically appended in
/// this case.
std::vector<uint32_t> runIndex;
std::vector<I> runIndex;
/// Optional: The OriginalID of the mesh this triangle run came from. This ID
/// is ideal for reapplying materials to the output mesh. Multiple runs may
/// have the same ID, e.g. representing different copies of the same input
Expand All @@ -95,7 +86,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 +108,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 +122,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 Expand Up @@ -231,11 +223,11 @@ class Manifold {
InvalidConstruction,
};
Error Status() const;
int NumVert() const;
int NumEdge() const;
int NumTri() const;
int NumProp() const;
int NumPropVert() const;
size_t NumVert() const;
size_t NumEdge() const;
size_t NumTri() const;
size_t NumProp() const;
size_t NumPropVert() const;
Box BoundingBox() const;
double Precision() const;
int Genus() const;
Expand Down Expand Up @@ -314,8 +306,8 @@ class Manifold {
*/
///@{
bool MatchesTriNormals() const;
int NumDegenerateTris() const;
int NumOverlaps(const Manifold& second) const;
size_t NumDegenerateTris() const;
size_t NumOverlaps(const Manifold& second) const;
///@}

struct Impl;
Expand Down
11 changes: 11 additions & 0 deletions src/manifold/src/boolean_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,22 @@
const int c3 = op == OpType::Intersect ? 1 : -1;

if (inP_.IsEmpty()) {
if (inP_.status_ != Manifold::Error::NoError ||
inQ_.status_ != Manifold::Error::NoError) {
auto impl = Manifold::Impl();
impl.status_ = Manifold::Error::InvalidConstruction;
return impl;

Check warning on line 678 in src/manifold/src/boolean_result.cpp

View check run for this annotation

Codecov / codecov/patch

src/manifold/src/boolean_result.cpp#L676-L678

Added lines #L676 - L678 were not covered by tests
}
if (!inQ_.IsEmpty() && op == OpType::Add) {
return inQ_;
}
return Manifold::Impl();
} else if (inQ_.IsEmpty()) {
if (inQ_.status_ != Manifold::Error::NoError) {
auto impl = Manifold::Impl();
impl.status_ = Manifold::Error::InvalidConstruction;
return impl;

Check warning on line 688 in src/manifold/src/boolean_result.cpp

View check run for this annotation

Codecov / codecov/patch

src/manifold/src/boolean_result.cpp#L686-L688

Added lines #L686 - L688 were not covered by tests
}
if (op == OpType::Intersect) {
return Manifold::Impl();
}
Expand Down
2 changes: 1 addition & 1 deletion src/manifold/src/constructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ std::vector<Manifold> Manifold::Decompose() const {
Vec<int> faceNew2Old(NumTri());
const auto& halfedge = pImpl_->halfedge_;
const int nFace =
copy_if(countAt(0), countAt(NumTri()), faceNew2Old.begin(),
copy_if(countAt(0_uz), countAt(NumTri()), faceNew2Old.begin(),
[i, &vertLabel, &halfedge](int face) {
return vertLabel[halfedge[3 * face].startVert] == i;
}) -
Expand Down
13 changes: 8 additions & 5 deletions src/manifold/src/csg_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@
std::vector<int> propVertIndices;
int numPropOut = 0;
for (auto &node : nodes) {
if (node->pImpl_->status_ != Manifold::Error::NoError) {
Manifold::Impl impl;
impl.status_ = Manifold::Error::InvalidConstruction;
return impl;

Check warning on line 189 in src/manifold/src/csg_tree.cpp

View check run for this annotation

Codecov / codecov/patch

src/manifold/src/csg_tree.cpp#L187-L189

Added lines #L187 - L189 were not covered by tests
}
double nodeOldScale = node->pImpl_->bBox_.Scale();
double nodeNewScale =
node->pImpl_->bBox_.Transform(node->transform_).Scale();
Expand Down Expand Up @@ -478,8 +483,6 @@
continue;
}
group.run([&, a, b]() {
const Manifold::Impl *aImpl;
const Manifold::Impl *bImpl;
pca006132 marked this conversation as resolved.
Show resolved Hide resolved
Boolean3 boolean(*getImplPtr(a), *getImplPtr(b), operation);
queue.emplace(
std::make_shared<Manifold::Impl>(boolean.Result(operation)));
Expand Down Expand Up @@ -507,11 +510,11 @@
results.pop_back();
// boolean operation
Boolean3 boolean(*a, *b, operation);
auto result = std::make_shared<Manifold::Impl>(boolean.Result(operation));
if (results.size() == 0) {
return std::make_shared<Manifold::Impl>(boolean.Result(operation));
return result;
}
results.push_back(
std::make_shared<const Manifold::Impl>(boolean.Result(operation)));
results.push_back(result);
std::push_heap(results.begin(), results.end(), cmpFn);
}
return std::make_shared<Manifold::Impl>(*results.front());
Expand Down
4 changes: 4 additions & 0 deletions src/manifold/src/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@
if (transform_ == mat4x3(1.0)) return *this;
auto policy = autoPolicy(NumVert());
Impl result;
if (status_ != Manifold::Error::NoError) {
result.status_ = status_;
return result;

Check warning on line 575 in src/manifold/src/impl.cpp

View check run for this annotation

Codecov / codecov/patch

src/manifold/src/impl.cpp#L574-L575

Added lines #L574 - L575 were not covered by tests
}
result.collider_ = collider_;
result.meshRelation_ = meshRelation_;
result.precision_ = precision_;
Expand Down
19 changes: 10 additions & 9 deletions src/manifold/src/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
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 @@ -133,15 +133,15 @@

Vec<TriRef> triRef;
if (!meshGL.runOriginalID.empty()) {
std::vector<uint32_t> runIndex = meshGL.runIndex;
const uint32_t runEnd = meshGL.triVerts.size();
auto runIndex = meshGL.runIndex;
const auto runEnd = meshGL.triVerts.size();

Check warning on line 137 in src/manifold/src/impl.h

View check run for this annotation

Codecov / codecov/patch

src/manifold/src/impl.h#L137

Added line #L137 was not covered by tests
if (runIndex.empty()) {
runIndex = {0, runEnd};
runIndex = {0, static_cast<I>(runEnd)};
} else if (runIndex.size() == meshGL.runOriginalID.size()) {
runIndex.push_back(runEnd);
}
triRef.resize(meshGL.NumTri());
const int startID = Impl::ReserveIDs(meshGL.runOriginalID.size());
const auto startID = Impl::ReserveIDs(meshGL.runOriginalID.size());
for (size_t i = 0; i < meshGL.runOriginalID.size(); ++i) {
const int meshID = startID + i;
const int originalID = meshGL.runOriginalID[i];
Expand Down Expand Up @@ -169,7 +169,7 @@
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 @@
}
if (numProp > 0) {
meshRelation_.triProperties.push_back(
ivec3(meshGL.triVerts[3 * i], meshGL.triVerts[3 * i + 1],
meshGL.triVerts[3 * i + 2]));
ivec3(static_cast<uint32_t>(meshGL.triVerts[3 * i]),
static_cast<uint32_t>(meshGL.triVerts[3 * i + 1]),
static_cast<uint32_t>(meshGL.triVerts[3 * i + 2])));
}
}
}
Expand Down
Loading
Loading