diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index aa3f7a920e..e3638486f1 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -94,6 +94,8 @@ set(SRC geo_objects/geo_objects.hpp geo_objects/geo_object_info_getter.cpp geo_objects/geo_object_info_getter.hpp + geo_objects/geo_objects_filter.cpp + geo_objects/geo_objects_filter.hpp geo_objects/key_value_storage.cpp geo_objects/key_value_storage.hpp geo_objects/region_info_getter.cpp diff --git a/generator/geo_objects/geo_objects.cpp b/generator/geo_objects/geo_objects.cpp index d380f98a88..89e4d6be0b 100644 --- a/generator/geo_objects/geo_objects.cpp +++ b/generator/geo_objects/geo_objects.cpp @@ -2,6 +2,7 @@ #include "generator/feature_builder.hpp" #include "generator/geo_objects/geo_object_info_getter.hpp" +#include "generator/geo_objects/geo_objects_filter.hpp" #include "generator/geo_objects/key_value_storage.hpp" #include "generator/geo_objects/region_info_getter.hpp" #include "generator/geo_objects/streets_builder.hpp" @@ -39,17 +40,6 @@ namespace { using IndexReader = ReaderPtr; -bool IsBuilding(FeatureBuilder1 const & fb) -{ - auto const & checker = ftypes::IsBuildingChecker::Instance(); - return checker(fb.GetTypes()); -} - -bool HasHouse(FeatureBuilder1 const & fb) -{ - return !fb.GetParams().house.IsEmpty(); -} - bool HouseHasAddress(base::Json json) { auto properties = json_object_get(json.get(), "properties"); @@ -163,7 +153,7 @@ void BuildGeoObjectsWithAddresses(RegionInfoGetter const & regionInfoGetter, { size_t countGeoObjects = 0; auto const fn = [&](FeatureBuilder1 & fb, uint64_t /* currPos */) { - if (!(IsBuilding(fb) || HasHouse(fb))) + if (!(GeoObjectsFilter::IsBuilding(fb) || GeoObjectsFilter::HasHouse(fb))) return; auto regionKeyValue = regionInfoGetter.FindDeepest(fb.GetKeyPoint()); @@ -187,7 +177,9 @@ void BuildGeoObjectsWithoutAddresses(GeoObjectInfoGetter const & geoObjectInfoGe { size_t countGeoObjects = 0; auto const fn = [&](FeatureBuilder1 & fb, uint64_t /* currPos */) { - if (IsBuilding(fb) || HasHouse(fb) || StreetsBuilder::IsStreet(fb)) + if (!GeoObjectsFilter::IsPoi(fb)) + return; + if (GeoObjectsFilter::IsBuilding(fb) || GeoObjectsFilter::HasHouse(fb) || GeoObjectsFilter::IsStreet(fb)) return; auto const house = FindHousePoi(fb, geoObjectInfoGetter); diff --git a/generator/geo_objects/geo_objects_filter.cpp b/generator/geo_objects/geo_objects_filter.cpp new file mode 100644 index 0000000000..dc46110e31 --- /dev/null +++ b/generator/geo_objects/geo_objects_filter.cpp @@ -0,0 +1,52 @@ +#include "generator/geo_objects/geo_objects_filter.hpp" + +#include "generator/geo_objects/streets_builder.hpp" +#include "generator/osm_element_helpers.hpp" + +#include "indexer/ftypes_matcher.hpp" + +namespace generator +{ +namespace geo_objects +{ +bool GeoObjectsFilter::IsAccepted(OsmElement const & element) +{ + return osm_element::IsBuilding(element) || osm_element::HasHouse(element) || osm_element::IsPoi(element) || + geo_objects::StreetsBuilder::IsStreet(element); +} + +bool GeoObjectsFilter::IsAccepted(FeatureBuilder1 const & feature) +{ + if (!feature.GetParams().IsValid()) + return false; + + return IsBuilding(feature) || HasHouse(feature) || IsPoi(feature) || IsStreet(feature); +} + +// static +bool GeoObjectsFilter::IsBuilding(FeatureBuilder1 const & fb) +{ + auto const & checker = ftypes::IsBuildingChecker::Instance(); + return checker(fb.GetTypes()); +} + +// static +bool GeoObjectsFilter::HasHouse(FeatureBuilder1 const & fb) +{ + return !fb.GetParams().house.IsEmpty(); +} + +// static +bool GeoObjectsFilter::IsPoi(FeatureBuilder1 const & fb) +{ + auto const & poiChecker = ftypes::IsPoiChecker::Instance(); + return poiChecker(fb.GetTypes()); +} + +// static +bool GeoObjectsFilter::IsStreet(FeatureBuilder1 const & fb) +{ + return geo_objects::StreetsBuilder::IsStreet(fb); +} +} // namespace geo_objects +} // namespace generator diff --git a/generator/geo_objects/geo_objects_filter.hpp b/generator/geo_objects/geo_objects_filter.hpp new file mode 100644 index 0000000000..5d61dd0431 --- /dev/null +++ b/generator/geo_objects/geo_objects_filter.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "generator/feature_builder.hpp" +#include "generator/filter_interface.hpp" +#include "generator/intermediate_data.hpp" +#include "generator/osm_element.hpp" + +namespace generator +{ +namespace geo_objects +{ +class GeoObjectsFilter : public FilterInterface +{ +public: + // FilterInterface overrides: + bool IsAccepted(OsmElement const & element) override; + bool IsAccepted(FeatureBuilder1 const & feature) override; + + static bool IsBuilding(FeatureBuilder1 const & fb); + static bool HasHouse(FeatureBuilder1 const & fb); + static bool IsPoi(FeatureBuilder1 const & fb); + static bool IsStreet(FeatureBuilder1 const & fb); +}; +} // namespace geo_objects +} // namespace generator diff --git a/generator/translator_geo_objects.cpp b/generator/translator_geo_objects.cpp index 71df787c4b..7b28e38724 100644 --- a/generator/translator_geo_objects.cpp +++ b/generator/translator_geo_objects.cpp @@ -2,37 +2,18 @@ #include "generator/feature_maker.hpp" #include "generator/filter_interface.hpp" -#include "generator/geo_objects/streets_builder.hpp" +#include "generator/geo_objects/geo_objects_filter.hpp" #include "generator/intermediate_data.hpp" #include "generator/osm_element.hpp" #include "generator/osm_element_helpers.hpp" namespace generator { -namespace -{ -class FilterGeoObjects : public FilterInterface -{ -public: - // FilterInterface overrides: - bool IsAccepted(OsmElement const & element) override - { - return osm_element::IsBuilding(element) || osm_element::IsPoi(element) || - geo_objects::StreetsBuilder::IsStreet(element); - } - - bool IsAccepted(FeatureBuilder1 const & feature) override - { - return feature.GetParams().IsValid(); - } -}; -} // namespace - TranslatorGeoObjects::TranslatorGeoObjects(std::shared_ptr emitter, cache::IntermediateDataReader & cache) : Translator(emitter, cache, std::make_shared(cache)) { - AddFilter(std::make_shared()); + AddFilter(std::make_shared()); } } // namespace generator