diff --git a/BaseCommonLibrary/BaseTool/BaseTool.h b/BaseCommonLibrary/BaseTool/BaseTool.h index 1122331..bbed5a7 100644 --- a/BaseCommonLibrary/BaseTool/BaseTool.h +++ b/BaseCommonLibrary/BaseTool/BaseTool.h @@ -130,6 +130,8 @@ void initializeMatrixWithSSE2(Eigen::MatrixXd& mat, const double* data, long row void initializeMatrixWithSSE2(Eigen::MatrixXf& mat, const float* data, long rowcount, long colcount); + + /** 模板函数类 ***********************************************************************************************************/ template inline void memsetInitArray(std::shared_ptr ptr, long arrcount,T ti) { @@ -172,4 +174,25 @@ inline void maxValueInArr(T* ptr, long arrcount, T& maxvalue) { } } + + +/** 常用SAR工具 ***********************************************************************************************************/ + + +template +inline T complexAbs(std::complex ccdata) { + return T(sqrt(pow(ccdata.real(), 2) + pow(ccdata.imag(), 2))); +} + +template +inline void complex2dB(std::complex* ccdata, T* outdata, long long count) { + + for (long long i = 0; i < count; i++) { + outdata[i] = 20 * log10(complexAbs(ccdata[i])); + } + +} + + + #endif \ No newline at end of file diff --git a/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp b/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp index aa65d70..dab330b 100644 --- a/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp +++ b/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp @@ -632,8 +632,6 @@ ErrorCode EchoL0Dataset::saveEchoArr(std::shared_ptr> echoP GDALAllRegister(); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen(this->echoDataFilePath.toUtf8().constData(), GDALAccess::GA_Update)); - - GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); GDALRasterBand* poBand = rasterDataset->GetRasterBand(1); @@ -670,4 +668,69 @@ ErrorCode EchoL0Dataset::saveEchoArr(std::shared_ptr> echoP omp_destroy_lock(&lock); // return ErrorCode::SUCCESS; } - \ No newline at end of file + +std::shared_ptr SatelliteAntPosOperator::readAntPosFile(QString filepath, long& count) +{ + gdalImage antimg(filepath); + long rowcount = count; + long colcount = 19; + std::shared_ptr antlist = readDataArr(antimg, 0, 0, rowcount, colcount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr antpos(new SatelliteAntPos[rowcount], delArrPtr); + for (long i = 0; i < colcount; i++) { + antpos.get()[i].time = antlist.get()[i * 19 + 1]; + antpos.get()[i].Px = antlist.get()[i * 19 + 2]; + antpos.get()[i].Py = antlist.get()[i * 19 + 3]; + antpos.get()[i].Pz = antlist.get()[i * 19 + 4]; + antpos.get()[i].Vx = antlist.get()[i * 19 + 5]; + antpos.get()[i].Vy = antlist.get()[i * 19 + 6]; + antpos.get()[i].Vz = antlist.get()[i * 19 + 7]; //7 + antpos.get()[i].AntDirectX = antlist.get()[i * 19 + 8]; + antpos.get()[i].AntDirectY = antlist.get()[i * 19 + 9]; + antpos.get()[i].AntDirectZ = antlist.get()[i * 19 + 10]; + antpos.get()[i].AVx = antlist.get()[i * 19 + 11]; + antpos.get()[i].AVy = antlist.get()[i * 19 + 12]; + antpos.get()[i].AVz = antlist.get()[i * 19 + 13]; + antpos.get()[i].ZeroAntDiectX = antlist.get()[i * 19 + 14]; + antpos.get()[i].ZeroAntDiectY = antlist.get()[i * 19 + 15]; + antpos.get()[i].ZeroAntDiectZ = antlist.get()[i * 19 + 16]; + antpos.get()[i].lon = antlist.get()[i * 19 + 17]; + antpos.get()[i].lat = antlist.get()[i * 19 + 18]; + antpos.get()[i].ati = antlist.get()[i * 19 + 19]; // 19 + } + return antpos; +} + +void SatelliteAntPosOperator::writeAntPosFile(QString filepath, std::shared_ptr data, const long count) +{ + gdalImage antimg=CreategdalImageDouble(filepath,count,19,1,true,true); + long rowcount = count; + long colcount = 19; + std::shared_ptr antpos(new double[rowcount*19], delArrPtr); + for (long i = 0; i < colcount; i++) { + antpos.get()[i * 19 + 1] = data.get()[i].time; + antpos.get()[i * 19 + 2] = data.get()[i].Px; + antpos.get()[i * 19 + 3] = data.get()[i].Py; + antpos.get()[i * 19 + 4] = data.get()[i].Pz; + antpos.get()[i * 19 + 5] = data.get()[i].Vx; + antpos.get()[i * 19 + 6] = data.get()[i].Vy; + antpos.get()[i * 19 + 7] = data.get()[i].Vz; + antpos.get()[i * 19 + 8] = data.get()[i].AntDirectX; + antpos.get()[i * 19 + 9] = data.get()[i].AntDirectY; + antpos.get()[i * 19 + 10] = data.get()[i].AntDirectZ; + antpos.get()[i * 19 + 11] = data.get()[i].AVx; + antpos.get()[i * 19 + 12] = data.get()[i].AVy; + antpos.get()[i * 19 + 13] = data.get()[i].AVz; + antpos.get()[i * 19 + 14] = data.get()[i].ZeroAntDiectX; + antpos.get()[i * 19 + 15] = data.get()[i].ZeroAntDiectY; + antpos.get()[i * 19 + 16] = data.get()[i].ZeroAntDiectZ; + antpos.get()[i * 19 + 17] = data.get()[i].lon; + antpos.get()[i * 19 + 18] = data.get()[i].lat; + antpos.get()[i * 19 + 19] = data.get()[i].ati; + } + antimg.saveImage(antpos, 0,0,rowcount, colcount, 1); + + return ; + + + +} diff --git a/BaseCommonLibrary/BaseTool/EchoDataFormat.h b/BaseCommonLibrary/BaseTool/EchoDataFormat.h index 1c7c486..49fea34 100644 --- a/BaseCommonLibrary/BaseTool/EchoDataFormat.h +++ b/BaseCommonLibrary/BaseTool/EchoDataFormat.h @@ -92,6 +92,31 @@ struct PluseAntPos { std::shared_ptr BASECONSTVARIABLEAPI CreatePluseAntPosArr(long pluseCount); +class BASECONSTVARIABLEAPI SatelliteAntPosOperator { +public: + static std::shared_ptr readAntPosFile(QString filepath,long& count); + static void writeAntPosFile(QString filepath, std::shared_ptr< SatelliteAntPos> data,const long count); + + +}; + + + + + + + + + + + + + + + + + + // L0 class BASECONSTVARIABLEAPI EchoL0Dataset { diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp index 10acd52..b3c419e 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp @@ -477,7 +477,7 @@ gdalImage::gdalImage(const QString& raster_path) rasterDataset = NULL; // 指矫匡拷 this->InitInv_gt(); delete[] gt; - ////GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH omp_unset_lock(&lock); // 锟酵放伙拷斤拷 omp_destroy_lock(&lock); // 劫伙拷斤拷 } @@ -624,7 +624,7 @@ Eigen::MatrixXd gdalImage::getData(int start_row, int start_col, int rows_count, GDALClose((GDALDatasetH)rasterDataset); omp_unset_lock(&lock); // 锟酵放伙拷斤拷 omp_destroy_lock(&lock); // 劫伙拷斤拷 - // GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH return datamatrix; } @@ -753,7 +753,7 @@ Eigen::MatrixXf gdalImage::getDataf(int start_row, int start_col, int rows_count GDALClose((GDALDatasetH)rasterDataset); omp_unset_lock(&lock); // 锟酵放伙拷斤拷 omp_destroy_lock(&lock); // 劫伙拷斤拷 - // GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH return datamatrix; } @@ -882,7 +882,7 @@ Eigen::MatrixXi gdalImage::getDatai(int start_row, int start_col, int rows_count GDALClose((GDALDatasetH)rasterDataset); omp_unset_lock(&lock); // 锟酵放伙拷斤拷 omp_destroy_lock(&lock); // 劫伙拷斤拷 - // GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH return datamatrix; } @@ -1039,7 +1039,7 @@ void gdalImage::saveImage(Eigen::MatrixXd data, int start_row = 0, int start_col } 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); // 劫伙拷斤拷 @@ -1120,7 +1120,7 @@ void gdalImage::saveImage(Eigen::MatrixXf data, int start_row = 0, int start_col } 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); // 劫伙拷斤拷 @@ -1179,7 +1179,7 @@ void gdalImage::saveImage(Eigen::MatrixXi data, int start_row, int start_col, in 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); // 劫伙拷斤拷 @@ -1240,7 +1240,7 @@ void gdalImage::saveImage(std::shared_ptr data, int start_row, int start 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); // 劫伙拷斤拷 @@ -1303,7 +1303,7 @@ void gdalImage::saveImage(std::shared_ptr data, int start_row, int start_ GDALClose((GDALDatasetH)poDstDS); //delete poDstDS; //poDstDS = nullptr; - // GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH delete[] databuffer; omp_unset_lock(&lock); // 锟酵放伙拷斤拷 omp_destroy_lock(&lock); // 劫伙拷斤拷 @@ -1365,7 +1365,7 @@ void gdalImage::saveImage(std::shared_ptr data, int start_row, int start_co 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); // 劫伙拷斤拷 @@ -1642,6 +1642,39 @@ RasterExtend gdalImage::getExtend() return extend; } +gdalImage BASECONSTVARIABLEAPI CreategdalImageDouble(QString& img_path, int height, int width, int band_num, bool overwrite, bool isEnvi) +{ + + if (exists_test(img_path.toUtf8().constData())) { + if (overwrite) { + gdalImage result_img(img_path); + return result_img; + } + else { + throw "file has exist!!!"; + exit(1); + } + } + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注锟斤拷锟绞斤拷锟斤拷锟斤拷锟?1锟?7 + GDALDriver* poDriver = nullptr; + if (isEnvi) { + poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); + } + else { + poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + } + + + GDALDataset* poDstDS = poDriver->Create(img_path.toUtf8().constData(), width, height, band_num,GDT_Float64, NULL); // 锟斤拷锟斤拷锟斤拷 + GDALFlushCache((GDALDatasetH)poDstDS); + GDALClose((GDALDatasetH)poDstDS); + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + gdalImage result_img(img_path); + return result_img; + +} + gdalImage CreategdalImageDouble(const QString& img_path, int height, int width, int band_num, Eigen::MatrixXd gt, QString projection, bool need_gt, bool overwrite, bool isEnvi) { if (exists_test(img_path.toUtf8().constData())) { @@ -1684,7 +1717,7 @@ gdalImage CreategdalImageDouble(const QString& img_path, int height, int width, } GDALFlushCache((GDALDatasetH)poDstDS); GDALClose((GDALDatasetH)poDstDS); - ////GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH gdalImage result_img(img_path); return result_img; } @@ -1731,7 +1764,7 @@ gdalImage CreategdalImage(const QString& img_path, int height, int width, int ba } GDALFlushCache((GDALDatasetH)poDstDS); GDALClose((GDALDatasetH)poDstDS); - ////GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH gdalImage result_img(img_path); return result_img; } @@ -1777,7 +1810,7 @@ gdalImage CreategdalImage(const QString& img_path, int height, int width, int ba } GDALFlushCache((GDALDatasetH)poDstDS); GDALClose((GDALDatasetH)poDstDS); - ////GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH gdalImage result_img(img_path); return result_img; } @@ -1817,7 +1850,7 @@ gdalImageComplex CreategdalImageComplex(const QString& img_path, int height, int //} GDALFlushCache((GDALDatasetH)poDstDS); GDALClose((GDALDatasetH)poDstDS); - ////GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH gdalImageComplex result_img(img_path); return result_img; } @@ -1962,7 +1995,7 @@ int ResampleGDAL(const char* pszSrcFile, const char* pszOutFile, double* gt, int // GDALDestroyWarpOptions(psWo); GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); - ////GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH return 0; } @@ -2551,7 +2584,7 @@ gdalImageComplex::gdalImageComplex(const QString& raster_path) rasterDataset = NULL; // 指矫匡拷 this->InitInv_gt(); delete[] gt; - ////GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH omp_unset_lock(&lock); // 锟酵放伙拷斤拷 omp_destroy_lock(&lock); // 劫伙拷斤拷 } @@ -2615,7 +2648,7 @@ void gdalImageComplex::saveImage(Eigen::MatrixXcd data, int start_row, int start GDALFlushCache(poDstDS); delete databuffer; GDALClose((GDALDatasetH)poDstDS); - // GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH omp_unset_lock(&lock); // omp_destroy_lock(&lock); // } @@ -2668,12 +2701,65 @@ void gdalImageComplex::saveImage(std::shared_ptr> data, lon GDALFlushCache(poDstDS); delete databuffer; GDALClose((GDALDatasetH)poDstDS); - // GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH omp_unset_lock(&lock); // omp_destroy_lock(&lock); // } +void gdalImageComplex::saveImage(std::complex* data, long start_row, long start_col, long rowCount, long colCount, int band_ids) +{ + omp_lock_t lock; + omp_init_lock(&lock); + omp_set_lock(&lock); + if (start_row + rowCount > this->height || start_col + colCount > this->width) { + QString tip = u8"file path: " + this->img_path; + qDebug() << tip; + throw std::exception(tip.toUtf8().constData()); + return; + } + GDALAllRegister(); + 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); // 斤拷锟斤拷 + 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++) { + gt_ptr[i * 3 + j] = this->gt(i, j); + } + } + poDstDS->SetGeoTransform(gt_ptr); + //delete[] gt_ptr; + } + + double* databuffer = new double[rowCount * colCount * 2]; + for (long i = 0; i < rowCount; i++) { + for (long j = 0; j < colCount; j++) { + databuffer[i * colCount * 2 + j * 2] = data[i * colCount + j].real(); + databuffer[i * colCount * 2 + j * 2 + 1] = data[i * colCount + 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, colCount, rowCount, + databuffer, colCount, rowCount, 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); // +} + Eigen::MatrixXcd gdalImageComplex::getDataComplex(int start_row, int start_col, int rows_count, int cols_count, int band_ids) { @@ -3525,6 +3611,29 @@ void testOutClsArr(QString filename, long* amp, long rowcount, long colcount) { } +void BASECONSTVARIABLEAPI testOutComplexDoubleArr(QString filename, std::complex* data, long rowcount, long colcount) +{ + gdalImageComplex compleximg= CreateEchoComplex(filename, rowcount, colcount, 1); + compleximg.saveImage( data, 0, 0, rowcount, colcount, 1); + + return void BASECONSTVARIABLEAPI(); +} + +void BASECONSTVARIABLEAPI testOutDataArr(QString filename, double* data, long rowcount, long colcount) +{ + return testOutAmpArr(filename, data, rowcount, colcount); +} + +void BASECONSTVARIABLEAPI testOutDataArr(QString filename, float* data, long rowcount, long colcount) +{ + return testOutAmpArr(filename, data, rowcount, colcount); +} + +void BASECONSTVARIABLEAPI testOutDataArr(QString filename, long* data, long rowcount, long colcount) +{ + return testOutClsArr(filename,data,rowcount,colcount); +} + void testOutAntPatternTrans(QString antpatternfilename, double* antPatternArr, double starttheta, double deltetheta, double startphi, double deltaphi, @@ -3905,7 +4014,7 @@ void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QStr GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); GDALClose((GDALDatasetH)(GDALDatasetH)pDRef); - ////GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH return ; } diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h index 3e15a58..b0f33ab 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h @@ -229,6 +229,8 @@ public: // 方法 void setData(Eigen::MatrixXcd); void saveImage(Eigen::MatrixXcd data, int start_row, int start_col, int band_ids); void saveImage(std::shared_ptr> data, long start_row, long start_col, long rowCount, long colCount, int band_ids); + void saveImage(std::complex* data, long start_row, long start_col, long rowcount, long colcount, int banids); + Eigen::MatrixXcd getDataComplex(int start_row, int start_col, int rows_count, int cols_count, int band_ids); std::shared_ptr> getDataComplexSharePtr(int start_row, int start_col, int rows_count, int cols_count, int band_ids); @@ -239,6 +241,7 @@ public: }; // 创建影像 +gdalImage BASECONSTVARIABLEAPI CreategdalImageDouble(QString& img_path, int height, int width, int band_num, bool overwrite = false, bool isEnvi = false); gdalImage BASECONSTVARIABLEAPI CreategdalImageDouble(const QString& img_path, int height, int width, int band_num, Eigen::MatrixXd gt, QString projection, bool need_gt = true, bool overwrite = false, bool isEnvi = false); gdalImage BASECONSTVARIABLEAPI CreategdalImage(const QString& img_path, int height, int width, int band_num, Eigen::MatrixXd gt, QString projection,bool need_gt = true, bool overwrite = false, bool isEnvi = false, GDALDataType datetype = GDT_Float32); @@ -301,8 +304,12 @@ bool BASECONSTVARIABLEAPI saveEigenMatrixXd2Bin(Eigen::MatrixXd data, QString void BASECONSTVARIABLEAPI testOutAntPatternTrans(QString antpatternfilename, double* antPatternArr, double starttheta, double deltetheta, double startphi, double deltaphi, long thetanum, long phinum); void BASECONSTVARIABLEAPI testOutAmpArr(QString filename, float* amp, long rowcount, long colcount); void BASECONSTVARIABLEAPI testOutAmpArr(QString filename, double* amp, long rowcount, long colcount); - -void BASECONSTVARIABLEAPI testOutClsArr(QString filename, long* amp, long rowcount, long colcount); +void BASECONSTVARIABLEAPI testOutClsArr(QString filename, long* amp, long rowcount, long colcount); +void BASECONSTVARIABLEAPI testOutComplexDoubleArr(QString filename, std::complex* data, long rowcount, long colcount); +void BASECONSTVARIABLEAPI testOutDataArr(QString filename, double* data, long rowcount, long colcount); +void BASECONSTVARIABLEAPI testOutDataArr(QString filename, float* data, long rowcount, long colcount); +void BASECONSTVARIABLEAPI testOutDataArr(QString filename, long* data, long rowcount, long colcount); + void BASECONSTVARIABLEAPI CreateSARIntensityByLookTable(QString IntensityRasterPath, QString LookTableRasterPath, QString SARIntensityPath, long min_rid, long max_rid, long min_cid, long max_cid, std::function processBarShow = {}); @@ -504,7 +511,7 @@ inline std::shared_ptr readDataArr(gdalImage& imgds, long start_row, long sta GDALClose((GDALDatasetH)rasterDataset); omp_unset_lock(&lock); // 锟酵放伙拷斤拷 omp_destroy_lock(&lock); // 劫伙拷斤拷 - // GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH return result; } @@ -577,7 +584,7 @@ inline std::shared_ptr readDataArrComplex(gdalImageComplex& imgds, long start GDALClose((GDALDatasetH)rasterDataset); omp_unset_lock(&lock); // 锟酵放伙拷斤拷 omp_destroy_lock(&lock); // 劫伙拷斤拷 - // GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH return result; } diff --git a/GPUBPSimulation/GPUBPSimulation.vcxproj b/GPUBPSimulation/GPUBPSimulation.vcxproj new file mode 100644 index 0000000..7f3357b --- /dev/null +++ b/GPUBPSimulation/GPUBPSimulation.vcxproj @@ -0,0 +1,104 @@ + + + + + Debug + x64 + + + Release + x64 + + + + 9233788c-bd43-41aa-b157-d77e92616d00 + GPUBPSimulation + + + + Application + true + MultiByte + + + + + + + + + v143 + + + + Application + false + true + MultiByte + + + + + + + + + v143 + + + + + + + + + + + + + + + true + + + + Level3 + Disabled + WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + true + Console + cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + 64 + + + + + Level3 + MaxSpeed + true + true + WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + true + true + true + Console + cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + 64 + + + + + + + + + + diff --git a/GPUBPSimulation/kernel.cu b/GPUBPSimulation/kernel.cu new file mode 100644 index 0000000..d2b1cf0 --- /dev/null +++ b/GPUBPSimulation/kernel.cu @@ -0,0 +1,121 @@ + +#include "cuda_runtime.h" +#include "device_launch_parameters.h" + +#include + +cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size); + +__global__ void addKernel(int *c, const int *a, const int *b) +{ + int i = threadIdx.x; + c[i] = a[i] + b[i]; +} + +int main() +{ + const int arraySize = 5; + const int a[arraySize] = { 1, 2, 3, 4, 5 }; + const int b[arraySize] = { 10, 20, 30, 40, 50 }; + int c[arraySize] = { 0 }; + + // Add vectors in parallel. + cudaError_t cudaStatus = addWithCuda(c, a, b, arraySize); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "addWithCuda failed!"); + return 1; + } + + printf("{1,2,3,4,5} + {10,20,30,40,50} = {%d,%d,%d,%d,%d}\n", + c[0], c[1], c[2], c[3], c[4]); + + // cudaDeviceReset must be called before exiting in order for profiling and + // tracing tools such as Nsight and Visual Profiler to show complete traces. + cudaStatus = cudaDeviceReset(); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "cudaDeviceReset failed!"); + return 1; + } + + return 0; +} + +// Helper function for using CUDA to add vectors in parallel. +cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size) +{ + int *dev_a = 0; + int *dev_b = 0; + int *dev_c = 0; + cudaError_t cudaStatus; + + // Choose which GPU to run on, change this on a multi-GPU system. + cudaStatus = cudaSetDevice(0); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "cudaSetDevice failed! Do you have a CUDA-capable GPU installed?"); + goto Error; + } + + // Allocate GPU buffers for three vectors (two input, one output) . + cudaStatus = cudaMalloc((void**)&dev_c, size * sizeof(int)); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "cudaMalloc failed!"); + goto Error; + } + + cudaStatus = cudaMalloc((void**)&dev_a, size * sizeof(int)); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "cudaMalloc failed!"); + goto Error; + } + + cudaStatus = cudaMalloc((void**)&dev_b, size * sizeof(int)); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "cudaMalloc failed!"); + goto Error; + } + + // Copy input vectors from host memory to GPU buffers. + cudaStatus = cudaMemcpy(dev_a, a, size * sizeof(int), cudaMemcpyHostToDevice); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "cudaMemcpy failed!"); + goto Error; + } + + cudaStatus = cudaMemcpy(dev_b, b, size * sizeof(int), cudaMemcpyHostToDevice); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "cudaMemcpy failed!"); + goto Error; + } + + // Launch a kernel on the GPU with one thread for each element. + addKernel<<<1, size>>>(dev_c, dev_a, dev_b); + + // Check for any errors launching the kernel + cudaStatus = cudaGetLastError(); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "addKernel launch failed: %s\n", cudaGetErrorString(cudaStatus)); + goto Error; + } + + // cudaDeviceSynchronize waits for the kernel to finish, and returns + // any errors encountered during the launch. + cudaStatus = cudaDeviceSynchronize(); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus); + goto Error; + } + + // Copy output vector from GPU buffer to host memory. + cudaStatus = cudaMemcpy(c, dev_c, size * sizeof(int), cudaMemcpyDeviceToHost); + if (cudaStatus != cudaSuccess) { + fprintf(stderr, "cudaMemcpy failed!"); + goto Error; + } + +Error: + cudaFree(dev_c); + cudaFree(dev_a); + cudaFree(dev_b); + + return cudaStatus; +} diff --git a/GPUBaseLib/GPUTool/GPUTool.cu b/GPUBaseLib/GPUTool/GPUTool.cu index 568f50e..be15ded 100644 --- a/GPUBaseLib/GPUTool/GPUTool.cu +++ b/GPUBaseLib/GPUTool/GPUTool.cu @@ -571,6 +571,7 @@ long NextBlockPad(long num, long blocksize) void PrintLasterError(const char* s) { + cudaDeviceSynchronize(); cudaError_t err = cudaGetLastError(); if (err != cudaSuccess) { //printf("%s: %s\n", s, cudaGetErrorString(err)); diff --git a/Toolbox/SimulationSARTool/GPUBpSimulation.cu b/Toolbox/SimulationSARTool/GPUBpSimulation.cu new file mode 100644 index 0000000..d92436c --- /dev/null +++ b/Toolbox/SimulationSARTool/GPUBpSimulation.cu @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "BaseConstVariable.h" +#include "GPUTool.cuh" +#include "GPUBPTool.cuh" +#include "BPBasic0_CUDA.cuh" +#include "GPUBpSimulation.cuh" +#include "GPURFPC.cuh" + + + +double* getFreqPoints_mallocHost(double startFreq, double endFreq, long freqpoints) +{ + long double dfreq = (endFreq - startFreq) / (freqpoints - 1); + double* freqlist = (double*)mallocCUDAHost(sizeof(double) * freqpoints); + for (long i = 0; i < freqpoints; i++) { + freqlist[i] = startFreq + dfreq * i; + } + return freqlist; +} + +cuComplex* createEchoPhase_mallocHost(long Np, long Nf) +{ + cuComplex* phdata = (cuComplex*)mallocCUDAHost(sizeof(cuComplex) * Np * Nf); + for (long i = 0; i < Np; i++) { + for (long j = 0; j < Nf; j++) { + phdata[i * Nf + j] = make_cuComplex(0, 0); + } + } + return phdata; +} + + +__global__ void kernel_RFPCProcess( + double* Sx,double* Sy,double* Sz, + double Tx, double Ty,double Tz, + double Tslx,double Tsly,double Tslz, // Ŀ + double p1,double p2, double p3, double p4, double p5, double p6, + long Np,long Nf, + double minF,double dFreq,double RefRange, + cuComplex* phdata +) { + //long prfid = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ + //if (prfid >= Np || prfid < 0) { return; } + //else {} + + //// + //Vector3 S{ Sx[prfid],Sy[prfid],Sz[prfid] }; + //Vector3 T{ Tx,Ty,Tz }; + //Vector3 slp{ Tslx,Tsly,Tslz }; + + //// + //Vector3 TS = vec_sub(S, T);//T-->S + //double localIncAngle = angleBetweenVectors(TS, slp, false);// + //double sigma0 = GPU_getSigma0dB(p1, p2, p3, p4, p5, p6, localIncAngle);// ɢϵ + //sigma0 = powf(10.0, sigma0 / 10.0); + + //// + //double R = sqrt(vec_dot(TS, TS)); + + //// + //double amp_echo = sigma0 / (powf(4 * LAMP_CUDA_PI, 2) * powf(R, 4)); // ǿ + //double phi = 0; + //for (long fid = 0; fid < Nf; fid++) { + // phi = 4.0 * PI / LIGHTSPEED * (minF + dFreq * fid) * (R - RefRange); + // phdata[prfid * Nf + fid].x += amp_echo * cos(phi); + // phdata[prfid * Nf + fid].y += amp_echo * sin(phi); + //} +} + + +void RFPCProcess(double Tx, double Ty, double Tz, + double Tslx, double Tsly, double Tslz, // Ŀ + double p1, double p2, double p3, double p4, double p5, double p6, + GPUDATA& d_data) +{ + + + double* AntX = (double*)mallocCUDADevice(sizeof(double) * d_data.Np); + double* AntY = (double*)mallocCUDADevice(sizeof(double) * d_data.Np); + double* AntZ = (double*)mallocCUDADevice(sizeof(double) * d_data.Np); + + HostToDevice(d_data.AntX, AntX, sizeof(double) * d_data.Np); + HostToDevice(d_data.AntY, AntY, sizeof(double) * d_data.Np); + HostToDevice(d_data.AntZ, AntZ, sizeof(double) * d_data.Np); + double minF = d_data.minF[0]; + long grid_size = (d_data.Np + BLOCK_SIZE - 1) / BLOCK_SIZE; + double dfreq = d_data.deltaF; + double R0 = d_data.R0; + kernel_RFPCProcess<<>>( + AntX, AntY, AntZ, + Tx, Ty, Tz, + Tslx, Tsly, Tslz, // Ŀ + p1, p2, p3, p4, p5, p6, + d_data.Np, d_data.Nfft, + minF, dfreq,R0, + d_data.phdata + ); + + PrintLasterError("RFPCProcess"); + FreeCUDADevice(AntX); + FreeCUDADevice(AntY); + FreeCUDADevice(AntZ); + + return ; +} + + + diff --git a/Toolbox/SimulationSARTool/GPUBpSimulation.cuh b/Toolbox/SimulationSARTool/GPUBpSimulation.cuh new file mode 100644 index 0000000..a2a560c --- /dev/null +++ b/Toolbox/SimulationSARTool/GPUBpSimulation.cuh @@ -0,0 +1,35 @@ +/*****************************************************************//** + * \file GPUBpSimulation.cuh + * \brief GPUľֲ + * + * \author 30453 + * \date March 2025 + *********************************************************************/ +#ifndef _GPUBPSIMUALTION_CUDA_H_ +#define _GPUBPSIMUALTION_CUDA_H_ +#include "BaseConstVariable.h" +#include "GPUTool.cuh" +#include +#include +#include +#include +#include "GPUTool.cuh" +#include "BPBasic0_CUDA.cuh" + + + + + +extern "C" double* getFreqPoints_mallocHost(double startFreq, double endFreq, long freqpoints); +extern "C" cuComplex* createEchoPhase_mallocHost(long Np, long Nf); + +extern "C" void RFPCProcess( + double Tx, double Ty, double Tz, // Ŀ + double Tslx,double Tsly,double Tslz, // Ŀ + double p1, double p2, double p3, double p4, double p5, double p6,// Ŀɢϵǹϵ ϵ + GPUDATA& d_data + ); + + + +#endif \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu index 95b4778..4c0d849 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu @@ -21,7 +21,7 @@ #include "GPUBPTool.cuh" #include "BPBasic0_CUDA.cuh" - +#define c LIGHTSPEED __global__ void phaseCompensationKernel(cufftComplex* phdata, const double* Freq, double r, int K, int Na) { int freqIdx = blockIdx.x * blockDim.x + threadIdx.x; @@ -141,7 +141,7 @@ void bpBasic0CUDA(GPUDATA& data, int flag,double* h_R) { dim3 block(16, 16); dim3 grid((data.K + 15) / 16, (data.Np + 15) / 16); phaseCompensationKernel << > > (data.phdata, data.Freq, data.R0, data.K, data.Np); - cudaCheckError(cudaDeviceSynchronize()); + PrintLasterError("bpBasic0CUDA Phase compensation"); //data.R0 = data.r; // data.rȷ } @@ -155,7 +155,7 @@ void bpBasic0CUDA(GPUDATA& data, int flag,double* h_R) { dim3 blockShift(256); dim3 gridShift((data.Np + 255) / 256); fftshiftKernel << > > (data.phdata, data.Nfft, data.Np); - cudaCheckError(cudaDeviceSynchronize()); + PrintLasterError("bpBasic0CUDA Phase FFT Process"); printf("fft finished!!\n"); // ͼؽ @@ -172,7 +172,6 @@ void bpBasic0CUDA(GPUDATA& data, int flag,double* h_R) { printf("r_start=%e;dr=%e;nR=%d\n", r_start, dr, data.Nfft); printf("BPimage .....\n"); for (long ii = 0; ii < data.Np; ++ii) { - processPulseKernel << > > ( ii, data.nx, data.ny, @@ -188,24 +187,11 @@ void bpBasic0CUDA(GPUDATA& data, int flag,double* h_R) { if (ii % 1000==0) { printf("\rPRF(%f %) %d / %d\t\t\t\t",(ii*100.0/data.Np), ii,data.Np); } - - - // DeviceToHost(h_R, d_R, sizeof(double) * data.nx * data.ny); - - // double minR = h_R[0], maxR = h_R[0]; - // for (long i = 0; i < data.nx * data.ny; i++) { - // if (minR > h_R[i]) { minR = h_R[i]; } - // if (maxR < h_R[i]) { maxR = h_R[i]; } - // } - - //printf("prfid=%d; R=[ %e , %e ]\n", ii,minR, maxR); - //break; - } //FreeCUDADevice(d_R); - - cudaCheckError(cudaDeviceSynchronize()); + PrintLasterError("bpBasic0CUDA Phase BPimage Process finished!!"); + } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cuh b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cuh index 80c1f14..bfb7e35 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cuh @@ -1,18 +1,21 @@ + +#ifndef _BPBASIC0_CUDA_H_ +#define _BPBASIC0_CUDA_H_ #include #include #include #include #include "BaseConstVariable.h" -#define cudaCheckError(ans) { gpuAssert((ans), __FILE__, __LINE__); } -inline void gpuAssert(cudaError_t code, const char* file, int line) { - if (code != cudaSuccess) { - fprintf(stderr, "CUDA Error: %s %s %d\n", cudaGetErrorString(code), file, line); - exit(code); - } -} - -#define c LIGHTSPEED +//#define cudaCheckError(ans) { gpuAssert((ans), __FILE__, __LINE__); } +//inline void gpuAssert(cudaError_t code, const char* file, int line) { +// if (code != cudaSuccess) { +// fprintf(stderr, "CUDA Error: %s %s %d\n", cudaGetErrorString(code), file, line); +// exit(code); +// } +//} +// +//#define c LIGHTSPEED struct GPUDATA { @@ -35,3 +38,4 @@ extern "C" { void BPBasic0(GPUDATA& h_data); }; +#endif \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPUBPTool.cuh b/Toolbox/SimulationSARTool/SimulationSAR/GPUBPTool.cuh index 78ca36c..c1ef4d3 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPUBPTool.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPUBPTool.cuh @@ -8,15 +8,12 @@ -extern __device__ __host__ double angleBetweenVectors(Vector3 a, Vector3 b, bool returnDegrees = false); +extern __device__ __host__ double angleBetweenVectors(Vector3 a, Vector3 b, bool returnDegrees = false); extern __device__ __host__ Vector3 vec_sub(Vector3 a, Vector3 b); extern __device__ __host__ double vec_dot(Vector3 a, Vector3 b); extern __device__ __host__ Vector3 vec_cross(Vector3 a, Vector3 b); extern __device__ __host__ Vector3 vec_normalize(Vector3 v); -extern __device__ __host__ Vector3 vec_normalize(Vector3 v); extern __device__ __host__ Vector3 compute_T(Vector3 S, Vector3 ray_dir, double H); // extern __device__ __host__ Vector3 compute_P(Vector3 S, Vector3 T, double R, double H ); -// -// diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index 89a0c7a..1045a19 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -19,13 +19,20 @@ /* ****************************************************************************************************************************/ -__device__ double GPU_getSigma0dB(CUDASigmaParam param, double theta) {//ֵ +extern __host__ __device__ double GPU_getSigma0dB(CUDASigmaParam param, double theta) {//ֵ double sigma = param.p1 + param.p2 * exp(-param.p3 * theta) + param.p4 * cos(param.p5 * theta + param.p6); return sigma; } +extern __host__ __device__ double GPU_getSigma0dB( + const double p1, const double p2, const double p3, const double p4, const double p5, const double p6, + double theta) {//ֵ + return p1 + p2 * exp(-p3 * theta) + p4 * cos(p5 * theta + p6); +} -__device__ CUDAVectorEllipsoidal GPU_SatelliteAntDirectNormal( + + +extern __host__ __device__ CUDAVectorEllipsoidal GPU_SatelliteAntDirectNormal( double RstX, double RstY, double RstZ, double AntXaxisX, double AntXaxisY, double AntXaxisZ, double AntYaxisX, double AntYaxisY, double AntYaxisZ, @@ -104,7 +111,7 @@ __device__ CUDAVectorEllipsoidal GPU_SatelliteAntDirectNormal( return result; } -__device__ double GPU_BillerInterpAntPattern(double* antpattern, +extern __host__ __device__ double GPU_BillerInterpAntPattern(double* antpattern, double starttheta, double startphi, double dtheta, double dphi, long thetapoints, long phipoints, double searththeta, double searchphi) { diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh index 50d9f8a..b66a476 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh @@ -22,15 +22,24 @@ extern "C" struct CUDASigmaParam { +extern __host__ __device__ double GPU_getSigma0dB( + const double p1, const double p2, const double p3, const double p4, const double p5, const double p6, + double theta); +extern __host__ __device__ double GPU_getSigma0dB(CUDASigmaParam param, double theta); +extern __host__ __device__ CUDAVectorEllipsoidal GPU_SatelliteAntDirectNormal( + double RstX, double RstY, double RstZ, + double AntXaxisX, double AntXaxisY, double AntXaxisZ, + double AntYaxisX, double AntYaxisY, double AntYaxisZ, + double AntZaxisX, double AntZaxisY, double AntZaxisZ, + double AntDirectX, double AntDirectY, double AntDirectZ +); - - - - - - +extern __host__ __device__ double GPU_BillerInterpAntPattern(double* antpattern, + double starttheta, double startphi, double dtheta, double dphi, + long thetapoints, long phipoints, + double searththeta, double searchphi); diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 4c43bfa..8099c72 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -41,7 +41,7 @@ Unicode - DynamicLibrary + Application v143 false true @@ -182,7 +182,7 @@ true - Windows + Console DebugFull true true @@ -220,8 +220,12 @@ + + + + @@ -234,6 +238,7 @@ + @@ -250,10 +255,6 @@ Document - - Document - - diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index 7a8f1d7..ab6021b 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -62,6 +62,12 @@ SimulationSAR + + SimulationSAR + + + SimulationSAR + @@ -106,6 +112,9 @@ PowerSimulationIncoherent + + Source Files + @@ -163,12 +172,6 @@ SimulationSAR - - SimulationSAR - - - SimulationSAR - PowerSimulationIncoherent @@ -184,5 +187,11 @@ SimulationSAR + + SimulationSAR + + + SimulationSAR + \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/UnitTestMain.cpp b/Toolbox/SimulationSARTool/UnitTestMain.cpp new file mode 100644 index 0000000..35133e0 --- /dev/null +++ b/Toolbox/SimulationSARTool/UnitTestMain.cpp @@ -0,0 +1,141 @@ +/* +* Դ +* +* +*/ +#include +#include + +#include "EchoDataFormat.h" +#include "ImageShowDialogClass.h" +#include "GPUBaseLibAPI.h" +#include "BaseConstVariable.h" +#include "GPUTool.cuh" +#include "GPUBPTool.cuh" +#include "BPBasic0_CUDA.cuh" +#include "ImageOperatorBase.h" +#include "GPUBpSimulation.cuh" + +int main(int argc, char* argv[]) { + + /** 1. **************************************************************************************************/ + qDebug() << u8"1.ļȡС"; + QString inGPSPath = u8"C:\\Users\\30453\\Desktop\\script\\data\\GF3_Simulation.gpspos.data"; + long gpspoints = gdalImage(inGPSPath).height; + std::shared_ptr antpos = SatelliteAntPosOperator::readAntPosFile(inGPSPath, gpspoints); + std::shared_ptr antX((double*)mallocCUDAHost(sizeof(double) * gpspoints), FreeCUDAHost); + std::shared_ptr antY((double*)mallocCUDAHost(sizeof(double) * gpspoints), FreeCUDAHost); + std::shared_ptr antZ((double*)mallocCUDAHost(sizeof(double) * gpspoints), FreeCUDAHost); + for (long i = 0; i < gpspoints; i++) { + antX.get()[i] = antpos.get()[i].Px; + antY.get()[i] = antpos.get()[i].Py; + antZ.get()[i] = antpos.get()[i].Pz; + } + /** 2. **************************************************************************************************/ + qDebug() << u8"ļȡ\n2.ȡ"; + QString demxyzPath = u8"C:\\Users\\30453\\Desktop\\script\\data\\demxyz.bin"; + gdalImage demgridimg(demxyzPath); + long dem_rowCount = demgridimg.height; + long dem_ColCount = demgridimg.width; + std::shared_ptr demX = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demY = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demZ = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + std::shared_ptr imgX((double*)mallocCUDAHost(sizeof(double) * dem_rowCount * dem_ColCount), FreeCUDAHost); + std::shared_ptr imgY((double*)mallocCUDAHost(sizeof(double) * dem_rowCount * dem_ColCount), FreeCUDAHost); + std::shared_ptr imgZ((double*)mallocCUDAHost(sizeof(double) * dem_rowCount * dem_ColCount), FreeCUDAHost); + for (long i = 0; i < dem_rowCount; i++) { + for (long j = 0; j < dem_ColCount; j++) { + imgX.get()[i * dem_ColCount + j] = demX.get()[i * dem_ColCount + j]; + imgY.get()[i * dem_ColCount + j] = demY.get()[i * dem_ColCount + j]; + imgZ.get()[i * dem_ColCount + j] = demZ.get()[i * dem_ColCount + j]; + } + } + qDebug() << u8"ȡ"; + /** 3. Ƶ **************************************************************************************************/ + qDebug() << u8"3.Ƶ"; + double centerFreq = 5.3e9; + double bandwidth = 40e6; + long freqpoints = 8096; + std::shared_ptr freqlist(getFreqPoints_mallocHost(centerFreq - bandwidth / 2, centerFreq + bandwidth / 2, freqpoints), FreeCUDAHost); + qDebug() << "start Freq:\t" << centerFreq - bandwidth / 2; + qDebug() << "end Freq:\t" << centerFreq + bandwidth / 2; + qDebug() << "freq points:\t" << freqpoints; + qDebug() << "delta freq:\t" << freqlist.get()[0] - freqlist.get()[1]; + qDebug() << u8"Ƶʽ"; + /** 4. ʼز **************************************************************************************************/ + qDebug() << u8"4.ʼز"; + std::shared_ptr phdata (createEchoPhase_mallocHost(gpspoints, freqpoints),FreeCUDAHost); + qDebug() << "Azimuth Points:\t"< im_final(createEchoPhase_mallocHost(dem_rowCount, dem_ColCount), FreeCUDAHost); + qDebug() << "Azimuth Points:\t" << gpspoints; + qDebug() << "Range Points:\t" << freqpoints; + qDebug() << u8"ʼͼ"; + + /** 6. ģͲʼ **************************************************************************************************/ + qDebug() << u8"6.ģͲʼ"; + GPUDATA h_data; + h_data.AntX = antX.get(); + h_data.AntX = antY.get(); + h_data.AntX = antZ.get(); + + h_data.x_mat = imgX.get(); + h_data.y_mat = imgY.get(); + h_data.z_mat = imgZ.get(); + + h_data.Freq = freqlist.get(); + h_data.Nfft = freqpoints; + h_data.K = h_data.Nfft; + h_data.phdata = phdata.get(); + h_data.im_final = im_final.get(); + qDebug() << u8"ģͲ"; + + + /** 7. Ŀ **************************************************************************************************/ + double Tx = -2028380.625000, Ty = 4139373.250000, Tz = 4393382.500000; + double Tslx = -2028380.625000, Tsly = 4139373.250000, Tslz = 4393382.500000; + + double p1 = 1, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0; + + /** 7. ز **************************************************************************************************/ + GPUDATA d_data; + initGPUData(h_data, d_data); + + RFPCProcess(Tx, Ty, Tz, + Tslx, Tsly, Tslz, // Ŀ + p1, p2, p3, p4, p5, p6, + d_data); + + HostToDevice(h_data.phdata, d_data.phdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); + /** 8. չʾز **************************************************************************************************/ + ImageShowDialogClass* dialog = new ImageShowDialogClass; + std::shared_ptr h_ifftphdata((cuComplex*)mallocCUDAHost(sizeof(cuComplex) * d_data.Np * d_data.Nfft), FreeCUDAHost); + std::shared_ptr d_ifftphdata((cuComplex*)mallocCUDADevice(sizeof(cuComplex) * d_data.Np * d_data.Nfft), FreeCUDADevice); + CUDAIFFT(d_data.phdata, d_ifftphdata.get(), d_data.Np, d_data.Nfft, d_data.Nfft); + FFTShift1D(d_ifftphdata.get(), d_data.Np, d_data.Nfft); + DeviceToHost(h_ifftphdata.get(), d_ifftphdata.get(), sizeof(cuComplex) * d_data.Np * d_data.Nfft); + std::shared_ptr echoAmpArr(new double[d_data.Np * d_data.Nfft], delArrPtr); + { + for (long i = 0; i < d_data.Np * d_data.Nfft; i++) { + echoAmpArr.get()[i] = + 20 * std::log10(std::sqrt(std::pow(h_ifftphdata.get()[i].x, 2) + std::pow(h_ifftphdata.get()[i].y, 2))); + } + } + dialog->load_double_data(echoAmpArr.get(), d_data.Np, d_data.Nfft, QString("ifft")); + dialog->exec(); + + + + + return 0; +} + + + + + +