EMAN2
Typedefs | Functions
eerio.cpp File Reference
#include "eerio.h"
#include <tiffio.h>
#include <boost/property_tree/xml_parser.hpp>
Include dependency graph for eerio.cpp:

Go to the source code of this file.

Typedefs

typedef vector< pair< int, int > > COORDS
 

Functions

auto decode_eer_data (EerWord *data, Decoder &decoder)
 
void TIFFOutputWarning (const char *module, const char *fmt, va_list ap)
 
string read_acquisition_metadata (TIFF *tiff)
 
string to_snake_case (const string &s)
 
Dict parse_acquisition_data (string metadata)
 
auto read_compression (TIFF *tiff)
 
auto read_raw_data (TIFF *tiff)
 

Typedef Documentation

◆ COORDS

typedef vector<pair<int, int> > COORDS

Definition at line 46 of file eerio.cpp.

Function Documentation

◆ decode_eer_data()

auto decode_eer_data ( EerWord data,
Decoder decoder 
)

Definition at line 48 of file eerio.cpp.

48 {
49 EerStream is((data));
50 EerRle rle;
51 EerSubPix sub_pix;
52
53 is >> rle >> sub_pix;
54 int count = rle;
55
56 COORDS coords;
57
58 while (count < decoder.camera_size * decoder.camera_size) {
59 coords.push_back(decoder(count, sub_pix));
60
61 is >> rle >> sub_pix;
62
63 count += rle+1;
64 }
65
66 return coords;
67}
const unsigned int camera_size
Definition: eerio.h:126
vector< pair< int, int > > COORDS
Definition: eerio.cpp:46

References EMAN::Decoder::camera_size.

◆ parse_acquisition_data()

Dict parse_acquisition_data ( string  metadata)

Definition at line 104 of file eerio.cpp.

104 {
105 Dict dict;
106 std::istringstream ins(metadata);
107 ptree pt;
108
109 read_xml(ins, pt);
110
111 for(auto &v : pt.get_child("metadata")) {
112 auto xml_item_name = v.second.get_child("<xmlattr>.name").data();
113 auto xml_item_value = v.second.data();
114
115 auto key = "EER." + to_snake_case(xml_item_name);
116
117 dict[key] = xml_item_value;
118 }
119
120 return dict;
121}
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
string to_snake_case(const string &s)
Definition: eerio.cpp:88

References to_snake_case().

Referenced by EMAN::EerIO::EerIO().

◆ read_acquisition_metadata()

string read_acquisition_metadata ( TIFF *  tiff)

Definition at line 78 of file eerio.cpp.

78 {
79 char *metadata_c = nullptr;
80 uint32_t count = 0;
81
82 TIFFSetDirectory(tiff, 0);
83 TIFFGetField(tiff, 65001, &count, &metadata_c);
84
85 return string(metadata_c, count);
86}

Referenced by EMAN::EerIO::EerIO().

◆ read_compression()

auto read_compression ( TIFF *  tiff)

Definition at line 123 of file eerio.cpp.

123 {
124 uint16_t compression = 0;
125
126 TIFFGetField(tiff, TIFFTAG_COMPRESSION, &compression);
127
128 return compression;
129}

◆ read_raw_data()

auto read_raw_data ( TIFF *  tiff)

Definition at line 131 of file eerio.cpp.

131 {
132 auto num_strips = TIFFNumberOfStrips(tiff);
133 vector<unsigned int> strip_sizes(num_strips);
134
135 for(size_t i=0; i<num_strips; ++i)
136 strip_sizes[i] = TIFFRawStripSize(tiff, i);
137
138 std::vector<unsigned char> data;
139
140 for(size_t i=0; i<num_strips; ++i) {
141 auto prev_size = data.size();
142 data.resize(prev_size + strip_sizes[i]);
143 TIFFReadRawStrip(tiff, i, data.data() + prev_size, strip_sizes[i]);
144 }
145
146 return data;
147}

◆ TIFFOutputWarning()

void TIFFOutputWarning ( const char *  module,
const char *  fmt,
va_list  ap 
)

Definition at line 69 of file eerio.cpp.

70{
71#ifdef DEBUG
72 cout << module << ": ";
73 vprintf(fmt, ap);
74 cout << endl;
75#endif //DEBUG
76}

Referenced by EMAN::EerIO::EerIO().

◆ to_snake_case()

string to_snake_case ( const string &  s)

Definition at line 88 of file eerio.cpp.

88 {
89 auto ret(s);
90 int sh = 0;
91 for(int i=0; i<s.size(); i++) {
92 if(isupper(s[i])) {
93 if(!isupper(s[i-1])) {
94 ret.insert(i + sh, "_");
95 sh++;
96 }
97 ret[i + sh] = ::tolower(s[i]);
98 }
99 }
100
101 return ret;
102}

Referenced by parse_acquisition_data().