迁移代码

Release
陈增辉 2024-11-27 13:10:40 +08:00
parent ae5473b380
commit e56b8f2d98
8 changed files with 488 additions and 11 deletions

View File

@ -120,6 +120,7 @@
<QtMocFileName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).moc</QtMocFileName>
</ClCompile>
<ClCompile Include="SimulationSAR\QImageSARRTPC.cpp" />
<ClCompile Include="SimulationSAR\QSimulationBPImage.cpp" />
<ClCompile Include="SimulationSAR\QToolAbstract.cpp" />
<ClCompile Include="SimulationSAR\RTPCProcessCls.cpp" />
<ClCompile Include="SimulationSAR\SARSatelliteSimulationAbstractCls.cpp" />
@ -166,6 +167,7 @@
<ClCompile Include="RasterProcessTool.cpp" />
<ClCompile Include="main.cpp" />
<QtUic Include="SimulationSAR\QImageSARRTPC.ui" />
<QtUic Include="SimulationSAR\QSimulationBPImage.ui" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="BaseLibraryCPP\BaseConstVariable.h" />
@ -176,6 +178,7 @@
<QtMoc Include="SimulationSAR\QImageSARRTPC.h" />
<QtMoc Include="SimulationSAR\QToolAbstract.h" />
<QtMoc Include="RegisterToolbox.h" />
<QtMoc Include="SimulationSAR\QSimulationBPImage.h" />
<ClInclude Include="SimulationSAR\TBPImageAlgCls.h" />
<QtMoc Include="QSimulationRTPCGUI.h" />
<QtMoc Include="GF3ProcessToolbox\QOrthSlrRaster.h" />

View File

@ -151,6 +151,9 @@
<ClCompile Include="SimulationSAR\QImageSARRTPC.cpp">
<Filter>SimulationSAR</Filter>
</ClCompile>
<ClCompile Include="SimulationSAR\QSimulationBPImage.cpp">
<Filter>SimulationSAR</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BaseLibraryCPP\BaseConstVariable.h">
@ -254,6 +257,9 @@
<QtMoc Include="SimulationSAR\QImageSARRTPC.h">
<Filter>SimulationSAR</Filter>
</QtMoc>
<QtMoc Include="SimulationSAR\QSimulationBPImage.h">
<Filter>SimulationSAR</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<QtUic Include="QMergeRasterProcessDialog.ui">
@ -286,6 +292,9 @@
<QtUic Include="SimulationSAR\QImageSARRTPC.ui">
<Filter>SimulationSAR</Filter>
</QtUic>
<QtUic Include="SimulationSAR\QSimulationBPImage.ui">
<Filter>SimulationSAR</Filter>
</QtUic>
</ItemGroup>
<ItemGroup>
<CudaCompile Include="SimulationSAR\TBPGPU.cu">

View File

