@@ -92,15 +92,15 @@ int RasterContainer::LoadRasterSource(const std::string &path_string,
9292 const auto _ymin = static_cast <std::int32_t >(util::toFixed (util::FloatLatitude{ymin}));
9393 const auto _ymax = static_cast <std::int32_t >(util::toFixed (util::FloatLatitude{ymax}));
9494
95- const auto itr = LoadedSourcePaths .find (path_string);
96- if (itr != LoadedSourcePaths .end ())
95+ const auto itr = RasterCache::getInstance (). getLoadedSourcePaths () .find (path_string);
96+ if (itr != RasterCache::getInstance (). getLoadedSourcePaths () .end ())
9797 {
9898 util::Log () << " [source loader] Already loaded source '" << path_string << " ' at source_id "
9999 << itr->second ;
100100 return itr->second ;
101101 }
102102
103- int source_id = static_cast <int >(LoadedSources .size ());
103+ int source_id = static_cast <int >(RasterCache::getInstance (). getLoadedSources () .size ());
104104
105105 util::Log () << " [source loader] Loading from " << path_string << " ... " ;
106106 TIMER_START (loading_source);
@@ -116,8 +116,8 @@ int RasterContainer::LoadRasterSource(const std::string &path_string,
116116
117117 RasterSource source{std::move (rasterData), ncols, nrows, _xmin, _xmax, _ymin, _ymax};
118118 TIMER_STOP (loading_source);
119- LoadedSourcePaths .emplace (path_string, source_id);
120- LoadedSources .push_back (std::move (source));
119+ RasterCache::getInstance (). getLoadedSourcePaths () .emplace (path_string, source_id);
120+ RasterCache::getInstance (). getLoadedSources () .push_back (std::move (source));
121121
122122 util::Log () << " [source loader] ok, after " << TIMER_SEC (loading_source) << " s" ;
123123
@@ -127,10 +127,11 @@ int RasterContainer::LoadRasterSource(const std::string &path_string,
127127// External function for looking up nearest data point from a specified source
128128RasterDatum RasterContainer::GetRasterDataFromSource (unsigned int source_id, double lon, double lat)
129129{
130- if (LoadedSources .size () < source_id + 1 )
130+ if (RasterCache::getInstance (). getLoadedSources () .size () < source_id + 1 )
131131 {
132132 throw util::exception (" Attempted to access source " + std::to_string (source_id) +
133- " , but there are only " + std::to_string (LoadedSources.size ()) +
133+ " , but there are only " +
134+ std::to_string (RasterCache::getInstance ().getLoadedSources ().size ()) +
134135 " loaded" + SOURCE_REF);
135136 }
136137
@@ -139,7 +140,7 @@ RasterDatum RasterContainer::GetRasterDataFromSource(unsigned int source_id, dou
139140 BOOST_ASSERT (lon < 180 );
140141 BOOST_ASSERT (lon > -180 );
141142
142- const auto &found = LoadedSources [source_id];
143+ const auto &found = RasterCache::getInstance (). getLoadedSources () [source_id];
143144 return found.GetRasterData (static_cast <std::int32_t >(util::toFixed (util::FloatLongitude{lon})),
144145 static_cast <std::int32_t >(util::toFixed (util::FloatLatitude{lat})));
145146}
@@ -148,10 +149,11 @@ RasterDatum RasterContainer::GetRasterDataFromSource(unsigned int source_id, dou
148149RasterDatum
149150RasterContainer::GetRasterInterpolateFromSource (unsigned int source_id, double lon, double lat)
150151{
151- if (LoadedSources .size () < source_id + 1 )
152+ if (RasterCache::getInstance (). getLoadedSources () .size () < source_id + 1 )
152153 {
153154 throw util::exception (" Attempted to access source " + std::to_string (source_id) +
154- " , but there are only " + std::to_string (LoadedSources.size ()) +
155+ " , but there are only " +
156+ std::to_string (RasterCache::getInstance ().getLoadedSources ().size ()) +
155157 " loaded" + SOURCE_REF);
156158 }
157159
@@ -160,10 +162,12 @@ RasterContainer::GetRasterInterpolateFromSource(unsigned int source_id, double l
160162 BOOST_ASSERT (lon < 180 );
161163 BOOST_ASSERT (lon > -180 );
162164
163- const auto &found = LoadedSources [source_id];
165+ const auto &found = RasterCache::getInstance (). getLoadedSources () [source_id];
164166 return found.GetRasterInterpolate (
165167 static_cast <std::int32_t >(util::toFixed (util::FloatLongitude{lon})),
166168 static_cast <std::int32_t >(util::toFixed (util::FloatLatitude{lat})));
167169}
170+
171+ RasterCache *RasterCache::g_instance = NULL ;
168172}
169173}
0 commit comments