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