|
Isis 3.0 Object Programmers' Reference |
Home |
00001 00023 #include <vector> 00024 #include "Blobber.h" 00025 #include "Table.h" 00026 #include "Cube.h" 00027 #include "Progress.h" 00028 #include "SpecialPixel.h" 00029 #include "iException.h" 00030 00031 namespace Isis { 00032 00033 using std::string; 00034 using std::vector; 00035 00042 Blobber::Blobber() : _blobname("_undefined_"), _fieldname("_undefined_"), 00043 _name("Blob") { } 00062 Blobber::Blobber(const std::string &blobname, const std::string &fieldname, 00063 const std::string &name) : _blobname(blobname), 00064 _fieldname(fieldname), _name(name) { 00065 } 00066 00091 Blobber::Blobber(Cube &cube, const std::string &blobname, 00092 const std::string &fieldname, 00093 const std::string &name) : 00094 _blobname(blobname), 00095 _fieldname(fieldname), 00096 _name(name) { 00097 load(cube); 00098 } 00099 00122 Blobber Blobber::deepcopy() const { 00123 Blobber myblob = *this; 00124 myblob._buf = _buf.copy(); 00125 return (myblob); 00126 } 00127 00135 void Blobber::load(const std::string &filename) { 00136 Cube cube; 00137 cube.Open(filename); 00138 load(cube); 00139 return; 00140 } 00153 void Blobber::load(Cube &cube) { 00154 Table tbl(getBlobName()); 00155 cube.Read(tbl); 00156 TableField data = tbl[0][getFieldName()]; 00157 if (data.IsDouble()) { 00158 loadDouble(tbl); 00159 } 00160 else if (data.IsInteger()) { 00161 loadInteger(tbl); 00162 } 00163 else { 00164 string msg = "Field type for " + getFieldName() + 00165 " is not double or integer"; 00166 throw iException::Message(iException::Programmer,msg,_FILEINFO_); 00167 } 00168 } 00169 00170 00181 void Blobber::loadDouble(Table &tbl) { 00182 int nlines = tbl.Records(); 00183 int nsamps = tbl[0][getFieldName()].Size(); 00184 BlobBuf pixels(nlines, nsamps); 00185 for (int i = 0 ; i < nlines ; i++) { 00186 vector<double> d = tbl[i][getFieldName()]; 00187 for (unsigned int j = 0 ; j < d.size() ; j++) { 00188 pixels[i][j] = d[j]; 00189 } 00190 } 00191 _buf = pixels; 00192 } 00193 00207 void Blobber::loadInteger(Table &tbl) { 00208 int nlines = tbl.Records(); 00209 int nsamps = tbl[0][getFieldName()].Size(); 00210 BlobBuf pixels(nlines, nsamps); 00211 for (int i = 0 ; i < nlines ; i++) { 00212 vector<int> d = tbl[i][getFieldName()]; 00213 for (unsigned int j = 0 ; j < d.size(); j++) { 00214 pixels[i][j] = int2ToDouble(d[j]); 00215 } 00216 } 00217 _buf = pixels; 00218 } 00219 00229 double Blobber::int2ToDouble (int value) const { 00230 if (value == NULL2) return NULL8; 00231 else if (value == LOW_REPR_SAT2) return LOW_REPR_SAT8; 00232 else if (value == LOW_INSTR_SAT2) return LOW_INSTR_SAT8; 00233 else if (value == HIGH_INSTR_SAT2) return HIGH_INSTR_SAT8; 00234 else if (value == HIGH_REPR_SAT2) return HIGH_REPR_SAT8; 00235 else return value; 00236 00237 } 00238 00239 } // end namespace Isis