增加局部修改

pull/6/head
陈增辉 2025-03-05 17:10:21 +08:00
parent 130c222c3d
commit 29a6214a14
18 changed files with 846 additions and 79 deletions

View File

@ -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<typename T>
inline void memsetInitArray(std::shared_ptr<T> ptr, long arrcount,T ti) {
@ -172,4 +174,25 @@ inline void maxValueInArr(T* ptr, long arrcount, T& maxvalue) {
}
}
/** 常用SAR工具 ***********************************************************************************************************/
template<typename T>
inline T complexAbs(std::complex<T> ccdata) {
return T(sqrt(pow(ccdata.real(), 2) + pow(ccdata.imag(), 2)));
}
template<typename T>
inline void complex2dB(std::complex<T>* ccdata, T* outdata, long long count) {
for (long long i = 0; i < count; i++) {
outdata[i] = 20 * log10(complexAbs(ccdata[i]));
}
}
#endif

View File

@ -632,8 +632,6 @@ ErrorCode EchoL0Dataset::saveEchoArr(std::shared_ptr<std::complex<double>> 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<std::complex<double>> echoP
omp_destroy_lock(&lock); //
return ErrorCode::SUCCESS;
}
std::shared_ptr<SatelliteAntPos> SatelliteAntPosOperator::readAntPosFile(QString filepath, long& count)
{
gdalImage antimg(filepath);
long rowcount = count;
long colcount = 19;
std::shared_ptr<double> antlist = readDataArr<double>(antimg, 0, 0, rowcount, colcount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);
std::shared_ptr<SatelliteAntPos> 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<SatelliteAntPos> data, const long count)
{
gdalImage antimg=CreategdalImageDouble(filepath,count,19,1,true,true);
long rowcount = count;
long colcount = 19;
std::shared_ptr<double> 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 ;
}

View File

@ -92,6 +92,31 @@ struct PluseAntPos {
std::shared_ptr<PluseAntPos> BASECONSTVARIABLEAPI CreatePluseAntPosArr(long pluseCount);
class BASECONSTVARIABLEAPI SatelliteAntPosOperator {
public:
static std::shared_ptr<SatelliteAntPos> readAntPosFile(QString filepath,long& count);
static void writeAntPosFile(QString filepath, std::shared_ptr< SatelliteAntPos> data,const long count);
};
// 定义L0级数据
class BASECONSTVARIABLEAPI EchoL0Dataset {

View File

@ -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<double> 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<float> 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<int> 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<std::complex<double>> 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<double>* 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<double>* 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 ;
}

View File

@ -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<std::complex<double>> data, long start_row, long start_col, long rowCount, long colCount, int band_ids);
void saveImage(std::complex<double>* 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<std::complex<double>> 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<double>* 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<void(long, long)> processBarShow = {});
@ -504,7 +511,7 @@ inline std::shared_ptr<T> 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<T> 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;
}

View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>9233788c-bd43-41aa-b157-d77e92616d00</ProjectGuid>
<RootNamespace>GPUBPSimulation</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 12.6.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>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)</AdditionalDependencies>
</Link>
<CudaCompile>
<TargetMachinePlatform>64</TargetMachinePlatform>
</CudaCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>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)</AdditionalDependencies>
</Link>
<CudaCompile>
<TargetMachinePlatform>64</TargetMachinePlatform>
</CudaCompile>
</ItemDefinitionGroup>
<ItemGroup>
<CudaCompile Include="kernel.cu" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 12.6.targets" />
</ImportGroup>
</Project>

121
GPUBPSimulation/kernel.cu Normal file
View File

@ -0,0 +1,121 @@

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
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;
}

View File

@ -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));

View File

@ -0,0 +1,125 @@
#include <cstdio>
#include <cufft.h>
#include <cmath>
#include <cuda_runtime.h>
#include <iostream>
#include <memory>
#include <vector>
#include <cmath>
#include <complex>
#include <device_launch_parameters.h>
#include <cuda_runtime.h>
#include <cublas_v2.h>
#include <cuComplex.h>
#include <cufft.h>
#include <cufftw.h>
#include <cufftXt.h>
#include <cublas_v2.h>
#include <cuComplex.h>
#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<<<grid_size , BLOCK_SIZE >>>(
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 ;
}

View File

@ -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 <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <cublas_v2.h>
#include <cuComplex.h>
#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

View File

@ -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 << <grid, block >> > (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 << <gridShift, blockShift >> > (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 << <grid_size, BLOCK_SIZE >> > (
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!!");
}

View File

@ -1,18 +1,21 @@
#ifndef _BPBASIC0_CUDA_H_
#define _BPBASIC0_CUDA_H_
#include <cstdio>
#include <cufft.h>
#include <cmath>
#include <cuda_runtime.h>
#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

View File

@ -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 );
//
//

View File

@ -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) {

View File

@ -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);

View File

