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