00001 #include "l7a_fast.h" 00002 #include <iostream> 00003 #include "TraceLog.h" 00004 00005 bool L7A_Fast::open( std::string fname ) { 00006 const int name_len = 29; 00007 const std::string lc_end[] = { "hpn.fst", "hrf.fst", "htm.fst"}; 00008 const std::string uc_end[] = { "HPN.FST", "HRF.FST", "HTM.FST"}; 00009 00010 if ( (int)fname.length() < name_len ) 00011 return false; 00012 00013 std::string dir = fname.substr( 0, fname.length()-name_len ); 00014 fname = fname.substr( fname.length()-name_len, name_len ); 00015 std::string pre = fname.substr( 0, fname.length()-7 ); 00016 std::string testname; 00017 bool opened = false; 00018 00019 for ( int iband=0; iband < 3; iband++ ) { 00020 testname = dir + pre + lc_end[iband]; 00021 GDALFrmt *gdal = new GDALFrmt; 00022 if ( gdal->open( testname ) ) { 00023 mFormatSet.push_back( gdal ); 00024 std::vector<BandInf> &bset = gdal->getBandInfSet(); 00025 for ( int i=0; i < (int)bset.size(); i++ ) 00026 mBandSet.push_back( bset[i] ); 00027 opened = true; 00028 continue; 00029 } 00030 00031 testname = dir + pre + uc_end[iband]; 00032 if ( gdal->open( testname ) ) { 00033 mFormatSet.push_back( gdal ); 00034 std::vector<BandInf> &bset = gdal->getBandInfSet(); 00035 for ( int i=0; i < (int)bset.size(); i++ ) 00036 mBandSet.push_back( bset[i] ); 00037 opened = true; 00038 continue; 00039 } 00040 00041 delete gdal; 00042 } 00043 if ((int)mBandSet.size()) { 00044 double x = mBandSet[0].width / 2; 00045 double y = mBandSet[0].height / 2; 00046 getLL( 0, x, y ); 00047 mImageInf.mCenterLat = y; 00048 mImageInf.mCenterLon = x; 00049 } 00050 mImageInf.mLocURL = fname ; 00051 00052 00053 return opened; 00054 } 00055 00056 void L7A_Fast::getLL( int iband, double &i, double &j ) { 00057 if ( iband < 0 || iband > (int)mBandSet.size() ) 00058 return; 00059 00060 int ifrmt = getFrmt( iband ); 00061 mFormatSet[ifrmt]->getLL( iband, i, j ); 00062 } 00063 00064 void L7A_Fast::getXY( int iband, double &i, double &j ) { 00065 if ( iband < 0 || iband > (int)mBandSet.size() ) 00066 return; 00067 00068 int ifrmt = getFrmt( iband ); 00069 mFormatSet[ifrmt]->getXY( iband, i, j ); 00070 } 00071 00072 void* L7A_Fast::getBand( int iband, 00073 int x1, 00074 int y1, 00075 int w1, 00076 int h1, 00077 int w2, 00078 int h2, 00079 ScaleType st ) const { 00080 if ( iband < 0 || iband > (int)mBandSet.size() ) 00081 return NULL; 00082 00083 int fiband = iband; 00084 int ifrmt = getFrmt( fiband ); 00085 00086 return mFormatSet[ifrmt]->getBand( fiband, x1, y1, w1, h1, w2, h2, st ); 00087 } 00088 00089 int L7A_Fast::getFrmt( int &iband ) const { 00090 int ifrmt = 0; 00091 if ( iband < 0 || iband > (int)mBandSet.size() ) 00092 return -1; 00093 00094 00095 for ( int i=0; i < (int)mFormatSet.size(); i++ ) { 00096 int nband = (int)mFormatSet[i]->getNumBands(); 00097 if ( iband >= nband ) { 00098 ifrmt++; 00099 iband -= nband; 00100 } else { 00101 break; 00102 } 00103 } 00104 00105 return ifrmt; 00106 } 00107 00108
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |