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 #include <Inventor/nodes/SoDrawStyle.h>
28 
30 {
32  const AffordanceKit::BimanualAffordancePtr& bimanualAffordance) :
33  visualizationNode(nullptr)
34  {
35  affordance = bimanualAffordance;
36  }
37 
39  {
41  {
42  visualizationNode->unref();
43  }
44  }
45 
46  void
48  {
50  {
51  visualizationNode->removeAllChildren();
52  }
53  }
54 
55  void
57  const std::string& layerName,
58  const std::string& id,
59  float minExpectedProbability,
60  const AffordanceKit::PrimitivePtr& primitive)
61  {
62  if (!primitive)
63  {
64  return;
65  }
66 
67  for (auto& entry : *affordance->getTheta())
68  {
69  if (primitive->getId() != entry.first.first->getId())
70  {
71  continue;
72  }
73 
74  AffordanceKit::PrimitivePair pp = entry.first;
75 
76  unsigned int size = primitive->getSamplingSize();
77  if (size == 0 || affordance->getThetaSize(pp) != size * size)
78  {
79  continue;
80  }
81 
82  armarx::DebugDrawer24BitColoredPointCloud pointCloud;
83  pointCloud.pointSize = 7;
84  pointCloud.transparency = 0;
85 
86  // Attention: This implicitly assumes four orientational samplings
87  pointCloud.points.reserve((size / 4) * (size / 4));
88 
89  std::map<std::pair<unsigned int, unsigned int>, AffordanceKit::Belief> maxBeliefMap;
90 
91  const Eigen::MatrixXf& T = affordance->getTheta(pp);
92  for (unsigned int i = 0; i < T.cols(); i++)
93  {
94  unsigned int index1 = i / size;
95  unsigned int index2 = i % size;
96 
97  // Attention: This implicitly assumes four orientational samplings
98  index1 = index1 - (index1 % 4);
99  index2 = index2 - (index2 % 4);
100 
101  // For visualization the index order does not matter
102  std::pair<unsigned int, unsigned int> indices =
103  (index1 <= index2) ? std::pair<unsigned int, unsigned int>(index1, index2)
104  : std::pair<unsigned int, unsigned int>(index2, index1);
105 
106  AffordanceKit::Belief belief(T.col(i));
107  if ((maxBeliefMap.find(indices) == maxBeliefMap.end()) ||
108  (belief.expectedProbability() > maxBeliefMap.at(indices).expectedProbability()))
109  {
110  maxBeliefMap[indices] = belief;
111  }
112  }
113 
114  std::cout << "maxBeliefMap size: " << maxBeliefMap.size() << std::endl;
115 
116  for (auto& entry : maxBeliefMap)
117  {
118  if (entry.second.expectedProbability() < minExpectedProbability)
119  {
120  continue;
121  }
122 
123  const Eigen::Matrix4f& x1 = primitive->getSampling(entry.first.first);
124  const Eigen::Matrix4f& x2 = primitive->getSampling(entry.first.second);
125  Eigen::Vector3i c = AffordanceKit::ColorMap::GetVisualizationColor(entry.second);
126 
127  armarx::DebugDrawer24BitColoredPointCloudElement e1;
128  e1.x = x1(0, 3);
129  e1.y = x1(1, 3);
130  e1.z = x1(2, 3);
131  e1.color = armarx::DrawColor24Bit{
132  (unsigned char)c(0), (unsigned char)c(1), (unsigned char)c(2)};
133  pointCloud.points.push_back(e1);
134 
135  armarx::DebugDrawer24BitColoredPointCloudElement e2;
136  e2.x = x2(0, 3);
137  e2.y = x2(1, 3);
138  e2.z = x2(2, 3);
139  e2.color = armarx::DrawColor24Bit{
140  (unsigned char)c(0), (unsigned char)c(1), (unsigned char)c(2)};
141  pointCloud.points.push_back(e2);
142  }
143 
144  std::cout << "pointCloud size: " << pointCloud.points.size() << std::endl;
145 
146  debugDrawer->set24BitColoredPointCloudVisu(layerName, id + "_sampling", pointCloud);
147  }
148  }
149 } // namespace AffordanceKitArmarX
AffordanceKitArmarX::BimanualAffordanceArmarX::~BimanualAffordanceArmarX
~BimanualAffordanceArmarX()
Definition: BimanualAffordanceArmarX.cpp:38
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
AffordanceKitArmarX::BimanualAffordanceArmarX::reset
void reset()
Definition: BimanualAffordanceArmarX.cpp:47
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
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:56
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:717
AffordanceKitArmarX::BimanualAffordanceArmarX::affordance
AffordanceKit::BimanualAffordancePtr affordance
Definition: BimanualAffordanceArmarX.h:53
AffordanceKitArmarX::BimanualAffordanceArmarX::BimanualAffordanceArmarX
BimanualAffordanceArmarX(const AffordanceKit::BimanualAffordancePtr &bimanualAffordance)
Definition: BimanualAffordanceArmarX.cpp:31
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
T
float T
Definition: UnscentedKalmanFilterTest.cpp:38
AffordanceKitArmarX
Definition: BimanualAffordanceArmarX.cpp:29
AffordanceKitArmarX::BimanualAffordanceArmarX::visualizationNode
SoSeparator * visualizationNode
Definition: BimanualAffordanceArmarX.h:58
BimanualAffordanceArmarX.h