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