uint32_t setGcpPoints(DataElement* pList, uint32_t count, struct Gcp* pPoints) { GcpList* pGcpList = dynamic_cast<GcpList*>(pList); if (pGcpList == NULL || (count > 0 && pPoints == NULL)) { setLastError(SIMPLE_BAD_PARAMS); return 0; } pGcpList->clearPoints(); if (count == 0) { setLastError(SIMPLE_NO_ERROR); return 0; } std::list<GcpPoint> points; for (uint32_t index = 0; index < count; ++index) { GcpPoint point; memcpy(&point, &pPoints[index], sizeof(struct Gcp)); points.push_back(point); } pGcpList->addPoints(points); setLastError(SIMPLE_NO_ERROR); return pGcpList->getCount(); }
void SetGcpPoints::executeRedo() { GcpList* pGcpList = dynamic_cast<GcpList*>(getSessionItem()); if (pGcpList != NULL) { if (pGcpList->getSelectedPoints() != mNewPoints) { pGcpList->clearPoints(); pGcpList->addPoints(mNewPoints); } } }
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 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; }
bool GcpGeoreference::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { StepResource pStep("Run GCP Georeference", "app", "296120A0-1CD5-467E-A501-934BCA7775EA"); Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()); mpProgress = pProgress; FAIL_IF(!isBatch(), "Interactive mode is not supported.", return false); int numPoints; PlugInArg* pArg = NULL; mpRaster = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); FAIL_IF(mpRaster == NULL, "Unable to find raster element input", return false); GcpList* pGcpList = NULL; if (mpGui != NULL) { mOrder = mpGui->getOrder(); string gcpListName = mpGui->getGcpListName(); if (gcpListName.empty() == false) { pGcpList = static_cast<GcpList*>(mpDataModel->getElement(gcpListName, TypeConverter::toString<GcpList>(), mpRaster)); } } else { pInArgList->getPlugInArgValue<int>("Order", mOrder); pGcpList = pInArgList->getPlugInArgValue<GcpList>(Georeference::GcpListArg()); } if (pGcpList != NULL) { pStep->addProperty("gcpList", pGcpList->getName()); } pStep->addProperty("polynomialOrder", mOrder); FAIL_IF(pGcpList == NULL, "Unable to find GCP list.", return false); if ((mOrder <= 0) || (mOrder > MAX_ORDER)) { if (mpProgress) { stringstream buffer; buffer << "Invalid polynomial order: " << mOrder << "\nThe order must be between 1 and " << MAX_ORDER << " (inclusive)"; mpProgress->updateProgress(buffer.str(), 0, ERRORS); } pStep->addProperty("Max Polynomial Order", MAX_ORDER); pStep->finalize(Message::Failure, "Invalid polynomial order"); return false; } mReverseOrder = min(MAX_ORDER, mOrder+1); int numCoeffs = COEFFS_FOR_ORDER(mOrder); numPoints = pGcpList->getSelectedPoints().size(); if (numPoints < numCoeffs) { if (mpProgress) { stringstream buffer; buffer << "Too few ground control points.\n" << "A polynomial fit of order " << mOrder << "\nrequires at least " << numCoeffs << " GCPs."; mpProgress->updateProgress(buffer.str(), 0, ERRORS); } pStep->addProperty("Required GCPs", numCoeffs); pStep->finalize(Message::Failure, "Too few ground control points"); return false; } int numReverseCoeffs = COEFFS_FOR_ORDER(mReverseOrder); vector<double> latCoeffs(numCoeffs); vector<double> lonCoeffs(numCoeffs); vector<double> pXCoeffs(numReverseCoeffs); vector<double> pYCoeffs(numReverseCoeffs); vector<LocationType> latlonValues(numPoints); vector<LocationType> pixelValues(numPoints); double maxLonSeparation(0.0); list<GcpPoint>::const_iterator it; unsigned int i; unsigned int j; for (i = 0, it = pGcpList->getSelectedPoints().begin(); it != pGcpList->getSelectedPoints().end(); ++it, ++i) { pixelValues[i] = it->mPixel; latlonValues[i] = it->mCoordinate; } // Find the maximum separation to determine if it is the antimeridian or the poles for (i = 0; i < pGcpList->getSelectedPoints().size(); ++i) { for (j = i + 1; j < pGcpList->getSelectedPoints().size(); ++j) { if (fabs(latlonValues[i].mY - latlonValues[j].mY) > maxLonSeparation) { maxLonSeparation = fabs(latlonValues[i].mY - latlonValues[j].mY); } } } bool badValues = true; bool badPixelValues = true; for (i = 0; i < pGcpList->getSelectedPoints().size(); ++i) { for (j = i + 1; j < pGcpList->getSelectedPoints().size(); ++j) { if (fabs(latlonValues[i].mX - latlonValues[j].mX) > 1e-20) { badValues = false; break; } if (fabs(latlonValues[i].mY - latlonValues[j].mY) > 1e-20) { badValues = false; break; } } } #pragma message(__FILE__ "(" STRING(__LINE__) ") : warning : This is a short term solution " \ "the draw method in LatLonLayer needs to be changed! (mconsidi)") // Special lon cases of the Antimeridian and poles // A value of more than 180.0 in maxLonSeparation indicates a special condition if (maxLonSeparation > 180.0) { for (i = 0; i < pGcpList->getSelectedPoints().size(); ++i) { if (latlonValues[i].mY < 0.0) { latlonValues[i].mY = 360.0 + latlonValues[i].mY; } } } if (badValues) { mMessageText = "All GCPs have the same value."; if (mpProgress) { mpProgress->updateProgress(mMessageText, 0, ERRORS); } pStep->finalize(Message::Failure, mMessageText); return false; } for (i = 0; i < pGcpList->getSelectedPoints().size(); ++i) { for (j = i + 1; j < pGcpList->getSelectedPoints().size(); ++j) { if (fabs(pixelValues[i].mX - pixelValues[j].mX) > 1e-20) { badPixelValues = false; break; } if (fabs(pixelValues[i].mY - pixelValues[j].mY) > 1e-20) { badPixelValues = false; break; } } } if (badPixelValues) { mMessageText = "All GCPs have the same pixel location value."; if (mpProgress) { mpProgress->updateProgress(mMessageText, 0, ERRORS); } pStep->finalize(Message::Failure, mMessageText); return false; } mMessageText = "GcpGeoreference started."; if (mpProgress) { mpProgress->updateProgress(mMessageText, 0, NORMAL); } bool success = computeFit(pixelValues, latlonValues, 0, latCoeffs); if (success) { success = computeFit(pixelValues, latlonValues, 1, lonCoeffs); } const RasterDataDescriptor* pDescriptor = dynamic_cast<const RasterDataDescriptor*>(mpRaster->getDataDescriptor()); if (pDescriptor != NULL) { setCubeSize(pDescriptor->getRowCount(), pDescriptor->getColumnCount()); } copy(latCoeffs.begin(), latCoeffs.end(), mLatCoefficients); copy(lonCoeffs.begin(), lonCoeffs.end(), mLonCoefficients); // Generate a gridSize x gridSize grid of GCPs calculated from the // frontwards (pixel-to-lat/lon) polynomial. Then generate the reverse // (lat/lon-to-pixel) polynomial from this grid of GCPs. const int gridSize = 30; pixelValues.clear(); latlonValues.clear(); for (i = 0; i < gridSize; ++i) { for (j = 0; j < gridSize; ++j) { LocationType pixel; LocationType latlon; pixel.mX = i * mNumColumns / gridSize; pixel.mY = j * mNumRows / gridSize; latlon.mX = computePolynomial(pixel, mOrder, latCoeffs); latlon.mY = computePolynomial(pixel, mOrder, lonCoeffs); pixelValues.push_back(pixel); latlonValues.push_back(latlon); } } if (success) { success = computeFit(latlonValues, pixelValues, 0, pXCoeffs); } if (success) { success = computeFit(latlonValues, pixelValues, 1, pYCoeffs); } copy(pXCoeffs.begin(), pXCoeffs.end(), mXCoefficients); copy(pYCoeffs.begin(), pYCoeffs.end(), mYCoefficients); list<GcpPoint> newPoints; list<GcpPoint>::iterator npIter; for (i = 0, it = pGcpList->getSelectedPoints().begin(); it != pGcpList->getSelectedPoints().end(); ++it, ++i) { GcpPoint newPoint; newPoint.mPixel.mX = it->mPixel.mX; newPoint.mPixel.mY = it->mPixel.mY; newPoint.mCoordinate.mX = it->mCoordinate.mX; newPoint.mCoordinate.mY = it->mCoordinate.mY; // If maxLonSeparation > 180.0 then this is a special case if (maxLonSeparation > 180.0 && newPoint.mCoordinate.mY < 0.0) { newPoint.mCoordinate.mY = newPoint.mCoordinate.mY + 360.0; } LocationType newPixel = geoToPixel(newPoint.mCoordinate); newPoint.mRmsError.mX = fabs(newPixel.mX - newPoint.mPixel.mX); newPoint.mRmsError.mY = fabs(newPixel.mY - newPoint.mPixel.mY); newPoints.push_back(newPoint); } pGcpList->clearPoints(); pGcpList->addPoints(newPoints); mpGui = NULL; if (mpRaster != NULL) { mpRaster->setGeoreferencePlugin(this); } pStep->finalize(Message::Success); if (mpProgress) { mpProgress->updateProgress("GcpGeoreference finished.", 0, NORMAL); } return true; }