SceneLearningEngine.cpp
Go to the documentation of this file.
1 
19 
20 
22 
23 
24 
26  : mPrivateNamespaceHandle("~")
27  {
28 
29  // Volume of the workspace the scene takes place in.
30  double workspaceVolume;
31 
32  // Parameters of heuristics used for hierarchical clustering.
33  double staticBreakRatio, togetherRatio, maxAngleDeviation;
34 
35  // Try to get the name of the scene model.
36  if(!mPrivateNamespaceHandle.getParam("scene_model_name", mSceneModelName))
37  throw std::runtime_error("Please specify parameter " + std::string("scene_model_name") + " when starting this node.");
38 
39  // Try to get the type of the scene model representation.
40  if(!mPrivateNamespaceHandle.getParam("scene_model_type", mSceneModelType))
41  throw std::runtime_error("Please specify parameter " + std::string("scene_model_type") + " when starting this node.");
42 
43  // Try to get the directory the model should be stored.
44  if(!mPrivateNamespaceHandle.getParam("scene_model_directory", mSceneModelDirectory))
45  throw std::runtime_error("Please specify parameter " + std::string("scene_model_directory") + " when starting this node.");
46 
47  // Get the current date and time for the timestamp.
48  std::stringstream ss;
49  ss.imbue(std::locale(ss.getloc(), new boost::local_time::local_time_facet("%Y-%m-%d %H:%M:%S")));
50  boost::local_time::time_zone_ptr zone_GMT1(new boost::local_time::posix_time_zone("GMT+1"));
51  ss << boost::local_time::local_sec_clock::local_time(zone_GMT1);
52  mDateTime = ss.str();
53 
54 
55  // Try to get names of bag files with PbdSceneGraph message input, if any exist.
57  {
58  throw std::runtime_error("Please specify parameter " + std::string("input_db_file") + " when starting this node.");
59 
60  }
61 
62  // Try to get the volume of the workspace where the scene takes place.
63  if(!mPrivateNamespaceHandle.getParam("workspace_volume", workspaceVolume))
64  throw std::runtime_error("Please specify the 'workspace volume' when starting this node.");
65 
66  // Try to get the volume of the workspace where the scene takes place.
67  if(!mPrivateNamespaceHandle.getParam("static_break_ratio", staticBreakRatio))
68  throw std::runtime_error("Please specify the 'static_break_ratio' when starting this node.");
69 
70  // Try to get the volume of the workspace where the scene takes place.
71  if(!mPrivateNamespaceHandle.getParam("together_ratio", togetherRatio))
72  throw std::runtime_error("Please specify the 'together_ratio' when starting this node.");
73 
74  // Try to get the volume of the workspace where the scene takes place.
75  if(!mPrivateNamespaceHandle.getParam("max_angle_deviation", maxAngleDeviation))
76  throw std::runtime_error("Please specify the 'max_angle_deviation' when starting this node.");
77 
78  // Try to get the name of the scene to be published.
79  if(!mPrivateNamespaceHandle.getParam("base_frame_id", mBaseFrameId))
80  throw std::runtime_error("Please specify parameter " + std::string("base_frame_id") + " when starting this node.");
81 
82  // Try to get the visualization scale factor.
83  if(!mPrivateNamespaceHandle.getParam("scale_factor", mScaleFactor))
84  throw std::runtime_error("Please specify parameter " + std::string("scale_factor") + " when starting this node.");
85 
86  // Try to get the sigma multiplicator.
87  if(!mPrivateNamespaceHandle.getParam("sigma_multiplicator", mSigmaMultiplicator))
88  throw std::runtime_error("Please specify parameter " + std::string("sigma_multiplicator") + " when starting this node.");
89 
90  // Try to get the targeting help flag.
91  if(!mPrivateNamespaceHandle.getParam("intermediate_results", mIntermediateResults))
92  throw std::runtime_error("Please specify parameter " + std::string("intermediate_results") + " when starting this node.");
93 
94  // Try to get the add timestamp to filenames flag.
96  throw std::runtime_error("Please specify parameter " + std::string("timestamps") + " when starting this node.");
97 
98  // Initialize the scene model.
99  initializeSceneModel(workspaceVolume, staticBreakRatio, togetherRatio, maxAngleDeviation);
100  }
101 
103  {
104 
105  }
106 
108  {
109  // If only one string is given to node, just use this as path to scene graphs.
110  // Otherwise load a bunch of files and process input as it was one file.
111 
112 
113  extractTracksFromDbFile(static_cast<std::string>(mInputDbFilename));
114 
115 
116  }
117 
118 
119  void SceneLearningEngine::extractTracksFromDbFile(const std::string& dbFileName)
120  {
121 
122 
123  ROS_INFO_STREAM("Pulling Objects from database " << dbFileName.c_str());
124  tableHelper = ISM::TableHelperPtr(new ISM::TableHelper(dbFileName));
125 
126  for(auto patternName : tableHelper->getRecordedPatternNames())
127  {
128  ISM::RecordedPatternPtr pattern = tableHelper->getRecordedPattern(patternName);
129  for(ISM::ObjectSetPtr objectSet : pattern->objectSets)
130  {
131  objectSet->mIdentifier = pattern->name;
132  mSceneModelLearner->addExample(objectSet);
133  }
134  }
135 
136 
137 
138  }
139 
141  {
142  // Some error checking.
143  if(!mSceneModelLearner)
144  throw std::logic_error("Cannot save a non-existing scene model and plot its distributions.");
145 
146  // Calculates the scene model.
147  mSceneModelLearner->generateSceneModel();
148 
149  // Initialize the visualizer.
151  }
152 
154  {
155  // Some error checking.
156  if(!mSceneModelLearner)
157  throw std::logic_error("Cannot save a non-existing scene model and plot its distributions.");
158 
159  // User information.
160  ROS_INFO_STREAM("Scene model learner: Storing scene model '" << mSceneModelName << "'.");
161 
162  // Build the path to the model file based on the directory, the scene model name and the timestamp (if requried).
163  std::string pathToFile = mSceneModelDirectory + "/";
164 
166  pathToFile += mDateTime + "-";
167 
168  pathToFile += mSceneModelName + ".xml";
169 
170  // Write scene model to file.
171  mSceneModelLearner->saveSceneModelToFile(pathToFile);
172  }
173 
175  {
176  if(mVisualizer)
177  {
179  mVisualizer->drawInLearningTrajectoryMode();
180  else
181  mVisualizer->drawInLearningMode();
182  }
183  }
184 
185  void SceneLearningEngine::initializeSceneModel(double pWorkspaceVolume, double mStaticBreakRatio, double mTogetherRatio, double mMaxAngleDeviation)
186  {
187  mSceneModelLearner.reset(new SceneModelLearner(mSceneModelType, pWorkspaceVolume, mStaticBreakRatio, mTogetherRatio, mMaxAngleDeviation));
188  }
189 
191  {
192  // Status information for the user.
193  ROS_INFO("Initializing visualization mechanism.");
194 
195  // Create a new coordinator for scene visualization.
196  mVisualizer.reset(new Visualization::ProbabilisticSceneModelVisualization());
197 
198  // Order the model to initialize the visualizers.
199  mSceneModelLearner->initializeVisualizer(mVisualizer);
200 
201  // Set drawing parameters.
202  mVisualizer->setDrawingParameters(mScaleFactor, mSigmaMultiplicator, mBaseFrameId);
203  }
204 
205 }
boost::shared_ptr< ISM::TableHelper > tableHelper
boost::shared_ptr< Visualization::ProbabilisticSceneModelVisualization > mVisualizer
void extractTracksFromDbFile(const std::string &dbFileName)
boost::shared_ptr< SceneModelLearner > mSceneModelLearner
void initializeSceneModel(double pWorkspaceVolume, double mStaticBreakRatio, double mTogetherRatio, double mMaxAngleDeviation)
#define ROS_INFO(...)
#define ROS_INFO_STREAM(args)
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