BBLongShort.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 <math.h>
27
28#include <limits>
29#include <vector>
30
31#include "BBFeature.hpp"
32
34{
35public:
37 {
38 }
39
40 BBLongShortRatio(const std::vector<Eigen::Vector3f>& points) : BBFeature(points)
41 {
42 m_name = "BBLongShortRatio";
43
44 m_longShortRatio = m_longSide / m_shortSide;
45 }
46
47 BBLongShortRatio(const std::pair<std::string, std::vector<Eigen::Vector3f>>& points) :
48 BBFeature(points)
49 {
50 m_name = "BBLongShortRatio";
51
52 m_longShortRatio = m_longSide / m_shortSide;
53 }
54
55 double
57 {
58 return m_longShortRatio;
59 }
60
62 calculate(const Points& points)
63 {
64 return FeaturePtr(new BBLongShortRatio(points));
65 }
66
68 calculate(const TaggedPoints& points)
69 {
70 return FeaturePtr(new BBLongShortRatio(points));
71 }
72
73 double
74 compare(const Feature& other) const
75 {
76 const BBLongShortRatio* casted = dynamic_cast<const BBLongShortRatio*>(&other);
77
78 if (casted)
79 {
80 return std::pow(m_longShortRatio - casted->longShortRatio(), 2.0);
81 }
82 else
83 {
84 return std::numeric_limits<double>::max();
85 }
86 }
87
88 virtual void
89 serialize(const ObjectSerializerBasePtr& serializer, const Ice::Current&) const
90 {
91 AbstractObjectSerializerPtr obj = AbstractObjectSerializerPtr::dynamicCast(serializer);
92
94
95 //Check if object already has a "features" field, else create a new one
96 if (obj->hasElement(FEATURE_FIELD_NAME))
97 {
98 featureObj = obj->getElement(FEATURE_FIELD_NAME);
99 featureObj->setDouble(m_name, m_longShortRatio);
100 }
101 else
102 {
103 featureObj = obj->createElement();
104 featureObj->setDouble(m_name, m_longShortRatio);
105 obj->setElement(FEATURE_FIELD_NAME, featureObj);
106 }
107 }
108
109 virtual void
110 deserialize(const ObjectSerializerBasePtr& serializer, const Ice::Current&)
111 {
112 AbstractObjectSerializerPtr obj = AbstractObjectSerializerPtr::dynamicCast(serializer);
113 AbstractObjectSerializerPtr featureObj = obj->getElement(FEATURE_FIELD_NAME);
114 //Now copy the result array from the DB
115 m_longShortRatio = featureObj->getDouble(m_name);
116 }
117
118 virtual std::ostream&
119 output(std::ostream& out) const
120 {
121 return out << m_longShortRatio;
122 }
123
124private:
125 double m_longShortRatio;
126};
const std::string FEATURE_FIELD_NAME
Definition Feature.hpp:43
std::shared_ptr< Feature > FeaturePtr
Definition Feature.hpp:104
double m_longSide
Definition BBFeature.hpp:80
double m_shortSide
Definition BBFeature.hpp:81
BBLongShortRatio(const std::vector< Eigen::Vector3f > &points)
double compare(const Feature &other) const
double longShortRatio() const
FeaturePtr calculate(const TaggedPoints &points)
FeaturePtr calculate(const Points &points)
BBLongShortRatio(const std::pair< std::string, std::vector< Eigen::Vector3f > > &points)
virtual void serialize(const ObjectSerializerBasePtr &serializer, const Ice::Current &) const
virtual void deserialize(const ObjectSerializerBasePtr &serializer, const Ice::Current &)
virtual std::ostream & output(std::ostream &out) const
std::vector< Eigen::Vector3f > Points
Definition Feature.hpp:48
std::shared_ptr< Feature > FeaturePtr
Definition Feature.hpp:50
std::pair< std::string, Points > TaggedPoints
Definition Feature.hpp:49
std::string m_name
Definition Feature.hpp:101
IceInternal::Handle< AbstractObjectSerializer > AbstractObjectSerializerPtr