OcmForegroundSceneLearner.cpp
Go to the documentation of this file.
1 
19 
21 
22  OcmForegroundSceneLearner::OcmForegroundSceneLearner(const ISM::ObjectSetPtr pExample)
23  : ForegroundSceneLearner(pExample)
24  {
25  }
26 
28  {
29  }
30 
32  {
33  // Debug message.
34  ROS_INFO_STREAM("Initializing visualizer for scene '" << mSceneName << "'.");
35 
36  // Create a new coordinator for primary scene object visualization.
37  mVisualizer.reset(new Visualization::ProbabilisticSceneVisualization(mSceneName));
38 
39  // Append it to supperior visualizer.
40  mSuperior->appendVisualizer(mVisualizer);
41 
42  // Command scene object learners to initialize their visualizers.
44  learner->initializeVisualizer(mVisualizer);
45  }
46 
47  void OcmForegroundSceneLearner::save(boost::property_tree::ptree& pPt)
48  {
49  // Create a subtree.
50  boost::property_tree::ptree subtree;
51 
52  // Add scene name and type.
53  subtree.add("<xmlattr>.type", "ocm");
54  subtree.add("<xmlattr>.name", mSceneName);
55  subtree.add("<xmlattr>.priori", mPriori);
56 
57  // Command scene object learners to save their content.
59  learner->save(subtree);
60 
61  // Add subtree to main tree.
62  pPt.add_child("psm.scenes.scene", subtree);
63  }
64 
66  {
67  /*****************************************************************************************************************
68  * What we do here:
69  * We create a scene object learner for every unique object in the scene. Objects ARE ONLY IDENTIFIED BY THEIR TYPE,
70  * NOT THEIR INSTANCE. That is because at the time of implementation, no instance information was available!
71  *****************************************************************************************************************/
72  std::vector<std::string> types;
73  // First we iterate over all examples for this scene.
74 
75  ISM::TracksPtr alltracks(new ISM::Tracks(mExamplesList));
76  // Iterate over all examples for all scenes.
77  for (auto &track : alltracks->tracks){
78  // Get the type of the first observation (we assume here that all obserations are of the same type).
79  std::string type = track->type;
80 
81  // Evalute if there already exists an object with the given type.
82  bool isExisting = false;
84  isExisting |= learner->hasType(type);
85 
86  // If no learner was found, create a new one.
87  if(!isExisting) {
89  types.push_back(type);
90  ROS_INFO_STREAM("Found a new scene object of type '" << type << "' in scene '" << mSceneName << "'.");
91  }
92 
93  }
94 
95  ROS_INFO("Building relation tree.");
96 
97  ros::NodeHandle nodeHandle("~");
98  std::string trainerType;
99  // Try to get the type of the relation tree trainer.
100  if(!nodeHandle.getParam("relation_tree_trainer_type", trainerType))
101  {
102  ROS_INFO_STREAM("Could not find ROS parameter relation_tree_trainer_type. Using standard method of hierarchical clustering (value=\"tree\").");
103  trainerType = "tree"; // for compatability with old launch files.
104  }
105 
106  // Create the relation graph.
107  SceneModel::AbstractTrainer trainer;
108  if (trainerType == "tree") // Hierarchical tree, like before, without references.
109  {
110  SceneModel::PSMTrainer psmtrainer(mStaticBreakRatio, mTogetherRatio, mMaxAngleDeviation);
111  psmtrainer.addSceneGraphMessages(mExamplesList);
112  trainer = psmtrainer;
113  }
114  else if (trainerType == "fullymeshed") // Fully meshed topology -> tree with references.
115  {
116  SceneModel::FullyMeshedTrainer fmtrainer;
117  fmtrainer.addSceneGraphMessages(mExamplesList);
118  trainer = fmtrainer;
119  }
120  else if (trainerType == "combinatorial_optimization") // combinatorial optimization
121  {
122  // Preparing learners for use in combinatorial optimization, compare below:
124  {
125  learner->setClusteringParameters(mStaticBreakRatio, mTogetherRatio, mMaxAngleDeviation);
126  learner->setVolumeOfWorkspace(mWorkspaceVolume);
127  learner->setPriori(1.0);
128  }
129 
130  CombinatorialTrainer combinatorialTrainer(mSceneObjectLearners, types);
131  combinatorialTrainer.addSceneGraphMessages(mExamplesList);
132  trainer = combinatorialTrainer;
133  }
134  else throw std::runtime_error("Trainer type " + trainerType + " is invalid. Valid types are tree, fullymeshed, combinatorial_optimization.");
135 
136  //trainer.addSceneGraphMessages(mExamplesList);
137  trainer.loadTrajectoriesAndBuildTree();
138 
139  // Print tree.
140  ROS_INFO("PSM trainer successfully generated tree.");
141  std::cout << "------------- TREE:" << std::endl;
142  trainer.getTree()->printTreeToConsole(0);
143  std::cout << "---------------------" << std::endl;
144 
145  // Now just forward all examples for the scene to the scene object learners.
147  {
148  learner->setClusteringParameters(mStaticBreakRatio, mTogetherRatio, mMaxAngleDeviation);
149  learner->setVolumeOfWorkspace(mWorkspaceVolume);
150  learner->learn(mExamplesList, trainer.getTree());
151  }
152 
153  // DEPRECATED could be removed!
154  // Same problem as in the occurence learner. We don't have tracking, so we don't know anything about the frequency of an object appearing.
155  // We assume an equal distribution over all objects.
157  learner->setPriori(1.0);
158 
159  }
160 
161 }
void initializeVisualizer(boost::shared_ptr< Visualization::ProbabilisticSceneModelVisualization > mSuperior)
void addSceneGraphMessages(std::vector< ISM::ObjectSetPtr > pMessages)
#define ROS_INFO(...)
std::vector< ISM::ObjectSetPtr > mExamplesList
Definition: SceneLearner.h:130
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
boost::shared_ptr< Visualization::ProbabilisticSceneVisualization > mVisualizer
std::vector< boost::shared_ptr< SceneObjectLearner > > mSceneObjectLearners


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