Structural deformable models
Data.h
Go to the documentation of this file.
1 /* data set functions -*- C++ -*- */
2 #ifndef _DATASET_H_
3 #define _DATASET_H_
4 
5 #include <vector>
6 #include "common.h"
7 #include "Image.h"
8 #include "glImage.h"
9 #include "Sensor.h"
10 #include "PropVec.h"
11 #include "vuThread.h"
12 
15 
16 #define DEFAULT_PPMM 0
17 
21 class Dataset : public Sensor {
22 // friend class Sensor;
23 public:
25  Dataset();
27  Dataset(const char* filename);
28 
29  //Dataset(const Dataset& rhs) { operator=(rhs); }
31  ~Dataset() {};
32 
33  //Dataset& operator=(const Dataset& rhs);
34 
36  bool load(const char* filename, dword ppmm=0);
37 
38  Dataset& copyData(const Dataset& rhs);
39 
41  void draw(float x=0, float y=0,
42  float sx = 1.0f, float sy = 1.0f) const;
43 
44  int getDim1Size() const { return m_Dim1; }
45  int getDim2Size() const { return m_Dim2; }
46  int getDim3Size() const { return m_Dim3; }
47  int getNChannels() const { return m_NChannels; }
48  std::ostream& print(std::ostream &os) const
49  { return os; } //don't print to model file
50 
51  void clear();
52  bool initialized() const { return m_Dim1 && m_Dim2; }
53  operator bool() const { return initialized(); }
54  const ByteImage& getImage() const { return data.at(m_CurrImage); }
55  ByteImage& getImage() { return data.at(m_CurrImage); }
56  const ByteImage& getImage(int index) const { return data.at(index); }
57  ByteImage& getImage(int index) { return data.at(index); }
58 
60  static bool loadImage(std::vector<Image<byte> > &image,
61  const char *filename);
63  static void drawImage(const std::vector<Image<byte> > &image,
64  float x=0, float y=0,
65  float sx = 1.0f, float sy = 1.0f);
66  static void drawImage(const Image<byte> &image, float x=0, float y=0,
67  float sx = 1.0f, float sy = 1.0f);
69 
70  dword getPPMM() const { return m_ppmm; }
71  void setPPMM(dword ppmm) { m_ppmm = ppmm ? ppmm : DEFAULT_PPMM; }
72  const Point2D& getOrigin() const { return m_Origin; }
73  const Point2D& getOSize() const { return m_OSize; }
74 
75  const std::string& getFilename() const { return m_Filename; }
77  { PropVec pv(0.f); return setPropScale(pv, (float)m_Dim1); }
79  { PropVec pv(getPropVec()); return scalePropVec(pv, 1.f/m_ppmm); }
80  void setHalveBeyondSize(dword hbs=0xffffffff) { m_HalveBeyondSize = hbs; }
82  void addNoise(float sigma);
83 protected:
85  float calcValue(int x, int y) const {
86  //vuLock l(*((vuMutex*)&writeMutex));
87  if((dword)x < (dword)m_Dim1 && (dword)y < (dword)m_Dim2)
88  return data[m_CurrImage].getPixel(x,y);
89  else return 0.0f;
90  }
92  std::vector<float> calcMValue(int x, int y) const {
93  //vuLock l(*((vuMutex*)&writeMutex));
94  std::vector<float> mv(m_NChannels);
95  int cc = 0;
96  for(std::vector<float>::iterator cv = mv.begin();
97  cv != mv.end(); cv++, cc++) {
98  *cv = (float)data[cc].getPixel(x,y);
99  }
100  return mv;
101  }
102  void calcMinMax() {
103  maxval = 255;
104  minval = 0;
105  }
108  std::vector<ByteImage> data;
109 
114  std::string m_Filename;
117  mutable bool m_RefreshImage;
118  dword m_HalveBeyondSize; //<! if(img>hbs) halve resolution
119 };
120 
121 #endif
const std::string & getFilename() const
Definition: Data.h:75
void setPPMM(dword ppmm)
Definition: Data.h:71
std::vector< ByteImage > data
Definition: Data.h:108
void clear()
Definition: Data.cpp:143
int m_Dim2
Definition: Data.h:111
int getDim1Size() const
Definition: Data.h:44
static bool loadImage(std::vector< Image< byte > > &image, const char *filename)
Definition: Data.cpp:159
Definition: glImage.h:9
float calcValue(int x, int y) const
Definition: Data.h:85
const Point2D & getOrigin() const
Definition: Data.h:72
int m_Dim3
Definition: Data.h:111
static void drawImage(const std::vector< Image< byte > > &image, float x=0, float y=0, float sx=1.0f, float sy=1.0f)
Definition: Data.cpp:263
float minval
overall minimum and maximum
Definition: Sensor.h:176
void setHalveBeyondSize(dword hbs=0xffffffff)
Definition: Data.h:80
const ByteImage & getImage(int index) const
Definition: Data.h:56
Dataset()
Definition: Data.cpp:46
ByteImage & getImage()
Definition: Data.h:55
Definition: Sensor.h:21
bool m_RefreshImage
Definition: Data.h:117
Point2D m_Origin
Definition: Data.h:115
Image< byte > ByteImage
Definition: Data.h:13
PropVec & scalePropVec(PropVec &prop, float scale)
Definition: PropVec.h:85
dword getPPMM() const
Definition: Data.h:70
int getDim3Size() const
Definition: Data.h:46
int getNChannels() const
Definition: Data.h:47
bool load(const char *filename, dword ppmm=0)
Definition: Data.cpp:62
Point2D m_OSize
Definition: Data.h:115
PropVec getPropVecMM() const
Definition: Data.h:78
std::ostream & print(std::ostream &os) const
Definition: Data.h:48
std::string m_Filename
Definition: Data.h:114
const Point2D & getOSize() const
Definition: Data.h:73
std::vector< float > calcMValue(int x, int y) const
Definition: Data.h:92
int getDim2Size() const
Definition: Data.h:45
ByteImage & getImage(int index)
Definition: Data.h:57
const ByteImage & getImage() const
Definition: Data.h:54
dword m_HalveBeyondSize
Definition: Data.h:118
int m_NChannels
Definition: Data.h:111
void draw(float x=0, float y=0, float sx=1.0f, float sy=1.0f) const
Definition: Data.cpp:113
unsigned long dword
Definition: simpletypes.h:6
void addNoise(float sigma)
Definition: Data.cpp:212
~Dataset()
Definition: Data.h:31
Definition: Data.h:21
GLImage m_GLImage
Definition: Data.h:116
int m_Dim1
Definition: Data.h:111
dword getHalveBeyondSize() const
Definition: Data.h:81
vuMutex writeMutex
Definition: Data.h:68
int m_CurrImage
current image
Definition: Data.h:112
void calcMinMax()
Definition: Data.h:102
Definition: Point.h:16
Image< float > FloatImage
Definition: Data.h:14
dword m_ppmm
Definition: Data.h:113
#define DEFAULT_PPMM
Definition: Data.h:16
PropVec & setPropScale(PropVec &prop, float pscale)
Definition: PropVec.h:22
PropVec getPropVec() const
Definition: Data.h:76
Dataset & copyData(const Dataset &rhs)
Definition: Data.cpp:127
bool initialized() const
Definition: Data.h:52
float maxval
Definition: Sensor.h:176