bool PropertiesFileDescriptor::initialize(SessionItem* pSessionItem) { FileDescriptorWidget* pDescriptorPage = dynamic_cast<FileDescriptorWidget*>(getWidget()); if (pDescriptorPage == NULL) { return false; } DataElement* pElement = dynamic_cast<DataElement*>(pSessionItem); if (pElement != NULL) { DataDescriptor* pDescriptor = pElement->getDataDescriptor(); if (pDescriptor != NULL) { const FileDescriptor* pFileDescriptor = pDescriptor->getFileDescriptor(); if (pFileDescriptor != NULL) { pDescriptorPage->setFileDescriptor(pFileDescriptor); return true; } } } return false; }
bool DiHdfImporter::createRasterPager(RasterElement *pRaster) const { VERIFY(pRaster != NULL); DataDescriptor *pDescriptor = pRaster->getDataDescriptor(); VERIFY(pDescriptor != NULL); FileDescriptor *pFileDescriptor = pDescriptor->getFileDescriptor(); VERIFY(pFileDescriptor != NULL); std::string filename = pRaster->getFilename(); Progress *pProgress = getProgress(); FactoryResource<Filename> pFilename; pFilename->setFullPathAndName(filename); ExecutableResource pagerPlugIn("DiHdfRasterPager", std::string(), pProgress); pagerPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedElementArg(), pRaster); pagerPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedFilenameArg(), pFilename.get()); bool success = pagerPlugIn->execute(); RasterPager *pPager = dynamic_cast<RasterPager*>(pagerPlugIn->getPlugIn()); if(!success || pPager == NULL) { std::string message = "Execution of DiHdfRasterPager failed!"; if (pProgress != NULL) pProgress->updateProgress(message, 0, ERRORS); return false; } pRaster->setPager(pPager); pagerPlugIn->releasePlugIn(); return true; }
bool Nitf::NitfImporterShell::createRasterPager(RasterElement *pRaster) const { VERIFY(pRaster != NULL); DataDescriptor* pDd = pRaster->getDataDescriptor(); VERIFY(pDd != NULL); FileDescriptor* pFd = pDd->getFileDescriptor(); VERIFY(pFd != NULL); const string& datasetLocation = pFd->getDatasetLocation(); if (datasetLocation.empty() == true) { return false; } stringstream imageNameStream(datasetLocation.substr(1)); int imageSegment; imageNameStream >> imageSegment; FactoryResource<Filename> pFn; pFn->setFullPathAndName(pFd->getFilename()); ExecutableResource pPlugIn("NitfPager"); pPlugIn->getInArgList().setPlugInArgValue("Segment Number", &imageSegment); pPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedElementArg(), pRaster); pPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedFilenameArg(), pFn.get()); if (pPlugIn->execute() == true) { RasterPager* pPager = dynamic_cast<RasterPager*>(pPlugIn->getPlugIn()); if (pPager != NULL) { pRaster->setPager(pPager); pPlugIn->releasePlugIn(); return true; } } return false; }
bool GeoTIFFExporter::applyWorldFile(TIFF *pOut) { FILE* pTfw = NULL; int size = 0; double pPixsize[3]; double xoff; double yoff; double pTiepoint[6]; double x_rot; double y_rot; double pAdfMatrix[16]; DataDescriptor* pDescriptor = mpRaster->getDataDescriptor(); if (pDescriptor == NULL) { return false; } FileDescriptor* pFileDescriptor = pDescriptor->getFileDescriptor(); if (pFileDescriptor == NULL) { return false; } const Filename& filename = pFileDescriptor->getFilename(); string path = filename.getPath(); string title = filename.getTitle(); std::string worldFilename = path + SLASH + title + ".tfw"; pTfw = fopen(worldFilename.c_str(), "rt"); if (pTfw == NULL) { return false; } fscanf(pTfw, "%lf", pPixsize + 0); fscanf(pTfw, "%lf", &y_rot); fscanf(pTfw, "%lf", &x_rot); fscanf(pTfw, "%lf", pPixsize + 1); fscanf(pTfw, "%lf", &xoff); fscanf(pTfw, "%lf", &yoff); fclose(pTfw); // Write out pixel scale, and tiepoint information. if ((x_rot == 0.0) && (y_rot == 0.0)) { pPixsize[1] = abs(pPixsize[1]); pPixsize[2] = 0.0; TIFFSetField(pOut, GTIFF_PIXELSCALE, 3, pPixsize); pTiepoint[0] = 0.5; pTiepoint[1] = 0.5; pTiepoint[2] = 0.0; pTiepoint[3] = xoff; pTiepoint[4] = yoff; pTiepoint[5] = 0.0; TIFFSetField(pOut, GTIFF_TIEPOINTS, 6, pTiepoint); } else { memset(pAdfMatrix, 0, sizeof(double) * 16); pAdfMatrix[0] = pPixsize[0]; pAdfMatrix[1] = x_rot; pAdfMatrix[3] = xoff - (pPixsize[0] + x_rot) * 0.5; pAdfMatrix[4] = y_rot; pAdfMatrix[5] = pPixsize[1]; pAdfMatrix[7] = yoff - (pPixsize[1] + y_rot) * 0.5; pAdfMatrix[15] = 1.0; TIFFSetField(pOut, TIFFTAG_GEOTRANSMATRIX, 16, pAdfMatrix); } return true; }
bool SignatureSetImporter::execute(PlugInArgList* pInArgList, PlugInArgList* OutArgList) { VERIFY(pInArgList != NULL); Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); ProgressTracker progress(pProgress, "Loading spectral signature library", "spectral", "7B21EE8A-D2E1-4325-BB9F-F4E521BFD5ED"); SignatureSet* pSignatureSet = pInArgList->getPlugInArgValue<SignatureSet>(Importer::ImportElementArg()); VERIFY(pSignatureSet != NULL); DataDescriptor* pDataDescriptor = pSignatureSet->getDataDescriptor(); VERIFY(pDataDescriptor != NULL); FileDescriptor* pFileDescriptor = pDataDescriptor->getFileDescriptor(); VERIFY(pFileDescriptor != NULL); const string& filename = pFileDescriptor->getFilename().getFullPathAndName(); progress.getCurrentStep()->addProperty("signature set", pSignatureSet->getName()); progress.getCurrentStep()->addProperty("dataset location", pFileDescriptor->getDatasetLocation()); // locate the spot in the tree for this dataset try { string expr; vector<string> parts = StringUtilities::split(pFileDescriptor->getDatasetLocation(), '/'); for (vector<string>::iterator part = parts.begin(); part != parts.end(); ++part) { if (!part->empty()) { expr += "/signature_set[metadata/@name='Name' and metadata/@value='" + *part + "']"; } } expr += "/signature"; loadDoc(filename); DOMXPathResult* pResult = mXml[filename]->query(expr, DOMXPathResult::SNAPSHOT_RESULT_TYPE); VERIFY(pResult != NULL); int nodeTotal = pResult->getSnapshotLength(); for (int nodeNum = 0; nodeNum < nodeTotal; ++nodeNum) { if (isAborted()) { progress.report("Aborted file " + pFileDescriptor->getFilename().getFullPathAndName(), 0, WARNING, true); progress.report("User aborted the operation.", 0, ABORT, true); return false; } int percent = static_cast<int>(100.0 * nodeNum / nodeTotal); progress.report("Importing signature library", percent, NORMAL); if (!pResult->snapshotItem(nodeNum) || !pResult->isNode()) { continue; } const DOMElement* pElmnt = static_cast<const DOMElement*>(pResult->getNodeValue()); string filename = A(pElmnt->getAttribute(X("filename"))); if (filename.empty() == false) { string path = pFileDescriptor->getFilename().getPath(); QString tempFilename = QString::fromStdString(filename); if (tempFilename.startsWith("./") == true) { tempFilename.replace(0, 1, QString::fromStdString(path)); filename = tempFilename.toStdString(); } else { QFileInfo fileInfo(tempFilename); if (fileInfo.isRelative() == true) { filename = path + SLASH + filename; } } } // don't pass progress to importer - the individual signature imports are rapid and passing progress will // cause isAborted() to not function properly. ImporterResource importer("Auto Importer", filename, NULL); if (importer->getPlugIn() == NULL) { progress.report("The \"Auto Importer\" is not available and is required to import signature sets.", 0, ERRORS, true); return false; } if (importer->execute()) { vector<DataElement*> elements = importer->getImportedElements(); vector<Signature*> sigs(elements.size(), NULL); for (vector<DataElement*>::iterator element = elements.begin(); element != elements.end(); ++element) { Signature* pSig = dynamic_cast<Signature*>(*element); if (pSig != NULL) { pSignatureSet->insertSignature(pSig); // reparent the signature Service<ModelServices>()->setElementParent(pSig, pSignatureSet); } } } else { progress.report("Unable to import signature " + filename, percent, WARNING, true); } } } catch(DOMException &exc) { progress.report(A(exc.getMessage()), 0, ERRORS, true); return false; } SignatureSet* pParent = dynamic_cast<SignatureSet*>(pSignatureSet->getParent()); if (pParent != NULL && pParent->getFilename() == pSignatureSet->getFilename()) { pParent->insertSignature(pSignatureSet); } progress.report("Spectral signature library loaded", 100, NORMAL); progress.upALevel(); return true; }
bool Nitf::NitfImporterShell::createRasterPager(RasterElement* pRaster) const { if (pRaster == NULL) { return false; } // Get the filename string filename = pRaster->getFilename(); FactoryResource<Filename> pFilename; pFilename->setFullPathAndName(filename); // Get the image segment corresponding to this raster element DataDescriptor* pDescriptor = pRaster->getDataDescriptor(); VERIFY(pDescriptor != NULL); FileDescriptor* pFileDescriptor = pDescriptor->getFileDescriptor(); VERIFY(pFileDescriptor != NULL); const string& datasetLocation = pFileDescriptor->getDatasetLocation(); if (datasetLocation.empty() == true) { return false; } string imageSegmentText = datasetLocation.substr(1); unsigned int imageSegment = StringUtilities::fromDisplayString<unsigned int>(imageSegmentText) - 1; // Create the resource to execute the pager ExecutableResource pPlugIn; // Check for J2K compression in the metadata of the raster element being imported and not the given raster // element, because the given raster element may be a temporary raster element used by RasterElementImporterShell // when the processing location is IN_MEMORY, which does not contain the metadata or the parent information // (see RasterUtilities::generateUnchippedRasterDataDescriptor()) string imageCompression; const RasterElement* pElement = getRasterElement(); if (pElement != NULL) { const DynamicObject* pMetadata = pElement->getMetadata(); VERIFYRV(pMetadata, NULL); const string attributePath[] = { Nitf::NITF_METADATA, Nitf::IMAGE_SUBHEADER, Nitf::ImageSubheaderFieldNames::COMPRESSION, END_METADATA_NAME }; imageCompression = pMetadata->getAttributeByPath(attributePath).toDisplayString(); } if ((imageCompression == Nitf::ImageSubheaderFieldValues::IC_C8) || (imageCompression == Nitf::ImageSubheaderFieldValues::IC_M8)) { // Get the offset and size of the image segment in the file uint64_t offset = getImageOffset(filename, imageSegment); uint64_t size = getImageSize(filename, imageSegment); // Use the JPEG2000 pager pPlugIn->setPlugIn("JPEG2000 Pager"); pPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedElementArg(), pRaster); pPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedFilenameArg(), pFilename.get()); pPlugIn->getInArgList().setPlugInArgValue("Offset", &offset); pPlugIn->getInArgList().setPlugInArgValue("Size", &size); } else { // Use the NITF Pager pPlugIn->setPlugIn("NitfPager"); pPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedElementArg(), pRaster); pPlugIn->getInArgList().setPlugInArgValue(CachedPager::PagedFilenameArg(), pFilename.get()); pPlugIn->getInArgList().setPlugInArgValue("Segment Number", &imageSegment); } if (pPlugIn->execute() == true) { RasterPager* pPager = dynamic_cast<RasterPager*>(pPlugIn->getPlugIn()); if (pPager != NULL) { pRaster->setPager(pPager); pPlugIn->releasePlugIn(); return true; } } return false; }
bool SignatureImporter::execute(PlugInArgList* pInArgList, PlugInArgList* OutArgList) { VERIFY(pInArgList != NULL); ProgressTracker progress(pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()), "Loading spectral signature", "spectral", "5A9F8379-7D7D-4575-B78B-305AE0DFC66D"); Signature* pSignature = pInArgList->getPlugInArgValue<Signature>(Importer::ImportElementArg()); VERIFY(pSignature != NULL); DataDescriptor* pDataDescriptor = pSignature->getDataDescriptor(); VERIFY(pDataDescriptor != NULL); FileDescriptor* pFileDescriptor = pDataDescriptor->getFileDescriptor(); VERIFY(pFileDescriptor != NULL); progress.getCurrentStep()->addProperty("filename", pFileDescriptor->getFilename().getFullPathAndName()); DynamicObject* pMetadata = pSignature->getMetadata(); VERIFY(pMetadata != NULL); string warningMsg; LargeFileResource pSigFile; VERIFY(pSigFile.open(pFileDescriptor->getFilename().getFullPathAndName(), O_RDONLY | O_BINARY, S_IREAD)); const Units* pUnits = pSignature->getUnits("Reflectance"); VERIFY(pUnits != NULL); // Read the signature data vector<double> wavelengthData, reflectanceData; int64_t fileSize = pSigFile.fileLength(); bool readError = false; size_t largeValueCount(0); for (string line = pSigFile.readLine(&readError); readError == false; line = pSigFile.readLine(&readError)) { if (isAborted()) { progress.report("Importer aborted", 0, ABORT, true); return false; } int64_t fileLocation = pSigFile.tell(); progress.report("Loading signature data", static_cast<int>(fileLocation * 100.0 / fileSize), NORMAL); trim(line); if (line.empty()) { continue; } if (line.find('=') == string::npos) { double wavelength = 0.0, reflectance = 0.0; vector<string> dataEntry; split(dataEntry, line, is_space()); bool error = true; if (dataEntry.size() >= 1) { wavelength = StringUtilities::fromXmlString<double>(dataEntry[0], &error); if (wavelength > 50.0) { // Assume wavelength values are in nanometers and convert to microns wavelength = Wavelengths::convertValue(wavelength, NANOMETERS, MICRONS); } } if (!error && dataEntry.size() == 2) { reflectance = StringUtilities::fromXmlString<double>(dataEntry[1], &error); // Since the signature file may not have contained info on units and unitScale (defaults to values of // "REFLECTANCE" and "1.0"), we need to check that the reflectance value is properly scaled. // In theory, a valid reflectance value should be between 0 and 1, but real data may extend beyond these // limits due to errors that occurred in collection, calibration, conversion, etc. We're assuming that a // value greater than 2.0 indicates that the value was scaled by a factor other than 1.0 - a common data // collection practice is to store a data value as an integer value equal to the actual value multiplied // by a scaling factor. This saves storage space while preserving precision. 10000 is a very common // scaling factor and the one we will assume was used. Right now we'll just count the number of large values. // If more than half the values are large, we will assume they were scaled and divide all the values by 10000. if (pUnits->getUnitType() == REFLECTANCE && pUnits->getScaleFromStandard() == 1.0 && fabs(reflectance) > 2.0) { ++largeValueCount; } } if (error) { progress.report("Error parsing signature data", 0, ERRORS, true); } wavelengthData.push_back(wavelength); reflectanceData.push_back(reflectance); } } if ((readError == true) && (pSigFile.eof() != 1)) { progress.report("Unable to read signature file", 0, ERRORS, true); return false; } // check for need to scale the values, i.e., at least half the values are large if (reflectanceData.empty() == false && largeValueCount > 0 && largeValueCount >= (reflectanceData.size() / 2)) { warningMsg += (warningMsg.empty() ? "" : "\n"); warningMsg += "Values appear to have been scaled - values have been divided by 10000"; for (vector<double>::iterator it = reflectanceData.begin(); it != reflectanceData.end(); ++it) { *it *= 0.0001; // divide by 10000 } } pSignature->setData("Wavelength", wavelengthData); pSignature->setData("Reflectance", reflectanceData); if (warningMsg.empty()) { progress.report("Spectral signature loaded", 100, NORMAL); } else { progress.report(warningMsg, 100, WARNING); progress.getCurrentStep()->addMessage(warningMsg, "spectral", "770EB61A-71CD-4f83-8C7B-E0FEF3D7EB8D"); } progress.upALevel(); return true; }