void PreviewWidget::updateCurrentDataset() { ChippingWidget* pChippingWidget = dynamic_cast<ChippingWidget*>(mpImporterWidget); if (pChippingWidget == NULL) { return; } ImportDescriptor* pActiveDataset = getCurrentDataset(); if (pActiveDataset != NULL) { RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pActiveDataset->getDataDescriptor()); if (pDescriptor != NULL) { // Rows vector<DimensionDescriptor> rows = pChippingWidget->getChipRows(); transform(rows.begin(), rows.end(), rows.begin(), UnsetActiveNumber()); pDescriptor->setRows(rows); // Columns vector<DimensionDescriptor> columns = pChippingWidget->getChipColumns(); transform(columns.begin(), columns.end(), columns.begin(), UnsetActiveNumber()); pDescriptor->setColumns(columns); // Bands -- ignore if the user deselected all bands vector<DimensionDescriptor> bands = pChippingWidget->getChipBands(); if (bands.empty() == false) { transform(bands.begin(), bands.end(), bands.begin(), UnsetActiveNumber()); pDescriptor->setBands(bands); } } } }
LocationType SampleGeoref::pixelToGeo(LocationType pixel, bool* pAccurate) const { LocationType geo; if (mRotate) { pixel = rotate(pixel, 2 * PI * mCurrentFrame/mFrames); geo.mX = pixel.mY * mXScale; geo.mY = pixel.mX * mYScale; } else { geo.mX = pixel.mY * mXScale; geo.mY = pixel.mX * mYScale + (mYSize * mCurrentFrame/mFrames); } // actual Georeference subclass will need to implement means to check for extrapolation // and to set pAccurate appropriately. if (pAccurate != NULL && mpRaster != NULL) { *pAccurate = false; RasterDataDescriptor* pDesc = dynamic_cast<RasterDataDescriptor*>(mpRaster->getDataDescriptor()); if (pDesc != NULL) { bool outsideCols = pixel.mX < 0.0 || pixel.mX > static_cast<double>(pDesc->getColumnCount()); bool outsideRows = pixel.mY < 0.0 || pixel.mY > static_cast<double>(pDesc->getRowCount()); bool locationExtrapolated = outsideCols || outsideRows; *pAccurate = (locationExtrapolated ? mExtrapolate : true); } } return geo; }
bool PropertiesWavelengths::initialize(SessionItem* pSessionItem) { WavelengthsWidget* pWavelengthsPage = dynamic_cast<WavelengthsWidget*>(getWidget()); if (pWavelengthsPage == NULL) { return false; } DataElement* pElement = dynamic_cast<DataElement*>(pSessionItem); if (pElement != NULL) { RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pElement->getDataDescriptor()); if (pDescriptor != NULL) { const DynamicObject* pMetadata = pElement->getMetadata(); if (pMetadata != NULL) { mWavelengths.initializeFromDynamicObject(pMetadata, true); pWavelengthsPage->setWavelengths(pDescriptor->getBands(), &mWavelengths); return PropertiesShell::initialize(pSessionItem); } } } return false; }
bool RasterElementImporterShell::copyData(const RasterElement* pSrcElement) const { VERIFY(pSrcElement != NULL && mpRasterElement != NULL); const RasterDataDescriptor* pSrcDescriptor = dynamic_cast<const RasterDataDescriptor*>( pSrcElement->getDataDescriptor()); RasterDataDescriptor* pChipDescriptor = dynamic_cast<RasterDataDescriptor*>( mpRasterElement->getDataDescriptor()); VERIFY(pSrcDescriptor != NULL && mpRasterElement != NULL); vector<DimensionDescriptor> selectedRows = getSelectedDims(pSrcDescriptor->getRows(), pChipDescriptor->getRows()); vector<DimensionDescriptor> selectedColumns = getSelectedDims(pSrcDescriptor->getColumns(), pChipDescriptor->getColumns()); vector<DimensionDescriptor> selectedBands = getSelectedDims(pSrcDescriptor->getBands(), pChipDescriptor->getBands()); bool success = true; Service<SessionManager> pSessionManager; if (pSessionManager->isSessionLoading() == false) { success = RasterUtilities::chipMetadata(mpRasterElement->getMetadata(), selectedRows, selectedColumns, selectedBands); } success = success && pSrcElement->copyDataToChip(mpRasterElement, selectedRows, selectedColumns, selectedBands, mAborted, mpProgress); return success; }
vector<ImportDescriptor*> Jpeg2000Importer::getImportDescriptors(const string& filename) { vector<ImportDescriptor*> descriptors; if (filename.empty() == true) { return descriptors; } vector<string>& warnings = msWarnings[filename]; warnings.clear(); vector<string>& errors = msErrors[filename]; errors.clear(); ImportDescriptor* pImportDescriptor = mpModel->createImportDescriptor(filename, "RasterElement", NULL); if (pImportDescriptor != NULL) { RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pImportDescriptor->getDataDescriptor()); if (pDescriptor != NULL) { vector<EncodingType> validDataTypes; validDataTypes.push_back(INT1UBYTE); validDataTypes.push_back(INT1SBYTE); validDataTypes.push_back(INT2UBYTES); validDataTypes.push_back(INT2SBYTES); validDataTypes.push_back(INT4UBYTES); validDataTypes.push_back(INT4SBYTES); validDataTypes.push_back(FLT4BYTES); pDescriptor->setValidDataTypes(validDataTypes); pDescriptor->setProcessingLocation(IN_MEMORY); // Create and set a file descriptor in the data descriptor FactoryResource<RasterFileDescriptor> pFileDescriptor; pFileDescriptor->setEndian(BIG_ENDIAN_ORDER); if (pFileDescriptor.get() != NULL) { pFileDescriptor->setFilename(filename); pDescriptor->setFileDescriptor(pFileDescriptor.get()); } // Populate the data descriptor from the file bool bSuccess = populateDataDescriptor(pDescriptor); if (bSuccess == true) { descriptors.push_back(pImportDescriptor); } else { // Delete the import descriptor mpModel->destroyImportDescriptor(pImportDescriptor); } } } return descriptors; }
bool bilinear_bayer::copyImage(RasterElement * pRaster, RasterElement * dRaster, int i, Progress * pProgress) { VERIFY(pRaster != NULL); RasterDataDescriptor *pDesc = dynamic_cast < RasterDataDescriptor * >(pRaster->getDataDescriptor()); VERIFY(dRaster != NULL); RasterDataDescriptor *rDesc = dynamic_cast < RasterDataDescriptor * >(dRaster->getDataDescriptor()); DimensionDescriptor thirdBand = pDesc->getActiveBand(i); // get active // band // source FactoryResource < DataRequest > pRequest; pRequest->setInterleaveFormat(BSQ); pRequest->setBands(thirdBand, thirdBand); DataAccessor thirdBandDa = pRaster->getDataAccessor(pRequest.release()); thirdBand = rDesc->getActiveBand(i); // destination FactoryResource < DataRequest > pResultRequest; pResultRequest->setWritable(true); pRequest->setInterleaveFormat(BSQ); pResultRequest->setBands(thirdBand, thirdBand); DataAccessor pDestAcc = dRaster->getDataAccessor(pResultRequest.release()); VERIFY(thirdBandDa.isValid()); VERIFY(pDestAcc.isValid()); for (unsigned int curRow = 0; curRow < pDesc->getRowCount(); ++curRow) { for (unsigned int curCol = 0; curCol < pDesc->getColumnCount(); ++curCol) { switchOnEncoding(pDesc->getDataType(), bilinear, pDestAcc->getColumn(), thirdBandDa, curRow, curCol, pDesc->getRowCount(), pDesc->getColumnCount(), i, pRaster); pDestAcc->nextColumn(); } pDestAcc->nextRow(); } return true; }
bool LandsatEtmPlusImporter::createRasterPager(RasterElement* pRaster) const { string srcFile = pRaster->getFilename(); if (srcFile.empty()) { return false; } { //scoping to ensure the file is closed before creating the pager LargeFileResource srcFileRes; if (!srcFileRes.open(srcFile, O_RDONLY | O_BINARY, S_IREAD)) { return false; } } // create the pager ExecutableResource pPager("BandResamplePager"); VERIFY(pPager->getPlugIn() != NULL); bool isWritable = false; bool useDataDescriptor = false; FactoryResource<Filename> pFilename; VERIFY(pFilename.get() != NULL); pFilename->setFullPathAndName(pRaster->getFilename()); pPager->getInArgList().setPlugInArgValue("Raster Element", pRaster); pPager->getInArgList().setPlugInArgValue("Filename", pFilename.get()); pPager->getInArgList().setPlugInArgValue("isWritable", &isWritable); pPager->getInArgList().setPlugInArgValue("Use Data Descriptor", &useDataDescriptor); RasterDataDescriptor* pDescriptor = static_cast<RasterDataDescriptor*>(pRaster->getDataDescriptor()); VERIFY(pDescriptor != NULL); RasterFileDescriptor* pFileDescriptor = static_cast<RasterFileDescriptor*>(pDescriptor->getFileDescriptor()); VERIFY(pFileDescriptor != NULL); unsigned int band = 5, rows = mB6Rows, cols = mB6Cols; pPager->getInArgList().setPlugInArgValue("Band", &band); pPager->getInArgList().setPlugInArgValue("Rows", &rows); pPager->getInArgList().setPlugInArgValue("Columns", &cols); if (!pPager->execute()) { return false; } RasterPager* pRasterPager = dynamic_cast<RasterPager*>(pPager->getPlugIn()); if (pRasterPager != NULL) { pPager->releasePlugIn(); } else { return false; } pRaster->setPager(pRasterPager); return true; }
RasterElement* AceAlgorithm::createResults(int numRows, int numColumns, const string& sigName) { RasterElement* pElement = getRasterElement(); if (pElement == NULL) { return NULL; } // Delete an existing element to ensure that the new results element is the correct size Service<ModelServices> pModel; RasterElement* pExistingResults = static_cast<RasterElement*>(pModel->getElement(sigName, TypeConverter::toString<RasterElement>(), pElement)); if (pExistingResults != NULL) { pModel->destroyElement(pExistingResults); } // Create the new results element ModelResource<RasterElement> pResults(RasterUtilities::createRasterElement(sigName, numRows, numColumns, FLT4BYTES, true, pElement)); if (pResults.get() == NULL) { pResults = ModelResource<RasterElement>(RasterUtilities::createRasterElement(sigName, numRows, numColumns, FLT4BYTES, false, pElement)); if (pResults.get() == NULL) { reportProgress(ERRORS, 0, ACEERR009); MessageResource(ACEERR009, "spectral", "C89D361B-DB12-43ED-B276-6D98CA3539EE"); return NULL; } } FactoryResource<Units> pUnits; pUnits->setUnitName("degrees"); vector<int> badValues(1, 181); RasterDataDescriptor* pResultsDescriptor = static_cast<RasterDataDescriptor*>(pResults->getDataDescriptor()); VERIFYRV(pResultsDescriptor != NULL, NULL); pResultsDescriptor->setUnits(pUnits.get()); pResultsDescriptor->setBadValues(badValues); Statistics* pStatistics = pResults->getStatistics(); VERIFYRV(pStatistics != NULL, NULL); pStatistics->setBadValues(badValues); return pResults.release(); }
DataAccessor BackgroundSuppressionShell::getCurrentFrameAccessor() const { if(mpRaster == NULL) { return DataAccessor(NULL, NULL); } RasterDataDescriptor *pDesc = static_cast<RasterDataDescriptor*>(mpRaster->getDataDescriptor()); VERIFYRV(pDesc != NULL, DataAccessor(NULL, NULL)); FactoryResource<DataRequest> request; VERIFYRV(request.get() != NULL, DataAccessor(NULL, NULL)); request->setInterleaveFormat(BSQ); DimensionDescriptor band = pDesc->getBands()[mCurrentFrame]; request->setBands(band, band, 1); return mpRaster->getDataAccessor(request.release()); }
bool BackgroundSuppressionShell::boxFilter(int size, BackgroundSuppressionShell::WrapTypeEnum wrap) { if(size <= 1 || size > 9 || size % 2 == 0) { return false; } if(mpTemporaryBuffer.get() == NULL) { return false; } RasterDataDescriptor *pDesc = static_cast<RasterDataDescriptor*>(mpRaster->getDataDescriptor()); switchOnEncoding(pDesc->getDataType(), performBoxFilter, mpTemporaryBuffer.get(), static_cast<int>(pDesc->getRowCount()), static_cast<int>(pDesc->getColumnCount()), static_cast<int>((size - 1) / 2), wrap); return true; }
DataAccessorImpl* createDataAccessor(DataElement* pElement, DataAccessorArgs* pArgs) { RasterElement* pRasterElement = dynamic_cast<RasterElement*>(pElement); if (pRasterElement == NULL) { setLastError(SIMPLE_BAD_PARAMS); return NULL; } FactoryResource<DataRequest> pRequest; RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pRasterElement->getDataDescriptor()); if (pArgs != NULL) { pRequest->setRows(pDescriptor->getActiveRow(pArgs->rowStart), pDescriptor->getActiveRow(pArgs->rowEnd),pArgs->concurrentRows); pRequest->setColumns(pDescriptor->getActiveColumn(pArgs->columnStart), pDescriptor->getActiveColumn(pArgs->columnEnd),pArgs->concurrentColumns); pRequest->setBands(pDescriptor->getActiveBand(pArgs->bandStart), pDescriptor->getActiveBand(pArgs->bandEnd),pArgs->concurrentBands); pRequest->setInterleaveFormat(static_cast<InterleaveFormatTypeEnum>(pArgs->interleaveFormat)); pRequest->setWritable(pArgs->writable != 0); } DataAccessor dataAccessor(pRasterElement->getDataAccessor(pRequest.release())); if (!dataAccessor.isValid()) { setLastError(SIMPLE_BAD_PARAMS); return NULL; } DataAccessorImpl* pRval = dataAccessor.operator->(); pRval->incrementRefCount(); setLastError(SIMPLE_NO_ERROR); return pRval; }
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 BackgroundSuppressionShell::preprocess() { if(mpRaster == NULL) { return false; } RasterDataDescriptor *pDesc = static_cast<RasterDataDescriptor*>(mpRaster->getDataDescriptor()); if(mpTemporaryBuffer.get() == NULL) { mpTemporaryBuffer.reset(new char[pDesc->getRowCount() * pDesc->getColumnCount() * pDesc->getBytesPerElement()]); if(mpTemporaryBuffer.get() == NULL) { return false; } } DataAccessor frameAccessor = getCurrentFrameAccessor(); size_t rowSize = pDesc->getColumnCount() * pDesc->getBytesPerElement(); for(unsigned int row = 0; row < pDesc->getRowCount(); row++) { if(!frameAccessor.isValid()) { return false; } memcpy(mpTemporaryBuffer.get() + row * rowSize, frameAccessor->getRow(), rowSize); frameAccessor->nextColumn(); } return true; }
DataAccessor getAccessor(int band, bool writable = false) { FactoryResource<DataRequest> pRequest = FactoryResource<DataRequest>(); pRequest->setRows(pDataDescriptor->getActiveRow(0), pDataDescriptor->getActiveRow(getRowCount() - 1)); pRequest->setColumns(pDataDescriptor->getActiveColumn(0), pDataDescriptor->getActiveColumn(getColumnCount() - 1)); pRequest->setBands(pDataDescriptor->getActiveBand(band), pDataDescriptor->getActiveBand(band)); pRequest->setWritable(writable); return pRaster->getDataAccessor(pRequest.release()); }
LocationType SampleGeoref::geoToPixel(LocationType geo, bool* pAccurate) const { LocationType pixel; pixel.mX = geo.mY / mYScale; pixel.mY = geo.mX / mXScale; // actual Georeference subclass will need to implement means to check for extrapolation // and to set pAccurate appropriately. if (pAccurate != NULL && mpRaster != NULL) { *pAccurate = false; RasterDataDescriptor* pDesc = dynamic_cast<RasterDataDescriptor*>(mpRaster->getDataDescriptor()); if (pDesc != NULL) { bool outsideCols = pixel.mX < 0.0 || pixel.mX > static_cast<double>(pDesc->getColumnCount()); bool outsideRows = pixel.mY < 0.0 || pixel.mY > static_cast<double>(pDesc->getRowCount()); bool locationExtrapolated = outsideCols || outsideRows; *pAccurate = (locationExtrapolated ? mExtrapolate : true); } } return pixel; }
DataInfo* createDataInfo(DataElement* pElement) { RasterElement* pRasterElement = dynamic_cast<RasterElement*>(pElement); if (pRasterElement == NULL) { setLastError(SIMPLE_BAD_PARAMS); return NULL; } RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pRasterElement->getDataDescriptor()); if (pDescriptor == NULL) { setLastError(SIMPLE_OTHER_FAILURE); return NULL; } DataInfo* pDataInfo = new DataInfo; pDataInfo->numRows = pDescriptor->getRowCount(); pDataInfo->numColumns = pDescriptor->getColumnCount(); pDataInfo->numBands = pDescriptor->getBandCount(); pDataInfo->encodingType = static_cast<uint32_t>(pDescriptor->getDataType()); pDataInfo->encodingTypeSize = RasterUtilities::bytesInEncoding(pDescriptor->getDataType()); pDataInfo->interleaveFormat = static_cast<uint32_t>(pDescriptor->getInterleaveFormat()); const std::vector<int>& badValues = pDescriptor->getBadValues(); pDataInfo->numBadValues = badValues.size(); if (pDataInfo->numBadValues == 0) { pDataInfo->pBadValues = NULL; } else { pDataInfo->pBadValues = new int32_t[pDataInfo->numBadValues]; memcpy(pDataInfo->pBadValues, &badValues[0], pDataInfo->numBadValues * sizeof(int32_t)); } setLastError(SIMPLE_NO_ERROR); return pDataInfo; }
DataElement* createRasterElement(const char* pName, RasterElementArgs args) { if (pName == NULL || args.location > 2) { setLastError(SIMPLE_BAD_PARAMS); return NULL; } // Check for an existing element with the name if (getDataElement(pName, TypeConverter::toString<RasterElement>(), 0) != NULL) { setLastError(SIMPLE_EXISTS); return NULL; } RasterElement* pElement = RasterUtilities::createRasterElement(std::string(pName), args.numRows, args.numColumns, args.numBands, static_cast<EncodingTypeEnum>(args.encodingType), static_cast<InterleaveFormatTypeEnum>(args.interleaveFormat), args.location != 2, args.pParent); if (pElement == NULL) { switch (args.location) { case 0: pElement = RasterUtilities::createRasterElement(std::string(pName), args.numRows, args.numColumns, args.numBands, static_cast<EncodingTypeEnum>(args.encodingType), static_cast<InterleaveFormatTypeEnum>(args.interleaveFormat), false, args.pParent); if (pElement == NULL) { setLastError(SIMPLE_OTHER_FAILURE); return NULL; } break; case 1: setLastError(SIMPLE_NO_MEM); return NULL; case 2: setLastError(SIMPLE_OTHER_FAILURE); return NULL; default: setLastError(SIMPLE_BAD_PARAMS); return NULL; } } if (args.pBadValues != NULL && args.numBadValues > 0) { RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pElement->getDataDescriptor()); if (pDesc != NULL) { std::vector<int> badValues; badValues.reserve(args.numBadValues); for (uint32_t idx = 0; idx < args.numBadValues; ++idx) { badValues.push_back(args.pBadValues[idx]); } pDesc->setBadValues(badValues); // set on the statistics objects const std::vector<DimensionDescriptor>& allBands = pDesc->getBands(); for (std::vector<DimensionDescriptor>::const_iterator band = allBands.begin(); band != allBands.end(); ++band) { if (band->isValid()) { Statistics* pStats = pElement->getStatistics(*band); if (pStats != NULL) { pStats->setBadValues(badValues); } } } pElement->updateData(); } } setLastError(SIMPLE_NO_ERROR); return pElement; }
bool ResultsExporter::runAllTests(Progress *pProgress, ostream& failure) { bool success = true; mpProgress = pProgress; mpResults = RasterUtilities::createRasterElement("ResultsExporterTestMatrix", 2, 2, FLT4BYTES, true, NULL); if (mpResults == NULL) { failure << "Unable to create a Raster Element."; success = false; } else { ModelResource<RasterElement> pResultsResource(mpResults); RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(mpResults->getDataDescriptor()); if (pDescriptor == NULL) { failure << "Unable to get the Raster Data Descriptor."; success = false; } else { // Bad values std::vector<int> badValues; badValues.push_back(2); badValues.push_back(4); pDescriptor->setBadValues(badValues); // Create the element FactoryResource<DataRequest> pRequest; pRequest->setWritable(true); DataAccessor da = mpResults->getDataAccessor(pRequest.release()); if (da.isValid() == false) { failure << "Data Accessor is not valid."; success = false; } else { float* pData = reinterpret_cast<float*>(da->getRow()); if (pData == NULL) { failure << "Data is not accessible."; success = false; } else { pData[0] = 1.0; pData[1] = 2.0; pData[2] = 3.0; pData[3] = 4.0; mFirstThreshold = 1.5; mSecondThreshold = 4.5; mPassArea = MIDDLE; mGeocoordType = GEOCOORD_LATLON; mbMetadata = false; mbAppendFile = false; const Filename* pTempPath = ConfigurationSettings::getSettingTempPath(); if (pTempPath == NULL) { failure << "Unable to get the temporary path from ConfigurationSettings."; success = false; } else { const string filename = pTempPath->getFullPathAndName() + "/ResultsExporterTest.rls"; mpFileDescriptor = dynamic_cast<RasterFileDescriptor*> (RasterUtilities::generateFileDescriptorForExport(pDescriptor, filename)); if (mpFileDescriptor == NULL) { failure << "Unable to generate a Raster File Descriptor for export."; success = false; } else { FactoryResource<RasterFileDescriptor> pFileDescriptor(mpFileDescriptor); stringstream stream; writeOutput(stream); if (stream.str() != "ResultsExporterTestMatrix Pixel: (1, 2) 3.000000\n\n") { failure << "Invalid output stream."; success = false; } } } } } } } mpResults = NULL; mpProgress = NULL; mpFileDescriptor = NULL; return success; }
bool HIGHPASS::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Tutorial 5", "app", "219F1882-A59F-4835-BE2A-E83C0C8111EB"); if (pInArgList == NULL || pOutArgList == NULL) { return false; } Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); RasterElement* pCube = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); if (pCube == NULL) { std::string msg = "A raster cube must be specified."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pCube->getDataDescriptor()); VERIFY(pDesc != NULL); FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BSQ); DataAccessor pSrcAcc = pCube->getDataAccessor(pRequest.release()); ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(pCube->getName() + "DResult", pDesc->getRowCount(), pDesc->getColumnCount(), pDesc->getDataType())); if (pResultCube.get() == NULL) { std::string msg = "A raster cube could not be created."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } FactoryResource<DataRequest> pResultRequest; pResultRequest->setWritable(true); DataAccessor pDestAcc = pResultCube->getDataAccessor(pResultRequest.release()); int rowSize= pDesc->getRowCount(); int colSize = pDesc->getColumnCount(); int zero=0; int prevCol = 0; int prevRow = 0; int nextCol = 0; int nextRow = 0; int prevCol1 = 0; int prevRow1= 0; int nextCol1= 0; int nextRow1= 0; for (unsigned int row = 0; row < pDesc->getRowCount(); ++row) { if (pProgress != NULL) { pProgress->updateProgress("Calculating result", row * 100 / pDesc->getRowCount(), NORMAL); } if (isAborted()) { std::string msg = getName() + " has been aborted."; pStep->finalize(Message::Abort, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ABORT); } return false; } if (!pDestAcc.isValid()) { std::string msg = "Unable to access the cube data."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } for (unsigned int col = 0; col < pDesc->getColumnCount(); ++col) { double value=edgeDetection7(pSrcAcc, row, col, pDesc->getRowCount(), pDesc->getColumnCount()); switchOnEncoding(pDesc->getDataType(), conversion, pDestAcc->getColumn(), value); pDestAcc->nextColumn(); } pDestAcc->nextRow(); } if (!isBatch()) { Service<DesktopServices> pDesktop; SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(pDesktop->createWindow(pResultCube->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { std::string msg = "Unable to create view."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pView->setPrimaryRasterElement(pResultCube.get()); pView->createLayer(RASTER, pResultCube.get()); } if (pProgress != NULL) { pProgress->updateProgress("HighPass is compete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("Result", pResultCube.release()); pStep->finalize(); return true; }
bool ResultsExporter::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Execute results exporter", "app", "ABF9EDE4-4672-4361-86BB-3258ADFB0793"); mpStep = pStep.get(); if (!extractInputArgs(pInArgList)) { return false; } // Check for complex data RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(mpResults->getDataDescriptor()); if (pDescriptor == NULL) { mMessage = "Could not get the data descriptor from the results matrix!"; if (mpProgress != NULL) { mpProgress->updateProgress(mMessage, 0, ERRORS); } pStep->finalize(Message::Failure, mMessage); return false; } EncodingType eDataType = pDescriptor->getDataType(); if ((eDataType == INT4SCOMPLEX) || (eDataType == FLT8COMPLEX)) { mMessage = "Cannot save complex data in text format!"; if (mpProgress != NULL) { mpProgress->updateProgress(mMessage, 0, ERRORS); } pStep->finalize(Message::Failure, mMessage); return false; } if (pDescriptor->getBandCount() > 1) { mMessage = "Can only export single band data."; if (mpProgress != NULL) { mpProgress->updateProgress(mMessage, 0, ERRORS); } pStep->finalize(Message::Failure, mMessage); return false; } pDescriptor->addToMessageLog(pStep.get()); const string& filename = mpFileDescriptor->getFilename(); pStep->addProperty("filename", filename); pStep->addProperty("firstThreshold", mFirstThreshold); pStep->addProperty("secondThreshold", mSecondThreshold); pStep->addProperty("passArea", mPassArea); pStep->addProperty("geocoordType", mGeocoordType); pStep->addProperty("metadata", mbMetadata); pStep->addProperty("appendFile", mbAppendFile); DataElement* pParent = mpResults->getParent(); if (pParent != NULL) { pStep->addProperty("sourceDataSet", pParent->getName()); } ofstream fileOutput; fileOutput.open(filename.c_str(), mbAppendFile ? ios_base::app : ios_base::trunc); if (!fileOutput.is_open()) { mMessage = "Could not open the output file for writing!"; if (mpProgress != NULL) { mpProgress->updateProgress(mMessage, 0, ERRORS); } pStep->finalize(Message::Failure, mMessage); return false; } if (!writeOutput(fileOutput)) { if (mbAbort) { pStep->finalize(Message::Abort); } fileOutput.close(); remove(filename.c_str()); } mMessage = "Results matrix export complete!"; if (mpProgress != NULL) { mpProgress->updateProgress(mMessage, 100, NORMAL); } pStep->finalize(Message::Success); return true; }
bool ResultsExporter::writeOutput(ostream &stream) { mMessage = "Exporting results matrix..."; if (mpProgress != NULL) { mpProgress->updateProgress(mMessage, 0, NORMAL); } StepResource pStep(mMessage, "app", "D890E37C-B960-4527-8AAC-D62F2DE7A541"); RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(mpResults->getDataDescriptor()); if (pDescriptor == NULL) { mMessage = "Could not get the results data descriptor!"; if (mpProgress != NULL) { mpProgress->updateProgress(mMessage, 0, ERRORS); } pStep->finalize(Message::Failure); return false; } VERIFY(mpResults != NULL); string name = mpResults->getName(); VERIFY(mpFileDescriptor != NULL); const vector<DimensionDescriptor>& rows = mpFileDescriptor->getRows(); const vector<DimensionDescriptor>& columns = mpFileDescriptor->getColumns(); unsigned int numRows = pDescriptor->getRowCount(); unsigned int numColumns = pDescriptor->getColumnCount(); EncodingType eDataType = pDescriptor->getDataType(); const vector<int>& badValues = pDescriptor->getBadValues(); if (mbMetadata) { stream << APP_NAME << " Results Raster\n"; stream << "Version = 4\n"; stream << "Results Name = " << name << "\n"; DataElement* pParent = mpResults->getParent(); if (pParent != NULL) { stream << "Data Set Name = " << pParent->getName() << "\n"; } stream << "Rows = " << numRows << "\n"; stream << "Columns = " << numColumns << "\n"; string dataType = StringUtilities::toDisplayString(eDataType); stream << "Data Type = " << dataType << "\n"; Statistics* pStatistics = mpResults->getStatistics(); if (pStatistics != NULL) { stream << "Min = " << pStatistics->getMin() << "\n"; stream << "Max = " << pStatistics->getMax() << "\n"; stream << "Average = " << pStatistics->getAverage() << "\n"; stream << "Standard Deviation = " << pStatistics->getStandardDeviation() << "\n\n"; } } RasterElement* pGeo = getGeoreferencedRaster(); DataAccessor da = mpResults->getDataAccessor(); if (!da.isValid()) { mMessage = "Could not access the data in the results raster!"; if (mpProgress != NULL) { mpProgress->updateProgress(mMessage, 0, ERRORS); } pStep->finalize(Message::Failure); return false; } unsigned int activeRowNumber = 0; for (unsigned int r = 0; r < rows.size(); ++r) { if (mbAbort) { mMessage = "Results exporter aborted!"; if (mpProgress != NULL) { mpProgress->updateProgress(mMessage, 0, ABORT); } pStep->finalize(Message::Abort); return false; } DimensionDescriptor rowDim = rows[r]; // Skip to the next row for (; activeRowNumber < rowDim.getActiveNumber(); ++activeRowNumber) { da->nextRow(); } unsigned int activeColumnNumber = 0; for (unsigned int c = 0; c < columns.size(); ++c) { DimensionDescriptor columnDim = columns[c]; // Skip to the next column for (; activeColumnNumber < columnDim.getActiveNumber(); ++activeColumnNumber) { da->nextColumn(); } VERIFY(da.isValid()); double dValue = ModelServices::getDataValue(eDataType, da->getColumn(), COMPLEX_MAGNITUDE, 0); if (isValueExported(dValue, badValues)) { string location = getLocationString(r, c, pGeo); char buffer[1024]; sprintf(buffer, "%lf\n", dValue); stream << name << " " << location << " " << buffer; } } // Update the progress int iProgress = (r * 100) / rows.size(); if (iProgress == 100) { iProgress = 99; } if (mpProgress != NULL) { mpProgress->updateProgress(mMessage, iProgress, NORMAL); } } stream << "\n"; return true; }
bool EdgeDetector::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Edge Detector", "app", "37C57772-DD49-4532-8BC6-9CFB8587D0C9"); if (pInArgList == NULL || pOutArgList == NULL) { return false; } Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); RasterElement* pCube = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); if (pCube == NULL) { std::string msg = "A raster cube must be specified."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pCube->getDataDescriptor()); VERIFY(pDesc != NULL); EncodingType ResultType = INT1UBYTE; FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BSQ); DataAccessor pSrcAcc = pCube->getDataAccessor(pRequest.release()); ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(pCube->getName() + "_Edge_Detect_Result", pDesc->getRowCount(), pDesc->getColumnCount(), ResultType)); if (pResultCube.get() == NULL) { std::string msg = "A raster cube could not be created."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } FactoryResource<DataRequest> pResultRequest; pResultRequest->setWritable(true); DataAccessor pDestAcc = pResultCube->getDataAccessor(pResultRequest.release()); Service<DesktopServices> pDesktop; EdgeRatioThresholdDlg dlg(pDesktop->getMainWidget(), SMALL_WINDOW_THRESHOLD, MEDIAN_WINDOW_THRESHOLD, LARGE_WINDOW_THRESHOLD); int stat = dlg.exec(); if (stat == QDialog::Accepted) { for (unsigned int row = 0; row < pDesc->getRowCount(); ++row) { if (pProgress != NULL) { pProgress->updateProgress("Edge detect ", row * 100 / pDesc->getRowCount(), NORMAL); } if (isAborted()) { std::string msg = getName() + " has been aborted."; pStep->finalize(Message::Abort, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ABORT); } return false; } if (!pDestAcc.isValid()) { std::string msg = "Unable to access the cube data."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } for (unsigned int col = 0; col < pDesc->getColumnCount(); ++col) { switchOnEncoding(ResultType, EdgeDetectSAR, pDestAcc->getColumn(), pSrcAcc, row, col, pDesc->getRowCount(), pDesc->getColumnCount(), pDesc->getDataType(), dlg.getSmallThreshold(), dlg.getMedianThreshold(), dlg.getLargeThreshold()); pDestAcc->nextColumn(); } pDestAcc->nextRow(); } if (!isBatch()) { //Service<DesktopServices> pDesktop; SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(pDesktop->createWindow(pResultCube->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { std::string msg = "Unable to create view."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pView->setPrimaryRasterElement(pResultCube.get()); pView->createLayer(RASTER, pResultCube.get()); } if (pProgress != NULL) { pProgress->updateProgress("Edge detect compete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("Edge detect result", pResultCube.release()); pStep->finalize(); } return true; }
bool RasterTimingTest::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { if (isBatch()) { VERIFY(pOutArgList != NULL); } Service<DesktopServices> pDesktop; SpatialDataView* pView = dynamic_cast<SpatialDataView*>(pDesktop->getCurrentWorkspaceWindowView()); if (pView) { UndoLock lock(pView); RasterElement* pElement = pView->getLayerList()->getPrimaryRasterElement(); RasterDataDescriptor* pDesc = dynamic_cast<RasterDataDescriptor*>(pElement->getDataDescriptor()); int bands = pDesc->getBandCount(); int frameNumber = 0; RasterLayer* pLayer = NULL; vector<Layer*> layers; pView->getLayerList()->getLayers(RASTER, layers); for (vector<Layer*>::iterator iter = layers.begin(); iter != layers.end(); ++iter) { RasterLayer* pRasterLayer = static_cast<RasterLayer*>(*iter); if (pRasterLayer != NULL) { RasterElement* pCurrentRasterElement = dynamic_cast<RasterElement*>(pRasterLayer->getDataElement()); if (pCurrentRasterElement == pElement) { pLayer = pRasterLayer; break; } } } for (int i = 0; i < bands; ++i) { pElement->getStatistics(pDesc->getActiveBand(i))->getMin(); } // set grayscale display mode DisplayMode initialDisplayMode = pLayer->getDisplayMode(); pLayer->setDisplayMode(GRAYSCALE_MODE); const int frameiterations = 10000; clock_t startTime = clock(); QWidget* pWidget = pView->getWidget(); int i = 0; for (i = 0; i < frameiterations; ++i, ++frameNumber) { if (frameNumber >= bands) { frameNumber = 0; } pLayer->setDisplayedBand(GRAY, pDesc->getActiveBand(frameNumber)); if (pWidget) { pWidget->repaint(); } if ((i + 1) % (frameiterations / 100) == 0) { QString message = QString("Frame ") + QString::number(i+1) + QString(" of ") + QString::number(frameiterations); pDesktop->setStatusBarMessage(message.toStdString()); } if ((i + 1) % 20 == 0) { clock_t stopTime = clock(); double elapsedTime = static_cast<double>(stopTime - startTime) / CLOCKS_PER_SEC; if (elapsedTime > 30) { ++i; break; } } } clock_t stopTime = clock(); double framesPerSec = i / (static_cast<double>(stopTime - startTime) / CLOCKS_PER_SEC); // restore display mode pLayer->setDisplayMode(initialDisplayMode); if (isBatch()) { pOutArgList->setPlugInArgValue<double>("Framerate", &framesPerSec); } else { QMessageBox::information(pDesktop->getMainWidget(), "Frame Rate", QString("The number of frames per second was: %1\nGPU Acceleration was%2 enabled\n").arg(framesPerSec) .arg(pLayer->isGpuImageEnabled() ? "" : " not")); } return true; } return false; }
bool bilinear_bayer::execute(PlugInArgList * pInArgList, PlugInArgList * pOutArgList) { StepResource pStep("bilinear_bayer", "pratik", "27170298-10CE-4E6C-AD7A-97E8058C29FF"); if (pInArgList == NULL || pOutArgList == NULL) { return false; } Progress *pProgress = pInArgList->getPlugInArgValue < Progress > (Executable::ProgressArg()); RasterElement *pCube = pInArgList->getPlugInArgValue < RasterElement > (Executable::DataElementArg()); // pCube if (pCube == NULL) { std::string msg = "A raster cube must be specified."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pProgress->updateProgress("Starting calculations", 10, NORMAL); RasterDataDescriptor *pDesc = static_cast < RasterDataDescriptor * >(pCube->getDataDescriptor()); VERIFY(pDesc != NULL); std::string msg = "De-bayerize by bilinear interpolation \n"; pProgress->updateProgress(msg, 20, NORMAL); // show initial R,G and B // values RasterElement *dRas = RasterUtilities::createRasterElement(pCube->getName() + "RGB", pDesc->getRowCount(), pDesc->getColumnCount(), 3, pDesc->getDataType(), BSQ); // request pProgress->updateProgress(msg, 50, NORMAL); copyImage(pCube, dRas, 0, pProgress); pProgress->updateProgress(msg + "RED complete", 60, NORMAL); copyImage(pCube, dRas, 1, pProgress); pProgress->updateProgress(msg + "GREEN complete", 70, NORMAL); copyImage(pCube, dRas, 2, pProgress); pProgress->updateProgress(msg + "BLUE complete", 80, NORMAL); // new model resource RasterDataDescriptor *rDesc = dynamic_cast < RasterDataDescriptor * >(dRas->getDataDescriptor()); rDesc->setDisplayMode(RGB_MODE); // enable color mode rDesc->setDisplayBand(RED, rDesc->getActiveBand(0)); rDesc->setDisplayBand(GREEN, rDesc->getActiveBand(1)); rDesc->setDisplayBand(BLUE, rDesc->getActiveBand(2)); ModelResource < RasterElement > pResultCube(dRas); pProgress->updateProgress("Final", 100, NORMAL); // create window if (!isBatch()) { Service < DesktopServices > pDesktop; SpatialDataWindow *pWindow = static_cast < SpatialDataWindow * >(pDesktop->createWindow(pResultCube->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView *pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { std::string msg = "Unable to create view."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pView->setPrimaryRasterElement(pResultCube.get()); pView->createLayer(RASTER, pResultCube.get()); } pOutArgList->setPlugInArgValue("bilinear_bayer_Result", pResultCube.release()); // for // saving // data pStep->finalize(); return true; }
std::vector<ImportDescriptor*> VideoImporter::getImportDescriptors(const std::string &filename) { std::vector<ImportDescriptor*> descriptors; AVFormatResource pFormatCtx; { // scope AVFormatContext* pTmp = NULL; if (av_open_input_file(&pTmp, filename.c_str(), NULL, 0, NULL) != 0) { return descriptors; } pFormatCtx.reset(pTmp); } if (av_find_stream_info(pFormatCtx) < 0) { return descriptors; } for(int streamId = 0; streamId < pFormatCtx->nb_streams; streamId++) { if(pFormatCtx->streams[streamId]->codec->codec_type == CODEC_TYPE_VIDEO) { AVCodecContext* pCodecCtx = pFormatCtx->streams[streamId]->codec; AVCodec *pCodec = avcodec_find_decoder(pCodecCtx->codec_id); VERIFYRV(pCodec != NULL, descriptors); if(pCodec->capabilities & CODEC_CAP_TRUNCATED) { pCodecCtx->flags |= CODEC_FLAG_TRUNCATED; } if(avcodec_open(pCodecCtx, pCodec) < 0) { return descriptors; } ImportDescriptorResource pStreamDescriptor(filename, "VideoStream"); VERIFYRV(pStreamDescriptor.get() != NULL, descriptors); pStreamDescriptor->getDataDescriptor()->setProcessingLocation(ON_DISK_READ_ONLY); RasterUtilities::generateAndSetFileDescriptor(pStreamDescriptor->getDataDescriptor(), filename, StringUtilities::toDisplayString(streamId), LITTLE_ENDIAN); std::string rasterName = filename + QString(":%1").arg(streamId).toStdString(); ImportDescriptorResource pRasterDescriptor(rasterName, TypeConverter::toString<RasterElement>(), std::vector<std::string>(1, filename)); VERIFYRV(pRasterDescriptor.get() != NULL, descriptors); RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pRasterDescriptor->getDataDescriptor()); std::vector<DimensionDescriptor> rowDims = RasterUtilities::generateDimensionVector(pCodecCtx->height); pDesc->setRows(rowDims); std::vector<DimensionDescriptor> colDims = RasterUtilities::generateDimensionVector(pCodecCtx->width); pDesc->setColumns(colDims); std::vector<DimensionDescriptor> bandDims = RasterUtilities::generateDimensionVector(3); pDesc->setBands(bandDims); pDesc->setInterleaveFormat(BIP); pDesc->setDataType(INT1UBYTE); pDesc->setProcessingLocation(IN_MEMORY); pDesc->setDisplayMode(RGB_MODE); pDesc->setDisplayBand(RED, pDesc->getActiveBand(0)); pDesc->setDisplayBand(GREEN, pDesc->getActiveBand(1)); pDesc->setDisplayBand(BLUE, pDesc->getActiveBand(2)); RasterUtilities::generateAndSetFileDescriptor(pDesc, filename, StringUtilities::toDisplayString(streamId), LITTLE_ENDIAN); descriptors.push_back(pStreamDescriptor.release()); descriptors.push_back(pRasterDescriptor.release()); } } return descriptors; }
bool BackgroundSuppressionShell::execute(PlugInArgList *pInArgList, PlugInArgList *pOutArgList) { if(pInArgList == NULL) { return false; } mProgress = ProgressTracker(pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()), "Suppressing background", "temporal", "{01F54B12-0323-4ac4-8C04-C89F1C45EAD9}"); mpRaster = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); if(mpRaster == NULL) { mProgress.report("No raster element specified.", 0, ERRORS, true); return false; } mpView = pInArgList->getPlugInArgValue<SpatialDataView>(Executable::ViewArg()); RasterDataDescriptor *pDescriptor = static_cast<RasterDataDescriptor*>(mpRaster->getDataDescriptor()); VERIFY(pDescriptor != NULL); mIsStreaming = !isBatch(); if(!isBatch()) { BackgroundSuppressionDialog dlg; if(dlg.exec() == QDialog::Rejected) { mProgress.report("Suppression canceled by user.", 0, ABORT, true); return false; } mIsStreaming = dlg.isStreaming(); mpAnimation.reset(dlg.animation()); } unsigned int totalFrames = pDescriptor->getBandCount(); mCurrentFrame = 0; mProgressStep = 25.0 / (totalFrames - mCurrentFrame); mCurrentProgress = mProgressStep; if(!mIsStreaming) { for(InitializeReturnType rval = INIT_CONTINUE; rval == INIT_CONTINUE; mCurrentFrame++) { rval = initializeModel(); if(rval == INIT_ERROR) { return false; } } for(; mCurrentFrame < totalFrames; mCurrentFrame++) { if(isAborted()) { try { mProgress.abort(); } catch(const AlgorithmAbort&) { } cleanup(false); return false; } if(!processFrame()) { cleanup(false); return false; } } if(!displayResults()) { cleanup(false); mProgress.report("Unable to display results.", 0, ERRORS, true); return false; } cleanup(true); mProgress.report("Extraction complete", 100, NORMAL); mProgress.upALevel(); } else { for(InitializeReturnType rval = INIT_CONTINUE; rval == INIT_CONTINUE; mCurrentFrame++) { rval = initializeModel(); if(rval == INIT_ERROR) { return false; } } if(mpAnimation.get() == NULL) { mProgress.report("No animation specified, unable to perform streaming execution. Provide and animation or run in batch mode.", 0, ERRORS, true); return false; } mCurrentFrame = 0; const AnimationFrame *pFrame = mpAnimation->getCurrentFrame(); if(pFrame != NULL) { mCurrentFrame = pFrame->mFrameNumber; } if(!processFrame() || !displayResults()) { mProgress.report("Unable to initialize streaming mode.", 0, ERRORS, true); return false; } mProgress.report("Streaming mode setup complete.", 100, NORMAL); mProgress.upALevel(); mProgress.initialize(NULL, "Suppressing background", "temporal", "{01F54B12-0323-4ac4-8C04-C89F1C45EAD9}"); destroyAfterExecute(false); } return true; }
bool SpectralLibraryManager::generateResampledLibrary(const RasterElement* pRaster) { VERIFY(pRaster != NULL); // check that lib sigs are in same units as the raster element const RasterDataDescriptor* pDesc = dynamic_cast<const RasterDataDescriptor*>(pRaster->getDataDescriptor()); VERIFY(pDesc != NULL); const Units* pUnits = pDesc->getUnits(); if (pDesc->getUnits()->getUnitType() != mLibraryUnitType) { if (Service<DesktopServices>()->showMessageBox("Mismatched Units", "The data are not in the " "same units as the spectral library.\n Do you want to continue anyway?", "Yes", "No") == 1) { return false; } } FactoryResource<Wavelengths> pWavelengths; pWavelengths->initializeFromDynamicObject(pRaster->getMetadata(), false); // populate the library with the resampled signatures PlugInResource pPlugIn("Resampler"); Resampler* pResampler = dynamic_cast<Resampler*>(pPlugIn.get()); VERIFY(pResampler != NULL); if (pWavelengths->getNumWavelengths() != pDesc->getBandCount()) { mpProgress->updateProgress("Wavelength information in metadata does not match the number of bands " "in the raster element", 0, ERRORS); return false; } // get resample suitable signatures - leave out signatures that don't cover the spectral range of the data std::vector<std::vector<double> > resampledData; resampledData.reserve(mSignatures.size()); std::vector<Signature*> resampledSignatures; resampledSignatures.reserve(mSignatures.size()); std::vector<std::string> unsuitableSignatures; std::vector<double> sigValues; std::vector<double> sigWaves; std::vector<double> rasterWaves = pWavelengths->getCenterValues(); std::vector<double> rasterFwhm = pWavelengths->getFwhm(); std::vector<double> resampledValues; std::vector<int> bandIndex; DataVariant data; for (std::vector<Signature*>::const_iterator it = mSignatures.begin(); it != mSignatures.end(); ++it) { data = (*it)->getData(SpectralLibraryMatch::getNameSignatureWavelengthData()); VERIFY(data.isValid()); VERIFY(data.getValue(sigWaves)); resampledValues.clear(); data = (*it)->getData(SpectralLibraryMatch::getNameSignatureAmplitudeData()); VERIFY(data.isValid()); VERIFY(data.getValue(sigValues)); double scaleFactor = (*it)->getUnits( SpectralLibraryMatch::getNameSignatureAmplitudeData())->getScaleFromStandard(); for (std::vector<double>::iterator sit = sigValues.begin(); sit != sigValues.end(); ++sit) { *sit *= scaleFactor; } std::string msg; if (pResampler->execute(sigValues, resampledValues, sigWaves, rasterWaves, rasterFwhm, bandIndex, msg) == false || resampledValues.size() != rasterWaves.size()) { unsuitableSignatures.push_back((*it)->getName()); continue; } resampledData.push_back(resampledValues); resampledSignatures.push_back(*it); } if (resampledSignatures.empty()) { std::string errMsg = "None of the signatures in the library cover the spectral range of the data."; if (mpProgress != NULL) { mpProgress->updateProgress(errMsg, 0, ERRORS); return false; } } if (unsuitableSignatures.empty() == false) { std::string warningMsg = "The following library signatures do not cover the spectral range of the data:\n"; for (std::vector<std::string>::iterator it = unsuitableSignatures.begin(); it != unsuitableSignatures.end(); ++it) { warningMsg += *it + "\n"; } warningMsg += "These signatures will not be searched for in the data."; Service<DesktopServices>()->showMessageBox("SpectralLibraryManager", warningMsg); StepResource pStep("Spectral LibraryManager", "spectral", "64B6C87A-A6C3-4378-9B6E-221D89D8707B"); pStep->finalize(Message::Unresolved, warningMsg); } std::string libName = "Resampled Spectral Library"; // Try to get the resampled lib element in case session was restored. If NULL, create a new raster element with // num rows = num valid signatures, num cols = 1, num bands = pRaster num bands RasterElement* pLib = dynamic_cast<RasterElement*>(Service<ModelServices>()->getElement(libName, TypeConverter::toString<RasterElement>(), pRaster)); if (pLib != NULL) { // check that pLib has same number of sigs as SpectralLibraryManager RasterDataDescriptor* pLibDesc = dynamic_cast<RasterDataDescriptor*>(pLib->getDataDescriptor()); VERIFY(pLibDesc != NULL); if (pLibDesc->getRowCount() != mSignatures.size()) { mpProgress->updateProgress("An error occurred during session restore and some signatures were not restored." " Check the spectral library before using.", 0, ERRORS); Service<ModelServices>()->destroyElement(pLib); pLib = NULL; } } bool isNewElement(false); if (pLib == NULL) { pLib = RasterUtilities::createRasterElement(libName, static_cast<unsigned int>(resampledData.size()), 1, pDesc->getBandCount(), FLT8BYTES, BIP, true, const_cast<RasterElement*>(pRaster)); isNewElement = true; } if (pLib == NULL) { mpProgress->updateProgress("Error occurred while trying to create the resampled spectral library", 0, ERRORS); return false; } RasterDataDescriptor* pLibDesc = dynamic_cast<RasterDataDescriptor*>(pLib->getDataDescriptor()); VERIFY(pLibDesc != NULL); // copy resampled data into new element if (isNewElement) { FactoryResource<DataRequest> pRequest; pRequest->setWritable(true); pRequest->setRows(pLibDesc->getActiveRow(0), pLibDesc->getActiveRow(pLibDesc->getRowCount()-1), 1); DataAccessor acc = pLib->getDataAccessor(pRequest.release()); for (std::vector<std::vector<double> >::iterator sit = resampledData.begin(); sit != resampledData.end(); ++sit) { VERIFY(acc->isValid()); void* pData = acc->getColumn(); memcpy(acc->getColumn(), &(sit->begin()[0]), pLibDesc->getBandCount() * sizeof(double)); acc->nextRow(); } // set wavelength info in resampled library pWavelengths->applyToDynamicObject(pLib->getMetadata()); FactoryResource<Units> libUnits; libUnits->setUnitType(mLibraryUnitType); libUnits->setUnitName(StringUtilities::toDisplayString<UnitType>(mLibraryUnitType)); pLibDesc->setUnits(libUnits.get()); } pLib->attach(SIGNAL_NAME(Subject, Deleted), Slot(this, &SpectralLibraryManager::resampledElementDeleted)); mLibraries[pRaster] = pLib; mResampledSignatures[pLib] = resampledSignatures; const_cast<RasterElement*>(pRaster)->attach(SIGNAL_NAME(Subject, Deleted), Slot(this, &SpectralLibraryManager::elementDeleted)); return true; }
bool Orthorectification::process(int type, RasterElement *pDSM, GRID DSMGrid, double Geoid_Offset, int DSM_resampling) { StepResource pStep("Orthorectification Process", "app", "B4D426EC-E06D-11E1-83C8-42E56088709B"); pStep->addStep("Start","app", "B4D426EC-E06D-11E1-83C8-42E56088709B"); boxsize=0; res_type = type; if (res_type == 0) { boxsize=0; } else if (res_type == 1) { boxsize=1; } else if (res_type == 2) { boxsize=2; } else if (res_type == 3) { boxsize=3; } ProgressResource pResource("ProgressBar"); Progress *pProgress=pResource.get(); pProgress->setSettingAutoClose(false); RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(Image->getDataDescriptor()); FactoryResource<DataRequest> pRequest; DataAccessor pSrcAcc = Image->getDataAccessor(pRequest.release()); RasterDataDescriptor* pDescDSM = static_cast<RasterDataDescriptor*>(pDSM->getDataDescriptor()); FactoryResource<DataRequest> pRequestDSM; DataAccessor pDSMAcc = pDSM->getDataAccessor(pRequestDSM.release()); unsigned int N_Row = int(OrthoGrid.Y_Dim)+1; unsigned int N_Col = int(OrthoGrid.X_Dim)+1; // Check name of raster element // Service<ModelServices> pModel; vector<string> mCubeNames = pModel->getElementNames("RasterElement"); int NameIndex = 0, control=0; stringstream out; string OutputName=Image->getName(); string OutputName1 = OutputName.substr(0,OutputName.find_last_of(".")); while (control == 0) { control = 1; OutputName = OutputName1+"_ortho_"; out << NameIndex; OutputName.append(out.str()+".tiff"); for (unsigned int k=0; k<mCubeNames.size(); k++) { if (OutputName.compare(mCubeNames[k]) == 0) control = 0; } NameIndex++; out.str(""); out.clear(); } // Create output raster element and assoiciated descriptor and accessor // ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(OutputName,N_Row ,N_Col, FLT4BYTES)); RasterDataDescriptor* pResultDesc = static_cast<RasterDataDescriptor*> (pResultCube->getDataDescriptor()); FactoryResource<DataRequest> pResultRequest; pResultRequest->setWritable(true); DataAccessor pDestAcc = pResultCube->getDataAccessor(pResultRequest.release()); double NodeLat, NodeLon, H_IJ=0; //int DSM_I, DSM_J; for (unsigned int row = 0; row < N_Row; ++row) { if (pProgress != NULL) { pProgress->updateProgress("Calculating result", row * 100 / N_Row, NORMAL); } if (!pDestAcc.isValid()) { std::string msg = "Unable to access the cube data."; pProgress->updateProgress(msg, 0, ERRORS); pStep->finalize(Message::Failure, msg); return false; } for (unsigned int col = 0; col < N_Col; ++col) { NodeLat = OrthoGrid.Lat_Min+row*OrthoGrid.Lat_Step; NodeLon = OrthoGrid.Lon_Min+col*OrthoGrid.Lon_Step; // RETRIEVE HEIGHT VALUE FROM DSM if (DSM_resampling == 0) { int DSM_I = int((NodeLon - DSMGrid.Lon_Min)/DSMGrid.Lon_Step); int DSM_J = pDescDSM->getRowCount() - int((NodeLat - DSMGrid.Lat_Min)/DSMGrid.Lat_Step); pDSMAcc->toPixel(DSM_J,DSM_I); VERIFY(pDSMAcc.isValid()); H_IJ = (pDSMAcc->getColumnAsDouble()); } else { double DSM_I = ((NodeLon - DSMGrid.Lon_Min)/DSMGrid.Lon_Step); double DSM_J = pDescDSM->getRowCount() - ((NodeLat - DSMGrid.Lat_Min)/DSMGrid.Lat_Step); H_IJ = bilinear_height(pDSMAcc,DSM_I,DSM_J); } P_COORD NodeImage = Model->SAR_GroundToImage(NodeLon,NodeLat,H_IJ+Geoid_Offset); if ((NodeImage.I>1 && NodeImage.I< Model->Metadata.Width-1) && (NodeImage.J>1 && NodeImage.J< Model->Metadata.Height-1)) { switchOnEncoding(pResultDesc->getDataType(), copypixel3, pDestAcc->getColumn(), pSrcAcc, int(NodeImage.I), int(NodeImage.J),boxsize, H_IJ); } pDestAcc->nextColumn(); } pDestAcc->nextRow(); } Service<DesktopServices> pDesktop; Service<ModelServices> pMod; GcpList* GcpL = static_cast<GcpList*>(pMod->createElement("corner coordinate","GcpList",pResultCube.get())); // Update GCPs Information: to account for Opticks reading gcp lat&lon values the opposite way around, // here it is necessary to switch the value to assign lat to gcp.mCoordinate.mX and lon to gcp.mCoordinate.mY GcpPoint Punto; Punto.mCoordinate.mX = OrthoGrid.Lat_Min; Punto.mCoordinate.mY = OrthoGrid.Lon_Min; Punto.mCoordinate.mZ = 0.0; Punto.mPixel.mX = 0.0; Punto.mPixel.mY = 0.0; GcpL->addPoint(Punto); Punto.mCoordinate.mX = OrthoGrid.Lat_Max; Punto.mCoordinate.mY = OrthoGrid.Lon_Min; Punto.mCoordinate.mZ = 0.0; Punto.mPixel.mX = 0.0; Punto.mPixel.mY = OrthoGrid.Y_Dim; GcpL->addPoint(Punto); Punto.mCoordinate.mX = OrthoGrid.Lat_Min; Punto.mCoordinate.mY = OrthoGrid.Lon_Max; Punto.mCoordinate.mZ = 0.0; Punto.mPixel.mX = OrthoGrid.X_Dim; Punto.mPixel.mY = 0.0; GcpL->addPoint(Punto); Punto.mCoordinate.mX = OrthoGrid.Lat_Max; Punto.mCoordinate.mY = OrthoGrid.Lon_Max; Punto.mCoordinate.mZ = 0.0; Punto.mPixel.mX = OrthoGrid.X_Dim; Punto.mPixel.mY = OrthoGrid.Y_Dim; GcpL->addPoint(Punto); SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(pDesktop->createWindow(pResultCube->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); pView->setPrimaryRasterElement(pResultCube.get()); pView->createLayer(RASTER, pResultCube.get()); pView->createLayer(GCP_LAYER,GcpL,"GCP"); pView->setDataOrigin(LOWER_LEFT); pResultCube.release(); pProgress->updateProgress("Orthorectification is complete.", 100, NORMAL); pStep->addStep("End","app", "B4D426EC-E06D-11E1-83C8-42E56088709B"); pStep->finalize(); return true; }
bool Deconvolution::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Deconvolution Sharpening", "app", "619F3C8A-FB70-44E0-B211-B116E604EDDA"); if (pInArgList == NULL || pOutArgList == NULL) { return false; } Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); RasterElement* pCube = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); if (pCube == NULL) { std::string msg = "A raster cube must be specified."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pCube->getDataDescriptor()); VERIFY(pDesc != NULL); EncodingType ResultType = pDesc->getDataType(); if (pDesc->getDataType() == INT4SCOMPLEX) { ResultType = INT4SBYTES; } else if (pDesc->getDataType() == FLT8COMPLEX) { ResultType = FLT8BYTES; } FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BSQ); DataAccessor pSrcAcc = pCube->getDataAccessor(pRequest.release()); ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(pCube->getName() + "_Deconvolution_Sharpening_Result", pDesc->getRowCount(), pDesc->getColumnCount(), ResultType)); if (pResultCube.get() == NULL) { std::string msg = "A raster cube could not be created."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } FactoryResource<DataRequest> pResultRequest; pResultRequest->setWritable(true); DataAccessor pDestAcc = pResultCube->getDataAccessor(pResultRequest.release()); Service<DesktopServices> pDesktop; DeconvolutionDlg dlg(pDesktop->getMainWidget()); int stat = dlg.exec(); if (stat != QDialog::Accepted) { return true; } double minGrayValue; double maxGrayValue; double deltaValue = 0.0; int nFilterType = dlg.getCurrentFilterType(); int windowSize = dlg.getCurrentWindowSize(); double sigmaVal = dlg.getSigmaValue(); double gamaVal = dlg.getGamaValue(); windowSize = (windowSize-1)/2; if (NULL != pOriginalImage) { free(pOriginalImage); } pOriginalImage = (double *)malloc(sizeof(double)*pDesc->getRowCount()*pDesc->getColumnCount()); double *OrigData = (double *)malloc(sizeof(double)*pDesc->getRowCount()*pDesc->getColumnCount()); double *NewData = (double *)malloc(sizeof(double)*pDesc->getRowCount()*pDesc->getColumnCount()); double *ConvoData = (double *)malloc(sizeof(double)*pDesc->getRowCount()*pDesc->getColumnCount()); double *pTempData; InitializeData(pSrcAcc, pOriginalImage, OrigData, pDesc->getRowCount(), pDesc->getColumnCount(), pDesc->getDataType()); GetGrayScale(&minGrayValue, &maxGrayValue, pDesc->getDataType()); //Perform deconvolution iteratively for (int num = 0; num < MAX_ITERATION_NUMBER; num++) { if (pProgress != NULL) { pProgress->updateProgress("Deconvolution process", num*100/MAX_ITERATION_NUMBER, NORMAL); } if (isAborted()) { std::string msg = getName() + " has been aborted."; pStep->finalize(Message::Abort, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ABORT); } free(OrigData); free(NewData); free(ConvoData); return false; } deltaValue = DeconvolutionFunc(OrigData, pOriginalImage, NewData, ConvoData, sigmaVal, gamaVal, windowSize, pDesc->getRowCount(), pDesc->getColumnCount(), nFilterType, maxGrayValue, minGrayValue); pTempData = OrigData; OrigData = NewData; NewData = pTempData; double errorRate = deltaValue/(maxGrayValue-minGrayValue); if (errorRate < CONVERGENCE_THRESHOLD) { break; } } free(NewData); free(ConvoData); //Output result unsigned int nCount = 0; for (int i = 0; i < pDesc->getRowCount(); i++) { for (int j = 0; j < pDesc->getColumnCount(); j++) { if (!pDestAcc.isValid()) { std::string msg = "Unable to access the cube data."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } free(OrigData); return false; } pDestAcc->toPixel(i, j); switchOnEncoding(ResultType, restoreImageValue, pDestAcc->getColumn(), (OrigData+nCount)); nCount++; } } free(OrigData); if (!isBatch()) { Service<DesktopServices> pDesktop; SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(pDesktop->createWindow(pResultCube->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { std::string msg = "Unable to create view."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } pView->setPrimaryRasterElement(pResultCube.get()); pView->createLayer(RASTER, pResultCube.get()); } if (pProgress != NULL) { pProgress->updateProgress("Deconvolution enhancement is complete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("Deconvolution enhancement Result", pResultCube.release()); pStep->finalize(); return true; }
vector<ImportDescriptor*> LandsatEtmPlusImporter::getImportDescriptors(const string& filename) { vector<ImportDescriptor*> descriptors; if (filename.empty()) { return descriptors; } if (!readHeader(filename)) { return descriptors; } string lowGainDatasetName = filename + " Low Gain"; string highGainDatasetName = filename + " High Gain"; string panDatasetName = filename + " Panchromatic"; if (!mFieldHRF.empty() && !mFieldHTM.empty()) { // low gain RasterDataDescriptor* pDescriptor = RasterUtilities::generateRasterDataDescriptor(lowGainDatasetName, NULL, mNumRows, mNumCols, 7, BSQ, INT1UBYTE, IN_MEMORY); VERIFYRV(pDescriptor != NULL, descriptors); pDescriptor->setValidDataTypes(vector<EncodingType>(1, INT1UBYTE)); ImportDescriptorResource pLowGainImportDescriptor(pDescriptor); VERIFYRV(pLowGainImportDescriptor.get() != NULL, descriptors); RasterFileDescriptor* pFileDescriptor = static_cast<RasterFileDescriptor*>( RasterUtilities::generateAndSetFileDescriptor(pDescriptor, filename, "L", LITTLE_ENDIAN_ORDER)); VERIFYRV(pFileDescriptor != NULL, descriptors); vector<int> badValues; badValues.push_back(0); pDescriptor->setBadValues(badValues); pFileDescriptor->setBandFiles(getBandFilenames(filename, LOW_GAIN)); DynamicObject* pMetadata = pDescriptor->getMetadata(); populateMetaData(pMetadata, pFileDescriptor, LOW_GAIN); pDescriptor->setDisplayMode(RGB_MODE); pDescriptor->setDisplayBand(GRAY, pDescriptor->getOriginalBand(0)); pDescriptor->setDisplayBand(RED, pDescriptor->getOriginalBand(3)); pDescriptor->setDisplayBand(GREEN, pDescriptor->getOriginalBand(2)); pDescriptor->setDisplayBand(BLUE, pDescriptor->getOriginalBand(1)); pDescriptor->getUnits()->setUnitType(DIGITAL_NO); descriptors.push_back(pLowGainImportDescriptor.release()); // high gain pDescriptor = static_cast<RasterDataDescriptor*>(pDescriptor->copy(highGainDatasetName, NULL)); VERIFYRV(pDescriptor != NULL, descriptors); ImportDescriptorResource pHighGainImportDescriptor(pDescriptor); VERIFYRV(pHighGainImportDescriptor.get() != NULL, descriptors); pHighGainImportDescriptor->setImported(false); pFileDescriptor = static_cast<RasterFileDescriptor*>( RasterUtilities::generateAndSetFileDescriptor(pDescriptor, filename, "H", LITTLE_ENDIAN_ORDER)); VERIFYRV(pFileDescriptor != NULL, descriptors); pFileDescriptor->setBandFiles(getBandFilenames(filename, HIGH_GAIN)); pMetadata = pDescriptor->getMetadata(); populateMetaData(pMetadata, pFileDescriptor, HIGH_GAIN); descriptors.push_back(pHighGainImportDescriptor.release()); } if (!mFieldHPN.empty()) { // panchromatic RasterDataDescriptor* pDescriptor = RasterUtilities::generateRasterDataDescriptor(panDatasetName, NULL, mB8Rows, mB8Cols, 1, BSQ, INT1UBYTE, IN_MEMORY); VERIFYRV(pDescriptor != NULL, descriptors); pDescriptor->setValidDataTypes(vector<EncodingType>(1, INT1UBYTE)); ImportDescriptorResource pPanImportDescriptor(pDescriptor); VERIFYRV(pPanImportDescriptor.get() != NULL, descriptors); pPanImportDescriptor->setImported(false); RasterFileDescriptor* pFileDescriptor = static_cast<RasterFileDescriptor*>( RasterUtilities::generateAndSetFileDescriptor(pDescriptor, filename, "Pan", LITTLE_ENDIAN_ORDER)); VERIFYRV(pFileDescriptor != NULL, descriptors); vector<int> badValues; badValues.push_back(0); pDescriptor->setBadValues(badValues); pFileDescriptor->setBandFiles(getBandFilenames(filename, PANCHROMATIC)); DynamicObject* pMetadata = pDescriptor->getMetadata(); populateMetaData(pMetadata, pFileDescriptor, PANCHROMATIC); pDescriptor->setDisplayMode(GRAYSCALE_MODE); pDescriptor->setDisplayBand(GRAY, pDescriptor->getOriginalBand(0)); pDescriptor->getUnits()->setUnitType(DIGITAL_NO); descriptors.push_back(pPanImportDescriptor.release()); } return descriptors; }