40 template <
class MAPNODE>
44 template <
class MAPNODE>
49 template <
class MAPNODE>
54 template <
class MAPNODE>
63 template <
class MAPNODE>
68 splitPathAndFilename(filenamefullpath, &path, &filename);
71 infile.open(filenamefullpath.c_str(), std::ifstream::in);
72 if(!infile.is_open()){
73 OCTOMAP_ERROR_STR(
"Could not open "<< filenamefullpath <<
". MapCollection not loaded.");
80 ok = readTagValue(
"MAPNODEID", infile, &nodeID);
86 std::string mapNodeFilename;
87 ok = readTagValue(
"MAPNODEFILENAME", infile, &mapNodeFilename);
94 ok = readTagValue(
"MAPNODEPOSE", infile, &poseStr);
95 std::istringstream poseStream(poseStr);
97 poseStream >> x >> y >> z;
98 double roll,pitch,yaw;
99 poseStream >> roll >> pitch >> yaw;
100 ok = ok && !poseStream.fail();
107 MAPNODE* node =
new MAPNODE(combinePathAndFilename(path,mapNodeFilename), origin);
111 for(
unsigned int i=0; i<nodes.size(); i++){
117 nodes.push_back(node);
124 template <
class MAPNODE>
126 nodes.push_back(node);
129 template <
class MAPNODE>
135 template <
class MAPNODE>
141 template <
class MAPNODE>
143 for (
const_iterator it = this->begin(); it != this->end(); ++it) {
144 point3d ptrans = (*it)->getOrigin().inv().transform(p);
145 typename MAPNODE::TreeType::NodeType* n = (*it)->getMap()->search(ptrans);
147 if ((*it)->getMap()->isNodeOccupied(n))
return (*it);
152 template <
class MAPNODE>
154 for (
const_iterator it = this->begin(); it != this->end(); ++it) {
155 point3d ptrans = (*it)->getOrigin().inv().transform(p);
156 typename MAPNODE::TreeType::NodeType* n = (*it)->getMap()->search(ptrans);
158 if ((*it)->getMap()->isNodeOccupied(n))
return true;
163 template <
class MAPNODE>
166 return this->isOccupied(q);
170 template <
class MAPNODE>
172 double max_occ_val = 0;
173 bool is_unknown =
true;
174 for (
const_iterator it = this->begin(); it != this->end(); ++it) {
175 point3d ptrans = (*it)->getOrigin().inv().transform(p);
176 typename MAPNODE::TreeType::NodeType* n = (*it)->getMap()->search(ptrans);
178 double occ = n->getOccupancy();
179 if (occ > max_occ_val) max_occ_val = occ;
183 if (is_unknown)
return 0.5;
188 template <
class MAPNODE>
190 bool ignoreUnknownCells,
double maxRange)
const {
191 bool hit_obstacle =
false;
192 double min_dist = 1e6;
195 for (
const_iterator it = this->begin(); it != this->end(); ++it) {
196 point3d origin_trans = (*it)->getOrigin().inv().transform(origin);
197 point3d direction_trans = (*it)->getOrigin().inv().rot().rotate(direction);
198 printf(
"ray from %.2f,%.2f,%.2f in dir %.2f,%.2f,%.2f in node %s\n",
199 origin_trans.
x(), origin_trans.
y(), origin_trans.
z(),
200 direction_trans.
x(), direction_trans.
y(), direction_trans.
z(),
201 (*it)->getId().c_str());
203 if ((*it)->getMap()->castRay(origin_trans, direction_trans, temp_endpoint, ignoreUnknownCells, maxRange)) {
204 printf(
"hit obstacle in node %s\n", (*it)->getId().c_str());
205 double current_dist = origin_trans.
distance(temp_endpoint);
206 if (current_dist < min_dist) {
207 min_dist = current_dist;
208 end = (*it)->getOrigin().transform(temp_endpoint);
217 template <
class MAPNODE>
220 for(
typename std::vector<MAPNODE* >::iterator it = nodes.begin(); it != nodes.end(); ++it){
229 template <
class MAPNODE>
233 std::ofstream outfile(filename.c_str());
234 outfile <<
"#This file was generated by the write-method of MapCollection\n";
236 for(
typename std::vector<MAPNODE* >::iterator it = nodes.begin(); it != nodes.end(); ++it){
237 std::string
id = (*it)->getId();
238 pose6d origin = (*it)->getOrigin();
239 std::string nodemapFilename =
"nodemap_";
240 nodemapFilename.append(
id);
241 nodemapFilename.append(
".bt");
243 outfile <<
"MAPNODEID " <<
id <<
"\n";
244 outfile <<
"MAPNODEFILENAME "<< nodemapFilename <<
"\n";
245 outfile <<
"MAPNODEPOSE " << origin.
x() <<
" " << origin.
y() <<
" " << origin.
z() <<
" "
246 << origin.
roll() <<
" " << origin.
pitch() <<
" " << origin.
yaw() << std::endl;
247 ok = ok && (*it)->writeMap(nodemapFilename);
254 template <
class MAPNODE>
256 double maxrange,
bool pruning,
bool lazy_eval) {
257 fprintf(stderr,
"ERROR: MapCollection::insertScan is not implemented yet.\n");
260 template <
class MAPNODE>
262 for (
const_iterator it = this->begin(); it != this->end(); ++it) {
263 if ((*it)->getId() == id)
return *(it);
269 template <
class MAPNODE>
271 std::vector<Pointcloud*> result;
272 fprintf(stderr,
"ERROR: MapCollection::segment is not implemented yet.\n");
277 template <
class MAPNODE>
279 fprintf(stderr,
"ERROR: MapCollection::associate is not implemented yet.\n");
283 template <
class MAPNODE>
285 std::string* path, std::string *filename) {
287 std::string::size_type lastSlash = filenamefullpath.find_last_of(
'\\');
289 std::string::size_type lastSlash = filenamefullpath.find_last_of(
'/');
291 if (lastSlash != std::string::npos){
292 *filename = filenamefullpath.substr(lastSlash + 1);
293 *path = filenamefullpath.substr(0, lastSlash);
295 *filename = filenamefullpath;
300 template <
class MAPNODE>
302 std::string result = path;
310 result.append(filename);
314 template <
class MAPNODE>
317 while( getline(infile, line) ){
318 if(line.length() != 0 && line[0] !=
'#')
322 std::string::size_type firstSpace = line.find(
' ');
323 if(firstSpace != std::string::npos && firstSpace != line.size()-1){
324 *value = line.substr(firstSpace + 1);