@ -6,6 +6,7 @@
#include "QRDOrthProcessClass.h"
#include "QOrthSlrRaster.h"
#include "QImageSARRTPC.h"
#include "QSimulationBPImage.h"
GF3ImportDataToolButton::GF3ImportDataToolButton(QWidget* parent) :QToolAbstract(parent)
{
@ -124,6 +125,8 @@ SARSimulationTBPImageToolButton::~SARSimulationTBPImageToolButton()
void SARSimulationTBPImageToolButton::excute()
{
QSimulationBPImage* dialog = new QSimulationBPImage;
dialog->show();
}
void RegisterPreToolBox(RasterProcessTool* mainWindows)

View File

@ -0,0 +1,91 @@
#include "QSimulationBPImage.h"
#include <QFileDialog>
#include <QMessageBox>
#include "TBPImageAlgCls.h"
#include "EchoDataFormat.h"
#include <boost/thread.hpp>
#include <thread>
QSimulationBPImage::QSimulationBPImage(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
QObject::connect(ui.pushButtonEchoSelect, SIGNAL(clicked()), this, SLOT(onpushButtonEchoSelectClicked()));
QObject::connect(ui.pushButtonImageSelect, SIGNAL(clicked()), this, SLOT(onpushButtonImageSelectClicked()));
QObject::connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(onbtnaccepted()));
QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(onbtnrejected()));
}
QSimulationBPImage::~QSimulationBPImage()
{}
void QSimulationBPImage::onpushButtonEchoSelectClicked()
{
QString fileNames = QFileDialog::getOpenFileName(
this, // 父窗口
tr(u8"选择影像文件"), // 标题
QString(), // 默认路径
tr(u8"xml Files (*.xml);;All Files (*)") // 文件过滤器
);
// 如果用户选择了文件
if (!fileNames.isEmpty()) {
QString message = "选择的文件有:\n";
this->ui.lineEditEchoPath->setText(fileNames);
}
else {
QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
}
}
void QSimulationBPImage::onpushButtonImageSelectClicked()
{
QString fileNames = QFileDialog::getSaveFileName(
this, // 父窗口
tr(u8"选择影像文件"), // 标题
QString(), // 默认路径
tr(u8"All Files(*)") // 文件过滤器
);
// 如果用户选择了文件
if (!fileNames.isEmpty()) {
this->ui.lineEditImagePath->setText(fileNames);
}
else {
QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
}
}
void QSimulationBPImage::onbtnaccepted()
{
QString echofile = this->ui.lineEditEchoPath->text().trimmed();
QString outImageFolder = getParantFromPath(this->ui.lineEditImagePath->text().trimmed());
QString imagename = getFileNameFromPath(this->ui.lineEditImagePath->text().trimmed());
std::shared_ptr<EchoL0Dataset> echoL0ds(new EchoL0Dataset);
echoL0ds->Open(echofile);
std::shared_ptr< SARSimulationImageL1Dataset> imagL1(new SARSimulationImageL1Dataset);
imagL1->setCenterAngle(echoL0ds->getCenterAngle());
imagL1->setCenterFreq(echoL0ds->getCenterFreq());
imagL1->setNearRange(echoL0ds->getNearRange());
imagL1->setRefRange((echoL0ds->getNearRange() + echoL0ds->getFarRange()) / 2);
imagL1->setFarRange(echoL0ds->getFarRange());
imagL1->setFs(echoL0ds->getFs());
imagL1->setLookSide(echoL0ds->getLookSide());
imagL1->OpenOrNew(outImageFolder, imagename, echoL0ds->getPluseCount(), echoL0ds->getPlusePoints());
TBPImageAlgCls TBPimag;
TBPimag.setEchoL0(echoL0ds);
TBPimag.setImageL1(imagL1);
long cpucore_num = std::thread::hardware_concurrency();
TBPimag.Process(cpucore_num);
}
void QSimulationBPImage::onbtnrejected()
{
this->close();
}

View File

@ -0,0 +1,23 @@
#pragma once
#include <QDialog>
#include "ui_QSimulationBPImage.h"
class QSimulationBPImage : public QDialog
{
Q_OBJECT
public:
QSimulationBPImage(QWidget *parent = nullptr);
~QSimulationBPImage();
public slots:
void onpushButtonEchoSelectClicked();
void onpushButtonImageSelectClicked();
void onbtnaccepted();
void onbtnrejected();
private:
Ui::QSimulationBPImageClass ui;
};

View File

