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