1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
//##########################################################################
//# #
//# CLOUDCOMPARE PLUGIN: qPCL #
//# #
//# This program is free software; you can redistribute it and/or modify #
//# it under the terms of the GNU General Public License as published by #
//# the Free Software Foundation; version 2 or later of the License. #
//# #
//# This program is distributed in the hope that it will be useful, #
//# but WITHOUT ANY WARRANTY; without even the implied warranty of #
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
//# GNU General Public License for more details. #
//# #
//# COPYRIGHT: Luca Penasa #
//# #
//##########################################################################
//
//#ifdef LP_PCL_PATCH_ENABLED
#include "copy.h"
//qCC_db
#include <ccScalarField.h>
#include <ccPointCloud.h>
void copyScalarFields(const ccPointCloud *inCloud, ccPointCloud *outCloud, pcl::PointIndicesPtr &in2outMapping, bool overwrite)
{
if (in2outMapping->indices.empty())
return;
assert(in2outMapping->indices.size() == outCloud->size());
unsigned n_out = outCloud->size();
unsigned sfCount = inCloud->getNumberOfScalarFields();
for (unsigned i = 0; i < sfCount; ++i)
{
const CCLib::ScalarField* field = inCloud->getScalarField(i);
const char* name = field->getName();
ccScalarField* new_field = 0;
//we need to verify no scalar field with the same name exists in the output cloud
int id = outCloud->getScalarFieldIndexByName(name);
if (id >= 0) //a scalar field with the same name exists
{
if (overwrite)
{
new_field = static_cast<ccScalarField*>(outCloud->getScalarField(id));
}
else
{
continue;
}
}
else
{
new_field = new ccScalarField(name);
//resize the scalar field to the outcloud size
if (!new_field->resize(n_out))
{
//not enough memory!
new_field->release();
new_field = 0;
continue;
}
}
//now perform point to point copy
for (unsigned j=0; j<n_out; ++j)
{
new_field->setValue(j, field->getValue(in2outMapping->indices.at(j)));
}
//recompute stats
new_field->computeMinAndMax();
//now put back the scalar field to the outCloud
if (id < 0)
{
outCloud->addScalarField(new_field);
}
}
outCloud->showSF(outCloud->sfShown() || inCloud->sfShown());
}
void copyRGBColors(const ccPointCloud *inCloud, ccPointCloud *outCloud, pcl::PointIndicesPtr &in2outMapping, bool overwrite)
{
// if inCloud has no color there is nothing to do
if (!inCloud->hasColors())
return;
if (in2outMapping->indices.empty())
return;
assert(in2outMapping->indices.size() == outCloud->size());
if (outCloud->hasColors() && !overwrite)
return;
if (outCloud->reserveTheRGBTable())
{
//now perform point to point copy
unsigned n_out = outCloud->size();
for (unsigned j=0; j<n_out; ++j)
{
outCloud->addRGBColor(inCloud->getPointColor(in2outMapping->indices.at(j)));
}
}
outCloud->showColors(outCloud->colorsShown() || inCloud->colorsShown());
}
//#endif // LP_PCL_PATCH_ENABLED
|