#include "GF3CalibrationAndOrthLib.h" #include "BaseConstVariable.h" #include "RasterToolBase.h" #include "ImageOperatorBase.h" #include #include #include #include "FileOperator.h" #include "GPUBaseTool.h" #include "GPUTool.cuh" #include // GPU相关的代码 #include "GF3CalibrationGeoCodingFunCUDA.cuh" /// /// 将HH极化转换为VV极化 /// /// /// /// /// 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(height) * static_cast(width); // 读取输入影像数据 std::shared_ptr sigmaHHRasterData = readDataArr(inSigmaHHRaster, 0, 0, height, width, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); std::shared_ptr incidenceAngleData = readDataArr(inIncidencAngleRaster, 0, 0, height, width, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); std::shared_ptr outSigmaVVRasterData = readDataArr(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;// 代表执行成功 }