Skip to content

Commit

Permalink
use std::move to avoid copying
Browse files Browse the repository at this point in the history
  • Loading branch information
pca006132 committed May 7, 2022
1 parent a3dbe15 commit 168fd07
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions manifold/src/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,17 +504,19 @@ void Manifold::Impl::CreateHalfedges(const VecDH<glm::ivec3>& triVerts) {
*/
void Manifold::Impl::CreateAndFixHalfedges(const VecDH<glm::ivec3>& triVerts) {
const int numTri = triVerts.size();
// drop the old value first to avoid copy
halfedge_.resize(0);
halfedge_.resize(3 * numTri);
VecDH<TmpEdge> edge(3 * numTri);
thrust::for_each_n(zip(countAt(0), triVerts.begin()), numTri,
Tri2Halfedges({halfedge_.ptrH(), edge.ptrH()}));
thrust::for_each_n(zip(countAt(0), triVerts.beginD()), numTri,
Tri2Halfedges({halfedge_.ptrD(), edge.ptrD()}));
// Stable sort is required here so that halfedges from the same face are
// paired together (the triangles were created in face order). In some
// degenerate situations the triangulator can add the same internal edge in
// two different faces, causing this edge to not be 2-manifold. We detect this
// and fix it by swapping one of the identical edges, so it is important that
// we have the edges paired according to their face.
std::stable_sort(edge.begin(), edge.end());
thrust::stable_sort(edge.beginD(), edge.endD());
thrust::for_each_n(thrust::host, countAt(0), halfedge_.size() / 2,
LinkHalfedges({halfedge_.ptrH(), edge.cptrH()}));
thrust::for_each(thrust::host, countAt(1), countAt(halfedge_.size() / 2),
Expand Down
2 changes: 1 addition & 1 deletion manifold/src/smoothing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ Manifold::Impl::MeshRelationD Manifold::Impl::Subdivide(int n) {
MeshRelationD relation;
relation.barycentric.resize(numTri * VertsPerTri(n + 1));
relation.triBary.resize(n * n * numTri);
MeshRelationD oldMeshRelation = meshRelation_;
MeshRelationD oldMeshRelation = std::move(meshRelation_);
meshRelation_.barycentric.resize(relation.barycentric.size());
meshRelation_.triBary.resize(relation.triBary.size());

Expand Down
4 changes: 2 additions & 2 deletions manifold/src/sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ void Manifold::Impl::GatherFaces(const VecDH<int>& faceNew2Old) {

if (faceNormal_.size() == NumTri()) Permute(faceNormal_, faceNew2Old);

VecDH<Halfedge> oldHalfedge(halfedge_);
VecDH<glm::vec4> oldHalfedgeTangent(halfedgeTangent_);
VecDH<Halfedge> oldHalfedge(std::move(halfedge_));
VecDH<glm::vec4> oldHalfedgeTangent(std::move(halfedgeTangent_));
VecDH<int> faceOld2New(oldHalfedge.size() / 3);
thrust::scatter(countAt(0), countAt(numTri), faceNew2Old.beginD(),
faceOld2New.beginD());
Expand Down

0 comments on commit 168fd07

Please sign in to comment.