PointCloud.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5  * Karlsruhe Institute of Technology (KIT), all rights reserved.
6  *
7  * ArmarX is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * ArmarX is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu)
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 // Header
25 #include "PointCloud.h"
26 
27 #include <SimoxUtility/meta/type_name.h>
28 
30 {
31  const std::map<type::pointcloud::VoxelType, std::tuple<std::string, int, std::string>>
33  // see http://docs.ros.org/en/groovy/api/pcl/html/point__types_8hpp_source.html
34  {type::pointcloud::VoxelType::POINT_XYZ,
35  {"pcl::PointXYZ", 16, "::armarx::aron::type::pointcloud::VoxelType::POINT_XYZ"}},
36  {type::pointcloud::VoxelType::POINT_XYZI,
37  {"pcl::PointXYZI", 32, "::armarx::aron::type::pointcloud::VoxelType::POINT_XYZI"}},
38  {type::pointcloud::VoxelType::POINT_XYZL,
39  {"pcl::PointXYZL", 32, "::armarx::aron::type::pointcloud::VoxelType::POINT_XYZL"}},
40  {type::pointcloud::VoxelType::POINT_XYZRGB,
41  {"pcl::PointXYZRGB", 32, "::armarx::aron::type::pointcloud::VoxelType::POINT_XYZRGB"}},
42  {type::pointcloud::VoxelType::POINT_XYZRGBL,
43  {"pcl::PointXYZRGBL",
44  32,
45  "::armarx::aron::type::pointcloud::VoxelType::POINT_XYZRGBL"}},
46  {type::pointcloud::VoxelType::POINT_XYZRGBA,
47  {"pcl::PointXYZRGBA",
48  32,
49  "::armarx::aron::type::pointcloud::VoxelType::POINT_XYZRGBA"}},
50  {type::pointcloud::VoxelType::POINT_XYZHSV,
51  {"pcl::PointXYZHSV",
52  32,
53  "::armarx::aron::type::pointcloud::VoxelType::POINT_XYZHSV"}}};
54 
55  // constructors
57  detail::NDArrayGenerator<type::PointCloud, PointCloud>(
58  "pcl::PointCloud<" + std::get<0>(VoxelType2Cpp.at(n.getVoxelType())) + ">",
59  "pcl::PointCloud<" + std::get<0>(VoxelType2Cpp.at(n.getVoxelType())) + ">",
60  simox::meta::get_type_name<data::dto::NDArray>(),
61  simox::meta::get_type_name<type::dto::PointCloud>(),
62  n)
63  {
64  }
65 
66  std::vector<std::string>
68  {
69  return {"<pcl/point_cloud.h>", "<pcl/point_types.h>"};
70  }
71 
72  std::pair<std::vector<std::pair<std::string, std::string>>, bool>
73  PointCloud::getCtorInitializers(const std::string&) const
74  {
75  // TODO
76  return {{}, false};
77  }
78 
80  PointCloud::getResetSoftBlock(const std::string& cppAccessor) const
81  {
82  CppBlockPtr block_if_data = std::make_shared<CppBlock>();
83  block_if_data->addLine(cppAccessor + " = " + getFullInstantiatedCppTypenameGenerator() +
84  "(" + cppAccessor + nextEl() + "width, " + cppAccessor + nextEl() +
85  "height);");
86  return this->resolveMaybeResetSoftBlock(block_if_data, cppAccessor);
87  }
88 
90  PointCloud::getWriteTypeBlock(const std::string& typeAccessor,
91  const std::string& cppAccessor,
92  const Path& p,
93  std::string& variantAccessor) const
94  {
95  CppBlockPtr b = std::make_shared<CppBlock>();
96  std::string escaped_accessor = EscapeAccessor(cppAccessor);
97  variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor;
98 
99  b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writePointCloud(" +
100  std::get<2>(VoxelType2Cpp.at(type.getVoxelType())) + ", " + "\"" +
101  type.getDefaultValue() + "\", " +
102  conversion::Maybe2CppString.at(type.getMaybe()) + ", " + "armarx::aron::Path(" +
103  ARON_PATH_ACCESSOR + ", {" + simox::alg::join(p.getPath(), ", ") +
104  "})); // of " + cppAccessor);
105  return b;
106  }
107 
109  PointCloud::getWriteBlock(const std::string& cppAccessor,
110  const Path& p,
111  std::string& variantAccessor) const
112  {
113  CppBlockPtr block_if_data = std::make_shared<CppBlock>();
114  std::string escaped_accessor = EscapeAccessor(cppAccessor);
115  variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor;
116 
117  block_if_data->addLine(
118  variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeNDArray({ static_cast<int>(" + cppAccessor +
119  nextEl() + "width), static_cast<int>(" + cppAccessor + nextEl() + "height), " +
120  std::to_string(std::get<1>(VoxelType2Cpp.at(type.getVoxelType()))) + "}, " + "\"" +
121  std::get<0>(VoxelType2Cpp.at(type.getVoxelType())) + "\", " +
122  "reinterpret_cast<const unsigned char*>(" + cppAccessor + nextEl() +
123  "points.data()), " + "armarx::aron::Path(" + ARON_PATH_ACCESSOR + ", {" +
124  simox::alg::join(p.getPath(), ", ") + "})); // of " + cppAccessor);
125 
126  return resolveMaybeWriteBlock(block_if_data, cppAccessor);
127  }
128 
130  PointCloud::getReadBlock(const std::string& cppAccessor,
131  const std::string& variantAccessor) const
132  {
133  CppBlockPtr block_if_data = std::make_shared<CppBlock>();
134  std::string escaped_accessor = EscapeAccessor(cppAccessor);
135  std::string type = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor + "_typeAsString";
136  std::string dims = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor + "_shape";
137  std::string data = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor + "_data";
138 
139  block_if_data->addLine("std::string " + type + ";");
140  block_if_data->addLine("std::vector<int> " + dims + ";");
141  block_if_data->addLine("std::vector<unsigned char> " + data + ";");
142  block_if_data->addLine("" + ARON_READER_ACCESSOR + ".readNDArray(" + variantAccessor +
143  ", " + dims + ", " + type + ", " + data + "); // of " + cppAccessor);
144 
145  block_if_data->addLine(
146  "ARMARX_CHECK_AND_THROW(" + dims +
147  ".size() == 3, ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, \"Received "
148  "wrong dimensions for member '" +
149  cppAccessor + "'.\"));");
150  block_if_data->addLine("ARMARX_CHECK_AND_THROW(" + type + " == \"" +
151  std::get<0>(VoxelType2Cpp.at(this->type.getVoxelType())) +
152  "\", ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, "
153  "\"Received wrong type for member '" +
154  cppAccessor + "'.\"));");
155 
156  // assign is not availablePCL for PCL 1.8
157  // block_if_data->addLine(cppAccessor + nextEl() + "assign(" + dims + "[0], " + dims + "[1], " + std::get<0>(VoxelType2Cpp.at(this->type.getVoxelType())) + "());");
158  block_if_data->addLine(cppAccessor + nextEl() + "clear();");
159  // resize(width, height , value) is not available either
160  // block_if_data->addLine(cppAccessor + nextEl() + "resize(" + dims + "[0], " + dims + "[1], " + std::get<0>(VoxelType2Cpp.at(this->type.getVoxelType())) + "()));");
161  block_if_data->addLine(cppAccessor + nextEl() + "resize(" + dims + "[0] * " + dims +
162  "[1]);");
163  block_if_data->addLine(cppAccessor + nextEl() + "width = " + dims + "[0];");
164  block_if_data->addLine(cppAccessor + nextEl() + "height = " + dims + "[1];");
165 
166  block_if_data->addLine("std::memcpy(reinterpret_cast<unsigned char*>(" + cppAccessor +
167  nextEl() + "points.data()), " + data + ".data(), " + data +
168  ".size());");
169  return resolveMaybeReadBlock(block_if_data, cppAccessor, variantAccessor);
170  }
171 
173  PointCloud::getEqualsBlock(const std::string& accessor,
174  const std::string& otherInstanceAccessor) const
175  {
176  CppBlockPtr block_if_data = std::make_shared<CppBlock>();
177  block_if_data->addLine("if (" + accessor + nextEl() + "width != " + otherInstanceAccessor +
178  nextEl() + "width || " + accessor + nextEl() +
179  "height != " + otherInstanceAccessor + nextEl() + "height)");
180  block_if_data->addLineAsBlock("return false;");
181 
182  //block_if_data->addLine("if (" + accessor + nextEl() + "points != " + otherInstanceAccessor + nextEl() + "points)");
183  //block_if_data->addLine("\t return false;");
184  return resolveMaybeEqualsBlock(block_if_data, accessor, otherInstanceAccessor);
185  }
186 } // namespace armarx::aron::codegenerator::cpp::generator
armarx::aron::codegenerator::cpp::Generator::ARON_VARIANT_RETURN_ACCESSOR
static const std::string ARON_VARIANT_RETURN_ACCESSOR
Definition: Generator.h:154
armarx::aron::codegenerator::cpp::generator::PointCloud::getEqualsBlock
CppBlockPtr getEqualsBlock(const std::string &cppAccessor, const std::string &) const final
Definition: PointCloud.cpp:173
armarx::aron::type::detail::SpecializedVariantBase::getMaybe
type::Maybe getMaybe() const override
get the maybe type
Definition: SpecializedVariant.h:92
armarx::aron::codegenerator::cpp::generator::PointCloud::getWriteTypeBlock
CppBlockPtr getWriteTypeBlock(const std::string &typeAccessor, const std::string &cppAccessor, const Path &, std::string &variantAccessor) const final
Definition: PointCloud.cpp:90
armarx::aron::type::PointCloud
The PointCloud class.
Definition: PointCloud.h:39
armarx::aron::codegenerator::cpp::Generator::EscapeAccessor
static std::string EscapeAccessor(const std::string &)
Definition: Generator.cpp:53
armarx::aron::codegenerator::cpp::generator::PointCloud
Definition: PointCloud.h:33
detail
Definition: OpenCVUtil.cpp:127
armarx::CppBlockPtr
std::shared_ptr< CppBlock > CppBlockPtr
Definition: CppBlock.h:35
armarx::aron::codegenerator::cpp::Generator::ARON_WRITER_ACCESSOR
static const std::string ARON_WRITER_ACCESSOR
Definition: Generator.h:152
armarx::aron::codegenerator::cpp::generator::PointCloud::getWriteBlock
CppBlockPtr getWriteBlock(const std::string &cppAccessor, const Path &, std::string &variantAccessor) const final
Definition: PointCloud.cpp:109
armarx::aron::codegenerator::cpp::Generator::ARON_PATH_ACCESSOR
static const std::string ARON_PATH_ACCESSOR
Definition: Generator.h:150
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::codegenerator::cpp::generator::PointCloud::getReadBlock
CppBlockPtr getReadBlock(const std::string &cppAccessor, const std::string &variantAccessor) const final
Definition: PointCloud.cpp:130
armarx::aron::codegenerator::cpp::generator::NDArray
Definition: NDArray.h:33
armarx::aron::codegenerator::cpp::Generator::getFullInstantiatedCppTypenameGenerator
std::string getFullInstantiatedCppTypenameGenerator() const
Definition: Generator.cpp:139
armarx::aron::codegenerator::cpp::generator::VoxelType2Cpp
const std::map< type::pointcloud::VoxelType, std::tuple< std::string, int, std::string > > VoxelType2Cpp
Definition: PointCloud.cpp:32
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
PointCloud.h
armarx::aron::codegenerator::cpp::generator::detail::SpecializedGeneratorBase< type::PointCloud, PointCloud >::type
type::PointCloud type
Definition: SpecializedGenerator.h:52
armarx::aron::codegenerator::cpp::generator::PointCloud::getResetSoftBlock
CppBlockPtr getResetSoftBlock(const std::string &cppAccessor) const final
Definition: PointCloud.cpp:80
armarx::aron::codegenerator::cpp::Generator::resolveMaybeReadBlock
CppBlockPtr resolveMaybeReadBlock(const CppBlockPtr &, const std::string &, const std::string &) const
Definition: Generator.cpp:711
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::aron::codegenerator::cpp::generator
Definition: AnyObject.cpp:29
armarx::aron::codegenerator::cpp::Generator::resolveMaybeEqualsBlock
CppBlockPtr resolveMaybeEqualsBlock(const CppBlockPtr &, const std::string &, const std::string &) const
Definition: Generator.cpp:735
armarx::aron::codegenerator::cpp::generator::PointCloud::PointCloud
PointCloud(const type::PointCloud &)
Definition: PointCloud.cpp:56
std
Definition: Application.h:66
armarx::aron::codegenerator::cpp::Generator::nextEl
std::string nextEl() const
Definition: Generator.cpp:613
armarx::aron::codegenerator::cpp::Generator::resolveMaybeResetSoftBlock
CppBlockPtr resolveMaybeResetSoftBlock(const CppBlockPtr &, const std::string &) const
Definition: Generator.cpp:677
armarx::aron::type::detail::NDArrayVariant::getDefaultValue
std::string getDefaultValue() const
Definition: NDArrayVariant.h:70
armarx::aron::codegenerator::cpp::Generator::ARON_READER_ACCESSOR
static const std::string ARON_READER_ACCESSOR
Definition: Generator.h:151
armarx::aron::codegenerator::cpp::generator::PointCloud::getCtorInitializers
std::pair< std::vector< std::pair< std::string, std::string > >, bool > getCtorInitializers(const std::string &) const final
Definition: PointCloud.cpp:73
armarx::aron::codegenerator::cpp::generator::PointCloud::getRequiredIncludes
std::vector< std::string > getRequiredIncludes() const final
Definition: PointCloud.cpp:67
armarx::aron::type::PointCloud::getVoxelType
type::pointcloud::VoxelType getVoxelType() const
Definition: PointCloud.cpp:62
simox
Definition: Impl.cpp:40
armarx::aron::codegenerator::cpp::Generator::resolveMaybeWriteBlock
CppBlockPtr resolveMaybeWriteBlock(const CppBlockPtr &, const std::string &) const
Definition: Generator.cpp:694
armarx::aron::codegenerator::cpp::conversion::Maybe2CppString
const std::map< type::Maybe, std::string > Maybe2CppString
Definition: Generator.h:49
armarx::aron::Path::getPath
std::vector< std::string > getPath() const
Definition: Path.cpp:85