-
Notifications
You must be signed in to change notification settings - Fork 2
/
Points3DGrid.h
95 lines (84 loc) · 3.24 KB
/
Points3DGrid.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef Points3DGrid_h
#define Points3DGrid_h
//std includes
#include <string>
// boost #includes
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/map.hpp>
//Qt includes
#include <QString>
#include <QStringList>
//my includes
#include "mytypes.h"
#include "Points3D.h"
#include "Points3DSqlQuery.h"
#include "utils/Rectangle.h"
#include "utils/utils.h"
#include "utils/load.h"
#include "utils/save.h"
#include "utils/contains_key.h"
template<class TGridDataContainer, class TSqlDataContainer>
class Points3DGrid : public Points3D
{
private:
TGridDataContainer m_gridData; // interpolated subset of m_sqlQueryPoints. Much smaller. Gets built once and then cached.
TSqlDataContainer m_sqlQueryPoints; // big data structure, only restored if m_gridData cannot be restored from local cache file. Gets built once from remote db and then cached on local disk.
bool Points3DGrid_dbg;
const char* m_cachefile;
public:
Points3DGrid(const QStringList& args) : m_sqlQueryPoints(args), Points3DGrid_dbg(false), m_cachefile("Points3DGrid.m_cachefile")
{
if (utils::load(this, m_cachefile))
{
std::cout << FN << " loaded object from file '" << m_cachefile << "'." << std::endl;
}
else
{
m_sqlQueryPoints.init(args);
}
if (utils::contains_key(args, "--points3dgrid-dbg"))
{
std::cout << "Points3DGrid_dbg = true" << std::endl;
Points3DGrid_dbg = true;
}
}
void saveIfUpdated()
{
std::cout << FN << "...." << m_cachefile ;
//utils::saveIfUpdated(this, CLASS);
utils::saveIfUpdated(this, "Points3DGrid.m_cachefile");
std::cout << ".finished" << std::endl;
}
bool getZ(const utils::Rectangle_t& rectangle, z_int32_t& elevation)
{
bool retval = false;
x_int32_t longitude = rectangle.xCentre();
y_int32_t latitude = rectangle.yCentre();
try
{
elevation = m_gridData.at(longitude).at(latitude);
retval = true;
}
catch (...) // this will happen once for every point in the grid. Once the answer has been calculated, the result is cached to ram, and then to disk for subsequent executions of the program. Next time the program is run, all elevations are restored from the local cache file to m_gridData. This code will not run again until the local cache file is deleted, or new grid points are plotted.
{
m_sqlQueryPoints.getZ(rectangle, elevation);
if (Points3DGrid_dbg) std::cout << FN << " catch (...) m_sqlQueryPoints.getZ(" << rectangle << ") returns " << elevation << std::endl;
m_gridData[longitude][latitude] = elevation; // save our interpolated gps location in RAM. Later on we will save it to disk.
m_changesNotSaved = true;
}
if (Points3DGrid_dbg) std::cout << FN << ": elevation " << elevation << std::endl;
return retval;
}
// When the class Archive corresponds to an output archive, the
// & operator is defined similar to <<. Likewise, when the class Archive
// is a type of input archive the & operator is defined similar to >>.
template<class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & m_gridData;
Q_UNUSED(version);
}
};
typedef Points3DGrid<mapx_mapyz, points3DSqlQuery_t> points3dgrid32_t;
#endif