@ -41,7 +41,7 @@
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
@ -182,7 +182,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
@ -220,8 +220,12 @@
<ClCompile Include="SimulationSAR\SatelliteOribtModel.cpp" />
<ClCompile Include="SimulationSAR\SigmaDatabase.cpp" />
<ClCompile Include="SimulationSAR\TBPImageAlgCls.cpp" />
<ClCompile Include="UnitTestMain.cpp" />
<CudaCompile Include="GPUBpSimulation.cu" />
<CudaCompile Include="SimulationSAR\GPUTBPImage.cu" />
<QtMoc Include="PowerSimulationIncoherent\QSimulationSARPolynomialOrbitModel.h" />
<CudaCompile Include="PowerSimulationIncoherent\LookTableSimulationComputer.cuh" />
<ClInclude Include="GPUBpSimulation.cuh" />
<ClInclude Include="PowerSimulationIncoherent\OribtModelOperator.h" />
<QtMoc Include="PowerSimulationIncoherent\QSimulationLookTableDialog.h" />
<QtMoc Include="PowerSimulationIncoherent\QCreateSARIntensityByLookTableDialog.h" />
@ -234,6 +238,7 @@
<CudaCompile Include="SimulationSAR\BPBasic0_CUDA.cu" />
<CudaCompile Include="SimulationSAR\GPUBPTool.cuh" />
<ClInclude Include="SimulationSAR\BPBasic0_CUDA.cuh" />
<ClInclude Include="SimulationSAR\GPUTBPImage.cuh" />
<ClInclude Include="SimulationSAR\RFPCProcessCls.h" />
<ClInclude Include="SimulationSAR\SARSatelliteSimulationAbstractCls.h" />
<ClInclude Include="SimulationSAR\SARSimulationTaskSetting.h" />
@ -250,10 +255,6 @@
<FileType>Document</FileType>
</CudaCompile>
<CudaCompile Include="SimulationSAR\GPURFPC.cuh" />
<CudaCompile Include="SimulationSAR\GPUTBPImage.cu">
<FileType>Document</FileType>
</CudaCompile>
<CudaCompile Include="SimulationSAR\GPUTBPImage.cuh" />
</ItemGroup>
<ItemGroup>
<QtUic Include="PowerSimulationIncoherent\QCreateSARIntensityByLookTableDialog.ui" />

View File

@ -62,6 +62,12 @@
<ClInclude Include="SimulationSAR\BPBasic0_CUDA.cuh">
<Filter>SimulationSAR</Filter>
</ClInclude>
<ClInclude Include="SimulationSAR\GPUTBPImage.cuh">
<Filter>SimulationSAR</Filter>
</ClInclude>
<ClInclude Include="GPUBpSimulation.cuh">
<Filter>SimulationSAR</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="SimulationSAR\QImageSARRFPC.cpp">
@ -106,6 +112,9 @@
<ClCompile Include="PowerSimulationIncoherent\QCreateSARIntensityByLookTableDialog.cpp">
<Filter>PowerSimulationIncoherent</Filter>
</ClCompile>
<ClCompile Include="UnitTestMain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtUic Include="SimulationSAR\QImageSARRFPC.ui">
@ -163,12 +172,6 @@
<CudaCompile Include="SimulationSAR\GPURFPC.cuh">
<Filter>SimulationSAR</Filter>
</CudaCompile>
<CudaCompile Include="SimulationSAR\GPUTBPImage.cu">
<Filter>SimulationSAR</Filter>
</CudaCompile>
<CudaCompile Include="SimulationSAR\GPUTBPImage.cuh">
<Filter>SimulationSAR</Filter>
</CudaCompile>
<CudaCompile Include="PowerSimulationIncoherent\LookTableSimulationComputer.cu">
<Filter>PowerSimulationIncoherent</Filter>
</CudaCompile>
@ -184,5 +187,11 @@
<CudaCompile Include="SimulationSAR\BPBasic0_CUDA.cu">
<Filter>SimulationSAR</Filter>
</CudaCompile>
<CudaCompile Include="SimulationSAR\GPUTBPImage.cu">
<Filter>SimulationSAR</Filter>
</CudaCompile>
<CudaCompile Include="GPUBpSimulation.cu">
<Filter>SimulationSAR</Filter>
</CudaCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,141 @@
/*
* 仿
*
*
*/
#include <stdio.h>
#include <QString>
#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<SatelliteAntPos> antpos = SatelliteAntPosOperator::readAntPosFile(inGPSPath, gpspoints);
std::shared_ptr<double> antX((double*)mallocCUDAHost(sizeof(double) * gpspoints), FreeCUDAHost);
std::shared_ptr<double> antY((double*)mallocCUDAHost(sizeof(double) * gpspoints), FreeCUDAHost);
std::shared_ptr<double> 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<double> demX = readDataArr<double>(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);
std::shared_ptr<double> demY = readDataArr<double>(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);
std::shared_ptr<double> demZ = readDataArr<double>(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);
std::shared_ptr<double> imgX((double*)mallocCUDAHost(sizeof(double) * dem_rowCount * dem_ColCount), FreeCUDAHost);
std::shared_ptr<double> imgY((double*)mallocCUDAHost(sizeof(double) * dem_rowCount * dem_ColCount), FreeCUDAHost);
std::shared_ptr<double> 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<double> 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<cuComplex> phdata (createEchoPhase_mallocHost(gpspoints, freqpoints),FreeCUDAHost);
qDebug() << "Azimuth Points:\t"<<gpspoints;
qDebug() << "Range Points:\t"<< freqpoints;
qDebug() << u8"初始化回波结束";
/** 5. 初始化图像 **************************************************************************************************/
qDebug() << u8"5.初始化图像";
std::shared_ptr<cuComplex> 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<cuComplex> h_ifftphdata((cuComplex*)mallocCUDAHost(sizeof(cuComplex) * d_data.Np * d_data.Nfft), FreeCUDAHost);
std::shared_ptr<cuComplex> 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<double> 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;
}