Hello, I amb like 5 years late, but maybe somebody search that and maybe wants a response.
I reached this place searching exactly the same, and even not finding that solution i realized two ways to solve it.
First of all, I am going to define that the reason why a point is duplicated in two pointclouds which you want to concatenate, probably (and at least is the only possibility I realise) it is because they come from the same pointcloud, whic chave been filtered in different ways (in my case, for example, i did a difference of normals filtering and a difference of grayscale filtering).
First approach:
Add two or more conditions into the removal:
During the filtering, there is the options of pcl:ConditionAnd and pcl::ConditionOr which can concatenate more than one conditions (with addComparison function or addCondition). This way you should be able to directly generate the filtered/concatenated pointcloud.
A main drawback? lets imagine my case in which each filtering is done using a dirrefent kind of pointcloud (pointXYZI with intensity and pcl::PointNormal with curvate) how you merge both pointclouds into one condition? here appears my second approach
Second approach
Just do as you desired originally (so, we create two independent filtered clouds). Remember in this case to set the setKeepOrganized insideconditionalremoval to false, to store the original index (the removed ones will become NaN).
Once you did that, the easies tolution is to convert both pointclouds into the same kind, something like:
pcl::copyPointCloud<pcl::PointXYZI, pcl::PointXYZ>( cloud_with_i, cloud_without_i);
and then apply the following code (dith cloud1 and cloud2 the clouds to concatenate):
pcl::PointCloud<pcl::PointXYZ> cloud_concatenated;
cloud_concatenated = cloud1; bool condition1=false; bool condition2=false;
for (int i = 0; i < cloud_concatenated.points.size(); i++) {
condition1 = (isnan(cloud_concatenated.points[i].x)) && (isnan(cloud_concatenated.points[i].y)) (isnan(cloud_concatenated.points[i].z));
condition2 = (!isnan(cloud2.points[i].x)) && (!isnan(cloud2.points[i].y)) (!isnan(cloud2.points[i].z));
if (condition1 && condition2) {
cloud_concatenated.points[i].x = cloud2.points[i].x;
cloud_concatenated.points[i].y = cloud2.points[i].y;
cloud_concatenated.points[i].z = cloud2.points[i].z;
}
}
Finally if you want to remove the Nan extra valures, just apply pcl::removeNaNFromPointCloud.
I could not test the code. so if there is any issue, please help to imporve the response :)