Simpact Cyan
Population based event driven simulation using mNRM
tiffdensityfile.h
1 #ifndef TIFFDENSITYFILE_H
2 
3 #define TIFFDENSITYFILE_H
4 
5 #include "errut/errorbase.h"
6 #include <assert.h>
7 #include <vector>
8 
9 class TIFFDensityFile : public errut::ErrorBase
10 {
11 public:
12  TIFFDensityFile();
13  ~TIFFDensityFile();
14 
15  // Note: everything will be converted to doubles!
16  bool init(const std::string &fileName, bool noNegativeValues = true, bool flipY = false);
17  int getWidth() const { return m_width; }
18  int getHeight() const { return m_height; }
19  double getValue(int x, int y) const;
20  void setValue(int x, int y, double v);
21  bool isYFlipped() const { return m_yFlipped; }
22 private:
23  bool readTiffFile(const std::string &fileName, bool noNeg, bool flipY);
24 
25  template<class T>
26  bool readTilesFromTIFF(void *pTiffVoid, int tileWidth, int tileHeight, int width, int height, bool noNeg, const std::string &fileName);
27 
28  int m_width, m_height;
29  std::vector<double> m_values;
30  bool m_yFlipped;
31 
32  template<class T>
33  class Tile
34  {
35  public:
36  Tile() { }
37  Tile(size_t s) { m_buffer.resize(s); }
38  Tile(const Tile &src) { m_buffer = src.m_buffer; }
39  T *getData() { assert(m_buffer.size() > 0); return &(m_buffer[0]); }
40  private:
41  std::vector<T> m_buffer;
42  };
43 };
44 
45 inline double TIFFDensityFile::getValue(int x, int y) const
46 {
47  assert(x >= 0 && x < m_width);
48  assert(y >= 0 && y < m_height);
49 
50  int idx = x + y*m_width;
51  assert(idx >= 0 && idx < m_values.size());
52 
53  return m_values[idx];
54 }
55 
56 inline void TIFFDensityFile::setValue(int x, int y, double v)
57 {
58  assert(x >= 0 && x < m_width);
59  assert(y >= 0 && y < m_height);
60 
61  int idx = x + y*m_width;
62  assert(idx >= 0 && idx < m_values.size());
63 
64  m_values[idx] = v;
65 }
66 
67 #endif // TIFFDENSITYFILE_H
Base class which allows an error message to be set.
Definition: errorbase.h:49