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);
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 private:
22  bool readTiffFile(const std::string &fileName, bool noNeg);
23 
24  int m_width, m_height;
25  std::vector<double> m_values;
26 
27  class Tile
28  {
29  public:
30  Tile() { }
31  Tile(size_t s) { m_buffer.resize(s); }
32  Tile(const Tile &src) { m_buffer = src.m_buffer; }
33  float *getData() { assert(m_buffer.size() > 0); return &(m_buffer[0]); }
34  private:
35  std::vector<float> m_buffer;
36  };
37 };
38 
39 inline double TIFFDensityFile::getValue(int x, int y) const
40 {
41  assert(x >= 0 && x < m_width);
42  assert(y >= 0 && y < m_height);
43 
44  int idx = x + y*m_width;
45  assert(idx >= 0 && idx < m_values.size());
46 
47  return m_values[idx];
48 }
49 
50 inline void TIFFDensityFile::setValue(int x, int y, double v)
51 {
52  assert(x >= 0 && x < m_width);
53  assert(y >= 0 && y < m_height);
54 
55  int idx = x + y*m_width;
56  assert(idx >= 0 && idx < m_values.size());
57 
58  m_values[idx] = v;
59 }
60 
61 #endif // TIFFDENSITYFILE_H
Base class which allows an error message to be set.
Definition: errorbase.h:49