增加了重采样的工具,并入库

pull/4/head
陈增辉 2025-02-19 10:06:45 +08:00
parent 87b45a6089
commit b8cf53cf20
26 changed files with 1083 additions and 62 deletions

View File

@ -187,6 +187,7 @@
<ClInclude Include="BaseTool\LogInfoCls.h" />
<QtMoc Include="ToolAbstract\QToolAbstract.h" />
<QtMoc Include="BaseTool\QToolProcessBarDialog.h" />
<ClInclude Include="BaseTool\PrintMsgToQDebug.h" />
<ClInclude Include="BaseTool\RasterToolBase.h" />
<ClInclude Include="BaseTool\SARSimulationImageL1.h" />
<ClInclude Include="BaseTool\stdafx.h" />
@ -200,6 +201,7 @@
<ClCompile Include="BaseTool\GeoOperator.cpp" />
<ClCompile Include="BaseTool\ImageOperatorBase.cpp" />
<ClCompile Include="BaseTool\LogInfoCls.cpp" />
<ClCompile Include="BaseTool\PrintMsgToQDebug.cpp" />
<ClCompile Include="BaseTool\QToolProcessBarDialog.cpp" />
<ClCompile Include="BaseTool\RasterToolBase.cpp" />
<ClCompile Include="BaseTool\SARSimulationImageL1.cpp" />

View File

@ -57,6 +57,9 @@
<ClInclude Include="BaseTool\stdafx.h">
<Filter>BaseTool</Filter>
</ClInclude>
<ClInclude Include="BaseTool\PrintMsgToQDebug.h">
<Filter>BaseTool</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
@ -98,6 +101,9 @@
<ClCompile Include="ToolAbstract\QToolAbstract.cpp">
<Filter>ToolAbstract</Filter>
</ClCompile>
<ClCompile Include="BaseTool\PrintMsgToQDebug.cpp">
<Filter>BaseTool</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="BaseTool\QToolProcessBarDialog.h">

View File

@ -35,6 +35,9 @@
#include <gsl/gsl_multifit.h>
#include <qcoreapplication.h>
#include <xmmintrin.h> // 包含SSE指令集头文件
#include <emmintrin.h> // 包含SSE2指令集头文件
#include <omp.h> // 包含OpenMP头文件
QString longDoubleToQStringScientific(long double value) {
@ -634,4 +637,46 @@ Eigen::VectorXd linspace(double start, double stop, int num) {
}
return result;
}
}
void initializeMatrixWithSSE2(Eigen::MatrixXd& mat, const double* data, long rowcount, long colcount) {
__m128d zero = _mm_setzero_pd();
#pragma omp parallel for
for (long i = 0; i < rowcount; ++i) {
for (long j = 0; j < colcount; j += 2) { // 每次处理2个double
if (j + 2 <= colcount) {
__m128d src = _mm_loadu_pd(&data[i * colcount + j]);
_mm_storeu_pd(&mat(i, j), src);
}
else {
// 处理剩余部分
for (long k = j; k < colcount; ++k) {
mat(i, k) = data[i * colcount + k];
}
}
}
}
}
void initializeMatrixWithSSE2(Eigen::MatrixXf& mat, const float* data, long rowcount, long colcount) {
__m128 zero = _mm_setzero_ps();
#pragma omp parallel for
for (long i = 0; i < rowcount; ++i) {
for (long j = 0; j < colcount; j += 4) { // 每次处理4个float
if (j + 4 <= colcount) {
__m128 src = _mm_loadu_ps(&data[i * colcount + j]);
_mm_storeu_ps(&mat(i, j), src);
}
else {
// 处理剩余部分
for (long k = j; k < colcount; ++k) {
mat(i, k) = data[i * colcount + k];
}
}
}
}
}

View File

