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