ShapeTermLearner.cpp
Go to the documentation of this file.
1 
19 
21 
22  ShapeTermLearner::ShapeTermLearner(std::string pSceneName)
23  : TermLearner()
24  , mPrivateNamespaceHandle("~")
25  , mSceneName(pSceneName)
26  {
27  }
28 
30  {
31  }
32 
34  {
35  // Iterate over all children of the given node.
36  BOOST_FOREACH(boost::shared_ptr<OcmTree> child, pModel->mRoot->mChildren)
37  {
38  // Learn the pose.
39  learnNodePose(pModel->mRoot, child);
40 
41  // ProceePositiond with the childs children.
42  learn(child);
43  }
44  }
45 
47  {
48  // Iterate over all children of the given node.
49  BOOST_FOREACH(boost::shared_ptr<OcmTree> child, pNode->mChildren)
50  {
51  // Learn the pose.
52  learnNodePose(pNode, child);
53 
54  // Proceed with the childs children.
55  learn(child);
56  }
57  }
58 
60  {
61  // Gets the length of the parent observation trajectory.
62  unsigned int trajectoryLength = pParent->mObjectSet->objects.size();
63 
64  // Check that both observation trajectories have the same length.
65  // If that's not the case, something went wrong in the Scene Graph Generator.
66  if(trajectoryLength != pChild->mObjectSet->objects.size())
67  throw std::runtime_error("Shape term learner: the observation trajectories of child and parent node don't have the same length. This indicates a bug in the scene_graph_generator.");
68 
69  // Try to get the minmal number of kernels.
70  getParameter("kernels_min", mNumberKernelsMin);
71 
72  // Try to get the maximal number of kernels.
73  getParameter("kernels_max", mNumberKernelsMax);
74 
75  // Try to get the number of training runs per kernel.
76  getParameter("runs_per_kernel", mRunsPerKernel);
77 
78  // Try to get the number of synthetic samples per kernel.
79  getParameter("synthetic_samples", mNumberOfSyntheticSamples);
80 
81  // Try to get sample relaxiation interval for the position.
82  getParameter("interval_position", mIntervalPosition);
83 
84  // Try to get sample relaxiation interval for the orientation.
85  getParameter("interval_orientation", mIntervalOrientation);
86 
87  // Try to get the path for the orientation plot.
88  if(!mPrivateNamespaceHandle.getParam("orientation_plot_path", mPathOrientationPlots))
89  mPathOrientationPlots = "UNDEFINED";
90 
91  // Try to get the number of attempts per run.
92  getParameter("attempts_per_run", mAttemptsPerRun);
93 
94  // Create leaners for position and orientation.
97 
98  // Iterate over both trajectories, calculate the relative pose of child to parent and add it to the learners.
99  for(unsigned int i = 0; i < trajectoryLength; i++)
100  {
101  // Extract the positions of child and parent.
102  boost::shared_ptr<ISM::Pose> childPose(pChild->mObjectSet->objects[i]->pose);
103  boost::shared_ptr<ISM::Pose> parentPose(pParent->mObjectSet->objects[i]->pose);
104 
105  // Calculate the relative pose between child and parent.
106  boost::shared_ptr<ISM::Pose> relativePoseToParent;
107  childPose->convertPoseIntoFrame(parentPose, relativePoseToParent);
108 
109  // Add the datum to the learner.
110  learnerPosition.addDatum(relativePoseToParent->point->getEigen());
111  learnerOrientation.addDatum(relativePoseToParent->quat->getEigen());
112  }
113 
114 
115  // Learn GMM over position and add model to child node.
116  ROS_INFO("Learning gaussian mixture model over position.");
117  learnerPosition.learn();
118  learnerPosition.getModel(pChild->mGaussianMixtureModelPosition);
119 
120  // Learn GMM over orientation.
121  ROS_INFO("Learning gaussian mixture model over orientation.");
122  learnerOrientation.learn();
123  learnerOrientation.getModel(pChild->mGaussianMixtureModelOrientation);
124 
125  // Export orientation plots.
126  if(mPathOrientationPlots.compare("UNDEFINED") != 0)
127  learnerOrientation.plotModel();
128  }
129 
130  void ShapeTermLearner::getParameter(std::string pParameterName, double& pParameter)
131  {
132  ros::NodeHandle localNamespaceHandle("~");
133  if (mSceneName != "")
134  localNamespaceHandle = ros::NodeHandle("~/" + mSceneName);
135  if(!localNamespaceHandle.getParam(pParameterName, pParameter))
136  {
137  ROS_DEBUG_STREAM("Could not find parameter " << "~/" << mSceneName << "/" << pParameterName << ". Using unspecific namespace instead.");
138  if (!mPrivateNamespaceHandle.getParam(pParameterName, pParameter))
139  throw std::runtime_error("Please specify parameter " + pParameterName + " when starting this node.");
140  }
141  }
142 
143  void ShapeTermLearner::getParameter(std::string pParameterName, int& pParameter)
144  {
145  double tempParameter;
146  getParameter(pParameterName, tempParameter);
147  pParameter = (int) tempParameter;
148  }
149 
150 }
void getParameter(std::string pParameterName, double &pParameter)
void learnNodePose(boost::shared_ptr< OcmTree > pParent, boost::shared_ptr< OcmTree > pChild)
#define ROS_INFO(...)
#define ROS_DEBUG_STREAM(args)
void learn(boost::shared_ptr< OcmModel > pModel)
bool getParam(const std::string &key, std::string &s) const


asr_psm
Author(s): Braun Kai, Gehrung Joachim, Heizmann Heinrich, Meißner Pascal
autogenerated on Fri Nov 15 2019 03:57:54