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