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; }
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; }
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; }
bool adaptive_median::execute(PlugInArgList * pInArgList, PlugInArgList * pOutArgList) { StepResource pStep("adap_median", "noise", "5EA0CC75-9E0B-4c3d-BA23-6DB7157BBD55"); if (pInArgList == NULL || pOutArgList == NULL) { return false; } std::string msg = "Noise Reduction by Adaptive Median Filter "; 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); if (pDesc->getDataType() == INT4SCOMPLEX || pDesc->getDataType() == FLT8COMPLEX) { std::string msg = "Noise Reduction cannot be performed on complex types."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } FactoryResource < DataRequest > pRequest; pRequest->setInterleaveFormat(BSQ); DataAccessor pSrcAcc = pCube->getDataAccessor(pRequest.release()); RasterElement *dRas = RasterUtilities::createRasterElement(pCube->getName() + "Noise_reduction_Median_filter", pDesc->getRowCount(), pDesc->getColumnCount(), 3, pDesc->getDataType(), BSQ); pProgress->updateProgress(msg, 50, NORMAL); copyImage4(pCube, dRas, 0, pProgress); pProgress->updateProgress(msg + "RED complete", 60, NORMAL); copyImage4(pCube, dRas, 1, pProgress); pProgress->updateProgress(msg + "GREEN complete", 70, NORMAL); copyImage4(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); 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; } pProgress->updateProgress("Final", 100, NORMAL); pProgress->updateProgress(msg, 100, NORMAL); 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("adaptive_median is compete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("adaptive_median_Result", pResultCube.release()); // saving // data pStep->finalize(); return true; }
void DataMergeGui::addMergeList() { for (int i = 0; i < importTree->topLevelItemCount(); i++) { QTreeWidgetItem *topItem = importTree->topLevelItem(i); for (int i = 0; i < topItem->childCount(); i++) { QTreeWidgetItem *childItem = topItem->child(i); if (childItem->checkState(0) == Qt::Checked) { QString crtText = topItem->text(0); if (flag == 0) { RasterElement *pFisrtElement = filenameMap[crtText.toStdString()]; RasterDataDescriptor* pFirstDesc = static_cast<RasterDataDescriptor*>(pFisrtElement->getDataDescriptor()); firstType = pFirstDesc->getDataType(); firstRowCount = pFirstDesc->getRowCount(); firstColCount = pFirstDesc->getColumnCount(); } else { RasterElement *pTempElement = filenameMap[crtText.toStdString()]; RasterDataDescriptor* pTempDesc = static_cast<RasterDataDescriptor*>(pTempElement->getDataDescriptor()); EncodingType tempType = pTempDesc->getDataType(); int tempRowCount = pTempDesc->getRowCount(); int tempColCount = pTempDesc->getColumnCount(); if (firstType != tempType) { QMessageBox::critical(NULL, "Spectral Data Merge", tr("Merge RasterElement %1 type different!").arg(crtText), "OK"); return; } if (firstRowCount != tempRowCount) { QMessageBox::critical(NULL, "Spectral Data Merge", tr("Merge RasterElement %1 row different!").arg(crtText), "OK"); return; } if (firstColCount != tempColCount) { QMessageBox::critical(NULL, "Spectral Data Merge", tr("Merge RasterElement column different!").arg(crtText), "OK"); return; } } QListWidgetItem *item = new QListWidgetItem(mergeList); item->setText(crtText + "--" + childItem->text(0)); // mergeElementList.push_back(filenameMap[crtText.toStdString()]); removeButton->setEnabled(true); mergeButton->setEnabled(true); flag = 1; } } //QListWidgetItem *crtItem = importList->currentItem(); /* QList<QListWidgetItem *> selectedList = importList->selectedItems(); for (int i = 0; i < selectedList.count(); i++) { QListWidgetItem *crtItem = selectedList.at(i); QString crtText = crtItem->text(); if (flag == 0) { RasterElement *pFisrtElement = filenameMap[crtText.toStdString()]; RasterDataDescriptor* pFirstDesc = static_cast<RasterDataDescriptor*>(pFisrtElement->getDataDescriptor()); firstType = pFirstDesc->getDataType(); firstRowCount = pFirstDesc->getRowCount(); firstColCount = pFirstDesc->getColumnCount(); } else { RasterElement *pTempElement = filenameMap[crtText.toStdString()]; RasterDataDescriptor* pTempDesc = static_cast<RasterDataDescriptor*>(pTempElement->getDataDescriptor()); EncodingType tempType = pTempDesc->getDataType(); int tempRowCount = pTempDesc->getRowCount(); int tempColCount = pTempDesc->getColumnCount(); if (firstType != tempType) { QMessageBox::critical(NULL, "Spectral Data Merge", "Merge RasterElement type different!", "OK"); return; } if (firstRowCount != tempRowCount) { QMessageBox::critical(NULL, "Spectral Data Merge", "Merge RasterElement row different!", "OK"); return; } if (firstColCount != tempColCount) { QMessageBox::critical(NULL, "Spectral Data Merge", "Merge RasterElement column different!", "OK"); return; } } QListWidgetItem *item = new QListWidgetItem(mergeList); item->setText(crtText); // mergeElementList.push_back(filenameMap[crtText.toStdString()]); removeButton->setEnabled(true); mergeButton->setEnabled(true); flag = 1; } */ } }
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 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; }
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 WaveletKSigmaFilter::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Wavelet K-Sigma Filter", "app", "1A4BDC34-5A95-419B-8E53-C92333AFFC3E"); 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() + "_Noise_Removal_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; WaveletKSigmaDlg dlg(pDesktop->getMainWidget()); int stat = dlg.exec(); if (stat != QDialog::Accepted) { // pProgress->updateProgress("Level 4 " + StringUtilities::toDisplayString(dlg.getLevelThreshold(3)) // + " Level5 " + StringUtilities::toDisplayString(dlg.getLevelThreshold(4)), dlg.getLevelThreshold(0), NORMAL); return true; } unsigned int rowLoops; unsigned int colLoops; unsigned int rowIndex = 0; unsigned int colIndex = 0; double ScaleKValue[MAX_WAVELET_LEVELS] = {0.0}; for (int k=0; k<MAX_WAVELET_LEVELS;k++) { ScaleKValue[k] = dlg.getLevelThreshold(k); } if (0 == pDesc->getRowCount()%rowBlocks) { rowLoops = pDesc->getRowCount()/rowBlocks; } else { rowLoops = pDesc->getRowCount()/rowBlocks + 1; } if (0 == pDesc->getColumnCount()%colBlocks) { colLoops = pDesc->getColumnCount()/colBlocks; } else { colLoops = pDesc->getColumnCount()/colBlocks + 1; } for (unsigned int i = 0; i < rowLoops; i++) { if ( rowIndex + rowBlocks > pDesc->getRowCount()) { rowIndex = pDesc->getRowCount() - rowBlocks; } colIndex = 0; for (unsigned int j = 0; j < colLoops; j++) { if ( colIndex + colBlocks > pDesc->getColumnCount()) { colIndex = pDesc->getColumnCount() - colBlocks; } if (pProgress != NULL) { pProgress->updateProgress("Remove result", (i*colLoops+j) / (rowLoops*colLoops), 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; } //Process the data in current block ProcessData(pSrcAcc, pBuffer, rowIndex, colIndex, rowBlocks, colBlocks, ScaleKValue, pDesc->getDataType()); //Output the value for (unsigned int m = 0; m < rowBlocks; m++) { for (unsigned int n = 0; n < colBlocks; n++) { 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; } pDestAcc->toPixel(rowIndex+m, colIndex+n); switchOnEncoding(ResultType, speckleNoiseRemove, pDestAcc->getColumn(), (pBuffer+m*colBlocks+n)); } } colIndex += colBlocks; } rowIndex += rowBlocks; } 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("Noise removal is compete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("Noise removal Result", pResultCube.release()); pStep->finalize(); return true; }
bool conservative_filter::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Conservative", "Filter", "5EA0CC75-9E0B-4c3d-BA23-6DB7157BBD55"); //what is this? if (pInArgList == NULL || pOutArgList == NULL) { return false; } Service <DesktopServices> pDesktop; conservative_filter_ui dialog(pDesktop->getMainWidget()); int status = dialog.exec(); if (status == QDialog::Accepted) { int radius = dialog.getRadiusValue(); 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); if (pDesc->getDataType() == INT4SCOMPLEX || pDesc->getDataType() == FLT8COMPLEX) { std::string msg = "Conservative Filter cannot be performed on complex types."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BSQ); DataAccessor pSrcAcc = pCube->getDataAccessor(pRequest.release()); ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(pCube->getName() + "_Conservative_Filter_Result", 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()); for (unsigned int row = 0; row < pDesc->getRowCount(); ++row) { if (pProgress != NULL) { pProgress->updateProgress("Applying Conservative Filter", 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(pDesc->getDataType(), verifyRange, pDestAcc->getColumn(), pSrcAcc, row, col, pDesc->getRowCount(), pDesc->getColumnCount(), radius); 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("COnservative Filter is complete", 100, NORMAL); } pOutArgList->setPlugInArgValue("conservative_filter_result", pResultCube.release()); pStep->finalize(); } return true; }
bool IceExporterShell::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { string filename; try { // Set up subclasses parseInputArgs(pInArgList); // Get the RasterElement and RasterFileDescriptor RasterElement* pOutputCube = NULL; RasterFileDescriptor* pOutputFileDescriptor = NULL; getOutputCubeAndFileDescriptor(pOutputCube, pOutputFileDescriptor); ICEVERIFY_MSG(pOutputCube != NULL, "No Raster Element specified."); ICEVERIFY_MSG(pOutputFileDescriptor != NULL, "No Raster File Descriptor specified."); RasterDataDescriptor* pRasterDescriptor = dynamic_cast<RasterDataDescriptor*>(pOutputCube->getDataDescriptor()); ICEVERIFY_MSG(pRasterDescriptor != NULL, "Raster Element is invalid."); // Open the file for writing filename = pOutputFileDescriptor->getFilename().getFullPathAndName(); Hdf5FileResource fileResource(H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)); ICEVERIFY_MSG(*fileResource >= 0, "Unable to create file " + filename) IceWriter writer(*fileResource, mFileType); mpWriter = &writer; if (mpOptionsWidget.get() != NULL) { writer.setChunkSize(mpOptionsWidget->getChunkSize() * 1024 * 1024); writer.setCompressionType(mpOptionsWidget->getCompressionType()); writer.setGzipCompressionLevel(mpOptionsWidget->getGzipCompressionLevel()); } if ((pRasterDescriptor->getDataType() == INT4SCOMPLEX || pRasterDescriptor->getDataType() == FLT8COMPLEX) && (writer.getCompressionType() == GZIP || writer.getCompressionType() == SHUFFLE_AND_GZIP)) { std::string msgtxt = "Compression not supported with complex data types, data will not be compressed."; MessageResource msg(msgtxt, "app", "{7B050EE4-D025-43b2-AD8F-DF8E28FA8551}"); if (mpProgress != NULL) { mpProgress->updateProgress(msgtxt, 1, WARNING); } } writer.writeFileHeader(); abortIfNecessary(); // Write the cube to the file writer.writeCube(outputCubePath(), pOutputCube, pOutputFileDescriptor, mpProgress); abortIfNecessary(); // Allow subclasses to write class-specific information to the file finishWriting(writer); abortIfNecessary(); // Finished mpWriter = NULL; if (mpProgress != NULL) { mpProgress->updateProgress("Ice export complete.", 100, NORMAL); } } catch (const IceException& ex) { if (mpProgress != NULL) { string msg = ex.getFailureMessage(); if (msg.empty()) { msg = "Unknown error. Failed to create file."; } mpProgress->updateProgress(msg, 0, ERRORS); } ex.addToMessageLog(); if (filename.empty() == false) { remove(filename.c_str()); } mpWriter = NULL; return false; } catch (const IceAbortException&) { if (mpProgress != NULL) { mpProgress->updateProgress("Ice export aborted.", 0, ABORT); } if (filename.empty() == false) { remove(filename.c_str()); } mpWriter = NULL; return false; } return true; }
bool KDISTRIBUTION::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("KDISTRIBUTION", "app10", "F298D57C-D816-42F0-AE27-43DAA02C0544"); 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; FactoryResource<DataRequest> pRequest2; pRequest->setInterleaveFormat(BSQ); pRequest2->setInterleaveFormat(BSQ); DataAccessor pAcc = pCube->getDataAccessor(pRequest.release()); DataAccessor pAcc2 = pCube->getDataAccessor(pRequest2.release()); ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(pCube->getName() + "Result", 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()); const RasterDataDescriptor* pDescriptor = dynamic_cast<const RasterDataDescriptor*>(pCube->getDataDescriptor()); int tester_count = 0; int eastCol = 0; int northRow = 0; int westCol = 0; int southRow = 0; double zstatistic = 0; double total = 0.0; double total_sum = 0.0; double mean = 0.0; double std = 0.0; double a=0; int rowSize=pDesc->getRowCount(); int colSize=pDesc->getColumnCount(); int prevCol = 0; int prevRow = 0; int nextCol = 0; int nextRow = 0; double long PFA = 0.0; int DEPTH1 = 10; int DEPTH2 = 10; int DEPTH3 = 1; int DEPTH4 = 1; int count=0; int zero=0; double long threshold = 100000.0; double look_table1[24][6]; for(int i=0; i<24; i++) { for(int j=0; j<3; j++) { look_table1[i][j]=0.0; } } QStringList Names("0.0000001"); QString value = QInputDialog::getItem(Service<DesktopServices>()->getMainWidget(), "Input a PFA value", "Input a PFA value (0.0000001 or 0.00000001)", Names); std::string strAoi = value.toStdString(); std::istringstream stm; stm.str(strAoi); //stm >> PFA; PFA=::atof(strAoi.c_str()); if (PFA==0.0000001) { look_table1[0][0]=1.0; look_table1[0][1]=5.0; look_table1[0][2]=32.3372530103729330; look_table1[1][0]=1.0; look_table1[1][1]=10.0; look_table1[1][2]=25.0723580041031010; look_table1[2][0]=1.0; look_table1[2][1]=15.0; look_table1[2][2]=22.3991160013551250; look_table1[3][0]=1.0; look_table1[3][1]=20.0; look_table1[3][2]=20.9821949998985920; look_table1[4][1]=1.0; look_table1[4][2]=40.0; look_table1[5][3]=18.7055519975583020; look_table1[5][1]=1.0; look_table1[5][2]=90.0; look_table1[5][3]=18.7055519975583020; look_table1[6][0]=2.0; look_table1[6][1]=5.0; look_table1[6][2]=20.2619339991581950; look_table1[7][0]=2.0; look_table1[7][1]=10.0; look_table1[7][2]=15.4860609951617470; look_table1[8][0]=2.0; look_table1[8][1]=15.0; look_table1[8][2]=13.7276789964777210; look_table1[9][0]=2.0; look_table1[9][1]=20.0; look_table1[9][2]=12.7942589971762930; look_table1[10][0]=2.0; look_table1[10][1]=40.0; look_table1[10][2]=11.2895769983023970; look_table1[11][0]=2.0; look_table1[11][1]=90.0; look_table1[11][2]=10.3695259989909640; look_table1[12][0]=3.0; look_table1[12][1]=5.0; look_table1[12][2]=15.9102209948443050; look_table1[13][0]=3.0; look_table1[13][1]=10.0; look_table1[13][2]=12.0443629977375150; look_table1[14][0]=3.0; look_table1[14][1]=15.0; look_table1[14][2]=10.6203179988032710; look_table1[15][0]=3.0; look_table1[15][1]=20.0; look_table1[15][2]=9.8635499993696367; look_table1[16][0]=3.0; look_table1[16][1]=40.0; look_table1[16][2]=8.6407550002847771; look_table1[17][0]=3.0; look_table1[17][1]=90.0; look_table1[17][2]=7.8893780007488568; look_table1[18][0]=4.0; look_table1[18][1]=5.0; look_table1[18][2]=13.6166519965608130; look_table1[19][0]=4.0; look_table1[19][1]=10.0; look_table1[19][2]=10.2336029990926890; look_table1[20][0]=4.0; look_table1[20][1]=15.0; look_table1[20][2]=10.6203179988032710; look_table1[21][0]=4.0; look_table1[21][1]=20.0; look_table1[21][2]=8.9868610000257512; look_table1[22][0]=4.0; look_table1[22][1]=40.0; look_table1[22][2]=7.2502150006595159; look_table1[23][0]=4.0; look_table1[23][1]=90.0; look_table1[23][2]=6.5879140005669408; } if (PFA==0.00000001) { look_table1[0][0]=1.0; look_table1[0][1]=5.0; look_table1[0][2]=20.0000019988889410; look_table1[1][0]=1.0; look_table1[1][1]=10.0; look_table1[1][2]=20.0000019988889410; look_table1[2][0]=1.0; look_table1[2][1]=15.0; look_table1[2][2]=20.0000019988889410; look_table1[3][0]=1.0; look_table1[3][1]=20.0; look_table1[3][2]=20.0000019988889410; look_table1[4][1]=1.0; look_table1[4][2]=40.0; look_table1[5][3]=20.0000019988889410; look_table1[5][1]=1.0; look_table1[5][2]=90.0; look_table1[5][3]=20.0000019988889410; look_table1[6][0]=2.0; look_table1[6][1]=5.0; look_table1[6][2]=18.3243529971664460; look_table1[7][0]=2.0; look_table1[7][1]=10.0; look_table1[7][2]=18.3243529971664460; look_table1[8][0]=2.0; look_table1[8][1]=15.0; look_table1[8][2]=16.0869139948664570; look_table1[9][0]=2.0; look_table1[9][1]=20.0; look_table1[9][2]=14.8998299956004820; look_table1[10][0]=2.0; look_table1[10][1]=40.0; look_table1[10][2]=12.9846719970337880; look_table1[11][0]=2.0; look_table1[11][1]=90.0; look_table1[11][2]=11.8094659979133120; look_table1[12][0]=3.0; look_table1[12][1]=5.0; look_table1[12][2]=18.9816659978421360; look_table1[13][0]=3.0; look_table1[13][1]=10.0; look_table1[13][2]=14.1167729961865230; look_table1[14][0]=3.0; look_table1[14][1]=15.0; look_table1[14][2]=12.3304539975234050; look_table1[15][0]=3.0; look_table1[15][1]=20.0; look_table1[15][2]=11.3819769982332450; look_table1[16][0]=3.0; look_table1[16][1]=40.0; look_table1[16][2]=9.8488249993806569; look_table1[17][0]=3.0; look_table1[17][1]=90.0; look_table1[17][2]=8.9039850000877756; look_table1[18][0]=4.0; look_table1[18][1]=5.0; look_table1[18][2]=16.1272319949079020; look_table1[19][0]=4.0; look_table1[19][1]=10.0; look_table1[19][2]=11.9117899978367330; look_table1[20][0]=4.0; look_table1[20][1]=15.0; look_table1[20][2]=10.3636999989953240; look_table1[21][0]=4.0; look_table1[21][1]=20.0; look_table1[21][2]=9.5411879996108926; look_table1[22][0]=4.0; look_table1[22][1]=40.0; look_table1[22][2]=8.2095870006074634; look_table1[23][0]=4.0; look_table1[23][1]=90.0; look_table1[23][2]=7.3860650006785047; } QStringList Names1("10"); QString value1 = QInputDialog::getItem(Service<DesktopServices>()->getMainWidget(), "Input the size of the window width", "Input the size of the window width in terms of the number of pixels (eg. 10)", Names1); std::string strAoi1 = value1.toStdString(); std::istringstream stm1; stm1.str(strAoi1); //stm1 >> DEPTH1; DEPTH1=::atof(strAoi1.c_str()); QStringList Names2("10"); QString value2 = QInputDialog::getItem(Service<DesktopServices>()->getMainWidget(), "Input the size of the window height", "Input the size of the window height in terms of the number of pixels (eg. 10)", Names2); std::string strAoi2 = value2.toStdString(); std::istringstream stm2; stm2.str(strAoi2); //stm2 >> DEPTH2; DEPTH2=::atof(strAoi2.c_str()); QStringList Names3("1"); QString value3 = QInputDialog::getItem(Service<DesktopServices>()->getMainWidget(), "Input the size of the gaurd width", "Input the size of the guard width in terms of the number of pixels (eg. 1)", Names3); std::string strAoi3 = value3.toStdString(); std::istringstream stm3; stm3.str(strAoi3); //stm3 >> DEPTH3; DEPTH3=::atof(strAoi3.c_str()); QStringList Names4("1"); QString value4 = QInputDialog::getItem(Service<DesktopServices>()->getMainWidget(), "Input the size of the guard height", "Input the size of the guard height in terms of the number of pixels (eg. 1)", Names4); std::string strAoi4 = value4.toStdString(); std::istringstream stm4; stm4.str(strAoi4); stm4 >> DEPTH4; DEPTH4=::atof(strAoi4.c_str()); for (int row = 0; row < rowSize; ++row) { 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 (!pAcc.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; } if (pProgress != NULL) { pProgress->updateProgress("Calculating statistics", row * 100 / pDesc->getRowCount(), NORMAL); } for (int col = 0; col < colSize; ++col) { //p[col]=pAcc2->getColumnAsInteger(); westCol=max(col-DEPTH1,zero); northRow=max(row-DEPTH2,zero); eastCol=min(colSize-1,col+DEPTH1); southRow=min(rowSize-1,row+DEPTH2); prevCol=max(col-DEPTH3,zero); prevRow=max(row-DEPTH4,zero); nextCol=min(col+DEPTH3,colSize-1); nextRow=min(row+DEPTH4,rowSize-1); pAcc2->toPixel(northRow,westCol); for(int row1=northRow; row1 < southRow+1; ++row1) { for (int col1=westCol; col1 < eastCol+1; ++col1) { if((row1>=prevRow && row1<=nextRow) && (col1>=prevCol && col1<=nextCol)) { continue; } else { updateStatistics3(pAcc2->getColumnAsDouble(), total, total_sum, count); } pAcc2->nextColumn(); } pAcc2->nextRow(); } mean = total / count; std = sqrt(total_sum / count - mean * mean); int ELVI = (mean/std)*(mean/std); int v = (ELVI+1)/((ELVI*mean/(std*std))-1); pAcc2->toPixel(row,col); pDestAcc->toPixel(row,col); zstatistic = (pAcc2->getColumnAsDouble()-mean)/std; if(v<=7 && v>=0) { v=5; } if(v<=12 && v>7) { v=10; } if(v<=17 && v>12) { v=15; } if(v<=30 && v>17) { v=20; } if(v<=65 && v>30) { v=40; } if(v<=90 && v>65) { v=90; } for(int i=0; i<24; i++) { if((look_table1[i][0]=ELVI) && (look_table1[i][1]==v)) { threshold=look_table1[i][2]; } } if(zstatistic>threshold) { switchOnEncoding(pDesc->getDataType(), conversion1, pDestAcc->getColumn(), 1000.0); } else { switchOnEncoding(pDesc->getDataType(), conversion1, pDestAcc->getColumn(), 0.0); } total = 0.0; total_sum=0.0; threshold=100000.0; mean = 0.0; std = 0.0; count=0; pAcc->nextColumn(); } pAcc->nextRow(); } // Create a GCP layer /* SpatialDataWindow* pWindow = dynamic_cast<SpatialDataWindow*>(Service<DesktopServices>()->createWindow(pResultCube.get()->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView* pView = pWindow->getSpatialDataView(); */ 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()); // Create the GCP list if (pCube->isGeoreferenced() == true) { const vector<DimensionDescriptor>& rows = pDescriptor->getRows(); const vector<DimensionDescriptor>& columns = pDescriptor->getColumns(); if ((rows.empty() == false) && (columns.empty() == false)) { // Get the geocoordinates at the chip corners /* VERIFYNRV(rows.front().isActiveNumberValid() == true); VERIFYNRV(rows.back().isActiveNumberValid() == true); VERIFYNRV(columns.front().isActiveNumberValid() == true); VERIFYNRV(columns.back().isActiveNumberValid() == true); */ unsigned int startRow = rows.front().getActiveNumber(); unsigned int endRow = rows.back().getActiveNumber(); unsigned int startCol = columns.front().getActiveNumber(); unsigned int endCol = columns.back().getActiveNumber(); GcpPoint ulPoint; ulPoint.mPixel = LocationType(startCol, startRow); ulPoint.mCoordinate = pCube->convertPixelToGeocoord(ulPoint.mPixel); GcpPoint urPoint; urPoint.mPixel = LocationType(endCol, startRow); urPoint.mCoordinate = pCube->convertPixelToGeocoord(urPoint.mPixel); GcpPoint llPoint; llPoint.mPixel = LocationType(startCol, endRow); llPoint.mCoordinate = pCube->convertPixelToGeocoord(llPoint.mPixel); GcpPoint lrPoint; lrPoint.mPixel = LocationType(endCol, endRow); lrPoint.mCoordinate = pCube->convertPixelToGeocoord(lrPoint.mPixel); GcpPoint centerPoint; centerPoint.mPixel = LocationType((startCol + endCol) / 2, (startRow + endRow) / 2); centerPoint.mCoordinate = pCube->convertPixelToGeocoord(centerPoint.mPixel); /* // Reset the coordinates to be in active numbers relative to the chip const vector<DimensionDescriptor>& chipRows = pDescriptor->getRows(); const vector<DimensionDescriptor>& chipColumns = pDescriptor->getColumns(); VERIFYNRV(chipRows.front().isActiveNumberValid() == true); VERIFYNRV(chipRows.back().isActiveNumberValid() == true); VERIFYNRV(chipColumns.front().isActiveNumberValid() == true); VERIFYNRV(chipColumns.back().isActiveNumberValid() == true); unsigned int chipStartRow = chipRows.front().getActiveNumber(); unsigned int chipEndRow = chipRows.back().getActiveNumber(); unsigned int chipStartCol = chipColumns.front().getActiveNumber(); unsigned int chipEndCol = chipColumns.back().getActiveNumber(); ulPoint.mPixel = LocationType(chipStartCol, chipStartRow); urPoint.mPixel = LocationType(chipEndCol, chipStartRow); llPoint.mPixel = LocationType(chipStartCol, chipEndRow); lrPoint.mPixel = LocationType(chipEndCol, chipEndRow); centerPoint.mPixel = LocationType((chipStartCol + chipEndCol) / 2, (chipStartRow + chipEndRow) / 2); */ Service<ModelServices> pModel; GcpList* pGcpList = static_cast<GcpList*>(pModel->createElement("Corner Coordinates", TypeConverter::toString<GcpList>(), pResultCube.get())); if (pGcpList != NULL) { list<GcpPoint> gcps; gcps.push_back(ulPoint); gcps.push_back(urPoint); gcps.push_back(llPoint); gcps.push_back(lrPoint); gcps.push_back(centerPoint); pGcpList->addPoints(gcps); pView->createLayer(GCP_LAYER, pGcpList); } } } if (pProgress != NULL) { pProgress->updateProgress("CFAR is compete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("Result", pResultCube.release()); pStep->finalize(); return true; }
bool LocalSharpening::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Local Sharpening", "app", "08BB9B79-5D24-4AB0-9F35-92DE77CED8E7"); 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() + "_Local_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; LocalSharpeningDlg dlg(pDesktop->getMainWidget()); int stat = dlg.exec(); if (stat != QDialog::Accepted) { return true; } double contrastVal = dlg.getContrastValue(); int nFilterType = dlg.getCurrentFilterType(); int windowSize = dlg.getCurrentWindowSize(); windowSize = (windowSize-1)/2; for (unsigned int row = 0; row < pDesc->getRowCount(); ++row) { if (pProgress != NULL) { pProgress->updateProgress("Local sharpening", 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) { if (nFilterType == 0) { switchOnEncoding(ResultType, localAdaptiveSharpening, pDestAcc->getColumn(), pSrcAcc, row, col, pDesc->getRowCount(), pDesc->getColumnCount(), pDesc->getDataType(), windowSize, contrastVal); } else { switchOnEncoding(ResultType, localExtremeSharpening, pDestAcc->getColumn(), pSrcAcc, row, col, pDesc->getRowCount(), pDesc->getColumnCount(), pDesc->getDataType(), windowSize); } 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("Local sharpening is compete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("Local sharpening Result", pResultCube.release()); pStep->finalize(); return true; }
bool DataMergeGui::mergeData() { // Service<ModelServices> pModel; StepResource pStep("Data Merge Begin", "app", "5E4BCD48-E662-408b-93AF-F9127CE56C66"); if (mergeList->count() == 0) { QMessageBox::critical(NULL, "Spectral Data Merge", "No RasterElement to merge", "OK"); pStep->finalize(Message::Failure, "No RasterElement to merge"); return false; } // pProgress = new Progress(this, "Progress Reporter"); // std::vector<DataElement*> cubes = pModel->getElements("RasterElement"); /* if (mergeElementList.size() == 0) { QMessageBox::critical(NULL, "Spectral Data Merge", "No RasterElement input found!", "OK"); pStep->finalize(Message::Failure, "No RasterElement input found!"); return false; } */ //QListWidgetItem *tmpItem = mergeList->item(i0); //QString tmpItemText = tmpItem->text(); RasterElement* pInitData = extractRasterElement(mergeList->item(0)->text()); // vector<RasterElement*>::iterator initIter = mergeElementList.begin(); // RasterElement* pInitData = model_cast<RasterElement*>(*initIter); if (pInitData == NULL) { pStep->finalize(Message::Failure, "Cube Data error!"); QMessageBox::critical(this, "Error", "pInitData Error"); return false; } RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pInitData->getDataDescriptor()); EncodingType type = pDesc->getDataType(); int rowCount = pDesc->getRowCount(); int colCount = pDesc->getColumnCount(); int bandCount = mergeList->count(); RasterElement* pDesRaster = RasterUtilities::createRasterElement("DataMergeCube", rowCount, colCount, bandCount, type, BIP, true, NULL); if (pDesRaster == NULL) { QMessageBox::critical(NULL, "Spectral Data Merge", "Create RasterElement failed, Please close the previous merge result!", "OK"); pStep->finalize(Message::Failure, "No RasterElement input found!"); return false; } FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BIP); DataAccessor pDesAcc = pDesRaster->getDataAccessor(pRequest.release()); if (!pDesAcc.isValid()) { QMessageBox::critical(NULL, "Spectral Data Merge", "pDesRaster Data Accessor Error!", "OK"); pStep->finalize(Message::Failure, "pDesRaster Data Accessor Error!"); return false; } if (pProgress == NULL) { QMessageBox::critical(NULL, "Spectral Data Merge", "pProgress Initialize Error!", "OK"); pStep->finalize(Message::Failure, "pProgress Error!"); return false; } // progressDialog = new QProgressDialog(); // progressDialog->setRange(0, rowCount); //int index = 0; for (int i = 0; i < mergeList->count(); i++) { QListWidgetItem *tmpItem = mergeList->item(i); QString tmpItemText = tmpItem->text(); RasterElement* pData = extractRasterElement(tmpItemText); int band = extractMergeBand(tmpItemText); if (pData != NULL) { RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pData->getDataDescriptor()); if (rowCount != pDesc->getRowCount()) { QMessageBox::critical(NULL, "Spectral Data Merge", "Merge Data Format Error!", "OK"); pStep->finalize(Message::Failure, "Merge Data Row Format Error!"); return false; } if (colCount != pDesc->getColumnCount()) { QMessageBox::critical(NULL, "Spectral Data Merge", "Merge Data Format Error!", "OK"); pStep->finalize(Message::Failure, "Merge Data Column Format Error!"); return false; } // QMessageBox::about(this, "Test", "Here2"); FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BIP); // pRequest->setWritable(true); DataAccessor pSrcAcc = pData->getDataAccessor(pRequest.release()); switchOnEncoding(pDesc->getDataType(), mergeElement, NULL, rowCount, colCount, pSrcAcc, pDesAcc, i, band, pProgress, mergeList->count()); // QMessageBox::about(this, "Test", "Here5"); } else { QMessageBox::critical(this, "Error", "pData is NULL"); return false; } // mergeElementList.push_back(filenameMap[tmpItemText.toStdString()]); } Service<DesktopServices> pDesktop; SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>(pDesktop->createWindow("DataMergeResult", SPATIAL_DATA_WINDOW)); SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { pStep->finalize(Message::Failure, "SpatialDataView error!"); return false; } pView->setPrimaryRasterElement(pDesRaster); pView->createLayer(RASTER, pDesRaster); if (pDesc != NULL) { const RasterFileDescriptor* pFileDescriptor = dynamic_cast<const RasterFileDescriptor*>(pDesc->getFileDescriptor()); if (pFileDescriptor != NULL) { Service<ModelServices> pModel; if (pModel.get() != NULL) { list<GcpPoint> gcps; gcps = pFileDescriptor->getGcps(); if (gcps.empty() == true) { if (pInitData->isGeoreferenced()) { GcpPoint gcp; // Lower left gcp.mPixel.mX = 0.0; gcp.mPixel.mY = 0.0; gcp.mCoordinate = pInitData->convertPixelToGeocoord(gcp.mPixel); gcps.push_back(gcp); // Lower right gcp.mPixel.mX = colCount - 1; gcp.mPixel.mY = 0.0; gcp.mCoordinate = pInitData->convertPixelToGeocoord(gcp.mPixel); gcps.push_back(gcp); // Upper left gcp.mPixel.mX = 0.0; gcp.mPixel.mY = rowCount - 1; gcp.mCoordinate = pInitData->convertPixelToGeocoord(gcp.mPixel); gcps.push_back(gcp); // Upper right gcp.mPixel.mX = colCount - 1; gcp.mPixel.mY = rowCount - 1; gcp.mCoordinate = pInitData->convertPixelToGeocoord(gcp.mPixel); gcps.push_back(gcp); // Center gcp.mPixel.mX = colCount / 2.0; gcp.mPixel.mY = rowCount / 2.0; gcp.mCoordinate = pInitData->convertPixelToGeocoord(gcp.mPixel); gcps.push_back(gcp); } } if (gcps.empty() == false) { DataDescriptor* pGcpDescriptor = pModel->createDataDescriptor("Corner Coordinates", "GcpList", pDesRaster); if (pGcpDescriptor != NULL) { GcpList* pGcpList = static_cast<GcpList*>(pModel->createElement(pGcpDescriptor)); if (pGcpList != NULL) { // Add the GCPs to the GCP list pGcpList->addPoints(gcps); // Create the GCP list layer pView->createLayer(GCP_LAYER, pGcpList); } } } } } } return true; }
bool SignatureLibraryImp::resample(const vector<double> &abscissa) { if (mpOdre.get() == NULL) { return false; } if (abscissa == mAbscissa) { return true; } PlugInResource resampler("Resampler"); Resampler* pResampler = dynamic_cast<Resampler*>(resampler.get()); if (pResampler == NULL) { return false; } desample(); if (abscissa.empty()) { return true; } RasterDataDescriptor* pDesc = dynamic_cast<RasterDataDescriptor*>(mpOdre->getDataDescriptor()); VERIFY(pDesc != NULL); unsigned int numSigs = pDesc->getRowCount(); if (numSigs == 0) { return true; } mResampledData.resize(numSigs * abscissa.size()); DataAccessor da = mpOdre->getDataAccessor(); if (da.isValid() == false) { desample(); return false; } vector<double> originalOrdinateData(mOriginalAbscissa.size()); vector<double> toData; vector<double> toFwhm; vector<int> toBands; string errorMessage; for (unsigned int i = 0; i < mSignatures.size(); ++i) { switchOnEncoding(pDesc->getDataType(), getOriginalAsDouble, da->getRow(), mOriginalAbscissa.size(), originalOrdinateData); toData.clear(); toData.reserve(mAbscissa.size()); toBands.clear(); toBands.reserve(mAbscissa.size()); bool success = pResampler->execute(originalOrdinateData, toData, mOriginalAbscissa, abscissa, toFwhm, toBands, errorMessage); if (!success || toData.size() != abscissa.size()) { desample(); return false; } std::copy(toData.begin(), toData.end(), &mResampledData[i*abscissa.size()]); da->nextRow(); } mAbscissa = abscissa; mNeedToResample = false; notify(SIGNAL_NAME(Subject, Modified)); return true; }
bool TextureSegmentation::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("SAR image segmentation", "app", "CC430C1A-9D8C-4bb5-9254-FCF7EECAFA3C"); 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() + "_Segmentation_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()); 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 (NULL != pBuffer) { free(pBuffer); } pBuffer = (float *)malloc(sizeof(float)*pDesc->getRowCount()*pDesc->getColumnCount()); MakeSegmentation(pSrcAcc, pBuffer, pBuffer, pDesc->getRowCount(), pDesc->getColumnCount(), pDesc->getDataType()); //Output the value unsigned int nCount = 0; for (unsigned int j = 0; j < pDesc->getColumnCount(); j++) { for (unsigned int i = 0; i < pDesc->getRowCount(); i++) { 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; } pDestAcc->toPixel(i, j); switchOnEncoding(ResultType, restoreSegmentationValue, pDestAcc->getColumn(), (pBuffer+nCount)); nCount++; } } 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("Image segmentation is compete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("Image segmentation result", pResultCube.release()); pStep->finalize(); return true; }
std::vector<ImportDescriptor*> LandsatGeotiffImporter::createImportDescriptors(const std::string& filename, const DynamicObject* pImageMetadata, Landsat::LandsatImageType type) { std::string suffix; if (type == Landsat::LANDSAT_VNIR) { suffix = "vnir"; } else if (type == Landsat::LANDSAT_PAN) { suffix = "pan"; } else if (type == Landsat::LANDSAT_TIR) { suffix = "tir"; } std::vector<ImportDescriptor*> descriptors; std::string spacecraft = dv_cast<std::string>( pImageMetadata->getAttributeByPath("LANDSAT_MTL/L1_METADATA_FILE/PRODUCT_METADATA/SPACECRAFT_ID"), ""); std::vector<std::string> bandNames = Landsat::getSensorBandNames(spacecraft, type); if (bandNames.empty()) { //this spacecraft and iamge type //isn't meant to have any bands, so terminate early //e.g. spacecraft == "Landsat5" && type == Landsat::LANDSAT_PAN return descriptors; } std::vector<unsigned int> validBands; std::vector<std::string> bandFiles = Landsat::getGeotiffBandFilenames( pImageMetadata, filename, type, validBands); if (bandFiles.empty()) { mWarnings.push_back("Unable to locate band files for " + suffix + " product."); return descriptors; } ImportDescriptorResource pImportDescriptor(filename + "-" + suffix, TypeConverter::toString<RasterElement>(), NULL, false); if (pImportDescriptor.get() == NULL) { return descriptors; } RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pImportDescriptor->getDataDescriptor()); if (pDescriptor == NULL) { return descriptors; } pDescriptor->setProcessingLocation(ON_DISK); DynamicObject* pMetadata = pDescriptor->getMetadata(); pMetadata->merge(pImageMetadata); FactoryResource<RasterFileDescriptor> pFileDescriptorRes; pDescriptor->setFileDescriptor(pFileDescriptorRes.get()); RasterFileDescriptor* pFileDescriptor = dynamic_cast<RasterFileDescriptor*>(pDescriptor->getFileDescriptor()); pFileDescriptor->setFilename(filename); std::string tiffFile = bandFiles[0]; if (!Landsat::parseBasicsFromTiff(tiffFile, pDescriptor)) { mWarnings.push_back("Unable to parse basic information about image from tiff file for " + suffix + " product."); return descriptors; } if (pDescriptor->getBandCount() != 1 || pDescriptor->getDataType() != INT1UBYTE) { mWarnings.push_back("Improperly formatted tiff file for " + suffix + " product."); return descriptors; } pDescriptor->setInterleaveFormat(BSQ); //one tiff file per band. pFileDescriptor->setInterleaveFormat(BSQ); std::vector<DimensionDescriptor> bands = RasterUtilities::generateDimensionVector( bandFiles.size(), true, false, true); pDescriptor->setBands(bands); pFileDescriptor->setBands(bands); pDescriptor->setBadValues(std::vector<int>(1, 0)); pFileDescriptor->setDatasetLocation(suffix); //special metadata here Landsat::fixMtlMetadata(pMetadata, type, validBands); std::vector<std::string> defaultImport = OptionsLandsatImport::getSettingDefaultImport(); bool fallbackToDn = false; descriptors.push_back(pImportDescriptor.release()); if (type == Landsat::LANDSAT_VNIR) { //attempt to display true-color DimensionDescriptor redBand = RasterUtilities::findBandWavelengthMatch(0.630, 0.690, pDescriptor); DimensionDescriptor greenBand = RasterUtilities::findBandWavelengthMatch(0.510, 0.590, pDescriptor); DimensionDescriptor blueBand = RasterUtilities::findBandWavelengthMatch(0.410, 0.490, pDescriptor); if (redBand.isValid() && greenBand.isValid() && blueBand.isValid()) { pDescriptor->setDisplayMode(RGB_MODE); pDescriptor->setDisplayBand(RED, redBand); pDescriptor->setDisplayBand(GREEN, greenBand); pDescriptor->setDisplayBand(BLUE, blueBand); } } std::vector<std::pair<double, double> > radianceFactors = Landsat::determineRadianceConversionFactors( pMetadata, type, validBands); bool shouldDefaultImportRadiance = std::find(defaultImport.begin(), defaultImport.end(), suffix + "-Radiance") != defaultImport.end(); if (radianceFactors.size() == bandFiles.size()) { //we have enough to create radiance import descriptor RasterDataDescriptor* pRadianceDescriptor = dynamic_cast<RasterDataDescriptor*>( pDescriptor->copy(filename + "-" + suffix + "-radiance", NULL)); if (pRadianceDescriptor != NULL) { pRadianceDescriptor->setDataType(FLT4BYTES); pRadianceDescriptor->setValidDataTypes(std::vector<EncodingType>(1, pRadianceDescriptor->getDataType())); pRadianceDescriptor->setBadValues(std::vector<int>(1, -100)); FactoryResource<Units> pUnits; pUnits->setUnitType(RADIANCE); pUnits->setUnitName("w/(m^2*sr*um)"); pUnits->setScaleFromStandard(1.0); pRadianceDescriptor->setUnits(pUnits.get()); FileDescriptor* pRadianceFileDescriptor = pRadianceDescriptor->getFileDescriptor(); if (pRadianceFileDescriptor != NULL) { pRadianceFileDescriptor->setDatasetLocation(suffix + "-radiance"); ImportDescriptorResource pRadianceImportDescriptor(pRadianceDescriptor, shouldDefaultImportRadiance); descriptors.push_back(pRadianceImportDescriptor.release()); } } } else if (shouldDefaultImportRadiance) { fallbackToDn = true; } std::vector<double> reflectanceFactors = Landsat::determineReflectanceConversionFactors( pMetadata, type, validBands); bool shouldDefaultImportReflectance = std::find(defaultImport.begin(), defaultImport.end(), suffix + "-Reflectance") != defaultImport.end(); if (radianceFactors.size() == bandFiles.size() && reflectanceFactors.size() == bandFiles.size()) { //we have enough to create reflectance import descriptor RasterDataDescriptor* pReflectanceDescriptor = dynamic_cast<RasterDataDescriptor*>( pDescriptor->copy(filename + "-" + suffix + "-reflectance", NULL)); if (pReflectanceDescriptor != NULL) { pReflectanceDescriptor->setDataType(INT2SBYTES); pReflectanceDescriptor->setValidDataTypes( std::vector<EncodingType>(1, pReflectanceDescriptor->getDataType())); pReflectanceDescriptor->setBadValues(std::vector<int>(1, std::numeric_limits<short>::max())); FactoryResource<Units> pUnits; pUnits->setUnitType(REFLECTANCE); pUnits->setUnitName("Reflectance"); pUnits->setScaleFromStandard(1/10000.0); pReflectanceDescriptor->setUnits(pUnits.get()); FileDescriptor* pReflectanceFileDescriptor = pReflectanceDescriptor->getFileDescriptor(); if (pReflectanceFileDescriptor != NULL) { pReflectanceFileDescriptor->setDatasetLocation(suffix + "-reflectance"); ImportDescriptorResource pReflectanceImportDescriptor(pReflectanceDescriptor, shouldDefaultImportReflectance); descriptors.push_back(pReflectanceImportDescriptor.release()); } } } else if (shouldDefaultImportReflectance) { fallbackToDn = true; } double K1 = 0.0; double K2 = 0.0; bool haveTemperatureFactors = Landsat::getTemperatureConstants(pMetadata, type, K1, K2); bool shouldDefaultImportTemperature = std::find(defaultImport.begin(), defaultImport.end(), suffix + "-Temperature") != defaultImport.end(); if (radianceFactors.size() == bandFiles.size() && haveTemperatureFactors) { //we have enough to create temperature import descriptor RasterDataDescriptor* pTemperatureDescriptor = dynamic_cast<RasterDataDescriptor*>( pDescriptor->copy(filename + "-" + suffix + "-temperature", NULL)); if (pTemperatureDescriptor != NULL) { pTemperatureDescriptor->setDataType(FLT4BYTES); pTemperatureDescriptor->setValidDataTypes( std::vector<EncodingType>(1, pTemperatureDescriptor->getDataType())); pTemperatureDescriptor->setBadValues(std::vector<int>(1, -1)); FactoryResource<Units> pUnits; pUnits->setUnitType(EMISSIVITY); pUnits->setUnitName("K"); pUnits->setScaleFromStandard(1.0); pTemperatureDescriptor->setUnits(pUnits.get()); FileDescriptor* pTemperatureFileDescriptor = pTemperatureDescriptor->getFileDescriptor(); if (pTemperatureFileDescriptor != NULL) { pTemperatureFileDescriptor->setDatasetLocation(suffix + "-temperature"); ImportDescriptorResource pTemperatureImportDescriptor(pTemperatureDescriptor, shouldDefaultImportTemperature); descriptors.push_back(pTemperatureImportDescriptor.release()); } } } else if (shouldDefaultImportTemperature) { fallbackToDn = true; } if (fallbackToDn || std::find(defaultImport.begin(), defaultImport.end(), suffix + "-DN") != defaultImport.end()) { pImportDescriptor->setImported(true); } return descriptors; }
vector<ImportDescriptor*> EnviImporter::getImportDescriptors(const string& filename) { string headerFile = filename; string dataFile; bool bSuccess = parseHeader(headerFile); if (bSuccess == false) { dataFile = filename; // was passed data file name instead of header file name headerFile = findHeaderFile(headerFile); if (headerFile.empty() == false) { bSuccess = parseHeader(headerFile); } } EnviField* pField = NULL; vector<ImportDescriptor*> descriptors; if (bSuccess == true) { if (dataFile.empty() == true) // was passed header file name and now need to find the data file name { dataFile = findDataFile(headerFile); } if (dataFile.empty() == false) { ImportDescriptor* pImportDescriptor = mpModel->createImportDescriptor(dataFile, "RasterElement", NULL); if (pImportDescriptor != NULL) { RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pImportDescriptor->getDataDescriptor()); if (pDescriptor != NULL) { FactoryResource<RasterFileDescriptor> pFileDescriptor; if (pFileDescriptor.get() != NULL) { // Filename pFileDescriptor->setFilename(dataFile); // Coordinate offset int columnOffset = 0; int rowOffset = 0; pField = mFields.find("x start"); if (pField != NULL) { // ENVI numbers are 1 based vs Opticks being 0 based columnOffset = atoi(pField->mValue.c_str()) - 1; } pField = mFields.find("y start"); if (pField != NULL) { rowOffset = atoi(pField->mValue.c_str()) - 1; // ENVI numbers are 1 based vs Opticks being 0 based } // Rows vector<DimensionDescriptor> rows; pField = mFields.find("lines"); if (pField != NULL) { int numRows = atoi(pField->mValue.c_str()); for (int i = 0; i < numRows; ++i) { DimensionDescriptor rowDim; rowDim.setOriginalNumber(static_cast<unsigned int>(rowOffset + i)); rowDim.setOnDiskNumber(static_cast<unsigned int>(i)); rows.push_back(rowDim); } pDescriptor->setRows(rows); pFileDescriptor->setRows(rows); } string samplesStr = "samples"; string bandsStr = "bands"; // Special case: if the file type is an ENVI Spectral Library, then swap samples with bands // If no file type field exists, assume this is a normal ENVI header (not a Spectral Library) EnviField* pFileTypeField = mFields.find("file type"); if (pFileTypeField != NULL && (pFileTypeField->mValue == "ENVI Spectral Library" || pFileTypeField->mValue == "Spectral Library")) { samplesStr = "bands"; bandsStr = "samples"; // Since bands and samples are swapped, force the interleave to BIP pField = mFields.find("interleave"); if (pField != NULL) { pField->mValue = "bip"; } } // Columns vector<DimensionDescriptor> columns; pField = mFields.find(samplesStr); if (pField != NULL) { int numColumns = atoi(pField->mValue.c_str()); for (int i = 0; i < numColumns; ++i) { DimensionDescriptor columnDim; columnDim.setOriginalNumber(static_cast<unsigned int>(columnOffset + i)); columnDim.setOnDiskNumber(static_cast<unsigned int>(i)); columns.push_back(columnDim); } pDescriptor->setColumns(columns); pFileDescriptor->setColumns(columns); } // Bands vector<DimensionDescriptor> bands; pField = mFields.find(bandsStr); if (pField != NULL) { int numBands = atoi(pField->mValue.c_str()); bands = RasterUtilities::generateDimensionVector(numBands, true, false, true); pDescriptor->setBands(bands); pFileDescriptor->setBands(bands); } // Description list<GcpPoint> gcps; pField = mFields.find("description"); if (pField != NULL) { // Metadata if (pField->mChildren.empty() == false) { FactoryResource<DynamicObject> pMetadata; for (unsigned int i = 0; i < pField->mChildren.size(); ++i) { EnviField* pChild = pField->mChildren[i]; if (pChild != NULL) { if (pChild->mTag == "classification") { // Classification FactoryResource<Classification> pClassification; if (pClassification.get() != NULL) { string classLevel; classLevel.append(1, *(pChild->mValue.data())); pClassification->setLevel(classLevel); pDescriptor->setClassification(pClassification.get()); } } else if ((pChild->mTag == "ll") || (pChild->mTag == "lr") || (pChild->mTag == "ul") || (pChild->mTag == "ur") || (pChild->mTag == "center")) { GcpPoint gcp; bool dmsFormat = false; char ns; char ew; sscanf(pChild->mValue.c_str(), "%lg%c %lg%c", &gcp.mCoordinate.mY, &ew, &gcp.mCoordinate.mX, &ns); if (fabs(gcp.mCoordinate.mY) > 180.0 || fabs(gcp.mCoordinate.mX) > 90.0) { dmsFormat = true; } double deg; double min; double sec; if (dmsFormat == true) { deg = static_cast<int>(gcp.mCoordinate.mY / 10000.0); min = static_cast<int>((gcp.mCoordinate.mY - 10000.0 * deg) / 100.0); sec = gcp.mCoordinate.mY - 10000.0 * deg - 100.0 * min; gcp.mCoordinate.mY = deg + (min / 60.0) + (sec / 3600.0); } if (ew == 'W' || ew == 'w') { gcp.mCoordinate.mY = -gcp.mCoordinate.mY; } if (dmsFormat) { deg = static_cast<int>(gcp.mCoordinate.mX / 10000.0); min = static_cast<int>((gcp.mCoordinate.mX - 10000.0 * deg) / 100.0); sec = gcp.mCoordinate.mX - 10000.0 * deg - 100.0 * min; gcp.mCoordinate.mX = deg + (min / 60.0) + (sec / 3600.0); } if (ns == 'S' || ns == 's') { gcp.mCoordinate.mX = -gcp.mCoordinate.mX; } // ENVI uses a 1-based pixel coordinate system, with each coordinate referring // to the top-left corner of the pixel, e.g. (1,1) is the top-left // corner of the pixel in the top-left of the raster cube // The ENVI pixel coordinate format is described on p. 1126 of the ENVI 4.2 User's Guide if (pChild->mTag == "ll") { gcp.mPixel.mX = 0.0; gcp.mPixel.mY = 0.0; } else if (pChild->mTag == "lr") { gcp.mPixel.mX = columns.size() - 1.0; gcp.mPixel.mY = 0.0; } else if (pChild->mTag == "ul") { gcp.mPixel.mX = 0.0; gcp.mPixel.mY = rows.size() - 1.0; } else if (pChild->mTag == "ur") { gcp.mPixel.mX = columns.size() - 1.0; gcp.mPixel.mY = rows.size() - 1.0; } else if (pChild->mTag == "center") { gcp.mPixel.mX = floor((columns.size() - 1.0) / 2.0); gcp.mPixel.mY = floor((rows.size() - 1.0) / 2.0); } gcps.push_back(gcp); } else if (pChild->mTag.empty() == false) { pMetadata->setAttribute(pChild->mTag, pChild->mValue); } } } if (pMetadata->getNumAttributes() > 0) { pDescriptor->setMetadata(pMetadata.get()); } } } if (gcps.empty()) // not in description, check for geo points keyword { pField = mFields.find("geo points"); if (pField != NULL) { vector<double> geoValues; const int expectedNumValues = 16; // 4 values for each of the 4 corners geoValues.reserve(expectedNumValues); for (unsigned int i = 0; i < pField->mChildren.size(); i++) { vectorFromField(pField->mChildren.at(i), geoValues, "%lf"); } if (geoValues.size() == expectedNumValues) { vector<double>::iterator iter = geoValues.begin(); GcpPoint gcp; while (iter != geoValues.end()) { gcp.mPixel.mX = *iter++ - 1.0; // adjust ref point for ENVI's use of gcp.mPixel.mY = *iter++ - 1.0; // upper left corner and one-based first pixel gcp.mCoordinate.mX = *iter++; // GcpPoint has lat as mX and Lon as mY gcp.mCoordinate.mY = *iter++; // geo point field has lat then lon value gcps.push_back(gcp); } } } } // GCPs if (gcps.empty() == false) { pFileDescriptor->setGcps(gcps); } // Header bytes pField = mFields.find("header offset"); if (pField != NULL) { int headerBytes = atoi(pField->mValue.c_str()); pFileDescriptor->setHeaderBytes(static_cast<unsigned int>(headerBytes)); } // Data type pField = mFields.find("data type"); if (pField != NULL) { vector<EncodingType> validDataTypes; switch (atoi(pField->mValue.c_str())) { case 1: // char pDescriptor->setDataType(INT1UBYTE); pFileDescriptor->setBitsPerElement(8); // signed char cannot be represented in ENVI header so use the closest thing validDataTypes.push_back(INT1SBYTE); break; case 2: // short pDescriptor->setDataType(INT2SBYTES); pFileDescriptor->setBitsPerElement(16); break; case 3: // int pDescriptor->setDataType(INT4SBYTES); pFileDescriptor->setBitsPerElement(32); break; case 4: // float pDescriptor->setDataType(FLT4BYTES); pFileDescriptor->setBitsPerElement(32); break; case 5: // double pDescriptor->setDataType(FLT8BYTES); pFileDescriptor->setBitsPerElement(64); break; case 6: // float complex pDescriptor->setDataType(FLT8COMPLEX); pFileDescriptor->setBitsPerElement(64); break; case 9: // double complex // not supported break; case 12: // unsigned short pDescriptor->setDataType(INT2UBYTES); pFileDescriptor->setBitsPerElement(16); break; case 13: // unsigned int pDescriptor->setDataType(INT4UBYTES); pFileDescriptor->setBitsPerElement(32); break; case 14: // 64-bit int case 15: // unsigned 64-bit int // not supported break; case 99: // integer complex (recognized only by this application) pDescriptor->setDataType(INT4SCOMPLEX); pFileDescriptor->setBitsPerElement(32); break; default: break; } // Bad values EncodingType dataType = pDescriptor->getDataType(); if ((dataType != FLT4BYTES) && (dataType != FLT8COMPLEX) && (dataType != FLT8BYTES)) { vector<int> badValues; badValues.push_back(0); pDescriptor->setBadValues(badValues); } validDataTypes.push_back(dataType); pDescriptor->setValidDataTypes(validDataTypes); } // Interleave format pField = mFields.find("interleave"); if (pField != NULL) { string interleave = StringUtilities::toLower(pField->mValue); if (interleave == "bip") { pDescriptor->setInterleaveFormat(BIP); pFileDescriptor->setInterleaveFormat(BIP); } else if (interleave == "bil") { pDescriptor->setInterleaveFormat(BIL); pFileDescriptor->setInterleaveFormat(BIL); } else if (interleave == "bsq") { pDescriptor->setInterleaveFormat(BSQ); pFileDescriptor->setInterleaveFormat(BSQ); } } // Endian pField = mFields.find("byte order"); if (pField != NULL) { int byteOrder = atoi(pField->mValue.c_str()); if (byteOrder == 0) { pFileDescriptor->setEndian(LITTLE_ENDIAN_ORDER); } else if (byteOrder == 1) { pFileDescriptor->setEndian(BIG_ENDIAN_ORDER); } } // check for scaling factor pField = mFields.find("reflectance scale factor"); if (pField != NULL) { double scalingFactor = 0.0; stringstream scaleStream(pField->mValue); scaleStream >> scalingFactor; if (!scaleStream.fail() && scalingFactor != 0.0) { Units* pUnits = pDescriptor->getUnits(); if (pUnits != NULL) { pUnits->setScaleFromStandard(1.0 / scalingFactor); pUnits->setUnitName("Reflectance"); pUnits->setUnitType(REFLECTANCE); } } } // Pixel size pField = mFields.find("pixel size"); if (pField != NULL) { if (pField->mChildren.size() == 2) { pField = pField->mChildren[0]; if (pField != NULL) { double pixelSize = 1.0; if (sscanf(pField->mValue.c_str(), "%g", &pixelSize) == 1) { pDescriptor->setXPixelSize(pixelSize); pFileDescriptor->setXPixelSize(pixelSize); } } pField = pField->mChildren[1]; if (pField != NULL) { double pixelSize = 1.0; if (sscanf(pField->mValue.c_str(), "%g", &pixelSize) == 1) { pDescriptor->setYPixelSize(pixelSize); pFileDescriptor->setYPixelSize(pixelSize); } } } } // Default bands pField = mFields.find("default bands"); if (pField != NULL) { vector<unsigned int> displayBands; parseDefaultBands(pField, &displayBands); if (displayBands.size() == 1) { DimensionDescriptor grayBand = pFileDescriptor->getOriginalBand(displayBands[0]); pDescriptor->setDisplayBand(GRAY, grayBand); pDescriptor->setDisplayMode(GRAYSCALE_MODE); } else if (displayBands.size() == 3) { DimensionDescriptor redBand = pFileDescriptor->getOriginalBand(displayBands[0]); DimensionDescriptor greenBand = pFileDescriptor->getOriginalBand(displayBands[1]); DimensionDescriptor blueBand = pFileDescriptor->getOriginalBand(displayBands[2]); pDescriptor->setDisplayBand(RED, redBand); pDescriptor->setDisplayBand(GREEN, greenBand); pDescriptor->setDisplayBand(BLUE, blueBand); pDescriptor->setDisplayMode(RGB_MODE); } } // Bad bands pField = mFields.find("bbl"); if (pField != NULL) { vector<unsigned int> validBands; parseBbl(pField, validBands); vector<DimensionDescriptor> bandsToLoad; for (vector<unsigned int>::const_iterator iter = validBands.begin(); iter != validBands.end(); ++iter) { const unsigned int onDiskNumber = *iter; const DimensionDescriptor dim = pFileDescriptor->getOnDiskBand(onDiskNumber); if (dim.isValid()) { bandsToLoad.push_back(dim); } } pDescriptor->setBands(bandsToLoad); } DynamicObject* pMetadata = pDescriptor->getMetadata(); // Band names pField = mFields.find("band names"); if (pField != NULL) { vector<string> bandNames; bandNames.reserve(bands.size()); vector<string> strNames; for (vector<EnviField*>::size_type i = 0; i < pField->mChildren.size(); ++i) { strNames = StringUtilities::split(pField->mChildren[i]->mValue, ','); copy(strNames.begin(), strNames.end(), back_inserter(bandNames)); } vector<string>::iterator it; for (it = bandNames.begin(); it != bandNames.end(); ++it) { *it = StringUtilities::stripWhitespace(*it); } if (pMetadata != NULL) { string pNamesPath[] = { SPECIAL_METADATA_NAME, BAND_METADATA_NAME, NAMES_METADATA_NAME, END_METADATA_NAME }; pMetadata->setAttributeByPath(pNamesPath, bandNames); } } // wavelength units pField = mFields.find("wavelength units"); if (pField != NULL) { mWavelengthUnits = strToType(pField->mValue); } // Wavelengths vector<double> centerWavelengths; pField = mFields.find("wavelength"); if (pField != NULL) { if ((parseWavelengths(pField, ¢erWavelengths) == true) && (pMetadata != NULL)) { string pCenterPath[] = { SPECIAL_METADATA_NAME, BAND_METADATA_NAME, CENTER_WAVELENGTHS_METADATA_NAME, END_METADATA_NAME }; pMetadata->setAttributeByPath(pCenterPath, centerWavelengths); } } // FWHM pField = mFields.find("fwhm"); if (pField != NULL) { vector<double> startWavelengths; vector<double> endWavelengths; if ((parseFwhm(pField, &startWavelengths, ¢erWavelengths, &endWavelengths) == true) && (pMetadata != NULL)) { string pStartPath[] = { SPECIAL_METADATA_NAME, BAND_METADATA_NAME, START_WAVELENGTHS_METADATA_NAME, END_METADATA_NAME }; pMetadata->setAttributeByPath(pStartPath, startWavelengths); string pEndPath[] = { SPECIAL_METADATA_NAME, BAND_METADATA_NAME, END_WAVELENGTHS_METADATA_NAME, END_METADATA_NAME }; pMetadata->setAttributeByPath(pEndPath, endWavelengths); } } // File descriptor pDescriptor->setFileDescriptor(pFileDescriptor.get()); }
bool Tutorial3::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Tutorial 3", "app", "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()); 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 pAcc = pCube->getDataAccessor(pRequest.release()); double min = std::numeric_limits<double>::max(); double max = -min; double total = 0.0; for (unsigned int row = 0; row < pDesc->getRowCount(); ++row) { 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 (!pAcc.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; } if (pProgress != NULL) { pProgress->updateProgress("Calculating statistics", row * 100 / pDesc->getRowCount(), NORMAL); } for (unsigned int col = 0; col < pDesc->getColumnCount(); ++col) { switchOnEncoding(pDesc->getDataType(), updateStatistics, pAcc->getColumn(), min, max, total); pAcc->nextColumn(); } pAcc->nextRow(); } unsigned int count = pDesc->getColumnCount() * pDesc->getRowCount(); double mean = total / count; if (pProgress != NULL) { std::string msg = "Minimum value: " + StringUtilities::toDisplayString(min) + "\n" + "Maximum value: " + StringUtilities::toDisplayString(max) + "\n" + "Number of pixels: " + StringUtilities::toDisplayString(count) + "\n" + "Average: " + StringUtilities::toDisplayString(mean); pProgress->updateProgress(msg, 100, NORMAL); } pStep->addProperty("Minimum", min); pStep->addProperty("Maximum", max); pStep->addProperty("Count", count); pStep->addProperty("Mean", mean); pOutArgList->setPlugInArgValue("Minimum", &min); pOutArgList->setPlugInArgValue("Maximum", &max); pOutArgList->setPlugInArgValue("Count", &count); pOutArgList->setPlugInArgValue("Mean", &mean); pStep->finalize(); 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; }
ImportDescriptor* Nitf::NitfImporterShell::getImportDescriptor(const string& filename, ossim_uint32 imageSegment, const Nitf::OssimFileResource& pFile, const ossimNitfFileHeaderV2_X* pFileHeader, const ossimNitfImageHeaderV2_X* pImageSubheader) { if (pImageSubheader == NULL) { return NULL; } EncodingType dataType = ossimImageHeaderToEncodingType(pImageSubheader); if (dataType.isValid() == false) { return NULL; } stringstream imageNameStream; imageNameStream << "I" << imageSegment + 1; string imageName = imageNameStream.str(); ImportDescriptorResource pImportDescriptor(filename + "-" + imageName, TypeConverter::toString<RasterElement>(), NULL); VERIFYRV(pImportDescriptor.get() != NULL, NULL); pImportDescriptor->setImported(pImageSubheader->getRepresentation() != "NODISPLY"); RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pImportDescriptor->getDataDescriptor()); VERIFYRV(pDescriptor != NULL, NULL); vector<DimensionDescriptor> bands = RasterUtilities::generateDimensionVector(pImageSubheader->getNumberOfBands(), true, false, true); pDescriptor->setBands(bands); vector<DimensionDescriptor> rows = RasterUtilities::generateDimensionVector(pImageSubheader->getNumberOfRows(), true, false, true); pDescriptor->setRows(rows); vector<DimensionDescriptor> cols = RasterUtilities::generateDimensionVector(pImageSubheader->getNumberOfCols(), true, false, true); pDescriptor->setColumns(cols); if (pImageSubheader->getIMode() == "P") { pDescriptor->setInterleaveFormat(BIP); } else if (pImageSubheader->getIMode() == "R") { pDescriptor->setInterleaveFormat(BIL); } else { pDescriptor->setInterleaveFormat(BSQ); } pDescriptor->setDataType(dataType); pDescriptor->setValidDataTypes(vector<EncodingType>(1, dataType)); pDescriptor->setProcessingLocation(IN_MEMORY); map<string, TrePlugInResource> parsers; string errorMessage; // Set the file descriptor RasterFileDescriptor* pFileDescriptor = dynamic_cast<RasterFileDescriptor*>( RasterUtilities::generateAndSetFileDescriptor(pDescriptor, filename, imageName, LITTLE_ENDIAN_ORDER)); if (pFileDescriptor == NULL) { return NULL; } // Set the bits per element, which may be different than the data type in the data descriptor, // using NBPP instead of ABPP as is done in ossimNitfTileSource.cpp. unsigned int bitsPerPixel = static_cast<unsigned int>(pImageSubheader->getBitsPerPixelPerBand()); pFileDescriptor->setBitsPerElement(bitsPerPixel); // Populate the metadata and set applicable values in the data descriptor if (Nitf::importMetadata(imageSegment + 1, pFile, pFileHeader, pImageSubheader, pDescriptor, parsers, errorMessage) == true) { // Populate specific fields in the data descriptor or file descriptor from the TREs const DynamicObject* pMetadata = pDescriptor->getMetadata(); VERIFYRV(pMetadata, NULL); // Pixel size - This info is contained in multiple TREs, but there is no documentation on which // TRE contains the more precise value if multiple TREs containing the info are present. Choosing // the order ACFTA, BANDSA, ACFTB, and BANDSB where the later "B" TREs will overwrite the values // contained in the earlier "A" TREs. The BANDSB TRE contains GSD values for each band, which is // currently not supported, so only set the pixel size if the values in all bands are the same. double xGsd = 1.0; double yGsd = 1.0; const string acrftaPath[] = { Nitf::NITF_METADATA, Nitf::TRE_METADATA, "ACFTA", "0", END_METADATA_NAME }; const DynamicObject* pAcrftA = dv_cast<DynamicObject>(&pMetadata->getAttributeByPath(acrftaPath)); if (pAcrftA != NULL) { // The ACFTA spec calls out specific spacing units for "SAR" and "EO-IR" data, but does not indicate how // this is determined. It seems to be related to the ACFTB SENSOR_ID_TYPE field, but that field is not // present in the ACFTA TRE. So just check for "SAR" data from the ICAT field in the image subheader // and assume every other data type is "EO-IR" data. const string imageCategory = pImageSubheader->getCategory().trim(); const DataVariant& rowSpacing = pAcrftA->getAttribute(Nitf::TRE::ACFTA::ROW_SPACING); if (rowSpacing.isValid() == true) { if (imageCategory == "SAR") { yGsd = getGsd(rowSpacing, "f"); // Feet } else { yGsd = getGsd(rowSpacing, "r"); // Micro-radians } } const DataVariant& columnSpacing = pAcrftA->getAttribute(Nitf::TRE::ACFTA::COL_SPACING); if (columnSpacing.isValid() == true) { if (imageCategory == "SAR") { xGsd = getGsd(columnSpacing, "f"); // Feet } else { xGsd = getGsd(columnSpacing, "r"); // Micro-radians } } } const string bandsaPath[] = { Nitf::NITF_METADATA, Nitf::TRE_METADATA, "BANDSA", "0", END_METADATA_NAME }; const DynamicObject* pBandsA = dv_cast<DynamicObject>(&pMetadata->getAttributeByPath(bandsaPath)); if (pBandsA != NULL) { const DataVariant& rowSpacing = pBandsA->getAttribute(Nitf::TRE::BANDSA::ROW_SPACING); if (rowSpacing.isValid() == true) { const DataVariant& rowSpacingUnits = pBandsA->getAttribute(Nitf::TRE::BANDSA::ROW_SPACING_UNITS); if (rowSpacingUnits.isValid() == true) { yGsd = getGsd(rowSpacing, rowSpacingUnits.toXmlString()); } } const DataVariant& columnSpacing = pBandsA->getAttribute(Nitf::TRE::BANDSA::COL_SPACING); if (columnSpacing.isValid() == true) { const DataVariant& columnSpacingUnits = pBandsA->getAttribute(Nitf::TRE::BANDSA::COL_SPACING_UNITS); if (columnSpacingUnits.isValid() == true) { xGsd = getGsd(columnSpacing, columnSpacingUnits.toXmlString()); } } } const string acrftbPath[] = { Nitf::NITF_METADATA, Nitf::TRE_METADATA, "ACFTB", "0", END_METADATA_NAME }; const DynamicObject* pAcrftB = dv_cast<DynamicObject>(&pMetadata->getAttributeByPath(acrftbPath)); if (pAcrftB != NULL) { const DataVariant& rowSpacing = pAcrftB->getAttribute(Nitf::TRE::ACFTB::ROW_SPACING); if (rowSpacing.isValid() == true) { const DataVariant& rowSpacingUnits = pAcrftB->getAttribute(Nitf::TRE::ACFTB::ROW_SPACING_UNITS); if (rowSpacingUnits.isValid() == true) { yGsd = getGsd(rowSpacing, rowSpacingUnits.toXmlString()); } } const DataVariant& columnSpacing = pAcrftB->getAttribute(Nitf::TRE::ACFTB::COL_SPACING); if (columnSpacing.isValid() == true) { const DataVariant& columnSpacingUnits = pAcrftB->getAttribute(Nitf::TRE::ACFTB::COL_SPACING_UNITS); if (columnSpacingUnits.isValid() == true) { xGsd = getGsd(columnSpacing, columnSpacingUnits.toXmlString()); } } } const string bandsbPath[] = { Nitf::NITF_METADATA, Nitf::TRE_METADATA, "BANDSB", "0", END_METADATA_NAME }; const DynamicObject* pBandsB = dv_cast<DynamicObject>(&pMetadata->getAttributeByPath(bandsbPath)); if (pBandsB != NULL) { bool validRowGsd = false; const DataVariant& rowGsd = pBandsB->getAttribute(Nitf::TRE::BANDSB::ROW_GSD); if (rowGsd.isValid() == true) { const DataVariant& rowGsdUnits = pBandsB->getAttribute(Nitf::TRE::BANDSB::ROW_GSD_UNIT); if (rowGsdUnits.isValid() == true) { yGsd = getGsd(rowGsd, rowGsdUnits.toXmlString()); validRowGsd = true; } } if (validRowGsd == false) { if (pBandsB->getAttribute(Nitf::TRE::BANDSB::ROW_GSD + "#0").isValid()) { double commonYGsd = -1.0; unsigned int numBands = pDescriptor->getBandCount(); for (unsigned int i = 0; i < numBands; ++i) { double bandYGsd = -1.0; string bandPostfix = "#" + StringUtilities::toDisplayString(i); const DataVariant& bandRowGsd = pBandsB->getAttribute(Nitf::TRE::BANDSB::ROW_GSD + bandPostfix); if (bandRowGsd.isValid() == true) { const DataVariant& bandRowGsdUnits = pBandsB->getAttribute(Nitf::TRE::BANDSB::ROW_GSD_UNIT + bandPostfix); if (bandRowGsdUnits.isValid() == true) { bandYGsd = getGsd(bandRowGsd, bandRowGsdUnits.toXmlString()); } } if (bandYGsd == commonYGsd) { continue; } if (commonYGsd != -1.0) { commonYGsd = -1.0; break; } commonYGsd = bandYGsd; } if (commonYGsd != 1.0) { yGsd = commonYGsd; } } } bool validColumnGsd = false; const DataVariant& columnGsd = pBandsB->getAttribute(Nitf::TRE::BANDSB::COL_GSD); if (columnGsd.isValid() == true) { const DataVariant& columnGsdUnits = pBandsB->getAttribute(Nitf::TRE::BANDSB::COL_GSD_UNITS); if (columnGsdUnits.isValid() == true) { xGsd = getGsd(columnGsd, columnGsdUnits.toXmlString()); validColumnGsd = true; } } if (validColumnGsd == false) { if (pBandsB->getAttribute(Nitf::TRE::BANDSB::COL_GSD + "#0").isValid()) { double commonXGsd = -1.0; unsigned int numBands = pDescriptor->getBandCount(); for (unsigned int i = 0; i < numBands; ++i) { double bandXGsd = -1.0; string bandPostfix = "#" + StringUtilities::toDisplayString(i); const DataVariant& bandRowGsd = pBandsB->getAttribute(Nitf::TRE::BANDSB::COL_GSD + bandPostfix); if (bandRowGsd.isValid() == true) { const DataVariant& bandRowGsdUnits = pBandsB->getAttribute(Nitf::TRE::BANDSB::COL_GSD_UNIT + bandPostfix); if (bandRowGsdUnits.isValid() == true) { bandXGsd = getGsd(bandRowGsd, bandRowGsdUnits.toXmlString()); } } if (bandXGsd == commonXGsd) { continue; } if (commonXGsd != -1.0) { commonXGsd = -1.0; break; } commonXGsd = bandXGsd; } if (commonXGsd != 1.0) { xGsd = commonXGsd; } } } } double magFactor = 1.0; ossimString imag = pImageSubheader->getImageMagnification().trim(); if (imag.empty() == false) { // Need to multiply the GSD values by the image magnification (IMAG) value in the image subheader if (imag[0] == '/') { ossimString reciprocal = imag.substr(1); magFactor = 1.0 / reciprocal.toDouble(); } else { magFactor = imag.toDouble(); } xGsd *= magFactor; yGsd *= magFactor; } pDescriptor->setXPixelSize(xGsd); pDescriptor->setYPixelSize(yGsd); // Higher precision GCPs const string blockaPath[] = { Nitf::NITF_METADATA, Nitf::TRE_METADATA, "BLOCKA", "0", END_METADATA_NAME }; const DynamicObject* pBlockA = dv_cast<DynamicObject>(&pMetadata->getAttributeByPath(blockaPath)); if (pBlockA != NULL) { const DataVariant& blockLines = pBlockA->getAttribute(Nitf::TRE::BLOCKA::L_LINES); if (blockLines.isValid() == true) { unsigned int numBlockRows = 0; if (blockLines.getValue<unsigned int>(numBlockRows) == true) { // Need to multiply the number of rows by the image magnification (IMAG) value in the image subheader numBlockRows = static_cast<unsigned int>(static_cast<double>(numBlockRows) * magFactor); if (numBlockRows == pFileDescriptor->getRowCount()) { list<GcpPoint> updatedGcps; list<GcpPoint> gcps = pFileDescriptor->getGcps(); for (list<GcpPoint>::iterator iter = gcps.begin(); iter != gcps.end(); ++iter) { GcpPoint gcp = *iter; string coordinateText; list<GcpPoint>::size_type index = updatedGcps.size(); if (index == 0) { const DataVariant& gcp1 = pBlockA->getAttribute(Nitf::TRE::BLOCKA::FRFC_LOC); if (gcp1.isValid() == true) { coordinateText = gcp1.toXmlString(); } } else if (index == 1) { const DataVariant& gcp2 = pBlockA->getAttribute(Nitf::TRE::BLOCKA::FRLC_LOC); if (gcp2.isValid() == true) { coordinateText = gcp2.toXmlString(); } } else if (index == 2) { const DataVariant& gcp3 = pBlockA->getAttribute(Nitf::TRE::BLOCKA::LRLC_LOC); if (gcp3.isValid() == true) { coordinateText = gcp3.toXmlString(); } } else if (index == 3) { const DataVariant& gcp4 = pBlockA->getAttribute(Nitf::TRE::BLOCKA::LRFC_LOC); if (gcp4.isValid() == true) { coordinateText = gcp4.toXmlString(); } } if (StringUtilities::isAllBlank(coordinateText) == false) { coordinateText.insert(10, ", "); LatLonPoint latLon(coordinateText); gcp.mCoordinate = latLon.getCoordinates(); } updatedGcps.push_back(gcp); } pFileDescriptor->setGcps(updatedGcps); } } } } // This only checks the first BANDSB. It is possible to have multiple BANDSB TREs. // If someone runs across real data where the bad band info is in another BANDSB TRE // this code will need to be modified. if (pBandsB != NULL && pBandsB->getAttribute(Nitf::TRE::BANDSB::BAD_BAND + "#0").isValid()) { const vector<DimensionDescriptor>& curBands = pDescriptor->getBands(); vector<DimensionDescriptor> newBands; for (size_t idx = 0; idx < curBands.size(); ++idx) { const int* pVal = dv_cast<int>(&pBandsB->getAttribute( Nitf::TRE::BANDSB::BAD_BAND + "#" + StringUtilities::toDisplayString(idx))); if (pVal == NULL || *pVal == 1) // 0 == invalid or suspect band, 1 = valid band { newBands.push_back(curBands[idx]); } } pDescriptor->setBands(newBands); } // Bad values if (pImageSubheader->hasTransparentCode() == true) { vector<int> badValues; badValues.push_back(static_cast<int>(pImageSubheader->getTransparentCode())); pDescriptor->setBadValues(badValues); } // If red, green, OR blue bands are valid, set the display mode to RGB. if (pDescriptor->getDisplayBand(RED).isValid() == true || pDescriptor->getDisplayBand(GREEN).isValid() == true || pDescriptor->getDisplayBand(BLUE).isValid() == true) { pDescriptor->setDisplayMode(RGB_MODE); } // Otherwise, if the gray band is valid, set the display mode to GRAYSCALE. else if (pDescriptor->getDisplayBand(GRAY).isValid() == true) { pDescriptor->setDisplayMode(GRAYSCALE_MODE); } // Otherwise, if at least 3 bands are available, set the display mode to RGB, // and set the first three bands to red, green, and blue respectively. else if (bands.size() >= 3) { pDescriptor->setDisplayBand(RED, bands[0]); pDescriptor->setDisplayBand(GREEN, bands[1]); pDescriptor->setDisplayBand(BLUE, bands[2]); pDescriptor->setDisplayMode(RGB_MODE); } // Otherwise, if at least 1 band is available, set the display mode to GRAYSCALE, // and set the first band to GRAY. else if (bands.empty() == false) { pDescriptor->setDisplayBand(GRAY, bands[0]); pDescriptor->setDisplayMode(GRAYSCALE_MODE); } else { return NULL; } // Special initialization for J2K compressed image segments const string compressionPath[] = { Nitf::NITF_METADATA, Nitf::IMAGE_SUBHEADER, Nitf::ImageSubheaderFieldNames::COMPRESSION, END_METADATA_NAME }; string imageCompression = pMetadata->getAttributeByPath(compressionPath).toDisplayString(); if ((imageCompression == Nitf::ImageSubheaderFieldValues::IC_C8) || (imageCompression == Nitf::ImageSubheaderFieldValues::IC_M8)) { // Per Section 8.1 of the BIIF Profile for JPEG 2000 Version 01.10 (BPJ2K01.10), // if the values in the J2K data differ from the values in the image subheader, // the J2K values are given precedence. opj_image_t* pImage = getImageInfo(filename, imageSegment, OPJ_CODEC_J2K); if (pImage == NULL) { pImage = getImageInfo(filename, imageSegment, OPJ_CODEC_JP2); } if (pImage != NULL) { // Bits per element unsigned int bitsPerElement = pImage->comps->prec; if (bitsPerElement != pFileDescriptor->getBitsPerElement()) { pFileDescriptor->setBitsPerElement(bitsPerElement); } // Data type EncodingType dataType = INT1UBYTE; if (bitsPerElement <= 8) { if (pImage->comps->sgnd) { dataType = INT1SBYTE; } else { dataType = INT1UBYTE; } } else if (bitsPerElement <= 16) { if (pImage->comps->sgnd) { dataType = INT2SBYTES; } else { dataType = INT2UBYTES; } } else if (bitsPerElement <= 32) { if (pImage->comps->sgnd) { dataType = INT4SBYTES; } else { dataType = INT4UBYTES; } } else if (bitsPerElement <= 64) { dataType = FLT8BYTES; } if (dataType != pDescriptor->getDataType()) { pDescriptor->setDataType(dataType); } // Rows unsigned int numRows = pImage->comps->h; if (numRows != pFileDescriptor->getRowCount()) { vector<DimensionDescriptor> rows = RasterUtilities::generateDimensionVector(numRows, true, false, true); pDescriptor->setRows(rows); pFileDescriptor->setRows(rows); } // Columns unsigned int numColumns = pImage->comps->w; if (numColumns != pFileDescriptor->getColumnCount()) { vector<DimensionDescriptor> columns = RasterUtilities::generateDimensionVector(numColumns, true, false, true); pDescriptor->setColumns(columns); pFileDescriptor->setColumns(columns); } // Bands unsigned int numBands = pImage->numcomps; if (numBands != pFileDescriptor->getBandCount()) { vector<DimensionDescriptor> bands = RasterUtilities::generateDimensionVector(numBands, true, false, true); pDescriptor->setBands(bands); pFileDescriptor->setBands(bands); } // Cleanup opj_image_destroy(pImage); } // Set the interleave format as BIP, which is the interleave format for J2K data pDescriptor->setInterleaveFormat(BIP); pFileDescriptor->setInterleaveFormat(BIP); } mParseMessages[imageSegment] = errorMessage; } return pImportDescriptor.release(); }
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 pagauss::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Tutorial 5", "app", "5EA0CC75-9E0B-4c3d-BA23-6DB7157BBD54"); 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); if (pDesc->getDataType() == INT4SCOMPLEX || pDesc->getDataType() == FLT8COMPLEX) { std::string msg = "Edge detection cannot be performed on complex types."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } FactoryResource<DataRequest> pRequest; pRequest->setInterleaveFormat(BSQ); DataAccessor pSrcAcc = pCube->getDataAccessor(pRequest.release()); ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(pCube->getName() + "_Edge_Detection_Result", 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()); for (long signed 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 (long signed int col = 0; col < pDesc->getColumnCount(); ++col) { switchOnEncoding(pDesc->getDataType(), gauss, pDestAcc->getColumn(), pSrcAcc, row, col, pDesc->getRowCount(), pDesc->getColumnCount()); 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("pagauss is compete.", 100, NORMAL); } pOutArgList->setPlugInArgValue("pagauss_Result", pResultCube.release()); pStep->finalize(); return true; }
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 adaptive_median::copyImage4(RasterElement * pRaster, RasterElement * dRaster, int i, Progress * pProgress) { int flag = 0; int size = 3; int sizeMax = MAX_SIZE; 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) { VERIFY(pDestAcc.isValid()); switchOnEncoding(pDesc->getDataType(), adaptivemedian, pDestAcc->getColumn(), thirdBandDa, curRow, curCol, pDesc->getRowCount(), pDesc->getColumnCount(), size, sizeMax, pProgress, &flag); if (flag == 1 && size <= sizeMax) { // increase window size size = size + 2; curCol--; } else { pDestAcc->nextColumn(); size = 3; flag = 0; } } pDestAcc->nextRow(); } 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; }
bool ImageRegistration::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Image Registration", "app", "A2E0FC44-2A31-41EE-90F8-805773D01FCA"); if (pInArgList == NULL || pOutArgList == NULL) { return false; } Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); //RasterElement* pCube = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); std::vector<Window*> windows; Service<DesktopServices>()->getWindows(SPATIAL_DATA_WINDOW, windows); std::vector<RasterElement*> elements; for (unsigned int i = 0; i < windows.size(); ++i) { SpatialDataWindow* pWindow = dynamic_cast<SpatialDataWindow*>(windows[i]); if (pWindow == NULL) { continue; } LayerList* pList = pWindow->getSpatialDataView()->getLayerList(); elements.push_back(pList->getPrimaryRasterElement()); } RasterElement* pCube = elements[0]; RasterElement* pCubeRef = elements[1]; if ((pCube == NULL) || (pCubeRef == 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()); FactoryResource<DataRequest> pRequestRef; pRequestRef->setInterleaveFormat(BSQ); DataAccessor pSrcAccRef = pCubeRef->getDataAccessor(pRequestRef.release()); ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(pCube->getName() + "_Image_Registration_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; } std::vector<int> badValues = pDesc->getBadValues(); //badValues.push_back(0); RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(pResultCube->getDataDescriptor()); Statistics* pStatistics = pResultCube->getStatistics(pDescriptor->getActiveBand(0)); pStatistics->setBadValues(badValues); FactoryResource<DataRequest> pResultRequest; pResultRequest->setWritable(true); DataAccessor pDestAcc = pResultCube->getDataAccessor(pResultRequest.release()); nCountMas = 0; nCountRef = 0; int windowSize = 6; double *pBuffer = (double *)calloc(pDesc->getRowCount()*pDesc->getColumnCount(), sizeof(double)); GetGrayScale(pDesc->getDataType()); for (unsigned int row = 0; row < pDesc->getRowCount(); ++row) { if (pProgress != NULL) { pProgress->updateProgress("Image registration", 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; } for (unsigned int col = 0; col < pDesc->getColumnCount(); ++col) { locateAllStarPosition(pSrcAcc, pSrcAccRef, row, col, pDesc->getRowCount(), pDesc->getColumnCount(), pDesc->getDataType(), windowSize, pBuffer); } } ModifyCenter(pSrcAcc, pDesc->getDataType(), windowSize, nCountMas, nStarPositionsMas); ModifyCenter(pSrcAccRef, pDesc->getDataType(), windowSize, nCountRef, nStarPositionsRef); GetAllNeighborStars(); GetMatchingStars(); GetParameters(pDesc->getRowCount(), pDesc->getColumnCount()); DrawStars(pBuffer, pSrcAccRef, pDesc->getDataType(), matrixT, pDesc->getRowCount(), pDesc->getColumnCount()); //Output the value for (unsigned int m = 0; m < pDesc->getRowCount(); m++) { for (unsigned int n = 0; n < pDesc->getColumnCount(); n++) { 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; } switchOnEncoding(ResultType, updatePixel, pDestAcc->getColumn(), pBuffer, m, n, pDesc->getRowCount(), pDesc->getColumnCount()); pDestAcc->nextColumn(); } pDestAcc->nextRow(); } free(pBuffer); 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()); } double theta = std::acos(matrixT[0][0])*180.0/3.1415926; std::string msg = "Image Registration is complete.\n Translation x = " + StringUtilities::toDisplayString(round(shiftX)) + ", y = " + StringUtilities::toDisplayString(round(shiftY)) + ", rotation = " + StringUtilities::toDisplayString(round(theta)) + " degree"; if (pProgress != NULL) { pProgress->updateProgress(msg, 100, NORMAL); } pOutArgList->setPlugInArgValue("Image Registration Result", pResultCube.release()); pStep->finalize(); return true; }