wykobi_utils.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Fabian Reister ( fabian dot reister at kit dot edu )
17  * @date 2021
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #pragma once
23 
24 #include <algorithm>
25 
26 #include <pcl/point_cloud.h>
27 #include <pcl/point_types.h>
28 
29 #include "wykobi_ext.h"
30 #include "wykobi_types.h"
31 #include <wykobi.hpp>
32 
33 namespace armarx::wykobi
34 {
35 
36  inline pcl::PointXYZ
37  fromWykobi(const wykobi::Point& ptWykobi)
38  {
39  pcl::PointXYZ pt;
40 
41  pt.x = ptWykobi.x;
42  pt.y = ptWykobi.y;
43  pt.z = 0.F;
44 
45  return pt;
46  }
47 
48  template <typename T = float>
49  void
50  project(pcl::PointCloud<pcl::PointXYZ>& cloud, wykobi::Polygon polygon)
51  {
52  const auto toWykobi = [](const pcl::PointXYZ& pt) -> ::wykobi::point2d<T>
53  { return ::wykobi::make_point(pt.x, pt.y); };
54 
55  // project in-place
56  const auto projectPoint = [&](pcl::PointXYZ& pt)
57  {
58  const auto ptWykobi = toWykobi(pt);
59 
60  const ::wykobi::point2d<T> closestPoint =
62 
63  pt = fromWykobi(closestPoint);
64  };
65 
66  std::for_each(cloud.points.begin(), cloud.points.end(), projectPoint);
67  }
68 
69 } // namespace armarx::wykobi
armarx::wykobi::Point
::wykobi::point2d< float > Point
Definition: wykobi_types.h:29
wykobi_ext.h
wykobi_types.h
armarx::wykobi::Polygon
::wykobi::polygon< float, 2 > Polygon
Definition: wykobi_types.h:30
armarx::wykobi::project
void project(pcl::PointCloud< pcl::PointXYZ > &cloud, wykobi::Polygon polygon)
Definition: wykobi_utils.h:50
armarx::wykobi
Definition: models.h:29
armarx::wykobi::fromWykobi
pcl::PointXYZ fromWykobi(const wykobi::Point &ptWykobi)
Definition: wykobi_utils.h:37
armarx::wykobi::ext::closest_point_on_polygon_from_point
inline ::wykobi::point2d< T > closest_point_on_polygon_from_point(const ::wykobi::polygon< T, 2 > &polygon, const ::wykobi::point2d< T > &point)
Compared to wykobi::closest_point_on_polygon_from_point, this function also projects points inside th...
Definition: wykobi_ext.h:33