BimanualAffordanceArmarX.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * ArmarX is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  *
17  * @package AffordanceKitArmarX
18  * @author Peter Kaiser ( peter dot kaiser at kit dot edu )
19  * @date 2016
20  * @copyright http://www.gnu.org/licenses/gpl.txt
21  * GNU General Public License
22  */
23 
25 
26 #include <AffordanceKit/ColorMap.h>
27 
28 #include <Inventor/nodes/SoDrawStyle.h>
29 
31 {
32  BimanualAffordanceArmarX::BimanualAffordanceArmarX(const AffordanceKit::BimanualAffordancePtr& bimanualAffordance) :
33  visualizationNode(nullptr)
34  {
35  affordance = bimanualAffordance;
36  }
37 
39  {
41  {
42  visualizationNode->unref();
43  }
44  }
45 
47  {
49  {
50  visualizationNode->removeAllChildren();
51  }
52  }
53 
54  void BimanualAffordanceArmarX::visualize(const armarx::DebugDrawerInterfacePrx& debugDrawer, const std::string& layerName, const std::string& id, float minExpectedProbability, const AffordanceKit::PrimitivePtr& primitive)
55  {
56  if (!primitive)
57  {
58  return;
59  }
60 
61  for (auto& entry : *affordance->getTheta())
62  {
63  if (primitive->getId() != entry.first.first->getId())
64  {
65  continue;
66  }
67 
68  AffordanceKit::PrimitivePair pp = entry.first;
69 
70  unsigned int size = primitive->getSamplingSize();
71  if (size == 0 || affordance->getThetaSize(pp) != size * size)
72  {
73  continue;
74  }
75 
76  armarx::DebugDrawer24BitColoredPointCloud pointCloud;
77  pointCloud.pointSize = 7;
78  pointCloud.transparency = 0;
79 
80  // Attention: This implicitly assumes four orientational samplings
81  pointCloud.points.reserve((size / 4) * (size / 4));
82 
83  std::map<std::pair<unsigned int, unsigned int>, AffordanceKit::Belief> maxBeliefMap;
84 
85  const Eigen::MatrixXf& T = affordance->getTheta(pp);
86  for (unsigned int i = 0; i < T.cols(); i++)
87  {
88  unsigned int index1 = i / size;
89  unsigned int index2 = i % size;
90 
91  // Attention: This implicitly assumes four orientational samplings
92  index1 = index1 - (index1 % 4);
93  index2 = index2 - (index2 % 4);
94 
95  // For visualization the index order does not matter
96  std::pair<unsigned int, unsigned int> indices = (index1 <= index2) ? std::pair<unsigned int, unsigned int>(index1, index2) : std::pair<unsigned int, unsigned int>(index2, index1);
97 
98  AffordanceKit::Belief belief(T.col(i));
99  if ((maxBeliefMap.find(indices) == maxBeliefMap.end()) || (belief.expectedProbability() > maxBeliefMap.at(indices).expectedProbability()))
100  {
101  maxBeliefMap[indices] = belief;
102  }
103  }
104 
105  std::cout << "maxBeliefMap size: " << maxBeliefMap.size() << std::endl;
106 
107  for (auto& entry : maxBeliefMap)
108  {
109  if (entry.second.expectedProbability() < minExpectedProbability)
110  {
111  continue;
112  }
113 
114  const Eigen::Matrix4f& x1 = primitive->getSampling(entry.first.first);
115  const Eigen::Matrix4f& x2 = primitive->getSampling(entry.first.second);
116  Eigen::Vector3i c = AffordanceKit::ColorMap::GetVisualizationColor(entry.second);
117 
118  armarx::DebugDrawer24BitColoredPointCloudElement e1;
119  e1.x = x1(0, 3);
120  e1.y = x1(1, 3);
121  e1.z = x1(2, 3);
122  e1.color = armarx::DrawColor24Bit {(unsigned char)c(0), (unsigned char)c(1), (unsigned char)c(2)};
123  pointCloud.points.push_back(e1);
124 
125  armarx::DebugDrawer24BitColoredPointCloudElement e2;
126  e2.x = x2(0, 3);
127  e2.y = x2(1, 3);
128  e2.z = x2(2, 3);
129  e2.color = armarx::DrawColor24Bit {(unsigned char)c(0), (unsigned char)c(1), (unsigned char)c(2)};
130  pointCloud.points.push_back(e2);
131  }
132 
133  std::cout << "pointCloud size: " << pointCloud.points.size() << std::endl;
134 
135  debugDrawer->set24BitColoredPointCloudVisu(layerName, id + "_sampling", pointCloud);
136  }
137  }
138 }
AffordanceKitArmarX::BimanualAffordanceArmarX::~BimanualAffordanceArmarX
~BimanualAffordanceArmarX()
Definition: BimanualAffordanceArmarX.cpp:38
AffordanceKitArmarX::BimanualAffordanceArmarX::reset
void reset()
Definition: BimanualAffordanceArmarX.cpp:46
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
AffordanceKitArmarX::BimanualAffordanceArmarX::visualize
void visualize(const armarx::DebugDrawerInterfacePrx &debugDrawer, const std::string &layerName, const std::string &id, float minExpectedProbability, const AffordanceKit::PrimitivePtr &primitive)
Definition: BimanualAffordanceArmarX.cpp:54
pcl::graph::indices
pcl::PointIndices::Ptr indices(const PCG &g)
Retrieve the indices of the points of the point cloud stored in a point cloud graph that actually bel...
Definition: point_cloud_graph.h:737
AffordanceKitArmarX::BimanualAffordanceArmarX::affordance
AffordanceKit::BimanualAffordancePtr affordance
Definition: BimanualAffordanceArmarX.h:52
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
AffordanceKitArmarX::BimanualAffordanceArmarX::BimanualAffordanceArmarX
BimanualAffordanceArmarX(const AffordanceKit::BimanualAffordancePtr &bimanualAffordance)
Definition: BimanualAffordanceArmarX.cpp:32
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
AffordanceKitArmarX
Definition: BimanualAffordanceArmarX.cpp:30
AffordanceKitArmarX::BimanualAffordanceArmarX::visualizationNode
SoSeparator * visualizationNode
Definition: BimanualAffordanceArmarX.h:57
BimanualAffordanceArmarX.h