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