[topography_generator] Review fixes.

This commit is contained in:
Daria Volvenkova 2020-01-24 15:39:18 +03:00
parent 799c7f2481
commit 8d060411fd
9 changed files with 59 additions and 41 deletions

View file

@ -160,8 +160,8 @@ void SrtmTile::Invalidate()
SrtmTileManager::SrtmTileManager(std::string const & dir) : m_dir(dir) {}
geometry::Altitude SrtmTileManager::GetHeight(ms::LatLon const & coord)
{
LatLonKey const key = {static_cast<int>(floor(coord.m_lat)),
static_cast<int>(floor(coord.m_lon))};
LatLonKey const key = {static_cast<int32_t>(floor(coord.m_lat)),
static_cast<int32_t>(floor(coord.m_lon))};
auto it = m_tiles.find(key);
if (it == m_tiles.end())
@ -186,8 +186,8 @@ geometry::Altitude SrtmTileManager::GetHeight(ms::LatLon const & coord)
bool SrtmTileManager::HasValidTile(ms::LatLon const & coord) const
{
LatLonKey const key = {static_cast<int>(floor(coord.m_lat)),
static_cast<int>(floor(coord.m_lon))};
LatLonKey const key = {static_cast<int32_t>(floor(coord.m_lat)),
static_cast<int32_t>(floor(coord.m_lon))};
auto it = m_tiles.find(key);
if (it != m_tiles.end())
return it->second.IsValid();

View file

@ -55,7 +55,7 @@ public:
private:
std::string m_dir;
using LatLonKey = std::pair<int, int>;
using LatLonKey = std::pair<int32_t, int32_t>;
struct Hash
{
size_t operator()(LatLonKey const & key) const

View file

@ -57,6 +57,7 @@ void ProcessWithLinearKernel(std::vector<double> const & kernel, size_t tileSize
auto const kernelRadius = kernel.size() / 2;
CHECK_LESS_OR_EQUAL(kernelRadius, tileOffset, ());
CHECK_GREATER(tileSize, tileOffset * 2, ());
CHECK_EQUAL(dstValues.size(), tileSize * tileSize, ());
std::vector<ValueType> tempValues(tileSize, 0);
@ -105,6 +106,7 @@ void ProcessWithSquareKernel(std::vector<double> const & kernel, size_t kernelSi
size_t const kernelRadius = kernelSize / 2;
CHECK_LESS_OR_EQUAL(kernelRadius, tileOffset, ());
CHECK_GREATER(tileSize, tileOffset * 2, ());
CHECK_EQUAL(dstValues.size(), tileSize * tileSize, ());
for (size_t i = tileOffset; i < tileSize - tileOffset; ++i)
{
@ -131,6 +133,7 @@ void ProcessMedian(size_t kernelRadius, size_t tileSize, size_t tileOffset,
{
CHECK_LESS_OR_EQUAL(kernelRadius, tileOffset, ());
CHECK_GREATER(tileSize, tileOffset * 2, ());
CHECK_EQUAL(dstValues.size(), tileSize * tileSize, ());
size_t const kernelSize = kernelRadius * 2 + 1;
std::vector<ValueType> kernel(kernelSize * kernelSize);

View file

@ -176,7 +176,12 @@ public:
, m_strmDir(srtmDir)
, m_srtmProvider(srtmDir)
, m_params(params)
{}
{
CHECK(right >= -180 && right <= 179, ());
CHECK(left >= -180 && left <= 179, ());
CHECK(top >= -90 && top <= 89, ());
CHECK(bottom >= -90 && bottom <= 89, ());
}
void Do() override
{

View file

@ -11,9 +11,9 @@
#include "base/thread_pool.hpp"
#include <condition_variable>
#include <string>
#include <memory>
#include <mutex>
#include <string>
namespace topography_generator
{

View file

@ -19,10 +19,10 @@ DEFINE_uint64(alt_step_factor, 1, "Isolines packing mode. Altitude step factor."
DEFINE_string(srtm_path, "",
"Isolines generating mode. Path to srtm directory.");
DEFINE_int32(left, 0, "Isolines generating mode. Left longitude of tiles rect [-180, 180].");
DEFINE_int32(right, 0, "Isolines generating mode. Right longitude of tiles rect [-180, 180].");
DEFINE_int32(bottom, 0, "Isolines generating mode. Bottom latitude of tiles rect [-90, 90].");
DEFINE_int32(top, 0, "Isolines generating mode. Top latitude of tiles rect [-90, 90].");
DEFINE_int32(left, 0, "Isolines generating mode. Left longitude of tiles rect [-180, 179].");
DEFINE_int32(right, 0, "Isolines generating mode. Right longitude of tiles rect [-179, 180].");
DEFINE_int32(bottom, 0, "Isolines generating mode. Bottom latitude of tiles rect [-90, 89].");
DEFINE_int32(top, 0, "Isolines generating mode. Top latitude of tiles rect [-89, 90].");
DEFINE_uint64(isolines_step, 10, "Isolines generating mode. Isolines step in meters.");
DEFINE_uint64(latlon_step_factor, 2, "Isolines generating mode. Lat/lon step factor.");
DEFINE_double(gaussian_st_dev, 2.0, "Isolines generating mode. Gaussian filter standard deviation.");
@ -42,9 +42,29 @@ int main(int argc, char ** argv)
return EXIT_FAILURE;
}
auto const validTilesRect = FLAGS_right > FLAGS_left && FLAGS_top > FLAGS_bottom &&
FLAGS_right <= 180 && FLAGS_left >= -180 &&
FLAGS_top <= 90 && FLAGS_bottom >= -90;
auto const isGeneratingMode = validTilesRect;
auto const isPackingMode = !FLAGS_countryId.empty();
if (isGeneratingMode && isPackingMode)
{
LOG(LERROR, ("Both tiles rect and country id are set. Сhoose one operation: "
"generation of tiles rect or packing tiles for the country"));
return EXIT_FAILURE;
}
if (!isGeneratingMode && !isPackingMode)
{
LOG(LERROR, ("Valid tiles rect or country id must be set."));
return EXIT_FAILURE;
}
topography_generator::Generator generator(FLAGS_srtm_path, FLAGS_threads,
FLAGS_tiles_per_thread);
if (!FLAGS_countryId.empty())
if (isPackingMode)
{
if (FLAGS_isolines_path.empty())
{
@ -67,12 +87,7 @@ int main(int argc, char ** argv)
return EXIT_FAILURE;
}
if (FLAGS_right <= FLAGS_left || FLAGS_top <= FLAGS_bottom ||
FLAGS_right > 180 || FLAGS_left < -180 || FLAGS_top > 90 || FLAGS_bottom < -90)
{
LOG(LERROR, ("Invalid tiles rect."));
return EXIT_FAILURE;
}
CHECK(!validTilesRect, ());
topography_generator::TileIsolinesParams params;
if (FLAGS_median_r > 0)

View file

@ -26,9 +26,8 @@ void ContoursBuilder::AddSegment(size_t levelInd, ms::LatLon const & beginPos, m
if (connectStart && connectEnd && contourItBefore != contourItAfter)
{
contourItBefore->m_countour.insert(contourItBefore->m_countour.end(),
contourItAfter->m_countour.begin(),
contourItAfter->m_countour.end());
std::move(contourItAfter->m_countour.begin(), contourItAfter->m_countour.end(),
std::back_inserter(contourItBefore->m_countour));
contourItBefore->m_active = true;
m_activeContours[levelInd].erase(contourItAfter);
}

View file

@ -65,7 +65,7 @@ void CropContours(m2::RectD & rect, std::vector<m2::RegionD> & regions, size_t m
levelCroppedContours.emplace_back(std::move(cropped));
}
}
it->second.swap(levelCroppedContours);
it->second = std::move(levelCroppedContours);
if (!it->second.empty())
{

View file

@ -42,9 +42,8 @@ private:
template <typename Sink>
void SerializeContour(Sink & sink, topography_generator::Contour const & contour)
{
serial::GeometryCodingParams codingParams;
serial::SavePoint(sink, contour[0], codingParams);
codingParams.SetBasePoint(contour[0]);
serial::GeometryCodingParams codingParams(kPointCoordBits, contour[0]);
codingParams.Save(sink);
serial::SaveOuterPath(contour, codingParams, sink);
}
@ -75,7 +74,7 @@ public:
ValueType levelValue;
std::vector<topography_generator::Contour> levelContours;
DeserializeContours(source, levelValue, levelContours);
contours.m_contours[levelValue].swap(levelContours);
contours.m_contours[levelValue] = std::move(levelContours);
}
}
@ -94,11 +93,10 @@ private:
topography_generator::Contour & contour)
{
serial::GeometryCodingParams codingParams;
auto const pt = serial::LoadPoint(source, codingParams);
codingParams.SetBasePoint(pt);
codingParams.Load(source);
std::vector<m2::PointD> points;
serial::LoadOuterPath(source, codingParams, points);
contour.swap(points);
contour = std::move(points);
}
};
@ -123,19 +121,17 @@ bool SaveContrours(std::string const & filePath,
template <typename ValueType>
bool LoadContours(std::string const & filePath, Contours<ValueType> & contours)
{
try
{
try
{
FileReader file(filePath);
DeserializerContours<ValueType> des;
des.Deserialize(file, contours);
}
catch (FileReader::Exception const & ex)
{
LOG(LWARNING, ("File writer exception raised:", ex.what(), ", file", filePath));
return false;
}
return true;
FileReader file(filePath);
DeserializerContours<ValueType> des;
des.Deserialize(file, contours);
}
catch (FileReader::Exception const & ex)
{
LOG(LWARNING, ("File reader exception raised:", ex.what(), ", file", filePath));
return false;
}
return true;
}
} // namespace topography_generator