-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCompositeImageMetaData.cpp
121 lines (105 loc) · 3.67 KB
/
CompositeImageMetaData.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* File: CompositeImageMetaData.cpp
* Author: Marc Gershow
*
* Created on November 5, 2010, 10:00 AM
*
* (C) Marc Gershow; licensed under the Creative Commons Attribution Share Alike 3.0 United States License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to
* Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*
*/
#include "CompositeImageMetaData.h"
#include "ImageMetaDataLoader.h"
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
CompositeImageMetaData::CompositeImageMetaData() {
}
CompositeImageMetaData::CompositeImageMetaData(const CompositeImageMetaData& orig) {
}
CompositeImageMetaData::~CompositeImageMetaData() {
for(vector<ImageMetaData *>::iterator it = imd.begin(); it != imd.end(); ++it) {
if (*it != NULL) {
// cout << "*it = " << (uint32_t) *it << endl;
// cout << "cimd: deleting a " << hex << (*it)->idCode()<<dec << endl;
delete (*it);
*it = NULL;
}
}
}
void CompositeImageMetaData::toDisk(std::ofstream& os)const {
uint32_t id = idCode();
//removeNulls();
int len = imd.size();
os.write((char *) &id, sizeof(id));
os.write((char *) &len, sizeof(len));
for(vector<ImageMetaData *>::const_iterator it = imd.begin(); it != imd.end(); ++it) {
if (*it != NULL) {
(*it)->toDisk(os);
}
}
}
void CompositeImageMetaData::removeNulls() {
vector<ImageMetaData *>::iterator newend = remove(imd.begin(), imd.end(), (ImageMetaData *) NULL);
imd.erase(newend, imd.end());
}
string CompositeImageMetaData::saveDescription()const{
stringstream os;
os << "Composite Meta Data: idcode (uint32_t) = " << hex << idCode() << dec << ", int number of Image Meta Datas stored, then each Meta Data in succession:\n";
for(vector<ImageMetaData *>::const_iterator it = imd.begin(); it != imd.end(); ++it) {
if (*it != NULL) {
os << (*it)->saveDescription();
}
}
return os.str();
}
void CompositeImageMetaData::addMetaData(ImageMetaData* md) {
if (md != NULL) {
imd.push_back(md);
}
}
int32_t CompositeImageMetaData::sizeOnDisk()const {
int sod = sizeof(uint32_t) + sizeof(int32_t);
for(vector<ImageMetaData *>::const_iterator it = imd.begin(); it != imd.end(); ++it) {
if (*it != NULL) {
sod+= (*it)->sizeOnDisk();
}
}
return sod;
}
CompositeImageMetaData *CompositeImageMetaData::fromFile(std::ifstream& is) {
CompositeImageMetaData *cmd = new CompositeImageMetaData();
int len;
is.read((char *) &len, sizeof(len));
for (int j = 0; j < len; ++j) {
cmd->addMetaData(ImageMetaDataLoader::fromFile(is));
}
return cmd;
}
std::map<std::string, double> CompositeImageMetaData::getFieldNamesAndValues() const {
map<std::string, double> fnav, snav;
for (vector<ImageMetaData *>::const_iterator it = imd.begin(); it != imd.end(); ++it) {
if (*it == NULL) {
continue;
}
snav = (*it)->getFieldNamesAndValues();
fnav.insert(snav.begin(), snav.end());
}
return fnav;
}
std::vector<const ImageMetaData *> CompositeImageMetaData::getMetaDataVector() {
std::vector<const ImageMetaData *> v;
v.insert(v.begin(), imd.begin(), imd.end());
return v;
}
ImageMetaData *CompositeImageMetaData::clone() const{
CompositeImageMetaData *cimd = new CompositeImageMetaData();
for(vector<ImageMetaData *>::const_iterator it = imd.begin(); it != imd.end(); ++it) {
if (*it != NULL) {
cimd->imd.push_back((*it)->clone());
}
}
return cimd;
}