SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
TileManager.h
Go to the documentation of this file.
1
17/*
18 * TileManager.h
19 *
20 * Created on: Feb 23, 2018
21 * Author: mschefer
22 */
23
24#ifndef _SEFRAMEWORK_IMAGE_TILEMANAGER_H_
25#define _SEFRAMEWORK_IMAGE_TILEMANAGER_H_
26
27#include <iostream>
28#include <thread>
29#include <list>
30#include <unordered_map>
31
32#include <boost/thread/shared_mutex.hpp>
33
34#include <ElementsKernel/Logging.h>
35
38
39namespace SourceXtractor {
40
41
42struct TileKey {
45
46 bool operator==(const TileKey& other) const;
47
48 std::string getRepr() const;
49};
50
51inline std::ostream& operator<<(std::ostream& out, const TileKey& tk) {
52 out << tk.getRepr();
53 return out;
54}
55
56}
57
58namespace std {
59
60template<>
61struct hash<SourceXtractor::TileKey> {
63 std::size_t local_hash = 0;
64 boost::hash_combine(local_hash, key.m_source);
65 boost::hash_combine(local_hash, key.m_tile_x);
66 boost::hash_combine(local_hash, key.m_tile_y);
67 return local_hash;
68 }
69};
70
71}
72
73namespace SourceXtractor {
74
76public:
77
79
80 virtual ~TileManager();
81
82 // Actually not thread safe, call before starting the multi-threading
83 void setOptions(int tile_width, int tile_height, int max_memory);
84
85 void flush();
86
89
91
92 void saveAllTiles();
93
94 int getTileWidth() const;
95
96 int getTileHeight() const;
97
98private:
99
101
103
104 void removeTile(TileKey tile_key);
105
106 void removeExtraTiles();
107
109
113
117
118 boost::shared_mutex m_mutex;
119};
120
121}
122
123
124#endif /* _SEFRAMEWORK_IMAGE_TILEMANAGER_H_ */
std::unordered_map< const ImageSource *, std::shared_ptr< boost::mutex > > m_mutex_map
std::shared_ptr< ImageTile > getTileForPixel(int x, int y, std::shared_ptr< const ImageSource > source)
boost::shared_mutex m_mutex
std::list< TileKey > m_tile_list
std::shared_ptr< ImageTile > tryTileFromCache(const TileKey &key)
void removeTile(TileKey tile_key)
void addTile(TileKey key, std::shared_ptr< ImageTile > tile)
void setOptions(int tile_width, int tile_height, int max_memory)
static std::shared_ptr< TileManager > getInstance()
std::unordered_map< TileKey, std::shared_ptr< ImageTile > > m_tile_map
std::shared_ptr< boost::mutex > & getMutexForImageSource(const ImageSource *)
std::ostream & operator<<(std::ostream &s, const cell_stream_adaptor &cell)
STL namespace.
bool operator==(const TileKey &other) const
std::shared_ptr< const ImageSource > m_source
Definition TileManager.h:43
std::string getRepr() const
std::size_t operator()(const SourceXtractor::TileKey &key) const
Definition TileManager.h:62