bool Test_Update_TerraSAR::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Tutorial CEO", "app", "0FD3C564-041D-4f8f-BBF8-96A7A165AB61"); 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; DataAccessor pAcc = pCube->getDataAccessor(pRequest.release()); std::string path = pCube->getFilename(); DataDescriptor* dMeta = pCube->getDataDescriptor(); DynamicObject* Metadata = dMeta->getMetadata(); // RETRIEVE & UPDATE METADATA INFORMATION // TerraSAR_Metadata Prova_metadata; bool control = Prova_metadata.ReadFile(path); if (control == false) { std::string msg = "This is not a TerraSAR-X SLC Files, Metadata can't be updated"; pProgress->updateProgress(msg, 100, ERRORS); return false; } Prova_metadata.UpdateMetadata(Metadata); //SAR_Model ModProva(Prova_metadata,1000); SAR_Model *ModProva; //ModProva = new SAR_Ground_Model(Prova_metadata); ModProva = new SAR_Slant_Model(Prova_metadata); if(Prova_metadata.Projection == "SGF") { ModProva = new SAR_Ground_Model(Prova_metadata); } //else //{ // ModProva = new SAR_Slant_Model(Prova_metadata); //} // WIDGET SELECT & RETRIEVE GCPs INFORMATION // GcpList * GCPs = NULL; Service<ModelServices> pModel; std::vector<DataElement*> pGcpLists = pModel->getElements(pCube, TypeConverter::toString<GcpList>()); std::list<GcpPoint> Punti; if (!pGcpLists.empty()) { QStringList aoiNames("<none>"); for (std::vector<DataElement*>::iterator it = pGcpLists.begin(); it != pGcpLists.end(); ++it) { aoiNames << QString::fromStdString((*it)->getName()); } QString aoi = QInputDialog::getItem(Service<DesktopServices>()->getMainWidget(), "Select a GCP List", "Select a GCP List for validate the orientation model", aoiNames); if (aoi != "<none>") { std::string strAoi = aoi.toStdString(); for (std::vector<DataElement*>::iterator it = pGcpLists.begin(); it != pGcpLists.end(); ++it) { if ((*it)->getName() == strAoi) { GCPs = static_cast<GcpList*>(*it); break; } } if (GCPs == NULL) { std::string msg = "Invalid GCPList."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } } else { std::string msg = "A set of GCPs must be specified."; pStep->finalize(Message::Failure, msg); if (pProgress != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return false; } // UPDATE GCPs HEIGHT INFORMATION AND SWITCH Lat&Lon COORDINATE FOR CORRECT VISUALIZAZION IN THE GCPs EDITOR Punti = GCPs->getSelectedPoints(); Punti = Prova_metadata.UpdateGCP(Punti, path, pProgress); P_COORD Punto; int N=Punti.size(); int n=0, indexP=0; double Lat, Lon; accumulator_set<double, stats<tag::mean, tag::variance> > accX, accY; list<GcpPoint>::iterator pList; for (pList = Punti.begin(); pList != Punti.end(); pList++) { if(pList->mPixel.mX<Prova_metadata.Width && pList->mPixel.mY<Prova_metadata.Height) { Lon = pList->mCoordinate.mX; Lat = pList->mCoordinate.mY; Punto = ModProva->SAR_GroundToImage(pList->mCoordinate.mX,pList->mCoordinate.mY,pList->mCoordinate.mZ); //pList->mRmsError.mX = pList->mPixel.mX -Punto.I; //pList->mRmsError.mY = pList->mPixel.mY -Punto.J; pList->mPixel.mX = (Prova_metadata.Grid_Range_Time/Prova_metadata.RowSpacing)*(indexP-int(indexP/Prova_metadata.Grid_N_Range)*Prova_metadata.Grid_N_Range); pList->mRmsError.mX = (Prova_metadata.Grid_Range_Time/Prova_metadata.RowSpacing)*(indexP-int(indexP/Prova_metadata.Grid_N_Range)*Prova_metadata.Grid_N_Range) -Punto.I; pList->mPixel.mY = (Prova_metadata.Grid_Azimuth_Time*Prova_metadata.PRF)*int(indexP/Prova_metadata.Grid_N_Range); pList->mRmsError.mY = (Prova_metadata.Grid_Azimuth_Time*Prova_metadata.PRF)*int(indexP/Prova_metadata.Grid_N_Range) - Punto.J; accX(pList->mRmsError.mX); accY(pList->mRmsError.mY); pList->mCoordinate.mX = Lat; pList->mCoordinate.mY = Lon; } else { Lon = pList->mCoordinate.mX; Lat = pList->mCoordinate.mY; pList->mRmsError.mX = -9999; pList->mRmsError.mY = -9999; pList->mCoordinate.mX = Lat; pList->mCoordinate.mY = Lon; } if (pProgress != NULL) { pProgress->updateProgress("Calculating statistics", int(100*n/N), NORMAL); } n++; indexP++; } double meanX = mean(accX); double meanY = mean(accY); double varX = variance(accX); double varY = variance(accY); GCPs->clearPoints(); GCPs->addPoints(Punti); if (pProgress != NULL) { std::string msg = "Number of Rows : " + StringUtilities::toDisplayString(pDesc->getRowCount()) + "\n" "Number of Columns : " + StringUtilities::toDisplayString(pDesc->getColumnCount()) + "\n\n" "Metadata update completed" + "\n\n" "********** Validation Results **********" "\n\n" "Number of GCPs: " + StringUtilities::toDisplayString(Punti.size()) + "\n\n" "Mean I : " + StringUtilities::toDisplayString(meanX) + "\n" "Variance I : " + StringUtilities::toDisplayString(varX) + "\n\n" "Mean J : " + StringUtilities::toDisplayString(meanY) + "\n" "Variance J : " + StringUtilities::toDisplayString(varY) + "\n\n" ; pProgress->updateProgress(msg, 100, NORMAL); } } // End if GcpList else { Punti.resize(Prova_metadata.Grid_N); Punti = Prova_metadata.UpdateGCP(Punti, path); } pStep->finalize(); return true; }
void Simulation_GUI::CheckModel() { ProgressResource pProgress("ProgressBar"); RasterDataDescriptor* pDesc = static_cast<RasterDataDescriptor*>(pCube->getDataDescriptor()); FactoryResource<DataRequest> pRequest; DataAccessor pAcc = pCube->getDataAccessor(pRequest.release()); DataDescriptor* dMeta = pCube->getDataDescriptor(); DynamicObject* oMetadata = dMeta->getMetadata(); // RETRIEVE & UPDATE METADATA INFORMATION // bool control = Metadata->ReadFile(image_path); Metadata->UpdateMetadata(oMetadata); // WIDGET SELECT & RETRIEVE GCPs INFORMATION // GcpList * GCPs = NULL; Service<ModelServices> pModel; std::vector<DataElement*> pGcpLists = pModel->getElements(pCube, TypeConverter::toString<GcpList>()); if (!pGcpLists.empty()) { QStringList aoiNames("<none>"); for (std::vector<DataElement*>::iterator it = pGcpLists.begin(); it != pGcpLists.end(); ++it) { aoiNames << QString::fromStdString((*it)->getName()); } QString aoi = QInputDialog::getItem(Service<DesktopServices>()->getMainWidget(), "Select a GCP List", "Select a GCP List for validate the orientation model", aoiNames); if (aoi != "<none>") { std::string strAoi = aoi.toStdString(); for (std::vector<DataElement*>::iterator it = pGcpLists.begin(); it != pGcpLists.end(); ++it) { if ((*it)->getName() == strAoi) { GCPs = static_cast<GcpList*>(*it); break; } } if (GCPs == NULL) { std::string msg = "Invalid GCPList."; pProgress->updateProgress(msg, 0, ERRORS); return; } } else { std::string msg = "A set of GCPs must be specified."; if (pProgress.get() != NULL) { pProgress->updateProgress(msg, 0, ERRORS); } return; } } // End if GcpList // UPDATE GCPs HEIGHT INFORMATION AND SWITCH Lat&Lon COORDINATE FOR CORRECT VISUALIZAZION IN THE GCPs EDITOR std::list<GcpPoint> Punti = GCPs->getSelectedPoints(); Punti = Metadata->UpdateGCP(Punti, image_path); //SAR_Model ModProva(*Metadata); SAR_Model *ModProva; //ModProva = new SAR_Ground_Model(Prova_metadata); ModProva = new SAR_Slant_Model(*Metadata); if(Metadata->Projection == "SGF") { ModProva = new SAR_Ground_Model(*Metadata); } P_COORD Punto; int N=Punti.size(); int n=0; double Lat, Lon; accumulator_set<double, stats<tag::mean, tag::variance> > accX, accY; list<GcpPoint>::iterator pList; for (pList = Punti.begin(); pList != Punti.end(); pList++) { if(pList->mPixel.mX<Metadata->Width && pList->mPixel.mY<Metadata->Height) { Lon = pList->mCoordinate.mX; Lat = pList->mCoordinate.mY; Punto = ModProva->SAR_GroundToImage(pList->mCoordinate.mX,pList->mCoordinate.mY,pList->mCoordinate.mZ); pList->mRmsError.mX = pList->mPixel.mX -Punto.I; pList->mRmsError.mY = pList->mPixel.mY -Punto.J; accX(pList->mRmsError.mX); accY(pList->mRmsError.mY); pList->mCoordinate.mX = Lat; pList->mCoordinate.mY = Lon; } else { Lon = pList->mCoordinate.mX; Lat = pList->mCoordinate.mY; pList->mRmsError.mX = -9999; pList->mRmsError.mY = -9999; pList->mCoordinate.mX = Lat; pList->mCoordinate.mY = Lon; } pProgress->updateProgress("Calculating statistics", int(100*n/N), NORMAL); n++; } double meanX = mean(accX); double meanY = mean(accY); double varX = variance(accX); double varY = variance(accY); GCPs->clearPoints(); GCPs->addPoints(Punti); std::string msg = "Number of Rows : " + StringUtilities::toDisplayString(pDesc->getRowCount()) + "\n" "Number of Columns : " + StringUtilities::toDisplayString(pDesc->getColumnCount()) + "\n\n" "Metadata update completed" + "\n\n" "********** Validation Results **********" "\n\n" "Number of GCPs: " + StringUtilities::toDisplayString(Punti.size()) + "\n\n" "Mean I : " + StringUtilities::toDisplayString(meanX) + "\n" "Variance I : " + StringUtilities::toDisplayString(varX) + "\n\n" "Mean J : " + StringUtilities::toDisplayString(meanY) + "\n" "Variance J : " + StringUtilities::toDisplayString(varY) + "\n\n" ; pProgress->updateProgress(msg, 100, NORMAL); // pStep->finalize(); }
bool SampleGeoref::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { // Do any kind of setup we need before converting coordinates. // In this case, get our X and Y factors. StepResource pStep("Run Sample Georef", "app", "CFCB8AA9-D504-42e9-86F0-547DF9B4798A"); Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); FAIL_IF(!isBatch(), "Interactive mode is not supported.", return false); // Default values bool animated = false; // get factors from pInArgList pInArgList->getPlugInArgValue("XSize", mXSize); pInArgList->getPlugInArgValue("YSize", mYSize); pInArgList->getPlugInArgValue("Extrapolate", mExtrapolate); pInArgList->getPlugInArgValue("Animated", animated); pInArgList->getPlugInArgValue("Rotate", mRotate); View* pView = pInArgList->getPlugInArgValue<View>(Executable::ViewArg()); mpRaster = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); FAIL_IF(mpRaster == NULL, "Could not find raster element", return false); if (mpGui != NULL) { mXSize = mpGui->getXSize(); mYSize = mpGui->getYSize(); animated = mpGui->getAnimated(); mRotate = mpGui->getRotate(); mExtrapolate = mpGui->getExtrapolate(); } if (animated) { SpatialDataView* pSpatialView = dynamic_cast<SpatialDataView*>(pView); FAIL_IF(pSpatialView == NULL, "Could not find spatial data view.", return false); LayerList* pLayerList = pSpatialView->getLayerList(); FAIL_IF(pLayerList == NULL, "Could not find layer list.", return false); RasterLayer* pLayer = dynamic_cast<RasterLayer*>(pLayerList->getLayer(RASTER, mpRaster)); FAIL_IF(pLayer == NULL, "Could not find raster layer", return false); Animation* pAnim = pLayer->getAnimation(); FAIL_IF(pAnim == NULL, "Could not find animation", return false); const std::vector<AnimationFrame>& frames = pAnim->getFrames(); FAIL_IF(frames.empty(), "No frames in animation.", return false); mpAnimation.reset(pAnim); mFrames = frames.size(); mCurrentFrame = 0; } RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(mpRaster->getDataDescriptor()); FAIL_IF(pDescriptor == NULL, "Could not get data descriptor.", return false); unsigned int rows = pDescriptor->getRowCount(); unsigned int cols = pDescriptor->getColumnCount(); unsigned int bands = pDescriptor->getBandCount(); mXScale = static_cast<double>(mXSize) / rows; mYScale = static_cast<double>(mYSize) / cols; mpRaster->setGeoreferencePlugin(this); mpGui = NULL; // Pointer not guaranteed to be valid after execute() is called return true; }
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 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 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 SignatureLibraryImp::resample(const vector<double> &abscissa) { if (mpOdre.get() == NULL) { return false; } if (mResampledData.empty() == false && mNeedToResample == false && 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; }
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 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 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 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; }
int getRowCount() { return pDataDescriptor->getRowCount(); }
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 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 SignatureLibraryImp::import(const string &filename, const string &importerName, Progress* pProgress) { ImporterResource importer(importerName, filename, pProgress); vector<ImportDescriptor*> descs = importer->getImportDescriptors(); RasterDataDescriptor* pCubeDescriptor = NULL; if (descs.size() == 1 && descs.front() != NULL) { pCubeDescriptor = dynamic_cast<RasterDataDescriptor*>(descs.front()->getDataDescriptor()); } if (pCubeDescriptor != NULL) { // Disable auto-georeference GeoreferenceDescriptor* pGeorefDescriptor = pCubeDescriptor->getGeoreferenceDescriptor(); if (pGeorefDescriptor != NULL) { pGeorefDescriptor->setGeoreferenceOnImport(false); } pCubeDescriptor->setProcessingLocation(ON_DISK); bool cubeSuccess = importer->execute(); if (cubeSuccess) { vector<DataElement*> importedElements = importer->getImportedElements(); if (!importedElements.empty()) { RasterElement* pCube = dynamic_cast<RasterElement*>(importedElements.front()); Service<ModelServices>()->setElementParent(pCube, dynamic_cast<DataElement*>(this)); if (pCube != NULL) { clear(); mpOdre.reset(pCube); DynamicObject* pMetadata = getMetadata(); if (pMetadata != NULL) { string pCenterPath[] = { SPECIAL_METADATA_NAME, BAND_METADATA_NAME, CENTER_WAVELENGTHS_METADATA_NAME, END_METADATA_NAME }; mOriginalAbscissa = dv_cast<vector<double> >( pMetadata->getAttributeByPath(pCenterPath), vector<double>()); vector<string> sigNames = dv_cast<vector<string> >(pMetadata->getAttribute("Signature Names"), vector<string>()); SignatureLibrary* pLib = dynamic_cast<SignatureLibrary*>(this); VERIFY(pLib != NULL); unsigned int numSigs = pCubeDescriptor->getRowCount(); mSignatures.reserve(numSigs); for (unsigned int i = 0; i < numSigs; ++i) { string name; if (i >= sigNames.size()) { stringstream stream; stream << "Signature " << i+1; name = stream.str(); } else { name = sigNames[i]; } DataDescriptor* pDataDesc = Service<ModelServices>()->createDataDescriptor(name, "DataElement", pLib); DataDescriptorImp* pSigDesc = dynamic_cast<DataDescriptorImp*>(pDataDesc); mSignatures.push_back(new LibrarySignatureAdapter(*pSigDesc, SessionItemImp::generateUniqueId(), i, pLib)); mSignatureNames[name] = mSignatures.back(); } } notify(SIGNAL_NAME(Subject, Modified)); return true; } } } } return false; }
bool SampleGeoref::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { // Do any kind of setup we need before converting coordinates. // In this case, get our X and Y factors. StepResource pStep("Run Sample Georef", "app", "CFCB8AA9-D504-42e9-86F0-547DF9B4798A"); Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); FAIL_IF(!isBatch(), "Interactive mode is not supported.", return false); mpRaster = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); FAIL_IF(mpRaster == NULL, "Could not find the raster element", return false); // Get the values from the input args bool xSizeArgSet = pInArgList->getPlugInArgValue("XSize", mXSize); bool ySizeArgSet = pInArgList->getPlugInArgValue("YSize", mYSize); bool extrapolateArgSet = pInArgList->getPlugInArgValue("Extrapolate", mExtrapolate); // If the arg values are not set, get the values from the georeference descriptor; // otherwise update the georeference descriptor with the arg values RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*>(mpRaster->getDataDescriptor()); FAIL_IF(pDescriptor == NULL, "Could not get the data descriptor.", return false); GeoreferenceDescriptor* pGeorefDescriptor = pDescriptor->getGeoreferenceDescriptor(); if (pGeorefDescriptor != NULL) { if (xSizeArgSet == false) { mXSize = dv_cast<int>(pGeorefDescriptor->getAttributeByPath("SampleGeoref/XSize"), mXSize); } if (ySizeArgSet == false) { mYSize = dv_cast<int>(pGeorefDescriptor->getAttributeByPath("SampleGeoref/YSize"), mYSize); } if (extrapolateArgSet == false) { mExtrapolate = dv_cast<bool>(pGeorefDescriptor->getAttributeByPath("SampleGeoref/Extrapolate"), mExtrapolate); } } // Calculate the scale for the georeference unsigned int rows = pDescriptor->getRowCount(); unsigned int cols = pDescriptor->getColumnCount(); mXScale = static_cast<double>(mXSize) / rows; mYScale = static_cast<double>(mYSize) / cols; // Set the georeference plug-in into the raster element mpRaster->setGeoreferencePlugin(this); // Update the georeference descriptor with the current georeference parameters if necessary if (pGeorefDescriptor != NULL) { // Georeference plug-in const std::string& plugInName = getName(); pGeorefDescriptor->setGeoreferencePlugInName(plugInName); // X-size if (xSizeArgSet == true) { pGeorefDescriptor->setAttributeByPath("SampleGeoref/XSize", mXSize); } // Y-size if (ySizeArgSet == true) { pGeorefDescriptor->setAttributeByPath("SampleGeoref/YSize", mYSize); } // Extrapolate if (extrapolateArgSet == true) { pGeorefDescriptor->setAttributeByPath("SampleGeoref/Extrapolate", mExtrapolate); } } pStep->finalize(Message::Success); return true; }
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; }