23 #include <pcl/common/time.h> 24 #include <pcl/io/pcd_io.h> 33 PbMapLocaliser::PbMapLocaliser(
PbMap& mPbM,
const string& config_file)
35 m_pbMapLocaliser_must_stop(false),
36 m_pbMapLocaliser_finished(false)
39 std::cout <<
"PbMapLocaliser::PbMapLocaliser min_planes_recognition " 53 cout <<
"PbMapLocaliser::LoadPreviousPbMaps(...)\n";
54 std::ifstream configFile;
55 configFile.open(fileMaps.c_str());
57 string mapFile, filepath =
"/home/edu/newPbMaps/";
59 while (!configFile.eof())
62 getline(configFile, mapFile);
63 if (mapFile ==
"")
break;
65 if (mapFile.at(0) ==
'%')
continue;
66 cout <<
"Load map: " << filepath << mapFile << endl;
69 previousPbMap.
loadPbMap(filepath + mapFile);
88 cout <<
"PbMapLocaliser:: previous PbMaps loaded\n";
94 cout <<
"PbMapLocaliser::compareSubgraphNeighbors\n";
104 for (
auto it1 =
mPbMap.
vPlanes[it->first].nearbyPlanes.begin();
111 matchedPbMap.
vPlanes[it->second].nearbyPlanes.begin();
112 it2 != matchedPbMap.
vPlanes[it->second].nearbyPlanes.end();
120 matchedPbMap,
false))
124 for (
auto it_matched =
bestMatch.begin();
125 it_matched !=
bestMatch.end(); it_matched++)
130 matchedPbMap.
vPlanes[it_matched->second]))
139 for (
auto it1 =
mPbMap.
vPlanes[it->first].neighborPlanes.begin();
140 it1 !=
mPbMap.
vPlanes[it->first].neighborPlanes.end(); it1++)
145 for (
auto it2 = matchedPbMap.
vPlanes[it->second]
146 .neighborPlanes.begin();
148 matchedPbMap.
vPlanes[it->second].neighborPlanes.end();
157 matchedPbMap.
vPlanes[it2->first], matchedPbMap,
161 for (
auto it_matched =
bestMatch.begin();
162 it_matched !=
bestMatch.end(); it_matched++)
166 matchedPbMap.
vPlanes[it2->first],
167 matchedPbMap.
vPlanes[it_matched->second]))
184 cout <<
"getAreaMatch " << area << endl;
197 cout <<
"\nSearching plane P" << searchPlane.
id <<
" numNeigs " 211 for (
size_t i = 0; i < prevPbMap.
vPlanes.size(); i++)
234 Subgraph targetSubgraph(&prevPbMap, targetPlane.
id);
241 std::map<unsigned, unsigned> resultingMatch =
246 if (resultingMatch.size() >
bestMatch.size())
264 cout <<
"bestMatch size " <<
bestMatch.size() <<
" min " 273 cout <<
"Context matched\n";
284 pcl::PointXYZ placePos(0, 0, 0);
288 winnerPbMap.
vPlanes[it->second].label)
294 winnerPbMap.
vPlanes[it->second].label))
296 cout <<
"Re-assign plane label\n";
304 [winnerPbMap.
vPlanes[it->second].label]
308 winnerPbMap.
vPlanes[it->second].label;
320 cout <<
"Assign plane label\n";
327 winnerPbMap.
vPlanes[it->second].label;
364 Eigen::Matrix4f rigidTransf;
365 Eigen::Matrix4f rigidTransfInv;
368 rigidTransfInv =
inverse(rigidTransf);
371 pcl::PCDReader reader;
372 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr
model(
373 new pcl::PointCloud<pcl::PointXYZRGBA>);
374 string filename =
"/home/edu/Projects/PbMaps/" +
376 reader.read(filename, *
model);
391 bool placeFound =
false;
393 std::map<unsigned, vector<double>> timeLocalizer;
394 std::map<unsigned, vector<int>> nCheckLocalizer;
402 std::this_thread::sleep_for(50ms);
417 .nearbyPlanes.size() <
431 .neighborPlanes.size() <
443 double search_plane_start = pcl::getTime();
450 double search_plane_end = pcl::getTime();
451 std::cout <<
"PLACE FOUND. Search took " 452 << double(search_plane_end - search_plane_start)
461 double search_plane_end = pcl::getTime();
463 .neighborPlanes.size()) == 0)
466 .neighborPlanes.size()]
468 double(search_plane_end - search_plane_start));
470 .neighborPlanes.size()]
475 vector<double> firstElement(
476 1,
double(search_plane_end - search_plane_start));
479 .neighborPlanes.size()] = firstElement;
481 .neighborPlanes.size()] = firstElement_;
485 double search_plane_end = pcl::getTime();
487 <<
"Search a plane took " 488 << double(search_plane_end - search_plane_start)
496 cout <<
"Print TIME PbLocalizer\n";
497 cout <<
"Tiempo1 " <<
time1 <<
" tiempo2 " <<
time2 << endl;
499 auto itChecks = nCheckLocalizer.begin();
500 for (
auto it = timeLocalizer.begin(); it != timeLocalizer.end(); it++)
502 double sum_times = 0;
503 double sum_nChecks = 0;
504 for (
unsigned j = 0; j < it->second.size(); j++)
506 sum_times += it->second[j];
507 sum_nChecks += itChecks->second[j];
511 cout <<
"Size " << it->first <<
" time " 512 << sum_times / it->second.size() << endl;
513 cout <<
"... nChecks " << sum_nChecks / it->second.size() << endl;
521 cout <<
"Waiting for PbMapLocaliser thread to die.." << endl;
void loadPbMap(std::string PbMapFile)
void load_params(const std::string &config_file_name)
std::vector< std::string > previousPbMapNames
std::thread pbMapLocaliser_hd
std::map< std::string, pcl::PointXYZ > foundPlaces
unsigned min_planes_recognition
A class used to store a planar feature (Plane for short).
float intensity_threshold
std::map< unsigned, unsigned > neighborPlanes
bool m_pbMapLocaliser_must_stop
pcl::PointCloud< pcl::PointXYZRGBA >::Ptr alignedModelPtr
Eigen::Matrix< dataType, 4, 4 > inverse(Eigen::Matrix< dataType, 4, 4 > &pose)
std::set< unsigned > nearbyPlanes
GLsizei const GLchar ** string
bool stop_pbMapLocaliser()
std::vector< unsigned > vQueueObservedPlanes
std::map< unsigned, unsigned > bestMatch
bool searchPlaneContext(Plane &searchPlane)
! Searches the input plane in the rest of planes of the map taking into account the neighboring relat...
bool m_pbMapLocaliser_finished
void compareSubgraphNeighbors(SubgraphMatcher &matcher)
config_heuristics configLocaliser
std::map< unsigned, unsigned > compareSubgraphs(Subgraph &subgraphSource, Subgraph &subgraphTarget, const int option=0)
unsigned id
! Parameters to allow the plane-based representation of the map by a graph
bool evalUnaryConstraints(Plane &plane1, Plane &plane2, PbMap &trgPbMap, bool useStructure=false)
! Check if the two input planes could be the same
bool evalBinaryConstraints(Plane &plane1, Plane &plane2, Plane &planeA, Plane &planeB)
! Compares the relation between Ref-neigRef with the relation between Check-neigCheck.
void LoadPreviousPbMaps(std::string fileMaps)
std::set< unsigned > subgraphPlanesIdx
std::vector< Plane > vPlanes
std::vector< PbMap > previousPbMaps
A class used to store a Plane-based Map (PbMap).
std::map< std::string, std::pair< int, double > > planeRecognitionLUT
*PbMapLocaliser y montarlo en un define *size_t totalPrevPlanes
Eigen::Matrix4f getRTwithModel(std::map< unsigned, unsigned > &matched_planes)