Skip to content

Commit

Permalink
[generator] Refactored names and comments GenerateFinalFeatures(). Fi…
Browse files Browse the repository at this point in the history
…xed return value.
  • Loading branch information
maksimandrianov authored and mpimenov committed Dec 12, 2019
1 parent b443c4f commit 6dbf745
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
34 changes: 12 additions & 22 deletions generator/feature_sorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "platform/country_file.hpp"
#include "platform/mwm_version.hpp"
#include "platform/platform.hpp"

#include "coding/files_container.hpp"
#include "coding/internal/file_data.hpp"
Expand Down Expand Up @@ -309,48 +310,43 @@ bool GenerateFinalFeatures(feature::GenerateInfo const & info, string const & na
string const srcFilePath = info.GetTmpFileName(name);
string const datFilePath = info.GetTargetFileName(name);

// stores cellIds for middle points
// Store cellIds for middle points.
CalculateMidPoints midPoints;
ForEachFromDatRawFormat(srcFilePath, [&midPoints](FeatureBuilder const & fb, uint64_t pos) {
midPoints(fb, pos);
});

// sort features by their middle point
// Sort features by their middle point.
midPoints.Sort();

// store sorted features
// Store sorted features.
{
FileReader reader(srcFilePath);

bool const isWorld = (mapType != DataHeader::MapType::Country);

// Fill mwm header.
DataHeader header;

bool const isWorldOrWorldCoasts = (mapType != DataHeader::MapType::Country);
uint8_t coordBits = kFeatureSorterPointCoordBits;
if (isWorld)
if (isWorldOrWorldCoasts)
coordBits -= ((scales::GetUpperScale() - scales::GetUpperWorldScale()) / 2);

// coding params
header.SetType(static_cast<DataHeader::MapType>(mapType));
header.SetGeometryCodingParams(serial::GeometryCodingParams(coordBits, midPoints.GetCenter()));

// scales
if (isWorld)
if (isWorldOrWorldCoasts)
header.SetScales(g_arrWorldScales);
else
header.SetScales(g_arrCountryScales);

// type
header.SetType(static_cast<DataHeader::MapType>(mapType));

// region data
RegionData regionData;
if (!ReadRegionData(name, regionData))
LOG(LWARNING, ("No extra data for country:", name));

// Transform features from raw format to optimized format.
try
{
// FeaturesCollector2 will create temprory file `datFilePath + DATA_FILE_TAG`.
// We cannot remove it in ~FeaturesCollector2(), we need to remove it in SCOPE_GUARD.
SCOPE_GUARD(_, [&](){ Platform::RemoveFileIfExists(datFilePath + DATA_FILE_TAG); });
FeaturesCollector2 collector(datFilePath, header, regionData, info.m_versionDate);

for (auto const & point : midPoints.GetVector())
Expand All @@ -360,8 +356,6 @@ bool GenerateFinalFeatures(feature::GenerateInfo const & info, string const & na

FeatureBuilder fb;
ReadFromSourceRawFormat(src, fb);

// emit the feature
collector(fb);
}

Expand All @@ -378,14 +372,10 @@ bool GenerateFinalFeatures(feature::GenerateInfo const & info, string const & na
catch (RootException const & ex)
{
LOG(LCRITICAL, ("MWM writing error:", ex.Msg()));
return false;
}

// at this point files should be closed
}

// remove old not-sorted dat file
FileWriter::DeleteFileX(datFilePath + DATA_FILE_TAG);

return true;
}
} // namespace feature
5 changes: 3 additions & 2 deletions generator/final_processor_intermediate_mwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,15 @@ void CountryFinalProcessor::Finish()
auto fbs = ReadAllDatRawFormat<MaxAccuracy>(fullPath);
Sort(fbs);

auto const isProhibited = routing::AreSpeedCamerasProhibited(platform::CountryFile(filename));
auto const speedCamerasProhibited =
routing::AreSpeedCamerasProhibited(platform::CountryFile(filename));
static auto const speedCameraType = classif().GetTypeByPath({"highway", "speed_camera"});

FeatureBuilderWriter<> collector(fullPath);
for (auto & fb : fbs)
{
// Removing point features with speed cameras type from geometry index for some countries.
if (isProhibited && fb.IsPoint() && fb.HasType(speedCameraType))
if (speedCamerasProhibited && fb.IsPoint() && fb.HasType(speedCameraType))
continue;

collector.Write(fb);
Expand Down

0 comments on commit 6dbf745

Please sign in to comment.