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 "Feature.hpp"
27 #include "Memoizer.hpp"
28 #include "../gdiam.h"
29 
30 
31 gdiam_bbox calculateBB(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 
54 class BBFeature : public Feature
55 {
56 public:
57  BBFeature() {}
58  BBFeature(const std::vector<Eigen::Vector3f>& points)
59  : m_bbox(calculateBB(points))
60  {
61  calculateProperties();
62  }
63  BBFeature(const std::pair<std::string, std::vector<Eigen::Vector3f>>& points)
64  : m_bbox(memoized(calculateBB)(points))
65  {
66  calculateProperties();
67  }
68  virtual double compare(const Feature&) const = 0;
69 protected:
71  double m_len1;
72  double m_len2;
73  double m_len3;
74 
75  double m_longSide;
76  double m_shortSide;
77  double m_mediumSide;
78 
79  double m_area;
80  double m_volume;
81 private:
82  void calculateProperties()
83  {
87  m_area = m_len1 * m_len2 * m_len3;
89 
92 
94  }
95 };
Feature
Definition: Feature.hpp:44
gdiam_bbox::volume
gdiam_real volume() const
Definition: gdiam.h:535
gdiam_approx_mvbb
gdiam_bbox gdiam_approx_mvbb(gdiam_point *start, int size, gdiam_real eps)
Definition: gdiam.cpp:2637
Feature.hpp
BBFeature::m_len3
double m_len3
Definition: BBFeature.hpp:73
BBFeature::m_volume
double m_volume
Definition: BBFeature.hpp:80
gdiam_bbox::low_2
gdiam_real low_2
Definition: gdiam.h:486
gdiam_bbox::high_1
gdiam_real high_1
Definition: gdiam.h:485
memoized
std::function< R(TaggedPoints)> memoized(R(*fn)(const std::vector< Eigen::Vector3f > &))
Definition: Memoizer.hpp:13
gdiam_bbox::low_1
gdiam_real low_1
Definition: gdiam.h:485
gdiam_bbox
Definition: gdiam.h:477
gdiam_point
gdiam_real * gdiam_point
Definition: gdiam.h:24
BBFeature::BBFeature
BBFeature(const std::vector< Eigen::Vector3f > &points)
Definition: BBFeature.hpp:58
gdiam_real
double gdiam_real
Definition: gdiam.h:20
BBFeature::BBFeature
BBFeature()
Definition: BBFeature.hpp:57
gdiam_bbox::low_3
gdiam_real low_3
Definition: gdiam.h:487
BBFeature::m_len2
double m_len2
Definition: BBFeature.hpp:72
BBFeature::m_longSide
double m_longSide
Definition: BBFeature.hpp:75
BBFeature::m_area
double m_area
Definition: BBFeature.hpp:79
BBFeature::compare
virtual double compare(const Feature &) const =0
gdiam_convert
gdiam_point * gdiam_convert(gdiam_real *start, int size)
Definition: gdiam.cpp:1302
BBFeature::m_mediumSide
double m_mediumSide
Definition: BBFeature.hpp:77
BBFeature::BBFeature
BBFeature(const std::pair< std::string, std::vector< Eigen::Vector3f >> &points)
Definition: BBFeature.hpp:63
max
T max(T t1, T t2)
Definition: gdiam.h:48
gdiam_bbox::high_2
gdiam_real high_2
Definition: gdiam.h:486
BBFeature::m_len1
double m_len1
Definition: BBFeature.hpp:71
BBFeature
Definition: BBFeature.hpp:54
gdiam_bbox::high_3
gdiam_real high_3
Definition: gdiam.h:487
calculateBB
gdiam_bbox calculateBB(const std::vector< Eigen::Vector3f > &points)
Definition: BBFeature.hpp:31
BBFeature::m_bbox
gdiam_bbox m_bbox
Definition: BBFeature.hpp:70
min
T min(T t1, T t2)
Definition: gdiam.h:42
Memoizer.hpp
BBFeature::m_shortSide
double m_shortSide
Definition: BBFeature.hpp:76