OcmTree.cpp
Go to the documentation of this file.
1 
19 
21 
23  {
24  // Set the type.
25  mType = pRoot->mObjectSet->objects[0]->type;
26 
27  // Take object observations.
28  mObjectSet = pRoot->mObjectSet;
29 
30  mIsReference = pRoot->mIsReference;
31  if (mIsReference) mReferenceToID = pRoot->mReferenceTo->mID;
32 
33  // Create child nodes and copy observations.
34  BOOST_FOREACH(boost::shared_ptr<SceneModel::TreeNode> child, pRoot->mChildren)
35  mChildren.push_back(boost::shared_ptr<OcmTree>(new OcmTree(child)));
36  }
37 
39  {
40  }
41 
43  {
44  // Debug message.
45  ROS_INFO_STREAM("Initializing visualizer for secondary scene object '" << mType << "'.");
46 
47  // Initialize the visualizer for the gaussian mixture distribution.
49 
50  // Set the pose of the parent object.
51  unsigned int lastObservationOffset = mObjectSet->objects.size() - 1;
52  mSuperior->setPose(*new boost::shared_ptr<ISM::Pose>(new ISM::Pose(*mObjectSet->objects[lastObservationOffset]->pose)));
53 
54  // Iterate over all child nodes and append them, too!
55  BOOST_FOREACH(boost::shared_ptr<OcmTree> child, mChildren)
56  child->initializeVisualizer(mSuperior, this);
57  }
58 
60  OcmTree* pParent)
61  {
62  // Debug message.
63  ROS_INFO_STREAM("Initializing visualizer for secondary scene object '" << mType << "'.");
64 
65  // Create a new coordinator for seondary scene object visualization.
66  mVisualizer.reset(new Visualization::ProbabilisticSecondarySceneObjectVisualization(mType));
67 
68  // Append it to supperior visualizer.
69  mSuperior->appendVisualizer(mVisualizer);
70 
71  // Initialize the visualizer for the gaussian mixture distribution.
73 
74  // Extract the trajectory used for learning to the visualizer.
75  std::vector<Eigen::Vector3d> mRelativeSamples;
76  std::vector<Eigen::Vector3d> mAbsoluteSamples;
77  std::vector<Eigen::Vector3d> mParentSamples;
78  for(unsigned int i = 0; i < mObjectSet->objects.size(); i++)
79  {
80  // Extract the positions of child and parent.
81  boost::shared_ptr<ISM::Pose> childPose(*new boost::shared_ptr<ISM::Pose>(new ISM::Pose(*mObjectSet->objects[i]->pose)));
82  boost::shared_ptr<ISM::Pose> parentPose(*new boost::shared_ptr<ISM::Pose>(new ISM::Pose(*pParent->mObjectSet->objects[i]->pose)));
83 
84  // All samples and gaussian kernels will be drawn relative to the praent object.
85  mVisualizer->setParentPose(parentPose);
86  //mVisualizer->setParentPose(parentPose);
87 
88  // Calculate the relative pose between child and parent.
89  boost::shared_ptr<ISM::Pose> relativePoseToParent;
90  childPose->convertPoseIntoFrame(parentPose, relativePoseToParent);
91 
92  // Add relative sample, absolute sample and corresponding parent pose to the list.
93  mAbsoluteSamples.push_back(childPose->point->eigen);
94  mParentSamples.push_back(parentPose->point->eigen);
95  mRelativeSamples.push_back(relativePoseToParent->point->eigen);
96  }
97 
98  // Forward relative learning samples, absolute learning samples and the corresponding parent poses
99  // for the secondary scene object to the visualizer.
100  mVisualizer->setAbsoluteLearningSamples(mRelativeSamples, mAbsoluteSamples, mParentSamples);
101 
102  // Iterate over all child nodes and append them, too!
103  BOOST_FOREACH(boost::shared_ptr<OcmTree> child, mChildren)
104  child->initializeVisualizer(mSuperior, this);
105  }
106 
107  void OcmTree::saveShape(boost::property_tree::ptree& pPt)
108  {
109  // Create a seperate tree.
110  boost::property_tree::ptree subtree;
111 
112  // Add the name of the child.
113  subtree.add("<xmlattr>.name", mType);
114 
115  // If reference: add ID of referenced
116  if (mIsReference) subtree.add("<xmlattr>.references", mReferenceToID);
117 
118  // Save the pose.
119  mGaussianMixtureModelPosition.save(subtree, "position");
120  mGaussianMixtureModelOrientation.save(subtree, "orientation");
121 
122  // Iterate over all children of the root node and save them.
123  BOOST_FOREACH(boost::shared_ptr<OcmTree> child, mChildren)
124  child->saveShape(subtree);
125 
126  // Add subtree to main tree.
127  pPt.add_child("child", subtree);
128  }
129 
131  {
132  if (mIsReference) return 0; // Do not count references as unique nodes
133 
134  unsigned int result = 1;
135 
136  BOOST_FOREACH(boost::shared_ptr<OcmTree> child, mChildren)
137  result += child->getNumberOfNodes();
138 
139  return result;
140  }
141 
142 }
std::vector< boost::shared_ptr< OcmTree > > mChildren
Definition: OcmTree.h:114
void save(boost::property_tree::ptree &pPt, std::string pNode)
void initializeVisualizer(boost::shared_ptr< Visualization::ProbabilisticSecondarySceneObjectVisualization > mSuperior)
GaussianMixtureModel mGaussianMixtureModelPosition
Definition: OcmTree.h:120
OcmTree(const boost::shared_ptr< SceneModel::TreeNode > pRoot)
Definition: OcmTree.cpp:22
void saveShape(boost::property_tree::ptree &pPt)
Definition: OcmTree.cpp:107
GaussianMixtureModel mGaussianMixtureModelOrientation
Definition: OcmTree.h:126
#define ROS_INFO_STREAM(args)
void initializeVisualizer(boost::shared_ptr< Visualization::ProbabilisticPrimarySceneObjectVisualization > mSuperior)
Definition: OcmTree.cpp:42
boost::shared_ptr< ISM::ObjectSet > mObjectSet
Definition: OcmTree.h:109
boost::shared_ptr< Visualization::ProbabilisticSecondarySceneObjectVisualization > mVisualizer
Definition: OcmTree.h:131


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