1
//##########################################################################
3
//# CLOUDCOMPARE PLUGIN: qPCL #
5
//# This program is free software; you can redistribute it and/or modify #
6
//# it under the terms of the GNU General Public License as published by #
7
//# the Free Software Foundation; version 2 or later of the License. #
9
//# This program is distributed in the hope that it will be useful, #
10
//# but WITHOUT ANY WARRANTY; without even the implied warranty of #
11
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
12
//# GNU General Public License for more details. #
14
//# COPYRIGHT: Luca Penasa #
16
//##########################################################################
18
//#ifdef LP_PCL_PATCH_ENABLED
23
#include <ccScalarField.h>
24
#include <ccPointCloud.h>
26
void copyScalarFields(const ccPointCloud *inCloud, ccPointCloud *outCloud, pcl::PointIndicesPtr &in2outMapping, bool overwrite)
28
if (in2outMapping->indices.empty())
30
assert(in2outMapping->indices.size() == outCloud->size());
32
unsigned n_out = outCloud->size();
34
unsigned sfCount = inCloud->getNumberOfScalarFields();
35
for (unsigned i = 0; i < sfCount; ++i)
37
const CCLib::ScalarField* field = inCloud->getScalarField(i);
38
const char* name = field->getName();
40
ccScalarField* new_field = 0;
42
//we need to verify no scalar field with the same name exists in the output cloud
43
int id = outCloud->getScalarFieldIndexByName(name);
44
if (id >= 0) //a scalar field with the same name exists
48
new_field = static_cast<ccScalarField*>(outCloud->getScalarField(id));
57
new_field = new ccScalarField(name);
59
//resize the scalar field to the outcloud size
60
if (!new_field->resize(n_out))
69
//now perform point to point copy
70
for (unsigned j=0; j<n_out; ++j)
72
new_field->setValue(j, field->getValue(in2outMapping->indices.at(j)));
76
new_field->computeMinAndMax();
78
//now put back the scalar field to the outCloud
81
outCloud->addScalarField(new_field);
85
outCloud->showSF(outCloud->sfShown() || inCloud->sfShown());
88
void copyRGBColors(const ccPointCloud *inCloud, ccPointCloud *outCloud, pcl::PointIndicesPtr &in2outMapping, bool overwrite)
90
// if inCloud has no color there is nothing to do
91
if (!inCloud->hasColors())
94
if (in2outMapping->indices.empty())
96
assert(in2outMapping->indices.size() == outCloud->size());
98
if (outCloud->hasColors() && !overwrite)
101
if (outCloud->reserveTheRGBTable())
103
//now perform point to point copy
104
unsigned n_out = outCloud->size();
105
for (unsigned j=0; j<n_out; ++j)
107
outCloud->addRGBColor(inCloud->getPointColor(in2outMapping->indices.at(j)));
111
outCloud->showColors(outCloud->colorsShown() || inCloud->colorsShown());
114
//#endif // LP_PCL_PATCH_ENABLED