diff options
author | vng <viktor.govako@gmail.com> | 2014-01-11 19:17:33 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:13:17 +0300 |
commit | e7a0ed8300cdffcc00e325045beffef7231dfce9 (patch) | |
tree | 6ee1f6779957972f183b494912ca73f01ccfe81e /search | |
parent | 00cac249971137b25cded35b10d0acf0ed53c0da (diff) |
[search] Added some debug functions.
Diffstat (limited to 'search')
-rw-r--r-- | search/house_detector.cpp | 120 | ||||
-rw-r--r-- | search/house_detector.hpp | 1 |
2 files changed, 100 insertions, 21 deletions
diff --git a/search/house_detector.cpp b/search/house_detector.cpp index 7bba0ef6c4..7f7de4f317 100644 --- a/search/house_detector.cpp +++ b/search/house_detector.cpp @@ -10,10 +10,83 @@ #include "../std/set.hpp" #include "../std/bind.hpp" +#ifdef DEBUG +#include "../platform/platform.hpp" + +#include "../std/iostream.hpp" +#include "../std/fstream.hpp" +#endif + namespace search { +namespace +{ + +#ifdef DEBUG +void Houses2KML(ostream & s, map<search::House, double> const & m) +{ + for (map<search::House, double>::const_iterator it = m.begin(); it != m.end(); ++it) + { + m2::PointD const & pt = it->first.GetPosition(); + + s << "<Placemark>" + << "<name>" << it->first.GetNumber() << "</name>" + + << "<Point><coordinates>" + << MercatorBounds::XToLon(pt.x) + << "," + << MercatorBounds::YToLat(pt.y) + + << "</coordinates></Point>" + << "</Placemark>" << endl; + } +} + +void Street2KML(ostream & s, vector<m2::PointD> const & pts, char const * color) +{ + s << "<Placemark>" << endl; + s << "<Style><LineStyle><color>" << color << "</color></LineStyle></Style>" << endl; + + s << "<LineString><coordinates>" << endl; + for (size_t i = 0; i < pts.size(); ++i) + { + s << MercatorBounds::XToLon(pts[i].x) << "," << MercatorBounds::YToLat(pts[i].y) << "," << "0.0" << endl; + } + s << "</coordinates></LineString>" << endl; + + s << "</Placemark>" << endl; +} + +void Streets2KML(ostream & s, vector<Street *> const & v, char const * color) +{ + for (size_t i = 0; i < v.size(); ++i) + Street2KML(s, v[i]->m_points, color); +} + +class KMLFileGuard +{ + ofstream m_file; +public: + KMLFileGuard(string const & name) + { + m_file.open(GetPlatform().WritablePathForFile(name).c_str()); + + m_file << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; + m_file << "<kml xmlns=\"http://earth.google.com/kml/2.2\">" << endl; + m_file << "<Document>" << endl; + } + + ostream & GetStream() { return m_file; } + + ~KMLFileGuard() + { + m_file << "</Document></kml>" << endl; + } +}; +#endif + /// @todo Move prefixes, suffixes into separate file (autogenerated). string affics1[] = @@ -49,6 +122,9 @@ void GetStreetName(strings::SimpleTokenizer iter, string & streetName) } } +} + + double const STREET_CONNECTION_LENGTH_M = 100.0; void House::InitHouseNumberAndSuffix() @@ -200,6 +276,8 @@ void HouseDetector::Bfs(Street * st) int HouseDetector::LoadStreets(vector<FeatureID> & ids) { + //LOG(LDEBUG, ("IDs = ", ids)); + int count = 0; for (size_t i = 0; i < ids.size(); ++i) { @@ -243,17 +321,36 @@ int HouseDetector::LoadStreets(vector<FeatureID> & ids) int HouseDetector::MergeStreets() { - LOG(LDEBUG, ("MergeStreets() called", m_end2st.size())); + LOG(LDEBUG, ("MergeStreets() called", m_id2st.size())); + +//#ifdef DEBUG +// KMLFileGuard file("dbg_merged_streets.kml"); +// char const * color = "FF000000"; +//#endif for (IterT it = m_end2st.begin(); it != m_end2st.end(); ++it) { - if (it->second->m_number == -1) + Street * st = it->second; + +//#ifdef DEBUG +// Street2KML(file.GetStream(), st->m_points, color); +//#endif + + if (st->m_number == -1) { - Street * st = it->second; ++m_streetNum; Bfs(st); } } + +//#ifdef DEBUG +// char const * arrColor[] = { "FFFF0000", "FF00FF00", "FF0000FF" }; +// for (size_t i = 0; i < m_streets.size(); ++i) +// { +// Streets2KML(file.GetStream(), m_streets[i], arrColor[i % ARRAY_SIZE(arrColor)]); +// } +//#endif + return m_streetNum; } @@ -542,23 +639,6 @@ bool CheckOddEven(search::HouseProjection const & h, bool isOdd) return ((x % 2 == 1) == isOdd); } -void CreateKMLString(ostream & s, map<search::House, double> const & m) -{ - for (map<search::House, double>::const_iterator it = m.begin(); it != m.end(); ++it) - { - s << "<Placemark>" - << "<name>" << it->first.GetNumber() << "</name>" - - << "<Point><coordinates>" - << MercatorBounds::XToLon(it->first.GetPosition().x) - << "," - << MercatorBounds::YToLat(it->first.GetPosition().y) - - << "</coordinates></Point>" - << "</Placemark>" << endl; - } -} - void ProccessHouses(vector<search::HouseProjection> & houses, vector<search::HouseProjection> & result, bool isOdd, HouseMapT & m) diff --git a/search/house_detector.hpp b/search/house_detector.hpp index 651a10cc2b..f7d47194c6 100644 --- a/search/house_detector.hpp +++ b/search/house_detector.hpp @@ -7,7 +7,6 @@ #include "../std/string.hpp" #include "../std/queue.hpp" -#include "../std/iostream.hpp" namespace search |