Page 1 of 1

ccPointCloud addPoint

Posted: Tue Jul 13, 2021 9:38 am
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.

Re: ccPointCloud addPoint

Posted: Tue Jul 13, 2021 9:43 am
by kasper
is addPoint sequential?

Re: ccPointCloud addPoint

Posted: Tue Jul 13, 2021 12:24 pm
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).

Re: ccPointCloud addPoint

Posted: Wed Jul 14, 2021 6:19 pm
by kasper
So there's no other way to improve performance of this issue?

maybe replace "addPoint" with other function or addPoint with Index ?

Re: ccPointCloud addPoint

Posted: Thu Jul 15, 2021 9:53 pm
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.

Re: ccPointCloud addPoint

Posted: Thu Jul 15, 2021 9:54 pm
by daniel
Are you running in debug mode maybe?

Re: ccPointCloud addPoint

Posted: Wed Jul 21, 2021 9:23 am
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.

Re: ccPointCloud addPoint

Posted: Thu Jul 22, 2021 7:32 pm
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).