void RasterElementImporterShell::polishDataDescriptor(DataDescriptor* pDescriptor) { RasterDataDescriptor* pRasterDescriptor = dynamic_cast<RasterDataDescriptor*>(pDescriptor); if (pRasterDescriptor == NULL) { return; } // Set a georeference plug-in in the georeference descriptor if one has not yet been set regardless of // the auto-georeference setting so that a default plug-in will be available for manual georeference GeoreferenceDescriptor* pGeorefDescriptor = pRasterDescriptor->getGeoreferenceDescriptor(); if (pGeorefDescriptor != NULL) { const string& plugInName = pGeorefDescriptor->getGeoreferencePlugInName(); if (plugInName.empty() == true) { pRasterDescriptor->setDefaultGeoreferencePlugIn(); } } }
bool SampleGeoref::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { // Do any kind of setup we need before converting coordinates. // In this case, get our X and Y factors. StepResource pStep("Run Sample Georef", "app", "CFCB8AA9-D504-42e9-86F0-547DF9B4798A"); Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); FAIL_IF(!isBatch(), "Interactive mode is not supported.", return false); mpRaster = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); FAIL_IF(mpRaster == NULL, "Could not find the raster element", return false); // Get the values from the input args bool xSizeArgSet = pInArgList->getPlugInArgValue("XSize", mXSize); bool ySizeArgSet = pInArgList->getPlugInArgValue("YSize", mYSize); bool extrapolateArgSet = pInArgList->getPlugInArgValue("Extrapolate", mExtrapolate); // If the arg values are not set, get the values from the georeference descriptor; // otherwise update the georeference descriptor with the arg values RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(mpRaster->getDataDescriptor()); FAIL_IF(pDescriptor == NULL, "Could not get the data descriptor.", return false); GeoreferenceDescriptor* pGeorefDescriptor = pDescriptor->getGeoreferenceDescriptor(); if (pGeorefDescriptor != NULL) { if (xSizeArgSet == false) { mXSize = dv_cast<int>(pGeorefDescriptor->getAttributeByPath("SampleGeoref/XSize"), mXSize); } if (ySizeArgSet == false) { mYSize = dv_cast<int>(pGeorefDescriptor->getAttributeByPath("SampleGeoref/YSize"), mYSize); } if (extrapolateArgSet == false) { mExtrapolate = dv_cast<bool>(pGeorefDescriptor->getAttributeByPath("SampleGeoref/Extrapolate"), mExtrapolate); } } // Calculate the scale for the georeference unsigned int rows = pDescriptor->getRowCount(); unsigned int cols = pDescriptor->getColumnCount(); mXScale = static_cast<double>(mXSize) / rows; mYScale = static_cast<double>(mYSize) / cols; // Set the georeference plug-in into the raster element mpRaster->setGeoreferencePlugin(this); // Update the georeference descriptor with the current georeference parameters if necessary if (pGeorefDescriptor != NULL) { // Georeference plug-in const std::string& plugInName = getName(); pGeorefDescriptor->setGeoreferencePlugInName(plugInName); // X-size if (xSizeArgSet == true) { pGeorefDescriptor->setAttributeByPath("SampleGeoref/XSize", mXSize); } // Y-size if (ySizeArgSet == true) { pGeorefDescriptor->setAttributeByPath("SampleGeoref/YSize", mYSize); } // Extrapolate if (extrapolateArgSet == true) { pGeorefDescriptor->setAttributeByPath("SampleGeoref/Extrapolate", mExtrapolate); } } pStep->finalize(Message::Success); return true; }
QWidget* RasterElementImporterShell::getPreview(const DataDescriptor* pDescriptor, Progress* pProgress) { if (pDescriptor == NULL) { return NULL; } // Create a copy of the descriptor to change the loading parameters string previewName = string("Preview: ") + pDescriptor->getName(); RasterDataDescriptor* pLoadDescriptor = dynamic_cast<RasterDataDescriptor*>(pDescriptor->copy(previewName, NULL)); if (pLoadDescriptor == NULL) { return NULL; } // Set the active row and column numbers vector<DimensionDescriptor> newRows = pLoadDescriptor->getRows(); for (unsigned int i = 0; i < newRows.size(); ++i) { newRows[i].setActiveNumber(i); } pLoadDescriptor->setRows(newRows); vector<DimensionDescriptor> newColumns = pLoadDescriptor->getColumns(); for (unsigned int i = 0; i < newColumns.size(); ++i) { newColumns[i].setActiveNumber(i); } pLoadDescriptor->setColumns(newColumns); // Set the bands to load to just the first band and display it in grayscale mode const vector<DimensionDescriptor>& bands = pLoadDescriptor->getBands(); if (bands.empty() == false) { DimensionDescriptor displayBand = bands.front(); displayBand.setActiveNumber(0); vector<DimensionDescriptor> newBands; newBands.push_back(displayBand); pLoadDescriptor->setBands(newBands); pLoadDescriptor->setDisplayMode(GRAYSCALE_MODE); pLoadDescriptor->setDisplayBand(GRAY, displayBand); } // Set the processing location to load on-disk read-only pLoadDescriptor->setProcessingLocation(ON_DISK_READ_ONLY); // Do not georeference GeoreferenceDescriptor* pLoadGeorefDescriptor = pLoadDescriptor->getGeoreferenceDescriptor(); if (pLoadGeorefDescriptor != NULL) { pLoadGeorefDescriptor->setGeoreferenceOnImport(false); } // Validate the preview string errorMessage; bool bValidPreview = validate(pLoadDescriptor, vector<const DataDescriptor*>(), errorMessage); if (bValidPreview == false) { // Try an in-memory preview pLoadDescriptor->setProcessingLocation(IN_MEMORY); bValidPreview = validate(pLoadDescriptor, vector<const DataDescriptor*>(), errorMessage); } QWidget* pPreviewWidget = NULL; if (bValidPreview == true) { // Create the model element RasterElement* pRasterElement = static_cast<RasterElement*>(mpModel->createElement(pLoadDescriptor)); if (pRasterElement != NULL) { // Add the progress and raster element to an input arg list PlugInArgList* pInArgList = NULL; bool bSuccess = getInputSpecification(pInArgList); if ((bSuccess == true) && (pInArgList != NULL)) { bSuccess = pInArgList->setPlugInArgValue(Executable::ProgressArg(), pProgress); if (bSuccess) { bSuccess = pInArgList->setPlugInArgValue(Importer::ImportElementArg(), pRasterElement); } } // Load the data in batch mode bool bBatch = isBatch(); setBatch(); bSuccess = execute(pInArgList, NULL); // Restore to interactive mode if necessary if (bBatch == false) { setInteractive(); } // Create the spatial data view if (bSuccess == true) { string name = pRasterElement->getName(); SpatialDataView* pView = static_cast<SpatialDataView*>(mpDesktop->createView(name, SPATIAL_DATA_VIEW)); if (pView != NULL) { // Set the spatial data in the view pView->setPrimaryRasterElement(pRasterElement); // Add the cube layer RasterLayer* pLayer = static_cast<RasterLayer*>(pView->createLayer(RASTER, pRasterElement)); if (pLayer != NULL) { // Get the widget from the view pPreviewWidget = pView->getWidget(); } else { string message = "Could not create the cube layer!"; if (pProgress != NULL) { pProgress->updateProgress(message, 0, ERRORS); } mpModel->destroyElement(pRasterElement); } } else { string message = "Could not create the view!"; if (pProgress != NULL) { pProgress->updateProgress(message, 0, ERRORS); } mpModel->destroyElement(pRasterElement); } } else { mpModel->destroyElement(pRasterElement); } } } // Delete the data descriptor copy mpModel->destroyDataDescriptor(pLoadDescriptor); return pPreviewWidget; }
bool SignatureLibraryImp::import(const string &filename, const string &importerName, Progress* pProgress) { ImporterResource importer(importerName, filename, pProgress); vector<ImportDescriptor*> descs = importer->getImportDescriptors(); RasterDataDescriptor* pCubeDescriptor = NULL; if (descs.size() == 1 && descs.front() != NULL) { pCubeDescriptor = dynamic_cast<RasterDataDescriptor*>(descs.front()->getDataDescriptor()); } if (pCubeDescriptor != NULL) { // Disable auto-georeference GeoreferenceDescriptor* pGeorefDescriptor = pCubeDescriptor->getGeoreferenceDescriptor(); if (pGeorefDescriptor != NULL) { pGeorefDescriptor->setGeoreferenceOnImport(false); } pCubeDescriptor->setProcessingLocation(ON_DISK); bool cubeSuccess = importer->execute(); if (cubeSuccess) { vector<DataElement*> importedElements = importer->getImportedElements(); if (!importedElements.empty()) { RasterElement* pCube = dynamic_cast<RasterElement*>(importedElements.front()); Service<ModelServices>()->setElementParent(pCube, dynamic_cast<DataElement*>(this)); if (pCube != NULL) { clear(); mpOdre.reset(pCube); DynamicObject* pMetadata = getMetadata(); if (pMetadata != NULL) { string pCenterPath[] = { SPECIAL_METADATA_NAME, BAND_METADATA_NAME, CENTER_WAVELENGTHS_METADATA_NAME, END_METADATA_NAME }; mOriginalAbscissa = dv_cast<vector<double> >( pMetadata->getAttributeByPath(pCenterPath), vector<double>()); vector<string> sigNames = dv_cast<vector<string> >(pMetadata->getAttribute("Signature Names"), vector<string>()); SignatureLibrary* pLib = dynamic_cast<SignatureLibrary*>(this); VERIFY(pLib != NULL); unsigned int numSigs = pCubeDescriptor->getRowCount(); mSignatures.reserve(numSigs); for (unsigned int i = 0; i < numSigs; ++i) { string name; if (i >= sigNames.size()) { stringstream stream; stream << "Signature " << i+1; name = stream.str(); } else { name = sigNames[i]; } DataDescriptor* pDataDesc = Service<ModelServices>()->createDataDescriptor(name, "DataElement", pLib); DataDescriptorImp* pSigDesc = dynamic_cast<DataDescriptorImp*>(pDataDesc); mSignatures.push_back(new LibrarySignatureAdapter(*pSigDesc, SessionItemImp::generateUniqueId(), i, pLib)); mSignatureNames[name] = mSignatures.back(); } } notify(SIGNAL_NAME(Subject, Modified)); return true; } } } } return false; }