bool SioImporter::ensureStatisticsReadProperly(Progress *pProgress, std::ostream& failure) { bool success = true; success &= setBatch(); PlugInArgList* pInList = NULL; PlugInArgList* pOutList = NULL; isseas(getInputSpecification(pInList) != false, failure); isseas(getOutputSpecification(pOutList) != false, failure); PlugInArg* pRasterElementArg = NULL; isseas(pInList->getArg(Importer::ImportElementArg(), pRasterElementArg) != false, failure); string testFilePath = TestUtilities::getTestDataPath() + "tipjul5bands.sio"; RasterElement* pRasterElement = NULL; if (success) { vector<ImportDescriptor*> descriptors = getImportDescriptors(testFilePath); if (descriptors.empty() == false) { ImportDescriptor* pImportDescriptor = descriptors.front(); if (pImportDescriptor != NULL) { DataDescriptor* pDescriptor = pImportDescriptor->getDataDescriptor(); if (pDescriptor != NULL) { Service<ModelServices> pModel; pRasterElement = dynamic_cast<RasterElement*>(pModel->createElement(pDescriptor)); if (pRasterElement != NULL) { pRasterElementArg->setActualValue(pRasterElement); } } } } } isseas(execute(pInList, pOutList) != false, failure); isseas(pRasterElement != NULL, failure); if (success) { RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pRasterElement->getDataDescriptor()); isseas(pDescriptor != NULL, failure); const vector<DimensionDescriptor>& loadedBands = pDescriptor->getBands(); isseas(loadedBands.size() == 5, failure); int iNumBandsWithStats = 0; for (int i = 0; i < 5; ++i) { // we don't want to do an assert yet... only when we know 4 bands have computed statistics Statistics* pStatistics = pRasterElement->getStatistics(loadedBands[i]); if (pStatistics != NULL) { if (pStatistics->areStatisticsCalculated() == true) { if (success) { iNumBandsWithStats++; } } } } // success of the band computation is dependent on 4 bands with statistics isseas(iNumBandsWithStats == 3, failure); } if (pRasterElement != NULL) { Service<ModelServices> pModel; pModel->destroyElement(pRasterElement); pRasterElement = NULL; } Service<PlugInManagerServices> pPim; if (pInList) { pPim->destroyPlugInArgList(pInList); } if (pOutList) { pPim->destroyPlugInArgList(pOutList); } return success; }
bool BandMath::execute(PlugInArgList* pInputArgList, PlugInArgList* pOutputArgList) { StepResource pStep("Start BandMath", "app", "02E18066-1355-4a5f-ABC5-0366D9890C1C"); mpStep = pStep.get(); // Initilize variables initialize(); // Get pointers // parse arg in list if (!parse(pInputArgList, pOutputArgList)) { meGabbiness = ERRORS; displayErrorMessage(); return false; } // Get important stuff pStep->addProperty("Dataset", mpCube->getFilename()); const RasterDataDescriptor* pDescriptor = dynamic_cast<const RasterDataDescriptor*>(mpCube->getDataDescriptor()); if (pDescriptor != NULL) { mCubeRows = pDescriptor->getRowCount(); mCubeColumns = pDescriptor->getColumnCount(); mCubeBands = pDescriptor->getBandCount(); } std::string tmpResultName; vector<DataElement*> elements = mpDataModel->getElements("RasterElement"); vector<DataElement*>::iterator iter; for (iter = elements.begin(); iter != elements.end(); ++iter) { RasterElement* pRaster = static_cast<RasterElement*>(*iter); if (pRaster != NULL) { const RasterDataDescriptor* pCurrentDescriptor = dynamic_cast<const RasterDataDescriptor*>(pRaster->getDataDescriptor()); if (pCurrentDescriptor != NULL) { if ((mCubeRows == static_cast<int>(pCurrentDescriptor->getRowCount())) && (mCubeColumns == static_cast<int>(pCurrentDescriptor->getColumnCount())) && (mCubeBands == static_cast<int>(pCurrentDescriptor->getBandCount()))) { mCubesList.push_back(pRaster); } } } } char errorVal[80]; int errorCode = -1; if (mbInteractive) { QWidget* pParent = mpDesktop->getMainWidget(); FrmBM frmASIT(pDescriptor, mCubesList, pParent); if (frmASIT.exec() == QDialog::Rejected) { pStep->finalize(Message::Abort); return false; } mExpression = frmASIT.getExpression(true).toStdString(); mbDegrees = frmASIT.isDegrees(); mbCubeMath = frmASIT.isMultiCube(); mbAsLayerOnExistingView = frmASIT.isResultsMatrix(); } else { mbCubeMath = false; //check for cube math unsigned int pos = mExpression.find_first_of(string("cC")); if ((pos >= 0) && (pos < (mExpression.length() - 1)) && ((mExpression[pos + 1] > '0') && (mExpression[pos + 1] < '9'))) { mbCubeMath = true; } } if (!createReturnValue(mExpression)) { mstrProgressString = "Could not allocate space for results."; meGabbiness = ERRORS; displayErrorMessage(); return false; } { StepResource pResultStep("Compute result", "app", "CDCC12AC-32DD-4831-BC6B-225538C92053"); mpStep = pResultStep.get(); pResultStep->addProperty("Expression", mExpression); FactoryResource<DataRequest> pReturnRequest; pReturnRequest->setInterleaveFormat(BIP); pReturnRequest->setWritable(true); DataAccessor returnDa = mpResultData->getDataAccessor(pReturnRequest.release()); if (!returnDa.isValid()) { mstrProgressString = "Could not access the result data."; meGabbiness = ERRORS; displayErrorMessage(); return false; } if (!mbCubeMath) { FactoryResource<DataRequest> pCubeRequest; pCubeRequest->setInterleaveFormat(BIP); DataAccessor cubeDa = mpCube->getDataAccessor(pCubeRequest.release()); if (!cubeDa.isValid()) { mstrProgressString = "Reading this cube format is not supported."; meGabbiness = ERRORS; displayErrorMessage(); return false; } vector<DataAccessor> accessors(1, cubeDa); vector<EncodingType> types(1, pDescriptor->getDataType()); char* mutableExpression = new char[mExpression.size() + 1]; strcpy(mutableExpression, mExpression.c_str()); errorCode = eval(mpProgress, accessors, types, mCubeRows, mCubeColumns, mCubeBands, mutableExpression, returnDa, mbDegrees, errorVal, mbCubeMath, mbInteractive); delete [] mutableExpression; } else // cube math { EncodingType type = pDescriptor->getDataType(); vector<DataAccessor> accessors; vector<EncodingType> dataTypes; for (unsigned int i = 0; i < mCubesList.size(); ++i) { FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BIP); DataAccessor daCube = mCubesList[i]->getDataAccessor(pRequest.release()); accessors.push_back(daCube); const RasterDataDescriptor* pDdCube = dynamic_cast<RasterDataDescriptor*>(mCubesList.at(i)-> getDataDescriptor()); if (pDdCube != NULL) { dataTypes.push_back(pDdCube->getDataType()); } else { mstrProgressString = "Could not get data description for cube."; meGabbiness = ERRORS; displayErrorMessage(); return false; } } char* mutableExpression = new char[mExpression.size() + 1]; strcpy(mutableExpression, mExpression.c_str()); errorCode = eval(mpProgress, accessors, dataTypes, mCubeRows, mCubeColumns, mCubeBands, mutableExpression, returnDa, mbDegrees, errorVal, mbCubeMath, mbInteractive); delete [] mutableExpression; } if (errorCode != 0) { mbError = true; if (errorCode == -1) { mstrProgressString = errorVal; meGabbiness = ERRORS; } else if (errorCode == -2) { mstrProgressString = "BandMath was cancelled due to an error in the input expression."; meGabbiness = ABORT; } else { mstrProgressString = "Unknown error has occured while executing BandMath."; meGabbiness = ERRORS; } displayErrorMessage(); return false; } pResultStep->finalize(Message::Success); } mpStep = pStep.get(); if (!createReturnGuiElement()) { mstrProgressString = "Could not create GUI element."; meGabbiness = ERRORS; displayErrorMessage(); return false; } // Fill output arg list if (pOutputArgList != NULL) { PlugInArg* pArg = NULL; pOutputArgList->getArg("Band Math Result", pArg); VERIFY(pArg != NULL); pArg->setActualValue(mpResultData); } mpResultData->updateData(); if (mpProgress != NULL) { mpProgress->updateProgress("Algorithm completed successfully", 100, meGabbiness); } pStep->finalize(Message::Success); mpStep = NULL; return true; }
bool CreateExportFileDescriptor::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Execute Wizard Item", "app", "E15CA38D-02CD-464B-8412-C0937D05A1FB"); pStep->addProperty("Item", getName()); mpStep = pStep.get(); if (extractInputArgs(pInArgList) == false) { return false; } VERIFY(mpFilename != NULL); // Create a file descriptor with the values in the element's data descriptor FileDescriptor* pFileDescriptor = NULL; if (mpElement != NULL) { const RasterDataDescriptor* pRasterDescriptor = dynamic_cast<const RasterDataDescriptor*>(mpElement->getDataDescriptor()); if (pRasterDescriptor != NULL) { // Start row DimensionDescriptor startRow; if (mpStartRow != NULL) { startRow = pRasterDescriptor->getOriginalRow(*mpStartRow - 1); } // End row DimensionDescriptor endRow; if (mpEndRow != NULL) { endRow = pRasterDescriptor->getOriginalRow(*mpEndRow - 1); } // Row skip unsigned int rowSkip = 0; if (mpRowSkipFactor != NULL) { rowSkip = *mpRowSkipFactor; } // Start column DimensionDescriptor startColumn; if (mpStartColumn != NULL) { startColumn = pRasterDescriptor->getOriginalColumn(*mpStartColumn - 1); } // End column DimensionDescriptor endColumn; if (mpEndColumn != NULL) { endColumn = pRasterDescriptor->getOriginalColumn(*mpEndColumn - 1); } // Column skip unsigned int columnSkip = 0; if (mpColumnSkipFactor != NULL) { columnSkip = *mpColumnSkipFactor; } // Start band DimensionDescriptor startBand; if (mpStartBand != NULL) { startBand = pRasterDescriptor->getOriginalBand(*mpStartBand - 1); } // End band DimensionDescriptor endBand; if (mpEndBand != NULL) { endBand = pRasterDescriptor->getOriginalBand(*mpEndBand - 1); } // Band skip unsigned int bandSkip = 0; if (mpBandSkipFactor != NULL) { bandSkip = *mpBandSkipFactor; } pFileDescriptor = RasterUtilities::generateFileDescriptorForExport(pRasterDescriptor, mpFilename->getFullPathAndName(), startRow, endRow, rowSkip, startColumn, endColumn, columnSkip, startBand, endBand, bandSkip); } } // Create a file descriptor with the input filename if (pFileDescriptor == NULL) { FactoryResource<FileDescriptor> pFactoryFileDescriptor; pFileDescriptor = pFactoryFileDescriptor.release(); if (pFileDescriptor != NULL) { pFileDescriptor->setFilename(mpFilename->getFullPathAndName()); } } if (pFileDescriptor == NULL) { reportError("Could not create the file descriptor!", "219F9340-1681-4BD8-90B4-2D9335E8B751"); return false; } // Set the output arg value if (pOutArgList != NULL) { PlugInArg* pArg = NULL; // File descriptor if (pOutArgList->getArg("File Descriptor", pArg) && (pArg != NULL)) { pArg->setActualValue(pFileDescriptor); } else { // Destroy the file descriptor Service<ApplicationServices> pApp; if (pApp.get() != NULL) { ObjectFactory* pObjFact = pApp->getObjectFactory(); if (pObjFact != NULL) { pObjFact->destroyObject(pFileDescriptor, "FileDescriptor"); } } reportError("Could not set the file descriptor output value!", "98FB7EB3-BC2A-4075-9DE2-FD28ABAECE5B"); return false; } } reportComplete(); return true; }