How to use multithreading to traverse a quadtree built from a point cloud model

The simplest description of this problem is how to traverse a quadtree using multiple threads.

The following figure is the quadtree model of my problem:

My algorithm does not need to traverse all leaf nodes from top to bottom, but only needs to traverse nodes that meet the conditions. In other words, if some branches do not meet the requirements, they will be discarded at the beginning. If I evenly distribute all branches to multiple cores, if some branches are discarded, it will cause a waste of CPU threads. Is there any way to make the traversal of the quadtree call all cores evenly?

The following is a detailed description of my application scenario:

I have a 3D object, such as a cup, originally modeled in Blender and saved in OBJ format. The surface of this object has been sampled to create a point cloud consisting of a total number of points that are a multiple of four, let’s say N points. I need to use this cup for collision detection against another object, such as a table.

If the cup and the table collide, it means there is an intersection between the point cloud model and the table’s 3D model. My task is to identify the points in the point cloud that are within the intersected area.

The collision detection algorithm I am using needs to be very fast, executing at approximately 1000Hz, which means I have about 1ms to identify the points involved in a collision.

To avoid checking each of the N points individually, I’ve built a quadtree and a hierarchy of bounding spheres. This algorithm can quickly discard non-colliding regions, rapidly narrowing down the query area to find the set of colliding points.

Here’s an overview of the process I used:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>1.The point cloud was clustered by grouping every four nearest neighbor points
into one cluster, creating a total of N/4 clusters.
2.The point closest to the geometric center of these four points was chosen as
the parent point.
3.These parent points were then similarly clustered into groups of four, and this
process was repeated until a single-point cluster remained at the top level.
4.A quadtree was constructed through these steps.
</code>
<code>1.The point cloud was clustered by grouping every four nearest neighbor points into one cluster, creating a total of N/4 clusters. 2.The point closest to the geometric center of these four points was chosen as the parent point. 3.These parent points were then similarly clustered into groups of four, and this process was repeated until a single-point cluster remained at the top level. 4.A quadtree was constructed through these steps. </code>
1.The point cloud was clustered by grouping every four nearest neighbor points 
into one cluster, creating a total of N/4 clusters. 

2.The point closest to the geometric center of these four points was chosen as 
the parent point.

3.These parent points were then similarly clustered into groups of four, and this 
process was repeated until a single-point cluster remained at the top level.

4.A quadtree was constructed through these steps.

After building the quadtree, a bounding sphere (sphere center and radius) was computed for each cluster at each level.
With the quadtree and bounding spheres prepared, the collision detection process can be significantly simplified, allowing for quick identification of the collision points as follows:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>1.Initially, check if the single-point cluster at the top level collides (i.e.,
if the distance from the sphere’s center to the table is less than its radius).
If there’s no collision, only one check is needed.
2.If there’s a collision at the top level, recursively check its child clusters for
collisions until the bottom-most clusters are reached, identifying all points
involved in the collision.
</code>
<code>1.Initially, check if the single-point cluster at the top level collides (i.e., if the distance from the sphere’s center to the table is less than its radius). If there’s no collision, only one check is needed. 2.If there’s a collision at the top level, recursively check its child clusters for collisions until the bottom-most clusters are reached, identifying all points involved in the collision. </code>
1.Initially, check if the single-point cluster at the top level collides (i.e., 
if the distance from the sphere’s center to the table is less than its radius). 
If there’s no collision, only one check is needed.  

2.If there’s a collision at the top level, recursively check its child clusters for 
collisions until the bottom-most clusters are reached, identifying all points 
involved in the collision.

For implementation, I use a FIFO queue Q to manage the nodes as follows:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>1.Start by pushing the top-level cluster (topLevelCluster) into the queue.
2.Pop the front cluster from the queue and check for collision. If it collides,
and it's not at the bottom level, push all its child clusters to the end of the
queue.
3.Repeat until the queue is empty.
</code>
<code>1.Start by pushing the top-level cluster (topLevelCluster) into the queue. 2.Pop the front cluster from the queue and check for collision. If it collides, and it's not at the bottom level, push all its child clusters to the end of the queue. 3.Repeat until the queue is empty. </code>
1.Start by pushing the top-level cluster (topLevelCluster) into the queue.

