Skip to content

Commit bc42484

Browse files
committed
Merge on Distance: accelerate new mesh creation
1 parent 0361977 commit bc42484

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/slg/shapes/merge_on_distance.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,18 +673,28 @@ ClusterMap mergePoints(const Point * points, u_int numPoints, u_int tolerance) {
673673
// Replace each variable with interpolated value
674674
luxrays::ExtTriangleMesh* RecreateMesh(
675675
const luxrays::ExtTriangleMesh& srcMesh,
676-
const ClusterMap& clusters
676+
const ClusterMap& clustermap
677677
) {
678678
const auto numPoints = srcMesh.GetTotalVertexCount();
679679
const auto srcPoints = srcMesh.GetVertices();
680-
const auto numNewPoints = clusters.size();
680+
const auto numNewPoints = clustermap.size();
681681

682682
// Nota: we use smart pointers until the creation of the ExtTriangleMesh,
683683
// so that the memory is automatically released if something goes wrong in
684684
// the process. Please keep it so.
685685

686+
std::vector<Cluster> clusters;
687+
clusters.reserve(numNewPoints);
688+
std::transform(
689+
std::make_move_iterator(clustermap.begin()),
690+
std::make_move_iterator(clustermap.end()),
691+
std::back_inserter(clusters),
692+
[](auto &kv){ return kv.second;}
693+
);
694+
686695
std::vector<u_int> pointMap(numPoints);
687696

697+
// Allocate mesh data structures
688698
// Points
689699
std::unique_ptr<Point> newPoints{
690700
luxrays::ExtTriangleMesh::AllocVerticesBuffer(numNewPoints)
@@ -747,11 +757,9 @@ luxrays::ExtTriangleMesh* RecreateMesh(
747757
tbb::blocked_range<size_t>(0, numNewPoints, grain),
748758

749759
[&](tbb::blocked_range<size_t>& r) {
750-
auto it = clusters.begin();
751-
std::advance(it, r.begin());
752760

753-
for (auto newIdx = r.begin(); newIdx != r.end(); ++newIdx, ++it) {
754-
const auto& cluster = it->second;
761+
for (auto newIdx = r.begin(); newIdx != r.end(); ++newIdx) {
762+
const auto& cluster = clusters[newIdx];
755763
auto cluster_size = cluster.size();
756764
if (!cluster_size) continue;
757765

0 commit comments

Comments
 (0)