Debian Codegraph @

plugins/core/Standard/qPCL/PclUtils/utils/copy.cpp

raw symbols SCIP
1 //##########################################################################
2 //# #
3 //# CLOUDCOMPARE PLUGIN: qPCL #
4 //# #
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. #
8 //# #
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. #
13 //# #
14 //# COPYRIGHT: Luca Penasa #
15 //# #
16 //##########################################################################
17 //
18 //#ifdef LP_PCL_PATCH_ENABLED
19
20 #include "copy.h"
21
22 //qCC_db
23 #include <ccScalarField.h>
24 #include <ccPointCloud.h>
25
26 void copyScalarFields(const ccPointCloud *inCloud, ccPointCloud *outCloud, pcl::PointIndicesPtr &in2outMapping, bool overwrite)
27 {
28 if (in2outMapping->indices.empty())
29 return;
30 assert(in2outMapping->indices.size() == outCloud->size());
31
32 unsigned outCloudSize = outCloud->size();
33
34 unsigned sfCount = inCloud->getNumberOfScalarFields();
35 for (unsigned i = 0; i < sfCount; ++i)
36 {
37 const CCCoreLib::ScalarField* field = inCloud->getScalarField(i);
38 const char* name = field->getName();
39
40 ccScalarField* newSF = nullptr;
41
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
45 {
46 if (overwrite)
47 {
48 newSF = static_cast<ccScalarField*>(outCloud->getScalarField(id));
49 }
50 else
51 {
52 continue;
53 }
54 }
55 else
56 {
57 newSF = new ccScalarField(name);
58
59 //resize the scalar field to the outcloud size
60 if (!newSF->resizeSafe(outCloudSize))
61 {
62 //not enough memory!
63 newSF->release();
64 newSF = nullptr;
65 continue;
66 }
67 }
68
69 //now perform point to point copy
70 for (unsigned j = 0; j < outCloudSize; ++j)
71 {
72 newSF->setValue(j, field->getValue(in2outMapping->indices.at(j)));
73 }
74
75 //recompute stats
76 newSF->computeMinAndMax();
77
78 //now put back the scalar field to the outCloud
79 if (id < 0)
80 {
81 outCloud->addScalarField(newSF);
82 }
83 }
84
85 outCloud->showSF(outCloud->sfShown() || inCloud->sfShown());
86 }
87
88 void copyRGBColors(const ccPointCloud *inCloud, ccPointCloud *outCloud, pcl::PointIndicesPtr &in2outMapping, bool overwrite)
89 {
90 // if inCloud has no color there is nothing to do
91 if (!inCloud->hasColors())
92 return;
93
94 if (in2outMapping->indices.empty())
95 return;
96 assert(in2outMapping->indices.size() == outCloud->size());
97
98 if (outCloud->hasColors() && !overwrite)
99 return;
100
101 if (outCloud->reserveTheRGBTable())
102 {
103 //now perform point to point copy
104 unsigned outCloudSize = outCloud->size();
105 for (unsigned j = 0; j < outCloudSize; ++j)
106 {
107 outCloud->addColor(inCloud->getPointColor(in2outMapping->indices.at(j)));
108 }
109 }
110
111 outCloud->showColors(outCloud->colorsShown() || inCloud->colorsShown());
112 }
113
114 //#endif // LP_PCL_PATCH_ENABLED