ObjectDatabaseRecognizer.cpp
Go to the documentation of this file.
1 
21 #include <ros/ros.h>
22 #include <boost/regex.hpp>
24 #include <ros_uri/ros_uri.hpp>
25 #include <boost/algorithm/string.hpp>
26 
27 namespace object_database
28 {
30  mDatabase(db),
31  mRead(false)
32 { }
33 
35 {
36  return mDatabase.uniqueName();
37 }
38 
40 {
42 }
43 
45 {
46  std::string realPath = ros_uri::absolute_path(mDatabase.objectDbRootFolder());
47  return fs::path(realPath);
48 }
49 
50 void ObjectDatabaseRecognizer::setPath(const fs::path pt)
51 {
52  std::string packageString = ros_uri::package_uri(pt.string());
53  mDatabase.objectDbRootFolder(packageString);
54 }
55 
57 {
59 }
60 
62 {
64 }
65 
67 {
68  return mRead;
69 }
70 
72 {
73  mRead = rd;
74 }
75 
77 {
78  // get the path where the database objects can be found
79  fs::path folder = this->getPath();
80  std::string regexp = this->getRegexp();
81 
82  // if the folder path is no directory or if the folder is already read
83  if (!fs::is_directory(folder))
84  {
85  ROS_DEBUG("'%s' is not a valid folder", folder.c_str());
86  return;
87  } else if (this->isRead())
88  {
89  ROS_DEBUG("'%s' already read", folder.c_str());
90  return;
91  }
92 
93  // Matching the expression regexp
94  boost::regex expression(regexp);
95 
96 
97  for (fs::directory_iterator diriter(folder); diriter != fs::directory_iterator(); diriter++)
98  {
99  fs::path path = *diriter;
100 
101  fs::path filename = path.filename();
102  boost::cmatch what;
103  if (boost::regex_match(filename.c_str(), what, expression))
104  {
105  if (fs::is_directory(path))
106  {
107  std::string strUniqueName;
108 
109  // generate the filename
110  if (what.size() > 1)
111  {
112  strUniqueName = what[1].str();
113  } else
114  {
115  strUniqueName = what[0].str();
116  }
117 
118  fs::path rvizMeshResourcePath = fs::path();
119  fs::path normalVectorResourcePath = fs::path();
120  fs::path deviation_resource_path = fs::path();
121  fs::path rotation_invariance_resource_path = fs::path();
122  for (fs::directory_iterator subdiriter(path); subdiriter != fs::directory_iterator();
123  subdiriter++)
124  {
125  fs::path subdir_path = *subdiriter;
126  fs::path subdir_filename = subdir_path.filename();
127 
128  boost::cmatch match;
129  if (boost::regex_match(subdir_filename.c_str(), match, boost::regex(".*\\.dae")))
130  {
131  rvizMeshResourcePath = subdir_path;
132  } else
133  {
134  if (boost::regex_match(subdir_filename.c_str(), match, boost::regex(".*\\.nv.txt")))
135  {
136  normalVectorResourcePath = subdir_path;
137  }
138  if (boost::regex_match(subdir_filename.c_str(), match, boost::regex(".*\\.dev.txt")))
139  {
140  deviation_resource_path = subdir_path;
141  }
142  if (boost::regex_match(subdir_filename.c_str(), match, boost::regex(".*\\.ri.txt")))
143  {
144  rotation_invariance_resource_path = subdir_path;
145  }
146  }
147  }
148 
149  ObjectDatabaseEntryPtr entryPtr(new ObjectDatabaseEntry(this, strUniqueName,
150  path, rvizMeshResourcePath,
151  normalVectorResourcePath,
152  deviation_resource_path,
153  rotation_invariance_resource_path));
154  mEntries[entryPtr->getUniqueName()] = entryPtr;
155 
156  ROS_DEBUG("File '%s' in db called '%s'", filename.c_str(), strUniqueName.c_str());
157  }
158  }
159  }
160  this->setRead(true);
161 }
162 
164 {
165  return mEntries;
166 }
167 
169 {
170  ObjectDatabaseEntryPtr ptr = this->mEntries[objectName];
171  return *(new ObjectDatabaseEntryPtr(ptr));
172 }
173 }
174 
const objectDbRootFolder_type & objectDbRootFolder() const
const ObjectDatabaseEntryPtr & getEntry(const std::string objectName)
boost::shared_ptr< ObjectDatabaseEntry > ObjectDatabaseEntryPtr
Definition: typedef.h:37
const uniqueName_type & uniqueName() const
std::map< std::string, ObjectDatabaseEntryPtr > ObjectDatabaseEntryPtrMap
Definition: typedef.h:40
::xsd::cxx::tree::string< char, simple_type > string
const basenameMatchPattern_type & basenameMatchPattern() const
#define ROS_DEBUG(...)


asr_object_database
Author(s): Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Braun Kai, Heizmann Heinrich, Heller Florian, Kasper Alexander, Marek Felix, Mehlhaus Jonas, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Walter Milena
autogenerated on Mon Feb 28 2022 21:49:21