ColormapManager.cc
1.92 KB
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
/*
* ColormapManager.cc
*
* Created on: 8 nov. 2013
* Author: guillaume
*/
#include "ColormapManager.hh"
#include "PlotConfigurationLoader.hh"
#include <fstream>
#include <boost/lexical_cast.hpp>
namespace plot {
const int ColormapManager::DEFAULT_COLORMAP_0 = 0;
const int ColormapManager::DEFAULT_COLORMAP_1 = 1;
std::unique_ptr<ColormapManager> ColormapManager::_instance = nullptr;
std::once_flag ColormapManager::_instanceOnceFlag;
ColormapManager::ColormapManager() :
_path("") {
PlotConfigurationLoader lPlotLoader = PlotConfigurationLoader();
lPlotLoader.load<ColormapManager>(this);
}
ColormapManager::~ColormapManager() {
}
/**
* @brief Return file name corresponding to the given index and mode.
*/
std::string ColormapManager::get(PlotCommon::Mode& pMode, int pIndex) {
ColorFileMap& lColorFileMap(_colormap[pMode]);
std::string lFile = "";
if ((pIndex != -1) && lColorFileMap.find(pIndex) != lColorFileMap.end()) {
// Concatenate path and filename.
lFile = _path + lColorFileMap[pIndex];
}
return lFile;
}
int ColormapManager::getDefault(PlotCommon::Mode& mode) {
return _defaultColormap[mode];
}
int ColormapManager::getDefaultSize(PlotCommon::Mode& mode)
{
std::map<PlotCommon::Mode, int>::iterator it;
it = _defaultSize.find(mode);
if (it != _defaultSize.end())
return it->second;
std::string filePath = ColormapManager::getInstance().get(mode,
ColormapManager::getInstance().getDefault(mode));
std::ifstream mapFile(filePath);
if (!mapFile.good())
return 0;
try {
std::string firstLine;
std::getline(mapFile, firstLine);
int nbCol = boost::lexical_cast<int>(firstLine);
return nbCol;
} catch (...)
{
}
return 0;
}
std::string ColormapManager::getColorAxis(int index)
{
std::string lFile = "";
if ((index != -1) && _coloraxis.find(index) != _coloraxis.end()) {
// Concatenate path and filename.
lFile = _path + _coloraxis[index];
}
return lFile;
}
} /* namespace plot */