BBFeature.hpp
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#pragma once
25
26#include "../gdiam.h"
27#include "Feature.hpp"
28#include "Memoizer.hpp"
29
31calculateBB(const std::vector<Eigen::Vector3f>& points)
32{
33 double eps = 0.005;
34 //Convert to gdiam format
35 int size = points.size();
36 gdiam_real* tmpVals = new gdiam_real[size * 3];
37
38 for (int i = 0; i < size * 3; i += 3)
39 {
40 tmpVals[i + 0] = points[i / 3][0];
41 tmpVals[i + 1] = points[i / 3][1];
42 tmpVals[i + 2] = points[i / 3][2];
43 }
44
45 gdiam_point* tmpPoints = gdiam_convert(tmpVals, size);
46 gdiam_bbox bbox = gdiam_approx_mvbb(tmpPoints, size, eps);
47
48 delete[] tmpVals;
49 delete[] tmpPoints;
50
51 return bbox;
52}
53
54class BBFeature : public Feature
55{
56public:
58 {
59 }
60
61 BBFeature(const std::vector<Eigen::Vector3f>& points) : m_bbox(calculateBB(points))
62 {
63 calculateProperties();
64 }
65
66 BBFeature(const std::pair<std::string, std::vector<Eigen::Vector3f>>& points) :
68 {
69 calculateProperties();
70 }
71
72 virtual double compare(const Feature&) const = 0;
73
74protected:
76 double m_len1;
77 double m_len2;
78 double m_len3;
79
80 double m_longSide;
83
84 double m_area;
85 double m_volume;
86
87private:
88 void
89 calculateProperties()
90 {
91 m_len1 = (m_bbox.high_1 - m_bbox.low_1);
92 m_len2 = (m_bbox.high_2 - m_bbox.low_2);
93 m_len3 = (m_bbox.high_3 - m_bbox.low_3);
95 m_volume = m_bbox.volume();
96
97 m_longSide = std::max(m_len1, std::max(m_len2, m_len3));
98 m_shortSide = std::min(m_len1, std::min(m_len2, m_len3));
99
101 }
102};
gdiam_bbox calculateBB(const std::vector< Eigen::Vector3f > &points)
Definition BBFeature.hpp:31
std::function< R(TaggedPoints)> memoized(R(*fn)(const std::vector< Eigen::Vector3f > &))
Definition Memoizer.hpp:15
double m_area
Definition BBFeature.hpp:84
double m_len3
Definition BBFeature.hpp:78
double m_longSide
Definition BBFeature.hpp:80
gdiam_bbox m_bbox
Definition BBFeature.hpp:75
double m_len2
Definition BBFeature.hpp:77
virtual double compare(const Feature &) const =0
double m_mediumSide
Definition BBFeature.hpp:82
double m_volume
Definition BBFeature.hpp:85
BBFeature(const std::pair< std::string, std::vector< Eigen::Vector3f > > &points)
Definition BBFeature.hpp:66
double m_len1
Definition BBFeature.hpp:76
double m_shortSide
Definition BBFeature.hpp:81
BBFeature(const std::vector< Eigen::Vector3f > &points)
Definition BBFeature.hpp:61
gdiam_bbox gdiam_approx_mvbb(gdiam_point *start, int size, gdiam_real eps)
Definition gdiam.cpp:2529
gdiam_point * gdiam_convert(gdiam_real *start, int size)
Definition gdiam.cpp:1266
gdiam_real * gdiam_point
Definition gdiam.h:24
double gdiam_real
Definition gdiam.h:20