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 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 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; }