| 43 | } |
| 44 | |
| 45 | bool VSIImage::initializeType(const std::string& imagePath) { |
| 46 | cleanup(); |
| 47 | if (!core::fileExists(imagePath)) { |
| 48 | return false; |
| 49 | } |
| 50 | _vsiFileName = imagePath; |
| 51 | string pth = core::extractFilePath(imagePath); |
| 52 | string fileName = core::extractFileName(imagePath); |
| 53 | string baseName = core::extractBaseName(imagePath); |
| 54 | vector<string> etsFiles; |
| 55 | core::getFiles(core::completePath("_" + baseName + "_",pth),"*.ets",etsFiles, true); |
| 56 | if (etsFiles.empty()) { |
| 57 | core::getFiles(core::completePath(baseName, pth), "*.ets", etsFiles, true); |
| 58 | if (etsFiles.empty()) { |
| 59 | core::getFiles("_" + core::completePath(baseName, pth), "*.ets", etsFiles, true); |
| 60 | if (etsFiles.empty()) { |
| 61 | core::getFiles(core::completePath(baseName, pth) + "_", "*.ets", etsFiles, true); |
| 62 | if (etsFiles.empty()) { |
| 63 | std::cout << "Could not find the .ets files belonging to " << baseName << ".vsi, is the VSI-folder present and correctly named?" << std::endl; |
| 64 | return false; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | unsigned long long _mostNrPixels = 0; |
| 70 | for (unsigned int i = 0; i < etsFiles.size(); ++i) { |
| 71 | ifstream ets; |
| 72 | ets.open(etsFiles[i].c_str(), ios::in | ios::binary); |
| 73 | if (ets.good()) { |
| 74 | unsigned long long nrPixels = parseETSFile(ets); |
| 75 | if (nrPixels > _mostNrPixels) { |
| 76 | _mostNrPixels = nrPixels; |
| 77 | _etsFile = etsFiles[i]; |
| 78 | } |
| 79 | } |
| 80 | ets.close(); |
| 81 | _tileCoords.clear(); |
| 82 | _tileOffsets.clear(); |
| 83 | _tileSizeX = 0; |
| 84 | _tileSizeY = 0; |
| 85 | _nrTilesX = 0; |
| 86 | _nrTilesY = 0; |
| 87 | _compressionType = 0; |
| 88 | _levelDimensions.clear(); |
| 89 | } |
| 90 | ifstream ets; |
| 91 | ets.open(_etsFile.c_str(), ios::in | ios::binary); |
| 92 | parseETSFile(ets); |
| 93 | ets.close(); |
| 94 | _fileType = "vsi"; |
| 95 | return _isValid; |
| 96 | } |
| 97 | |
| 98 | unsigned long long VSIImage::parseETSFile(std::ifstream& ets) { |
| 99 | // Read general file info |
nothing calls this directly
no test coverage detected