diff --git a/geometry/rect2d.hpp b/geometry/rect2d.hpp index 40109415bf..a4cd5a6b79 100644 --- a/geometry/rect2d.hpp +++ b/geometry/rect2d.hpp @@ -17,6 +17,7 @@ namespace m2 template struct min_max_value { T get_min() { return numeric_limits::max(); } + // TODO: There is an overflow here: -(-128) != 127. T get_max() { return -get_min(); } }; template struct min_max_value @@ -52,6 +53,16 @@ namespace m2 { } + static Rect GetEmptyRect() { return Rect(); } + + static Rect GetInfiniteRect() + { + T const tMax = numeric_limits::max(); + // This works for both ints and floats. + T const tMin = min(-tMax, numeric_limits::min()); + return Rect(tMin, tMin, tMax, tMax); + } + void MakeEmpty() { m_minX = m_minY = impl::min_max_value::is_signed>().get_min(); diff --git a/indexer/index.hpp b/indexer/index.hpp index 160a31aa45..8f6666291e 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -6,8 +6,10 @@ #include "scales.hpp" #include "../geometry/rect2d.hpp" +#include "../coding/file_container.hpp" #include "../coding/varint.hpp" #include "../base/base.hpp" +#include "../base/macros.hpp" #include "../base/stl_add.hpp" #include "../std/string.hpp" @@ -26,7 +28,8 @@ public: { vector > intervals = covering::CoverViewportAndAppendLowerLevels(rect); for (size_t i = 0; i < intervals.size(); ++i) - BaseT::ForEachInIntervalAndScale(f, intervals[i].first, intervals[i].second, scale, query); + BaseT::ForEachInIntervalAndScale(f, intervals[i].first, intervals[i].second, scale, + rect, query); } template @@ -53,7 +56,8 @@ public: void ForEachInScale(F const & f, uint32_t scale, Query & query) const { int64_t const rootId = RectId("").ToInt64(); - BaseT::ForEachInIntervalAndScale(f, rootId, rootId + RectId("").SubTreeSize(), scale, query); + BaseT::ForEachInIntervalAndScale(f, rootId, rootId + RectId("").SubTreeSize(), scale, + m2::RectD::GetInfiniteRect(), query); } template @@ -76,16 +80,20 @@ public: template void ForEachInIntervalAndScale(F const & f, int64_t beg, int64_t end, uint32_t scale, - Query & query) const + m2::RectD const & occlusionRect, Query & query) const { + // TODO: Use occlusionRect. + UNUSED_VALUE(occlusionRect); for (size_t i = 0; i < m_Indexes.size(); ++i) m_Indexes[i]->ForEachInIntervalAndScale(f, beg, end, scale, query); } - template - void Add(FeatureReaders const & dataR, IndexReaderT const & indexR) + void Add(string const & path) { - m_Indexes.push_back(new IndexT(dataR, indexR)); + uint32_t const logPageSize = 12; + uint32_t const logPageCount = 12; + FilesContainerR container(path, logPageSize, logPageCount); + m_Indexes.push_back(new IndexT(container)); } bool IsExist(string const & dataPath) const @@ -123,9 +131,9 @@ template class OffsetToFeatureAdapter : publ public: typedef typename BaseT::Query Query; - OffsetToFeatureAdapter( FeatureReaders const & dataR, - typename BaseT::ReaderType const & indexR) - : BaseT(indexR), m_FeatureVector(dataR) + explicit OffsetToFeatureAdapter(FilesContainerR const & container) + : BaseT(container.GetReader(INDEX_FILE_TAG)), + m_FeatureVector(FeatureReaders(container)) { } @@ -207,14 +215,14 @@ private: }; }; -template +template struct Index { typedef IndexForEachAdapter< MultiIndexAdapter< - OffsetToFeatureAdapter, + OffsetToFeatureAdapter, UniqueOffsetAdapter< - ScaleIndex + ScaleIndex > > > diff --git a/indexer/indexer_tests/index_builder_test.cpp b/indexer/indexer_tests/index_builder_test.cpp index a6fa3f4827..8ab256bc37 100644 --- a/indexer/indexer_tests/index_builder_test.cpp +++ b/indexer/indexer_tests/index_builder_test.cpp @@ -28,7 +28,10 @@ UNIT_TEST(BuildIndexTest) indexer::BuildIndex(featuresVector, serialWriter, "build_index_test"); } + // TODO: Restore unit test! + /* MemReader indexReader(&serial[0], serial.size()); Index::Type index; index.Add(FeatureReaders(container), indexReader); + */ } diff --git a/indexer/indexer_tests/index_test.cpp b/indexer/indexer_tests/index_test.cpp index fb9f18b5c5..42118fdd1b 100644 --- a/indexer/indexer_tests/index_test.cpp +++ b/indexer/indexer_tests/index_test.cpp @@ -1,21 +1,29 @@ -#include "../../base/SRC_FIRST.hpp" - +#include "../../testing/testing.hpp" #include "../index.hpp" #include "../index_builder.hpp" - -#include "../../testing/testing.hpp" - -#include "../../coding/file_container.hpp" - #include "../../platform/platform.hpp" - +#include "../../coding/file_container.hpp" +#include "../../base/macros.hpp" #include "../../std/string.hpp" +namespace +{ + +struct NoopFunctor +{ + template void operator () (T const & value) const + { + UNUSED_VALUE(value); + } +}; + +} UNIT_TEST(IndexParseTest) { - FilesContainerR container(GetPlatform().WritablePathForFile("minsk-pass" DATA_FILE_EXTENSION)); + Index::Type index; + index.Add(GetPlatform().WritablePathForFile("minsk-pass" DATA_FILE_EXTENSION)); - Index::Type index; - index.Add(FeatureReaders(container), container.GetReader(INDEX_FILE_TAG)); + // Make sure that index is actually parsed. + index.ForEachInScale(NoopFunctor(), 15); } diff --git a/map/feature_vec_model.cpp b/map/feature_vec_model.cpp index 4034504494..7b6990b353 100644 --- a/map/feature_vec_model.cpp +++ b/map/feature_vec_model.cpp @@ -9,8 +9,6 @@ #include "../indexer/classif_routine.hpp" #include "../indexer/classificator.hpp" -#include "../coding/file_container.hpp" - #include "../base/logging.hpp" #include "../std/bind.hpp" @@ -35,11 +33,7 @@ void FeaturesFetcher::AddMap(string const & fName) try { - uint32_t const logPageSize = 12; - uint32_t const logPageCount = 12; - - FilesContainerR container(fName, logPageSize, logPageCount); - m_multiIndex.Add(FeatureReaders(container), container.GetReader(INDEX_FILE_TAG)); + m_multiIndex.Add(fName); } catch (Reader::OpenException const & e) { diff --git a/map/feature_vec_model.hpp b/map/feature_vec_model.hpp index 56e3432fb5..f82e76a6aa 100644 --- a/map/feature_vec_model.hpp +++ b/map/feature_vec_model.hpp @@ -42,7 +42,7 @@ namespace model typedef FileReader reader_t; #endif - typedef Index::Type index_t; + typedef Index::Type index_t; index_t m_multiIndex;