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 
31 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:
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) :
67  m_bbox(memoized(calculateBB)(points))
68  {
69  calculateProperties();
70  }
71 
72  virtual double compare(const Feature&) const = 0;
73 
74 protected:
76  double m_len1;
77  double m_len2;
78  double m_len3;
79 
80  double m_longSide;
81  double m_shortSide;
82  double m_mediumSide;
83 
84  double m_area;
85  double m_volume;
86 
87 private:
88  void
89  calculateProperties()
90  {
94  m_area = m_len1 * m_len2 * m_len3;
96 
99 
101  }
102 };
Feature
Definition: Feature.hpp:45
gdiam_bbox::volume
gdiam_real volume() const
Definition: gdiam.h:552
gdiam_approx_mvbb
gdiam_bbox gdiam_approx_mvbb(gdiam_point *start, int size, gdiam_real eps)
Definition: gdiam.cpp:2529
Feature.hpp
BBFeature::m_len3
double m_len3
Definition: BBFeature.hpp:78
BBFeature::m_volume
double m_volume
Definition: BBFeature.hpp:85
gdiam_bbox::low_2
gdiam_real low_2
Definition: gdiam.h:500
gdiam_bbox::high_1
gdiam_real high_1
Definition: gdiam.h:499
memoized
std::function< R(TaggedPoints)> memoized(R(*fn)(const std::vector< Eigen::Vector3f > &))
Definition: Memoizer.hpp:15
gdiam_bbox::low_1
gdiam_real low_1
Definition: gdiam.h:499
gdiam_bbox
Definition: gdiam.h:492
gdiam_point
gdiam_real * gdiam_point
Definition: gdiam.h:24
BBFeature::BBFeature
BBFeature(const std::vector< Eigen::Vector3f > &points)
Definition: BBFeature.hpp:61
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:501
BBFeature::m_len2
double m_len2
Definition: BBFeature.hpp:77
BBFeature::m_longSide
double m_longSide
Definition: BBFeature.hpp:80
BBFeature::m_area
double m_area
Definition: BBFeature.hpp:84
BBFeature::compare
virtual double compare(const Feature &) const =0
gdiam_convert
gdiam_point * gdiam_convert(gdiam_real *start, int size)
Definition: gdiam.cpp:1266
BBFeature::m_mediumSide
double m_mediumSide
Definition: BBFeature.hpp:82
BBFeature::BBFeature
BBFeature(const std::pair< std::string, std::vector< Eigen::Vector3f >> &points)
Definition: BBFeature.hpp:66
max
T max(T t1, T t2)
Definition: gdiam.h:51
gdiam_bbox::high_2
gdiam_real high_2
Definition: gdiam.h:500
BBFeature::m_len1
double m_len1
Definition: BBFeature.hpp:76
BBFeature
Definition: BBFeature.hpp:54
gdiam_bbox::high_3
gdiam_real high_3
Definition: gdiam.h:501
calculateBB
gdiam_bbox calculateBB(const std::vector< Eigen::Vector3f > &points)
Definition: BBFeature.hpp:31
BBFeature::m_bbox
gdiam_bbox m_bbox
Definition: BBFeature.hpp:75
min
T min(T t1, T t2)
Definition: gdiam.h:44
Memoizer.hpp
BBFeature::m_shortSide
double m_shortSide
Definition: BBFeature.hpp:81