bool ExportDlg::invokeOptionsDialog() { // Update the file descriptor with the selected file QString strFilename = getExportFile(); updateFromFile(strFilename); // Display the dialog ExportOptionsDlg optionsDlg(mpExporter, this); if (optionsDlg.exec() == QDialog::Accepted) { // Selecting file because the filename can be changed in Export Options widget (ie: ShapeFileOptionsWidget). if (mpExporter.get() != NULL) { FileDescriptor* pFileDesc = mpExporter->getFileDescriptor(); if (pFileDesc != NULL) { std::string newFilename = pFileDesc->getFilename().getFullPathAndName(); selectFile(QString::fromStdString(newFilename)); } } mValidated = true; return true; } mValidated = false; return false; }
bool PicturesExporter::extractInputArgs(const PlugInArgList* pInArgList) { string exporter = getName(); if (exporter.empty()) { exporter = "Pictures Exporter"; } PlugInArg* pArg = NULL; // Progress if (pInArgList->getArg(Executable::ProgressArg(), pArg) && (pArg != NULL)) { mpProgress = pArg->getPlugInArgValue<Progress>(); } // File Descriptor mOutPath.erase(); FileDescriptor* pFileDescriptor = pInArgList->getPlugInArgValue<FileDescriptor>(Exporter::ExportDescriptorArg()); if (pFileDescriptor != NULL) { mOutPath = pFileDescriptor->getFilename().getFullPathAndName(); } if (mOutPath.empty()) { mMessage = "The destination path is invalid."; return false; } 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 ModelExporter::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { Progress* pProgress = NULL; FileDescriptor* pFileDescriptor = NULL; DataElement* pElement = NULL; StepResource pStep("Export model element", "app", "2BF48AAB-4832-4694-8583-882A8D584E97"); // get input arguments and log some useful info about them { // scope the MessageResource MessageResource pMsg("Input arguments", "app", "1B02F950-2E04-4BEF-8561-BB8D993340F7"); pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); pMsg->addBooleanProperty("Progress Present", (pProgress != NULL)); pFileDescriptor = pInArgList->getPlugInArgValue<FileDescriptor>(Exporter::ExportDescriptorArg()); if (pFileDescriptor == NULL) { if (pProgress != NULL) { pProgress->updateProgress("No file specified", 100, ERRORS); } pStep->finalize(Message::Failure, "No file specified"); return false; } pMsg->addProperty("Destination", pFileDescriptor->getFilename()); pElement = pInArgList->getPlugInArgValueUnsafe<DataElement>(Exporter::ExportItemArg()); if (pElement == NULL) { if (pProgress != NULL) { pProgress->updateProgress("No model element specified", 100, ERRORS); } pStep->finalize(Message::Failure, "No model element specified"); return false; } pMsg->addProperty("Name", pElement->getName()); } if (pProgress != NULL) { pProgress->updateProgress("Open output file", 10, NORMAL); } FILE* pFile = fopen(pFileDescriptor->getFilename().getFullPathAndName().c_str(), "w"); if (pFile == NULL) { if (pProgress != NULL) { pProgress->updateProgress("File can not be created", 100, ERRORS); } pStep->finalize(Message::Failure, "File can not be created"); return false; } DataDescriptor* pElementDescriptor = pElement->getDataDescriptor(); VERIFY(pElementDescriptor != NULL); if (pProgress != NULL) { pProgress->updateProgress("Save element", 20, NORMAL); } string elementName = pElementDescriptor->getType(); XMLWriter xml(elementName.c_str(), Service<MessageLogMgr>()->getLog()); if (!pElement->toXml(&xml)) { if (pProgress != NULL) { pProgress->updateProgress("Error saving model element", 100, ERRORS); } pStep->finalize(Message::Failure, "Error saving model element"); return false; } else { xml.writeToFile(pFile); } fclose(pFile); if (pProgress != NULL) { pProgress->updateProgress("Finished saving the model element", 100, NORMAL); } pStep->finalize(Message::Success); return true; }
bool ShapeFileExporter::extractInputs(const PlugInArgList* pInArgList, string& message) { if (pInArgList == NULL) { message = "Invalid argument list."; return false; } FileDescriptor* pFileDescriptor = pInArgList->getPlugInArgValue<FileDescriptor>(Exporter::ExportDescriptorArg()); if (pFileDescriptor == NULL) { message = "No file specified."; return false; } mShapefile.setFilename(pFileDescriptor->getFilename().getFullPathAndName()); if (isBatch()) { mpAoi = pInArgList->getPlugInArgValue<AoiElement>("AoiElement"); mpGeoref = pInArgList->getPlugInArgValue<RasterElement>("RasterElement"); } else { AoiLayer* pLayer = pInArgList->getPlugInArgValue<AoiLayer>(Exporter::ExportItemArg()); if (pLayer == NULL) { message = "Input argument list did not include anything to export."; return false; } mpAoi = dynamic_cast<AoiElement*>(pLayer->getDataElement()); SpatialDataView* pView = dynamic_cast<SpatialDataView*>(pLayer->getView()); if (pView != NULL) { mpLayers = pView->getLayerList(); if (mpLayers != NULL) { mpGeoref = mpLayers->getPrimaryRasterElement(); } } } if (mpAoi == NULL) { message = "Could not identify the data element to export."; return false; } // The BitMaskIterator does not support negative extents and // the BitMask does not correctly handle the outside flag so // the BitMaskIterator is used for cases when the outside flag is true and // the BitMask is used for cases when the outside flag is false. // This is the case when the outside flag is false. The case where the // outside flag is true for this condition is handled in // ShapeFile::addFeatures() const BitMask* pMask = mpAoi->getSelectedPoints(); if (mpAoi->getGroup()->getObjects().empty() == true && pMask->isOutsideSelected() == false) { message = "The AOI does not contain any points to export."; return false; } if (mpGeoref == NULL) { message = "Could not identify the georeference to use for export."; return false; } //add aoi to shape file mShapefile.setShape(ShapefileTypes::MULTIPOINT_SHAPE); string err; mShapefile.addFeatures(mpAoi, mpGeoref, err); return true; }
void ImportOptionsDlg::setCurrentDataset(ImportDescriptor* pImportDescriptor) { if (pImportDescriptor == NULL) { return; } if (pImportDescriptor == mpCurrentDataset) { return; } // Apply changes to the current data set if necessary bool bSuccess = true; if ((mpCurrentDataset != NULL) && (mEditDataDescriptorModified == true)) { if (mPromptForChanges == true) { int iReturn = QMessageBox::question(this, APP_NAME, "Apply changes to data?", QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::Cancel); if ((iReturn == QMessageBox::Yes) || (iReturn == QMessageBox::YesToAll)) { bSuccess = applyChanges(); if (iReturn == QMessageBox::YesToAll) { mPromptForChanges = false; } } else if (iReturn == QMessageBox::No) { // Update the validation icon for the original data descriptor validateDataset(mpCurrentDataset->getDataDescriptor()); } else if (iReturn == QMessageBox::Cancel) { bSuccess = false; } } else { bSuccess = applyChanges(); } } if (bSuccess == false) { // Select the tree widget item for the previously selected data set selectCurrentDatasetItem(); return; } mpCurrentDataset = pImportDescriptor; // Destroy the existing edit data descriptor if necessary Service<ModelServices> pModel; if (mpEditDescriptor != NULL) { Classification* pClassification = mpEditDescriptor->getClassification(); if (pClassification != NULL) { VERIFYNR(pClassification->detach(SIGNAL_NAME(Subject, Modified), Slot(this, &ImportOptionsDlg::editClassificationModified))); } RasterDataDescriptor* pRasterDescriptor = dynamic_cast<RasterDataDescriptor*>(mpEditDescriptor); if (pRasterDescriptor != NULL) { VERIFYNR(pRasterDescriptor->detach(SIGNAL_NAME(RasterDataDescriptor, RowsChanged), Slot(this, &ImportOptionsDlg::editDataDescriptorRowsModified))); VERIFYNR(pRasterDescriptor->detach(SIGNAL_NAME(RasterDataDescriptor, ColumnsChanged), Slot(this, &ImportOptionsDlg::editDataDescriptorColumnsModified))); VERIFYNR(pRasterDescriptor->detach(SIGNAL_NAME(RasterDataDescriptor, BandsChanged), Slot(this, &ImportOptionsDlg::editDataDescriptorBandsModified))); } RasterFileDescriptor* pRasterFileDescriptor = dynamic_cast<RasterFileDescriptor*>(mpEditDescriptor->getFileDescriptor()); if (pRasterFileDescriptor != NULL) { VERIFYNR(pRasterFileDescriptor->detach(SIGNAL_NAME(RasterFileDescriptor, RowsChanged), Slot(this, &ImportOptionsDlg::editFileDescriptorRowsModified))); VERIFYNR(pRasterFileDescriptor->detach(SIGNAL_NAME(RasterFileDescriptor, ColumnsChanged), Slot(this, &ImportOptionsDlg::editFileDescriptorColumnsModified))); VERIFYNR(pRasterFileDescriptor->detach(SIGNAL_NAME(RasterFileDescriptor, BandsChanged), Slot(this, &ImportOptionsDlg::editFileDescriptorBandsModified))); } VERIFYNR(mpEditDescriptor->detach(SIGNAL_NAME(Subject, Modified), Slot(this, &ImportOptionsDlg::editDataDescriptorModified))); pModel->destroyDataDescriptor(mpEditDescriptor); mpEditDescriptor = NULL; mEditDataDescriptorModified = false; } // Create a new data descriptor to validate the user inputs DataDescriptor* pDescriptor = mpCurrentDataset->getDataDescriptor(); if (pDescriptor != NULL) { mpEditDescriptor = pDescriptor->copy(); } VERIFYNRV(mpEditDescriptor != NULL); VERIFYNR(mpEditDescriptor->attach(SIGNAL_NAME(Subject, Modified), Slot(this, &ImportOptionsDlg::editDataDescriptorModified))); RasterDataDescriptor* pRasterDescriptor = dynamic_cast<RasterDataDescriptor*>(mpEditDescriptor); FileDescriptor* pFileDescriptor = mpEditDescriptor->getFileDescriptor(); RasterFileDescriptor* pRasterFileDescriptor = dynamic_cast<RasterFileDescriptor*>(pFileDescriptor); if (pRasterDescriptor != NULL) { VERIFYNR(pRasterDescriptor->attach(SIGNAL_NAME(RasterDataDescriptor, RowsChanged), Slot(this, &ImportOptionsDlg::editDataDescriptorRowsModified))); VERIFYNR(pRasterDescriptor->attach(SIGNAL_NAME(RasterDataDescriptor, ColumnsChanged), Slot(this, &ImportOptionsDlg::editDataDescriptorColumnsModified))); VERIFYNR(pRasterDescriptor->attach(SIGNAL_NAME(RasterDataDescriptor, BandsChanged), Slot(this, &ImportOptionsDlg::editDataDescriptorBandsModified))); } if (pRasterFileDescriptor != NULL) { VERIFYNR(pRasterFileDescriptor->attach(SIGNAL_NAME(RasterFileDescriptor, RowsChanged), Slot(this, &ImportOptionsDlg::editFileDescriptorRowsModified))); VERIFYNR(pRasterFileDescriptor->attach(SIGNAL_NAME(RasterFileDescriptor, ColumnsChanged), Slot(this, &ImportOptionsDlg::editFileDescriptorColumnsModified))); VERIFYNR(pRasterFileDescriptor->attach(SIGNAL_NAME(RasterFileDescriptor, BandsChanged), Slot(this, &ImportOptionsDlg::editFileDescriptorBandsModified))); } // Select the tree widget item for the current data set selectCurrentDatasetItem(); // Disconnect pages updateConnections(false); // Subset page if (pRasterFileDescriptor != NULL) { // Show the tab if necessary if (mpTabWidget->indexOf(mpSubsetPage) == -1) { mpTabWidget->insertTab(2, mpSubsetPage, "Subset"); } // Rows const vector<DimensionDescriptor>& rows = pRasterFileDescriptor->getRows(); const vector<DimensionDescriptor>& loadedRows = pRasterDescriptor->getRows(); mpSubsetPage->setRows(rows, loadedRows); // Columns const vector<DimensionDescriptor>& columns = pRasterFileDescriptor->getColumns(); const vector<DimensionDescriptor>& loadedColumns = pRasterDescriptor->getColumns(); mpSubsetPage->setColumns(columns, loadedColumns); // Bands const vector<DimensionDescriptor>& bands = pRasterFileDescriptor->getBands(); const vector<DimensionDescriptor>& selectedBands = pRasterDescriptor->getBands(); setSubsetBands(bands, selectedBands); // Initial bad band file directory if (pFileDescriptor != NULL) { QString strDirectory; string filename = pFileDescriptor->getFilename(); if (filename.empty() == false) { QFileInfo fileInfo(QString::fromStdString(filename)); strDirectory = fileInfo.absolutePath(); } mpSubsetPage->setBadBandFileDirectory(strDirectory); } } else { // Remove the subset page, since the file descriptor either isn't // present or isn't a RasterFileDescriptor, just a FileDescriptor int index = mpTabWidget->indexOf(mpSubsetPage); if (index != -1) { mpTabWidget->removeTab(index); } } // Data descriptor page - enable editing for all fields mpDataPage->setDataDescriptor(mpEditDescriptor, true); // File descriptor page bool editFilePage = false; if (pRasterFileDescriptor != NULL) { unsigned int numRows = pRasterFileDescriptor->getRowCount(); unsigned int numColumns = pRasterFileDescriptor->getColumnCount(); unsigned int bitsPerElement = pRasterFileDescriptor->getBitsPerElement(); unsigned int numBands = pRasterFileDescriptor->getBandCount(); if ((numRows == 0) || (numColumns == 0) || (numBands == 0) || (bitsPerElement == 0)) { editFilePage = true; } } mpFilePage->setFileDescriptor(pFileDescriptor, editFilePage); int iIndex = mpTabWidget->indexOf(mpFilePage); if (iIndex != -1) { if (pFileDescriptor == NULL) { mpTabWidget->removeTab(iIndex); } } else { if (pFileDescriptor != NULL) { mpTabWidget->insertTab(1, mpFilePage, "File"); } } // Classification page updateClassificationLabel(); Classification* pClassification = mpEditDescriptor->getClassification(); if (pClassification != NULL) { VERIFYNR(pClassification->attach(SIGNAL_NAME(Subject, Modified), Slot(this, &ImportOptionsDlg::editClassificationModified))); mpClassificationPage->setClassification(pClassification); } // Metadata page mpMetadataPage->setMetadata(mpEditDescriptor->getMetadata()); // Wavelengths page bool bWavelengthsPageActive = false; if (mpTabWidget->currentWidget() == mpWavelengthsPage) { bWavelengthsPageActive = true; } int index = mpTabWidget->indexOf(mpWavelengthsPage); if (index != -1) { mpTabWidget->removeTab(index); } if (pRasterFileDescriptor != NULL) { // Populate the wavelengths with the file descriptor bands since the metadata wavelengths // apply to all bands in the file mpWavelengthsPage->setWavelengths(pRasterFileDescriptor->getBands(), mpEditDescriptor->getMetadata()); if (pRasterDescriptor != NULL) { mpWavelengthsPage->highlightActiveBands(pRasterDescriptor->getBands()); } mpTabWidget->addTab(mpWavelengthsPage, "Wavelengths"); if (bWavelengthsPageActive == true) { mpTabWidget->setCurrentWidget(mpWavelengthsPage); } } // Importer page bool bImporterPageActive = false; if (mpImporterPage != NULL) { if (mpTabWidget->currentWidget() == mpImporterPage) { bImporterPageActive = true; } } removeImporterPage(); if (mpImporter != NULL) { mpImporterPage = mpImporter->getImportOptionsWidget(mpEditDescriptor); if (mpImporterPage != NULL) { QLayout* pLayout = mpImporterPage->layout(); if (pLayout != NULL) { if (pLayout->margin() <= 0) { pLayout->setMargin(10); } } QString strCaption = mpImporterPage->windowTitle(); if (strCaption.isEmpty() == true) { strCaption = "Importer"; } mpTabWidget->addTab(mpImporterPage, strCaption); if (bImporterPageActive == true) { mpTabWidget->setCurrentWidget(mpImporterPage); } } // Set the valid processing locations on the data page. This must be done after getting the import options // widget from the importer so that the auto importer will correctly query the importer that is used. // This can be changed if the importer design (and auto importer) is modified to support valid processing // locations for a specific data set. vector<ProcessingLocation> locations; if (mpImporter->isProcessingLocationSupported(IN_MEMORY) == true) { locations.push_back(IN_MEMORY); } if (mpImporter->isProcessingLocationSupported(ON_DISK) == true) { locations.push_back(ON_DISK); } if (mpImporter->isProcessingLocationSupported(ON_DISK_READ_ONLY) == true) { locations.push_back(ON_DISK_READ_ONLY); } mpDataPage->setValidProcessingLocations(locations); } // Validate the current data descriptor validateEditDataset(); // Reconnect the pages updateConnections(true); // Notify connected objects emit currentDatasetChanged(mpCurrentDataset); }
bool MetadataExporter::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { Progress* pProgress = NULL; FileDescriptor* pFileDescriptor = NULL; DataElement* pElement = NULL; StepResource pStep("Export metadata", "app", "{08701b89-565c-4e0a-92ef-9bf22395f902}"); // get input arguments and log some useful info about them { // scope the MessageResource MessageResource pMsg("Input arguments", "app", "{5e921da0-6470-44f1-a910-ed12af1e5ebc}"); pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); pMsg->addBooleanProperty("Progress Present", (pProgress != NULL)); pFileDescriptor = pInArgList->getPlugInArgValue<FileDescriptor>(Exporter::ExportDescriptorArg()); if (pFileDescriptor == NULL) { if (pProgress != NULL) { pProgress->updateProgress("No file specified", 100, ERRORS); } pStep->finalize(Message::Failure, "No file specified"); return false; } pMsg->addProperty("Destination", pFileDescriptor->getFilename()); pElement = pInArgList->getPlugInArgValue<DataElement>(Exporter::ExportItemArg()); if (pElement == NULL) { if (pProgress != NULL) { pProgress->updateProgress("No data element specified", 100, ERRORS); } pStep->finalize(Message::Failure, "No data element specified"); return false; } pMsg->addProperty("Name", pElement->getName()); } if (pProgress != NULL) { pProgress->updateProgress("Open output file", 10, NORMAL); } FILE* pFile = fopen(pFileDescriptor->getFilename().getFullPathAndName().c_str(), "w"); if (pFile == NULL) { if (pProgress != NULL) { pProgress->updateProgress("File can not be created", 100, ERRORS); } pStep->finalize(Message::Failure, "File can not be created"); return false; } const DynamicObject* pMetadata = pElement->getMetadata(); VERIFY(pMetadata); if (pProgress != NULL) { pProgress->updateProgress("Save metadata", 20, NORMAL); } if (pMetadata->getNumAttributes() == 0) { if (pProgress != NULL) { pProgress->updateProgress("Metadata is empty. A file will be created anyway.", 20, WARNING); } pStep->addMessage("Metadata is empty. A file will be created anyway.", "app", "{29274eb3-c899-4778-ae1e-d267ea0dd346}", true); } XMLWriter xml("Metadata", Service<MessageLogMgr>()->getLog()); xml.pushAddPoint(NULL); if (!pMetadata->toXml(&xml)) { if (pProgress != NULL) { pProgress->updateProgress("Error saving metadata", 100, ERRORS); } pStep->finalize(Message::Failure, "Error saving metadata"); return false; } xml.popAddPoint(); xml.writeToFile(pFile); fclose(pFile); if (pProgress != NULL) { pProgress->updateProgress("Finished saving the metadata", 100, NORMAL); } pStep->finalize(Message::Success); return true; }
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; }
bool PostScriptExporter::execute(PlugInArgList *pInArgList, PlugInArgList *pOutArgList) { StepResource pStep("Execute PostScript Exporter", "app", "5BE7D170-BFB5-43C9-A980-06C8C376D558"); Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); View* pView = pInArgList->getPlugInArgValue<View>(Exporter::ExportItemArg()); if (pView == NULL) { string msg = "No view specified."; if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } pStep->finalize(Message::Failure, msg); return false; } string outPath; string viewName = pView->getName(); pStep->addProperty("View Name", viewName); FileDescriptor* pFileDescriptor = pInArgList->getPlugInArgValue<FileDescriptor>(Exporter::ExportDescriptorArg()); if (pFileDescriptor != NULL) { outPath = pFileDescriptor->getFilename().getFullPathAndName(); } if (outPath.empty()) { string msg = "The destination path is invalid."; if (pProgress) { pProgress->updateProgress(msg, 0, ERRORS); } pStep->finalize(Message::Failure, msg); return false; } pStep->addProperty("Filename", outPath); QSize outputSize; unsigned int outputWidth = 0; unsigned int outputHeight = 0; if (pInArgList->getPlugInArgValue("Output Width", outputWidth) && pInArgList->getPlugInArgValue("Output Height", outputHeight)) { pStep->addProperty("Output Width", outputWidth); pStep->addProperty("Output Height", outputHeight); outputSize = QSize(outputWidth, outputHeight); } // Get the current image from the viewer FileResource outFile(outPath.c_str(), "wb"); VERIFY(outFile.get() != NULL); mpOutFile = outFile.get(); if (outputSize == QSize()) { QImage image; pView->getCurrentImage(image); writePostScriptHeader(outPath, QPoint(0, 0), image.size()); writeImageSegment(image, QPoint(0, 0)); } else { writePostScriptHeader(outPath, QPoint(0, 0), outputSize); QSize subImageSize(512, 512); QPoint origin(0, 0); View::SubImageIterator* pSubImage = pView->getSubImageIterator(outputSize, subImageSize); int totalX; int totalTiles; pSubImage->count(totalX, totalTiles); totalTiles *= totalX; while (pSubImage->hasNext()) { QImage subImage; if (!pSubImage->next(subImage)) { if (pProgress != NULL) { pProgress->updateProgress("An error occurred when generating the image", 0, ERRORS); } delete pSubImage; return false; } writeImageSegment(subImage, origin); int newX = origin.x() + subImage.width(); int newY = origin.y(); if (newX >= outputSize.width()) { newY += subImage.height(); newX = 0; } origin = QPoint(newX, newY); if (pProgress != NULL) { int x; int y; pSubImage->location(x, y); int tileNumber = y * totalX + x; QString msg = QString("Processing sub-image %1 of %2...").arg(y * totalX + x + 1).arg(totalTiles); pProgress->updateProgress(msg.toStdString(), 100 * tileNumber / totalTiles - 1, NORMAL); } } delete pSubImage; } writePostScriptFooter(); if (pProgress != NULL) { pProgress->updateProgress("PostScript Exporter completed", 100, NORMAL); } mpOutFile = NULL; pStep->finalize(Message::Success); return true; }