Descriptor.cpp
Go to the documentation of this file.
1 // (C) Copyright Renaud Detry 2007-2015.
2 // Distributed under the GNU General Public License and under the
3 // BSD 3-Clause License (See accompanying file LICENSE.txt).
4 
5 /** @file */
6 
7 #include <nuklei/Descriptor.h>
8 
9 namespace nuklei
10 {
11 
12  const std::string GraspDescriptor::TypeNames[] = {
13  "physical_success", "physical_failure", "physical_unstable",
14  "virtual_success", "virtual_failure", "pe_error", "kinematic_error",
15  "unknown" };
16 
17  double ColorDescriptor::distanceTo(const Descriptor &d) const
18  {
19  NUKLEI_TRACE_BEGIN();
20  const ColorDescriptor* cd = dynamic_cast<const ColorDescriptor*>(&d);
21  if (cd != NULL)
22  {
23  HSVConeColor c1(getColor());
24  HSVConeColor c2(cd->getColor());
25  return c1.distanceTo(c2);
26  }
27  const ColorPairDescriptor* cpd = dynamic_cast<const ColorPairDescriptor*>(&d);
28  if (cpd != NULL)
29  {
30  HSVConeColor c1(getColor());
31  HSVConeColor c2(cpd->getLeftColor());
32  HSVConeColor c3(cpd->getRightColor());
33  return std::min(c1.distanceTo(c2),
34  c1.distanceTo(c3));
35  }
36  NUKLEI_THROW("Not implemented.");
37  NUKLEI_TRACE_END();
38  }
39 
40 
41  double ColorPairDescriptor::distanceTo(const Descriptor &d) const
42  {
43  NUKLEI_TRACE_BEGIN();
44  const ColorDescriptor* cd = dynamic_cast<const ColorDescriptor*>(&d);
45  if (cd != NULL)
46  {
47  HSVConeColor c1(getLeftColor());
48  HSVConeColor c2(getRightColor());
49  HSVConeColor c3(cd->getColor());
50  return std::min(c1.distanceTo(c3),
51  c2.distanceTo(c3));
52  }
53  NUKLEI_THROW("Not implemented.");
54  NUKLEI_TRACE_END();
55  }
56 
57 
58 }
59 
60 #if BOOST_VERSION < 104100
61 
62 BOOST_CLASS_EXPORT_GUID(nuklei::ColorPairDescriptor, "mdfh_Descriptor_ColorPair")
63 BOOST_CLASS_EXPORT_GUID(nuklei::ColorDescriptor, "mdfh_Descriptor_Color")
64 BOOST_CLASS_EXPORT_GUID(nuklei::GraspDescriptor, "mdfh_Descriptor_Grasp")
65 BOOST_CLASS_EXPORT_GUID(nuklei::TwoFingerDescriptor, "mdfh_Descriptor_TwoFinger")
66 BOOST_CLASS_EXPORT_GUID(nuklei::PlaneDescriptor, "mdfh_Descriptor_Plane")
67 BOOST_CLASS_EXPORT_GUID(nuklei::RGBColor, "mdfh_Color_RGB")
68 BOOST_CLASS_EXPORT_GUID(nuklei::HSVColor, "mdfh_Color_HSV")
69 BOOST_CLASS_EXPORT_GUID(nuklei::HSVConeColor, "mdfh_Color_HSVCone")
70 
71 #else
72 
73 NUKLEI_SERIALIZATION_REGISTER_TYPE(nuklei::ColorPairDescriptor)
74 NUKLEI_SERIALIZATION_REGISTER_TYPE(nuklei::ColorDescriptor)
75 NUKLEI_SERIALIZATION_REGISTER_TYPE(nuklei::GraspDescriptor)
76 NUKLEI_SERIALIZATION_REGISTER_TYPE(nuklei::TwoFingerDescriptor)
77 NUKLEI_SERIALIZATION_REGISTER_TYPE(nuklei::PlaneDescriptor)
78 NUKLEI_SERIALIZATION_REGISTER_TYPE(nuklei::RGBColor)
79 NUKLEI_SERIALIZATION_REGISTER_TYPE(nuklei::HSVColor)
80 NUKLEI_SERIALIZATION_REGISTER_TYPE(nuklei::HSVConeColor)
81 
82 #endif // BOOST_VERSION
Definition: Color.h:56
Public namespace.
Definition: Color.cpp:9
Definition: Descriptor.h:115
Definition: Color.h:127
Definition: Descriptor.h:68
Definition: Descriptor.h:307
Definition: Color.h:190
Definition: Descriptor.h:172
Definition: Descriptor.h:229
#define NUKLEI_THROW(x)
Throws an Error.
Definition: Common.h:94
© Copyright 2007-2013 Renaud Detry.
Distributed under the terms of the GNU General Public License (GPL).
(See accompanying file LICENSE.txt or copy at http://www.gnu.org/copyleft/gpl.html.)
Revised Sun Sep 13 2020 19:10:06.