CGAL RTree在处理39,651,210个二维点时出现内存问题。

huangapple go评论53阅读模式
英文:

Memory issue with CGAL RTree when working with 39,651,210 2D points

问题

我正在使用CGAL的RTree来查找点云中在一个区间内的2D点。点云的大小为39,651,210个点。然而,当我将这些点传递给RTree时,它导致RAM使用量大幅增加,从Windows任务管理器中的15 GB增加到60 GB。因此,我被迫终止程序的执行。

以下是代码:

// ... (先前的代码)
typedef CGAL::Exact_predicates_inexact_constructions_kernel EPIC;
typedef EPIC::Point_2 Point_2;
// 因为只有关键字本身相关,不涉及值,所以是bool类型。
typedef CGAL::Range_tree_map_traits_2<EPIC, bool> Traits;
typedef CGAL::Range_tree_2<Traits> Range_tree_2;
typedef Traits::Key Key;
typedef Traits::Interval Interval;
std::vector<Key> rTreeInput;

// 创建一个向量来保存RTree的输入
std::vector<Key> rTreeInput;
rTreeInput.reserve(numPoints);

// 使用2D点作为关键字,虚拟布尔值作为值来填充向量
for (size_t pointIndex = 0; pointIndex < numPoints; ++pointIndex) {
    const size_t offset = pointIndex * pointDimension;
    const size_t xCoordinateIndex = offset;
    const size_t yCoordinateIndex = offset + 1;
    rTreeInput.push_back(Key(Point_2(pPoints[xCoordinateIndex], pPoints[yCoordinateIndex]), false));
}

// 使用填充的向量创建RTree
Range_tree_2 rTree(rTreeInput.begin(), rTreeInput.end()); // <-- 导致RAM爆炸

// ... (剩余的代码)

我注意到CGAL的RTree需要一个键值对,但我只对点感兴趣。为了优化效率,我将虚拟布尔值设置为“值”部分,并且只使用“键”,因为它们表示感兴趣的点。

是否有办法优化我的代码以减少这种过度的内存使用?当前的内存消耗对我的应用程序来说是不可接受的。对于我的问题,是否有任何建议或见解将不胜感激。

英文:

I am using the CGAL RTree to find 2D points within an interval in a point cloud. The size of the point cloud is 39,651,210 points. However, when I pass these points to the RTree, it causes a massive increase in RAM usage, going from 15 GB to 60 GB in the Windows Task Manager. As a result, I am forced to terminate the program execution.

Here the code:

// ... (previous code)
typedef CGAL::Exact_predicates_inexact_constructions_kernel EPIC;
typedef EPIC::Point_2 Point_2;
// bool because only the key itself is relevent, not the value.
typedef CGAL::Range_tree_map_traits_2<EPIC, bool> Traits;
typedef CGAL::Range_tree_2<Traits> Range_tree_2;
typedef Traits::Key Key;
typedef Traits::Interval Interval;
std::vector<Key> rTreeInput;

// Create a vector to hold the input for the RTree
std::vector<Key> rTreeInput;
rTreeInput.reserve(numPoints);

// Populate the vector with the 2D points as keys and dummy boolean as values
for (size_t pointIndex = 0; pointIndex < numPoints; ++pointIndex) {
    const size_t offset = pointIndex * pointDimension;
    const size_t xCoordinateIndex = offset;
    const size_t yCoordinateIndex = offset + 1;
    rTreeInput.push_back(Key(Point_2(pPoints[xCoordinateIndex], pPoints[yCoordinateIndex]), false));
}

// Create the RTree using the populated vector
Range_tree_2 rTree(rTreeInput.begin(), rTreeInput.end()); // <-- causes the RAM explosion

// ... (remaining code)

I noticed that the CGAL RTree expects a Key-Value pair, but I am only interested in the points. To optimize for efficiency, I have set a dummy boolean value as the "value" part of the pair and only work with the "keys" since they represent the points of interest.

Is there a way to optimize my code to reduce this excessive memory usage? The current memory consumption is not acceptable for my application. Any suggestions or insights would be greatly appreciated.

答案1

得分: 0

为了解决这个问题,我用 Boost 库中的 RTree 替换了 CGAL RTree。使用 Boost RTree,我显著降低了内存消耗,现在我的应用程序可以在相同的数据集上平稳运行。

总之,如果在处理大型数据集时遇到 CGAL RTree 的内存使用过多的情况,考虑尝试 Boost RTree 作为潜在的替代方案,因为它可能为您特定的用例提供更节省内存的解决方案。

希望这些信息能帮助那些可能遇到 CGAL RTree 类似问题并寻找潜在解决方案的人。

英文:

To overcome this issue, I replaced the CGAL RTree with the RTree from the Boost library. Using the Boost RTree, I achieved significantly reduced memory consumption, and my application now works smoothly with the same dataset.

In conclusion, if you encounter excessive memory usage with the CGAL RTree when dealing with large datasets, consider trying the Boost RTree as a potential alternative, as it might provide a more memory-efficient solution for your specific use case.

I hope this information helps others who might encounter a similar issue with the CGAL RTree and are looking for potential solutions.

huangapple
  • 本文由 发表于 2023年7月24日 19:39:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76754109.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定