97 lines
3.4 KiB
C++
97 lines
3.4 KiB
C++
#include "GF3CalibrationAndOrthLib.h"
|
|
#include "BaseConstVariable.h"
|
|
#include "RasterToolBase.h"
|
|
#include "ImageOperatorBase.h"
|
|
#include <QDebug>
|
|
#include <QFile>
|
|
#include <memory>
|
|
#include "FileOperator.h"
|
|
#include "GPUBaseTool.h"
|
|
#include "GPUTool.cuh"
|
|
#include <omp.h>
|
|
// GPU相关的代码
|
|
#include "GF3CalibrationGeoCodingFunCUDA.cuh"
|
|
|
|
/// <summary>
|
|
/// 将HH极化转换为VV极化
|
|
/// </summary>
|
|
/// <param name="in_SigmaHHRasterPath"></param>
|
|
/// <param name="in_IncidencAngleRasterPath"></param>
|
|
/// <param name="out_SigmaVVRasterPath"></param>
|
|
/// <returns></returns>
|
|
int GF3_Sigma0_HH2VV(QString in_SigmaHHRasterPath, QString in_IncidencAngleRasterPath, QString out_SigmaVVRasterPath, SIGMATYPE sigmatype)
|
|
{
|
|
// step 1 检查输入合法性
|
|
{
|
|
// 1. 检查输入合法性
|
|
if (in_SigmaHHRasterPath.isEmpty() || in_IncidencAngleRasterPath.isEmpty() || out_SigmaVVRasterPath.isEmpty())
|
|
{
|
|
qDebug() << "Input or output file path is empty.";
|
|
throw std::invalid_argument("Input or output file path is empty.");
|
|
return 1; // 代表输入或输出文件路径为空
|
|
}
|
|
// 2. 检查输入影像是否存在
|
|
if (!QFile::exists(in_SigmaHHRasterPath) || !QFile::exists(in_IncidencAngleRasterPath))
|
|
{
|
|
qDebug() << "Input file does not exist.";
|
|
throw std::runtime_error("Input file does not exist.");
|
|
return 2; // 代表输入文件不存在
|
|
}
|
|
gdalImage inSigmaHHRaster(in_SigmaHHRasterPath);
|
|
gdalImage inIncidencAngleRaster(in_IncidencAngleRasterPath);
|
|
// 3. 检查输入影像大小是否一致
|
|
if (inSigmaHHRaster.width != inIncidencAngleRaster.width || inSigmaHHRaster.height != inIncidencAngleRaster.height)
|
|
{
|
|
qDebug() << "Input images have different sizes.";
|
|
throw std::runtime_error("Input images have different sizes.");
|
|
return 3; // 代表输入影像大小不一致
|
|
}
|
|
|
|
// 复制输入文件到输出文件
|
|
copyFile(in_SigmaHHRasterPath, out_SigmaVVRasterPath);
|
|
// 4. 检查输出文件是否存在
|
|
if (!QFile::exists(out_SigmaVVRasterPath))
|
|
{
|
|
qDebug() << "Output file does not exist.";
|
|
throw std::runtime_error("Output file does not exist.");
|
|
return 4; // 代表输出文件不存在
|
|
}
|
|
}
|
|
|
|
// step 2 执行操作
|
|
{
|
|
gdalImage inSigmaHHRaster(in_SigmaHHRasterPath);
|
|
gdalImage inIncidencAngleRaster(in_IncidencAngleRasterPath);
|
|
gdalImage outSigmaVVRaster(out_SigmaVVRasterPath);
|
|
|
|
long width = inSigmaHHRaster.width;
|
|
long height = inSigmaHHRaster.height;
|
|
|
|
int64_t pixel_count64 = static_cast<int64_t>(height) * static_cast<int64_t>(width);
|
|
// 读取输入影像数据
|
|
std::shared_ptr<double> sigmaHHRasterData = readDataArr<double>(inSigmaHHRaster, 0, 0, height, width, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);
|
|
std::shared_ptr<double> incidenceAngleData = readDataArr<double>(inIncidencAngleRaster, 0, 0, height, width, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);
|
|
std::shared_ptr<double> outSigmaVVRasterData = readDataArr<double>(outSigmaVVRaster, 0, 0, height, width, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);
|
|
|
|
#pragma omp parallel for
|
|
for (int64_t i = 0; i < pixel_count64; i++)
|
|
{
|
|
double sigmaHH = sigmaHHRasterData.get()[i];
|
|
sigmaHH = converSigma2amp(sigmaHH,sigmatype);
|
|
double incidenceAngle = incidenceAngleData.get()[i];// 角度
|
|
sigmaHH = 20 * log10(sigmaHH);
|
|
double sigmaVV = polartionConver_d(sigmaHH, incidenceAngle, 1.0, false); // 输出dB值
|
|
outSigmaVVRasterData.get()[i] = sigmaVV;
|
|
}
|
|
|
|
// 保存输出影像数据
|
|
outSigmaVVRaster.saveImage(outSigmaVVRasterData,0,0,height,width,1);
|
|
// 释放内存
|
|
sigmaHHRasterData.reset();
|
|
incidenceAngleData.reset();
|
|
outSigmaVVRasterData.reset();
|
|
|
|
}
|
|
return -1;// 代表执行成功
|
|
}
|