516 lines
17 KiB
C++
516 lines
17 KiB
C++
#include "stdafx.h"
|
|
#include "SARSimulationImageL1.h"
|
|
#include "LogInfoCls.h"
|
|
#include <memory>
|
|
#include <QFile>
|
|
#include <QDomDocument>
|
|
#include <QXmlStreamReader>
|
|
|
|
SARSimulationImageL1Dataset::SARSimulationImageL1Dataset()
|
|
{
|
|
}
|
|
|
|
SARSimulationImageL1Dataset::~SARSimulationImageL1Dataset()
|
|
{
|
|
}
|
|
|
|
QString SARSimulationImageL1Dataset::getoutFolderPath()
|
|
{
|
|
return outFolderPath;
|
|
}
|
|
|
|
QString SARSimulationImageL1Dataset::getDatesetName()
|
|
{
|
|
return L1DatasetName;
|
|
}
|
|
|
|
QString SARSimulationImageL1Dataset::getxmlfileName()
|
|
{
|
|
return xmlfileName;
|
|
}
|
|
|
|
QString SARSimulationImageL1Dataset::getxmlFilePath()
|
|
{
|
|
return xmlFilePath;
|
|
}
|
|
|
|
QString SARSimulationImageL1Dataset::getImageRasterName()
|
|
{
|
|
return ImageRasterName;
|
|
}
|
|
|
|
QString SARSimulationImageL1Dataset::getImageRasterPath()
|
|
{
|
|
return ImageRasterPath;
|
|
}
|
|
|
|
QString SARSimulationImageL1Dataset::getGPSPointFilename()
|
|
{
|
|
return GPSPointFilename;
|
|
}
|
|
|
|
QString SARSimulationImageL1Dataset::getGPSPointFilePath()
|
|
{
|
|
return GPSPointFilePath;
|
|
}
|
|
|
|
ErrorCode SARSimulationImageL1Dataset::OpenOrNew(QString folder, QString filename, long inrowCount, long incolCount)
|
|
{
|
|
qDebug() << "--------------Image Raster L1 Data OpenOrNew ---------------------------------------";
|
|
qDebug() << "Folder: " << folder;
|
|
qDebug() << "Filename: " << filename;
|
|
QDir dir(folder);
|
|
if (dir.exists() == false)
|
|
{
|
|
dir.mkpath(folder);
|
|
}
|
|
else {}
|
|
|
|
if (dir.exists() == false) {
|
|
return ErrorCode::FOLDER_NOT_EXIST;
|
|
}
|
|
else {}
|
|
QString filePath = dir.filePath(filename); // Éú³ÉÍêÕûµÄÎļþ·¾¶
|
|
this->rowCount = inrowCount;
|
|
this->colCount = incolCount;
|
|
|
|
this->outFolderPath = folder;
|
|
this->L1DatasetName = filename;
|
|
|
|
this->xmlfileName = filename + ".xml";
|
|
this->GPSPointFilename = filename + ".gpspos.data";
|
|
this->ImageRasterName = filename + ".bin";
|
|
|
|
this->xmlFilePath = dir.filePath(this->xmlfileName);
|
|
this->GPSPointFilePath = dir.filePath(this->GPSPointFilename);
|
|
this->ImageRasterPath = dir.filePath(this->ImageRasterName);
|
|
|
|
if (QFile(this->xmlFilePath).exists())
|
|
{
|
|
this->loadFromXml();
|
|
}
|
|
else
|
|
{
|
|
this->saveToXml();
|
|
}
|
|
|
|
if (QFile(this->GPSPointFilePath).exists() == false) {
|
|
// ´´½¨ÐÂÎļþ
|
|
omp_lock_t lock;
|
|
omp_init_lock(&lock);
|
|
omp_set_lock(&lock);
|
|
GDALAllRegister();
|
|
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
|
|
|
|
GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI");
|
|
std::shared_ptr<GDALDataset> poDstDS(poDriver->Create(this->GPSPointFilePath.toUtf8().constData(), 16, rowCount, 1, GDT_Float64, NULL));
|
|
GDALFlushCache((GDALDatasetH)poDstDS.get());
|
|
poDstDS.reset();
|
|
omp_unset_lock(&lock);
|
|
omp_destroy_lock(&lock);
|
|
}
|
|
|
|
if (QFile(this->ImageRasterPath).exists() == false) {
|
|
|
|
// ´´½¨ÐÂÎļþ
|
|
omp_lock_t lock;
|
|
omp_init_lock(&lock);
|
|
omp_set_lock(&lock);
|
|
GDALAllRegister();
|
|
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
|
|
|
|
GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI");
|
|
std::shared_ptr<GDALDataset> poDstDS(poDriver->Create(this->ImageRasterPath.toUtf8().constData(), colCount, rowCount, 1, GDT_CFloat64, NULL));
|
|
GDALFlushCache((GDALDatasetH)poDstDS.get());
|
|
poDstDS.reset();
|
|
omp_unset_lock(&lock); //
|
|
omp_destroy_lock(&lock); //
|
|
}
|
|
|
|
return ErrorCode::SUCCESS;
|
|
}
|
|
|
|
ErrorCode SARSimulationImageL1Dataset::Open(QString folder, QString filename)
|
|
{
|
|
|
|
QDir dir(folder);
|
|
if (dir.exists() == false)
|
|
{
|
|
return ErrorCode::FOLDER_NOT_EXIST;
|
|
}
|
|
else {}
|
|
|
|
if (dir.exists() == false) {
|
|
return ErrorCode::FOLDER_NOT_EXIST;
|
|
}
|
|
else {}
|
|
QString filePath = dir.filePath(filename); // Éú³ÉÍêÕûµÄÎļþ·¾¶
|
|
|
|
this->outFolderPath = folder;
|
|
this->L1DatasetName = filename;
|
|
|
|
this->xmlfileName = filename + ".xml";
|
|
this->GPSPointFilename = filename + ".gpspos.data";
|
|
this->ImageRasterName = filename + ".bin";
|
|
|
|
this->xmlFilePath = dir.filePath(this->xmlfileName);
|
|
this->GPSPointFilePath = dir.filePath(this->GPSPointFilename);
|
|
this->ImageRasterPath = dir.filePath(this->ImageRasterName);
|
|
|
|
if (QFile(this->xmlFilePath).exists())
|
|
{
|
|
this->loadFromXml();
|
|
}
|
|
else
|
|
{
|
|
return ErrorCode::ECHO_L0DATA_ECHOFILEFORMATERROR;
|
|
}
|
|
}
|
|
|
|
ErrorCode SARSimulationImageL1Dataset::Open(QString xmlPath)
|
|
{
|
|
QFileInfo fileInfo(xmlPath);
|
|
QString fileName = fileInfo.fileName(); // »ñÈ¡ÎļþÃû
|
|
QString fileSuffix = fileInfo.suffix(); // »ñÈ¡ºó׺Ãû
|
|
QString fileNameWithoutSuffix = fileInfo.baseName(); // »ñÈ¡²»´øºó׺µÄÎļþÃû
|
|
QString directoryPath = fileInfo.path(); // »ñÈ¡Îļþ¼Ð·¾¶
|
|
if (fileSuffix.toLower() == "xml" || fileSuffix.toLower() == ".xml") {
|
|
return this->Open(directoryPath, fileNameWithoutSuffix);
|
|
}
|
|
else {
|
|
return ErrorCode::IMAGE_L1DATA_XMLNAMEERROR;
|
|
}
|
|
return ErrorCode::SUCCESS;
|
|
|
|
}
|
|
|
|
void SARSimulationImageL1Dataset::saveToXml()
|
|
{
|
|
QFile file(this->xmlFilePath);
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
qDebug() << "Cannot open file for writing:" << file.errorString();
|
|
return;
|
|
}
|
|
|
|
QXmlStreamWriter xmlWriter(&file);
|
|
xmlWriter.setAutoFormatting(true);
|
|
|
|
xmlWriter.writeStartDocument();
|
|
xmlWriter.writeStartElement("Parameters");
|
|
|
|
xmlWriter.writeTextElement("RowCount", QString::number(this->rowCount));
|
|
xmlWriter.writeTextElement("ColCount", QString::number(this->colCount));
|
|
xmlWriter.writeTextElement("Rnear", QString::number(this->Rnear));
|
|
xmlWriter.writeTextElement("Rfar", QString::number(this->Rfar));
|
|
xmlWriter.writeTextElement("Rref", QString::number(this->Rref));
|
|
xmlWriter.writeTextElement("CenterFreq", QString::number(this->centerFreq));
|
|
xmlWriter.writeTextElement("Fs", QString::number(this->Fs));
|
|
xmlWriter.writeTextElement("CenterAngle", QString::number(this->CenterAngle));
|
|
xmlWriter.writeTextElement("LookSide", this->LookSide);
|
|
|
|
xmlWriter.writeEndElement(); // Parameters
|
|
xmlWriter.writeEndDocument();
|
|
|
|
file.close();
|
|
}
|
|
|
|
ErrorCode SARSimulationImageL1Dataset::loadFromXml()
|
|
{
|
|
QFile file(this->xmlFilePath);
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
qDebug() << "Cannot open file for reading:" << file.errorString();
|
|
return ErrorCode::IMAGE_L1DATA_XMLNAMEOPENERROR;
|
|
}
|
|
|
|
QXmlStreamReader xmlReader(&file);
|
|
while (!xmlReader.atEnd() && !xmlReader.hasError()) {
|
|
QXmlStreamReader::TokenType token = xmlReader.readNext();
|
|
if (token == QXmlStreamReader::StartDocument) {
|
|
continue;
|
|
}
|
|
if (token == QXmlStreamReader::StartElement) {
|
|
if (xmlReader.name() == "Parameters") {
|
|
continue;
|
|
}
|
|
else if (xmlReader.name() == "RowCount") {
|
|
this->rowCount = xmlReader.readElementText().toLong();
|
|
}
|
|
else if (xmlReader.name() == "ColCount") {
|
|
this->colCount = xmlReader.readElementText().toLong();
|
|
}
|
|
else if (xmlReader.name() == "Rnear") {
|
|
this->Rnear = xmlReader.readElementText().toDouble();
|
|
}
|
|
else if (xmlReader.name() == "Rfar") {
|
|
this->Rfar = xmlReader.readElementText().toDouble();
|
|
}
|
|
else if (xmlReader.name() == "Rref") {
|
|
this->Rref = xmlReader.readElementText().toDouble();
|
|
}
|
|
else if (xmlReader.name() == "CenterFreq") {
|
|
this->centerFreq = xmlReader.readElementText().toDouble();
|
|
}
|
|
else if (xmlReader.name() == "Fs") {
|
|
this->Fs = xmlReader.readElementText().toDouble();
|
|
}
|
|
else if (xmlReader.name() == "CenterAngle") {
|
|
this->CenterAngle = xmlReader.readElementText().toDouble();
|
|
}
|
|
else if (xmlReader.name() == "LookSide") {
|
|
this->LookSide = xmlReader.readElementText();
|
|
}
|
|
}
|
|
}
|
|
|
|
if (xmlReader.hasError()) {
|
|
qDebug() << "XML error:" << xmlReader.errorString();
|
|
return ErrorCode::IMAGE_L1DATA_XMLNAMEPARASEERROR;
|
|
}
|
|
|
|
file.close();
|
|
return ErrorCode::SUCCESS;
|
|
}
|
|
|
|
std::shared_ptr<double> SARSimulationImageL1Dataset::getAntPos()
|
|
{
|
|
omp_lock_t lock;
|
|
omp_init_lock(&lock);
|
|
omp_set_lock(&lock);
|
|
// ¶ÁÈ¡Îļþ
|
|
std::shared_ptr<GDALDataset> rasterDataset = OpenDataset(this->GPSPointFilePath, GDALAccess::GA_ReadOnly);
|
|
|
|
GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType();
|
|
GDALRasterBand* demBand = rasterDataset->GetRasterBand(1);
|
|
|
|
long width = rasterDataset->GetRasterXSize();
|
|
long height = rasterDataset->GetRasterYSize();
|
|
long band_num = rasterDataset->GetRasterCount();
|
|
|
|
std::shared_ptr<double> temp = nullptr;
|
|
|
|
if (gdal_datatype == GDT_Float64) {
|
|
temp = std::shared_ptr<double>(new double[this->rowCount * 16], delArrPtr);
|
|
demBand->RasterIO(GF_Read, 0, 0, 10, this->rowCount, temp.get(), 16, this->rowCount, gdal_datatype, 0, 0);
|
|
}
|
|
else {
|
|
qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_GPSFILEFORMATERROR));
|
|
}
|
|
rasterDataset.reset();
|
|
omp_unset_lock(&lock); //
|
|
omp_destroy_lock(&lock); //
|
|
return temp;
|
|
}
|
|
|
|
ErrorCode SARSimulationImageL1Dataset::saveAntPos(std::shared_ptr<double> ptr)
|
|
{
|
|
omp_lock_t lock;
|
|
omp_init_lock(&lock);
|
|
omp_set_lock(&lock);
|
|
// ¶ÁÈ¡Îļþ
|
|
std::shared_ptr<GDALDataset> rasterDataset = OpenDataset(this->GPSPointFilePath, GDALAccess::GA_Update);
|
|
|
|
GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType();
|
|
GDALRasterBand* demBand = rasterDataset->GetRasterBand(1);
|
|
|
|
long width = rasterDataset->GetRasterXSize();
|
|
long height = rasterDataset->GetRasterYSize();
|
|
long band_num = rasterDataset->GetRasterCount();
|
|
|
|
if (gdal_datatype == GDT_Float64) {
|
|
demBand->RasterIO(GF_Write, 0, 0, 16, this->rowCount, ptr.get(), 16, this->rowCount, gdal_datatype, 0, 0);
|
|
}
|
|
else {
|
|
qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_GPSFILEFORMATERROR));
|
|
omp_unset_lock(&lock);
|
|
omp_destroy_lock(&lock);
|
|
return ErrorCode::ECHO_L0DATA_GPSFILEFORMATERROR;
|
|
}
|
|
rasterDataset.reset();
|
|
omp_unset_lock(&lock);
|
|
omp_destroy_lock(&lock);
|
|
return ErrorCode::SUCCESS;
|
|
}
|
|
|
|
std::shared_ptr<std::complex<double>> SARSimulationImageL1Dataset::getImageRaster()
|
|
{
|
|
return this->getImageRaster(0, this->rowCount);
|
|
}
|
|
|
|
ErrorCode SARSimulationImageL1Dataset::saveImageRaster(std::shared_ptr<std::complex<double>> echoPtr, long startPRF, long PRFLen)
|
|
{
|
|
if (!(startPRF < this->rowCount)) {
|
|
qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_PRFIDXOUTRANGE));
|
|
return ErrorCode::ECHO_L0DATA_PRFIDXOUTRANGE;
|
|
}
|
|
else {}
|
|
|
|
omp_lock_t lock;
|
|
omp_init_lock(&lock);
|
|
omp_set_lock(&lock);
|
|
std::shared_ptr<GDALDataset> rasterDataset = OpenDataset(this->ImageRasterPath, GDALAccess::GA_Update);
|
|
|
|
|
|
GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType();
|
|
GDALRasterBand* poBand = rasterDataset->GetRasterBand(1);
|
|
if (NULL == poBand || nullptr == poBand) {
|
|
omp_lock_t lock;
|
|
omp_init_lock(&lock);
|
|
omp_set_lock(&lock);
|
|
qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_ECHOFILEFORMATERROR));
|
|
return ErrorCode::ECHO_L0DATA_ECHOFILEFORMATERROR;
|
|
}
|
|
else {}
|
|
long width = rasterDataset->GetRasterXSize();
|
|
long height = rasterDataset->GetRasterYSize();
|
|
long band_num = rasterDataset->GetRasterCount();
|
|
|
|
if (height != this->rowCount || width != this->colCount) {
|
|
qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_ECHOFILEFORMATERROR));
|
|
omp_unset_lock(&lock); //
|
|
omp_destroy_lock(&lock); //
|
|
return ErrorCode::ECHO_L0DATA_ECHOFILEFORMATERROR;
|
|
}
|
|
else {
|
|
if (gdal_datatype == GDT_CFloat64) {
|
|
poBand->RasterIO(GF_Write, 0, startPRF, width, PRFLen, echoPtr.get(), width, PRFLen, GDT_CFloat64, 0, 0);
|
|
GDALFlushCache((GDALDatasetH)rasterDataset.get());
|
|
}
|
|
else {
|
|
qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_ECHOFILEFORMATERROR));
|
|
}
|
|
}
|
|
rasterDataset.reset();
|
|
omp_unset_lock(&lock); //
|
|
omp_destroy_lock(&lock); //
|
|
return ErrorCode::SUCCESS;
|
|
}
|
|
|
|
std::shared_ptr<std::complex<double>> SARSimulationImageL1Dataset::getImageRaster(long startPRF, long PRFLen)
|
|
{
|
|
if (!(startPRF < this->rowCount)) {
|
|
qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_PRFIDXOUTRANGE)) << startPRF << " " << this->rowCount;
|
|
return nullptr;
|
|
}
|
|
else {}
|
|
|
|
omp_lock_t lock;
|
|
omp_init_lock(&lock);
|
|
omp_set_lock(&lock);
|
|
std::shared_ptr<GDALDataset> rasterDataset = OpenDataset(this->ImageRasterPath, GDALAccess::GA_ReadOnly);
|
|
|
|
|
|
GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType();
|
|
GDALRasterBand* poBand = rasterDataset->GetRasterBand(1);
|
|
if (NULL == poBand || nullptr == poBand) {
|
|
omp_lock_t lock;
|
|
omp_init_lock(&lock);
|
|
omp_set_lock(&lock);
|
|
qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_ECHOFILEFORMATERROR));
|
|
return nullptr;
|
|
}
|
|
else {}
|
|
long width = rasterDataset->GetRasterXSize();
|
|
long height = rasterDataset->GetRasterYSize();
|
|
long band_num = rasterDataset->GetRasterCount();
|
|
std::shared_ptr<std::complex<double>> temp = nullptr;
|
|
if (height != this->rowCount || width != this->colCount) {
|
|
qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_ECHOFILEFORMATERROR));
|
|
}
|
|
else {
|
|
if (gdal_datatype == GDT_CFloat64) {
|
|
temp = std::shared_ptr<std::complex<double>>(new std::complex<double>[PRFLen * width], delArrPtr);
|
|
poBand->RasterIO(GF_Read, 0, startPRF, width, PRFLen, temp.get(), width, PRFLen, GDT_CFloat64, 0, 0);
|
|
GDALFlushCache((GDALDatasetH)rasterDataset.get());
|
|
}
|
|
else {
|
|
qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_ECHOFILEFORMATERROR));
|
|
}
|
|
}
|
|
|
|
rasterDataset.reset();
|
|
omp_unset_lock(&lock); //
|
|
omp_destroy_lock(&lock); //
|
|
return temp;
|
|
}
|
|
|
|
Eigen::MatrixXcd SARSimulationImageL1Dataset::getImageRasterMatrix()
|
|
{
|
|
std::shared_ptr<std::complex<double>> data = this->getImageRaster();
|
|
Eigen::MatrixXcd dataimg = Eigen::MatrixXcd::Zero(this->rowCount, this->colCount);
|
|
for (long i = 0; i < this->rowCount; i++) {
|
|
for (long j = 0; j < this->colCount; j++) {
|
|
dataimg(i, j) = data.get()[i*colCount+j];
|
|
}
|
|
}
|
|
return Eigen::MatrixXcd();
|
|
}
|
|
|
|
ErrorCode SARSimulationImageL1Dataset::saveImageRaster(Eigen::MatrixXcd& dataimg, long startPRF)
|
|
{
|
|
std::shared_ptr<std::complex<double>> data(new std::complex<double>[dataimg.rows()* dataimg.cols()]);
|
|
long dataimgrows = dataimg.rows();
|
|
long dataimgcols = dataimg.cols();
|
|
for (long i = 0; i < dataimgrows; i++) {
|
|
for (long j = 0; j < dataimgcols; j++) {
|
|
data.get()[i * dataimgcols + j] = dataimg(i, j);
|
|
}
|
|
}
|
|
this->saveImageRaster(data, startPRF,dataimgrows);
|
|
return ErrorCode();
|
|
}
|
|
|
|
|
|
|
|
|
|
// Getter ºÍ Setter ·½·¨ÊµÏÖ
|
|
long SARSimulationImageL1Dataset::getrowCount() { return this->rowCount; }
|
|
void SARSimulationImageL1Dataset::setrowCount(long rowCountin) { this->rowCount = rowCountin; }
|
|
|
|
long SARSimulationImageL1Dataset::getcolCount() { return this->colCount; }
|
|
void SARSimulationImageL1Dataset::setcolCount(long pulsePointsin) { this->colCount = pulsePointsin; }
|
|
|
|
|
|
double SARSimulationImageL1Dataset::getNearRange() { return this->Rnear; }
|
|
void SARSimulationImageL1Dataset::setNearRange(double nearRange) { this->Rnear = nearRange; }
|
|
|
|
double SARSimulationImageL1Dataset::getFarRange() { return this->Rfar; }
|
|
void SARSimulationImageL1Dataset::setFarRange(double farRange) { this->Rfar = farRange; }
|
|
|
|
double SARSimulationImageL1Dataset::getRefRange()
|
|
{
|
|
return this->Rref;
|
|
}
|
|
|
|
void SARSimulationImageL1Dataset::setRefRange(double refRange)
|
|
{
|
|
this->Rref = refRange;
|
|
}
|
|
|
|
double SARSimulationImageL1Dataset::getCenterFreq() { return this->centerFreq; }
|
|
void SARSimulationImageL1Dataset::setCenterFreq(double freq) { this->centerFreq = freq; }
|
|
|
|
double SARSimulationImageL1Dataset::getFs() { return this->Fs; }
|
|
void SARSimulationImageL1Dataset::setFs(double samplingFreq) { this->Fs = samplingFreq; }
|
|
|
|
|
|
|
|
double SARSimulationImageL1Dataset::getCenterAngle()
|
|
{
|
|
return this->CenterAngle;
|
|
}
|
|
|
|
void SARSimulationImageL1Dataset::setCenterAngle(double angle)
|
|
{
|
|
this->CenterAngle = angle;
|
|
}
|
|
|
|
QString SARSimulationImageL1Dataset::getLookSide()
|
|
{
|
|
return this->LookSide;
|
|
}
|
|
|
|
void SARSimulationImageL1Dataset::setLookSide(QString looksides)
|
|
{
|
|
this->LookSide = looksides;
|
|
}
|