~ubuntu-branches/debian/sid/cloudcompare/sid

« back to all changes in this revision

Viewing changes to plugins/qPCL/PclUtils/utils/copy.cpp

  • Committer: Package Import Robot
  • Author(s): Gürkan Myczko
  • Date: 2018-02-23 08:38:00 UTC
  • Revision ID: package-import@ubuntu.com-20180223083800-m96gby901656yjd1
Tags: upstream-2.9.1+git20180223
Import upstream version 2.9.1+git20180223

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 n_out = outCloud->size();
 
33
 
 
34
        unsigned sfCount = inCloud->getNumberOfScalarFields();
 
35
        for (unsigned i = 0; i < sfCount; ++i)
 
36
        {
 
37
                const CCLib::ScalarField* field = inCloud->getScalarField(i);
 
38
                const char* name = field->getName();
 
39
 
 
40
                ccScalarField* new_field = 0;
 
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
                                new_field = static_cast<ccScalarField*>(outCloud->getScalarField(id));
 
49
                        }
 
50
                        else
 
51
                        {
 
52
                                continue;
 
53
                        }
 
54
                }
 
55
                else
 
56
                {
 
57
                        new_field = new ccScalarField(name);
 
58
 
 
59
                        //resize the scalar field to the outcloud size
 
60
                        if (!new_field->resize(n_out))
 
61
                        {
 
62
                                //not enough memory!
 
63
                                new_field->release();
 
64
                                new_field = 0;
 
65
                                continue;
 
66
                        }
 
67
                }
 
68
 
 
69
                //now perform point to point copy
 
70
                for (unsigned j=0; j<n_out; ++j)
 
71
                {
 
72
                        new_field->setValue(j, field->getValue(in2outMapping->indices.at(j)));
 
73
                }
 
74
 
 
75
                //recompute stats
 
76
                new_field->computeMinAndMax();
 
77
 
 
78
                //now put back the scalar field to the outCloud
 
79
                if (id < 0)
 
80
                {
 
81
                        outCloud->addScalarField(new_field);
 
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 n_out = outCloud->size();
 
105
                for (unsigned j=0; j<n_out; ++j)
 
106
                {
 
107
                        outCloud->addRGBColor(inCloud->getPointColor(in2outMapping->indices.at(j)));
 
108
                }
 
109
        }
 
110
 
 
111
        outCloud->showColors(outCloud->colorsShown() || inCloud->colorsShown());
 
112
}
 
113
 
 
114
//#endif // LP_PCL_PATCH_ENABLED