[generator] Review fixes.

This commit is contained in:
Daria Volvenkova 2020-01-29 00:55:26 +03:00
parent 1659deda41
commit 4916fd63a1
5 changed files with 60 additions and 58 deletions

View file

@ -127,11 +127,6 @@ std::string GetCountryNameFromTmpMwmPath(std::string filename)
return filename;
}
{
strings::ReplaceLast(filename, DATA_FILE_EXTENSION_TMP, "");
return filename;
}
bool FilenameIsCountry(std::string const & filename, AffiliationInterface const & affiliation)
{
return affiliation.HasCountryByName(GetCountryNameFromTmpMwmPath(filename));
@ -279,12 +274,10 @@ bool FinalProcessorIntermediateMwmInterface::operator!=(
CountryFinalProcessor::CountryFinalProcessor(std::string const & borderPath,
std::string const & temporaryMwmPath,
std::string const & isolinesPath,
bool haveBordersForWholeWorld, size_t threadsCount)
: FinalProcessorIntermediateMwmInterface(FinalProcessorPriority::CountriesOrWorld)
, m_borderPath(borderPath)
, m_temporaryMwmPath(temporaryMwmPath)
, m_isolinesPath(isolinesPath)
, m_haveBordersForWholeWorld(haveBordersForWholeWorld)
, m_threadsCount(threadsCount)
{
@ -334,6 +327,11 @@ void CountryFinalProcessor::SetMiniRoundabouts(std::string const & filename)
m_miniRoundaboutsFilename = filename;
}
void CountryFinalProcessor::SetIsolinesDir(std::string const & dir)
{
m_isolinesPath = dir;
}
void CountryFinalProcessor::Process()
{
if (!m_hotelsFilename.empty())
@ -422,24 +420,19 @@ void CountryFinalProcessor::AddIsolines()
{
IsolineFeaturesGenerator isolineFeaturesGenerator(m_isolinesPath);
auto const affiliation = CountriesFilesIndexAffiliation(m_borderPath, m_haveBordersForWholeWorld);
{
ThreadPool pool(m_threadsCount);
ForEachCountry(m_temporaryMwmPath, [&](auto const & filename) {
pool.SubmitWork([&, filename]() {
if (!FilenameIsCountry(filename, affiliation))
return;
auto const countryName = GetCountryNameFromTmpMwmPath(filename);
ThreadPool pool(m_threadsCount);
ForEachCountry(m_temporaryMwmPath, [&](auto const & filename) {
pool.SubmitWork([&, filename]() {
if (!FilenameIsCountry(filename, affiliation))
return;
auto const countryName = GetCountryNameFromTmpMwmPath(filename);
std::vector<feature::FeatureBuilder> fbs;
isolineFeaturesGenerator.GenerateIsolines(countryName, fbs);
auto const fullPath = base::JoinPath(m_temporaryMwmPath, filename);
FeatureBuilderWriter<MaxAccuracy> writer(fullPath, FileWriter::Op::OP_APPEND);
for (auto const & fb : fbs)
writer.Write(fb);
});
auto const fullPath = base::JoinPath(m_temporaryMwmPath, filename);
FeatureBuilderWriter<MaxAccuracy> writer(fullPath, FileWriter::Op::OP_APPEND);
isolineFeaturesGenerator.GenerateIsolines(
countryName, [&writer](feature::FeatureBuilder && fb){ writer.Write(fb); });
});
}
});
}
void CountryFinalProcessor::ProcessRoutingCityBoundaries()

View file

@ -49,7 +49,6 @@ class CountryFinalProcessor : public FinalProcessorIntermediateMwmInterface
public:
CountryFinalProcessor(std::string const & borderPath,
std::string const & temporaryMwmPath,
std::string const & isolinesPath,
bool haveBordersForWholeWorld, size_t threadsCount);
void SetBooking(std::string const & filename);
@ -59,6 +58,7 @@ public:
std::string const & worldCoastsFilename);
void SetFakeNodes(std::string const & filename);
void SetMiniRoundabouts(std::string const & filename);
void SetIsolinesDir(std::string const & dir);
void DumpCitiesBoundaries(std::string const & filename);
void DumpRoutingCitiesBoundaries(std::string const & collectorFilename,
@ -73,8 +73,8 @@ private:
void ProcessCities();
void ProcessCoastline();
void ProcessRoundabouts();
void AddIsolines();
void AddFakeNodes();
void AddIsolines();
void Finish();
std::string m_borderPath;

View file

@ -9,41 +9,47 @@ namespace generator
{
namespace
{
static std::vector<int> const kAltClasses = {1000, 500, 100, 50, 10};
static std::vector<int> const kNamedAltClasses = {1000, 500, 100, 50};
static std::string const kTypePrefix = "step_";
std::string GetIsolineType(topography_generator::Altitude altitude)
{
ASSERT(std::is_sorted(kAltClasses.cbegin(), kAltClasses.cend(), std::greater<int>()), ());
if (altitude == 0)
return kTypePrefix + strings::to_string(kAltClasses.back());
for (auto altStep : kAltClasses)
{
if (altitude % altStep == 0)
return kTypePrefix + strings::to_string(altStep);
}
return "";
}
std::vector<int> const kAltClasses = {1000, 500, 100, 50, 10};
int const kNamedAltStep = 50;
std::string const kTypePrefix = "step_";
std::string const kTypeZero = "zero";
uint32_t const kInvalidType = 0;
std::string GetIsolineName(topography_generator::Altitude altitude)
{
for (auto altStep : kNamedAltClasses)
{
if (altitude % altStep == 0)
return strings::to_string(altitude);
}
if (altitude % kNamedAltStep == 0)
return strings::to_string(altitude);
return "";
}
} // namespace
IsolineFeaturesGenerator::IsolineFeaturesGenerator(std::string const & isolinesDir)
: m_isolinesDir(isolinesDir)
{}
{
ASSERT(std::is_sorted(kAltClasses.cbegin(), kAltClasses.cend(), std::greater<int>()), ());
for (auto alt : kAltClasses)
{
auto const type = kTypePrefix + strings::to_string(alt);
m_altClassToType[alt] = classif().GetTypeByPath({"isoline", type});
}
m_altClassToType[0] = classif().GetTypeByPath({"isoline", kTypeZero});
}
uint32_t IsolineFeaturesGenerator::GetIsolineType(int altitude) const
{
if (altitude == 0)
return m_altClassToType.at(0);
for (auto altStep : kAltClasses)
{
if (altitude % altStep == 0)
return m_altClassToType.at(altStep);
}
return kInvalidType;
}
void IsolineFeaturesGenerator::GenerateIsolines(std::string const & countryName,
std::vector<feature::FeatureBuilder> & fbs) const
FeaturesCollectFn const & fn) const
{
auto const isolinesPath = topography_generator::GetIsolinesFilePath(countryName,
m_isolinesDir);
@ -56,24 +62,22 @@ void IsolineFeaturesGenerator::GenerateIsolines(std::string const & countryName,
auto const altitude = levelIsolines.first;
auto const isolineName = GetIsolineName(altitude);
auto const isolineType = GetIsolineType(altitude);
if (isolineType.empty())
if (isolineType == kInvalidType)
{
LOG(LWARNING, ("Skip unsupported altitudes level", altitude, "in", countryName));
continue;
}
auto const type = classif().GetTypeByPath({"isoline", isolineType});
for (auto const & isoline : levelIsolines.second)
{
feature::FeatureBuilder fb;
fb.SetLinear();
for (auto const & pt : isoline)
fb.AddPoint(pt);
fb.AddType(type);
fb.AddType(isolineType);
if (!isolineName.empty())
fb.AddName("default", isolineName);
fbs.emplace_back(std::move(fb));
fb.SetLinear();
fn(std::move(fb));
}
}
}

View file

@ -2,7 +2,9 @@
#include "generator/feature_builder.hpp"
#include <functional>
#include <string>
#include <unordered_map>
namespace generator
{
@ -11,10 +13,13 @@ class IsolineFeaturesGenerator
public:
explicit IsolineFeaturesGenerator(std::string const & isolinesDir);
void GenerateIsolines(std::string const & countryName,
std::vector<feature::FeatureBuilder> & fbs) const;
using FeaturesCollectFn = std::function<void(feature::FeatureBuilder && fb)>;
void GenerateIsolines(std::string const & countryName, FeaturesCollectFn const & fn) const;
private:
uint32_t GetIsolineType(int altitude) const;
std::string m_isolinesDir;
std::unordered_map<int, uint32_t> m_altClassToType;
};
} // namespace generator

View file

@ -111,8 +111,8 @@ RawGenerator::FinalProcessorPtr RawGenerator::CreateCountryFinalProcessor(bool a
{
auto finalProcessor =
make_shared<CountryFinalProcessor>(m_genInfo.m_targetDir, m_genInfo.m_tmpDir,
m_genInfo.m_isolinesDir,
m_genInfo.m_haveBordersForWholeWorld, m_threadsCount);
finalProcessor->SetIsolinesDir(m_genInfo.m_isolinesDir);
finalProcessor->SetBooking(m_genInfo.m_bookingDataFilename);
finalProcessor->SetCitiesAreas(m_genInfo.GetIntermediateFileName(CITIES_AREAS_TMP_FILENAME));
finalProcessor->SetPromoCatalog(m_genInfo.m_promoCatalogCitiesFilename);