@ -32,6 +32,7 @@
#include <iomanip>
#include <sstream>
///////////////////////////////////// 基础数学函数 /////////////////////////////////////////////////////////////
@ -122,4 +123,31 @@ QVector<SatellitePos> BASECONSTVARIABLEAPI SatelliteAntPos2SatellitePos(QVector
QString BASECONSTVARIABLEAPI getDebugDataPath(QString filename);
std::vector<std::string> BASECONSTVARIABLEAPI split(const std::string& str, char delimiter);
Eigen::VectorXd BASECONSTVARIABLEAPI linspace(double start, double stop, int num);
/** 内存赋值 ***********************************************************************************************************/
void initializeMatrixWithSSE2(Eigen::MatrixXd& mat, const double* data, long rowcount, long colcount);
void initializeMatrixWithSSE2(Eigen::MatrixXf& mat, const float* data, long rowcount, long colcount);
/** 模板函数类 ***********************************************************************************************************/
template<typename T>
inline void BASECONSTVARIABLEAPI memsetInitArray(std::shared_ptr<T> ptr, long arrcount,T ti) {
for (long i = 0; i < arrcount; i++) {
ptr.get()[i] = ti;
}
}
template<typename T>
inline void BASECONSTVARIABLEAPI memcpyArray(std::shared_ptr<T> srct, std::shared_ptr<T> dest, long arrcount) {
for (long i = 0; i < arrcount; i++) {
dest.get()[i] = srct.get()[i];
}
}
#endif

View File

@ -97,6 +97,13 @@ QString getFileNameWidthoutExtend(QString path)
return fileNameWithoutExtension;
}
QString BASECONSTVARIABLEAPI getFileExtension(QString path)
{
QFileInfo fileInfo(path);
QString fileExtension = fileInfo.suffix(); // 获取无后缀文件名
return fileExtension;
}
bool isDirectory(const QString& path)
{
QFileInfo fileinfo(path);

View File

@ -37,6 +37,8 @@ QString BASECONSTVARIABLEAPI getFileNameFromPath(const QString& path);
QString BASECONSTVARIABLEAPI getFileNameWidthoutExtend(QString path);
QString BASECONSTVARIABLEAPI getFileExtension(QString path);
int BASECONSTVARIABLEAPI write_binfile(char* filepath, char* data, size_t data_len);
char* read_textfile(char* text_path, int* length);

View File

@ -629,6 +629,137 @@ Eigen::MatrixXd gdalImage::getData(int start_row, int start_col, int rows_count,
return datamatrix;
}
Eigen::MatrixXf gdalImage::getDataf(int start_row, int start_col, int rows_count, int cols_count,
int band_ids = 1)
{
omp_lock_t lock;
omp_init_lock(&lock);
omp_set_lock(&lock);
GDALAllRegister();
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen(
this->img_path.toUtf8().constData(), GA_ReadOnly)); // 锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷
GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType();
GDALRasterBand* demBand = rasterDataset->GetRasterBand(band_ids);
rows_count = start_row + rows_count <= this->height ? rows_count : this->height - start_row;
cols_count = start_col + cols_count <= this->width ? cols_count : this->width - start_col;
Eigen::MatrixXf datamatrix(rows_count, cols_count);
if (gdal_datatype == GDT_Byte) {
char* temp = new char[rows_count * cols_count];
demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count,
rows_count, gdal_datatype, 0, 0);
for (int i = 0; i < rows_count; i++) {
for (int j = 0; j < cols_count; j++) {
datamatrix(i, j) = temp[i * cols_count + j];
}
}
delete[] temp;
}
else if (gdal_datatype == GDT_UInt16) {
unsigned short* temp = new unsigned short[rows_count * cols_count];
demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count,
rows_count, gdal_datatype, 0, 0);
for (int i = 0; i < rows_count; i++) {
for (int j = 0; j < cols_count; j++) {
datamatrix(i, j) = temp[i * cols_count + j];
}
}
delete[] temp;
}
else if (gdal_datatype == GDT_Int16) {
short* temp = new short[rows_count * cols_count];
demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count,
rows_count, gdal_datatype, 0, 0);
for (int i = 0; i < rows_count; i++) {
for (int j = 0; j < cols_count; j++) {
datamatrix(i, j) = temp[i * cols_count + j];
}
}
delete[] temp;
}
else if (gdal_datatype == GDT_UInt32) {
unsigned int* temp = new unsigned int[rows_count * cols_count];
demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count,
rows_count, gdal_datatype, 0, 0);
for (int i = 0; i < rows_count; i++) {
for (int j = 0; j < cols_count; j++) {
datamatrix(i, j) = temp[i * cols_count + j];
}
}
delete[] temp;
}
else if (gdal_datatype == GDT_Int32) {
int* temp = new int[rows_count * cols_count];
demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count,
rows_count, gdal_datatype, 0, 0);
for (int i = 0; i < rows_count; i++) {
for (int j = 0; j < cols_count; j++) {
datamatrix(i, j) = temp[i * cols_count + j];
}
}
delete[] temp;
}
//else if (gdal_datatype == GDT_UInt64) {
// unsigned long* temp = new unsigned long[rows_count * cols_count];
// demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count,
// rows_count, gdal_datatype, 0, 0); for (int i = 0; i < rows_count; i++) {
// for (int j = 0; j <
// cols_count; j++) {
// datamatrix(i, j) = temp[i * cols_count + j];
// }
// }
// delete[] temp;
//}
//else if (gdal_datatype == GDT_Int64) {
// long* temp = new long[rows_count * cols_count];
// demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count,
// rows_count, gdal_datatype, 0, 0); for (int i = 0; i < rows_count; i++) {
// for (int j = 0; j <
// cols_count; j++) {
// datamatrix(i, j) = temp[i * cols_count + j];
// }
// }
// delete[] temp;
//}
else if (gdal_datatype == GDT_Float32) {
float* temp = new float[rows_count * cols_count];
demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count,
rows_count, gdal_datatype, 0, 0);
for (int i = 0; i < rows_count; i++) {
for (int j = 0; j < cols_count; j++) {
datamatrix(i, j) = temp[i * cols_count + j];
}
}
delete[] temp;
}
else if (gdal_datatype == GDT_Float64) {
double* temp = new double[rows_count * cols_count];
demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, temp, cols_count,
rows_count, gdal_datatype, 0, 0);
for (int i = 0; i < rows_count; i++) {
for (int j = 0; j < cols_count; j++) {
datamatrix(i, j) = temp[i * cols_count + j];
}
}
delete[] temp;
}
else {
}
GDALClose((GDALDatasetH)rasterDataset);
omp_unset_lock(&lock); // 锟酵放伙拷斤拷
omp_destroy_lock(&lock); // 劫伙拷斤拷
// GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH
return datamatrix;
}
Eigen::MatrixXi gdalImage::getDatai(int start_row, int start_col, int rows_count, int cols_count, int band_ids)
{
omp_lock_t lock;
@ -848,7 +979,10 @@ void gdalImage::saveImage(Eigen::MatrixXd data, int start_row = 0, int start_col
}
GDALAllRegister();
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff");
QString filesuffer = getFileExtension(this->img_path).toLower();
bool isTiff = filesuffer.contains("tif");
GDALDriver* poDriver = isTiff? GetGDALDriverManager()->GetDriverByName("GTiff"): GetGDALDriverManager()->GetDriverByName("ENVI");
GDALDataset* poDstDS = nullptr;
if(exists_test(this->img_path)) {
poDstDS = (GDALDataset*)(GDALOpen(this->img_path.toUtf8().constData(), GA_Update));
@ -912,9 +1046,90 @@ void gdalImage::saveImage(Eigen::MatrixXd data, int start_row = 0, int start_col
omp_destroy_lock(&lock); // 劫伙拷斤拷
}
void gdalImage::saveImage(Eigen::MatrixXf data, int start_row = 0, int start_col = 0,
int band_ids = 1)
{
GDALDataType datetype = this->getDataType();
omp_lock_t lock;
omp_init_lock(&lock);
omp_set_lock(&lock);
if (start_row + data.rows() > this->height || start_col + data.cols() > this->width) {
QString tip = u8"file path: " + this->img_path + " image size :( " + QString::number(this->height) + " , " + QString::number(this->width) + " ) " + " input size (" + QString::number(start_row + data.rows()) + ", " + QString::number(start_col + data.cols()) + ") ";
qDebug() << tip;
throw std::exception(tip.toUtf8().constData());
}
GDALAllRegister();
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
QString filesuffer = getFileExtension(this->img_path).toLower();
bool isTiff = filesuffer.contains("tif");
GDALDriver* poDriver = isTiff ? GetGDALDriverManager()->GetDriverByName("GTiff") : 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, datetype, NULL); // 斤拷锟斤拷
if (nullptr == poDstDS) {
QString tip = u8"file path: " + this->img_path + " image size :( " + QString::number(this->height) + " , " + QString::number(this->width) + " ) " + " input size (" + QString::number(start_row + data.rows()) + ", " + QString::number(start_col + data.cols()) + ") ";
qDebug() << tip;
throw std::exception(tip.toUtf8().constData());
return;
}
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;
}
int datarows = data.rows();
int datacols = data.cols();
void* databuffer = nullptr;
if (datetype == GDT_Float32) {
databuffer = new float[datarows * datacols];
for (int i = 0; i < datarows; i++) {
for (int j = 0; j < datacols; j++) {
((float*)databuffer)[i * datacols + j] = float(data(i, j));
}
}
poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_col, start_row, datacols, datarows,
databuffer, datacols, datarows, datetype, 0, 0);
}
else if (datetype == GDT_Float64) {
databuffer = new double[datarows * datacols];
for (int i = 0; i < datarows; i++) {
for (int j = 0; j < datacols; j++) {
((double*)databuffer)[i * datacols + j] = double(data(i, j));
}
}
poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_col, start_row, datacols, datarows,
databuffer, datacols, datarows, datetype, 0, 0);
}
else {
}
GDALFlushCache(poDstDS);
GDALClose((GDALDatasetH)poDstDS);
// GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH
delete[] databuffer;
omp_unset_lock(&lock); // 锟酵放伙拷斤拷
omp_destroy_lock(&lock); // 劫伙拷斤拷
}
void gdalImage::saveImage(Eigen::MatrixXi data, int start_row, int start_col, int band_ids)
{
GDALDataType datetype=this->getDataType();
omp_lock_t lock;
omp_init_lock(&lock);
@ -926,7 +1141,9 @@ void gdalImage::saveImage(Eigen::MatrixXi data, int start_row, int start_col, in
}
GDALAllRegister();
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff");
QString filesuffer = getFileExtension(this->img_path).toLower();
bool isTiff = filesuffer.contains("tif");
GDALDriver* poDriver = isTiff ? GetGDALDriverManager()->GetDriverByName("GTiff") : GetGDALDriverManager()->GetDriverByName("ENVI");
GDALDataset* poDstDS = nullptr;
if (exists_test(this->img_path)) {
poDstDS = (GDALDataset*)(GDALOpen(this->img_path.toUtf8().constData(), GA_Update));
@ -969,6 +1186,191 @@ void gdalImage::saveImage(Eigen::MatrixXi data, int start_row, int start_col, in
omp_destroy_lock(&lock); // 劫伙拷斤拷
}
void gdalImage::saveImage(std::shared_ptr<double> data, int start_row, int start_col, int rowcount, int colcount, int band_ids)
{
GDALDataType datetype = this->getDataType();
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 + " image size :( " + QString::number(this->height) + " , " + QString::number(this->width) + " ) " + " input size (" + QString::number(start_row + rowcount) + ", " + QString::number(start_col + colcount) + ") ";
qDebug() << tip;
throw std::exception(tip.toUtf8().constData());
}
GDALAllRegister();
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
QString filesuffer = getFileExtension(this->img_path).toLower();
bool isTiff = filesuffer.contains("tif");
GDALDriver* poDriver = isTiff ? GetGDALDriverManager()->GetDriverByName("GTiff") : 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_Float32, NULL); // 斤拷锟斤拷
poDstDS->SetProjection(this->projection.toUtf8().constData());
double gt_ptr[6];
for (int i = 0; i < this->gt.rows(); i++) {
for (int j = 0; j < this->gt.cols(); j++) {
gt_ptr[i * 3 + j] = this->gt(i, j);
}
}
poDstDS->SetGeoTransform(gt_ptr);
}
long datarows = rowcount;
long datacols = colcount;
double* databuffer = new double[datarows * datacols];
if (datetype == GDT_Float64) {
memcpy(databuffer, data.get(), sizeof(double) * datarows * datacols);
}
else {
for (long i = 0; i < datarows; i++) {
for (long j = 0; j < datacols; j++) {
databuffer[i * datacols + j] = data.get()[i * datacols + j];
}
}
}
// poDstDS->RasterIO(GF_Write,start_col, start_row, datacols, datarows, databuffer, datacols,
// datarows, GDT_Float32,band_ids, num,0,0,0);
poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_col, start_row, datacols, datarows,
databuffer, datacols, datarows, datetype, 0, 0);
GDALFlushCache(poDstDS);
GDALClose((GDALDatasetH)poDstDS);
// GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH
delete[] databuffer;
omp_unset_lock(&lock); // 锟酵放伙拷斤拷
omp_destroy_lock(&lock); // 劫伙拷斤拷
}
void gdalImage::saveImage(std::shared_ptr<float> data, int start_row, int start_col, int rowcount, int colcount, int band_ids)
{
GDALDataType datetype = this->getDataType();
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 + " image size :( " + QString::number(this->height) + " , " + QString::number(this->width) + " ) " + " input size (" + QString::number(start_row + rowcount) + ", " + QString::number(start_col + colcount) + ") ";
qDebug() << tip;
throw std::exception(tip.toUtf8().constData());
}
GDALAllRegister();
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
QString filesuffer = getFileExtension(this->img_path).toLower();
bool isTiff = filesuffer.contains("tif");
GDALDriver* poDriver = isTiff ? GetGDALDriverManager()->GetDriverByName("GTiff") : 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_Float32, NULL); // 斤拷锟斤拷
poDstDS->SetProjection(this->projection.toUtf8().constData());
double gt_ptr[6];
for (int i = 0; i < this->gt.rows(); i++) {
for (int j = 0; j < this->gt.cols(); j++) {
gt_ptr[i * 3 + j] = this->gt(i, j);
}
}
poDstDS->SetGeoTransform(gt_ptr);
}
long datarows = rowcount;
long datacols = colcount;
float* databuffer = new float[datarows * datacols];
if (datetype == GDT_Float32) {
memcpy(databuffer, data.get(), sizeof(float) * datarows * datacols);
}
else {
for (long i = 0; i < datarows; i++) {
for (long j = 0; j < datacols; j++) {
databuffer[i * datacols + j] = data.get()[i * datacols + j];
}
}
}
// poDstDS->RasterIO(GF_Write,start_col, start_row, datacols, datarows, databuffer, datacols,
// datarows, GDT_Float32,band_ids, num,0,0,0);
poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_col, start_row, datacols, datarows,
databuffer, datacols, datarows, datetype, 0, 0);
GDALFlushCache(poDstDS);
GDALClose((GDALDatasetH)poDstDS);
// GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH
delete[] databuffer;
omp_unset_lock(&lock); // 锟酵放伙拷斤拷
omp_destroy_lock(&lock); // 劫伙拷斤拷
}
void gdalImage::saveImage(std::shared_ptr<int> data, int start_row, int start_col, int rowcount, int colcount, int band_ids)
{
GDALDataType datetype = this->getDataType();
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 + " image size :( " + QString::number(this->height) + " , " + QString::number(this->width) + " ) " + " input size (" + QString::number(start_row + rowcount) + ", " + QString::number(start_col + colcount) + ") ";
qDebug() << tip;
throw std::exception(tip.toUtf8().constData());
}
GDALAllRegister();
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
QString filesuffer = getFileExtension(this->img_path).toLower();
bool isTiff = filesuffer.contains("tif");
GDALDriver* poDriver = isTiff ? GetGDALDriverManager()->GetDriverByName("GTiff") : 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_Float32, NULL); // 斤拷锟斤拷
poDstDS->SetProjection(this->projection.toUtf8().constData());
double gt_ptr[6];
for (int i = 0; i < this->gt.rows(); i++) {
for (int j = 0; j < this->gt.cols(); j++) {
gt_ptr[i * 3 + j] = this->gt(i, j);
}
}
poDstDS->SetGeoTransform(gt_ptr);
}
long datarows = rowcount;
long datacols = colcount;
int* databuffer = new int[datarows * datacols];
if (datetype == GDT_Int32) {
memcpy(databuffer, data.get(), sizeof(int) * datarows * datacols);
}
else {
for (long i = 0; i < datarows; i++) {
for (long j = 0; j < datacols; j++) {
databuffer[i * datacols + j] = data.get()[i * datacols + j];
}
}
}
// poDstDS->RasterIO(GF_Write,start_col, start_row, datacols, datarows, databuffer, datacols,
// datarows, GDT_Float32,band_ids, num,0,0,0);
poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_col, start_row, datacols, datarows,
databuffer, datacols, datarows, datetype, 0, 0);
GDALFlushCache(poDstDS);
GDALClose((GDALDatasetH)poDstDS);
// GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH
delete[] databuffer;
omp_unset_lock(&lock); // 锟酵放伙拷斤拷
omp_destroy_lock(&lock); // 劫伙拷斤拷
}
void gdalImage::saveImage()
{
this->saveImage(this->data, this->start_row, this->start_col, this->data_band_ids);
@ -1500,7 +1902,8 @@ int ResampleGDAL(const char* pszSrcFile, const char* pszOutFile, double* gt, int
pDDst->SetGeoTransform(gt);
GDALWarpOptions* psWo = GDALCreateWarpOptions();
CPLSetConfigOption("GDAL_NUM_THREADS", "ALL_CPUS"); // 使用所有可用的CPU核心
CPLSetConfigOption("GDAL_CACHEMAX", "16000"); // 设置缓存大小为500MB
// psWo->papszWarpOptions = CSLDuplicate(NULL);
psWo->eWorkingDataType = dataType;
psWo->eResampleAlg = eResample;

View File

@ -71,14 +71,14 @@ enum GDALREADARRCOPYMETHOD {
VARIABLEMETHOD // 变量赋值
};
class BASECONSTVARIABLEAPI ShowProessAbstract{
class BASECONSTVARIABLEAPI ShowProessAbstract {
public:
virtual void showProcess(double precent,QString tip);
virtual void showToolInfo( QString tip) ;
virtual void showProcess(double precent, QString tip);
virtual void showToolInfo(QString tip);
};
@ -91,7 +91,7 @@ public:
/// \param long 经度
/// \param lat 纬度
/// \return 对应投影坐标系统的 EPSG编码,-1 表示计算错误
long BASECONSTVARIABLEAPI getProjectEPSGCodeByLon_Lat(double long, double lat,ProjectStripDelta stripState );
long BASECONSTVARIABLEAPI getProjectEPSGCodeByLon_Lat(double long, double lat, ProjectStripDelta stripState);
long BASECONSTVARIABLEAPI getProjectEPSGCodeByLon_Lat_inStrip3(double lon, double lat);
@ -106,15 +106,15 @@ long BASECONSTVARIABLEAPI GetEPSGFromRasterFile(QString filepath);
std::shared_ptr<PointRaster> BASECONSTVARIABLEAPI GetCenterPointInRaster(QString filepath);
CoordinateSystemType BASECONSTVARIABLEAPI getCoordinateSystemTypeByEPSGCode(long EPSGCODE);
// 文件打开 // 当指令销毁时调用GDALClose 销毁类型
std::shared_ptr<GDALDataset> BASECONSTVARIABLEAPI OpenDataset(const QString& in_path, GDALAccess rwmode= GA_ReadOnly);
std::shared_ptr<GDALDataset> BASECONSTVARIABLEAPI OpenDataset(const QString& in_path, GDALAccess rwmode = GA_ReadOnly);
void BASECONSTVARIABLEAPI CloseDataset(GDALDataset* ptr);
// 数据格式转换
int BASECONSTVARIABLEAPI TIFF2ENVI(QString in_tiff_path,QString out_envi_path);
int BASECONSTVARIABLEAPI ENVI2TIFF(QString in_envi_path,QString out_tiff_path);
int BASECONSTVARIABLEAPI TIFF2ENVI(QString in_tiff_path, QString out_envi_path);
int BASECONSTVARIABLEAPI ENVI2TIFF(QString in_envi_path, QString out_tiff_path);
// 保存影像数据 --直接保存 ENVI 文件
@ -123,12 +123,12 @@ int BASECONSTVARIABLEAPI CreateDataset(QString new_file_path, int height, in
int BASECONSTVARIABLEAPI saveDataset(QString new_file_path, int start_line, int start_cols, int band_ids, int datacols, int datarows, void* databuffer);
// 根据限制条件估算分块大小
int BASECONSTVARIABLEAPI block_num_pre_memory(int width, int height, GDALDataType gdal_dtype,double memey_size);
int BASECONSTVARIABLEAPI block_num_pre_memory(int width, int height, GDALDataType gdal_dtype, double memey_size);
// 将结果转换为复数 或者 实数
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> BASECONSTVARIABLEAPI ReadComplexMatrixData(int start_line,int width, int line_num, std::shared_ptr<GDALDataset> rasterDataset, GDALDataType gdal_datatype);
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> BASECONSTVARIABLEAPI ReadComplexMatrixData(int start_line, int width, int line_num, std::shared_ptr<GDALDataset> rasterDataset, GDALDataType gdal_datatype);
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> BASECONSTVARIABLEAPI ReadMatrixDoubleData(int start_line, int width, int line_num, std::shared_ptr<GDALDataset> rasterDataset, GDALDataType gdal_datatype,int band_idx);
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> BASECONSTVARIABLEAPI ReadMatrixDoubleData(int start_line, int width, int line_num, std::shared_ptr<GDALDataset> rasterDataset, GDALDataType gdal_datatype, int band_idx);
Eigen::MatrixXd BASECONSTVARIABLEAPI getGeoTranslationArray(QString in_path);
ImageGEOINFO BASECONSTVARIABLEAPI getImageINFO(QString in_path);
@ -143,7 +143,7 @@ struct RasterExtend {
double max_y;//经度
};
@ -161,15 +161,23 @@ public: // 方法
virtual void setHeight(int);
virtual void setWidth(int);
virtual void setTranslationMatrix(Eigen::MatrixXd gt);
virtual void setData(Eigen::MatrixXd,int data_band_ids=1);
virtual void setData(Eigen::MatrixXd, int data_band_ids = 1);
virtual Eigen::MatrixXd getData(int start_row, int start_col, int rows_count, int cols_count, int band_ids);
virtual Eigen::MatrixXf getDataf(int start_row, int start_col, int rows_count, int cols_count, int band_ids);
virtual Eigen::MatrixXi getDatai(int start_row, int start_col, int rows_count, int cols_count, int band_ids);
virtual ErrorCode getData(double* data, int start_row, int start_col, int rows_count, int cols_count, int band_ids);
virtual ErrorCode getData(long* data, int start_row, int start_col, int rows_count, int cols_count, int band_ids);
virtual Eigen::MatrixXd getGeoTranslation();
virtual GDALDataType getDataType();
virtual void saveImage(Eigen::MatrixXd, int start_row, int start_col, int band_ids);
virtual void saveImage(Eigen::MatrixXf, int start_row, int start_col, int band_ids);
virtual void saveImage(Eigen::MatrixXi, int start_row, int start_col, int band_ids);
virtual void saveImage(std::shared_ptr<double>, int start_row, int start_col,int rowcount,int colcount, int band_ids);
virtual void saveImage(std::shared_ptr<float>, int start_row, int start_col, int rowcount, int colcount, int band_ids);
virtual void saveImage(std::shared_ptr<int>, int start_row, int start_col, int rowcount, int colcount, int band_ids);
virtual void saveImage();
virtual void setNoDataValue(double nodatavalue, int band_ids);
virtual void setNoDataValuei(int nodatavalue, int band_ids);
@ -186,7 +194,7 @@ public: // 方法
double BandminValue(int bandids = 1);
virtual GDALRPCInfo getRPC();
virtual Eigen::MatrixXd getLandPoint(Eigen::MatrixXd points);
virtual Eigen::MatrixXd getHist(int bandids);
virtual RasterExtend getExtend();
@ -210,7 +218,7 @@ public:
/// <summary>
/// gdalImage图像操作类
/// </summary>
class BASECONSTVARIABLEAPI gdalImageComplex:public gdalImage
class BASECONSTVARIABLEAPI gdalImageComplex :public gdalImage
{
public: // 方法
@ -219,7 +227,7 @@ public: // 方法
void setData(Eigen::MatrixXcd);
void saveImage(Eigen::MatrixXcd data, int start_row, int start_col, int band_ids);
Eigen::MatrixXcd getDataComplex(int start_row, int start_col, int rows_count, int cols_count, int band_ids);
void saveImage() override;
void savePreViewImage();
public:
@ -230,7 +238,7 @@ public:
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);
gdalImage BASECONSTVARIABLEAPI CreategdalImage(const QString& img_path, int height, int width, int band_num, Eigen::MatrixXd gt, long espgcode, GDALDataType eType=GDT_Float32, 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, long espgcode, GDALDataType eType = GDT_Float32, bool need_gt = true, bool overwrite = false, bool isENVI = false);
gdalImageComplex BASECONSTVARIABLEAPI CreategdalImageComplex(const QString& img_path, int height, int width, int band_num, Eigen::MatrixXd gt, QString projection, bool need_gt = true, bool overwrite = false);
@ -255,7 +263,7 @@ int BASECONSTVARIABLEAPI alignRaster(QString inputPath, QString referencePath
//--------------------- 保存文博 -------------------------------
int BASECONSTVARIABLEAPI saveMatrixXcd2TiFF(Eigen::MatrixXcd data, QString out_tiff_path);
//----------------------------------------------------
void BASECONSTVARIABLEAPI clipRaster(QString inRasterPath, QString outRasterPath, long minRow, long maxRow, long minCol, long maxCol);
@ -270,11 +278,11 @@ enum MERGEMODE
};
ErrorCode BASECONSTVARIABLEAPI MergeRasterProcess(QVector<QString> filepath, QString outfileptah, QString mainString, MERGEMODE mergecode = MERGEMODE::MERGE_GEOCODING, bool isENVI = false, ShowProessAbstract* dia=nullptr);
ErrorCode BASECONSTVARIABLEAPI MergeRasterProcess(QVector<QString> filepath, QString outfileptah, QString mainString, MERGEMODE mergecode = MERGEMODE::MERGE_GEOCODING, bool isENVI = false, ShowProessAbstract* dia = nullptr);
ErrorCode BASECONSTVARIABLEAPI MergeRasterInGeoCoding(QVector<gdalImage> inimgs, gdalImage resultimg,gdalImage maskimg, ShowProessAbstract* dia = nullptr);
ErrorCode BASECONSTVARIABLEAPI MergeRasterInGeoCoding(QVector<gdalImage> inimgs, gdalImage resultimg, gdalImage maskimg, ShowProessAbstract* dia = nullptr);
// 保存矩阵转换为envi文件默认数据格式为double
bool BASECONSTVARIABLEAPI saveEigenMatrixXd2Bin(Eigen::MatrixXd data, QString dataStrPath);
@ -293,7 +301,7 @@ void BASECONSTVARIABLEAPI testOutClsArr(QString filename, long* amp, long rowc
//--------------------- 图像文件读写 ------------------------------
template<typename T>
inline std::shared_ptr<T> readDataArr(gdalImage& imgds, int start_row, int start_col, int rows_count, int cols_count, int band_ids, GDALREADARRCOPYMETHOD method)
inline std::shared_ptr<T> readDataArr(gdalImage& imgds, int start_row, int start_col, int& rows_count, int& cols_count, int band_ids, GDALREADARRCOPYMETHOD method)
{
std::shared_ptr<T> result = nullptr;
@ -492,7 +500,7 @@ inline std::shared_ptr<T> readDataArr(gdalImage& imgds, int start_row, int start
}
template<typename T>
inline std::shared_ptr<T> readDataArrComplex(gdalImageComplex& imgds, int start_row, int start_col, int rows_count, int cols_count, int band_ids, GDALREADARRCOPYMETHOD method)
inline std::shared_ptr<T> readDataArrComplex(gdalImageComplex& imgds, int start_row, int start_col, int& rows_count, int& cols_count, int band_ids, GDALREADARRCOPYMETHOD method)
{
std::shared_ptr<T> result = nullptr;
@ -565,6 +573,8 @@ inline std::shared_ptr<T> readDataArrComplex(gdalImageComplex& imgds, int start_
}
//--------------------- 图像分块 ------------------------------

View File

@ -0,0 +1,7 @@
#include "PrintMsgToQDebug.h"
#include <QDebug>
BASECONSTVARIABLEAPI void PrintMsgToQDebug(char* msg)
{
qDebug() << QString(msg);
return ;
}

View File

@ -0,0 +1,10 @@
#pragma once
#ifndef PRINTMSGTOQDEBUG_H_
#define PRINTMSGTOQDEBUG_H_
#include "BaseConstVariable.h"
extern "C" BASECONSTVARIABLEAPI void PrintMsgToQDebug(char* msg);
#endif // !PRINTMSGTOQDEBUG_H_

View File

@ -148,6 +148,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="RasterProcessToolWidgetAPI.h" />
<ClInclude Include="RasterProcessToolWidgetCFunAPI.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">

View File

@ -64,5 +64,8 @@
<ClInclude Include="RasterProcessToolWidgetAPI.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RasterProcessToolWidgetCFunAPI.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,12 @@
#pragma once
#ifndef RASTERPROCESSTOOLWIDGETCFUNAPI_H_
#define RASTERPROCESSTOOLWIDGETCFUNAPI_H_
#ifdef RASTERPROCESSTOOLWIDGET_LIB
#define RASTERPROCESSTOOLWIDGETCFUNAPI_EXPORT __declspec(dllexport)
#else
#define RASTERPROCESSTOOLWIDGETCFUNAPI_EXPORT __declspec(dllimport)
#endif
#endif

View File

@ -0,0 +1,10 @@
#include "PrintMessage_C.h"
#include <QDebug>
RASTERMAINWIDGETGUICFUNAPI_EXPORT void PrintMessageWindowsShow_C_Fun(char* msg)
{
qDebug() << QString(msg);
return ;
}

View File

@ -0,0 +1,13 @@
#pragma once
#ifndef PRINTMESSAGE_C_H_
#define PRINTMESSAGE_C_H_
#include "RasterMainWidgetGUICFunAPI.h"
extern "C" RASTERMAINWIDGETGUICFUNAPI_EXPORT void PrintMessageWindowsShow_C_Fun(char* msg);
#endif

View File

@ -99,6 +99,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="PrintMessage_C.cpp" />
<ClCompile Include="RasterMainWidget\crs.cpp" />
<ClCompile Include="RasterMainWidget\gaodenormalprovider.cpp" />
<ClCompile Include="RasterMainWidget\imgwriter.cpp" />
@ -135,7 +136,9 @@
<QtUic Include="RasterMainWidget\taskwindow.ui" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="PrintMessage_C.h" />
<ClInclude Include="RasterMainWidgetGUIAPI.h" />
<ClInclude Include="RasterMainWidgetGUICFunAPI.h" />
<ClInclude Include="RasterMainWidget\crs.h" />
<ClInclude Include="RasterMainWidget\gaodesatelliteprovider.h" />
<ClInclude Include="RasterMainWidget\googlechinanormalprovider.h" />

View File

@ -118,6 +118,9 @@
<ClCompile Include="RasterWidgetMessageShow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PrintMessage_C.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="RasterMainWidget\crs.h">
@ -201,6 +204,12 @@
<ClInclude Include="RasterMainWidgetGUIAPI.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PrintMessage_C.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RasterMainWidgetGUICFunAPI.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<QtMoc Include="RasterMainWidget\gaodenormalprovider.h">

View File

@ -0,0 +1,11 @@
#pragma once
#ifndef RASTERMAINWIDGETGUICFUNAPI_H_
#define RASTERMAINWIDGETGUICFUNAPI_H_
#ifdef RASTERMAINWIDGETGUI_LIB
#define RASTERMAINWIDGETGUICFUNAPI_EXPORT __declspec(dllexport)
#else
#define RASTERMAINWIDGETGUICFUNAPI_EXPORT __declspec(dllimport)
#endif
#endif

View File

@ -1,17 +1,44 @@
#include "LookTableComputerClass.h"
#include "SatelliteOribtModel.h"
#include "SARSimulationTaskSetting.h"
#include "ImageOperatorBase.h"
#include "FileOperator.h"
#include "BaseConstVariable.h"
#include "GPUTool.cuh"
#include <QDebug>
// dingy
namespace LookTableSimualtionMainProcessSpace {
void LookTableSimualtionMainProcess(QString orbitpath, QString SatePath, QString DEMPath, QString outDirPath,
double gridX, double gridY, bool gpuflag, bool looktableflag, bool checkBoxIncAngle, bool BoxDopplerFlag)
void LookTableSimualtionMainProcess(
QString sateName,
QString orbitpath, QString SatePath, QString DEMPath, QString outDirPath,
bool gpuflag,
bool looktableflag,
bool checkBoxIncAngle,
bool DopplerFlag)
{
if (!isExists(orbitpath)) {
qDebug() << "Orbit model file is not exist !!!";
return;
}
if (!isExists(SatePath)) {
qDebug() << "Satellite Model file is not exist !!!";
return;
}
if (!isExists(DEMPath)) {
qDebug() << "DEM file is not exist !!!";
return;
}
// 读取轨道模型
qDebug() << "load orbit model params from xml :" << orbitpath;
PolyfitSatelliteOribtModel orbitmodel;
@ -19,12 +46,12 @@ namespace LookTableSimualtionMainProcessSpace {
// 轨道参数
long double OribtStartTime = orbitmodel.getOribtStartTime();
std::vector<double> PolyfitPx = orbitmodel.getPolyfitPx();
std::vector<double> PolyfitPy = orbitmodel.getPolyfitPy();
std::vector<double> PolyfitPz = orbitmodel.getPolyfitPz();
std::vector<double> PolyfitVx = orbitmodel.getPolyfitVx();
std::vector<double> PolyfitVy = orbitmodel.getPolyfitVy();
std::vector<double> PolyfitVz = orbitmodel.getPolyfitVz();
std::vector<double> PolyfitPx = orbitmodel.getPolyfitPx();
std::vector<double> PolyfitPy = orbitmodel.getPolyfitPy();
std::vector<double> PolyfitPz = orbitmodel.getPolyfitPz();
std::vector<double> PolyfitVx = orbitmodel.getPolyfitVx();
std::vector<double> PolyfitVy = orbitmodel.getPolyfitVy();
std::vector<double> PolyfitVz = orbitmodel.getPolyfitVz();
// 参数模型
@ -36,11 +63,248 @@ namespace LookTableSimualtionMainProcessSpace {
std::vector<double> DopplerCentroidCoefficients = SARSetting->getDopplerCentroidCoefficients();
std::vector<double> DopplerRateValuesCoefficient = SARSetting->getDopplerRateValuesCoefficients();
// ĘýžÝ´ŚŔí
// 仿真成像参数计算
double startTime = SARSetting->getSARImageStartTime();
double endTime = SARSetting->getSARImageStartTime();
double PRF = SARSetting->getPRF();
double Fs = SARSetting->getFs();
double nearRange = SARSetting->getNearRange();
double farRange = SARSetting->getFarRange();
double lamda = SARSetting->getCenterLamda();
// 输出结果处理
QString outLookTablePath = "";
QString outIncPath = "";
gdalImage demimg(DEMPath);
if (looktableflag|| checkBoxIncAngle) {
outLookTablePath = JoinPath(outDirPath, sateName+"__looktable.bin");
LookTableSimulationDopplerProcess(
DEMPath, outLookTablePath,
OribtStartTime,
PolyfitPx, PolyfitPy, PolyfitPz,
PolyfitVx, PolyfitVy, PolyfitVz,
dopplerRefrenceTime,
DopplerCentroidCoefficients,
startTime,
endTime,
nearRange,
farRange,
PRF,
Fs,
lamda,
gpuflag,
looktableflag,
checkBoxIncAngle
);
}
if (checkBoxIncAngle) {
outIncPath = JoinPath(outDirPath, sateName + "__incAngle.bin");
}
}
void LookTableSimulationDopplerProcess(
QString DEMPath,
QString outLookTablePath,
long double OribtStartTime,
std::vector<double> PolyfitPx,
std::vector<double> PolyfitPy,
std::vector<double> PolyfitPz,
std::vector<double> PolyfitVx,
std::vector<double> PolyfitVy,
std::vector<double> PolyfitVz,
double dopplerRefrenceTime,
std::vector<double>
DopplerCentroidCoefficients,
double starttime,
double endtime,
double nearRange,
double farRange,
double PRF,
double Fs,
double lamda,
bool gpuflag,
bool looktableflag,
bool incflag
)
{
qDebug() << "generate look table ";
qDebug() << "DEMPath\t" << DEMPath;
qDebug() << "outLookTablePath\t" << outLookTablePath;
gdalImage demimg(DEMPath);
gdalImage outLookTable = CreategdalImage( // 创建查找表
outLookTablePath,
demimg.height, demimg.width, 2,
demimg.gt,
demimg.projection,
true,
true,
true
);
starttime = starttime - OribtStartTime; // 处理坐标时间
endtime = endtime - OribtStartTime;
// 轨道模型
double Xp0=0,Yp0=0,Zp0=0,Xv0=0,Yv0=0,Zv0=0;
double Xp1=0,Yp1=0,Zp1=0,Xv1=0,Yv1=0,Zv1=0;
double Xp2=0,Yp2=0,Zp2=0,Xv2=0,Yv2=0,Zv2=0;
double Xp3=0,Yp3=0,Zp3=0,Xv3=0,Yv3=0,Zv3=0;
double Xp4=0,Yp4=0,Zp4=0,Xv4=0,Yv4=0,Zv4=0;
double Xp5=0,Yp5=0,Zp5=0,Xv5=0,Yv5=0,Zv5=0;
int degree = PolyfitPx.size();
switch (degree){
case(6):
Xp5 = PolyfitPx[5];
Yp5 = PolyfitPy[5];
Zp5 = PolyfitPz[5];
Xv5 = PolyfitVx[5];
Yv5 = PolyfitVy[5];
Zv5 = PolyfitVz[5];
case(5):
Xp4 = PolyfitPx[4];
Yp4 = PolyfitPy[4];
Zp4 = PolyfitPz[4];
Xv4 = PolyfitVx[4];
Yv4 = PolyfitVy[4];
Zv4 = PolyfitVz[4];
case(4):
Xp3 = PolyfitPx[3];
Yp3 = PolyfitPy[3];
Zp3 = PolyfitPz[3];
Xv3 = PolyfitVx[3];
Yv3 = PolyfitVy[3];
Zv3 = PolyfitVz[3];
case(3):
Xp2 = PolyfitPx[2];
Yp2 = PolyfitPy[2];
Zp2 = PolyfitPz[2];
Xv2 = PolyfitVx[2];
Yv2 = PolyfitVy[2];
Zv2 = PolyfitVz[2];
case(2):
Xp1 = PolyfitPx[1];
Yp1 = PolyfitPy[1];
Zp1 = PolyfitPz[1];
Xv1 = PolyfitVx[1];
Yv1 = PolyfitVy[1];
Zv1 = PolyfitVz[1];
case(1):
Xp0 = PolyfitPx[0];
Yp0 = PolyfitPy[0];
Zp0 = PolyfitPz[0];
Xv0 = PolyfitVx[0];
Yv0 = PolyfitVy[0];
Zv0 = PolyfitVz[0];
default:
break;
}
// 多普勒参数
double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0;
degree = DopplerCentroidCoefficients.size();
switch (degree)
{
case(5):
r4 = DopplerCentroidCoefficients[4];
case(4):
r3 = DopplerCentroidCoefficients[3];
case(3):
r2 = DopplerCentroidCoefficients[2];
case(2):
r1 = DopplerCentroidCoefficients[1];
case(1):
r0 = DopplerCentroidCoefficients[0];
default:
break;
}
// 处理分块
long GPUMemoryline = floor((Memory1MB * 2.0 / 8.0/3.0 / demimg.width*1000));//2GB
GPUMemoryline = GPUMemoryline < 1 ? 1 : GPUMemoryline;
// 内存预分配
//
std::shared_ptr<float> host_Rid((float*)mallocCUDAHost(sizeof(float) * GPUMemoryline * demimg.width), FreeCUDAHost);
std::shared_ptr<float> host_Cid((float*)mallocCUDAHost(sizeof(float) * GPUMemoryline * demimg.width), FreeCUDAHost);
std::shared_ptr<float> device_Rid((float*)mallocCUDADevice(sizeof(float) * GPUMemoryline * demimg.width), FreeCUDADevice);
std::shared_ptr<float> device_Cid((float*)mallocCUDADevice(sizeof(float) * GPUMemoryline * demimg.width), FreeCUDADevice);
//
std::shared_ptr<double> host_demX((double*)mallocCUDAHost(sizeof(double) * GPUMemoryline * demimg.width), FreeCUDAHost);
std::shared_ptr<double> host_demY((double*)mallocCUDAHost(sizeof(double) * GPUMemoryline * demimg.width), FreeCUDAHost);
std::shared_ptr<double> host_demZ((double*)mallocCUDAHost(sizeof(double) * GPUMemoryline * demimg.width), FreeCUDAHost);
std::shared_ptr<double> device_demX((double*)mallocCUDADevice(sizeof(double) * GPUMemoryline * demimg.width), FreeCUDADevice);
std::shared_ptr<double> device_demY((double*)mallocCUDADevice(sizeof(double) * GPUMemoryline * demimg.width), FreeCUDADevice);
std::shared_ptr<double> device_demZ((double*)mallocCUDADevice(sizeof(double) * GPUMemoryline * demimg.width), FreeCUDADevice);
// 处理复制结果
int rowcount = 0;
int colcount = 0;
for (long rid = 0; rid < demimg.height; rid = rid + GPUMemoryline) {
rowcount = GPUMemoryline;
colcount = demimg.width;
std::shared_ptr<double> demX = readDataArr<double>(demimg, rid, 0, rowcount, colcount, 1,GDALREADARRCOPYMETHOD::MEMCPYMETHOD);// 行列数修改
std::shared_ptr<double> demY = readDataArr<double>(demimg, rid, 0, rowcount, colcount, 2,GDALREADARRCOPYMETHOD::MEMCPYMETHOD);
std::shared_ptr<double> demZ = readDataArr<double>(demimg, rid, 0, rowcount, colcount, 3,GDALREADARRCOPYMETHOD::MEMCPYMETHOD);
// 数据复制
memcpy(host_demX.get(), demX.get(), sizeof(double)* rowcount* colcount);
memcpy(host_demY.get(), demY.get(), sizeof(double)* rowcount* colcount);
memcpy(host_demZ.get(), demZ.get(), sizeof(double)* rowcount* colcount);
//内存->GPU
HostToDevice(host_demX.get(), device_demX.get(), sizeof(double)* GPUMemoryline* demimg.width);
HostToDevice(host_demY.get(), device_demY.get(), sizeof(double)* GPUMemoryline* demimg.width);
HostToDevice(host_demZ.get(), device_demZ.get(), sizeof(double)* GPUMemoryline* demimg.width);
// GPU -> 内存
DeviceToHost(host_Rid.get(), device_Rid.get(), sizeof(float)* GPUMemoryline* demimg.width);
DeviceToHost(host_Cid.get(), device_Cid.get(), sizeof(float)* GPUMemoryline* demimg.width);
// 数据存储
outLookTable.saveImage(host_Rid, rid, 0, rowcount, colcount,1);
outLookTable.saveImage(host_Cid, rid, 0, rowcount, colcount,2);
}
qDebug() << "look table computed finished!!!";
}
void LocalIncidenceAngleSimulationCompter(QString DEMPath, QString LookTablePath, QString outIncPath, long double OribtStartTime, std::vector<double> PolyfitPx, std::vector<double> PolyfitPy, std::vector<double> PolyfitPz, std::vector<double> PolyfitVx, std::vector<double> PolyfitVy, std::vector<double> PolyfitVz, double starttime, double endtime, double nearRange, double farRange, double PRF, double Fs)
{
//gdalImage outInc = CreategdalImageDouble(
// outIncPath,
// demimg.height, demimg.width, 1,
// demimg.gt,
// demimg.projection,
// true,
// true,
// true
//);
}
}

View File

@ -2,7 +2,7 @@
#include <QString>
#include <stdio.h>
#include <memory>
#include <vector>
/**
@ -21,9 +21,66 @@
namespace LookTableSimualtionMainProcessSpace {
void LookTableSimualtionMainProcess(QString orbitpath, QString SatePath, QString DEMPath, QString outDirPath
, double gridX, double gridY, bool gpuflag, bool looktableflag, bool checkBoxIncAngle, bool BoxDopplerFlag
void LookTableSimualtionMainProcess(
QString sateName,
QString orbitpath, QString SatePath, QString DEMPath, QString outDirPath
, bool gpuflag, bool looktableflag, bool checkBoxIncAngle, bool DopplerFlag
);
void LookTableSimulationDopplerProcess(
QString DEMPath,
QString outLookTablePath,
// 多项式轨道参数
long double OribtStartTime, // 轨道模型参考时间
std::vector<double> PolyfitPx , // 5次项空余填0
std::vector<double> PolyfitPy , // 5次项空余填0
std::vector<double> PolyfitPz , // 5次项空余填0
std::vector<double> PolyfitVx , // 5次项空余填0
std::vector<double> PolyfitVy , // 5次项空余填0
std::vector<double> PolyfitVz , // 5次项空余填0
// 多普勒参数
double dopplerRefrenceTime,
std::vector<double> DopplerCentroidCoefficients,// d0 ~ d5 空余填零
// 其他成像参数
double starttime, // 成像开始时间
double endtime, // 成像结束时间
double nearRange, // 近斜距
double farRange, // 远斜距
double PRF, // 脉冲重复采样频率
double Fs, // 距离采样频率
double lamda,
bool gpuflag,
bool looktableflag,
bool incflag
);
void LocalIncidenceAngleSimulationCompter(
QString DEMPath,
QString LookTablePath,
QString outIncPath,
long double OribtStartTime, // 轨道模型参考时间
std::vector<double> PolyfitPx, // 5次项空余填0
std::vector<double> PolyfitPy, // 5次项空余填0
std::vector<double> PolyfitPz, // 5次项空余填0
std::vector<double> PolyfitVx, // 5次项空余填0
std::vector<double> PolyfitVy, // 5次项空余填0
std::vector<double> PolyfitVz, // 5次项空余填0
double starttime, // 成像开始时间
double endtime, // 成像结束时间
double nearRange, // 近斜距
double farRange, // 远斜距
double PRF, // 脉冲重复采样频率
double Fs // 距离采样频率
);
}

View File

@ -0,0 +1,37 @@
#include <time.h>
#include <iostream>
#include <memory>
#include <cmath>
#include <complex>
#include <device_launch_parameters.h>
#include <cuda_runtime.h>
#include <cublas_v2.h>
#include <cuComplex.h>
#include "BaseConstVariable.h"
#include "LookTableSimulationComputer.cuh"
extern __device__ __host__ double getNumberDopplerCenterRate(double R, double r0, double r1, double r2, double r3, double r4, double reftime)
{
double t=R / LIGHTSPEED - reftime;
double dopplerCenterRate = r0 + r1*t + r2*t*t + r3*t*t*t + r4*t*t*t*t;
return dopplerCenterRate;
}
__device__ __host__ double getDopplerCenterRate(double Rx, double Ry, double Rz, double Vx, double Vy, double Vz, double lamda)
{
return __device__ __host__ double();
}
__device__ __host__ double getPolyfitNumber(double x, double a0, double a1, double a2, double a3, double a4, double a5)
{
return a0 + a1 * x + a2 * x * x + a3 * x * x * x + a4 * x * x * x * x + a5 * x * x * x * x * x;
}

View File

@ -0,0 +1,37 @@
#include "GPUTool.cuh"
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <cublas_v2.h>
#include "BaseConstVariable.h"
extern __device__ __host__ double getNumberDopplerCenterRate(double R, double r0, double r1, double r2, double r3, double r4,double reftime);
extern __device__ __host__ double getDopplerCenterRate(double Rx,double Ry,double Rz,double Vx,double Vy,double Vz,double lamda);
extern __device__ __host__ double getPolyfitNumber(double x, double a0, double a1, double a2, double a3, double a4,double a5);
//
extern "C" void RDProcess_doppler(
);

View File

@ -90,17 +90,18 @@ void QSimulationLookTableDialog::onaccepted()
QString DEMPath = this->ui->DEMLineEdit->text();
QString outDirPath = this->ui->outDirLineEdit->text();
double gridX = this->ui->doubleSpinBoxGridX->value();
double gridY = this->ui->doubleSpinBoxGridY->value();
//double gridX = this->ui->doubleSpinBoxGridX->value();
//double gridY = this->ui->doubleSpinBoxGridY->value();
bool gpuflag = this->ui->radioButtonGPU->isChecked();
bool looktableflag = this->ui->LookTableCheck->isChecked();
bool checkBoxIncAngle = this->ui->checkBoxIncAngle->isChecked();
bool BoxDopplerFlag = this->ui->checkBoxDoppler->isChecked();
QString simulationName = this->ui->lineEditLookName->text();
LookTableSimualtionMainProcessSpace::LookTableSimualtionMainProcess(
orbitpath, SatePath, DEMPath, outDirPath
, gridX, gridY, gpuflag, looktableflag, checkBoxIncAngle, BoxDopplerFlag
simulationName,
orbitpath, SatePath, DEMPath, outDirPath,
gpuflag, looktableflag, checkBoxIncAngle, BoxDopplerFlag
);

View File

@ -23,7 +23,7 @@
</size>
</property>
<property name="text">
<string>DEM文件</string>
<string>DEM文件(XYZ)</string>
</property>
</widget>
</item>
@ -37,7 +37,7 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QLineEdit" name="outDirLineEdit">
<property name="minimumSize">
<size>
@ -89,7 +89,7 @@
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -102,6 +102,16 @@
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkBoxDoppler">
<property name="text">
<string>采用多普勒参数</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="SateSettingLineEdit">
<property name="minimumSize">
@ -141,7 +151,7 @@
</property>
</widget>
</item>
<item row="4" column="2">
<item row="5" column="2">
<widget class="QPushButton" name="pushButtonOutDir">
<property name="minimumSize">
<size>
@ -154,7 +164,7 @@
</property>
</widget>
</item>
<item row="5" column="0" rowspan="2">
<item row="6" column="0" rowspan="2">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>计算资源</string>
@ -171,6 +181,9 @@
<property name="text">
<string>GPU</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
@ -189,7 +202,7 @@
</layout>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -215,7 +228,7 @@
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>产品输出类型</string>
@ -232,6 +245,9 @@
<property name="text">
<string>查找表</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
@ -245,19 +261,22 @@
<property name="text">
<string>局地入射角</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="8" column="0" colspan="3">
<item row="9" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_9">
<property name="minimumSize">
<size>
@ -270,13 +289,29 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkBoxDoppler">
<property name="text">
<string>采用多普勒参数</string>
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="checked">
<bool>true</bool>
<property name="text">
<string>查找表名</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lineEditLookName">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>

View File

@ -127,6 +127,7 @@
<ClCompile Include="SimulationSAR\TBPImageAlgCls.cpp" />
<QtMoc Include="PowerSimulationIncoherent\QSimulationSARPolynomialOrbitModel.h" />
<ClInclude Include="PowerSimulationIncoherent\LookTableComputerClass.h" />
<CudaCompile Include="PowerSimulationIncoherent\LookTableSimulationComputer.cuh" />
<ClInclude Include="PowerSimulationIncoherent\OribtModelOperator.h" />
<QtMoc Include="PowerSimulationIncoherent\QSimulationLookTableDialog.h" />
<ClInclude Include="SimulationSARToolAPI.h" />
@ -145,6 +146,7 @@
<ClCompile Include="SimulationSARTool.cpp" />
</ItemGroup>
<ItemGroup>
<CudaCompile Include="PowerSimulationIncoherent\LookTableSimulationComputer.cu" />
<CudaCompile Include="SimulationSAR\GPURFPC.cu">
<FileType>Document</FileType>
</CudaCompile>

View File

@ -163,5 +163,11 @@
<CudaCompile Include="SimulationSAR\GPUTBPImage.cuh">
<Filter>SimulationSAR</Filter>
</CudaCompile>
<CudaCompile Include="PowerSimulationIncoherent\LookTableSimulationComputer.cu">
<Filter>PowerSimulationIncoherent</Filter>
</CudaCompile>
<CudaCompile Include="PowerSimulationIncoherent\LookTableSimulationComputer.cuh">
<Filter>PowerSimulationIncoherent</Filter>
</CudaCompile>
</ItemGroup>
</Project>