OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
PortableGraymapReader.h
Go to the documentation of this file.
1 #ifndef PORTABLEGRAYMAPRREADER_H
2 #define PORTABLEGRAYMAPRREADER_H
3 
5 
6 #include <string>
7 #include <vector>
8 #include <istream>
9 
11 public:
12  PortableGraymapReader(const std::string & input);
13 
14  unsigned int getWidth() const;
15  unsigned int getHeight() const;
16 
17  unsigned short getPixel(unsigned int i, unsigned int j) const;
18  std::vector<unsigned short> getPixels() const;
19  void print(std::ostream &out) const;
20 
21 private:
22  void readHeader(std::istream &in);
23  void readImageAscii(std::istream &in);
24  void readImageBinary(std::istream &in);
25  std::string getNextPart(std::istream &in);
26 
27  unsigned int getIdx(unsigned int h, unsigned int w) const;
28 
29  unsigned int width_m;
30  unsigned int height_m;
31  unsigned short depth_m;
32 
33  enum FileType {
36  };
37 
39 
40  std::vector<unsigned short> pixels_m;
41 };
42 
43 inline
44 unsigned int PortableGraymapReader::getWidth() const {
45  return width_m;
46 }
47 
48 inline
49 unsigned int PortableGraymapReader::getHeight() const {
50  return height_m;
51 }
52 
53 inline
54 unsigned short PortableGraymapReader::getPixel(unsigned int i, unsigned int j) const {
55  return pixels_m[getIdx(i, j)];
56 }
57 
58 inline
59 std::vector<unsigned short> PortableGraymapReader::getPixels() const {
60  return pixels_m;
61 }
62 
63 inline
64 unsigned int PortableGraymapReader::getIdx(unsigned int h, unsigned int w) const {
65  if (h >= height_m || w >= width_m) throw OpalException("PortableGraymapReader::getIdx",
66  "Pixel number out of bounds");
67  return h * width_m + w;
68 }
69 
70 #endif
unsigned short getPixel(unsigned int i, unsigned int j) const
unsigned int getHeight() const
The base class for all OPAL exceptions.
Definition: OpalException.h:28
unsigned int getIdx(unsigned int h, unsigned int w) const
unsigned int getWidth() const
std::vector< unsigned short > pixels_m
std::string getNextPart(std::istream &in)
std::vector< unsigned short > getPixels() const
void readImageAscii(std::istream &in)
void readHeader(std::istream &in)
void print(std::ostream &out) const
void readImageBinary(std::istream &in)
PortableGraymapReader(const std::string &input)