OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
11public:
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
21private:
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 {
35 BINARY
36 };
37
39
40 std::vector<unsigned short> pixels_m;
41};
42
43inline
44unsigned int PortableGraymapReader::getWidth() const {
45 return width_m;
46}
47
48inline
50 return height_m;
51}
52
53inline
54unsigned short PortableGraymapReader::getPixel(unsigned int i, unsigned int j) const {
55 return pixels_m[getIdx(i, j)];
56}
57
58inline
59std::vector<unsigned short> PortableGraymapReader::getPixels() const {
60 return pixels_m;
61}
62
63inline
64unsigned 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
std::vector< unsigned short > pixels_m
std::string getNextPart(std::istream &in)
void print(std::ostream &out) const
void readImageBinary(std::istream &in)
unsigned int getWidth() const
unsigned int getIdx(unsigned int h, unsigned int w) const
unsigned int getHeight() const
unsigned short getPixel(unsigned int i, unsigned int j) const
std::vector< unsigned short > getPixels() const
void readHeader(std::istream &in)
void readImageAscii(std::istream &in)
PortableGraymapReader(const std::string &input)
The base class for all OPAL exceptions.
Definition: OpalException.h:28