CoinPointCloud.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include "CoinPointCloud.h"
25 
26 #include <vector>
27 
28 //Coin includes
29 #include <pcl/common/colors.h>
30 
31 #include <Inventor/SbColor.h>
32 #include <Inventor/SbVec3f.h>
33 #include <Inventor/nodes/SoCoordinate3.h>
34 #include <Inventor/nodes/SoDrawStyle.h>
35 #include <Inventor/nodes/SoMaterial.h>
36 #include <Inventor/nodes/SoMaterialBinding.h>
37 #include <Inventor/nodes/SoPointSet.h>
38 
39 namespace visionx
40 {
41 
42  template <class ColorT>
43  void
44  fillColorArray(float array[3], const ColorT& color)
45  {
46  array[0] = static_cast<float>(color.r) / 255.0f;
47  array[1] = static_cast<float>(color.g) / 255.0f;
48  array[2] = static_cast<float>(color.b) / 255.0f;
49  }
50 
51  CoinPointCloud::CoinPointCloud(pcl::PointCloud<PointT>::ConstPtr originalCloud,
52  visionx::PointContentType originalType,
53  bool colorFromLabel,
54  float pointSize) :
55  originalCloud(originalCloud), originalType(originalType)
56  {
57  // Insert color information into scene graph
58  SoMaterial* materialInfo = new SoMaterial();
59  std::vector<SbColor> colorData;
60  colorData.reserve(originalCloud->points.size());
61  // Add point coordinates
62  SoCoordinate3* coordinates = new SoCoordinate3();
63  std::vector<SbVec3f> pointData;
64  pointData.reserve(originalCloud->points.size());
65  for (const PointT& p : originalCloud->points)
66  {
67  if (std::isfinite(p.x) && std::isfinite(p.y) && std::isfinite(p.z))
68  {
69  SbColor colorContainer;
70  float colorArray[3];
71 
72  if (colorFromLabel)
73  {
74  const pcl::RGB color = pcl::GlasbeyLUT::at(p.label % pcl::GlasbeyLUT::size());
75  fillColorArray(colorArray, color);
76  }
77  else
78  {
79  fillColorArray(colorArray, p);
80  }
81 
82  colorContainer.setValue(colorArray);
83  colorData.push_back(colorContainer);
84 
85  SbVec3f pointContainer;
86  pointContainer[0] = p.x;
87  pointContainer[1] = p.y;
88  pointContainer[2] = p.z;
89 
90  pointData.push_back(pointContainer);
91  }
92  }
93 
94  materialInfo->diffuseColor.setValues(0, colorData.size(), colorData.data());
95  this->addChild(materialInfo);
96 
97  // Bind materials to per part
98  SoMaterialBinding* binding = new SoMaterialBinding();
99  binding->value = SoMaterialBinding::PER_PART;
100  this->addChild(binding);
101 
102  coordinates->point.setValues(0, pointData.size(), pointData.data());
103  this->addChild(coordinates);
104 
105  // Set point size
106  SoDrawStyle* sopointSize = new SoDrawStyle();
107  sopointSize->pointSize = pointSize;
108  this->addChild(sopointSize);
109 
110  // Draw a point set out of all that data
111  SoPointSet* pointSet = new SoPointSet();
112  this->addChild(pointSet);
113  }
114 
116 
117  auto
119  {
120  return this->originalCloud;
121  }
122 
123  visionx::PointContentType
125  {
126  return this->originalType;
127  }
128 } // namespace visionx
pcl
Definition: pcl_point_operators.cpp:3
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::CoinPointCloud::~CoinPointCloud
~CoinPointCloud() override
CoinPointCloud.h
visionx::CoinPointCloud::PointT
pcl::PointXYZRGBL PointT
Definition: CoinPointCloud.h:41
visionx::fillColorArray
void fillColorArray(float array[3], const ColorT &color)
Definition: CoinPointCloud.cpp:44
visionx::CoinPointCloud::getPCLCloud
pcl::PointCloud< PointT >::ConstPtr getPCLCloud() const
Definition: CoinPointCloud.cpp:118
visionx::CoinPointCloud::getOriginalType
visionx::PointContentType getOriginalType() const
Definition: CoinPointCloud.cpp:124
std::isfinite
bool isfinite(const std::vector< T, Ts... > &v)
Definition: algorithm.h:366
PointCloud
Definition: PointCloud.h:85
visionx::CoinPointCloud::CoinPointCloud
CoinPointCloud(pcl::PointCloud< PointT >::ConstPtr originalCloud, visionx::PointContentType originalType, bool colorFromLabel, float pointSize=1)
Definition: CoinPointCloud.cpp:51