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& name) const
74 {
75 /** for now we do not have any default values
76 if (type.getDefaultValue() == aron::type::pointcloud::default_value::DEFAULT ||
77 type.getDefaultValue() == aron::type::pointcloud::default_value::ZEROS)
78 {
79 return {{{name, getInstantiatedCppTypename() + "::Zero()"}}, true};
80 }
81 else if (type.getDefaultValue() == aron::type::pointcloud::default_value::ONES)
82 {
83 return {{{name, getInstantiatedCppTypename() + "::One()"}}, true};
84 }
85 else
86 */
87
88 if (type.getDefaultValue() == aron::type::pointcloud::default_value::DEFAULT ||
89 type.getDefaultValue() == aron::type::pointcloud::default_value::ZEROS)
90 {
91 std::cerr << "Currently ARON does not support default values for pointclouds. Ignoring "
92 "your request";
93 }
94 else if (type.getDefaultValue() == aron::type::pointcloud::default_value::ONES)
95 {
96 std::cerr << "Currently ARON does not support default values for pointclouds. Ignoring "
97 "your request";
98 }
99
100 if (type.getMaybe() == type::Maybe::OPTIONAL)
101 {
102 return {{{name, "std::nullopt"}}, true};
103 }
104 return {{}, false};
105 }
106
108 PointCloud::getResetSoftBlock(const std::string& cppAccessor) const
109 {
110 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
111 block_if_data->addLine(cppAccessor + " = " + getFullInstantiatedCppTypenameGenerator() +
112 "(" + cppAccessor + nextEl() + "width, " + cppAccessor + nextEl() +
113 "height);");
114 return this->resolveMaybeResetSoftBlock(block_if_data, cppAccessor);
115 }
116
118 PointCloud::getWriteTypeBlock(const std::string& typeAccessor,
119 const std::string& cppAccessor,
120 const Path& p,
121 std::string& variantAccessor) const
122 {
123 CppBlockPtr b = std::make_shared<CppBlock>();
124 std::string escaped_accessor = EscapeAccessor(cppAccessor);
125 variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor;
126
127 b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writePointCloud(" +
128 std::get<2>(VoxelType2Cpp.at(type.getVoxelType())) + ", " + "\"" +
129 type.getDefaultValue() + "\", " +
130 conversion::Maybe2CppString.at(type.getMaybe()) + ", " + "armarx::aron::Path(" +
131 ARON_PATH_ACCESSOR + ", {" + simox::alg::join(p.getPath(), ", ") +
132 "})); // of " + cppAccessor);
133 return b;
134 }
135
137 PointCloud::getWriteBlock(const std::string& cppAccessor,
138 const Path& p,
139 std::string& variantAccessor) const
140 {
141 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
142 std::string escaped_accessor = EscapeAccessor(cppAccessor);
143 variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor;
144
145 block_if_data->addLine(
146 variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeNDArray({ static_cast<int>(" +
147 cppAccessor + nextEl() + "width), static_cast<int>(" + cppAccessor + nextEl() +
148 "height), " + std::to_string(std::get<1>(VoxelType2Cpp.at(type.getVoxelType()))) +
149 "}, " + "\"" + std::get<0>(VoxelType2Cpp.at(type.getVoxelType())) + "\", " +
150 "reinterpret_cast<const unsigned char*>(" + cppAccessor + nextEl() +
151 "points.data()), " + "armarx::aron::Path(" + ARON_PATH_ACCESSOR + ", {" +
152 simox::alg::join(p.getPath(), ", ") + "})); // of " + cppAccessor);
153
154 return resolveMaybeWriteBlock(block_if_data, cppAccessor);
155 }
156
158 PointCloud::getReadBlock(const std::string& cppAccessor,
159 const std::string& variantAccessor) const
160 {
161 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
162 std::string escaped_accessor = EscapeAccessor(cppAccessor);
163 std::string type = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor + "_typeAsString";
164 std::string dims = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor + "_shape";
165 std::string data = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor + "_data";
166
167 block_if_data->addLine("std::string " + type + ";");
168 block_if_data->addLine("std::vector<int> " + dims + ";");
169 block_if_data->addLine("std::vector<unsigned char> " + data + ";");
170 block_if_data->addLine("" + ARON_READER_ACCESSOR + ".readNDArray(" + variantAccessor +
171 ", " + dims + ", " + type + ", " + data + "); // of " + cppAccessor);
172
173 block_if_data->addLine(
174 "ARMARX_CHECK_AND_THROW(" + dims +
175 ".size() == 3, ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, \"Received "
176 "wrong dimensions for member '" +
177 cppAccessor + "'.\"));");
178 block_if_data->addLine("ARMARX_CHECK_AND_THROW(" + type + " == \"" +
179 std::get<0>(VoxelType2Cpp.at(this->type.getVoxelType())) +
180 "\", ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, "
181 "\"Received wrong type for member '" +
182 cppAccessor + "'.\"));");
183
184 // assign is not availablePCL for PCL 1.8
185 // block_if_data->addLine(cppAccessor + nextEl() + "assign(" + dims + "[0], " + dims + "[1], " + std::get<0>(VoxelType2Cpp.at(this->type.getVoxelType())) + "());");
186 block_if_data->addLine(cppAccessor + nextEl() + "clear();");
187 // resize(width, height , value) is not available either
188 // block_if_data->addLine(cppAccessor + nextEl() + "resize(" + dims + "[0], " + dims + "[1], " + std::get<0>(VoxelType2Cpp.at(this->type.getVoxelType())) + "()));");
189 block_if_data->addLine(cppAccessor + nextEl() + "resize(" + dims + "[0] * " + dims +
190 "[1]);");
191 block_if_data->addLine(cppAccessor + nextEl() + "width = " + dims + "[0];");
192 block_if_data->addLine(cppAccessor + nextEl() + "height = " + dims + "[1];");
193
194 block_if_data->addLine("std::memcpy(reinterpret_cast<unsigned char*>(" + cppAccessor +
195 nextEl() + "points.data()), " + data + ".data(), " + data +
196 ".size());");
197 return resolveMaybeReadBlock(block_if_data, cppAccessor, variantAccessor);
198 }
199
201 PointCloud::getEqualsBlock(const std::string& accessor,
202 const std::string& otherInstanceAccessor) const
203 {
204 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
205 block_if_data->addLine("if (" + accessor + nextEl() + "width != " + otherInstanceAccessor +
206 nextEl() + "width || " + accessor + nextEl() +
207 "height != " + otherInstanceAccessor + nextEl() + "height)");
208 block_if_data->addLineAsBlock("return false;");
209
210 //block_if_data->addLine("if (" + accessor + nextEl() + "points != " + otherInstanceAccessor + nextEl() + "points)");
211 //block_if_data->addLine("\t return false;");
212 return resolveMaybeEqualsBlock(block_if_data, accessor, otherInstanceAccessor);
213 }
214} // namespace armarx::aron::codegenerator::cpp::generator
The Path class.
Definition Path.h:36
std::vector< std::string > getPath() const
Definition Path.cpp:87
CppBlockPtr resolveMaybeEqualsBlock(const CppBlockPtr &, const std::string &, const std::string &) const
CppBlockPtr resolveMaybeReadBlock(const CppBlockPtr &, const std::string &, const std::string &) const
static std::string EscapeAccessor(const std::string &)
Definition Generator.cpp:53
std::string getFullInstantiatedCppTypenameGenerator() const
CppBlockPtr resolveMaybeResetSoftBlock(const CppBlockPtr &, const std::string &) const
static const std::string ARON_READER_ACCESSOR
Definition Generator.h:164
static const std::string ARON_PATH_ACCESSOR
Definition Generator.h:163
static const std::string ARON_WRITER_ACCESSOR
Definition Generator.h:165
static const std::string ARON_VARIANT_RETURN_ACCESSOR
Definition Generator.h:167
CppBlockPtr resolveMaybeWriteBlock(const CppBlockPtr &, const std::string &) const
CppBlockPtr getReadBlock(const std::string &cppAccessor, const std::string &variantAccessor) const final
std::vector< std::string > getRequiredIncludes() const final
CppBlockPtr getEqualsBlock(const std::string &cppAccessor, const std::string &) const final
CppBlockPtr getWriteTypeBlock(const std::string &typeAccessor, const std::string &cppAccessor, const Path &, std::string &variantAccessor) const final
std::pair< std::vector< std::pair< std::string, std::string > >, bool > getCtorInitializers(const std::string &) const final
CppBlockPtr getWriteBlock(const std::string &cppAccessor, const Path &, std::string &variantAccessor) const final
CppBlockPtr getResetSoftBlock(const std::string &cppAccessor) const final
The PointCloud class.
Definition PointCloud.h:40
const std::map< type::Maybe, std::string > Maybe2CppString
Definition Generator.h:48
const std::map< type::pointcloud::VoxelType, std::tuple< std::string, int, std::string > > VoxelType2Cpp
A convenience header to include all aron files (full include, not forward declared)
std::shared_ptr< CppBlock > CppBlockPtr
Definition CppBlock.h:37
Definition Impl.cpp:41