@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QSimulationBPImageClass</class>
<widget class="QDialog" name="QSimulationBPImageClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>仿真图像TimeBP方法</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>回波地址:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditEchoPath">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonEchoSelect">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>选择</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>仿真图像:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditImagePath">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonImageSelect">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>选择</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@ -4,6 +4,54 @@
#include <complex>
#include <cuda_runtime.h>
#include <cublas_v2.h>
#include <device_launch_parameters.h>
#include "BaseConstVariable.h"
void checkCudaError(cudaError_t err, const char* msg) {
if (err != cudaSuccess) {
std::cerr << "CUDA error: " << msg << " (" << cudaGetErrorString(err) << ")" << std::endl;
exit(EXIT_FAILURE);
}
}
// CUDA 核函数
__global__ void computeDistanceAndEchoID(float* antPx, float* antPy, float* antPz,
float* img_x, float* img_y, float* img_z,
float* imgR, float* imgEchoID,
long rowcount, long colcount, long prfid,
float Rnear, float fs) {
int i = blockIdx.x * blockDim.x + threadIdx.x;
int j = blockIdx.y * blockDim.y + threadIdx.y;
// 确保线程索引有效
if (i < rowcount && j < colcount) {
int idx = i * colcount + j;
// 计算距离
float dx = antPx[prfid] - img_x[idx];
float dy = antPy[prfid] - img_y[idx];
float dz = antPz[prfid] - img_z[idx];
imgR[idx] = sqrt(dx * dx + dy * dy + dz * dz);
// 计算 EchoID
imgEchoID[idx] = (imgR[idx] - Rnear) / (2 * LIGHTSPEED) * fs;
}
}
@ -13,9 +61,123 @@
/// <param name="antpos_ptr">ÎÀÐǹìµÀ×ø±ê</param>
/// <param name="echoArr">»Ø²¨¾ØÕó</param>
/// <param name="img_arr">ͼÏñ¾ØÕó</param>
void TBPImageGPUAlg(std::shared_ptr<float> antPx, std::shared_ptr<float> antPy, std::shared_ptr<float> antPz,
void TBPImageGPUAlgBlock(std::shared_ptr<float> antPx, std::shared_ptr<float> antPy, std::shared_ptr<float> antPz, // 天线坐标
std::shared_ptr<float> antVx, std::shared_ptr<float> antVy, std::shared_ptr<float> antVz,
std::shared_ptr<std::complex<double>> echoArr,std::shared_ptr<std::complex<double>> img_arr) {
std::shared_ptr<float> img_x, std::shared_ptr<float> img_y, std::shared_ptr<float> img_z, // 图像坐标
std::shared_ptr<std::complex<float>> echoArr,std::shared_ptr<std::complex<float>> img_arr,
float freq, float fs,float Rnear,float Rfar,
long rowcount,long colcount) {
float factorj = freq * 4 * PI / LIGHTSPEED;
std::shared_ptr<float> imgR(new float[rowcount * colcount]);
std::shared_ptr<long> imgEchoID(new long[rowcount * colcount]);
for (long prfid = 0; prfid < rowcount; prfid++) {
for (long i = 0; i < rowcount; i++) {
for (long j = 0; j < colcount; j++) {
imgR.get()[i * colcount + j] = std::sqrt(
std::pow(antPx.get()[prfid]-img_x.get()[i * colcount + j], 2)
+ std::pow(antPy.get()[prfid] - img_y.get()[i * colcount + j], 2)
+ std::pow(antPz.get()[prfid] - img_z.get()[i * colcount + j], 2)
);
imgEchoID.get()[i * colcount + j] = (imgR.get()[i * colcount + j] - Rnear) / 2 / LIGHTSPEED * fs;
}
}
}
// 分配主机内存
float* h_antPx, * h_antPy, * h_antPz, * h_img_x, * h_img_y, * h_img_z;
float* h_imgR, * h_imgEchoID;
cudaMallocHost(&h_antPx, sizeof(float) * 1); // 单个传感器的位置
cudaMallocHost(&h_antPy, sizeof(float) * 1);
cudaMallocHost(&h_antPz, sizeof(float) * 1);
cudaMallocHost(&h_img_x, sizeof(float) * rowcount * colcount);
cudaMallocHost(&h_img_y, sizeof(float) * rowcount * colcount);
cudaMallocHost(&h_img_z, sizeof(float) * rowcount * colcount);
cudaMallocHost(&h_imgR, sizeof(float) * rowcount * colcount);
cudaMallocHost(&h_imgEchoID, sizeof(float) * rowcount * colcount);
// 将数据初始化到主机内存(这里仅为示例,实际数据根据需求加载)
for (long i = 0; i < rowcount * colcount; i++) {
h_img_x[i] = 0.0f;
h_img_y[i] = 0.0f;
h_img_z[i] = 0.0f;
}
h_antPx[0] = 0.0f;
h_antPy[0] = 0.0f;
h_antPz[0] = 0.0f;
// 分配设备内存
float* d_antPx, * d_antPy, * d_antPz, * d_img_x, * d_img_y, * d_img_z;
float* d_imgR, * d_imgEchoID;
cudaMalloc(&d_antPx, sizeof(float) * 1);
cudaMalloc(&d_antPy, sizeof(float) * 1);
cudaMalloc(&d_antPz, sizeof(float) * 1);
cudaMalloc(&d_img_x, sizeof(float) * rowcount * colcount);
cudaMalloc(&d_img_y, sizeof(float) * rowcount * colcount);
cudaMalloc(&d_img_z, sizeof(float) * rowcount * colcount);
cudaMalloc(&d_imgR, sizeof(float) * rowcount * colcount);
cudaMalloc(&d_imgEchoID, sizeof(float) * rowcount * colcount);
// 将数据从主机拷贝到设备
cudaMemcpy(d_antPx, h_antPx, sizeof(float) * 1, cudaMemcpyHostToDevice);
cudaMemcpy(d_antPy, h_antPy, sizeof(float) * 1, cudaMemcpyHostToDevice);
cudaMemcpy(d_antPz, h_antPz, sizeof(float) * 1, cudaMemcpyHostToDevice);
cudaMemcpy(d_img_x, h_img_x, sizeof(float) * rowcount * colcount, cudaMemcpyHostToDevice);
cudaMemcpy(d_img_y, h_img_y, sizeof(float) * rowcount * colcount, cudaMemcpyHostToDevice);
cudaMemcpy(d_img_z, h_img_z, sizeof(float) * rowcount * colcount, cudaMemcpyHostToDevice);
// 设置 CUDA 核函数的网格和块的尺寸
dim3 blockDim(16, 16); // 每个块处理 16x16 的像素点
dim3 gridDim((colcount + blockDim.x - 1) / blockDim.x,
(rowcount + blockDim.y - 1) / blockDim.y);
// 调用 CUDA 核函数
computeDistanceAndEchoID << <gridDim, blockDim >> > (d_antPx, d_antPy, d_antPz,
d_img_x, d_img_y, d_img_z,
d_imgR, d_imgEchoID,
rowcount, colcount, prfid,
RNEAR, LIGHTSPEED, FS);
// 等待所有设备任务完成
cudaDeviceSynchronize();
// 将结果从设备拷贝回主机
cudaMemcpy(h_imgR, d_imgR, sizeof(float) * rowcount * colcount, cudaMemcpyDeviceToHost);
cudaMemcpy(h_imgEchoID, d_imgEchoID, sizeof(float) * rowcount * colcount, cudaMemcpyDeviceToHost);
// 清理资源
cudaFree(d_antPx);
cudaFree(d_antPy);
cudaFree(d_antPz);
cudaFree(d_img_x);
cudaFree(d_img_y);
cudaFree(d_img_z);
cudaFree(d_imgR);
cudaFree(d_imgEchoID);
cudaFreeHost(h_antPx);
cudaFreeHost(h_antPy);
cudaFreeHost(h_antPz);
cudaFreeHost(h_img_x);
cudaFreeHost(h_img_y);
cudaFreeHost(h_img_z);
cudaFreeHost(h_imgR);
cudaFreeHost(h_imgEchoID);

View File

@ -4,6 +4,7 @@
#include <QDebug>
#include <QString>
#include <cmath>
#include <QProgressDialog>
void TBPImageProcess(QString echofile, QString outImageFolder, QString imagePlanePath,long num_thread)
{
@ -188,6 +189,15 @@ ErrorCode TBPImageAlgCls::ProcessCPU(long num_thread)
long startLine = 0;
long processValue = 0;
long processNumber = 0;
QProgressDialog progressDialog(u8"RTPC回波生成中", u8"终止", 0, rowCount);
progressDialog.setWindowTitle(u8"RTPC回波生成中");
progressDialog.setWindowModality(Qt::WindowModal);
progressDialog.setAutoClose(true);
progressDialog.setValue(0);
progressDialog.setMaximum(rowCount);
progressDialog.setMinimum(0);
progressDialog.show();
#pragma omp parallel for
for (startLine = 0; startLine < rowCount; startLine = startLine + BlockLine) { // 图像大小
@ -227,12 +237,16 @@ ErrorCode TBPImageAlgCls::ProcessCPU(long num_thread)
processValue = processValue + BlockLine;
this->L1ds->saveImageRaster(imagarr, 0, rowCount);
qDebug() << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz").toUtf8().constData() << "\t" << processValue * 100.0 / rowCount << "%\t" << startLine << "\t-\t" << startLine + BlockLine << "\tend\t\t";
processNumber = processNumber + BlockLine;
processNumber = processNumber < progressDialog.maximum() ? processNumber : progressDialog.maximum();
progressDialog.setValue(processNumber);
omp_unset_lock(&lock); // 解锁
}
omp_destroy_lock(&lock); // 销毁锁
this->L1ds->saveImageRaster(imagarr, 0, rowCount);
this->L1ds->saveToXml();
progressDialog.close();
return ErrorCode::SUCCESS;
}
@ -246,13 +260,14 @@ ErrorCode TBPImageAlgCls::ProcessGPU()
long PlusePoints = this->L0ds->getPlusePoints();
double Rnear = this->L1ds->getNearRange();
double Rfar = this->L1ds->getFarRange();
double fs = this->L1ds->getFs();
float Rnear = this->L1ds->getNearRange();
float Rfar = this->L1ds->getFarRange();
float fs = this->L1ds->getFs();
double dx = LIGHTSPEED / 2 / fs;
double factorj = this->L1ds->getCenterFreq() * 4 * M_PI / LIGHTSPEED * 1e9;
float freq = this->L1ds->getCenterFreq()*1.0*1e9;
double factorj = freq * 4 * M_PI / LIGHTSPEED ;
std::shared_ptr<float> pixelX(new float[rowCount*colCount],delArrPtr);
std::shared_ptr<float> pixelX(new float[rowCount*colCount],delArrPtr); // 图像成像网格
std::shared_ptr<float> pixelY(new float[rowCount*colCount],delArrPtr);
std::shared_ptr<float> pixelZ(new float[rowCount*colCount],delArrPtr);
@ -262,7 +277,7 @@ ErrorCode TBPImageAlgCls::ProcessGPU()
std::shared_ptr<float> Vxs (new float[this->L0ds->getPluseCount()]);
std::shared_ptr<float> Vys (new float[this->L0ds->getPluseCount()]);
std::shared_ptr<float> Vzs (new float[this->L0ds->getPluseCount()]);
// 图像网格坐标
@ -309,10 +324,17 @@ ErrorCode TBPImageAlgCls::ProcessGPU()
antpos.get()[i *19 + 14] = AntDirectY;
antpos.get()[i *19 + 15] = AntDirectZ;
Pxs.get()[i] = Px;
Pys.get()[i] = Py;
Pzs.get()[i] = Pz;
Vxs.get()[i] = Vx;
Vys.get()[i] = Vy;
Vzs.get()[i] = Vz;
for (long j = 0; j < colCount; j++) {
R = j * dx + Rnear;
pixelX.get()[i*colCount+ j] = Px + AntDirectX * R;
pixelY.get()[i*colCount+ j] = Py + AntDirectY * R;
pixelZ.get()[i*colCount+ j] = Pz + AntDirectZ * R;
}
}
@ -320,8 +342,28 @@ ErrorCode TBPImageAlgCls::ProcessGPU()
antpos.reset();
}
std::shared_ptr<std::complex<float>> imagarr(new std::complex<float>[rowCount * colCount]);
{
std::shared_ptr<std::complex<double>> Rasterarr = this->L1ds->getImageRaster();
for (long i = 0; i < pixelCount; i++) {
imagarr.get()[i] = Rasterarr.get()[i];
}
}
std::shared_ptr<std::complex<float>> echodata(new std::complex<float>[rowCount * colCount]);
{
std::shared_ptr<std::complex<double>> echodataPtr = this->L0ds->getEchoArr();
for (long i = 0; i < PRFCount; i++) {
for (long j = 0; j < PlusePoints; j++) {
echodata.get()[i * PlusePoints + j] = echodataPtr.get()[i * PlusePoints + j];
}
}
}
TBPImageGPUAlg(Pxs, Pys, Pzs, // 天线坐标
Vxs, Vys, Vzs,
pixelX, pixelY, pixelZ, // 图像坐标
echodata, imagarr, freq,fs,Rnear,Rfar,rowCount,colCount);