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 <Inventor/nodes/SoMaterial.h>
30 #include <Inventor/nodes/SoMaterialBinding.h>
31 #include <Inventor/nodes/SoCoordinate3.h>
32 #include <Inventor/nodes/SoDrawStyle.h>
33 #include <Inventor/nodes/SoPointSet.h>
34 #include <Inventor/SbColor.h>
35 #include <Inventor/SbVec3f.h>
36 
37 #include <pcl/common/colors.h>
38 
39 
40 namespace visionx
41 {
42 
43  template <class ColorT>
44  void 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),
56  originalType(originalType)
57  {
58  // Insert color information into scene graph
59  SoMaterial* materialInfo = new SoMaterial();
60  std::vector<SbColor> colorData;
61  colorData.reserve(originalCloud->points.size());
62  // Add point coordinates
63  SoCoordinate3* coordinates = new SoCoordinate3();
64  std::vector<SbVec3f> pointData;
65  pointData.reserve(originalCloud->points.size());
66  for (const PointT& p : originalCloud->points)
67  {
68  if (std::isfinite(p.x) && std::isfinite(p.y) && std::isfinite(p.z))
69  {
70  SbColor colorContainer;
71  float colorArray[3];
72 
73  if (colorFromLabel)
74  {
75  const pcl::RGB color = pcl::GlasbeyLUT::at(p.label % pcl::GlasbeyLUT::size());
76  fillColorArray(colorArray, color);
77  }
78  else
79  {
80  fillColorArray(colorArray, p);
81  }
82 
83  colorContainer.setValue(colorArray);
84  colorData.push_back(colorContainer);
85 
86  SbVec3f pointContainer;
87  pointContainer[0] = p.x;
88  pointContainer[1] = p.y;
89  pointContainer[2] = p.z;
90 
91  pointData.push_back(pointContainer);
92  }
93  }
94 
95  materialInfo->diffuseColor.setValues(0, colorData.size(), colorData.data());
96  this->addChild(materialInfo);
97 
98  // Bind materials to per part
99  SoMaterialBinding* binding = new SoMaterialBinding();
100  binding->value = SoMaterialBinding::PER_PART;
101  this->addChild(binding);
102 
103  coordinates->point.setValues(0, pointData.size(), pointData.data());
104  this->addChild(coordinates);
105 
106  // Set point size
107  SoDrawStyle* sopointSize = new SoDrawStyle();
108  sopointSize->pointSize = pointSize;
109  this->addChild(sopointSize);
110 
111  // Draw a point set out of all that data
112  SoPointSet* pointSet = new SoPointSet();
113  this->addChild(pointSet);
114  }
115 
117 
118  auto CoinPointCloud::getPCLCloud() const -> pcl::PointCloud<PointT>::ConstPtr
119  {
120  return this->originalCloud;
121  }
122 
123  visionx::PointContentType CoinPointCloud::getOriginalType() const
124  {
125  return this->originalType;
126  }
127 }
pcl
Definition: pcl_point_operators.cpp:4
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::CoinPointCloud::~CoinPointCloud
~CoinPointCloud() override
CoinPointCloud.h
visionx::CoinPointCloud::PointT
pcl::PointXYZRGBL PointT
Definition: CoinPointCloud.h:42
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:123
std::isfinite
bool isfinite(const std::vector< T, Ts... > &v)
Definition: algorithm.h:327
PointCloud
Definition: PointCloud.h:69
visionx::CoinPointCloud::CoinPointCloud
CoinPointCloud(pcl::PointCloud< PointT >::ConstPtr originalCloud, visionx::PointContentType originalType, bool colorFromLabel, float pointSize=1)
Definition: CoinPointCloud.cpp:51