2.Pop the front cluster from the queue and check for collision. If it collides, 
and it's not at the bottom level, push all its child clusters to the end of the 
queue.

3.Repeat until the queue is empty.

Currently, this algorithm is executed on a single core. I’m looking to implement this traversal algorithm in a multithreaded manner. My system is Windows 10 x64 with an AMD 7950X 16-core CPU.

I have tested the multithreaded version using Boost’s boost::lockfree::queue, which performs well with high data throughput scenarios like millions of points, taking around 80-100ms on a single core and about 10ms with 8 cores.

However, with smaller datasets like tens of thousands of points, the improvement with 8 cores isn’t as significant (only reducing the time from about 3-5ms per traversal to about 1-2ms).

I also tried a brute-force approach by dividing the original point cloud into 8 groups through Gaussian sampling, then creating eight separate quadtrees, each processed by one of the eight cores. This method showed a significant performance increase, nearly 8x faster. But this approach is a last resort.

Is there a better way to perform parallel traversal of my quadtree to greatly speed up the detection process?

Here’s the simplified version of my multithreading pseudocode:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>void processQueue(int thread_id, boost::lockfree::queue<ClusterC*>& Q)
{
ClusterC* c=NULL;
while (!Q.empty())
{
if (Q.pop(c))
{
if(isCollide(c))
{
if (c->getLevel() == BottomLevel)
{
processPointData(thread_id);
}
else
{
for (auto& child : c->getChildClusters())
{
Q.push(child.get());
}
}
}
}
}
}
void collisionQueryMT()
{
BS::thread_pool pool(16);
boost::lockfree::queue<ClusterC*> Q(80000);
Q.push(topLevelCluster);// 加入顶层簇
for (int i = 0; i < NUM_THREADS; ++i)
{
pool.detach_task(std::bind(processQueueMT, i, std::ref(Q)));
}
pool.wait();
}
</code>
<code>void processQueue(int thread_id, boost::lockfree::queue<ClusterC*>& Q) { ClusterC* c=NULL; while (!Q.empty()) { if (Q.pop(c)) { if(isCollide(c)) { if (c->getLevel() == BottomLevel) { processPointData(thread_id); } else { for (auto& child : c->getChildClusters()) { Q.push(child.get()); } } } } } } void collisionQueryMT() { BS::thread_pool pool(16); boost::lockfree::queue<ClusterC*> Q(80000); Q.push(topLevelCluster);// 加入顶层簇 for (int i = 0; i < NUM_THREADS; ++i) { pool.detach_task(std::bind(processQueueMT, i, std::ref(Q))); } pool.wait(); } </code>
void processQueue(int thread_id, boost::lockfree::queue<ClusterC*>& Q)
{
    ClusterC* c=NULL;
    
    while (!Q.empty())
    {
        if (Q.pop(c))
        {
            if(isCollide(c))
            {
                if (c->getLevel() == BottomLevel)
                {
                    processPointData(thread_id);
                }
                else
                {
                    for (auto& child : c->getChildClusters())
                    {
                        Q.push(child.get());
                    }
                }
            }
        }
    }
}


void collisionQueryMT()
{
    BS::thread_pool pool(16);
    boost::lockfree::queue<ClusterC*> Q(80000);

    Q.push(topLevelCluster);// 加入顶层簇

    for (int i = 0; i < NUM_THREADS; ++i)
    {
        pool.detach_task(std::bind(processQueueMT, i, std::ref(Q)));
    }

    pool.wait();
}

Can anyone suggest methods to optimize the multi-threaded traversal of my quadtree to accelerate the detection process even further? Thanks.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật