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