SIMOrthoProgram-Orth_GF3-Strip/simptsn.cpp

3314 lines
139 KiB
C++
Raw Normal View History

#pragma once
///
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
///
//#define EIGEN_USE_MKL_ALL
//#define EIGEN_VECTORIZE_SSE4_2
//#include <mkl.h>
// <20><><EFBFBD>ط<EFBFBD><D8B7><EFBFBD>
#include <iostream>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <time.h>
#include <boost/filesystem.hpp>
#include <omp.h>
#include "baseTool.h"
#include "simptsn.h"
#include "SateOrbit.h"
#include "ImageMatch.h"
#include <gdal_utils.h>
#include <armadillo>
#include <proj.h>
#include "gdal_priv.h"
#include "gdal_alg.h"
#include <gdal_priv.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <gdalgrid.h>
using namespace std;
using namespace Eigen;
using namespace arma;
PSTNAlgorithm::PSTNAlgorithm()
{
}
PSTNAlgorithm::PSTNAlgorithm(string infile_path)
{
std::cout << "=========================================================================" << endl;
std::cout << "read parameters :\t" << infile_path << endl;
std::cout << "parameters files :\t" << infile_path << endl;
std::cout << "============================================================================" << endl;
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
ifstream infile(infile_path, ios::in);
if (!infile.is_open()) {
throw "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
}
try {
int line_ids = 0;
string buf;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
getline(infile, buf); this->height = stoi(buf);
getline(infile, buf); this->width = stoi(buf); std::cout << "height,width\t" << this->height << "," << this->width << endl;
getline(infile, buf); this->R0 = stod(buf); std::cout << "R0\t" << this->R0 << endl; //<2F><>б<EFBFBD><D0B1>
getline(infile, buf); this->near_in_angle = stod(buf); std::cout << "near_in_angle\t" << this->R0 << endl; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
getline(infile, buf); this->far_in_angle = stod(buf); std::cout << "far_in_angle\t" << this->R0 << endl; //Զ<><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
getline(infile, buf); this->LightSpeed = stod(buf); std::cout << "LightSpeed\t" << this->LightSpeed << endl;
getline(infile, buf); this->lamda = stod(buf); std::cout << "lamda\t" << this->lamda << endl;
getline(infile, buf); this->imgStartTime = stod(buf); std::cout << "imgStartTime\t" << this->imgStartTime << endl;
getline(infile, buf); this->PRF = stod(buf); std::cout << "PRF\t" << this->PRF << endl;
getline(infile, buf); this->refrange = stod(buf); std::cout << "refrange\t" << this->refrange << endl;
getline(infile, buf); this->widthspace = stod(buf); std::cout << "widthspace\t" << this->widthspace << endl;
getline(infile, buf); this->doppler_paramenter_number = stoi(buf); std::cout << "doppler_paramenter_number\t" << this->doppler_paramenter_number << endl;
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>
this->doppler_paras = Eigen::MatrixX<double>(this->doppler_paramenter_number, 1);
if (this->doppler_paramenter_number > 0) {
for (int i = 0; i < this->doppler_paramenter_number; i++) {
getline(infile, buf);
this->doppler_paras(i, 0) = stod(buf);
}
std::cout << "doppler_paramenter:\n" << this->doppler_paras << endl;
}
else {
throw "<EFBFBD>ڴ治<EFBFBD><EFBFBD>";
}
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ǹ<EFBFBD><C7B9><EFBFBD>
getline(infile, buf); std::cout << "ispolySatelliteModel\t" << buf << endl;
if (stoi(buf) != 1) {
throw "<EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>";
}
getline(infile, buf); int polynum = stoi(buf) + 1; // <20><><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
getline(infile, buf); double SatelliteModelStartTime = stod(buf); // <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>ʼʱ<CABC><CAB1>
Eigen::MatrixX<double> polySatellitePara(polynum, 6);
if (polynum >= 4) {
for (int i = 0; i < 6; i++) {
for (int j = 0; j < polynum; j++) {
getline(infile, buf);
polySatellitePara(j, i) = stod(buf);
}
}
}
else {
throw "<EFBFBD>ڴ治<EFBFBD><EFBFBD>";
}
OrbitPoly orbit(polynum, polySatellitePara, SatelliteModelStartTime);
this->orbit = orbit;
std::cout << "sate polynum\t" << polynum << endl;
std::cout << "sate polySatellitePara\n" << polySatellitePara << endl;
std::cout << "sate SatelliteModelStartTime\t" << SatelliteModelStartTime << endl;
if (!infile.eof()) // <20><>ȡ<EFBFBD><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
{
double yy, mm, dd;
getline(infile, buf);
if (buf != "" || buf.length() > 3) {
yy = stod(buf);
getline(infile, buf); mm = stod(buf);
getline(infile, buf); dd = stod(buf);
this->UTC = Eigen::Matrix<double, 1, 3>{ yy,mm,dd };
std::cout << "UTC\t" << this->UTC << endl;
std::cout << "\nWGS84 to J2000 Params:\t" << endl;
getline(infile, buf); this->Xp = stod(buf); std::cout << "Xp\t" << this->Xp << endl;
getline(infile, buf); this->Yp = stod(buf); std::cout << "Yp\t" << this->Yp << endl;
getline(infile, buf); this->Dut1 = stod(buf); std::cout << "dut1\t" << this->Dut1 << endl;
getline(infile, buf); this->Dat = stod(buf); std::cout << "dat\t" << this->Dat << endl;
}
}
}
catch (exception e) {
infile.close();
throw "<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
}
infile.close();
std::cout << "============================================================================" << endl;
}
PSTNAlgorithm::~PSTNAlgorithm()
{
}
/// <summary>
/// <20><>dem<65><6D><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA>γ<EFBFBD>ļ<EFBFBD>
/// </summary>
/// <param name="dem_path">dem</param>
/// <param name="lon_path"><3E><><EFBFBD><EFBFBD></param>
/// <param name="lat_path">γ<><CEB3></param>
/// <returns></returns>
int PSTNAlgorithm::dem2lat_lon(std::string dem_path, std::string lon_path, std::string lat_path)
{
gdalImage dem_img(dem_path);
//gdalImage lon_img = CreategdalImage(lon_path, dem_img.height, dem_img.width);
//gdalImage lat_img = CreategdalImage(lat_path, dem_img.height, dem_img.width);
return 0;
}
int PSTNAlgorithm::dem2SAR_RC(std::string dem_path, std::string sim_rc_path)
{
return 0;
}
Eigen::MatrixX<double> PSTNAlgorithm::calNumericalDopplerValue(Eigen::MatrixX<double> R)
{
Eigen::MatrixX<double> t = (R.array() - this->refrange) * (1000000 / this->LightSpeed);
Eigen::MatrixX<double> tlist(t.rows(), this->doppler_paramenter_number);// nx5
tlist.col(0) = Eigen::MatrixX<double>::Ones(t.rows(), 1).col(0);
for (int i = 1; i < this->doppler_paramenter_number; i++)
{
tlist.col(i) = t.array().pow(i);
}
//return tlist.array()*this
return tlist * this->doppler_paras; //nx5,5x1
//return Eigen::MatrixX<double>(1, 1);
}
double PSTNAlgorithm::calNumericalDopplerValue(double R)
{
double t = (R - this->refrange) * (1000000 / this->LightSpeed);
return this->doppler_paras(0) + this->doppler_paras(1) * t + this->doppler_paras(2) * t * t + this->doppler_paras(3) * t * t * t + this->doppler_paras(4) * t * t * t;
}
Eigen::MatrixX<double> PSTNAlgorithm::PSTN(Eigen::MatrixX<double> landpoints, double ave_dem = 0, double dt = 0.001, bool isCol = false)
{
//Eigen::MatrixX<double> a(1, 1);
//a(0, 0) = 1554386455.999999;
//Eigen::MatrixX<double> satestatetest = this->orbit.SatelliteSpacePoint(a);
//std::cout << satestatetest << endl;
int point_num = landpoints.rows();
Eigen::MatrixX<double> SARPoint = Eigen::MatrixX<double>::Ones(point_num, 3);
double L_T = 0;
double S_T = 0;
double R_T = 0;
double cos_theta = 0;
double delta_col_ref = ((this->refrange - this->R0) * 100000000 / this->LightSpeed) / this->widthspace;
Eigen::MatrixX<double> landpoint = Eigen::MatrixX<double>::Ones(1, 6);// <20><><EFBFBD><EFBFBD>״̬
Eigen::MatrixX<double> satestate = Eigen::MatrixX<double>::Ones(1, 6);// <20><><EFBFBD><EFBFBD>״̬
Eigen::MatrixX<double> satepoint = Eigen::MatrixX<double>::Ones(1, 3);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Eigen::MatrixX<double> satevector = Eigen::MatrixX<double>::Ones(1, 3);// <20><><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
Eigen::MatrixX<double> sate_land = Eigen::MatrixX<double>::Ones(1, 3); // <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD>ʸ<EFBFBD><CAB8>
double ti = this->orbit.SatelliteModelStartTime;
double R1 = 0;// б<><D0B1>
double R2 = 0;// б<><D0B1>
double FdTheory1 = 0;
double FdTheory2 = 0;
double FdNumberical = 0;
double inc_t = 0;
double delta_angle = (this->far_in_angle - this->near_in_angle) / this->width;
//std::cout << landpoint(0, 0) << "\t" << landpoint(0, 1) << "\t" << landpoint(0, 2) << endl;
dt = dt / this->PRF;
Landpoint satePoints = { 0, 0, 0 };
Landpoint landPoint = { 0, 0, 0 };
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
for (int j = 0; j < point_num; j++) {
landpoint = landpoints.row(j);
for (int i = 0; i < 50; i++) {
satestate = this->orbit.SatelliteSpacePoint(ti + dt);
satepoint = satestate(Eigen::all, { 0,1,2 });
satevector = satestate(Eigen::all, { 3,4,5 });
sate_land = satepoint - landpoint;
//std::cout << sate_land << endl;
R1 = (sate_land.array().pow(2).array().rowwise().sum().array().sqrt())[0];;
FdTheory1 = this->calTheoryDopplerValue(R1, sate_land, satevector);
satestate = this->orbit.SatelliteSpacePoint(ti);
satepoint = satestate(Eigen::all, { 0,1,2 });
satevector = satestate(Eigen::all, { 3,4,5 });
sate_land = satepoint - landpoint;
R2 = (sate_land.array().pow(2).array().rowwise().sum().array().sqrt())[0];
FdNumberical = this->calNumericalDopplerValue(R2);
FdTheory2 = this->calTheoryDopplerValue(R2, sate_land, satevector);
inc_t = dt * (FdTheory2 - FdNumberical) / (FdTheory1 - FdTheory2);
if (abs(FdTheory1 - FdTheory2) < 1e-9) {
break;
}
ti = ti - inc_t;
if (abs(inc_t) <= dt) {
break;
}
}
SARPoint(j, 0) = ti;
SARPoint(j, 1) = (ti - this->imgStartTime) * this->PRF;
// <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><D0B7>к<EFBFBD>
satestate = this->orbit.SatelliteSpacePoint(ti);
satepoint = satestate(Eigen::all, { 0,1,2 });
sate_land = satepoint - landpoint;
R1 = (sate_land.array().pow(2).array().rowwise().sum().array().sqrt())[0];;
//SARPoint(j, 2) = getIncAngle(satePoints, landPoint);
//SARPoint(j, 2) = (R1 - this->R0 - (this->refrange - this->R0) / 3) / this->widthspace;
SARPoint(j, 2) = (R1 - this->R0) / this->widthspace;
}
//std::cout <<"SARPoints(200, 0):\t" << SARPoint(200, 0) << "\t" << SARPoint(200, 1) << "\t" << SARPoint(200, 2) << "\t" << endl;
return SARPoint;
}
/*
Eigen::MatrixXd PSTNAlgorithm::WGS842J2000(Eigen::MatrixXd blh)
{
return WGS84_J2000::WGS842J2000(blh, this->UTC, this->Xp, this->Yp, this->Dut1, this->Dat);
//return Eigen::MatrixXd();
}
Landpoint PSTNAlgorithm::WGS842J2000(Landpoint p)
{
Eigen::MatrixXd blh = Eigen::MatrixXd(1, 3);
blh<<p.lon, p.lat, p.ati;
blh=this->WGS842J2000(blh);
return Landpoint{ blh(0,0),blh(0,1) ,blh(0,0) };
}
*/
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>۶<EFBFBD><DBB6><EFBFBD><EFBFBD>վ<EFBFBD><D5BE><EFBFBD>
/// </summary>
/// <param name="R">б<><D0B1></param>
/// <param name="R_s1">nx3</param>
/// <param name="V_s1">nx3</param>
/// <returns></returns>
Eigen::MatrixX<double> PSTNAlgorithm::calTheoryDopplerValue(Eigen::MatrixX<double> R, Eigen::MatrixX<double> R_s1, Eigen::MatrixX<double> V_s1)
{
return (R_s1.array() * V_s1.array()).rowwise().sum().array() * (-2) / (R.array() * this->lamda);
//return Eigen::MatrixX<double>(1, 1);
}
double PSTNAlgorithm::calTheoryDopplerValue(double R, Eigen::MatrixX<double> R_s1, Eigen::MatrixX<double> V_s1) {
return ((R_s1.array() * V_s1.array()).rowwise().sum().array() * (-2) / (R * this->lamda))[0];
}
simProcess::simProcess()
{
}
simProcess::~simProcess()
{
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="argc"></param>
/// <param name="argv"></param>
/// <returns></returns>
int simProcess::parameters(int argc, char* argv[])
{
for (int i = 0; i < argc; i++) {
std::cout << argv[i] << endl;
}
return 0;
}
/// <summary>
/// <20><><EFBFBD>Ӷ<EFBFBD>λ<EFBFBD><CEBB>,<2C><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="paras_path"><3E><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7></param>
/// <param name="workspace_path"><3E><><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>·<EFBFBD><C2B7></param>
/// <param name="out_dir_path"><3E><><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>·<EFBFBD><C2B7></param>
/// <param name="in_dem_path"><3E><><EFBFBD><EFBFBD>DEM<45>ļ<EFBFBD>·<EFBFBD><C2B7></param>
/// <param name="in_sar_path"><3E><><EFBFBD><EFBFBD>SARӰ<52><D3B0><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7></param>
/// <returns><3E><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>u<EFBFBD><75></returns>
int simProcess::InitSimulationSAR(std::string paras_path, std::string workspace_path, std::string out_dir_path, std::string in_dem_path, std::string in_sar_path)
{
this->pstn = PSTNAlgorithm(paras_path); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
this->in_dem_path = in_dem_path;
this->dem_path = JoinPath(workspace_path, "SAR_dem.tiff");// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>DEM
this->workSpace_path = workspace_path;
this->dem_r_path = JoinPath(workspace_path, "dem_r.tiff");
this->dem_rc_path = JoinPath(workspace_path, "dem_rc.tiff");
string dem_rcs_path = JoinPath(workspace_path, "dem_rcs.tiff");
this->sar_sim_wgs_path = JoinPath(workspace_path, "sar_sim_wgs.tiff");
this->sar_sim_path = JoinPath(workspace_path, "sar_sim.tiff");
this->ori_sim_count_tiff = JoinPath(workspace_path, "RD_ori_sim_count.tiff");
this->in_sar_path = in_sar_path;
this->sar_power_path = JoinPath(workspace_path, "in_sar_power.tiff");
this->outSpace_path = out_dir_path;
this->out_dem_slantRange_path = out_dir_path + "\\" + "dem_slantRange.tiff";// <20><><EFBFBD><EFBFBD>б<EFBFBD><D0B1>
this->out_plant_slantRange_path = out_dir_path + "\\" + "flat_slantRange.tiff";// ƽ<><C6BD>б<EFBFBD><D0B1>
this->out_dem_rc_path = out_dir_path + "\\" + "WGS_SAR_map.tiff";// <20><>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>ӳ<EFBFBD><D3B3>
this->out_incidence_path = out_dir_path + "\\" + "incidentAngle.tiff";// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
this->out_localIncidenct_path = out_dir_path + "\\" + "localincidentAngle.tiff";// <20>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
this->out_ori_sim_tiff = out_dir_path + "\\" + "RD_ori_sim.tif";// <20>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
this->in_rpc_lon_lat_path = this->out_ori_sim_tiff;
this->out_inc_angle_rpc_path = out_dir_path + "\\" + "RD_incidentAngle.tiff";// <20>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
this->out_local_inc_angle_rpc_path = out_dir_path + "\\" + "RD_localincidentAngle.tiff";// <20>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
std::cout << "==========================================================================" << endl;
std::cout << "in_dem_path" << ":\t" << this->in_dem_path << endl;
std::cout << "in_sar_path" << ":\t" << this->in_sar_path << endl;
std::cout << "workSpace_path" << ":\t" << this->workSpace_path << endl;
std::cout << "dem_path" << ":\t" << this->dem_path << endl;
std::cout << "sar_power_path" << ":\t" << this->sar_power_path << endl;
std::cout << "dem_r_path" << ":\t" << this->dem_r_path << endl;
std::cout << "dem_rc_path" << ":\t" << this->dem_rc_path << endl;
std::cout << "sar_sim_wgs_path" << ":\t" << this->sar_sim_wgs_path << endl;
std::cout << "sar_sim_path" << ":\t" << this->sar_sim_path << endl;
std::cout << "outSpace_path" << ":\t" << this->outSpace_path << endl;
std::cout << "out_dem_slantRange_path" << ":\t" << this->out_dem_slantRange_path << endl;
std::cout << "out_plant_slantRange_path" << ":\t" << this->out_plant_slantRange_path << endl;
std::cout << "out_dem_rc_path" << ":\t" << this->out_dem_rc_path << endl;
std::cout << "out_incidence_path" << ":\t" << this->out_incidence_path << endl;
std::cout << "out_localIncidenct_path" << ":\t" << this->out_localIncidenct_path << endl;
std::cout << "==========================================================================" << endl;
this->CreateSARDEM();
this->dem2SAR_row(); // <20><>ȡ<EFBFBD>к<EFBFBD>
this->SARIncidentAngle();
this->SARSimulationWGS();
this->SARSimulation();
this->in_sar_power();
if (boost::filesystem::exists(boost::filesystem::path(this->out_dem_rc_path))) {
boost::filesystem::remove(boost::filesystem::path(this->out_dem_rc_path));
}
boost::filesystem::copy_file(boost::filesystem::path(this->dem_rc_path), boost::filesystem::path(this->out_dem_rc_path));
string sim_rcs_jpg_path = JoinPath(workspace_path, "dem_rcs.jpg");
string sar_rcs_jpg_path = JoinPath(workspace_path, "sar_rcs.jpg");
//this->createImageMatchModel(this->sar_power_path, sar_rcs_jpg_path, this->sar_sim_path, sim_rcs_jpg_path, this->workSpace_path);
if (this->isMatchModel) {
std::cout << "У<EFBFBD><EFBFBD>" << endl;
// this->correctOrth_rc(this->dem_rc_path, this->matchmodel);
}
// <20><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
this->ReflectTable_WGS2Range();
this->SARIncidentAngle_RPC();
return 0;
}
int simProcess::InitASFSAR(std::string paras_path, std::string workspace_path, std::string out_dir_path, std::string in_dem_path)
{
return 0;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD>SAR<41><52>Ӧ<EFBFBD><D3A6>DEM
/// </summary>
/// <returns><3E><><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD></returns>
int simProcess::CreateSARDEM()
{
std::cout << "dem2SAR_Row_col begin time:" << getCurrentTimeString() << std::endl;
{
gdalImage dem(this->in_dem_path);
double dem_mean = dem.mean();
gdalImage sim_rc = CreategdalImage(this->dem_rc_path, dem.height, dem.width, 2, dem.gt, dem.projection);
DemBox box{ 9999,9999,-9999,-9999 };
{
Eigen::MatrixXd sim_r;
Eigen::MatrixXd sim_c;
int line_invert = int(2000000 / dem.width);
line_invert = line_invert > 10 ? line_invert : 10;
int max_rows_ids = 0;
int all_count = 0;
bool state = true;
omp_lock_t lock;
omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#pragma omp parallel for num_threads(8) // NEW ADD
for (int max_rows_ids = 0; max_rows_ids < dem.height; max_rows_ids = max_rows_ids + line_invert) {
//line_invert = dem_clip.height - max_rows_ids > line_invert ? line_invert : dem_clip.height - max_rows_ids;
Eigen::MatrixXd demdata = dem.getData(max_rows_ids, 0, line_invert, dem.width, 1);
Eigen::MatrixXd sim_r = demdata.array() * 0;
Eigen::MatrixXd sim_c = demdata.array() * 0;
int datarows = demdata.rows();
int datacols = demdata.cols();
Eigen::MatrixX<double> landpoint(datarows * datacols, 3);
for (int i = 0; i < datarows; i++) {
for (int j = 0; j < datacols; j++) {
landpoint(i * datacols + j, 0) = i + max_rows_ids;
landpoint(i * datacols + j, 1) = j;
landpoint(i * datacols + j, 2) = demdata(i, j); // <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><E0A3AC><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>Ϊ0
}
}
//demdata = Eigen::MatrixXd(1, 1);
landpoint = dem.getLandPoint(landpoint);
//landpoint.col(2) = landpoint.col(2).array() * 0;
landpoint = LLA2XYZ(landpoint);
landpoint = this->pstn.PSTN(landpoint, dem_mean, 0.001, true); // time,r,c
//std::cout << "for time " << getCurrentTimeString() << std::endl;
double min_lat = 9999;
double max_lat = -9999;
double min_lon = 9999;
double max_lon = -9999;
bool has_min_max = false;
Landpoint p1{ 0,0,0 };
for (int i = 0; i < datarows; i++) {
for (int j = 0; j < datacols; j++) {
sim_r(i, j) = landpoint(i * datacols + j, 1);
sim_c(i, j) = landpoint(i * datacols + j, 2);
p1 = dem.getLandPoint(i + max_rows_ids, j, demdata(i, j));
if (sim_r(i, j) >= 0 && sim_c(i, j) >= 0 && sim_r(i, j) <= this->pstn.height && sim_c(i, j) <= this->pstn.width) {
min_lat = min_lat < p1.lat ? min_lat : p1.lat;
max_lat = max_lat > p1.lat ? max_lat : p1.lat;
min_lon = min_lon < p1.lon ? min_lon : p1.lon;
max_lon = max_lon > p1.lon ? max_lon : p1.lon;
has_min_max = true;
}
}
}
//std::cout << "for time " << getCurrentTimeString() << std::endl;
// д<><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
omp_set_lock(&lock); //<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
//std::cout << "lock" << endl;
if (has_min_max) {
box.min_lat = min_lat < box.min_lat ? min_lat : box.min_lat;
box.max_lat = max_lat > box.max_lat ? max_lat : box.max_lat;;
box.min_lon = min_lon < box.min_lon ? min_lon : box.min_lon;;
box.max_lon = max_lon > box.max_lon ? max_lon : box.max_lon;;
}
sim_rc.saveImage(sim_r, max_rows_ids, 0, 1);
sim_rc.saveImage(sim_c, max_rows_ids, 0, 2);
all_count = all_count + line_invert;
std::cout << "rows:\t" << all_count << "/" << dem.height << "\t computing.....\t" << getCurrentTimeString() << endl;
omp_unset_lock(&lock); //<2F>ͷŻ<CDB7><C5BB><EFBFBD><EFBFBD><EFBFBD>
}
omp_destroy_lock(&lock); //<2F><><EFBFBD>ٻ<EFBFBD><D9BB><EFBFBD><EFBFBD><EFBFBD>
}
std::cout << "prepare over" << getCurrentTimeString() << std::endl;
double dist_lat = box.max_lat - box.min_lat;
double dist_lon = box.max_lon - box.min_lon;
dist_lat = 0.2 * dist_lat;
dist_lon = 0.2 * dist_lon;
box.min_lat = box.min_lat - dist_lat;
box.max_lat = box.max_lat + dist_lat;
box.min_lon = box.min_lon - dist_lon;
box.max_lon = box.max_lon + dist_lon;
std::cout << "box:" << endl;
std::cout << "min_lat-max_lat:\t" << box.min_lat << "\t" << box.max_lat << endl;
std::cout << "min_lon-max_lon:\t" << box.min_lon << "\t" << box.max_lon << endl;
std::cout << "cal box of sar over" << endl;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD>С
int width = 1.8 * this->pstn.width;
int height = 1.8 * this->pstn.height;
double heightspace = (box.max_lat - box.min_lat) / height;
double widthspace = (box.max_lon - box.min_lon) / width;
std::cout << "resample dem:\n" << getCurrentTimeString() << std::endl;
std::cout << "in_dem:\t" << this->in_dem_path << endl;
std::cout << "out_dem:\t" << this->dem_path << endl;
std::cout << "width-height:\t" << width << "-" << height << endl;
std::cout << "widthspace\t-\theight\tspace:\t" << widthspace << "\t-\t" << heightspace << endl;
int pBandIndex[1] = { 1 };
int pBandCount[1] = { 1 };
double gt[6] = {
box.min_lon,widthspace,0, //x
box.max_lat,0,-heightspace//y
};
//boost::filesystem::copy(dem_path, this->dem_path);
ResampleGDAL(this->in_dem_path.c_str(), this->dem_path.c_str(), gt, width, height, GRA_Bilinear);
std::cout << "resample dem over:\n" << getCurrentTimeString() << std::endl;
std::cout << "remove sim_rc_path:\t" << this->dem_rc_path << std::endl;
}
return 0;
}
/// <summary>
/// <20><>ȡ<EFBFBD>к<EFBFBD>
/// </summary>
/// <returns></returns>
int simProcess::dem2SAR()
{
std::cout << "the row of the sar in dem:" << getCurrentTimeString() << std::endl;
{
this->dem2SAR_row();
}
std::cout << "the slant range of the sar in dem:" << getCurrentTimeString() << std::endl;
{
gdalImage dem_clip(this->dem_path);
gdalImage dem_r(this->dem_r_path);
double dem_mean = dem_clip.mean();
gdalImage dem_slant_range = CreategdalImage(this->out_dem_slantRange_path, dem_clip.height, dem_clip.width, 1, dem_clip.gt, dem_clip.projection);
gdalImage plant_slant_range = CreategdalImage(this->out_plant_slantRange_path, dem_clip.height, dem_clip.width, 1, dem_clip.gt, dem_clip.projection);
int line_invert = int(10000000 / dem_clip.width);
line_invert = line_invert > 10 ? line_invert : 10;
int count_lines = 0;
omp_lock_t lock;
omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
std::cout << "the slant range of the sar:" << getCurrentTimeString() << std::endl;
#pragma omp parallel for num_threads(6) // NEW ADD
for (int max_rows_ids = 0; max_rows_ids < dem_clip.height; max_rows_ids = max_rows_ids + line_invert) {
Eigen::MatrixXd dem_r_block = dem_r.getData(max_rows_ids, 0, line_invert, dem_clip.width, 1); // <20>к<EFBFBD>
Eigen::MatrixXd demdata = dem_clip.getData(max_rows_ids, 0, line_invert, dem_clip.width, 1); // <20><><EFBFBD><EFBFBD>
Eigen::MatrixXd demslant_range = demdata.array() * 0; // <20><><EFBFBD><EFBFBD>б<EFBFBD><D0B1>
int datarows = demdata.rows();
int datacols = demdata.cols();
Eigen::MatrixX<double> landpoint(datarows * datacols, 3);
for (int i = 0; i < datarows; i++) {
for (int j = 0; j < datacols; j++) {
landpoint(i * datacols + j, 0) = i + max_rows_ids;
landpoint(i * datacols + j, 1) = j;
landpoint(i * datacols + j, 2) = demdata(i, j); // <20><>Ϊ0 <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ʼ
}
}
landpoint = dem_clip.getLandPoint(landpoint);
landpoint = LLA2XYZ(landpoint);// this->pstn.WGS842J2000(landpoint);
Eigen::MatrixX<double> satestate = Eigen::MatrixX<double>::Ones(1, 6);// <20><><EFBFBD><EFBFBD>״̬
Eigen::MatrixX<double> satepoint = Eigen::MatrixX<double>::Ones(1, 3);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
long double ti = 0;
for (int i = 0; i < datarows; i++) {
for (int j = 0; j < datacols; j++) {
ti = dem_r_block(i, j) / this->pstn.PRF + this->pstn.imgStartTime;
satestate = this->pstn.orbit.SatelliteSpacePoint(ti);
satepoint = satestate(Eigen::all, { 0,1,2 });
satepoint(0, 0) = satepoint(0, 0) - landpoint(i * datacols + j, 0);
satepoint(0, 1) = satepoint(0, 1) - landpoint(i * datacols + j, 1);
satepoint(0, 2) = satepoint(0, 2) - landpoint(i * datacols + j, 2);
demslant_range(i, j) = (satepoint.array().pow(2).array().rowwise().sum().array().sqrt())[0];
}
}
//std::cout << "for time " << getCurrentTimeString() << std::endl;
// д<><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
omp_set_lock(&lock); //<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
dem_slant_range.saveImage(demslant_range, max_rows_ids, 0, 1);
//sim_rc_reprocess.saveImage(sim_c, max_rows_ids, 0, 2);
count_lines = count_lines + line_invert;
std::cout << "rows:\t" << max_rows_ids << "\t-\t" << max_rows_ids + line_invert << "\t" << count_lines << "/" << dem_clip.height << "\t computing.....\t" << getCurrentTimeString() << endl;
omp_unset_lock(&lock); //<2F>ͷŻ<CDB7><C5BB><EFBFBD><EFBFBD><EFBFBD>
}
count_lines = 0;
std::cout << "the plant slant range of the sar:" << getCurrentTimeString() << std::endl;
#pragma omp parallel for num_threads(6) // NEW ADD
for (int max_rows_ids = 0; max_rows_ids < dem_clip.height; max_rows_ids = max_rows_ids + line_invert) {
Eigen::MatrixXd dem_r_block = dem_r.getData(max_rows_ids, 0, line_invert, dem_clip.width, 1); // <20>к<EFBFBD>
Eigen::MatrixXd demdata = dem_clip.getData(max_rows_ids, 0, line_invert, dem_clip.width, 1); // <20><><EFBFBD><EFBFBD>
Eigen::MatrixXd demslant_range = demdata.array() * 0; // <20><><EFBFBD><EFBFBD>б<EFBFBD><D0B1>
int datarows = demdata.rows();
int datacols = demdata.cols();
Eigen::MatrixX<double> landpoint(datarows * datacols, 3);
for (int i = 0; i < datarows; i++) {
for (int j = 0; j < datacols; j++) {
landpoint(i * datacols + j, 0) = i + max_rows_ids;
landpoint(i * datacols + j, 1) = j;
landpoint(i * datacols + j, 2) = 0; // <20><>Ϊ0 <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ʼ
}
}
landpoint = dem_clip.getLandPoint(landpoint);
landpoint = LLA2XYZ(landpoint);
Eigen::MatrixX<double> satestate = Eigen::MatrixX<double>::Ones(1, 6);// <20><><EFBFBD><EFBFBD>״̬
Eigen::MatrixX<double> satepoint = Eigen::MatrixX<double>::Ones(1, 3);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
long double ti = 0;
for (int i = 0; i < datarows; i++) {
for (int j = 0; j < datacols; j++) {
ti = dem_r_block(i, j) / this->pstn.PRF + this->pstn.imgStartTime;
satestate = this->pstn.orbit.SatelliteSpacePoint(ti);
satepoint = satestate(Eigen::all, { 0,1,2 });
satepoint(0, 0) = satepoint(0, 0) - landpoint(i * datacols + j, 0);
satepoint(0, 1) = satepoint(0, 1) - landpoint(i * datacols + j, 1);
satepoint(0, 2) = satepoint(0, 2) - landpoint(i * datacols + j, 2);
demslant_range(i, j) = (satepoint.array().pow(2).array().rowwise().sum().array().sqrt())[0];
}
}
//std::cout << "for time " << getCurrentTimeString() << std::endl;
// д<><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
omp_set_lock(&lock); //<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
plant_slant_range.saveImage(demslant_range, max_rows_ids, 0, 1);
count_lines = count_lines + line_invert;
std::cout << "rows:\t" << max_rows_ids << "\t-\t" << max_rows_ids + line_invert << "\t" << count_lines << "/" << dem_clip.height << "\t computing.....\t" << getCurrentTimeString() << endl;
omp_unset_lock(&lock); //<2F>ͷŻ<CDB7><C5BB><EFBFBD><EFBFBD><EFBFBD>
}
omp_destroy_lock(&lock); //<2F><><EFBFBD>ٻ<EFBFBD><D9BB><EFBFBD><EFBFBD><EFBFBD>
}
std::cout << "the row and col of the sar in dem:" << getCurrentTimeString() << std::endl;
{
gdalImage dem_r(this->dem_r_path);
gdalImage plant_slant_range(this->out_plant_slantRange_path);
gdalImage dem_rc = CreategdalImage(this->dem_rc_path, dem_r.height, dem_r.width, 2, dem_r.gt, dem_r.projection);
int line_invert = int(10000000 / dem_r.width);
line_invert = line_invert > 10 ? line_invert : 10;
int count_lines = 0;
omp_lock_t lock;
omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
std::cout << "the row and col of the sar:" << getCurrentTimeString() << std::endl;
#pragma omp parallel for num_threads(6) // NEW ADD
for (int max_rows_ids = 0; max_rows_ids < dem_r.height; max_rows_ids = max_rows_ids + line_invert) {
Eigen::MatrixXd dem_r_block = dem_r.getData(max_rows_ids, 0, line_invert, dem_r.width, 1); // <20>к<EFBFBD>
Eigen::MatrixXd slant_range = plant_slant_range.getData(max_rows_ids, 0, line_invert, dem_r.width, 1); // <20><><EFBFBD><EFBFBD>
Eigen::MatrixXd dem_c = (slant_range.array() - this->pstn.R0) / this->pstn.widthspace;
omp_set_lock(&lock); //<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
dem_rc.saveImage(dem_r_block, max_rows_ids, 0, 1);
dem_rc.saveImage(dem_c, max_rows_ids, 0, 2);
count_lines = count_lines + line_invert;
std::cout << "rows:\t" << max_rows_ids << "\t-\t" << max_rows_ids + line_invert << "\t" << count_lines << "/" << dem_r.height << "\t computing.....\t" << getCurrentTimeString() << endl;
omp_unset_lock(&lock); //<2F>ͷŻ<CDB7><C5BB><EFBFBD><EFBFBD><EFBFBD>
}
omp_destroy_lock(&lock); //<2F><><EFBFBD>ٻ<EFBFBD><D9BB><EFBFBD><EFBFBD><EFBFBD>
}
return 0;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>б<EFBFBD><D0B1> -- <20><><EFBFBD><EFBFBD>ֵ
/// </summary>
/// <returns></returns>
int simProcess::SARIncidentAngle()
{
std::cout << "the incidence angle and local incidence :" << getCurrentTimeString() << std::endl;
{
gdalImage dem_img(this->dem_path);
gdalImage sim_r_img(this->dem_r_path);
gdalImage localincidence_angle_img = CreategdalImage(this->out_localIncidenct_path, dem_img.height, dem_img.width, 1, dem_img.gt, dem_img.projection);// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
gdalImage incidence_angle_img = CreategdalImage(this->out_incidence_path, dem_img.height, dem_img.width, 1, dem_img.gt, dem_img.projection);// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
incidence_angle_img.setNoDataValue(-10, 1);
localincidence_angle_img.setNoDataValue(-10, 1);
double PRF = this->pstn.PRF;
double imgstarttime = this->pstn.imgStartTime;
int line_invert = int(5000000 / dem_img.width);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
line_invert = line_invert > 100 ? line_invert : 100;
int start_ids = 0; // <20><>ʾ1
int line_width = dem_img.width;
int count_lines = 0;
for (int max_rows_ids = 0; max_rows_ids < dem_img.height; max_rows_ids = max_rows_ids + line_invert) {
Eigen::MatrixXd sim_inclocal = incidence_angle_img.getData(max_rows_ids, 0, line_invert + 2, line_width, 1);
Eigen::MatrixXd sim_localinclocal = localincidence_angle_img.getData(max_rows_ids, 0, line_invert + 2, line_width, 1);
sim_inclocal = sim_inclocal.array() * 0 - 10;
sim_localinclocal = sim_localinclocal.array() * 0 - 10;
localincidence_angle_img.saveImage(sim_localinclocal, max_rows_ids, 0, 1);
incidence_angle_img.saveImage(sim_inclocal, max_rows_ids, 0, 1);
}
omp_lock_t lock;
omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
line_invert = int(200000000 / dem_img.width);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
for (int max_rows_ids = 1; max_rows_ids < dem_img.height; max_rows_ids = max_rows_ids + line_invert) {
start_ids = max_rows_ids - 1;
Eigen::MatrixXd demdata = dem_img.getData(max_rows_ids - 1, 0, line_invert + 2, line_width, 1);
Eigen::MatrixXd sim_r = sim_r_img.getData(max_rows_ids - 1, 0, line_invert + 2, line_width, 1).cast<double>(); //
Eigen::MatrixXd sim_inclocal = incidence_angle_img.getData(max_rows_ids - 1, 0, line_invert + 2, line_width, 1);
Eigen::MatrixXd sim_localinclocal = localincidence_angle_img.getData(max_rows_ids - 1, 0, line_invert + 2, line_width, 1);
//sim_r = sim_r.array() * (1 / PRF) + imgstarttime;
int rowcount = demdata.rows();
int colcount = demdata.cols();
#pragma omp parallel for num_threads(8) // NEW ADD
for (int i = 1; i < rowcount - 1; i++) {
// sataState =
Landpoint p0, p1, p2, p3, p4, slopeVector, landpoint, satepoint;
long double r;
for (int j = 1; j < colcount - 1; j++) {
r = sim_r(i, j);
Eigen::MatrixX<double> sataState = this->pstn.orbit.SatelliteSpacePoint(r / PRF + imgstarttime);
p0 = dem_img.getLandPoint(i + start_ids, j, demdata(i, j)); // <20><><EFBFBD><EFBFBD>
p1 = dem_img.getLandPoint(i + start_ids - 1, j, demdata(i - 1, j)); // 1
p2 = dem_img.getLandPoint(i + start_ids, j + 1, demdata(i, j + 1)); // 2
p3 = dem_img.getLandPoint(i + start_ids + 1, j, demdata(i + 1, j)); // 3
p4 = dem_img.getLandPoint(i + start_ids, j - 1, demdata(i, j - 1)); // 4
slopeVector = getSlopeVector(p0, p1, p2, p3, p4);
landpoint = LLA2XYZ(p0);
satepoint = Landpoint{ sataState(0,0),sataState(0,1) ,sataState(0,2) };
sim_localinclocal(i, j) = getlocalIncAngle(satepoint, landpoint, slopeVector);
//p0.ati = 0;
p0 = dem_img.getLandPoint(i + start_ids, j, demdata(i, j)); // <20><><EFBFBD><EFBFBD>
landpoint = LLA2XYZ(p0);
sim_inclocal(i, j) = getIncAngle(satepoint, landpoint);
}
}
int rows_save = sim_inclocal.rows() - 2;
//sim_inclocal =.array();
//sim_localinclocal = .array();
omp_set_lock(&lock); //<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
count_lines = count_lines + line_invert;
localincidence_angle_img.saveImage(sim_localinclocal.block(1, 0, rows_save, line_width), max_rows_ids, 0, 1);
incidence_angle_img.saveImage(sim_inclocal.block(1, 0, rows_save, line_width), max_rows_ids, 0, 1);
std::cout << "rows:\t" << max_rows_ids << "\t-\t" << max_rows_ids + line_invert << "\t" << count_lines << "/" << dem_img.height << "\t computing.....\t" << getCurrentTimeString() << endl;
omp_unset_lock(&lock); //<2F>ͷŻ<CDB7><C5BB><EFBFBD><EFBFBD><EFBFBD>
}
omp_destroy_lock(&lock); //<2F><><EFBFBD>ٻ<EFBFBD><D9BB><EFBFBD><EFBFBD><EFBFBD>
}
std::cout << "the incidence angle and local incidence over:\t" << getCurrentTimeString() << std::endl;
return 0;
}
/// <summary>
/// ģ<><C4A3>WGS<47><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SARֵ
/// </summary>
/// <returns></returns>
int simProcess::SARSimulationWGS()
{
std::cout << "computer the simulation value of evering dem meta, begining:\t" << getCurrentTimeString() << endl;
gdalImage localincidence_angle_img(this->out_localIncidenct_path);
gdalImage sim_sar_img = CreategdalImage(this->sar_sim_wgs_path, localincidence_angle_img.height, localincidence_angle_img.width, 1, localincidence_angle_img.gt, localincidence_angle_img.projection);// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int line_invert = int(5000000 / localincidence_angle_img.width);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
line_invert = line_invert > 100 ? line_invert : 100;
int start_ids = 0; // <20><>ʾ1
int line_width = localincidence_angle_img.width;
int count_lines = 0;
omp_lock_t lock;
omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#pragma omp parallel for num_threads(6) // NEW ADD
for (int max_rows_ids = 0; max_rows_ids < sim_sar_img.height; max_rows_ids = max_rows_ids + line_invert) {
Eigen::MatrixXd sim_localinclocal = localincidence_angle_img.getData(max_rows_ids, 0, line_invert, line_width, 1);
Eigen::MatrixXd sim_sar(line_invert, line_width);
sim_localinclocal = sim_localinclocal.array() * d2r;
// double((0.0133 * cos(localincangle) / pow(sin(localincangle + 0.1 * localincangle), 3)));
Eigen::MatrixXd cos_angle = sim_localinclocal.array().cos();
Eigen::MatrixXd sin_angle = sim_localinclocal.array().sin();
sim_sar = (0.0133 * cos_angle.array()) / ((sin_angle.array() + 0.1 * cos_angle.array()).pow(3));
omp_set_lock(&lock); //<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
count_lines = count_lines + line_invert;
sim_sar_img.saveImage(sim_sar, max_rows_ids, 0, 1);
std::cout << "rows:\t" << max_rows_ids << "\t-\t" << max_rows_ids + line_invert << "\t" << count_lines << "/" << sim_sar_img.height << "\t computing.....\t" << getCurrentTimeString() << endl;
omp_unset_lock(&lock); //<2F>ͷŻ<CDB7><C5BB><EFBFBD><EFBFBD><EFBFBD>
}
omp_destroy_lock(&lock); //<2F><><EFBFBD>ٻ<EFBFBD><D9BB><EFBFBD><EFBFBD><EFBFBD>
std::cout << "computer the simulation value of evering dem meta, begining:\t" << getCurrentTimeString() << endl;
return 0;
}
int simProcess::SARSimulation()
{
std::cout << "computer the simulation value of sim_sar, begining:\t" << getCurrentTimeString() << endl;
gdalImage sim_sar_wgs_img(this->sar_sim_wgs_path);
gdalImage sim_rc(this->dem_rc_path);
gdalImage localIncident_img(this->out_localIncidenct_path);
gdalImage sim_sar_img = CreategdalImage(this->sar_sim_path, this->pstn.height, this->pstn.width, 1, sim_sar_wgs_img.gt, sim_sar_wgs_img.projection, false);// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
sim_sar_img.setNoDataValue(-9999, 1);
//double PRF = this->pstn.PRF;
//double imgstarttime = this->pstn.imgStartTime;
int line_invert = int(30000000 / sim_sar_wgs_img.width);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
line_invert = line_invert > 100 ? line_invert : 100;
int start_ids = 0; // <20><>ʾ1
int line_width = sim_sar_wgs_img.width;
Eigen::MatrixXd sim_r(line_invert, line_width);
Eigen::MatrixXd sim_c(line_invert, line_width);
Eigen::MatrixXd sim_sum_h(line_invert, line_width);
Eigen::MatrixXd sim_rsc_orth(line_invert, line_width);
Eigen::MatrixXd sim_sum_sar(line_invert, line_width);
Eigen::MatrixXd demdata(line_invert, line_width);
Eigen::MatrixXd angle(line_invert, line_width);
// <20><>ʼ<EFBFBD><CABC>
do {
sim_sum_sar = sim_sar_img.getData(start_ids, 0, line_invert, this->pstn.width, 1).cast<double>();
sim_sum_sar = sim_sum_sar.array() * 0;
sim_sar_img.saveImage(sim_sum_sar, start_ids, 0, 1);
start_ids = start_ids + line_invert;
} while (start_ids < this->pstn.height);
{
// <20>ۼӼ<DBBC><D3BC><EFBFBD>ģ<EFBFBD><C4A3>ֵ
int rowcount = 0, colcount = 0;
int row_min = 0, row_max = 0;
start_ids = 0;
std::cout << "time:\tsim_arr_row_min\tsim_arr_row_max\tsim_arr_all_lines\tsim_row_min\tsim_row_max\tsim_row_min0\tsim_row_max0" << std::endl;;
do {
std::cout << "\n" << getCurrentTimeString() << "\t" << start_ids << "\t" << start_ids + line_invert << "\t" << sim_rc.height << "\t";
sim_r = sim_rc.getData(start_ids, 0, line_invert, line_width, 1).cast<double>(); // <20><>
sim_c = sim_rc.getData(start_ids, 0, line_invert, line_width, 2).cast<double>(); // <20><>
angle = localIncident_img.getData(start_ids, 0, line_invert, line_width, 1).cast<double>();
sim_rsc_orth = sim_sar_wgs_img.getData(start_ids, 0, line_invert, line_width, 1).cast<double>(); // <20><><EFBFBD><EFBFBD>ֵ
// <20><>Χ
row_min = (floor(sim_r.minCoeff()));
row_max = (ceil(sim_r.maxCoeff()));
std::cout << row_min << "\t" << row_max << "\t";
//std::cout << "line range:\t" << row_min << " - " << row_max << "\t computing.....\t" << getCurrentTimeString() << endl;
if (row_max < 0 || row_min>this->pstn.height) {
start_ids = start_ids + line_invert;
continue;
}
row_min = row_min <= 0 ? 0 : row_min;
row_max = row_max >= this->pstn.height ? this->pstn.height : row_max;
std::cout << row_min << "\t" << row_max << std::endl;
//sim_sum_sar =sim_sar.getData(row_min, 0, row_max-row_min+1, this->pstn.width, 1).cast<double>();
//sim_sum_count = sim_sar.getData(row_min, 0, row_max - row_min + 1, this->pstn.width, 2).cast<double>();
if (row_min >= row_max) {
break;
}
sim_sum_sar = sim_sar_img.getData(row_min, 0, row_max - row_min + 1, this->pstn.width, 1).cast<double>();
rowcount = sim_r.rows();
colcount = sim_r.cols();
#pragma omp parallel for num_threads(4) // NEW ADD
for (int i = 0; i < rowcount; i++) {
int row_ids = 0, col_ids = 0;
for (int j = 0; j < colcount; j++) {
row_ids = int(round(sim_r(i, j)));
col_ids = int(round(sim_c(i, j)));
if (row_ids >= 0 && row_ids < this->pstn.height && col_ids >= 0 && col_ids < this->pstn.width && (angle(i, j) < 90 || angle(i, j) > 270)) {
sim_sum_sar(row_ids - row_min, col_ids) += sim_rsc_orth(i, j);
}
}
}
sim_sar_img.saveImage(sim_sum_sar, row_min, 0, 1);
start_ids = start_ids + line_invert;
} while (start_ids < sim_rc.height);
std::cout << "\ncomputer the simulation value of sim_sar, overing :\t" << getCurrentTimeString() << endl;
}
}
{
std::cout << "Resample simulation value of sim_sar :\t" << getCurrentTimeString() << endl;
ResampleGDALs(this->sar_sim_path.c_str(), 1, GRIORA_Bilinear);
}
return 0;
}
int simProcess::in_sar_power()
{
std::cout << "compute the power value of ori sar, beiging:\t" << getCurrentTimeString() << endl;
gdalImage ori_sar(this->in_sar_path);
gdalImage sim_power = CreategdalImage(this->sar_power_path, ori_sar.height, ori_sar.width, 1, ori_sar.gt, ori_sar.projection);
sim_power.setNoDataValue(-9999, 1);
{
Eigen::MatrixXd band1(1, 1);
Eigen::MatrixXd band2(1, 1);
Eigen::MatrixXd power_value(1, 1);
int start_ids = 0;
int line_invert = int(8000000 / ori_sar.width);
line_invert = line_invert > 10 ? line_invert : 10;
int row_count = 0, col_count = 0;
do {
std::cout << "rows:\t" << start_ids << "/" << ori_sar.height << "\t computing.....\t" << getCurrentTimeString() << endl;
band1 = ori_sar.getData(start_ids, 0, line_invert, ori_sar.width, 1).cast<double>(); // a
band2 = ori_sar.getData(start_ids, 0, line_invert, ori_sar.width, 2).cast<double>(); // b
power_value = (band1.array().pow(2) + band2.array().pow(2) + 1).log10() * 10;// 10 * Eigen::log10(Eigen::pow(0.5, Eigen::pow(2, band1.array()) + Eigen::pow(2, band2.array()))).array();
sim_power.saveImage(power_value, start_ids, 0, 1);
start_ids = start_ids + line_invert;
} while (start_ids < ori_sar.height);
}
{
std::cout << "Resample the power value of ori sar :\t" << getCurrentTimeString() << endl;
ResampleGDALs(this->sar_power_path.c_str(), 1, GRIORA_Bilinear);
}
std::cout << "compute the power value of ori sar, ending:\t" << getCurrentTimeString() << endl;
{
std::cout << "=========================================\n";
std::cout << " the power image of sar :\n";
std::cout << this->sar_power_path.c_str() << "\n";
std::cout << "band 1 : power value \t 10*log10(b1^2+b2^2) \n";
std::cout << "=========================================\n";
}
return 0;
return 0;
}
int simProcess::Scatter2Grid(std::string lon_lat_path, std::string data_tiff, std::string grid_path, double space) {
gdalImage lon_lat_img(lon_lat_path);
double min_lon = 400, max_lon = -400, min_lat = 300, max_lat = -300;
{
int conver_lines = 2000;
for (int max_rows_ids = 0; max_rows_ids < lon_lat_img.height; max_rows_ids = max_rows_ids + conver_lines) {
Eigen::MatrixXd lon = lon_lat_img.getData(max_rows_ids, 0, conver_lines, lon_lat_img.width, 1);
Eigen::MatrixXd lat = lon_lat_img.getData(max_rows_ids, 0, conver_lines, lon_lat_img.width, 2);
int rows = lon.rows();
int cols = lon.cols();
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (min_lon > lon(i, j) && !isnan(lon(i, j)) && lon(i, j) > -200) {
min_lon = lon(i, j);
}
if (min_lat > lat(i, j) && !isnan(lat(i, j)) && lat(i, j) > -200) {
min_lat = lat(i, j);
}
if (max_lon < lon(i, j) && !isnan(lon(i, j)) && lon(i, j) > -200) {
max_lon = lon(i, j);
}
if (max_lat < lat(i, j) && !isnan(lat(i, j)) && lat(i, j) > -200) {
max_lat = lat(i, j);
}
}
}
}
}
std::cout << "lon:\t" << min_lon << " , " << max_lon << endl;
std::cout << "lat:\t" << min_lat << " , " << max_lat << endl;
double delta = space /( 110 * 1000);
int width = int((max_lon - min_lon) / delta) + 1;
int height = int((max_lat - min_lat) / delta) + 1;
Eigen::MatrixXd gt(2, 3);
gt(0, 0) = min_lon; gt(0, 1) = delta; gt(0, 2) = 0;//x
gt(1, 0) = max_lat; gt(1, 1) = 0; gt(1, 2) = -1*delta;//y
// #
char* pszSrcWKT = NULL;
OGRSpatialReference oSRS;
oSRS.importFromEPSG(4326);
//oSRS.SetUTM(50, true); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>120<32><30>
//oSRS.SetWellKnownGeogCS("WGS84");
oSRS.exportToWkt(&pszSrcWKT);
gdalImage grid_img = CreategdalImage(grid_path, height, width, 1, gt, pszSrcWKT, true);
int conver_lines = 2000;
for (int max_rows_ids = 0; max_rows_ids < grid_img.height; max_rows_ids = max_rows_ids + conver_lines) {
Eigen::MatrixXd grid_data = grid_img.getData(max_rows_ids, 0, conver_lines, width, 1);
grid_data = grid_data.array() * 0 - 9999;
grid_img.saveImage(grid_data, max_rows_ids, 0, 1);
}
grid_img.setNoDataValue(-9999, 1);
Eigen::MatrixXd grid_data = grid_img.getData(0, 0, grid_img.height, grid_img.width, 1);
gdalImage Range_data(data_tiff);
grid_img.InitInv_gt();
{
int conver_lines = 500;
int line_invert = 400;// <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>
int line_offset = 60;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
omp_lock_t lock;
omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int allCount = 0;
for (int max_rows_ids = 0; max_rows_ids < lon_lat_img.height; max_rows_ids = max_rows_ids + line_invert) {
Eigen::MatrixXd lon_data = lon_lat_img.getData(max_rows_ids, 0, conver_lines, lon_lat_img.width, 1);
Eigen::MatrixXd lat_data = lon_lat_img.getData(max_rows_ids, 0, conver_lines, lon_lat_img.width, 2);
Eigen::MatrixXd data = Range_data.getData(max_rows_ids, 0, conver_lines, lon_lat_img.width, 1);
int lon_row_count = lon_data.rows();
for (int i = 0; i < lon_row_count; i++) {
for (int j = 0; j < lon_lat_img.width; j++) {
Landpoint p = grid_img.getRow_Col(lon_data(i, j), lat_data(i, j));
lon_data(i, j) = p.lon;
lat_data(i, j) = p.lat;
}
}
int dem_rows_num = lon_data.rows();
int dem_cols_num = lon_data.cols();
#pragma omp parallel for num_threads(8) // NEW ADD
for (int i = 0; i < dem_rows_num - 1; i++) {
for (int j = 0; j < dem_cols_num - 1; j++) {
Point_3d p, p1, p2, p3, p4;
p1 = { lat_data(i,j),lon_data(i,j) };
p2 = { lat_data(i,j + 1),lon_data(i,j + 1) };
p3 = { lat_data(i + 1, j + 1),lon_data(i + 1, j + 1) };
p4 = { lat_data(i + 1, j),lon_data(i + 1, j) };
//if (angle(i, j) >= 90 && angle(i, j + 1) >= 90 && angle(i + 1, j) >= 90 && angle(i + 1, j + 1) >= 90) {
// continue;
//}
double temp_min_r = lat_data.block(i, j, 2, 2).minCoeff();
double temp_max_r = lat_data.block(i, j, 2, 2).maxCoeff();
double temp_min_c = lon_data.block(i, j, 2, 2).minCoeff();
double temp_max_c = lon_data.block(i, j, 2, 2).maxCoeff();
if ((int(temp_min_r) != int(temp_max_r)) && (int(temp_min_c) != int(temp_max_c))) {
for (int ii = int(temp_min_r); ii <= temp_max_r + 1; ii++) {
for (int jj = int(temp_min_c); jj < temp_max_c + 1; jj++) {
if (ii < 0 || ii >= height || jj < 0 || jj >= width) {
continue;
}
p = { double(ii),double(jj),0 };
//if (PtInRect(p, p1, p2, p3, p4)) {
p1.z = data(i, j);
p2.z = data(i, j + 1);
p3.z = data(i + 1, j + 1);
p4.z = data(i + 1, j);
p = invBilinear(p, p1, p2, p3, p4);
if (isnan(p.z)) {
continue;
}
if (p.x < 0) {
continue;
}
double mean = (p1.z + p2.z + p3.z + p4.z) / 4;
if (p.z > p1.z && p.z > p2.z && p.z > p3.z && p.z > p4.z) {
p.z = mean;
}
if (p.z < p1.z && p.z < p2.z && p.z < p3.z && p.z < p4.z) {
p.z = mean;
}
grid_data(ii , jj) = p.z;
//}
}
}
}
}
}
allCount = allCount + line_invert;
std::cout << "rows:\t" << allCount << "/" << lon_lat_img.height << "\t computing.....\t" << getCurrentTimeString() << endl;
}
}
grid_img.saveImage(grid_data, 0, 0, 1);
return 0;
}
/*
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϵ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pCur<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>
pLeftTop<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD>
pRightTop<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD>
pRightBelow<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pLeftBelow<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򷵻<EFBFBD> false
*/
bool PtInRect(Point_3d pCur, Point_3d pLeftTop, Point_3d pRightTop, Point_3d pRightBelow, Point_3d pLeftBelow)
{
int nCount = 4;//<2F><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Point_3d RectPoints[4] = { pLeftTop, pLeftBelow, pRightBelow, pRightTop };
int nCross = 0;
double lastPointX = -999.999;
for (int i = 0; i < nCount; i++)
{
//<2F><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Point_3d pBegin = RectPoints[i];
Point_3d pEnd = RectPoints[(i + 1) % nCount];
//<2F><><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>x<EFBFBD><78><EFBFBD><EFBFBD>,<2C><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>x<EFBFBD><78><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>Ҫô<D2AA>غ<EFBFBD>,Ҫô<D2AA><C3B4><EFBFBD>ཻ,<2C><><EFBFBD><EFBFBD>
if (pBegin.y == pEnd.y)continue;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pBegin,pEnd<6E><64><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>
if (pCur.y < min(pBegin.y, pEnd.y) || pCur.y > max(pBegin.y, pEnd.y))continue;
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>x<EFBFBD><78><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pBegin,pEndֱ<64>ߵĽ<DFB5><C4BD><EFBFBD><EFBFBD><EFBFBD>x<EFBFBD><78><EFBFBD><EFBFBD>
double x = (double)(pCur.y - pBegin.y) * (double)(pEnd.x - pBegin.x) / (double)(pEnd.y - pBegin.y) + pBegin.x;
if (x > pCur.x)//ֻ<><D6BB>pCur<75>ұ߽<D2B1><DFBD><EFBFBD>
{
if (x != lastPointX)//<2F><>ֹ<EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
nCross++;
lastPointX = x;
}
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD>򽻵<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE>
// <20><><EFBFBD><EFBFBD><EFBFBD>򽻵<EFBFBD>Ϊż<CEAA><C5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE>
return (nCross % 2 == 1);
}
int simProcess::ReflectTable_WGS2Range()
{
gdalImage sim_rc(this->dem_rc_path);
gdalImage sim_sar_img = CreategdalImage(this->out_ori_sim_tiff, this->pstn.height, this->pstn.width, 2, sim_rc.gt, sim_rc.projection, false);// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
gdalImage sim_sar_count_img = CreategdalImage(this->ori_sim_count_tiff, this->pstn.height, this->pstn.width, 1, sim_rc.gt, sim_rc.projection, false);// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
gdalImage localIncident_img(this->out_localIncidenct_path);
for (int max_rows_ids = 0; max_rows_ids < this->pstn.height; max_rows_ids = max_rows_ids + 1000) {
Eigen::MatrixXd sim_sar = sim_sar_img.getData(max_rows_ids, 0, 1000, this->pstn.width, 1);
Eigen::MatrixXd sim_sarc = sim_sar_img.getData(max_rows_ids, 0, 1000, this->pstn.width, 2);
Eigen::MatrixXd sim_sar_count = sim_sar_count_img.getData(max_rows_ids, 0, 1000, this->pstn.width, 1);
sim_sar = sim_sar.array() * 0 - 9999;
sim_sarc= sim_sar.array() * 0 - 9999;
sim_sar_count = sim_sar_count.array() * 0;
sim_sar_img.saveImage(sim_sar, max_rows_ids, 0, 1);
sim_sar_img.saveImage(sim_sarc, max_rows_ids, 0, 2);
sim_sar_count_img.saveImage(sim_sar_count, max_rows_ids, 0, 1);
}
sim_sar_img.setNoDataValue(-9999, 1);
sim_sar_img.setNoDataValue(-9999, 2);
int conver_lines = 5000;
int line_invert = 4000;// <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>
int line_offset = 60;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
omp_lock_t lock;
omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int allCount = 0;
for (int max_rows_ids = 0; max_rows_ids < sim_rc.height; max_rows_ids = max_rows_ids + line_invert) {
Eigen::MatrixXd angle = localIncident_img.getData(max_rows_ids, 0, conver_lines, sim_rc.width, 1).cast<double>();
Eigen::MatrixXd dem_r = sim_rc.getData(max_rows_ids, 0, conver_lines, sim_rc.width, 1);
Eigen::MatrixXd dem_c = sim_rc.getData(max_rows_ids, 0, conver_lines, sim_rc.width, 2);
int dem_rows_num = dem_r.rows();
int dem_cols_num = dem_r.cols();
// <20><><EFBFBD>²<EFBFBD>ֵ<EFBFBD><D6B5>γ<EFBFBD><CEB3>
//Eigen::MatrixXd dem_lon = dem_r;
//Eigen::MatrixXd dem_lat = dem_c;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>¾<EFBFBD>γ<EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int temp_r, temp_c;
int min_row = dem_r.minCoeff() + 1;
int max_row = dem_r.maxCoeff() + 1;
if (max_row < 0) {
continue;
}
int len_rows = max_row - min_row;
min_row = min_row < 0 ? 0 : min_row;
Eigen::MatrixXd sar_r = sim_sar_img.getData(min_row, 0, len_rows, this->pstn.width, 1);
Eigen::MatrixXd sar_c = sim_sar_img.getData(min_row, 0, len_rows, this->pstn.width, 2);
len_rows = sar_r.rows();
#pragma omp parallel for num_threads(8) // NEW ADD
for (int i = 0; i < dem_rows_num - 1; i++) {
for (int j = 0; j < dem_cols_num - 1; j++) {
Point_3d p, p1, p2, p3, p4;
Landpoint lp1, lp2, lp3, lp4;
lp1 = sim_rc.getLandPoint(i + max_rows_ids, j, 0);
lp2 = sim_rc.getLandPoint(i + max_rows_ids, j + 1, 0);
lp3 = sim_rc.getLandPoint(i + 1 + max_rows_ids, j + 1, 0);
lp4 = sim_rc.getLandPoint(i + 1 + max_rows_ids, j, 0);
p1 = { dem_r(i,j),dem_c(i,j) };
p2 = { dem_r(i,j + 1),dem_c(i,j + 1) };
p3 = { dem_r(i + 1,j + 1),dem_c(i + 1,j + 1) };
p4 = { dem_r(i + 1,j),dem_c(i + 1,j) };
//if (angle(i, j) >= 90 && angle(i, j + 1) >= 90 && angle(i + 1, j) >= 90 && angle(i + 1, j + 1) >= 90) {
// continue;
//}
double temp_min_r = dem_r.block(i, j, 2, 2).minCoeff();
double temp_max_r = dem_r.block(i, j, 2, 2).maxCoeff();
double temp_min_c = dem_c.block(i, j, 2, 2).minCoeff();
double temp_max_c = dem_c.block(i, j, 2, 2).maxCoeff();
if ((int(temp_min_r) != int(temp_max_r)) && (int(temp_min_c) != int(temp_max_c))) {
for (int ii = int(temp_min_r); ii <= temp_max_r + 1; ii++) {
for (int jj = int(temp_min_c); jj < temp_max_c + 1; jj++) {
if (ii < min_row || ii - min_row >= len_rows || jj < 0 || jj >= this->pstn.width) {
continue;
}
p = { double(ii),double(jj),0 };
//if (PtInRect(p, p1, p2, p3, p4)) {
p1.z = lp1.lon;
p2.z = lp2.lon;
p3.z = lp3.lon;
p4.z = lp4.lon;
p = invBilinear(p, p1, p2, p3, p4);
if (isnan(p.z)) {
continue;
}
if (p.x < 0) {
continue;
}
double mean = (p1.z + p2.z + p3.z + p4.z) / 4;
if (p.z > p1.z && p.z > p2.z && p.z > p3.z && p.z > p4.z) {
p.z = mean;
}
if (p.z < p1.z && p.z < p2.z && p.z < p3.z && p.z < p4.z) {
p.z = mean;
}
sar_r(ii - min_row, jj) = p.z;
p1.z = lp1.lat;
p2.z = lp2.lat;
p3.z = lp3.lat;
p4.z = lp4.lat;
p = invBilinear(p, p1, p2, p3, p4);
if (isnan(p.z)) {
continue;
}
if (p.x < 0) {
continue;
}
mean = (p1.z + p2.z + p3.z + p4.z) / 4;
if (p.z > p1.z && p.z > p2.z && p.z > p3.z && p.z > p4.z) {
p.z = mean;
}
if (p.z < p1.z && p.z < p2.z && p.z < p3.z && p.z < p4.z) {
p.z = mean;
}
sar_c(ii - min_row, jj) = p.z;
//}
}
}
}
}
}
omp_set_lock(&lock); //<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
sim_sar_img.saveImage(sar_r, min_row, 0, 1);
sim_sar_img.saveImage(sar_c, min_row, 0, 2);
allCount = allCount + conver_lines;
std::cout << "rows:\t" << allCount << "/" << sim_rc.height << "\t computing.....\t" << getCurrentTimeString() << endl;
omp_unset_lock(&lock); //<2F>ͷŻ<CDB7><C5BB><EFBFBD><EFBFBD><EFBFBD>
}
std::cout << "\t resample computing.....\t" << getCurrentTimeString() << endl;
{ int conver = 5000;
int line_invert = 4000;// <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>
ResampleGDALs(this->out_ori_sim_tiff.c_str(), 1, GRIORA_Bilinear);
ResampleGDALs(this->out_ori_sim_tiff.c_str(), 2, GRIORA_Bilinear);
}
return 0;
}
int simProcess::InitRPCIncAngle(std::string paras_path, std::string workspace_path, std::string out_dir_path, std::string in_dem_path, std::string in_rpc_lon_lat_paths, std::string out_inc_angle_path, std::string out_local_inc_angle_path, std::string out_inc_angle_geo_path, std::string out_local_inc_angle_geo_path)
{
this->pstn = PSTNAlgorithm(paras_path); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
this->in_rpc_lon_lat_path = in_rpc_lon_lat_paths;
this->in_dem_path = in_dem_path;
this->outSpace_path = out_dir_path;
this->workSpace_path = workspace_path;
// <20><>ʱ<EFBFBD>ļ<EFBFBD>
this->dem_path = JoinPath(this->workSpace_path, "SAR_dem.tiff");
this->dem_rc_path = JoinPath(this->workSpace_path, "dem_rc.tiff");
this->dem_r_path = JoinPath(this->workSpace_path, "dem_r.tiff");
this->out_incidence_path = out_inc_angle_geo_path;
this->out_localIncidenct_path = out_local_inc_angle_geo_path;
this->rpc_wgs_path = JoinPath(this->workSpace_path, "rcp2dem_wgs.tiff");
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
this->out_inc_angle_rpc_path = out_inc_angle_path;
this->out_local_inc_angle_rpc_path = out_local_inc_angle_path;
std::cout << "==========================================================================" << endl;
std::cout << "in_dem_path" << ":\t" << this->in_dem_path << endl;
std::cout << "in_rpc_lon_lat_path" << ":\t" << this->in_rpc_lon_lat_path << endl;
std::cout << "workSpace_path" << ":\t" << this->workSpace_path << endl;
std::cout << "out_dir_path" << ":\t" << this->out_dir_path << endl;
std::cout << "out_inc_angle_path" << ":\t" << this->out_incidence_path << endl;
std::cout << "out_local_inc_angle_path" << ":\t" << this->out_localIncidenct_path << endl;
std::cout << "==========================================================================" << endl;
this->createRPCDEM();
this->dem2SAR_row(); // <20><>ȡ<EFBFBD>к<EFBFBD>
this->SARIncidentAngle();
this->SARIncidentAngle_RPC();
this->in_sar_power();
return 0;
return 0;
}
int simProcess::dem2SAR_row()
{
std::cout << "the row of the sar in dem:" << getCurrentTimeString() << std::endl;
{
gdalImage dem_clip(this->dem_path);
double dem_mean = dem_clip.mean();
gdalImage sim_r_reprocess = CreategdalImage(this->dem_r_path, dem_clip.height, dem_clip.width, 1, dem_clip.gt, dem_clip.projection);
gdalImage sim_rc_reprocess = CreategdalImage(this->dem_rc_path, dem_clip.height, dem_clip.width, 2, dem_clip.gt, dem_clip.projection);
int line_invert = int(15000000 / dem_clip.width);
line_invert = line_invert > 10 ? line_invert : 10;
int count_lines = 0;
omp_lock_t lock;
omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#pragma omp parallel for num_threads(8) // NEW ADD
for (int max_rows_ids = 0; max_rows_ids < dem_clip.height; max_rows_ids = max_rows_ids + line_invert) {
//line_invert = dem_clip.height - max_rows_ids > line_invert ? line_invert : dem_clip.height - max_rows_ids;
Eigen::MatrixXd demdata = dem_clip.getData(max_rows_ids, 0, line_invert, dem_clip.width, 1);
Eigen::MatrixXd sim_r = demdata.array() * 0;
Eigen::MatrixXd sim_c = demdata.array() * 0;
int datarows = demdata.rows();
int datacols = demdata.cols();
Eigen::MatrixX<double> landpoint(datarows * datacols, 3);
for (int i = 0; i < datarows; i++) {
for (int j = 0; j < datacols; j++) {
landpoint(i * datacols + j, 0) = i + max_rows_ids;
landpoint(i * datacols + j, 1) = j;
landpoint(i * datacols + j, 2) = demdata(i, j); // <20><>Ϊ0 <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ʼ
}
}
landpoint = dem_clip.getLandPoint(landpoint);
//landpoint.col(2) = landpoint.col(2).array() * 0;
landpoint = LLA2XYZ(landpoint);
landpoint = this->pstn.PSTN(landpoint, dem_mean); // time,r,c
//std::cout << "for time " << getCurrentTimeString() << std::endl;
for (int i = 0; i < datarows; i++) {
for (int j = 0; j < datacols; j++) {
sim_r(i, j) = landpoint(i * datacols + j, 1);
sim_c(i, j) = landpoint(i * datacols + j, 2);
}
}
//std::cout << "for time " << getCurrentTimeString() << std::endl;
// д<><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
omp_set_lock(&lock); //<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
sim_r_reprocess.saveImage(sim_r, max_rows_ids, 0, 1);
sim_rc_reprocess.saveImage(sim_r, max_rows_ids, 0, 1);
sim_rc_reprocess.saveImage(sim_c, max_rows_ids, 0, 2);
count_lines = count_lines + line_invert;
std::cout << "rows:\t" << max_rows_ids << "\t-\t" << max_rows_ids + line_invert << "\t" << count_lines << "/" << dem_clip.height << "\t computing.....\t" << getCurrentTimeString() << endl;
omp_unset_lock(&lock); //<2F>ͷŻ<CDB7><C5BB><EFBFBD><EFBFBD><EFBFBD>
}
omp_destroy_lock(&lock); //<2F><><EFBFBD>ٻ<EFBFBD><D9BB><EFBFBD><EFBFBD><EFBFBD>
std::cout << "dem2SAR_Row_col dem_2_sarRC over " << getCurrentTimeString() << std::endl;
std::cout << "=========================================\n";
std::cout << "the row and col of the sar in dem:\n";
std::cout << this->dem_r_path << "\n";
std::cout << "band 1 : the row of the sar \n";
std::cout << "=========================================\n";
}
return 0;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD>RPC<50><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <returns></returns>
int simProcess::SARIncidentAngle_RPC() {
this->calGEC_Incident_localIncident_angle(this->dem_path, this->in_rpc_lon_lat_path, this->out_inc_angle_rpc_path, this->out_local_inc_angle_rpc_path, this->pstn);
return 0;
}
int simProcess::createRPCDEM()
{
std::cout << "dem2SAR_Row_col begin time:" << getCurrentTimeString() << std::endl;
{
gdalImage dem(this->in_dem_path);
gdalImage lonlat(this->in_rpc_lon_lat_path);
DemBox box{ 9999,9999,-9999,-9999 };
{
int start_ids = 0;
int line_invert = int(4000000 / dem.width);
line_invert = line_invert > 10 ? line_invert : 10;
for (start_ids = 0; start_ids < this->pstn.height; start_ids = start_ids + line_invert) {
std::cout << "rows:\t" << start_ids << "/" << this->pstn.height << "\t computing.....\t" << getCurrentTimeString() << endl;
Eigen::MatrixXd lon = lonlat.getData(start_ids, 0, line_invert, this->pstn.width, 1);
Eigen::MatrixXd lat = lonlat.getData(start_ids, 0, line_invert, this->pstn.width, 2);
double min_lat = lat.array().minCoeff();
double max_lat = lat.array().maxCoeff();
double min_lon = lon.array().minCoeff();
double max_lon = lon.array().maxCoeff();
box.min_lat = min_lat < box.min_lat ? min_lat : box.min_lat;
box.max_lat = max_lat > box.max_lat ? max_lat : box.max_lat;;
box.min_lon = min_lon < box.min_lon ? min_lon : box.min_lon;;
box.max_lon = max_lon > box.max_lon ? max_lon : box.max_lon;;
}
}
std::cout << "prepare over" << getCurrentTimeString() << std::endl;
double dist_lat = box.max_lat - box.min_lat;
double dist_lon = box.max_lon - box.min_lon;
dist_lat = 0.1 * dist_lat;
dist_lon = 0.1 * dist_lon;
box.min_lat = box.min_lat - dist_lat;
box.max_lat = box.max_lat + dist_lat;
box.min_lon = box.min_lon - dist_lon;
box.max_lon = box.max_lon + dist_lon;
std::cout << "box:" << endl;
std::cout << "min_lat-max_lat:\t" << box.min_lat << "\t" << box.max_lat << endl;
std::cout << "min_lon-max_lon:\t" << box.min_lon << "\t" << box.max_lon << endl;
std::cout << "cal box of sar over" << endl;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD>С
int width = 1.5 * this->pstn.width;
int height = 1.5 * this->pstn.height;
double heightspace = (box.max_lat - box.min_lat) / height;
double widthspace = (box.max_lon - box.min_lon) / width;
std::cout << "resample dem:\n" << getCurrentTimeString() << std::endl;
std::cout << "in_dem:\t" << this->in_dem_path << endl;
std::cout << "out_dem:\t" << this->dem_path << endl;
std::cout << "width-height:\t" << width << "-" << height << endl;
std::cout << "widthspace\t-\theight\tspace:\t" << widthspace << "\t-\t" << heightspace << endl;
int pBandIndex[1] = { 1 };
int pBandCount[1] = { 1 };
double gt[6] = {
box.min_lon,widthspace,0, //x
box.max_lat,0,-heightspace//y
};
//boost::filesystem::copy(dem_path, this->dem_path);
ResampleGDAL(this->in_dem_path.c_str(), this->dem_path.c_str(), gt, width, height, GRA_Bilinear);
std::cout << "resample dem over:\n" << getCurrentTimeString() << std::endl;
std::cout << "remove sim_rc_path:\t" << this->dem_rc_path << std::endl;
}
return 0;
}
/// <summary>
/// ģ<><C4A3>SARӰ<52><D3B0>
/// </summary>
/// <param name="dem_path">demӰ<6D><D3B0></param>
/// <param name="sim_rc_path">rc Ӱ<><D3B0></param>
/// <param name="sim_sar_path"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>sarӰ<72><D3B0></param>
/// <param name="PSTN"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
/// <returns>ִ<><D6B4>״̬</returns>
int simProcess::sim_SAR(std::string dem_path, std::string sim_rc_path, std::string sim_sar_path, PSTNAlgorithm PSTN)
{
std::cout << "computer the simulation value of evering dem meta, begining:\t" << getCurrentTimeString() << endl;
gdalImage dem_img(dem_path);
gdalImage sim_rc(sim_rc_path);
gdalImage sim_sar = CreategdalImage(sim_sar_path, dem_img.height, dem_img.width, 2, dem_img.gt, dem_img.projection);// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sim_sar.setNoDataValue(-9999, 1);
double PRF = this->pstn.PRF;
double imgstarttime = this->pstn.imgStartTime;
int line_invert = int(50000000 / dem_img.width);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
line_invert = line_invert > 100 ? line_invert : 100;
int start_ids = 0; // <20><>ʾ1
int line_width = dem_img.width;
Eigen::MatrixX<double> sim_r(line_invert, line_width);
Eigen::MatrixXd sim_c(line_invert, line_width);
Eigen::MatrixXd dem(line_invert, line_width);
Eigen::MatrixXd sim_rsc(line_invert, line_width);
Eigen::MatrixXd sim_inclocal(line_invert, line_width);
int rowcount = 0, colcount = 0;
//omp_lock_t lock;
//omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
do {
std::cout << "rows:\t" << start_ids << "-" << start_ids + line_invert + 2 << "/" << dem_img.height << "\t computing.....\t" << getCurrentTimeString() << endl;
dem = dem_img.getData(start_ids, 0, line_invert + 2, line_width, 1);
sim_r = sim_rc.getData(start_ids, 0, line_invert + 2, line_width, 1).cast<double>();
sim_r = sim_r.array() * (1 / PRF) + imgstarttime;
//sim_c = sim_rc.getData(start_ids, 0, line_invert + 1, line_width, 2);
sim_rsc = dem.array() * 0;
sim_inclocal = dem.array() * 0 - 9999;
rowcount = dem.rows();
colcount = dem.cols();
#pragma omp parallel for num_threads(4) // NEW ADD
for (int i = 1; i < rowcount - 1; i++) {
Eigen::MatrixX<double> sataState = sim_r.row(i).reshaped(line_width, 1);
sataState = this->pstn.orbit.SatelliteSpacePoint(sataState);
Landpoint p0, p1, p2, p3, p4, slopeVector, landpoint, satepoint;
double localincangle;
for (int j = 1; j < colcount - 1; j++) {
p0 = dem_img.getLandPoint(i + start_ids, j, dem(i, j)); // <20><><EFBFBD><EFBFBD>
p1 = dem_img.getLandPoint(i + start_ids - 1, j, dem(i - 1, j)); // 1
p2 = dem_img.getLandPoint(i + start_ids, j + 1, dem(i, j + 1)); // 2
p3 = dem_img.getLandPoint(i + start_ids + 1, j, dem(i + 1, j)); // 3
p4 = dem_img.getLandPoint(i + start_ids, j - 1, dem(i, j - 1)); // 4
slopeVector = getSlopeVector(p0, p1, p2, p3, p4);
landpoint = LLA2XYZ(p0);
satepoint = Landpoint{ sataState(j,0),sataState(j,1) ,sataState(j,2) };
localincangle = getlocalIncAngle(satepoint, landpoint, slopeVector);
sim_inclocal(i, j) = localincangle;
if (localincangle < 90)
{
localincangle = localincangle * d2r;
sim_rsc(i, j) = 100 * double((0.0133 * cos(localincangle) / pow(sin(localincangle + 0.1 * localincangle), 3)));
//sim_rsc(i, j) = sim_rsc(i, j) > 100 ? -9999 : sim_rsc(i, j);
}
}
}
//omp_set_lock(&lock); //<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
//std::cout << sim_rsc(1, 1961) << endl;
sim_sar.saveImage(sim_rsc.block(1, 0, rowcount - 2, colcount), start_ids + 1, 0, 1);
sim_sar.saveImage(sim_inclocal.block(1, 0, rowcount - 2, colcount), start_ids + 1, 0, 2);
//omp_unset_lock(&lock); //<2F>ͷŻ<CDB7><C5BB><EFBFBD><EFBFBD><EFBFBD>
start_ids = start_ids + line_invert - 4;
} while (start_ids < dem_img.height);
//omp_destroy_lock(&lock); //<2F><><EFBFBD>ٻ<EFBFBD><D9BB><EFBFBD><EFBFBD><EFBFBD>
std::cout << "computer the simulation value of evering dem meta, over:\t" << getCurrentTimeString() << endl;
std::cout << "==========================================================" << endl;
std::cout << "the simulation sar value Raster has the projection that is same of dem" << endl;
std::cout << sim_sar_path << endl;
std::cout << "band 1: the simulation sar value" << endl;
std::cout << "band 2: the local incident angle " << endl;
std::cout << "==========================================================" << endl;
return 0;
}
int simProcess::dem2aspect_slope(std::string dem_path, std::string aspect_path, std::string slope_path)
{
std::cout << "computer aspect and slop begining:\t" << getCurrentTimeString() << endl;
GDALAllRegister();// ע<><D7A2><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff");
GDALDataset* dem = (GDALDataset*)(GDALOpen(dem_path.c_str(), GA_ReadOnly));
GDALDEMProcessing(aspect_path.c_str(), dem, "aspect", NULL, NULL, NULL);
GDALDEMProcessing(slope_path.c_str(), dem, "slope", NULL, NULL, NULL);
GDALClose(dem);
std::cout << "computer aspect and slop overing:\t" << getCurrentTimeString() << endl;
return 0;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>кţ<D0BA><C5A3><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɲ<EFBFBD><C9B2><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="sim_rc_path"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD></param>
/// <param name="sim_orth_path"><3E><><EFBFBD>䵥Ԫ<E4B5A5><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
/// <param name="sim_sum_path">ģ<><C4A3>Ӱ<EFBFBD><D3B0>·<EFBFBD><C2B7></param>
/// <returns></returns>
int simProcess::sim_sum_SAR(std::string sim_dem_path, std::string sim_rc_path, std::string sim_orth_path, std::string sim_sum_path, PSTNAlgorithm PSTN)
{
std::cout << "computer the simulation value of sim_sar, begining:\t" << getCurrentTimeString() << endl;
//gdalImage dem_img(dem_path);
gdalImage sim_rc(sim_rc_path);
gdalImage sim_rsc(sim_orth_path);
gdalImage dem(sim_dem_path);
gdalImage sim_sar = CreategdalImage(sim_sum_path, this->pstn.height, this->pstn.width, 1, sim_rc.gt, sim_rc.projection, false);// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
sim_sar.setNoDataValue(-9999, 1);
//double PRF = this->pstn.PRF;
//double imgstarttime = this->pstn.imgStartTime;
int line_invert = int(16000000 / sim_rc.width);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
line_invert = line_invert > 100 ? line_invert : 100;
int start_ids = 0; // <20><>ʾ1
int line_width = sim_rc.width;
Eigen::MatrixX<double> sim_r(line_invert, line_width);
Eigen::MatrixXd sim_c(line_invert, line_width);
Eigen::MatrixXd sim_sum_h(line_invert, line_width);
Eigen::MatrixXd sim_rsc_orth(line_invert, line_width);
Eigen::MatrixXd sim_sum_sar(line_invert, line_width);
Eigen::MatrixXd sim_sum_count(line_invert, line_width);
Eigen::MatrixXd demdata(line_invert, line_width);
// <20><>ʼ<EFBFBD><CABC>
do {
sim_sum_sar = sim_sar.getData(start_ids, 0, line_invert, this->pstn.width, 1).cast<double>();
sim_sum_sar = sim_sum_sar.array() * 0;
sim_sar.saveImage(sim_sum_sar, start_ids, 0, 1);
sim_sar.saveImage(sim_sum_sar, start_ids, 0, 2);
sim_sar.saveImage(sim_sum_sar, start_ids, 0, 3);
start_ids = start_ids + line_invert;
} while (start_ids < this->pstn.height);
{
// <20>ۼӼ<DBBC><D3BC><EFBFBD>ģ<EFBFBD><C4A3>ֵ
int rowcount = 0, colcount = 0;
int row_min = 0, row_max = 0;
start_ids = 0;
std::cout << "time:\tsim_arr_row_min\tsim_arr_row_max\tsim_arr_all_lines\tsim_row_min\tsim_row_max\tsim_row_min0\tsim_row_max0" << std::endl;;
do {
std::cout << "\n" << getCurrentTimeString() << "\t" << start_ids << "\t" << start_ids + line_invert << "\t" << sim_rc.height << "\t";
sim_r = sim_rc.getData(start_ids, 0, line_invert, line_width, 1).cast<double>(); // <20><>
sim_c = sim_rc.getData(start_ids, 0, line_invert, line_width, 2).cast<double>(); // <20><>
sim_rsc_orth = sim_rsc.getData(start_ids, 0, line_invert, line_width, 1).cast<double>(); // <20><><EFBFBD><EFBFBD>ֵ
demdata = dem.getData(start_ids, 0, line_invert, line_width, 1).cast<double>(); // <20><><EFBFBD><EFBFBD>ֵ
// <20><>Χ
row_min = (floor(sim_r.minCoeff()));
row_max = (ceil(sim_r.maxCoeff()));
std::cout << row_min << "\t" << row_max << "\t";
//std::cout << "line range:\t" << row_min << " - " << row_max << "\t computing.....\t" << getCurrentTimeString() << endl;
if (row_max < 0 || row_min>this->pstn.height) {
start_ids = start_ids + line_invert;
continue;
}
row_min = row_min <= 0 ? 0 : row_min;
row_max = row_max >= this->pstn.height ? this->pstn.height : row_max;
std::cout << row_min << "\t" << row_max << std::endl;
//sim_sum_sar =sim_sar.getData(row_min, 0, row_max-row_min+1, this->pstn.width, 1).cast<double>();
//sim_sum_count = sim_sar.getData(row_min, 0, row_max - row_min + 1, this->pstn.width, 2).cast<double>();
if (row_min >= row_max) {
break;
}
sim_sum_sar = sim_sar.getData(row_min, 0, row_max - row_min + 1, this->pstn.width, 1).cast<double>();
sim_sum_count = sim_sar.getData(row_min, 0, row_max - row_min + 1, this->pstn.width, 2).cast<double>();
sim_sum_h = sim_sar.getData(row_min, 0, row_max - row_min + 1, this->pstn.width, 3).cast<double>(); // <20><>
rowcount = sim_r.rows();
colcount = sim_r.cols();
#pragma omp parallel for num_threads(4) // NEW ADD
for (int i = 0; i < rowcount; i++) {
int row_ids = 0, col_ids = 0;
for (int j = 0; j < colcount; j++) {
row_ids = int(round(sim_r(i, j)));
col_ids = int(round(sim_c(i, j)));
if (row_ids >= 0 && row_ids < this->pstn.height && col_ids >= 0 && col_ids < this->pstn.width) {
sim_sum_sar(row_ids - row_min, col_ids) += sim_rsc_orth(i, j);
sim_sum_count(row_ids - row_min, col_ids) += 1;
sim_sum_h(row_ids - row_min, col_ids) += demdata(i, j);
}
}
}
sim_sar.saveImage(sim_sum_sar, row_min, 0, 1);
sim_sar.saveImage(sim_sum_count, row_min, 0, 2);
sim_sar.saveImage(sim_sum_h, row_min, 0, 3);
start_ids = start_ids + line_invert;
} while (start_ids < sim_rc.height);
std::cout << "\ncomputer the simulation value of sim_sar, overing :\t" << getCurrentTimeString() << endl;
}
}
{
std::cout << "computer the height of sim_sar, begining :\t" << getCurrentTimeString() << endl;
Eigen::MatrixXd sim_sum_h(1, 1);
Eigen::MatrixXd sim_sum_count(1, 1);
int start_ids = 0;
int line_invert = int(8000000 / this->pstn.width);
line_invert = line_invert > 10 ? line_invert : 10;
int row_count = 0, col_count = 0;
do {
sim_sum_count = sim_sar.getData(start_ids, 0, line_invert, this->pstn.width, 2).cast<double>(); // <20><>
sim_sum_h = sim_sar.getData(start_ids, 0, line_invert, this->pstn.width, 3).cast<double>(); // <20><>
row_count = sim_sum_h.rows();
col_count = sim_sum_h.cols();
std::cout << "min~max:" << endl;
std::cout << sim_sum_count.minCoeff() << "\t" << sim_sum_count.maxCoeff() << endl;
std::cout << sim_sum_h.minCoeff() << "\t" << sim_sum_h.maxCoeff() << endl;
for (int i = 0; i < row_count; i++) {
for (int j = 0; j < col_count; j++) {
if (sim_sum_count(i, j) == 0) {
sim_sum_h(i, j) = 0;
}
else {
sim_sum_h(i, j) = sim_sum_h(i, j) / sim_sum_count(i, j);
}
}
}
sim_sar.saveImage(sim_sum_h, start_ids, 0, 3);
start_ids = start_ids + line_invert;
} while (start_ids < this->pstn.height);
std::cout << "computer the height of sim_sar, overing :\t" << getCurrentTimeString() << endl;
}
{
std::cout << "compute the average value of sim_sar, beiging:\t" << getCurrentTimeString() << endl;
//ResampleGDALs(sim_sum_path.c_str(), 1, GRIORA_Bilinear);
//ResampleGDALs(sim_sum_path.c_str(), 3, GRIORA_Bilinear);
std::cout << "compute the average value of sim_sar, over :\t" << getCurrentTimeString() << endl;
}
{
std::cout << "=========================================\n";
std::cout << "sim_sar_tif infomation :\n";
std::cout << sim_sum_path << "\n";
std::cout << "band 1 : simulation sar value \n";
std::cout << "band 2 : the sum of the effective value from the dem \n";
std::cout << "band 3 : the dem altitude of the effective value from the dem \n";
std::cout << "=========================================\n";
}
return 0;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD>
/// </summary>
/// <param name="ori_sar_path"></param>
/// <param name="out_sar_power_path"></param>
/// <returns></returns>
int simProcess::ori_sar_power(std::string ori_sar_path, std::string out_sar_power_path)
{
std::cout << "compute the power value of ori sar, beiging:\t" << getCurrentTimeString() << endl;
gdalImage ori_sar(ori_sar_path);
gdalImage sim_power = CreategdalImage(out_sar_power_path, ori_sar.height, ori_sar.width, 1, ori_sar.gt, ori_sar.projection);
sim_power.setNoDataValue(-9999, 1);
{
Eigen::MatrixXd band1(1, 1);
Eigen::MatrixXd band2(1, 1);
Eigen::MatrixXd power_value(1, 1);
int start_ids = 0;
int line_invert = int(8000000 / ori_sar.width);
line_invert = line_invert > 10 ? line_invert : 10;
int row_count = 0, col_count = 0;
do {
std::cout << "rows:\t" << start_ids << "/" << ori_sar.height << "\t computing.....\t" << getCurrentTimeString() << endl;
band1 = ori_sar.getData(start_ids, 0, line_invert, ori_sar.width, 1).cast<double>(); // a
band2 = ori_sar.getData(start_ids, 0, line_invert, ori_sar.width, 2).cast<double>(); // b
//power_value = band2.array() * 0-9999;
power_value = (band1.array().pow(2) + band2.array().pow(2) + 1).log10() * 10;// 10 * Eigen::log10(Eigen::pow(0.5, Eigen::pow(2, band1.array()) + Eigen::pow(2, band2.array()))).array();
//if () {
//
//}// power_value.isNaN())
//std::cout << power_value.minCoeff() << "\t" << power_value.maxCoeff() << "\t" << endl;
//std::cout << "band 1\t" << band1.minCoeff() << "\t" << band1.maxCoeff() << "\t" << endl;
//std::cout << "band 2\t" << band2.minCoeff() << "\t" << band2.maxCoeff() << "\t" << endl;
sim_power.saveImage(power_value, start_ids, 0, 1);
start_ids = start_ids + line_invert;
} while (start_ids < ori_sar.height);
}
{
std::cout << "Resample the power value of ori sar :\t" << getCurrentTimeString() << endl;
ResampleGDALs(out_sar_power_path.c_str(), 1, GRIORA_Cubic);
}
std::cout << "compute the power value of ori sar, ending:\t" << getCurrentTimeString() << endl;
{
std::cout << "=========================================\n";
std::cout << " the power image of sar :\n";
std::cout << out_sar_power_path << "\n";
std::cout << "band 1 : power value \t 10*log10(b1^2+b2^2) \n";
std::cout << "=========================================\n";
}
return 0;
}
int simProcess::createImageMatchModel(std::string ori_sar_rsc_path, std::string ori_sar_rsc_jpg_path, std::string sim_sar_path, std::string sim_sar_jpg_path, std::string matchmodel_path)
{
// ת<><D7AA>Ӱ<EFBFBD><D3B0>
{
std::cout << "compute the power value of sar, begining:\t" << getCurrentTimeString() << endl;
this->matchmodel.gdal2JPG(ori_sar_rsc_path, ori_sar_rsc_jpg_path, 1);
this->matchmodel.gdal2JPG(sim_sar_path, sim_sar_jpg_path, 1);
std::cout << "compute the power value of sar, ending:\t" << getCurrentTimeString() << endl;
}
// <20><><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5>ģ<EFBFBD><C4A3>
{
this->matchmodel.offsetXY_matrix = this->matchmodel.ImageMatch_ori_sim(ori_sar_rsc_jpg_path, sim_sar_jpg_path);
if (this->matchmodel.offsetXY_matrix.rows() < 7) { // <20>޷<EFBFBD><DEB7><EFBFBD><EFBFBD>о<EFBFBD>У׼
this->isMatchModel = false;
}
else {
//this->matchmodel.match_model = this->matchmodel.CreateMatchModel(this->matchmodel.offsetXY_matrix);
//this->matchmodel.outMatchModel(matchmodel_path);
}
}
return 0;
}
/// <summary>
/// <20><><EFBFBD>ݾ<EFBFBD>ȷƥ<C8B7><C6A5><EFBFBD>õ<EFBFBD><C3B5>ľ<EFBFBD><C4BE><EFBFBD>ģ<EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>
/// </summary>
/// <param name="sim_rc_path"></param>
/// <param name="matchmodel"></param>
/// <returns></returns>
int simProcess::correctOrth_rc(std::string sim_rc_path, ImageMatch matchmodel)
{
gdalImage sim_rc(sim_rc_path);
{
int lineVert = (1000000 / sim_rc.width);
int start_ids = 0;
do {
Eigen::MatrixXd sim_r = sim_rc.getData(start_ids, 0, lineVert, sim_rc.width, 1);
Eigen::MatrixXd sim_c = sim_rc.getData(start_ids, 0, lineVert, sim_rc.width, 2);
// <20><><EFBFBD><EFBFBD>ƫ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>
int rowcount = sim_r.rows();
int colcount = sim_r.cols();
for (int i = 0; i < rowcount; i++) {
Eigen::MatrixXd temp = matchmodel.correctMatchModel(sim_r.row(i), sim_c.col(i));
sim_r.row(i) = temp.row(0).array();
sim_c.row(i) = temp.row(1).array();
}
// д<><D0B4>Ӱ<EFBFBD><D3B0>
sim_rc.saveImage(sim_r, start_ids, 0, 1);
sim_rc.saveImage(sim_c, start_ids, 0, 2);
start_ids = start_ids + lineVert;
} while (start_ids < sim_rc.height);
}
return 0;
}
/// <summary>
///
/// </summary>
/// <param name="orth_rc_path"></param>
/// <param name="dem_path"></param>
/// <param name="out_inclocal_path"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
/// <param name="out_dem_path"><3E><><EFBFBD><EFBFBD>dem</param>
/// <param name="out_count_path">count<6E><74>tif</param>
/// <returns></returns>
int simProcess::correct_ati(std::string orth_rc_path, std::string dem_path, std::string out_inclocal_path, std::string out_dem_path, std::string out_count_path, PSTNAlgorithm PSTN)
{
std::cout << "computer the simulation value of evering dem meta, begining:\t" << getCurrentTimeString() << endl;
gdalImage dem_img(dem_path);
gdalImage orth_rc(orth_rc_path);
//gdalImage ori_inclocal = CreategdalImage(out_inclocal_path, this->pstn.height, this->pstn.width, 1, orth_rc.gt, orth_rc.projection, false);// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
gdalImage ori_dem = CreategdalImage(out_dem_path, this->pstn.height, this->pstn.width, 1, orth_rc.gt, orth_rc.projection, false);// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
gdalImage ori_count = CreategdalImage(out_count_path, this->pstn.height, this->pstn.width, 1, orth_rc.gt, orth_rc.projection, false);// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><>ʼ<EFBFBD><CABC>
{
int line_invert = int(500000 / this->pstn.width);
line_invert = line_invert > 10 ? line_invert : 10;
int start_ids = 0;
do {
Eigen::MatrixXd sar_dem = ori_dem.getData(start_ids, 0, line_invert, this->pstn.width, 1);
//Eigen::MatrixXd sar_inclocal = ori_inclocal.getData(start_ids, 0, line_invert, this->pstn.width, 1);
Eigen::MatrixXd sar_count = ori_count.getData(start_ids, 0, line_invert, this->pstn.width, 1);
sar_dem = sar_dem.array() * 0;
//sar_inclocal = sar_inclocal.array() * 0;
sar_count = sar_count.array() * 0;
ori_dem.saveImage(sar_dem, start_ids, 0, 1);
//ori_inclocal.saveImage(sar_inclocal, start_ids, 0, 1);
ori_count.saveImage(sar_count, start_ids, 0, 1);
start_ids = start_ids + line_invert;
} while (start_ids < this->pstn.height);
}
{
double PRF = this->pstn.PRF;
double imgstarttime = this->pstn.imgStartTime;
int line_invert = int(50000000 / dem_img.width);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
line_invert = line_invert > 10 ? line_invert : 10;
int start_ids = 0; // <20><>ʾ1
int line_width = dem_img.width;
Eigen::MatrixX<double> sar_r(line_invert, line_width);
Eigen::MatrixXd sar_c(line_invert, line_width);
Eigen::MatrixXd dem(line_invert, line_width);
Eigen::MatrixXd sar_dem;
Eigen::MatrixXd sar_inclocal;
Eigen::MatrixXd sar_count;
int rowcount = 0, colcount = 0;
int r_min, r_max, c_min, c_max;
omp_lock_t lock;
omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
do {
std::cout << "rows:\t" << start_ids << "-" << start_ids + line_invert + 2 << "/" << dem_img.height << "\t computing.....\t" << getCurrentTimeString() << endl;
dem = dem_img.getData(start_ids, 0, line_invert + 2, line_width, 1);
sar_r = orth_rc.getData(start_ids, 0, line_invert + 2, line_width, 1).cast<double>();
sar_c = orth_rc.getData(start_ids, 0, line_invert + 2, line_width, 2).cast<double>();
r_min = int(floor(sar_r.minCoeff()));
r_max = int(ceil(sar_r.maxCoeff()));
c_min = int(floor(sar_c.minCoeff()));
c_max = int(ceil(sar_c.maxCoeff()));
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD>
rowcount = r_max - r_min + 1;
colcount = c_max - c_min + 1;
if (r_max < 0 || r_min>this->pstn.height) {
start_ids = start_ids + line_invert;
continue;
}
r_min = r_min <= 0 ? 0 : r_min;
r_max = r_max >= this->pstn.height ? this->pstn.height : r_max;
sar_dem = ori_dem.getData(r_min, 0, r_max - r_min + 1, this->pstn.width, 1).cast<double>();
sar_count = ori_count.getData(r_min, 0, r_max - r_min + 1, this->pstn.width, 1).cast<double>();
//sar_inclocal = ori_inclocal.getData(r_min, 0, r_max - r_min + 1, this->pstn.width, 1).cast<double>(); // <20><>
rowcount = dem.rows();
colcount = dem.cols();
#pragma omp parallel for num_threads(8) // NEW ADD
for (int i = 1; i < rowcount - 1; i++) {
Eigen::MatrixX<double> sataState = sar_r.row(i).reshaped(line_width, 1).array() * (1 / PRF) + imgstarttime;
sataState = this->pstn.orbit.SatelliteSpacePoint(sataState);
Landpoint p0, p1, p2, p3, p4, slopeVector, landpoint, satepoint;
double localincangle;
int r, c;
for (int j = 1; j < colcount - 1; j++) {
p0 = dem_img.getLandPoint(i + start_ids, j, dem(i, j)); // <20><><EFBFBD><EFBFBD>
p1 = dem_img.getLandPoint(i + start_ids - 1, j, dem(i - 1, j)); // 1
p2 = dem_img.getLandPoint(i + start_ids, j + 1, dem(i, j + 1)); // 2
p3 = dem_img.getLandPoint(i + start_ids + 1, j, dem(i + 1, j)); // 3
p4 = dem_img.getLandPoint(i + start_ids, j - 1, dem(i, j - 1)); // 4
slopeVector = getSlopeVector(p0, p1, p2, p3, p4);
landpoint = LLA2XYZ(p0);
satepoint = Landpoint{ sataState(j,0),sataState(j,1) ,sataState(j,2) };
localincangle = getlocalIncAngle(satepoint, landpoint, slopeVector);
if (localincangle < 90)
{
r = sar_r(i, j);
c = sar_c(i, j);
if (r >= 0 && r < this->pstn.height && c >= 0 && c < this->pstn.width) {
//sar_inclocal(r - r_min, c) += localincangle;
sar_count(r - r_min, c) += 1;
sar_dem(r - r_min, c) += dem(i, j);
}
}
}
}
//std::cout << sim_rsc(1, 1961) << endl;
ori_dem.saveImage(sar_dem, r_min, 0, 1);
//ori_inclocal.saveImage(sar_inclocal, r_min, 0, 1);
ori_count.saveImage(sar_count, r_min, 0, 1);
start_ids = start_ids + line_invert - 4;
} while (start_ids < dem_img.height);
omp_destroy_lock(&lock); //<2F><><EFBFBD>ٻ<EFBFBD><D9BB><EFBFBD><EFBFBD><EFBFBD>
}
// ƽ<><C6BD><EFBFBD><EFBFBD>
{
int line_invert = int(500000 / this->pstn.width);
line_invert = line_invert > 10 ? line_invert : 10;
int start_ids = 0;
do {
Eigen::MatrixXd sar_dem = ori_dem.getData(start_ids, 0, line_invert, this->pstn.width, 1);
//Eigen::MatrixXd sar_inclocal = ori_inclocal.getData(start_ids, 0, line_invert, this->pstn.width, 1);
Eigen::MatrixXd sar_count = ori_count.getData(start_ids, 0, line_invert, this->pstn.width, 1);
sar_dem = sar_dem.array() / sar_count.array();
//sar_inclocal = sar_inclocal.array() / sar_count.array();
ori_dem.saveImage(sar_dem, start_ids, 0, 1);
//ori_inclocal.saveImage(sar_inclocal, start_ids, 0, 1);
start_ids = start_ids + line_invert;
} while (start_ids < this->pstn.height);
}
std::cout << "repair dem by resample, begining:\t" << getCurrentTimeString() << endl;
{
}
std::cout << "repair dem by resample, overing:\t" << getCurrentTimeString() << endl;
std::cout << "correct the evering dem meta, over:\t" << getCurrentTimeString() << endl;
std::cout << "==========================================================" << endl;
std::cout << "the dem of sar:\t" << out_dem_path << endl;
std::cout << "the local incident angle of sar:\t " << out_inclocal_path << endl;
std::cout << "==========================================================" << endl;
return 0;
}
int simProcess::ASF(std::string in_dem_path, std::string out_latlon_path, std::string in_sar_rc_path, ASFOrthClass asfclass, PSTNAlgorithm PSTN)
{
std::cout << "computer ASF, begining:\t" << getCurrentTimeString() << endl;
std::cout << "==========================================================" << endl;
std::cout << "in parameters" << endl;
std::cout << "the dem of sar:\t" << in_dem_path << endl;
std::cout << "in sar rc path:\t" << in_dem_path << endl;
std::cout << "out parameters" << endl;
std::cout << "out latlon of sar:\t" << out_latlon_path << endl;
std::cout << "==========================================================" << endl;
gdalImage dem(in_dem_path);
gdalImage latlon = CreategdalImage(out_latlon_path, this->pstn.height, this->pstn.width, 2, dem.gt, dem.projection, false);
gdalImage sar_rc(in_sar_rc_path);
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double aveageAti = 0;
{
int line_invert = int(500000 / dem.width);
line_invert = line_invert > 10 ? line_invert : 10;
int start_ids = 0;
int count = 0;
do {
Eigen::MatrixXd sar_dem = dem.getData(start_ids, 0, line_invert, dem.width, 1);
int row_count = sar_dem.rows();
int col_count = sar_dem.cols();
for (int i = 0; i < row_count; i++) {
for (int j = 0; j < col_count; j++) {
if (!isnan(sar_dem(i, j)) && !isinf(sar_dem(i, j))) {
aveageAti += sar_dem(i, j);
count = count + 1;
}
}
}
start_ids = start_ids + line_invert;
} while (start_ids < this->pstn.height);
aveageAti = aveageAti / count;
}
cout << "the aveage ati of dem:\t" << aveageAti << endl;
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Landpoint initp = sar_rc.getLandPoint(int(sar_rc.height / 2), int(sar_rc.width / 2), aveageAti);
cout << "initlandpoint lon lat ati\t" << initp.lon << "\t" << initp.lat << "\t" << initp.ati << "\t" << endl;
initp = LLA2XYZ(initp);
cout << "initlandpoint lon lat ati\t" << initp.lon << "\t" << initp.lat << "\t" << initp.ati << "\t" << endl;
double PRF = this->pstn.PRF;
double imgstarttime = this->pstn.imgStartTime;
double alpha0 = 0;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
int line_invert = int(1000000 / dem.width) > 10 ? int(1000000 / dem.width) : 10;
line_invert = line_invert > 10 ? line_invert : 10;
int start_ids = 0;
omp_lock_t lock;
omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#pragma omp parallel for num_threads(8) // NEW ADD
for (int start_ids = 0; start_ids < this->pstn.height; start_ids = start_ids + line_invert)
{
Eigen::MatrixXd sar_dem = dem.getData(start_ids, 0, line_invert, this->pstn.width, 1);
Eigen::MatrixXd sar_lon = latlon.getData(start_ids, 0, line_invert, this->pstn.width, 1);
Eigen::MatrixXd sar_lat = latlon.getData(start_ids, 0, line_invert, this->pstn.width, 2);
Eigen::Vector3d initTagetPoint(initp.lon, initp.lat, initp.ati);
int row_min = start_ids;
int row_max = sar_lon.rows() + row_min;
std::cout << "rows:\t" << row_min << "-" << row_max << "/" << this->pstn.height << "\t computing.....\t" << getCurrentTimeString() << endl;
for (int i = row_min; i < row_max; i++) {
long double satetime = i * (1 / PRF) + imgstarttime;
Eigen::MatrixXd sataspace = this->pstn.orbit.SatelliteSpacePoint(satetime); // <20>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>
Eigen::Vector3d SatellitePosition(sataspace(0, 0), sataspace(0, 1), sataspace(0, 2));
Eigen::Vector3d SatelliteVelocity(sataspace(0, 3), sataspace(0, 4), sataspace(0, 5));
Landpoint sata{ sataspace(0,0), sataspace(0, 1), sataspace(0, 2) };
double beta0 = 50 * d2r;// (180-getAngle(sata, sata-initp))* d2r;
for (int j = 0; j < this->pstn.width; j++) {
double R = this->pstn.R0 + j * this->pstn.widthspace;
double ati_H = sar_dem(i - row_min, j);
if (!isnan(ati_H) && !isinf(ati_H)) {
ati_H = aveageAti;
}
Eigen::Vector3d landp = asfclass.ASF(R, SatellitePosition, SatelliteVelocity, initTagetPoint, PSTN, this->pstn.R0, ati_H, alpha0, beta0);
Landpoint landpoint{ landp(0),landp(1) ,landp(2) };
landpoint = XYZ2LLA(landpoint);
sar_lon(i - row_min, j) = landpoint.lon;
sar_lat(i - row_min, j) = landpoint.lat;
}
}
omp_set_lock(&lock);
latlon.saveImage(sar_lon, row_min, 0, 1);
latlon.saveImage(sar_lat, row_min, 0, 2);
omp_unset_lock(&lock);
}
omp_destroy_lock(&lock); //<2F><><EFBFBD>ٻ<EFBFBD><D9BB><EFBFBD><EFBFBD><EFBFBD>
}
std::cout << "out lon and lat of sar, over:\t" << getCurrentTimeString() << endl;
std::cout << "==========================================================" << endl;
std::cout << "the lon lat of sar:\t" << out_latlon_path << endl;
std::cout << "band 1: lon" << endl;
std::cout << "band 2: lat " << endl;
std::cout << "==========================================================" << endl;
return 0;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǻ;<C7BA><CDBE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="in_dem_path"></param>
/// <param name="in_rc_wgs84_path"></param>
/// <param name="out_incident_angle_path"></param>
/// <param name="out_local_incident_angle_path"></param>
/// <param name="PSTN"></param>
void simProcess::calcalIncident_localIncident_angle(std::string in_dem_path, std::string in_rc_wgs84_path, std::string out_incident_angle_path, std::string out_local_incident_angle_path, PSTNAlgorithm PSTN)
{
this->calGEC_Incident_localIncident_angle(in_dem_path, in_rc_wgs84_path, out_incident_angle_path, out_local_incident_angle_path, PSTN);
}
/// <summary>
/// <20><>ȡGEC<45><43><EFBFBD><EFBFBD>ϵ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="in_dem_path"></param>
/// <param name="in_gec_lon_lat_path"></param>
/// <param name="out_incident_angle_path"></param>
/// <param name="out_local_incident_angle_path"></param>
/// <param name="PSTN"></param>
void simProcess::calGEC_Incident_localIncident_angle(std::string in_dem_path, std::string in_gec_lon_lat_path, std::string out_incident_angle_path, std::string out_local_incident_angle_path, PSTNAlgorithm PSTN)
{
std::cout << "computer Incident_localIncident_angle in sar, begining:\t" << getCurrentTimeString() << endl;
std::cout << "==========================================================" << endl;
std::cout << "in parameters" << endl;
std::cout << "the dem in wgs84 of sar:\t" << in_dem_path << endl;
std::cout << "in gec lon lat path:\t" << in_gec_lon_lat_path << endl;
std::cout << "out parameters" << endl;
std::cout << "out incident_angle of sar:\t" << out_incident_angle_path << endl;
std::cout << "out local incident_angle of sar:\t" << out_local_incident_angle_path << endl;
std::cout << "==========================================================" << endl;
gdalImage dem_img(in_dem_path);
gdalImage lonlat(in_gec_lon_lat_path);
gdalImage incident_angle = CreategdalImage(out_incident_angle_path, this->pstn.height, this->pstn.width, 1, dem_img.gt, dem_img.projection, false);
gdalImage local_incident_angle = CreategdalImage(out_local_incident_angle_path, this->pstn.height, this->pstn.width, 1, dem_img.gt, dem_img.projection, false);
// <20><>ʼ<EFBFBD><CABC>
{
dem_img.InitInv_gt();
int line_invert = int(500000 / this->pstn.width);
line_invert = line_invert > 10 ? line_invert : 10;
int start_ids = 0;
do {
Eigen::MatrixXd sar_inc = incident_angle.getData(start_ids, 0, line_invert, this->pstn.width, 1);
Eigen::MatrixXd sar_local_incident = local_incident_angle.getData(start_ids, 0, line_invert, this->pstn.width, 1);
sar_inc = sar_inc.array() * 0;
sar_local_incident = sar_local_incident.array() * 0;
incident_angle.saveImage(sar_inc, start_ids, 0, 1);
local_incident_angle.saveImage(sar_local_incident, start_ids, 0, 1);
start_ids = start_ids + line_invert;
} while (start_ids < this->pstn.height);
}
{
double PRF = this->pstn.PRF;
double imgstarttime = this->pstn.imgStartTime;
int line_invert = 500;
int start_ids = 0;
int line_cound_sum = 0;
omp_lock_t lock;
omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (start_ids = 0; start_ids < this->pstn.height; start_ids = start_ids + line_invert) {
Eigen::MatrixXd lon = lonlat.getData(start_ids, 0, line_invert, this->pstn.width, 1);
Eigen::MatrixXd lat = lonlat.getData(start_ids, 0, line_invert, this->pstn.width, 2);
Eigen::MatrixXd dem_col = dem_img.inv_gt(0, 0) + dem_img.inv_gt(0, 1) * lon.array() + dem_img.inv_gt(0, 2) * lat.array();
Eigen::MatrixXd dem_row = dem_img.inv_gt(1, 0) + dem_img.inv_gt(1, 1) * lon.array() + dem_img.inv_gt(1, 2) * lat.array();
//lon = Eigen::MatrixXd::Ones(1,1);
//lat= Eigen::MatrixXd::Ones(1,1);
int min_row = floor(dem_row.array().minCoeff());
int max_row = ceil(dem_row.array().maxCoeff());
min_row = min_row - 1 >= 0 ? min_row - 1 : 0;
max_row = max_row + 1 < dem_img.height ? max_row + 1 : dem_img.height;
int row_len = max_row - min_row + 1;
Eigen::MatrixXd dem = dem_img.getData(min_row, 0, row_len, dem_img.width, 1);
Eigen::MatrixXd sar_inc = incident_angle.getData(start_ids, 0, line_invert, this->pstn.width, 1);
Eigen::MatrixXd sar_local_incident = local_incident_angle.getData(start_ids, 0, line_invert, this->pstn.width, 1);
int min_col = 0;
int lon_row_count = dem_col.rows();
int lon_col_count = dem_col.cols();
#pragma omp parallel for num_threads(8) // NEW ADD
for (int i = 0; i < lon_row_count; i++)
{
Landpoint p0, p1, p2, p3, p4, slopeVector, landpoint, satepoint;
double localincangle, inc_angle;
// ͬһ<CDAC>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
long double satatime = (i + start_ids) * (1 / PRF) + imgstarttime;
Eigen::MatrixXd sataState = this->pstn.orbit.SatelliteSpacePoint(satatime);
satepoint = Landpoint{ sataState(0,0),sataState(0,1) ,sataState(0,2) };
double dem_r, dem_c;
int r0, r1;
int c0, c1;
for (int j = 0; j < lon_col_count; j++) {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
dem_r = dem_row(i, j); //y
dem_c = dem_col(i, j); // x
r0 = floor(dem_r);
r1 = ceil(dem_r);
c0 = floor(dem_c);
c1 = ceil(dem_c);
p0 = Landpoint{ dem_c - c0,dem_r - r0,0 };
p1 = Landpoint{ 0,0,dem(r0 - min_row, c0 - min_col) }; // p11(0,0)
p2 = Landpoint{ 0,1,dem(r0 - min_row + 1, c0 - min_col) }; // p21(0,1)
p3 = Landpoint{ 1,0,dem(r0 - min_row , c0 + 1 - min_col) }; // p12(1,0)
p4 = Landpoint{ 1,1,dem(r0 - min_row + 1, c0 + 1 - min_col) }; // p22(1,1)
p0.ati = Bilinear_interpolation(p0, p1, p2, p3, p4);
p0 = dem_img.getLandPoint(dem_r, dem_c, p0.ati); // <20><><EFBFBD><EFBFBD>
p1 = dem_img.getLandPoint(r0, c0, dem(r0 - min_row, c0 - min_col)); // p11(0,0)
p2 = dem_img.getLandPoint(r1, c0, dem(r1 - min_row, c0 - min_col)); // p21(0,1)
p3 = dem_img.getLandPoint(r0, c1, dem(r0 - min_row, c1 - min_col)); // p12(1,0)
p4 = dem_img.getLandPoint(r1, c1, dem(r1 - min_row, c1 - min_col)); // p22(1,1)
slopeVector = getSlopeVector(p0, p1, p2, p3, p4); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʸ<EFBFBD><CAB8>
landpoint = LLA2XYZ(p0);
localincangle = getlocalIncAngle(satepoint, landpoint, slopeVector);// <20>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
inc_angle = getIncAngle(satepoint, landpoint); // <20><><EFBFBD>ӽ<EFBFBD>
// <20><>¼ֵ
sar_local_incident(i, j) = localincangle;
sar_inc(i, j) = inc_angle;
}
}
omp_set_lock(&lock);
incident_angle.saveImage(sar_inc, start_ids, 0, 1);
local_incident_angle.saveImage(sar_local_incident, start_ids, 0, 1);
line_cound_sum = line_cound_sum + line_invert;
std::cout << "rows:\t" << start_ids << "\t" << line_cound_sum << "/" << this->pstn.height << "\t computing.....\t" << getCurrentTimeString() << endl;
omp_unset_lock(&lock);
}
omp_destroy_lock(&lock); //<2F><><EFBFBD>ٻ<EFBFBD><D9BB><EFBFBD><EFBFBD><EFBFBD>
}
std::cout << "computer Incident_localIncident_angle in sar, overing:\t" << getCurrentTimeString() << endl;
}
/// <summary>
/// <20><>ֵGTC<54><43>Ӱ<EFBFBD><D3B0>ֵ
/// </summary>
/// <param name="in_rc_wgs84_path"></param>
/// <param name="in_ori_sar_path"></param>
/// <param name="out_orth_sar_path"></param>
/// <param name="PSTN"></param>
void simProcess::interpolation_GTC_sar(std::string in_rc_wgs84_path, std::string in_ori_sar_path, std::string out_orth_sar_path, PSTNAlgorithm pstn)
{
std::cout << "interpolation(cubic convolution) orth sar value by rc_wgs84 and ori_sar image and model, begin time:" << getCurrentTimeString() << std::endl;
gdalImage sar_rc(in_rc_wgs84_path);
gdalImage ori_sar(in_ori_sar_path);
gdalImage sar_img = CreategdalImage(out_orth_sar_path, sar_rc.height, sar_rc.width, 2, sar_rc.gt, sar_rc.projection);
// <20><>ʼ<EFBFBD><CABC>
{
sar_rc.InitInv_gt();
int line_invert = 100;
int start_ids = 0;
do {
Eigen::MatrixXd sar_a = sar_img.getData(start_ids, 0, line_invert, sar_rc.width, 1);
Eigen::MatrixXd sar_b = sar_img.getData(start_ids, 0, line_invert, sar_rc.width, 2);
sar_a = sar_a.array() * 0 - 9999;
sar_b = sar_b.array() * 0 - 9999;
sar_img.saveImage(sar_a, start_ids, 0, 1);
sar_img.saveImage(sar_a, start_ids, 0, 2);
start_ids = start_ids + line_invert;
} while (start_ids < sar_rc.height);
sar_img.setNoDataValue(-9999, 1);
sar_img.setNoDataValue(-9999, 2);
}
// <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
{
int line_invert = 500;
line_invert = line_invert > 10 ? line_invert : 10;
int start_ids = 0;
do {
std::cout << "rows:\t" << start_ids << "/" << sar_rc.height << "\t computing.....\t" << getCurrentTimeString() << endl;
Eigen::MatrixXd sar_r = sar_rc.getData(start_ids, 0, line_invert, sar_rc.width, 1);
Eigen::MatrixXd sar_c = sar_rc.getData(start_ids, 0, line_invert, sar_rc.width, 2);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>кŻ<D0BA>ȡ<EFBFBD><C8A1>Χ
int min_r = floor(sar_r.array().minCoeff());
int max_r = ceil(sar_r.array().maxCoeff());
int min_c = floor(sar_c.array().minCoeff());
int max_c = ceil(sar_c.array().maxCoeff());
if (max_r < 0 || max_c < 0 || min_r >= this->pstn.height || min_c >= this->pstn.width) {
start_ids = start_ids + line_invert;
if (start_ids < sar_rc.height) {
continue;
}
else {
break;
}
}
min_r = min_r >= 0 ? min_r : 0;
max_r = max_r < this->pstn.height ? max_r : this->pstn.height;
min_c = min_c >= 0 ? min_c : 0;
max_c = max_c < this->pstn.width ? max_c : this->pstn.width;
// <20><>ȡӰ<C8A1><D3B0>
int len_row = max_r - min_r + 4;
Eigen::MatrixXd ori_a = ori_sar.getData(min_r, 0, len_row, this->pstn.width, 1);
Eigen::MatrixXd ori_b = ori_sar.getData(min_r, 0, len_row, this->pstn.width, 2);
int row_count = ori_a.rows();
int col_count = ori_a.cols();
Eigen::MatrixX<complex<double>> ori(ori_a.rows(), ori_a.cols());
for (int i = 0; i < row_count; i++) {
for (int j = 0; j < col_count; j++) {
ori(i, j) = complex<double>{ ori_a(i, j), ori_b(i, j) };
}
}
ori_a = Eigen::MatrixXd(1, 1);
ori_b = Eigen::MatrixXd(1, 1); // <20>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
Eigen::MatrixXd sar_a = sar_img.getData(start_ids, 0, line_invert, sar_rc.width, 1);
Eigen::MatrixXd sar_b = sar_img.getData(start_ids, 0, line_invert, sar_rc.width, 2);
sar_r = sar_rc.getData(start_ids, 0, line_invert, sar_rc.width, 1);
sar_c = sar_rc.getData(start_ids, 0, line_invert, sar_rc.width, 2);
row_count = sar_r.rows();
col_count = sar_r.cols();
#pragma omp parallel for num_threads(8) // NEW ADD
for (int i = 0; i < row_count; i++) {
int r0, r1, r2, r3, c0, c1, c2, c3;
double r, c;
for (int j = 0; j < col_count; j++) {
r = sar_r(i, j);
c = sar_c(i, j);
if (r < 0 || c < 0 || r >= this->pstn.height || c >= this->pstn.width) {
continue;
}
else {
int kkkkk = 0;
}
r1 = floor(r);
r0 = r1 - 1; r2 = r1 + 1; r3 = r1 + 2; // <20><>ȡ<EFBFBD><C8A1>
c1 = floor(c);
c0 = c1 - 1; c2 = c1 + 1; c3 = c1 + 2; // <20><>ȡ<EFBFBD><C8A1>
// <20><><EFBFBD>DZ߽<C7B1><DFBD><EFBFBD><EFBFBD><EFBFBD>
if (r0<-1 || c0<-1 || c3>this->pstn.width || r3>this->pstn.height) {
continue;
}
// <20>߽<EFBFBD><DFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><E3A3AC>ֵģ<D6B5><C4A3>Ȩ<EFBFBD><C8A8>
Eigen::MatrixX<complex<double>> img_block(4, 4);
if (r0 == -1 || c0 == -1) {
if (r0 == -1) {
if (c0 == -1) {
img_block(3, 3) = ori(r3 - min_r, c3);
img_block(3, 2) = ori(r3 - min_r, c2);
img_block(3, 1) = ori(r3 - min_r, c1);
img_block(3, 0) = ori(r3 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r3 - min_r, c2) + ori(r3 - min_r, c3); // k,-1
img_block(2, 3) = ori(r2 - min_r, c3);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 0) = ori(r2 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c2) + ori(r2 - min_r, c3); // k,-1
img_block(1, 3) = ori(r1 - min_r, c3);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 0) = ori(r1 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c2) + ori(r1 - min_r, c3); // k,-1
img_block(0, 3) = ori(r1 - min_r, c3) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c3) + ori(r3 - min_r, c3);//-1,k
img_block(0, 2) = ori(r1 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c2) + ori(r3 - min_r, c2);//-1,
img_block(0, 1) = ori(r1 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c1) + ori(r3 - min_r, c1);//-1,
img_block(0, 0) = img_block(1, 0) * complex<double>{3, 0} - complex<double>{3, 0} *img_block(2, 0) + img_block(3, 0);// -1,-1
}
else if (c3 == this->pstn.width) {
img_block(3, 3) = ori(r3 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r3 - min_r, c1) + ori(r3 - min_r, c0);//2,M+1
img_block(3, 2) = ori(r3 - min_r, c2);
img_block(3, 1) = ori(r3 - min_r, c1);
img_block(3, 0) = ori(r3 - min_r, c0);//j,M-2
img_block(2, 3) = ori(r2 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c1) + ori(r2 - min_r, c0);//1,M+1
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 0) = ori(r2 - min_r, c0);//j,M-2
img_block(1, 3) = ori(r1 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c1) + ori(r1 - min_r, c0);//0,M+1
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 0) = ori(r1 - min_r, c0);//j,M-2
img_block(0, 3) = img_block(2, 3) * complex<double>{3, 0} - complex<double>{3, 0} *img_block(2, 3) + img_block(3, 3);//-1,M+1
img_block(0, 2) = ori(r1 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c2) + ori(r3 - min_r, c2);//-1,
img_block(0, 1) = ori(r1 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c1) + ori(r3 - min_r, c1);//-1,
img_block(0, 0) = ori(r1 - min_r, c0) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c0) + ori(r3 - min_r, c0);//-1,k
}
else {
img_block(3, 3) = ori(r3 - min_r, c3);
img_block(3, 2) = ori(r3 - min_r, c2);
img_block(3, 1) = ori(r3 - min_r, c1);
img_block(3, 0) = ori(r3 - min_r, c0);
img_block(2, 3) = ori(r2 - min_r, c3);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 0) = ori(r2 - min_r, c0);
img_block(1, 3) = ori(r1 - min_r, c3);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 0) = ori(r1 - min_r, c0);
img_block(0, 3) = ori(r1 - min_r, c3) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c3) + ori(r3 - min_r, c3);//-1,k
img_block(0, 2) = ori(r1 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c2) + ori(r3 - min_r, c2);//-1
img_block(0, 1) = ori(r1 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c1) + ori(r3 - min_r, c1);//-1
img_block(0, 0) = ori(r1 - min_r, c0) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c0) + ori(r3 - min_r, c0);//-1
}
}
else if (c0 == -1)//r0 != -1
{
if (r3 == this->pstn.height) {
img_block(0, 0) = ori(r0 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r0 - min_r, c2) + ori(r0 - min_r, c3);//j,-1
img_block(0, 1) = ori(r0 - min_r, c1);
img_block(0, 2) = ori(r0 - min_r, c2);
img_block(0, 3) = ori(r0 - min_r, c3);
img_block(1, 0) = ori(r1 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c2) + ori(r1 - min_r, c3);//j,-1
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 3) = ori(r1 - min_r, c3);
img_block(2, 0) = ori(r2 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c2) + ori(r2 - min_r, c3);//j,-1
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 3) = ori(r2 - min_r, c3);
img_block(3, 0) = img_block(2, 0) * complex<double>{3, 0} - complex<double>{3, 0} *img_block(1, 0) + img_block(0, 0);//N+1,-1
img_block(3, 1) = ori(r2 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c1) + ori(r0 - min_r, c1);//N+1,j
img_block(3, 2) = ori(r2 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c2) + ori(r0 - min_r, c2);//N+1,j
img_block(3, 3) = ori(r2 - min_r, c3) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c3) + ori(r0 - min_r, c3);//N+1,j
}
else { //
img_block(0, 0) = ori(r0 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r0 - min_r, c2) + ori(r0 - min_r, c3);//j,-1
img_block(0, 1) = ori(r0 - min_r, c1);
img_block(0, 2) = ori(r0 - min_r, c2);
img_block(0, 3) = ori(r0 - min_r, c3);
img_block(1, 0) = ori(r1 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c2) + ori(r1 - min_r, c3);//j,-1
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 3) = ori(r1 - min_r, c3);
img_block(2, 0) = ori(r2 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c2) + ori(r2 - min_r, c3);//j,-1
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 3) = ori(r2 - min_r, c3);
img_block(3, 0) = img_block(2, 0) * complex<double>{3, 0} - complex<double>{3, 0} *img_block(1, 0) + img_block(0, 0);//N+1,-1
img_block(3, 1) = ori(r3 - min_r, c1);
img_block(3, 2) = ori(r3 - min_r, c2);
img_block(3, 3) = ori(r3 - min_r, c3);
}
}
}
else if (r3 == this->pstn.height || c3 == this->pstn.width) {
if (r3 == this->pstn.height) {
if (c3 == this->pstn.width) {
img_block(0, 0) = ori(r0 - min_r, c0);
img_block(0, 1) = ori(r0 - min_r, c1);
img_block(0, 2) = ori(r0 - min_r, c2);
img_block(0, 3) = ori(r0 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r0 - min_r, c1) + ori(r0 - min_r, c0);;//j,M+1
img_block(1, 0) = ori(r1 - min_r, c0);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 3) = ori(r1 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c1) + ori(r1 - min_r, c0);;//j,M+1
img_block(2, 0) = ori(r2 - min_r, c0);//j,-1
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 3) = ori(r2 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c1) + ori(r2 - min_r, c0);;//j,M+1
img_block(3, 0) = ori(r2 - min_r, c0) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c0) + ori(r0 - min_r, c0);//N+1,-1
img_block(3, 1) = ori(r2 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c1) + ori(r0 - min_r, c1);//N+1,j
img_block(3, 2) = ori(r2 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c2) + ori(r0 - min_r, c2);//N+1,j
img_block(3, 3) = img_block(2, 3) * complex<double>{3, 0} - complex<double>{3, 0} *img_block(1, 3) + img_block(0, 3);//N+1,M+1
}
else {
img_block(0, 0) = ori(r0 - min_r, c0);
img_block(0, 1) = ori(r0 - min_r, c1);
img_block(0, 2) = ori(r0 - min_r, c2);
img_block(0, 3) = ori(r0 - min_r, c3);//j,M+1
img_block(1, 0) = ori(r1 - min_r, c0);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 3) = ori(r1 - min_r, c3);//j,M+1
img_block(2, 0) = ori(r2 - min_r, c0);//j,-1
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 3) = ori(r2 - min_r, c3);//j,M+1
img_block(3, 0) = ori(r2 - min_r, c0) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c0) + ori(r0 - min_r, c0);//N+1,-1
img_block(3, 1) = ori(r2 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c1) + ori(r0 - min_r, c1);//N+1,j
img_block(3, 2) = ori(r2 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c2) + ori(r0 - min_r, c2);//N+1,j
img_block(3, 3) = ori(r2 - min_r, c3) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c3) + ori(r0 - min_r, c3);//N+1,j
}
}
else if (c3 == this->pstn.width) { // r3 != this->pstn.height
img_block(3, 3) = ori(r3 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r3 - min_r, c1) + ori(r3 - min_r, c0);//2,M+1
img_block(3, 2) = ori(r3 - min_r, c2);
img_block(3, 1) = ori(r3 - min_r, c1);
img_block(3, 0) = ori(r3 - min_r, c0);//j,M-2
img_block(2, 3) = ori(r2 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c1) + ori(r2 - min_r, c0);//1,M+1
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 0) = ori(r2 - min_r, c0);//j,M-2
img_block(1, 3) = ori(r1 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c1) + ori(r1 - min_r, c0);//0,M+1
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 0) = ori(r1 - min_r, c0);//j,M-2
img_block(0, 3) = ori(r0 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r0 - min_r, c1) + ori(r0 - min_r, c0);//0,M+1
img_block(0, 2) = ori(r0 - min_r, c2);
img_block(0, 1) = ori(r0 - min_r, c1);
img_block(0, 0) = ori(r0 - min_r, c0);
}
}
else {
img_block(3, 3) = ori(r3 - min_r, c3);
img_block(3, 2) = ori(r3 - min_r, c2);
img_block(3, 1) = ori(r3 - min_r, c1);
img_block(3, 0) = ori(r3 - min_r, c0);
img_block(2, 3) = ori(r2 - min_r, c3);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 0) = ori(r2 - min_r, c0);
img_block(1, 3) = ori(r1 - min_r, c3);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 0) = ori(r1 - min_r, c0);
img_block(0, 3) = ori(r0 - min_r, c3);
img_block(0, 2) = ori(r0 - min_r, c2);
img_block(0, 1) = ori(r0 - min_r, c1);
img_block(0, 0) = ori(r0 - min_r, c0);
}
complex<double> interpolation_value = Cubic_Convolution_interpolation(r - r1, c - c1, img_block);
//
sar_a(i, j) = interpolation_value.real();
sar_b(i, j) = interpolation_value.imag();
}
}
sar_img.saveImage(sar_a, start_ids, 0, 1);
sar_img.saveImage(sar_b, start_ids, 0, 2);
start_ids = start_ids + line_invert;
} while (start_ids < sar_rc.height);
}
std::cout << "interpolation(cubic convolution) orth sar value by rc_wgs84 and ori_sar image and model, over:\t" << getCurrentTimeString() << std::endl;
}
/// <summary>
/// <20><>ֵGTC<54><43>Ӱ<EFBFBD><D3B0>ֵ
/// </summary>
/// <param name="in_rc_wgs84_path"></param>
/// <param name="in_ori_sar_path"></param>
/// <param name="out_orth_sar_path"></param>
/// <param name="PSTN"></param>
void simProcess::interpolation_GTC_sar_sigma(std::string in_rc_wgs84_path, std::string in_ori_sar_path, std::string out_orth_sar_path, PSTNAlgorithm pstn)
{
std::cout << "interpolation(cubic convolution) orth sar value by rc_wgs84 and ori_sar image and model, begin time:" << getCurrentTimeString() << std::endl;
gdalImage sar_rc(in_rc_wgs84_path);
gdalImage ori_sar(in_ori_sar_path);
gdalImage sar_img = CreategdalImage(out_orth_sar_path, sar_rc.height, sar_rc.width, 1, sar_rc.gt, sar_rc.projection);
// <20><>ʼ<EFBFBD><CABC>
{
sar_rc.InitInv_gt();
int line_invert = 100;
int start_ids = 0;
do {
Eigen::MatrixXd sar_a = sar_img.getData(start_ids, 0, line_invert, sar_rc.width, 1);
//Eigen::MatrixXd sar_b = sar_img.getData(start_ids, 0, line_invert, sar_rc.width, 2);
sar_a = sar_a.array() * 0 - 9999;
//sar_b = sar_b.array() * 0 - 9999;
sar_img.saveImage(sar_a, start_ids, 0, 1);
//sar_img.saveImage(sar_a, start_ids, 0, 2);
start_ids = start_ids + line_invert;
} while (start_ids < sar_rc.height);
sar_img.setNoDataValue(-9999, 1);
//sar_img.setNoDataValue(-9999, 2);
}
// <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
{
int line_invert = 500;
line_invert = line_invert > 10 ? line_invert : 10;
int start_ids = 0;
do {
std::cout << "rows:\t" << start_ids << "/" << sar_rc.height << "\t computing.....\t" << getCurrentTimeString() << endl;
Eigen::MatrixXd sar_r = sar_rc.getData(start_ids, 0, line_invert, sar_rc.width, 1);
Eigen::MatrixXd sar_c = sar_rc.getData(start_ids, 0, line_invert, sar_rc.width, 2);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>кŻ<D0BA>ȡ<EFBFBD><C8A1>Χ
int min_r = floor(sar_r.array().minCoeff());
int max_r = ceil(sar_r.array().maxCoeff());
int min_c = floor(sar_c.array().minCoeff());
int max_c = ceil(sar_c.array().maxCoeff());
if (max_r < 0 || max_c < 0 || min_r >= this->pstn.height || min_c >= this->pstn.width) {
start_ids = start_ids + line_invert;
if (start_ids < sar_rc.height) {
continue;
}
else {
break;
}
}
min_r = min_r >= 0 ? min_r : 0;
max_r = max_r < this->pstn.height ? max_r : this->pstn.height;
min_c = min_c >= 0 ? min_c : 0;
max_c = max_c < this->pstn.width ? max_c : this->pstn.width;
// <20><>ȡӰ<C8A1><D3B0>
int len_row = max_r - min_r + 4;
Eigen::MatrixXd ori_a = ori_sar.getData(min_r, 0, len_row, this->pstn.width, 1);
//Eigen::MatrixXd ori_b = ori_sar.getData(min_r, 0, len_row, this->pstn.width, 2);
int row_count = ori_a.rows();
int col_count = ori_a.cols();
Eigen::MatrixX<complex<double>> ori(ori_a.rows(), ori_a.cols());
for (int i = 0; i < row_count; i++) {
for (int j = 0; j < col_count; j++) {
ori(i, j) = complex<double>{ ori_a(i, j), 0 };
}
}
ori_a = Eigen::MatrixXd(1, 1);
//ori_b = Eigen::MatrixXd(1, 1); // <20>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
Eigen::MatrixXd sar_a = sar_img.getData(start_ids, 0, line_invert, sar_rc.width, 1);
//Eigen::MatrixXd sar_b = sar_img.getData(start_ids, 0, line_invert, sar_rc.width, 2);
sar_r = sar_rc.getData(start_ids, 0, line_invert, sar_rc.width, 1);
sar_c = sar_rc.getData(start_ids, 0, line_invert, sar_rc.width, 2);
row_count = sar_r.rows();
col_count = sar_r.cols();
#pragma omp parallel for num_threads(8) // NEW ADD
for (int i = 0; i < row_count; i++) {
int r0, r1, r2, r3, c0, c1, c2, c3;
double r, c;
for (int j = 0; j < col_count; j++) {
r = sar_r(i, j);
c = sar_c(i, j);
if (r < 0 || c < 0 || r >= this->pstn.height || c >= this->pstn.width) {
continue;
}
else {
int kkkkk = 0;
}
r1 = floor(r);
r0 = r1 - 1; r2 = r1 + 1; r3 = r1 + 2; // <20><>ȡ<EFBFBD><C8A1>
c1 = floor(c);
c0 = c1 - 1; c2 = c1 + 1; c3 = c1 + 2; // <20><>ȡ<EFBFBD><C8A1>
// <20><><EFBFBD>DZ߽<C7B1><DFBD><EFBFBD><EFBFBD><EFBFBD>
if (r0<-1 || c0<-1 || c3>this->pstn.width || r3>this->pstn.height) {
continue;
}
// <20>߽<EFBFBD><DFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><E3A3AC>ֵģ<D6B5><C4A3>Ȩ<EFBFBD><C8A8>
Eigen::MatrixX<complex<double>> img_block(4, 4);
if (r0 == -1 || c0 == -1) {
if (r0 == -1) {
if (c0 == -1) {
img_block(3, 3) = ori(r3 - min_r, c3);
img_block(3, 2) = ori(r3 - min_r, c2);
img_block(3, 1) = ori(r3 - min_r, c1);
img_block(3, 0) = ori(r3 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r3 - min_r, c2) + ori(r3 - min_r, c3); // k,-1
img_block(2, 3) = ori(r2 - min_r, c3);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 0) = ori(r2 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c2) + ori(r2 - min_r, c3); // k,-1
img_block(1, 3) = ori(r1 - min_r, c3);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 0) = ori(r1 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c2) + ori(r1 - min_r, c3); // k,-1
img_block(0, 3) = ori(r1 - min_r, c3) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c3) + ori(r3 - min_r, c3);//-1,k
img_block(0, 2) = ori(r1 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c2) + ori(r3 - min_r, c2);//-1,
img_block(0, 1) = ori(r1 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c1) + ori(r3 - min_r, c1);//-1,
img_block(0, 0) = img_block(1, 0) * complex<double>{3, 0} - complex<double>{3, 0} *img_block(2, 0) + img_block(3, 0);// -1,-1
}
else if (c3 == this->pstn.width) {
img_block(3, 3) = ori(r3 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r3 - min_r, c1) + ori(r3 - min_r, c0);//2,M+1
img_block(3, 2) = ori(r3 - min_r, c2);
img_block(3, 1) = ori(r3 - min_r, c1);
img_block(3, 0) = ori(r3 - min_r, c0);//j,M-2
img_block(2, 3) = ori(r2 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c1) + ori(r2 - min_r, c0);//1,M+1
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 0) = ori(r2 - min_r, c0);//j,M-2
img_block(1, 3) = ori(r1 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c1) + ori(r1 - min_r, c0);//0,M+1
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 0) = ori(r1 - min_r, c0);//j,M-2
img_block(0, 3) = img_block(2, 3) * complex<double>{3, 0} - complex<double>{3, 0} *img_block(2, 3) + img_block(3, 3);//-1,M+1
img_block(0, 2) = ori(r1 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c2) + ori(r3 - min_r, c2);//-1,
img_block(0, 1) = ori(r1 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c1) + ori(r3 - min_r, c1);//-1,
img_block(0, 0) = ori(r1 - min_r, c0) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c0) + ori(r3 - min_r, c0);//-1,k
}
else {
img_block(3, 3) = ori(r3 - min_r, c3);
img_block(3, 2) = ori(r3 - min_r, c2);
img_block(3, 1) = ori(r3 - min_r, c1);
img_block(3, 0) = ori(r3 - min_r, c0);
img_block(2, 3) = ori(r2 - min_r, c3);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 0) = ori(r2 - min_r, c0);
img_block(1, 3) = ori(r1 - min_r, c3);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 0) = ori(r1 - min_r, c0);
img_block(0, 3) = ori(r1 - min_r, c3) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c3) + ori(r3 - min_r, c3);//-1,k
img_block(0, 2) = ori(r1 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c2) + ori(r3 - min_r, c2);//-1
img_block(0, 1) = ori(r1 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c1) + ori(r3 - min_r, c1);//-1
img_block(0, 0) = ori(r1 - min_r, c0) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c0) + ori(r3 - min_r, c0);//-1
}
}
else if (c0 == -1)//r0 != -1
{
if (r3 == this->pstn.height) {
img_block(0, 0) = ori(r0 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r0 - min_r, c2) + ori(r0 - min_r, c3);//j,-1
img_block(0, 1) = ori(r0 - min_r, c1);
img_block(0, 2) = ori(r0 - min_r, c2);
img_block(0, 3) = ori(r0 - min_r, c3);
img_block(1, 0) = ori(r1 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c2) + ori(r1 - min_r, c3);//j,-1
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 3) = ori(r1 - min_r, c3);
img_block(2, 0) = ori(r2 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c2) + ori(r2 - min_r, c3);//j,-1
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 3) = ori(r2 - min_r, c3);
img_block(3, 0) = img_block(2, 0) * complex<double>{3, 0} - complex<double>{3, 0} *img_block(1, 0) + img_block(0, 0);//N+1,-1
img_block(3, 1) = ori(r2 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c1) + ori(r0 - min_r, c1);//N+1,j
img_block(3, 2) = ori(r2 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c2) + ori(r0 - min_r, c2);//N+1,j
img_block(3, 3) = ori(r2 - min_r, c3) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c3) + ori(r0 - min_r, c3);//N+1,j
}
else { //
img_block(0, 0) = ori(r0 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r0 - min_r, c2) + ori(r0 - min_r, c3);//j,-1
img_block(0, 1) = ori(r0 - min_r, c1);
img_block(0, 2) = ori(r0 - min_r, c2);
img_block(0, 3) = ori(r0 - min_r, c3);
img_block(1, 0) = ori(r1 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c2) + ori(r1 - min_r, c3);//j,-1
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 3) = ori(r1 - min_r, c3);
img_block(2, 0) = ori(r2 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c2) + ori(r2 - min_r, c3);//j,-1
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 3) = ori(r2 - min_r, c3);
img_block(3, 0) = img_block(2, 0) * complex<double>{3, 0} - complex<double>{3, 0} *img_block(1, 0) + img_block(0, 0);//N+1,-1
img_block(3, 1) = ori(r3 - min_r, c1);
img_block(3, 2) = ori(r3 - min_r, c2);
img_block(3, 3) = ori(r3 - min_r, c3);
}
}
}
else if (r3 == this->pstn.height || c3 == this->pstn.width) {
if (r3 == this->pstn.height) {
if (c3 == this->pstn.width) {
img_block(0, 0) = ori(r0 - min_r, c0);
img_block(0, 1) = ori(r0 - min_r, c1);
img_block(0, 2) = ori(r0 - min_r, c2);
img_block(0, 3) = ori(r0 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r0 - min_r, c1) + ori(r0 - min_r, c0);;//j,M+1
img_block(1, 0) = ori(r1 - min_r, c0);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 3) = ori(r1 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c1) + ori(r1 - min_r, c0);;//j,M+1
img_block(2, 0) = ori(r2 - min_r, c0);//j,-1
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 3) = ori(r2 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c1) + ori(r2 - min_r, c0);;//j,M+1
img_block(3, 0) = ori(r2 - min_r, c0) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c0) + ori(r0 - min_r, c0);//N+1,-1
img_block(3, 1) = ori(r2 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c1) + ori(r0 - min_r, c1);//N+1,j
img_block(3, 2) = ori(r2 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c2) + ori(r0 - min_r, c2);//N+1,j
img_block(3, 3) = img_block(2, 3) * complex<double>{3, 0} - complex<double>{3, 0} *img_block(1, 3) + img_block(0, 3);//N+1,M+1
}
else {
img_block(0, 0) = ori(r0 - min_r, c0);
img_block(0, 1) = ori(r0 - min_r, c1);
img_block(0, 2) = ori(r0 - min_r, c2);
img_block(0, 3) = ori(r0 - min_r, c3);//j,M+1
img_block(1, 0) = ori(r1 - min_r, c0);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 3) = ori(r1 - min_r, c3);//j,M+1
img_block(2, 0) = ori(r2 - min_r, c0);//j,-1
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 3) = ori(r2 - min_r, c3);//j,M+1
img_block(3, 0) = ori(r2 - min_r, c0) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c0) + ori(r0 - min_r, c0);//N+1,-1
img_block(3, 1) = ori(r2 - min_r, c1) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c1) + ori(r0 - min_r, c1);//N+1,j
img_block(3, 2) = ori(r2 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c2) + ori(r0 - min_r, c2);//N+1,j
img_block(3, 3) = ori(r2 - min_r, c3) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c3) + ori(r0 - min_r, c3);//N+1,j
}
}
else if (c3 == this->pstn.width) { // r3 != this->pstn.height
img_block(3, 3) = ori(r3 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r3 - min_r, c1) + ori(r3 - min_r, c0);//2,M+1
img_block(3, 2) = ori(r3 - min_r, c2);
img_block(3, 1) = ori(r3 - min_r, c1);
img_block(3, 0) = ori(r3 - min_r, c0);//j,M-2
img_block(2, 3) = ori(r2 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r2 - min_r, c1) + ori(r2 - min_r, c0);//1,M+1
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 0) = ori(r2 - min_r, c0);//j,M-2
img_block(1, 3) = ori(r1 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r1 - min_r, c1) + ori(r1 - min_r, c0);//0,M+1
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 0) = ori(r1 - min_r, c0);//j,M-2
img_block(0, 3) = ori(r0 - min_r, c2) * complex<double>{3, 0} - complex<double>{3, 0} *ori(r0 - min_r, c1) + ori(r0 - min_r, c0);//0,M+1
img_block(0, 2) = ori(r0 - min_r, c2);
img_block(0, 1) = ori(r0 - min_r, c1);
img_block(0, 0) = ori(r0 - min_r, c0);
}
}
else {
img_block(3, 3) = ori(r3 - min_r, c3);
img_block(3, 2) = ori(r3 - min_r, c2);
img_block(3, 1) = ori(r3 - min_r, c1);
img_block(3, 0) = ori(r3 - min_r, c0);
img_block(2, 3) = ori(r2 - min_r, c3);
img_block(2, 2) = ori(r2 - min_r, c2);
img_block(2, 1) = ori(r2 - min_r, c1);
img_block(2, 0) = ori(r2 - min_r, c0);
img_block(1, 3) = ori(r1 - min_r, c3);
img_block(1, 2) = ori(r1 - min_r, c2);
img_block(1, 1) = ori(r1 - min_r, c1);
img_block(1, 0) = ori(r1 - min_r, c0);
img_block(0, 3) = ori(r0 - min_r, c3);
img_block(0, 2) = ori(r0 - min_r, c2);
img_block(0, 1) = ori(r0 - min_r, c1);
img_block(0, 0) = ori(r0 - min_r, c0);
}
complex<double> interpolation_value = Cubic_Convolution_interpolation(r - r1, c - c1, img_block);
//
sar_a(i, j) = interpolation_value.real();
//sar_b(i, j) = interpolation_value.imag();
}
}
sar_img.saveImage(sar_a, start_ids, 0, 1);
//sar_img.saveImage(sar_b, start_ids, 0, 2);
start_ids = start_ids + line_invert;
} while (start_ids < sar_rc.height);
}
std::cout << "interpolation(cubic convolution) orth sar value by rc_wgs84 and ori_sar image and model, over:\t" << getCurrentTimeString() << std::endl;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD>RPC<50><43><EFBFBD><EFBFBD><EFBFBD>кţ<D0BA><C5A3><EFBFBD><EFBFBD><EFBFBD>RPC<50><43>Ӧ<EFBFBD><D3A6>DEM<45>ļ<EFBFBD>
/// </summary>
/// <param name="in_rpc_rc_path"></param>
/// <param name="in_dem_path"></param>
/// <param name="out_rpc_dem_path"></param>
void simProcess::CreateRPC_DEM(std::string in_rpc_rc_path, std::string in_dem_path, std::string out_rpc_dem_path)
{
gdalImage rpc_rc(in_rpc_rc_path);
gdalImage dem_img(in_dem_path);
gdalImage rpc_dem_img = CreategdalImage(out_rpc_dem_path, rpc_rc.height, rpc_rc.width, 1, rpc_rc.gt, rpc_rc.projection);
// <20><>ʼ<EFBFBD><CABC>
{
dem_img.InitInv_gt();
int line_invert = 100;
int start_ids = 0;
do {
Eigen::MatrixXd rpc_dem = rpc_dem_img.getData(start_ids, 0, line_invert, rpc_dem_img.width, 1);
rpc_dem = rpc_dem.array() * 0 - 9999;
rpc_dem_img.saveImage(rpc_dem, start_ids, 0, 1);
start_ids = start_ids + line_invert;
} while (start_ids < rpc_dem_img.height);
rpc_dem_img.setNoDataValue(-9999, 1);
}
// <20><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
dem_img.InitInv_gt();
int line_invert = 100;
int start_ids = 0;
do {
std::cout << "rows:\t" << start_ids << "/" << rpc_dem_img.height << "\t computing.....\t" << getCurrentTimeString() << endl;
Eigen::MatrixXd rpc_dem = rpc_dem_img.getData(start_ids, 0, line_invert, rpc_dem_img.width, 1);
Eigen::MatrixXd rpc_row = rpc_dem.array() * 0 - 1;
Eigen::MatrixXd rpc_col = rpc_dem.array() * 0 - 1;
int row_count = rpc_dem.rows();
int col_count = rpc_dem.cols();
for (int i = 0; i < row_count; i++) {
for (int j = 0; j < col_count; j++) {
Landpoint landpoint = rpc_dem_img.getLandPoint(i + start_ids, j, 0);
Landpoint land_row_col = dem_img.getRow_Col(landpoint.lon, landpoint.lat); // x,y,z
rpc_row(i, j) = land_row_col.lat; // row
rpc_col(i, j) = land_row_col.lon; // col
}
}
double min_r = floor(rpc_row.minCoeff()) - 1;
double max_r = ceil(rpc_row.maxCoeff()) + 1;
min_r = min_r >= 0 ? min_r : 0;
int len_r = max_r - min_r;
Eigen::MatrixXd dem = dem_img.getData(min_r, 0, len_r + 2, dem_img.width, 1);
for (int i = 0; i < row_count; i++) {
for (int j = 0; j < col_count; j++) {
Landpoint p0 = Landpoint{ rpc_row(i,j),rpc_col(i,j),0 };
Landpoint p1 = Landpoint{ floor(p0.lon),floor(p0.lat),0 }; p1.ati = dem(int(p1.lon - min_r), int(p1.lat)); p1 = Landpoint{ 0,0,p1.ati };
Landpoint p2 = Landpoint{ floor(p0.lon),ceil(p0.lat),0 }; p2.ati = dem(int(p2.lon - min_r), int(p2.lat)); p2 = Landpoint{ 0,1,p2.ati };
Landpoint p3 = Landpoint{ ceil(p0.lon),floor(p0.lat),0 }; p3.ati = dem(int(p3.lon - min_r), int(p3.lat)); p3 = Landpoint{ 1,0,p3.ati };
Landpoint p4 = Landpoint{ ceil(p0.lon),ceil(p0.lat),0 }; p4.ati = dem(int(p4.lon - min_r), int(p4.lat)); p4 = Landpoint{ 1,1,p4.ati };
p0 = Landpoint{ p0.lon - floor(p0.lon), p0.lat - floor(p0.lat), 0 };
p0.ati = Bilinear_interpolation(p0, p1, p2, p3, p4);
rpc_dem(i, j) = p0.ati;
}
}
rpc_dem_img.saveImage(rpc_dem, start_ids, 0, 1);
start_ids = start_ids + line_invert;
} while (start_ids < rpc_dem_img.height);
}
}
void simProcess::CreateRPC_refrenceTable(string in_rpc_tiff_path, string out_rpc_lon_lat_tiff_path)
{
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO");
CPLSetConfigOption("GDAL_DATA", "./data");
GDALAllRegister();//ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
const char* pszTif = in_rpc_tiff_path.c_str();
gdalImage rpc_img(in_rpc_tiff_path);
GDALRPCInfo oInfo = rpc_img.getRPC();
//<2F><><EFBFBD><EFBFBD>RPCģ<43><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DEM·<4D><C2B7>
char** papszTransOption = NULL;
//papszTransOption = CSLSetNameValue(papszTransOption, "RPC_DEM", "E:\\DEM.img"); //<2F><><EFBFBD><EFBFBD>DEM
//ʹ<><CAB9>RPC<50><43>Ϣ<EFBFBD><CFA2>DEM<45>ȹ<EFBFBD><C8B9><EFBFBD>RPCת<43><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void* pRPCTransform = GDALCreateRPCTransformer(&oInfo, FALSE, 0, papszTransOption);
// <20><><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0>
gdalImage lon_lat_img = CreategdalImage(out_rpc_lon_lat_tiff_path, rpc_img.height, rpc_img.width, 2, rpc_img.gt, rpc_img.projection, false);
// <20><><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD>
double X[4] = { 0,0,rpc_img.width - 1,rpc_img.width - 1 };
double Y[4] = { 0,rpc_img.height - 1,rpc_img.height - 1,0 };
double Z[4] = { 0,0,0,0 };
int sucess_num[4] = { false,false,false,false };
GDALRPCTransform(pRPCTransform, FALSE, 4, X, Y, Z, sucess_num);
for (int i = 0; i < 4; i++) {
std::cout << X[i] << "\t" << Y[i] << "\t" << Z[i] << "\t" << sucess_num[i] << std::endl;
}
int line_invert = int(1500000 / rpc_img.width);
line_invert = line_invert > 10 ? line_invert : 10;
int count_lines = 0;
omp_lock_t lock;
omp_init_lock(&lock); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#pragma omp parallel for num_threads(6) // NEW ADD
for (int max_rows_ids = 0; max_rows_ids < lon_lat_img.height; max_rows_ids = max_rows_ids + line_invert) {
//line_invert = dem_clip.height - max_rows_ids > line_invert ? line_invert : dem_clip.height - max_rows_ids;
Eigen::MatrixXd lon = lon_lat_img.getData(max_rows_ids, 0, line_invert, lon_lat_img.width, 1);
Eigen::MatrixXd lat = lon_lat_img.getData(max_rows_ids, 0, line_invert, lon_lat_img.width, 2);
int row_count = lon.rows();
int col_count = lon.cols();
for (int i = 0; i < row_count; i++) {
for (int j = 0; j < col_count; j++) {
//<2F><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD>
double dY[1] = { i + max_rows_ids };
double dX[1] = { j };
double dZ[1] = { 0 };
int nSuccess[1] = { FALSE };
GDALRPCTransform(pRPCTransform, FALSE, 1, dX, dY, dZ, nSuccess);
lon(i, j) = dX[0];
lat(i, j) = dY[0];
}
}
//std::cout << "for time " << getCurrentTimeString() << std::endl;
// д<><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
omp_set_lock(&lock); //<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
std::cout << lon.array().minCoeff() << endl;
lon_lat_img.saveImage(lon, max_rows_ids, 0, 1);
lon_lat_img.saveImage(lat, max_rows_ids, 0, 2);
count_lines = count_lines + line_invert;
std::cout << "rows:\t" << max_rows_ids << "\t-\t" << max_rows_ids + line_invert << "\t" << count_lines << "/" << lon_lat_img.height << "\t computing.....\t" << getCurrentTimeString() << endl;
omp_unset_lock(&lock); //<2F>ͷŻ<CDB7><C5BB><EFBFBD><EFBFBD><EFBFBD>
}
omp_destroy_lock(&lock); //<2F><><EFBFBD>ٻ<EFBFBD><D9BB><EFBFBD><EFBFBD><EFBFBD>
//<2F>ͷ<EFBFBD><CDB7><EFBFBD>Դ
GDALDestroyRPCTransformer(pRPCTransform);
CSLDestroy(papszTransOption);
}
/// <summary>
/// <20><><EFBFBD><EFBFBD>DEM<45><4D><EFBFBD><EFBFBD>SAR_rc
/// </summary>
/// <param name="dem_path"></param>
/// <param name="sim_rc_path"></param>
/// <param name="PSTN"></param>
/// <returns></returns>
double getlocalIncAngle(Landpoint& satepoint, Landpoint& landpoint, Landpoint& slopeVector) {
Landpoint Rsc = satepoint - landpoint; // AB=B-A
//double R = getlength(Rsc);
//std::cout << R << endl;
double angle = getAngle(Rsc, slopeVector);
if (angle >= 180) {
return 360 - angle;
}
else {
return angle;
}
}
double getIncAngle(Landpoint& satepoint, Landpoint& landpoint) {
Landpoint Rsc = satepoint - landpoint; // AB=B-A
Landpoint Rs = landpoint;// landpoint;
double angle = getAngle(Rsc, Rs);
if (angle >= 180) {
return 360 - angle;
}
else {
return angle;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////// ASF <20><><EFBFBD><EFBFBD> ///////////////////////////////////////////////////
////// <20><><EFBFBD><EFBFBD><EFBFBD>غϳɿ׾<C9BF><D7BE>״<EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD> <20><EFBFBD>ѧ /////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// <20><><EFBFBD><EFBFBD> <20><EFBFBD><E4BBBB><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ-> ECR
/// </summary>
/// <param name="sataspace">[x,y,z,vx,vy,vz] nx6 </param>
/// <returns></returns>
Eigen::MatrixXd ASFOrthClass::Satellite2ECR(Eigen::Vector3d Rsc, Eigen::Vector3d Vsc)
{
Eigen::Vector3d x, y, z;
Eigen::MatrixXd M(3, 3);
z = Rsc / Rsc.norm();
y = Rsc.cross(Vsc) / (Rsc.norm() * Vsc.norm());
x = y.cross(z);
M.col(0) = x;
M.col(1) = y;
M.col(2) = z;
return M;
}
/// <summary>
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>ĵ<EFBFBD>λʸ<CEBB><CAB8>
/// </summary>
/// <param name="alpha"><3E><><EFBFBD><EFBFBD>ֵ</param>
/// <param name="beta"><3E><><EFBFBD><EFBFBD>ֵ</param>
/// <param name="M"><3E><EFBFBD><E4BBBB><EFBFBD><EFBFBD></param>
/// <returns></returns>
Eigen::Vector3d ASFOrthClass::UnitVectorOfSatelliteAndTarget(double alpha, double beta, Eigen::MatrixXd M)
{
// Ŀ<><C4BF>T<EFBFBD>ĵ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD> ST = R * M * P
Eigen::Vector3d P(sin(alpha), -1.0 * cos(alpha) * sin(beta), -1.0 * cos(alpha) * cos(beta));
return M * P;
}
/// <summary>
///
/// </summary>
/// <param name="R"></param>
/// <param name="alpha"></param>
/// <param name="beta"></param>
/// <param name="SatellitePosition"></param>
/// <param name="SatelliteVelocity"></param>
/// <param name="R_threshold"></param>
/// <param name="H"></param>
/// <returns></returns>
double ASFOrthClass::GetLookFromRangeYaw(double R, double alpha, double beta, Eigen::Vector3d SatellitePosition, Eigen::Vector3d SatelliteVelocity, double R_threshold, double H)
{
/**
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>R<EFBFBD><EFBFBD>alpha <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>beta<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>ݲο<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>ʽ3 - 13<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɴ˷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǽ<EFBFBD><EFBFBD>Ʒ<EFBFBD>
args :
R<EFBFBD><EFBFBD>б<EFBFBD><EFBFBD>
alpha : <EFBFBD>״<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD>
beta0 : beta<EFBFBD><EFBFBD>ʼֵ
SatellitePosition : 3x1 <EFBFBD><EFBFBD><EFBFBD>ǿռ<EFBFBD>λ<EFBFBD><EFBFBD>
TargetPosition<EFBFBD><EFBFBD>3x1 Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
Eigen::MatrixXd M = this->Satellite2ECR(SatellitePosition, SatelliteVelocity);
// <20><><EFBFBD><EFBFBD><EFBFBD>
double Rp = earth_Rp + H;
double Rs_norm = SatellitePosition.norm();
// <20><>ʼ<EFBFBD><CABC>beta
if (beta == 0) {
double beta_cos = (Rs_norm * Rs_norm + R * R - Rp * Rp) / (2 * Rs_norm * R);
beta = acos(beta_cos);
}
double delta_R, sin_eta, delta_beta, tan_eta;
// <20><><EFBFBD><EFBFBD>
int i = 0;
do {
// <20><><EFBFBD><EFBFBD>б<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD>
delta_R = R - this->FR(alpha, beta, SatellitePosition, M, R_threshold, H);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sin_eta = Rs_norm * sin(beta) / Rp;
tan_eta = sin_eta / sqrt(1 - sin_eta * sin_eta);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
delta_beta = delta_R / (R * tan_eta);
// <20><><EFBFBD><EFBFBD>
beta = beta + delta_beta;
// <20>ж<EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
i = i + 1;
if (i >= 10000) // <20><EFBFBD><EFB5BD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
{
return -9999;
}
} while (abs(delta_R) > 0.01);
return beta;
}
/// <summary>
/// <20><>beta<74><61>alpha<68><61>ȡ<EFBFBD><C8A1>ȡĿ<C8A1><C4BF><EFBFBD>Ŀռ<C4BF>λ<EFBFBD><CEBB>
/// </summary>
/// <param name="alpha"></param>
/// <param name="beta"></param>
/// <param name="SatellitePosition"></param>
/// <param name="R"></param>
/// <param name="M"></param>
/// <returns></returns>
Eigen::Vector3d ASFOrthClass::GetXYZByBetaAlpha(double alpha, double beta, Eigen::Vector3d SatellitePosition, double R, Eigen::MatrixXd M)
{
return SatellitePosition + R * this->UnitVectorOfSatelliteAndTarget(alpha, beta, M);
}
/// <summary>
/// FD
/// </summary>
/// <param name="alpha"></param>
/// <param name="beta"></param>
/// <param name="SatelliteVelocity"></param>
/// <param name="TargetVelocity"></param>
/// <param name="R"></param>
/// <param name="lamda"></param>
/// <param name="M"></param>
/// <returns></returns>
double ASFOrthClass::FD(double alpha, double beta, Eigen::Vector3d SatelliteVelocity, Eigen::Vector3d TargetVelocity, double R, double lamda, Eigen::MatrixXd M)
{
/**
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>beta, alpha, <EFBFBD><EFBFBD><EFBFBD>ǿռ<EFBFBD>λ<EFBFBD><EFBFBD>, б<EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
Eigen::Vector3d UnitVector = this->UnitVectorOfSatelliteAndTarget(alpha, beta, M);
Eigen::Vector3d Rst = -1 * R * UnitVector;
double Rst_Vst = Rst.dot(SatelliteVelocity - TargetVelocity);
return -2 / (R * lamda) * Rst_Vst;
}
/// <summary>
/// FR
/// </summary>
/// <param name="alpha"></param>
/// <param name="beta"></param>
/// <param name="SatellitePosition"></param>
/// <param name="M"></param>
/// <param name="R_threshold"></param>
/// <param name="H"></param>
/// <returns></returns>
double ASFOrthClass::FR(double alpha, double beta, Eigen::Vector3d SatellitePosition, Eigen::MatrixXd M, double R_threshold, double H)
{
/*
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>״<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽǣ<EFBFBD><EFBFBD>״<EFBFBD><EFBFBD>ӽǣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>󣬴<EFBFBD><EFBFBD>ظߵȲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲο<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD>ʽ3 - 1 == <EFBFBD><EFBFBD>3 - 10<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƴ˷<EFBFBD><EFBFBD><EFBFBD>
args :
alpha:<EFBFBD>״<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD><EFBFBD>˶<EFBFBD><EFBFBD><EFBFBD>µģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ƵĽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
beta : <EFBFBD>״<EFBFBD><EFBFBD>ӽ<EFBFBD>
Satellite_position : <EFBFBD><EFBFBD><EFBFBD>ǿռ<EFBFBD>λ<EFBFBD><EFBFBD>
M<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
H<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>
return :
R<EFBFBD><EFBFBD>б<EFBFBD><EFBFBD>
*/
//std::cout << beta << endl;
Eigen::Vector3d UnitVector = R_threshold * this->UnitVectorOfSatelliteAndTarget(alpha, beta, M);
// <20><EFBFBD><E2B7BD> 3 - 10 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>A<EFBFBD><41>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double a = (earth_Re + H) * (earth_Re + H);
double b = earth_Rp * earth_Rp;
long double Xs = SatellitePosition(0);
long double Ys = SatellitePosition(1);
long double Zs = SatellitePosition(2);
long double Xp = UnitVector(0);
long double Yp = UnitVector(1);
long double Zp = UnitVector(2);
//std::cout << Xp<<"\t"<< Yp<<"\t"<< Zp << endl;
long double A = (Xp * Xp + Yp * Yp) / a + (Zp * Zp) / b;
long double B = 2 * (Xs * Xp + Ys * Yp) / a + 2 * Zs * Zp / b;
long double C = (Xs * Xs + Ys * Ys) / a + Zs * Zs / b - 1;
//std::cout << A << "\t" << B << "\t" << C << endl;
C = B * B - 4 * A * C;
//std::cout << A << "\t" << B << "\t" << C << endl;
double R1 = (-B - sqrt(C)) / (2 * A);
//double R2 = (-B + sqrt(C)) / (2 * A);
//std::cout << R1 << "\t" << R2 << endl;
if (R1 > 1) {
return R1 * R_threshold;
}
else {
return -9999;
//return (-B + math.sqrt(t)) / (2 * A) # <20><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD>η<EFBFBD><CEB7><EFBFBD><EFBFBD>ų<EFBFBD><C5B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
/// <summary>
/// ASF<53><46><EFBFBD><EFBFBD>
/// </summary>
/// <param name="R"></param>
/// <param name="SatellitePosition"><3E><><EFBFBD>Ǹ߶<C7B8></param>
/// <param name="SatelliteVelocity"><3E><><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD></param>
/// <param name="TargetPosition"><3E><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
/// <param name="PSTN"></param>
/// <param name="R_threshold"></param>
/// <param name="H"><3E><>ʼ<EFBFBD>߳<EFBFBD></param>
/// <param name="alpha0"></param>
/// <param name="beta0"></param>
/// <returns></returns>
Eigen::Vector3d ASFOrthClass::ASF(double R, Eigen::Vector3d SatellitePosition, Eigen::Vector3d SatelliteVelocity, Eigen::Vector3d TargetPosition, PSTNAlgorithm PSTN, double R_threshold, double H, double alpha0, double beta0)
{
// <20><><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
double alpha = alpha0;
double beta = beta0;
double delta_alpha = 0;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>Ǹ<EFBFBD><C7B8>ݡ<EFBFBD><DDA1>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϳɿ׾<C9BF><D7BE>״<EFBFBD><D7B4><EFBFBD><EFBFBD>ǹ<EFBFBD><C7B9>̡<EFBFBD><CCA1><EFBFBD>Ʒ<EFBFBD><EFBFBD><EBB4A6><EFBFBD><EFBFBD>
// P164 5.8.4 <20><><EFBFBD><EFBFBD><EFBFBD>ղ<EFBFBD><D5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double fd = PSTN.calNumericalDopplerValue(R);
Eigen::MatrixXd M = this->Satellite2ECR(SatellitePosition, SatelliteVelocity);
double FD_, delta_fd;
Eigen::Vector3d XYZ;
int i = 0;// ͳ<>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while (true) {
Eigen::Vector3d TargetVelocity = Eigen::Vector3d(-1 * earth_We * TargetPosition(1), earth_We * TargetPosition(0), 0);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>, <20>ֲڼ<D6B2><DABC><EFBFBD>ʱ<EFBFBD><CAB1>Ĭ<EFBFBD><C4AC>Ϊ0
beta = this->GetLookFromRangeYaw(R, alpha, beta, SatellitePosition, SatelliteVelocity, R_threshold, H);
FD_ = this->FD(alpha, beta, SatelliteVelocity, TargetVelocity, R, PSTN.lamda, M);
delta_fd = FD_ - fd;
delta_alpha = -1 * delta_fd * PSTN.lamda / (2 * (SatelliteVelocity - TargetVelocity).norm());
TargetPosition = this->GetXYZByBetaAlpha(alpha, beta, SatellitePosition, R, M);
//cout << i << "\t" << delta_alpha * R << "\t" << delta_alpha<<"\t"<< (abs(delta_alpha * R) < 0.1)<<"\t"<< (abs(delta_alpha) < 0.001) << endl;
if (abs(delta_alpha * R) < 0.1 || abs(delta_alpha) < 0.0003)
{
break;
}
alpha = alpha + delta_alpha;
i = i + 1;
if (i > 10000) {
throw new exception("ASF ʧ<><CAA7>");
}
}
return TargetPosition;
}