ccPointCloud addPoint

Feel free to ask any question here
Post Reply
kasper
Posts: 29
Joined: Thu May 17, 2018 6:13 am

ccPointCloud addPoint

Post by kasper »

Code: Select all

ccPointCloud *cloud = new ccPointCloud;
cloud->reserve(points.size());
for(int i=0;i<points.size();i++)
{
	cloud->addPoint(points[i]);
}
There is a points array, and I want to convert it into ccPointCloud type, andt it costs time.
I want to use parallel for to improve its efficacy.
But when I use

Code: Select all

#omp parallel for

It doesn't seem to be effective.

1. I want to make sure that is "addPoint" has no "input order" ploblems.
2. Is there any better way to optimized the tranform in cloudcompare?


Thanks.
kasper
Posts: 29
Joined: Thu May 17, 2018 6:13 am

Re: ccPointCloud addPoint

Post by kasper »

is addPoint sequential?
daniel
Site Admin
Posts: 7712
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: ccPointCloud addPoint

Post by daniel »

Yes, it's like std::vector::push_back. So you could use it in parallel, but you'll need a mutex (so I'm not sure it's worth it).
Daniel, CloudCompare admin
kasper
Posts: 29
Joined: Thu May 17, 2018 6:13 am

Re: ccPointCloud addPoint

Post by kasper »

So there's no other way to improve performance of this issue?

maybe replace "addPoint" with other function or addPoint with Index ?
daniel
Site Admin
Posts: 7712
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: ccPointCloud addPoint

Post by daniel »

I have some hard time imagining that 'addPoint' is that slow (since it's literally just a 'push_back' in a vector), but currently there's no other way to populate a point cloud.

You could add a 'resize' method to resize the vector of points in one call, and then use a const_cast<CCVector3*>(getPoint(i)) to set the coordinates of a given point. Just don't forget to call 'invalidateBoundingBox()' (or something like that, I don't remember exactly) to force the bounding-box update at the end.
Daniel, CloudCompare admin
daniel
Site Admin
Posts: 7712
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: ccPointCloud addPoint

Post by daniel »

Are you running in debug mode maybe?
Daniel, CloudCompare admin
kasper
Posts: 29
Joined: Thu May 17, 2018 6:13 am

Re: ccPointCloud addPoint

Post by kasper »

Actually, It doesn't take that much time.
We just want to make it faster.

we're in release mode.

Another aimuler question,
about "getPoint(index)"

Code: Select all

for(int i=0;i<size;i++)
{
   CCVector3 p = cloud->getPoint(i);
}
it seems cost the same time whatever we use "#pragma omp parallel for" or not.
WargodHernandez
Posts: 187
Joined: Tue Mar 05, 2019 3:59 pm

Re: ccPointCloud addPoint

Post by WargodHernandez »

These micro optimizations are very challenging, when trying to spread the load to multiple threads you could easily make the process slower due to the task scheduler overhead in comparison to just single threaded performance. The performance likely changes with the amount of points your trying to add as well, using threads to add 4 points is obviously much slower than using a single core, the number of points required to be worthwhile is likely very high, also cache misses tend to become an issue for using lots of threads in parallel, another thing is that we are calling push_back which is not considered thread safe (although it probably is because of the reserve function).
Post Reply