From 7c58127fcf3e69061b3f9704b8563910e3c2145c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=89=91=E5=8F=A4=E6=95=9B=E9=94=8B?= <3045316072@qq.com> Date: Tue, 2 Jul 2024 15:48:59 +0800 Subject: [PATCH] =?UTF-8?q?DEM=20:=E5=9C=B0=E7=90=86=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E4=B8=8E=E6=8A=95=E5=BD=B1=E5=9D=90=E6=A0=87=E7=B3=BB=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dialogimportmodeldataset.cpp | 41 + .../dialogimportmodeldataset.h | 42 + .../dialogimportmodeldataset.ui | 155 ++ .../DEM2PointCloudTemplateFun.h | 216 +++ src/PluginWBFZExchangePlugin/CMakeLists.txt | 6 +- .../FEKOBaseToolClass.cpp | 33 +- .../ImageOperatorBase.cpp | 1245 +++++++++-------- .../ImageOperatorBase.h | 2 +- .../LAMPDataShowClass.ui | 7 +- .../LAMPImageCreateClass.cpp | 63 +- 10 files changed, 1218 insertions(+), 592 deletions(-) create mode 100644 src/PluginMeshDataExchange/dialogimportmodeldataset.cpp create mode 100644 src/PluginMeshDataExchange/dialogimportmodeldataset.h create mode 100644 src/PluginMeshDataExchange/dialogimportmodeldataset.ui create mode 100644 src/PluginRasterTool/DEM2PointCloudTemplateFun.h diff --git a/src/PluginMeshDataExchange/dialogimportmodeldataset.cpp b/src/PluginMeshDataExchange/dialogimportmodeldataset.cpp new file mode 100644 index 0000000..35a90fe --- /dev/null +++ b/src/PluginMeshDataExchange/dialogimportmodeldataset.cpp @@ -0,0 +1,41 @@ +/** + * @file dialogimportmodeldataset.cpp + * @brief None + * @author 陈增辉 (3045316072@qq.com) + * @version 2.5.0 + * @date 24-6-25 + * @copyright Copyright (c) Since 2024 中科卫星应用研究院 All rights reserved. + */ + +// You may need to build the project (run Qt uic code generator) to get +// "ui_DialogImportModelDataset.h" resolved + +#include "dialogimportmodeldataset.h" +#include "ui_dialogimportmodeldataset.h" +#include "Settings/BusAPI.h" + + +namespace WBFZ { + DialogImportModelDataset::DialogImportModelDataset(QWidget* parent) + : QDialog(parent) + , ui(new Ui::DialogImportModelDataset) + { + ui->setupUi(this); + } + + DialogImportModelDataset::~DialogImportModelDataset() + { + delete ui; + } + + // 初始化模型库 + void DialogImportModelDataset::initLibrary() { + + Setting::BusAPI* busapi=Setting::BusAPI::instance(); + QString executablePath = QApplication::applicationDirPath(); // exe 路径 + + + + } + +} // namespace WBFZ diff --git a/src/PluginMeshDataExchange/dialogimportmodeldataset.h b/src/PluginMeshDataExchange/dialogimportmodeldataset.h new file mode 100644 index 0000000..77bdacb --- /dev/null +++ b/src/PluginMeshDataExchange/dialogimportmodeldataset.h @@ -0,0 +1,42 @@ +/** + * @file dialogimportmodeldataset.h + * @brief None + * @author 陈增辉 (3045316072@qq.com) + * @version 2.5.0 + * @date 24-6-25 + * @copyright Copyright (c) Since 2024 中科卫星应用研究院 All rights reserved. + */ + +#ifndef LAMPCAE_DIALOGIMPORTMODELDATASET_H +#define LAMPCAE_DIALOGIMPORTMODELDATASET_H + +#include +#include "ModuleBase/graph3DWindow.h" +#include + + +namespace WBFZ { + QT_BEGIN_NAMESPACE + namespace Ui { + class DialogImportModelDataset; + } + QT_END_NAMESPACE + + class DialogImportModelDataset : public QDialog { + Q_OBJECT + + public: + explicit DialogImportModelDataset(QWidget* parent = nullptr); + ~DialogImportModelDataset() override; + + public: + void initLibrary(); + void filterModel();// 根据条件筛选 + + private: + Ui::DialogImportModelDataset* ui; + QString _librarySettingPath; // ini 配置环境地址 + }; +} // namespace WBFZ + +#endif // LAMPCAE_DIALOGIMPORTMODELDATASET_H diff --git a/src/PluginMeshDataExchange/dialogimportmodeldataset.ui b/src/PluginMeshDataExchange/dialogimportmodeldataset.ui new file mode 100644 index 0000000..3372891 --- /dev/null +++ b/src/PluginMeshDataExchange/dialogimportmodeldataset.ui @@ -0,0 +1,155 @@ + + + WBFZ::DialogImportModelDataset + + + + 0 + 0 + 1003 + 805 + + + + DialogImportModelDataset + + + + + + + 350 + 0 + + + + + 350 + 16777215 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 30 + + + + + 16777215 + 30 + + + + + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + 预制模型类型 + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 300 + 0 + + + + + 300 + 16777215 + + + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 600 + 600 + + + + + 1000 + 1000 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + diff --git a/src/PluginRasterTool/DEM2PointCloudTemplateFun.h b/src/PluginRasterTool/DEM2PointCloudTemplateFun.h new file mode 100644 index 0000000..11dc588 --- /dev/null +++ b/src/PluginRasterTool/DEM2PointCloudTemplateFun.h @@ -0,0 +1,216 @@ +/** + * @file DEM2PointCloudTemplateFun.h + * @brief DEM转点云的匿名函数 + * @author 陈增辉 (3045316072@qq.com) + * @version 2.5.0 + * @date 24-6-19 + * @copyright Copyright (c) Since 2024 中科卫星应用研究院 All rights reserved. + */ + +#ifndef LAMPCAE_DEM2POINTCLOUDTEMPLATEFUN_H +#define LAMPCAE_DEM2POINTCLOUDTEMPLATEFUN_H + +#include "DEM2PointCloud.h" +#include "RasterToolBase.h" +#include "RasterDataClass.h" + +#include +#include + + +namespace LAMPToolBox{ + + template + bool DEM2PointCloud_project(RasterToolBase::RasterDataClass rasterdatades,QString out_plygon){ + qDebug()<<"bool DEM2PointCloud_project(RasterToolBase::RasterDataClass rasterdatades,QString out_plygon)"; + QString _inDEMPath=rasterdatades.getFilepath(); + + // 创建文件对象 + QFile file(out_plygon); + // 打开文件,如果打开失败则输出错误信息并返回 + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + qDebug() << "Could not open file for writing."; + return 1; + } + QTextStream out(&file); + if(RasterToolBase::GDALAllRegisterEnable){ + + }else{ + GDALAllRegister(); + RasterToolBase::GDALAllRegisterEnable=true; + } + + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注册GDAL驱动 + GDALDataset *poDataset; + poDataset = (GDALDataset *)GDALOpen(_inDEMPath.toUtf8().data(), GA_ReadOnly); + { + if(NULL == poDataset) { + return false; + } + GDALRasterBand *poBand = poDataset->GetRasterBand(1); + + // 仿射矩阵 + double gt[6]; + poDataset->GetGeoTransform(gt); + + // 分块处理 + long block_row_len=5000; + long block_col_len=5000; + RasterToolBase::RasterDataSplitBlockParams blockParams(rasterdatades.getHeight(),rasterdatades.getWidth(),5000,5000); + + long start_row=0; + long start_col=0; + long RowLen=0; + long ColLen=0; + T* datablock=new T[block_row_len*block_col_len]; + double x,y,z; + for(long id=0;idRasterIO(GF_Read, start_col, start_row, ColLen, RowLen, datablock, ColLen, RowLen, rasterdatades.getDataType(), 0, 0); + }else{ + poBand->RasterIO(GF_Read, start_col, start_row, ColLen, RowLen, datablock, ColLen, RowLen, rasterdatades.getDataType(), 0, 0); + } + // 计算坐标,并输出 + for(long i=0;i + bool DEM2PointCloud_Geo(RasterToolBase::RasterDataClass rasterdatades,QString out_plygon){ + qDebug()<<"bool DEM2PointCloud_Geo(RasterToolBase::RasterDataClass rasterdatades,QString out_plygon)"; + if(rasterdatades.getEpsgCode()==-1){return false;}else{} + + QString _inDEMPath=rasterdatades.getFilepath(); + + // 创建文件对象 + QFile file(out_plygon); + + // 打开文件,如果打开失败则输出错误信息并返回 + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + qDebug() << "Could not open file for writing."; + return 1; + } + QTextStream out(&file); + + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注册GDAL驱动 + + // 定义输入的空间参考系统(WGS84坐标系) + OGRSpatialReference oSRS; + oSRS.importFromEPSG(rasterdatades.getEpsgCode()); // EPSG:4326 是WGS84坐标系的标识 + + // 定义输出的空间参考系统(地心地固坐标系,通常是ECEF) + OGRSpatialReference oTargetSRS; + oTargetSRS.SetWellKnownGeogCS("WGS84"); // 使用WGS84的地心参考系 + OGRCoordinateTransformation *poTransform = OGRCreateCoordinateTransformation(&oSRS, &oTargetSRS); + if (poTransform == nullptr) { + qDebug("Transformation initialization failed.\n"); + return false; + } + + GDALDataset *poDataset; + poDataset = (GDALDataset *)GDALOpen(_inDEMPath.toUtf8().data(), GA_ReadOnly); + { + if(NULL == poDataset) { + return false; + } + GDALRasterBand *poBand = poDataset->GetRasterBand(1); + + // 仿射矩阵 + double gt[6]; + poDataset->GetGeoTransform(gt); + + // 分块处理 + long block_row_len=5000; + long block_col_len=5000; + RasterToolBase::RasterDataSplitBlockParams blockParams(rasterdatades.getHeight(),rasterdatades.getWidth(),5000,5000); + + long start_row=0; + long start_col=0; + long RowLen=0; + long ColLen=0; + T* datablock=new T[block_row_len*block_col_len]; + double lon,lat,ati,x,y,z; + OGRPoint pt; // 经纬度坐标 + + for(long id=0;idRasterIO(GF_Read, start_col, start_row, ColLen, RowLen, datablock, ColLen, RowLen, rasterdatades.getDataType(), 0, 0); + }else{ + poBand->RasterIO(GF_Read, start_col, start_row, ColLen, RowLen, datablock, ColLen, RowLen, rasterdatades.getDataType(), 0, 0); + } + // 计算坐标,并输出 + for(long i=0;i j(0, 1); // 虚数单位 @@ -1460,11 +1461,14 @@ bool FEKOBase::FBPImage_FREQ(QString& restiffpath, Eigen::MatrixXcd& echoData, { // 适用于近场成像 ,只有 ISAR 与 圆迹SAR 适用于远场 #ifdef __IMAGEPARALLEL -#pragma omp parallel for - for(long ii = 0; ii < image_height; ii++) { + unsigned int cores = std::thread::hardware_concurrency()/2+1; // CPU 核数 + size_t block_len=image_height/cores+1; // 获取模块计算 +#pragma omp parallel for num_threads(cores) + for(long start_ii = 0; start_ii < image_height; start_ii=start_ii+block_len) { Eigen::MatrixXd im_R = Eigen::MatrixXd::Zero(PRFCount, 1); // 图像到脉冲矩阵 prf*1 Eigen::MatrixXcd term_R = Eigen::MatrixXcd::Zero(1, frepoints); Eigen::MatrixXcd pluse_R = Eigen::MatrixXcd::Zero(PRFCount, 1); + for(long ii=start_ii;ii j(0, 1); // 虚数单位 @@ -1855,8 +1861,8 @@ bool FEKOBase::FBPImage_CirCleSAR(QString& restiffpath, MatrixXcd& echoData, Mat progressDialog.show(); #endif // __SHOWPROCESS -#ifdef __IMAGEWINDOWSPROCESS // 加窗处理 - Eigen::MatrixXd normw = WINDOWFun(echoData, winfun); +#ifdef __IMAGEWINDOWSPROCESS // 加窗处理 + //Eigen::MatrixXd normw = WINDOWFun(echoData, winfun); #endif if(EchoMode == FEKOBase::FARFIELD) { // 远场模式只有 ISAR 与 圆迹成像模式启动 @@ -1875,11 +1881,14 @@ bool FEKOBase::FBPImage_CirCleSAR(QString& restiffpath, MatrixXcd& echoData, Mat (Mat_Freq.array().cast>().array() * j * 4 * M_PI / c).exp().array() * (echoData.array()); #ifdef __IMAGEPARALLEL -#pragma omp parallel for - for(long ii = 0; ii < image_height; ii++) { + unsigned int cores = std::thread::hardware_concurrency()/2+1; // CPU 核数 + size_t block_len=image_height/cores+1; // 获取模块计算 +#pragma omp parallel for num_threads(cores) + for(long start_ii = 0; start_ii < image_height; start_ii=start_ii+block_len) { Eigen::MatrixXd im_R = Eigen::MatrixXd::Zero(PRFCount, 1); // 图像到脉冲矩阵 prf*1 Eigen::MatrixXcd term_R = Eigen::MatrixXcd::Zero(1, frepoints); Eigen::MatrixXcd pluse_R = Eigen::MatrixXcd::Zero(PRFCount, 1); + for(long ii=start_ii;ii j(0, 1); // 虚数单位 @@ -2094,11 +2104,14 @@ bool FEKOBase::FBPImage_ISARNEAR(QString& restiffpath, MatrixXcd& echoData, Matr } else { // 适用于近场成像 #ifdef __IMAGEPARALLEL -#pragma omp parallel for - for(long ii = 0; ii < image_height; ii++) { + unsigned int cores = std::thread::hardware_concurrency()/2+1; // CPU 核数 + size_t block_len=image_height/cores+1; // 获取模块计算 +#pragma omp parallel for num_threads(cores) + for(long start_ii = 0; start_ii < image_height; start_ii=start_ii+block_len) { Eigen::MatrixXd im_R = Eigen::MatrixXd::Zero(PRFCount, 1); // 图像到脉冲矩阵 prf*1 Eigen::MatrixXcd term_R = Eigen::MatrixXcd::Zero(1, frepoints); Eigen::MatrixXcd pluse_R = Eigen::MatrixXcd::Zero(PRFCount, 1); + for(long ii=start_ii;ii #include @@ -16,386 +17,420 @@ #include #include #include "FileOperator.h" +#include using namespace std; using namespace Eigen; /** -* 输入数据是ENVI格式数据 -*/ + * 输入数据是ENVI格式数据 + */ - - - - - -std::shared_ptr OpenDataset(const QString& in_path,GDALAccess rwmode) +std::shared_ptr OpenDataset(const QString& in_path, GDALAccess rwmode) { GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); GDALDataset* dataset_ptr = (GDALDataset*)(GDALOpen(in_path.toUtf8().constData(), rwmode)); std::shared_ptr rasterDataset(dataset_ptr, CloseDataset); return rasterDataset; } -void CloseDataset(GDALDataset* ptr) +void CloseDataset(GDALDataset* ptr) { GDALClose(ptr); ptr = NULL; } -int TIFF2ENVI(QString in_tiff_path, QString out_envi_path) +int TIFF2ENVI(QString in_tiff_path, QString out_envi_path) { - std::shared_ptr ds = OpenDataset(in_tiff_path); - const char* args[] = { "-of", "ENVI", NULL }; - GDALTranslateOptions* psOptions = GDALTranslateOptionsNew((char**)args, NULL); - GDALClose(GDALTranslate(out_envi_path.toUtf8().constData(),ds.get(), psOptions,NULL)); + std::shared_ptr ds = OpenDataset(in_tiff_path); + const char* args[] = { "-of", "ENVI", NULL }; + GDALTranslateOptions* psOptions = GDALTranslateOptionsNew((char**)args, NULL); + GDALClose(GDALTranslate(out_envi_path.toUtf8().constData(), ds.get(), psOptions, NULL)); GDALTranslateOptionsFree(psOptions); return 0; } -int ENVI2TIFF(QString in_envi_path, QString out_tiff_path) +int ENVI2TIFF(QString in_envi_path, QString out_tiff_path) { - std::shared_ptr ds = OpenDataset(in_envi_path); - const char* args[] = { "-of", "Gtiff", NULL }; - GDALTranslateOptions* psOptions = GDALTranslateOptionsNew((char**)args, NULL); + std::shared_ptr ds = OpenDataset(in_envi_path); + const char* args[] = { "-of", "Gtiff", NULL }; + GDALTranslateOptions* psOptions = GDALTranslateOptionsNew((char**)args, NULL); GDALClose(GDALTranslate(out_tiff_path.toUtf8().constData(), ds.get(), psOptions, NULL)); GDALTranslateOptionsFree(psOptions); return 0; } -int CreateDataset(QString new_file_path,int height, int width, int band_num,double* gt, QString projection, GDALDataType gdal_dtype ,bool need_gt) +int CreateDataset(QString new_file_path, int height, int width, int band_num, double* gt, + QString projection, GDALDataType gdal_dtype, bool need_gt) { GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); - std::shared_ptr< GDALDataset> poDstDS(poDriver->Create(new_file_path.toUtf8().constData(), width, height, band_num, gdal_dtype, NULL)); - if (need_gt) - { + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); + std::shared_ptr poDstDS(poDriver->Create(new_file_path.toUtf8().constData(), width, + height, band_num, gdal_dtype, NULL)); + if(need_gt) { poDstDS->SetProjection(projection.toUtf8().constData()); poDstDS->SetGeoTransform(gt); + } else { } - else {} GDALFlushCache((GDALDatasetH)poDstDS.get()); return 0; } -int saveDataset(QString new_file_path, int start_line,int start_cols ,int band_ids, int datacols,int datarows,void* databuffer) +int saveDataset(QString new_file_path, int start_line, int start_cols, int band_ids, int datacols, + int datarows, void* databuffer) { GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - std::shared_ptr poDstDS = OpenDataset(new_file_path,GA_Update); - GDALDataType gdal_datatype = poDstDS->GetRasterBand(1)->GetRasterDataType(); - poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_cols, start_line, datacols, datarows, databuffer, datacols, datarows, gdal_datatype, 0, 0); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + std::shared_ptr poDstDS = OpenDataset(new_file_path, GA_Update); + GDALDataType gdal_datatype = poDstDS->GetRasterBand(1)->GetRasterDataType(); + poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_cols, start_line, datacols, datarows, + databuffer, datacols, datarows, gdal_datatype, 0, 0); GDALFlushCache(poDstDS.get()); return 0; } -int block_num_pre_memory(int block_width, int height, GDALDataType gdal_datatype,double memey_size) +int block_num_pre_memory(int block_width, int height, GDALDataType gdal_datatype, double memey_size) { // 计算大小 int size_meta = 0; - if (gdal_datatype == GDT_Byte) { + if(gdal_datatype == GDT_Byte) { size_meta = 1; - } - else if (gdal_datatype == GDT_UInt16) { - size_meta = 2; // 只有双通道才能构建 复数矩阵 - } - else if (gdal_datatype == GDT_UInt16) { - size_meta = 2; - } - else if (gdal_datatype == GDT_Int16) { - size_meta = 2; - } - else if (gdal_datatype == GDT_UInt32) { - size_meta = 4; - } - else if (gdal_datatype == GDT_Int32) { - size_meta = 4; - } - //else if (gdal_datatype == GDT_UInt64) { - // size_meta = 8; - //} - //else if (gdal_datatype == GDT_Int64) { - // size_meta = 8; - //} - else if (gdal_datatype == GDT_Float32) { + } else if(gdal_datatype == GDT_UInt16) { + size_meta = 2; // 只有双通道才能构建 复数矩阵 + } else if(gdal_datatype == GDT_UInt16) { + size_meta = 2; + } else if(gdal_datatype == GDT_Int16) { + size_meta = 2; + } else if(gdal_datatype == GDT_UInt32) { + size_meta = 4; + } else if(gdal_datatype == GDT_Int32) { size_meta = 4; } - else if (gdal_datatype == GDT_Float64) { - size_meta = 4; + // else if (gdal_datatype == GDT_UInt64) { + // size_meta = 8; + // } + // else if (gdal_datatype == GDT_Int64) { + // size_meta = 8; + // } + else if(gdal_datatype == GDT_Float32) { + size_meta = 4; + } else if(gdal_datatype == GDT_Float64) { + size_meta = 4; + } else if(gdal_datatype == GDT_CInt16) { + size_meta = 2; + } else if(gdal_datatype == GDT_CInt32) { + size_meta = 2; + } else if(gdal_datatype == GDT_CFloat32) { + size_meta = 4; + } else if(gdal_datatype == GDT_CFloat64) { + size_meta = 8; + } else { } - else if (gdal_datatype == GDT_CInt16) { size_meta = 2; } - else if (gdal_datatype == GDT_CInt32) { size_meta = 2; } - else if (gdal_datatype == GDT_CFloat32) { size_meta = 4; } - else if (gdal_datatype == GDT_CFloat64) { size_meta = 8; } - else {} int block_num = int(memey_size / (size_meta * block_width)); - block_num = block_num > height ? height : block_num; // 行数 - block_num = block_num < 1 ? 1 : block_num; + block_num = block_num > height ? height : block_num; // 行数 + block_num = block_num < 1 ? 1 : block_num; return block_num; } -Eigen::Matrix ReadComplexMatrixData(int start_line, int width, int line_num, std::shared_ptr rasterDataset, GDALDataType gdal_datatype) +Eigen::Matrix +ReadComplexMatrixData(int start_line, int width, int line_num, + std::shared_ptr rasterDataset, GDALDataType gdal_datatype) { - int band_num = rasterDataset->GetRasterCount(); - if (gdal_datatype == 0) { - return Eigen::Matrix (0, 0); - } - else if (gdal_datatype < 8) { - if (band_num != 2) { + if(gdal_datatype == 0) { + return Eigen::Matrix(0, 0); + } else if(gdal_datatype < 8) { + if(band_num != 2) { return Eigen::Matrix(0, 0); } - } - else if (gdal_datatype < 12) { - if (band_num != 1) { + } else if(gdal_datatype < 12) { + if(band_num != 1) { return Eigen::Matrix(0, 0); } + } else { } - else {} - bool _flag = false; - Eigen::Matrix data_mat(line_num * width, 2);// 必须强制行优先 - if (gdal_datatype == GDT_Byte) { + bool _flag = false; + Eigen::Matrix data_mat( + line_num * width, 2); // 必须强制行优先 + if(gdal_datatype == GDT_Byte) { Eigen::MatrixX real_mat(line_num * width, 1); Eigen::MatrixX imag_mat(line_num * width, 1); - rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real - rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag data_mat.col(0) = (real_mat.array().cast()).array(); data_mat.col(1) = (imag_mat.array().cast()).array(); - _flag = true; - } - else if (gdal_datatype == GDT_UInt16) { - Eigen::MatrixX real_mat(line_num * width, 1); - Eigen::MatrixX imag_mat(line_num * width, 1); - rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real - rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag + _flag = true; + } else if(gdal_datatype == GDT_UInt16) { + Eigen::MatrixX real_mat(line_num * width, 1); + Eigen::MatrixX imag_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag data_mat.col(0) = (real_mat.array().cast()).array(); data_mat.col(1) = (imag_mat.array().cast()).array(); - _flag = true; - } - else if (gdal_datatype == GDT_Int16) { - Eigen::MatrixX real_mat(line_num * width, 1); - Eigen::MatrixX imag_mat(line_num * width, 1); - rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real - rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag + _flag = true; + } else if(gdal_datatype == GDT_Int16) { + Eigen::MatrixX real_mat(line_num * width, 1); + Eigen::MatrixX imag_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag data_mat.col(0) = (real_mat.array().cast()).array(); data_mat.col(1) = (imag_mat.array().cast()).array(); - _flag = true; - } - else if (gdal_datatype == GDT_UInt32) { - Eigen::MatrixX real_mat(line_num * width, 1); - Eigen::MatrixX imag_mat(line_num * width, 1); - rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real - rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag + _flag = true; + } else if(gdal_datatype == GDT_UInt32) { + Eigen::MatrixX real_mat(line_num * width, 1); + Eigen::MatrixX imag_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag data_mat.col(0) = (real_mat.array().cast()).array(); data_mat.col(1) = (imag_mat.array().cast()).array(); - _flag = true; - } - else if (gdal_datatype == GDT_Int32) { - Eigen::MatrixX real_mat(line_num * width, 1); - Eigen::MatrixX imag_mat(line_num * width, 1); - rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real - rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag + _flag = true; + } else if(gdal_datatype == GDT_Int32) { + Eigen::MatrixX real_mat(line_num * width, 1); + Eigen::MatrixX imag_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag data_mat.col(0) = (real_mat.array().cast()).array(); data_mat.col(1) = (imag_mat.array().cast()).array(); - _flag = true; + _flag = true; } - //else if (gdal_datatype == GDT_UInt64) { + // else if (gdal_datatype == GDT_UInt64) { // Eigen::MatrixX real_mat(line_num * width, 1); // Eigen::MatrixX imag_mat(line_num * width, 1); - // rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real - // rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag - // data_mat.col(0) = (real_mat.array().cast()).array(); - // data_mat.col(1) = (imag_mat.array().cast()).array(); - // _flag = true; - //} - //else if (gdal_datatype == GDT_Int64) { + // rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + //real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + // rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + //imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag data_mat.col(0) = + //(real_mat.array().cast()).array(); data_mat.col(1) = + //(imag_mat.array().cast()).array(); _flag = true; + // } + // else if (gdal_datatype == GDT_Int64) { // Eigen::MatrixX real_mat(line_num * width, 1); // Eigen::MatrixX imag_mat(line_num * width, 1); - // rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real - // rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag - // data_mat.col(0) = (real_mat.array().cast()).array(); - // data_mat.col(1) = (imag_mat.array().cast()).array(); - // _flag = true; - //} - else if (gdal_datatype == GDT_Float32) { + // rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + //real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + // rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + //imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag data_mat.col(0) = + //(real_mat.array().cast()).array(); data_mat.col(1) = + //(imag_mat.array().cast()).array(); _flag = true; + // } + else if(gdal_datatype == GDT_Float32) { Eigen::MatrixX real_mat(line_num * width, 1); Eigen::MatrixX imag_mat(line_num * width, 1); - rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real - rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag data_mat.col(0) = (real_mat.array().cast()).array(); data_mat.col(1) = (imag_mat.array().cast()).array(); - _flag = true; - } - else if (gdal_datatype == GDT_Float64) { + _flag = true; + } else if(gdal_datatype == GDT_Float64) { Eigen::MatrixX real_mat(line_num * width, 1); Eigen::MatrixX imag_mat(line_num * width, 1); - rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real - rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag data_mat.col(0) = (real_mat.array().cast()).array(); data_mat.col(1) = (imag_mat.array().cast()).array(); - _flag = true; - } - else if (gdal_datatype == GDT_CInt16) { + _flag = true; + } else if(gdal_datatype == GDT_CInt16) { Eigen::MatrixX> complex_short_mat(line_num * width, 1); - rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, complex_short_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + complex_short_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real data_mat.col(0) = (complex_short_mat.real().array().cast()).array(); data_mat.col(1) = (complex_short_mat.imag().array().cast()).array(); - _flag = true; - } - else if (gdal_datatype == GDT_CInt32) { + _flag = true; + } else if(gdal_datatype == GDT_CInt32) { Eigen::MatrixX> complex_short_mat(line_num * width, 1); - rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, complex_short_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + complex_short_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real data_mat.col(0) = (complex_short_mat.real().array().cast()).array(); data_mat.col(1) = (complex_short_mat.imag().array().cast()).array(); - _flag = true; - } - else if (gdal_datatype == GDT_CFloat32) { + _flag = true; + } else if(gdal_datatype == GDT_CFloat32) { Eigen::MatrixX> complex_short_mat(line_num * width, 1); - rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, complex_short_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + complex_short_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real data_mat.col(0) = (complex_short_mat.real().array().cast()).array(); data_mat.col(1) = (complex_short_mat.imag().array().cast()).array(); - _flag = true; - } - else if (gdal_datatype == GDT_CFloat64) { + _flag = true; + } else if(gdal_datatype == GDT_CFloat64) { Eigen::MatrixX> complex_short_mat(line_num * width, 1); - rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, complex_short_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + complex_short_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real data_mat.col(0) = (complex_short_mat.real().array().cast()).array(); data_mat.col(1) = (complex_short_mat.imag().array().cast()).array(); - _flag = true; + _flag = true; + } else { } - else {} // 保存数据 - - if (_flag) { + if(_flag) { return data_mat; - } - else { - return Eigen::Matrix(0, 0);// 必须强制行优先; + } else { + return Eigen::Matrix( + 0, 0); // 必须强制行优先; } } -Eigen::Matrix ReadMatrixDoubleData(int start_line, int width, int line_num, std::shared_ptr rasterDataset, GDALDataType gdal_datatype, int band_idx) +Eigen::Matrix +ReadMatrixDoubleData(int start_line, int width, int line_num, + std::shared_ptr rasterDataset, GDALDataType gdal_datatype, + int band_idx) { // 构建矩阵块,使用eigen 进行矩阵计算,加速计算 - bool _flag = false; - Eigen::Matrix data_mat(line_num * width, 1);// 必须强制行优先 - if (gdal_datatype == GDT_Byte) { + bool _flag = false; + Eigen::Matrix data_mat( + line_num * width, 1); // 必须强制行优先 + if(gdal_datatype == GDT_Byte) { Eigen::MatrixX real_mat(line_num * width, 1); - rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; - _flag = true; - } - else if (gdal_datatype == GDT_UInt16) { - Eigen::MatrixX real_mat(line_num * width, 1); - rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + _flag = true; + } else if(gdal_datatype == GDT_UInt16) { + Eigen::MatrixX real_mat(line_num * width, 1); + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; - _flag = true; - } - else if (gdal_datatype == GDT_Int16) { - Eigen::MatrixX real_mat(line_num * width, 1); - rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + _flag = true; + } else if(gdal_datatype == GDT_Int16) { + Eigen::MatrixX real_mat(line_num * width, 1); + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; - _flag = true; - } - else if (gdal_datatype == GDT_UInt32) { - Eigen::MatrixX real_mat(line_num * width, 1); - rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + _flag = true; + } else if(gdal_datatype == GDT_UInt32) { + Eigen::MatrixX real_mat(line_num * width, 1); + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; - _flag = true; - } - else if (gdal_datatype == GDT_Int32) { - Eigen::MatrixX real_mat(line_num * width, 1); - rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + _flag = true; + } else if(gdal_datatype == GDT_Int32) { + Eigen::MatrixX real_mat(line_num * width, 1); + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; - _flag = true; + _flag = true; } - //else if (gdal_datatype == GDT_UInt64) { + // else if (gdal_datatype == GDT_UInt64) { // Eigen::MatrixX real_mat(line_num * width, 1); - // rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real - // data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; - // _flag = true; - //} - //else if (gdal_datatype == GDT_Int64) { + // rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + //real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real data_mat.col(0) = + //((real_mat.array().cast()).array().pow(2)).log10() * 10.0; _flag = true; + // } + // else if (gdal_datatype == GDT_Int64) { // Eigen::MatrixX real_mat(line_num * width, 1); - // rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real - // data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; - // _flag = true; - //} - else if (gdal_datatype == GDT_Float32) { + // rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + //real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real data_mat.col(0) = + //((real_mat.array().cast()).array().pow(2)).log10() * 10.0; _flag = true; + // } + else if(gdal_datatype == GDT_Float32) { Eigen::MatrixX real_mat(line_num * width, 1); - rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; - _flag = true; - } - else if (gdal_datatype == GDT_Float64) { + _flag = true; + } else if(gdal_datatype == GDT_Float64) { Eigen::MatrixX real_mat(line_num * width, 1); - rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; - _flag = true; + _flag = true; + } else { } - else {} - return data_mat; } -Eigen::MatrixXd getGeoTranslationArray(QString in_path) +Eigen::MatrixXd getGeoTranslationArray(QString in_path) { - - - return Eigen::MatrixXd(); } -ImageGEOINFO getImageINFO(QString in_path) +ImageGEOINFO getImageINFO(QString in_path) { - std::shared_ptr df = OpenDataset(in_path); - int width = df->GetRasterXSize(); - int heigh = df->GetRasterYSize(); - int band_num = df->GetRasterCount(); - ImageGEOINFO result; - result.width = width; - result.height = heigh; + std::shared_ptr df = OpenDataset(in_path); + int width = df->GetRasterXSize(); + int heigh = df->GetRasterYSize(); + int band_num = df->GetRasterCount(); + ImageGEOINFO result; + result.width = width; + result.height = heigh; result.bandnum = band_num; return result; } -GDALDataType getGDALDataType(QString fileptah) +GDALDataType getGDALDataType(QString fileptah) { omp_lock_t lock; omp_init_lock(&lock); omp_set_lock(&lock); GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen(fileptah.toUtf8().constData(), GA_ReadOnly));//锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( + fileptah.toUtf8().constData(), GA_ReadOnly)); // 锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); GDALClose((GDALDatasetH)rasterDataset); - omp_unset_lock(&lock); //锟酵放伙拷斤拷 - omp_destroy_lock(&lock); //劫伙拷斤拷 + omp_unset_lock(&lock); // 锟酵放伙拷斤拷 + omp_destroy_lock(&lock); // 劫伙拷斤拷 return gdal_datatype; } - gdalImage::gdalImage() { - this->height = 0; - this->width = 0; + this->height = 0; + this->width = 0; this->data_band_ids = 1; - this->start_row = 0; - this->start_col = 0; + this->start_row = 0; + this->start_col = 0; } /// @@ -406,19 +441,20 @@ gdalImage::gdalImage(const QString& raster_path) { omp_lock_t lock; omp_init_lock(&lock); // 锟斤拷始斤拷斤拷 - omp_set_lock(&lock); //锟斤拷没斤拷锟?1锟?7 + omp_set_lock(&lock); // 锟斤拷没斤拷锟?1锟?7 this->img_path = raster_path; GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");// 注绞斤拷斤拷锟?1锟?7 + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7 CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 锟斤拷DEM影锟斤拷 - GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen(raster_path.toUtf8().constData(), GA_ReadOnly));//锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 - this->width = rasterDataset->GetRasterXSize(); - this->height = rasterDataset->GetRasterYSize(); - this->band_num = rasterDataset->GetRasterCount(); + GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( + raster_path.toUtf8().constData(), GA_ReadOnly)); // 锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 + this->width = rasterDataset->GetRasterXSize(); + this->height = rasterDataset->GetRasterYSize(); + this->band_num = rasterDataset->GetRasterCount(); - double* gt = new double[6]; + double* gt = new double[6]; // 锟斤拷梅斤拷锟斤拷 rasterDataset->GetGeoTransform(gt); this->gt = Eigen::MatrixXd(2, 3); @@ -426,22 +462,20 @@ CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");// 注绞斤拷斤拷锟?1锟 this->projection = rasterDataset->GetProjectionRef(); // 斤拷斤拷 - //double* inv_gt = new double[6];; - //GDALInvGeoTransform(gt, inv_gt); // 斤拷斤拷 + // double* inv_gt = new double[6];; + // GDALInvGeoTransform(gt, inv_gt); // 斤拷斤拷 // 斤拷投影 GDALFlushCache((GDALDatasetH)rasterDataset); GDALClose((GDALDatasetH)rasterDataset); - rasterDataset = NULL;// 指矫匡拷 + rasterDataset = NULL; // 指矫匡拷 this->InitInv_gt(); delete[] gt; ////GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH - omp_unset_lock(&lock); //锟酵放伙拷斤拷 - omp_destroy_lock(&lock); //劫伙拷斤拷 + omp_unset_lock(&lock); // 锟酵放伙拷斤拷 + omp_destroy_lock(&lock); // 劫伙拷斤拷 } -gdalImage::~gdalImage() -{ -} +gdalImage::~gdalImage() {} void gdalImage::setHeight(int height) { @@ -460,129 +494,127 @@ void gdalImage::setTranslationMatrix(Eigen::MatrixXd gt) void gdalImage::setData(Eigen::MatrixXd, int data_band_ids) { - this->data = data; + this->data = data; this->data_band_ids = data_band_ids; } - - -Eigen::MatrixXd gdalImage::getData(int start_row, int start_col, int rows_count, int cols_count, int band_ids = 1) +Eigen::MatrixXd gdalImage::getData(int start_row, int start_col, int rows_count, int cols_count, + int band_ids = 1) { omp_lock_t lock; omp_init_lock(&lock); omp_set_lock(&lock); GDALAllRegister(); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly));//锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 + GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( + this->img_path.toUtf8().constData(), GA_ReadOnly)); // 锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 - GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); - GDALRasterBand* demBand = rasterDataset->GetRasterBand(band_ids); + GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); + GDALRasterBand* demBand = rasterDataset->GetRasterBand(band_ids); rows_count = start_row + rows_count <= this->height ? rows_count : this->height - start_row; cols_count = start_col + cols_count <= this->width ? cols_count : this->width - start_col; MatrixXd datamatrix(rows_count, cols_count); - - if (gdal_datatype == GDT_Byte) { + if(gdal_datatype == GDT_Byte) { char* temp = new char[rows_count * cols_count]; - demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0); - for (int i = 0; i < rows_count; i++) { - for (int j = 0; j < cols_count; j++) { + demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, + rows_count, gdal_datatype, 0, 0); + for(int i = 0; i < rows_count; i++) { + for(int j = 0; j < cols_count; j++) { datamatrix(i, j) = temp[i * cols_count + j]; } } delete[] temp; - } - else if (gdal_datatype == GDT_UInt16) { + } else if(gdal_datatype == GDT_UInt16) { unsigned short* temp = new unsigned short[rows_count * cols_count]; - demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0); - for (int i = 0; i < rows_count; i++) { - for (int j = 0; j < cols_count; j++) { + demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, + rows_count, gdal_datatype, 0, 0); + for(int i = 0; i < rows_count; i++) { + for(int j = 0; j < cols_count; j++) { datamatrix(i, j) = temp[i * cols_count + j]; } } delete[] temp; - } - else if (gdal_datatype == GDT_Int16) { + } else if(gdal_datatype == GDT_Int16) { short* temp = new short[rows_count * cols_count]; - demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0); - for (int i = 0; i < rows_count; i++) { - for (int j = 0; j < cols_count; j++) { + demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, + rows_count, gdal_datatype, 0, 0); + for(int i = 0; i < rows_count; i++) { + for(int j = 0; j < cols_count; j++) { datamatrix(i, j) = temp[i * cols_count + j]; } } delete[] temp; - } - else if (gdal_datatype == GDT_UInt32) { + } else if(gdal_datatype == GDT_UInt32) { unsigned int* temp = new unsigned int[rows_count * cols_count]; - demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0); - for (int i = 0; i < rows_count; i++) { - for (int j = 0; j < cols_count; j++) { + demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, + rows_count, gdal_datatype, 0, 0); + for(int i = 0; i < rows_count; i++) { + for(int j = 0; j < cols_count; j++) { datamatrix(i, j) = temp[i * cols_count + j]; } } delete[] temp; - } - else if (gdal_datatype == GDT_Int32) { + } else if(gdal_datatype == GDT_Int32) { int* temp = new int[rows_count * cols_count]; - demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0); - for (int i = 0; i < rows_count; i++) { - for (int j = 0; j < cols_count; j++) { + demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, + rows_count, gdal_datatype, 0, 0); + for(int i = 0; i < rows_count; i++) { + for(int j = 0; j < cols_count; j++) { datamatrix(i, j) = temp[i * cols_count + j]; } } delete[] temp; } - //else if (gdal_datatype == GDT_UInt64) { + // else if (gdal_datatype == GDT_UInt64) { // unsigned long* temp = new unsigned long[rows_count * cols_count]; - // demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0); - // for (int i = 0; i < rows_count; i++) { - // for (int j = 0; j < cols_count; j++) { - // datamatrix(i, j) = temp[i * cols_count + j]; + // demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, + //rows_count, gdal_datatype, 0, 0); for (int i = 0; i < rows_count; i++) { for (int j = 0; j < + //cols_count; j++) { datamatrix(i, j) = temp[i * cols_count + j]; // } // } // delete[] temp; - //} - //else if (gdal_datatype == GDT_Int64) { + // } + // else if (gdal_datatype == GDT_Int64) { // long* temp = new long[rows_count * cols_count]; - // demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0); - // for (int i = 0; i < rows_count; i++) { - // for (int j = 0; j < cols_count; j++) { - // datamatrix(i, j) = temp[i * cols_count + j]; + // demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, + //rows_count, gdal_datatype, 0, 0); for (int i = 0; i < rows_count; i++) { for (int j = 0; j < + //cols_count; j++) { datamatrix(i, j) = temp[i * cols_count + j]; // } // } // delete[] temp; - //} - else if (gdal_datatype == GDT_Float32) { + // } + else if(gdal_datatype == GDT_Float32) { float* temp = new float[rows_count * cols_count]; - demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0); + demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, + rows_count, gdal_datatype, 0, 0); - for (int i = 0; i < rows_count; i++) { - for (int j = 0; j < cols_count; j++) { + for(int i = 0; i < rows_count; i++) { + for(int j = 0; j < cols_count; j++) { datamatrix(i, j) = temp[i * cols_count + j]; } } delete[] temp; - } - else if (gdal_datatype == GDT_Float64) { + } else if(gdal_datatype == GDT_Float64) { double* temp = new double[rows_count * cols_count]; - demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0); + demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, + rows_count, gdal_datatype, 0, 0); - for (int i = 0; i < rows_count; i++) { - for (int j = 0; j < cols_count; j++) { + for(int i = 0; i < rows_count; i++) { + for(int j = 0; j < cols_count; j++) { datamatrix(i, j) = temp[i * cols_count + j]; } } delete[] temp; + } else { } - else {} GDALClose((GDALDatasetH)rasterDataset); - omp_unset_lock(&lock); //锟酵放伙拷斤拷 - omp_destroy_lock(&lock); //劫伙拷斤拷 - //GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + omp_unset_lock(&lock); // 锟酵放伙拷斤拷 + omp_destroy_lock(&lock); // 劫伙拷斤拷 + // GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH return datamatrix; - } Eigen::MatrixXd gdalImage::getGeoTranslation() @@ -592,7 +624,8 @@ Eigen::MatrixXd gdalImage::getGeoTranslation() GDALDataType gdalImage::getDataType() { - GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly)); + GDALDataset* rasterDataset = + (GDALDataset*)(GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly)); GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); return gdal_datatype; } @@ -604,59 +637,62 @@ GDALDataType gdalImage::getDataType() /// /// /// -void gdalImage::saveImage(Eigen::MatrixXd data, int start_row = 0, int start_col = 0, int band_ids = 1) +void gdalImage::saveImage(Eigen::MatrixXd data, int start_row = 0, int start_col = 0, + int band_ids = 1) { omp_lock_t lock; omp_init_lock(&lock); omp_set_lock(&lock); - if (start_row + data.rows() > this->height || start_col + data.cols() > this->width) { + if(start_row + data.rows() > this->height || start_col + data.cols() > this->width) { QString tip = u8"file path: " + this->img_path; qDebug() << tip; throw exception(tip.toUtf8().constData()); } GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); - GDALDataset* poDstDS = nullptr; - if (exists_test(this->img_path)) { + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + GDALDataset* poDstDS = nullptr; + if(exists_test(this->img_path)) { poDstDS = (GDALDataset*)(GDALOpen(this->img_path.toUtf8().constData(), GA_Update)); - } - else { - poDstDS = poDriver->Create(this->img_path.toUtf8().constData(), this->width, this->height, this->band_num, GDT_Float32, NULL); // 斤拷锟斤拷 + } else { + poDstDS = poDriver->Create(this->img_path.toUtf8().constData(), this->width, this->height, + this->band_num, GDT_Float32, NULL); // 斤拷锟斤拷 poDstDS->SetProjection(this->projection.toUtf8().constData()); - double gt_ptr[6]; - for (int i = 0; i < this->gt.rows(); i++) { - for (int j = 0; j < this->gt.cols(); j++) { + for(int i = 0; i < this->gt.rows(); i++) { + for(int j = 0; j < this->gt.cols(); j++) { gt_ptr[i * 3 + j] = this->gt(i, j); } } poDstDS->SetGeoTransform(gt_ptr); - delete[] gt_ptr; + //delete gt_ptr; } - int datarows = data.rows(); - int datacols = data.cols(); + int datarows = data.rows(); + int datacols = data.cols(); - float* databuffer = new float[datarows * datacols];// (float*)malloc(datarows * datacols * sizeof(float)); + float* databuffer = + new float[datarows * datacols]; // (float*)malloc(datarows * datacols * sizeof(float)); - for (int i = 0; i < datarows; i++) { - for (int j = 0; j < datacols; j++) { - float temp = float(data(i, j)); + for(int i = 0; i < datarows; i++) { + for(int j = 0; j < datacols; j++) { + float temp = float(data(i, j)); databuffer[i * datacols + j] = temp; } } - //poDstDS->RasterIO(GF_Write,start_col, start_row, datacols, datarows, databuffer, datacols, datarows, GDT_Float32,band_ids, num,0,0,0); - poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_col, start_row, datacols, datarows, databuffer, datacols, datarows, GDT_Float32, 0, 0); + // poDstDS->RasterIO(GF_Write,start_col, start_row, datacols, datarows, databuffer, datacols, + // datarows, GDT_Float32,band_ids, num,0,0,0); + poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_col, start_row, datacols, datarows, + databuffer, datacols, datarows, GDT_Float32, 0, 0); GDALFlushCache(poDstDS); GDALClose((GDALDatasetH)poDstDS); - //GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + // GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH delete[] databuffer; - omp_unset_lock(&lock); //锟酵放伙拷斤拷 - omp_destroy_lock(&lock); //劫伙拷斤拷 + omp_unset_lock(&lock); // 锟酵放伙拷斤拷 + omp_destroy_lock(&lock); // 劫伙拷斤拷 } void gdalImage::saveImage() @@ -667,8 +703,8 @@ void gdalImage::saveImage() void gdalImage::setNoDataValue(double nodatavalue = -9999, int band_ids = 1) { GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");// 注绞斤拷斤拷锟?1锟?7 - //GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7 + // GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); GDALDataset* poDstDS = (GDALDataset*)(GDALOpen(img_path.toUtf8().constData(), GA_Update)); poDstDS->GetRasterBand(band_ids)->SetNoDataValue(nodatavalue); GDALFlushCache((GDALDatasetH)poDstDS); @@ -677,106 +713,104 @@ CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");// 注绞斤拷斤拷锟?1锟 int gdalImage::InitInv_gt() { - //1 lon lat = x - //1 lon lat = y - Eigen::MatrixXd temp=Eigen::MatrixXd::Zero(2, 3); - this->inv_gt = temp; - double a = this->gt(0, 0); - double b = this->gt(0, 1); - double c = this->gt(0, 2); - double d = this->gt(1, 0); - double e = this->gt(1, 1); - double f = this->gt(1, 2); - double g = 1; - double det_gt = b * f - c * e; - if (det_gt == 0) { + // 1 lon lat = x + // 1 lon lat = y + Eigen::MatrixXd temp = Eigen::MatrixXd::Zero(2, 3); + this->inv_gt = temp; + double a = this->gt(0, 0); + double b = this->gt(0, 1); + double c = this->gt(0, 2); + double d = this->gt(1, 0); + double e = this->gt(1, 1); + double f = this->gt(1, 2); + double g = 1; + double det_gt = b * f - c * e; + if(det_gt == 0) { return 0; } - this->inv_gt(0, 0) = (c * d - a * f) / det_gt; //2 - this->inv_gt(0, 1) = f / det_gt; // lon - this->inv_gt(0, 2) = -c / det_gt; // lat - this->inv_gt(1, 0) = (a * e - b * d) / det_gt; //1 - this->inv_gt(1, 1) = -e / det_gt; // lon - this->inv_gt(1, 2) = b / det_gt; // lat + this->inv_gt(0, 0) = (c * d - a * f) / det_gt; // 2 + this->inv_gt(0, 1) = f / det_gt; // lon + this->inv_gt(0, 2) = -c / det_gt; // lat + this->inv_gt(1, 0) = (a * e - b * d) / det_gt; // 1 + this->inv_gt(1, 1) = -e / det_gt; // lon + this->inv_gt(1, 2) = b / det_gt; // lat return 1; } Landpoint gdalImage::getRow_Col(double lon, double lat) { - Landpoint p{ 0,0,0 }; - p.lon = this->inv_gt(0, 0) + lon * this->inv_gt(0, 1) + lat * this->inv_gt(0, 2); //x - p.lat = this->inv_gt(1, 0) + lon * this->inv_gt(1, 1) + lat * this->inv_gt(1, 2); //y + Landpoint p{ 0, 0, 0 }; + p.lon = this->inv_gt(0, 0) + lon * this->inv_gt(0, 1) + lat * this->inv_gt(0, 2); // x + p.lat = this->inv_gt(1, 0) + lon * this->inv_gt(1, 1) + lat * this->inv_gt(1, 2); // y return p; } Landpoint gdalImage::getLandPoint(double row, double col, double ati = 0) { - Landpoint p{ 0,0,0 }; - p.lon = this->gt(0, 0) + col * this->gt(0, 1) + row * this->gt(0, 2); //x - p.lat = this->gt(1, 0) + col * this->gt(1, 1) + row * this->gt(1, 2); //y + Landpoint p{ 0, 0, 0 }; + p.lon = this->gt(0, 0) + col * this->gt(0, 1) + row * this->gt(0, 2); // x + p.lat = this->gt(1, 0) + col * this->gt(1, 1) + row * this->gt(1, 2); // y p.ati = ati; return p; } double gdalImage::mean(int bandids) { - double mean_value = 0; - double count = this->height * this->width; - int line_invert = 100; - int start_ids = 0; + double mean_value = 0; + double count = this->height * this->width; + int line_invert = 100; + int start_ids = 0; do { - Eigen::MatrixXd sar_a = this->getData(start_ids, 0, line_invert, this->width, bandids); - mean_value = mean_value + sar_a.sum() / count; - start_ids = start_ids + line_invert; - } while (start_ids < this->height); + Eigen::MatrixXd sar_a = this->getData(start_ids, 0, line_invert, this->width, bandids); + mean_value = mean_value + sar_a.sum() / count; + start_ids = start_ids + line_invert; + } while(start_ids < this->height); return mean_value; } double gdalImage::max(int bandids) { - double max_value = 0; - bool state_max = true; - int line_invert = 100; - int start_ids = 0; - double temp_max = 0; + double max_value = 0; + bool state_max = true; + int line_invert = 100; + int start_ids = 0; + double temp_max = 0; do { - Eigen::MatrixXd sar_a = this->getData(start_ids, 0, line_invert, this->width, bandids); - if (state_max) { + Eigen::MatrixXd sar_a = this->getData(start_ids, 0, line_invert, this->width, bandids); + if(state_max) { state_max = false; max_value = sar_a.maxCoeff(); - } - else { + } else { temp_max = sar_a.maxCoeff(); - if (max_value < temp_max) { + if(max_value < temp_max) { max_value = temp_max; } } start_ids = start_ids + line_invert; - } while (start_ids < this->height); + } while(start_ids < this->height); return max_value; } double gdalImage::min(int bandids) { - double min_value = 0; - bool state_min = true; - int line_invert = 100; - int start_ids = 0; - double temp_min = 0; + double min_value = 0; + bool state_min = true; + int line_invert = 100; + int start_ids = 0; + double temp_min = 0; do { - Eigen::MatrixXd sar_a = this->getData(start_ids, 0, line_invert, this->width, bandids); - if (state_min) { + Eigen::MatrixXd sar_a = this->getData(start_ids, 0, line_invert, this->width, bandids); + if(state_min) { state_min = false; min_value = sar_a.minCoeff(); - } - else { + } else { temp_min = sar_a.minCoeff(); - if (min_value < temp_min) { + if(min_value < temp_min) { min_value = temp_min; } } start_ids = start_ids + line_invert; - } while (start_ids < this->height); + } while(start_ids < this->height); return min_value; } @@ -785,14 +819,14 @@ GDALRPCInfo gdalImage::getRPC() CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); CPLSetConfigOption("GDAL_DATA", "./data"); GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");//注斤拷锟斤拷 - //斤拷锟斤拷 + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注斤拷锟斤拷 + // 斤拷锟斤拷 GDALDataset* pDS = (GDALDataset*)GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly); - //锟斤拷元斤拷锟叫伙拷取RPC锟斤拷息 - char** papszRPC = pDS->GetMetadata("RPC"); + // 锟斤拷元斤拷锟叫伙拷取RPC锟斤拷息 + char** papszRPC = pDS->GetMetadata("RPC"); - //斤拷取锟斤拷RPC锟斤拷息斤拷山峁癸拷锟?1锟?7 - GDALRPCInfo oInfo; + // 斤拷取锟斤拷RPC锟斤拷息斤拷山峁癸拷锟?1锟?7 + GDALRPCInfo oInfo; GDALExtractRPCInfo(papszRPC, &oInfo); GDALClose((GDALDatasetH)pDS); @@ -802,17 +836,17 @@ CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");//注斤拷锟斤拷 Eigen::MatrixXd gdalImage::getLandPoint(Eigen::MatrixXd points) { - if (points.cols() != 3) { + if(points.cols() != 3) { throw new exception("the size of points is equit 3!!!"); } Eigen::MatrixXd result(points.rows(), 3); - result.col(2) = points.col(2);// 锟竭筹拷 + result.col(2) = points.col(2); // 锟竭筹拷 points.col(2) = points.col(2).array() * 0 + 1; - points.col(0).swap(points.col(2));// 斤拷 + points.col(0).swap(points.col(2)); // 斤拷 Eigen::MatrixXd gts(3, 2); - gts.col(0) = this->gt.row(0); - gts.col(1) = this->gt.row(1); + gts.col(0) = this->gt.row(0); + gts.col(1) = this->gt.row(1); result.block(0, 0, points.rows(), 2) = points * gts; return result; @@ -821,23 +855,23 @@ Eigen::MatrixXd gdalImage::getLandPoint(Eigen::MatrixXd points) Eigen::MatrixXd gdalImage::getHist(int bandids) { GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");// 注绞斤拷斤拷锟?1锟?7 + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7 // 锟斤拷DEM影锟斤拷 - GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly));//锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 + GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( + this->img_path.toUtf8().constData(), GA_ReadOnly)); // 锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 - GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); - GDALRasterBand* xBand = rasterDataset->GetRasterBand(bandids); + GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); + GDALRasterBand* xBand = rasterDataset->GetRasterBand(bandids); - - double dfMin = this->min(bandids); - double dfMax = this->max(bandids); - int count = int((dfMax - dfMin) / 0.01); - count = count > 255 ? count : 255; - GUIntBig* panHistogram = new GUIntBig[count]; + double dfMin = this->min(bandids); + double dfMax = this->max(bandids); + int count = int((dfMax - dfMin) / 0.01); + count = count > 255 ? count : 255; + GUIntBig* panHistogram = new GUIntBig[count]; xBand->GetHistogram(dfMin, dfMax, count, panHistogram, TRUE, FALSE, NULL, NULL); Eigen::MatrixXd result(count, 2); - double delta = (dfMax - dfMin) / count; - for (int i = 0; i < count; i++) { + double delta = (dfMax - dfMin) / count; + for(int i = 0; i < count; i++) { result(i, 0) = dfMin + i * delta; result(i, 1) = double(panHistogram[i]); } @@ -846,36 +880,36 @@ CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");// 注绞斤拷斤拷锟?1锟 return result; } - -gdalImage CreategdalImage(const QString& img_path, int height, int width, int band_num, Eigen::MatrixXd gt, QString projection, bool need_gt,bool overwrite) { - - if (exists_test(img_path.toUtf8().constData())) { - if (overwrite) { +gdalImage CreategdalImage(const QString& img_path, int height, int width, int band_num, + Eigen::MatrixXd gt, QString projection, bool need_gt, bool overwrite) +{ + if(exists_test(img_path.toUtf8().constData())) { + if(overwrite) { gdalImage result_img(img_path); return result_img; - } - else { - throw "file has exist!!!"; - exit(1); + } else { + throw "file has exist!!!"; + exit(1); } } GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");// 注锟斤拷锟绞斤拷锟斤拷锟斤拷锟?1锟?7 - GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); - GDALDataset* poDstDS = poDriver->Create(img_path.toUtf8().constData(), width, height, band_num, GDT_Float32, NULL); // 锟斤拷锟斤拷锟斤拷 - if (need_gt) { + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注锟斤拷锟绞斤拷锟斤拷锟斤拷锟?1锟?7 + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + GDALDataset* poDstDS = poDriver->Create(img_path.toUtf8().constData(), width, height, band_num, + GDT_Float32, NULL); // 锟斤拷锟斤拷锟斤拷 + if(need_gt) { poDstDS->SetProjection(projection.toUtf8().constData()); // 锟斤拷锟斤拷转锟斤拷锟斤拷锟斤拷 double gt_ptr[6] = { 0 }; - for (int i = 0; i < gt.rows(); i++) { - for (int j = 0; j < gt.cols(); j++) { + for(int i = 0; i < gt.rows(); i++) { + for(int j = 0; j < gt.cols(); j++) { gt_ptr[i * 3 + j] = gt(i, j); } } poDstDS->SetGeoTransform(gt_ptr); } - for (int i = 1; i <= band_num; i++) { + for(int i = 1; i <= band_num; i++) { poDstDS->GetRasterBand(i)->SetNoDataValue(-9999); } GDALFlushCache((GDALDatasetH)poDstDS); @@ -885,35 +919,37 @@ CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");// 注锟斤拷锟绞斤拷 return result_img; } -gdalImageComplex CreategdalImageComplex(const QString& img_path, int height, int width, int band_num, Eigen::MatrixXd gt, QString projection, bool need_gt, bool overwrite) +gdalImageComplex CreategdalImageComplex(const QString& img_path, int height, int width, + int band_num, Eigen::MatrixXd gt, QString projection, + bool need_gt, bool overwrite) { - if (exists_test(img_path.toUtf8().constData())) { - if (overwrite) { + if(exists_test(img_path.toUtf8().constData())) { + if(overwrite) { gdalImageComplex result_img(img_path); return result_img; - } - else { + } else { throw "file has exist!!!"; exit(1); } } GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); - GDALDataset* poDstDS = poDriver->Create(img_path.toUtf8().constData(), width, height, band_num, GDT_CFloat64, NULL); - if (need_gt) { + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); + GDALDataset* poDstDS = poDriver->Create(img_path.toUtf8().constData(), width, height, band_num, + GDT_CFloat64, NULL); + if(need_gt) { poDstDS->SetProjection(projection.toUtf8().constData()); // 锟斤拷锟斤拷转锟斤拷锟斤拷锟斤拷 double gt_ptr[6] = { 0 }; - for (int i = 0; i < gt.rows(); i++) { - for (int j = 0; j < gt.cols(); j++) { + for(int i = 0; i < gt.rows(); i++) { + for(int j = 0; j < gt.cols(); j++) { gt_ptr[i * 3 + j] = gt(i, j); } } poDstDS->SetGeoTransform(gt_ptr); } - for (int i = 1; i <= band_num; i++) { + for(int i = 1; i <= band_num; i++) { poDstDS->GetRasterBand(i)->SetNoDataValue(-9999); } GDALFlushCache((GDALDatasetH)poDstDS); @@ -923,66 +959,63 @@ CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); return result_img; } - -int ResampleGDAL(const char* pszSrcFile, const char* pszOutFile, double* gt, int new_width, int new_height, GDALResampleAlg eResample) +int ResampleGDAL(const char* pszSrcFile, const char* pszOutFile, double* gt, int new_width, + int new_height, GDALResampleAlg eResample) { GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); GDALDataset* pDSrc = (GDALDataset*)GDALOpen(pszSrcFile, GA_ReadOnly); - if (pDSrc == NULL) - { + if(pDSrc == NULL) { return -1; } GDALDriver* pDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); - if (pDriver == NULL) - { + if(pDriver == NULL) { GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); return -2; } - int width = pDSrc->GetRasterXSize(); - int height = pDSrc->GetRasterYSize(); - int nBandCount = pDSrc->GetRasterCount(); - GDALDataType dataType = pDSrc->GetRasterBand(1)->GetRasterDataType(); + int width = pDSrc->GetRasterXSize(); + int height = pDSrc->GetRasterYSize(); + int nBandCount = pDSrc->GetRasterCount(); + GDALDataType dataType = pDSrc->GetRasterBand(1)->GetRasterDataType(); - char* pszSrcWKT = NULL; - pszSrcWKT = const_cast(pDSrc->GetProjectionRef()); + char* pszSrcWKT = NULL; + pszSrcWKT = const_cast(pDSrc->GetProjectionRef()); - //锟斤拷锟矫伙拷锟酵队帮拷锟斤拷锟轿?拷锟斤拷锟揭伙拷锟?1锟?7 - if (strlen(pszSrcWKT) <= 0) - { + // 锟斤拷锟矫伙拷锟酵队帮拷锟斤拷锟轿?拷锟斤拷锟揭伙拷锟?1锟?7 + if(strlen(pszSrcWKT) <= 0) { OGRSpatialReference oSRS; oSRS.importFromEPSG(4326); - //oSRS.SetUTM(50, true); //锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷120锟斤拷 - //oSRS.SetWellKnownGeogCS("WGS84"); + // oSRS.SetUTM(50, true); //锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷120锟斤拷 + // oSRS.SetWellKnownGeogCS("WGS84"); oSRS.exportToWkt(&pszSrcWKT); } qDebug() << "GDALCreateGenImgProjTransformer " << endl; void* hTransformArg; - hTransformArg = GDALCreateGenImgProjTransformer((GDALDatasetH)pDSrc, pszSrcWKT, NULL, pszSrcWKT, FALSE, 0.0, 1); + hTransformArg = GDALCreateGenImgProjTransformer((GDALDatasetH)pDSrc, pszSrcWKT, NULL, pszSrcWKT, + FALSE, 0.0, 1); qDebug() << "no proj " << endl; - //(没锟斤拷投影锟斤拷影锟斤拷锟斤拷锟斤拷锟斤拷卟锟酵?拷锟?1锟?7) - if (hTransformArg == NULL) - { + //(没锟斤拷投影锟斤拷影锟斤拷锟斤拷锟斤拷锟斤拷卟锟酵?拷锟?1锟?7) + if(hTransformArg == NULL) { GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); return -3; } qDebug() << "has proj " << endl; double dGeoTrans[6] = { 0 }; - int nNewWidth = 0, nNewHeight = 0; - if (GDALSuggestedWarpOutput((GDALDatasetH)pDSrc, GDALGenImgProjTransform, hTransformArg, dGeoTrans, &nNewWidth, &nNewHeight) != CE_None) - { + int nNewWidth = 0, nNewHeight = 0; + if(GDALSuggestedWarpOutput((GDALDatasetH)pDSrc, GDALGenImgProjTransform, hTransformArg, + dGeoTrans, &nNewWidth, &nNewHeight) + != CE_None) { GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); return -3; } - //GDALDestroyGenImgProjTransformer(hTransformArg); + // GDALDestroyGenImgProjTransformer(hTransformArg); - - GDALDataset* pDDst = pDriver->Create(pszOutFile, new_width, new_height, nBandCount, dataType, NULL); - if (pDDst == NULL) - { + GDALDataset* pDDst = + pDriver->Create(pszOutFile, new_width, new_height, nBandCount, dataType, NULL); + if(pDDst == NULL) { GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); return -2; } @@ -990,31 +1023,31 @@ CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); pDDst->SetProjection(pszSrcWKT); pDDst->SetGeoTransform(gt); - GDALWarpOptions* psWo = GDALCreateWarpOptions(); + GDALWarpOptions* psWo = GDALCreateWarpOptions(); - //psWo->papszWarpOptions = CSLDuplicate(NULL); + // psWo->papszWarpOptions = CSLDuplicate(NULL); psWo->eWorkingDataType = dataType; - psWo->eResampleAlg = eResample; + psWo->eResampleAlg = eResample; - psWo->hSrcDS = (GDALDatasetH)pDSrc; - psWo->hDstDS = (GDALDatasetH)pDDst; + psWo->hSrcDS = (GDALDatasetH)pDSrc; + psWo->hDstDS = (GDALDatasetH)pDDst; qDebug() << "GDALCreateGenImgProjTransformer" << endl; - psWo->pfnTransformer = GDALGenImgProjTransform; - psWo->pTransformerArg = GDALCreateGenImgProjTransformer((GDALDatasetH)pDSrc, pszSrcWKT, (GDALDatasetH)pDDst, pszSrcWKT, FALSE, 0.0, 1);; + psWo->pfnTransformer = GDALGenImgProjTransform; + psWo->pTransformerArg = GDALCreateGenImgProjTransformer( + (GDALDatasetH)pDSrc, pszSrcWKT, (GDALDatasetH)pDDst, pszSrcWKT, FALSE, 0.0, 1); + ; qDebug() << "GDALCreateGenImgProjTransformer has created" << endl; - psWo->nBandCount = nBandCount; + psWo->nBandCount = nBandCount; psWo->panSrcBands = (int*)CPLMalloc(nBandCount * sizeof(int)); psWo->panDstBands = (int*)CPLMalloc(nBandCount * sizeof(int)); - for (int i = 0; i < nBandCount; i++) - { + for(int i = 0; i < nBandCount; i++) { psWo->panSrcBands[i] = i + 1; psWo->panDstBands[i] = i + 1; } GDALWarpOperation oWo; - if (oWo.Initialize(psWo) != CE_None) - { + if(oWo.Initialize(psWo) != CE_None) { GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); return -3; @@ -1023,81 +1056,81 @@ CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); oWo.ChunkAndWarpMulti(0, 0, new_width, new_height); GDALFlushCache(pDDst); qDebug() << "ChunkAndWarpImage over" << endl; - //GDALDestroyGenImgProjTransformer(psWo->pTransformerArg); - //GDALDestroyWarpOptions(psWo); + // GDALDestroyGenImgProjTransformer(psWo->pTransformerArg); + // GDALDestroyWarpOptions(psWo); GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); ////GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH return 0; } -int ResampleGDALs(const char* pszSrcFile, int band_ids, GDALRIOResampleAlg eResample) +int ResampleGDALs(const char* pszSrcFile, int band_ids, GDALRIOResampleAlg eResample) { GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); GDALDataset* pDSrc = (GDALDataset*)GDALOpen(pszSrcFile, GA_Update); - if (pDSrc == NULL) - { + if(pDSrc == NULL) { return -1; } - GDALDataType gdal_datatype = pDSrc->GetRasterBand(1)->GetRasterDataType(); + GDALDataType gdal_datatype = pDSrc->GetRasterBand(1)->GetRasterDataType(); - GDALRasterBand* demBand = pDSrc->GetRasterBand(band_ids); + GDALRasterBand* demBand = pDSrc->GetRasterBand(band_ids); - int width = pDSrc->GetRasterXSize(); - int height = pDSrc->GetRasterYSize(); - int start_col = 0, start_row = 0, rows_count = 0, cols_count; + int width = pDSrc->GetRasterXSize(); + int height = pDSrc->GetRasterYSize(); + int start_col = 0, start_row = 0, rows_count = 0, cols_count; - int row_delta = int(120000000 / width); + int row_delta = int(120000000 / width); GDALRasterIOExtraArg psExtraArg; INIT_RASTERIO_EXTRA_ARG(psExtraArg); psExtraArg.eResampleAlg = eResample; do { - rows_count = start_row + row_delta < height ? row_delta : height - start_row; cols_count = width; - if (gdal_datatype == GDALDataType::GDT_UInt16) { - + if(gdal_datatype == GDALDataType::GDT_UInt16) { unsigned short* temp = new unsigned short[rows_count * cols_count]; - demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0); - demBand->RasterIO(GF_Write, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0, &psExtraArg); + demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, + cols_count, rows_count, gdal_datatype, 0, 0); + demBand->RasterIO(GF_Write, start_col, start_row, cols_count, rows_count, temp, + cols_count, rows_count, gdal_datatype, 0, 0, &psExtraArg); delete[] temp; - } - else if (gdal_datatype == GDALDataType::GDT_Int16) { - + } else if(gdal_datatype == GDALDataType::GDT_Int16) { short* temp = new short[rows_count * cols_count]; - demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0); - demBand->RasterIO(GF_Write, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0, &psExtraArg); + demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, + cols_count, rows_count, gdal_datatype, 0, 0); + demBand->RasterIO(GF_Write, start_col, start_row, cols_count, rows_count, temp, + cols_count, rows_count, gdal_datatype, 0, 0, &psExtraArg); delete[] temp; - } - else if (gdal_datatype == GDALDataType::GDT_Float32) { + } else if(gdal_datatype == GDALDataType::GDT_Float32) { float* temp = new float[rows_count * cols_count]; - demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0); - demBand->RasterIO(GF_Write, start_col, start_row, cols_count, rows_count, temp, cols_count, rows_count, gdal_datatype, 0, 0, &psExtraArg); + demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, + cols_count, rows_count, gdal_datatype, 0, 0); + demBand->RasterIO(GF_Write, start_col, start_row, cols_count, rows_count, temp, + cols_count, rows_count, gdal_datatype, 0, 0, &psExtraArg); delete[] temp; } start_row = start_row + rows_count; - } while (start_row < height); + } while(start_row < height); GDALClose((GDALDatasetH)pDSrc); - return 0; } -int saveMatrixXcd2TiFF(Eigen::MatrixXcd data, QString out_tiff_path) +int saveMatrixXcd2TiFF(Eigen::MatrixXcd data, QString out_tiff_path) { - int rows = data.rows(); - int cols = data.cols(); + int rows = data.rows(); + int cols = data.cols(); - Eigen::MatrixXd gt = Eigen::MatrixXd::Zero(2, 3); + Eigen::MatrixXd gt = Eigen::MatrixXd::Zero(2, 3); - gdalImage image_tiff = CreategdalImage(out_tiff_path, rows, cols, 2, gt, "", false, true);// 注意这里保留仿真结果 + gdalImage image_tiff = + CreategdalImage(out_tiff_path, rows, cols, 2, gt, "", false, true); // 注意这里保留仿真结果 // 保存二进制文件 Eigen::MatrixXd real_img = data.array().real(); Eigen::MatrixXd imag_img = data.array().imag(); @@ -1106,52 +1139,47 @@ int saveMatrixXcd2TiFF(Eigen::MatrixXcd data, QString out_tiff_path) return -1; } - gdalImageComplex::gdalImageComplex(const QString& raster_path) { omp_lock_t lock; omp_init_lock(&lock); - omp_set_lock(&lock); + omp_set_lock(&lock); this->img_path = raster_path; GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen(raster_path.toUtf8().constData(), GA_ReadOnly));//锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 - this->width = rasterDataset->GetRasterXSize(); - this->height = rasterDataset->GetRasterYSize(); - this->band_num = rasterDataset->GetRasterCount(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( + raster_path.toUtf8().constData(), GA_ReadOnly)); // 锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 + this->width = rasterDataset->GetRasterXSize(); + this->height = rasterDataset->GetRasterYSize(); + this->band_num = rasterDataset->GetRasterCount(); - double* gt = new double[6]; + double* gt = new double[6]; rasterDataset->GetGeoTransform(gt); this->gt = Eigen::MatrixXd(2, 3); this->gt << gt[0], gt[1], gt[2], gt[3], gt[4], gt[5]; - - double a = this->gt(0, 0); - double b = this->gt(0, 1); - double c = this->gt(0, 2); - double d = this->gt(1, 0); - double e = this->gt(1, 1); - double f = this->gt(1, 2); + double a = this->gt(0, 0); + double b = this->gt(0, 1); + double c = this->gt(0, 2); + double d = this->gt(1, 0); + double e = this->gt(1, 1); + double f = this->gt(1, 2); this->projection = rasterDataset->GetProjectionRef(); - + // 斤拷投影 GDALFlushCache((GDALDatasetH)rasterDataset); GDALClose((GDALDatasetH)rasterDataset); - rasterDataset = NULL;// 指矫匡拷 + rasterDataset = NULL; // 指矫匡拷 this->InitInv_gt(); delete[] gt; ////GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH - omp_unset_lock(&lock); //锟酵放伙拷斤拷 - omp_destroy_lock(&lock); //劫伙拷斤拷 - - + omp_unset_lock(&lock); // 锟酵放伙拷斤拷 + omp_destroy_lock(&lock); // 劫伙拷斤拷 } -gdalImageComplex::~gdalImageComplex() -{ -} +gdalImageComplex::~gdalImageComplex() {} void gdalImageComplex::setData(Eigen::MatrixXcd data) { @@ -1163,96 +1191,179 @@ void gdalImageComplex::saveImage(Eigen::MatrixXcd data, int start_row, int start omp_lock_t lock; omp_init_lock(&lock); omp_set_lock(&lock); - if (start_row + data.rows() > this->height || start_col + data.cols() > this->width) { + if(start_row + data.rows() > this->height || start_col + data.cols() > this->width) { QString tip = u8"file path: " + this->img_path; qDebug() << tip; throw exception(tip.toUtf8().constData()); } GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); - GDALDataset* poDstDS = nullptr; - if (exists_test(this->img_path)) { + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); + GDALDataset* poDstDS = nullptr; + if(exists_test(this->img_path)) { poDstDS = (GDALDataset*)(GDALOpen(this->img_path.toUtf8().constData(), GA_Update)); - } - else { - poDstDS = poDriver->Create(this->img_path.toUtf8().constData(), this->width, this->height, this->band_num, GDT_CFloat64, NULL); // 斤拷锟斤拷 + } else { + poDstDS = poDriver->Create(this->img_path.toUtf8().constData(), this->width, this->height, + this->band_num, GDT_CFloat64, NULL); // 斤拷锟斤拷 poDstDS->SetProjection(this->projection.toUtf8().constData()); - double gt_ptr[6]; - for (int i = 0; i < this->gt.rows(); i++) { - for (int j = 0; j < this->gt.cols(); j++) { + for(int i = 0; i < this->gt.rows(); i++) { + for(int j = 0; j < this->gt.cols(); j++) { gt_ptr[i * 3 + j] = this->gt(i, j); } } poDstDS->SetGeoTransform(gt_ptr); - delete[] gt_ptr; + //delete[] gt_ptr; } - int datarows = data.rows(); - int datacols = data.cols(); - + int datarows = data.rows(); + int datacols = data.cols(); + double* databuffer = new double[data.size() * 2]; - for (int i = 0; i < data.rows(); i++) { - for (int j = 0; j < data.cols(); j++) { - databuffer[i * data.cols() * 2 + j * 2] = data(i, j).real(); + for(int i = 0; i < data.rows(); i++) { + for(int j = 0; j < data.cols(); j++) { + databuffer[i * data.cols() * 2 + j * 2] = data(i, j).real(); databuffer[i * data.cols() * 2 + j * 2 + 1] = data(i, j).imag(); } } - - //poDstDS->RasterIO(GF_Write,start_col, start_row, datacols, datarows, databuffer, datacols, datarows, GDT_Float32,band_ids, num,0,0,0); - poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_col, start_row, datacols, datarows, databuffer, datacols, datarows, GDT_CFloat64, 0, 0); + + // poDstDS->RasterIO(GF_Write,start_col, start_row, datacols, datarows, databuffer, datacols, + // datarows, GDT_Float32,band_ids, num,0,0,0); + poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_col, start_row, datacols, datarows, + databuffer, datacols, datarows, GDT_CFloat64, 0, 0); GDALFlushCache(poDstDS); delete databuffer; GDALClose((GDALDatasetH)poDstDS); - //GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH - omp_unset_lock(&lock); //锟酵放伙拷斤拷 - omp_destroy_lock(&lock); //劫伙拷斤拷 - + // GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + omp_unset_lock(&lock); // + omp_destroy_lock(&lock); // } -Eigen::MatrixXcd gdalImageComplex::getDataComplex(int start_row, int start_col, int rows_count, int cols_count, int band_ids) +Eigen::MatrixXcd gdalImageComplex::getDataComplex(int start_row, int start_col, int rows_count, + int cols_count, int band_ids) { - - GDALDataset* poDataset; GDALAllRegister(); -CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 打开TIFF文件 poDataset = (GDALDataset*)GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly); - if (poDataset == nullptr) { + if(poDataset == nullptr) { QMessageBox::warning(nullptr, u8"错误", u8"无法打开文件:" + this->img_path); qDebug() << u8"无法打开文件:" + this->img_path; } // 获取数据集的第一个波段 GDALRasterBand* poBand; - poBand = poDataset->GetRasterBand(1); + poBand = poDataset->GetRasterBand(1); // 读取波段信息,假设是复数类型 - int nXSize = poBand->GetXSize(); - int nYSize = poBand->GetYSize(); - + int nXSize = poBand->GetXSize(); + int nYSize = poBand->GetYSize(); double* databuffer = new double[nXSize * nYSize * 2]; - poBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, databuffer, cols_count, rows_count, GDT_CFloat64, 0, 0); + poBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, databuffer, cols_count, + rows_count, GDT_CFloat64, 0, 0); GDALClose((GDALDatasetH)poDataset); Eigen::MatrixXcd rasterData(nYSize, nXSize); // 使用Eigen的MatrixXcd - for (size_t i = 0; i < nYSize; i++) - { - for (size_t j = 0; j < nXSize; j++) { - rasterData(i, j) = std::complex(databuffer[i * nXSize * 2 + j * 2], databuffer[i * nXSize * 2 + j * 2 + 1]); + for(size_t i = 0; i < nYSize; i++) { + for(size_t j = 0; j < nXSize; j++) { + rasterData(i, j) = std::complex(databuffer[i * nXSize * 2 + j * 2], + databuffer[i * nXSize * 2 + j * 2 + 1]); } } delete databuffer; return rasterData; - } void gdalImageComplex::saveImage() { this->saveImage(this->data, this->start_row, this->start_col, this->data_band_ids); + this->savePreViewImage(); +} +void gdalImageComplex::savePreViewImage() +{ + qDebug()<<"void gdalImageComplex::savePreViewImage()"; + Eigen::MatrixXd data_abs = Eigen::MatrixXd::Zero(this->height, this->width); + data_abs = (this->data.array().real().pow(2) + this->data.array().imag().pow(2)) + .array() + .log10()*10.0; // 计算振幅 + + double min_abs = data_abs.minCoeff(); // 最大值 + double max_abs = data_abs.maxCoeff(); // 最小值 + double delta = (max_abs - min_abs) / 1000; // 1000分位档 + Eigen::MatrixX data_idx = + ((data_abs.array() - min_abs).array() / delta).array().floor().cast(); + + // 初始化 + double hist[1001]; + for(size_t i = 0; i < 1001; i++) { + hist[i] = 0; // 初始化 + } + for(size_t i = 0; i < this->height; i++) { + for(size_t j = 0; j < this->width; j++) { + hist[data_idx(i, j)]++; + } + } + + // 统计 + size_t count = this->height * this->width; + double precent = 0; + size_t curCount = 0; + double pre2 = 0; + bool findprec_2 = true; + double pre98 = 0; + bool findprec_98 = true; + for(size_t i = 0; i < 1001; i++) { + precent = precent + hist[i]; + if(findprec_2 & precent / count > 0.02) { + pre2 = i * delta + min_abs; + findprec_2 = false; + } + if(findprec_98 & precent / count > 0.98) { + pre98 = (i-1) * delta + min_abs; + findprec_98 = false; + } + } + // 拉伸 + delta = (pre98-pre2)/200; + data_idx= + ((data_abs.array() - pre2).array() / delta).array().floor().cast(); + + for(size_t i = 0; i < this->height; i++) { + for(size_t j = 0; j < this->width; j++) { + if(data_idx(i,j)<0){ + data_idx(i,j)=0; + } + else if(data_idx(i,j)>255){ + data_idx(i,j)=255; + }else{ + + } + } + } + + // 赋值 + QString filePath = this->img_path; + QFile file(filePath); + QFileInfo fileInfo(file); + + QString directory = fileInfo.absolutePath(); + qDebug() << "文件所在目录:" << directory; + QString baseName = fileInfo.completeBaseName(); + qDebug() << "无后缀文件名:" << baseName; + + // 创建文件路径 + QString previewImagePath = JoinPath(directory, baseName+"_preview.png"); + cv::Mat img(this->height, this->width, CV_8U ,cv::Scalar(0)); + + for(size_t i = 0; i < this->height; i++) { + for(size_t j = 0; j < this->width; j++) { + img.at(i,j)= (uchar)(data_idx(i,j)); + } + } + //std::string outimgpath=previewImagePath.toUtf8().data(); + cv::imwrite(previewImagePath.toUtf8().data(), img); } \ No newline at end of file diff --git a/src/PluginWBFZExchangePlugin/ImageOperatorBase.h b/src/PluginWBFZExchangePlugin/ImageOperatorBase.h index 67f04df..b5f407c 100644 --- a/src/PluginWBFZExchangePlugin/ImageOperatorBase.h +++ b/src/PluginWBFZExchangePlugin/ImageOperatorBase.h @@ -137,7 +137,7 @@ public: // 方法 void saveImage(Eigen::MatrixXcd data, int start_row, int start_col, int band_ids); Eigen::MatrixXcd getDataComplex(int start_row, int start_col, int rows_count, int cols_count, int band_ids); void saveImage() override; - + void savePreViewImage(); public: Eigen::MatrixXcd data; }; diff --git a/src/PluginWBFZExchangePlugin/LAMPDataShowClass.ui b/src/PluginWBFZExchangePlugin/LAMPDataShowClass.ui index 16aee90..fe4bed6 100644 --- a/src/PluginWBFZExchangePlugin/LAMPDataShowClass.ui +++ b/src/PluginWBFZExchangePlugin/LAMPDataShowClass.ui @@ -19,7 +19,7 @@ - 16 + 14 @@ -27,6 +27,11 @@ fsada + + + 范德萨 + + diff --git a/src/PluginWBFZExchangePlugin/LAMPImageCreateClass.cpp b/src/PluginWBFZExchangePlugin/LAMPImageCreateClass.cpp index 0d07176..a377443 100644 --- a/src/PluginWBFZExchangePlugin/LAMPImageCreateClass.cpp +++ b/src/PluginWBFZExchangePlugin/LAMPImageCreateClass.cpp @@ -100,6 +100,42 @@ void LAMPImageCreateClass::on_pushButton_OK_clicked() { FEKOBase::FEKOImageSettingParams imageparams = this->getFEKOImageSettingParams(); + // 成像前检查 + { + // 检查成像模式 + qDebug()<ui->comboBox_ImageMode->currentText().trimmed()); + FEKOBase::FEKOImageMode imgmode=FEKOBase::FEKOImageModeString2Enum(this->ui->comboBox_ImageMode->currentText().trimmed()); + this->simulationparams->imagemode=imgmode; + switch(imgmode){ + case(FEKOBase::FEKOImageMode::Strip):{ + break; + } + case(FEKOBase::FEKOImageMode::Scane):{ + break; + } + case(FEKOBase::FEKOImageMode::ISAR):{ + break; + } + case(FEKOBase::FEKOImageMode::CircleSAR):{ + break; + } + default:{ + QMessageBox::warning(this,"waring","the image mode do not found"); + return; + } + } + if(QFile(this->ui->lineEdit_thetaechopath->text().trimmed()).exists()){}else{ + QMessageBox::warning(this,"waring","the theta ehco data file do not found"); + } + + if(QFile(this->ui->lineEdit_phiechopath->text().trimmed()).exists()){}else{ + QMessageBox::warning(this,"waring","the phi ehco data file do not found"); + } + } + + + + // 计算回波 if (this->ui->checkBoxTheta->isChecked()) { // theta @@ -110,11 +146,11 @@ void LAMPImageCreateClass::on_pushButton_OK_clicked() qDebug()<<"theta EchoData loading start !!! EchoData File : "<simulationparams&&(this->simulationparams->imagemode==FEKOBase::FEKOImageMode::Strip|| this->simulationparams->imagemode == FEKOBase::FEKOImageMode::Scane)) { + if ( (this->simulationparams->imagemode==FEKOBase::FEKOImageMode::Strip|| this->simulationparams->imagemode == FEKOBase::FEKOImageMode::Scane)) { FEKOBase::FEKOImageProcess(data, imageparams, theta_tiff_filepath,FEKOBase::FEKOImageAlgorithm::TBP_FREQ,FEKOBase::ImageAlgWindowFun::HANMMING); } else { - FEKOBase::FEKOImageProcess(data, imageparams, theta_tiff_filepath,FEKOBase::FEKOImageAlgorithm::TBP_FREQ); + FEKOBase::FEKOImageProcess(data, imageparams, theta_tiff_filepath,FEKOBase::FEKOImageAlgorithm::TBP_CIRCLESAR,FEKOBase::ImageAlgWindowFun::UNKONWWINDOW); } } else { @@ -131,18 +167,25 @@ void LAMPImageCreateClass::on_pushButton_OK_clicked() data.loadEchoData(phifileptah); qDebug()<<"phi EchoData loading finish !!! EchoData File : "<simulationparams && (this->simulationparams->imagemode == FEKOBase::FEKOImageMode::Strip || this->simulationparams->imagemode == FEKOBase::FEKOImageMode::Scane)) { - FEKOBase::FEKOImageProcess(data, imageparams, phi_tiff_filepath, FEKOBase::FEKOImageAlgorithm::TBP_FREQ, FEKOBase::ImageAlgWindowFun::HANMMING); - } - else if(this->simulationparams->imagemode == FEKOBase::FEKOImageMode::ISAR){ - FEKOBase::FEKOImageProcess(data, imageparams, phi_tiff_filepath,FEKOBase::FEKOImageAlgorithm::FAR_ISAR); - }else if(this->simulationparams->imagemode == FEKOBase::FEKOImageMode::CircleSAR){ - FEKOBase::FEKOImageProcess(data, imageparams, phi_tiff_filepath,FEKOBase::FEKOImageAlgorithm::TBP_CIRCLESAR,FEKOBase::ImageAlgWindowFun::HANMMING1AXIS); + if ( (this->simulationparams->imagemode==FEKOBase::FEKOImageMode::Strip|| this->simulationparams->imagemode == FEKOBase::FEKOImageMode::Scane)) { + FEKOBase::FEKOImageProcess(data, imageparams, phi_tiff_filepath,FEKOBase::FEKOImageAlgorithm::TBP_FREQ,FEKOBase::ImageAlgWindowFun::HANMMING); } else { - FEKOBase::FEKOImageProcess(data, imageparams, phi_tiff_filepath,FEKOBase::FEKOImageAlgorithm::TBP_FREQ); + FEKOBase::FEKOImageProcess(data, imageparams, phi_tiff_filepath,FEKOBase::FEKOImageAlgorithm::TBP_CIRCLESAR,FEKOBase::ImageAlgWindowFun::UNKONWWINDOW); } + +// if ( (this->simulationparams->imagemode == FEKOBase::FEKOImageMode::Strip || this->simulationparams->imagemode == FEKOBase::FEKOImageMode::Scane)) { +// FEKOBase::FEKOImageProcess(data, imageparams, phi_tiff_filepath, FEKOBase::FEKOImageAlgorithm::TBP_FREQ, FEKOBase::ImageAlgWindowFun::HANMMING); +// } +// else if(this->simulationparams->imagemode == FEKOBase::FEKOImageMode::ISAR){ +// FEKOBase::FEKOImageProcess(data, imageparams, phi_tiff_filepath,FEKOBase::FEKOImageAlgorithm::FAR_ISAR); +// }else if(this->simulationparams->imagemode == FEKOBase::FEKOImageMode::CircleSAR){ +// FEKOBase::FEKOImageProcess(data, imageparams, phi_tiff_filepath,FEKOBase::FEKOImageAlgorithm::TBP_CIRCLESAR,FEKOBase::ImageAlgWindowFun::UNKONWWINDOW); +// } +// else { +// FEKOBase::FEKOImageProcess(data, imageparams, phi_tiff_filepath,FEKOBase::FEKOImageAlgorithm::TBP_FREQ); +// } } else {