diff --git a/app/otbSARAltAmbig.cxx b/app/otbSARAltAmbig.cxx index a8b2eab147ef5e58c777ce926ea92e9a9b103080..64a40ca656731e34a69926fecdacc2e24913c488 100644 --- a/app/otbSARAltAmbig.cxx +++ b/app/otbSARAltAmbig.cxx @@ -77,6 +77,13 @@ private: AddParameter(ParameterType_InputImage, "target", "Target geosar image"); SetParameterDescription("target", "Target geosar image"); + AddParameter(ParameterType_OutputFilename, "outfile", "Output file to store the results"); + SetParameterDescription("outfile","Output file to store the results"); + + AddParameter(ParameterType_Bool, "bistatic", "Activate bistatic Mode"); + SetParameterDescription("bistatic", "If true, set the formula in bistatic mode"); + MandatoryOff("bistatic"); + AddRAMParameter(); SetDocExampleParameterValue("inmaster", "s1a-s4-slc-vv-20160818t014650-20160818t014715-012648-013db1-002_SLC.tiff"); @@ -84,6 +91,7 @@ private: SetDocExampleParameterValue("lat", "10.5"); SetDocExampleParameterValue("lon", "5.8"); SetDocExampleParameterValue("height", "45.9"); + SetDocExampleParameterValue("outfile", "alt_ambig.log"); } @@ -100,15 +108,24 @@ private: // Start the target pipeline (Read SAR image metadata) ComplexFloatImageType::Pointer SARPtr_target = GetParameterComplexFloatImage("target"); + // Open the output file + std::ofstream output(GetParameterString("outfile"), std::ios::out | std::ios::trunc); + // Get lat, lon and height float lat = GetParameterFloat("lat"); otbAppLogINFO(<<"Lat : "<<lat); + output << "Latitude of the target = " << lat << std::endl; float lon = GetParameterFloat("lon"); otbAppLogINFO(<<"Lon : "<<lon); + output << "Longitude of the target = " << lon << std::endl; float height = GetParameterFloat("height"); otbAppLogINFO(<<"Height : "<<height); + output << "Altitude of the target = " << height << std::endl; + + bool bistatic = IsParameterEnabled("bistatic"); + otbAppLogINFO(<<"Bistatic : " << bistatic); otb::ImageKeywordlist sarKWL = SARPtr->GetImageKeywordlist(); otb::ImageKeywordlist sarKWL_target = SARPtr_target->GetImageKeywordlist(); @@ -134,15 +151,19 @@ private: SarSensorModelAdapter::WorldToCartesian(demGeoPoint, xyzCart); otbAppLogINFO(<<"Cartesian coords : " << xyzCart[0] << " " << xyzCart[1] << " " << xyzCart[2]); + output << "GROUND COORDINATES = " << xyzCart[0] << " " << xyzCart[1] << " " << xyzCart[2] << std::endl; // Master otbAppLogINFO(<<"Inmaster Image : "); + output << std::endl << "Inmaster Image :" << std::endl; m_SarSensorModelAdapter->WorldToSatPositionAndVelocity(demGeoPoint, satellitePosition[0], satelliteVelocity[0]); otbAppLogINFO(<<"Satellite Position : " << satellitePosition[0][0] << " " << satellitePosition[0][1] << " " << satellitePosition[0][2]); otbAppLogINFO(<<"Satellite Velocity : " << satelliteVelocity[0][0] << " " << satelliteVelocity[0][1] << " " << satelliteVelocity[0][2]); + output << "SATELLITE POSITIONS = " << satellitePosition[0][0] << " " << satellitePosition[0][1] << " " << satellitePosition[0][2] << std::endl; + output << "SATELLITE VELOCITY = " << satelliteVelocity[0][0] << " " << satelliteVelocity[0][1] << " " << satelliteVelocity[0][2] << std::endl; - searchPassageCloserToGround(satellitePosition[0], incidence[0], xyzCart, demGeoPointRadian); + searchPassageCloserToGround(satellitePosition[0], incidence[0], xyzCart, demGeoPointRadian, output); otbAppLogINFO(<<"Incidence : " << incidence[0]); // Calculate lambda @@ -155,18 +176,32 @@ private: // Target loadOk = m_SarSensorModelAdapter->LoadState(sarKWL_target); otbAppLogINFO(<<"Target Image : "); + output << std::endl << "Target Image : " << std::endl; m_SarSensorModelAdapter->WorldToSatPositionAndVelocity(demGeoPoint, satellitePosition[1], satelliteVelocity[1]); otbAppLogINFO(<<"Satellite Position : " << satellitePosition[1][0] << " " << satellitePosition[1][1] << " " << satellitePosition[1][2]); otbAppLogINFO(<<"Satellite Velocity : " << satelliteVelocity[1][0] << " " << satelliteVelocity[1][1] << " " << satelliteVelocity[1][2]); + output << "SATELLITE POSITIONS = " << satellitePosition[1][0] << " " << satellitePosition[1][1] << " " << satellitePosition[2][2] << std::endl; + output << "SATELLITE VELOCITY = " << satelliteVelocity[1][0] << " " << satelliteVelocity[1][1] << " " << satelliteVelocity[1][2] << std::endl; - searchPassageCloserToGround(satellitePosition[1], incidence[1], xyzCart, demGeoPointRadian); + searchPassageCloserToGround(satellitePosition[1], incidence[1], xyzCart, demGeoPointRadian, output); otbAppLogINFO(<<"Incidence : " << incidence[1]); - computeAltAmbig(xyzCart, satellitePosition, satelliteVelocity, lambda, incidence); - + otbAppLogINFO(<< "Compute Alt Ambig"); + otbAppLogINFO(<< "Master ORBIT\tSLAVE ORBIT\tIncidence\tALT AMBIG\tRadial \tLateral"); + output << std::endl << "Master ORBIT\tSLAVE ORBIT\tIncidence\tALT AMBIG\tRadial \tLateral" << std::endl; + computeAltAmbig(xyzCart, satellitePosition, satelliteVelocity, lambda, incidence, output); + + // Close the output file + output.close(); + } + + std::string getFilename(std::string filePath){ + std::size_t dotPos = filePath.rfind("."); + std::size_t sepPos = filePath.rfind("/"); + return filePath.substr(sepPos + 1, dotPos - sepPos - 1); } - void searchPassageCloserToGround(SarSensorModelAdapter::Point3DType satellitePosition, double& incidence, SarSensorModelAdapter::Point3DType xyzCart, SarSensorModelAdapter::Point3DType demGeoPoint){ + void searchPassageCloserToGround(SarSensorModelAdapter::Point3DType satellitePosition, double& incidence, SarSensorModelAdapter::Point3DType xyzCart, SarSensorModelAdapter::Point3DType demGeoPoint, std::ofstream& output){ SarSensorModelAdapter::Point3DType rm; rm[0] = xyzCart[0] - satellitePosition[0]; rm[1] = xyzCart[1] - satellitePosition[1]; @@ -203,19 +238,22 @@ private: vectk[2] = sin(lat); // Rm projection + output << "Ground target --> Satellite Vector" << std::endl; double northProjection = -(vecti[0]*rm[0]+vecti[1]*rm[1]+vecti[2]*rm[2])/normeRm; double eastProjection = -(vectj[0]*rm[0]+vectj[1]*rm[1]+vectj[2]*rm[2])/normeRm; double verticalProjection = -(vectk[0]*rm[0]+vectk[1]*rm[1]+vectk[2]*rm[2])/normeRm; otbAppLogINFO(<< "North Projection : " << northProjection); otbAppLogINFO(<< "East Projection : " << eastProjection); otbAppLogINFO(<< "Vertical Projection : " << verticalProjection); + output << "North Projection : " << northProjection << std::endl; + output << "East Projection : " << eastProjection << std::endl; + output << "Vertical Projection : " << verticalProjection << std::endl; } - void computeAltAmbig(SarSensorModelAdapter::Point3DType xyzCart, SarSensorModelAdapter::Point3DType* satellitePosition, SarSensorModelAdapter::Point3DType* satelliteVelocity, double lambda, double* incidence){ - otbAppLogINFO(<< "Compute Alt Ambig"); - // TODO : Get the type of phase (monostatic by default) - double factorBperp = 1.0; - double factorHamb = 2.0; + void computeAltAmbig(SarSensorModelAdapter::Point3DType xyzCart, SarSensorModelAdapter::Point3DType* satellitePosition, SarSensorModelAdapter::Point3DType* satelliteVelocity, double lambda, double* incidence, std::ofstream& output){ + // Adjust the formula in case of non-monostatic mode + double factorBperp = (!IsParameterEnabled("bistatic"))? 1.0:2.0; + double factorHamb = (!IsParameterEnabled("bistatic"))? 2.0:1.0; SarSensorModelAdapter::Point3DType rm; rm[0] = -(xyzCart[0] - satellitePosition[0][0]); @@ -269,9 +307,10 @@ private: double inc_moy = ((incidence[1] + incidence[0]) / 2) * M_PI / 180.; double alt_amb = lambda * sin(inc_moy) / (factorHamb * tan(alpha)); - otbAppLogINFO(<< "Incidence\tALT AMBIG\tRadial\tLateral"); - otbAppLogINFO(<< inc_moy * 180. / M_PI << "\t" << alt_amb << "\t" << xe << "\t" << ye / factorBperp); - + std::string master = getFilename(GetParameterString("inmaster")); + std::string target = getFilename(GetParameterString("target")); + otbAppLogINFO(<< master << "\t" << target << "\t" << inc_moy * 180. / M_PI << " \t" << alt_amb << "\t" << xe << "\t" << ye / factorBperp); + output << master << "\t" << target << "\t" << inc_moy * 180. / M_PI << " \t" << alt_amb << "\t" << xe << "\t" << ye / factorBperp << std::endl; } };