From 44a5db316850780011a36f9de036ea624d6a625a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sat, 8 Mar 2025 17:24:38 +0800 Subject: [PATCH 01/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=9F=BA?= =?UTF-8?q?=E4=BA=8ESPG4=E6=A8=A1=E5=9E=8B=E4=B8=8E=E4=B8=A4=E8=A1=8C?= =?UTF-8?q?=E6=A0=B9=E6=95=B0=E7=9A=84=EF=BC=8C=E5=8D=AB=E6=98=9F=E8=BD=A8?= =?UTF-8?q?=E9=81=93=E7=82=B9=E7=94=9F=E6=88=90=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LAMPDataProcess.sln | 15 + SPG4Tool/SPG4Function.cpp | 135 +++ SPG4Tool/SPG4Function.h | 17 + SPG4Tool/SPG4Tool.vcxproj | 145 +++ SPG4Tool/SPG4Tool.vcxproj.filters | 137 +++ SPG4Tool/SPG4Toolmain.cpp | 38 + SPG4Tool/libsgp4/CMakeLists.txt | 41 + SPG4Tool/libsgp4/CoordGeodetic.cc | 18 + SPG4Tool/libsgp4/CoordGeodetic.h | 126 +++ SPG4Tool/libsgp4/CoordTopocentric.cc | 18 + SPG4Tool/libsgp4/CoordTopocentric.h | 122 +++ SPG4Tool/libsgp4/DateTime.cc | 149 +++ SPG4Tool/libsgp4/DateTime.h | 721 +++++++++++++ SPG4Tool/libsgp4/DecayedException.cc | 1 + SPG4Tool/libsgp4/DecayedException.h | 79 ++ SPG4Tool/libsgp4/Eci.cc | 111 ++ SPG4Tool/libsgp4/Eci.h | 146 +++ SPG4Tool/libsgp4/Globals.cc | 18 + SPG4Tool/libsgp4/Globals.h | 77 ++ SPG4Tool/libsgp4/Observer.cc | 86 ++ SPG4Tool/libsgp4/Observer.h | 103 ++ SPG4Tool/libsgp4/OrbitalElements.cc | 70 ++ SPG4Tool/libsgp4/OrbitalElements.h | 147 +++ SPG4Tool/libsgp4/SGP4.cc | 1353 ++++++++++++++++++++++++ SPG4Tool/libsgp4/SGP4.h | 260 +++++ SPG4Tool/libsgp4/SatelliteException.cc | 1 + SPG4Tool/libsgp4/SatelliteException.h | 38 + SPG4Tool/libsgp4/SolarPosition.cc | 68 ++ SPG4Tool/libsgp4/SolarPosition.h | 40 + SPG4Tool/libsgp4/TimeSpan.cc | 18 + SPG4Tool/libsgp4/TimeSpan.h | 259 +++++ SPG4Tool/libsgp4/Tle.cc | 376 +++++++ SPG4Tool/libsgp4/Tle.h | 341 ++++++ SPG4Tool/libsgp4/TleException.cc | 1 + SPG4Tool/libsgp4/TleException.h | 44 + SPG4Tool/libsgp4/Util.cc | 45 + SPG4Tool/libsgp4/Util.h | 111 ++ SPG4Tool/libsgp4/Vector.cc | 18 + SPG4Tool/libsgp4/Vector.h | 160 +++ 39 files changed, 5653 insertions(+) create mode 100644 SPG4Tool/SPG4Function.cpp create mode 100644 SPG4Tool/SPG4Function.h create mode 100644 SPG4Tool/SPG4Tool.vcxproj create mode 100644 SPG4Tool/SPG4Tool.vcxproj.filters create mode 100644 SPG4Tool/SPG4Toolmain.cpp create mode 100644 SPG4Tool/libsgp4/CMakeLists.txt create mode 100644 SPG4Tool/libsgp4/CoordGeodetic.cc create mode 100644 SPG4Tool/libsgp4/CoordGeodetic.h create mode 100644 SPG4Tool/libsgp4/CoordTopocentric.cc create mode 100644 SPG4Tool/libsgp4/CoordTopocentric.h create mode 100644 SPG4Tool/libsgp4/DateTime.cc create mode 100644 SPG4Tool/libsgp4/DateTime.h create mode 100644 SPG4Tool/libsgp4/DecayedException.cc create mode 100644 SPG4Tool/libsgp4/DecayedException.h create mode 100644 SPG4Tool/libsgp4/Eci.cc create mode 100644 SPG4Tool/libsgp4/Eci.h create mode 100644 SPG4Tool/libsgp4/Globals.cc create mode 100644 SPG4Tool/libsgp4/Globals.h create mode 100644 SPG4Tool/libsgp4/Observer.cc create mode 100644 SPG4Tool/libsgp4/Observer.h create mode 100644 SPG4Tool/libsgp4/OrbitalElements.cc create mode 100644 SPG4Tool/libsgp4/OrbitalElements.h create mode 100644 SPG4Tool/libsgp4/SGP4.cc create mode 100644 SPG4Tool/libsgp4/SGP4.h create mode 100644 SPG4Tool/libsgp4/SatelliteException.cc create mode 100644 SPG4Tool/libsgp4/SatelliteException.h create mode 100644 SPG4Tool/libsgp4/SolarPosition.cc create mode 100644 SPG4Tool/libsgp4/SolarPosition.h create mode 100644 SPG4Tool/libsgp4/TimeSpan.cc create mode 100644 SPG4Tool/libsgp4/TimeSpan.h create mode 100644 SPG4Tool/libsgp4/Tle.cc create mode 100644 SPG4Tool/libsgp4/Tle.h create mode 100644 SPG4Tool/libsgp4/TleException.cc create mode 100644 SPG4Tool/libsgp4/TleException.h create mode 100644 SPG4Tool/libsgp4/Util.cc create mode 100644 SPG4Tool/libsgp4/Util.h create mode 100644 SPG4Tool/libsgp4/Vector.cc create mode 100644 SPG4Tool/libsgp4/Vector.h diff --git a/LAMPDataProcess.sln b/LAMPDataProcess.sln index 089c1ce..8d9901f 100644 --- a/LAMPDataProcess.sln +++ b/LAMPDataProcess.sln @@ -38,6 +38,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RasterMainWidgetGUI", "Rast EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImageshowTool", "ImageshowTool\ImageshowTool.vcxproj", "{8C8CA066-A93A-4098-9A46-B855EFEAADF2}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SPG4Tool", "SPG4Tool\SPG4Tool.vcxproj", "{80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM = Debug|ARM @@ -168,6 +170,18 @@ Global {8C8CA066-A93A-4098-9A46-B855EFEAADF2}.Release|x64.Build.0 = Release|x64 {8C8CA066-A93A-4098-9A46-B855EFEAADF2}.Release|x86.ActiveCfg = Release|x64 {8C8CA066-A93A-4098-9A46-B855EFEAADF2}.Release|x86.Build.0 = Release|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|ARM.ActiveCfg = Debug|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|ARM.Build.0 = Debug|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|x64.ActiveCfg = Debug|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|x64.Build.0 = Debug|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|x86.ActiveCfg = Debug|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|x86.Build.0 = Debug|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|ARM.ActiveCfg = Release|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|ARM.Build.0 = Release|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x64.ActiveCfg = Release|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x64.Build.0 = Release|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x86.ActiveCfg = Release|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -181,6 +195,7 @@ Global {B8B40C54-F7FE-4809-B6FB-8BC014570D7B} = {2768F9D6-D410-4E88-A479-8336DAF97072} {E56B3878-A3DC-41A4-ABF3-B628816D0D64} = {6505E2BA-06A2-447B-BC85-8CF1A81359BC} {8C8CA066-A93A-4098-9A46-B855EFEAADF2} = {2768F9D6-D410-4E88-A479-8336DAF97072} + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E} = {2768F9D6-D410-4E88-A479-8336DAF97072} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {179F0A62-C631-4667-AD03-3780ADE09F41} diff --git a/SPG4Tool/SPG4Function.cpp b/SPG4Tool/SPG4Function.cpp new file mode 100644 index 0000000..7fb0c3d --- /dev/null +++ b/SPG4Tool/SPG4Function.cpp @@ -0,0 +1,135 @@ +#include "SPG4Function.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + + +std::vector RunTle(libsgp4::Tle tle, double start, double end, double inc, bool printfinfoflag) +{ + std::vector resultpos(0); + double current = start; + libsgp4::SGP4 model(tle); + bool running = true; + bool first_run = true; + + std::cout << std::setprecision(0) << tle.NoradNumber() << " xx" + << std::endl; + + while (running) + { + bool error = false; + libsgp4::Vector position; + libsgp4::Vector velocity; + double tsince; + + try + { + if (first_run && current != 0.0) + { + /* + * make sure first run is always as zero + */ + tsince = 0.0; + } + else + { + /* + * otherwise run as normal + */ + tsince = current; + } + + libsgp4::Eci eci = model.FindPosition(tsince); + position = eci.Position(); + velocity = eci.Velocity(); + } + catch (libsgp4::SatelliteException& e) + { + std::cerr << e.what() << std::endl; + error = true; + running = false; + } + catch (libsgp4::DecayedException& e) + { + std::cerr << e.what() << std::endl; + + position = e.Position(); + velocity = e.Velocity(); + + if (!first_run) + { + // print out position on first run + error = true; + } + + running = false; + } + + if (!error) + { + SatelliteAntPos antpos{}; + antpos.time = tsince; + antpos.Px = position.x; + antpos.Py = position.y; + antpos.Pz = position.z; + antpos.Vx = velocity.z; + antpos.Vy = velocity.z; + antpos.Vz = velocity.z; + + resultpos.push_back(antpos); + if (printfinfoflag) { + std::cout << std::setprecision(8) << std::fixed; + std::cout.width(17); + std::cout << tsince << " "; + std::cout.width(16); + std::cout << position.x << " "; + std::cout.width(16); + std::cout << position.y << " "; + std::cout.width(16); + std::cout << position.z << " "; + std::cout << std::setprecision(9) << std::fixed; + std::cout.width(14); + std::cout << velocity.x << " "; + std::cout.width(14); + std::cout << velocity.y << " "; + std::cout.width(14); + std::cout << velocity.z << std::endl; + } + } + + if ((first_run && current == 0.0) || !first_run) + { + if (current == end) + { + running = false; + } + else if (current + inc > end) + { + current = end; + } + else + { + current += inc; + } + } + first_run = false; + } + + + return resultpos; +} + + + + diff --git a/SPG4Tool/SPG4Function.h b/SPG4Tool/SPG4Function.h new file mode 100644 index 0000000..a9cbd4a --- /dev/null +++ b/SPG4Tool/SPG4Function.h @@ -0,0 +1,17 @@ +#pragma once +#ifndef __SPG4FUNCTION__H__ +#define __SPG4FUNCTION__H__ + +#include "Tle.h" +#include "SGP4.h" +#include "Observer.h" +#include "BaseConstVariable.h" +#include + +//void RunTle(libsgp4::Tle tle, double start, double end, double inc); + + +std::vector RunTle(libsgp4::Tle tle, double start, double end, double inc,bool printfinfoflag=false); + + +#endif diff --git a/SPG4Tool/SPG4Tool.vcxproj b/SPG4Tool/SPG4Tool.vcxproj new file mode 100644 index 0000000..1e28b4b --- /dev/null +++ b/SPG4Tool/SPG4Tool.vcxproj @@ -0,0 +1,145 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E} + QtVS_v304 + 10.0 + 10.0 + $(MSBuildProjectDirectory)\QtMsBuild + + + + Application + v143 + true + Unicode + + + DynamicLibrary + v143 + false + true + Unicode + + + + + + + tools_qt5 + core + debug + + + tools_qt5 + core + release + + + + + + + + + + + + + + + + + + + .\libsgp4;..\BaseCommonLibrary\BaseTool;$(IncludePath) + + + + true + Level3 + true + true + + + Console + true + + + + + true + Level3 + true + true + true + true + + + Console + false + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {872ecd6f-30e3-4a1b-b17c-15e87d373ff6} + + + + + + + + + \ No newline at end of file diff --git a/SPG4Tool/SPG4Tool.vcxproj.filters b/SPG4Tool/SPG4Tool.vcxproj.filters new file mode 100644 index 0000000..cfa82a2 --- /dev/null +++ b/SPG4Tool/SPG4Tool.vcxproj.filters @@ -0,0 +1,137 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + qml;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {99349809-55BA-4b9d-BF79-8FDBB0286EB3} + ui + + + {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C} + ts + + + {fd21014a-ae49-484d-bbcf-92b5b994c075} + + + + + Source Files + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + Source Files + + + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + libsgp4 + + + Header Files + + + \ No newline at end of file diff --git a/SPG4Tool/SPG4Toolmain.cpp b/SPG4Tool/SPG4Toolmain.cpp new file mode 100644 index 0000000..4faaabe --- /dev/null +++ b/SPG4Tool/SPG4Toolmain.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include "Tle.h" +#include "SGP4.h" +#include "Observer.h" +#include "CoordGeodetic.h" +#include "CoordTopocentric.h" +#include +#include "SPG4Function.h" + +/** + +½̽ĺ01ǹ +1 57624U 23120A 25064.58152700 -.00000191 00000-0 00000+0 0 9998 +2 57624 15.4792 205.4597 0004587 123.7538 133.1804 1.00272901 5837 + + */ + + +// +//int main(int argc, char *argv[]) +//{ +// +// std::string line1="1 57624U 23120A 25064.58152700 -.00000191 00000-0 00000+0 0 9998"; +// std::string line2="2 57624 15.4792 205.4597 0004587 123.7538 133.1804 1.00272901 5837"; +// +// libsgp4::Tle tle("GF3", line1, line2); +// +// double start = 0; +// double end = 10; +// double inc = 1; +// +// RunTle(tle, start, end, inc); +// //QCoreApplication a(argc, argv); +// +// //return a.exec(); +//} diff --git a/SPG4Tool/libsgp4/CMakeLists.txt b/SPG4Tool/libsgp4/CMakeLists.txt new file mode 100644 index 0000000..f70d73b --- /dev/null +++ b/SPG4Tool/libsgp4/CMakeLists.txt @@ -0,0 +1,41 @@ +set(SRCS + CoordGeodetic.cc + CoordTopocentric.cc + DateTime.cc + DecayedException.cc + Eci.cc + Globals.cc + Observer.cc + OrbitalElements.cc + SGP4.cc + SatelliteException.cc + SolarPosition.cc + TimeSpan.cc + Tle.cc + TleException.cc + Util.cc + Vector.cc) + + set(INCS + CoordGeodetic.h + CoordTopocentric.h + DateTime.h + DecayedException.h + Eci.h + Globals.h + Observer.h + OrbitalElements.h + SatelliteException.h + SGP4.h + SolarPosition.h + TimeSpan.h + TleException.h + Tle.h + Util.h + Vector.h + ) + +add_library(sgp4 STATIC ${SRCS} ${INCS}) +add_library(sgp4s SHARED ${SRCS} ${INCS}) +install( TARGETS sgp4s LIBRARY DESTINATION lib ) +install( FILES ${INCS} DESTINATION include/libsgp4 ) diff --git a/SPG4Tool/libsgp4/CoordGeodetic.cc b/SPG4Tool/libsgp4/CoordGeodetic.cc new file mode 100644 index 0000000..0a92103 --- /dev/null +++ b/SPG4Tool/libsgp4/CoordGeodetic.cc @@ -0,0 +1,18 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "CoordGeodetic.h" diff --git a/SPG4Tool/libsgp4/CoordGeodetic.h b/SPG4Tool/libsgp4/CoordGeodetic.h new file mode 100644 index 0000000..8007168 --- /dev/null +++ b/SPG4Tool/libsgp4/CoordGeodetic.h @@ -0,0 +1,126 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include "Util.h" + +#include +#include +#include + +namespace libsgp4 +{ + +/** + * @brief Stores a geodetic location (latitude, longitude, altitude). + * + * Internally the values are stored in radians and kilometres. + */ +struct CoordGeodetic +{ +public: + /** + * Default constructor + */ + CoordGeodetic() = default; + + /** + * Constructor + * @param[in] lat the latitude (degrees by default) + * @param[in] lon the longitude (degrees by default) + * @param[in] alt the altitude in kilometers + * @param[in] is_radians whether the latitude/longitude is in radians + */ + CoordGeodetic( + double lat, + double lon, + double alt, + bool is_radians = false) + { + if (is_radians) + { + latitude = lat; + longitude = lon; + } + else + { + latitude = Util::DegreesToRadians(lat); + longitude = Util::DegreesToRadians(lon); + } + altitude = alt; + } + + /** + * Copy constructor + * @param[in] geo object to copy from + */ + CoordGeodetic(const CoordGeodetic& geo) + { + latitude = geo.latitude; + longitude = geo.longitude; + altitude = geo.altitude; + } + + /** + * Assignment operator + * @param[in] geo object to copy from + */ + CoordGeodetic& operator=(const CoordGeodetic& geo) + { + if (this != &geo) + { + latitude = geo.latitude; + longitude = geo.longitude; + altitude = geo.altitude; + } + return *this; + } + + /** + * Dump this object to a string + * @returns string + */ + std::string ToString() const + { + std::stringstream ss; + ss << std::right << std::fixed << std::setprecision(3); + ss << "Lat: " << std::setw(8) << Util::RadiansToDegrees(latitude); + ss << ", Lon: " << std::setw(8) << Util::RadiansToDegrees(longitude); + ss << ", Alt: " << std::setw(10) << altitude; + return ss.str(); + } + + /** latitude in radians (-PI >= latitude < PI) */ + double latitude{}; + /** latitude in radians (-PI/2 >= latitude <= PI/2) */ + double longitude{}; + /** altitude in kilometers */ + double altitude{}; +}; + +/** + * Dump a Coordgeodetic to a stream + * @param[in,out] strm stream to output to + * @param[in] g the CoordGeodetic to print + */ +inline std::ostream& operator<<(std::ostream& strm, const CoordGeodetic& g) +{ + return strm << g.ToString(); +} + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/CoordTopocentric.cc b/SPG4Tool/libsgp4/CoordTopocentric.cc new file mode 100644 index 0000000..a418a90 --- /dev/null +++ b/SPG4Tool/libsgp4/CoordTopocentric.cc @@ -0,0 +1,18 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "CoordTopocentric.h" diff --git a/SPG4Tool/libsgp4/CoordTopocentric.h b/SPG4Tool/libsgp4/CoordTopocentric.h new file mode 100644 index 0000000..f70b8fe --- /dev/null +++ b/SPG4Tool/libsgp4/CoordTopocentric.h @@ -0,0 +1,122 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include "Util.h" + +#include +#include +#include + +namespace libsgp4 +{ + +/** + * @brief Stores a topocentric location (azimuth, elevation, range and range + * rate). + * + * Azimuth and elevation are stored in radians. Range in kilometres. Range + * rate in kilometres/second. + */ +struct CoordTopocentric +{ +public: + /** + * Default constructor + */ + CoordTopocentric() = default; + + /** + * Constructor + * @param[in] az azimuth in radians + * @param[in] el elevation in radians + * @param[in] rnge range in kilometers + * @param[in] rnge_rate range rate in kilometers per second + */ + CoordTopocentric( + double az, + double el, + double rnge, + double rnge_rate) + : azimuth(az) + , elevation(el) + , range(rnge) + , range_rate(rnge_rate) + { + } + + /** + * Copy constructor + * @param[in] topo object to copy from + */ + CoordTopocentric(const CoordTopocentric& topo) + { + azimuth = topo.azimuth; + elevation = topo.elevation; + range = topo.range; + range_rate = topo.range_rate; + } + + /** + * Assignment operator + * @param[in] topo object to copy from + */ + CoordTopocentric& operator=(const CoordTopocentric& topo) + { + if (this != &topo) + { + azimuth = topo.azimuth; + elevation = topo.elevation; + range = topo.range; + range_rate = topo.range_rate; + } + return *this; + } + + /** + * Dump this object to a string + * @returns string + */ + std::string ToString() const + { + std::stringstream ss; + ss << std::right << std::fixed << std::setprecision(3); + ss << "Az: " << std::setw(8) << Util::RadiansToDegrees(azimuth); + ss << ", El: " << std::setw(8) << Util::RadiansToDegrees(elevation); + ss << ", Rng: " << std::setw(10) << range; + ss << ", Rng Rt: " << std::setw(7) << range_rate; + return ss.str(); + } + + /** azimuth in radians */ + double azimuth{}; + /** elevations in radians */ + double elevation{}; + /** range in kilometers */ + double range{}; + /** range rate in kilometers per second */ + double range_rate{}; +}; + + +inline std::ostream& operator<<(std::ostream& strm, const CoordTopocentric& t) +{ + return strm << t.ToString(); +} + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/DateTime.cc b/SPG4Tool/libsgp4/DateTime.cc new file mode 100644 index 0000000..e056208 --- /dev/null +++ b/SPG4Tool/libsgp4/DateTime.cc @@ -0,0 +1,149 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "DateTime.h" + +#if 0 + +bool jd_dmy(int JD, int c_year, int c_month, int c_day) +{ + // For the Gregorian calendar: + int a = JD + 32044; + int b = (4 * a + 3) / 146097; + int c = a - (b * 146097) / 4; + + // Then, for both calendars: + int d = (4 * c + 3) / 1461; + int e = c - (1461 * d) / 4; + int m = (5 * e + 2) / 153; + + int day = e - (153 * m + 2) / 5 + 1; + int month = m + 3 - 12 * (m / 10); + int year = b * 100 + d - 4800 + m / 10; + + if (c_year != year || c_month != month || c_day != day) + { + std::cout << year << " " << month << " " << day << std::endl; + return false; + } + else + { + return true; + } +} + + +int main() +{ + for (int year = 1; year <= 9999; year++) + { + for (int month = 1; month <= 12; month++) + { + for (int day = 1; day <= DateTime::DaysInMonth(year, month); day++) + { + int hour = 23; + int minute = 59; + int second = 59; + int microsecond = 999999; + + DateTime dt(year, month, day, hour, minute, second, microsecond); + + if (dt.Year() != year || + dt.Month() != month || + dt.Day() != day || + dt.Hour() != hour || + dt.Minute() != minute || + dt.Second() != second || + dt.Microsecond() != microsecond) + { + std::cout << "failed" << std::endl; + std::cout << "Y " << dt.Year() << " " << year << std::endl; + std::cout << "M " << dt.Month() << " " << month << std::endl; + std::cout << "D " << dt.Day() << " " << day << std::endl; + std::cout << "H " << dt.Hour() << " " << hour << std::endl; + std::cout << "M " << dt.Minute() << " " << minute << std::endl; + std::cout << "S " << dt.Second() << " " << second << std::endl; + std::cout << "F " << dt.Microsecond() << " " << microsecond << std::endl; + return 0; + } + + if (!jd_dmy(dt.Julian() + 0.5, year, month, day)) + { + std::cout << "julian" << std::endl; + return 0; + } + } + } + } + + for (int hour = 1; hour < 24; hour++) + { + std::cout << hour << std::endl; + for (int minute = 0; minute < 60; minute++) + { + for (int second = 0; second < 60; second++) + { + for (int microsecond = 0; microsecond < 1000000; microsecond += 10000) + { + int year = 1000; + int month = 10; + int day = 23; + + DateTime dt(year, month, day, hour, minute, second, microsecond); + + if (dt.Year() != year || + dt.Month() != month || + dt.Day() != day || + dt.Hour() != hour || + dt.Minute() != minute || + dt.Second() != second || + dt.Microsecond() != microsecond) + { + std::cout << "failed" << std::endl; + std::cout << "Y " << dt.Year() << " " << year << std::endl; + std::cout << "M " << dt.Month() << " " << month << std::endl; + std::cout << "D " << dt.Day() << " " << day << std::endl; + std::cout << "H " << dt.Hour() << " " << hour << std::endl; + std::cout << "M " << dt.Minute() << " " << minute << std::endl; + std::cout << "S " << dt.Second() << " " << second << std::endl; + std::cout << "F " << dt.Microsecond() << " " << microsecond << std::endl; + return 0; + } + } + } + } + } + + jd_dmy(1721425.5, 0, 0, 0); + + DateTime d1(1000, 1, 1); + DateTime d2(2000, 1, 1); + DateTime d3(4000, 1, 1); + DateTime d4(6000, 1, 1); + DateTime d5(8000, 1, 1); + + std::cout << std::setprecision(20); + std::cout << d1.Julian() << std::endl; + std::cout << d2.Julian() << std::endl; + std::cout << d3.Julian() << std::endl; + std::cout << d4.Julian() << std::endl; + std::cout << d5.Julian() << std::endl; + + return 0; +} + +#endif diff --git a/SPG4Tool/libsgp4/DateTime.h b/SPG4Tool/libsgp4/DateTime.h new file mode 100644 index 0000000..7005ba6 --- /dev/null +++ b/SPG4Tool/libsgp4/DateTime.h @@ -0,0 +1,721 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include +#include +#include +#include +#include +#include +#include "TimeSpan.h" +#include "Util.h" + +namespace libsgp4 +{ +namespace +{ + static int daysInMonth[2][13] = { + // 1 2 3 4 5 6 7 8 9 10 11 12 + {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, + {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} + }; + static int cumulDaysInMonth[2][13] = { + // 1 2 3 4 5 6 7 8 9 10 11 12 + {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, + {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335} + }; +} + +/** + * @brief Represents an instance in time. + */ +class DateTime +{ +public: + /** + * Default contructor + * Initialise to 0001/01/01 00:00:00.000000 + */ + DateTime() + { + Initialise(1, 1, 1, 0, 0, 0, 0); + } + + /** + * Constructor + * @param[in] ticks raw tick value + */ + explicit DateTime(int64_t ticks) + : m_encoded(ticks) + { + } + + /** + * Constructor + * @param[in] year the year + * @param[in] doy the day of the year + */ + DateTime(unsigned int year, double doy) + { + m_encoded = TimeSpan( + static_cast(AbsoluteDays(year, doy) * TicksPerDay)).Ticks(); + } + + /** + * Constructor + * @param[in] year the year + * @param[in] month the month + * @param[in] day the day + */ + DateTime(int year, int month, int day) + { + Initialise(year, month, day, 0, 0, 0, 0); + } + + /** + * Constructor + * @param[in] year the year + * @param[in] month the month + * @param[in] day the day + * @param[in] hour the hour + * @param[in] minute the minute + * @param[in] second the second + */ + DateTime(int year, int month, int day, int hour, int minute, int second) + { + Initialise(year, month, day, hour, minute, second, 0); + } + + /** + * Constructor + * @param[in] year the year + * @param[in] month the month + * @param[in] day the day + * @param[in] hour the hour + * @param[in] minute the minute + * @param[in] second the second + * @param[in] microsecond the microsecond + */ + DateTime(int year, int month, int day, int hour, int minute, int second, int microsecond) + { + Initialise(year, month, day, hour, minute, second, microsecond); + } + + /** + * Initialise to the given data and time. + * @param[in] year the year + * @param[in] month the month + * @param[in] day the day + * @param[in] hour the hour + * @param[in] minute the minute + * @param[in] second the second + * @param[in] microsecond the microsecond + */ + void Initialise(int year, + int month, + int day, + int hour, + int minute, + int second, + int microsecond) + { + if (!IsValidYearMonthDay(year, month, day) || + hour < 0 || hour > 23 || + minute < 0 || minute > 59 || + second < 0 || second > 59 || + microsecond < 0 || microsecond > 999999) + { + assert(false && "Invalid date"); + } + m_encoded = TimeSpan( + AbsoluteDays(year, month, day), + hour, + minute, + second, + microsecond).Ticks(); + } + + /** + * Return the current time + * @param[in] microseconds whether to set the microsecond component + * @returns a DateTime object set to the current date and time + */ + static DateTime Now(bool useMicroseconds = false) + { + using namespace std::chrono; + if (useMicroseconds) + { + return DateTime(UnixEpoch + + duration_cast(system_clock::now() + .time_since_epoch()).count() * TicksPerMicrosecond); + } + else + { + return DateTime(UnixEpoch + + duration_cast(system_clock::now() + .time_since_epoch()).count() * TicksPerSecond); + } + } + + /** + * Find whether a year is a leap year + * @param[in] year the year to check + * @returns whether the year is a leap year + */ + static bool IsLeapYear(int year) + { + if (!IsValidYear(year)) + { + assert(false && "Invalid year"); + } + + return (((year % 4) == 0 && (year % 100) != 0) || (year % 400) == 0); + } + + /** + * Checks whether the given year is valid + * @param[in] year the year to check + * @returns whether the year is valid + */ + static bool IsValidYear(int year) + { + bool valid = true; + if (year < 1 || year > 9999) + { + valid = false; + } + return valid; + } + + /** + * Check whether the year/month is valid + * @param[in] year the year to check + * @param[in] month the month to check + * @returns whether the year/month is valid + */ + static bool IsValidYearMonth(int year, int month) + { + bool valid = true; + if (IsValidYear(year)) + { + if (month < 1 || month > 12) + { + valid = false; + } + } + else + { + valid = false; + } + return valid; + } + + /** + * Check whether the year/month/day is valid + * @param[in] year the year to check + * @param[in] month the month to check + * @param[in] day the day to check + * @returns whether the year/month/day is valid + */ + static bool IsValidYearMonthDay(int year, int month, int day) + { + bool valid = true; + if (IsValidYearMonth(year, month)) + { + if (day < 1 || day > DaysInMonth(year, month)) + { + valid = false; + } + } + else + { + valid = false; + } + return valid; + } + + /** + * Find the number of days in a month given the year/month + * @param[in] year the year + * @param[in] month the month + * @returns the days in the given month + */ + static int DaysInMonth(int year, int month) + { + if (!IsValidYearMonth(year, month)) + { + assert(false && "Invalid year and month"); + } + + const int* daysInMonthPtr; + + if (IsLeapYear(year)) + { + daysInMonthPtr = daysInMonth[1]; + } + else + { + daysInMonthPtr = daysInMonth[0]; + } + + return daysInMonthPtr[month]; + } + + /** + * Find the day of the year given the year/month/day + * @param[in] year the year + * @param[in] month the month + * @param[in] day the day + * @returns the day of the year + */ + int DayOfYear(int year, int month, int day) const + { + if (!IsValidYearMonthDay(year, month, day)) + { + assert(false && "Invalid year, month and day"); + } + + int daysThisYear = day; + + if (IsLeapYear(year)) + { + daysThisYear += cumulDaysInMonth[1][month]; + } + else + { + daysThisYear += cumulDaysInMonth[0][month]; + } + + return daysThisYear; + } + + /** + * + */ + double AbsoluteDays(unsigned int year, double doy) const + { + int64_t previousYear = year - 1; + + /* + * + days in previous years ignoring leap days + * + Julian leap days before this year + * - minus prior century years + * + plus prior years divisible by 400 days + */ + int64_t daysSoFar = 365 * previousYear + + previousYear / 4LL + - previousYear / 100LL + + previousYear / 400LL; + + return static_cast(daysSoFar) + doy - 1.0; + } + + int AbsoluteDays(int year, int month, int day) const + { + int previousYear = year - 1; + + /* + * days this year (0 - ...) + * + days in previous years ignoring leap days + * + Julian leap days before this year + * - minus prior century years + * + plus prior years divisible by 400 days + */ + int result = DayOfYear(year, month, day) - 1 + + 365 * previousYear + + previousYear / 4 + - previousYear / 100 + + previousYear / 400; + + return result; + } + + TimeSpan TimeOfDay() const + { + return TimeSpan(Ticks() % TicksPerDay); + } + + int DayOfWeek() const + { + /* + * The fixed day 1 (January 1, 1 Gregorian) is Monday. + * 0 Sunday + * 1 Monday + * 2 Tuesday + * 3 Wednesday + * 4 Thursday + * 5 Friday + * 6 Saturday + */ + return static_cast(((m_encoded / TicksPerDay) + 1LL) % 7LL); + } + + bool Equals(const DateTime& dt) const + { + return (m_encoded == dt.m_encoded); + } + + int Compare(const DateTime& dt) const + { + int ret = 0; + + if (m_encoded < dt.m_encoded) + { + return -1; + } + else if (m_encoded > dt.m_encoded) + { + return 1; + } + + return ret; + } + + DateTime AddYears(const int years) const + { + return AddMonths(years * 12); + } + + DateTime AddMonths(const int months) const + { + int year; + int month; + int day; + FromTicks(year, month, day); + month += months % 12; + year += months / 12; + + if (month < 1) + { + month += 12; + --year; + } + else if (month > 12) + { + month -= 12; + ++year; + } + + int maxday = DaysInMonth(year, month); + day = std::min(day, maxday); + + return DateTime(year, month, day).Add(TimeOfDay()); + } + + /** + * Add a TimeSpan to this DateTime + * @param[in] t the TimeSpan to add + * @returns a DateTime which has the given TimeSpan added + */ + DateTime Add(const TimeSpan& t) const + { + return AddTicks(t.Ticks()); + } + + DateTime AddDays(const double days) const + { + return AddMicroseconds(days * 86400000000.0); + } + + DateTime AddHours(const double hours) const + { + return AddMicroseconds(hours * 3600000000.0); + } + + DateTime AddMinutes(const double minutes) const + { + return AddMicroseconds(minutes * 60000000.0); + } + + DateTime AddSeconds(const double seconds) const + { + return AddMicroseconds(seconds * 1000000.0); + } + + DateTime AddMicroseconds(const double microseconds) const + { + auto ticks = static_cast(microseconds * TicksPerMicrosecond); + return AddTicks(ticks); + } + + DateTime AddTicks(int64_t ticks) const + { + return DateTime(m_encoded + ticks); + } + + /** + * Get the number of ticks + * @returns the number of ticks + */ + int64_t Ticks() const + { + return m_encoded; + } + + void FromTicks(int& year, int& month, int& day) const + { + int totalDays = static_cast(m_encoded / TicksPerDay); + + /* + * number of 400 year cycles + */ + int num400 = totalDays / 146097; + totalDays -= num400 * 146097; + /* + * number of 100 year cycles + */ + int num100 = totalDays / 36524; + if (num100 == 4) + { + /* + * last day of the last leap century + */ + num100 = 3; + } + totalDays -= num100 * 36524; + /* + * number of 4 year cycles + */ + int num4 = totalDays / 1461; + totalDays -= num4 * 1461; + /* + * number of years + */ + int num1 = totalDays / 365; + if (num1 == 4) + { + /* + * last day of the last leap olympiad + */ + num1 = 3; + } + totalDays -= num1 * 365; + + /* + * find year + */ + year = (num400 * 400) + (num100 * 100) + (num4 * 4) + num1 + 1; + + /* + * convert day of year to month/day + */ + const int* daysInMonthPtr; + if (IsLeapYear(year)) + { + daysInMonthPtr = daysInMonth[1]; + } + else + { + daysInMonthPtr = daysInMonth[0]; + } + + month = 1; + while (totalDays >= daysInMonthPtr[month] && month <= 12) + { + totalDays -= daysInMonthPtr[month++]; + } + + day = totalDays + 1; + } + + int Year() const + { + int year; + int month; + int day; + FromTicks(year, month, day); + return year; + } + + int Month() const + { + int year; + int month; + int day; + FromTicks(year, month, day); + return month; + } + + int Day() const + { + int year; + int month; + int day; + FromTicks(year, month, day); + return day; + } + + /** + * Hour component + * @returns the hour component + */ + int Hour() const + { + return static_cast(m_encoded % TicksPerDay / TicksPerHour); + } + + /** + * Minute component + * @returns the minute component + */ + int Minute() const + { + return static_cast(m_encoded % TicksPerHour / TicksPerMinute); + } + + /** + * Second component + * @returns the Second component + */ + int Second() const + { + return static_cast(m_encoded % TicksPerMinute / TicksPerSecond); + } + + /** + * Microsecond component + * @returns the microsecond component + */ + int Microsecond() const + { + return static_cast(m_encoded % TicksPerSecond / TicksPerMicrosecond); + } + + /** + * Convert to a julian date + * @returns the julian date + */ + double ToJulian() const + { + auto ts = TimeSpan(Ticks()); + return ts.TotalDays() + 1721425.5; + } + + /** + * Convert to greenwich sidereal time + * @returns the greenwich sidereal time + */ + double ToGreenwichSiderealTime() const + { + // julian date of previous midnight + double jd0 = floor(ToJulian() + 0.5) - 0.5; + // julian centuries since epoch + double t = (jd0 - 2451545.0) / 36525.0; + double jdf = ToJulian() - jd0; + + double gt = 24110.54841 + t * (8640184.812866 + t * (0.093104 - t * 6.2E-6)); + gt += jdf * 1.00273790935 * 86400.0; + + // 360.0 / 86400.0 = 1.0 / 240.0 + return Util::WrapTwoPI(Util::DegreesToRadians(gt / 240.0)); + } + + /** + * Return the modified julian date since the j2000 epoch + * January 1, 2000, at 12:00 TT + * @returns the modified julian date + */ + double ToJ2000() const + { + return ToJulian() - 2415020.0; + } + + /** + * Convert to local mean sidereal time (GMST plus the observer's longitude) + * @param[in] lon observers longitude + * @returns the local mean sidereal time + */ + double ToLocalMeanSiderealTime(const double lon) const + { + return Util::WrapTwoPI(ToGreenwichSiderealTime() + lon); + } + + std::string ToString() const + { + std::stringstream ss; + int year; + int month; + int day; + FromTicks(year, month, day); + ss << std::right << std::setfill('0'); + ss << std::setw(4) << year << "-"; + ss << std::setw(2) << month << "-"; + ss << std::setw(2) << day << " "; + ss << std::setw(2) << Hour() << ":"; + ss << std::setw(2) << Minute() << ":"; + ss << std::setw(2) << Second() << "."; + ss << std::setw(6) << Microsecond() << " UTC"; + return ss.str(); + } + +private: + int64_t m_encoded{}; +}; + +inline std::ostream& operator<<(std::ostream& strm, const DateTime& dt) +{ + return strm << dt.ToString(); +} + +inline DateTime operator+(const DateTime& dt, TimeSpan ts) +{ + return DateTime(dt.Ticks() + ts.Ticks()); +} + +inline DateTime operator-(const DateTime& dt, const TimeSpan& ts) +{ + return DateTime(dt.Ticks() - ts.Ticks()); +} + +inline TimeSpan operator-(const DateTime& dt1, const DateTime& dt2) +{ + return TimeSpan(dt1.Ticks() - dt2.Ticks()); +} + +inline bool operator==(const DateTime& dt1, const DateTime& dt2) +{ + return dt1.Equals(dt2); +} + +inline bool operator>(const DateTime& dt1, const DateTime& dt2) +{ + return (dt1.Compare(dt2) > 0); +} + +inline bool operator>=(const DateTime& dt1, const DateTime& dt2) +{ + return (dt1.Compare(dt2) >= 0); +} + +inline bool operator!=(const DateTime& dt1, const DateTime& dt2) +{ + return !dt1.Equals(dt2); +} + +inline bool operator<(const DateTime& dt1, const DateTime& dt2) +{ + return (dt1.Compare(dt2) < 0); +} + +inline bool operator<=(const DateTime& dt1, const DateTime& dt2) +{ + return (dt1.Compare(dt2) <= 0); +} + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/DecayedException.cc b/SPG4Tool/libsgp4/DecayedException.cc new file mode 100644 index 0000000..2b4c522 --- /dev/null +++ b/SPG4Tool/libsgp4/DecayedException.cc @@ -0,0 +1 @@ +#include "DecayedException.h" diff --git a/SPG4Tool/libsgp4/DecayedException.h b/SPG4Tool/libsgp4/DecayedException.h new file mode 100644 index 0000000..b05d350 --- /dev/null +++ b/SPG4Tool/libsgp4/DecayedException.h @@ -0,0 +1,79 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include "DateTime.h" +#include "Vector.h" + +#include +#include + +namespace libsgp4 +{ + +/** + * @brief The exception that the SGP4 class throws when a satellite decays. + */ +class DecayedException : public std::runtime_error +{ +public: + /** + * Constructor + * @param[in] dt time of the event + * @param[in] pos position of the satellite at dt + * @param[in] vel velocity of the satellite at dt + */ + DecayedException(const DateTime& dt, const Vector& pos, const Vector& vel) + : runtime_error("Satellite decayed") + , _dt(dt) + , _pos(pos) + , _vel(vel) + { + } + + /** + * @returns the date + */ + DateTime Decayed() const + { + return _dt; + } + + /** + * @returns the position + */ + Vector Position() const + { + return _pos; + } + + /** + * @returns the velocity + */ + Vector Velocity() const + { + return _vel; + } + +private: + DateTime _dt; + Vector _pos; + Vector _vel; +}; + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/Eci.cc b/SPG4Tool/libsgp4/Eci.cc new file mode 100644 index 0000000..61d24bc --- /dev/null +++ b/SPG4Tool/libsgp4/Eci.cc @@ -0,0 +1,111 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "Eci.h" + +#include "Globals.h" +#include "Util.h" + +namespace libsgp4 +{ + +/** + * Converts a DateTime and Geodetic position to Eci coordinates + * @param[in] dt the date + * @param[in] geo the geodetic position + */ +void Eci::ToEci(const DateTime& dt, const CoordGeodetic &geo) +{ + /* + * set date + */ + m_dt = dt; + + static const double mfactor = kTWOPI * (kOMEGA_E / kSECONDS_PER_DAY); + + /* + * Calculate Local Mean Sidereal Time for observers longitude + */ + const double theta = m_dt.ToLocalMeanSiderealTime(geo.longitude); + + /* + * take into account earth flattening + */ + const double c = 1.0 + / sqrt(1.0 + kF * (kF - 2.0) * pow(sin(geo.latitude), 2.0)); + const double s = pow(1.0 - kF, 2.0) * c; + const double achcp = (kXKMPER * c + geo.altitude) * cos(geo.latitude); + + /* + * X position in km + * Y position in km + * Z position in km + * W magnitude in km + */ + m_position.x = achcp * cos(theta); + m_position.y = achcp * sin(theta); + m_position.z = (kXKMPER * s + geo.altitude) * sin(geo.latitude); + m_position.w = m_position.Magnitude(); + + /* + * X velocity in km/s + * Y velocity in km/s + * Z velocity in km/s + * W magnitude in km/s + */ + m_velocity.x = -mfactor * m_position.y; + m_velocity.y = mfactor * m_position.x; + m_velocity.z = 0.0; + m_velocity.w = m_velocity.Magnitude(); +} + +/** + * @returns the position in geodetic form + */ +CoordGeodetic Eci::ToGeodetic() const +{ + const double theta = Util::AcTan(m_position.y, m_position.x); + + const double lon = Util::WrapNegPosPI(theta + - m_dt.ToGreenwichSiderealTime()); + + const double r = sqrt((m_position.x * m_position.x) + + (m_position.y * m_position.y)); + + static const double e2 = kF * (2.0 - kF); + + double lat = Util::AcTan(m_position.z, r); + double phi = 0.0; + double c = 0.0; + int cnt = 0; + + do + { + phi = lat; + const double sinphi = sin(phi); + c = 1.0 / sqrt(1.0 - e2 * sinphi * sinphi); + lat = Util::AcTan(m_position.z + kXKMPER * c * e2 * sinphi, r); + cnt++; + } + while (fabs(lat - phi) >= 1e-10 && cnt < 10); + + const double alt = r / cos(lat) - kXKMPER * c; + + return CoordGeodetic(lat, lon, alt, true); +} + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/Eci.h b/SPG4Tool/libsgp4/Eci.h new file mode 100644 index 0000000..7a8197e --- /dev/null +++ b/SPG4Tool/libsgp4/Eci.h @@ -0,0 +1,146 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include "CoordGeodetic.h" +#include "Vector.h" +#include "DateTime.h" + +namespace libsgp4 +{ + +/** + * @brief Stores an Earth-centered inertial position for a particular time. + */ +class Eci +{ +public: + + /** + * @param[in] dt the date to be used for this position + * @param[in] latitude the latitude in degrees + * @param[in] longitude the longitude in degrees + * @param[in] altitude the altitude in kilometers + */ + Eci(const DateTime& dt, + const double latitude, + const double longitude, + const double altitude) + { + ToEci(dt, CoordGeodetic(latitude, longitude, altitude)); + } + + /** + * @param[in] dt the date to be used for this position + * @param[in] geo the position + */ + Eci(const DateTime& dt, const CoordGeodetic& geo) + { + ToEci(dt, geo); + } + + /** + * @param[in] dt the date to be used for this position + * @param[in] position the position + */ + Eci(const DateTime &dt, const Vector &position) + : m_dt(dt) + , m_position(position) + { + } + + /** + * @param[in] dt the date to be used for this position + * @param[in] position the position + * @param[in] velocity the velocity + */ + Eci(const DateTime &dt, const Vector &position, const Vector &velocity) + : m_dt(dt) + , m_position(position) + , m_velocity(velocity) + { + } + + /** + * Equality operator + * @param dt the date to compare + * @returns true if the object matches + */ + bool operator==(const DateTime& dt) const + { + return m_dt == dt; + } + + /** + * Inequality operator + * @param dt the date to compare + * @returns true if the object doesn't match + */ + bool operator!=(const DateTime& dt) const + { + return m_dt != dt; + } + + /** + * Update this object with a new date and geodetic position + * @param dt new date + * @param geo new geodetic position + */ + void Update(const DateTime& dt, const CoordGeodetic& geo) + { + ToEci(dt, geo); + } + + /** + * @returns the position + */ + Vector Position() const + { + return m_position; + } + + /** + * @returns the velocity + */ + Vector Velocity() const + { + return m_velocity; + } + + /** + * @returns the date + */ + DateTime GetDateTime() const + { + return m_dt; + } + + /** + * @returns the position in geodetic form + */ + CoordGeodetic ToGeodetic() const; + +private: + void ToEci(const DateTime& dt, const CoordGeodetic& geo); + + DateTime m_dt; + Vector m_position; + Vector m_velocity; +}; + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/Globals.cc b/SPG4Tool/libsgp4/Globals.cc new file mode 100644 index 0000000..dad80d5 --- /dev/null +++ b/SPG4Tool/libsgp4/Globals.cc @@ -0,0 +1,18 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "Globals.h" diff --git a/SPG4Tool/libsgp4/Globals.h b/SPG4Tool/libsgp4/Globals.h new file mode 100644 index 0000000..cfc3d0a --- /dev/null +++ b/SPG4Tool/libsgp4/Globals.h @@ -0,0 +1,77 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include + +namespace libsgp4 +{ + +const double kAE = 1.0; +const double kQ0 = 120.0; +const double kS0 = 78.0; +const double kMU = 398600.8; +const double kXKMPER = 6378.135; +const double kXJ2 = 1.082616e-3; +const double kXJ3 = -2.53881e-6; +const double kXJ4 = -1.65597e-6; + +/* + * alternative XKE + * affects final results + * aiaa-2006-6573 + * const double kXKE = 60.0 / sqrt(kXKMPER * kXKMPER * kXKMPER / kMU); + * dundee + * const double kXKE = 7.43669161331734132e-2; + */ +const double kXKE = 60.0 / sqrt(kXKMPER * kXKMPER * kXKMPER / kMU); +const double kCK2 = 0.5 * kXJ2 * kAE * kAE; +const double kCK4 = -0.375 * kXJ4 * kAE * kAE * kAE * kAE; + +/* + * alternative QOMS2T + * affects final results + * aiaa-2006-6573 + * #define QOMS2T (pow(((Q0 - S0) / XKMPER), 4.0)) + * dundee + * #define QOMS2T (1.880279159015270643865e-9) + */ +const double kQOMS2T = pow(((kQ0 - kS0) / kXKMPER), 4.0); + +const double kS = kAE * (1.0 + kS0 / kXKMPER); +const double kPI = 3.14159265358979323846264338327950288419716939937510582; +const double kTWOPI = 2.0 * kPI; +const double kTWOTHIRD = 2.0 / 3.0; +const double kTHDT = 4.37526908801129966e-3; +/* + * earth flattening + */ +const double kF = 1.0 / 298.26; +/* + * earth rotation per sideral day + */ +const double kOMEGA_E = 1.00273790934; +const double kAU = 1.49597870691e8; + +const double kSECONDS_PER_DAY = 86400.0; +const double kMINUTES_PER_DAY = 1440.0; +const double kHOURS_PER_DAY = 24.0; + +const double kA3OVK2 = -kXJ3 / kCK2 * kAE * kAE * kAE; + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/Observer.cc b/SPG4Tool/libsgp4/Observer.cc new file mode 100644 index 0000000..2065eef --- /dev/null +++ b/SPG4Tool/libsgp4/Observer.cc @@ -0,0 +1,86 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "Observer.h" +#include "CoordTopocentric.h" + +namespace libsgp4 +{ + +/* + * calculate lookangle between the observer and the passed in Eci object + */ +CoordTopocentric Observer::GetLookAngle(const Eci &eci) +{ + /* + * update the observers Eci to match the time of the Eci passed in + * if necessary + */ + Update(eci.GetDateTime()); + + /* + * calculate differences + */ + Vector range_rate = eci.Velocity() - m_eci.Velocity(); + Vector range = eci.Position() - m_eci.Position(); + + range.w = range.Magnitude(); + + /* + * Calculate Local Mean Sidereal Time for observers longitude + */ + double theta = eci.GetDateTime().ToLocalMeanSiderealTime(m_geo.longitude); + + double sin_lat = sin(m_geo.latitude); + double cos_lat = cos(m_geo.latitude); + double sin_theta = sin(theta); + double cos_theta = cos(theta); + + double top_s = sin_lat * cos_theta * range.x + + sin_lat * sin_theta * range.y - cos_lat * range.z; + double top_e = -sin_theta * range.x + + cos_theta * range.y; + double top_z = cos_lat * cos_theta * range.x + + cos_lat * sin_theta * range.y + sin_lat * range.z; + double az = atan(-top_e / top_s); + + if (top_s > 0.0) + { + az += kPI; + } + + if (az < 0.0) + { + az += 2.0 * kPI; + } + + double el = asin(top_z / range.w); + double rate = range.Dot(range_rate) / range.w; + + /* + * azimuth in radians + * elevation in radians + * range in km + * range rate in km/s + */ + return CoordTopocentric(az, + el, + range.w, + rate); +} + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/Observer.h b/SPG4Tool/libsgp4/Observer.h new file mode 100644 index 0000000..89387e8 --- /dev/null +++ b/SPG4Tool/libsgp4/Observer.h @@ -0,0 +1,103 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include "CoordGeodetic.h" +#include "Eci.h" + +namespace libsgp4 +{ + +class DateTime; +struct CoordTopocentric; + +/** + * @brief Stores an observers location in Eci coordinates. + */ +class Observer +{ +public: + /** + * Constructor + * @param[in] latitude observers latitude in degrees + * @param[in] longitude observers longitude in degrees + * @param[in] altitude observers altitude in kilometers + */ + Observer(const double latitude, + const double longitude, + const double altitude) + : m_geo(latitude, longitude, altitude) + , m_eci(DateTime(), m_geo) + { + } + + /** + * Constructor + * @param[in] geo the observers position + */ + explicit Observer(const CoordGeodetic &geo) + : m_geo(geo) + , m_eci(DateTime(), geo) + { + } + + /** + * Set the observers location + * @param[in] geo the observers position + */ + void SetLocation(const CoordGeodetic& geo) + { + m_geo = geo; + m_eci.Update(m_eci.GetDateTime(), m_geo); + } + + /** + * Get the observers location + * @returns the observers position + */ + CoordGeodetic GetLocation() const + { + return m_geo; + } + + /** + * Get the look angle for the observers position to the object + * @param[in] eci the object to find the look angle to + * @returns the lookup angle + */ + CoordTopocentric GetLookAngle(const Eci &eci); + +private: + /** + * @param[in] dt the date to update the observers position for + */ + void Update(const DateTime &dt) + { + if (m_eci != dt) + { + m_eci.Update(dt, m_geo); + } + } + + /** the observers position */ + CoordGeodetic m_geo; + /** the observers Eci for a particular time */ + Eci m_eci; +}; + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/OrbitalElements.cc b/SPG4Tool/libsgp4/OrbitalElements.cc new file mode 100644 index 0000000..7e85720 --- /dev/null +++ b/SPG4Tool/libsgp4/OrbitalElements.cc @@ -0,0 +1,70 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "OrbitalElements.h" + +#include "Tle.h" + +namespace libsgp4 +{ + +OrbitalElements::OrbitalElements(const Tle& tle) +{ + /* + * extract and format tle data + */ + mean_anomoly_ = tle.MeanAnomaly(false); + ascending_node_ = tle.RightAscendingNode(false); + argument_perigee_ = tle.ArgumentPerigee(false); + eccentricity_ = tle.Eccentricity(); + inclination_ = tle.Inclination(false); + mean_motion_ = tle.MeanMotion() * kTWOPI / kMINUTES_PER_DAY; + bstar_ = tle.BStar(); + epoch_ = tle.Epoch(); + + /* + * recover original mean motion (xnodp) and semimajor axis (aodp) + * from input elements + */ + const double a1 = pow(kXKE / MeanMotion(), kTWOTHIRD); + const double cosio = cos(Inclination()); + const double theta2 = cosio * cosio; + const double x3thm1 = 3.0 * theta2 - 1.0; + const double eosq = Eccentricity() * Eccentricity(); + const double betao2 = 1.0 - eosq; + const double betao = sqrt(betao2); + const double temp = (1.5 * kCK2) * x3thm1 / (betao * betao2); + const double del1 = temp / (a1 * a1); + const double a0 = a1 * (1.0 - del1 * (1.0 / 3.0 + del1 * (1.0 + del1 * 134.0 / 81.0))); + const double del0 = temp / (a0 * a0); + + recovered_mean_motion_ = MeanMotion() / (1.0 + del0); + /* + * alternative way to calculate + * doesnt affect final results + * recovered_semi_major_axis_ = pow(XKE / RecoveredMeanMotion(), TWOTHIRD); + */ + recovered_semi_major_axis_ = a0 / (1.0 - del0); + + /* + * find perigee and period + */ + perigee_ = (RecoveredSemiMajorAxis() * (1.0 - Eccentricity()) - kAE) * kXKMPER; + period_ = kTWOPI / RecoveredMeanMotion(); +} + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/OrbitalElements.h b/SPG4Tool/libsgp4/OrbitalElements.h new file mode 100644 index 0000000..9ce389a --- /dev/null +++ b/SPG4Tool/libsgp4/OrbitalElements.h @@ -0,0 +1,147 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include "Util.h" +#include "DateTime.h" + +namespace libsgp4 +{ + +class Tle; + +/** + * @brief The extracted orbital elements used by the SGP4 propagator. + */ +class OrbitalElements +{ +public: + explicit OrbitalElements(const Tle& tle); + + /* + * XMO + */ + double MeanAnomoly() const + { + return mean_anomoly_; + } + + /* + * XNODEO + */ + double AscendingNode() const + { + return ascending_node_; + } + + /* + * OMEGAO + */ + double ArgumentPerigee() const + { + return argument_perigee_; + } + + /* + * EO + */ + double Eccentricity() const + { + return eccentricity_; + } + + /* + * XINCL + */ + double Inclination() const + { + return inclination_; + } + + /* + * XNO + */ + double MeanMotion() const + { + return mean_motion_; + } + + /* + * BSTAR + */ + double BStar() const + { + return bstar_; + } + + /* + * AODP + */ + double RecoveredSemiMajorAxis() const + { + return recovered_semi_major_axis_; + } + + /* + * XNODP + */ + double RecoveredMeanMotion() const + { + return recovered_mean_motion_; + } + + /* + * PERIGE + */ + double Perigee() const + { + return perigee_; + } + + /* + * Period in minutes + */ + double Period() const + { + return period_; + } + + /* + * EPOCH + */ + DateTime Epoch() const + { + return epoch_; + } + +private: + double mean_anomoly_; + double ascending_node_; + double argument_perigee_; + double eccentricity_; + double inclination_; + double mean_motion_; + double bstar_; + double recovered_semi_major_axis_; + double recovered_mean_motion_; + double perigee_; + double period_; + DateTime epoch_; +}; + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/SGP4.cc b/SPG4Tool/libsgp4/SGP4.cc new file mode 100644 index 0000000..ecd9026 --- /dev/null +++ b/SPG4Tool/libsgp4/SGP4.cc @@ -0,0 +1,1353 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "SGP4.h" + +#include "Util.h" +#include "Vector.h" +#include "SatelliteException.h" +#include "DecayedException.h" + +#include +#include +#include + +namespace libsgp4 +{ + +void SGP4::SetTle(const Tle& tle) +{ + /* + * extract and format tle data + */ + elements_ = OrbitalElements(tle); + + Initialise(); +} + +void SGP4::Initialise() +{ + /* + * reset all constants etc + */ + Reset(); + + /* + * error checks + */ + if (elements_.Eccentricity() < 0.0 || elements_.Eccentricity() > 0.999) + { + throw SatelliteException("Eccentricity out of range"); + } + + if (elements_.Inclination() < 0.0 || elements_.Inclination() > kPI) + { + throw SatelliteException("Inclination out of range"); + } + + RecomputeConstants(elements_.Inclination(), + common_consts_.sinio, + common_consts_.cosio, + common_consts_.x3thm1, + common_consts_.x1mth2, + common_consts_.x7thm1, + common_consts_.xlcof, + common_consts_.aycof); + + const double theta2 = common_consts_.cosio * common_consts_.cosio; + const double eosq = elements_.Eccentricity() * elements_.Eccentricity(); + const double betao2 = 1.0 - eosq; + const double betao = sqrt(betao2); + + if (elements_.Period() >= 225.0) + { + use_deep_space_ = true; + } + else + { + use_deep_space_ = false; + use_simple_model_ = false; + /* + * for perigee less than 220 kilometers, the simple_model flag is set + * and the equations are truncated to linear variation in sqrt a and + * quadratic variation in mean anomly. also, the c3 term, the + * delta omega term and the delta m term are dropped + */ + if (elements_.Perigee() < 220.0) + { + use_simple_model_ = true; + } + } + + /* + * for perigee below 156km, the values of + * s4 and qoms2t are altered + */ + double s4 = kS; + double qoms24 = kQOMS2T; + if (elements_.Perigee() < 156.0) + { + s4 = elements_.Perigee() - 78.0; + if (elements_.Perigee() < 98.0) + { + s4 = 20.0; + } + qoms24 = pow((120.0 - s4) * kAE / kXKMPER, 4.0); + s4 = s4 / kXKMPER + kAE; + } + + /* + * generate constants + */ + const double pinvsq = 1.0 + / (elements_.RecoveredSemiMajorAxis() + * elements_.RecoveredSemiMajorAxis() + * betao2 * betao2); + const double tsi = 1.0 / (elements_.RecoveredSemiMajorAxis() - s4); + common_consts_.eta = elements_.RecoveredSemiMajorAxis() + * elements_.Eccentricity() * tsi; + const double etasq = common_consts_.eta * common_consts_.eta; + const double eeta = elements_.Eccentricity() * common_consts_.eta; + const double psisq = fabs(1.0 - etasq); + const double coef = qoms24 * pow(tsi, 4.0); + const double coef1 = coef / pow(psisq, 3.5); + const double c2 = coef1 * elements_.RecoveredMeanMotion() + * (elements_.RecoveredSemiMajorAxis() + * (1.0 + 1.5 * etasq + eeta * (4.0 + etasq)) + + 0.75 * kCK2 * tsi / psisq * common_consts_.x3thm1 + * (8.0 + 3.0 * etasq * (8.0 + etasq))); + common_consts_.c1 = elements_.BStar() * c2; + common_consts_.c4 = 2.0 * elements_.RecoveredMeanMotion() + * coef1 * elements_.RecoveredSemiMajorAxis() * betao2 + * (common_consts_.eta * (2.0 + 0.5 * etasq) + elements_.Eccentricity() + * (0.5 + 2.0 * etasq) + - 2.0 * kCK2 * tsi / (elements_.RecoveredSemiMajorAxis() * psisq) + * (-3.0 * common_consts_.x3thm1 * (1.0 - 2.0 * eeta + etasq + * (1.5 - 0.5 * eeta)) + + 0.75 * common_consts_.x1mth2 * (2.0 * etasq - eeta * + (1.0 + etasq)) * cos(2.0 * elements_.ArgumentPerigee()))); + const double theta4 = theta2 * theta2; + const double temp1 = 3.0 * kCK2 * pinvsq * elements_.RecoveredMeanMotion(); + const double temp2 = temp1 * kCK2 * pinvsq; + const double temp3 = 1.25 * kCK4 * pinvsq * pinvsq * elements_.RecoveredMeanMotion(); + common_consts_.xmdot = elements_.RecoveredMeanMotion() + 0.5 * temp1 * betao * + common_consts_.x3thm1 + 0.0625 * temp2 * betao * + (13.0 - 78.0 * theta2 + 137.0 * theta4); + const double x1m5th = 1.0 - 5.0 * theta2; + common_consts_.omgdot = -0.5 * temp1 * x1m5th + + 0.0625 * temp2 * (7.0 - 114.0 * theta2 + 395.0 * theta4) + + temp3 * (3.0 - 36.0 * theta2 + 49.0 * theta4); + const double xhdot1 = -temp1 * common_consts_.cosio; + common_consts_.xnodot = xhdot1 + (0.5 * temp2 * (4.0 - 19.0 * theta2) + 2.0 * temp3 * + (3.0 - 7.0 * theta2)) * common_consts_.cosio; + common_consts_.xnodcf = 3.5 * betao2 * xhdot1 * common_consts_.c1; + common_consts_.t2cof = 1.5 * common_consts_.c1; + + if (use_deep_space_) + { + deepspace_consts_.gsto = elements_.Epoch().ToGreenwichSiderealTime(); + + DeepSpaceInitialise(eosq, + common_consts_.sinio, + common_consts_.cosio, + betao, + theta2, + betao2, + common_consts_.xmdot, + common_consts_.omgdot, + common_consts_.xnodot); + } + else + { + double c3 = 0.0; + if (elements_.Eccentricity() > 1.0e-4) + { + c3 = coef * tsi * kA3OVK2 * elements_.RecoveredMeanMotion() * kAE * + common_consts_.sinio / elements_.Eccentricity(); + } + + nearspace_consts_.c5 = 2.0 * coef1 * elements_.RecoveredSemiMajorAxis() * betao2 * (1.0 + 2.75 * + (etasq + eeta) + eeta * etasq); + nearspace_consts_.omgcof = elements_.BStar() * c3 * cos(elements_.ArgumentPerigee()); + + nearspace_consts_.xmcof = 0.0; + if (elements_.Eccentricity() > 1.0e-4) + { + nearspace_consts_.xmcof = -kTWOTHIRD * coef * elements_.BStar() * kAE / eeta; + } + + nearspace_consts_.delmo = pow(1.0 + common_consts_.eta * (cos(elements_.MeanAnomoly())), 3.0); + nearspace_consts_.sinmo = sin(elements_.MeanAnomoly()); + + if (!use_simple_model_) + { + const double c1sq = common_consts_.c1 * common_consts_.c1; + nearspace_consts_.d2 = 4.0 * elements_.RecoveredSemiMajorAxis() * tsi * c1sq; + const double temp = nearspace_consts_.d2 * tsi * common_consts_.c1 / 3.0; + nearspace_consts_.d3 = (17.0 * elements_.RecoveredSemiMajorAxis() + s4) * temp; + nearspace_consts_.d4 = 0.5 * temp * elements_.RecoveredSemiMajorAxis() * + tsi * (221.0 * elements_.RecoveredSemiMajorAxis() + 31.0 * s4) * common_consts_.c1; + nearspace_consts_.t3cof = nearspace_consts_.d2 + 2.0 * c1sq; + nearspace_consts_.t4cof = 0.25 * (3.0 * nearspace_consts_.d3 + common_consts_.c1 * + (12.0 * nearspace_consts_.d2 + 10.0 * c1sq)); + nearspace_consts_.t5cof = 0.2 * (3.0 * nearspace_consts_.d4 + 12.0 * common_consts_.c1 * + nearspace_consts_.d3 + 6.0 * nearspace_consts_.d2 * nearspace_consts_.d2 + 15.0 * + c1sq * (2.0 * nearspace_consts_.d2 + c1sq)); + } + } +} + +Eci SGP4::FindPosition(const DateTime& dt) const +{ + return FindPosition((dt - elements_.Epoch()).TotalMinutes()); +} + +Eci SGP4::FindPosition(double tsince) const +{ + if (use_deep_space_) + { + return FindPositionSDP4(tsince); + } + else + { + return FindPositionSGP4(tsince); + } +} + +Eci SGP4::FindPositionSDP4(double tsince) const +{ + /* + * the final values + */ + double e; + double a; + double omega; + double xl; + double xnode; + double xinc; + + /* + * update for secular gravity and atmospheric drag + */ + double xmdf = elements_.MeanAnomoly() + + common_consts_.xmdot * tsince; + double omgadf = elements_.ArgumentPerigee() + + common_consts_.omgdot * tsince; + const double xnoddf = elements_.AscendingNode() + + common_consts_.xnodot * tsince; + + const double tsq = tsince * tsince; + xnode = xnoddf + common_consts_.xnodcf * tsq; + double tempa = 1.0 - common_consts_.c1 * tsince; + double tempe = elements_.BStar() * common_consts_.c4 * tsince; + double templ = common_consts_.t2cof * tsq; + + double xn = elements_.RecoveredMeanMotion(); + double em = elements_.Eccentricity(); + xinc = elements_.Inclination(); + + DeepSpaceSecular(tsince, + elements_, + common_consts_, + deepspace_consts_, + integrator_params_, + xmdf, + omgadf, + xnode, + em, + xinc, + xn); + + if (xn <= 0.0) + { + throw SatelliteException("Error: (xn <= 0.0)"); + } + + a = pow(kXKE / xn, kTWOTHIRD) * tempa * tempa; + e = em - tempe; + double xmam = xmdf + elements_.RecoveredMeanMotion() * templ; + + DeepSpacePeriodics(tsince, + deepspace_consts_, + e, + xinc, + omgadf, + xnode, + xmam); + + /* + * keeping xinc positive important unless you need to display xinc + * and dislike negative inclinations + */ + if (xinc < 0.0) + { + xinc = -xinc; + xnode += kPI; + omgadf -= kPI; + } + + xl = xmam + omgadf + xnode; + omega = omgadf; + + /* + * fix tolerance for error recognition + */ + if (e <= -0.001) + { + throw SatelliteException("Error: (e <= -0.001)"); + } + else if (e < 1.0e-6) + { + e = 1.0e-6; + } + else if (e > (1.0 - 1.0e-6)) + { + e = 1.0 - 1.0e-6; + } + + /* + * re-compute the perturbed values + */ + double perturbed_sinio; + double perturbed_cosio; + double perturbed_x3thm1; + double perturbed_x1mth2; + double perturbed_x7thm1; + double perturbed_xlcof; + double perturbed_aycof; + RecomputeConstants(xinc, + perturbed_sinio, + perturbed_cosio, + perturbed_x3thm1, + perturbed_x1mth2, + perturbed_x7thm1, + perturbed_xlcof, + perturbed_aycof); + + /* + * using calculated values, find position and velocity + */ + return CalculateFinalPositionVelocity(elements_.Epoch().AddMinutes(tsince), + e, + a, + omega, + xl, + xnode, + xinc, + perturbed_xlcof, + perturbed_aycof, + perturbed_x3thm1, + perturbed_x1mth2, + perturbed_x7thm1, + perturbed_cosio, + perturbed_sinio); +} + +void SGP4::RecomputeConstants(const double xinc, + double& sinio, + double& cosio, + double& x3thm1, + double& x1mth2, + double& x7thm1, + double& xlcof, + double& aycof) +{ + sinio = sin(xinc); + cosio = cos(xinc); + + const double theta2 = cosio * cosio; + + x3thm1 = 3.0 * theta2 - 1.0; + x1mth2 = 1.0 - theta2; + x7thm1 = 7.0 * theta2 - 1.0; + + if (fabs(cosio + 1.0) > 1.5e-12) + { + xlcof = 0.125 * kA3OVK2 * sinio * (3.0 + 5.0 * cosio) / (1.0 + cosio); + } + else + { + xlcof = 0.125 * kA3OVK2 * sinio * (3.0 + 5.0 * cosio) / 1.5e-12; + } + + aycof = 0.25 * kA3OVK2 * sinio; +} + +Eci SGP4::FindPositionSGP4(double tsince) const +{ + /* + * the final values + */ + double e; + double a; + double omega; + double xl; + double xnode; + const double xinc = elements_.Inclination(); + + /* + * update for secular gravity and atmospheric drag + */ + const double xmdf = elements_.MeanAnomoly() + + common_consts_.xmdot * tsince; + const double omgadf = elements_.ArgumentPerigee() + + common_consts_.omgdot * tsince; + const double xnoddf = elements_.AscendingNode() + + common_consts_.xnodot * tsince; + + omega = omgadf; + double xmp = xmdf; + + const double tsq = tsince * tsince; + xnode = xnoddf + common_consts_.xnodcf * tsq; + double tempa = 1.0 - common_consts_.c1 * tsince; + double tempe = elements_.BStar() * common_consts_.c4 * tsince; + double templ = common_consts_.t2cof * tsq; + + if (!use_simple_model_) + { + const double delomg = nearspace_consts_.omgcof * tsince; + const double delm = nearspace_consts_.xmcof + * (pow(1.0 + common_consts_.eta * cos(xmdf), 3.0) + - nearspace_consts_.delmo); + const double temp = delomg + delm; + + xmp += temp; + omega -= temp; + + const double tcube = tsq * tsince; + const double tfour = tsince * tcube; + + tempa = tempa - nearspace_consts_.d2 * tsq - nearspace_consts_.d3 + * tcube - nearspace_consts_.d4 * tfour; + tempe += elements_.BStar() * nearspace_consts_.c5 + * (sin(xmp) - nearspace_consts_.sinmo); + templ += nearspace_consts_.t3cof * tcube + tfour + * (nearspace_consts_.t4cof + tsince * nearspace_consts_.t5cof); + } + + a = elements_.RecoveredSemiMajorAxis() * tempa * tempa; + e = elements_.Eccentricity() - tempe; + xl = xmp + omega + xnode + elements_.RecoveredMeanMotion() * templ; + + /* + * fix tolerance for error recognition + */ + if (e <= -0.001) + { + throw SatelliteException("Error: (e <= -0.001)"); + } + else if (e < 1.0e-6) + { + e = 1.0e-6; + } + else if (e > (1.0 - 1.0e-6)) + { + e = 1.0 - 1.0e-6; + } + + /* + * using calculated values, find position and velocity + * we can pass in constants from Initialise() as these dont change + */ + return CalculateFinalPositionVelocity(elements_.Epoch().AddMinutes(tsince), + e, + a, + omega, + xl, + xnode, + xinc, + common_consts_.xlcof, + common_consts_.aycof, + common_consts_.x3thm1, + common_consts_.x1mth2, + common_consts_.x7thm1, + common_consts_.cosio, + common_consts_.sinio); +} + +Eci SGP4::CalculateFinalPositionVelocity( + const DateTime& dt, + const double e, + const double a, + const double omega, + const double xl, + const double xnode, + const double xinc, + const double xlcof, + const double aycof, + const double x3thm1, + const double x1mth2, + const double x7thm1, + const double cosio, + const double sinio) +{ + const double beta2 = 1.0 - e * e; + const double xn = kXKE / pow(a, 1.5); + /* + * long period periodics + */ + const double axn = e * cos(omega); + const double temp11 = 1.0 / (a * beta2); + const double xll = temp11 * xlcof * axn; + const double aynl = temp11 * aycof; + const double xlt = xl + xll; + const double ayn = e * sin(omega) + aynl; + const double elsq = axn * axn + ayn * ayn; + + if (elsq >= 1.0) + { + throw SatelliteException("Error: (elsq >= 1.0)"); + } + + /* + * solve keplers equation + * - solve using Newton-Raphson root solving + * - here capu is almost the mean anomoly + * - initialise the eccentric anomaly term epw + * - The fmod saves reduction of angle to +/-2pi in sin/cos() and prevents + * convergence problems. + */ + const double capu = fmod(xlt - xnode, kTWOPI); + double epw = capu; + + double sinepw = 0.0; + double cosepw = 0.0; + double ecose = 0.0; + double esine = 0.0; + + /* + * sensibility check for N-R correction + */ + const double max_newton_naphson = 1.25 * fabs(sqrt(elsq)); + + bool kepler_running = true; + + for (int i = 0; i < 10 && kepler_running; i++) + { + sinepw = sin(epw); + cosepw = cos(epw); + ecose = axn * cosepw + ayn * sinepw; + esine = axn * sinepw - ayn * cosepw; + + double f = capu - epw + esine; + + if (fabs(f) < 1.0e-12) + { + kepler_running = false; + } + else + { + /* + * 1st order Newton-Raphson correction + */ + const double fdot = 1.0 - ecose; + double delta_epw = f / fdot; + + /* + * 2nd order Newton-Raphson correction. + * f / (fdot - 0.5 * d2f * f/fdot) + */ + if (i == 0) + { + if (delta_epw > max_newton_naphson) + { + delta_epw = max_newton_naphson; + } + else if (delta_epw < -max_newton_naphson) + { + delta_epw = -max_newton_naphson; + } + } + else + { + delta_epw = f / (fdot + 0.5 * esine * delta_epw); + } + + /* + * Newton-Raphson correction of -F/DF + */ + epw += delta_epw; + } + } + /* + * short period preliminary quantities + */ + const double temp21 = 1.0 - elsq; + const double pl = a * temp21; + + if (pl < 0.0) + { + throw SatelliteException("Error: (pl < 0.0)"); + } + + const double r = a * (1.0 - ecose); + const double temp31 = 1.0 / r; + const double rdot = kXKE * sqrt(a) * esine * temp31; + const double rfdot = kXKE * sqrt(pl) * temp31; + const double temp32 = a * temp31; + const double betal = sqrt(temp21); + const double temp33 = 1.0 / (1.0 + betal); + const double cosu = temp32 * (cosepw - axn + ayn * esine * temp33); + const double sinu = temp32 * (sinepw - ayn - axn * esine * temp33); + const double u = atan2(sinu, cosu); + const double sin2u = 2.0 * sinu * cosu; + const double cos2u = 2.0 * cosu * cosu - 1.0; + + /* + * update for short periodics + */ + const double temp41 = 1.0 / pl; + const double temp42 = kCK2 * temp41; + const double temp43 = temp42 * temp41; + + const double rk = r * (1.0 - 1.5 * temp43 * betal * x3thm1) + + 0.5 * temp42 * x1mth2 * cos2u; + const double uk = u - 0.25 * temp43 * x7thm1 * sin2u; + const double xnodek = xnode + 1.5 * temp43 * cosio * sin2u; + const double xinck = xinc + 1.5 * temp43 * cosio * sinio * cos2u; + const double rdotk = rdot - xn * temp42 * x1mth2 * sin2u; + const double rfdotk = rfdot + xn * temp42 * (x1mth2 * cos2u + 1.5 * x3thm1); + + /* + * orientation vectors + */ + const double sinuk = sin(uk); + const double cosuk = cos(uk); + const double sinik = sin(xinck); + const double cosik = cos(xinck); + const double sinnok = sin(xnodek); + const double cosnok = cos(xnodek); + const double xmx = -sinnok * cosik; + const double xmy = cosnok * cosik; + const double ux = xmx * sinuk + cosnok * cosuk; + const double uy = xmy * sinuk + sinnok * cosuk; + const double uz = sinik * sinuk; + const double vx = xmx * cosuk - cosnok * sinuk; + const double vy = xmy * cosuk - sinnok * sinuk; + const double vz = sinik * cosuk; + /* + * position and velocity + */ + const double x = rk * ux * kXKMPER; + const double y = rk * uy * kXKMPER; + const double z = rk * uz * kXKMPER; + Vector position(x, y, z); + const double xdot = (rdotk * ux + rfdotk * vx) * kXKMPER / 60.0; + const double ydot = (rdotk * uy + rfdotk * vy) * kXKMPER / 60.0; + const double zdot = (rdotk * uz + rfdotk * vz) * kXKMPER / 60.0; + Vector velocity(xdot, ydot, zdot); + + if (rk < 1.0) + { + throw DecayedException( + dt, + position, + velocity); + } + + return Eci(dt, position, velocity); +} + +static inline double EvaluateCubicPolynomial( + const double x, + const double constant, + const double linear, + const double squared, + const double cubed) +{ + return constant + x * linear + x * x * squared + x * x * x * cubed; +} + +void SGP4::DeepSpaceInitialise( + const double eosq, + const double sinio, + const double cosio, + const double betao, + const double theta2, + const double betao2, + const double xmdot, + const double omgdot, + const double xnodot) +{ + double se = 0.0; + double si = 0.0; + double sl = 0.0; + double sgh = 0.0; + double shdq = 0.0; + + double bfact = 0.0; + + static const double ZNS = 1.19459E-5; + static const double C1SS = 2.9864797E-6; + static const double ZES = 0.01675; + static const double ZNL = 1.5835218E-4; + static const double C1L = 4.7968065E-7; + static const double ZEL = 0.05490; + static const double ZCOSIS = 0.91744867; + static const double ZSINI = 0.39785416; + static const double ZSINGS = -0.98088458; + static const double ZCOSGS = 0.1945905; + static const double Q22 = 1.7891679E-6; + static const double Q31 = 2.1460748E-6; + static const double Q33 = 2.2123015E-7; + static const double ROOT22 = 1.7891679E-6; + static const double ROOT32 = 3.7393792E-7; + static const double ROOT44 = 7.3636953E-9; + static const double ROOT52 = 1.1428639E-7; + static const double ROOT54 = 2.1765803E-9; + + const double aqnv = 1.0 / elements_.RecoveredSemiMajorAxis(); + const double xpidot = omgdot + xnodot; + const double sinq = sin(elements_.AscendingNode()); + const double cosq = cos(elements_.AscendingNode()); + const double sing = sin(elements_.ArgumentPerigee()); + const double cosg = cos(elements_.ArgumentPerigee()); + + /* + * initialize lunar / solar terms + */ + const double jday = elements_.Epoch().ToJ2000(); + + const double xnodce = Util::WrapTwoPI(4.5236020 - 9.2422029e-4 * jday); + const double stem = sin(xnodce); + const double ctem = cos(xnodce); + const double zcosil = 0.91375164 - 0.03568096 * ctem; + const double zsinil = sqrt(1.0 - zcosil * zcosil); + const double zsinhl = 0.089683511 * stem / zsinil; + const double zcoshl = sqrt(1.0 - zsinhl * zsinhl); + const double c = 4.7199672 + 0.22997150 * jday; + const double gam = 5.8351514 + 0.0019443680 * jday; + deepspace_consts_.zmol = Util::WrapTwoPI(c - gam); + double zx = 0.39785416 * stem / zsinil; + double zy = zcoshl * ctem + 0.91744867 * zsinhl * stem; + zx = atan2(zx, zy); + zx = gam + zx - xnodce; + + const double zcosgl = cos(zx); + const double zsingl = sin(zx); + deepspace_consts_.zmos = Util::WrapTwoPI(6.2565837 + 0.017201977 * jday); + + /* + * do solar terms + */ + double zcosg = ZCOSGS; + double zsing = ZSINGS; + double zcosi = ZCOSIS; + double zsini = ZSINI; + double zcosh = cosq; + double zsinh = sinq; + double cc = C1SS; + double zn = ZNS; + double ze = ZES; + const double xnoi = 1.0 / elements_.RecoveredMeanMotion(); + + for (int cnt = 0; cnt < 2; cnt++) + { + /* + * solar terms are done a second time after lunar terms are done + */ + const double a1 = zcosg * zcosh + zsing * zcosi * zsinh; + const double a3 = -zsing * zcosh + zcosg * zcosi * zsinh; + const double a7 = -zcosg * zsinh + zsing * zcosi * zcosh; + const double a8 = zsing * zsini; + const double a9 = zsing * zsinh + zcosg * zcosi*zcosh; + const double a10 = zcosg * zsini; + const double a2 = cosio * a7 + sinio * a8; + const double a4 = cosio * a9 + sinio * a10; + const double a5 = -sinio * a7 + cosio * a8; + const double a6 = -sinio * a9 + cosio * a10; + const double x1 = a1 * cosg + a2 * sing; + const double x2 = a3 * cosg + a4 * sing; + const double x3 = -a1 * sing + a2 * cosg; + const double x4 = -a3 * sing + a4 * cosg; + const double x5 = a5 * sing; + const double x6 = a6 * sing; + const double x7 = a5 * cosg; + const double x8 = a6 * cosg; + const double z31 = 12.0 * x1 * x1 - 3. * x3 * x3; + const double z32 = 24.0 * x1 * x2 - 6. * x3 * x4; + const double z33 = 12.0 * x2 * x2 - 3. * x4 * x4; + double z1 = 3.0 * (a1 * a1 + a2 * a2) + z31 * eosq; + double z2 = 6.0 * (a1 * a3 + a2 * a4) + z32 * eosq; + double z3 = 3.0 * (a3 * a3 + a4 * a4) + z33 * eosq; + + const double z11 = -6.0 * a1 * a5 + + eosq * (-24. * x1 * x7 - 6. * x3 * x5); + const double z12 = -6.0 * (a1 * a6 + a3 * a5) + + eosq * (-24. * (x2 * x7 + x1 * x8) - 6. * (x3 * x6 + x4 * x5)); + const double z13 = -6.0 * a3 * a6 + + eosq * (-24. * x2 * x8 - 6. * x4 * x6); + const double z21 = 6.0 * a2 * a5 + + eosq * (24. * x1 * x5 - 6. * x3 * x7); + const double z22 = 6.0 * (a4 * a5 + a2 * a6) + + eosq * (24. * (x2 * x5 + x1 * x6) - 6. * (x4 * x7 + x3 * x8)); + const double z23 = 6.0 * a4 * a6 + + eosq * (24. * x2 * x6 - 6. * x4 * x8); + + z1 = z1 + z1 + betao2 * z31; + z2 = z2 + z2 + betao2 * z32; + z3 = z3 + z3 + betao2 * z33; + + const double s3 = cc * xnoi; + const double s2 = -0.5 * s3 / betao; + const double s4 = s3 * betao; + const double s1 = -15.0 * elements_.Eccentricity() * s4; + const double s5 = x1 * x3 + x2 * x4; + const double s6 = x2 * x3 + x1 * x4; + const double s7 = x2 * x4 - x1 * x3; + + se = s1 * zn * s5; + si = s2 * zn * (z11 + z13); + sl = -zn * s3 * (z1 + z3 - 14.0 - 6.0 * eosq); + sgh = s4 * zn * (z31 + z33 - 6.0); + + /* + * replaced + * sh = -zn * s2 * (z21 + z23 + * with + * shdq = (-zn * s2 * (z21 + z23)) / sinio + */ + if (elements_.Inclination() < 5.2359877e-2 + || elements_.Inclination() > kPI - 5.2359877e-2) + { + shdq = 0.0; + } + else + { + shdq = (-zn * s2 * (z21 + z23)) / sinio; + } + + deepspace_consts_.ee2 = 2.0 * s1 * s6; + deepspace_consts_.e3 = 2.0 * s1 * s7; + deepspace_consts_.xi2 = 2.0 * s2 * z12; + deepspace_consts_.xi3 = 2.0 * s2 * (z13 - z11); + deepspace_consts_.xl2 = -2.0 * s3 * z2; + deepspace_consts_.xl3 = -2.0 * s3 * (z3 - z1); + deepspace_consts_.xl4 = -2.0 * s3 * (-21.0 - 9.0 * eosq) * ze; + deepspace_consts_.xgh2 = 2.0 * s4 * z32; + deepspace_consts_.xgh3 = 2.0 * s4 * (z33 - z31); + deepspace_consts_.xgh4 = -18.0 * s4 * ze; + deepspace_consts_.xh2 = -2.0 * s2 * z22; + deepspace_consts_.xh3 = -2.0 * s2 * (z23 - z21); + + if (cnt == 1) + { + break; + } + /* + * do lunar terms + */ + deepspace_consts_.sse = se; + deepspace_consts_.ssi = si; + deepspace_consts_.ssl = sl; + deepspace_consts_.ssh = shdq; + deepspace_consts_.ssg = sgh - cosio * deepspace_consts_.ssh; + deepspace_consts_.se2 = deepspace_consts_.ee2; + deepspace_consts_.si2 = deepspace_consts_.xi2; + deepspace_consts_.sl2 = deepspace_consts_.xl2; + deepspace_consts_.sgh2 = deepspace_consts_.xgh2; + deepspace_consts_.sh2 = deepspace_consts_.xh2; + deepspace_consts_.se3 = deepspace_consts_.e3; + deepspace_consts_.si3 = deepspace_consts_.xi3; + deepspace_consts_.sl3 = deepspace_consts_.xl3; + deepspace_consts_.sgh3 = deepspace_consts_.xgh3; + deepspace_consts_.sh3 = deepspace_consts_.xh3; + deepspace_consts_.sl4 = deepspace_consts_.xl4; + deepspace_consts_.sgh4 = deepspace_consts_.xgh4; + zcosg = zcosgl; + zsing = zsingl; + zcosi = zcosil; + zsini = zsinil; + zcosh = zcoshl * cosq + zsinhl * sinq; + zsinh = sinq * zcoshl - cosq * zsinhl; + zn = ZNL; + cc = C1L; + ze = ZEL; + } + + deepspace_consts_.sse += se; + deepspace_consts_.ssi += si; + deepspace_consts_.ssl += sl; + deepspace_consts_.ssg += sgh - cosio * shdq; + deepspace_consts_.ssh += shdq; + + deepspace_consts_.shape = DeepSpaceConstants::NONE; + + if (elements_.RecoveredMeanMotion() < 0.0052359877 + && elements_.RecoveredMeanMotion() > 0.0034906585) + { + /* + * 24h synchronous resonance terms initialisation + */ + deepspace_consts_.shape = DeepSpaceConstants::SYNCHRONOUS; + + const double g200 = 1.0 + eosq * (-2.5 + 0.8125 * eosq); + const double g310 = 1.0 + 2.0 * eosq; + const double g300 = 1.0 + eosq * (-6.0 + 6.60937 * eosq); + const double f220 = 0.75 * (1.0 + cosio) * (1.0 + cosio); + const double f311 = 0.9375 * sinio * sinio * (1.0 + 3.0 * cosio) + - 0.75 * (1.0 + cosio); + double f330 = 1.0 + cosio; + f330 = 1.875 * f330 * f330 * f330; + deepspace_consts_.del1 = 3.0 * elements_.RecoveredMeanMotion() + * elements_.RecoveredMeanMotion() + * aqnv * aqnv; + deepspace_consts_.del2 = 2.0 * deepspace_consts_.del1 + * f220 * g200 * Q22; + deepspace_consts_.del3 = 3.0 * deepspace_consts_.del1 + * f330 * g300 * Q33 * aqnv; + deepspace_consts_.del1 = deepspace_consts_.del1 + * f311 * g310 * Q31 * aqnv; + + deepspace_consts_.xlamo = Util::WrapTwoPI(elements_.MeanAnomoly() + + elements_.AscendingNode() + + elements_.ArgumentPerigee() + - deepspace_consts_.gsto); + bfact = xmdot + xpidot - kTHDT + + deepspace_consts_.ssl + + deepspace_consts_.ssg + + deepspace_consts_.ssh; + } + else if (elements_.RecoveredMeanMotion() < 8.26e-3 + || elements_.RecoveredMeanMotion() > 9.24e-3 + || elements_.Eccentricity() < 0.5) + { + // do nothing + } + else + { + /* + * geopotential resonance initialisation for 12 hour orbits + */ + deepspace_consts_.shape = DeepSpaceConstants::RESONANCE; + + double g211; + double g310; + double g322; + double g410; + double g422; + double g520; + + double g201 = -0.306 - (elements_.Eccentricity() - 0.64) * 0.440; + + if (elements_.Eccentricity() <= 0.65) + { + g211 = EvaluateCubicPolynomial(elements_.Eccentricity(), + 3.616, -13.247, 16.290, 0.0); + g310 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -19.302, 117.390, -228.419, 156.591); + g322 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -18.9068, 109.7927, -214.6334, 146.5816); + g410 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -41.122, 242.694, -471.094, 313.953); + g422 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -146.407, 841.880, -1629.014, 1083.435); + g520 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -532.114, 3017.977, -5740.032, 3708.276); + } + else + { + g211 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -72.099, 331.819, -508.738, 266.724); + g310 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -346.844, 1582.851, -2415.925, 1246.113); + g322 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -342.585, 1554.908, -2366.899, 1215.972); + g410 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -1052.797, 4758.686, -7193.992, 3651.957); + g422 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -3581.69, 16178.11, -24462.77, 12422.52); + + if (elements_.Eccentricity() <= 0.715) + { + g520 = EvaluateCubicPolynomial(elements_.Eccentricity(), + 1464.74, -4664.75, 3763.64, 0.0); + } + else + { + g520 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -5149.66, 29936.92, -54087.36, 31324.56); + } + } + + double g533; + double g521; + double g532; + + if (elements_.Eccentricity() < 0.7) + { + g533 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -919.2277, 4988.61, -9064.77, 5542.21); + g521 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -822.71072, 4568.6173, -8491.4146, 5337.524); + g532 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -853.666, 4690.25, -8624.77, 5341.4); + } + else + { + g533 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -37995.78, 161616.52, -229838.2, 109377.94); + g521 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -51752.104, 218913.95, -309468.16, 146349.42); + g532 = EvaluateCubicPolynomial(elements_.Eccentricity(), + -40023.88, 170470.89, -242699.48, 115605.82); + } + + const double sini2 = sinio * sinio; + const double f220 = 0.75 * (1.0 + 2.0 * cosio + theta2); + const double f221 = 1.5 * sini2; + const double f321 = 1.875 * sinio * (1.0 - 2.0 * cosio - 3.0 * theta2); + const double f322 = -1.875 * sinio * (1.0 + 2.0 * cosio - 3.0 * theta2); + const double f441 = 35.0 * sini2 * f220; + const double f442 = 39.3750 * sini2 * sini2; + const double f522 = 9.84375 * sinio + * (sini2 * (1.0 - 2.0 * cosio - 5.0 * theta2) + + 0.33333333 * (-2.0 + 4.0 * cosio + 6.0 * theta2)); + const double f523 = sinio + * (4.92187512 * sini2 * (-2.0 - 4.0 * cosio + 10.0 * theta2) + + 6.56250012 * (1.0 + 2.0 * cosio - 3.0 * theta2)); + const double f542 = 29.53125 * sinio * (2.0 - 8.0 * cosio + theta2 * + (-12.0 + 8.0 * cosio + 10.0 * theta2)); + const double f543 = 29.53125 * sinio * (-2.0 - 8.0 * cosio + theta2 * + (12.0 + 8.0 * cosio - 10.0 * theta2)); + + const double xno2 = elements_.RecoveredMeanMotion() + * elements_.RecoveredMeanMotion(); + const double ainv2 = aqnv * aqnv; + + double temp1 = 3.0 * xno2 * ainv2; + double temp = temp1 * ROOT22; + deepspace_consts_.d2201 = temp * f220 * g201; + deepspace_consts_.d2211 = temp * f221 * g211; + + temp1 *= aqnv; + temp = temp1 * ROOT32; + deepspace_consts_.d3210 = temp * f321 * g310; + deepspace_consts_.d3222 = temp * f322 * g322; + + temp1 *= aqnv; + temp = 2.0 * temp1 * ROOT44; + deepspace_consts_.d4410 = temp * f441 * g410; + deepspace_consts_.d4422 = temp * f442 * g422; + + temp1 *= aqnv; + temp = temp1 * ROOT52; + deepspace_consts_.d5220 = temp * f522 * g520; + deepspace_consts_.d5232 = temp * f523 * g532; + + temp = 2.0 * temp1 * ROOT54; + deepspace_consts_.d5421 = temp * f542 * g521; + deepspace_consts_.d5433 = temp * f543 * g533; + + deepspace_consts_.xlamo = Util::WrapTwoPI( + elements_.MeanAnomoly() + + elements_.AscendingNode() + + elements_.AscendingNode() + - deepspace_consts_.gsto + - deepspace_consts_.gsto); + bfact = xmdot + + xnodot + xnodot + - kTHDT - kTHDT + + deepspace_consts_.ssl + + deepspace_consts_.ssh + + deepspace_consts_.ssh; + } + + if (deepspace_consts_.shape != DeepSpaceConstants::NONE) + { + /* + * initialise integrator + */ + deepspace_consts_.xfact = bfact - elements_.RecoveredMeanMotion(); + integrator_params_.atime = 0.0; + integrator_params_.xni = elements_.RecoveredMeanMotion(); + integrator_params_.xli = deepspace_consts_.xlamo; + } +} + +/** + * From DeepSpaceConstants, this uses: + * zmos, se2, se3, si2, si3, sl2, sl3, sl4, sgh2, sgh3, sgh4, sh2, sh3 + * zmol, ee2, e3, xi2, xi3, xl2, xl3, xl4, xgh2, xgh3, xgh4, xh2, xh3 + */ +void SGP4::DeepSpacePeriodics( + const double tsince, + const DeepSpaceConstants& ds_constants, + double& em, + double& xinc, + double& omgasm, + double& xnodes, + double& xll) +{ + static const double ZES = 0.01675; + static const double ZNS = 1.19459E-5; + static const double ZNL = 1.5835218E-4; + static const double ZEL = 0.05490; + + // calculate solar terms for time tsince + double zm = ds_constants.zmos + ZNS * tsince; + double zf = zm + 2.0 * ZES * sin(zm); + double sinzf = sin(zf); + double f2 = 0.5 * sinzf * sinzf - 0.25; + double f3 = -0.5 * sinzf * cos(zf); + + const double ses = ds_constants.se2 * f2 + + ds_constants.se3 * f3; + const double sis = ds_constants.si2 * f2 + + ds_constants.si3 * f3; + const double sls = ds_constants.sl2 * f2 + + ds_constants.sl3 * f3 + + ds_constants.sl4 * sinzf; + const double sghs = ds_constants.sgh2 * f2 + + ds_constants.sgh3 * f3 + + ds_constants.sgh4 * sinzf; + const double shs = ds_constants.sh2 * f2 + + ds_constants.sh3 * f3; + + // calculate lunar terms for time tsince + zm = ds_constants.zmol + ZNL * tsince; + zf = zm + 2.0 * ZEL * sin(zm); + sinzf = sin(zf); + f2 = 0.5 * sinzf * sinzf - 0.25; + f3 = -0.5 * sinzf * cos(zf); + + const double sel = ds_constants.ee2 * f2 + + ds_constants.e3 * f3; + const double sil = ds_constants.xi2 * f2 + + ds_constants.xi3 * f3; + const double sll = ds_constants.xl2 * f2 + + ds_constants.xl3 * f3 + + ds_constants.xl4 * sinzf; + const double sghl = ds_constants.xgh2 * f2 + + ds_constants.xgh3 * f3 + + ds_constants.xgh4 * sinzf; + const double shl = ds_constants.xh2 * f2 + + ds_constants.xh3 * f3; + + // merge calculated values + const double pe = ses + sel; + const double pinc = sis + sil; + const double pl = sls + sll; + const double pgh = sghs + sghl; + const double ph = shs + shl; + + xinc += pinc; + em += pe; + + /* Spacetrack report #3 has sin/cos from before perturbations + * added to xinc (oldxinc), but apparently report # 6 has then + * from after they are added. + * use for strn3 + * if (elements_.Inclination() >= 0.2) + * use for gsfc + * if (xinc >= 0.2) + * (moved from start of function) + */ + const double sinis = sin(xinc); + const double cosis = cos(xinc); + + if (xinc >= 0.2) + { + // apply periodics directly + omgasm += pgh - cosis * ph / sinis; + xnodes += ph / sinis; + xll += pl; + } + else + { + // apply periodics with lyddane modification + const double sinok = sin(xnodes); + const double cosok = cos(xnodes); + double alfdp = sinis * sinok; + double betdp = sinis * cosok; + const double dalf = ph * cosok + pinc * cosis * sinok; + const double dbet = -ph * sinok + pinc * cosis * cosok; + alfdp += dalf; + betdp += dbet; + xnodes = Util::WrapTwoPI(xnodes); + double xls = xll + omgasm + cosis * xnodes; + double dls = pl + pgh - pinc * xnodes * sinis; + xls += dls; + const double oldxnodes = xnodes; + xnodes = atan2(alfdp, betdp); + /** + * Get perturbed xnodes in to same quadrant as original. + * RAAN is in the range of 0 to 360 degrees + * atan2 is in the range of -180 to 180 degrees + */ + if (fabs(oldxnodes - xnodes) > kPI) + { + if (xnodes < oldxnodes) + { + xnodes += kTWOPI; + } + else + { + xnodes -= kTWOPI; + } + } + + xll += pl; + omgasm = xls - xll - cosis * xnodes; + } +} + +void SGP4::DeepSpaceSecular( + const double tsince, + const OrbitalElements& elements, + const CommonConstants& c_constants, + const DeepSpaceConstants& ds_constants, + IntegratorParams& integ_params, + double& xll, + double& omgasm, + double& xnodes, + double& em, + double& xinc, + double& xn) +{ + static const double G22 = 5.7686396; + static const double G32 = 0.95240898; + static const double G44 = 1.8014998; + static const double G52 = 1.0508330; + static const double G54 = 4.4108898; + static const double FASX2 = 0.13130908; + static const double FASX4 = 2.8843198; + static const double FASX6 = 0.37448087; + + static const double STEP = 720.0; + static const double STEP2 = 259200.0; + + xll += ds_constants.ssl * tsince; + omgasm += ds_constants.ssg * tsince; + xnodes += ds_constants.ssh * tsince; + em += ds_constants.sse * tsince; + xinc += ds_constants.ssi * tsince; + + if (ds_constants.shape != DeepSpaceConstants::NONE) + { + double xndot = 0.0; + double xnddt = 0.0; + double xldot = 0.0; + /* + * 1st condition (if tsince is less than one time step from epoch) + * 2nd condition (if atime and + * tsince are of opposite signs, so zero crossing required) + * 3rd condition (if tsince is closer to zero than + * atime, only integrate away from zero) + */ + if (fabs(tsince) < STEP || + tsince * integ_params.atime <= 0.0 || + fabs(tsince) < fabs(integ_params.atime)) + { + // restart back at the epoch + integ_params.atime = 0.0; + // TODO: check + integ_params.xni = elements.RecoveredMeanMotion(); + // TODO: check + integ_params.xli = ds_constants.xlamo; + } + + bool running = true; + while (running) + { + // always calculate dot terms ready for integration beginning + // from the start of the range which is 'atime' + if (ds_constants.shape == DeepSpaceConstants::SYNCHRONOUS) + { + xndot = ds_constants.del1 * sin(integ_params.xli - FASX2) + + ds_constants.del2 * sin(2.0 * (integ_params.xli - FASX4)) + + ds_constants.del3 * sin(3.0 * (integ_params.xli - FASX6)); + xnddt = ds_constants.del1 * cos(integ_params.xli - FASX2) + + 2.0 * ds_constants.del2 * cos(2.0 * (integ_params.xli - FASX4)) + + 3.0 * ds_constants.del3 * cos(3.0 * (integ_params.xli - FASX6)); + } + else + { + // TODO: check + const double xomi = elements.ArgumentPerigee() + c_constants.omgdot * integ_params.atime; + const double x2omi = xomi + xomi; + const double x2li = integ_params.xli + integ_params.xli; + xndot = ds_constants.d2201 * sin(x2omi + integ_params.xli - G22) + + ds_constants.d2211 * sin(integ_params.xli - G22) + + ds_constants.d3210 * sin(xomi + integ_params.xli - G32) + + ds_constants.d3222 * sin(-xomi + integ_params.xli - G32) + + ds_constants.d4410 * sin(x2omi + x2li - G44) + + ds_constants.d4422 * sin(x2li - G44) + + ds_constants.d5220 * sin(xomi + integ_params.xli - G52) + + ds_constants.d5232 * sin(-xomi + integ_params.xli - G52) + + ds_constants.d5421 * sin(xomi + x2li - G54) + + ds_constants.d5433 * sin(-xomi + x2li - G54); + xnddt = ds_constants.d2201 * cos(x2omi + integ_params.xli - G22) + + ds_constants.d2211 * cos(integ_params.xli - G22) + + ds_constants.d3210 * cos(xomi + integ_params.xli - G32) + + ds_constants.d3222 * cos(-xomi + integ_params.xli - G32) + + ds_constants.d5220 * cos(xomi + integ_params.xli - G52) + + ds_constants.d5232 * cos(-xomi + integ_params.xli - G52) + + 2.0 * (ds_constants.d4410 * cos(x2omi + x2li - G44) + + ds_constants.d4422 * cos(x2li - G44) + + ds_constants.d5421 * cos(xomi + x2li - G54) + + ds_constants.d5433 * cos(-xomi + x2li - G54)); + } + xldot = integ_params.xni + ds_constants.xfact; + xnddt *= xldot; + + double ft = tsince - integ_params.atime; + if (fabs(ft) >= STEP) + { + const double delt = (ft >= 0.0 ? STEP : -STEP); + // integrate by a full step ('delt'), updating the cached + // values for the new 'atime' + integ_params.xli = integ_params.xli + xldot * delt + xndot * STEP2; + integ_params.xni = integ_params.xni + xndot * delt + xnddt * STEP2; + integ_params.atime += delt; + } + else + { + // integrate by the difference 'ft' remaining + xn = integ_params.xni + xndot * ft + + xnddt * ft * ft * 0.5; + const double xl_temp = integ_params.xli + xldot * ft + + xndot * ft * ft * 0.5; + + const double theta = Util::WrapTwoPI(ds_constants.gsto + tsince * kTHDT); + if (ds_constants.shape == DeepSpaceConstants::SYNCHRONOUS) + { + xll = xl_temp + theta - xnodes - omgasm; + } + else + { + xll = xl_temp + 2.0 * (theta - xnodes); + } + running = false; + } + } + } +} + +void SGP4::Reset() +{ + use_simple_model_ = false; + use_deep_space_ = false; + + std::memset(&common_consts_, 0, sizeof(common_consts_)); + std::memset(&nearspace_consts_, 0, sizeof(nearspace_consts_)); + std::memset(&deepspace_consts_, 0, sizeof(deepspace_consts_)); + std::memset(&integrator_params_, 0, sizeof(integrator_params_)); +} + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/SGP4.h b/SPG4Tool/libsgp4/SGP4.h new file mode 100644 index 0000000..e67aa1f --- /dev/null +++ b/SPG4Tool/libsgp4/SGP4.h @@ -0,0 +1,260 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include "Tle.h" +#include "OrbitalElements.h" +#include "Eci.h" +#include "SatelliteException.h" +#include "DecayedException.h" + +namespace libsgp4 +{ + +/** + * @mainpage + * + * This documents the SGP4 tracking library. + */ + +/** + * @brief The simplified perturbations model 4 propagater. + */ +class SGP4 +{ +public: + explicit SGP4(const Tle& tle) + : elements_(tle) + { + Initialise(); + } + + void SetTle(const Tle& tle); + Eci FindPosition(double tsince) const; + Eci FindPosition(const DateTime& date) const; + +private: + struct CommonConstants + { + double cosio; + double sinio; + double eta; + double t2cof; + double x1mth2; + double x3thm1; + double x7thm1; + double aycof; + double xlcof; + double xnodcf; + double c1; + double c4; + double omgdot; // secular rate of omega (radians/sec) + double xnodot; // secular rate of xnode (radians/sec) + double xmdot; // secular rate of xmo (radians/sec) + }; + + struct NearSpaceConstants + { + double c5; + double omgcof; + double xmcof; + double delmo; + double sinmo; + double d2; + double d3; + double d4; + double t3cof; + double t4cof; + double t5cof; + }; + + struct DeepSpaceConstants + { + double gsto; + double zmol; + double zmos; + + /* + * lunar / solar constants for epoch + * applied during DeepSpaceSecular() + */ + double sse; + double ssi; + double ssl; + double ssg; + double ssh; + /* + * lunar / solar constants + * used during DeepSpaceCalculateLunarSolarTerms() + */ + double se2; + double si2; + double sl2; + double sgh2; + double sh2; + double se3; + double si3; + double sl3; + double sgh3; + double sh3; + double sl4; + double sgh4; + double ee2; + double e3; + double xi2; + double xi3; + double xl2; + double xl3; + double xl4; + double xgh2; + double xgh3; + double xgh4; + double xh2; + double xh3; + /* + * used during DeepSpaceCalcDotTerms() + */ + double d2201; + double d2211; + double d3210; + double d3222; + double d4410; + double d4422; + double d5220; + double d5232; + double d5421; + double d5433; + double del1; + double del2; + double del3; + /* + * integrator constants + */ + double xfact; + double xlamo; + + enum TOrbitShape + { + NONE, + RESONANCE, + SYNCHRONOUS + } shape; + }; + + struct IntegratorParams + { + /* + * integrator values + */ + double xli; + double xni; + double atime; + }; + + void Initialise(); + static void RecomputeConstants(const double xinc, + double& sinio, + double& cosio, + double& x3thm1, + double& x1mth2, + double& x7thm1, + double& xlcof, + double& aycof); + Eci FindPositionSDP4(const double tsince) const; + Eci FindPositionSGP4(double tsince) const; + static Eci CalculateFinalPositionVelocity( + const DateTime& date, + const double e, + const double a, + const double omega, + const double xl, + const double xnode, + const double xinc, + const double xlcof, + const double aycof, + const double x3thm1, + const double x1mth2, + const double x7thm1, + const double cosio, + const double sinio); + /** + * Deep space initialisation + */ + void DeepSpaceInitialise( + const double eosq, + const double sinio, + const double cosio, + const double betao, + const double theta2, + const double betao2, + const double xmdot, + const double omgdot, + const double xnodot); + /** + * Calculate lunar / solar periodics and apply + */ + static void DeepSpacePeriodics( + const double tsince, + const DeepSpaceConstants& ds_constants, + double& em, + double& xinc, + double& omgasm, + double& xnodes, + double& xll); + /** + * Deep space secular effects + */ + static void DeepSpaceSecular( + const double tsince, + const OrbitalElements& elements, + const CommonConstants& c_constants, + const DeepSpaceConstants& ds_constants, + IntegratorParams& integ_params, + double& xll, + double& omgasm, + double& xnodes, + double& em, + double& xinc, + double& xn); + + /** + * Reset + */ + void Reset(); + + /* + * the constants used + */ + struct CommonConstants common_consts_; + struct NearSpaceConstants nearspace_consts_; + struct DeepSpaceConstants deepspace_consts_; + mutable struct IntegratorParams integrator_params_; + + /* + * the orbit data + */ + OrbitalElements elements_; + + /* + * flags + */ + bool use_simple_model_; + bool use_deep_space_; +}; + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/SatelliteException.cc b/SPG4Tool/libsgp4/SatelliteException.cc new file mode 100644 index 0000000..5fe1212 --- /dev/null +++ b/SPG4Tool/libsgp4/SatelliteException.cc @@ -0,0 +1 @@ +#include "SatelliteException.h" diff --git a/SPG4Tool/libsgp4/SatelliteException.h b/SPG4Tool/libsgp4/SatelliteException.h new file mode 100644 index 0000000..900947a --- /dev/null +++ b/SPG4Tool/libsgp4/SatelliteException.h @@ -0,0 +1,38 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include +#include + +namespace libsgp4 +{ + +/** + * @brief The exception that the SGP4 class throws upon an error. + */ +class SatelliteException : public std::runtime_error +{ +public: + explicit SatelliteException(const char* message) + : runtime_error(message) + { + } +}; + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/SolarPosition.cc b/SPG4Tool/libsgp4/SolarPosition.cc new file mode 100644 index 0000000..cb6bbeb --- /dev/null +++ b/SPG4Tool/libsgp4/SolarPosition.cc @@ -0,0 +1,68 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "SolarPosition.h" + +#include "Globals.h" +#include "Util.h" + +#include + +namespace libsgp4 +{ + +Eci SolarPosition::FindPosition(const DateTime& dt) +{ + const double mjd = dt.ToJ2000(); + const double year = 1900 + mjd / 365.25; + const double T = (mjd + Delta_ET(year) / kSECONDS_PER_DAY) / 36525.0; + const double M = Util::DegreesToRadians(Util::Wrap360(358.47583 + + Util::Wrap360(35999.04975 * T) + - (0.000150 + 0.0000033 * T) * T * T)); + const double L = Util::DegreesToRadians(Util::Wrap360(279.69668 + + Util::Wrap360(36000.76892 * T) + + 0.0003025 * T*T)); + const double e = 0.01675104 - (0.0000418 + 0.000000126 * T) * T; + const double C = Util::DegreesToRadians((1.919460 + - (0.004789 + 0.000014 * T) * T) * sin(M) + + (0.020094 - 0.000100 * T) * sin(2 * M) + + 0.000293 * sin(3 * M)); + const double O = Util::DegreesToRadians( + Util::Wrap360(259.18 - 1934.142 * T)); + const double Lsa = Util::WrapTwoPI(L + C + - Util::DegreesToRadians(0.00569 - 0.00479 * sin(O))); + const double nu = Util::WrapTwoPI(M + C); + double R = 1.0000002 * (1 - e * e) / (1 + e * cos(nu)); + const double eps = Util::DegreesToRadians(23.452294 - (0.0130125 + + (0.00000164 - 0.000000503 * T) * T) * T + 0.00256 * cos(O)); + R = R * kAU; + + Vector solar_position(R * cos(Lsa), + R * sin(Lsa) * cos(eps), + R * sin(Lsa) * sin(eps), + R); + + return Eci(dt, solar_position); +} + +double SolarPosition::Delta_ET(double year) const +{ + return 26.465 + 0.747622 * (year - 1950) + 1.886913 + * sin(kTWOPI * (year - 1975) / 33); +} + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/SolarPosition.h b/SPG4Tool/libsgp4/SolarPosition.h new file mode 100644 index 0000000..7e19c19 --- /dev/null +++ b/SPG4Tool/libsgp4/SolarPosition.h @@ -0,0 +1,40 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include "DateTime.h" +#include "Eci.h" + +namespace libsgp4 +{ + +/** + * @brief Find the position of the sun + */ +class SolarPosition +{ +public: + SolarPosition() = default; + + Eci FindPosition(const DateTime& dt); + +private: + double Delta_ET(double year) const; +}; + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/TimeSpan.cc b/SPG4Tool/libsgp4/TimeSpan.cc new file mode 100644 index 0000000..c426258 --- /dev/null +++ b/SPG4Tool/libsgp4/TimeSpan.cc @@ -0,0 +1,18 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "TimeSpan.h" diff --git a/SPG4Tool/libsgp4/TimeSpan.h b/SPG4Tool/libsgp4/TimeSpan.h new file mode 100644 index 0000000..0bfdcdb --- /dev/null +++ b/SPG4Tool/libsgp4/TimeSpan.h @@ -0,0 +1,259 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include +#include +#include +#include +#include + +namespace libsgp4 +{ + +namespace +{ + static const int64_t TicksPerDay = 86400000000LL; + static const int64_t TicksPerHour = 3600000000LL; + static const int64_t TicksPerMinute = 60000000LL; + static const int64_t TicksPerSecond = 1000000LL; + static const int64_t TicksPerMillisecond = 1000LL; + static const int64_t TicksPerMicrosecond = 1LL; + + static const int64_t UnixEpoch = 62135596800000000LL; + + static const int64_t MaxValueTicks = 315537897599999999LL; + + // 1582-Oct-15 + static const int64_t GregorianStart = 49916304000000000LL; +} + +/** + * @brief Represents a time interval. + * + * Represents a time interval (duration/elapsed) that is measured as a positive + * or negative number of days, hours, minutes, seconds, and fractions + * of a second. + */ +class TimeSpan +{ +public: + explicit TimeSpan(int64_t ticks) + : m_ticks(ticks) + { + } + + TimeSpan(int hours, int minutes, int seconds) + { + CalculateTicks(0, hours, minutes, seconds, 0); + } + + TimeSpan(int days, int hours, int minutes, int seconds) + { + CalculateTicks(days, hours, minutes, seconds, 0); + } + + TimeSpan(int days, int hours, int minutes, int seconds, int microseconds) + { + CalculateTicks(days, hours, minutes, seconds, microseconds); + } + + TimeSpan Add(const TimeSpan& ts) const + { + return TimeSpan(m_ticks + ts.m_ticks); + } + + TimeSpan Subtract(const TimeSpan& ts) const + { + return TimeSpan(m_ticks - ts.m_ticks); + } + + int Compare(const TimeSpan& ts) const + { + int ret = 0; + + if (m_ticks < ts.m_ticks) + { + ret = -1; + } + if (m_ticks > ts.m_ticks) + { + ret = 1; + } + return ret; + } + + bool Equals(const TimeSpan& ts) const + { + return m_ticks == ts.m_ticks; + } + + int Days() const + { + return static_cast(m_ticks / TicksPerDay); + } + + int Hours() const + { + return static_cast(m_ticks % TicksPerDay / TicksPerHour); + } + + int Minutes() const + { + return static_cast(m_ticks % TicksPerHour / TicksPerMinute); + } + + int Seconds() const + { + return static_cast(m_ticks % TicksPerMinute / TicksPerSecond); + } + + int Milliseconds() const + { + return static_cast(m_ticks % TicksPerSecond / TicksPerMillisecond); + } + + int Microseconds() const + { + return static_cast(m_ticks % TicksPerSecond / TicksPerMicrosecond); + } + + int64_t Ticks() const + { + return m_ticks; + } + + double TotalDays() const + { + return static_cast(m_ticks) / TicksPerDay; + } + + double TotalHours() const + { + return static_cast(m_ticks) / TicksPerHour; + } + + double TotalMinutes() const + { + return static_cast(m_ticks) / TicksPerMinute; + } + + double TotalSeconds() const + { + return static_cast(m_ticks) / TicksPerSecond; + } + + double TotalMilliseconds() const + { + return static_cast(m_ticks) / TicksPerMillisecond; + } + + double TotalMicroseconds() const + { + return static_cast(m_ticks) / TicksPerMicrosecond; + } + + std::string ToString() const + { + std::stringstream ss; + + ss << std::right << std::setfill('0'); + + if (m_ticks < 0) + { + ss << '-'; + } + + if (Days() != 0) + { + ss << std::setw(2) << std::abs(Days()) << '.'; + } + + ss << std::setw(2) << std::abs(Hours()) << ':'; + ss << std::setw(2) << std::abs(Minutes()) << ':'; + ss << std::setw(2) << std::abs(Seconds()); + + if (Microseconds() != 0) + { + ss << '.' << std::setw(6) << std::abs(Microseconds()); + } + + return ss.str(); + } + +private: + int64_t m_ticks{}; + + void CalculateTicks(int days, + int hours, + int minutes, + int seconds, + int microseconds) + { + m_ticks = days * TicksPerDay + + (hours * 3600LL + minutes * 60LL + seconds) * TicksPerSecond + + microseconds * TicksPerMicrosecond; + } +}; + +inline std::ostream& operator<<(std::ostream& strm, const TimeSpan& t) +{ + return strm << t.ToString(); +} + +inline TimeSpan operator+(const TimeSpan& ts1, const TimeSpan& ts2) +{ + return ts1.Add(ts2); +} + +inline TimeSpan operator-(const TimeSpan& ts1, const TimeSpan& ts2) +{ + return ts1.Subtract(ts2); +} + +inline bool operator==(const TimeSpan& ts1, TimeSpan& ts2) +{ + return ts1.Equals(ts2); +} + +inline bool operator>(const TimeSpan& ts1, const TimeSpan& ts2) +{ + return (ts1.Compare(ts2) > 0); +} + +inline bool operator>=(const TimeSpan& ts1, const TimeSpan& ts2) +{ + return (ts1.Compare(ts2) >= 0); +} + +inline bool operator!=(const TimeSpan& ts1, const TimeSpan& ts2) +{ + return !ts1.Equals(ts2); +} + +inline bool operator<(const TimeSpan& ts1, const TimeSpan& ts2) +{ + return (ts1.Compare(ts2) < 0); +} + +inline bool operator<=(const TimeSpan& ts1, const TimeSpan& ts2) +{ + return (ts1.Compare(ts2) <= 0); +} + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/Tle.cc b/SPG4Tool/libsgp4/Tle.cc new file mode 100644 index 0000000..c74aaa3 --- /dev/null +++ b/SPG4Tool/libsgp4/Tle.cc @@ -0,0 +1,376 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "Tle.h" + +#include + +namespace libsgp4 +{ +namespace +{ + static const unsigned int TLE1_COL_NORADNUM = 2; + static const unsigned int TLE1_LEN_NORADNUM = 5; + static const unsigned int TLE1_COL_INTLDESC_A = 9; + static const unsigned int TLE1_LEN_INTLDESC_A = 2; +// static const unsigned int TLE1_COL_INTLDESC_B = 11; + static const unsigned int TLE1_LEN_INTLDESC_B = 3; +// static const unsigned int TLE1_COL_INTLDESC_C = 14; + static const unsigned int TLE1_LEN_INTLDESC_C = 3; + static const unsigned int TLE1_COL_EPOCH_A = 18; + static const unsigned int TLE1_LEN_EPOCH_A = 2; + static const unsigned int TLE1_COL_EPOCH_B = 20; + static const unsigned int TLE1_LEN_EPOCH_B = 12; + static const unsigned int TLE1_COL_MEANMOTIONDT2 = 33; + static const unsigned int TLE1_LEN_MEANMOTIONDT2 = 10; + static const unsigned int TLE1_COL_MEANMOTIONDDT6 = 44; + static const unsigned int TLE1_LEN_MEANMOTIONDDT6 = 8; + static const unsigned int TLE1_COL_BSTAR = 53; + static const unsigned int TLE1_LEN_BSTAR = 8; +// static const unsigned int TLE1_COL_EPHEMTYPE = 62; +// static const unsigned int TLE1_LEN_EPHEMTYPE = 1; +// static const unsigned int TLE1_COL_ELNUM = 64; +// static const unsigned int TLE1_LEN_ELNUM = 4; + + static const unsigned int TLE2_COL_NORADNUM = 2; + static const unsigned int TLE2_LEN_NORADNUM = 5; + static const unsigned int TLE2_COL_INCLINATION = 8; + static const unsigned int TLE2_LEN_INCLINATION = 8; + static const unsigned int TLE2_COL_RAASCENDNODE = 17; + static const unsigned int TLE2_LEN_RAASCENDNODE = 8; + static const unsigned int TLE2_COL_ECCENTRICITY = 26; + static const unsigned int TLE2_LEN_ECCENTRICITY = 7; + static const unsigned int TLE2_COL_ARGPERIGEE = 34; + static const unsigned int TLE2_LEN_ARGPERIGEE = 8; + static const unsigned int TLE2_COL_MEANANOMALY = 43; + static const unsigned int TLE2_LEN_MEANANOMALY = 8; + static const unsigned int TLE2_COL_MEANMOTION = 52; + static const unsigned int TLE2_LEN_MEANMOTION = 11; + static const unsigned int TLE2_COL_REVATEPOCH = 63; + static const unsigned int TLE2_LEN_REVATEPOCH = 5; +} + +/** + * Initialise the tle object. + * @exception TleException + */ +void Tle::Initialize() +{ + if (!IsValidLineLength(line_one_)) + { + throw TleException("Invalid length for line one"); + } + + if (!IsValidLineLength(line_two_)) + { + throw TleException("Invalid length for line two"); + } + + if (line_one_[0] != '1') + { + throw TleException("Invalid line beginning for line one"); + } + + if (line_two_[0] != '2') + { + throw TleException("Invalid line beginning for line two"); + } + + unsigned int sat_number_1; + unsigned int sat_number_2; + + ExtractInteger(line_one_.substr(TLE1_COL_NORADNUM, + TLE1_LEN_NORADNUM), sat_number_1); + ExtractInteger(line_two_.substr(TLE2_COL_NORADNUM, + TLE2_LEN_NORADNUM), sat_number_2); + + if (sat_number_1 != sat_number_2) + { + throw TleException("Satellite numbers do not match"); + } + + norad_number_ = sat_number_1; + + if (name_.empty()) + { + name_ = line_one_.substr(TLE1_COL_NORADNUM, TLE1_LEN_NORADNUM); + } + + int_designator_ = line_one_.substr(TLE1_COL_INTLDESC_A, + TLE1_LEN_INTLDESC_A + TLE1_LEN_INTLDESC_B + TLE1_LEN_INTLDESC_C); + + unsigned int year = 0; + double day = 0.0; + + ExtractInteger(line_one_.substr(TLE1_COL_EPOCH_A, + TLE1_LEN_EPOCH_A), year); + ExtractDouble(line_one_.substr(TLE1_COL_EPOCH_B, + TLE1_LEN_EPOCH_B), 4, day); + ExtractDouble(line_one_.substr(TLE1_COL_MEANMOTIONDT2, + TLE1_LEN_MEANMOTIONDT2), 2, mean_motion_dt2_); + ExtractExponential(line_one_.substr(TLE1_COL_MEANMOTIONDDT6, + TLE1_LEN_MEANMOTIONDDT6), mean_motion_ddt6_); + ExtractExponential(line_one_.substr(TLE1_COL_BSTAR, + TLE1_LEN_BSTAR), bstar_); + + /* + * line 2 + */ + ExtractDouble(line_two_.substr(TLE2_COL_INCLINATION, + TLE2_LEN_INCLINATION), 4, inclination_); + ExtractDouble(line_two_.substr(TLE2_COL_RAASCENDNODE, + TLE2_LEN_RAASCENDNODE), 4, right_ascending_node_); + ExtractDouble(line_two_.substr(TLE2_COL_ECCENTRICITY, + TLE2_LEN_ECCENTRICITY), -1, eccentricity_); + ExtractDouble(line_two_.substr(TLE2_COL_ARGPERIGEE, + TLE2_LEN_ARGPERIGEE), 4, argument_perigee_); + ExtractDouble(line_two_.substr(TLE2_COL_MEANANOMALY, + TLE2_LEN_MEANANOMALY), 4, mean_anomaly_); + ExtractDouble(line_two_.substr(TLE2_COL_MEANMOTION, + TLE2_LEN_MEANMOTION), 3, mean_motion_); + ExtractInteger(line_two_.substr(TLE2_COL_REVATEPOCH, + TLE2_LEN_REVATEPOCH), orbit_number_); + + if (year < 57) + { + year += 2000; + } + else + { + year += 1900; + } + + epoch_ = DateTime(year, day); +} + +/** + * Check + * @param str The string to check + * @returns Whether true of the string has a valid length + */ +bool Tle::IsValidLineLength(const std::string& str) +{ + return str.length() == LineLength() ? true : false; +} + +/** + * Convert a string containing an integer + * @param[in] str The string to convert + * @param[out] val The result + * @exception TleException on conversion error + */ +void Tle::ExtractInteger(const std::string& str, unsigned int& val) +{ + bool found_digit = false; + unsigned int temp = 0; + + for (auto& i : str) + { + if (isdigit(i)) + { + found_digit = true; + temp = (temp * 10) + static_cast(i - '0'); + } + else if (found_digit) + { + throw TleException("Unexpected non digit"); + } + else if (i != ' ') + { + throw TleException("Invalid character"); + } + } + + if (!found_digit) + { + val = 0; + } + else + { + val = temp; + } +} + +/** + * Convert a string containing an double + * @param[in] str The string to convert + * @param[in] point_pos The position of the decimal point. (-1 if none) + * @param[out] val The result + * @exception TleException on conversion error + */ +void Tle::ExtractDouble(const std::string& str, int point_pos, double& val) +{ + std::string temp; + bool found_digit = false; + + for (std::string::const_iterator i = str.begin(); i != str.end(); ++i) + { + /* + * integer part + */ + if (point_pos >= 0 && i < str.begin() + point_pos - 1) + { + bool done = false; + + if (i == str.begin()) + { + if(*i == '-' || *i == '+') + { + /* + * first character could be signed + */ + temp += *i; + done = true; + } + } + + if (!done) + { + if (isdigit(*i)) + { + found_digit = true; + temp += *i; + } + else if (found_digit) + { + throw TleException("Unexpected non digit"); + } + else if (*i != ' ') + { + throw TleException("Invalid character"); + } + } + } + /* + * decimal point + */ + else if (point_pos >= 0 && i == str.begin() + point_pos - 1) + { + if (temp.length() == 0) + { + /* + * integer part is blank, so add a '0' + */ + temp += '0'; + } + + if (*i == '.') + { + /* + * decimal point found + */ + temp += *i; + } + else + { + throw TleException("Failed to find decimal point"); + } + } + /* + * fraction part + */ + else + { + if (i == str.begin() && point_pos == -1) + { + /* + * no decimal point expected, add 0. beginning + */ + temp += '0'; + temp += '.'; + } + + /* + * should be a digit + */ + if (isdigit(*i)) + { + temp += *i; + } + else + { + throw TleException("Invalid digit"); + } + } + } + + if (!Util::FromString(temp, val)) + { + throw TleException("Failed to convert value to double"); + } +} + +/** + * Convert a string containing an exponential + * @param[in] str The string to convert + * @param[out] val The result + * @exception TleException on conversion error + */ +void Tle::ExtractExponential(const std::string& str, double& val) +{ + std::string temp; + + for (std::string::const_iterator i = str.begin(); i != str.end(); ++i) + { + if (i == str.begin()) + { + if (*i == '-' || *i == '+' || *i == ' ') + { + if (*i == '-') + { + temp += *i; + } + temp += '0'; + temp += '.'; + } + else + { + throw TleException("Invalid sign"); + } + } + else if (i == str.end() - 2) + { + if (*i == '-' || *i == '+') + { + temp += 'e'; + temp += *i; + } + else + { + throw TleException("Invalid exponential sign"); + } + } + else + { + if (isdigit(*i)) + { + temp += *i; + } + else + { + throw TleException("Invalid digit"); + } + } + } + + if (!Util::FromString(temp, val)) + { + throw TleException("Failed to convert value to double"); + } +} + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/Tle.h b/SPG4Tool/libsgp4/Tle.h new file mode 100644 index 0000000..a822a40 --- /dev/null +++ b/SPG4Tool/libsgp4/Tle.h @@ -0,0 +1,341 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include "Util.h" +#include "DateTime.h" +#include "TleException.h" + +namespace libsgp4 +{ + +/** + * @brief Processes a two-line element set used to convey OrbitalElements. + * + * Used to extract the various raw fields from a two-line element set. + */ +class Tle +{ +public: + /** + * @details Initialise given the two lines of a tle + * @param[in] line_one Tle line one + * @param[in] line_two Tle line two + */ + Tle(std::string line_one, std::string line_two) + : line_one_(std::move(line_one)) + , line_two_(std::move(line_two)) + { + Initialize(); + } + + /** + * @details Initialise given the satellite name and the two lines of a tle + * @param[in] name Satellite name + * @param[in] line_one Tle line one + * @param[in] line_two Tle line two + */ + Tle(std::string name, std::string line_one, std::string line_two) + : name_(std::move(name)) + , line_one_(std::move(line_one)) + , line_two_(std::move(line_two)) + { + Initialize(); + } + + /** + * Copy constructor + * @param[in] tle Tle object to copy from + */ + Tle(const Tle& tle) + { + name_ = tle.name_; + line_one_ = tle.line_one_; + line_two_ = tle.line_two_; + + norad_number_ = tle.norad_number_; + int_designator_ = tle.int_designator_; + epoch_ = tle.epoch_; + mean_motion_dt2_ = tle.mean_motion_dt2_; + mean_motion_ddt6_ = tle.mean_motion_ddt6_; + bstar_ = tle.bstar_; + inclination_ = tle.inclination_; + right_ascending_node_ = tle.right_ascending_node_; + eccentricity_ = tle.eccentricity_; + argument_perigee_ = tle.argument_perigee_; + mean_anomaly_ = tle.mean_anomaly_; + mean_motion_ = tle.mean_motion_; + orbit_number_ = tle.orbit_number_; + } + + /** + * Get the satellite name + * @returns the satellite name + */ + std::string Name() const + { + return name_; + } + + /** + * Get the first line of the tle + * @returns the first line of the tle + */ + std::string Line1() const + { + return line_one_; + } + + /** + * Get the second line of the tle + * @returns the second line of the tle + */ + std::string Line2() const + { + return line_two_; + } + + /** + * Get the norad number + * @returns the norad number + */ + unsigned int NoradNumber() const + { + return norad_number_; + } + + /** + * Get the international designator + * @returns the international designator + */ + std::string IntDesignator() const + { + return int_designator_; + } + + /** + * Get the tle epoch + * @returns the tle epoch + */ + DateTime Epoch() const + { + return epoch_; + } + + /** + * Get the first time derivative of the mean motion divided by two + * @returns the first time derivative of the mean motion divided by two + */ + double MeanMotionDt2() const + { + return mean_motion_dt2_; + } + + /** + * Get the second time derivative of mean motion divided by six + * @returns the second time derivative of mean motion divided by six + */ + double MeanMotionDdt6() const + { + return mean_motion_ddt6_; + } + + /** + * Get the BSTAR drag term + * @returns the BSTAR drag term + */ + double BStar() const + { + return bstar_; + } + + /** + * Get the inclination + * @param in_degrees Whether to return the value in degrees or radians + * @returns the inclination + */ + double Inclination(bool in_degrees) const + { + if (in_degrees) + { + return inclination_; + } + else + { + return Util::DegreesToRadians(inclination_); + } + } + + /** + * Get the right ascension of the ascending node + * @param in_degrees Whether to return the value in degrees or radians + * @returns the right ascension of the ascending node + */ + double RightAscendingNode(const bool in_degrees) const + { + if (in_degrees) + { + return right_ascending_node_; + } + else + { + return Util::DegreesToRadians(right_ascending_node_); + } + } + + /** + * Get the eccentricity + * @returns the eccentricity + */ + double Eccentricity() const + { + return eccentricity_; + } + + /** + * Get the argument of perigee + * @param in_degrees Whether to return the value in degrees or radians + * @returns the argument of perigee + */ + double ArgumentPerigee(const bool in_degrees) const + { + if (in_degrees) + { + return argument_perigee_; + } + else + { + return Util::DegreesToRadians(argument_perigee_); + } + } + + /** + * Get the mean anomaly + * @param in_degrees Whether to return the value in degrees or radians + * @returns the mean anomaly + */ + double MeanAnomaly(const bool in_degrees) const + { + if (in_degrees) + { + return mean_anomaly_; + } + else + { + return Util::DegreesToRadians(mean_anomaly_); + } + } + + /** + * Get the mean motion + * @returns the mean motion (revolutions per day) + */ + double MeanMotion() const + { + return mean_motion_; + } + + /** + * Get the orbit number + * @returns the orbit number + */ + unsigned int OrbitNumber() const + { + return orbit_number_; + } + + /** + * Get the expected tle line length + * @returns the tle line length + */ + static unsigned int LineLength() + { + return TLE_LEN_LINE_DATA; + } + + /** + * Dump this object to a string + * @returns string + */ + std::string ToString() const + { + std::stringstream ss; + ss << std::right << std::fixed; + ss << "Norad Number: " << NoradNumber() << std::endl; + ss << "Int. Designator: " << IntDesignator() << std::endl; + ss << "Epoch: " << Epoch() << std::endl; + ss << "Orbit Number: " << OrbitNumber() << std::endl; + ss << std::setprecision(8); + ss << "Mean Motion Dt2: "; + ss << std::setw(12) << MeanMotionDt2() << std::endl; + ss << "Mean Motion Ddt6: "; + ss << std::setw(12) << MeanMotionDdt6() << std::endl; + ss << "Eccentricity: "; + ss << std::setw(12) << Eccentricity() << std::endl; + ss << "BStar: "; + ss << std::setw(12) << BStar() << std::endl; + ss << "Inclination: "; + ss << std::setw(12) << Inclination(true) << std::endl; + ss << "Right Ascending Node: "; + ss << std::setw(12) << RightAscendingNode(true) << std::endl; + ss << "Argument Perigee: "; + ss << std::setw(12) << ArgumentPerigee(true) << std::endl; + ss << "Mean Anomaly: "; + ss << std::setw(12) << MeanAnomaly(true) << std::endl; + ss << "Mean Motion: "; + ss << std::setw(12) << MeanMotion() << std::endl; + return ss.str(); + } + +private: + void Initialize(); + static bool IsValidLineLength(const std::string& str); + void ExtractInteger(const std::string& str, unsigned int& val); + void ExtractDouble(const std::string& str, int point_pos, double& val); + void ExtractExponential(const std::string& str, double& val); + +private: + std::string name_; + std::string line_one_; + std::string line_two_; + + std::string int_designator_; + DateTime epoch_; + double mean_motion_dt2_{}; + double mean_motion_ddt6_{}; + double bstar_{}; + double inclination_{}; + double right_ascending_node_{}; + double eccentricity_{}; + double argument_perigee_{}; + double mean_anomaly_{}; + double mean_motion_{}; + unsigned int norad_number_{}; + unsigned int orbit_number_{}; + + static const unsigned int TLE_LEN_LINE_DATA = 69; + static const unsigned int TLE_LEN_LINE_NAME = 22; +}; + + +inline std::ostream& operator<<(std::ostream& strm, const Tle& t) +{ + return strm << t.ToString(); +} + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/TleException.cc b/SPG4Tool/libsgp4/TleException.cc new file mode 100644 index 0000000..6a23d01 --- /dev/null +++ b/SPG4Tool/libsgp4/TleException.cc @@ -0,0 +1 @@ +#include "TleException.h" diff --git a/SPG4Tool/libsgp4/TleException.h b/SPG4Tool/libsgp4/TleException.h new file mode 100644 index 0000000..1caf6d0 --- /dev/null +++ b/SPG4Tool/libsgp4/TleException.h @@ -0,0 +1,44 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include +#include + +namespace libsgp4 +{ + +/** + * @brief The exception that the Tle class throws on an error. + * + * The exception that the Tle decoder will throw on an error. + */ +class TleException : public std::runtime_error +{ +public: + /** + * Constructor + * @param message Exception message + */ + explicit TleException(const char* message) + : runtime_error(message) + { + } +}; + +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/Util.cc b/SPG4Tool/libsgp4/Util.cc new file mode 100644 index 0000000..c022ac9 --- /dev/null +++ b/SPG4Tool/libsgp4/Util.cc @@ -0,0 +1,45 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "Util.h" + +#include +#include +#include + +namespace libsgp4 +{ + namespace Util { + void TrimLeft(std::string& s) + { + s.erase(s.begin(), + std::find_if(s.begin(), s.end(), [](unsigned char c) { return std::isgraph(c) != 0; })); + } + + void TrimRight(std::string& s) + { + s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char c) { return std::isgraph(c) != 0; }).base(), + s.end()); + } + + void Trim(std::string& s) + { + TrimLeft(s); + TrimRight(s); + } + } +} // namespace libsgp4::Util diff --git a/SPG4Tool/libsgp4/Util.h b/SPG4Tool/libsgp4/Util.h new file mode 100644 index 0000000..4135a7d --- /dev/null +++ b/SPG4Tool/libsgp4/Util.h @@ -0,0 +1,111 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include "Globals.h" + +#include + +namespace libsgp4 +{ +namespace Util +{ + template + + bool FromString(const std::string& str, T& val) + { + std::stringstream ss(str); + return !(ss >> val).fail(); + } + + /* + * always positive result + * Mod(-3,4)= 1 fmod(-3,4)= -3 + */ + inline double Mod(const double x, const double y) + { + if (y == 0.0) + { + return x; + } + + return x - y * floor(x / y); + } + + inline double WrapNegPosPI(const double a) + { + return Mod(a + kPI, kTWOPI) - kPI; + } + + inline double WrapTwoPI(const double a) + { + return Mod(a, kTWOPI); + } + + inline double WrapNegPos180(const double a) + { + return Mod(a + 180.0, 360.0) - 180.0; + } + + inline double Wrap360(const double a) + { + return Mod(a, 360.0); + } + + inline double DegreesToRadians(const double degrees) + { + return degrees * kPI / 180.0; + } + + inline double RadiansToDegrees(const double radians) + { + return radians * 180.0 / kPI; + } + + inline double AcTan(const double sinx, const double cosx) + { + if (cosx == 0.0) + { + if (sinx > 0.0) + { + return kPI / 2.0; + } + else + { + return 3.0 * kPI / 2.0; + } + } + else + { + if (cosx > 0.0) + { + return atan(sinx / cosx); + } + else + { + return kPI + atan(sinx / cosx); + } + } + } + + void TrimLeft(std::string& s); + void TrimRight(std::string& s); + void Trim(std::string& s); + +} // namespace Util +} // namespace libsgp4 diff --git a/SPG4Tool/libsgp4/Vector.cc b/SPG4Tool/libsgp4/Vector.cc new file mode 100644 index 0000000..1b12c95 --- /dev/null +++ b/SPG4Tool/libsgp4/Vector.cc @@ -0,0 +1,18 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "Vector.h" diff --git a/SPG4Tool/libsgp4/Vector.h b/SPG4Tool/libsgp4/Vector.h new file mode 100644 index 0000000..40856e5 --- /dev/null +++ b/SPG4Tool/libsgp4/Vector.h @@ -0,0 +1,160 @@ +/* + * Copyright 2013 Daniel Warner + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +#include +#include +#include +#include + +namespace libsgp4 +{ + +/** + * @brief Generic vector + * + * Stores x, y, z, w + */ +struct Vector +{ +public: + + /** + * Default constructor + */ + Vector() = default; + + /** + * Constructor + * @param arg_x x value + * @param arg_y y value + * @param arg_z z value + */ + Vector(const double arg_x, + const double arg_y, + const double arg_z) + : x(arg_x), y(arg_y), z(arg_z) + { + } + + /** + * Constructor + * @param arg_x x value + * @param arg_y y value + * @param arg_z z value + * @param arg_w w value + */ + Vector(const double arg_x, + const double arg_y, + const double arg_z, + const double arg_w) + : x(arg_x), y(arg_y), z(arg_z), w(arg_w) + { + } + + /** + * Copy constructor + * @param v value to copy from + */ + Vector(const Vector& v) + { + x = v.x; + y = v.y; + z = v.z; + w = v.w; + } + + /** + * Assignment operator + * @param v value to copy from + */ + Vector& operator=(const Vector& v) + { + if (this != &v) + { + x = v.x; + y = v.y; + z = v.z; + w = v.w; + } + return *this; + } + + /** + * Subtract operator + * @param v value to suctract from + */ + Vector operator-(const Vector& v) + { + return Vector(x - v.x, + y - v.y, + z - v.z, + 0.0); + } + + /** + * Calculates the magnitude of the vector + * @returns magnitude of the vector + */ + double Magnitude() const + { + return sqrt(x * x + y * y + z * z); + } + + /** + * Calculates the dot product + * @returns dot product + */ + double Dot(const Vector& vec) const + { + return (x * vec.x) + + (y * vec.y) + + (z * vec.z); + } + + /** + * Converts this vector to a string + * @returns this vector as a string + */ + std::string ToString() const + { + std::stringstream ss; + ss << std::right << std::fixed << std::setprecision(3); + ss << "X: " << std::setw(9) << x; + ss << ", Y: " << std::setw(9) << y; + ss << ", Z: " << std::setw(9) << z; + ss << ", W: " << std::setw(9) << w; + return ss.str(); + } + + /** x value */ + double x{}; + /** y value */ + double y{}; + /** z value */ + double z{}; + /** w value */ + double w{}; +}; + +inline std::ostream& operator<<(std::ostream& strm, const Vector& v) +{ + return strm << v.ToString(); +} + +} // namespace libsgp4 From 797c892f625996e1eb8c55c4f98ffd3be9ea32dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sat, 8 Mar 2025 21:50:48 +0800 Subject: [PATCH 02/94] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SPG4Tool/SPG4Tool.vcxproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SPG4Tool/SPG4Tool.vcxproj b/SPG4Tool/SPG4Tool.vcxproj index 1e28b4b..9a056ef 100644 --- a/SPG4Tool/SPG4Tool.vcxproj +++ b/SPG4Tool/SPG4Tool.vcxproj @@ -64,6 +64,11 @@ .\libsgp4;..\BaseCommonLibrary\BaseTool;$(IncludePath) + + + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + true From 3b300af71c773a870c741d12eab3b4e1324b1917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 11 Mar 2025 09:31:03 +0800 Subject: [PATCH 03/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=9F=BA?= =?UTF-8?q?=E4=BA=8Efp32=E7=9A=84fp64=E6=A8=A1=E6=8B=9F=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/ImageOperatorBase.cpp | 3 +- GPUBaseLib/GPUBaseLib.vcxproj | 5 + GPUBaseLib/GPUBaseLib.vcxproj.filters | 6 + GPUBaseLib/GPUTool/GPUDouble32.cu | 560 +++++++++ GPUBaseLib/GPUTool/GPUDouble32.cuh | 76 ++ Toolbox/SimulationSARTool/GPUBpSimulation.cu | 6 +- .../SimulationSAR/BPBasic0_CUDA.cu | 335 +++++- .../SimulationSAR/BPBasic0_CUDA.cuh | 14 +- .../SimulationSARTool.vcxproj | 2 +- Toolbox/SimulationSARTool/UnitTestMain.cpp | 1045 ++++++++++------- 10 files changed, 1640 insertions(+), 412 deletions(-) create mode 100644 GPUBaseLib/GPUTool/GPUDouble32.cu create mode 100644 GPUBaseLib/GPUTool/GPUDouble32.cuh diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp index b3c419e..4ffc877 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp @@ -3613,7 +3613,8 @@ void testOutClsArr(QString filename, long* amp, long rowcount, long colcount) { void BASECONSTVARIABLEAPI testOutComplexDoubleArr(QString filename, std::complex* data, long rowcount, long colcount) { - gdalImageComplex compleximg= CreateEchoComplex(filename, rowcount, colcount, 1); + QString ampPath = getDebugDataPath(filename); + gdalImageComplex compleximg= CreateEchoComplex(ampPath, rowcount, colcount, 1); compleximg.saveImage( data, 0, 0, rowcount, colcount, 1); return void BASECONSTVARIABLEAPI(); diff --git a/GPUBaseLib/GPUBaseLib.vcxproj b/GPUBaseLib/GPUBaseLib.vcxproj index 103a178..0e21f32 100644 --- a/GPUBaseLib/GPUBaseLib.vcxproj +++ b/GPUBaseLib/GPUBaseLib.vcxproj @@ -27,10 +27,12 @@ + + @@ -193,6 +195,9 @@ true compute_86,sm_86 + true + compile + O3 diff --git a/GPUBaseLib/GPUBaseLib.vcxproj.filters b/GPUBaseLib/GPUBaseLib.vcxproj.filters index a0ea2cd..1d8fae5 100644 --- a/GPUBaseLib/GPUBaseLib.vcxproj.filters +++ b/GPUBaseLib/GPUBaseLib.vcxproj.filters @@ -24,10 +24,16 @@ GPUTool + + GPUTool + GPUTool + + GPUTool + \ No newline at end of file diff --git a/GPUBaseLib/GPUTool/GPUDouble32.cu b/GPUBaseLib/GPUTool/GPUDouble32.cu new file mode 100644 index 0000000..7343486 --- /dev/null +++ b/GPUBaseLib/GPUTool/GPUDouble32.cu @@ -0,0 +1,560 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "BaseConstVariable.h" +#include "GPUTool.cuh" +#include "GPUDouble32.cuh" +#include "PrintMsgToQDebug.h" + + +// double תΪ double32 + + +// һʹCUDAÿٳָ +__device__ float fast_reciprocal(float x) { + return __fdividef(1.0f, x); // ȷԼ21λ +} + + +// PTXָʵ֣쵫Եͣ +__device__ float ptx_reciprocal(float x) { + float r; + asm("rcp.approx.ftz.f32 %0, %1;" : "=f"(r) : "f"(x)); + return r; // ȷԼ20λ +} + + +// ˫32λ㷨 +__device__ __host__ double32 two_sum(float a, float b) { + float s = a + b; + float v = s - a; + float e = (a - (s - v)) + (b - v); + return double32(s, e); +} + +__device__ __host__ double32 quick_two_sum(float a, float b) { + float s = a + b; + float e = b - (s - a); + return double32(s, e); +} + + + + + + +__device__ double32 double_to_double32(double value) { + const float SCALE_FACTOR = 1u << 12 + 1; // 4097.0f + const float INV_SCALE = 1.0f / SCALE_FACTOR; + + // Step 1: ָ˫ֵΪߵ + float high = __double2float_rd(value); + double residual = value - __double2float_rd(high); + + // Step 2: ʹDekker㷨ȷֽ + float temp = SCALE_FACTOR * __double2float_ru(residual); + float res_hi = temp - (temp - __double2float_ru(residual)); + float res_lo = __double2float_ru(residual) - res_hi; + + // Step 3: ϲ + float low = (res_hi + (res_lo + (residual - __double2float_rd(residual)))) * INV_SCALE; + + // Step 4: 淶 + float s = high + low; + float e = low - (s - high); + return double32(s, e); +} + +// double32 תΪ double +__device__ __host__ double double32_to_double(const double32& value) { + // ֲתȷȲʧ + const double high_part = static_cast(value.high); + const double low_part = static_cast(value.low); + + // Kahanʽӷ + const double sum = high_part + low_part; + const double err = (high_part - sum) + low_part; + + return sum + err; +} + + + +// ʹüӷ +__device__ double32 double32_add(const double32& a, const double32& b) { + double32 s = two_sum(a.high, b.high); + s.low += a.low + b.low; + return quick_two_sum(s.high, s.low); +} + +// ʹü +__device__ double32 double32_sub(const double32& a, const double32& b) { + // 1λļ㣩 + float high_diff = a.high - b.high; + + // 2㣨οDekker㷨 + float temp = (a.high - (high_diff + b.high)) + (b.high - (a.high - high_diff)); + + // 3λۺϼ㣨ϲοľȱƣ + float low_diff = (a.low - b.low) + temp; + + // 4滯ؼȱϣο + float sum = high_diff + low_diff; + float residual = low_diff - (sum - high_diff); + + return { sum, residual }; +} + +// ʹó˷ +__device__ double32 double32_mul(const double32& a, const double32& b) { + const float split = 4097.0f; // 2^12 + 1 + float c = split * a.high; + float a_hi = c - (c - a.high); + float a_lo = a.high - a_hi; + + c = split * b.high; + float b_hi = c - (c - b.high); + float b_lo = b.high - b_hi; + + float p = a.high * b.high; + float e = (((a_hi * b_hi - p) + a_hi * b_lo) + a_lo * b_hi) + a_lo * b_lo; + e += a.high * b.low + a.low * b.high; + return quick_two_sum(p, e); +} + +// ʹó +__device__ double32 double32_div(const double32& x, const double32& y) { + // 1ʹøĽţٵ + float y_hi = y.high; + float inv_hi = fast_reciprocal(y_hi); + + // һţٵȣҪ2FMA + inv_hi = __fmaf_rn(inv_hi, __fmaf_rn(-y_hi, inv_hi, 1.0f), inv_hi); + + // 2̵ĸλ + float q_hi = x.high * inv_hi; + + // 3 + double32 p = double32_mul(y, double32(q_hi, 0)); + double32 r = double32_sub(x, p); + + // 4ȷλ + float q_lo = (r.high + r.low) * inv_hi; + q_lo = __fmaf_rn(-q_hi, y.low, q_lo) * inv_hi; + + // 5淶 + return quick_two_sum(q_hi, q_lo); +} + +// ʹ sin +__device__ double32 double32_sin(const double32& a) { + double32 result; + result.high = sinf(a.high); + result.low = sinf(a.low); + return result; +} + +// ʹ cos +__device__ double32 double32_cos(const double32& a) { + double32 result; + result.high = cosf(a.high); + result.low = cosf(a.low); + return result; +} + +// ʹ log2 +__device__ double32 double32_log2(const double32& a) { + double32 result; + result.high = log2f(a.high); + result.low = log2f(a.low); + return result; +} + +// ʹ log10 +__device__ double32 double32_log10(const double32& a) { + double32 result; + result.high = log10f(a.high); + result.low = log10f(a.low); + return result; +} + +// ʹ ln +__device__ double32 double32_ln(const double32& a) { + double32 result; + result.high = logf(a.high); + result.low = logf(a.low); + return result; +} + +// ʹ exp +__device__ double32 double32_exp(const double32& a) { + double32 result; + result.high = expf(a.high); + result.low = expf(a.low); + return result; +} + +// ʹ pow +__device__ double32 double32_pow(const double32& a, const double32& b) { + double32 result; + result.high = powf(a.high, b.high); + result.low = powf(a.low, b.low); + return result; +} + +// ʹ sqrt +__device__ double32 double32_sqrt(const double32& a) { + double32 result; + result.high = sqrtf(a.high); + result.low = sqrtf(a.low); + return result; +} + + + + +__global__ void test_double_to_double32_kernel(double* d_input, double* d_output, int size) { + int idx = blockIdx.x * blockDim.x + threadIdx.x; + if (idx < size) { + double value = d_input[idx]; + d_output[idx] = double32_to_double(double_to_double32(value))-value; + } +} + + + + +__global__ void test_kernel(double* d_input, double* d_output, int size, int operation) { + int idx = blockIdx.x * blockDim.x + threadIdx.x; + if (idx < size) { + double va = d_input[idx]; + double vb = va + 1.0; + double32 a = double_to_double32(va); + double32 b = double_to_double32(vb); // ڶԪĵڶ + switch (operation) { + case 0: d_output[idx] = double32_to_double(double32_add(a, b)) - (va + vb); break; + case 1: d_output[idx] = double32_to_double(double32_sub(a, b)) - (va - vb); break; + case 2: d_output[idx] = double32_to_double(double32_mul(a, b)) - (va * vb); break; + case 3: d_output[idx] = double32_to_double(double32_div(a, b)) - (va / vb); break; + case 4: d_output[idx] = double32_to_double(double32_sin(a))-sin(va); break; + case 5: d_output[idx] = double32_to_double(double32_cos(a))-cos(va); break; + case 6: d_output[idx] = double32_to_double(double32_log2(a))-log2(va); break; + case 7: d_output[idx] = double32_to_double(double32_log10(a))-log10(va); break; + case 8: d_output[idx] = double32_to_double(double32_ln(a))-log(va); break; + case 9: d_output[idx] = double32_to_double(double32_exp(a))-exp(va); break; + case 10: d_output[idx] = double32_to_double(double32_pow(a, b))-pow(va,vb); break; + case 11: d_output[idx] = double32_to_double(double32_sqrt(a))-sqrt(va); break; + } + if (idx == 1) { + switch (operation) { + case 0: d_output[idx] = printf("add, \tva=%f,vb=%f,d_output=%e\n", va, vb, d_output[idx]);; break; + case 1: d_output[idx] = printf("sub, \tva=%f,vb=%f,d_output=%e\n", va, vb, d_output[idx]);; break; + case 2: d_output[idx] = printf("mul, \tva=%f,vb=%f,d_output=%e\n", va, vb, d_output[idx]);; break; + case 3: d_output[idx] = printf("div, \tva=%f,vb=%f,d_output=%e\n", va, vb, d_output[idx]);; break; + case 4: d_output[idx] = printf("sin, \tva=%f,vb=%f,d_output=%e\n", va, vb, d_output[idx]);; break; + case 5: d_output[idx] = printf("cos, \tva=%f,vb=%f,d_output=%e\n", va, vb, d_output[idx]);; break; + case 6: d_output[idx] = printf("log2, \tva=%f,vb=%f,d_output=%e\n", va, vb, d_output[idx]);; break; + case 7: d_output[idx] = printf("log10, \tva=%f,vb=%f,d_output=%e\n", va, vb, d_output[idx]);; break; + case 8: d_output[idx] = printf("ln, \tva=%f,vb=%f,d_output=%e\n", va, vb, d_output[idx]);; break; + case 9: d_output[idx] = printf("exp, \tva=%f,vb=%f,d_output=%e\n", va, vb, d_output[idx]);; break; + case 10: d_output[idx] = printf("pow, \tva=%f,vb=%f,d_output=%e\n", va, vb, d_output[idx]);; break; + case 11: d_output[idx] = printf("sqrt, \tva=%f,vb=%f,d_output=%e\n", va, vb, d_output[idx]);; break; + } + + } + + } +} + +void test_function(int operation, const char* operation_name) { + const int size = 1024; + double* h_input = new double[size]; + double* h_output = new double[size]; + double* d_input; + double* d_output; + + // ʼ + for (int i = 0; i < size; ++i) { + h_input[i] = static_cast(i)*100000.0 + 0.1234564324324232421421421421* 100000.0; + } + + // 豸ڴ + cudaMalloc(&d_input, size * sizeof(double)); + cudaMalloc(&d_output, size * sizeof(double)); + cudaMemcpy(d_input, h_input, size * sizeof(double), cudaMemcpyHostToDevice); + + // CUDA ں + auto start = std::chrono::high_resolution_clock::now(); + test_kernel << <(size + 255) / 256, 256 >> > (d_input, d_output, size, operation); + cudaDeviceSynchronize(); + auto end = std::chrono::high_resolution_clock::now(); + std::chrono::duration elapsed = end - start; + std::cout << operation_name << " time: " << elapsed.count() << " seconds" << std::endl; + + // ƽ + cudaMemcpy(h_output, d_output, size * sizeof(double), cudaMemcpyDeviceToHost); + + // 㾫 + double total_error = 0.0; + for (int i = 0; i < size; ++i) { + + double error = std::abs(h_output[i]); + total_error += error; + } + double average_error = total_error / size; + std::cout << operation_name << " average error: " << average_error << std::endl; + std::cout << operation_name << " average error: " << average_error << std::endl; + + // ͷڴ + delete[] h_input; + delete[] h_output; + cudaFree(d_input); + cudaFree(d_output); +} + + +__global__ void time_test_kernel(double* d_input, double* d_output, int size, int operation) { + int idx = blockIdx.x * blockDim.x + threadIdx.x; + if (idx < size) { + double va = d_input[idx]; + double vb = va + 1.0; + double32 a = double_to_double32(va); + double32 b = double_to_double32(vb); // ڶԪĵڶ + double result = 0.0; + for (long i = 0; i< 1000000; i++) { + switch (operation) { + case 0: result+= (double32_add(a, b).high); break; + case 1: result+= (double32_sub(a, b).high); break; + case 2: result+= (double32_mul(a, b).high); break; + case 3: result+= (double32_div(a, b).high); break; + case 4: result+= (double32_sin(a).high); break; + case 5: result+= (double32_cos(a).high); break; + case 6: result+= (double32_log2(a).high); break; + case 7: result+= (double32_log10(a).high); break; + case 8: result+= (double32_ln(a).high); break; + case 9: result+= (double32_exp(a).high); break; + case 10: result+= (double32_pow(a, b).high); break; + case 11: result+= (double32_sqrt(a).high); break; + } + } + d_output[idx]=result; + } +} + +__global__ void time_test_double_kernel(double* d_input, double* d_output, int size, int operation) { + int idx = blockIdx.x * blockDim.x + threadIdx.x; + if (idx < size) { + double va = d_input[idx]; + double vb = va + 1.0; + double32 a = double_to_double32(va); + double32 b = double_to_double32(vb); // ڶԪĵڶ + double result = 0.0; + for (long i = 0; i < 1000000; i++) { + switch (operation) { + case 0: result+= (va + vb); break; + case 1: result+= (va - vb); break; + case 2: result+= (va * vb); break; + case 3: result+= (va / vb); break; + case 4: result+= sin(va); break; + case 5: result+= cos(va); break; + case 6: result+= log2(va); break; + case 7: result+= log10(va); break; + case 8: result+= log(va); break; + case 9: result+= exp(va); break; + case 10:result+= pow(va, vb); break; + case 11:result+= sqrt(va); break; + } + } + d_output[idx] = result; + } +} + + + +void test_double_to_double32() { + const int size = 1024; + double* h_input = new double[size]; + double* h_output = new double[size]; + double* d_input; + double* d_output; + + // ʼ + for (int i = 0; i < size; ++i) { + h_input[i] = static_cast(i) * 1000000.0 + 0.123456789011 * 1000000.0; + } + + // 豸ڴ + cudaMalloc(&d_input, size * sizeof(double)); + cudaMalloc(&d_output, size * sizeof(double)); + cudaMemcpy(d_input, h_input, size * sizeof(double), cudaMemcpyHostToDevice); + + // CUDA ں + auto start = std::chrono::high_resolution_clock::now(); + test_double_to_double32_kernel << <(size + 255) / 256, 256 >> > (d_input, d_output, size); + cudaDeviceSynchronize(); + auto end = std::chrono::high_resolution_clock::now(); + std::chrono::duration elapsed = end - start; + std::cout << "double_to_double32 conversion time: " << elapsed.count() << " seconds" << std::endl; + + // ƽ + cudaMemcpy(h_output, d_output, size * sizeof(double), cudaMemcpyDeviceToHost); + + // 㾫 + double total_error = 0.0; + for (int i = 0; i < size; ++i) { + double error = std::abs(h_output[i]); + total_error += error; + } + double average_error = total_error / size; + std::cout << "double_to_double32 average error: " << average_error << std::endl; + + // Чλ + double effective_digits = -std::log10(average_error); + std::cout << "double_to_double32 effective digits: " << effective_digits << std::endl; + + // ͷڴ + delete[] h_input; + delete[] h_output; + cudaFree(d_input); + cudaFree(d_output); +} + + +void time_test_function(int operation, const char* operation_name) { + const int size = 1024; + double* h_input = new double[size]; + double* h_output = new double[size]; + double* d_input; + double* d_output; + + // ʼ + for (int i = 0; i < size; ++i) { + h_input[i] = static_cast(i) * 100000.0 + 0.1234564324324232421421421421 * 100000.0; + } + + // 豸ڴ + cudaMalloc(&d_input, size * sizeof(double)); + cudaMalloc(&d_output, size * sizeof(double)); + cudaMemcpy(d_input, h_input, size * sizeof(double), cudaMemcpyHostToDevice); + + // CUDA ں (double32) + auto start = std::chrono::high_resolution_clock::now(); + time_test_kernel << <(size + 255) / 256, 256 >> > (d_input, d_output, size, operation); + cudaDeviceSynchronize(); + auto end = std::chrono::high_resolution_clock::now(); + std::chrono::duration elapsed = end - start; + std::cout << operation_name << " (double32) time: " << elapsed.count() << " seconds" << std::endl; + + // ƽ + cudaMemcpy(h_output, d_output, size * sizeof(double), cudaMemcpyDeviceToHost); + + // 㾫 + double total_error = 0.0; + for (int i = 0; i < size; ++i) { + double error = std::abs(h_output[i]); + total_error += error; + } + double average_error = total_error / size; + std::cout << operation_name << " (double32) average error: " << average_error << std::endl; + + // CUDA ں (double) + start = std::chrono::high_resolution_clock::now(); + time_test_double_kernel << <(size + 255) / 256, 256 >> > (d_input, d_output, size, operation); + cudaDeviceSynchronize(); + end = std::chrono::high_resolution_clock::now(); + elapsed = end - start; + std::cout << operation_name << " (double) time: " << elapsed.count() << " seconds" << std::endl; + + // ƽ + cudaMemcpy(h_output, d_output, size * sizeof(double), cudaMemcpyDeviceToHost); + + // 㾫 + total_error = 0.0; + for (int i = 0; i < size; ++i) { + double error = std::abs(h_output[i]); + total_error += error; + } + average_error = total_error / size; + std::cout << operation_name << " (double) average error: " << average_error << std::endl; + + // ͷڴ + delete[] h_input; + delete[] h_output; + cudaFree(d_input); + cudaFree(d_output); +} + +void time_test_double_to_double32() { + const int size = 1024; + double* h_input = new double[size]; + double* h_output = new double[size]; + double* d_input; + double* d_output; + + // ʼ + for (int i = 0; i < size; ++i) { + h_input[i] = static_cast(i) * 1000000.0 + 0.123456789011 * 1000000.0; + } + + // 豸ڴ + cudaMalloc(&d_input, size * sizeof(double)); + cudaMalloc(&d_output, size * sizeof(double)); + cudaMemcpy(d_input, h_input, size * sizeof(double), cudaMemcpyHostToDevice); + + // CUDA ں + auto start = std::chrono::high_resolution_clock::now(); + test_double_to_double32_kernel << <(size + 255) / 256, 256 >> > (d_input, d_output, size); + cudaDeviceSynchronize(); + auto end = std::chrono::high_resolution_clock::now(); + std::chrono::duration elapsed = end - start; + std::cout << "double_to_double32 conversion time: " << elapsed.count() << " seconds" << std::endl; + + // ƽ + cudaMemcpy(h_output, d_output, size * sizeof(double), cudaMemcpyDeviceToHost); + + // 㾫 + double total_error = 0.0; + for (int i = 0; i < size; ++i) { + double error = std::abs(h_output[i]); + total_error += error; + } + double average_error = total_error / size; + std::cout << "double_to_double32 average error: " << average_error << std::endl; + + // Чλ + double effective_digits = -std::log10(average_error); + std::cout << "double_to_double32 effective digits: " << effective_digits << std::endl; + + // ͷڴ + delete[] h_input; + delete[] h_output; + cudaFree(d_input); + cudaFree(d_output); +} + + + +void time_test_add() { time_test_function(0, "Addition"); } +void time_test_sub() { time_test_function(1, "Subtraction"); } +void time_test_mul() { time_test_function(2, "Multiplication"); } +void time_test_div() { time_test_function(3, "Division"); } +void time_test_sin() { time_test_function(4, "Sine"); } +void time_test_cos() { time_test_function(5, "Cosine"); } +void time_test_log2() { time_test_function(6, "Log2"); } +void time_test_log10() { time_test_function(7, "Log10"); } +void time_test_ln() { time_test_function(8, "Natural Logarithm"); } +void time_test_exp() { time_test_function(9, "Exponential"); } +void time_test_pow() { time_test_function(10, "Power"); } +void time_test_sqrt() { time_test_function(11, "Square Root"); } diff --git a/GPUBaseLib/GPUTool/GPUDouble32.cuh b/GPUBaseLib/GPUTool/GPUDouble32.cuh new file mode 100644 index 0000000..b1e571d --- /dev/null +++ b/GPUBaseLib/GPUTool/GPUDouble32.cuh @@ -0,0 +1,76 @@ +#ifndef __GPUDOUBLE32__H__ +#define __GPUDOUBLE32__H__ + +// double32 struct ,ʹfp32ģdouble +struct double32{ + float high; + float low; + __device__ __host__ double32(float h = 0, float l = 0) : high(h), low(l) {} +}; + +extern __device__ double32 double_to_double32(double value); +extern __device__ __host__ double double32_to_double(const double32& value); +// ʹ PTX Żļӷ +extern __device__ double32 double32_add(const double32& a, const double32& b); + +// ʹ PTX Żļ +extern __device__ double32 double32_sub(const double32& a, const double32& b); + +// ʹ PTX Żij˷ +extern __device__ double32 double32_mul(const double32& a, const double32& b); + +// ʹ PTX Żij +extern __device__ double32 double32_div(const double32& a, const double32& b); + +// ʹ PTX Ż sin +extern __device__ double32 double32_sin(const double32& a); + +// ʹ PTX Ż cos +extern __device__ double32 double32_cos(const double32& a); + +// ʹ PTX Ż log2 +extern __device__ double32 double32_log2(const double32& a); + +// ʹ PTX Ż log10 +extern __device__ double32 double32_log10(const double32& a); + +// ʹ PTX Ż ln +extern __device__ double32 double32_ln(const double32& a); + +// ʹ PTX Ż exp +extern __device__ double32 double32_exp(const double32& a); + +// ʹ PTX Ż pow +extern __device__ double32 double32_pow(const double32& a, const double32& b); + +// ʹ PTX Ż sqrt +extern __device__ double32 double32_sqrt(const double32& a); + + +extern "C" GPUBASELIBAPI void test_double_to_double32(); +extern "C" GPUBASELIBAPI void test_function(int operation, const char* operation_name); + + + + + +extern "C" GPUBASELIBAPI void time_test_add(); +extern "C" GPUBASELIBAPI void time_test_sub(); +extern "C" GPUBASELIBAPI void time_test_mul(); +extern "C" GPUBASELIBAPI void time_test_div(); +extern "C" GPUBASELIBAPI void time_test_sin(); +extern "C" GPUBASELIBAPI void time_test_cos(); +extern "C" GPUBASELIBAPI void time_test_log2(); +extern "C" GPUBASELIBAPI void time_test_log10(); +extern "C" GPUBASELIBAPI void time_test_ln(); +extern "C" GPUBASELIBAPI void time_test_exp(); +extern "C" GPUBASELIBAPI void time_test_pow(); +extern "C" GPUBASELIBAPI void time_test_sqrt(); + + + + + + + +#endif // !__GPUDOUBLE32__H__ diff --git a/Toolbox/SimulationSARTool/GPUBpSimulation.cu b/Toolbox/SimulationSARTool/GPUBpSimulation.cu index 4c66f27..03648eb 100644 --- a/Toolbox/SimulationSARTool/GPUBpSimulation.cu +++ b/Toolbox/SimulationSARTool/GPUBpSimulation.cu @@ -99,9 +99,9 @@ void RFPCProcess(double Tx, double Ty, double Tz, 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); printf("antX host to device finished!!\n"); - HostToDevice(d_data.AntY, AntY, sizeof(double) * d_data.Np); printf("antY host to device finished!!\n"); - HostToDevice(d_data.AntZ, AntZ, sizeof(double) * d_data.Np); printf("antZ host to device finished!!\n"); + HostToDevice(d_data.AntX, AntX, sizeof(double) * d_data.Np); //printf("antX host to device finished!!\n"); + HostToDevice(d_data.AntY, AntY, sizeof(double) * d_data.Np); //printf("antY host to device finished!!\n"); + HostToDevice(d_data.AntZ, AntZ, sizeof(double) * d_data.Np); //printf("antZ host to device finished!!\n"); double minF = d_data.minF[0]; long grid_size = (d_data.Np + BLOCK_SIZE - 1) / BLOCK_SIZE; double dfreq = d_data.deltaF; diff --git a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu index 0156e2b..cdf1705 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu @@ -278,7 +278,337 @@ void BPBasic0(GPUDATA& h_data) - + + +/** ȴ**********************************************************************************************/ + + + + + + + +__global__ void phaseCompensationKernel_single(cufftComplex* phdata, const float* Freq, float r, int K, int Na) { + int freqIdx = blockIdx.x * blockDim.x + threadIdx.x; + int pulseIdx = blockIdx.y * blockDim.y + threadIdx.y; + + if (freqIdx >= K || pulseIdx >= Na) return; + + int idx = pulseIdx * K + freqIdx; + float phase = 4 * PI * Freq[freqIdx] * r / c; + float cos_phase = cosf(phase); + float sin_phase = sinf(phase); + + cufftComplex ph = phdata[idx]; + float new_real = ph.x * cos_phase - ph.y * sin_phase; + float new_imag = ph.x * sin_phase + ph.y * cos_phase; + phdata[idx] = make_cuComplex(new_real, new_imag); +} + +__global__ void fftshiftKernel_single(cufftComplex* data, int Nfft, int Np) { + int pulse = blockIdx.x * blockDim.x + threadIdx.x; + if (pulse >= Np) return; + + int half = Nfft / 2; + for (int i = 0; i < half; ++i) { + cufftComplex temp = data[pulse * Nfft + i]; + data[pulse * Nfft + i] = data[pulse * Nfft + i + half]; + data[pulse * Nfft + i + half] = temp; + } +} + +__global__ void processPulseKernel_single( + long prfid, + int nx, int ny, + const float* x_mat, const float* y_mat, const float* z_mat, + float AntX, float AntY, float AntZ, + float R0, float minF, + const cufftComplex* rc_pulse, + const float r_start, const float dr, const int nR, + cufftComplex* im_final +) { + // + + long long idx = blockIdx.x * blockDim.x + threadIdx.x; + long long pixelcount = nx * ny; + if (idx >= pixelcount) return; + + //printf("processPulseKernel start!!\n"); + + //if (x >= nx || y >= ny) return; + //int idx = x * ny + y; + + + float dx = AntX - x_mat[idx]; + float dy = AntY - y_mat[idx]; + float dz = AntZ - z_mat[idx]; + + //printf("processPulseKernel xmat !!\n"); + float R = sqrtf(dx * dx + dy * dy + dz * dz); + float dR = R - R0; + + if (dR < r_start || dR >= (r_start + dr * (nR - 1))) return; + // Linear interpolation + float pos = (dR - r_start) / dr; + int index = (int)floorf(pos); + float weight = pos - index; + + if (index < 0 || index >= nR - 1) return; + + cufftComplex rc_low = rc_pulse[prfid * nR + index]; + cufftComplex rc_high = rc_pulse[prfid * nR + index + 1]; + cufftComplex rc_interp; + rc_interp.x = rc_low.x * (1 - weight) + rc_high.x * weight; + rc_interp.y = rc_low.y * (1 - weight) + rc_high.y * weight; + + // Phase correction + float phase = 4 * PI * minF / c * dR; + float cos_phase = cosf(phase); + float sin_phase = sinf(phase); + + cufftComplex phCorr; + phCorr.x = rc_interp.x * cos_phase - rc_interp.y * sin_phase; + phCorr.y = rc_interp.x * sin_phase + rc_interp.y * cos_phase; + + // Accumulate + im_final[idx].x += phCorr.x; + im_final[idx].y += phCorr.y; + //printf("r_start=%e;dr=%e;nR=%d\n", r_start, dr, nR); + +} + + + + + + + + + + + + + + + + + + + + + + + + + + +void bpBasic0CUDA_single(GPUDATA_single& data, int flag, float* h_R) +{ + // Phase compensation + if (flag == 1) { + dim3 block(16, 16); + dim3 grid((data.K + 15) / 16, (data.Np + 15) / 16); + phaseCompensationKernel_single << > > (data.phdata, data.Freq, data.R0, data.K, data.Np); + PrintLasterError("bpBasic0CUDA Phase compensation"); + //data.R0 = data.r; // data.rȷ + } + + // FFT + cufftHandle plan; + cufftPlan1d(&plan, data.Nfft, CUFFT_C2C, data.Np); + cufftExecC2C(plan, data.phdata, data.phdata, CUFFT_INVERSE); + cufftDestroy(plan); + + // FFTλ + dim3 blockShift(256); + dim3 gridShift((data.Np + 255) / 256); + fftshiftKernel_single << > > (data.phdata, data.Nfft, data.Np); + PrintLasterError("bpBasic0CUDA Phase FFT Process"); + + printfinfo("fft finished!!\n"); + // ͼؽ + + + + float r_start = data.r_vec[0]; + float dr = (data.r_vec[data.Nfft - 1] - r_start) / (data.Nfft - 1); + printfinfo("dr = %f\n", dr); + long pixelcount = data.nx * data.ny; + long grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; + printfinfo("grid finished!!\n"); + + //float* d_R = (float*)mallocCUDADevice(sizeof(float) * data.nx * data.ny); + printfinfo("r_start=%e;dr=%e;nR=%d\n", r_start, dr, data.Nfft); + printfinfo("BPimage .....\n"); + for (long ii = 0; ii < data.Np; ++ii) { + processPulseKernel_single << > > ( + ii, + data.nx, data.ny, + data.x_mat, data.y_mat, data.z_mat, + data.AntX[ii], data.AntY[ii], data.AntZ[ii], + data.R0, data.minF[ii], + data.phdata, + r_start, dr, data.Nfft, + data.im_final + //,d_R + ); + PrintLasterError("processPulseKernel"); + if (ii % 1000 == 0) { + printfinfo("\rPRF(%f %) %d / %d\t\t\t\t", (ii * 100.0 / data.Np), ii, data.Np); + } + } + //FreeCUDADevice(d_R); + + PrintLasterError("bpBasic0CUDA Phase BPimage Process finished!!"); +} + +void initGPUData_single(GPUDATA_single& h_data, GPUDATA_single& d_data) +{ + d_data.AntX = h_data.AntX; //(double*)mallocCUDADevice(sizeof(double) * h_data.Np); + d_data.AntY = h_data.AntY;//(double*)mallocCUDADevice(sizeof(double) * h_data.Np); + d_data.AntZ = h_data.AntZ;// (double*)mallocCUDADevice(sizeof(double) * h_data.Np); + d_data.minF = h_data.minF;// (double*)mallocCUDADevice(sizeof(double) * h_data.Np); + d_data.x_mat = (float*)mallocCUDADevice(sizeof(float) * h_data.nx * h_data.ny); + d_data.y_mat = (float*)mallocCUDADevice(sizeof(float) * h_data.nx * h_data.ny); + d_data.z_mat = (float*)mallocCUDADevice(sizeof(float) * h_data.nx * h_data.ny); + d_data.r_vec = h_data.r_vec;// (double*)mallocCUDADevice(sizeof(double) * h_data.Nfft); + d_data.Freq = (float*)mallocCUDADevice(sizeof(float) * h_data.Nfft); + d_data.phdata = (cuComplex*)mallocCUDADevice(sizeof(cuComplex) * h_data.Nfft * h_data.Np); + d_data.im_final = (cuComplex*)mallocCUDADevice(sizeof(cuComplex) * h_data.nx * h_data.ny); + + //HostToDevice(h_data.AntX, d_data.AntX,sizeof(double) * h_data.Np); + //HostToDevice(h_data.AntY, d_data.AntY,sizeof(double) * h_data.Np); + //HostToDevice(h_data.AntZ, d_data.AntZ,sizeof(double) * h_data.Np); + //HostToDevice(h_data.minF, d_data.minF,sizeof(double) * h_data.Np); + HostToDevice(h_data.x_mat, d_data.x_mat, sizeof(float) * h_data.nx * h_data.ny); printf("image X Copy finished!!!\n"); + HostToDevice(h_data.y_mat, d_data.y_mat, sizeof(float) * h_data.nx * h_data.ny); printf("image Y Copy finished!!!\n"); + HostToDevice(h_data.z_mat, d_data.z_mat, sizeof(float) * h_data.nx * h_data.ny); printf("image Z Copy finished!!!\n"); + HostToDevice(h_data.Freq, d_data.Freq, sizeof(float) * h_data.Nfft); + //HostToDevice(h_data.r_vec, d_data.r_vec, sizeof(double) * h_data.Nfft); + HostToDevice(h_data.phdata, d_data.phdata, sizeof(cuComplex) * h_data.Nfft * h_data.Np); printf("image echo Copy finished!!!\n"); + HostToDevice(h_data.im_final, d_data.im_final, sizeof(cuComplex) * h_data.nx * h_data.ny); printf("image data Copy finished!!!\n"); + + // + d_data.Nfft = h_data.Nfft; + d_data.K = h_data.K; + d_data.Np = h_data.Np; + d_data.nx = h_data.nx; + d_data.ny = h_data.ny; + d_data.R0 = h_data.R0; + d_data.deltaF = h_data.deltaF; +} + +void freeGPUData_single(GPUDATA_single& d_data) +{ + //FreeCUDADevice((d_data.AntX)); +//FreeCUDADevice((d_data.AntY)); +//FreeCUDADevice((d_data.AntZ)); +//FreeCUDADevice((d_data.minF)); + FreeCUDADevice((d_data.x_mat)); + FreeCUDADevice((d_data.y_mat)); + FreeCUDADevice((d_data.z_mat)); + //FreeCUDADevice((d_data.r_vec)); + FreeCUDADevice((d_data.Freq)); + FreeCUDADevice((d_data.phdata)); + FreeCUDADevice((d_data.im_final)); +} + +void freeHostData_single(GPUDATA_single& h_data) +{ + //FreeCUDAHost((h_data.AntX)); +//FreeCUDAHost((h_data.AntY)); +//FreeCUDAHost((h_data.AntZ)); + FreeCUDAHost((h_data.minF)); + //FreeCUDAHost((h_data.x_mat)); + //FreeCUDAHost((h_data.y_mat)); + //FreeCUDAHost((h_data.z_mat)); + FreeCUDAHost((h_data.r_vec)); + FreeCUDAHost((h_data.Freq)); + FreeCUDAHost((h_data.phdata)); + FreeCUDAHost((h_data.im_final)); +} + +void BPBasic0_single(GPUDATA_single& h_data) +{ + GPUDATA_single d_data; + initGPUData_single(h_data, d_data); + bpBasic0CUDA_single(d_data, 0); + DeviceToHost(h_data.im_final, d_data.im_final, sizeof(cuComplex) * h_data.nx * h_data.ny); + freeGPUData_single(d_data); +} + +void copy_Host_Single_GPUData(GPUDATA_single& h_data, GPUDATA& d_data) +{ + d_data.Nfft = h_data.Nfft; + d_data.K = h_data.K; + d_data.Np = h_data.Np; + d_data.nx = h_data.nx; + d_data.ny = h_data.ny; + d_data.R0 = h_data.R0; + d_data.deltaF = h_data.deltaF; + + + d_data.AntX = (double*)mallocCUDAHost(sizeof(double) * h_data.Np); + d_data.AntY = (double*)mallocCUDAHost(sizeof(double) * h_data.Np); + d_data.AntZ = (double*)mallocCUDAHost(sizeof(double) * h_data.Np); + d_data.r_vec = (double*)mallocCUDAHost(sizeof(double) * h_data.Nfft); + d_data.minF = (double*)mallocCUDAHost(sizeof(double) * h_data.Np); + + d_data.x_mat = (double*)mallocCUDADevice(sizeof(double) * h_data.nx * h_data.ny); + d_data.y_mat = (double*)mallocCUDADevice(sizeof(double) * h_data.nx * h_data.ny); + d_data.z_mat = (double*)mallocCUDADevice(sizeof(double) * h_data.nx * h_data.ny); + d_data.Freq = (double*)mallocCUDADevice(sizeof(double) * h_data.Nfft); + + d_data.phdata = (cuComplex*)mallocCUDADevice(sizeof(cuComplex) * h_data.Nfft * h_data.Np); + d_data.im_final = (cuComplex*)mallocCUDADevice(sizeof(cuComplex) * h_data.nx * h_data.ny); + + + for (long i = 0; i < h_data.Np; i++) { + d_data.AntX[i] = h_data.AntX[i]; + d_data.AntY[i] = h_data.AntY[i]; + d_data.AntZ[i] = h_data.AntZ[i]; + d_data.minF[i] = h_data.minF[i]; + } + + + + for (long i = 0; i < h_data.Nfft; i++) { + d_data.r_vec[i] = h_data.r_vec[i]; + + } + + double* x_mat = (double*)mallocCUDAHost(sizeof(double) * h_data.nx * h_data.ny); + double* y_mat = (double*)mallocCUDAHost(sizeof(double) * h_data.nx * h_data.ny); + double* z_mat = (double*)mallocCUDAHost(sizeof(double) * h_data.nx * h_data.ny); + + + for (long i = 0; i < h_data.ny; i++) { + for (long j = 0; j < h_data.nx; j++) { + x_mat[i * h_data.nx + j] = h_data.x_mat[i * h_data.nx + j]; + y_mat[i * h_data.nx + j] = h_data.y_mat[i * h_data.nx + j]; + z_mat[i * h_data.nx + j] = h_data.z_mat[i * h_data.nx + j]; + } + } + + double* h_freq = (double*)mallocCUDAHost(sizeof(double) * h_data.Nfft); + for (long i = 0; i < h_data.Nfft; i++) { + h_freq[i] = h_data.Freq[i]; + } + HostToDevice(h_freq, d_data.Freq, sizeof(double) * h_data.Nfft); + HostToDevice(x_mat, d_data.x_mat, sizeof(double) * h_data.nx * h_data.ny); printf("image X Copy finished!!!\n"); + HostToDevice(y_mat, d_data.y_mat, sizeof(double) * h_data.nx * h_data.ny); printf("image Y Copy finished!!!\n"); + HostToDevice(z_mat, d_data.z_mat, sizeof(double) * h_data.nx * h_data.ny); printf("image Z Copy finished!!!\n"); + + HostToDevice(h_data.phdata, d_data.phdata, sizeof(cuComplex) * h_data.Nfft * h_data.Np); printf("image echo Copy finished!!!\n"); + HostToDevice(h_data.im_final, d_data.im_final, sizeof(cuComplex) * h_data.nx * h_data.ny); printf("image data Copy finished!!!\n"); + FreeCUDAHost(h_freq); + FreeCUDAHost(x_mat); + FreeCUDAHost(y_mat); + FreeCUDAHost(z_mat); + + +} + //int main() { // GPUDATA h_data, d_data; // @@ -301,4 +631,5 @@ void BPBasic0(GPUDATA& h_data) // freeGPUData(d_data); // // return 0; -//} \ No newline at end of file +//} + \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cuh b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cuh index 47857e2..c971640 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cuh @@ -56,11 +56,15 @@ extern "C" { extern "C" { // Ϊ񾫶Ȳ - //void bpBasic0CUDA_single(GPUDATA_single& data, int flag, float* h_R = nullptr); - //void initGPUData_single(GPUDATA_single& h_data, GPUDATA_single& d_data); - //void freeGPUData_single(GPUDATA_single& d_data); - //void freeHostData_single(GPUDATA_single& d_data); - //void BPBasic0_single(GPUDATA_single& h_data); + void bpBasic0CUDA_single(GPUDATA_single& data, int flag, float* h_R = nullptr); + void initGPUData_single(GPUDATA_single& h_data, GPUDATA_single& d_data); + void freeGPUData_single(GPUDATA_single& d_data); + void freeHostData_single(GPUDATA_single& d_data); + void BPBasic0_single(GPUDATA_single& h_data); + + void copy_Host_Single_GPUData(GPUDATA_single& h_data, GPUDATA& d_data); + + }; diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 455e87e..d538eab 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -41,7 +41,7 @@ Unicode - DynamicLibrary + Application v143 false true diff --git a/Toolbox/SimulationSARTool/UnitTestMain.cpp b/Toolbox/SimulationSARTool/UnitTestMain.cpp index 7ed4763..1d1c4e6 100644 --- a/Toolbox/SimulationSARTool/UnitTestMain.cpp +++ b/Toolbox/SimulationSARTool/UnitTestMain.cpp @@ -15,6 +15,7 @@ #include "BPBasic0_CUDA.cuh" #include "ImageOperatorBase.h" #include "GPUBpSimulation.cuh" +#include "GPUDouble32.cuh" #include @@ -120,11 +121,19 @@ void testSimualtionEchoPoint() { /** 7. ز **************************************************************************************************/ GPUDATA d_data; initGPUData(h_data, d_data); + + long targetStep = dem_rowCount * dem_ColCount / 100; + for (long i = 0; i < dem_rowCount * dem_ColCount; i = i + targetStep) { + float Tx = h_data.x_mat[i], + Ty = h_data.y_mat[i], + Tz = h_data.z_mat[i]; + float Tslx = h_data.x_mat[i], Tsly = h_data.y_mat[i], Tslz = h_data.z_mat[i]; - RFPCProcess(Tx, Ty, Tz, - Tslx, Tsly, Tslz, // Ŀ - p1, p2, p3, p4, p5, p6, - d_data); + RFPCProcess(Tx, Ty, Tz, + Tslx, Tsly, Tslz, // Ŀ + p1, p2, p3, p4, p5, p6, + d_data); + } /** 8. չʾز **************************************************************************************************/ @@ -404,405 +413,641 @@ void testBpImage() { } -// -// -//void testSimualtionEchoPoint_single() { -// GPUDATA_single h_data{}; -// /** 1. **************************************************************************************************/ -// qDebug() << u8"1.ļȡС"; -// QString inGPSPath = u8"C:\\Users\\30453\\Desktop\\script\\data\\GF3_Simulation.gpspos.data"; -// long gpspoints = gdalImage(inGPSPath).height; -// std::shared_ptr antpos = SatelliteAntPosOperator::readAntPosFile(inGPSPath, gpspoints); -// h_data.AntX = (float*)mallocCUDAHost(sizeof(float) * gpspoints); -// h_data.AntY = (float*)mallocCUDAHost(sizeof(float) * gpspoints); -// h_data.AntZ = (float*)mallocCUDAHost(sizeof(float) * gpspoints); -// -// for (long i = 0; i < gpspoints; i = i + 1) { -// h_data.AntX[i] = antpos.get()[i].Px; -// h_data.AntY[i] = antpos.get()[i].Py; -// h_data.AntZ[i] = antpos.get()[i].Pz; -// } -// //gpspoints = gpspoints / 2; -// qDebug() << "GPS points Count:\t" << gpspoints; -// qDebug() << "PRF 0:\t " << QString("%1,%2,%3").arg(h_data.AntX[0]).arg(h_data.AntY[0]).arg(h_data.AntZ[0]); -// qDebug() << "PRF " << gpspoints - 1 << ":\t " << QString("%1,%2,%3") -// .arg(h_data.AntX[gpspoints - 1]) -// .arg(h_data.AntY[gpspoints - 1]) -// .arg(h_data.AntZ[gpspoints - 1]); -// /** 2. **************************************************************************************************/ -// qDebug() << u8"ļȡ\n2.ȡ"; -// QString demxyzPath = u8"C:\\Users\\30453\\Desktop\\script\\޸GF3\\data\\demxyz.bin"; -// gdalImage demgridimg(demxyzPath); -// long dem_rowCount = demgridimg.height; -// long dem_ColCount = demgridimg.width; -// std::shared_ptr demX = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); -// std::shared_ptr demY = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); -// std::shared_ptr demZ = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); -// -// h_data.x_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); -// h_data.y_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); -// h_data.z_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); -// -// for (long i = 0; i < dem_rowCount; i++) { -// for (long j = 0; j < dem_ColCount; j++) { -// h_data.x_mat[i * dem_ColCount + j] = demX.get()[i * dem_ColCount + j]; -// h_data.y_mat[i * dem_ColCount + j] = demY.get()[i * dem_ColCount + j]; -// h_data.z_mat[i * dem_ColCount + j] = demZ.get()[i * dem_ColCount + j]; -// } -// } -// qDebug() << "dem row Count:\t" << dem_rowCount; -// qDebug() << "dem col Count:\t" << dem_ColCount; -// -// qDebug() << u8"ȡ"; -// /** 3. Ƶ **************************************************************************************************/ -// qDebug() << u8"3.Ƶ"; -// float centerFreq = 5.3e9; -// float bandwidth = 40e6; -// long freqpoints = 2048; -// std::shared_ptr freqlist(getFreqPoints_mallocHost_single(centerFreq - bandwidth / 2, centerFreq + bandwidth / 2, freqpoints), FreeCUDAHost); -// std::shared_ptr minF(new float[gpspoints], delArrPtr); -// for (long i = 0; i < gpspoints; i++) { -// minF.get()[i] = freqlist.get()[0]; -// } -// h_data.deltaF = bandwidth / (freqpoints - 1); -// 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()[1] - freqlist.get()[0]; -// qDebug() << u8"Ƶʽ"; -// /** 4. ʼز **************************************************************************************************/ -// qDebug() << u8"4.ʼز"; -// std::shared_ptr phdata(createEchoPhase_mallocHost(gpspoints, freqpoints), FreeCUDAHost); -// qDebug() << "Azimuth Points:\t" << gpspoints; -// qDebug() << "Range Points:\t" << freqpoints; -// qDebug() << u8"ʼز"; -// /** 5. ʼͼ **************************************************************************************************/ -// qDebug() << u8"5.ʼͼ"; -// h_data.im_final = (cuComplex*)mallocCUDAHost(sizeof(cuComplex) * dem_rowCount * dem_ColCount); -// qDebug() << "Azimuth Points:\t" << gpspoints; -// qDebug() << "Range Points:\t" << freqpoints; -// qDebug() << u8"ʼͼ"; -// -// /** 6. ģͲʼ **************************************************************************************************/ -// qDebug() << u8"6.ģͲʼ"; -// -// h_data.nx = dem_ColCount; -// h_data.ny = dem_rowCount; -// -// h_data.Np = gpspoints; -// h_data.Freq = freqlist.get(); -// h_data.minF = minF.get(); -// h_data.Nfft = freqpoints; -// h_data.K = h_data.Nfft; -// h_data.phdata = phdata.get(); -// h_data.R0 = 900000; -// qDebug() << u8"ģͲ"; -// -// -// /** 7. Ŀ **************************************************************************************************/ -// float Tx = -2029086.618142, Ty = 4139594.934504, Tz = 4392846.782027; -// float Tslx = -2029086.618142, Tsly = 4139594.934504, Tslz = 4392846.782027; -// float p1 = 1, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0; -// -// /** 7. ز **************************************************************************************************/ -// GPUDATA_single d_data; -// initGPUData_single(h_data, d_data); -// -// RFPCProcess_single(Tx, Ty, Tz, -// Tslx, Tsly, Tslz, // Ŀ -// p1, p2, p3, p4, p5, p6, -// d_data); -// -// -// /** 8. չʾز **************************************************************************************************/ -// { -// DeviceToHost(h_data.phdata, d_data.phdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); -// cuComplex* h_ifftphdata = (cuComplex*)mallocCUDAHost(sizeof(cuComplex) * d_data.Np * d_data.Nfft); -// cuComplex* d_ifftphdata = (cuComplex*)mallocCUDADevice(sizeof(cuComplex) * d_data.Np * d_data.Nfft); -// CUDAIFFT(d_data.phdata, d_ifftphdata, d_data.Np, d_data.Nfft, d_data.Nfft); -// FFTShift1D(d_ifftphdata, d_data.Np, d_data.Nfft); -// DeviceToHost(h_ifftphdata, d_ifftphdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); -// std::shared_ptr> ifftdata(new std::complex[d_data.Np * d_data.Nfft], delArrPtr); -// { -// for (long i = 0; i < d_data.Np; i++) { -// for (long j = 0; j < d_data.Nfft; j++) { -// ifftdata.get()[i * d_data.Nfft + j] = -// std::complex( -// h_ifftphdata[i * d_data.Nfft + j].x, -// h_ifftphdata[i * d_data.Nfft + j].y); -// } -// } -// } -// testOutComplexDoubleArr(QString("echo_ifft_single.bin"), ifftdata.get(), d_data.Np, d_data.Nfft); -// -// FreeCUDADevice(d_ifftphdata); -// FreeCUDAHost(h_ifftphdata); -// -// } -// /** 9. **************************************************************************************************/ -// -// // maxWrҪȼdeltaF -// float deltaF = h_data.deltaF; // ȡ -// float maxWr = 299792458.0f / (2.0f * deltaF); -// qDebug() << "maxWr :\t" << maxWr; -// float* r_vec_host = (float*)mallocCUDAHost(sizeof(float) * h_data.Nfft);// new float[data.Nfft]; -// const float step = maxWr / h_data.Nfft; -// const float start = -1 * h_data.Nfft / 2.0f * step; -// printf("nfft=%d\n", h_data.Nfft); -// -// for (int i = 0; i < h_data.Nfft; ++i) { -// r_vec_host[i] = start + i * step; -// } -// -// h_data.r_vec = r_vec_host; -// d_data.r_vec = h_data.r_vec; -// -// qDebug() << "r_vec [0]:\t" << h_data.r_vec[0]; -// qDebug() << "r_vec step:\t" << step; -// -// bpBasic0CUDA_single(d_data, 0); -// -// DeviceToHost(h_data.im_final, d_data.im_final, sizeof(cuComplex) * d_data.nx * d_data.ny); -// -// { -// DeviceToHost(h_data.phdata, d_data.phdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); -// std::shared_ptr> ifftdata(new std::complex[d_data.Np * d_data.Nfft], delArrPtr); -// { -// for (long i = 0; i < d_data.Np; i++) { -// for (long j = 0; j < d_data.Nfft; j++) { -// ifftdata.get()[i * d_data.Nfft + j] = -// std::complex( -// h_data.phdata[i * d_data.Nfft + j].x, -// h_data.phdata[i * d_data.Nfft + j].y); -// } -// } -// } -// testOutComplexDoubleArr(QString("echo_ifft_BPBasic_single.bin"), ifftdata.get(), d_data.Np, d_data.Nfft); -// -// -// -// std::shared_ptr> im_finals(new std::complex[d_data.nx * d_data.ny], delArrPtr); -// { -// for (long i = 0; i < d_data.ny; i++) { -// for (long j = 0; j < d_data.nx; j++) { -// im_finals.get()[i * d_data.nx + j] = std::complex( -// h_data.im_final[i * d_data.nx + j].x, -// h_data.im_final[i * d_data.nx + j].y); -// } -// } -// } -// testOutComplexDoubleArr(QString("im_finals_single.bin"), im_finals.get(), d_data.ny, d_data.nx); -// } -//} -// -// -//void testBpImage_single() { -// -// GPUDATA_single h_data{}; -// /** 0. **************************************************************************************************/ -// QString echoPath = "D:\\Programme\\vs2022\\RasterMergeTest\\LAMPCAE_SCANE-all-scane\\GF3_Simulation.xml"; -// std::shared_ptr echoL0ds(new EchoL0Dataset); -// echoL0ds->Open(echoPath); -// qDebug() << u8"ػزļ\t" << echoPath; -// -// /** 1. **************************************************************************************************/ -// qDebug() << u8"1.ļȡС"; -// QString inGPSPath = echoL0ds->getGPSPointFilePath(); -// long gpspoints = gdalImage(inGPSPath).height; -// std::shared_ptr antpos = SatelliteAntPosOperator::readAntPosFile(inGPSPath, gpspoints); -// h_data.AntX = (float*)mallocCUDAHost(sizeof(float) * gpspoints); -// h_data.AntY = (float*)mallocCUDAHost(sizeof(float) * gpspoints); -// h_data.AntZ = (float*)mallocCUDAHost(sizeof(float) * gpspoints); -// -// for (long i = 0; i < gpspoints; i = i + 1) { -// h_data.AntX[i] = antpos.get()[i].Px; -// h_data.AntY[i] = antpos.get()[i].Py; -// h_data.AntZ[i] = antpos.get()[i].Pz; -// } -// //gpspoints = gpspoints / 2; -// qDebug() << "GPS points Count:\t" << gpspoints; -// qDebug() << "PRF 0:\t " << QString("%1,%2,%3").arg(h_data.AntX[0]).arg(h_data.AntY[0]).arg(h_data.AntZ[0]); -// qDebug() << "PRF " << gpspoints - 1 << ":\t " << QString("%1,%2,%3") -// .arg(h_data.AntX[gpspoints - 1]) -// .arg(h_data.AntY[gpspoints - 1]) -// .arg(h_data.AntZ[gpspoints - 1]); -// /** 2. **************************************************************************************************/ -// qDebug() << u8"ļȡ\n2.ȡ"; -// QString demxyzPath = u8"D:\\Programme\\vs2022\\RasterMergeTest\\simulationData\\demdataset\\demxyz.bin"; -// gdalImage demgridimg(demxyzPath); -// long dem_rowCount = demgridimg.height; -// long dem_ColCount = demgridimg.width; -// std::shared_ptr demX = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); -// std::shared_ptr demY = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); -// std::shared_ptr demZ = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); -// -// h_data.x_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); -// h_data.y_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); -// h_data.z_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); -// -// for (long i = 0; i < dem_rowCount; i++) { -// for (long j = 0; j < dem_ColCount; j++) { -// h_data.x_mat[i * dem_ColCount + j] = demX.get()[i * dem_ColCount + j]; -// h_data.y_mat[i * dem_ColCount + j] = demY.get()[i * dem_ColCount + j]; -// h_data.z_mat[i * dem_ColCount + j] = demZ.get()[i * dem_ColCount + j]; -// } -// } -// qDebug() << "dem row Count:\t" << dem_rowCount; -// qDebug() << "dem col Count:\t" << dem_ColCount; -// -// qDebug() << u8"ȡ"; -// /** 3. Ƶ **************************************************************************************************/ -// qDebug() << u8"3.Ƶ"; -// float centerFreq = echoL0ds->getCenterFreq(); -// float bandwidth = echoL0ds->getBandwidth(); -// size_t freqpoints = echoL0ds->getPlusePoints(); -// std::shared_ptr freqlist(getFreqPoints_mallocHost_single(centerFreq - bandwidth / 2, centerFreq + bandwidth / 2, freqpoints), FreeCUDAHost); -// std::shared_ptr minF(new float[gpspoints], delArrPtr); -// for (long i = 0; i < gpspoints; i++) { -// minF.get()[i] = freqlist.get()[0]; -// } -// h_data.deltaF = bandwidth / (freqpoints - 1); -// 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()[1] - freqlist.get()[0]; -// qDebug() << u8"Ƶʽ"; -// /** 4. ʼز **************************************************************************************************/ -// qDebug() << u8"4.ʼز"; -// std::shared_ptr> echoData = echoL0ds->getEchoArr(); -// size_t echosize = sizeof(cuComplex) * gpspoints * freqpoints; -// qDebug() << "echo data size (byte) :\t" << echosize; -// h_data.phdata = (cuComplex*)mallocCUDAHost(echosize); -// shared_complexPtrToHostCuComplex(echoData.get(), h_data.phdata, gpspoints * freqpoints); -// -// qDebug() << "Azimuth Points:\t" << gpspoints; -// qDebug() << "Range Points:\t" << freqpoints; -// qDebug() << u8"ʼز"; -// /** 5. ʼͼ **************************************************************************************************/ -// qDebug() << u8"5.ʼͼ"; -// h_data.im_final = (cuComplex*)mallocCUDAHost(sizeof(cuComplex) * dem_rowCount * dem_ColCount); -// qDebug() << "Azimuth Points:\t" << gpspoints; -// qDebug() << "Range Points:\t" << freqpoints; -// qDebug() << u8"ʼͼ"; -// -// /** 6. ģͲʼ **************************************************************************************************/ -// qDebug() << u8"6.ģͲʼ"; -// -// h_data.nx = dem_ColCount; -// h_data.ny = dem_rowCount; -// -// h_data.Np = gpspoints; -// h_data.Freq = freqlist.get(); -// h_data.minF = minF.get(); -// h_data.Nfft = freqpoints; -// h_data.K = h_data.Nfft; -// -// h_data.R0 = echoL0ds->getRefPhaseRange(); -// qDebug() << u8"ģͲ"; -// -// -// /** 7. Ŀ **************************************************************************************************/ -// double Tx = -2029086.618142, Ty = 4139594.934504, Tz = 4392846.782027; -// double Tslx = -2029086.618142, Tsly = 4139594.934504, Tslz = 4392846.782027; -// double p1 = 33.3, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0; -// -// /** 7. ز **************************************************************************************************/ -// GPUDATA_single d_data; -// initGPUData_single(h_data, d_data); -// -// /** 8. չʾز **************************************************************************************************/ -// { -// DeviceToHost(h_data.phdata, d_data.phdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); -// cuComplex* h_ifftphdata = (cuComplex*)mallocCUDAHost(sizeof(cuComplex) * d_data.Np * d_data.Nfft); -// cuComplex* d_ifftphdata = (cuComplex*)mallocCUDADevice(sizeof(cuComplex) * d_data.Np * d_data.Nfft); -// CUDAIFFT(d_data.phdata, d_ifftphdata, d_data.Np, d_data.Nfft, d_data.Nfft); -// FFTShift1D(d_ifftphdata, d_data.Np, d_data.Nfft); -// DeviceToHost(h_ifftphdata, d_ifftphdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); -// std::shared_ptr> ifftdata(new std::complex[d_data.Np * d_data.Nfft], delArrPtr); -// { -// for (long i = 0; i < d_data.Np; i++) { -// for (long j = 0; j < d_data.Nfft; j++) { -// ifftdata.get()[i * d_data.Nfft + j] = -// std::complex( -// h_ifftphdata[i * d_data.Nfft + j].x, -// h_ifftphdata[i * d_data.Nfft + j].y); -// } -// } -// } -// testOutComplexDoubleArr(QString("echo_ifft_single.bin"), ifftdata.get(), d_data.Np, d_data.Nfft); -// -// FreeCUDADevice(d_ifftphdata); -// FreeCUDAHost(h_ifftphdata); -// -// } -// /** 9. **************************************************************************************************/ -// -// // maxWrҪȼdeltaF -// double deltaF = h_data.deltaF; // ȡ -// double maxWr = 299792458.0f / (2.0f * deltaF); -// qDebug() << "maxWr :\t" << maxWr; -// float* r_vec_host = (float*)mallocCUDAHost(sizeof(float) * h_data.Nfft);// new double[data.Nfft]; -// const double step = maxWr / h_data.Nfft; -// const double start = -1 * h_data.Nfft / 2.0f * step; -// printf("nfft=%d\n", h_data.Nfft); -// -// for (int i = 0; i < h_data.Nfft; ++i) { -// r_vec_host[i] = start + i * step; -// } -// -// h_data.r_vec = r_vec_host; -// d_data.r_vec = h_data.r_vec; -// -// qDebug() << "r_vec [0]:\t" << h_data.r_vec[0]; -// qDebug() << "r_vec step:\t" << step; -// -// bpBasic0CUDA_single(d_data, 0); -// -// DeviceToHost(h_data.im_final, d_data.im_final, sizeof(cuComplex) * d_data.nx * d_data.ny); -// { -// DeviceToHost(h_data.phdata, d_data.phdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); -// std::shared_ptr> ifftdata(new std::complex[d_data.Np * d_data.Nfft], delArrPtr); -// { -// for (long i = 0; i < d_data.Np; i++) { -// for (long j = 0; j < d_data.Nfft; j++) { -// ifftdata.get()[i * d_data.Nfft + j] = -// std::complex( -// h_data.phdata[i * d_data.Nfft + j].x, -// h_data.phdata[i * d_data.Nfft + j].y); -// } -// } -// } -// testOutComplexDoubleArr(QString("echo_ifft_BPBasic_single.bin"), ifftdata.get(), d_data.Np, d_data.Nfft); -// -// std::shared_ptr> im_finals(new std::complex[d_data.nx * d_data.ny], delArrPtr); -// { -// for (long i = 0; i < d_data.ny; i++) { -// for (long j = 0; j < d_data.nx; j++) { -// im_finals.get()[i * d_data.nx + j] = std::complex( -// h_data.im_final[i * d_data.nx + j].x, -// h_data.im_final[i * d_data.nx + j].y); -// } -// } -// } -// testOutComplexDoubleArr(QString("im_finals_single.bin"), im_finals.get(), d_data.ny, d_data.nx); -// } -// -// -// -//} -// + + +void testSimualtionEchoPoint_single() { + GPUDATA_single h_data{}; + /** 1. **************************************************************************************************/ + qDebug() << u8"1.ļȡС"; + QString inGPSPath = u8"C:\\Users\\30453\\Desktop\\script\\data\\GF3_Simulation.gpspos.data"; + long gpspoints = gdalImage(inGPSPath).height; + std::shared_ptr antpos = SatelliteAntPosOperator::readAntPosFile(inGPSPath, gpspoints); + h_data.AntX = (float*)mallocCUDAHost(sizeof(float) * gpspoints); + h_data.AntY = (float*)mallocCUDAHost(sizeof(float) * gpspoints); + h_data.AntZ = (float*)mallocCUDAHost(sizeof(float) * gpspoints); + + for (long i = 0; i < gpspoints; i = i + 1) { + h_data.AntX[i] = antpos.get()[i].Px; + h_data.AntY[i] = antpos.get()[i].Py; + h_data.AntZ[i] = antpos.get()[i].Pz; + } + //gpspoints = gpspoints / 2; + qDebug() << "GPS points Count:\t" << gpspoints; + qDebug() << "PRF 0:\t " << QString("%1,%2,%3").arg(h_data.AntX[0]).arg(h_data.AntY[0]).arg(h_data.AntZ[0]); + qDebug() << "PRF " << gpspoints - 1 << ":\t " << QString("%1,%2,%3") + .arg(h_data.AntX[gpspoints - 1]) + .arg(h_data.AntY[gpspoints - 1]) + .arg(h_data.AntZ[gpspoints - 1]); + /** 2. **************************************************************************************************/ + qDebug() << u8"ļȡ\n2.ȡ"; + QString demxyzPath = u8"C:\\Users\\30453\\Desktop\\script\\޸GF3\\data\\demxyz.bin"; + gdalImage demgridimg(demxyzPath); + long dem_rowCount = demgridimg.height; + long dem_ColCount = demgridimg.width; + std::shared_ptr demX = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demY = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demZ = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + h_data.x_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); + h_data.y_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); + h_data.z_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); + + for (long i = 0; i < dem_rowCount; i++) { + for (long j = 0; j < dem_ColCount; j++) { + h_data.x_mat[i * dem_ColCount + j] = demX.get()[i * dem_ColCount + j]; + h_data.y_mat[i * dem_ColCount + j] = demY.get()[i * dem_ColCount + j]; + h_data.z_mat[i * dem_ColCount + j] = demZ.get()[i * dem_ColCount + j]; + } + } + qDebug() << "dem row Count:\t" << dem_rowCount; + qDebug() << "dem col Count:\t" << dem_ColCount; + + qDebug() << u8"ȡ"; + /** 3. Ƶ **************************************************************************************************/ + qDebug() << u8"3.Ƶ"; + float centerFreq = 5.3e9; + float bandwidth = 40e6; + long freqpoints = 2048; + std::shared_ptr freqlist(getFreqPoints_mallocHost_single(centerFreq - bandwidth / 2, centerFreq + bandwidth / 2, freqpoints), FreeCUDAHost); + std::shared_ptr minF(new float[gpspoints], delArrPtr); + for (long i = 0; i < gpspoints; i++) { + minF.get()[i] = freqlist.get()[0]; + } + h_data.deltaF = bandwidth / (freqpoints - 1); + 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()[1] - freqlist.get()[0]; + qDebug() << u8"Ƶʽ"; + /** 4. ʼز **************************************************************************************************/ + qDebug() << u8"4.ʼز"; + std::shared_ptr phdata(createEchoPhase_mallocHost(gpspoints, freqpoints), FreeCUDAHost); + qDebug() << "Azimuth Points:\t" << gpspoints; + qDebug() << "Range Points:\t" << freqpoints; + qDebug() << u8"ʼز"; + /** 5. ʼͼ **************************************************************************************************/ + qDebug() << u8"5.ʼͼ"; + h_data.im_final = (cuComplex*)mallocCUDAHost(sizeof(cuComplex) * dem_rowCount * dem_ColCount); + qDebug() << "Azimuth Points:\t" << gpspoints; + qDebug() << "Range Points:\t" << freqpoints; + qDebug() << u8"ʼͼ"; + + /** 6. ģͲʼ **************************************************************************************************/ + qDebug() << u8"6.ģͲʼ"; + + h_data.nx = dem_ColCount; + h_data.ny = dem_rowCount; + + h_data.Np = gpspoints; + h_data.Freq = freqlist.get(); + h_data.minF = minF.get(); + h_data.Nfft = freqpoints; + h_data.K = h_data.Nfft; + h_data.phdata = phdata.get(); + h_data.R0 = 900000; + qDebug() << u8"ģͲ"; + + + /** 7. Ŀ **************************************************************************************************/ + float Tx = -2029086.618142, Ty = 4139594.934504, Tz = 4392846.782027; + float Tslx = -2029086.618142, Tsly = 4139594.934504, Tslz = 4392846.782027; + float p1 = 1, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0; + + /** 7. ز **************************************************************************************************/ + GPUDATA_single d_data; + initGPUData_single(h_data, d_data); + + RFPCProcess_single(Tx, Ty, Tz, + Tslx, Tsly, Tslz, // Ŀ + p1, p2, p3, p4, p5, p6, + d_data); + + + /** 8. չʾز **************************************************************************************************/ + { + DeviceToHost(h_data.phdata, d_data.phdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); + cuComplex* h_ifftphdata = (cuComplex*)mallocCUDAHost(sizeof(cuComplex) * d_data.Np * d_data.Nfft); + cuComplex* d_ifftphdata = (cuComplex*)mallocCUDADevice(sizeof(cuComplex) * d_data.Np * d_data.Nfft); + CUDAIFFT(d_data.phdata, d_ifftphdata, d_data.Np, d_data.Nfft, d_data.Nfft); + FFTShift1D(d_ifftphdata, d_data.Np, d_data.Nfft); + DeviceToHost(h_ifftphdata, d_ifftphdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); + std::shared_ptr> ifftdata(new std::complex[d_data.Np * d_data.Nfft], delArrPtr); + { + for (long i = 0; i < d_data.Np; i++) { + for (long j = 0; j < d_data.Nfft; j++) { + ifftdata.get()[i * d_data.Nfft + j] = + std::complex( + h_ifftphdata[i * d_data.Nfft + j].x, + h_ifftphdata[i * d_data.Nfft + j].y); + } + } + } + testOutComplexDoubleArr(QString("echo_ifft_single.bin"), ifftdata.get(), d_data.Np, d_data.Nfft); + + FreeCUDADevice(d_ifftphdata); + FreeCUDAHost(h_ifftphdata); + + } + /** 9. **************************************************************************************************/ + + // maxWrҪȼdeltaF + float deltaF = h_data.deltaF; // ȡ + float maxWr = 299792458.0f / (2.0f * deltaF); + qDebug() << "maxWr :\t" << maxWr; + float* r_vec_host = (float*)mallocCUDAHost(sizeof(float) * h_data.Nfft);// new float[data.Nfft]; + const float step = maxWr / h_data.Nfft; + const float start = -1 * h_data.Nfft / 2.0f * step; + printf("nfft=%d\n", h_data.Nfft); + + for (int i = 0; i < h_data.Nfft; ++i) { + r_vec_host[i] = start + i * step; + } + + h_data.r_vec = r_vec_host; + d_data.r_vec = h_data.r_vec; + + qDebug() << "r_vec [0]:\t" << h_data.r_vec[0]; + qDebug() << "r_vec step:\t" << step; + + bpBasic0CUDA_single(d_data, 0); + + DeviceToHost(h_data.im_final, d_data.im_final, sizeof(cuComplex) * d_data.nx * d_data.ny); + + { + DeviceToHost(h_data.phdata, d_data.phdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); + std::shared_ptr> ifftdata(new std::complex[d_data.Np * d_data.Nfft], delArrPtr); + { + for (long i = 0; i < d_data.Np; i++) { + for (long j = 0; j < d_data.Nfft; j++) { + ifftdata.get()[i * d_data.Nfft + j] = + std::complex( + h_data.phdata[i * d_data.Nfft + j].x, + h_data.phdata[i * d_data.Nfft + j].y); + } + } + } + testOutComplexDoubleArr(QString("echo_ifft_BPBasic_single.bin"), ifftdata.get(), d_data.Np, d_data.Nfft); -// -//int main(int argc, char* argv[]) { -// -// QApplication a(argc, argv); -// -// return 0; -//} -// -// + std::shared_ptr> im_finals(new std::complex[d_data.nx * d_data.ny], delArrPtr); + { + for (long i = 0; i < d_data.ny; i++) { + for (long j = 0; j < d_data.nx; j++) { + im_finals.get()[i * d_data.nx + j] = std::complex( + h_data.im_final[i * d_data.nx + j].x, + h_data.im_final[i * d_data.nx + j].y); + } + } + } + testOutComplexDoubleArr(QString("im_finals_single.bin"), im_finals.get(), d_data.ny, d_data.nx); + } +} + + +void testBpImage_single() { + + GPUDATA_single h_data{}; + /** 0. **************************************************************************************************/ + QString echoPath = "D:\\Programme\\vs2022\\RasterMergeTest\\LAMPCAE_SCANE-all-scane\\GF3_Simulation.xml"; + std::shared_ptr echoL0ds(new EchoL0Dataset); + echoL0ds->Open(echoPath); + qDebug() << u8"ػزļ\t" << echoPath; + + /** 1. **************************************************************************************************/ + qDebug() << u8"1.ļȡС"; + QString inGPSPath = echoL0ds->getGPSPointFilePath(); + long gpspoints = gdalImage(inGPSPath).height; + std::shared_ptr antpos = SatelliteAntPosOperator::readAntPosFile(inGPSPath, gpspoints); + h_data.AntX = (float*)mallocCUDAHost(sizeof(float) * gpspoints); + h_data.AntY = (float*)mallocCUDAHost(sizeof(float) * gpspoints); + h_data.AntZ = (float*)mallocCUDAHost(sizeof(float) * gpspoints); + + for (long i = 0; i < gpspoints; i = i + 1) { + h_data.AntX[i] = antpos.get()[i].Px; + h_data.AntY[i] = antpos.get()[i].Py; + h_data.AntZ[i] = antpos.get()[i].Pz; + } + //gpspoints = gpspoints / 2; + qDebug() << "GPS points Count:\t" << gpspoints; + qDebug() << "PRF 0:\t " << QString("%1,%2,%3").arg(h_data.AntX[0]).arg(h_data.AntY[0]).arg(h_data.AntZ[0]); + qDebug() << "PRF " << gpspoints - 1 << ":\t " << QString("%1,%2,%3") + .arg(h_data.AntX[gpspoints - 1]) + .arg(h_data.AntY[gpspoints - 1]) + .arg(h_data.AntZ[gpspoints - 1]); + /** 2. **************************************************************************************************/ + qDebug() << u8"ļȡ\n2.ȡ"; + QString demxyzPath = u8"D:\\Programme\\vs2022\\RasterMergeTest\\simulationData\\demdataset\\demxyz.bin"; + gdalImage demgridimg(demxyzPath); + long dem_rowCount = demgridimg.height; + long dem_ColCount = demgridimg.width; + std::shared_ptr demX = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demY = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demZ = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + h_data.x_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); + h_data.y_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); + h_data.z_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); + + for (long i = 0; i < dem_rowCount; i++) { + for (long j = 0; j < dem_ColCount; j++) { + h_data.x_mat[i * dem_ColCount + j] = demX.get()[i * dem_ColCount + j]; + h_data.y_mat[i * dem_ColCount + j] = demY.get()[i * dem_ColCount + j]; + h_data.z_mat[i * dem_ColCount + j] = demZ.get()[i * dem_ColCount + j]; + } + } + qDebug() << "dem row Count:\t" << dem_rowCount; + qDebug() << "dem col Count:\t" << dem_ColCount; + + qDebug() << u8"ȡ"; + /** 3. Ƶ **************************************************************************************************/ + qDebug() << u8"3.Ƶ"; + float centerFreq = echoL0ds->getCenterFreq(); + float bandwidth = echoL0ds->getBandwidth(); + size_t freqpoints = echoL0ds->getPlusePoints(); + std::shared_ptr freqlist(getFreqPoints_mallocHost_single(centerFreq - bandwidth / 2, centerFreq + bandwidth / 2, freqpoints), FreeCUDAHost); + std::shared_ptr minF(new float[gpspoints], delArrPtr); + for (long i = 0; i < gpspoints; i++) { + minF.get()[i] = freqlist.get()[0]; + } + h_data.deltaF = bandwidth / (freqpoints - 1); + 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()[1] - freqlist.get()[0]; + qDebug() << u8"Ƶʽ"; + /** 4. ʼز **************************************************************************************************/ + qDebug() << u8"4.ʼز"; + std::shared_ptr> echoData = echoL0ds->getEchoArr(); + size_t echosize = sizeof(cuComplex) * gpspoints * freqpoints; + qDebug() << "echo data size (byte) :\t" << echosize; + h_data.phdata = (cuComplex*)mallocCUDAHost(echosize); + shared_complexPtrToHostCuComplex(echoData.get(), h_data.phdata, gpspoints * freqpoints); + + qDebug() << "Azimuth Points:\t" << gpspoints; + qDebug() << "Range Points:\t" << freqpoints; + qDebug() << u8"ʼز"; + /** 5. ʼͼ **************************************************************************************************/ + qDebug() << u8"5.ʼͼ"; + h_data.im_final = (cuComplex*)mallocCUDAHost(sizeof(cuComplex) * dem_rowCount * dem_ColCount); + qDebug() << "Azimuth Points:\t" << gpspoints; + qDebug() << "Range Points:\t" << freqpoints; + qDebug() << u8"ʼͼ"; + + /** 6. ģͲʼ **************************************************************************************************/ + qDebug() << u8"6.ģͲʼ"; + + h_data.nx = dem_ColCount; + h_data.ny = dem_rowCount; + + h_data.Np = gpspoints; + h_data.Freq = freqlist.get(); + h_data.minF = minF.get(); + h_data.Nfft = freqpoints; + h_data.K = h_data.Nfft; + + h_data.R0 = echoL0ds->getRefPhaseRange(); + qDebug() << u8"ģͲ"; + + + /** 7. Ŀ **************************************************************************************************/ + double Tx = -2029086.618142, Ty = 4139594.934504, Tz = 4392846.782027; + double Tslx = -2029086.618142, Tsly = 4139594.934504, Tslz = 4392846.782027; + double p1 = 33.3, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0; + + /** 7. ز **************************************************************************************************/ + GPUDATA_single d_data; + initGPUData_single(h_data, d_data); + + /** 8. չʾز **************************************************************************************************/ + { + DeviceToHost(h_data.phdata, d_data.phdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); + cuComplex* h_ifftphdata = (cuComplex*)mallocCUDAHost(sizeof(cuComplex) * d_data.Np * d_data.Nfft); + cuComplex* d_ifftphdata = (cuComplex*)mallocCUDADevice(sizeof(cuComplex) * d_data.Np * d_data.Nfft); + CUDAIFFT(d_data.phdata, d_ifftphdata, d_data.Np, d_data.Nfft, d_data.Nfft); + FFTShift1D(d_ifftphdata, d_data.Np, d_data.Nfft); + DeviceToHost(h_ifftphdata, d_ifftphdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); + std::shared_ptr> ifftdata(new std::complex[d_data.Np * d_data.Nfft], delArrPtr); + { + for (long i = 0; i < d_data.Np; i++) { + for (long j = 0; j < d_data.Nfft; j++) { + ifftdata.get()[i * d_data.Nfft + j] = + std::complex( + h_ifftphdata[i * d_data.Nfft + j].x, + h_ifftphdata[i * d_data.Nfft + j].y); + } + } + } + testOutComplexDoubleArr(QString("echo_ifft_single.bin"), ifftdata.get(), d_data.Np, d_data.Nfft); + + FreeCUDADevice(d_ifftphdata); + FreeCUDAHost(h_ifftphdata); + + } + /** 9. **************************************************************************************************/ + + // maxWrҪȼdeltaF + double deltaF = h_data.deltaF; // ȡ + double maxWr = 299792458.0f / (2.0f * deltaF); + qDebug() << "maxWr :\t" << maxWr; + float* r_vec_host = (float*)mallocCUDAHost(sizeof(float) * h_data.Nfft);// new double[data.Nfft]; + const double step = maxWr / h_data.Nfft; + const double start = -1 * h_data.Nfft / 2.0f * step; + printf("nfft=%d\n", h_data.Nfft); + + for (int i = 0; i < h_data.Nfft; ++i) { + r_vec_host[i] = start + i * step; + } + + h_data.r_vec = r_vec_host; + d_data.r_vec = h_data.r_vec; + + qDebug() << "r_vec [0]:\t" << h_data.r_vec[0]; + qDebug() << "r_vec step:\t" << step; + + bpBasic0CUDA_single(d_data, 0); + + DeviceToHost(h_data.im_final, d_data.im_final, sizeof(cuComplex) * d_data.nx * d_data.ny); + { + DeviceToHost(h_data.phdata, d_data.phdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); + std::shared_ptr> ifftdata(new std::complex[d_data.Np * d_data.Nfft], delArrPtr); + { + for (long i = 0; i < d_data.Np; i++) { + for (long j = 0; j < d_data.Nfft; j++) { + ifftdata.get()[i * d_data.Nfft + j] = + std::complex( + h_data.phdata[i * d_data.Nfft + j].x, + h_data.phdata[i * d_data.Nfft + j].y); + } + } + } + testOutComplexDoubleArr(QString("echo_ifft_BPBasic_single.bin"), ifftdata.get(), d_data.Np, d_data.Nfft); + + std::shared_ptr> im_finals(new std::complex[d_data.nx * d_data.ny], delArrPtr); + { + for (long i = 0; i < d_data.ny; i++) { + for (long j = 0; j < d_data.nx; j++) { + im_finals.get()[i * d_data.nx + j] = std::complex( + h_data.im_final[i * d_data.nx + j].x, + h_data.im_final[i * d_data.nx + j].y); + } + } + } + testOutComplexDoubleArr(QString("im_finals_single.bin"), im_finals.get(), d_data.ny, d_data.nx); + } +} + + + +void testSimualtionEchoPoint_singleRFPC_doubleImage() { + GPUDATA_single h_data{}; + /** 1. **************************************************************************************************/ + qDebug() << u8"1.ļȡС"; + QString inGPSPath = u8"C:\\Users\\30453\\Desktop\\script\\data\\GF3_Simulation.gpspos.data"; + long gpspoints = gdalImage(inGPSPath).height; + std::shared_ptr antpos = SatelliteAntPosOperator::readAntPosFile(inGPSPath, gpspoints); + h_data.AntX = (float*)mallocCUDAHost(sizeof(float) * gpspoints); + h_data.AntY = (float*)mallocCUDAHost(sizeof(float) * gpspoints); + h_data.AntZ = (float*)mallocCUDAHost(sizeof(float) * gpspoints); + + for (long i = 0; i < gpspoints; i = i + 1) { + h_data.AntX[i] = antpos.get()[i].Px; + h_data.AntY[i] = antpos.get()[i].Py; + h_data.AntZ[i] = antpos.get()[i].Pz; + } + //gpspoints = gpspoints / 2; + qDebug() << "GPS points Count:\t" << gpspoints; + qDebug() << "PRF 0:\t " << QString("%1,%2,%3").arg(h_data.AntX[0]).arg(h_data.AntY[0]).arg(h_data.AntZ[0]); + qDebug() << "PRF " << gpspoints - 1 << ":\t " << QString("%1,%2,%3") + .arg(h_data.AntX[gpspoints - 1]) + .arg(h_data.AntY[gpspoints - 1]) + .arg(h_data.AntZ[gpspoints - 1]); + /** 2. **************************************************************************************************/ + qDebug() << u8"ļȡ\n2.ȡ"; + QString demxyzPath = u8"C:\\Users\\30453\\Desktop\\script\\޸GF3\\data\\demxyz.bin"; + gdalImage demgridimg(demxyzPath); + long dem_rowCount = demgridimg.height; + long dem_ColCount = demgridimg.width; + std::shared_ptr demX = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demY = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demZ = readDataArr(demgridimg, 0, 0, dem_rowCount, dem_ColCount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + h_data.x_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); + h_data.y_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); + h_data.z_mat = (float*)mallocCUDAHost(sizeof(float) * dem_rowCount * dem_ColCount); + + for (long i = 0; i < dem_rowCount; i++) { + for (long j = 0; j < dem_ColCount; j++) { + h_data.x_mat[i * dem_ColCount + j] = demX.get()[i * dem_ColCount + j]; + h_data.y_mat[i * dem_ColCount + j] = demY.get()[i * dem_ColCount + j]; + h_data.z_mat[i * dem_ColCount + j] = demZ.get()[i * dem_ColCount + j]; + } + } + qDebug() << "dem row Count:\t" << dem_rowCount; + qDebug() << "dem col Count:\t" << dem_ColCount; + + qDebug() << u8"ȡ"; + /** 3. Ƶ **************************************************************************************************/ + qDebug() << u8"3.Ƶ"; + float centerFreq = 5.3e9; + float bandwidth = 40e6; + long freqpoints = 2048; + std::shared_ptr freqlist(getFreqPoints_mallocHost_single(centerFreq - bandwidth / 2, centerFreq + bandwidth / 2, freqpoints), FreeCUDAHost); + std::shared_ptr minF(new float[gpspoints], delArrPtr); + for (long i = 0; i < gpspoints; i++) { + minF.get()[i] = freqlist.get()[0]; + } + h_data.deltaF = bandwidth / (freqpoints - 1); + 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()[1] - freqlist.get()[0]; + qDebug() << u8"Ƶʽ"; + /** 4. ʼز **************************************************************************************************/ + qDebug() << u8"4.ʼز"; + std::shared_ptr phdata(createEchoPhase_mallocHost(gpspoints, freqpoints), FreeCUDAHost); + qDebug() << "Azimuth Points:\t" << gpspoints; + qDebug() << "Range Points:\t" << freqpoints; + qDebug() << u8"ʼز"; + /** 5. ʼͼ **************************************************************************************************/ + qDebug() << u8"5.ʼͼ"; + h_data.im_final = (cuComplex*)mallocCUDAHost(sizeof(cuComplex) * dem_rowCount * dem_ColCount); + qDebug() << "Azimuth Points:\t" << gpspoints; + qDebug() << "Range Points:\t" << freqpoints; + qDebug() << u8"ʼͼ"; + + /** 6. ģͲʼ **************************************************************************************************/ + qDebug() << u8"6.ģͲʼ"; + + h_data.nx = dem_ColCount; + h_data.ny = dem_rowCount; + + h_data.Np = gpspoints; + h_data.Freq = freqlist.get(); + h_data.minF = minF.get(); + h_data.Nfft = freqpoints; + h_data.K = h_data.Nfft; + h_data.phdata = phdata.get(); + h_data.R0 = 900000; + qDebug() << u8"ģͲ"; + + + /** 7. Ŀ **************************************************************************************************/ + + + float p1 = 1, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0; + + /** 7. ز **************************************************************************************************/ + GPUDATA_single d_data; + initGPUData_single(h_data, d_data); + long targetStep = dem_rowCount * dem_ColCount/100; + for (long i = 0; i < dem_rowCount*dem_ColCount; i=i+ targetStep) { + float Tx = h_data.x_mat[i], + Ty = h_data.y_mat[i], + Tz = h_data.z_mat[i]; + float Tslx = h_data.x_mat[i], Tsly = h_data.y_mat[i], Tslz = h_data.z_mat[i]; + + RFPCProcess_single(Tx, Ty, Tz, + Tslx, Tsly, Tslz, // Ŀ + p1, p2, p3, p4, p5, p6, + d_data); + } + + /** 8. չʾز **************************************************************************************************/ + { + DeviceToHost(h_data.phdata, d_data.phdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); + cuComplex* h_ifftphdata = (cuComplex*)mallocCUDAHost(sizeof(cuComplex) * d_data.Np * d_data.Nfft); + cuComplex* d_ifftphdata = (cuComplex*)mallocCUDADevice(sizeof(cuComplex) * d_data.Np * d_data.Nfft); + CUDAIFFT(d_data.phdata, d_ifftphdata, d_data.Np, d_data.Nfft, d_data.Nfft); + FFTShift1D(d_ifftphdata, d_data.Np, d_data.Nfft); + DeviceToHost(h_ifftphdata, d_ifftphdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); + std::shared_ptr> ifftdata(new std::complex[d_data.Np * d_data.Nfft], delArrPtr); + { + for (long i = 0; i < d_data.Np; i++) { + for (long j = 0; j < d_data.Nfft; j++) { + ifftdata.get()[i * d_data.Nfft + j] = + std::complex( + h_ifftphdata[i * d_data.Nfft + j].x, + h_ifftphdata[i * d_data.Nfft + j].y); + } + } + } + testOutComplexDoubleArr(QString("echo_ifft_single.bin"), ifftdata.get(), d_data.Np, d_data.Nfft); + + FreeCUDADevice(d_ifftphdata); + FreeCUDAHost(h_ifftphdata); + + } + /** 9. **************************************************************************************************/ + + // maxWrҪȼdeltaF + float deltaF = h_data.deltaF; // ȡ + float maxWr = 299792458.0f / (2.0f * deltaF); + qDebug() << "maxWr :\t" << maxWr; + float* r_vec_host = (float*)mallocCUDAHost(sizeof(float) * h_data.Nfft);// new float[data.Nfft]; + const float step = maxWr / h_data.Nfft; + const float start = -1 * h_data.Nfft / 2.0f * step; + printf("nfft=%d\n", h_data.Nfft); + + for (int i = 0; i < h_data.Nfft; ++i) { + r_vec_host[i] = start + i * step; + } + + h_data.r_vec = r_vec_host; + d_data.r_vec = h_data.r_vec; + + qDebug() << "r_vec [0]:\t" << h_data.r_vec[0]; + qDebug() << "r_vec step:\t" << step; + + + // double ͳ + GPUDATA g_data{}; + + + copy_Host_Single_GPUData(h_data, g_data); + bpBasic0CUDA(g_data, 0); + + DeviceToHost(h_data.im_final, g_data.im_final, sizeof(cuComplex) * d_data.nx * d_data.ny); + + { + DeviceToHost(h_data.phdata, g_data.phdata, sizeof(cuComplex) * d_data.Np * d_data.Nfft); + std::shared_ptr> ifftdata(new std::complex[d_data.Np * d_data.Nfft], delArrPtr); + { + for (long i = 0; i < d_data.Np; i++) { + for (long j = 0; j < d_data.Nfft; j++) { + ifftdata.get()[i * d_data.Nfft + j] = + std::complex( + h_data.phdata[i * d_data.Nfft + j].x, + h_data.phdata[i * d_data.Nfft + j].y); + } + } + } + testOutComplexDoubleArr(QString("echo_ifft_BPBasic_double.bin"), ifftdata.get(), d_data.Np, d_data.Nfft); + + + + std::shared_ptr> im_finals(new std::complex[d_data.nx * d_data.ny], delArrPtr); + { + for (long i = 0; i < d_data.ny; i++) { + for (long j = 0; j < d_data.nx; j++) { + im_finals.get()[i * d_data.nx + j] = std::complex( + h_data.im_final[i * d_data.nx + j].x, + h_data.im_final[i * d_data.nx + j].y); + } + } + } + testOutComplexDoubleArr(QString("im_finals_double.bin"), im_finals.get(), d_data.ny, d_data.nx); + } +} + + +void test_double32() { + test_double_to_double32(); + test_function(0, "Addition"); + test_function(1, "Subtraction"); + test_function(2, "Multiplication"); + test_function(3, "Division"); + test_function(4, "Sine"); + test_function(5, "Cosine"); + test_function(6, "Log2"); + test_function(7, "Log10"); + test_function(8, "Natural Logarithm"); + test_function(9, "Exponential"); + test_function(10, "Power"); + test_function(11, "Square Root"); + + + + + + time_test_add(); + time_test_sub(); + time_test_mul(); + time_test_div(); + time_test_sin(); + time_test_cos(); + time_test_log2(); + time_test_log10(); + time_test_ln(); + time_test_exp(); + time_test_pow(); + time_test_sqrt(); +} + +/** ܲ************************************************************************/ + +int main(int argc, char* argv[]) { + + QApplication a(argc, argv); + + + + //testSimualtionEchoPoint(); + //testSimualtionEchoPoint_singleRFPC_doubleImage(); + return 0; +} + + From d72d2a366afd8d11f7321bd974276c30855da1fd Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Tue, 11 Mar 2025 12:59:13 +0800 Subject: [PATCH 04/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BA=BF=E6=80=A7?= =?UTF-8?q?=E5=80=BC=E8=BD=AC=E6=8D=A2=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QtLinearToIntenisityDialog.cpp | 10 + .../QtLinearToIntenisityDialog.h | 16 ++ .../QtLinearToIntenisityDialog.ui | 177 ++++++++++++++++++ .../SimulationSARTool.vcxproj | 3 + .../SimulationSARTool.vcxproj.filters | 9 + 5 files changed, 215 insertions(+) create mode 100644 Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.cpp create mode 100644 Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.h create mode 100644 Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.ui diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.cpp b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.cpp new file mode 100644 index 0000000..9455828 --- /dev/null +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.cpp @@ -0,0 +1,10 @@ +#include "QtLinearToIntenisityDialog.h" + +QtLinearToIntenisityDialog::QtLinearToIntenisityDialog(QWidget *parent) + : QDialog(parent) +{ + ui.setupUi(this); +} + +QtLinearToIntenisityDialog::~QtLinearToIntenisityDialog() +{} diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.h b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.h new file mode 100644 index 0000000..f0bbade --- /dev/null +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include "ui_QtLinearToIntenisityDialog.h" + +class QtLinearToIntenisityDialog : public QDialog +{ + Q_OBJECT + +public: + QtLinearToIntenisityDialog(QWidget *parent = nullptr); + ~QtLinearToIntenisityDialog(); + +private: + Ui::QtLinearToIntenisityDialogClass ui; +}; diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.ui b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.ui new file mode 100644 index 0000000..2a27ba6 --- /dev/null +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.ui @@ -0,0 +1,177 @@ + + + QtLinearToIntenisityDialogClass + + + + 0 + 0 + 1002 + 400 + + + + dB转线性值 + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 30 + + + + 输入影像(dB): + + + + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\LT1_Simulation_OrbitModel.xml + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 输出影像: + + + + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\LT1_Simulation_Setting.xml + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 30 + + + + 强度 + + + + + + + + 0 + 30 + + + + 振幅 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 24 + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index d538eab..66e4019 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -210,6 +210,7 @@ + @@ -230,6 +231,7 @@ + @@ -262,6 +264,7 @@ + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index 4820ec5..df35be2 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -118,6 +118,9 @@ Source Files + + PowerSimulationIncoherent + @@ -141,6 +144,9 @@ PowerSimulationIncoherent + + PowerSimulationIncoherent + @@ -167,6 +173,9 @@ PowerSimulationIncoherent + + PowerSimulationIncoherent + From 7e5d3909342d260cd10dbd0660329ad9912c6f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 11 Mar 2025 13:42:07 +0800 Subject: [PATCH 05/94] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=AE=8CdB=E8=BD=AC?= =?UTF-8?q?=E7=BA=BF=E6=80=A7=E5=80=BC=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QtLinearToIntenisityDialog.cpp | 120 +++++++++++++++++- .../QtLinearToIntenisityDialog.h | 19 ++- Toolbox/SimulationSARTool/UnitTestMain.cpp | 20 +-- 3 files changed, 143 insertions(+), 16 deletions(-) diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.cpp b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.cpp index 9455828..5a6fcb8 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.cpp +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.cpp @@ -1,10 +1,122 @@ +#include #include "QtLinearToIntenisityDialog.h" +#include +#include "ImageOperatorBase.h" +#include "ui_QtLinearToIntenisityDialog.h" -QtLinearToIntenisityDialog::QtLinearToIntenisityDialog(QWidget *parent) - : QDialog(parent) + +QtLinearToIntenisityDialog::QtLinearToIntenisityDialog(QWidget* parent) + : QDialog(parent), ui(new Ui::QtLinearToIntenisityDialogClass) { - ui.setupUi(this); + ui->setupUi(this); + + connect(ui->pushButtonInRaster, SIGNAL(clicked(bool)), this, SLOT(On_pushButtonInRasterTriggled())); + connect(ui->pushButtonSave, SIGNAL(clicked(bool)), this, SLOT(On_pushButtonSaveTriggled())); + connect(ui->radioButtonIntenisty, SIGNAL(clicked(bool)), this, SLOT(On_radioButtonIntenistyTriggled())); + connect(ui->radioButtonAmp, SIGNAL(clicked(bool)), this, SLOT(On_radioButtonAmpTriggled())); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbtnaccepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbtnrejected())); } QtLinearToIntenisityDialog::~QtLinearToIntenisityDialog() -{} +{ +} + +void QtLinearToIntenisityDialog::On_pushButtonInRasterTriggled() +{ + QString fileName = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡӰ"), // + QString(), // Ĭ· + tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)") // ļ + ); + + // ûѡļ + if (!fileName.isEmpty()) { + this->ui->InputRasterLineEdit->setText(fileName); + + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QtLinearToIntenisityDialog::On_pushButtonSaveTriggled() +{ + QString fileName = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡӰ"), // + QString(), // Ĭ· + tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)") // ļ + ); + + // ûѡļ + if (!fileName.isEmpty()) { + this->ui->OutputRasterLineEdit->setText(fileName); + + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QtLinearToIntenisityDialog::On_radioButtonIntenistyTriggled() +{ + +} + +void QtLinearToIntenisityDialog::On_radioButtonAmpTriggled() +{ + +} + +void QtLinearToIntenisityDialog::onbtnaccepted() +{ + this->hide(); + QString inputRaster = this->ui->InputRasterLineEdit->text(); + QString outputRaster = this->ui->OutputRasterLineEdit->text(); + // inputRaster outputRaster,ھ͸ + QFile::copy(inputRaster, outputRaster); + + + gdalImage img(outputRaster); + long rowblock = Memory1GB / img.width / 8 * 2; + ui->progressBar->setMaximum(img.height); + ui->progressBar->setValue(0); + for (long rid = 0; rid < img.height; rid = rid + rowblock) + { + for (long bid = 0; bid < img.band_num; bid++) + { + Eigen::MatrixXd data = img.getData(rid, 0, rowblock, img.width, bid); + + for (long i = 0; i < data.rows(); i++) + { + for (long j = 0; j < data.cols(); j++) + { + if (ui->radioButtonAmp->isChecked()) + { + data(i, j) = std::pow(10.0,data(i,j)/20.0); + } + else if (ui->radioButtonIntenisty->isChecked()) + { + data(i, j) = std::pow(10.0, data(i, j) / 10.0); + } + else + { + } + } + } + img.saveImage(data, rid, 0, bid); + } + ui->progressBar->setValue(rid); + + } + ui->progressBar->setValue(img.height); + + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"completed!!!")); +} + +void QtLinearToIntenisityDialog::onbtnrejected() +{ + this->close(); +} diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.h b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.h index f0bbade..67d2cd1 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.h +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.h @@ -1,7 +1,14 @@ #pragma once #include -#include "ui_QtLinearToIntenisityDialog.h" + + + +namespace Ui +{ + class QtLinearToIntenisityDialogClass; +} + class QtLinearToIntenisityDialog : public QDialog { @@ -11,6 +18,14 @@ public: QtLinearToIntenisityDialog(QWidget *parent = nullptr); ~QtLinearToIntenisityDialog(); +public slots: + + void On_pushButtonInRasterTriggled(); + void On_pushButtonSaveTriggled(); + void On_radioButtonIntenistyTriggled(); + void On_radioButtonAmpTriggled(); + void onbtnaccepted(); + void onbtnrejected(); private: - Ui::QtLinearToIntenisityDialogClass ui; + Ui::QtLinearToIntenisityDialogClass* ui; }; diff --git a/Toolbox/SimulationSARTool/UnitTestMain.cpp b/Toolbox/SimulationSARTool/UnitTestMain.cpp index 1d1c4e6..ce12182 100644 --- a/Toolbox/SimulationSARTool/UnitTestMain.cpp +++ b/Toolbox/SimulationSARTool/UnitTestMain.cpp @@ -1036,16 +1036,16 @@ void test_double32() { /** ܲ************************************************************************/ -int main(int argc, char* argv[]) { - - QApplication a(argc, argv); - - - - //testSimualtionEchoPoint(); - //testSimualtionEchoPoint_singleRFPC_doubleImage(); - return 0; -} +//int main(int argc, char* argv[]) { +// +// QApplication a(argc, argv); +// +// +// +// //testSimualtionEchoPoint(); +// //testSimualtionEchoPoint_singleRFPC_doubleImage(); +// return 0; +//} From 8ef3831d65ceba44d85acbf69b390566bf828e3f Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Tue, 11 Mar 2025 13:43:00 +0800 Subject: [PATCH 06/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0dB=E5=88=B0=E7=BA=BF?= =?UTF-8?q?=E6=80=A7=E5=80=BC=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSARTool/SimulationSARTool.cpp | 18 ++++++++++++++++++ Toolbox/SimulationSARTool/SimulationSARTool.h | 12 ++++++++++++ .../SimulationSARTool.vcxproj | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index b83e2cc..0c98dc8 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -5,6 +5,7 @@ #include "QSimulationSARPolynomialOrbitModel.h" #include "QSimulationLookTableDialog.h" #include "QCreateSARIntensityByLookTableDialog.h" +#include "QtLinearToIntenisityDialog.h" SARSimlulationRFPCToolButton::SARSimlulationRFPCToolButton(QWidget* parent) { @@ -73,6 +74,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QSimulationSAROrbitModelToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new LookTableComputerClassToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QCreateSARIntensityByLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QQtLinearToIntenisityToolButton(toolbox)); @@ -111,3 +113,19 @@ void QCreateSARIntensityByLookTableToolButton::excute() QCreateSARIntensityByLookTableDialog* dialog = new QCreateSARIntensityByLookTableDialog; dialog->show(); } + +QQtLinearToIntenisityToolButton::QQtLinearToIntenisityToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8""); + this->toolname = QString(u8"dBת"); +} + +QQtLinearToIntenisityToolButton::~QQtLinearToIntenisityToolButton() +{ +} +void QQtLinearToIntenisityToolButton::excute() +{ + QtLinearToIntenisityDialog* dialog = new QtLinearToIntenisityDialog; + dialog->show(); +} diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.h b/Toolbox/SimulationSARTool/SimulationSARTool.h index 5105552..8b21275 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.h +++ b/Toolbox/SimulationSARTool/SimulationSARTool.h @@ -71,6 +71,18 @@ public slots: }; +class SIMULATIONSARTOOL_EXPORT QQtLinearToIntenisityToolButton : public QToolAbstract { + Q_OBJECT +public: + QQtLinearToIntenisityToolButton(QWidget* parent = nullptr); + ~QQtLinearToIntenisityToolButton(); +public slots: + + virtual void excute() override; + +}; + + extern "C" SIMULATIONSARTOOL_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 66e4019..a13b73b 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -41,7 +41,7 @@ Unicode - Application + DynamicLibrary v143 false true From f0b0156af30366af777d828b281e3c76cba672fb Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Wed, 12 Mar 2025 10:23:09 +0800 Subject: [PATCH 07/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/ImageOperatorBase.cpp | 132 ++++++-------- .../BaseTool/ImageOperatorBase.h | 8 +- LAMPDataProcess.sln | 14 ++ LAMPDataProcessEXE/LAMPDataProcessEXE.vcxproj | 3 + SPG4Tool/SPG4Function.h | 4 +- SPG4Tool/SPG4Tool.vcxproj | 3 +- SPG4Tool/SPG4Tool_global.h | 17 ++ .../BaseToolbox/QComplex2AmpPhase.cpp | 10 +- .../BaseToolbox/QComplex2AmpPhase.h | 4 +- .../BaseToolbox/QDEMResampleDialog.cpp | 3 + .../BaseToolbox/QImportGF3StripL1ADataset.cpp | 9 +- .../BaseToolbox/QImportGF3StripL1ADataset.h | 4 +- .../BaseToolbox/QOrthSlrRaster.cpp | 7 +- .../BaseToolbox/BaseToolbox/QOrthSlrRaster.h | 4 +- .../BaseToolbox/QRDOrthProcessClass.cpp | 7 +- .../BaseToolbox/QRDOrthProcessClass.h | 4 +- .../QtLinearToIntenisityDialog.cpp | 2 +- .../pluginToolboxLibrary.vcxproj | 161 ++++++++++++++++++ .../pluginToolboxLibrary.vcxproj.filters | 17 ++ 19 files changed, 305 insertions(+), 108 deletions(-) create mode 100644 SPG4Tool/SPG4Tool_global.h create mode 100644 pluginToolboxLibrary/pluginToolboxLibrary.vcxproj create mode 100644 pluginToolboxLibrary/pluginToolboxLibrary.vcxproj.filters diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp index 4ffc877..ae25053 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp @@ -1675,6 +1675,38 @@ gdalImage BASECONSTVARIABLEAPI CreategdalImageDouble(QString& img_path, int heig } +gdalImage BASECONSTVARIABLEAPI CreategdalImageFloat(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_Float32, 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())) { @@ -4149,93 +4181,37 @@ void CreateSARIntensityByLookTable(QString IntensityRasterPath, std::function processBarShow ) { - GDALAllRegister(); - constexpr size_t GB4 = size_t(1) * 1024 * 1024 * 1024; // 4GB in bytes - - // 打开输入数据集 - GDALDataset* lookDS = (GDALDataset*)GDALOpen(LookTableRasterPath.toStdString().c_str(), GA_ReadOnly); - GDALDataset* intensityDS = (GDALDataset*)GDALOpen(IntensityRasterPath.toStdString().c_str(), GA_ReadOnly); - - // 验证数据集有效性 - if (!lookDS || !intensityDS || - lookDS->GetRasterXSize() != intensityDS->GetRasterXSize() || - lookDS->GetRasterYSize() != intensityDS->GetRasterYSize()) - { - if (lookDS) GDALClose(lookDS); - if (intensityDS) GDALClose(intensityDS); - return; - } - - // 获取栅格参数 - const int width = lookDS->GetRasterXSize(); - const int height = lookDS->GetRasterYSize(); - const int rows_sar = max_rid - min_rid + 1; - const int cols_sar = max_cid - min_cid + 1; - - // 计算分块策略 - const size_t pixelBytes = - GDALGetDataTypeSizeBytes(lookDS->GetRasterBand(1)->GetRasterDataType()) * 2 + // 两个波段 - GDALGetDataTypeSizeBytes(intensityDS->GetRasterBand(1)->GetRasterDataType()); - - const size_t maxPixelsPerBlock = GB4 / pixelBytes; - int blockXSize = width; - int blockYSize = static_cast(maxPixelsPerBlock / width); - blockYSize = std::max(1, std::min(blockYSize, height)); - - // 输出矩阵初始化 - std::vector sarData(rows_sar * cols_sar, 0.0); + gdalImage looktableds(LookTableRasterPath); + gdalImage geoIntensity(IntensityRasterPath); + gdalImage SARIntensity= CreategdalImageDouble(SARIntensityPath,max_rid-min_rid,max_cid-min_cid,1); + long blockYSize = Memory1GB / looktableds.width / 8 * 2; + + Eigen::MatrixXd SARData = SARIntensity.getData(0, 0, SARIntensity.height, SARIntensity.width, 1); // 分块处理 - for (int yOff = 0; yOff < height; yOff += blockYSize) + for (int yOff = 0; yOff < looktableds.height; yOff += blockYSize) { - const int ySize = std::min(blockYSize, height - yOff); - - // 读取行号列号数据 - std::vector rData(width * ySize); - std::vector cData(width * ySize); - lookDS->GetRasterBand(1)->RasterIO(GF_Read, 0, yOff, width, ySize, - rData.data(), width, ySize, GDT_Int32, 0, 0); - lookDS->GetRasterBand(2)->RasterIO(GF_Read, 0, yOff, width, ySize, - cData.data(), width, ySize, GDT_Int32, 0, 0); + processBarShow(yOff, looktableds.height); + qDebug() << "Process : [" << yOff * 100.0 / looktableds.height << " % ]"; + Eigen::MatrixXd rowData = looktableds.getData(yOff, 0, blockYSize, looktableds.width, 1); + Eigen::MatrixXd colData = looktableds.getData(yOff, 0, blockYSize, looktableds.width, 2); + Eigen::MatrixXd geoData = geoIntensity.getData(yOff, 0, blockYSize, looktableds.width, 1); - // 读取强度数据 - std::vector intensity(width * ySize); - intensityDS->GetRasterBand(1)->RasterIO(GF_Read, 0, yOff, width, ySize, - intensity.data(), width, ySize, GDT_Float32, 0, 0); + for (long i = 0; i < rowData.rows(); i++) { + for (long j = 0; j < rowData.cols(); j++) { + const long r =round( rowData(i,j))-min_rid; + const long c = round(colData(i, j))-min_cid; - // 处理当前块 -#pragma omp parallel for collapse(2) - for (int y = 0; y < ySize; ++y) { - for (int x = 0; x < width; ++x) { - const int idx = y * width + x; - const long r = rData[idx]; - const long c = cData[idx]; - - if (r >= min_rid && r <= max_rid && c >= min_cid && c <= max_cid) { - const int row = r - min_rid; - const int col = c - min_cid; -#pragma omp atomic - sarData[row * cols_sar + col] += intensity[idx]; + if (r >= 0 && r < SARIntensity.height && c >= 0 && c <= SARIntensity.width) { + SARData(r, c) = SARData(r, c) + geoData(i, j); + } } } - if (processBarShow) { - processBarShow(yOff, height); - } - } - - // 写入输出 - GDALDriver* driver = GetGDALDriverManager()->GetDriverByName("GTiff"); - GDALDataset* outDS = driver->Create(SARIntensityPath.toStdString().c_str(), - cols_sar, rows_sar, 1, GDT_Float64, nullptr); - outDS->GetRasterBand(1)->RasterIO(GF_Write, 0, 0, cols_sar, rows_sar, - sarData.data(), cols_sar, rows_sar, GDT_Float64, 0, 0); - - // 资源清理 - GDALClose(lookDS); - GDALClose(intensityDS); - GDALClose(outDS); + SARIntensity.saveImage(SARData, 0, 0, 1); + qDebug() << "Process : [ 100 % ]"; + processBarShow(1000,1000); } diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h index b0f33ab..54c488e 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h @@ -242,10 +242,10 @@ 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); - -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 CreategdalImageFloat(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); +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); gdalImageComplex BASECONSTVARIABLEAPI CreategdalImageComplexNoProj(const QString& img_path, int height, int width, int band_num, bool overwrite = true); diff --git a/LAMPDataProcess.sln b/LAMPDataProcess.sln index 8d9901f..1f54f80 100644 --- a/LAMPDataProcess.sln +++ b/LAMPDataProcess.sln @@ -40,6 +40,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImageshowTool", "ImageshowT EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SPG4Tool", "SPG4Tool\SPG4Tool.vcxproj", "{80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pluginToolboxLibrary", "pluginToolboxLibrary\pluginToolboxLibrary.vcxproj", "{667625A5-8DE2-4373-99F0-8BAD2CCED011}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM = Debug|ARM @@ -182,6 +184,18 @@ Global {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x64.Build.0 = Release|x64 {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x86.ActiveCfg = Release|x64 {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x86.Build.0 = Release|x64 + {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Debug|ARM.ActiveCfg = Debug|x64 + {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Debug|ARM.Build.0 = Debug|x64 + {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Debug|x64.ActiveCfg = Debug|x64 + {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Debug|x64.Build.0 = Debug|x64 + {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Debug|x86.ActiveCfg = Debug|Win32 + {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Debug|x86.Build.0 = Debug|Win32 + {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Release|ARM.ActiveCfg = Release|x64 + {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Release|ARM.Build.0 = Release|x64 + {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Release|x64.ActiveCfg = Release|x64 + {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Release|x64.Build.0 = Release|x64 + {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Release|x86.ActiveCfg = Release|Win32 + {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LAMPDataProcessEXE/LAMPDataProcessEXE.vcxproj b/LAMPDataProcessEXE/LAMPDataProcessEXE.vcxproj index 96d1cdf..cc60302 100644 --- a/LAMPDataProcessEXE/LAMPDataProcessEXE.vcxproj +++ b/LAMPDataProcessEXE/LAMPDataProcessEXE.vcxproj @@ -199,6 +199,9 @@ {8c8ca066-a93a-4098-9a46-b855efeaadf2} + + {667625a5-8de2-4373-99f0-8bad2cced011} + {e56b3878-a3dc-41a4-abf3-b628816d0d64} diff --git a/SPG4Tool/SPG4Function.h b/SPG4Tool/SPG4Function.h index a9cbd4a..70c8ebd 100644 --- a/SPG4Tool/SPG4Function.h +++ b/SPG4Tool/SPG4Function.h @@ -1,7 +1,7 @@ #pragma once #ifndef __SPG4FUNCTION__H__ #define __SPG4FUNCTION__H__ - +#include "SPG4Tool_global.h" #include "Tle.h" #include "SGP4.h" #include "Observer.h" @@ -11,7 +11,7 @@ //void RunTle(libsgp4::Tle tle, double start, double end, double inc); -std::vector RunTle(libsgp4::Tle tle, double start, double end, double inc,bool printfinfoflag=false); +SPG4TOOL_EXPORT std::vector RunTle(libsgp4::Tle tle, double start, double end, double inc,bool printfinfoflag=false); #endif diff --git a/SPG4Tool/SPG4Tool.vcxproj b/SPG4Tool/SPG4Tool.vcxproj index 9a056ef..6b55812 100644 --- a/SPG4Tool/SPG4Tool.vcxproj +++ b/SPG4Tool/SPG4Tool.vcxproj @@ -66,7 +66,7 @@ - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + _CRT_SECURE_NO_WARNINGS;SPG4TOOL_LIB;%(PreprocessorDefinitions) @@ -135,6 +135,7 @@ + diff --git a/SPG4Tool/SPG4Tool_global.h b/SPG4Tool/SPG4Tool_global.h new file mode 100644 index 0000000..7e912f2 --- /dev/null +++ b/SPG4Tool/SPG4Tool_global.h @@ -0,0 +1,17 @@ +#pragma once +#ifndef __SPG4TOOL_GLOBAL__H__ +#define __SPG4TOOL_GLOBAL__H__ + +#include + +#ifdef SPG4TOOL_LIB +#define SPG4TOOL_EXPORT Q_DECL_EXPORT +#else +#define SPG4TOOL_EXPORT Q_DECL_IMPORT +#endif + + + +#endif + + diff --git a/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp b/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp index 19bb96a..90b6580 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp @@ -10,11 +10,13 @@ QComplex2AmpPhase::QComplex2AmpPhase(QWidget *parent) : QDialog(parent) { ui.setupUi(this); + QObject::connect(ui.pushButtonAdd,SIGNAL(clicked(bool)),this,SLOT(onpushButtonAddClicked(bool))); + QObject::connect(ui.pushButtonRemove,SIGNAL(clicked(bool)),this,SLOT(onpushButtonRemoveClicked(bool))); QObject::connect(ui.radioButtonAmp,SIGNAL(toggled(bool)),this,SLOT(radioButtonAmptoggled(bool))); QObject::connect(ui.radioButtonPhase, SIGNAL(toggled(bool)), this, SLOT(radioButtonPhasetoggled(bool))); QObject::connect(ui.radioButtonSigma0, SIGNAL(toggled(bool)), this, SLOT(radioButtonSigma0toggled(bool))); - QObject::connect(ui.buttonBox, SIGNAL(accept()), this, SLOT(accept())); - QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + QObject::connect(ui.buttonBox, SIGNAL(accept()), this, SLOT(onaccept())); + QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(onreject())); //toggled(bool ) } @@ -24,7 +26,7 @@ QComplex2AmpPhase::~QComplex2AmpPhase() } -void QComplex2AmpPhase::accept() +void QComplex2AmpPhase::onaccept() { QProgressDialog progressDialog(u8"ת", u8"ֹ", 0, ui.listWidgetImg->count()); progressDialog.setWindowTitle(u8"ת"); @@ -63,7 +65,7 @@ void QComplex2AmpPhase::accept() progressDialog.close(); } -void QComplex2AmpPhase::reject() +void QComplex2AmpPhase::onreject() { this->close(); } diff --git a/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.h b/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.h index b1201c2..21a974d 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.h +++ b/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.h @@ -13,8 +13,8 @@ public: public slots: - void accept(); - void reject(); + void onaccept(); + void onreject(); void onpushButtonAddClicked(bool); void onpushButtonRemoveClicked(bool); void onpushButtonWorkSpaceClicked(bool); diff --git a/Toolbox/BaseToolbox/BaseToolbox/QDEMResampleDialog.cpp b/Toolbox/BaseToolbox/BaseToolbox/QDEMResampleDialog.cpp index 5c42a13..f09c558 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QDEMResampleDialog.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QDEMResampleDialog.cpp @@ -55,6 +55,7 @@ void QDEMResampleDialog::onoutDEMSelectBtnClicked(bool flag) void QDEMResampleDialog::onAccepted() { + this->hide(); double gridx = ui->doubleSpinBoxGridX->value(); double gridy = ui->doubleSpinBoxGridY->value(); @@ -103,6 +104,8 @@ void QDEMResampleDialog::onAccepted() outDEMPath.toLocal8Bit().constData(), gt.get(), new_width, new_height, GDALResampleAlg::GRA_Bilinear); qDebug() << "DEM ReSample finished!!!"; + this->show(); + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"completed!!!")); } void QDEMResampleDialog::onRejected() diff --git a/Toolbox/BaseToolbox/BaseToolbox/QImportGF3StripL1ADataset.cpp b/Toolbox/BaseToolbox/BaseToolbox/QImportGF3StripL1ADataset.cpp index cdce92d..12793e3 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QImportGF3StripL1ADataset.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QImportGF3StripL1ADataset.cpp @@ -8,10 +8,11 @@ QImportGF3StripL1ADataset::QImportGF3StripL1ADataset(QWidget *parent) ui.setupUi(this); QListWidget* listWidgetMetaxml; - QObject::connect( ui.pushButtonAdd,SIGNAL(clicked(clicked)),this,SLOT(onpushButtonAddClicked(bool))); + QObject::connect(ui.pushButtonAdd,SIGNAL(clicked(clicked)),this,SLOT(onpushButtonAddClicked(bool))); QObject::connect(ui.pushButtonRemove, SIGNAL(clicked(clicked)), this, SLOT(onpushButtonRemoveClicked(bool))); QObject::connect(ui.pushButtonWorkSpace, SIGNAL(clicked(clicked)), this, SLOT(onpushButtonWorkSpaceClicked(bool))); - QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(onreject())); + QObject::connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(onaccept())); } @@ -20,7 +21,7 @@ QImportGF3StripL1ADataset::~QImportGF3StripL1ADataset() } -void QImportGF3StripL1ADataset::accept() +void QImportGF3StripL1ADataset::onaccept() { QProgressDialog progressDialog(u8"GF3L1AӰ", u8"ֹ", 0, ui.listWidgetMetaxml->count()); progressDialog.setWindowTitle(u8"GF3L1AӰ"); @@ -40,7 +41,7 @@ void QImportGF3StripL1ADataset::accept() progressDialog.close(); } -void QImportGF3StripL1ADataset::reject() +void QImportGF3StripL1ADataset::onreject() { this->close(); } diff --git a/Toolbox/BaseToolbox/BaseToolbox/QImportGF3StripL1ADataset.h b/Toolbox/BaseToolbox/BaseToolbox/QImportGF3StripL1ADataset.h index 79759c4..7b2bc56 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QImportGF3StripL1ADataset.h +++ b/Toolbox/BaseToolbox/BaseToolbox/QImportGF3StripL1ADataset.h @@ -14,8 +14,8 @@ public: ~QImportGF3StripL1ADataset(); public slots: - void accept(); - void reject(); + void onaccept(); + void onreject(); void onpushButtonAddClicked(bool); void onpushButtonRemoveClicked(bool); void onpushButtonWorkSpaceClicked(bool); diff --git a/Toolbox/BaseToolbox/BaseToolbox/QOrthSlrRaster.cpp b/Toolbox/BaseToolbox/BaseToolbox/QOrthSlrRaster.cpp index b8e3add..6e4ad79 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QOrthSlrRaster.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QOrthSlrRaster.cpp @@ -16,13 +16,14 @@ QOrthSlrRaster::QOrthSlrRaster(QWidget *parent) connect(ui.pushButtonRemove, SIGNAL(clicked(bool)), this, SLOT(onpushButtonRemoveClicked(bool))); connect(ui.pushButtonDEMSelect, SIGNAL(clicked(bool)), this, SLOT(onpushButtonWorkSpaceClicked(bool))); connect(ui.pushButtonWorkSpace, SIGNAL(clicked(bool)), this, SLOT(pushButtonDEMSelectClicked(bool))); - QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(onreject())); + QObject::connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(onreject())); } QOrthSlrRaster::~QOrthSlrRaster() {} -void QOrthSlrRaster::accept() +void QOrthSlrRaster::onaccept() { QToolProcessBarDialog* processdialog = new QToolProcessBarDialog(this); processdialog->show(); @@ -49,7 +50,7 @@ void QOrthSlrRaster::accept() processdialog->close(); } -void QOrthSlrRaster::reject() +void QOrthSlrRaster::onreject() { this->close(); } diff --git a/Toolbox/BaseToolbox/BaseToolbox/QOrthSlrRaster.h b/Toolbox/BaseToolbox/BaseToolbox/QOrthSlrRaster.h index bdfa19f..abb7623 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QOrthSlrRaster.h +++ b/Toolbox/BaseToolbox/BaseToolbox/QOrthSlrRaster.h @@ -16,8 +16,8 @@ private: public slots: - void accept(); - void reject(); + void onaccept(); + void onreject(); void onpushButtonAddClicked(bool); void onpushButtonRemoveClicked(bool); void onpushButtonWorkSpaceClicked(bool); diff --git a/Toolbox/BaseToolbox/BaseToolbox/QRDOrthProcessClass.cpp b/Toolbox/BaseToolbox/BaseToolbox/QRDOrthProcessClass.cpp index 7a3fd52..2ad3480 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QRDOrthProcessClass.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QRDOrthProcessClass.cpp @@ -12,7 +12,8 @@ QRDOrthProcessClass::QRDOrthProcessClass(QWidget *parent) connect(ui.pushButtonRemove,SIGNAL(clicked(bool)),this,SLOT(onpushButtonRemoveClicked(bool))); connect(ui.pushButtonDEMSelect,SIGNAL(clicked(bool)),this,SLOT(onpushButtonWorkSpaceClicked(bool))); connect(ui.pushButtonWorkSpace, SIGNAL(clicked(bool)), this, SLOT(pushButtonDEMSelectClicked(bool))); - QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(onreject())); + QObject::connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(onaccept())); // QDialogButtonBox* buttonBox; //QLineEdit* lineEditDEM; //QLineEdit* lineEditWorkDir; @@ -22,7 +23,7 @@ QRDOrthProcessClass::QRDOrthProcessClass(QWidget *parent) QRDOrthProcessClass::~QRDOrthProcessClass() {} -void QRDOrthProcessClass::accept() +void QRDOrthProcessClass::onaccept() { QToolProcessBarDialog* processdialog = new QToolProcessBarDialog(this); processdialog->show(); @@ -52,7 +53,7 @@ void QRDOrthProcessClass::accept() processdialog->close(); } -void QRDOrthProcessClass::reject() +void QRDOrthProcessClass::onreject() { this->close(); } diff --git a/Toolbox/BaseToolbox/BaseToolbox/QRDOrthProcessClass.h b/Toolbox/BaseToolbox/BaseToolbox/QRDOrthProcessClass.h index 4b0c0b7..6b6a544 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QRDOrthProcessClass.h +++ b/Toolbox/BaseToolbox/BaseToolbox/QRDOrthProcessClass.h @@ -14,8 +14,8 @@ public: public slots: - void accept(); - void reject(); + void onaccept(); + void onreject(); void onpushButtonAddClicked(bool); void onpushButtonRemoveClicked(bool); void onpushButtonWorkSpaceClicked(bool); diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.cpp b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.cpp index 5a6fcb8..53f55f2 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.cpp +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.cpp @@ -85,7 +85,7 @@ void QtLinearToIntenisityDialog::onbtnaccepted() ui->progressBar->setValue(0); for (long rid = 0; rid < img.height; rid = rid + rowblock) { - for (long bid = 0; bid < img.band_num; bid++) + for (long bid = 1; bid <= img.band_num; bid++) { Eigen::MatrixXd data = img.getData(rid, 0, rowblock, img.width, bid); diff --git a/pluginToolboxLibrary/pluginToolboxLibrary.vcxproj b/pluginToolboxLibrary/pluginToolboxLibrary.vcxproj new file mode 100644 index 0000000..d3a2e08 --- /dev/null +++ b/pluginToolboxLibrary/pluginToolboxLibrary.vcxproj @@ -0,0 +1,161 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {667625a5-8de2-4373-99f0-8bad2cced011} + pluginToolboxLibrary + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Makefile + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + {872ecd6f-30e3-4a1b-b17c-15e87d373ff6} + + + {b8b40c54-f7fe-4809-b6fb-8bc014570d7b} + + + {8c8ca066-a93a-4098-9a46-b855efeaadf2} + + + {e56b3878-a3dc-41a4-abf3-b628816d0d64} + + + {7ef67daa-dbc0-4b7f-80e8-11b4d2cb7ec2} + + + {80a5854f-6f80-4ec2-9f73-84e0f4db8d7e} + + + {070c157e-3c30-4e2b-a80c-cbc7b74df03f} + + + {d603a623-132d-4304-ab03-638fc438f084} + + + {ed06dfcd-4b9f-41f7-8f25-1823c2398142} + + + + + + \ No newline at end of file diff --git a/pluginToolboxLibrary/pluginToolboxLibrary.vcxproj.filters b/pluginToolboxLibrary/pluginToolboxLibrary.vcxproj.filters new file mode 100644 index 0000000..afef69e --- /dev/null +++ b/pluginToolboxLibrary/pluginToolboxLibrary.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + \ No newline at end of file From d0651791ea9b6d08edf902d2cb37dac7da7111c2 Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Wed, 12 Mar 2025 10:48:02 +0800 Subject: [PATCH 08/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp index ae25053..2277d52 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp @@ -4188,6 +4188,7 @@ void CreateSARIntensityByLookTable(QString IntensityRasterPath, long blockYSize = Memory1GB / looktableds.width / 8 * 2; Eigen::MatrixXd SARData = SARIntensity.getData(0, 0, SARIntensity.height, SARIntensity.width, 1); + SARData = SARData.array() * 0; // 分块处理 for (int yOff = 0; yOff < looktableds.height; yOff += blockYSize) { @@ -4199,12 +4200,11 @@ void CreateSARIntensityByLookTable(QString IntensityRasterPath, for (long i = 0; i < rowData.rows(); i++) { for (long j = 0; j < rowData.cols(); j++) { - const long r =round( rowData(i,j))-min_rid; - const long c = round(colData(i, j))-min_cid; + long r =round( rowData(i,j))-min_rid; + long c = round(colData(i, j))-min_cid; - if (r >= 0 && r < SARIntensity.height && c >= 0 && c <= SARIntensity.width) { + if (r >= 0 && r < SARIntensity.height && c >= 0 && c < SARIntensity.width) { SARData(r, c) = SARData(r, c) + geoData(i, j); - } } } From 4582ccc8d5f5b04292747eb719cfc6d5096d8a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Wed, 12 Mar 2025 12:15:26 +0800 Subject: [PATCH 09/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9C=B0=E8=B7=9D?= =?UTF-8?q?=E4=BB=BF=E7=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/BaseTool/BaseTool.cpp | 22 ++ BaseCommonLibrary/BaseTool/BaseTool.h | 18 +- .../QtLinearToIntenisityDialog.ui | 4 +- .../QtSimulationGeoSARSigma0Dialog.cpp | 171 ++++++++++++ .../QtSimulationGeoSARSigma0Dialog.h | 33 +++ .../QtSimulationGeoSARSigma0Dialog.ui | 243 ++++++++++++++++++ .../SimulationSAR/SigmaDatabase.cpp | 69 +++++ .../SimulationSAR/SigmaDatabase.h | 15 +- .../SimulationSARTool/SimulationSARTool.cpp | 18 ++ Toolbox/SimulationSARTool/SimulationSARTool.h | 13 + .../SimulationSARTool.vcxproj | 3 + .../SimulationSARTool.vcxproj.filters | 9 + 12 files changed, 613 insertions(+), 5 deletions(-) create mode 100644 Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.cpp create mode 100644 Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.h create mode 100644 Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.ui diff --git a/BaseCommonLibrary/BaseTool/BaseTool.cpp b/BaseCommonLibrary/BaseTool/BaseTool.cpp index 5cd20e5..656e73b 100644 --- a/BaseCommonLibrary/BaseTool/BaseTool.cpp +++ b/BaseCommonLibrary/BaseTool/BaseTool.cpp @@ -679,4 +679,26 @@ void initializeMatrixWithSSE2(Eigen::MatrixXf& mat, const float* data, long rowc } } +Eigen::MatrixXd BASECONSTVARIABLEAPI MuhlemanSigmaArray(Eigen::MatrixXd& eta_deg) +{ + Eigen::MatrixXd sigma = Eigen::MatrixXd::Zero(eta_deg.rows(), eta_deg.cols()); + for (long i = 0; i < sigma.rows(); i++) { + for (long j = 0; j < sigma.cols(); j++) { + sigma(i,j) = calculate_MuhlemanSigma(eta_deg(i, j)); + } + } + return sigma; +} + +Eigen::MatrixXd BASECONSTVARIABLEAPI dB2Amp(Eigen::MatrixXd& sigma0) +{ + Eigen::MatrixXd sigma = Eigen::MatrixXd::Zero(sigma0.rows(), sigma0.cols()); + for (long i = 0; i < sigma.rows(); i++) { + for (long j = 0; j < sigma.cols(); j++) { + sigma(i, j) =std::pow(10.0, sigma0(i,j)/20.0); + } + } + return sigma; +} + diff --git a/BaseCommonLibrary/BaseTool/BaseTool.h b/BaseCommonLibrary/BaseTool/BaseTool.h index bbed5a7..3255943 100644 --- a/BaseCommonLibrary/BaseTool/BaseTool.h +++ b/BaseCommonLibrary/BaseTool/BaseTool.h @@ -129,10 +129,24 @@ Eigen::VectorXd BASECONSTVARIABLEAPI linspace(double start, double stop, int nu void initializeMatrixWithSSE2(Eigen::MatrixXd& mat, const double* data, long rowcount, long colcount); void initializeMatrixWithSSE2(Eigen::MatrixXf& mat, const float* data, long rowcount, long colcount); - - +Eigen::MatrixXd BASECONSTVARIABLEAPI MuhlemanSigmaArray(Eigen::MatrixXd& eta_deg); +Eigen::MatrixXd BASECONSTVARIABLEAPI dB2Amp(Eigen::MatrixXd& sigma0); /** 模板函数类 ***********************************************************************************************************/ + +inline double calculate_MuhlemanSigma(double eta_deg) { + const double eta_rad = eta_deg * M_PI / 180.0; // 角度转弧度 + + const double cos_eta = std::cos(eta_rad); + const double sin_eta = std::sin(eta_rad); + + const double denominator = sin_eta + 0.1 * cos_eta; + + return (0.0133 * cos_eta) / std::pow(denominator, 3); +} + + + template inline void memsetInitArray(std::shared_ptr ptr, long arrcount,T ti) { for (long i = 0; i < arrcount; i++) { diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.ui b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.ui index 2a27ba6..86749b2 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.ui +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtLinearToIntenisityDialog.ui @@ -6,8 +6,8 @@ 0 0 - 1002 - 400 + 676 + 305 diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.cpp b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.cpp new file mode 100644 index 0000000..d74d654 --- /dev/null +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.cpp @@ -0,0 +1,171 @@ +#include "QtSimulationGeoSARSigma0Dialog.h" +#include "ui_QtSimulationGeoSARSigma0Dialog.h" +#include +#include +#include "BaseTool.h" +#include "SigmaDatabase.h" +#include + + +QtSimulationGeoSARSigma0Dialog::QtSimulationGeoSARSigma0Dialog(QWidget *parent) + : QDialog(parent), ui(new Ui::QtSimulationGeoSARSigma0DialogClass) +{ + ui->setupUi(this); + // źźͲ + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbtnaccepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbtnrejected())); + connect(ui->InputIncAngleRasterBtn, SIGNAL(clicked(bool)), this, SLOT(onpushButtonIncAngleRasterClicked(bool))); + connect(ui->InputLandClsRasterBtn, SIGNAL(clicked(bool)), this, SLOT(onpushButtonLandClsRasterClicked(bool))); + connect(ui->InputClsWeightRasterBtn, SIGNAL(clicked(bool)), this, SLOT(onpushButtonClsWeightRasterClicked(bool))); + connect(ui->OutputTerrianRasterBtn, SIGNAL(clicked(bool)), this, SLOT(onpushButtonOutputTerrianRasterClicked(bool))); + connect(ui->OutputClsSARRasterBtn, SIGNAL(clicked(bool)), this, SLOT(onpushButtonOutputClsSARRasterClicked(bool))); + +} + +QtSimulationGeoSARSigma0Dialog::~QtSimulationGeoSARSigma0Dialog() +{} + +void QtSimulationGeoSARSigma0Dialog::onpushButtonIncAngleRasterClicked(bool) +{ + QString fileName = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡӰ"), // + QString(), // Ĭ· + tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)") // ļ + ); + + // ûѡļ + if (!fileName.isEmpty()) { + this->ui->InputIncAngleRasterLineEdit->setText(fileName); + + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QtSimulationGeoSARSigma0Dialog::onpushButtonLandClsRasterClicked(bool) +{ + QString fileName = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡӰ"), // + QString(), // Ĭ· + tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)") // ļ + ); + + // ûѡļ + if (!fileName.isEmpty()) { + this->ui->InputLandClsRasterLineEdit->setText(fileName); + + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QtSimulationGeoSARSigma0Dialog::onpushButtonClsWeightRasterClicked(bool) +{ + QString fileName = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡӰ"), // + QString(), // Ĭ· + tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)") // ļ + ); + + // ûѡļ + if (!fileName.isEmpty()) { + this->ui->InputClsWeightRasterLineEdit->setText(fileName); + + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QtSimulationGeoSARSigma0Dialog::onpushButtonOutputTerrianRasterClicked(bool) +{ + QString fileName = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡӰ"), // + QString(), // Ĭ· + tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)") // ļ + ); + + // ûѡļ + if (!fileName.isEmpty()) { + this->ui->OutputTerrianRasterLineEdit->setText(fileName); + + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QtSimulationGeoSARSigma0Dialog::onpushButtonOutputClsSARRasterClicked(bool) +{ + QString fileName = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡӰ"), // + QString(), // Ĭ· + tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)") // ļ + ); + + // ûѡļ + if (!fileName.isEmpty()) { + this->ui->OutputClsSARRasterLineEdit->setText(fileName); + + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + + +void QtSimulationGeoSARSigma0Dialog::onbtnaccepted() +{ + // ļ + QString IncAngleRaster = this->ui->InputIncAngleRasterLineEdit->text(); // ļ + QString LandClsRaster = this->ui->InputLandClsRasterLineEdit->text(); // رǷļ + QString ClsWeightRaster = this->ui->InputClsWeightRasterLineEdit->text();// SigmaDatabase Ȩļ + QString OutputTerrianRaster = this->ui->OutputTerrianRasterLineEdit->text(); // ǷSARļ + QString OutputClsSARRaster = this->ui->OutputClsSARRasterLineEdit->text();// رǷSARļ + + // ļļĴСļĴСһ£ļļļ + gdalImage IncAngle(IncAngleRaster); + gdalImage LandCls(LandClsRaster); + SigmaDatabase sigmads; + sigmads.readParamsFromFile(ClsWeightRaster.toStdString()); + + // ļ + QFile::copy(IncAngleRaster, OutputTerrianRaster); + QFile::copy(IncAngleRaster, OutputClsSARRaster); + + gdalImage OutputTerrian(OutputTerrianRaster); + gdalImage OutputClsSAR(OutputClsSARRaster); + + // ȡļ + Eigen::MatrixXd IncAngleData = IncAngle.getData(0, 0, IncAngle.height, IncAngle.width, 0); + Eigen::MatrixXd LandClsData = LandCls.getData(0, 0, LandCls.height, LandCls.width, 0); + + Eigen::MatrixXd SigmaSARData = MuhlemanSigmaArray(IncAngleData); + Eigen::MatrixXd SigmaSARDataCls = SigmaSARData; + OutputTerrian.saveImage(SigmaSARData, 0, 0, 1); + + for (long i = 0; i < LandClsData.rows(); i++) + { + for (long j = 0; j < LandClsData.cols(); j++) + { + double weight = sigmads.getAmpHH(LandClsData(i, j),IncAngleData(i,j)*d2r); + SigmaSARDataCls(i, j) = std::pow(10.0, weight/20.0); + } + } + OutputClsSAR.saveImage(SigmaSARDataCls, 0, 0, 1); + + QMessageBox::information(nullptr, u8"ʾ", u8"completed!!!"); + +} + +void QtSimulationGeoSARSigma0Dialog::onbtnrejected() +{ + this->close(); +} diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.h b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.h new file mode 100644 index 0000000..92afdce --- /dev/null +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +namespace Ui +{ + class QtSimulationGeoSARSigma0DialogClass; +} + + +class QtSimulationGeoSARSigma0Dialog : public QDialog +{ + Q_OBJECT + +public: + QtSimulationGeoSARSigma0Dialog(QWidget *parent = nullptr); + ~QtSimulationGeoSARSigma0Dialog(); + + + + // QtSimulationGeoSARSigma0DialogClassֵĿؼӦIJۺ +public slots: + void onpushButtonIncAngleRasterClicked(bool); + void onpushButtonLandClsRasterClicked(bool); + void onpushButtonClsWeightRasterClicked(bool); + void onpushButtonOutputTerrianRasterClicked(bool); + void onpushButtonOutputClsSARRasterClicked(bool); + void onbtnaccepted(); + void onbtnrejected(); + +private: + Ui::QtSimulationGeoSARSigma0DialogClass* ui; +}; diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.ui b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.ui new file mode 100644 index 0000000..7f561ce --- /dev/null +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.ui @@ -0,0 +1,243 @@ + + + QtSimulationGeoSARSigma0DialogClass + + + + 0 + 0 + 451 + 400 + + + + QtSimulationGeoSARSigma0Dialog + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 30 + + + + 入射角影像: + + + + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\LT1_Simulation_OrbitModel.xml + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 地表覆盖影像: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 权重文件: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 输出地形仿真: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 输出地类仿真影像: + + + + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\LT1_Simulation_Setting.xml + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + + + 24 + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp index 5ce2eb9..2a797e9 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp @@ -4,6 +4,17 @@ #include #include "BaseConstVariable.h" +struct SigmaParam { + double p1; + double p2; + double p3; + double p4; + double p5; + double p6; +}; + + + double getSigma(double& theta, SigmaParam& param) { return param.p1 + param.p2 * exp(-param.p3 * theta) + param.p4 * cos(param.p5 * theta + param.p6); } @@ -156,3 +167,61 @@ std::map SigmaDatabase::getsigmaParams(POLARTYPEENUM polartype } } +void SigmaDatabase::readParamsFromFile(const std::string& filename) { + std::ifstream infile(filename); + if (!infile.is_open()) { + std::cerr << "Failed to open file: " << filename << std::endl; + return; + } + + std::string line; + while (std::getline(infile, line)) { + std::istringstream iss(line); + std::string polarType; + long cls; + SigmaParam param; + + if (!(iss >> polarType >> cls >> param.p1 >> param.p2 >> param.p3 + >> param.p4 >> param.p5 >> param.p6)) { + std::cerr << "Error parsing line: " << line << std::endl; + continue; + } + + if (polarType == "HH") HH_sigmaParam[cls] = param; + else if (polarType == "HV") HV_sigmaParam[cls] = param; + else if (polarType == "VH") VH_sigmaParam[cls] = param; + else if (polarType == "VV") VV_sigmaParam[cls] = param; + else + std::cerr << "Unknown polarization type: " << polarType << std::endl; + } + infile.close(); +} + + +void SigmaDatabase::writeParamsToFile(const std::string& filename) { + std::ofstream outfile(filename); + if (!outfile.is_open()) { + std::cerr << "Failed to create file: " << filename << std::endl; + return; + } + + // C++11lambdaд + auto writePolarData = [&outfile](const std::string& polarType, + const std::map& params) { + for (const auto& entry : params) { + const long cls = entry.first; + const SigmaParam& param = entry.second; + outfile << polarType << " " << cls << " " + << param.p1 << " " << param.p2 << " " + << param.p3 << " " << param.p4 << " " + << param.p5 << " " << param.p6 << "\n"; + } + }; + + writePolarData("HH", HH_sigmaParam); + writePolarData("HV", HV_sigmaParam); + writePolarData("VH", VH_sigmaParam); + writePolarData("VV", VV_sigmaParam); + + outfile.close(); +} \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.h b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.h index cbeb621..64b2ea5 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.h +++ b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.h @@ -75,6 +75,19 @@ public: double getAmp(long cls, double angle, POLARTYPEENUM polartype); std::map getsigmaParams( POLARTYPEENUM polartype); + + /// + /// ļȡ + /// + /// ļ + void readParamsFromFile(const std::string& filename); + + /// + /// дļ + /// + /// ļ + void writeParamsToFile(const std::string& filename); + private: std::map HH_sigmaParam; std::map HV_sigmaParam; @@ -83,4 +96,4 @@ private: }; - + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index b83e2cc..cf72a79 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -5,6 +5,7 @@ #include "QSimulationSARPolynomialOrbitModel.h" #include "QSimulationLookTableDialog.h" #include "QCreateSARIntensityByLookTableDialog.h" +#include "QtSimulationGeoSARSigma0Dialog.h" SARSimlulationRFPCToolButton::SARSimlulationRFPCToolButton(QWidget* parent) { @@ -73,6 +74,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QSimulationSAROrbitModelToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new LookTableComputerClassToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QCreateSARIntensityByLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QtSimulationGeoSARSigma0ToolButton(toolbox)); @@ -111,3 +113,19 @@ void QCreateSARIntensityByLookTableToolButton::excute() QCreateSARIntensityByLookTableDialog* dialog = new QCreateSARIntensityByLookTableDialog; dialog->show(); } + +QtSimulationGeoSARSigma0ToolButton::QtSimulationGeoSARSigma0ToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"湤߿"); + this->toolname = QString(u8"ģǿͼ(ؾ)"); +} + +QtSimulationGeoSARSigma0ToolButton::~QtSimulationGeoSARSigma0ToolButton() +{ +} +void QtSimulationGeoSARSigma0ToolButton::excute() +{ + QtSimulationGeoSARSigma0Dialog* dialog = new QtSimulationGeoSARSigma0Dialog; + dialog->show(); +} diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.h b/Toolbox/SimulationSARTool/SimulationSARTool.h index 5105552..87d0f92 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.h +++ b/Toolbox/SimulationSARTool/SimulationSARTool.h @@ -71,6 +71,19 @@ public slots: }; +// QtSimulationGeoSARSigma0Dialog + +class SIMULATIONSARTOOL_EXPORT QtSimulationGeoSARSigma0ToolButton : public QToolAbstract { + Q_OBJECT +public: + QtSimulationGeoSARSigma0ToolButton(QWidget* parent = nullptr); + ~QtSimulationGeoSARSigma0ToolButton(); +public slots: + + virtual void excute() override; + +}; + extern "C" SIMULATIONSARTOOL_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 66e4019..cf7091f 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -211,6 +211,7 @@ + @@ -232,6 +233,7 @@ + @@ -265,6 +267,7 @@ + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index df35be2..c565244 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -121,6 +121,9 @@ PowerSimulationIncoherent + + PowerSimulationIncoherent + @@ -147,6 +150,9 @@ PowerSimulationIncoherent + + PowerSimulationIncoherent + @@ -176,6 +182,9 @@ PowerSimulationIncoherent + + PowerSimulationIncoherent + From c7291b0475dfcf13ab9f19fd0cb69ee9c2a23307 Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Thu, 13 Mar 2025 12:08:14 +0800 Subject: [PATCH 10/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=BC=BA?= =?UTF-8?q?=E5=BA=A6=E4=BB=BF=E7=9C=9F-=E5=9C=B0=E8=B7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QtSimulationGeoSARSigma0Dialog.cpp | 42 +++++++-------- .../SimulationSAR/SigmaDatabase.cpp | 51 ++++++++----------- .../SimulationSAR/SigmaDatabase.h | 7 ++- .../SimulationSARTool/SimulationSARTool.cpp | 23 +++++++-- Toolbox/SimulationSARTool/SimulationSARTool.h | 16 ++++++ 5 files changed, 84 insertions(+), 55 deletions(-) diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.cpp b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.cpp index d74d654..06534ef 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.cpp +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.cpp @@ -132,35 +132,37 @@ void QtSimulationGeoSARSigma0Dialog::onbtnaccepted() // ļļĴСļĴСһ£ļļļ gdalImage IncAngle(IncAngleRaster); - gdalImage LandCls(LandClsRaster); - SigmaDatabase sigmads; - sigmads.readParamsFromFile(ClsWeightRaster.toStdString()); - - // ļ QFile::copy(IncAngleRaster, OutputTerrianRaster); - QFile::copy(IncAngleRaster, OutputClsSARRaster); - gdalImage OutputTerrian(OutputTerrianRaster); - gdalImage OutputClsSAR(OutputClsSARRaster); - - // ȡļ - Eigen::MatrixXd IncAngleData = IncAngle.getData(0, 0, IncAngle.height, IncAngle.width, 0); - Eigen::MatrixXd LandClsData = LandCls.getData(0, 0, LandCls.height, LandCls.width, 0); + Eigen::MatrixXd IncAngleData = IncAngle.getData(0, 0, IncAngle.height, IncAngle.width,1); Eigen::MatrixXd SigmaSARData = MuhlemanSigmaArray(IncAngleData); - Eigen::MatrixXd SigmaSARDataCls = SigmaSARData; + OutputTerrian.saveImage(SigmaSARData, 0, 0, 1); - for (long i = 0; i < LandClsData.rows(); i++) - { - for (long j = 0; j < LandClsData.cols(); j++) + + + if (QFile(LandClsRaster).exists()) { + + QFile::copy(IncAngleRaster, OutputClsSARRaster); + gdalImage OutputClsSAR(OutputClsSARRaster); + gdalImage LandCls(LandClsRaster); + SigmaDatabase sigmads; + sigmads.readParamsFromFile(ClsWeightRaster.toStdString()); + Eigen::MatrixXd LandClsData = LandCls.getData(0, 0, LandCls.height, LandCls.width,1); + + Eigen::MatrixXd SigmaSARDataCls = SigmaSARData; + for (long i = 0; i < LandClsData.rows(); i++) { - double weight = sigmads.getAmpHH(LandClsData(i, j),IncAngleData(i,j)*d2r); - SigmaSARDataCls(i, j) = std::pow(10.0, weight/20.0); + for (long j = 0; j < LandClsData.cols(); j++) + { + double weight = sigmads.getAmpHH(LandClsData(i, j), IncAngleData(i, j) * d2r); + SigmaSARDataCls(i, j) = std::pow(10.0, weight / 20.0); + } } + OutputClsSAR.saveImage(SigmaSARDataCls, 0, 0, 1); } - OutputClsSAR.saveImage(SigmaSARDataCls, 0, 0, 1); - + else {} QMessageBox::information(nullptr, u8"ʾ", u8"completed!!!"); } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp index 2a797e9..3271027 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp @@ -4,17 +4,7 @@ #include #include "BaseConstVariable.h" -struct SigmaParam { - double p1; - double p2; - double p3; - double p4; - double p5; - double p6; -}; - - - + double getSigma(double& theta, SigmaParam& param) { return param.p1 + param.p2 * exp(-param.p3 * theta) + param.p4 * cos(param.p5 * theta + param.p6); } @@ -198,6 +188,20 @@ void SigmaDatabase::readParamsFromFile(const std::string& filename) { } + +void SigmaDatabase::writePolarData(std::ofstream& outfile, const std::string& polarType, const std::map& params) +{ + for (const auto& entry : params) { + const long cls = entry.first; + const SigmaParam& param = entry.second; + outfile << polarType << " " << cls << " " + << param.p1 << " " << param.p2 << " " + << param.p3 << " " << param.p4 << " " + << param.p5 << " " << param.p6 << "\n"; + } +} + + void SigmaDatabase::writeParamsToFile(const std::string& filename) { std::ofstream outfile(filename); if (!outfile.is_open()) { @@ -205,23 +209,12 @@ void SigmaDatabase::writeParamsToFile(const std::string& filename) { return; } - // C++11lambdaд - auto writePolarData = [&outfile](const std::string& polarType, - const std::map& params) { - for (const auto& entry : params) { - const long cls = entry.first; - const SigmaParam& param = entry.second; - outfile << polarType << " " << cls << " " - << param.p1 << " " << param.p2 << " " - << param.p3 << " " << param.p4 << " " - << param.p5 << " " << param.p6 << "\n"; - } - }; - - writePolarData("HH", HH_sigmaParam); - writePolarData("HV", HV_sigmaParam); - writePolarData("VH", VH_sigmaParam); - writePolarData("VV", VV_sigmaParam); + // ʽĴظ + writePolarData(outfile, "HH", HH_sigmaParam); + writePolarData(outfile, "HV", HV_sigmaParam); + writePolarData(outfile, "VH", VH_sigmaParam); + writePolarData(outfile, "VV", VV_sigmaParam); outfile.close(); -} \ No newline at end of file +} + diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.h b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.h index 64b2ea5..3c5e5fb 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.h +++ b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.h @@ -94,6 +94,11 @@ private: std::map VH_sigmaParam; std::map VV_sigmaParam; +private: + // ˽и + void writePolarData(std::ofstream& outfile, + const std::string& polarType, + const std::map& params); -}; + }; diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index cf72a79..e726c24 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -6,6 +6,7 @@ #include "QSimulationLookTableDialog.h" #include "QCreateSARIntensityByLookTableDialog.h" #include "QtSimulationGeoSARSigma0Dialog.h" +#include "QtLinearToIntenisityDialog.h" SARSimlulationRFPCToolButton::SARSimlulationRFPCToolButton(QWidget* parent) { @@ -67,18 +68,14 @@ void QSimulationSAROrbitModelToolButton::excute() void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox) { - - emit toolbox->addBoxToolItemSIGNAL(new SARSimlulationRFPCToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new SARSimulationTBPImageToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QSimulationSAROrbitModelToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new LookTableComputerClassToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QCreateSARIntensityByLookTableToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QtSimulationGeoSARSigma0ToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QtLinearToIntenisityToolButton(toolbox)); - - - } LookTableComputerClassToolButton::LookTableComputerClassToolButton(QWidget* parent) @@ -129,3 +126,19 @@ void QtSimulationGeoSARSigma0ToolButton::excute() QtSimulationGeoSARSigma0Dialog* dialog = new QtSimulationGeoSARSigma0Dialog; dialog->show(); } + +QtLinearToIntenisityToolButton::QtLinearToIntenisityToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"湤߿"); + this->toolname = QString(u8"dBתֵ"); +} + +QtLinearToIntenisityToolButton::~QtLinearToIntenisityToolButton() +{ +} +void QtLinearToIntenisityToolButton::excute() +{ + QtLinearToIntenisityDialog* dialog = new QtLinearToIntenisityDialog; + dialog->show(); +} \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.h b/Toolbox/SimulationSARTool/SimulationSARTool.h index 87d0f92..ae6cf44 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.h +++ b/Toolbox/SimulationSARTool/SimulationSARTool.h @@ -84,6 +84,22 @@ public slots: }; + + +class SIMULATIONSARTOOL_EXPORT QtLinearToIntenisityToolButton : public QToolAbstract { + Q_OBJECT +public: + QtLinearToIntenisityToolButton(QWidget* parent = nullptr); + ~QtLinearToIntenisityToolButton(); +public slots: + + virtual void excute() override; + +}; + + + + extern "C" SIMULATIONSARTOOL_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); From 0dbe3a0d2054366e142349474003c74d2c2258b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Thu, 13 Mar 2025 13:03:10 +0800 Subject: [PATCH 11/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/BaseToolbox/BaseToolbox.cpp | 18 ++ Toolbox/BaseToolbox/BaseToolbox.h | 12 ++ Toolbox/BaseToolbox/BaseToolbox.vcxproj | 3 + .../BaseToolbox/BaseToolbox.vcxproj.filters | 9 + .../QtLookTableCorrectOffsetDialog.cpp | 109 ++++++++++ .../QtLookTableCorrectOffsetDialog.h | 28 +++ .../QtLookTableCorrectOffsetDialog.ui | 196 ++++++++++++++++++ 7 files changed, 375 insertions(+) create mode 100644 Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.cpp create mode 100644 Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.h create mode 100644 Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.ui diff --git a/Toolbox/BaseToolbox/BaseToolbox.cpp b/Toolbox/BaseToolbox/BaseToolbox.cpp index e3f7b94..c3fd9e6 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox.cpp @@ -11,6 +11,7 @@ #include "DEMLLA2XYZTool.h" #include "QConvertCoordinateSystemDialog.h" #include "QResampleRefrenceRaster.h" +#include "QtLookTableCorrectOffsetDialog.h" GF3ImportDataToolButton::GF3ImportDataToolButton(QWidget* parent) :QToolAbstract(parent) { @@ -111,6 +112,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QDEMLLA2XYZToolToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QConvertCoordinateSystemToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QResampleRefrenceRasterToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QLookTableCorrectOffsetToolButton(toolbox)); } QDEMResampleDialogToolButton::QDEMResampleDialogToolButton(QWidget* parent) @@ -180,3 +182,19 @@ void QResampleRefrenceRasterToolButton::excute() QResampleRefrenceRaster* dialog = new QResampleRefrenceRaster; dialog->show(); } + +QLookTableCorrectOffsetToolButton::QLookTableCorrectOffsetToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8""); + this->toolname = QString(u8"ұƫУ"); +} + +QLookTableCorrectOffsetToolButton::~QLookTableCorrectOffsetToolButton() +{ +} +void QLookTableCorrectOffsetToolButton::excute() +{ + QtLookTableCorrectOffsetDialog* dialog = new QtLookTableCorrectOffsetDialog; + dialog->show(); +} \ No newline at end of file diff --git a/Toolbox/BaseToolbox/BaseToolbox.h b/Toolbox/BaseToolbox/BaseToolbox.h index d1bf550..45749b3 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.h +++ b/Toolbox/BaseToolbox/BaseToolbox.h @@ -109,4 +109,16 @@ public slots: }; +class BASETOOLBOX_EXPORT QLookTableCorrectOffsetToolButton : public QToolAbstract { + Q_OBJECT +public: + QLookTableCorrectOffsetToolButton(QWidget* parent = nullptr); + ~QLookTableCorrectOffsetToolButton(); +public slots: + virtual void excute() override; + +}; + + + extern "C" BASETOOLBOX_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); diff --git a/Toolbox/BaseToolbox/BaseToolbox.vcxproj b/Toolbox/BaseToolbox/BaseToolbox.vcxproj index d2e57f9..b7ee469 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.vcxproj +++ b/Toolbox/BaseToolbox/BaseToolbox.vcxproj @@ -205,6 +205,7 @@ + @@ -221,6 +222,7 @@ + @@ -240,6 +242,7 @@ + diff --git a/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters b/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters index 40f93db..6302cc9 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters +++ b/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters @@ -100,6 +100,9 @@ BaseToolbox + + BaseToolbox + @@ -135,6 +138,9 @@ BaseToolbox + + BaseToolbox + @@ -167,5 +173,8 @@ BaseToolbox + + BaseToolbox + \ No newline at end of file diff --git a/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.cpp b/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.cpp new file mode 100644 index 0000000..615fc90 --- /dev/null +++ b/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.cpp @@ -0,0 +1,109 @@ +#include "QtLookTableCorrectOffsetDialog.h" +#include "ui_QtLookTableCorrectOffsetDialog.h" +#include +#include +#include "ImageOperatorBase.h" +#include "GeoOperator.h" +#include +#include "BaseConstVariable.h" +#include +#include "BaseTool.h" + + +QtLookTableCorrectOffsetDialog::QtLookTableCorrectOffsetDialog(QWidget *parent) + : QDialog(parent), ui(new Ui::QtLookTableCorrectOffsetDialogClass) +{ + ui->setupUi(this); + + QPushButton* OutRasterBtn = ui->OutRasterBtn; + QPushButton* InRasterBtn = ui->InRasterBtn; + QDialogButtonBox* dialogBtn = ui->dialogBtn; + + connect(OutRasterBtn, SIGNAL(clicked()), this, SLOT(onOutRasterBtnClicked())); + connect(InRasterBtn, SIGNAL(clicked()), this, SLOT(onInRasterBtnClicked())); + connect(dialogBtn, SIGNAL(accepted()), this, SLOT(onAcceptBtnClicked())); + connect(dialogBtn, SIGNAL(rejected()), this, SLOT(onRejectBtnClicked())); + +} + +QtLookTableCorrectOffsetDialog::~QtLookTableCorrectOffsetDialog() +{} + +void QtLookTableCorrectOffsetDialog::onOutRasterBtnClicked() +{ + QString fileName = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡӰļ"), // + QString(), // Ĭ· + tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)") // ļ + ); + + // ûѡļ + if (!fileName.isEmpty()) { + this->ui->OutRasterlineEdit->setText(fileName); + + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QtLookTableCorrectOffsetDialog::onInRasterBtnClicked() +{ + QString fileName = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡӰļ"), // + QString(), // Ĭ· + tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)") // ļ + ); + + // ûѡļ + if (!fileName.isEmpty()) { + this->ui->InRasterlineEdit->setText(fileName); + + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QtLookTableCorrectOffsetDialog::onAcceptBtnClicked() +{ + this->ui->progressBar->setValue(0); + QString OutRasterPath = this->ui->OutRasterlineEdit->text(); + QString InRasterPath = this->ui->InRasterlineEdit->text(); + double offsetRow = this->ui->OffsetRowdoubleSpinBox->value(); + double offsetCol = this->ui->OffsetColdoubleSpinBox->value(); + + QFile::copy(InRasterPath, OutRasterPath); + + gdalImage outds(OutRasterPath); + gdalImage inds(InRasterPath); + + if (outds.height != inds.height || outds.width != inds.width) { + QMessageBox::information(this, tr(u8"tip"), tr(u8"size not match!!")); + return; + } + this->ui->progressBar->setMaximum(inds.height); + this->ui->progressBar->setValue(0); + + long blocksize = Memory1MB / 8.0 / outds.width * 2000; + for (long i = 0; i < outds.height; i = i + blocksize) { + Eigen::MatrixXd Rowdata = inds.getData(i, 0, blocksize, outds.width, 1); + Eigen::MatrixXd Coldata = inds.getData(i, 0, blocksize, outds.width, 2); + Rowdata = Rowdata.array() + offsetRow; + Coldata = Coldata.array() + offsetCol; + + outds.saveImage(Rowdata, i, 0, 1); + outds.saveImage(Coldata, i, 0, 1); + this->ui->progressBar->setValue(i); + } + this->ui->progressBar->setValue(inds.height); + + QMessageBox::information(this, tr(u8"tip"), tr(u8"completed!!")); +} + +void QtLookTableCorrectOffsetDialog::onRejectBtnClicked() +{ + this->close(); +} diff --git a/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.h b/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.h new file mode 100644 index 0000000..6bb8b51 --- /dev/null +++ b/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.h @@ -0,0 +1,28 @@ +#pragma once + +#include + + +namespace Ui { + class QtLookTableCorrectOffsetDialogClass; +} + +class QtLookTableCorrectOffsetDialog : public QDialog +{ + Q_OBJECT + +public: + QtLookTableCorrectOffsetDialog(QWidget *parent = nullptr); + ~QtLookTableCorrectOffsetDialog(); + +public slots: + void onOutRasterBtnClicked(); + + void onInRasterBtnClicked(); + void onAcceptBtnClicked(); + void onRejectBtnClicked(); + + +private: + Ui::QtLookTableCorrectOffsetDialogClass* ui; +}; diff --git a/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.ui b/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.ui new file mode 100644 index 0000000..a93c34c --- /dev/null +++ b/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.ui @@ -0,0 +1,196 @@ + + + QtLookTableCorrectOffsetDialogClass + + + + 0 + 0 + 600 + 400 + + + + 查找表数值校正 + + + + + + + + + 0 + 30 + + + + 查找表: + + + + + + + + 0 + 30 + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + + + + + + 0 + 30 + + + + 行号偏移: + + + + + + + + 0 + 30 + + + + 查找表校正: + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 列号偏移: + + + + + + + + 0 + 30 + + + + 6 + + + -1000000000000.000000000000000 + + + 1000000000000.000000000000000 + + + + + + + + 0 + 30 + + + + 6 + + + -1000000000000.000000000000000 + + + 1000000000000.000000000000000 + + + + + + + + + Qt::Vertical + + + + 20 + 158 + + + + + + + + + + + + + + + 24 + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + From 5254154c5c38b4cd35d3fd8db57b5f6a8fa5f3fd Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Fri, 14 Mar 2025 14:49:13 +0800 Subject: [PATCH 12/94] =?UTF-8?q?=E6=8F=92=E5=80=BC=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=89=8D=E5=A2=9E=E5=8A=A0=E7=B1=BB=E5=9E=8B=E5=88=A4=E6=96=AD?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=B8=94=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BA=A7=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/ImageOperatorBase.cpp | 21 +- Toolbox/BaseToolbox/BaseToolbox.cpp | 2 +- .../BaseToolbox/DEMLLA2XYZTool.cpp | 4 +- .../BaseToolbox/QResampleRefrenceRaster.cpp | 28 +- .../BaseToolbox/QResampleRefrenceRaster.ui | 2 +- .../QtLookTableCorrectOffsetDialog.cpp | 6 +- .../LookTableSimulationComputer.cu | 89 +++- .../LookTableSimulationComputer.cuh | 18 + .../QSimulationLookTableDialog.cpp | 320 ++++++++++++-- .../QSimulationLookTableDialog.h | 4 +- .../QSimulationLookTableDialog.ui | 395 ++++++++++-------- .../QtSimulationGeoSARSigma0Dialog.cpp | 137 ++++-- .../QtSimulationGeoSARSigma0Dialog.ui | 285 +++++++------ .../SimulationSAR/TBPImageAlgCls.cpp | 4 +- .../SimulationSARTool.vcxproj | 1 + 15 files changed, 911 insertions(+), 405 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp index 2277d52..377cf48 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp @@ -530,7 +530,7 @@ Eigen::MatrixXd gdalImage::getData(int start_row, int start_col, int rows_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]; + datamatrix(i, j) = long(temp[i * cols_count + j])*1.0; } } delete[] temp; @@ -540,7 +540,7 @@ Eigen::MatrixXd gdalImage::getData(int start_row, int start_col, int rows_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]; + datamatrix(i, j) = long(temp[i * cols_count + j]) * 1.0; } } delete[] temp; @@ -550,7 +550,7 @@ Eigen::MatrixXd gdalImage::getData(int start_row, int start_col, int rows_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]; + datamatrix(i, j) = long(temp[i * cols_count + j]) * 1.0; } } delete[] temp; @@ -570,7 +570,7 @@ Eigen::MatrixXd gdalImage::getData(int start_row, int start_col, int rows_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]; + datamatrix(i, j) = long(temp[i * cols_count + j]) * 1.0; } } delete[] temp; @@ -3843,13 +3843,22 @@ void ConvertCoordinateSystem(QString inRasterPath, QString outRasterPath, long o // qDebug() << "无效的EPSG代码:" << outepsgcode; return; } - + GDALDataType datetype = srcDataset->GetRasterBand(1)->GetRasterDataType(); // 获取目标坐标系的WKT表示 char* targetSRSWkt = nullptr; targetSRS.exportToWkt(&targetSRSWkt); + bool flag = (datetype == GDT_Byte || datetype == GDT_Int8 || datetype == GDT_Int16 ||datetype == GDT_UInt16 || datetype == GDT_Int32 || datetype == GDT_UInt32 || datetype == GDT_Int64 || datetype == GDT_UInt64); + // 创建重投影后的虚拟数据集(Warped VRT) - GDALDataset* warpedVRT = (GDALDataset*)GDALAutoCreateWarpedVRT( + GDALDataset* warpedVRT = flag? (GDALDataset*)GDALAutoCreateWarpedVRT( + srcDataset, + nullptr, // 输入坐标系(默认使用源数据) + targetSRSWkt, // 目标坐标系 + GRA_NearestNeighbour, // 重采样方法:双线性插值 + 0.0, // 最大误差(0表示自动计算) + nullptr // 其他选项 + ) :(GDALDataset*)GDALAutoCreateWarpedVRT( srcDataset, nullptr, // 输入坐标系(默认使用源数据) targetSRSWkt, // 目标坐标系 diff --git a/Toolbox/BaseToolbox/BaseToolbox.cpp b/Toolbox/BaseToolbox/BaseToolbox.cpp index c3fd9e6..58ad050 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox.cpp @@ -119,7 +119,7 @@ QDEMResampleDialogToolButton::QDEMResampleDialogToolButton(QWidget* parent) { this->toolPath = QVector(0); this->toolPath.push_back(u8""); - this->toolname = QString(u8"DEMز"); + this->toolname = QString(u8"դز"); } QDEMResampleDialogToolButton::~QDEMResampleDialogToolButton() diff --git a/Toolbox/BaseToolbox/BaseToolbox/DEMLLA2XYZTool.cpp b/Toolbox/BaseToolbox/BaseToolbox/DEMLLA2XYZTool.cpp index 672c2e5..b5fd618 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/DEMLLA2XYZTool.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/DEMLLA2XYZTool.cpp @@ -110,7 +110,7 @@ void DEMLLA2XYZTool::onaccept() Vector3D Zaxis = { 0,0,1 }; double rowidx = 0, colidx = 0; -#pragma omp parallel for +//#pragma omp parallel for for (long i = 1; i < dem_rows - 1; i++) { for (long j = 1; j < dem_cols - 1; j++) { rowidx = i + startlineid; @@ -127,7 +127,7 @@ void DEMLLA2XYZTool::onaccept() Zaxis.x = pp.lon; Zaxis.y = pp.lat; Zaxis.z = pp.ati; - sloperAngle = getCosAngle(slopeVector, Zaxis); // + sloperAngle = getCosAngle(slopeVector, Zaxis)*r2d; // demsloper_x(i, j) = slopeVector.x; demsloper_y(i, j) = slopeVector.y; diff --git a/Toolbox/BaseToolbox/BaseToolbox/QResampleRefrenceRaster.cpp b/Toolbox/BaseToolbox/BaseToolbox/QResampleRefrenceRaster.cpp index 2e8471e..24a0f4c 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QResampleRefrenceRaster.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QResampleRefrenceRaster.cpp @@ -94,12 +94,32 @@ void QResampleRefrenceRaster::ondialogBtnaccepted() gt.get()[4] = refimage.gt(1, 1); gt.get()[5] = refimage.gt(1, 2); + gdalImage inRaster(inRasterPath); + + GDALDataType datetype = inRaster.getDataType(); + + if (datetype == GDT_Byte || + datetype == GDT_Int8 || + datetype == GDT_Int16 || + datetype == GDT_UInt16 || + datetype == GDT_Int32 || + datetype == GDT_UInt32 || + datetype == GDT_Int64 || + datetype == GDT_UInt64 + ) { + ResampleGDAL(inRasterPath.toLocal8Bit().constData(), OutRasterPath.toLocal8Bit().constData(), + gt.get(), refimage.width, refimage.height, + GDALResampleAlg::GRA_NearestNeighbour); + //alignRaster(inRasterPath, RefRasterPath, OutRasterPath,GDALResampleAlg::GRA_Bilinear); + } + else { + ResampleGDAL(inRasterPath.toLocal8Bit().constData(), OutRasterPath.toLocal8Bit().constData(), + gt.get(), refimage.width, refimage.height, + GDALResampleAlg::GRA_Bilinear); + //alignRaster(inRasterPath, RefRasterPath, OutRasterPath,GDALResampleAlg::GRA_Bilinear); + } - ResampleGDAL(inRasterPath.toLocal8Bit().constData(), OutRasterPath.toLocal8Bit().constData(), - gt.get(), refimage.width, refimage.height, - GDALResampleAlg::GRA_Bilinear); - //alignRaster(inRasterPath, RefRasterPath, OutRasterPath,GDALResampleAlg::GRA_Bilinear); diff --git a/Toolbox/BaseToolbox/BaseToolbox/QResampleRefrenceRaster.ui b/Toolbox/BaseToolbox/BaseToolbox/QResampleRefrenceRaster.ui index 94b3cfe..35a7c90 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QResampleRefrenceRaster.ui +++ b/Toolbox/BaseToolbox/BaseToolbox/QResampleRefrenceRaster.ui @@ -7,7 +7,7 @@ 0 0 600 - 400 + 322 diff --git a/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.cpp b/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.cpp index 615fc90..e87735a 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QtLookTableCorrectOffsetDialog.cpp @@ -31,7 +31,7 @@ QtLookTableCorrectOffsetDialog::~QtLookTableCorrectOffsetDialog() void QtLookTableCorrectOffsetDialog::onOutRasterBtnClicked() { - QString fileName = QFileDialog::getOpenFileName( + QString fileName = QFileDialog::getSaveFileName( this, // tr(u8"ѡӰļ"), // QString(), // Ĭ· @@ -50,7 +50,7 @@ void QtLookTableCorrectOffsetDialog::onOutRasterBtnClicked() void QtLookTableCorrectOffsetDialog::onInRasterBtnClicked() { - QString fileName = QFileDialog::getSaveFileName( + QString fileName = QFileDialog::getOpenFileName( this, // tr(u8"ѡӰļ"), // QString(), // Ĭ· @@ -95,7 +95,7 @@ void QtLookTableCorrectOffsetDialog::onAcceptBtnClicked() Coldata = Coldata.array() + offsetCol; outds.saveImage(Rowdata, i, 0, 1); - outds.saveImage(Coldata, i, 0, 1); + outds.saveImage(Coldata, i, 0, 2); this->ui->progressBar->setValue(i); } this->ui->progressBar->setValue(inds.height); diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cu b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cu index 6781aa7..8f0550b 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cu +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cu @@ -131,7 +131,7 @@ __global__ void Kernel_RDProcess_doppler( Rd_r = (ti - starttime) * PRF; Rd_c = Fs/LIGHTSPEED * (R - nearRange)*2; - //printf("ti: %10.6f,starttime:%10.6f,PRF:%10.6f,Rd_c:%10.6f,R:%10.6f\n", ti, starttime, PRF, Rd_c, R); + //printf("ti: %10.6f,starttime:%10.6f,PRF:%10.6f,Rd_r:%10.6f,Rd_c:%10.6f,R:%10.6f\n", ti, starttime, PRF, Rd_r, Rd_c, R); outRidx[idx] = Rd_r; outCidx[idx] = Rd_c;//Rd_c; return; @@ -185,6 +185,93 @@ void RDProcess_dopplerGPU( cudaDeviceSynchronize(); } +__device__ double calculateIncidenceAngle(double Rx, double Ry, double Rz, double Sx, double Sy, double Sz) { + double dotProduct = Rx * Sx + Ry * Sy + Rz * Sz; + double magnitudeR = sqrt(Rx * Rx + Ry * Ry + Rz * Rz); + double magnitudeS = sqrt(Sx * Sx + Sy * Sy + Sz * Sz); + return acos(dotProduct / (magnitudeR * magnitudeS)); +} + +__global__ void Kernel_RDProcess_demSloper( + double* demX, double* demY, double* demZ, + double* demSloperX, double* demSloperY, double* demSloperZ, + float* InRidx, + float* outIncAngle, + long pixelcount, + double Xp0, double Yp0, double Zp0, double Xv0, double Yv0, double Zv0, + double Xp1, double Yp1, double Zp1, double Xv1, double Yv1, double Zv1, + double Xp2, double Yp2, double Zp2, double Xv2, double Yv2, double Zv2, + double Xp3, double Yp3, double Zp3, double Xv3, double Yv3, double Zv3, + double Xp4, double Yp4, double Zp4, double Xv4, double Yv4, double Zv4, + double Xp5, double Yp5, double Zp5, double Xv5, double Yv5, double Zv5, + + double starttime, double nearRange, double farRange, + double PRF +) { + long idx = blockIdx.x * blockDim.x + threadIdx.x; + if (idx < pixelcount) { + double demx = demX[idx]; + double demy = demY[idx]; + double demz = demZ[idx]; + double demSloperx = demSloperX[idx]; + double demSlopery = demSloperY[idx]; + double demSloperz = demSloperZ[idx]; + float Rd_r = InRidx[idx]; + double ti = starttime + Rd_r / PRF; + double Spx = getPolyfitNumber(ti, Xp0, Xp1, Xp2, Xp3, Xp4, Xp5); + double Spy = getPolyfitNumber(ti, Yp0, Yp1, Yp2, Yp3, Yp4, Yp5); + double Spz = getPolyfitNumber(ti, Zp0, Zp1, Zp2, Zp3, Zp4, Zp5); + double Rx = Spx - demx; + double Ry = Spy - demy; + double Rz = Spz - demz; + double R = sqrt(Rx * Rx + Ry * Ry + Rz * Rz); + Rx = Rx / R; + Ry = Ry / R; + Rz = Rz / R; + double incidenceAngle = calculateIncidenceAngle(Rx, Ry, Rz, demSloperx, demSlopery, demSloperz); + //printf("incangle:%f\n", incidenceAngle * r2d); + outIncAngle[idx] = incidenceAngle*r2d; + } +} + +void RDProcess_demSloperGPU( + double* demX, double* demY, double* demZ, + double* demSloperX, double* demSloperY, double* demSloperZ, + float* InRidx, + float* outIncAngle, + long rowcount, long colcount, + double starttime, double nearRange, double farRange, + double PRF, + double Xp0, double Yp0, double Zp0, double Xv0, double Yv0, double Zv0, + double Xp1, double Yp1, double Zp1, double Xv1, double Yv1, double Zv1, + double Xp2, double Yp2, double Zp2, double Xv2, double Yv2, double Zv2, + double Xp3, double Yp3, double Zp3, double Xv3, double Yv3, double Zv3, + double Xp4, double Yp4, double Zp4, double Xv4, double Yv4, double Zv4, + double Xp5, double Yp5, double Zp5, double Xv5, double Yv5, double Zv5 + +) { + long pixelcount = rowcount * colcount; + int numBlocks = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; + Kernel_RDProcess_demSloper << > > ( + demX, demY, demZ, + demSloperX, demSloperY, demSloperZ, + InRidx, + outIncAngle, + pixelcount, + Xp0, Yp0, Zp0, Xv0, Yv0, Zv0, + Xp1, Yp1, Zp1, Xv1, Yv1, Zv1, + Xp2, Yp2, Zp2, Xv2, Yv2, Zv2, + Xp3, Yp3, Zp3, Xv3, Yv3, Zv3, + Xp4, Yp4, Zp4, Xv4, Yv4, Zv4, + Xp5, Yp5, Zp5, Xv5, Yv5, Zv5, + + starttime, nearRange, farRange, + PRF + ); + PrintLasterError("RD with demSloper function"); + cudaDeviceSynchronize(); +} + diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cuh b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cuh index ab810f3..1ce140e 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cuh +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cuh @@ -37,5 +37,23 @@ extern "C" void RDProcess_dopplerGPU( +// +extern "C" void RDProcess_demSloperGPU( + double* demX, double* demY, double* demZ, // + double* demSloperX, double* demSloperY, double* demSloperZ, // + float* InRidx, //float* InCidx, // + float* outIncAngle, + long rowcount, long colcount, + double starttime, double nearRange, double farRange, + double PRF, //double Fs, + //double fact_lamda, // lamda + double Xp0 = 0, double Yp0 = 0, double Zp0 = 0, double Xv0 = 0, double Yv0 = 0, double Zv0 = 0, // + double Xp1 = 0, double Yp1 = 0, double Zp1 = 0, double Xv1 = 0, double Yv1 = 0, double Zv1 = 0, + double Xp2 = 0, double Yp2 = 0, double Zp2 = 0, double Xv2 = 0, double Yv2 = 0, double Zv2 = 0, + double Xp3 = 0, double Yp3 = 0, double Zp3 = 0, double Xv3 = 0, double Yv3 = 0, double Zv3 = 0, + double Xp4 = 0, double Yp4 = 0, double Zp4 = 0, double Xv4 = 0, double Yv4 = 0, double Zv4 = 0, + double Xp5 = 0, double Yp5 = 0, double Zp5 = 0, double Xv5 = 0, double Yv5 = 0, double Zv5 = 0 + +); diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QSimulationLookTableDialog.cpp b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QSimulationLookTableDialog.cpp index cc682f9..cc5cc07 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QSimulationLookTableDialog.cpp +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QSimulationLookTableDialog.cpp @@ -15,13 +15,14 @@ #include "ImageShowDialogClass.h" #include "QToolProcessBarDialog.h" -QSimulationLookTableDialog::QSimulationLookTableDialog(QWidget *parent) - : QDialog(parent),ui(new Ui::QSimulationLookTableDialogClass) +QSimulationLookTableDialog::QSimulationLookTableDialog(QWidget* parent) + : QDialog(parent), ui(new Ui::QSimulationLookTableDialogClass) { ui->setupUi(this); connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onaccepted())); connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onrejected())); connect(ui->pushButtonDEM, SIGNAL(clicked(bool)), this, SLOT(onpushButtonDEMClicked(bool))); + connect(ui->pushButtonSloper, SIGNAL(clicked(bool)), this, SLOT(onpushButtonSloperClicked(bool))); connect(ui->pushButtonOrbitModel, SIGNAL(clicked(bool)), this, SLOT(onpushButtonOrbitModelClicked(bool))); connect(ui->pushButtonOutDir, SIGNAL(clicked(bool)), this, SLOT(onpushButtonOutDirClicked(bool))); connect(ui->pushButtonSataSetting, SIGNAL(clicked(bool)), this, SLOT(onpushButtonSataSettingClicked(bool))); @@ -76,7 +77,7 @@ void QSimulationLookTableDialog::onpushButtonDEMClicked(bool) { // ļѡԻѡһ .tif ļ QString fileName = QFileDialog::getOpenFileName(this, - u8"DEM Raster Select", // Ի + u8"DEM XYZ Raster Select", // Ի "", // ʼĿ¼Ϊ· u8"tiff Files (*.tiff);;tif Files (*.tif);;dat Files (*.dat);;All Files (*.*)"); // ļ͹ @@ -88,13 +89,29 @@ void QSimulationLookTableDialog::onpushButtonDEMClicked(bool) } } +void QSimulationLookTableDialog::onpushButtonSloperClicked(bool) +{ + // ļѡԻѡһ .tif ļ + QString fileName = QFileDialog::getOpenFileName(this, + u8"DEM Sloper Raster Select", // Ի + "", // ʼĿ¼Ϊ· + u8"tiff Files (*.tiff);;tif Files (*.tif);;dat Files (*.dat);;All Files (*.*)"); // ļ͹ + + if (!fileName.isEmpty()) { + this->ui->SloperLineEdit->setText(fileName); + } + else { + QMessageBox::information(this, u8"ûѡļ", u8"ûѡκļ"); + } +} + void QSimulationLookTableDialog::onpushButtonOutDirClicked(bool) { // ļѡԻѡһ .tif ļ QString fileName = QFileDialog::getExistingDirectory(this, u8"DEM Raster Select", // Ի "" // ʼĿ¼Ϊ· - ); + ); if (!fileName.isEmpty()) { this->ui->outDirLineEdit->setText(fileName); } @@ -174,7 +191,8 @@ void QSimulationLookTableDialog::LookTableSimualtionMainProcess(QString sateName this->ui->label_tip->setText(u8"look table create..."); this->ui->progressBar->setValue(0); this->LookTableSimulationDopplerProcess( - DEMPath, outLookTablePath, + DEMPath, + outLookTablePath, OribtStartTime, PolyfitPx, PolyfitPy, PolyfitPz, PolyfitVx, PolyfitVy, PolyfitVz, @@ -193,14 +211,27 @@ void QSimulationLookTableDialog::LookTableSimualtionMainProcess(QString sateName ); } - + if (checkBoxIncAngle) { this->ui->label_tip->setText(u8"sloper process..."); this->ui->progressBar->setValue(0); outIncPath = JoinPath(outDirPath, sateName + "_incAngle.bin"); - - - + QString sloperPath = this->ui->SloperLineEdit->text(); + LocalIncidenceAngleSimulationCompter( + sloperPath, + DEMPath, + outLookTablePath, + outIncPath, + OribtStartTime, + PolyfitPx, + PolyfitPy, + PolyfitPz, + PolyfitVx, + PolyfitVy, + PolyfitVz, + startTime, endTime, + nearRange, farRange, + PRF, Fs); } @@ -310,37 +341,24 @@ void QSimulationLookTableDialog::LookTableSimulationDopplerProcess(QString DEMPa // ڴԤ - // - std::shared_ptr host_Rid((float*)mallocCUDAHost(sizeof(float) * GPUMemoryline * demimg.width), FreeCUDAHost); - std::shared_ptr host_Cid((float*)mallocCUDAHost(sizeof(float) * GPUMemoryline * demimg.width), FreeCUDAHost); - std::shared_ptr device_Rid((float*)mallocCUDADevice(sizeof(float) * GPUMemoryline * demimg.width), FreeCUDADevice); - std::shared_ptr device_Cid((float*)mallocCUDADevice(sizeof(float) * GPUMemoryline * demimg.width), FreeCUDADevice); - - // - std::shared_ptr host_demX((double*)mallocCUDAHost(sizeof(double) * GPUMemoryline * demimg.width), FreeCUDAHost); - std::shared_ptr host_demY((double*)mallocCUDAHost(sizeof(double) * GPUMemoryline * demimg.width), FreeCUDAHost); - std::shared_ptr host_demZ((double*)mallocCUDAHost(sizeof(double) * GPUMemoryline * demimg.width), FreeCUDAHost); - - std::shared_ptr device_demX((double*)mallocCUDADevice(sizeof(double) * GPUMemoryline * demimg.width), FreeCUDADevice); - std::shared_ptr device_demY((double*)mallocCUDADevice(sizeof(double) * GPUMemoryline * demimg.width), FreeCUDADevice); - std::shared_ptr device_demZ((double*)mallocCUDADevice(sizeof(double) * GPUMemoryline * demimg.width), FreeCUDADevice); // //std::shared_ptr datashowptr(new ImageShowDialogClass); // ƽ - long rowcount = GPUMemoryline; - long colcount = demimg.width; + //rowcount = 1; //colcount = 1; //long testRid = demimg.height / 2; //long testCid = demimg.width / 2; - + double fact_lamda = 1 / lamda; for (long rid = 0; rid < demimg.height; rid = rid + GPUMemoryline) { + long rowcount = GPUMemoryline; + long colcount = demimg.width; qDebug() << "computer read file : " << rid << "~" << rowcount + rid << "\t:" << demimg.height; //double* tmep = new double[rowcount * colcount]; std::shared_ptr demX = readDataArr(demimg, rid, 0, rowcount, colcount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);// ޸ @@ -348,7 +366,21 @@ void QSimulationLookTableDialog::LookTableSimulationDopplerProcess(QString DEMPa std::shared_ptr demZ = readDataArr(demimg, rid, 0, rowcount, colcount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + // + std::shared_ptr host_Rid((float*)mallocCUDAHost(sizeof(float) * rowcount * demimg.width), FreeCUDAHost); + std::shared_ptr host_Cid((float*)mallocCUDAHost(sizeof(float) * rowcount * demimg.width), FreeCUDAHost); + std::shared_ptr device_Rid((float*)mallocCUDADevice(sizeof(float) * rowcount * demimg.width), FreeCUDADevice); + std::shared_ptr device_Cid((float*)mallocCUDADevice(sizeof(float) * rowcount * demimg.width), FreeCUDADevice); + + // + std::shared_ptr host_demX((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + std::shared_ptr host_demY((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + std::shared_ptr host_demZ((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + + std::shared_ptr device_demX((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); + std::shared_ptr device_demY((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); + std::shared_ptr device_demZ((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); //std::shared_ptr demX = readDataArr(demimg, rid, testCid, rowcount, colcount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);// ޸ //std::shared_ptr demY = readDataArr(demimg, rid, testCid, rowcount, colcount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); @@ -363,9 +395,9 @@ void QSimulationLookTableDialog::LookTableSimulationDopplerProcess(QString DEMPa 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); + HostToDevice(host_demX.get(), device_demX.get(), sizeof(double) * rowcount * demimg.width); + HostToDevice(host_demY.get(), device_demY.get(), sizeof(double) * rowcount * demimg.width); + HostToDevice(host_demZ.get(), device_demZ.get(), sizeof(double) * rowcount * demimg.width); qDebug() << "GPU computer start: " << rid << "~" << rowcount + rid << "\t:" << demimg.height; RDProcess_dopplerGPU( @@ -385,8 +417,8 @@ void QSimulationLookTableDialog::LookTableSimulationDopplerProcess(QString DEMPa // 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); + DeviceToHost(host_Rid.get(), device_Rid.get(), sizeof(float) * rowcount * demimg.width); + DeviceToHost(host_Cid.get(), device_Cid.get(), sizeof(float) * rowcount * demimg.width); qDebug() << "GPU computer finished!!: " << rid << "~" << rowcount + rid << "\t:" << demimg.height; //exit(-1); // ݴ洢 @@ -397,25 +429,227 @@ void QSimulationLookTableDialog::LookTableSimulationDopplerProcess(QString DEMPa //datashowptr->exec(); qDebug() << "GPU computer result write finished: " << rid << "~" << rowcount + rid << "\t:" << demimg.height; - - this->ui->progressBar->setValue(floor(100.0*(rowcount + rid)/ demimg.height)); + + this->ui->progressBar->setValue(floor(100.0 * (rowcount + rid) / demimg.height)); } qDebug() << "look table computed finished!!!"; this->ui->progressBar->setValue(100); } -void QSimulationLookTableDialog::LocalIncidenceAngleSimulationCompter(QString DEMPath, QString LookTablePath, QString outIncPath, long double OribtStartTime, std::vector PolyfitPx, std::vector PolyfitPy, std::vector PolyfitPz, std::vector PolyfitVx, std::vector PolyfitVy, std::vector PolyfitVz, double starttime, double endtime, double nearRange, double farRange, double PRF, double Fs) +void QSimulationLookTableDialog::LocalIncidenceAngleSimulationCompter(QString sloperPath, QString demxyzPath, QString LookTablePath, QString outIncPath, long double OribtStartTime, std::vector PolyfitPx, std::vector PolyfitPy, std::vector PolyfitPz, std::vector PolyfitVx, std::vector PolyfitVy, std::vector 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 -//); + // + + qDebug() << "generate look table "; + qDebug() << "Sloper Path\t" << sloperPath; + qDebug() << "outLookTablePath\t" << LookTablePath; + + + gdalImage sloperimg(sloperPath); + gdalImage demimg(demxyzPath); + gdalImage looktableimg(LookTablePath); + gdalImage outIncAngle = CreategdalImage( // ұ + outIncPath, + demimg.height, demimg.width,1, + 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; + } + + + + // ֿ + long GPUMemoryline = floor((Memory1MB * 2.0 / 8.0 / 3.0 / demimg.width * 2000));//2GB + GPUMemoryline = GPUMemoryline < 1 ? 1 : GPUMemoryline; + + for (long rid = 0; rid < demimg.height; rid = rid + GPUMemoryline) { + long rowcount = GPUMemoryline; + long colcount = demimg.width; + qDebug() << "computer read file : " << rid << "~" << rowcount + rid << "\t:" << demimg.height; + //double* tmep = new double[rowcount * colcount]; + std::shared_ptr demX = readDataArr(demimg, rid, 0, rowcount, colcount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);// ޸ + std::shared_ptr demY = readDataArr(demimg, rid, 0, rowcount, colcount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demZ = readDataArr(demimg, rid, 0, rowcount, colcount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + std::shared_ptr demSloperX = readDataArr(sloperimg, rid, 0, rowcount, colcount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);// ޸ + std::shared_ptr demSloperY = readDataArr(sloperimg, rid, 0, rowcount, colcount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demSloperZ = readDataArr(sloperimg, rid, 0, rowcount, colcount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + std::shared_ptr look_rid = readDataArr(looktableimg, rid, 0, rowcount, colcount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + // + std::shared_ptr host_incangle((float*)mallocCUDAHost(sizeof(float) * rowcount * demimg.width), FreeCUDAHost); + std::shared_ptr device_incangle((float*)mallocCUDADevice(sizeof(float) * rowcount * demimg.width), FreeCUDADevice); + + // + std::shared_ptr host_demX((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + std::shared_ptr host_demY((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + std::shared_ptr host_demZ((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + + std::shared_ptr device_demX((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); + std::shared_ptr device_demY((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); + std::shared_ptr device_demZ((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); + + // Ӧ¶ + std::shared_ptr host_demSloperX((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + std::shared_ptr host_demSloperY((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + std::shared_ptr host_demSloperZ((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + + std::shared_ptr device_demSloperX((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); + std::shared_ptr device_demSloperY((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); + std::shared_ptr device_demSloperZ((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); + + // к + std::shared_ptr host_Rid((float*)mallocCUDAHost(sizeof(float) * rowcount * demimg.width), FreeCUDAHost); + std::shared_ptr device_Rid((float*)mallocCUDADevice(sizeof(float) * rowcount * demimg.width), FreeCUDADevice); + + + //std::shared_ptr demX = readDataArr(demimg, rid, testCid, rowcount, colcount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);// ޸ + //std::shared_ptr demY = readDataArr(demimg, rid, testCid, rowcount, colcount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + //std::shared_ptr demZ = readDataArr(demimg, rid, testCid, rowcount, colcount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + //demX.get()[0]=-1407793.922129; + //demY.get()[0]=5465044.940211; + //demZ.get()[0]=2963219.736386; + // ݸ + 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); + + memcpy(host_demSloperX.get(), demSloperX.get(), sizeof(double) * rowcount * colcount); + memcpy(host_demSloperY.get(), demSloperY.get(), sizeof(double) * rowcount * colcount); + memcpy(host_demSloperZ.get(), demSloperZ.get(), sizeof(double) * rowcount * colcount); + + + //ڴ->GPU + HostToDevice(host_demX.get(), device_demX.get(), sizeof(double) * rowcount * demimg.width); + HostToDevice(host_demY.get(), device_demY.get(), sizeof(double) * rowcount * demimg.width); + HostToDevice(host_demZ.get(), device_demZ.get(), sizeof(double) * rowcount * demimg.width); + HostToDevice(host_demSloperX.get(), device_demSloperX.get(), sizeof(double) * rowcount * demimg.width); + HostToDevice(host_demSloperY.get(), device_demSloperY.get(), sizeof(double) * rowcount * demimg.width); + HostToDevice(host_demSloperZ.get(), device_demSloperZ.get(), sizeof(double) * rowcount * demimg.width); + HostToDevice(look_rid.get(), device_Rid.get(), sizeof(float) * rowcount * demimg.width); + + + + qDebug() << "GPU computer start: " << rid << "~" << rowcount + rid << "\t:" << demimg.height; + + RDProcess_demSloperGPU( + device_demX.get(), device_demY.get(), device_demZ.get(), + device_demSloperX.get(), device_demSloperY.get(), device_demSloperZ.get(), + device_Rid.get(), device_incangle.get(), + + rowcount, colcount, + starttime, nearRange, farRange, + PRF, + Xp0, Yp0, Zp0, Xv0, Yv0, Zv0, + Xp1, Yp1, Zp1, Xv1, Yv1, Zv1, + Xp2, Yp2, Zp2, Xv2, Yv2, Zv2, + Xp3, Yp3, Zp3, Xv3, Yv3, Zv3, + Xp4, Yp4, Zp4, Xv4, Yv4, Zv4, + Xp5, Yp5, Zp5, Xv5, Yv5, Zv5 + ); + + DeviceToHost(host_incangle.get(), device_incangle.get(), sizeof(float) * rowcount * demimg.width); + + qDebug() << "GPU computer finished!!: " << rid << "~" << rowcount + rid << "\t:" << demimg.height; + //exit(-1); + // ݴ洢 + outIncAngle.saveImage(host_incangle, rid, 0, rowcount, colcount, 1); + + //datashowptr->load_double_data(host_Rid.get(), rowcount, colcount, QString("host_Rid")); + //datashowptr->exec(); + + qDebug() << "GPU computer result write finished: " << rid << "~" << rowcount + rid << "\t:" << demimg.height; + + this->ui->progressBar->setValue(floor(100.0 * (rowcount + rid) / demimg.height)); + } + + qDebug() << "look table computed finished!!!"; + this->ui->progressBar->setValue(100); + + + + + + + + + + + + + + + + + + + + + } void QSimulationLookTableDialog::onaccepted() diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QSimulationLookTableDialog.h b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QSimulationLookTableDialog.h index 14f5291..6d9570d 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QSimulationLookTableDialog.h +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QSimulationLookTableDialog.h @@ -26,6 +26,7 @@ public slots: void onpushButtonOrbitModelClicked(bool); void onpushButtonSataSettingClicked(bool); void onpushButtonDEMClicked(bool); + void onpushButtonSloperClicked(bool); void onpushButtonOutDirClicked(bool); @@ -69,7 +70,8 @@ private: // doppler ); void LocalIncidenceAngleSimulationCompter( - QString DEMPath, + QString sloperPath, + QString demxyzPath, QString LookTablePath, QString outIncPath, long double OribtStartTime, // ģͲοʱ diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QSimulationLookTableDialog.ui b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QSimulationLookTableDialog.ui index 2335b52..ff74438 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QSimulationLookTableDialog.ui +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QSimulationLookTableDialog.ui @@ -7,14 +7,106 @@ 0 0 763 - 387 + 498 QSimulationLookTableDialog - + + + + + 0 + 30 + + + + 选择 + + + + + + + + + + + + + + 24 + + + + + + + + 0 + 30 + + + + LT1A_20250210 + + + + + + + + 0 + 30 + + + + 结果文件保存地址: + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\LT1_Simulation_OrbitModel.xml + + + + 计算资源 @@ -52,15 +144,8 @@ - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - + + 0 @@ -68,7 +153,20 @@ - LT1A_20250210 + 多项式轨道模型参数: + + + + + + + + 0 + 30 + + + + 坡度法向文件(sloper) @@ -85,7 +183,46 @@ - + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\LT1A_DEM_20250210_resampleXYZ.dat + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 30 + + + + 选择 + + + + Qt::Vertical @@ -98,7 +235,56 @@ - + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\Looktable + + + + + + + + 0 + 30 + + + + 查找表名 + + + + + + + 采用多普勒参数 + + + true + + + + + + + + 0 + 30 + + + + 卫星仿真参数: + + + + @@ -111,6 +297,19 @@ + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\LT1_Simulation_Setting.xml + + + @@ -124,95 +323,14 @@ - - - - - 0 - 30 - - - - 结果文件保存地址: - - - - - - - - 0 - 30 - - - - 多项式轨道模型参数: - - - - - - - - 0 - 30 - - - - 查找表名 - - - - - - - - 0 - 30 - - - - 选择 - - - - - - - 采用多普勒参数 - - - true - - - - - - - - 0 - 30 - - - - 选择 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - Qt::Vertical - - - - 20 - 40 - - - - - 产品输出类型 @@ -253,85 +371,6 @@ - - - - - 0 - 30 - - - - 卫星仿真参数: - - - - - - - - 0 - 30 - - - - 选择 - - - - - - - - 0 - 30 - - - - D:\FZSimulation\LT1A\L20250210\LT1_Simulation_Setting.xml - - - - - - - - 0 - 30 - - - - D:\FZSimulation\LT1A\L20250210\Looktable - - - - - - - - 0 - 30 - - - - D:\FZSimulation\LT1A\L20250210\LT1_Simulation_OrbitModel.xml - - - - - - - 24 - - - - - - - - - - diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.cpp b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.cpp index 06534ef..8c138c5 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.cpp +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.cpp @@ -128,41 +128,128 @@ void QtSimulationGeoSARSigma0Dialog::onbtnaccepted() QString LandClsRaster = this->ui->InputLandClsRasterLineEdit->text(); // رǷļ QString ClsWeightRaster = this->ui->InputClsWeightRasterLineEdit->text();// SigmaDatabase Ȩļ QString OutputTerrianRaster = this->ui->OutputTerrianRasterLineEdit->text(); // ǷSARļ - QString OutputClsSARRaster = this->ui->OutputClsSARRasterLineEdit->text();// رǷSARļ + //QString OutputClsSARRaster = this->ui->OutputClsSARRasterLineEdit->text();// رǷSARļ - // ļļĴСļĴСһ£ļļļ - gdalImage IncAngle(IncAngleRaster); - QFile::copy(IncAngleRaster, OutputTerrianRaster); - gdalImage OutputTerrian(OutputTerrianRaster); - Eigen::MatrixXd IncAngleData = IncAngle.getData(0, 0, IncAngle.height, IncAngle.width,1); - Eigen::MatrixXd SigmaSARData = MuhlemanSigmaArray(IncAngleData); - - OutputTerrian.saveImage(SigmaSARData, 0, 0, 1); + gdalImage incAngleImg(IncAngleRaster); + gdalImage landImg(LandClsRaster); + gdalImage weightImg(ClsWeightRaster); + gdalImage OutputTerrian=CreategdalImage(OutputTerrianRaster, incAngleImg.height, incAngleImg.width, 1, incAngleImg.gt, 4326, GDT_Float32, true, true); - if (QFile(LandClsRaster).exists()) { + // ֿ incAngleImg landImg weightImgÿδ100 + int blockSize = 100; + int numRows = incAngleImg.height; + int numCols = incAngleImg.width; - QFile::copy(IncAngleRaster, OutputClsSARRaster); - gdalImage OutputClsSAR(OutputClsSARRaster); - gdalImage LandCls(LandClsRaster); - SigmaDatabase sigmads; - sigmads.readParamsFromFile(ClsWeightRaster.toStdString()); - Eigen::MatrixXd LandClsData = LandCls.getData(0, 0, LandCls.height, LandCls.width,1); + double calibration = 0; + bool flag = false; + for (int row = 0; row < numRows; row += blockSize) { + int numRowsToProcess = std::min(blockSize, numRows - row); - Eigen::MatrixXd SigmaSARDataCls = SigmaSARData; - for (long i = 0; i < LandClsData.rows(); i++) - { - for (long j = 0; j < LandClsData.cols(); j++) - { - double weight = sigmads.getAmpHH(LandClsData(i, j), IncAngleData(i, j) * d2r); - SigmaSARDataCls(i, j) = std::pow(10.0, weight / 20.0); + Eigen::MatrixXd incAngleData = incAngleImg.getData(row, 0, numRowsToProcess, numCols, 1); + Eigen::MatrixXd landData = landImg.getData(row, 0, numRowsToProcess, numCols, 1); + Eigen::MatrixXd weightData = weightImg.getData(row, 0, numRowsToProcess, numCols, 1); + + //qDebug() << "(0,0)" << incAngleData(0, 2); + + for (int i = 0; i < incAngleData.rows(); i++) { + for (int j = 0; j < incAngleData.cols(); j++) { + double weight = weightData(i, j); + double incAngle = incAngleData(i, j); + double weightSIgma = weight* sin(38 * d2r) / sin(incAngle * d2r); + + double muhsigmaAmp=calculate_MuhlemanSigma(incAngle); + if ((landData(i, j) == 10|| std::abs(landData(i, j) - 10)<10|| + landData(i, j) == 30 || std::abs(landData(i, j) - 30) < 10 || + landData(i, j) == 90 || std::abs(landData(i, j) -90) < 10 + )&&!isnan(incAngle)&&!isinf(incAngle)) { + //qDebug() << "muhsigmaAmp:" << muhsigmaAmp << "weightSIgma:" << weightSIgma << "weight:" << weight << "incAngle:" << incAngle; + calibration= (10 * log10(muhsigmaAmp))/ weightSIgma ; + if (!isinf(calibration) && !isnan(calibration)) + { + flag = true; + break; + } + } + else { + //alibration = weightSIgma / (10 * log10(muhsigmaAmp)); + } + } } - OutputClsSAR.saveImage(SigmaSARDataCls, 0, 0, 1); + + if (flag) { + break; + } + + } + + + + for (int row = 0; row < numRows; row += blockSize) { + int numRowsToProcess = std::min(blockSize, numRows - row); + + Eigen::MatrixXd incAngleData = incAngleImg.getData(row, 0, numRowsToProcess, numCols, 1); + Eigen::MatrixXd landData = landImg.getData(row, 0, numRowsToProcess, numCols, 1); + Eigen::MatrixXd weightData = weightImg.getData(row, 0, numRowsToProcess, numCols, 1); + Eigen::MatrixXd OutputTerrianData = OutputTerrian.getData(row, 0, numRowsToProcess, numCols, 1); + + for (int i = 0; i < incAngleData.rows(); i++) { + for (int j = 0; j < incAngleData.cols(); j++) { + double weight = weightData(i, j); + double incAngle = incAngleData(i, j); + double weightSIgma = weight * sin(38 * d2r) / sin(incAngle * d2r)* calibration; + double amp = std::pow(10, weightSIgma / 20); + OutputTerrianData(i, j) = amp; + } + } + + OutputTerrian.saveImage(OutputTerrianData, row, 0, 1); } - else {} + + + + //// ļļĴСļĴСһ£ļļļ + //gdalImage IncAngle(IncAngleRaster); + // + + //// createImageļ + //gdalImage OutputTerrian=CreategdalImage(OutputTerrianRaster, IncAngle.height, IncAngle.width, 1, IncAngle.gt, 4326, GDT_Float32, true, true); + // + //Eigen::MatrixXd IncAngleData = IncAngle.getData(0, 0, IncAngle.height, IncAngle.width,1); + //Eigen::MatrixXd SigmaSARData = MuhlemanSigmaArray(IncAngleData); + // + //OutputTerrian.saveImage(SigmaSARData, 0, 0, 1); + + + + //if (QFile(LandClsRaster).exists()) { + + // QFile::copy(OutputTerrianRaster, OutputClsSARRaster); + // gdalImage OutputClsSAR(OutputClsSARRaster); + // gdalImage LandCls(LandClsRaster); + // SigmaDatabase sigmads; + // sigmads.readParamsFromFile(ClsWeightRaster.toStdString()); + // Eigen::MatrixXd LandClsData = LandCls.getData(0, 0, LandCls.height, LandCls.width,1); + + // Eigen::MatrixXd SigmaSARDataCls = SigmaSARData; + // for (long i = 0; i < LandClsData.rows(); i++) + // { + // for (long j = 0; j < LandClsData.cols(); j++) + // { + // double weight = sigmads.getAmpHH(LandClsData(i, j), IncAngleData(i, j) * d2r); + // SigmaSARDataCls(i, j) = weight; + // } + // } + // OutputClsSAR.saveImage(SigmaSARDataCls, 0, 0, 1); + //} + //else {} + + + + QMessageBox::information(nullptr, u8"ʾ", u8"completed!!!"); } diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.ui b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.ui index 7f561ce..43dd894 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.ui +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.ui @@ -6,8 +6,8 @@ 0 0 - 451 - 400 + 810 + 604 @@ -23,71 +23,6 @@ QFrame::Raised - - - - - 0 - 30 - - - - 入射角影像: - - - - - - - - 0 - 30 - - - - D:\FZSimulation\LT1A\L20250210\LT1_Simulation_OrbitModel.xml - - - - - - - - 0 - 30 - - - - 选择 - - - - - - - - 0 - 30 - - - - 地表覆盖影像: - - - - - - - - 0 - 30 - - - - - - - @@ -101,71 +36,6 @@ - - - - - 0 - 30 - - - - 权重文件: - - - - - - - - 0 - 30 - - - - - - - - - - - - 0 - 30 - - - - 选择 - - - - - - - - 0 - 30 - - - - 输出地形仿真: - - - - - - - - 0 - 30 - - - - - - - @@ -179,8 +49,8 @@ - - + + 0 @@ -188,12 +58,12 @@ - 输出地类仿真影像: + D:/FZSimulation/LT1A/L20250210/Looktable/LT1A_2025021_simualtion_terrian.tif - - + + 0 @@ -201,12 +71,80 @@ - D:\FZSimulation\LT1A\L20250210\LT1_Simulation_Setting.xml + 输出地形仿真: + + + + + + + + 0 + 30 + + + + D:/FZSimulation/LT1A/L20250210/Looktable/LT1A_20250210_incAngle.bin + + false + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + D:/FZSimulation/LT1A/n48_25_2020lc030_WGS84_aligned.tif + + + + + + + + 0 + 30 + + + + 地表覆盖影像: + + + + + + + + 0 + 30 + + + + 权重文件: + + + + + 0 @@ -218,6 +156,77 @@ + + + + + 0 + 30 + + + + 选择 + + + + + + + false + + + + 0 + 30 + + + + + + + + + + + false + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 入射角影像: + + + + + + + + 0 + 30 + + + + D:/FZSimulation/LT1A/S1GBM_Merge_aligned.tif + + + diff --git a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp index 1dd1b00..8286a6b 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp @@ -286,11 +286,11 @@ ErrorCode TBPImageAlgCls::ProcessGPU() size_t prfcount = L0ds->getPluseCount(); size_t freqpoints = L0ds->getPlusePoints(); - size_t block_pfrcount = Memory1MB / freqpoints / 8 * 2000;// 4GB -- 可以分配内存 + size_t block_pfrcount = Memory1GB / freqpoints / 8 * 2;// 4GB -- 可以分配内存 size_t img_rowCont = L1ds->getrowCount(); size_t img_colCont = L1ds->getcolCount(); - size_t block_imgRowCount = Memory1MB / img_colCont / 8 / 3 * 2000;// 4GB-- 可以分配内存 + size_t block_imgRowCount = Memory1GB / img_colCont / 8 / 3 * 1;// 4GB-- 可以分配内存 gdalImage demgridimg(imgXYZPath); gdalImageComplex im_finalds(outimgDataPath); diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index f4d8472..e87bda5 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -124,6 +124,7 @@ true stdcpp14 stdc11 + false true From 151d878e61ed6cd2896e74df5712c1f19c1da209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Fri, 14 Mar 2025 19:43:25 +0800 Subject: [PATCH 13/94] =?UTF-8?q?=E4=B8=BA=E9=AB=98=E8=BD=A820=E7=B1=B3?= =?UTF-8?q?=E5=87=86=E5=A4=87=EF=BC=8C=E4=B8=A4=E8=A1=8C=E6=A0=B9=E6=95=B0?= =?UTF-8?q?=E7=94=9F=E6=88=90=E8=BD=A8=E9=81=93=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SPG4Tool/SPG4Function.cpp | 6 + SPG4Tool/SPG4Function.h | 6 +- SPG4Tool/SPG4Tool.vcxproj.filters | 3 + Toolbox/BaseToolbox/BaseToolbox.cpp | 18 ++ Toolbox/BaseToolbox/BaseToolbox.h | 11 + Toolbox/BaseToolbox/BaseToolbox.vcxproj | 8 +- .../BaseToolbox/BaseToolbox.vcxproj.filters | 9 + .../BaseToolbox/QtCreateGPSPointsDialog.cpp | 136 +++++++++++ .../BaseToolbox/QtCreateGPSPointsDialog.h | 26 +++ .../BaseToolbox/QtCreateGPSPointsDialog.ui | 217 ++++++++++++++++++ .../SimulationSAR/QImageSARRFPC.cpp | 2 +- 11 files changed, 435 insertions(+), 7 deletions(-) create mode 100644 Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.cpp create mode 100644 Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.h create mode 100644 Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui diff --git a/SPG4Tool/SPG4Function.cpp b/SPG4Tool/SPG4Function.cpp index 7fb0c3d..3cfacc3 100644 --- a/SPG4Tool/SPG4Function.cpp +++ b/SPG4Tool/SPG4Function.cpp @@ -130,6 +130,12 @@ std::vector RunTle(libsgp4::Tle tle, double start, double end, return resultpos; } +SPG4TOOL_EXPORT std::vector getGPSPoints(std::string line1, std::string line2, double start, double end, double inc, bool printfinfoflag) +{ + libsgp4::Tle tle("GF3", line1, line2); + return RunTle( tle, start, end, inc, printfinfoflag); +} + diff --git a/SPG4Tool/SPG4Function.h b/SPG4Tool/SPG4Function.h index 70c8ebd..92dd453 100644 --- a/SPG4Tool/SPG4Function.h +++ b/SPG4Tool/SPG4Function.h @@ -2,16 +2,12 @@ #ifndef __SPG4FUNCTION__H__ #define __SPG4FUNCTION__H__ #include "SPG4Tool_global.h" -#include "Tle.h" -#include "SGP4.h" -#include "Observer.h" #include "BaseConstVariable.h" #include //void RunTle(libsgp4::Tle tle, double start, double end, double inc); -SPG4TOOL_EXPORT std::vector RunTle(libsgp4::Tle tle, double start, double end, double inc,bool printfinfoflag=false); - +SPG4TOOL_EXPORT std::vector getGPSPoints(std::string line1, std::string line2, double start, double end, double inc, bool printfinfoflag = false); #endif diff --git a/SPG4Tool/SPG4Tool.vcxproj.filters b/SPG4Tool/SPG4Tool.vcxproj.filters index cfa82a2..2f2687e 100644 --- a/SPG4Tool/SPG4Tool.vcxproj.filters +++ b/SPG4Tool/SPG4Tool.vcxproj.filters @@ -133,5 +133,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Toolbox/BaseToolbox/BaseToolbox.cpp b/Toolbox/BaseToolbox/BaseToolbox.cpp index 58ad050..1bad4fa 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox.cpp @@ -12,6 +12,7 @@ #include "QConvertCoordinateSystemDialog.h" #include "QResampleRefrenceRaster.h" #include "QtLookTableCorrectOffsetDialog.h" +#include "QtCreateGPSPointsDialog.h" GF3ImportDataToolButton::GF3ImportDataToolButton(QWidget* parent) :QToolAbstract(parent) { @@ -113,6 +114,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QConvertCoordinateSystemToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QResampleRefrenceRasterToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QLookTableCorrectOffsetToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QCreateGPSPointsToolButton(toolbox)); } QDEMResampleDialogToolButton::QDEMResampleDialogToolButton(QWidget* parent) @@ -197,4 +199,20 @@ void QLookTableCorrectOffsetToolButton::excute() { QtLookTableCorrectOffsetDialog* dialog = new QtLookTableCorrectOffsetDialog; dialog->show(); +} + +QCreateGPSPointsToolButton::QCreateGPSPointsToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8""); + this->toolname = QString(u8"иɹڵ"); +} + +QCreateGPSPointsToolButton::~QCreateGPSPointsToolButton() +{ +} +void QCreateGPSPointsToolButton::excute() +{ + QtCreateGPSPointsDialog* dialog = new QtCreateGPSPointsDialog; + dialog->show(); } \ No newline at end of file diff --git a/Toolbox/BaseToolbox/BaseToolbox.h b/Toolbox/BaseToolbox/BaseToolbox.h index 45749b3..5c15ea7 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.h +++ b/Toolbox/BaseToolbox/BaseToolbox.h @@ -121,4 +121,15 @@ public slots: + +class BASETOOLBOX_EXPORT QCreateGPSPointsToolButton : public QToolAbstract { + Q_OBJECT +public: + QCreateGPSPointsToolButton(QWidget* parent = nullptr); + ~QCreateGPSPointsToolButton(); +public slots: + virtual void excute() override; + +}; + extern "C" BASETOOLBOX_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); diff --git a/Toolbox/BaseToolbox/BaseToolbox.vcxproj b/Toolbox/BaseToolbox/BaseToolbox.vcxproj index b7ee469..5384b55 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.vcxproj +++ b/Toolbox/BaseToolbox/BaseToolbox.vcxproj @@ -103,7 +103,7 @@ - ..\..\BaseCommonLibrary;..\..\BaseCommonLibrary\BaseTool;..\..\BaseCommonLibrary\ToolAbstract;..\..\GPUBaseLib\GPUTool;.\BaseToolbox;..\..\RasterMainWidgetGUI\RasterMainWidget;..\..\RasterMainWidgetGUI;..\..\RasterProcessToolWidget;$(VC_IncludePath);$(WindowsSDK_IncludePath) + ..\..\BaseCommonLibrary;..\..\BaseCommonLibrary\BaseTool;..\..\BaseCommonLibrary\ToolAbstract;..\..\GPUBaseLib\GPUTool;.\BaseToolbox;..\..\RasterMainWidgetGUI\RasterMainWidget;..\..\RasterMainWidgetGUI;..\..\SPG4Tool;..\..\RasterProcessToolWidget;$(VC_IncludePath);$(WindowsSDK_IncludePath) $(SolutionDir)$(Platform)\$(Configuration)\Toolbox\ PluginTool_$(ProjectName) true @@ -205,6 +205,7 @@ + @@ -223,6 +224,7 @@ + @@ -242,6 +244,7 @@ + @@ -257,6 +260,9 @@ {7ef67daa-dbc0-4b7f-80e8-11b4d2cb7ec2} + + {80a5854f-6f80-4ec2-9f73-84e0f4db8d7e} + diff --git a/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters b/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters index 6302cc9..03e37b6 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters +++ b/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters @@ -103,6 +103,9 @@ BaseToolbox + + BaseToolbox + @@ -141,6 +144,9 @@ BaseToolbox + + BaseToolbox + @@ -176,5 +182,8 @@ BaseToolbox + + BaseToolbox + \ No newline at end of file diff --git a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.cpp b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.cpp new file mode 100644 index 0000000..6afbf3d --- /dev/null +++ b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.cpp @@ -0,0 +1,136 @@ +#include "QtCreateGPSPointsDialog.h" +#include "ui_QtCreateGPSPointsDialog.h" +#include +#include +#include +#include +#include +#include +#include +#include "SPG4Function.h" + + +QtCreateGPSPointsDialog::QtCreateGPSPointsDialog(QWidget *parent) + : QDialog(parent),ui(new Ui::QtCreateGPSPointsDialogClass) +{ + ui->setupUi(this); + + // ؼ󶨲ۺ + connect(ui->LTESelectBtn, SIGNAL(clicked()), this, SLOT(onLTESelectBtnClicked())); + connect(ui->outGPSxmlSelectBtn, SIGNAL(clicked()), this, SLOT(onoutGPSxmlSelectBtnClicked())); + connect(ui->dialogBtn, SIGNAL(accepted()), this, SLOT(onaccepted())); + connect(ui->dialogBtn, SIGNAL(rejected()), this, SLOT(onrejected())); + + +} + +QtCreateGPSPointsDialog::~QtCreateGPSPointsDialog() +{} + +void QtCreateGPSPointsDialog::onLTESelectBtnClicked() +{ + QString fileName = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡӰļ"), // + QString(), // Ĭ· + tr(u8"TLE File(*.TLE);;Txt File(*.txt);;All File(*,*)") // ļ + ); + + // ûѡļ + if (!fileName.isEmpty()) { + this->ui->lineEditLTE->setText(fileName); + + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QtCreateGPSPointsDialog::onoutGPSxmlSelectBtnClicked() +{ + QString fileName = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡӰļ"), // + QString(), // Ĭ· + tr(u8"xml Files (*.xml)") // ļ + ); + + // ûѡļ + if (!fileName.isEmpty()) { + this->ui->outGPSxmlSelectBtn->setText(fileName); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QtCreateGPSPointsDialog::onaccepted() +{ + QString inLTEPath = this->ui->lineEditLTE->text(); + QString outGPSxmlPath = this->ui->outGPSxmlSelectBtn->text(); + + double start = this->ui->StartimedateTimeEdit->dateTime().toTime_t(); + double end = this->ui->EndimedateTimeEdit->dateTime().toTime_t(); + + long gpsoint = this->ui->spinBoxGPSPoints->value(); + + qDebug() << "inLTEPath:" << inLTEPath; + qDebug() << "outGPSxmlPath:" << outGPSxmlPath; + qDebug() << "start:" << start << " str:" << this->ui->StartimedateTimeEdit->text(); + qDebug() << "end:" << end << " str:" << this->ui->EndimedateTimeEdit->text(); + qDebug() << "gpsoint:" << gpsoint; + + // ȡTLEļ + std::ifstream ifs(inLTEPath.toLocal8Bit().constData()); + if (!ifs.is_open()) { + QMessageBox::warning(this, tr(u8"ʾ"), tr(u8"open file failed!!")); + return; + } + + // ȡTLEļ + std::string line; + std::string tle1, tle2; + while (std::getline(ifs, line)) { + if (line.find("1 ") != std::string::npos) { + tle1 = line; + } + else if (line.find("2 ") != std::string::npos) { + tle2 = line; + } + } + + ifs.close(); + std::vector gpspoints = getGPSPoints(tle1, tle2, start, end, gpsoint, true); + + + // GPS + std::ofstream ofs(outGPSxmlPath.toLocal8Bit().constData()); + if (!ofs.is_open()) { + QMessageBox::warning(this, tr(u8"ʾ"), tr(u8"open file failed!!")); + return; + } + + ofs << "\n\n"; + for (const auto& point : gpspoints) { + ofs << "\n"; + ofs << "" << QDateTime::fromTime_t(point.time).toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString() << "\n"; + ofs << "" << point.Px << "\n"; + ofs << "" << point.Py << "\n"; + ofs << "" << point.Pz << "\n"; + ofs << "" << point.Vx << "\n"; + ofs << "" << point.Vy << "\n"; + ofs << "" << point.Vz << "\n"; + ofs << "\n"; + } + ofs << "\n\n"; + + ofs.close(); + + QMessageBox::warning(this, tr(u8"ʾ"), tr(u8"completed!!")); + +} + +void QtCreateGPSPointsDialog::onrejected() +{ + this->close(); +} diff --git a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.h b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.h new file mode 100644 index 0000000..760153a --- /dev/null +++ b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.h @@ -0,0 +1,26 @@ +#pragma once +#include "BaseConstVariable.h" +#include + +namespace Ui { + class QtCreateGPSPointsDialogClass; +} + +class QtCreateGPSPointsDialog : public QDialog +{ + Q_OBJECT + +public: + QtCreateGPSPointsDialog(QWidget *parent = nullptr); + ~QtCreateGPSPointsDialog(); + + +public slots: + void onLTESelectBtnClicked(); + void onoutGPSxmlSelectBtnClicked(); + void onaccepted(); + void onrejected(); + +private: + Ui::QtCreateGPSPointsDialogClass* ui; +}; diff --git a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui new file mode 100644 index 0000000..17987d2 --- /dev/null +++ b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui @@ -0,0 +1,217 @@ + + + QtCreateGPSPointsDialogClass + + + + 0 + 0 + 600 + 248 + + + + QtCreateGPSPointsDialog + + + + + + + 0 + 30 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + 参数 + + + + + + + 0 + 30 + + + + 轨道起始时间 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 160 + 30 + + + + yyyy/M/d H:mm:ss.zzz + + + + + + + + 160 + 30 + + + + QDateTimeEdit::YearSection + + + yyyy/M/d H:mm:ss.zzz + + + + + + + + 0 + 30 + + + + 轨道结束时间 + + + + + + + + 0 + 30 + + + + 轨道节点数 + + + + + + + + 0 + 30 + + + + 1000 + + + + + + + + + + + 0 + 30 + + + + 两行根数: + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + GPS节点: + + + + + + + + 0 + 30 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.cpp b/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.cpp index 4e93059..a1cc69f 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.cpp @@ -8,7 +8,7 @@ QImageSARRFPC::QImageSARRFPC(QWidget *parent) - : QDialog(parent) + : QDialog(parent), ui(new Ui::QImageSARRFPCClass) { ui->setupUi(this); From 2c7e64e3701ed803f591c20fd31946102e7d71e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sat, 15 Mar 2025 17:14:17 +0800 Subject: [PATCH 14/94] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=A4=E8=A1=8C?= =?UTF-8?q?=E6=A0=B9=E6=95=B0=E5=88=9B=E5=BB=BA=E5=8D=AB=E6=98=9F=E8=BD=A8?= =?UTF-8?q?=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SPG4Tool/SPG4Function.cpp | 59 +++++++++++++++---- SPG4Tool/SPG4Function.h | 16 ++++- SPG4Tool/SPG4Tool.h | 13 ++++ SPG4Tool/SPG4Tool.vcxproj | 4 +- SPG4Tool/SPG4Tool.vcxproj.filters | 3 + .../BaseToolbox/QtCreateGPSPointsDialog.cpp | 38 ++++++++---- .../BaseToolbox/QtCreateGPSPointsDialog.ui | 23 ++++++++ 7 files changed, 130 insertions(+), 26 deletions(-) create mode 100644 SPG4Tool/SPG4Tool.h diff --git a/SPG4Tool/SPG4Function.cpp b/SPG4Tool/SPG4Function.cpp index 3cfacc3..99dac1e 100644 --- a/SPG4Tool/SPG4Function.cpp +++ b/SPG4Tool/SPG4Function.cpp @@ -1,4 +1,5 @@ #include "SPG4Function.h" +#include "SPG4Tool.h" #include #include #include @@ -12,16 +13,23 @@ #include #include #include +#include +#include -std::vector RunTle(libsgp4::Tle tle, double start, double end, double inc, bool printfinfoflag) +std::vector RunTle(libsgp4::Tle tle, double start, double end, double inc, bool printfinfoflag, bool running, bool first_run) { + std::cout << "RunTle\t" ; + std::cout << "Start time:\t" << start; + std::cout << "End time:\t" << end; + std::cout << "inc time:\t" << inc << std::endl; + std::vector resultpos(0); double current = start; libsgp4::SGP4 model(tle); - bool running = true; - bool first_run = true; + //bool running = true; + //bool first_run = true; std::cout << std::setprecision(0) << tle.NoradNumber() << " xx" << std::endl; @@ -53,16 +61,17 @@ std::vector RunTle(libsgp4::Tle tle, double start, double end, libsgp4::Eci eci = model.FindPosition(tsince); position = eci.Position(); velocity = eci.Velocity(); + } catch (libsgp4::SatelliteException& e) { - std::cerr << e.what() << std::endl; + std::cerr << "SatelliteException:\t" << e.what() << std::endl; error = true; running = false; } catch (libsgp4::DecayedException& e) { - std::cerr << e.what() << std::endl; + std::cerr <<"DecayedException:\t" << e.what() << std::endl; position = e.Position(); velocity = e.Velocity(); @@ -83,8 +92,8 @@ std::vector RunTle(libsgp4::Tle tle, double start, double end, antpos.Px = position.x; antpos.Py = position.y; antpos.Pz = position.z; - antpos.Vx = velocity.z; - antpos.Vy = velocity.z; + antpos.Vx = velocity.x; + antpos.Vy = velocity.y; antpos.Vz = velocity.z; resultpos.push_back(antpos); @@ -114,7 +123,7 @@ std::vector RunTle(libsgp4::Tle tle, double start, double end, { running = false; } - else if (current + inc > end) + else if ((current + inc) > end) { current = end; } @@ -130,12 +139,40 @@ std::vector RunTle(libsgp4::Tle tle, double start, double end, return resultpos; } -SPG4TOOL_EXPORT std::vector getGPSPoints(std::string line1, std::string line2, double start, double end, double inc, bool printfinfoflag) +std::vector getGPSPoints(std::string line1, std::string line2, double start, double end, double inc, bool printfinfoflag, bool running , bool first_run ) { - libsgp4::Tle tle("GF3", line1, line2); - return RunTle( tle, start, end, inc, printfinfoflag); + libsgp4::Tle tle("satellites", line1, line2); + std::cout << "Start time:\t" << start; + std::cout << "End time:\t" << end; + std::cout << "inc time:\t" << inc << std::endl; + std::vector result= RunTle(tle, start, end, inc, printfinfoflag); + return result; } +double parseTLETimeOffset(const std::string& tle) { + // TLEַʱϢضλ + // 磬TLEĵ1932ַʾԪʱ + if (tle.length() < 32) { + return 0.0; + } + std::string epochStr = tle.substr(18, 14); + int year = std::stoi(epochStr.substr(0, 2)); + double dayOfYear = std::stod(epochStr.substr(2)); + // λתΪλ + if (year < 57) { + year += 2000; + } + else { + year += 1900; + } + + // ӼԪʼָڵĺ + QDate date(year, 1, 1); + QDateTime dateTime(date.addDays(static_cast(dayOfYear) - 1), QTime(0, 0), Qt::UTC); + qint64 millisecondsSinceEpoch = dateTime.toMSecsSinceEpoch() + static_cast((dayOfYear - static_cast(dayOfYear)) * 86400000); + + return millisecondsSinceEpoch / 1000.0; +} diff --git a/SPG4Tool/SPG4Function.h b/SPG4Tool/SPG4Function.h index 92dd453..c9c8b81 100644 --- a/SPG4Tool/SPG4Function.h +++ b/SPG4Tool/SPG4Function.h @@ -8,6 +8,18 @@ //void RunTle(libsgp4::Tle tle, double start, double end, double inc); - -SPG4TOOL_EXPORT std::vector getGPSPoints(std::string line1, std::string line2, double start, double end, double inc, bool printfinfoflag = false); +SPG4TOOL_EXPORT double parseTLETimeOffset(const std::string& tle); +/// +/// иٶȣעⷵصĵλ km +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +SPG4TOOL_EXPORT std::vector getGPSPoints(std::string line1, std::string line2, double start, double end, double inc, bool printfinfoflag = false, bool running = true, bool first_run = true); #endif diff --git a/SPG4Tool/SPG4Tool.h b/SPG4Tool/SPG4Tool.h new file mode 100644 index 0000000..40103f3 --- /dev/null +++ b/SPG4Tool/SPG4Tool.h @@ -0,0 +1,13 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include "BaseConstVariable.h" + + +std::vector RunTle(libsgp4::Tle tle, double start, double end, double inc, bool printfinfoflag, bool running = true, bool first_run = true); diff --git a/SPG4Tool/SPG4Tool.vcxproj b/SPG4Tool/SPG4Tool.vcxproj index 6b55812..878cdae 100644 --- a/SPG4Tool/SPG4Tool.vcxproj +++ b/SPG4Tool/SPG4Tool.vcxproj @@ -67,6 +67,7 @@ _CRT_SECURE_NO_WARNINGS;SPG4TOOL_LIB;%(PreprocessorDefinitions) + false @@ -92,7 +93,7 @@ Console - false + DebugFull true true @@ -135,6 +136,7 @@ + diff --git a/SPG4Tool/SPG4Tool.vcxproj.filters b/SPG4Tool/SPG4Tool.vcxproj.filters index 2f2687e..e658568 100644 --- a/SPG4Tool/SPG4Tool.vcxproj.filters +++ b/SPG4Tool/SPG4Tool.vcxproj.filters @@ -136,5 +136,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.cpp b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.cpp index 6afbf3d..0aca402 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.cpp @@ -57,7 +57,7 @@ void QtCreateGPSPointsDialog::onoutGPSxmlSelectBtnClicked() // ûѡļ if (!fileName.isEmpty()) { - this->ui->outGPSxmlSelectBtn->setText(fileName); + this->ui->lineEditoutGPSxml->setText(fileName); } else { QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); @@ -67,7 +67,7 @@ void QtCreateGPSPointsDialog::onoutGPSxmlSelectBtnClicked() void QtCreateGPSPointsDialog::onaccepted() { QString inLTEPath = this->ui->lineEditLTE->text(); - QString outGPSxmlPath = this->ui->outGPSxmlSelectBtn->text(); + QString outGPSxmlPath = this->ui->lineEditoutGPSxml->text(); double start = this->ui->StartimedateTimeEdit->dateTime().toTime_t(); double end = this->ui->EndimedateTimeEdit->dateTime().toTime_t(); @@ -100,9 +100,20 @@ void QtCreateGPSPointsDialog::onaccepted() } ifs.close(); - std::vector gpspoints = getGPSPoints(tle1, tle2, start, end, gpsoint, true); + // иʱƫ + // tle1tle2ʱϢҿԽΪʱƫ + double tle1TimeOffset = parseTLETimeOffset(tle1); + //double tle2TimeOffset = parseTLETimeOffset(tle2); + start = start- tle1TimeOffset; + end = end- tle1TimeOffset; + + double inc = (end - start) / (gpsoint-1); + + std::vector gpspoints = getGPSPoints(tle1, tle2, start, end, inc, true,true,false); + + qDebug() << "create gpspoints size:" << gpspoints.size(); // GPS std::ofstream ofs(outGPSxmlPath.toLocal8Bit().constData()); if (!ofs.is_open()) { @@ -111,19 +122,19 @@ void QtCreateGPSPointsDialog::onaccepted() } ofs << "\n\n"; - for (const auto& point : gpspoints) { + for (const auto& point : gpspoints) { // ŵλ ofs << "\n"; - ofs << "" << QDateTime::fromTime_t(point.time).toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString() << "\n"; - ofs << "" << point.Px << "\n"; - ofs << "" << point.Py << "\n"; - ofs << "" << point.Pz << "\n"; - ofs << "" << point.Vx << "\n"; - ofs << "" << point.Vy << "\n"; - ofs << "" << point.Vz << "\n"; + ofs << "" << QDateTime::fromTime_t(point.time+ tle1TimeOffset).toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString() << "\n"; + ofs << "" << point.Px*1000.0 << "\n"; + ofs << "" << point.Py*1000.0 << "\n"; + ofs << "" << point.Pz*1000.0 << "\n"; + ofs << "" << point.Vx*1000.0 << "\n"; + ofs << "" << point.Vy*1000.0 << "\n"; + ofs << "" << point.Vz*1000.0 << "\n"; ofs << "\n"; } ofs << "\n\n"; - + ofs.flush(); ofs.close(); QMessageBox::warning(this, tr(u8"ʾ"), tr(u8"completed!!")); @@ -134,3 +145,6 @@ void QtCreateGPSPointsDialog::onrejected() { this->close(); } + + + \ No newline at end of file diff --git a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui index 17987d2..027a1d4 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui +++ b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui @@ -71,6 +71,16 @@ 30 + + + 19 + 56 + 21 + 2025 + 3 + 14 + + yyyy/M/d H:mm:ss.zzz @@ -84,6 +94,16 @@ 30 + + + 19 + 55 + 11 + 2025 + 3 + 14 + + QDateTimeEdit::YearSection @@ -129,6 +149,9 @@ 1000 + + 71 + From 65b01a6c13b828c80743bfc0bf18e37b92116f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 16 Mar 2025 00:26:12 +0800 Subject: [PATCH 15/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=87=E5=A2=83?= =?UTF-8?q?=E9=A2=84=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SPG4Tool/PassPredict.cpp | 402 ++++++++++++++++++++++++++++++ SPG4Tool/SPG4Function.h | 6 +- SPG4Tool/SPG4Tool.h | 7 +- SPG4Tool/SPG4Tool.vcxproj | 1 + SPG4Tool/SPG4Tool.vcxproj.filters | 3 + 5 files changed, 417 insertions(+), 2 deletions(-) create mode 100644 SPG4Tool/PassPredict.cpp diff --git a/SPG4Tool/PassPredict.cpp b/SPG4Tool/PassPredict.cpp new file mode 100644 index 0000000..a1148a9 --- /dev/null +++ b/SPG4Tool/PassPredict.cpp @@ -0,0 +1,402 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "SPG4Function.h" + +struct PassDetails +{ + libsgp4::DateTime aos; + libsgp4::DateTime los; + double max_elevation; +}; + +double FindMaxElevation( + const libsgp4::CoordGeodetic& user_geo, + libsgp4::SGP4& sgp4, + const libsgp4::DateTime& aos, + const libsgp4::DateTime& los) +{ + libsgp4::Observer obs(user_geo); + + bool running; + + double time_step = (los - aos).TotalSeconds() / 9.0; + libsgp4::DateTime current_time(aos); //! current time + libsgp4::DateTime time1(aos); //! start time of search period + libsgp4::DateTime time2(los); //! end time of search period + double max_elevation; //! max elevation + + running = true; + + do + { + running = true; + max_elevation = -99999999999999.0; + while (running && current_time < time2) + { + /* + * find position + */ + libsgp4::Eci eci = sgp4.FindPosition(current_time); + libsgp4::CoordTopocentric topo = obs.GetLookAngle(eci); + + if (topo.elevation > max_elevation) + { + /* + * still going up + */ + max_elevation = topo.elevation; + /* + * move time along + */ + current_time = current_time.AddSeconds(time_step); + if (current_time > time2) + { + /* + * dont go past end time + */ + current_time = time2; + } + } + else + { + /* + * stop + */ + running = false; + } + } + + /* + * make start time to 2 time steps back + */ + time1 = current_time.AddSeconds(-2.0 * time_step); + /* + * make end time to current time + */ + time2 = current_time; + /* + * current time to start time + */ + current_time = time1; + /* + * recalculate time step + */ + time_step = (time2 - time1).TotalSeconds() / 9.0; + } while (time_step > 1.0); + + return max_elevation; +} + +libsgp4::DateTime FindCrossingPoint( + const libsgp4::CoordGeodetic& user_geo, + libsgp4::SGP4& sgp4, + const libsgp4::DateTime& initial_time1, + const libsgp4::DateTime& initial_time2, + bool finding_aos) +{ + libsgp4::Observer obs(user_geo); + + bool running; + int cnt; + + libsgp4::DateTime time1(initial_time1); + libsgp4::DateTime time2(initial_time2); + libsgp4::DateTime middle_time; + + running = true; + cnt = 0; + while (running && cnt++ < 16) + { + middle_time = time1.AddSeconds((time2 - time1).TotalSeconds() / 2.0); + /* + * calculate satellite position + */ + libsgp4::Eci eci = sgp4.FindPosition(middle_time); + libsgp4::CoordTopocentric topo = obs.GetLookAngle(eci); + + if (topo.elevation > 0.0) + { + /* + * satellite above horizon + */ + if (finding_aos) + { + time2 = middle_time; + } + else + { + time1 = middle_time; + } + } + else + { + if (finding_aos) + { + time1 = middle_time; + } + else + { + time2 = middle_time; + } + } + + if ((time2 - time1).TotalSeconds() < 1.0) + { + /* + * two times are within a second, stop + */ + running = false; + /* + * remove microseconds + */ + int us = middle_time.Microsecond(); + middle_time = middle_time.AddMicroseconds(-us); + /* + * step back into the pass by 1 second + */ + middle_time = middle_time.AddSeconds(finding_aos ? 1 : -1); + } + } + + /* + * go back/forward 1second until below the horizon + */ + running = true; + cnt = 0; + while (running && cnt++ < 6) + { + libsgp4::Eci eci = sgp4.FindPosition(middle_time); + libsgp4::CoordTopocentric topo = obs.GetLookAngle(eci); + if (topo.elevation > 0) + { + middle_time = middle_time.AddSeconds(finding_aos ? -1 : 1); + } + else + { + running = false; + } + } + + return middle_time; +} + +std::list GeneratePassList( + const libsgp4::CoordGeodetic& user_geo, + libsgp4::SGP4& sgp4, + const libsgp4::DateTime& start_time, + const libsgp4::DateTime& end_time, + const int time_step) +{ + std::list pass_list; + + libsgp4::Observer obs(user_geo); + + libsgp4::DateTime aos_time; + libsgp4::DateTime los_time; + + bool found_aos = false; + + libsgp4::DateTime previous_time(start_time); + libsgp4::DateTime current_time(start_time); + + while (current_time < end_time) + { + bool end_of_pass = false; + + /* + * calculate satellite position + */ + libsgp4::Eci eci = sgp4.FindPosition(current_time); + libsgp4::CoordTopocentric topo = obs.GetLookAngle(eci); + + if (!found_aos && topo.elevation > 0.0) + { + /* + * aos hasnt occured yet, but the satellite is now above horizon + * this must have occured within the last time_step + */ + if (start_time == current_time) + { + /* + * satellite was already above the horizon at the start, + * so use the start time + */ + aos_time = start_time; + } + else + { + /* + * find the point at which the satellite crossed the horizon + */ + aos_time = FindCrossingPoint( + user_geo, + sgp4, + previous_time, + current_time, + true); + } + found_aos = true; + } + else if (found_aos && topo.elevation < 0.0) + { + found_aos = false; + /* + * end of pass, so move along more than time_step + */ + end_of_pass = true; + /* + * already have the aos, but now the satellite is below the horizon, + * so find the los + */ + los_time = FindCrossingPoint( + user_geo, + sgp4, + previous_time, + current_time, + false); + + struct PassDetails pd; + pd.aos = aos_time; + pd.los = los_time; + pd.max_elevation = FindMaxElevation( + user_geo, + sgp4, + aos_time, + los_time); + + pass_list.push_back(pd); + } + + /* + * save current time + */ + previous_time = current_time; + + if (end_of_pass) + { + /* + * at the end of the pass move the time along by 30mins + */ + current_time = current_time + libsgp4::TimeSpan(0, 30, 0); + } + else + { + /* + * move the time along by the time step value + */ + current_time = current_time + libsgp4::TimeSpan(0, 0, time_step); + } + + if (current_time > end_time) + { + /* + * dont go past end time + */ + current_time = end_time; + } + }; + + if (found_aos) + { + /* + * satellite still above horizon at end of search period, so use end + * time as los + */ + struct PassDetails pd; + pd.aos = aos_time; + pd.los = end_time; + pd.max_elevation = FindMaxElevation(user_geo, sgp4, aos_time, end_time); + pass_list.push_back(pd); + } + + return pass_list; +} + + +bool PassPredict(std::vector& aos, std::vector& los, std::string line1, std::string line2, double startTime, double predictDayLen, double lon, double lat, double ati) { + + libsgp4::CoordGeodetic geo(lat, lon, ati); + libsgp4::Tle tle("GALILEO-PFM (GSAT0101) ", + line1, + line2); + libsgp4::SGP4 sgp4(tle); + + std::vector result; + + // double ʱתΪ QDateTime + + QDateTime dateTime = QDateTime::fromSecsSinceEpoch(static_cast(startTime*1000)); + + + libsgp4::DateTime start_date( + dateTime.date().year(), + dateTime.date().month(), + dateTime.date().day(), + dateTime.time().hour(), + dateTime.time().minute(), + dateTime.time().second(), + dateTime.time().msec() * 1000); + + libsgp4::DateTime end_date(start_date.AddDays(predictDayLen)); + + std::list pass_list; + pass_list = GeneratePassList(geo, sgp4, start_date, end_date, 180); + + if (pass_list.begin() == pass_list.end()) + { + return false; + } + else + { + std::stringstream ss; + ss << std::right << std::setprecision(1) << std::fixed; + std::list::const_iterator itr = pass_list.begin(); + do + { + ss << "AOS: " << itr->aos + << ", LOS: " << itr->los + << ", Max El: " << std::setw(4) << libsgp4::Util::RadiansToDegrees(itr->max_elevation) + << ", Duration: " << (itr->los - itr->aos) + << std::endl; + + + // AOSʱ + QDate aosDate(itr->aos.Year(), itr->aos.Month(), itr->aos.Day()); + QTime aosTimePart(itr->aos.Hour(), itr->aos.Minute(), itr->aos.Second(), itr->aos.Microsecond()); + QDateTime aosDateTime(aosDate, aosTimePart, Qt::UTC); // + + // LOSʱ + QDate losDate(itr->los.Year(), itr->los.Month(), itr->los.Day()); + QTime losTimePart(itr->los.Hour(), itr->los.Minute(), itr->los.Second(), itr->los.Microsecond()); + QDateTime losDateTime(losDate, losTimePart, Qt::UTC); // + + aos.push_back(aosDateTime); + los.push_back(losDateTime); + + + + } while (++itr != pass_list.end()); + std::cout << ss.str(); + + return true; + + } + + return false; + +} + + + \ No newline at end of file diff --git a/SPG4Tool/SPG4Function.h b/SPG4Tool/SPG4Function.h index c9c8b81..4e99725 100644 --- a/SPG4Tool/SPG4Function.h +++ b/SPG4Tool/SPG4Function.h @@ -4,10 +4,11 @@ #include "SPG4Tool_global.h" #include "BaseConstVariable.h" #include - +#include //void RunTle(libsgp4::Tle tle, double start, double end, double inc); + SPG4TOOL_EXPORT double parseTLETimeOffset(const std::string& tle); /// /// иٶȣעⷵصĵλ km @@ -22,4 +23,7 @@ SPG4TOOL_EXPORT double parseTLETimeOffset(const std::string& tle); /// /// SPG4TOOL_EXPORT std::vector getGPSPoints(std::string line1, std::string line2, double start, double end, double inc, bool printfinfoflag = false, bool running = true, bool first_run = true); +SPG4TOOL_EXPORT bool PassPredict(std::vector& aos, std::vector& los, std::string line1, std::string line2, double startTime, double predictDayLen, double lon, double lat, double ati); + + #endif diff --git a/SPG4Tool/SPG4Tool.h b/SPG4Tool/SPG4Tool.h index 40103f3..cf443e1 100644 --- a/SPG4Tool/SPG4Tool.h +++ b/SPG4Tool/SPG4Tool.h @@ -8,6 +8,11 @@ #include #include #include "BaseConstVariable.h" - +#include +#include +#include +#include +#include + std::vector RunTle(libsgp4::Tle tle, double start, double end, double inc, bool printfinfoflag, bool running = true, bool first_run = true); diff --git a/SPG4Tool/SPG4Tool.vcxproj b/SPG4Tool/SPG4Tool.vcxproj index 878cdae..1b5bd90 100644 --- a/SPG4Tool/SPG4Tool.vcxproj +++ b/SPG4Tool/SPG4Tool.vcxproj @@ -115,6 +115,7 @@ + diff --git a/SPG4Tool/SPG4Tool.vcxproj.filters b/SPG4Tool/SPG4Tool.vcxproj.filters index e658568..d2d7c1f 100644 --- a/SPG4Tool/SPG4Tool.vcxproj.filters +++ b/SPG4Tool/SPG4Tool.vcxproj.filters @@ -80,6 +80,9 @@ Source Files + + Source Files + From ab2800533a68d3dfd1f1538a7ea63f71723b3ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 16 Mar 2025 03:04:51 +0800 Subject: [PATCH 16/94] =?UTF-8?q?=E6=8F=90=E5=8D=87GPS=E7=82=B9=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=9C=80=E5=A4=A7=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui index 027a1d4..319035a 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui +++ b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui @@ -7,7 +7,7 @@ 0 0 600 - 248 + 259 @@ -147,7 +147,7 @@ - 1000 + 1000000000 71 From 5741dda08ce6bed7221b3e75d732921cbb518e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 16 Mar 2025 14:26:16 +0800 Subject: [PATCH 17/94] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BD=A8=E9=81=93?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E8=B0=83=E7=94=A8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SPG4Tool/SPG4Function.cpp | 2 +- SPG4Tool/SPG4Toolmain.cpp | 10 +++++----- .../BaseToolbox/QtCreateGPSPointsDialog.cpp | 17 ++++++++++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/SPG4Tool/SPG4Function.cpp b/SPG4Tool/SPG4Function.cpp index 99dac1e..dc207cd 100644 --- a/SPG4Tool/SPG4Function.cpp +++ b/SPG4Tool/SPG4Function.cpp @@ -145,7 +145,7 @@ std::vector getGPSPoints(std::string line1, std::string line2, std::cout << "Start time:\t" << start; std::cout << "End time:\t" << end; std::cout << "inc time:\t" << inc << std::endl; - std::vector result= RunTle(tle, start, end, inc, printfinfoflag); + std::vector result= RunTle(tle, start, end, inc, printfinfoflag,running,first_run); return result; } diff --git a/SPG4Tool/SPG4Toolmain.cpp b/SPG4Tool/SPG4Toolmain.cpp index 4faaabe..4b628d4 100644 --- a/SPG4Tool/SPG4Toolmain.cpp +++ b/SPG4Tool/SPG4Toolmain.cpp @@ -8,7 +8,7 @@ #include "CoordTopocentric.h" #include #include "SPG4Function.h" - +#include "SPG4Tool.h" /** ½̽ĺ01ǹ @@ -18,7 +18,7 @@ */ -// + //int main(int argc, char *argv[]) //{ // @@ -28,10 +28,10 @@ // libsgp4::Tle tle("GF3", line1, line2); // // double start = 0; -// double end = 10; -// double inc = 1; +// double end = 1; +// double inc = 1/60.0; // -// RunTle(tle, start, end, inc); +// RunTle(tle, start, end, inc,true); // //QCoreApplication a(argc, argv); // // //return a.exec(); diff --git a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.cpp b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.cpp index 0aca402..797d8f2 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.cpp @@ -69,8 +69,14 @@ void QtCreateGPSPointsDialog::onaccepted() QString inLTEPath = this->ui->lineEditLTE->text(); QString outGPSxmlPath = this->ui->lineEditoutGPSxml->text(); - double start = this->ui->StartimedateTimeEdit->dateTime().toTime_t(); - double end = this->ui->EndimedateTimeEdit->dateTime().toTime_t(); + QDateTime startTime = this->ui->StartimedateTimeEdit->dateTime().toUTC(); + QDateTime endTime = this->ui->EndimedateTimeEdit->dateTime().toUTC(); + + double start = startTime.toTime_t(); + double end = endTime.toTime_t(); + // תΪutcʱ + + long gpsoint = this->ui->spinBoxGPSPoints->value(); @@ -111,6 +117,11 @@ void QtCreateGPSPointsDialog::onaccepted() double inc = (end - start) / (gpsoint-1); + start = start / 60.0; // תΪ + end = end / 60.0; + inc = inc / 60.0; + + std::vector gpspoints = getGPSPoints(tle1, tle2, start, end, inc, true,true,false); qDebug() << "create gpspoints size:" << gpspoints.size(); @@ -124,7 +135,7 @@ void QtCreateGPSPointsDialog::onaccepted() ofs << "\n\n"; for (const auto& point : gpspoints) { // ŵλ ofs << "\n"; - ofs << "" << QDateTime::fromTime_t(point.time+ tle1TimeOffset).toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString() << "\n"; + ofs << "" << QDateTime::fromTime_t(point.time*60.0+ tle1TimeOffset, Qt::UTC).toLocalTime().toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString() << "\n"; ofs << "" << point.Px*1000.0 << "\n"; ofs << "" << point.Py*1000.0 << "\n"; ofs << "" << point.Pz*1000.0 << "\n"; From 6ff1bcc3076ccc245ecc14b286f24b2d83bccddc Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Mon, 17 Mar 2025 01:36:15 +0800 Subject: [PATCH 18/94] =?UTF-8?q?=E5=BC=BA=E5=BA=A6=E4=BB=BF=E7=9C=9F?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseToolbox/QtCreateGPSPointsDialog.ui | 14 +++++++------- .../QtSimulationGeoSARSigma0Dialog.ui | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui index 319035a..4d587b1 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui +++ b/Toolbox/BaseToolbox/BaseToolbox/QtCreateGPSPointsDialog.ui @@ -73,9 +73,9 @@ - 19 - 56 - 21 + 12 + 26 + 24 2025 3 14 @@ -96,9 +96,9 @@ - 19 - 55 - 11 + 12 + 7 + 35 2025 3 14 @@ -150,7 +150,7 @@ 1000000000 - 71 + 1130 diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.ui b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.ui index 43dd894..d24ef89 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.ui +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QtSimulationGeoSARSigma0Dialog.ui @@ -100,7 +100,7 @@ - + @@ -181,7 +181,7 @@ - + @@ -197,7 +197,7 @@ - + From 8dc550fbec74469d3cfd317e0dae00a185c31005 Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Wed, 19 Mar 2025 18:14:09 +0800 Subject: [PATCH 19/94] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A2=91=E7=82=B9?= =?UTF-8?q?=E8=AE=A1=E7=AE=97bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/BaseTool/EchoDataFormat.cpp | 60 ++++++++++++ BaseCommonLibrary/BaseTool/EchoDataFormat.h | 1 + .../SimulationSAR/QImageSARRFPC.ui | 14 +-- .../SimulationSAR/RFPCProcessCls.cpp | 28 +++--- .../SimulationSAR/SigmaDatabase.cpp | 93 +++++++++++-------- .../SimulationSARTool.vcxproj | 1 + 6 files changed, 136 insertions(+), 61 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp b/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp index e78b9d8..b2824ba 100644 --- a/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp +++ b/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp @@ -592,6 +592,66 @@ std::shared_ptr> EchoL0Dataset::getEchoArr(long startPRF, l return temp; } + +std::vector> EchoL0Dataset::getEchoArrVector(long startPRF, long& PRFLen) { + if (!(startPRF < this->PluseCount)) { + qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_PRFIDXOUTRANGE)) << startPRF << " " << this->PluseCount; + return std::vector>(0); + } + else {} + + omp_lock_t lock; + omp_init_lock(&lock); + omp_set_lock(&lock); + std::shared_ptr rasterDataset = OpenDataset(this->echoDataFilePath, 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 std::vector>(0); + } + else {} + long width = rasterDataset->GetRasterXSize(); + long height = rasterDataset->GetRasterYSize(); + long band_num = rasterDataset->GetRasterCount(); + + PRFLen = (PRFLen + startPRF) < height ? PRFLen : height - startPRF; + + std::vector> tempArr(size_t(PRFLen) * width); + if (height != this->PluseCount || width != this->PlusePoints) { + qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_ECHOFILEFORMATERROR)); + } + else { + if (gdal_datatype == GDT_CFloat64) { + std::shared_ptr> temp(new std::complex[PRFLen * width], delArrPtr); + poBand->RasterIO(GF_Read, 0, startPRF, width, PRFLen, temp.get(), width, PRFLen, GDT_CFloat64, 0, 0); + GDALFlushCache((GDALDatasetH)rasterDataset.get()); + + + for (long i = 0; i < PRFLen; i++){ + for (long j = 0; j < width; j++){ + tempArr[i * width + j] = temp.get()[i * width + j]; + } + } + + } + else { + qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::ECHO_L0DATA_ECHOFILEFORMATERROR)); + } + } + + rasterDataset.reset(); + omp_unset_lock(&lock); // + omp_destroy_lock(&lock); // + return tempArr; +} + + std::shared_ptr> EchoL0Dataset::getEchoArr() { return this->getEchoArr(0,this->PluseCount); diff --git a/BaseCommonLibrary/BaseTool/EchoDataFormat.h b/BaseCommonLibrary/BaseTool/EchoDataFormat.h index ca0e5ce..749843f 100644 --- a/BaseCommonLibrary/BaseTool/EchoDataFormat.h +++ b/BaseCommonLibrary/BaseTool/EchoDataFormat.h @@ -212,6 +212,7 @@ public: std::shared_ptr getAntPos(); std::shared_ptr> getEchoArr(long startPRF, long& PRFLen); std::shared_ptr> getEchoArr(); + std::vector> getEchoArrVector(long startPRF, long& PRFLen); //ļ ErrorCode saveAntPos(std::shared_ptr ptr); // עΣգдǰǷȷ ErrorCode saveEchoArr(std::shared_ptr> echoPtr, long startPRF, long PRFLen); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui b/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui index 0aa0741..e80d621 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui +++ b/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui @@ -38,7 +38,7 @@ - GF3_Simulation + LT1B_Simulation @@ -51,7 +51,7 @@ - D:/Programme/vs2022/RasterMergeTest/LAMPCAE_SCANE/ + D:/FZSimulation/LT1AB_FZ/Input01/tempEcho @@ -90,7 +90,7 @@ - D:/Programme/vs2022/RasterMergeTest/simulationData/GF3_Simulation_Setting.xml + D:/FZSimulation/LT1AB_FZ/Input01/LT1B_Simulation_Setting.xml @@ -103,7 +103,7 @@ - D:/Programme/vs2022/RasterMergeTest/simulationData/demdataset/landcover_aligned2.dat + D:/FZSimulation/LT1AB_FZ/Input01/landacover_Resample.dat @@ -142,7 +142,7 @@ - D:/Programme/vs2022/RasterMergeTest/simulationData/GF3_Simulation_GPSNode.xml + D:/FZSimulation/LT1AB_FZ/Input01/LT1B_GPSPoints.xml @@ -233,7 +233,7 @@ - D:/Programme/vs2022/RasterMergeTest/simulationData/demdataset/demxyz.bin + D:/FZSimulation/LT1AB_FZ/Input01/ASTGTM2_N28E087_dem_XYZ.dat @@ -350,7 +350,7 @@ - D:/Programme/vs2022/RasterMergeTest/simulationData/demdataset/demsloper.bin + D:/FZSimulation/LT1AB_FZ/Input01/ASTGTM2_N28E087_dem_Sloper.dat diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 092eda3..97aaade 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1,5 +1,6 @@  #include "stdafx.h" +#include #include "RFPCProcessCls.h" #include "BaseConstVariable.h" #include "SARSatelliteSimulationAbstractCls.h" @@ -333,7 +334,11 @@ ErrorCode RFPCProcessCls::InitParams() // 远斜距 //double rangeTimeSample = * 2.0 / LIGHTSPEED; double drange = LIGHTSPEED / 2.0 / this->TaskSetting->getBandWidth(); - this->PlusePoint = ceil((this->TaskSetting->getFarRange() - this->TaskSetting->getNearRange()) / LIGHTSPEED * 2 * this->TaskSetting->getBandWidth()); + QVector freqlist = this->TaskSetting->getFreqList(); + const long freqnum = freqlist.count(); + + + this->PlusePoint = freqnum;// ceil((this->TaskSetting->getFarRange() - this->TaskSetting->getNearRange()) / LIGHTSPEED * 2 * this->TaskSetting->getBandWidth()); this->TaskSetting->setFarRange(this->TaskSetting->getNearRange() + (this->PlusePoint-1) * drange); //ceil(rangeTimeSample * this->TaskSetting->getFs()); @@ -530,18 +535,11 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { /** 参数区域***************************************************/ QVector freqlist = this->TaskSetting->getFreqList(); - long freqnum = freqlist.count(); + const long freqnum = freqlist.count(); + long freqnum_temp = freqnum; float f0 = float(freqlist[0] / 1e9); float dfreq = float((freqlist[1] - freqlist[0]) / 1e9); - -#if (defined __PRFDEBUG__) && (defined __PRFDEBUG_PRFINF__) - double* h_freqPtr = (double*)mallocCUDAHost(sizeof(double) * freqnum); - for (long fid = 0; fid < freqnum; fid++) { - h_freqPtr[fid] = (f0 + dfreq * fid) * 1e9; - } - testOutAmpArr("freqlist.bin", h_freqPtr, freqnum, 1); -#endif - + qDebug() << "freqnum: " << freqnum << " f0: " << f0 << " dfreq: " << dfreq; long PRFCount = this->EchoSimulationData->getPluseCount(); double NearRange = this->EchoSimulationData->getNearRange(); // 近斜距 @@ -556,7 +554,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { double dt = 1 / this->TaskSetting->getPRF();// 获取每次脉冲的时间间隔 bool antflag = true; // 计算天线方向图 long double imageStarttime = this->TaskSetting->getSARImageStartTime(); - + qDebug() << "freqnum: " << freqnum << " f0: " << f0 << " dfreq: " << dfreq << "freqnum_temp: " << freqnum_temp; this->EchoSimulationData->getAntPos(); std::shared_ptr sateOirbtNodes = this->getSatelliteOribtNodes(prf_time, dt, antflag, imageStarttime); @@ -787,9 +785,11 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { COPY_AntStation_FROM_HOST_GPU(sateOirbtNodes, antptrlist, sprfid, PRF_len); - + qDebug() << "freqnum: " << freqnum << " f0: " << f0 << " dfreq: " << dfreq << "freqnum_temp: " << freqnum_temp; qDebug() << "Start PRF: " << sprfid << "\t-\t" << sprfid + PRF_len << "\t:copy echo data list host -> GPU"; std::shared_ptr> echo_temp = this->EchoSimulationData->getEchoArr(sprfid, PRF_len); + + for (long ii = 0; ii < PRF_len; ii++) { for (long jj = 0; jj < freqnum; jj++) { h_echo_block_real[ii * freqnum + jj]=echo_temp.get()[ii * freqnum + jj].real(); @@ -884,7 +884,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { #endif DeviceToHost(h_echo_block_real, d_echo_block_real, sizeof(float) * PRF_len * freqnum); DeviceToHost(h_echo_block_imag, d_echo_block_imag, sizeof(float) * PRF_len * freqnum); - + qDebug() << "freqnum: " << freqnum << " f0: " << f0 << " dfreq: " << dfreq; for (long ii = 0; ii < PRF_len; ii++) { for (long jj = 0; jj < freqnum; jj++) { echo_temp.get()[ii * freqnum + jj].real(h_echo_block_real[ii * freqnum + jj]); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp index 3271027..9d38d40 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp @@ -30,53 +30,66 @@ SigmaDatabase::SigmaDatabase() this->VH_sigmaParam.insert(std::pair(0, SigmaParam{ 0,0,0, 0, 0,0 })); this->VV_sigmaParam.insert(std::pair(0, SigmaParam{ 0,0,0, 0, 0,0 })); - //12 - this->HH_sigmaParam.insert(std::pair(12, SigmaParam{ -21.1019701821713, 9.00621457243906, 6.52932182540331, - 1.11157376729893, - 15.8022895411007, 11.4690828129602 })); - this->HV_sigmaParam.insert(std::pair(12, SigmaParam{ -30.0103645753547, 27.1700862271921, 11.8007376386356, - 0.933835390422269, - 16.4640776105300, 11.8318838032267 })); - this->VH_sigmaParam.insert(std::pair(12, SigmaParam{ -30.0103645753547, 27.1700862271921, 11.8007376386356, -0.933835390422269, -16.4640776105300, 11.8318838032267 })); - this->VV_sigmaParam.insert(std::pair(12, SigmaParam{ -21.1019701821713, 9.00621457243906, 6.52932182540331, -1.11157376729893, -15.8022895411007, 11.4690828129602 })); + ////12 + //this->HH_sigmaParam.insert(std::pair(12, SigmaParam{ -21.1019701821713, 9.00621457243906, 6.52932182540331, - 1.11157376729893, - 15.8022895411007, 11.4690828129602 })); + //this->HV_sigmaParam.insert(std::pair(12, SigmaParam{ -30.0103645753547, 27.1700862271921, 11.8007376386356, - 0.933835390422269, - 16.4640776105300, 11.8318838032267 })); + //this->VH_sigmaParam.insert(std::pair(12, SigmaParam{ -30.0103645753547, 27.1700862271921, 11.8007376386356, -0.933835390422269, -16.4640776105300, 11.8318838032267 })); + //this->VV_sigmaParam.insert(std::pair(12, SigmaParam{ -21.1019701821713, 9.00621457243906, 6.52932182540331, -1.11157376729893, -15.8022895411007, 11.4690828129602 })); - //22 - this->HH_sigmaParam.insert(std::pair(22, SigmaParam{ -43.6677042155964, 32.0245140457417, 0.511060658303930, - 2.68482232690106, 6.29783274559538, 1.96648609622833 })); - this->HV_sigmaParam.insert(std::pair(22, SigmaParam{ -36.3971634075803, 13.1296247093899, 1.12707368693158, - 1.88195857790977, 6.57450737122974, 2.11755051297951 })); - this->VH_sigmaParam.insert(std::pair(22, SigmaParam{ -36.3971634075803, 13.1296247093899, 1.12707368693158, -1.88195857790977, 6.57450737122974, 2.11755051297951 })); - this->VV_sigmaParam.insert(std::pair(22, SigmaParam{ -43.6677042155964, 32.0245140457417, 0.511060658303930, -2.68482232690106, 6.29783274559538, 1.96648609622833 })); + ////22 + //this->HH_sigmaParam.insert(std::pair(22, SigmaParam{ -43.6677042155964, 32.0245140457417, 0.511060658303930, - 2.68482232690106, 6.29783274559538, 1.96648609622833 })); + //this->HV_sigmaParam.insert(std::pair(22, SigmaParam{ -36.3971634075803, 13.1296247093899, 1.12707368693158, - 1.88195857790977, 6.57450737122974, 2.11755051297951 })); + //this->VH_sigmaParam.insert(std::pair(22, SigmaParam{ -36.3971634075803, 13.1296247093899, 1.12707368693158, -1.88195857790977, 6.57450737122974, 2.11755051297951 })); + //this->VV_sigmaParam.insert(std::pair(22, SigmaParam{ -43.6677042155964, 32.0245140457417, 0.511060658303930, -2.68482232690106, 6.29783274559538, 1.96648609622833 })); - //30 - this->HH_sigmaParam.insert(std::pair(30, SigmaParam{ -59.1080014669385, 47.6710707363975, 0.300193452564135, - 3.93463636916976, 5.99799798331127, - 10.3772604045974 })); - this->HV_sigmaParam.insert(std::pair(30, SigmaParam{ -55.1864353240982, 32.2453149408716, 0.333758208816865, - 3.38774208141056, 6.12774897769798, - 10.1192846531823 })); - this->VH_sigmaParam.insert(std::pair(30, SigmaParam{ -55.1864353240982, 32.2453149408716, 0.333758208816865, - 3.38774208141056, 6.12774897769798, - 10.1192846531823 })); - this->VV_sigmaParam.insert(std::pair(30, SigmaParam{ -59.1080014669385, 47.6710707363975, 0.300193452564135, -3.93463636916976, 5.99799798331127, -10.3772604045974 })); + ////30 + //this->HH_sigmaParam.insert(std::pair(30, SigmaParam{ -59.1080014669385, 47.6710707363975, 0.300193452564135, - 3.93463636916976, 5.99799798331127, - 10.3772604045974 })); + //this->HV_sigmaParam.insert(std::pair(30, SigmaParam{ -55.1864353240982, 32.2453149408716, 0.333758208816865, - 3.38774208141056, 6.12774897769798, - 10.1192846531823 })); + //this->VH_sigmaParam.insert(std::pair(30, SigmaParam{ -55.1864353240982, 32.2453149408716, 0.333758208816865, - 3.38774208141056, 6.12774897769798, - 10.1192846531823 })); + //this->VV_sigmaParam.insert(std::pair(30, SigmaParam{ -59.1080014669385, 47.6710707363975, 0.300193452564135, -3.93463636916976, 5.99799798331127, -10.3772604045974 })); - //50 - this->HH_sigmaParam.insert(std::pair(50, SigmaParam{ -22.9105602882378, 8170.54100628307, 15.4916054293135, - 0.970580847008280, 28.9025325818511, - 21.4319176514170 })); - this->HV_sigmaParam.insert(std::pair(50, SigmaParam{ -39.7459019584805, 151.391039247574, 5.17117231380975, - 4.10303899418773, 8.04893424718507, - 3.17171678851531 })); - this->VH_sigmaParam.insert(std::pair(50, SigmaParam{ -39.7459019584805, 151.391039247574, 5.17117231380975, -4.10303899418773, 8.04893424718507, -3.17171678851531 })); - this->VV_sigmaParam.insert(std::pair(50, SigmaParam{ -22.9105602882378, 8170.54100628307, 15.4916054293135, -0.970580847008280, 28.9025325818511, -21.4319176514170 })); + ////50 + //this->HH_sigmaParam.insert(std::pair(50, SigmaParam{ -22.9105602882378, 8170.54100628307, 15.4916054293135, - 0.970580847008280, 28.9025325818511, - 21.4319176514170 })); + //this->HV_sigmaParam.insert(std::pair(50, SigmaParam{ -39.7459019584805, 151.391039247574, 5.17117231380975, - 4.10303899418773, 8.04893424718507, - 3.17171678851531 })); + //this->VH_sigmaParam.insert(std::pair(50, SigmaParam{ -39.7459019584805, 151.391039247574, 5.17117231380975, -4.10303899418773, 8.04893424718507, -3.17171678851531 })); + //this->VV_sigmaParam.insert(std::pair(50, SigmaParam{ -22.9105602882378, 8170.54100628307, 15.4916054293135, -0.970580847008280, 28.9025325818511, -21.4319176514170 })); + + ////61 + //this->HH_sigmaParam.insert(std::pair(61, SigmaParam{ 27.2590864500905, 95.6840751800642, 3.98975084647232, 50.3262749621072, 3.09962879546370, - 5.10400310274333 })); + //this->HV_sigmaParam.insert(std::pair(61, SigmaParam{ -65.9799383836613, 106.831320929437, 1.53821651203361, 0.704332523237733, 36.3654715437260, - 13.7449876973719 })); + //this->VH_sigmaParam.insert(std::pair(61, SigmaParam{ -65.9799383836613, 106.831320929437, 1.53821651203361, 0.704332523237733, 36.3654715437260, -13.7449876973719 })); + //this->VV_sigmaParam.insert(std::pair(61, SigmaParam{ 27.2590864500905, 95.6840751800642, 3.98975084647232, 50.3262749621072, 3.09962879546370, -5.10400310274333 })); + + ////62 + //this->HH_sigmaParam.insert(std::pair(62, SigmaParam{ -34.3961764495281, 21.7503968763591, 1.15914650010176, - 2.83950292185421, 10.3519995095232, 2.75293811408200 })); + //this->HV_sigmaParam.insert(std::pair(62, SigmaParam{ -34.0710914034599, 14.1778732014224, 3.47049853590805, - 1.73813229616801, 10.9627971440838, 2.19731364578002 })); + //this->VH_sigmaParam.insert(std::pair(62, SigmaParam{ -34.0710914034599, 14.1778732014224, 3.47049853590805, -1.73813229616801, 10.9627971440838, 2.19731364578002 })); + //this->VV_sigmaParam.insert(std::pair(62, SigmaParam{ -34.3961764495281, 21.7503968763591, 1.15914650010176, -2.83950292185421, 10.3519995095232, 2.75293811408200 })); + + ////80 + //this->HH_sigmaParam.insert(std::pair(80, SigmaParam{ -5.76486750987210, - 7.80014668607246, 0.0880097904597720, - 5.44564720816575, - 0.530358195545799, 1.04332202699956 })); + //this->HV_sigmaParam.insert(std::pair(80, SigmaParam{ 484.928701445606, - 0.992170190244375, - 1.98914783519718, - 507.127544388772, 0.195180814149377, 6.21339949756719 })); + //this->VH_sigmaParam.insert(std::pair(80, SigmaParam{ 484.928701445606, -0.992170190244375, -1.98914783519718, -507.127544388772, 0.195180814149377, 6.21339949756719 })); + //this->VV_sigmaParam.insert(std::pair(80, SigmaParam{ -5.76486750987210, -7.80014668607246, 0.0880097904597720, -5.44564720816575, -0.530358195545799, 1.04332202699956 })); + + ////90 + //this->HH_sigmaParam.insert(std::pair(90, SigmaParam{ -20.1761798059391, 13.2752519275021, 2.74667225608397, 3.63052241744923, 8.99932188120922, 34.8246533269446 })); + //this->HV_sigmaParam.insert(std::pair(90, SigmaParam{ -26.8776515733889, 10.4251866500052, 8.43273666535992, 4.33165922141213, 8.68204389555939, - 2.51718779582920 })); + //this->VH_sigmaParam.insert(std::pair(90, SigmaParam{ -26.8776515733889, 10.4251866500052, 8.43273666535992, 4.33165922141213, 8.68204389555939, - 2.51718779582920 })); + //this->VV_sigmaParam.insert(std::pair(90, SigmaParam{ -20.1761798059391, 13.2752519275021, 2.74667225608397, 3.63052241744923, 8.99932188120922, 34.8246533269446 })); + + this->HH_sigmaParam.insert(std::pair(10, SigmaParam{ 28.15,-39.73,0.0986,2.863,4.356,-6.279 })); + this->HH_sigmaParam.insert(std::pair(20, SigmaParam{ 36.13,-48.2,0.1299,-1.838,5.404,-4.015 })); + this->HH_sigmaParam.insert(std::pair(30, SigmaParam{ 183.5,-194.6,0.0167,2.952,-4.1,6.026 })); + this->HH_sigmaParam.insert(std::pair(40, SigmaParam{ 50.97,-62.9,0.0968,1.604,4.637,6.108 })); + this->HH_sigmaParam.insert(std::pair(50, SigmaParam{ -10.31,15.96,37.73,-4.584,4.997,-3.569 })); + this->HH_sigmaParam.insert(std::pair(60, SigmaParam{ -12.45,0.1561,-3.187,-2.482,8.244,0.3632 })); + this->HH_sigmaParam.insert(std::pair(80, SigmaParam{ -19.23,0.3623,-2.209,9.649,0.1292,-0.264 })); + this->HH_sigmaParam.insert(std::pair(100, SigmaParam{ 56.61,-62.29,0.01388,2.767,-3.943,5.995 })); - //61 - this->HH_sigmaParam.insert(std::pair(61, SigmaParam{ 27.2590864500905, 95.6840751800642, 3.98975084647232, 50.3262749621072, 3.09962879546370, - 5.10400310274333 })); - this->HV_sigmaParam.insert(std::pair(61, SigmaParam{ -65.9799383836613, 106.831320929437, 1.53821651203361, 0.704332523237733, 36.3654715437260, - 13.7449876973719 })); - this->VH_sigmaParam.insert(std::pair(61, SigmaParam{ -65.9799383836613, 106.831320929437, 1.53821651203361, 0.704332523237733, 36.3654715437260, -13.7449876973719 })); - this->VV_sigmaParam.insert(std::pair(61, SigmaParam{ 27.2590864500905, 95.6840751800642, 3.98975084647232, 50.3262749621072, 3.09962879546370, -5.10400310274333 })); - //62 - this->HH_sigmaParam.insert(std::pair(62, SigmaParam{ -34.3961764495281, 21.7503968763591, 1.15914650010176, - 2.83950292185421, 10.3519995095232, 2.75293811408200 })); - this->HV_sigmaParam.insert(std::pair(62, SigmaParam{ -34.0710914034599, 14.1778732014224, 3.47049853590805, - 1.73813229616801, 10.9627971440838, 2.19731364578002 })); - this->VH_sigmaParam.insert(std::pair(62, SigmaParam{ -34.0710914034599, 14.1778732014224, 3.47049853590805, -1.73813229616801, 10.9627971440838, 2.19731364578002 })); - this->VV_sigmaParam.insert(std::pair(62, SigmaParam{ -34.3961764495281, 21.7503968763591, 1.15914650010176, -2.83950292185421, 10.3519995095232, 2.75293811408200 })); - //80 - this->HH_sigmaParam.insert(std::pair(80, SigmaParam{ -5.76486750987210, - 7.80014668607246, 0.0880097904597720, - 5.44564720816575, - 0.530358195545799, 1.04332202699956 })); - this->HV_sigmaParam.insert(std::pair(80, SigmaParam{ 484.928701445606, - 0.992170190244375, - 1.98914783519718, - 507.127544388772, 0.195180814149377, 6.21339949756719 })); - this->VH_sigmaParam.insert(std::pair(80, SigmaParam{ 484.928701445606, -0.992170190244375, -1.98914783519718, -507.127544388772, 0.195180814149377, 6.21339949756719 })); - this->VV_sigmaParam.insert(std::pair(80, SigmaParam{ -5.76486750987210, -7.80014668607246, 0.0880097904597720, -5.44564720816575, -0.530358195545799, 1.04332202699956 })); - //90 - this->HH_sigmaParam.insert(std::pair(90, SigmaParam{ -20.1761798059391, 13.2752519275021, 2.74667225608397, 3.63052241744923, 8.99932188120922, 34.8246533269446 })); - this->HV_sigmaParam.insert(std::pair(90, SigmaParam{ -26.8776515733889, 10.4251866500052, 8.43273666535992, 4.33165922141213, 8.68204389555939, - 2.51718779582920 })); - this->VH_sigmaParam.insert(std::pair(90, SigmaParam{ -26.8776515733889, 10.4251866500052, 8.43273666535992, 4.33165922141213, 8.68204389555939, - 2.51718779582920 })); - this->VV_sigmaParam.insert(std::pair(90, SigmaParam{ -20.1761798059391, 13.2752519275021, 2.74667225608397, 3.63052241744923, 8.99932188120922, 34.8246533269446 })); } SigmaDatabase::~SigmaDatabase() diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index e87bda5..899218d 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -125,6 +125,7 @@ stdcpp14 stdc11 false + true true From 2b586efe03660a6f0f5d1313f2a7c69a5f41531e Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Fri, 21 Mar 2025 16:00:31 +0800 Subject: [PATCH 20/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp | 5 ++++- .../SimulationSAR/SARSatelliteSimulationAbstractCls.cpp | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 97aaade..7412081 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -291,7 +291,7 @@ ErrorCode RFPCProcessCls::Process(long num_thread) else {} qDebug() << "RFPCMainProcess"; - + //return ErrorCode::SUCCESS; stateCode = this->InitEchoMaskArray(); if (stateCode != ErrorCode::SUCCESS) { return stateCode; @@ -303,6 +303,9 @@ ErrorCode RFPCProcessCls::Process(long num_thread) // 初始化回波 this->EchoSimulationData->initEchoArr(std::complex(0, 0)); + + //return ErrorCode::SUCCESS; + stateCode = this->RFPCMainProcess_GPU(); if (stateCode != ErrorCode::SUCCESS) { diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SARSatelliteSimulationAbstractCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/SARSatelliteSimulationAbstractCls.cpp index 73a329b..b56f7c2 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SARSatelliteSimulationAbstractCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/SARSatelliteSimulationAbstractCls.cpp @@ -278,6 +278,7 @@ double AbstractSARSatelliteModel::getCenterLookAngle() void AbstractSARSatelliteModel::setCenterLookAngle(double angle) { + } void AbstractSARSatelliteModel::setTransformRadiationPattern(std::shared_ptr radiationPanttern) From d1806f74273dba13b92e25f843c74ce8e3fdb723 Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Fri, 21 Mar 2025 16:04:39 +0800 Subject: [PATCH 21/94] tongbuxiugai --- GPUBaseLib/GPUTool/GPUTool.cu | 44 ++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/GPUBaseLib/GPUTool/GPUTool.cu b/GPUBaseLib/GPUTool/GPUTool.cu index 300acf7..0a8c652 100644 --- a/GPUBaseLib/GPUTool/GPUTool.cu +++ b/GPUBaseLib/GPUTool/GPUTool.cu @@ -353,18 +353,40 @@ extern "C" void FreeCUDAHost(void* ptr) { ptr = nullptr; } -// GPUڴ -extern "C" void* mallocCUDADevice(size_t memsize) { - void* ptr; - cudaMalloc(&ptr, memsize); -#ifdef __CUDADEBUG__ - cudaError_t err = cudaGetLastError(); - if (err != cudaSuccess) { - printf("mallocCUDADevice CUDA Error: %s, malloc memory : %d byte\n", cudaGetErrorString(err), memsize); - exit(2); +// GPUڴ亯 +void* mallocCUDADevice(size_t memsize, int device_id = 0) +{ + void* ptr = nullptr; + cudaError_t err; + + // 1. 豸IDЧ + int num_devices; + cudaGetDeviceCount(&num_devices); + if (device_id < 0 || device_id >= num_devices) + { + printfinfo("Invalid device ID: %d\n", device_id); + return nullptr; } -#endif // __CUDADEBUG__ - cudaDeviceSynchronize(); + + // 2. лĿGPU豸 + err = cudaSetDevice(device_id); + if (err != cudaSuccess) + { + PrintLasterError("cudaSetDevice"); + return nullptr; + } + + // 3. Դ + err = cudaMalloc(&ptr, memsize); + if (err != cudaSuccess) + { + PrintLasterError("cudaMalloc"); + return nullptr; + } + + // 4. ѡͬ豸Ƿ + // cudaDeviceSynchronize(); + return ptr; } From fda3b7b1ca0ed0b65dc030ea1dca83c33898612f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Fri, 21 Mar 2025 17:31:19 +0800 Subject: [PATCH 22/94] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GPUBaseLib/GPUTool/GPUTool.cu | 2 +- GPUBaseLib/GPUTool/GPUTool.cuh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GPUBaseLib/GPUTool/GPUTool.cu b/GPUBaseLib/GPUTool/GPUTool.cu index 0a8c652..5891175 100644 --- a/GPUBaseLib/GPUTool/GPUTool.cu +++ b/GPUBaseLib/GPUTool/GPUTool.cu @@ -354,7 +354,7 @@ extern "C" void FreeCUDAHost(void* ptr) { } // GPUڴ亯 -void* mallocCUDADevice(size_t memsize, int device_id = 0) +void* mallocCUDADevice(size_t memsize, int device_id ) { void* ptr = nullptr; cudaError_t err; diff --git a/GPUBaseLib/GPUTool/GPUTool.cuh b/GPUBaseLib/GPUTool/GPUTool.cuh index d16af3c..2a9a709 100644 --- a/GPUBaseLib/GPUTool/GPUTool.cuh +++ b/GPUBaseLib/GPUTool/GPUTool.cuh @@ -77,7 +77,7 @@ extern "C" GPUBASELIBAPI void checkCudaError(cudaError_t err, const char* msg); // GPU ڴ溯 extern "C" GPUBASELIBAPI void* mallocCUDAHost(size_t memsize); // ڴ extern "C" GPUBASELIBAPI void FreeCUDAHost(void* ptr); -extern "C" GPUBASELIBAPI void* mallocCUDADevice(size_t memsize); // GPUڴ +extern "C" GPUBASELIBAPI void* mallocCUDADevice(size_t memsize, int device_id = 0); // GPUڴ extern "C" GPUBASELIBAPI void FreeCUDADevice(void* ptr); extern "C" GPUBASELIBAPI void HostToDevice(void* hostptr, void* deviceptr, size_t memsize);//GPU ڴת 豸 -> GPU extern "C" GPUBASELIBAPI void DeviceToHost(void* hostptr, void* deviceptr, size_t memsize);//GPU ڴת GPU -> 豸 From e08ca45f36164353d4e9db7afd8938f63f3a0d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Fri, 21 Mar 2025 18:14:29 +0800 Subject: [PATCH 23/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ALLRelease/ALLRelease.vcxproj | 6 ------ BaseCommonLibrary/BaseTool/BaseConstVariable.h | 8 ++++---- BaseCommonLibrary/BaseTool/BaseTool.cpp | 2 +- LAMPDataProcessEXE/LAMPDataProcessEXE.vcxproj | 3 --- RasterMainWidgetGUI/RasterMainWidgetGUI.vcxproj | 3 --- .../SimulationSAR/TBPImageAlgCls.h | 16 ++++++++-------- .../SimulationSARTool/SimulationSARTool.vcxproj | 3 --- .../pluginToolboxLibrary.vcxproj | 6 ------ 8 files changed, 13 insertions(+), 34 deletions(-) diff --git a/ALLRelease/ALLRelease.vcxproj b/ALLRelease/ALLRelease.vcxproj index 0552d3d..fd90192 100644 --- a/ALLRelease/ALLRelease.vcxproj +++ b/ALLRelease/ALLRelease.vcxproj @@ -196,9 +196,6 @@ {b8b40c54-f7fe-4809-b6fb-8bc014570d7b} - - {8c8ca066-a93a-4098-9a46-b855efeaadf2} - {4e6e79a3-048c-4fb4-bbb0-43c518a3e6d4} @@ -211,9 +208,6 @@ {070c157e-3c30-4e2b-a80c-cbc7b74df03f} - - {d603a623-132d-4304-ab03-638fc438f084} - {ed06dfcd-4b9f-41f7-8f25-1823c2398142} diff --git a/BaseCommonLibrary/BaseTool/BaseConstVariable.h b/BaseCommonLibrary/BaseTool/BaseConstVariable.h index 979b12f..07dccd3 100644 --- a/BaseCommonLibrary/BaseTool/BaseConstVariable.h +++ b/BaseCommonLibrary/BaseTool/BaseConstVariable.h @@ -17,10 +17,10 @@ - -#define EIGEN_USE_BLAS -#define EIGEN_USE_LAPACK -#define EIGEN_VECTORIZE_SSE2 +// +//#define EIGEN_USE_BLAS +//#define EIGEN_USE_LAPACK +//#define EIGEN_VECTORIZE_SSE2 //#define DEBUGSHOWDIALOG diff --git a/BaseCommonLibrary/BaseTool/BaseTool.cpp b/BaseCommonLibrary/BaseTool/BaseTool.cpp index 656e73b..64d6252 100644 --- a/BaseCommonLibrary/BaseTool/BaseTool.cpp +++ b/BaseCommonLibrary/BaseTool/BaseTool.cpp @@ -1,5 +1,5 @@ #include "stdafx.h" -#define EIGEN_USE_BLAS +//#define EIGEN_USE_BLAS #define EIGEN_VECTORIZE_SSE4_2 //#include diff --git a/LAMPDataProcessEXE/LAMPDataProcessEXE.vcxproj b/LAMPDataProcessEXE/LAMPDataProcessEXE.vcxproj index cc60302..b979ef0 100644 --- a/LAMPDataProcessEXE/LAMPDataProcessEXE.vcxproj +++ b/LAMPDataProcessEXE/LAMPDataProcessEXE.vcxproj @@ -196,9 +196,6 @@ {b8b40c54-f7fe-4809-b6fb-8bc014570d7b} - - {8c8ca066-a93a-4098-9a46-b855efeaadf2} - {667625a5-8de2-4373-99f0-8bad2cced011} diff --git a/RasterMainWidgetGUI/RasterMainWidgetGUI.vcxproj b/RasterMainWidgetGUI/RasterMainWidgetGUI.vcxproj index 123f057..4a41a0b 100644 --- a/RasterMainWidgetGUI/RasterMainWidgetGUI.vcxproj +++ b/RasterMainWidgetGUI/RasterMainWidgetGUI.vcxproj @@ -265,9 +265,6 @@ {b8b40c54-f7fe-4809-b6fb-8bc014570d7b} - - {8c8ca066-a93a-4098-9a46-b855efeaadf2} - {7ef67daa-dbc0-4b7f-80e8-11b4d2cb7ec2} diff --git a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.h b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.h index 3222ec3..61b925c 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.h +++ b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.h @@ -13,14 +13,14 @@ * \author * \date October 2024 *********************************************************************/ -#define EIGEN_USE_BLAS -#define EIGEN_USE_LAPACK -#define EIGEN_ENABLE_AVX512 -#define EIGEN_VECTORIZE_SSE -#define EIGEN_VECTORIZE_SSE2 -#define EIGEN_VECTORIZE_SSSE3 -#define EIGEN_VECTORIZE_SSE4_1 -#define EIGEN_VECTORIZE_SSE4_2 +//#define EIGEN_USE_BLAS +//#define EIGEN_USE_LAPACK +//#define EIGEN_ENABLE_AVX512 +//#define EIGEN_VECTORIZE_SSE +//#define EIGEN_VECTORIZE_SSE2 +//#define EIGEN_VECTORIZE_SSSE3 +//#define EIGEN_VECTORIZE_SSE4_1 +//#define EIGEN_VECTORIZE_SSE4_2 #include "BaseConstVariable.h" #include "SARSatelliteSimulationAbstractCls.h" diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 899218d..e18556f 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -282,9 +282,6 @@ {b8b40c54-f7fe-4809-b6fb-8bc014570d7b} - - {8c8ca066-a93a-4098-9a46-b855efeaadf2} - {e56b3878-a3dc-41a4-abf3-b628816d0d64} diff --git a/pluginToolboxLibrary/pluginToolboxLibrary.vcxproj b/pluginToolboxLibrary/pluginToolboxLibrary.vcxproj index d3a2e08..f5137fd 100644 --- a/pluginToolboxLibrary/pluginToolboxLibrary.vcxproj +++ b/pluginToolboxLibrary/pluginToolboxLibrary.vcxproj @@ -133,9 +133,6 @@ {b8b40c54-f7fe-4809-b6fb-8bc014570d7b} - - {8c8ca066-a93a-4098-9a46-b855efeaadf2} - {e56b3878-a3dc-41a4-abf3-b628816d0d64} @@ -148,9 +145,6 @@ {070c157e-3c30-4e2b-a80c-cbc7b74df03f} - - {d603a623-132d-4304-ab03-638fc438f084} - {ed06dfcd-4b9f-41f7-8f25-1823c2398142} From 7a374c135b5a6c931b05e1e3e72f00cee5d518fb Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Sat, 22 Mar 2025 20:04:33 +0800 Subject: [PATCH 24/94] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=EF=BC=8C=E6=A3=80=E6=9F=A5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GPUBaseLib/GPUTool/GPUTool.cu | 2 +- GPUBaseLib/GPUTool/GPUTool.cuh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GPUBaseLib/GPUTool/GPUTool.cu b/GPUBaseLib/GPUTool/GPUTool.cu index 0a8c652..5891175 100644 --- a/GPUBaseLib/GPUTool/GPUTool.cu +++ b/GPUBaseLib/GPUTool/GPUTool.cu @@ -354,7 +354,7 @@ extern "C" void FreeCUDAHost(void* ptr) { } // GPUڴ亯 -void* mallocCUDADevice(size_t memsize, int device_id = 0) +void* mallocCUDADevice(size_t memsize, int device_id ) { void* ptr = nullptr; cudaError_t err; diff --git a/GPUBaseLib/GPUTool/GPUTool.cuh b/GPUBaseLib/GPUTool/GPUTool.cuh index d16af3c..5da4c7e 100644 --- a/GPUBaseLib/GPUTool/GPUTool.cuh +++ b/GPUBaseLib/GPUTool/GPUTool.cuh @@ -77,7 +77,7 @@ extern "C" GPUBASELIBAPI void checkCudaError(cudaError_t err, const char* msg); // GPU ڴ溯 extern "C" GPUBASELIBAPI void* mallocCUDAHost(size_t memsize); // ڴ extern "C" GPUBASELIBAPI void FreeCUDAHost(void* ptr); -extern "C" GPUBASELIBAPI void* mallocCUDADevice(size_t memsize); // GPUڴ +extern "C" GPUBASELIBAPI void* mallocCUDADevice(size_t memsize, int device_id=0); // GPUڴ extern "C" GPUBASELIBAPI void FreeCUDADevice(void* ptr); extern "C" GPUBASELIBAPI void HostToDevice(void* hostptr, void* deviceptr, size_t memsize);//GPU ڴת 豸 -> GPU extern "C" GPUBASELIBAPI void DeviceToHost(void* hostptr, void* deviceptr, size_t memsize);//GPU ڴת GPU -> 豸 From 8bd997f92425f9c3445cd7320060d55431ba19a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 23 Mar 2025 16:01:28 +0800 Subject: [PATCH 25/94] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=9A=E5=8D=A1?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/BaseConstVariable.h | 6 + BaseCommonLibrary/BaseTool/EchoDataFormat.cpp | 13 ++ BaseCommonLibrary/BaseTool/EchoDataFormat.h | 1 + GPUBaseLib/GPUBaseLib.vcxproj | 6 +- GPUBaseLib/GPUBaseLib.vcxproj.filters | 8 + GPUBaseLib/GPUTool/GPUBaseTool.cpp | 56 +++++ GPUBaseLib/GPUTool/GPUBaseTool.h | 25 +++ GPUBaseLib/GPUTool/GPUTool.cuh | 15 +- Toolbox/SimulationSARTool/Sigma0ClsReflect.cu | 132 +++++++++++ .../SimulationSAR/GPURFPC.cu | 122 +++++++++++ .../SimulationSAR/GPURFPC.cuh | 76 ++++++- .../SimulationSAR/RFPCProcessCls.cpp | 206 +++++++++++++++++- .../SimulationSAR/RFPCProcessCls.h | 4 + .../SimulationSARTool.vcxproj | 1 + .../SimulationSARTool.vcxproj.filters | 3 + 15 files changed, 660 insertions(+), 14 deletions(-) create mode 100644 GPUBaseLib/GPUTool/GPUBaseTool.cpp create mode 100644 GPUBaseLib/GPUTool/GPUBaseTool.h create mode 100644 Toolbox/SimulationSARTool/Sigma0ClsReflect.cu diff --git a/BaseCommonLibrary/BaseTool/BaseConstVariable.h b/BaseCommonLibrary/BaseTool/BaseConstVariable.h index 07dccd3..f001b98 100644 --- a/BaseCommonLibrary/BaseTool/BaseConstVariable.h +++ b/BaseCommonLibrary/BaseTool/BaseConstVariable.h @@ -339,6 +339,12 @@ inline long nextpow2(long n) { return pow(2,en); } +inline void releaseVoidArray(void* a) +{ + free(a); + a = NULL; +} + #endif \ No newline at end of file diff --git a/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp b/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp index b2824ba..250ef30 100644 --- a/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp +++ b/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp @@ -511,6 +511,19 @@ ErrorCode EchoL0Dataset::loadFromXml() { return ErrorCode::SUCCESS; } +std::shared_ptr EchoL0Dataset::getAntPosVelc() +{ + omp_lock_t lock; + omp_init_lock(&lock); + omp_set_lock(&lock); + long prfcount = this->PluseCount; + std::shared_ptr antposlist= SatelliteAntPosOperator::readAntPosFile(this->GPSPointFilePath, prfcount); + + omp_unset_lock(&lock); // + omp_destroy_lock(&lock); // + return antposlist; +} + std::shared_ptr EchoL0Dataset::getAntPos() { omp_lock_t lock; diff --git a/BaseCommonLibrary/BaseTool/EchoDataFormat.h b/BaseCommonLibrary/BaseTool/EchoDataFormat.h index 749843f..ec2f685 100644 --- a/BaseCommonLibrary/BaseTool/EchoDataFormat.h +++ b/BaseCommonLibrary/BaseTool/EchoDataFormat.h @@ -209,6 +209,7 @@ public: // public: // ȡļ + std::shared_ptr< SatelliteAntPos> getAntPosVelc(); std::shared_ptr getAntPos(); std::shared_ptr> getEchoArr(long startPRF, long& PRFLen); std::shared_ptr> getEchoArr(); diff --git a/GPUBaseLib/GPUBaseLib.vcxproj b/GPUBaseLib/GPUBaseLib.vcxproj index 0e21f32..8ebd518 100644 --- a/GPUBaseLib/GPUBaseLib.vcxproj +++ b/GPUBaseLib/GPUBaseLib.vcxproj @@ -32,6 +32,7 @@ + @@ -40,6 +41,9 @@ {872ecd6f-30e3-4a1b-b17c-15e87d373ff6} + + + 17.0 Win32Proj @@ -180,7 +184,7 @@ true true true - NDEBUG;_CONSOLE;GPUBASELIB_API;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;GPUBASELIB_API;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true stdcpp14 stdc11 diff --git a/GPUBaseLib/GPUBaseLib.vcxproj.filters b/GPUBaseLib/GPUBaseLib.vcxproj.filters index 1d8fae5..4fddae9 100644 --- a/GPUBaseLib/GPUBaseLib.vcxproj.filters +++ b/GPUBaseLib/GPUBaseLib.vcxproj.filters @@ -35,5 +35,13 @@ GPUTool + + GPUTool + + + + + GPUTool + \ No newline at end of file diff --git a/GPUBaseLib/GPUTool/GPUBaseTool.cpp b/GPUBaseLib/GPUTool/GPUBaseTool.cpp new file mode 100644 index 0000000..6832603 --- /dev/null +++ b/GPUBaseLib/GPUTool/GPUBaseTool.cpp @@ -0,0 +1,56 @@ +#include "GPUBaseTool.h" + + +// ȡļС +extern "C" size_t getfsize(FILE* fp) +{ + fseek(fp, 0L, SEEK_END); + size_t size = ftell(fp); + fseek(fp, 0L, SEEK_SET); + return size; +} + +extern "C" unsigned char* loadBinFromPath(char* binPath, size_t* binpath_len) +{ + FILE* fd = fopen(binPath, "rb"); + if (NULL == fd) + { + perror("Failed to open file"); + return NULL; + } + + size_t f_len = getfsize(fd); + *binpath_len = f_len; + + unsigned char* buffer = (unsigned char*)malloc(f_len * sizeof(unsigned char)); + if (buffer == NULL) + { + perror("Failed to allocate memory"); + fclose(fd); + return NULL; + } + + size_t fread_count = fread(buffer, 1, f_len, fd); + fclose(fd); + + if (fread_count != f_len) + { + releaseVoidArray(buffer); + return NULL; + } + + return buffer; +} + +extern "C" void writeComplexDataBinFile(char* dataPath, size_t datalen, cuComplex* data) +{ + FILE* pd = fopen(dataPath, "w"); + double* tempdata = (double*)malloc(datalen * 2 * sizeof(double)); + for (long i = 0; i < datalen; i++) + { + tempdata[i * 2 + 0] = data[i].x; + tempdata[i * 2 + 1] = data[i].y; + } + fwrite(tempdata, sizeof(double), datalen * 2, pd); + fclose(pd); +} diff --git a/GPUBaseLib/GPUTool/GPUBaseTool.h b/GPUBaseLib/GPUTool/GPUBaseTool.h new file mode 100644 index 0000000..e6bf254 --- /dev/null +++ b/GPUBaseLib/GPUTool/GPUBaseTool.h @@ -0,0 +1,25 @@ +#ifndef __GPUBASETOOL_H__ +#define __GPUBASETOOL_H__ + +#include "GPUBaseLibAPI.h" +#include "BaseConstVariable.h" +#include +#include +#include +#include "GPUTool.cuh" + +extern "C" GPUBASELIBAPI size_t getfsize(FILE* fp); +extern "C" GPUBASELIBAPI unsigned char* loadBinFromPath(char* binPath, size_t* binpath_len); +extern "C" GPUBASELIBAPI void writeComplexDataBinFile(char* dataPath, size_t datalen, cuComplex* data); + +template +inline std::shared_ptr CPUToHost(std::shared_ptr CPUArr, size_t len) { + std::shared_ptr result = std::shared_ptr((T*)mallocCUDAHost(len*sizeof(T)), FreeCUDAHost); + for (size_t i = 0; i < len; i++) { + result.get()[i] = CPUArr.get()[i]; + } + return result; +} + + +#endif // !__GPUBASETOOL_H__ diff --git a/GPUBaseLib/GPUTool/GPUTool.cuh b/GPUBaseLib/GPUTool/GPUTool.cuh index 2a9a709..a1730d8 100644 --- a/GPUBaseLib/GPUTool/GPUTool.cuh +++ b/GPUBaseLib/GPUTool/GPUTool.cuh @@ -16,11 +16,13 @@ #define LAMP_CUDA_PI 3.141592653589793238462643383279 // SHAREMEMORY_FLOAT_HALF_STEP * BLOCK_SIZE = SHAREMEMORY_FLOAT_HALF +/** CUDA ò ************************************************************************************/ #define BLOCK_SIZE 256 -#define SHAREMEMORY_BYTE 49152 -#define SHAREMEMORY_FLOAT_HALF 6144 +#define SHAREMEMORY_BYTE 49152 +#define SHAREMEMORY_FLOAT_HALF 6144 #define SHAREMEMORY_FLOAT_HALF_STEP 24 - +#define SHAREMEMORY_DEM_STEP 768 +#define SHAREMEMORY_Reflect 612 @@ -110,6 +112,13 @@ extern "C" GPUBASELIBAPI void CUDAIFFT(cuComplex* inArr, cuComplex* outArr, long extern "C" GPUBASELIBAPI void FFTShift1D(cuComplex* d_data, int batch_size, int signal_length); extern "C" GPUBASELIBAPI void shared_complexPtrToHostCuComplex(std::complex* src, cuComplex* dst, size_t len); + + extern "C" GPUBASELIBAPI void HostCuComplexToshared_complexPtr(cuComplex* src, std::complex* dst, size_t len); + + + + + #endif #endif diff --git a/Toolbox/SimulationSARTool/Sigma0ClsReflect.cu b/Toolbox/SimulationSARTool/Sigma0ClsReflect.cu new file mode 100644 index 0000000..a33f484 --- /dev/null +++ b/Toolbox/SimulationSARTool/Sigma0ClsReflect.cu @@ -0,0 +1,132 @@ +#include "BaseConstVariable.h" +#include "GPURFPC.cuh" + +const double cls_sigma0[102][6] = { + {0, 0, 0, 0, 0, 0}, // 0 + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {28.15, -39.73, 0.0986, 2.863, 4.356, -6.279}, // 10 + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {36.13, -48.2, 0.1299, -1.838, 5.404, -4.015}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {183.5, -194.6, 0.0167, 2.952, -4.1, 6.026}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {50.97, -62.9, 0.0968, 1.604, 4.637, 6.108}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {-10.31, 15.96, 37.73, -4.584, 4.997, -3.569}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {-12.45, 0.1561, -3.187, -2.482, 8.244, 0.3632}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {-19.23, 0.3623, -2.209, 9.649, 0.1292, -0.264}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {56.61, -62.29, 0.01388, 2.767, -3.943, 5.995}, + {0, 0, 0, 0, 0, 0} }; + + + +/** ***************************************************************/ + + + +extern "C" double* hostSigmaData_toDevice(int devid) +{ + double* h_data = (double*)mallocCUDAHost(102 * 6 * sizeof(double)); + double* d_data = (double*)mallocCUDADevice(102 * 6 * sizeof(double), devid); + printf("copy to "); + for (long i = 0; i < 102; i++) + { + printf(" %d ,", i); + for (long j = 0; j < 6; j++) + { + h_data[i * 6 + j] = cls_sigma0[i][j]; + } + } + printf("host to device sigma data\n"); + HostToDevice(h_data, d_data, 102 * 6 * sizeof(double)); + FreeCUDAHost(h_data); + return d_data; +} + diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index cef1a04..cd86f67 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -463,6 +463,128 @@ void CUDA_RFPC_MainProcess( } + + + + + + + + + +/* ˺ ****************************************************************************************************************************/ +__global__ void CUDA_Kernel_RFPC( + SateState* antlist, + long PRFCount, long Freqcount, // + GoalState* goallist, + long demLen, + double StartFreqGHz, double FreqStep, + double refPhaseRange, + double NearR, double FarR, + CUDASigmaParam clsSigma0, + cuComplex* echodata + ) +{ + + __shared__ GoalState Ts[SHAREMEMORY_DEM_STEP]; + long threadid = threadIdx.x; + + long idx = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ + long prfid = floorf(idx / Freqcount); + long freqid = idx % Freqcount; + // printf("%d,%d ",prfid,freqid); + if (prfid < PRFCount && freqid < Freqcount) + { + SateState antPos = antlist[prfid]; + double factorjTemp = RFPCPIDIVLIGHT * (StartFreqGHz + freqid * FreqStep); + + double Tx = 0; + double Ty = 0; + double Tz = 0; + + double R = 0; + double incAngle = 0; + + double echo_real = 0; + double echo_imag = 0; + + cuComplex echo = make_cuComplex(0, 0); + + for (long startid = 0; startid < demLen; startid = startid + SHAREMEMORY_DEM_STEP) + { + __syncthreads(); // ȷдݶѾ + for (long i = 0; i < 3; i++) { + long ttid = startid + threadid + i * blockDim.x; + long stid = threadid + i * blockDim.x; + if ((stid < SHAREMEMORY_DEM_STEP) && (ttid < demLen)) { + Ts[stid] = goallist[ttid]; + } + } + __syncthreads(); // ȷдݶѾ + + for (long tid = 0; tid < SHAREMEMORY_DEM_STEP; tid++) + { + if ((tid + startid) < demLen) + { + GoalState p = Ts[tid]; + Tx = p.Tx; + Ty = p.Ty; + Tz = p.Tz; + + Tx = antPos.Px - Tx; // T->P + Ty = antPos.Py - Ty; + Tz = antPos.Pz - Tz; + + R = sqrt(Tx * Tx + Ty * Ty + Tz * Tz); + bool isNearFar = (R < NearR || R > FarR); + + + incAngle = sqrt(p.TsX * p.TsX + p.TsY * p.TsY + p.TsZ * p.TsZ); + incAngle = acos((Tx * p.TsX + Ty * p.TsY + Tz * p.TsZ) / (R * incAngle)); + incAngle = GPU_getSigma0dB_params(clsSigma0.p1, clsSigma0.p2, clsSigma0.p3, clsSigma0.p4, clsSigma0.p5, clsSigma0.p6, incAngle); // sigma + incAngle = pow(10.0, incAngle / 10.0); // amp + incAngle = incAngle / (powf(4 * LAMP_CUDA_PI, 2) * powf(R, 4)); // + + R = (R - refPhaseRange); + R = factorjTemp * R; + + echo_real = incAngle * cos(R)* isNearFar; + echo_imag = incAngle * sin(R)* isNearFar; + echo.x = echo.x + echo_real; + echo.y = echo.y + echo_imag; + } + } + } + + echodata[idx] = cuCaddf(echodata[idx], echo); + } +} + + +/** ֿ鴦 ****************************************************************************************************************/ + +extern "C" void ProcessRFPCTask(RFPCTask& task) +{ + long pixelcount = task.prfNum * task.freqNum; + long grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; + printf("start %d ,%d,%d\n", task.targetnum, grid_size, BLOCK_SIZE); + CUDA_Kernel_RFPC << > > ( + task.antlist, + task.prfNum,task.freqNum, + task.goallist, + task.targetnum, + task.startFreq,task.stepFreq, + task.Rref,task.Rnear,task.Rfar, + task.sigma0_cls, + task.d_echoData + ); + PrintLasterError("ProcessRFPCTask"); + cudaDeviceSynchronize(); + printf("start %d \n", task.targetnum); +} + + + #endif diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh index 6b5b4a2..b72623b 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh @@ -8,8 +8,25 @@ #include #include +/** CUDA ò ************************************************************************************/ + + + #define RFPCPIDIVLIGHT -4*PI/(LIGHTSPEED/1e9) + +extern "C" struct SateState { + double Px, Py, Pz, Vx, Vy, Vz; +}; + + +extern "C" struct GoalState { + double Tx, Ty, Tz, TsX, TsY, TsZ; + size_t cls; +}; + + + extern "C" struct CUDASigmaParam { double p1; @@ -20,7 +37,60 @@ extern "C" struct CUDASigmaParam { double p6; }; - +extern "C" struct SloperDs +{ + double* SloperX; + double* SloperY; + double* SloperZ; + double* SloperAngle; + +}; + +extern "C" struct DEMDs +{ + double* demX; + double* demY; + double* demZ; +}; + +extern "C" struct LandDataDs +{ + unsigned char* landData; +}; + +extern "C" struct GPSPointsDs +{ + double* Pxs; + double* Pys; + double* Pzs; + double* Vxs; + double* Vys; + double* Vzs; +}; + + +extern "C" struct RFPCTask +{ + double startFreq; + double stepFreq; + long freqNum; + long prfNum; + + double Rnear; + double Rfar; + double Rref; + + + SateState* antlist = nullptr; + GoalState* goallist = nullptr; + cuComplex* d_echoData = nullptr; // ز + CUDASigmaParam sigma0_cls; + + + long targetnum; + +}; + extern __device__ double GPU_getSigma0dB_params( const double p1, const double p2, const double p3, const double p4, const double p5, const double p6, @@ -73,8 +143,8 @@ extern "C" void CUDA_RFPC_MainProcess( - - +extern "C" double* hostSigmaData_toDevice(int devid); +extern "C" void ProcessRFPCTask(RFPCTask& task); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 7412081..221d981 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1,6 +1,7 @@  #include "stdafx.h" #include +#include "GPUBaseTool.h" #include "RFPCProcessCls.h" #include "BaseConstVariable.h" #include "SARSatelliteSimulationAbstractCls.h" @@ -306,8 +307,8 @@ ErrorCode RFPCProcessCls::Process(long num_thread) //return ErrorCode::SUCCESS; - stateCode = this->RFPCMainProcess_GPU(); - + //stateCode = this->RFPCMainProcess_GPU(); + stateCode = this->RFPCMainProcess_MultiGPU_NoAntPattern(); if (stateCode != ErrorCode::SUCCESS) { return stateCode; } @@ -542,17 +543,12 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { long freqnum_temp = freqnum; float f0 = float(freqlist[0] / 1e9); float dfreq = float((freqlist[1] - freqlist[0]) / 1e9); - qDebug() << "freqnum: " << freqnum << " f0: " << f0 << " dfreq: " << dfreq; long PRFCount = this->EchoSimulationData->getPluseCount(); - double NearRange = this->EchoSimulationData->getNearRange(); // 近斜距 double FarRange = this->EchoSimulationData->getFarRange(); - double Pt = this->TaskSetting->getPt() * this->TaskSetting->getGri();// 发射电压 1v - double lamda = this->TaskSetting->getCenterLamda(); // 波长 double refphaseRange = this->TaskSetting->getRefphaseRange(); // 参考相位斜距 - double prf_time = 0; double dt = 1 / this->TaskSetting->getPRF();// 获取每次脉冲的时间间隔 bool antflag = true; // 计算天线方向图 @@ -935,6 +931,202 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { return ErrorCode::SUCCESS; } +ErrorCode RFPCProcessCls::RFPCMainProcess_MultiGPU_NoAntPattern() +{ + int num_devices; + cudaGetDeviceCount(&num_devices); + PRINT("GPU Count : %d \n", num_devices); + + long prfcount = this->EchoSimulationData->getPluseCount(); + size_t prfblockcount = (prfcount + num_devices +2- 1) / num_devices; + + double prf_time = 0; + double dt = 1 / this->TaskSetting->getPRF();// 获取每次脉冲的时间间隔 + bool antflag = true; // 计算天线方向图 + long double imageStarttime = this->TaskSetting->getSARImageStartTime(); + std::shared_ptr sateOirbtNodes = this->getSatelliteOribtNodes(prf_time, dt, antflag, imageStarttime); + + + + +#pragma omp parallel for + for (int devid = 0; devid < num_devices; devid++) { + cudaSetDevice(devid); // 确保当前线程操作指定的GPU设备 + this->RFPCMainProcess_GPU_NoAntPattern(0, 0, devid); + size_t startTid = devid * prfblockcount; + size_t prf_devLen = prfblockcount; + prf_devLen = (startTid + prf_devLen) < prfcount ? prf_devLen : (prfcount - startTid); + this->RFPCMainProcess_GPU_NoAntPattern(startTid, prf_devLen, devid); + } + + + return ErrorCode::SUCCESS; +} + +ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, size_t prfcount, int devId) +{ + /// 显存不限制 + cudaSetDevice(devId); // 确保当前线程操作指定的GPU设备 + POLARTYPEENUM polartype = this->TaskSetting->getPolarType(); + std::map clssigmaParamsDict = this->SigmaDatabasePtr->getsigmaParams(polartype);; + std::map clsCUDASigmaParamsDict; + for (const auto& pair : clssigmaParamsDict) { + clsCUDASigmaParamsDict.insert(std::pair(pair.first, + CUDASigmaParam{ + pair.second.p1, + pair.second.p2, + pair.second.p3, + pair.second.p4, + pair.second.p5, + pair.second.p6 + })); + } + + + // 读取类别 + gdalImage demxyz(this->demxyzPath);// 地面点坐标 + gdalImage demlandcls(this->LandCoverPath);// 地表覆盖类型 + gdalImage slpxyz(this->demsloperPath);// 地面坡向 + // 处理地面坐标 + long demRow = demxyz.height; + long demCol = demxyz.width; + size_t demCount = size_t(demRow) * size_t(demCol); + + std::shared_ptr demX = readDataArr(demxyz, 0, 0, demRow, demCol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demY = readDataArr(demxyz, 0, 0, demRow, demCol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demZ = readDataArr(demxyz, 0, 0, demRow, demCol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr slpX = readDataArr(slpxyz, 0, 0, demRow, demCol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr slpY = readDataArr(slpxyz, 0, 0, demRow, demCol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr slpZ = readDataArr(slpxyz, 0, 0, demRow, demCol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr clsArr = readDataArr(demlandcls, 0, 0, demRow, demCol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + + // 检索类别数量 + std::map clsCountDict; + for (const auto& pair : clssigmaParamsDict) { + clsCountDict.insert(std::pair(pair.first, 0)); + } + + for (size_t i = 0; i < demCount; i++) { + long clsid = clsArr.get()[i]; + if (clsCountDict.find(clsid) != clsCountDict.end()) { + clsCountDict[clsid] = clsCountDict[clsid] + 1; + } + } + + std::map> clsGoalStateDict; + for (const auto& pair : clsCountDict) { + clsGoalStateDict.insert( + std::pair>( + pair.first, + std::shared_ptr((GoalState*)mallocCUDAHost(sizeof(GoalState) * pair.second), FreeCUDAHost))); + } + + // 分块处理大小 + size_t blocksize = 1000; + + std::map clsCountDictTemp; + for (const auto& pair : clsCountDict) { + clsCountDictTemp.insert(std::pair(pair.first, pair.second)); + } + + for (long i = 0; i < demCount; i++) { + long clsid = clsArr.get()[i]; + size_t Currentclscount = clsCountDictTemp[clsid]; + size_t allclscount = clsCountDict[clsid]; + clsGoalStateDict[clsid].get()[Currentclscount-allclscount].Tx = demX.get()[i]; + clsGoalStateDict[clsid].get()[Currentclscount-allclscount].Ty = demY.get()[i]; + clsGoalStateDict[clsid].get()[Currentclscount-allclscount].Tz = demZ.get()[i]; + clsGoalStateDict[clsid].get()[Currentclscount-allclscount].TsX = slpX.get()[i]; + clsGoalStateDict[clsid].get()[Currentclscount-allclscount].TsY = slpY.get()[i]; + clsGoalStateDict[clsid].get()[Currentclscount-allclscount].TsZ = slpZ.get()[i]; + clsGoalStateDict[clsid].get()[Currentclscount-allclscount].cls = clsArr.get()[i]; + Currentclscount = Currentclscount - 1; + } + + + + RFPCTask task; + // 参数声明 + task.freqNum = this->EchoSimulationData->getPlusePoints(); + task.prfNum = prfcount; + task.Rref = this->EchoSimulationData->getRefPhaseRange(); + task.Rnear = this->EchoSimulationData->getNearRange(); + task.Rfar = this->EchoSimulationData->getFarRange(); + task.startFreq = this->EchoSimulationData->getCenterFreq() - this->EchoSimulationData->getBandwidth() / 2; + task.stepFreq = this->EchoSimulationData->getBandwidth() / (task.freqNum - 1); + task.d_echoData = (cuComplex*)mallocCUDADevice(prfcount * task.freqNum * sizeof(cuComplex), devId); + + // 天线位置 + { + std::shared_ptr antplise = this->EchoSimulationData->getAntPosVelc(); + std::shared_ptr h_antlist((SateState*)mallocCUDAHost(prfcount * sizeof(SateState)), FreeCUDAHost); + + for (long i = 0; i < prfcount; i++) { + h_antlist.get()[i].Px = antplise.get()[i + startprfid].Px; + h_antlist.get()[i].Py = antplise.get()[i + startprfid].Py; + h_antlist.get()[i].Pz = antplise.get()[i + startprfid].Pz; + h_antlist.get()[i].Vx = antplise.get()[i + startprfid].Vx; + h_antlist.get()[i].Vy = antplise.get()[i + startprfid].Vy; + h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; + } + + task.antlist = (SateState*)mallocCUDADevice(prfcount * sizeof(SateState), devId); + HostToDevice(h_antlist.get(), task.antlist, sizeof(double) * prfcount); + + } + + // 分块计算 + for (const auto& pair : clsCUDASigmaParamsDict) { + long clsid = pair.first; + size_t clscount = clsCountDict[clsid]; + PRINT("Process Class ID : %d , Count: %d\n", clsid, clscount); + task.targetnum = clscount; + task.goallist = (GoalState*)mallocCUDADevice(clscount * sizeof(GoalState), devId); + HostToDevice(clsGoalStateDict[clsid].get(), task.goallist, sizeof(GoalState) * clscount); + task.sigma0_cls = pair.second; + ProcessRFPCTask(task); + FreeCUDADevice(task.goallist); + } + + + + // 文件读写 + omp_lock_t lock; + omp_init_lock(&lock); + omp_set_lock(&lock); + + + cuComplex* h_echoData = (cuComplex*)mallocCUDAHost(prfcount * task.freqNum * sizeof(cuComplex)); + DeviceToHost(h_echoData, task.d_echoData, prfcount* task.freqNum * sizeof(cuComplex)); + + long prfcount_read = prfcount; + std::shared_ptr> fileEchoArr = this->EchoSimulationData->getEchoArr(startprfid, prfcount_read); + + for (size_t i = 0; i < prfcount; i++) { + for (size_t j = 0; j < task.freqNum; j++) { + std::complex temp = fileEchoArr.get()[i * task.freqNum + j]; + fileEchoArr.get()[i * task.freqNum + j] = std::complex( + temp.real() + h_echoData[i * task.freqNum + j].x, + temp.imag() + h_echoData[i * task.freqNum + j].y + ); + } + } + + + this->EchoSimulationData->saveEchoArr(fileEchoArr, startprfid, prfcount_read); + + + omp_unset_lock(&lock); // 锟酵放伙拷斤拷 + omp_destroy_lock(&lock); // 劫伙拷斤拷 + + FreeCUDADevice(task.d_echoData); + FreeCUDADevice(task.antlist); + //FreeCUDADevice(task.goallist); + + return ErrorCode::SUCCESS; +} + diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.h b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.h index 75c9667..0dafc01 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.h +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.h @@ -79,6 +79,10 @@ private: // ErrorCode InitEchoMaskArray(); //ErrorCode RFPCMainProcess(long num_thread); ErrorCode RFPCMainProcess_GPU(); + ErrorCode RFPCMainProcess_MultiGPU_NoAntPattern(); // GPU,߷ͼ + + ErrorCode RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, size_t prfcount,int devId=0); + std::shared_ptr getSatelliteOribtNodes(double prf_time, double dt, bool antflag, long double imageStarttime); diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index e18556f..1072389 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -226,6 +226,7 @@ + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index c565244..6ca9c53 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -217,5 +217,8 @@ SimulationSAR + + SimulationSAR + \ No newline at end of file From 6a62a17dc26dc64791cd4c62883dbcf3b1195496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 23 Mar 2025 17:31:22 +0800 Subject: [PATCH 26/94] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/BaseTool/EchoDataFormat.cpp | 1 + .../SimulationSAR/RFPCProcessCls.cpp | 41 +++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp b/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp index 250ef30..42044ff 100644 --- a/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp +++ b/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp @@ -234,6 +234,7 @@ ErrorCode EchoL0Dataset::Open(QString folder, QString filename) { return ErrorCode::ECHO_L0DATA_ECHOFILEFORMATERROR; } + return ErrorCode::SUCCESS; } QString EchoL0Dataset::getxmlName() diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 221d981..d7f08f7 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1016,10 +1016,12 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si std::map> clsGoalStateDict; for (const auto& pair : clsCountDict) { - clsGoalStateDict.insert( - std::pair>( - pair.first, - std::shared_ptr((GoalState*)mallocCUDAHost(sizeof(GoalState) * pair.second), FreeCUDAHost))); + if (pair.second > 0) { + clsGoalStateDict.insert( + std::pair>( + pair.first, + std::shared_ptr((GoalState*)mallocCUDAHost(sizeof(GoalState) * pair.second), FreeCUDAHost))); + } } // 分块处理大小 @@ -1030,18 +1032,33 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si clsCountDictTemp.insert(std::pair(pair.first, pair.second)); } + double sumdemx = 0; + for (long i = 0; i < demCount; i++) { + sumdemx= sumdemx+demX.get()[i]; + } + + + for (long i = 0; i < demCount; i++) { long clsid = clsArr.get()[i]; size_t Currentclscount = clsCountDictTemp[clsid]; size_t allclscount = clsCountDict[clsid]; - clsGoalStateDict[clsid].get()[Currentclscount-allclscount].Tx = demX.get()[i]; - clsGoalStateDict[clsid].get()[Currentclscount-allclscount].Ty = demY.get()[i]; - clsGoalStateDict[clsid].get()[Currentclscount-allclscount].Tz = demZ.get()[i]; - clsGoalStateDict[clsid].get()[Currentclscount-allclscount].TsX = slpX.get()[i]; - clsGoalStateDict[clsid].get()[Currentclscount-allclscount].TsY = slpY.get()[i]; - clsGoalStateDict[clsid].get()[Currentclscount-allclscount].TsZ = slpZ.get()[i]; - clsGoalStateDict[clsid].get()[Currentclscount-allclscount].cls = clsArr.get()[i]; - Currentclscount = Currentclscount - 1; + + if (clsGoalStateDict.find(clsid) == clsGoalStateDict.end()) { + continue; + } + + clsGoalStateDict[clsid].get()[Currentclscount - allclscount]; + + + clsGoalStateDict[clsid].get()[allclscount- Currentclscount].Tx = demX.get()[i]; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].Ty = demY.get()[i]; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].Tz = demZ.get()[i]; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].TsX = slpX.get()[i]; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].TsY = slpY.get()[i]; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].TsZ = slpZ.get()[i]; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].cls = clsArr.get()[i]; + clsCountDictTemp[clsid] = clsCountDictTemp[clsid] - 1; } From cb9012e7501b36255dc0c896f9da4287db41abc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 23 Mar 2025 18:07:40 +0800 Subject: [PATCH 27/94] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSARTool/SimulationSAR/GPURFPC.cu | 16 ++++++++-------- .../SimulationSAR/RFPCProcessCls.cpp | 11 ++++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index cd86f67..3e2aa72 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -485,13 +485,13 @@ __global__ void CUDA_Kernel_RFPC( cuComplex* echodata ) { - __shared__ GoalState Ts[SHAREMEMORY_DEM_STEP]; - long threadid = threadIdx.x; + + size_t threadid = threadIdx.x; - long idx = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ - long prfid = floorf(idx / Freqcount); - long freqid = idx % Freqcount; + size_t idx = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ + size_t prfid = floorf(idx / Freqcount); + size_t freqid = idx % Freqcount; // printf("%d,%d ",prfid,freqid); if (prfid < PRFCount && freqid < Freqcount) { @@ -565,9 +565,9 @@ __global__ void CUDA_Kernel_RFPC( extern "C" void ProcessRFPCTask(RFPCTask& task) { - long pixelcount = task.prfNum * task.freqNum; - long grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; - printf("start %d ,%d,%d\n", task.targetnum, grid_size, BLOCK_SIZE); + size_t pixelcount = task.prfNum * task.freqNum; + size_t grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; + printf("start %d,%d ,%d,%d\n", pixelcount, task.targetnum, grid_size, BLOCK_SIZE); CUDA_Kernel_RFPC << > > ( task.antlist, task.prfNum,task.freqNum, diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index d7f08f7..4d37a4c 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -939,23 +939,23 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_MultiGPU_NoAntPattern() long prfcount = this->EchoSimulationData->getPluseCount(); size_t prfblockcount = (prfcount + num_devices +2- 1) / num_devices; - + PRINT("PRF COUNT : %d , child PRF COUNT: %d\n", prfcount, prfblockcount); double prf_time = 0; double dt = 1 / this->TaskSetting->getPRF();// 获取每次脉冲的时间间隔 bool antflag = true; // 计算天线方向图 long double imageStarttime = this->TaskSetting->getSARImageStartTime(); std::shared_ptr sateOirbtNodes = this->getSatelliteOribtNodes(prf_time, dt, antflag, imageStarttime); - + #pragma omp parallel for for (int devid = 0; devid < num_devices; devid++) { cudaSetDevice(devid); // 确保当前线程操作指定的GPU设备 - this->RFPCMainProcess_GPU_NoAntPattern(0, 0, devid); size_t startTid = devid * prfblockcount; size_t prf_devLen = prfblockcount; prf_devLen = (startTid + prf_devLen) < prfcount ? prf_devLen : (prfcount - startTid); + PRINT("dev ID:%d,start PRF ID: %d , PRF COUNT: %d \n", devid, startTid, prf_devLen); this->RFPCMainProcess_GPU_NoAntPattern(startTid, prf_devLen, devid); } @@ -965,6 +965,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_MultiGPU_NoAntPattern() ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, size_t prfcount, int devId) { + PRINT("dev ID:%d,start PRF ID: %d , PRF COUNT: %d \n", devId,startprfid,prfcount); /// 显存不限制 cudaSetDevice(devId); // 确保当前线程操作指定的GPU设备 POLARTYPEENUM polartype = this->TaskSetting->getPolarType(); @@ -1094,14 +1095,14 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si } // 分块计算 - for (const auto& pair : clsCUDASigmaParamsDict) { + for (const auto& pair : clsGoalStateDict) { long clsid = pair.first; size_t clscount = clsCountDict[clsid]; PRINT("Process Class ID : %d , Count: %d\n", clsid, clscount); task.targetnum = clscount; task.goallist = (GoalState*)mallocCUDADevice(clscount * sizeof(GoalState), devId); HostToDevice(clsGoalStateDict[clsid].get(), task.goallist, sizeof(GoalState) * clscount); - task.sigma0_cls = pair.second; + task.sigma0_cls = clsCUDASigmaParamsDict[clsid]; ProcessRFPCTask(task); FreeCUDADevice(task.goallist); } From 96eb60bbec47281ee3dc61fc4b3ca752a667a5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 23 Mar 2025 18:49:27 +0800 Subject: [PATCH 28/94] tongbuxiugai --- .../SimulationSAR/GPURFPC.cu | 75 ++++++++----------- 1 file changed, 32 insertions(+), 43 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index 3e2aa72..db28ac6 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -510,50 +510,39 @@ __global__ void CUDA_Kernel_RFPC( cuComplex echo = make_cuComplex(0, 0); - for (long startid = 0; startid < demLen; startid = startid + SHAREMEMORY_DEM_STEP) - { - __syncthreads(); // ȷдݶѾ - for (long i = 0; i < 3; i++) { - long ttid = startid + threadid + i * blockDim.x; - long stid = threadid + i * blockDim.x; - if ((stid < SHAREMEMORY_DEM_STEP) && (ttid < demLen)) { - Ts[stid] = goallist[ttid]; + + + for (long tid = 0;tid < demLen;tid++) { + GoalState p = goallist[tid]; + Tx = p.Tx; + Ty = p.Ty; + Tz = p.Tz; + + Tx = antPos.Px - Tx; // T->P + Ty = antPos.Py - Ty; + Tz = antPos.Pz - Tz; + + R = sqrt(Tx * Tx + Ty * Ty + Tz * Tz); + bool isNearFar = (R < NearR || R > FarR) && ((abs(p.TsX) > 1000) || (abs(p.TsY) > 1000) || (abs(p.TsZ) > 1000)); + + + incAngle = sqrt(p.TsX * p.TsX + p.TsY * p.TsY + p.TsZ * p.TsZ); + incAngle = acos((Tx * p.TsX + Ty * p.TsY + Tz * p.TsZ) / (R * incAngle)); + incAngle = GPU_getSigma0dB_params(clsSigma0.p1, clsSigma0.p2, clsSigma0.p3, clsSigma0.p4, clsSigma0.p5, clsSigma0.p6, incAngle); // sigma + incAngle = pow(10.0, incAngle / 10.0); // amp + incAngle = incAngle / (powf(4 * LAMP_CUDA_PI, 2) * powf(R, 4)); // + + R = (R - refPhaseRange); + R = factorjTemp * R; + + echo_real = incAngle * cos(R) * isNearFar; + echo_imag = incAngle * sin(R) * isNearFar; + echo.x = echo.x + echo_real; + echo.y = echo.y + echo_imag; + + if (idx == 0 && tid % (10 * SHAREMEMORY_DEM_STEP) == 0) { + printf("Idx:%d , TsID: %d, TSCOUNT: %d \n", idx, tid, demLen); } - } - __syncthreads(); // ȷдݶѾ - - for (long tid = 0; tid < SHAREMEMORY_DEM_STEP; tid++) - { - if ((tid + startid) < demLen) - { - GoalState p = Ts[tid]; - Tx = p.Tx; - Ty = p.Ty; - Tz = p.Tz; - - Tx = antPos.Px - Tx; // T->P - Ty = antPos.Py - Ty; - Tz = antPos.Pz - Tz; - - R = sqrt(Tx * Tx + Ty * Ty + Tz * Tz); - bool isNearFar = (R < NearR || R > FarR); - - - incAngle = sqrt(p.TsX * p.TsX + p.TsY * p.TsY + p.TsZ * p.TsZ); - incAngle = acos((Tx * p.TsX + Ty * p.TsY + Tz * p.TsZ) / (R * incAngle)); - incAngle = GPU_getSigma0dB_params(clsSigma0.p1, clsSigma0.p2, clsSigma0.p3, clsSigma0.p4, clsSigma0.p5, clsSigma0.p6, incAngle); // sigma - incAngle = pow(10.0, incAngle / 10.0); // amp - incAngle = incAngle / (powf(4 * LAMP_CUDA_PI, 2) * powf(R, 4)); // - - R = (R - refPhaseRange); - R = factorjTemp * R; - - echo_real = incAngle * cos(R)* isNearFar; - echo_imag = incAngle * sin(R)* isNearFar; - echo.x = echo.x + echo_real; - echo.y = echo.y + echo_imag; - } - } } echodata[idx] = cuCaddf(echodata[idx], echo); From 4cf63eee3667fdf97a2d2c326c01105a8f87b849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 24 Mar 2025 10:36:46 +0800 Subject: [PATCH 29/94] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=9A=E5=8D=A1?= =?UTF-8?q?=E6=97=A0=E5=A4=A9=E7=BA=BF=E8=BE=90=E5=B0=84=E5=9B=BE=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSAR/GPURFPC.cu | 326 ++++++++++++++---- .../SimulationSAR/GPURFPC.cuh | 2 +- .../SimulationSAR/RFPCProcessCls.cpp | 2 +- 3 files changed, 256 insertions(+), 74 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index db28ac6..a2efa46 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -21,8 +21,8 @@ extern __device__ double GPU_getSigma0dB(CUDASigmaParam param, double theta) {/ __device__ double GPU_getSigma0dB_params( - const double p1, const double p2, const double p3, const double p4, const double p5, const double p6, - double theta) {//ֵ + 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); } @@ -71,8 +71,8 @@ extern __device__ CUDAVectorEllipsoidal GPU_SatelliteAntDirectNormal( // theta phi double Norm = sqrtf(Xant * Xant + Yant * Yant + Zant * Zant); // pho double Zn = Zant / Norm; - double ThetaAnt = ( - 1 > Zn) ? PI : (Zn > 1 ? 0 : acos(Zn));// acosf(Zant / Norm); // theta Zļн - double PhiAnt = abs(Xant) Zn) ? PI : (Zn > 1 ? 0 : acos(Zn));// acosf(Zant / Norm); // theta Zļн + double PhiAnt = abs(Xant) < PRECISIONTOLERANCE ? 0 : atanf(Yant / Xant); // -pi/2 ~pi/2 if (abs(Yant) < PRECISIONTOLERANCE) { // X PhiAnt = 0; @@ -161,9 +161,9 @@ extern __device__ double GPU_BillerInterpAntPattern(double* antpattern, return GainValue; } } - - + + /* ˺ ****************************************************************************************************************************/ // ÿ __global__ void CUDA_Kernel_Computer_R_amp( @@ -173,8 +173,8 @@ __global__ void CUDA_Kernel_Computer_R_amp( double* antZaxisX, double* antZaxisY, double* antZaxisZ, double* antDirectX, double* antDirectY, double* antDirectZ, long PRFCount, // - double* targetX, double* targetY, double* targetZ, long* demCls, - double* demSlopeX, double* demSlopeY, double* demSlopeZ , + double* targetX, double* targetY, double* targetZ, long* demCls, + double* demSlopeX, double* demSlopeY, double* demSlopeZ, long startPosId, long pixelcount, CUDASigmaParam* sigma0Paramslist, long sigmaparamslistlen, double Pt, @@ -189,8 +189,8 @@ __global__ void CUDA_Kernel_Computer_R_amp( ) { long idx = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ long prfId = idx / SHAREMEMORY_FLOAT_HALF; - long posId = idx % SHAREMEMORY_FLOAT_HALF+ startPosId; // ǰ̶߳ӦӰ - + long posId = idx % SHAREMEMORY_FLOAT_HALF + startPosId; // ǰ̶߳ӦӰ + if (prfId < PRFCount && posId < pixelcount) { double RstX = antX[prfId] - targetX[posId]; // ʸ double RstY = antY[prfId] - targetY[posId]; @@ -206,13 +206,13 @@ __global__ void CUDA_Kernel_Computer_R_amp( double slopeX = demSlopeX[posId]; double slopeY = demSlopeY[posId]; double slopeZ = demSlopeZ[posId]; - + double slopR = sqrtf(slopeX * slopeX + slopeY * slopeY + slopeZ * slopeZ); // if (abs(slopR - 0) > 1e-3) { double dotAB = RstX * slopeX + RstY * slopeY + RstZ * slopeZ; - double localangle = acos(dotAB / (RstR * slopR)); + double localangle = acos(dotAB / (RstR * slopR)); - if (localangle < 0 || localangle >= LAMP_CUDA_PI / 2|| isnan(localangle)) { + if (localangle < 0 || localangle >= LAMP_CUDA_PI / 2 || isnan(localangle)) { d_temp_R[idx] = 0; d_temp_amps[idx] = 0; return; @@ -248,7 +248,7 @@ __global__ void CUDA_Kernel_Computer_R_amp( //printf("clsid=%d\n", clsid); CUDASigmaParam tempsigma = sigma0Paramslist[clsid]; - + if (abs(tempsigma.p1) < PRECISIONTOLERANCE && abs(tempsigma.p2) < PRECISIONTOLERANCE && abs(tempsigma.p3) < PRECISIONTOLERANCE && @@ -276,19 +276,19 @@ __global__ void CUDA_Kernel_Computer_R_amp( ampGain = ampGain / (powf(4 * LAMP_CUDA_PI, 2) * powf(RstR, 4)); // ǿ - + float temp_amp = float(ampGain * Pt * sigma0); float temp_R = float(RstR - refPhaseRange); - if (isnan(temp_amp) || isnan(temp_R)|| isinf(temp_amp) || isinf(temp_R)) { + if (isnan(temp_amp) || isnan(temp_R) || isinf(temp_amp) || isinf(temp_R)) { printf("amp is nan or R is nan,amp=%f;R=%f; \n", temp_amp, temp_R); d_temp_R[idx] = 0; d_temp_amps[idx] = 0; return; } else {} - - + + d_temp_amps[idx] = temp_amp; d_temp_R[idx] = temp_R; return; @@ -313,12 +313,12 @@ __global__ void CUDA_Kernel_Computer_R_amp( __global__ void CUDA_Kernel_Computer_echo( float* d_temp_R, float* d_temp_amps, long posNum, - float f0, float dfreq, + float f0, float dfreq, long FreqPoints, // ǰƵʵķֿ long maxfreqnum, // ֵ float* d_temp_echo_real, float* d_temp_echo_imag, long temp_PRF_Count -) { +) { __shared__ float s_R[SHAREMEMORY_FLOAT_HALF]; // עһblock_size ͬڴ __shared__ float s_amp[SHAREMEMORY_FLOAT_HALF]; @@ -349,7 +349,7 @@ __global__ void CUDA_Kernel_Computer_echo( if (fId < maxfreqnum && prfId < temp_PRF_Count) { - + long echo_ID = prfId * maxfreqnum + fId; // ӦĻزλ float factorjTemp = RFPCPIDIVLIGHT * (f0 + fId * dfreq); float temp_real = 0; @@ -368,9 +368,9 @@ __global__ void CUDA_Kernel_Computer_echo( if (isnan(temp_phi) || isnan(temp_amp) || isnan(temp_real) || isnan(temp_imag) || isinf(temp_phi) || isinf(temp_amp) || isinf(temp_real) || isinf(temp_imag) ) { - printf("[amp,phi,real,imag]=[%f,%f,%f,%f];\n",temp_amp,temp_phi,temp_real,temp_imag); + printf("[amp,phi,real,imag]=[%f,%f,%f,%f];\n", temp_amp, temp_phi, temp_real, temp_imag); } - + } //printf("echo_ID=%d; ehodata=(%f,%f)\n", echo_ID, temp_real, temp_imag); //printf("(%f %f %f) ", factorjTemp, s_amp[0], s_R[0]); @@ -390,7 +390,7 @@ void CUDA_RFPC_MainProcess( double* antYaxisX, double* antYaxisY, double* antYaxisZ, double* antZaxisX, double* antZaxisY, double* antZaxisZ, double* antDirectX, double* antDirectY, double* antDirectZ, - long PRFCount, long FreqNum, + long PRFCount, long FreqNum, float f0, float dfreq, double Pt, double refPhaseRange, @@ -401,7 +401,7 @@ void CUDA_RFPC_MainProcess( double maxTransAntPatternValue, double maxReceiveAntPatternValue, double NearR, double FarR, double* targetX, double* targetY, double* targetZ, long* demCls, long TargetNumber, - double* demSlopeX, double* demSlopeY, double* demSlopeZ, + double* demSlopeX, double* demSlopeY, double* demSlopeZ, CUDASigmaParam* sigma0Paramslist, long sigmaparamslistlen, float* out_echoReal, float* out_echoImag, float* d_temp_R, float* d_temp_amp @@ -420,9 +420,9 @@ void CUDA_RFPC_MainProcess( antYaxisX, antYaxisY, antYaxisZ, antZaxisX, antZaxisY, antZaxisZ, antDirectX, antDirectY, antDirectZ, - PRFCount, - targetX, targetY, targetZ, demCls, - demSlopeX, demSlopeY, demSlopeZ, + PRFCount, + targetX, targetY, targetZ, demCls, + demSlopeX, demSlopeY, demSlopeZ, sTi, TargetNumber, sigma0Paramslist, sigmaparamslistlen, Pt, @@ -437,23 +437,23 @@ void CUDA_RFPC_MainProcess( ); PrintLasterError("CUDA_Kernel_Computer_R_amp"); - - + + cudaBlocknum = (PRFCount * BLOCK_FREQNUM + BLOCK_SIZE - 1) / BLOCK_SIZE; CUDA_Kernel_Computer_echo << > > ( d_temp_R, d_temp_amp, SHAREMEMORY_FLOAT_HALF, - f0, dfreq, + f0, dfreq, freqpoints, FreqNum, out_echoReal, out_echoImag, PRFCount ); PrintLasterError("CUDA_Kernel_Computer_echo"); - if ((sTi * 100.0 / TargetNumber ) - process >= 1) { + if ((sTi * 100.0 / TargetNumber) - process >= 1) { process = sTi * 100.0 / TargetNumber; - PRINT("TargetID [%f]: %d / %d finished\n", sTi*100.0/ TargetNumber,sTi, TargetNumber); + PRINT("TargetID [%f]: %d / %d finished\n", sTi * 100.0 / TargetNumber, sTi, TargetNumber); } - + } @@ -473,6 +473,150 @@ void CUDA_RFPC_MainProcess( /* ˺ ****************************************************************************************************************************/ + +__global__ void Kernel_Computer_R_amp_NoAntPattern( + SateState* antlist, + long PRFCount, + GoalState* goallist, + long demLen, + long startPosId, long pixelcount, + CUDASigmaParam sigma0Params, + double Pt, + double refPhaseRange, + double NearR, double FarR, + double* d_temp_R, double* d_temp_amps// +) { + long idx = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ + long prfId = idx / SHAREMEMORY_FLOAT_HALF; + long posId = idx % SHAREMEMORY_FLOAT_HALF + startPosId; // ǰ̶߳ӦӰ + + if (prfId < PRFCount && posId < pixelcount) { + double RstX = antlist[prfId].Px - goallist[posId].Tx; // ʸ + double RstY = antlist[prfId].Py - goallist[posId].Ty; + double RstZ = antlist[prfId].Pz - goallist[posId].Tz; + + double RstR = sqrt(RstX * RstX + RstY * RstY + RstZ * RstZ); // ʸ + if (RstRFarR) { + d_temp_R[idx] = 0; + d_temp_amps[idx] = 0; + return; + } + else { + double slopeX = goallist[posId].TsX; + double slopeY = goallist[posId].TsY; + double slopeZ = goallist[posId].TsZ; + + double slopR = sqrtf(slopeX * slopeX + slopeY * slopeY + slopeZ * slopeZ); // + if (abs(slopR - 0) > 1e-3) { + double dotAB = RstX * slopeX + RstY * slopeY + RstZ * slopeZ; + double localangle = acos(dotAB / (RstR * slopR)); + + if (localangle < 0 || localangle >= LAMP_CUDA_PI / 2 || isnan(localangle)) { + d_temp_R[idx] = 0; + d_temp_amps[idx] = 0; + return; + } + else {} + + double ampGain = 1; + ampGain = ampGain / (powf(4 * LAMP_CUDA_PI, 2) * powf(RstR, 4)); // ǿ + double sigma = GPU_getSigma0dB(sigma0Params, localangle); + sigma = powf(10.0, sigma / 10.0); + + double temp_amp = double(ampGain * Pt * sigma); + double temp_R = double(RstR - refPhaseRange); + + bool isNan = !(isnan(temp_amp) || isnan(temp_R) || isinf(temp_amp) || isinf(temp_R)); + + + d_temp_amps[idx] = temp_amp * isNan; + d_temp_R[idx] = temp_R * isNan; + return; + } + } + } +} + + + + +__global__ void CUDA_Kernel_Computer_echo_NoAntPattern( + double* d_temp_R, double* d_temp_amps, long posNum, + double f0, double dfreq, + long FreqPoints, // ǰƵʵķֿ + long maxfreqnum, // ֵ + cuComplex* echodata, + long temp_PRF_Count +) { + __shared__ float s_R[SHAREMEMORY_FLOAT_HALF]; // עһblock_size ͬڴ + __shared__ float s_amp[SHAREMEMORY_FLOAT_HALF]; + + long tid = threadIdx.x; + long bid = blockIdx.x; + long idx = bid * blockDim.x + tid; + long prfId = idx / FreqPoints; // ID + long fId = idx % FreqPoints;//ƵID + + long psid = 0; + long pixelId = 0; + for (long ii = 0; ii < SHAREMEMORY_FLOAT_HALF_STEP; ii++) { // SHAREMEMORY_FLOAT_HALF_STEP * BLOCK_SIZE=SHAREMEMORY_FLOAT_HALF + psid = tid * SHAREMEMORY_FLOAT_HALF_STEP + ii; + pixelId = prfId * posNum + psid; // + if (psid < posNum) { + s_R[psid] = d_temp_R[pixelId]; + s_amp[psid] = d_temp_amps[pixelId]; + } + else { + s_R[psid] = 0; + s_amp[psid] = 0; + } + + } + + __syncthreads(); // ȷдݶѾ + + + + if (fId < maxfreqnum && prfId < temp_PRF_Count) { + + long echo_ID = prfId * maxfreqnum + fId; // ӦĻزλ + float factorjTemp = RFPCPIDIVLIGHT * (f0 + fId * dfreq); + cuComplex echo = make_cuComplex(0, 0); + float temp_phi = 0; + float temp_amp = 0; + for (long dataid = 0; dataid < SHAREMEMORY_FLOAT_HALF; dataid++) { + + temp_phi = s_R[dataid] * factorjTemp; + temp_amp = s_amp[dataid]; + echo.x += (temp_amp * cosf(temp_phi)); + echo.y += (temp_amp * sinf(temp_phi)); + //if (dataid > 5000) { + // printf("echo_ID=%d; dataid=%d;ehodata=(%f,%f);R=%f;amp=%f;\n", echo_ID, dataid, temp_real, temp_imag, s_R[0], s_amp[0]); + //} + if (isnan(temp_phi) || isnan(temp_amp) || isnan(echo.x) || isnan(echo.y) + || isinf(temp_phi) || isinf(temp_amp) || isinf(echo.x) || isinf(echo.y) + ) { + printf("[amp,phi,real,imag]=[%f,%f,%f,%f];\n", temp_amp, temp_phi, echo.x, echo.y); + } + + } + + echodata[echo_ID] = cuCaddf(echodata[echo_ID], echo); + + } +} + + + + + + + + + + + + __global__ void CUDA_Kernel_RFPC( SateState* antlist, long PRFCount, long Freqcount, // @@ -483,12 +627,12 @@ __global__ void CUDA_Kernel_RFPC( double NearR, double FarR, CUDASigmaParam clsSigma0, cuComplex* echodata - ) +) { __shared__ GoalState Ts[SHAREMEMORY_DEM_STEP]; size_t threadid = threadIdx.x; - + size_t idx = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ size_t prfid = floorf(idx / Freqcount); size_t freqid = idx % Freqcount; @@ -512,37 +656,37 @@ __global__ void CUDA_Kernel_RFPC( - for (long tid = 0;tid < demLen;tid++) { - GoalState p = goallist[tid]; - Tx = p.Tx; - Ty = p.Ty; - Tz = p.Tz; + for (long tid = 0; tid < demLen; tid++) { + GoalState p = goallist[tid]; + Tx = p.Tx; + Ty = p.Ty; + Tz = p.Tz; - Tx = antPos.Px - Tx; // T->P - Ty = antPos.Py - Ty; - Tz = antPos.Pz - Tz; + Tx = antPos.Px - Tx; // T->P + Ty = antPos.Py - Ty; + Tz = antPos.Pz - Tz; - R = sqrt(Tx * Tx + Ty * Ty + Tz * Tz); - bool isNearFar = (R < NearR || R > FarR) && ((abs(p.TsX) > 1000) || (abs(p.TsY) > 1000) || (abs(p.TsZ) > 1000)); + R = sqrt(Tx * Tx + Ty * Ty + Tz * Tz); + bool isNearFar = (R < NearR || R > FarR) && ((abs(p.TsX) > 1000) || (abs(p.TsY) > 1000) || (abs(p.TsZ) > 1000)); - incAngle = sqrt(p.TsX * p.TsX + p.TsY * p.TsY + p.TsZ * p.TsZ); - incAngle = acos((Tx * p.TsX + Ty * p.TsY + Tz * p.TsZ) / (R * incAngle)); - incAngle = GPU_getSigma0dB_params(clsSigma0.p1, clsSigma0.p2, clsSigma0.p3, clsSigma0.p4, clsSigma0.p5, clsSigma0.p6, incAngle); // sigma - incAngle = pow(10.0, incAngle / 10.0); // amp - incAngle = incAngle / (powf(4 * LAMP_CUDA_PI, 2) * powf(R, 4)); // + incAngle = sqrt(p.TsX * p.TsX + p.TsY * p.TsY + p.TsZ * p.TsZ); + incAngle = acos((Tx * p.TsX + Ty * p.TsY + Tz * p.TsZ) / (R * incAngle)); + incAngle = GPU_getSigma0dB_params(clsSigma0.p1, clsSigma0.p2, clsSigma0.p3, clsSigma0.p4, clsSigma0.p5, clsSigma0.p6, incAngle); // sigma + incAngle = pow(10.0, incAngle / 10.0); // amp + incAngle = incAngle / (powf(4 * LAMP_CUDA_PI, 2) * powf(R, 4)); // - R = (R - refPhaseRange); - R = factorjTemp * R; + R = (R - refPhaseRange); + R = factorjTemp * R; - echo_real = incAngle * cos(R) * isNearFar; - echo_imag = incAngle * sin(R) * isNearFar; - echo.x = echo.x + echo_real; - echo.y = echo.y + echo_imag; + echo_real = incAngle * cos(R) * isNearFar; + echo_imag = incAngle * sin(R) * isNearFar; + echo.x = echo.x + echo_real; + echo.y = echo.y + echo_imag; - if (idx == 0 && tid % (10 * SHAREMEMORY_DEM_STEP) == 0) { - printf("Idx:%d , TsID: %d, TSCOUNT: %d \n", idx, tid, demLen); - } + if (idx == 0 && tid % (10 * SHAREMEMORY_DEM_STEP) == 0) { + printf("Idx:%d , TsID: %d, TSCOUNT: %d \n", idx, tid, demLen); + } } echodata[idx] = cuCaddf(echodata[idx], echo); @@ -552,24 +696,62 @@ __global__ void CUDA_Kernel_RFPC( /** ֿ鴦 ****************************************************************************************************************/ -extern "C" void ProcessRFPCTask(RFPCTask& task) +extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) { size_t pixelcount = task.prfNum * task.freqNum; size_t grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; printf("start %d,%d ,%d,%d\n", pixelcount, task.targetnum, grid_size, BLOCK_SIZE); - CUDA_Kernel_RFPC << > > ( - task.antlist, - task.prfNum,task.freqNum, - task.goallist, - task.targetnum, - task.startFreq,task.stepFreq, - task.Rref,task.Rnear,task.Rfar, - task.sigma0_cls, - task.d_echoData + + double* d_R = (double*)mallocCUDADevice(task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(double), devid); + double* d_amps = (double*)mallocCUDADevice(task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(double), devid); + + + long BLOCK_FREQNUM = NextBlockPad(task.freqNum, BLOCK_SIZE); // 256*freqBlockID + long cudaBlocknum = 0; + long freqpoints = BLOCK_FREQNUM; + printf("freqpoints:%d\n", freqpoints); + long process = 0; + for (long sTi = 0; sTi < task.targetnum; sTi = sTi + SHAREMEMORY_FLOAT_HALF) { + cudaBlocknum = (task.prfNum * SHAREMEMORY_FLOAT_HALF + BLOCK_SIZE - 1) / BLOCK_SIZE; + Kernel_Computer_R_amp_NoAntPattern << > >( + task.antlist, + task.prfNum, + task.goallist, + task.targetnum, + sTi, task.targetnum, + task.sigma0_cls, + 1, + task.Rref, + task.Rnear, task.Rfar, + d_R, d_amps// ); - PrintLasterError("ProcessRFPCTask"); + PrintLasterError("CUDA_Kernel_Computer_R_amp"); + + + cudaBlocknum = (task.prfNum * BLOCK_FREQNUM + BLOCK_SIZE - 1) / BLOCK_SIZE; + CUDA_Kernel_Computer_echo_NoAntPattern << > > ( + d_R, d_amps, SHAREMEMORY_FLOAT_HALF, + task.startFreq, task.stepFreq, + freqpoints, task.freqNum, + task.d_echoData, + task.prfNum + ); + PrintLasterError("CUDA_Kernel_Computer_echo"); + + if ((sTi * 100.0 / task.targetnum) - process >= 1) { + process = sTi * 100.0 / task.targetnum; + PRINT("TargetID [%f]: %d / %d finished\n", sTi * 100.0 / task.targetnum, sTi, task.targetnum); + } + + + + } + + cudaDeviceSynchronize(); - printf("start %d \n", task.targetnum); + + FreeCUDADevice(d_R); + FreeCUDADevice(d_amps); } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh index b72623b..3035cc8 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh @@ -144,7 +144,7 @@ extern "C" void CUDA_RFPC_MainProcess( extern "C" double* hostSigmaData_toDevice(int devid); -extern "C" void ProcessRFPCTask(RFPCTask& task); +extern "C" void ProcessRFPCTask(RFPCTask& task,long devid); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 4d37a4c..0bb6b46 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1103,7 +1103,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si task.goallist = (GoalState*)mallocCUDADevice(clscount * sizeof(GoalState), devId); HostToDevice(clsGoalStateDict[clsid].get(), task.goallist, sizeof(GoalState) * clscount); task.sigma0_cls = clsCUDASigmaParamsDict[clsid]; - ProcessRFPCTask(task); + ProcessRFPCTask(task,devId); FreeCUDADevice(task.goallist); } From 25057d0b62f7c13e8fd4b27fafef05ad27c8e64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 24 Mar 2025 14:03:54 +0800 Subject: [PATCH 30/94] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/BaseTool/EchoDataFormat.cpp | 2 ++ .../SimulationSAR/GPURFPC.cu | 9 ++++-- .../SimulationSAR/GPURFPC.cuh | 2 +- .../SimulationSAR/RFPCProcessCls.cpp | 29 ++++++++++++------- .../SimulationSAR/RFPCProcessCls.h | 4 +-- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp b/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp index 42044ff..bc50ed5 100644 --- a/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp +++ b/BaseCommonLibrary/BaseTool/EchoDataFormat.cpp @@ -748,8 +748,10 @@ ErrorCode EchoL0Dataset::saveEchoArr(std::shared_ptr> echoP } GDALClose(rasterDataset); rasterDataset = nullptr; + GDALDestroy(); omp_unset_lock(&lock); // omp_destroy_lock(&lock); // + return ErrorCode::SUCCESS; } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index a2efa46..261e7fa 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -531,6 +531,7 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( d_temp_amps[idx] = temp_amp * isNan; d_temp_R[idx] = temp_R * isNan; + //printf("out R amp : %f %e %d %e\n", d_temp_R[idx], d_temp_amps[idx], isNan, sigma); return; } } @@ -695,12 +696,11 @@ __global__ void CUDA_Kernel_RFPC( /** ֿ鴦 ****************************************************************************************************************/ - extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) { size_t pixelcount = task.prfNum * task.freqNum; size_t grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; - printf("start %d,%d ,%d,%d\n", pixelcount, task.targetnum, grid_size, BLOCK_SIZE); + printf("computer pixelcount goalnum gridsize blocksize %zu,%zu ,%zu,%d\n", pixelcount, task.targetnum, grid_size, BLOCK_SIZE); double* d_R = (double*)mallocCUDADevice(task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(double), devid); double* d_amps = (double*)mallocCUDADevice(task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(double), devid); @@ -726,6 +726,9 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) d_R, d_amps// ); PrintLasterError("CUDA_Kernel_Computer_R_amp"); + cudaDeviceSynchronize(); + + cudaBlocknum = (task.prfNum * BLOCK_FREQNUM + BLOCK_SIZE - 1) / BLOCK_SIZE; @@ -737,7 +740,7 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) task.prfNum ); PrintLasterError("CUDA_Kernel_Computer_echo"); - + cudaDeviceSynchronize(); if ((sTi * 100.0 / task.targetnum) - process >= 1) { process = sTi * 100.0 / task.targetnum; PRINT("TargetID [%f]: %d / %d finished\n", sTi * 100.0 / task.targetnum, sTi, task.targetnum); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh index 3035cc8..79b94b8 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh @@ -87,7 +87,7 @@ extern "C" struct RFPCTask CUDASigmaParam sigma0_cls; - long targetnum; + size_t targetnum; }; diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 0bb6b46..5d64dc8 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1108,6 +1108,18 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si } + this->SaveBlockSimulationEchoArr(task.d_echoData, prfcount, task.freqNum, startprfid); + + + FreeCUDADevice(task.d_echoData); + FreeCUDADevice(task.antlist); + //FreeCUDADevice(task.goallist); + + return ErrorCode::SUCCESS; +} + +ErrorCode RFPCProcessCls::SaveBlockSimulationEchoArr(cuComplex* d_echoData,size_t prfcount,size_t freqNum,long startprfid) +{ // 文件读写 omp_lock_t lock; @@ -1115,18 +1127,18 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si omp_set_lock(&lock); - cuComplex* h_echoData = (cuComplex*)mallocCUDAHost(prfcount * task.freqNum * sizeof(cuComplex)); - DeviceToHost(h_echoData, task.d_echoData, prfcount* task.freqNum * sizeof(cuComplex)); + cuComplex* h_echoData = (cuComplex*)mallocCUDAHost(prfcount * freqNum * sizeof(cuComplex)); + DeviceToHost(h_echoData, d_echoData, prfcount * freqNum * sizeof(cuComplex)); long prfcount_read = prfcount; std::shared_ptr> fileEchoArr = this->EchoSimulationData->getEchoArr(startprfid, prfcount_read); for (size_t i = 0; i < prfcount; i++) { - for (size_t j = 0; j < task.freqNum; j++) { - std::complex temp = fileEchoArr.get()[i * task.freqNum + j]; - fileEchoArr.get()[i * task.freqNum + j] = std::complex( - temp.real() + h_echoData[i * task.freqNum + j].x, - temp.imag() + h_echoData[i * task.freqNum + j].y + for (size_t j = 0; j < freqNum; j++) { + std::complex temp = fileEchoArr.get()[i * freqNum + j]; + fileEchoArr.get()[i * freqNum + j] = std::complex( + temp.real() + h_echoData[i * freqNum + j].x, + temp.imag() + h_echoData[i * freqNum + j].y ); } } @@ -1138,9 +1150,6 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si omp_unset_lock(&lock); // 锟酵放伙拷斤拷 omp_destroy_lock(&lock); // 劫伙拷斤拷 - FreeCUDADevice(task.d_echoData); - FreeCUDADevice(task.antlist); - //FreeCUDADevice(task.goallist); return ErrorCode::SUCCESS; } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.h b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.h index 0dafc01..b271d16 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.h +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.h @@ -27,7 +27,7 @@ #include "SatelliteOribtModel.h" #include "EchoDataFormat.h" #include "SigmaDatabase.h" - +#include /***** ߺ *******************************/ @@ -82,7 +82,7 @@ private: // ErrorCode RFPCMainProcess_MultiGPU_NoAntPattern(); // GPU,߷ͼ ErrorCode RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, size_t prfcount,int devId=0); - + ErrorCode SaveBlockSimulationEchoArr(cuComplex* d_echoData, size_t prfcount, size_t freqNum, long startprfid); std::shared_ptr getSatelliteOribtNodes(double prf_time, double dt, bool antflag, long double imageStarttime); From 3512ebfe69df81c51d83c91a92354615d59b3857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 24 Mar 2025 14:33:21 +0800 Subject: [PATCH 31/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=AE=97=E6=B3=95bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSAR/GPURFPC.cu | 22 +++++++++---------- .../SimulationSAR/RFPCProcessCls.cpp | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index 261e7fa..ddde40b 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -486,9 +486,9 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( double NearR, double FarR, double* d_temp_R, double* d_temp_amps// ) { - long idx = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ - long prfId = idx / SHAREMEMORY_FLOAT_HALF; - long posId = idx % SHAREMEMORY_FLOAT_HALF + startPosId; // ǰ̶߳ӦӰ + long long idx = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ + long long prfId = idx / SHAREMEMORY_FLOAT_HALF; + long long posId = idx % SHAREMEMORY_FLOAT_HALF + startPosId; // ǰ̶߳ӦӰ if (prfId < PRFCount && posId < pixelcount) { double RstX = antlist[prfId].Px - goallist[posId].Tx; // ʸ @@ -552,14 +552,14 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( __shared__ float s_R[SHAREMEMORY_FLOAT_HALF]; // עһblock_size ͬڴ __shared__ float s_amp[SHAREMEMORY_FLOAT_HALF]; - long tid = threadIdx.x; - long bid = blockIdx.x; - long idx = bid * blockDim.x + tid; - long prfId = idx / FreqPoints; // ID - long fId = idx % FreqPoints;//ƵID + long long tid = threadIdx.x; + long long bid = blockIdx.x; + long long idx = bid * blockDim.x + tid; + long long prfId = idx / FreqPoints; // ID + long long fId = idx % FreqPoints;//ƵID - long psid = 0; - long pixelId = 0; + long long psid = 0; + long long pixelId = 0; for (long ii = 0; ii < SHAREMEMORY_FLOAT_HALF_STEP; ii++) { // SHAREMEMORY_FLOAT_HALF_STEP * BLOCK_SIZE=SHAREMEMORY_FLOAT_HALF psid = tid * SHAREMEMORY_FLOAT_HALF_STEP + ii; pixelId = prfId * posNum + psid; // @@ -743,7 +743,7 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) cudaDeviceSynchronize(); if ((sTi * 100.0 / task.targetnum) - process >= 1) { process = sTi * 100.0 / task.targetnum; - PRINT("TargetID [%f]: %d / %d finished\n", sTi * 100.0 / task.targetnum, sTi, task.targetnum); + PRINT("TargetID [%f]: %d / %d finished %d\n", sTi * 100.0 / task.targetnum, sTi, task.targetnum,devid); } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 5d64dc8..ebcac77 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1022,6 +1022,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si std::pair>( pair.first, std::shared_ptr((GoalState*)mallocCUDAHost(sizeof(GoalState) * pair.second), FreeCUDAHost))); + PRINT("clsid : %d ,Count: %d\n", pair.first, pair.second); } } From 4bd1b24af039ff2fec96dcac955d6c4aee4c3524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 24 Mar 2025 14:56:14 +0800 Subject: [PATCH 32/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=8F=82?= =?UTF-8?q?=E6=95=B0print=20=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index ebcac77..ff8b3be 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -966,6 +966,11 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_MultiGPU_NoAntPattern() ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, size_t prfcount, int devId) { PRINT("dev ID:%d,start PRF ID: %d , PRF COUNT: %d \n", devId,startprfid,prfcount); + + + + + /// 显存不限制 cudaSetDevice(devId); // 确保当前线程操作指定的GPU设备 POLARTYPEENUM polartype = this->TaskSetting->getPolarType(); @@ -1076,6 +1081,9 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si task.stepFreq = this->EchoSimulationData->getBandwidth() / (task.freqNum - 1); task.d_echoData = (cuComplex*)mallocCUDADevice(prfcount * task.freqNum * sizeof(cuComplex), devId); + PRINT("Dev:%d ,freqnum:%d , prfnum:%d ,Rref: %e ,Rnear : %e ,Rfar: %e , StartFreq: %e ,DeletFreq: %e \n", + devId,task.freqNum,task.prfNum,task.Rref,task.Rnear,task.Rfar,task.startFreq,task.stepFreq); + // 天线位置 { std::shared_ptr antplise = this->EchoSimulationData->getAntPosVelc(); From d047a9442c704f5ca826d03ba12430d55f626d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 25 Mar 2025 10:15:52 +0800 Subject: [PATCH 33/94] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/BaseToolbox/BaseToolbox/DEMLLA2XYZTool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Toolbox/BaseToolbox/BaseToolbox/DEMLLA2XYZTool.cpp b/Toolbox/BaseToolbox/BaseToolbox/DEMLLA2XYZTool.cpp index b5fd618..d50853b 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/DEMLLA2XYZTool.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/DEMLLA2XYZTool.cpp @@ -127,7 +127,7 @@ void DEMLLA2XYZTool::onaccept() Zaxis.x = pp.lon; Zaxis.y = pp.lat; Zaxis.z = pp.ati; - sloperAngle = getCosAngle(slopeVector, Zaxis)*r2d; // + sloperAngle = getCosAngle(slopeVector, Zaxis); // demsloper_x(i, j) = slopeVector.x; demsloper_y(i, j) = slopeVector.y; From 74296aa8bef36726cdfc52c0804a3e0edcc97fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 25 Mar 2025 11:23:14 +0800 Subject: [PATCH 34/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/ImageOperatorBase.cpp | 7 +++-- .../LookTableSimulationComputer.cu | 2 +- .../SimulationSAR/GPURFPC.cu | 1 + .../SimulationSAR/RFPCProcessCls.cpp | 26 ++++++++----------- .../SARSatelliteSimulationAbstractCls.cpp | 19 +++++++------- .../SARSatelliteSimulationAbstractCls.h | 1 + .../SARSimulationTaskSetting.cpp | 18 ++++++------- .../SimulationSAR/SARSimulationTaskSetting.h | 7 ++--- 8 files changed, 42 insertions(+), 39 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp index 377cf48..ad2efb6 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp @@ -455,8 +455,11 @@ gdalImage::gdalImage(const QString& raster_path) CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7 CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 锟斤拷DEM影锟斤拷 - GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( - raster_path.toUtf8().constData(), GA_ReadOnly)); // 锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 + GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen(raster_path.toUtf8().constData(), GA_ReadOnly)); + if (nullptr == rasterDataset || NULL == rasterDataset) { + QMessageBox::warning(nullptr, u8"警告", QString(u8"文件无法打开:")+QString(raster_path)); + exit(1); + } this->width = rasterDataset->GetRasterXSize(); this->height = rasterDataset->GetRasterYSize(); this->band_num = rasterDataset->GetRasterCount(); diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cu b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cu index 8f0550b..6d6e7ef 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cu +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cu @@ -131,7 +131,7 @@ __global__ void Kernel_RDProcess_doppler( Rd_r = (ti - starttime) * PRF; Rd_c = Fs/LIGHTSPEED * (R - nearRange)*2; - //printf("ti: %10.6f,starttime:%10.6f,PRF:%10.6f,Rd_r:%10.6f,Rd_c:%10.6f,R:%10.6f\n", ti, starttime, PRF, Rd_r, Rd_c, R); + //printf("ti: %10.6f,starttime:%10.6f,PRF:%10.6f,Rd_r:%10.6f,Rd_c:%10.6f,R:%10.6f,nearRange:%e Fs: %e\n", ti, starttime, PRF, Rd_r, Rd_c, R, nearRange,Fs); outRidx[idx] = Rd_r; outCidx[idx] = Rd_c;//Rd_c; return; diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index ddde40b..420dcd5 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -585,6 +585,7 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( cuComplex echo = make_cuComplex(0, 0); float temp_phi = 0; float temp_amp = 0; + for (long dataid = 0; dataid < SHAREMEMORY_FLOAT_HALF; dataid++) { temp_phi = s_R[dataid] * factorjTemp; diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index ff8b3be..a0563a6 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -30,10 +30,6 @@ //#include - - - - CUDA_AntSate_PtrList* malloc_AntSate_PtrList(long PRFCount) { CUDA_AntSate_PtrList* antlist = (CUDA_AntSate_PtrList*)malloc(sizeof(CUDA_AntSate_PtrList)); @@ -359,7 +355,7 @@ ErrorCode RFPCProcessCls::InitParams() this->EchoSimulationData->setLookSide(this->TaskSetting->getIsRightLook() ? "R" : "L"); this->EchoSimulationData->OpenOrNew(OutEchoPath, TaskFileName, PluseCount, PlusePoint); this->EchoSimulationData->setRefPhaseRange(this->TaskSetting->getRefphaseRange()); - + this->EchoSimulationData->saveToXml(); QString tmpfolderPath = QDir(OutEchoPath).filePath("tmp"); if (QDir(tmpfolderPath).exists() == false) { QDir(OutEchoPath).mkpath(tmpfolderPath); @@ -933,8 +929,8 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { ErrorCode RFPCProcessCls::RFPCMainProcess_MultiGPU_NoAntPattern() { - int num_devices; - cudaGetDeviceCount(&num_devices); + int num_devices=1; + //cudaGetDeviceCount(&num_devices); PRINT("GPU Count : %d \n", num_devices); long prfcount = this->EchoSimulationData->getPluseCount(); @@ -967,10 +963,6 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si { PRINT("dev ID:%d,start PRF ID: %d , PRF COUNT: %d \n", devId,startprfid,prfcount); - - - - /// 显存不限制 cudaSetDevice(devId); // 确保当前线程操作指定的GPU设备 POLARTYPEENUM polartype = this->TaskSetting->getPolarType(); @@ -1144,22 +1136,26 @@ ErrorCode RFPCProcessCls::SaveBlockSimulationEchoArr(cuComplex* d_echoData,size_ for (size_t i = 0; i < prfcount; i++) { for (size_t j = 0; j < freqNum; j++) { + //fileEchoArr.get()[i * freqNum + j] = std::complex(1, 1); + std::complex temp = fileEchoArr.get()[i * freqNum + j]; fileEchoArr.get()[i * freqNum + j] = std::complex( - temp.real() + h_echoData[i * freqNum + j].x, - temp.imag() + h_echoData[i * freqNum + j].y - ); + temp.real() + h_echoData[i * freqNum + j].x, + temp.imag() + h_echoData[i * freqNum + j].y + ); } } + qDebug() << "write echo :\t " << "prfcount:\t" << prfcount << " freqnum:\t" << freqNum; + testOutComplexDoubleArr(QString("testoutEcho.dat"),fileEchoArr.get(), prfcount_read, freqNum); this->EchoSimulationData->saveEchoArr(fileEchoArr, startprfid, prfcount_read); omp_unset_lock(&lock); // 锟酵放伙拷斤拷 omp_destroy_lock(&lock); // 劫伙拷斤拷 - + FreeCUDAHost(h_echoData); return ErrorCode::SUCCESS; } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SARSatelliteSimulationAbstractCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/SARSatelliteSimulationAbstractCls.cpp index b56f7c2..ed8e4a6 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SARSatelliteSimulationAbstractCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/SARSatelliteSimulationAbstractCls.cpp @@ -227,11 +227,12 @@ QVector AbstractSARSatelliteModel::getFreqList() void AbstractSARSatelliteModel::setRefphaseRange(double refRange) { + this->refRangePhase = refRange; } double AbstractSARSatelliteModel::getRefphaseRange() { - return 0.0; + return this->refRangePhase; } POLARTYPEENUM AbstractSARSatelliteModel::getPolarType() @@ -254,17 +255,17 @@ double AbstractSARSatelliteModel::getPRF() double AbstractSARSatelliteModel::getFs() { - //double NearRange = this->getNearRange(); - //double FarRange = this->getFarRange(); + double NearRange = this->getNearRange(); + double FarRange = this->getFarRange(); - //QVector freqpoints = this->getFreqList(); - //long freqNum = freqpoints.size(); + QVector freqpoints = this->getFreqList(); + long freqNum = freqpoints.size(); - //double timeRange = 2 * (FarRange - NearRange) / LIGHTSPEED; - //double fs = freqNum / timeRange; + double timeRange = 2 * (FarRange - NearRange) / LIGHTSPEED; + double fs = (freqNum-1) / timeRange; - //return fs; - return 0.0; + return fs; + //return 0.0; } void AbstractSARSatelliteModel::setFs(double fs) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SARSatelliteSimulationAbstractCls.h b/Toolbox/SimulationSARTool/SimulationSAR/SARSatelliteSimulationAbstractCls.h index 817befa..d404189 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SARSatelliteSimulationAbstractCls.h +++ b/Toolbox/SimulationSARTool/SimulationSAR/SARSatelliteSimulationAbstractCls.h @@ -211,6 +211,7 @@ public: virtual void setGri(double gri); private: + double refRangePhase; double DopplerParametersReferenceTime; std::vector DopplerCentroidCoefficients; std::vector DopplerRateValuesCoefficients; diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SARSimulationTaskSetting.cpp b/Toolbox/SimulationSARTool/SimulationSAR/SARSimulationTaskSetting.cpp index efc3955..314ed06 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SARSimulationTaskSetting.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/SARSimulationTaskSetting.cpp @@ -143,15 +143,15 @@ double SARSimulationTaskSetting::getPRF() return this->PRF; } -void SARSimulationTaskSetting::setRefphaseRange(double refRange) -{ - this->refPhaseRange = refRange; -} - -double SARSimulationTaskSetting::getRefphaseRange() -{ - return this->refPhaseRange; -} +//void SARSimulationTaskSetting::setRefphaseRange(double refRange) +//{ +// this->refPhaseRange = refRange; +//} +// +//double SARSimulationTaskSetting::getRefphaseRange() +//{ +// return this->refPhaseRange; +//} double SARSimulationTaskSetting::getFs() { diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SARSimulationTaskSetting.h b/Toolbox/SimulationSARTool/SimulationSAR/SARSimulationTaskSetting.h index eda41eb..94ff9bf 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SARSimulationTaskSetting.h +++ b/Toolbox/SimulationSARTool/SimulationSAR/SARSimulationTaskSetting.h @@ -50,6 +50,7 @@ private: double imageEndTime; double NearRange; double FarRange; + bool isR; @@ -78,15 +79,15 @@ private: public: // PRFFS virtual void setPRF(double prf) override; // λƵ virtual double getPRF() override; - virtual void setRefphaseRange(double refRange); - virtual double getRefphaseRange(); + //virtual void setRefphaseRange(double refRange) override; + //virtual double getRefphaseRange() override; virtual double getFs() override; virtual void setFs(double fs) override; private: double PRF; double Fs; - double refPhaseRange; + //double refPhaseRange; double pt; double Gri; From 4f79dbd6a75475c7914d4557ceef16f3f8f0f3aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 25 Mar 2025 11:39:28 +0800 Subject: [PATCH 35/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu | 14 +++----------- .../SimulationSARTool/SimulationSAR/GPURFPC.cuh | 1 + .../SimulationSAR/RFPCProcessCls.cpp | 3 +-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index 420dcd5..0dcf380 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -309,8 +309,6 @@ __global__ void CUDA_Kernel_Computer_R_amp( } - - __global__ void CUDA_Kernel_Computer_echo( float* d_temp_R, float* d_temp_amps, long posNum, float f0, float dfreq, @@ -380,7 +378,6 @@ __global__ void CUDA_Kernel_Computer_echo( } - /** * ֿ */ @@ -453,9 +450,6 @@ void CUDA_RFPC_MainProcess( process = sTi * 100.0 / TargetNumber; PRINT("TargetID [%f]: %d / %d finished\n", sTi * 100.0 / TargetNumber, sTi, TargetNumber); } - - - } @@ -589,7 +583,7 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( for (long dataid = 0; dataid < SHAREMEMORY_FLOAT_HALF; dataid++) { temp_phi = s_R[dataid] * factorjTemp; - temp_amp = s_amp[dataid]; + temp_amp = 1; s_amp[dataid]; echo.x += (temp_amp * cosf(temp_phi)); echo.y += (temp_amp * sinf(temp_phi)); //if (dataid > 5000) { @@ -710,6 +704,7 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) long BLOCK_FREQNUM = NextBlockPad(task.freqNum, BLOCK_SIZE); // 256*freqBlockID long cudaBlocknum = 0; long freqpoints = BLOCK_FREQNUM; + printf("freqpoints:%d\n", freqpoints); long process = 0; for (long sTi = 0; sTi < task.targetnum; sTi = sTi + SHAREMEMORY_FLOAT_HALF) { @@ -721,7 +716,7 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) task.targetnum, sTi, task.targetnum, task.sigma0_cls, - 1, + task.pt, task.Rref, task.Rnear, task.Rfar, d_R, d_amps// @@ -729,9 +724,6 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) PrintLasterError("CUDA_Kernel_Computer_R_amp"); cudaDeviceSynchronize(); - - - cudaBlocknum = (task.prfNum * BLOCK_FREQNUM + BLOCK_SIZE - 1) / BLOCK_SIZE; CUDA_Kernel_Computer_echo_NoAntPattern << > > ( d_R, d_amps, SHAREMEMORY_FLOAT_HALF, diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh index 79b94b8..04d6de4 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh @@ -80,6 +80,7 @@ extern "C" struct RFPCTask double Rfar; double Rref; + double Pt = 1; SateState* antlist = nullptr; GoalState* goallist = nullptr; diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index a0563a6..c63353c 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1069,6 +1069,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si task.Rref = this->EchoSimulationData->getRefPhaseRange(); task.Rnear = this->EchoSimulationData->getNearRange(); task.Rfar = this->EchoSimulationData->getFarRange(); + task.Pt = this->TaskSetting->getPt(); task.startFreq = this->EchoSimulationData->getCenterFreq() - this->EchoSimulationData->getBandwidth() / 2; task.stepFreq = this->EchoSimulationData->getBandwidth() / (task.freqNum - 1); task.d_echoData = (cuComplex*)mallocCUDADevice(prfcount * task.freqNum * sizeof(cuComplex), devId); @@ -1136,8 +1137,6 @@ ErrorCode RFPCProcessCls::SaveBlockSimulationEchoArr(cuComplex* d_echoData,size_ for (size_t i = 0; i < prfcount; i++) { for (size_t j = 0; j < freqNum; j++) { - //fileEchoArr.get()[i * freqNum + j] = std::complex(1, 1); - std::complex temp = fileEchoArr.get()[i * freqNum + j]; fileEchoArr.get()[i * freqNum + j] = std::complex( temp.real() + h_echoData[i * freqNum + j].x, From 2df4b86cb10672a8af648993b497867df289d130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 25 Mar 2025 12:34:35 +0800 Subject: [PATCH 36/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index 0dcf380..66787d9 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -716,7 +716,7 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) task.targetnum, sTi, task.targetnum, task.sigma0_cls, - task.pt, + task.Pt, task.Rref, task.Rnear, task.Rfar, d_R, d_amps// From c8d3f62cd588d2dad93f99f434bdaf77b44692c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 25 Mar 2025 14:31:04 +0800 Subject: [PATCH 37/94] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=20=E5=88=86=E5=8F=B7=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/BaseConstVariable.h | 20 +++++++++---------- BaseCommonLibrary/BaseTool/BaseTool.h | 20 +++++++++---------- .../BaseTool/ImageOperatorBase.h | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/BaseConstVariable.h b/BaseCommonLibrary/BaseTool/BaseConstVariable.h index f001b98..5be8598 100644 --- a/BaseCommonLibrary/BaseTool/BaseConstVariable.h +++ b/BaseCommonLibrary/BaseTool/BaseConstVariable.h @@ -307,7 +307,7 @@ inline void delArrPtr(void* p) } delete[] p; p = nullptr; -} +}; inline void delPointer(void* p) { @@ -316,34 +316,34 @@ inline void delPointer(void* p) } delete p; p = nullptr; -} +}; inline void PrintTime() { time_t current_time; time(¤t_time); printf("Current timestamp in seconds: %ld\n", (long)current_time); -} +}; /** 计算分块 ******************************************************************/ -inline long getBlockRows(long sizeMB, long cols,long sizeMeta,long maxRows) { - long rownum= (round(Memory1MB * 1.0 / sizeMeta / cols * sizeMB) + cols - 1); +inline long getBlockRows(long sizeMB, long cols, long sizeMeta, long maxRows) { + long rownum = (round(Memory1MB * 1.0 / sizeMeta / cols * sizeMB) + cols - 1); rownum = rownum < 0 ? 1 : rownum; - rownum =rownum < maxRows ? rownum : maxRows; + rownum = rownum < maxRows ? rownum : maxRows; return rownum; -} +}; inline long nextpow2(long n) { long en = ceil(log2(n)); - return pow(2,en); -} + return pow(2, en); +}; inline void releaseVoidArray(void* a) { free(a); a = NULL; -} +}; diff --git a/BaseCommonLibrary/BaseTool/BaseTool.h b/BaseCommonLibrary/BaseTool/BaseTool.h index 3255943..9bc6296 100644 --- a/BaseCommonLibrary/BaseTool/BaseTool.h +++ b/BaseCommonLibrary/BaseTool/BaseTool.h @@ -143,28 +143,28 @@ inline double calculate_MuhlemanSigma(double eta_deg) { const double denominator = sin_eta + 0.1 * cos_eta; return (0.0133 * cos_eta) / std::pow(denominator, 3); -} +}; template -inline void memsetInitArray(std::shared_ptr ptr, long arrcount,T ti) { +inline void memsetInitArray(std::shared_ptr ptr, long arrcount, T ti) { for (long i = 0; i < arrcount; i++) { ptr.get()[i] = ti; } -} +}; template inline void memcpyArray(std::shared_ptr srct, std::shared_ptr dest, long arrcount) { for (long i = 0; i < arrcount; i++) { dest.get()[i] = srct.get()[i]; } -} +}; template -inline void minValueInArr(T* ptr, long arrcount, T& minvalue) { - +inline void minValueInArr(T* ptr, long arrcount, T& minvalue) { + if (arrcount == 0)return; minvalue = ptr[0]; @@ -173,7 +173,7 @@ inline void minValueInArr(T* ptr, long arrcount, T& minvalue) { minvalue = ptr[i]; } } -} +}; template inline void maxValueInArr(T* ptr, long arrcount, T& maxvalue) { @@ -186,7 +186,7 @@ inline void maxValueInArr(T* ptr, long arrcount, T& maxvalue) { maxvalue = ptr[i]; } } -} +}; @@ -196,7 +196,7 @@ inline void maxValueInArr(T* ptr, long arrcount, T& maxvalue) { template inline T complexAbs(std::complex ccdata) { return T(sqrt(pow(ccdata.real(), 2) + pow(ccdata.imag(), 2))); -} +}; template inline void complex2dB(std::complex* ccdata, T* outdata, long long count) { @@ -205,7 +205,7 @@ inline void complex2dB(std::complex* ccdata, T* outdata, long long count) { outdata[i] = 20 * log10(complexAbs(ccdata[i])); } -} +}; diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h index 54c488e..7a024de 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h @@ -513,7 +513,7 @@ inline std::shared_ptr readDataArr(gdalImage& imgds, long start_row, long sta omp_destroy_lock(&lock); // 劫伙拷斤拷 GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH return result; -} +}; template inline std::shared_ptr readDataArrComplex(gdalImageComplex& imgds, long start_row, long start_col, long& rows_count, long& cols_count, int band_ids, GDALREADARRCOPYMETHOD method) @@ -586,7 +586,7 @@ inline std::shared_ptr readDataArrComplex(gdalImageComplex& imgds, long start omp_destroy_lock(&lock); // 劫伙拷斤拷 GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH return result; -} +}; From 66bed7370257c97a6b2f8cd38be98a524eec76e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 25 Mar 2025 15:20:58 +0800 Subject: [PATCH 38/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=8F=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E5=88=86=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/BaseTool/BaseConstVariable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaseCommonLibrary/BaseTool/BaseConstVariable.h b/BaseCommonLibrary/BaseTool/BaseConstVariable.h index 5be8598..f16210d 100644 --- a/BaseCommonLibrary/BaseTool/BaseConstVariable.h +++ b/BaseCommonLibrary/BaseTool/BaseConstVariable.h @@ -49,7 +49,7 @@ inline char* get_cur_time() { return s; } -#define PRINT(fmt, ...) printf("%s " fmt, get_cur_time(), ##__VA_ARGS__) +#define PRINT(fmt, ...) printf("%s " fmt, get_cur_time(), ##__VA_ARGS__); From 17aca87ef0fc99f2e944093bd0a571f76450cdce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 25 Mar 2025 16:41:05 +0800 Subject: [PATCH 39/94] =?UTF-8?q?=E6=8B=86=E5=88=86ImageOperator=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/BaseCommonLibrary.vcxproj | 5 + .../BaseCommonLibrary.vcxproj.filters | 15 + .../BaseTool/ImageOperatorBase.cpp | 2453 +---------------- .../BaseTool/MergeRasterOperator.cpp | 488 ++++ .../BaseTool/ShowProessAbstract.cpp | 43 + .../BaseTool/TestImageOperator.cpp | 146 + .../BaseTool/gdalImageComplexOperator.cpp | 497 ++++ .../BaseTool/gdalImageOperator.cpp | 1477 ++++++++++ 8 files changed, 2678 insertions(+), 2446 deletions(-) create mode 100644 BaseCommonLibrary/BaseTool/MergeRasterOperator.cpp create mode 100644 BaseCommonLibrary/BaseTool/ShowProessAbstract.cpp create mode 100644 BaseCommonLibrary/BaseTool/TestImageOperator.cpp create mode 100644 BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp create mode 100644 BaseCommonLibrary/BaseTool/gdalImageOperator.cpp diff --git a/BaseCommonLibrary/BaseCommonLibrary.vcxproj b/BaseCommonLibrary/BaseCommonLibrary.vcxproj index e6163eb..e3ba449 100644 --- a/BaseCommonLibrary/BaseCommonLibrary.vcxproj +++ b/BaseCommonLibrary/BaseCommonLibrary.vcxproj @@ -287,14 +287,19 @@ + + + + + Create diff --git a/BaseCommonLibrary/BaseCommonLibrary.vcxproj.filters b/BaseCommonLibrary/BaseCommonLibrary.vcxproj.filters index 81cb853..f3a4c49 100644 --- a/BaseCommonLibrary/BaseCommonLibrary.vcxproj.filters +++ b/BaseCommonLibrary/BaseCommonLibrary.vcxproj.filters @@ -104,6 +104,21 @@ BaseTool + + BaseTool + + + BaseTool + + + BaseTool + + + 源文件 + + + BaseTool + diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp index ad2efb6..777afd5 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp @@ -431,1502 +431,6 @@ GDALDataType getGDALDataType(QString fileptah) return gdal_datatype; } -gdalImage::gdalImage() -{ - this->height = 0; - this->width = 0; - this->data_band_ids = 1; - this->start_row = 0; - this->start_col = 0; -} - -/// -/// 斤拷图饺∮帮拷锟?1锟?7 -/// -/// -gdalImage::gdalImage(const QString& raster_path) -{ - omp_lock_t lock; - omp_init_lock(&lock); // 锟斤拷始斤拷斤拷 - omp_set_lock(&lock); // 锟斤拷没斤拷锟?1锟?7 - this->img_path = raster_path; - - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7 - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - // 锟斤拷DEM影锟斤拷 - GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen(raster_path.toUtf8().constData(), GA_ReadOnly)); - if (nullptr == rasterDataset || NULL == rasterDataset) { - QMessageBox::warning(nullptr, u8"警告", QString(u8"文件无法打开:")+QString(raster_path)); - exit(1); - } - this->width = rasterDataset->GetRasterXSize(); - this->height = rasterDataset->GetRasterYSize(); - this->band_num = rasterDataset->GetRasterCount(); - - double* gt = new double[6]; - // 锟斤拷梅斤拷锟斤拷 - rasterDataset->GetGeoTransform(gt); - this->gt = Eigen::MatrixXd(2, 3); - this->gt << gt[0], gt[1], gt[2], gt[3], gt[4], gt[5]; - - this->projection = rasterDataset->GetProjectionRef(); - // 斤拷斤拷 - // double* inv_gt = new double[6];; - // GDALInvGeoTransform(gt, inv_gt); // 斤拷斤拷 - // 斤拷投影 - GDALFlushCache((GDALDatasetH)rasterDataset); - GDALClose((GDALDatasetH)rasterDataset); - rasterDataset = NULL; // 指矫匡拷 - this->InitInv_gt(); - delete[] gt; - GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH - omp_unset_lock(&lock); // 锟酵放伙拷斤拷 - omp_destroy_lock(&lock); // 劫伙拷斤拷 -} - -gdalImage::~gdalImage() {} - -void gdalImage::setHeight(int height) -{ - this->height = height; -} - -void gdalImage::setWidth(int width) -{ - this->width = width; -} - -void gdalImage::setTranslationMatrix(Eigen::MatrixXd gt) -{ - this->gt = gt; -} - -void gdalImage::setData(Eigen::MatrixXd, int data_band_ids) -{ - this->data = data; - this->data_band_ids = data_band_ids; -} - -Eigen::MatrixXd gdalImage::getData(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::MatrixXd 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) = long(temp[i * cols_count + j])*1.0; - } - } - 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) = long(temp[i * cols_count + j]) * 1.0; - } - } - 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) = long(temp[i * cols_count + j]) * 1.0; - } - } - 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) = long(temp[i * cols_count + j]) * 1.0; - } - } - 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::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; - 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::MatrixXi 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; -} - -ErrorCode gdalImage::getData(double* data, int start_row, int start_col, int rows_count, int cols_count, int band_ids) -{ - ErrorCode state =ErrorCode::SUCCESS; - 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; - - - - if (gdal_datatype == GDT_Float64) { - demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, data, cols_count,rows_count, gdal_datatype, 0, 0); - } - else { - state = ErrorCode::FAIL; - } - GDALClose((GDALDatasetH)rasterDataset); - omp_unset_lock(&lock); // 锟酵放伙拷斤拷 - omp_destroy_lock(&lock); // 劫伙拷斤拷 - return state; -} - -ErrorCode gdalImage::getData(long* data, int start_row, int start_col, int rows_count, int cols_count, int band_ids) -{ - ErrorCode state = ErrorCode::SUCCESS; - 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; - - if (gdal_datatype == GDT_Int32) { - demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, data, cols_count,rows_count, gdal_datatype, 0, 0); - } - else { - state = ErrorCode::FAIL; - } - GDALClose((GDALDatasetH)rasterDataset); - omp_unset_lock(&lock); // 锟酵放伙拷斤拷 - omp_destroy_lock(&lock); // 劫伙拷斤拷 - return state; -} - -Eigen::MatrixXd gdalImage::getGeoTranslation() -{ - return this->gt; -} - -GDALDataType gdalImage::getDataType() -{ - GDALDataset* rasterDataset = - (GDALDataset*)(GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly)); - GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); - return gdal_datatype; -} - -/// -/// -/// -/// -/// -/// -/// -void gdalImage::saveImage(Eigen::MatrixXd 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::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); - 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, 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); - //delete gt_ptr; - } - - long datarows = data.rows(); - long datacols = data.cols(); - - long* databuffer = new long[datarows * datacols]; // (float*)malloc(datarows * datacols * sizeof(float)); - - for (long i = 0; i < datarows; i++) { - for (long j = 0; j < datacols; j++) { - databuffer[i * datacols + j] = data(i, 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 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_Float64, 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 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); - //delete poDstDS; - //poDstDS = nullptr; - GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH - delete[] databuffer; - omp_unset_lock(&lock); // 锟酵放伙拷斤拷 - omp_destroy_lock(&lock); // 劫伙拷斤拷 -} - - -void gdalImage::saveImage(std::shared_ptr 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); -} - -void gdalImage::setNoDataValue(double nodatavalue = -9999, int band_ids = 1) -{ - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7 - // GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); - GDALDataset* poDstDS = (GDALDataset*)(GDALOpen(img_path.toUtf8().constData(), GA_Update)); - poDstDS->GetRasterBand(band_ids)->SetNoDataValue(nodatavalue); - GDALFlushCache((GDALDatasetH)poDstDS); - GDALClose((GDALDatasetH)poDstDS); -} - -void gdalImage::setNoDataValuei(int nodatavalue, int band_ids) -{ - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7 - // GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); - GDALDataset* poDstDS = (GDALDataset*)(GDALOpen(img_path.toUtf8().constData(), GA_Update)); - poDstDS->GetRasterBand(band_ids)->SetNoDataValue(nodatavalue); - GDALFlushCache((GDALDatasetH)poDstDS); - GDALClose((GDALDatasetH)poDstDS); -} - -double gdalImage::getNoDataValue(int band_ids) -{ - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7 - // GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); - GDALDataset* poDstDS = (GDALDataset*)(GDALOpen(img_path.toUtf8().constData(), GA_Update)); - double v= poDstDS->GetRasterBand(band_ids)->GetNoDataValue( ); - GDALFlushCache((GDALDatasetH)poDstDS); - GDALClose((GDALDatasetH)poDstDS); - return v; -} - -int gdalImage::getNoDataValuei(int band_ids) -{ - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7 - // GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); - GDALDataset* poDstDS = (GDALDataset*)(GDALOpen(img_path.toUtf8().constData(), GA_Update)); - int v= poDstDS->GetRasterBand(band_ids)->GetNoDataValue( ); - GDALFlushCache((GDALDatasetH)poDstDS); - GDALClose((GDALDatasetH)poDstDS); - return v; -} - - -int gdalImage::InitInv_gt() -{ - // 1 lon lat = x - // 1 lon lat = y - Eigen::MatrixXd temp = Eigen::MatrixXd::Zero(2, 3); - this->inv_gt = temp; - double a = this->gt(0, 0); - double b = this->gt(0, 1); - double c = this->gt(0, 2); - double d = this->gt(1, 0); - double e = this->gt(1, 1); - double f = this->gt(1, 2); - double g = 1; - double det_gt = b * f - c * e; - if(det_gt == 0) { - return 0; - } - this->inv_gt(0, 0) = (c * d - a * f) / det_gt; // 2 - this->inv_gt(0, 1) = f / det_gt; // lon - this->inv_gt(0, 2) = -c / det_gt; // lat - this->inv_gt(1, 0) = (a * e - b * d) / det_gt; // 1 - this->inv_gt(1, 1) = -e / det_gt; // lon - this->inv_gt(1, 2) = b / det_gt; // lat - return 1; -} - -Landpoint gdalImage::getRow_Col(double lon, double lat) -{ - Landpoint p{ 0, 0, 0 }; - p.lon = this->inv_gt(0, 0) + lon * this->inv_gt(0, 1) + lat * this->inv_gt(0, 2); // x - p.lat = this->inv_gt(1, 0) + lon * this->inv_gt(1, 1) + lat * this->inv_gt(1, 2); // y - return p; -} - -Landpoint gdalImage::getLandPoint(double row, double col, double ati = 0) -{ - Landpoint p{ 0, 0, 0 }; - p.lon = this->gt(0, 0) + col * this->gt(0, 1) + row * this->gt(0, 2); // x - p.lat = this->gt(1, 0) + col * this->gt(1, 1) + row * this->gt(1, 2); // y - p.ati = ati; - return p; -} - -void gdalImage::getLandPoint(double row, double col, double ati, Landpoint& Lp) -{ - Lp.lon = this->gt(0, 0) + col * this->gt(0, 1) + row * this->gt(0, 2); // x - Lp.lat = this->gt(1, 0) + col * this->gt(1, 1) + row * this->gt(1, 2); // y - Lp.ati = ati; - -} - - - - - - -double gdalImage::mean(int bandids) -{ - double mean_value = 0; - double count = this->height * this->width; - int line_invert = 100; - int start_ids = 0; - do { - Eigen::MatrixXd sar_a = this->getData(start_ids, 0, line_invert, this->width, bandids); - mean_value = mean_value + sar_a.sum() / count; - start_ids = start_ids + line_invert; - } while(start_ids < this->height); - return mean_value; -} - -double gdalImage::BandmaxValue(int bandids) -{ - double max_value = 0; - bool state_max = true; - int line_invert = 100; - int start_ids = 0; - double temp_max = 0; - do { - Eigen::MatrixXd sar_a = this->getData(start_ids, 0, line_invert, this->width, bandids); - if(state_max) { - state_max = false; - max_value = sar_a.maxCoeff(); - } else { - temp_max = sar_a.maxCoeff(); - if(max_value < temp_max) { - max_value = temp_max; - } - } - start_ids = start_ids + line_invert; - } while(start_ids < this->height); - return max_value; -} - -double gdalImage::BandminValue(int bandids) -{ - double min_value = 0; - bool state_min = true; - int line_invert = 100; - int start_ids = 0; - double temp_min = 0; - do { - Eigen::MatrixXd sar_a = this->getData(start_ids, 0, line_invert, this->width, bandids); - if(state_min) { - state_min = false; - min_value = sar_a.minCoeff(); - } else { - temp_min = sar_a.minCoeff(); - if(min_value < temp_min) { - min_value = temp_min; - } - } - start_ids = start_ids + line_invert; - } while(start_ids < this->height); - return min_value; -} - -GDALRPCInfo gdalImage::getRPC() -{ - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); - CPLSetConfigOption("GDAL_DATA", "./data"); - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注斤拷锟斤拷 - // 斤拷锟斤拷 - GDALDataset* pDS = (GDALDataset*)GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly); - // 锟斤拷元斤拷锟叫伙拷取RPC锟斤拷息 - char** papszRPC = pDS->GetMetadata("RPC"); - - // 斤拷取锟斤拷RPC锟斤拷息斤拷山峁癸拷锟?1锟?7 - GDALRPCInfo oInfo; - GDALExtractRPCInfo(papszRPC, &oInfo); - - GDALClose((GDALDatasetH)pDS); - - return oInfo; -} - -Eigen::MatrixXd gdalImage::getLandPoint(Eigen::MatrixXd points) -{ - if(points.cols() != 3) { - throw new std::exception("the size of points is equit 3!!!"); - } - - Eigen::MatrixXd result(points.rows(), 3); - result.col(2) = points.col(2); // 锟竭筹拷 - points.col(2) = points.col(2).array() * 0 + 1; - points.col(0).swap(points.col(2)); // 斤拷 - Eigen::MatrixXd gts(3, 2); - gts.col(0) = this->gt.row(0); - gts.col(1) = this->gt.row(1); - - result.block(0, 0, points.rows(), 2) = points * gts; - return result; -} - -Eigen::MatrixXd gdalImage::getHist(int bandids) -{ - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7 - // 锟斤拷DEM影锟斤拷 - GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( - this->img_path.toUtf8().constData(), GA_ReadOnly)); // 锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 - - GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); - GDALRasterBand* xBand = rasterDataset->GetRasterBand(bandids); - - double dfMin = this->BandminValue(bandids); - double dfMax = this->BandmaxValue(bandids); - int count = int((dfMax - dfMin) / 0.01); - count = count > 255 ? count : 255; - GUIntBig* panHistogram = new GUIntBig[count]; - xBand->GetHistogram(dfMin, dfMax, count, panHistogram, TRUE, FALSE, NULL, NULL); - Eigen::MatrixXd result(count, 2); - double delta = (dfMax - dfMin) / count; - for(int i = 0; i < count; i++) { - result(i, 0) = dfMin + i * delta; - result(i, 1) = double(panHistogram[i]); - } - delete[] panHistogram; - GDALClose((GDALDatasetH)rasterDataset); - return result; -} - -RasterExtend gdalImage::getExtend() -{ - RasterExtend extend{ 0,0,0,0 }; - double x1 = this->gt(0, 0); - double y1 = this->gt(1, 0); - - double x2 = this->gt(0, 0) + (this->width - 1) * gt(0, 1) + (0) * gt(0, 2); - double y2 = this->gt(1, 0) + (this->width - 1) * gt(1, 1) + (0) * gt(1, 2); - - double x3 = this->gt(0, 0) + (0) * gt(0, 1) + (this->height - 1) * gt(0, 2); - double y3 = this->gt(1, 0) + (0) * gt(1, 1) + (this->height - 1) * gt(1, 2); - - double x4 = this->gt(0, 0) + (this->width - 1) * gt(0, 1) + (this->height - 1) * gt(0, 2); - double y4 = this->gt(1, 0) + (this->width - 1) * gt(1, 1) + (this->height - 1) * gt(1, 2); - - - extend.min_x = x1 < x2 ? x1 : x2; - extend.max_x = x1 < x2 ? x2 : x1; - extend.min_y = y1 < y2 ? y1 : y2; - extend.max_y = y1 < y2 ? y2 : y1; - - - extend.min_x = extend.min_x < x3 ? extend.min_x : x3; - extend.max_x = extend.max_x > x3 ? extend.max_x : x3; - extend.min_y = extend.min_y < y3 ? extend.min_y : y3; - extend.max_y = extend.max_y > y3 ? extend.max_y : y3; - - - extend.min_x = extend.min_x < x4 ? extend.min_x : x4; - extend.max_x = extend.max_x > x4 ? extend.max_x : x4; - extend.min_y = extend.min_y < y4 ? extend.min_y : y4; - extend.max_y = extend.max_y > y4 ? extend.max_y : y4; - - 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 BASECONSTVARIABLEAPI CreategdalImageFloat(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_Float32, 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())) { - 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); // 锟斤拷锟斤拷锟斤拷 - if (need_gt) { - if (!projection.isEmpty()) { - poDstDS->SetProjection(projection.toUtf8().constData()); - } - double gt_ptr[6] = { 0 }; - for (int i = 0; i < gt.rows(); i++) { - for (int j = 0; j < gt.cols(); j++) { - gt_ptr[i * 3 + j] = gt(i, j); - } - } - poDstDS->SetGeoTransform(gt_ptr); - } - for (int i = 1; i <= band_num; i++) { - poDstDS->GetRasterBand(i)->SetNoDataValue(-9999); - } - GDALFlushCache((GDALDatasetH)poDstDS); - GDALClose((GDALDatasetH)poDstDS); - GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH - gdalImage result_img(img_path); - return result_img; -} - -gdalImage CreategdalImage(const QString& img_path, int height, int width, int band_num, - Eigen::MatrixXd gt, QString projection,bool need_gt, bool overwrite, bool isEnvi, GDALDataType datetype) -{ - 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, - datetype, NULL); // 锟斤拷锟斤拷锟斤拷 - if(need_gt) { - if (!projection.isEmpty()) { - poDstDS->SetProjection(projection.toUtf8().constData()); - } - double gt_ptr[6] = { 0 }; - for(int i = 0; i < gt.rows(); i++) { - for(int j = 0; j < gt.cols(); j++) { - gt_ptr[i * 3 + j] = gt(i, j); - } - } - poDstDS->SetGeoTransform(gt_ptr); - } - for(int i = 1; i <= band_num; i++) { - poDstDS->GetRasterBand(i)->SetNoDataValue(-9999); - } - GDALFlushCache((GDALDatasetH)poDstDS); - GDALClose((GDALDatasetH)poDstDS); - GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH - gdalImage result_img(img_path); - return result_img; -} - -gdalImage CreategdalImage(const QString& img_path, int height, int width, int band_num, Eigen::MatrixXd gt, long epsgCode, GDALDataType eType, bool need_gt, 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 = isENVI? GetGDALDriverManager()->GetDriverByName("ENVI"): GetGDALDriverManager()->GetDriverByName("GTiff"); - GDALDataset* poDstDS = poDriver->Create(img_path.toUtf8().constData(), width, height, band_num, eType, NULL); // 锟斤拷锟斤拷锟斤拷 - if (need_gt) { - OGRSpatialReference oSRS; - - if (oSRS.importFromEPSG(epsgCode) != OGRERR_NONE) { - qDebug() << "Failed to import EPSG code " << epsgCode ; - throw "Failed to import EPSG code "; - exit(1); - } - char* pszWKT = NULL; - oSRS.exportToWkt(&pszWKT); - qDebug() << "WKT of EPSG:"<< epsgCode <<" :\n" << pszWKT ; - poDstDS->SetProjection(pszWKT); - double gt_ptr[6] = { 0 }; - for (int i = 0; i < gt.rows(); i++) { - for (int j = 0; j < gt.cols(); j++) { - gt_ptr[i * 3 + j] = gt(i, j); - } - } - poDstDS->SetGeoTransform(gt_ptr); - } - for (int i = 1; i <= band_num; i++) { - poDstDS->GetRasterBand(i)->SetNoDataValue(-9999); - } - GDALFlushCache((GDALDatasetH)poDstDS); - GDALClose((GDALDatasetH)poDstDS); - GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH - gdalImage result_img(img_path); - return result_img; -} - -gdalImageComplex CreategdalImageComplex(const QString& img_path, int height, int width, - int band_num, Eigen::MatrixXd gt, QString projection, - bool need_gt, bool overwrite) -{ - if(exists_test(img_path.toUtf8().constData())) { - if(overwrite) { - gdalImageComplex result_img(img_path); - return result_img; - } else { - throw "file has exist!!!"; - exit(1); - } - } - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); - GDALDataset* poDstDS = poDriver->Create(img_path.toUtf8().constData(), width, height, band_num, - GDT_CFloat64, NULL); - if(need_gt) { - poDstDS->SetProjection(projection.toUtf8().constData()); - - // 锟斤拷锟斤拷转锟斤拷锟斤拷锟斤拷 - double gt_ptr[6] = { 0 }; - for(int i = 0; i < gt.rows(); i++) { - for(int j = 0; j < gt.cols(); j++) { - gt_ptr[i * 3 + j] = gt(i, j); - } - } - poDstDS->SetGeoTransform(gt_ptr); - } - //for(int i = 1; i <= band_num; i++) { - // poDstDS->GetRasterBand(i)->SetNoDataValue(0); // 回波部分 - //} - GDALFlushCache((GDALDatasetH)poDstDS); - GDALClose((GDALDatasetH)poDstDS); - GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH - gdalImageComplex result_img(img_path); - return result_img; -} - -gdalImageComplex BASECONSTVARIABLEAPI CreategdalImageComplexNoProj(const QString& img_path, int height, int width, int band_num, bool overwrite) -{ - - // 创建新文件 - omp_lock_t lock; - omp_init_lock(&lock); - omp_set_lock(&lock); - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - - GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); - GDALDataset* poDstDS = (poDriver->Create(img_path.toUtf8().constData(), width, height, band_num, GDT_CFloat64, NULL)); - GDALFlushCache((GDALDatasetH)poDstDS); - GDALClose((GDALDatasetH)poDstDS); - //poDstDS.reset(); - omp_unset_lock(&lock); // - omp_destroy_lock(&lock); // - - gdalImageComplex result_img(img_path); - return result_img; -} - -gdalImageComplex CreateEchoComplex(const QString& img_path, int height, int width, int band_num) -{ - // 创建图像 - Eigen::MatrixXd gt = Eigen::MatrixXd::Zero(2, 3); - //Xgeo = GeoTransform[0] + Xpixel * GeoTransform[1] + Ypixel * GeoTransform[2] - //Ygeo = GeoTransform[3] + Xpixel * GeoTransform[4] + Ypixel * GeoTransform[5] - // X - gt(0, 0) = 0; gt(0, 2) = 1; gt(0, 2) = 0; - gt(1, 0) = 0; gt(1, 1) = 0; gt(1, 2) = 1; - // Y - QString projection = ""; - gdalImageComplex echodata = CreategdalImageComplex(img_path, height, width, 1, gt, projection, false, true); - return echodata; - -} int ResampleGDAL(const char* pszSrcFile, const char* pszOutFile, double* gt, int new_width, int new_height, GDALResampleAlg eResample) @@ -2198,8 +702,6 @@ int alignRaster(QString inputPath, QString referencePath, QString outputPath, GD } - - int saveMatrixXcd2TiFF(Eigen::MatrixXcd data, QString out_tiff_path) { @@ -2243,334 +745,6 @@ void clipRaster(QString inRasterPath, QString outRasterPath, long minRow, long m } -ErrorCode MergeRasterProcess(QVector filepaths, QString outfileptah, QString mainString, MERGEMODE mergecode, bool isENVI, ShowProessAbstract* dia ) -{ - // 参数检查 - if (!isExists(mainString)) { - qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::FILENOFOUND) )<< "\t" << mainString; - return ErrorCode::FILENOFOUND; - } - else {} - gdalImage mainimg(mainString); - QVector imgdslist(filepaths.count()); - for (long i = 0; i < filepaths.count(); i++) { - if (!isExists(filepaths[i])) { - qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::FILENOFOUND)) << "\t" << filepaths[i]; - return ErrorCode::FILENOFOUND; - } - else { - imgdslist[i] = gdalImage(filepaths[i]); - if (imgdslist[i].band_num != mainimg.band_num) { - qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::RASTERBAND_NOTEQUAL)) << "\t" << imgdslist[i].band_num <<" != "<< mainimg.band_num; - return ErrorCode::RASTERBAND_NOTEQUAL; - } - } - } - - // 检查坐标系是否统一 - long EPSGCode = GetEPSGFromRasterFile(mainString); - long tempCode = 0; - for (long i = 0; i < filepaths.count(); i++) { - tempCode = GetEPSGFromRasterFile(filepaths[i]); - if (EPSGCode != tempCode) { - qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::EPSGCODE_NOTSAME)) << "\t" << EPSGCode <<"!="<< tempCode; - return ErrorCode::EPSGCODE_NOTSAME; - } - } - - // 检查影像类型是否统一 - GDALDataType mainType = mainimg.getDataType(); - for (long i = 0; i < imgdslist.count(); i++) { - if (mainType != imgdslist[i].getDataType()) { - qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::RASTER_DATETYPE_NOTSAME)) << "\t" << mainType << "!=" << imgdslist[i].getDataType(); - return ErrorCode::RASTER_DATETYPE_NOTSAME; - } - } - - Eigen::MatrixXd maingt = mainimg.getGeoTranslation(); - Eigen::MatrixXd rgt = Eigen::MatrixXd::Zero(2,3); - RasterExtend mainExtend = mainimg.getExtend(); - rgt(0, 1) = (mainExtend.max_x - mainExtend.min_x) / (mainimg.width - 1); //dx - rgt(1, 2) = -1*std::abs(( (mainExtend.max_y - mainExtend.min_y) / (mainimg.height - 1)));//dy - QVector extendlist(imgdslist.count()); - for (long i = 0; i < imgdslist.count(); i++) { - extendlist[i] = imgdslist[i].getExtend(); - mainExtend.min_x = mainExtend.min_x < extendlist[i].min_x ? mainExtend.min_x : extendlist[i].min_x; - mainExtend.max_x = mainExtend.max_x > extendlist[i].max_x ? mainExtend.max_x : extendlist[i].max_x; - mainExtend.min_y = mainExtend.min_y < extendlist[i].min_y ? mainExtend.min_y : extendlist[i].min_y; - mainExtend.max_y = mainExtend.max_y > extendlist[i].max_y ? mainExtend.max_y : extendlist[i].max_y; - } - - rgt(0, 0) = mainExtend.min_x; - rgt(1, 0) = mainExtend.max_y; - - // 计算数量 - - long width = std::ceil((mainExtend.max_x - mainExtend.min_x) / rgt(0, 1) + 1); - long height = std::ceil(std::abs((mainExtend.min_y - mainExtend.max_y) / rgt(1, 2)) + 1); - OGRSpatialReference oSRS; - if (oSRS.importFromEPSG(EPSGCode) != OGRERR_NONE) { - qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::EPSGCODE_NOTSUPPORT)) << "\t" << EPSGCode; - return ErrorCode::EPSGCODE_NOTSUPPORT; - } - - gdalImage resultImage = CreategdalImage(outfileptah, height, width, mainimg.band_num, rgt, EPSGCode, mainType, true, true, isENVI); - - QString resultMaskString = addMaskToFileName(outfileptah, QString("_MASK")); - gdalImage maskImage = CreategdalImage(resultMaskString, height, width,1 , rgt, EPSGCode, GDT_Int32, true, true, isENVI); - - // 初始化 - long resultline = Memory1MB * 500 / 8 / resultImage.width; - resultline = resultline < 10000 ? resultline : 10000; // 最多100行 - resultline = resultline > 0 ? resultline : 2; - long bandnum = resultImage.band_num + 1; - long starti = 0; - long rasterCount = imgdslist.count(); - - - - QProgressDialog progressDialog(u8"初始化影像", u8"终止", 0, resultImage.height); - progressDialog.setWindowTitle(u8"初始化影像"); - progressDialog.setWindowModality(Qt::WindowModal); - progressDialog.setAutoClose(true); - progressDialog.setValue(0); - progressDialog.setMaximum(resultImage.height); - progressDialog.setMinimum(0); - progressDialog.show(); - - - for (starti = 0; starti < resultImage.height; starti = starti + resultline) { - long blocklines = resultline; - blocklines = starti + blocklines < resultImage.height ? blocklines : resultImage.height - starti; - for (long b = 1; b < bandnum; b++) { - Eigen::MatrixXd data = resultImage.getData(starti, 0, blocklines, resultImage.width, b); - Eigen::MatrixXi maskdata = maskImage.getDatai(starti, 0, blocklines, resultImage.width, b); - data = data.array() * 0; - maskdata = maskdata.array() * 0; - resultImage.saveImage(data, starti, 0, b); - maskImage.saveImage(maskdata, starti, 0, b); - } - if (nullptr != dia) { - dia->showProcess(starti * 1.0 / resultImage.height, u8"初始化影像数据"); - } - progressDialog.setValue(starti+ blocklines); - } - progressDialog.close(); - - - - switch (mergecode) - { - case MERGE_GEOCODING: - return MergeRasterInGeoCoding(imgdslist, resultImage, maskImage, dia); - default: - break; - } - - - return ErrorCode::SUCCESS; -} - -ErrorCode MergeRasterInGeoCoding(QVector imgdslist, gdalImage resultimg, gdalImage maskimg, ShowProessAbstract* dia) -{ - omp_set_num_threads(Paral_num_thread); - // 逐点合并计算 - QVector extendlist(imgdslist.count()); - for (long i = 0; i < imgdslist.count(); i++) { - extendlist[i] = imgdslist[i].getExtend(); - imgdslist[i].InitInv_gt(); - } - - // 分块计算 - long resultline = Memory1MB * 1000 / 8 / resultimg.width; - resultline = resultline < 300 ? resultline : 300; // 最多100行 - - long bandnum = resultimg.band_num+1; - long starti = 0; - long rasterCount = imgdslist.count(); - - long processNumber = 0; - QProgressDialog progressDialog(u8"合并影像", u8"终止", 0, resultimg.height); - progressDialog.setWindowTitle(u8"合并影像"); - progressDialog.setWindowModality(Qt::WindowModal); - progressDialog.setAutoClose(true); - progressDialog.setValue(0); - progressDialog.setMaximum(resultimg.height); - progressDialog.setMinimum(0); - progressDialog.show(); - omp_lock_t lock; - omp_init_lock(&lock); - -#pragma omp parallel for - for (starti = 0; starti < resultimg.height; starti = starti + resultline) { - long blocklines = resultline; - blocklines = starti + blocklines < resultimg.height ? blocklines : resultimg.height - starti; - - long rid = starti; - long cid = 0; - - Landpoint pp = {0,0,0}; - Landpoint lp = { 0,0,0 }; - - for (long ir = 0; ir < rasterCount; ir++) {// 影像 - long minRid = imgdslist[ir].height; - long maxRid = 0; - - Eigen::MatrixXd ridlist = resultimg.getData(starti, 0, blocklines, resultimg.width, 1); - ridlist = ridlist.array() * 0; - Eigen::MatrixXd cidlist = ridlist.array() * 0; - - for (long i = 0; i < blocklines; i++) {// 行号 - rid = starti + i; - for (long j = 0; j < resultimg.width; j++) {// 列号 - cid = j; - resultimg.getLandPoint(rid, cid,0,pp); - lp = imgdslist[ir].getRow_Col(pp.lon, pp.lat); // 获取点坐标 - ridlist(i, j) = lp.lat; - cidlist(i, j) = lp.lon; - } - } - - //ImageShowDialogClass* dialog = new ImageShowDialogClass; - //dialog->show(); - //dialog->load_double_MatrixX_data(cidlist, u8""); - - //dialog->exec(); - - - if (ridlist.maxCoeff() < 0 || ridlist.minCoeff() >= imgdslist[ir].height) { - continue; - } - - if (cidlist.maxCoeff() < 0 || cidlist.minCoeff() >= imgdslist[ir].width) { - continue; - } - - minRid = std::floor(ridlist.minCoeff()); - maxRid = std::ceil(ridlist.maxCoeff()); - minRid = minRid < 0 ? 0 : minRid; - maxRid = maxRid < imgdslist[ir].height ? maxRid : imgdslist[ir].height - 1; - - long rowlen = maxRid - minRid + 1; - if(rowlen <= 0) { - continue; - } - // 获取分配代码 - Landpoint p0{ 0,0,0 }, p11{ 0,0,0 }, p21{ 0,0,0 }, p12{ 0,0,0 }, p22{ 0,0,0 }, p{ 0,0,0 }; - - - long rowcount = 0; - long colcount = 0; - double ridtemp = 0, cidtemp = 0; - - long lastr = 0, nextr = 0; - long lastc = 0, nextc = 0; - - double r0=0, c0 = 0; - - for (long b = 1; b < bandnum; b++) { - Eigen::MatrixXd resultdata = resultimg.getData(starti, 0, blocklines, resultimg.width, b); - Eigen::MatrixXi resultmask = maskimg.getDatai(starti, 0, blocklines, resultimg.width, b); - Eigen::MatrixXd data = imgdslist[ir].getData(minRid, 0, rowlen, imgdslist[ir].width, b); - - double nodata = imgdslist[ir].getNoDataValue(b); - for (long ii = 0; ii < data.rows(); ii++) { - for (long jj = 0; jj < data.cols(); jj++) { - if (std::abs(data(ii, jj) - nodata) < 1e-6) { - data(ii, jj) = 0; - } - } - } - rowcount = ridlist.rows(); - colcount = ridlist.cols(); - double Bileanervalue = 0; - for (long i = 0; i < rowcount; i++) { - for (long j = 0; j < colcount; j++) { - ridtemp = ridlist(i, j); - cidtemp = cidlist(i, j); - - lastr = std::floor(ridtemp); - nextr = std::ceil(ridtemp); - lastc = std::floor(cidtemp); - nextc = std::ceil(cidtemp); - - if (lastr < 0 || lastr >= imgdslist[ir].height - || nextr < 0 || nextr >= imgdslist[ir].height - || lastc < 0 || lastc >= imgdslist[ir].width - || nextc <0|| nextc >=imgdslist[ir].width) { - continue; - } - else {} - - r0 = ridtemp - std::floor(ridtemp); - c0 = cidtemp - std::floor(cidtemp); - - lastr = lastr - minRid; - nextr = nextr - minRid; - - p0 = Landpoint{ c0,r0,0 }; - p11 = Landpoint{ 0,0,data(lastr,lastc) }; - p21 = Landpoint{ 0,1,data(nextr,lastc) }; - p12 = Landpoint{ 1,0,data(lastr,nextc) }; - p22 = Landpoint{ 1,1,data(nextr,nextc) }; - Bileanervalue = Bilinear_interpolation(p0, p11, p21, p12, p22); - if (std::abs(Bileanervalue) < 1e-6||resultmask(i, j)>0) { - continue; - } - resultdata(i,j) = resultdata(i, j)+ Bileanervalue; - resultmask(i, j) = resultmask(i, j) + 1; - } - } - resultimg.saveImage(resultdata, starti, 0, b); - maskimg.saveImage(resultmask, starti, 0, b); - } - } - - omp_set_lock(&lock); - processNumber = processNumber + blocklines; - qDebug() << "\rprocess bar:\t" << processNumber * 100.0 / resultimg.height << " % " << "\t\t\t"; - if (nullptr != dia) { - dia->showProcess(processNumber * 1.0 / resultimg.height, u8"合并图像"); - } - if (progressDialog.maximum() <= processNumber) { - processNumber = progressDialog.maximum() - 1; - } - progressDialog.setValue(processNumber); - omp_unset_lock(&lock); - } - omp_destroy_lock(&lock); - - progressDialog.setWindowTitle(u8"影像掩膜"); - progressDialog.setLabelText(u8"影像掩膜"); - for (starti = 0; starti < resultimg.height; starti = starti + resultline) { - long blocklines = resultline; - blocklines = starti + blocklines < resultimg.height ? blocklines : resultimg.height - starti; - for (long b = 1; b < bandnum; b++) { - Eigen::MatrixXd data = resultimg.getData(starti, 0, blocklines, resultimg.width, b); - Eigen::MatrixXd maskdata = maskimg.getData(starti, 0, blocklines, maskimg.width, b); - - for (long i = 0; i < data.rows(); i++) { - for (long j = 0; j < data.cols(); j++) { - if (maskdata(i, j) == 0) { - data(i, j) = -9999; - continue; - } - data(i, j) = data(i, j) / maskdata(i, j); - } - } - - resultimg.saveImage(data, starti, 0, b); - maskimg.saveImage(maskdata, starti, 0, b); - } - if (nullptr != dia) { - dia->showProcess((starti + blocklines) * 1.0 / resultimg.height, u8"影像掩膜"); - } - progressDialog.setValue(starti + blocklines); - } - resultimg.setNoDataValue(-9999); - progressDialog.close(); - return ErrorCode::SUCCESS; -} bool saveEigenMatrixXd2Bin(Eigen::MatrixXd data, QString dataStrPath) { @@ -2584,383 +758,6 @@ bool saveEigenMatrixXd2Bin(Eigen::MatrixXd data, QString dataStrPath) return true; } -gdalImageComplex::gdalImageComplex(const QString& raster_path) -{ - omp_lock_t lock; - omp_init_lock(&lock); - omp_set_lock(&lock); - this->img_path = raster_path; - - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( - raster_path.toUtf8().constData(), GA_ReadOnly)); - this->width = rasterDataset->GetRasterXSize(); - this->height = rasterDataset->GetRasterYSize(); - this->band_num = rasterDataset->GetRasterCount(); - - double* gt = new double[6]; - rasterDataset->GetGeoTransform(gt); - this->gt = Eigen::MatrixXd(2, 3); - this->gt << gt[0], gt[1], gt[2], gt[3], gt[4], gt[5]; - - double a = this->gt(0, 0); - double b = this->gt(0, 1); - double c = this->gt(0, 2); - double d = this->gt(1, 0); - double e = this->gt(1, 1); - double f = this->gt(1, 2); - - this->projection = rasterDataset->GetProjectionRef(); - - // 释放投影 - GDALFlushCache((GDALDatasetH)rasterDataset); - GDALClose((GDALDatasetH)rasterDataset); - rasterDataset = NULL; // 指矫匡拷 - this->InitInv_gt(); - delete[] gt; - GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH - omp_unset_lock(&lock); // 锟酵放伙拷斤拷 - omp_destroy_lock(&lock); // 劫伙拷斤拷 -} - -gdalImageComplex::~gdalImageComplex() {} - -void gdalImageComplex::setData(Eigen::MatrixXcd data) -{ - this->data = data; -} - -void gdalImageComplex::saveImage(Eigen::MatrixXcd data, int start_row, int start_col, int band_ids) -{ - - - - 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; - qDebug() << tip; - throw std::exception(tip.toUtf8().constData()); - } - 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; - } - - int datarows = data.rows(); - int datacols = data.cols(); - - double* databuffer = new double[data.size() * 2]; - for(int i = 0; i < data.rows(); i++) { - for(int j = 0; j < data.cols(); j++) { - databuffer[i * data.cols() * 2 + j * 2] = data(i, j).real(); - databuffer[i * data.cols() * 2 + j * 2 + 1] = data(i, 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, datacols, datarows, - databuffer, datacols, datarows, 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); // -} - -void gdalImageComplex::saveImage(std::shared_ptr> 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.get()[i*colCount+j].real(); - databuffer[i * colCount * 2 + j * 2 + 1] = data.get()[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); // - -} - -void gdalImageComplex::saveImage(std::complex* data, long start_row, long start_col, long rowCount, long colCount, int band_ids) -{ - omp_lock_t lock; - omp_init_lock(&lock); - omp_set_lock(&lock); - if (start_row + rowCount > this->height || start_col + colCount > this->width) { - QString tip = u8"file path: " + this->img_path; - qDebug() << tip; - throw std::exception(tip.toUtf8().constData()); - return; - } - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); - GDALDataset* poDstDS = nullptr; - if (exists_test(this->img_path)) { - poDstDS = (GDALDataset*)(GDALOpen(this->img_path.toUtf8().constData(), GA_Update)); - } - else { - poDstDS = poDriver->Create(this->img_path.toUtf8().constData(), this->width, this->height, - this->band_num, GDT_CFloat64, NULL); // 斤拷锟斤拷 - poDstDS->SetProjection(this->projection.toUtf8().constData()); - - double gt_ptr[6]; - for (int i = 0; i < this->gt.rows(); i++) { - for (int j = 0; j < this->gt.cols(); j++) { - gt_ptr[i * 3 + j] = this->gt(i, j); - } - } - poDstDS->SetGeoTransform(gt_ptr); - //delete[] gt_ptr; - } - - double* databuffer = new double[rowCount * colCount * 2]; - for (long i = 0; i < rowCount; i++) { - for (long j = 0; j < colCount; j++) { - databuffer[i * colCount * 2 + j * 2] = data[i * colCount + j].real(); - databuffer[i * colCount * 2 + j * 2 + 1] = data[i * colCount + j].imag(); - } - } - - // poDstDS->RasterIO(GF_Write,start_col, start_row, datacols, datarows, databuffer, datacols, - // datarows, GDT_Float32,band_ids, num,0,0,0); - poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_col, start_row, colCount, rowCount, - databuffer, colCount, rowCount, GDT_CFloat64, 0, 0); - GDALFlushCache(poDstDS); - delete databuffer; - GDALClose((GDALDatasetH)poDstDS); - GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH - omp_unset_lock(&lock); // - omp_destroy_lock(&lock); // -} - -Eigen::MatrixXcd gdalImageComplex::getDataComplex(int start_row, int start_col, int rows_count, - int cols_count, int band_ids) -{ - GDALDataset* poDataset; - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - - // 打开TIFF文件 - poDataset = (GDALDataset*)GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly); - if(poDataset == nullptr) { - QMessageBox::warning(nullptr, u8"错误", u8"无法打开文件:" + this->img_path); - qDebug() << u8"无法打开文件:" + this->img_path; - } - - // 获取数据集的第一个波段 - GDALRasterBand* poBand; - poBand = poDataset->GetRasterBand(1); - - // 读取波段信息,假设是复数类型 - int nXSize = cols_count; poBand->GetXSize(); - int nYSize = rows_count; poBand->GetYSize(); - - double* databuffer = new double[nXSize * nYSize * 2]; - poBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, databuffer, cols_count, - rows_count, GDT_CFloat64, 0, 0); - GDALClose((GDALDatasetH)poDataset); - Eigen::MatrixXcd rasterData(nYSize, nXSize); // 使用Eigen的MatrixXcd - for(size_t i = 0; i < nYSize; i++) { - for(size_t j = 0; j < nXSize; j++) { - rasterData(i, j) = std::complex(databuffer[i * nXSize * 2 + j * 2], - databuffer[i * nXSize * 2 + j * 2 + 1]); - } - } - - delete[] databuffer; - return rasterData; -} - -std::shared_ptr> gdalImageComplex::getDataComplexSharePtr(int start_row, int start_col, int rows_count, int cols_count, int band_ids) -{ - GDALDataset* poDataset; - GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - - // 打开TIFF文件 - poDataset = (GDALDataset*)GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly); - if(poDataset == nullptr) { - QMessageBox::warning(nullptr, u8"错误", u8"无法打开文件:" + this->img_path); - qDebug() << u8"无法打开文件:" + this->img_path; - } - - // 获取数据集的第一个波段 - GDALRasterBand* poBand; - poBand = poDataset->GetRasterBand(1); - - // 读取波段信息,假设是复数类型 - - - double* databuffer = new double[rows_count * cols_count * 2]; - poBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, databuffer, cols_count, - rows_count, GDT_CFloat64, 0, 0); - GDALClose((GDALDatasetH)poDataset); - - std::shared_ptr> rasterData(new std::complex[rows_count * cols_count], delArrPtr); - - for(size_t i = 0; i < rows_count; i++) { - for(size_t j = 0; j < cols_count; j++) { - rasterData.get()[i*cols_count+ j] = std::complex(databuffer[i * cols_count * 2 + j * 2], - databuffer[i * cols_count * 2 + j * 2 + 1]); - } - } - - delete[] databuffer; - return rasterData; -} - -void gdalImageComplex::saveImage() -{ - this->saveImage(this->data, this->start_row, this->start_col, this->data_band_ids); -} -void gdalImageComplex::savePreViewImage() -{ - qDebug()<<"void gdalImageComplex::savePreViewImage()"; - Eigen::MatrixXd data_abs = Eigen::MatrixXd::Zero(this->height, this->width); - data_abs = (this->data.array().real().pow(2) + this->data.array().imag().pow(2)) - .array() - .log10()*10.0; // 计算振幅 - - double min_abs = data_abs.minCoeff(); // 最大值 - double max_abs = data_abs.maxCoeff(); // 最小值 - double delta = (max_abs - min_abs) / 1000; // 1000分位档 - Eigen::MatrixX data_idx = - ((data_abs.array() - min_abs).array() / delta).array().floor().cast(); - - // 初始化 - double hist[1001]; - for(size_t i = 0; i < 1001; i++) { - hist[i] = 0; // 初始化 - } - for(size_t i = 0; i < this->height; i++) { - for(size_t j = 0; j < this->width; j++) { - hist[data_idx(i, j)]++; - } - } - - // 统计 - size_t count = this->height * this->width; - double precent = 0; - size_t curCount = 0; - double pre2 = 0; - bool findprec_2 = true; - double pre98 = 0; - bool findprec_98 = true; - for(size_t i = 0; i < 1001; i++) { - precent = precent + hist[i]; - if(findprec_2 & precent / count > 0.02) { - pre2 = i * delta + min_abs; - findprec_2 = false; - } - if(findprec_98 & precent / count > 0.98) { - pre98 = (i-1) * delta + min_abs; - findprec_98 = false; - } - } - // 拉伸 - delta = (pre98-pre2)/200; - data_idx= - ((data_abs.array() - pre2).array() / delta).array().floor().cast(); - - for(size_t i = 0; i < this->height; i++) { - for(size_t j = 0; j < this->width; j++) { - if(data_idx(i,j)<0){ - data_idx(i,j)=0; - } - else if(data_idx(i,j)>255){ - data_idx(i,j)=255; - }else{ - - } - } - } - - // 赋值 - QString filePath = this->img_path; - QFile file(filePath); - QFileInfo fileInfo(file); - - QString directory = fileInfo.absolutePath(); - qDebug() << "文件所在目录:" << directory; - QString baseName = fileInfo.completeBaseName(); - qDebug() << "无后缀文件名:" << baseName; - - // 创建文件路径 - QString previewImagePath = JoinPath(directory, baseName+"_preview.png"); - cv::Mat img(this->height, this->width, CV_8U ,cv::Scalar(0)); - - for(size_t i = 0; i < this->height; i++) { - for(size_t j = 0; j < this->width; j++) { - img.at(i,j)= (uchar)(data_idx(i,j)); - } - } - //std::string outimgpath=previewImagePath.toUtf8().data(); - cv::imwrite(previewImagePath.toUtf8().data(), img); -} - - long getProjectEPSGCodeByLon_Lat(double long, double lat, ProjectStripDelta stripState) @@ -3063,6 +860,9 @@ QString GetProjectionNameFromEPSG(long epsgCode) // return projName; } + + + long GetEPSGFromRasterFile(QString filepath) { qDebug() << "============= GetEPSGFromRasterFile ======================"; @@ -3127,6 +927,7 @@ long GetEPSGFromRasterFile(QString filepath) } } } + std::shared_ptr GetCenterPointInRaster(QString filepath) { qDebug() << "============= GetCenterPointInRaster ======================"; @@ -3227,21 +1028,15 @@ CoordinateSystemType getCoordinateSystemTypeByEPSGCode(long epsg_code) else if (oSRS.IsProjected()) { return CoordinateSystemType::ProjectCoordinateSystem; } + else { + return CoordinateSystemType::UNKNOW; + } } else { return CoordinateSystemType::UNKNOW; } } -void ShowProessAbstract::showProcess(double precent, QString tip) -{ - -} - -void ShowProessAbstract::showToolInfo(QString tip) -{ -} - void resampleRaster(const char* inputRaster, const char* outputRaster, double targetPixelSizeX, double targetPixelSizeY) { // 初始化GDAL @@ -3592,240 +1387,6 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri return ErrorCode::SUCCESS; } -void testOutAmpArr(QString filename, float* amp, long rowcount, long colcount) -{ - - - Eigen::MatrixXd h_amp_img = Eigen::MatrixXd::Zero(rowcount, colcount); - - for (long hii = 0; hii < rowcount; hii++) { - for (long hjj = 0; hjj < colcount; hjj++) { - h_amp_img(hii, hjj) = amp[hii * colcount + hjj]; - } - } - QString ampPath = getDebugDataPath(filename); - saveEigenMatrixXd2Bin(h_amp_img, ampPath); - qDebug() << filename.toLocal8Bit().constData() ; - qDebug() << "max:\t" << h_amp_img.maxCoeff() ; - qDebug() << "min:\t" << h_amp_img.minCoeff() ; -} - -void testOutAmpArr(QString filename, double* amp, long rowcount, long colcount) -{ - - - Eigen::MatrixXd h_amp_img = Eigen::MatrixXd::Zero(rowcount, colcount); - - for (long hii = 0; hii < rowcount; hii++) { - for (long hjj = 0; hjj < colcount; hjj++) { - h_amp_img(hii, hjj) = amp[hii * colcount + hjj]; - } - } - QString ampPath = getDebugDataPath(filename); - saveEigenMatrixXd2Bin(h_amp_img, ampPath); - qDebug() << filename.toLocal8Bit().constData() ; - qDebug() << "max:\t" << h_amp_img.maxCoeff() ; - qDebug() << "min:\t" << h_amp_img.minCoeff() ; -} - - -void testOutClsArr(QString filename, long* amp, long rowcount, long colcount) { - - Eigen::MatrixXd h_amp_img = Eigen::MatrixXd::Zero(rowcount, colcount); - - for (long hii = 0; hii < rowcount; hii++) { - for (long hjj = 0; hjj < colcount; hjj++) { - h_amp_img(hii, hjj) = amp[hii * colcount + hjj]; - } - } - QString ampPath = getDebugDataPath(filename); - saveEigenMatrixXd2Bin(h_amp_img, ampPath); - qDebug() << filename.toLocal8Bit().constData() ; - qDebug() << "max:\t" << h_amp_img.maxCoeff() ; - qDebug() << "min:\t" << h_amp_img.minCoeff() ; - -} - -void BASECONSTVARIABLEAPI testOutComplexDoubleArr(QString filename, std::complex* data, long rowcount, long colcount) -{ - QString ampPath = getDebugDataPath(filename); - gdalImageComplex compleximg= CreateEchoComplex(ampPath, 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, - long thetanum, long phinum) -{ - - - Eigen::MatrixXd antPatternMatrix(thetanum, phinum); - for (long t = 0; t < thetanum; ++t) { - for (long p = 0; p < phinum; ++p) { - long index = t * phinum + p; - if (index < thetanum * phinum) { - antPatternMatrix(t, p) = static_cast(antPatternArr[index]); // Copy to Eigen matrix - } - } - } - - Eigen::MatrixXd gt(2, 3); - gt(0, 0) = startphi;//x - gt(0, 1) = deltaphi; - gt(0, 2) = 0; - - gt(1, 0) = starttheta; - gt(1, 1) = 0; - gt(1, 2) = deltetheta; - - QString antpatternfilepath = getDebugDataPath(antpatternfilename); - gdalImage ds = CreategdalImageDouble(antpatternfilepath, thetanum, phinum, 1, gt, "", true, true, true); - ds.saveImage(antPatternMatrix, 0, 0, 1); -} - - -void MergeTiffs(QList inputFiles, QString outputFile) { - GDALAllRegister(); - - if (inputFiles.isEmpty()) { - fprintf(stderr, "No input files provided.\n"); - return; - } - - // Open the first file to determine the data type and coordinate system - GDALDataset* poFirstDS = (GDALDataset*)GDALOpen(inputFiles.first().toUtf8().constData(), GA_ReadOnly); - if (poFirstDS == nullptr) { - fprintf(stderr, "Failed to open the first file %s\n", inputFiles.first().toUtf8().constData()); - return; - } - - double adfGeoTransform[6]; - CPLErr eErr = poFirstDS->GetGeoTransform(adfGeoTransform); - if (eErr != CE_None) { - fprintf(stderr, "Failed to get GeoTransform for the first file %s\n", inputFiles.first().toUtf8().constData()); - GDALClose(poFirstDS); - return; - } - - int nXSize = 0; - int nYSize = 0; - double minX = std::numeric_limits::max(); - double minY = std::numeric_limits::max(); - double maxX = std::numeric_limits::lowest(); - double maxY = std::numeric_limits::lowest(); - double pixelWidth = adfGeoTransform[1]; - double pixelHeight = adfGeoTransform[5]; - - // Determine the bounding box and size of the output raster - for (const QString& inputFile : inputFiles) { - GDALDataset* poSrcDS = (GDALDataset*)GDALOpen(inputFile.toUtf8().constData(), GA_ReadOnly); - if (poSrcDS == nullptr) { - fprintf(stderr, "Failed to open %s\n", inputFile.toUtf8().constData()); - continue; - } - - double adfThisTransform[6]; - eErr = poSrcDS->GetGeoTransform(adfThisTransform); - if (eErr != CE_None) { - fprintf(stderr, "Failed to get GeoTransform for %s\n", inputFile.toUtf8().constData()); - GDALClose(poSrcDS); - continue; - } - - minX = std::min(minX, adfThisTransform[0]); - minY = std::min(minY, adfThisTransform[3] + adfThisTransform[5] * poSrcDS->GetRasterYSize()); - maxX = std::max(maxX, adfThisTransform[0] + adfThisTransform[1] * poSrcDS->GetRasterXSize()); - maxY = std::max(maxY, adfThisTransform[3]); - - GDALClose(poSrcDS); - } - - nXSize = static_cast(std::ceil((maxX - minX) / pixelWidth)); - nYSize = static_cast(std::ceil((maxY - minY) / (-pixelHeight))); - - GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); - if (poDriver == nullptr) { - fprintf(stderr, "GTiff driver not available.\n"); - GDALClose(poFirstDS); - return; - } - - char** papszOptions = nullptr; - GDALDataset* poDstDS = poDriver->Create(outputFile.toUtf8().constData(), nXSize, nYSize, 1, poFirstDS->GetRasterBand(1)->GetRasterDataType(), papszOptions); - if (poDstDS == nullptr) { - fprintf(stderr, "Creation of output file failed.\n"); - GDALClose(poFirstDS); - return; - } - - poDstDS->SetGeoTransform(adfGeoTransform); - - const OGRSpatialReference* oSRS = poFirstDS->GetSpatialRef( ); - poDstDS->SetSpatialRef(oSRS); - - float fillValue = std::numeric_limits::quiet_NaN(); - void* pafScanline = CPLMalloc(GDALGetDataTypeSizeBytes(poFirstDS->GetRasterBand(1)->GetRasterDataType()) * nXSize); - memset(pafScanline, 0, GDALGetDataTypeSizeBytes(poFirstDS->GetRasterBand(1)->GetRasterDataType()) * nXSize); - - // Initialize all pixels to NaN - for (int iY = 0; iY < nYSize; ++iY) { - GDALRasterBand* poBand = poDstDS->GetRasterBand(1); - poBand->RasterIO(GF_Write, 0, iY, nXSize, 1, pafScanline, nXSize, 1, poFirstDS->GetRasterBand(1)->GetRasterDataType(), 0, 0); - } - - CPLFree(pafScanline); - - // Read each source image and write into the destination image - for (const QString& inputFile : inputFiles) { - GDALDataset* poSrcDS = (GDALDataset*)GDALOpen(inputFile.toUtf8().constData(), GA_ReadOnly); - if (poSrcDS == nullptr) { - fprintf(stderr, "Failed to open %s\n", inputFile.toUtf8().constData()); - continue; - } - - double adfThisTransform[6]; - poSrcDS->GetGeoTransform(adfThisTransform); - - int srcXSize = poSrcDS->GetRasterXSize(); - int srcYSize = poSrcDS->GetRasterYSize(); - - int dstXOffset = static_cast(std::round((adfThisTransform[0] - minX) / pixelWidth)); - int dstYOffset = static_cast(std::round((maxY - adfThisTransform[3]) / (-pixelHeight))); - - GDALRasterBand* poSrcBand = poSrcDS->GetRasterBand(1); - GDALRasterBand* poDstBand = poDstDS->GetRasterBand(1); - - void* pafBuffer = CPLMalloc(GDALGetDataTypeSizeBytes(poFirstDS->GetRasterBand(1)->GetRasterDataType()) * srcXSize * srcYSize); - poSrcBand->RasterIO(GF_Read, 0, 0, srcXSize, srcYSize, pafBuffer, srcXSize, srcYSize, poFirstDS->GetRasterBand(1)->GetRasterDataType(), 0, 0); - - poDstBand->RasterIO(GF_Write, dstXOffset, dstYOffset, srcXSize, srcYSize, pafBuffer, srcXSize, srcYSize, poFirstDS->GetRasterBand(1)->GetRasterDataType(), 0, 0); - - CPLFree(pafBuffer); - GDALClose(poSrcDS); - } - - GDALClose(poDstDS); - GDALClose(poFirstDS); - -} void ConvertCoordinateSystem(QString inRasterPath, QString outRasterPath, long outepsgcode) { // 注册所有GDAL驱动 diff --git a/BaseCommonLibrary/BaseTool/MergeRasterOperator.cpp b/BaseCommonLibrary/BaseTool/MergeRasterOperator.cpp new file mode 100644 index 0000000..f8144e7 --- /dev/null +++ b/BaseCommonLibrary/BaseTool/MergeRasterOperator.cpp @@ -0,0 +1,488 @@ +#include "stdafx.h" +#include "ImageOperatorBase.h" +#include "BaseTool.h" +#include "GeoOperator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FileOperator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // OGRSpatialReference ڿռοת +#include // GDALWarp + +ErrorCode MergeRasterProcess(QVector filepaths, QString outfileptah, QString mainString, MERGEMODE mergecode, bool isENVI, ShowProessAbstract* dia) +{ + // + if (!isExists(mainString)) { + qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::FILENOFOUND)) << "\t" << mainString; + return ErrorCode::FILENOFOUND; + } + else {} + gdalImage mainimg(mainString); + QVector imgdslist(filepaths.count()); + for (long i = 0; i < filepaths.count(); i++) { + if (!isExists(filepaths[i])) { + qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::FILENOFOUND)) << "\t" << filepaths[i]; + return ErrorCode::FILENOFOUND; + } + else { + imgdslist[i] = gdalImage(filepaths[i]); + if (imgdslist[i].band_num != mainimg.band_num) { + qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::RASTERBAND_NOTEQUAL)) << "\t" << imgdslist[i].band_num << " != " << mainimg.band_num; + return ErrorCode::RASTERBAND_NOTEQUAL; + } + } + } + + // ϵǷͳһ + long EPSGCode = GetEPSGFromRasterFile(mainString); + long tempCode = 0; + for (long i = 0; i < filepaths.count(); i++) { + tempCode = GetEPSGFromRasterFile(filepaths[i]); + if (EPSGCode != tempCode) { + qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::EPSGCODE_NOTSAME)) << "\t" << EPSGCode << "!=" << tempCode; + return ErrorCode::EPSGCODE_NOTSAME; + } + } + + // ӰǷͳһ + GDALDataType mainType = mainimg.getDataType(); + for (long i = 0; i < imgdslist.count(); i++) { + if (mainType != imgdslist[i].getDataType()) { + qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::RASTER_DATETYPE_NOTSAME)) << "\t" << mainType << "!=" << imgdslist[i].getDataType(); + return ErrorCode::RASTER_DATETYPE_NOTSAME; + } + } + + Eigen::MatrixXd maingt = mainimg.getGeoTranslation(); + Eigen::MatrixXd rgt = Eigen::MatrixXd::Zero(2, 3); + RasterExtend mainExtend = mainimg.getExtend(); + rgt(0, 1) = (mainExtend.max_x - mainExtend.min_x) / (mainimg.width - 1); //dx + rgt(1, 2) = -1 * std::abs(((mainExtend.max_y - mainExtend.min_y) / (mainimg.height - 1)));//dy + QVector extendlist(imgdslist.count()); + for (long i = 0; i < imgdslist.count(); i++) { + extendlist[i] = imgdslist[i].getExtend(); + mainExtend.min_x = mainExtend.min_x < extendlist[i].min_x ? mainExtend.min_x : extendlist[i].min_x; + mainExtend.max_x = mainExtend.max_x > extendlist[i].max_x ? mainExtend.max_x : extendlist[i].max_x; + mainExtend.min_y = mainExtend.min_y < extendlist[i].min_y ? mainExtend.min_y : extendlist[i].min_y; + mainExtend.max_y = mainExtend.max_y > extendlist[i].max_y ? mainExtend.max_y : extendlist[i].max_y; + } + + rgt(0, 0) = mainExtend.min_x; + rgt(1, 0) = mainExtend.max_y; + + // + + long width = std::ceil((mainExtend.max_x - mainExtend.min_x) / rgt(0, 1) + 1); + long height = std::ceil(std::abs((mainExtend.min_y - mainExtend.max_y) / rgt(1, 2)) + 1); + OGRSpatialReference oSRS; + if (oSRS.importFromEPSG(EPSGCode) != OGRERR_NONE) { + qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::EPSGCODE_NOTSUPPORT)) << "\t" << EPSGCode; + return ErrorCode::EPSGCODE_NOTSUPPORT; + } + + gdalImage resultImage = CreategdalImage(outfileptah, height, width, mainimg.band_num, rgt, EPSGCode, mainType, true, true, isENVI); + + QString resultMaskString = addMaskToFileName(outfileptah, QString("_MASK")); + gdalImage maskImage = CreategdalImage(resultMaskString, height, width, 1, rgt, EPSGCode, GDT_Int32, true, true, isENVI); + + // ʼ + long resultline = Memory1MB * 500 / 8 / resultImage.width; + resultline = resultline < 10000 ? resultline : 10000; // 100 + resultline = resultline > 0 ? resultline : 2; + long bandnum = resultImage.band_num + 1; + long starti = 0; + long rasterCount = imgdslist.count(); + + + + QProgressDialog progressDialog(u8"ʼӰ", u8"ֹ", 0, resultImage.height); + progressDialog.setWindowTitle(u8"ʼӰ"); + progressDialog.setWindowModality(Qt::WindowModal); + progressDialog.setAutoClose(true); + progressDialog.setValue(0); + progressDialog.setMaximum(resultImage.height); + progressDialog.setMinimum(0); + progressDialog.show(); + + + for (starti = 0; starti < resultImage.height; starti = starti + resultline) { + long blocklines = resultline; + blocklines = starti + blocklines < resultImage.height ? blocklines : resultImage.height - starti; + for (long b = 1; b < bandnum; b++) { + Eigen::MatrixXd data = resultImage.getData(starti, 0, blocklines, resultImage.width, b); + Eigen::MatrixXi maskdata = maskImage.getDatai(starti, 0, blocklines, resultImage.width, b); + data = data.array() * 0; + maskdata = maskdata.array() * 0; + resultImage.saveImage(data, starti, 0, b); + maskImage.saveImage(maskdata, starti, 0, b); + } + if (nullptr != dia) { + dia->showProcess(starti * 1.0 / resultImage.height, u8"ʼӰ"); + } + progressDialog.setValue(starti + blocklines); + } + progressDialog.close(); + + + + switch (mergecode) + { + case MERGE_GEOCODING: + return MergeRasterInGeoCoding(imgdslist, resultImage, maskImage, dia); + default: + break; + } + + + return ErrorCode::SUCCESS; +} + +ErrorCode MergeRasterInGeoCoding(QVector imgdslist, gdalImage resultimg, gdalImage maskimg, ShowProessAbstract* dia) +{ + omp_set_num_threads(Paral_num_thread); + // ϲ + QVector extendlist(imgdslist.count()); + for (long i = 0; i < imgdslist.count(); i++) { + extendlist[i] = imgdslist[i].getExtend(); + imgdslist[i].InitInv_gt(); + } + + // ֿ + long resultline = Memory1MB * 1000 / 8 / resultimg.width; + resultline = resultline < 300 ? resultline : 300; // 100 + + long bandnum = resultimg.band_num + 1; + long starti = 0; + long rasterCount = imgdslist.count(); + + long processNumber = 0; + QProgressDialog progressDialog(u8"ϲӰ", u8"ֹ", 0, resultimg.height); + progressDialog.setWindowTitle(u8"ϲӰ"); + progressDialog.setWindowModality(Qt::WindowModal); + progressDialog.setAutoClose(true); + progressDialog.setValue(0); + progressDialog.setMaximum(resultimg.height); + progressDialog.setMinimum(0); + progressDialog.show(); + omp_lock_t lock; + omp_init_lock(&lock); + +#pragma omp parallel for + for (starti = 0; starti < resultimg.height; starti = starti + resultline) { + long blocklines = resultline; + blocklines = starti + blocklines < resultimg.height ? blocklines : resultimg.height - starti; + + long rid = starti; + long cid = 0; + + Landpoint pp = { 0,0,0 }; + Landpoint lp = { 0,0,0 }; + + for (long ir = 0; ir < rasterCount; ir++) {// Ӱ + long minRid = imgdslist[ir].height; + long maxRid = 0; + + Eigen::MatrixXd ridlist = resultimg.getData(starti, 0, blocklines, resultimg.width, 1); + ridlist = ridlist.array() * 0; + Eigen::MatrixXd cidlist = ridlist.array() * 0; + + for (long i = 0; i < blocklines; i++) {// к + rid = starti + i; + for (long j = 0; j < resultimg.width; j++) {// к + cid = j; + resultimg.getLandPoint(rid, cid, 0, pp); + lp = imgdslist[ir].getRow_Col(pp.lon, pp.lat); // ȡ + ridlist(i, j) = lp.lat; + cidlist(i, j) = lp.lon; + } + } + + //ImageShowDialogClass* dialog = new ImageShowDialogClass; + //dialog->show(); + //dialog->load_double_MatrixX_data(cidlist, u8""); + + //dialog->exec(); + + + if (ridlist.maxCoeff() < 0 || ridlist.minCoeff() >= imgdslist[ir].height) { + continue; + } + + if (cidlist.maxCoeff() < 0 || cidlist.minCoeff() >= imgdslist[ir].width) { + continue; + } + + minRid = std::floor(ridlist.minCoeff()); + maxRid = std::ceil(ridlist.maxCoeff()); + minRid = minRid < 0 ? 0 : minRid; + maxRid = maxRid < imgdslist[ir].height ? maxRid : imgdslist[ir].height - 1; + + long rowlen = maxRid - minRid + 1; + if (rowlen <= 0) { + continue; + } + // ȡ + Landpoint p0{ 0,0,0 }, p11{ 0,0,0 }, p21{ 0,0,0 }, p12{ 0,0,0 }, p22{ 0,0,0 }, p{ 0,0,0 }; + + + long rowcount = 0; + long colcount = 0; + double ridtemp = 0, cidtemp = 0; + + long lastr = 0, nextr = 0; + long lastc = 0, nextc = 0; + + double r0 = 0, c0 = 0; + + for (long b = 1; b < bandnum; b++) { + Eigen::MatrixXd resultdata = resultimg.getData(starti, 0, blocklines, resultimg.width, b); + Eigen::MatrixXi resultmask = maskimg.getDatai(starti, 0, blocklines, resultimg.width, b); + Eigen::MatrixXd data = imgdslist[ir].getData(minRid, 0, rowlen, imgdslist[ir].width, b); + + double nodata = imgdslist[ir].getNoDataValue(b); + for (long ii = 0; ii < data.rows(); ii++) { + for (long jj = 0; jj < data.cols(); jj++) { + if (std::abs(data(ii, jj) - nodata) < 1e-6) { + data(ii, jj) = 0; + } + } + } + rowcount = ridlist.rows(); + colcount = ridlist.cols(); + double Bileanervalue = 0; + for (long i = 0; i < rowcount; i++) { + for (long j = 0; j < colcount; j++) { + ridtemp = ridlist(i, j); + cidtemp = cidlist(i, j); + + lastr = std::floor(ridtemp); + nextr = std::ceil(ridtemp); + lastc = std::floor(cidtemp); + nextc = std::ceil(cidtemp); + + if (lastr < 0 || lastr >= imgdslist[ir].height + || nextr < 0 || nextr >= imgdslist[ir].height + || lastc < 0 || lastc >= imgdslist[ir].width + || nextc < 0 || nextc >= imgdslist[ir].width) { + continue; + } + else {} + + r0 = ridtemp - std::floor(ridtemp); + c0 = cidtemp - std::floor(cidtemp); + + lastr = lastr - minRid; + nextr = nextr - minRid; + + p0 = Landpoint{ c0,r0,0 }; + p11 = Landpoint{ 0,0,data(lastr,lastc) }; + p21 = Landpoint{ 0,1,data(nextr,lastc) }; + p12 = Landpoint{ 1,0,data(lastr,nextc) }; + p22 = Landpoint{ 1,1,data(nextr,nextc) }; + Bileanervalue = Bilinear_interpolation(p0, p11, p21, p12, p22); + if (std::abs(Bileanervalue) < 1e-6 || resultmask(i, j) > 0) { + continue; + } + resultdata(i, j) = resultdata(i, j) + Bileanervalue; + resultmask(i, j) = resultmask(i, j) + 1; + } + } + resultimg.saveImage(resultdata, starti, 0, b); + maskimg.saveImage(resultmask, starti, 0, b); + } + } + + omp_set_lock(&lock); + processNumber = processNumber + blocklines; + qDebug() << "\rprocess bar:\t" << processNumber * 100.0 / resultimg.height << " % " << "\t\t\t"; + if (nullptr != dia) { + dia->showProcess(processNumber * 1.0 / resultimg.height, u8"ϲͼ"); + } + if (progressDialog.maximum() <= processNumber) { + processNumber = progressDialog.maximum() - 1; + } + progressDialog.setValue(processNumber); + omp_unset_lock(&lock); + } + omp_destroy_lock(&lock); + + progressDialog.setWindowTitle(u8"ӰĤ"); + progressDialog.setLabelText(u8"ӰĤ"); + for (starti = 0; starti < resultimg.height; starti = starti + resultline) { + long blocklines = resultline; + blocklines = starti + blocklines < resultimg.height ? blocklines : resultimg.height - starti; + for (long b = 1; b < bandnum; b++) { + Eigen::MatrixXd data = resultimg.getData(starti, 0, blocklines, resultimg.width, b); + Eigen::MatrixXd maskdata = maskimg.getData(starti, 0, blocklines, maskimg.width, b); + + for (long i = 0; i < data.rows(); i++) { + for (long j = 0; j < data.cols(); j++) { + if (maskdata(i, j) == 0) { + data(i, j) = -9999; + continue; + } + data(i, j) = data(i, j) / maskdata(i, j); + } + } + + resultimg.saveImage(data, starti, 0, b); + maskimg.saveImage(maskdata, starti, 0, b); + } + if (nullptr != dia) { + dia->showProcess((starti + blocklines) * 1.0 / resultimg.height, u8"ӰĤ"); + } + progressDialog.setValue(starti + blocklines); + } + + + progressDialog.close(); + return ErrorCode::SUCCESS; +} + + +void MergeTiffs(QList inputFiles, QString outputFile) { + GDALAllRegister(); + + if (inputFiles.isEmpty()) { + fprintf(stderr, "No input files provided.\n"); + return; + } + + // Open the first file to determine the data type and coordinate system + GDALDataset* poFirstDS = (GDALDataset*)GDALOpen(inputFiles.first().toUtf8().constData(), GA_ReadOnly); + if (poFirstDS == nullptr) { + fprintf(stderr, "Failed to open the first file %s\n", inputFiles.first().toUtf8().constData()); + return; + } + + double adfGeoTransform[6]; + CPLErr eErr = poFirstDS->GetGeoTransform(adfGeoTransform); + if (eErr != CE_None) { + fprintf(stderr, "Failed to get GeoTransform for the first file %s\n", inputFiles.first().toUtf8().constData()); + GDALClose(poFirstDS); + return; + } + + int nXSize = 0; + int nYSize = 0; + double minX = std::numeric_limits::max(); + double minY = std::numeric_limits::max(); + double maxX = std::numeric_limits::lowest(); + double maxY = std::numeric_limits::lowest(); + double pixelWidth = adfGeoTransform[1]; + double pixelHeight = adfGeoTransform[5]; + + // Determine the bounding box and size of the output raster + for (const QString& inputFile : inputFiles) { + GDALDataset* poSrcDS = (GDALDataset*)GDALOpen(inputFile.toUtf8().constData(), GA_ReadOnly); + if (poSrcDS == nullptr) { + fprintf(stderr, "Failed to open %s\n", inputFile.toUtf8().constData()); + continue; + } + + double adfThisTransform[6]; + eErr = poSrcDS->GetGeoTransform(adfThisTransform); + if (eErr != CE_None) { + fprintf(stderr, "Failed to get GeoTransform for %s\n", inputFile.toUtf8().constData()); + GDALClose(poSrcDS); + continue; + } + + minX = std::min(minX, adfThisTransform[0]); + minY = std::min(minY, adfThisTransform[3] + adfThisTransform[5] * poSrcDS->GetRasterYSize()); + maxX = std::max(maxX, adfThisTransform[0] + adfThisTransform[1] * poSrcDS->GetRasterXSize()); + maxY = std::max(maxY, adfThisTransform[3]); + + GDALClose(poSrcDS); + } + + nXSize = static_cast(std::ceil((maxX - minX) / pixelWidth)); + nYSize = static_cast(std::ceil((maxY - minY) / (-pixelHeight))); + + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + if (poDriver == nullptr) { + fprintf(stderr, "GTiff driver not available.\n"); + GDALClose(poFirstDS); + return; + } + + char** papszOptions = nullptr; + GDALDataset* poDstDS = poDriver->Create(outputFile.toUtf8().constData(), nXSize, nYSize, 1, poFirstDS->GetRasterBand(1)->GetRasterDataType(), papszOptions); + if (poDstDS == nullptr) { + fprintf(stderr, "Creation of output file failed.\n"); + GDALClose(poFirstDS); + return; + } + + poDstDS->SetGeoTransform(adfGeoTransform); + + const OGRSpatialReference* oSRS = poFirstDS->GetSpatialRef(); + poDstDS->SetSpatialRef(oSRS); + + float fillValue = std::numeric_limits::quiet_NaN(); + void* pafScanline = CPLMalloc(GDALGetDataTypeSizeBytes(poFirstDS->GetRasterBand(1)->GetRasterDataType()) * nXSize); + memset(pafScanline, 0, GDALGetDataTypeSizeBytes(poFirstDS->GetRasterBand(1)->GetRasterDataType()) * nXSize); + + // Initialize all pixels to NaN + for (int iY = 0; iY < nYSize; ++iY) { + GDALRasterBand* poBand = poDstDS->GetRasterBand(1); + poBand->RasterIO(GF_Write, 0, iY, nXSize, 1, pafScanline, nXSize, 1, poFirstDS->GetRasterBand(1)->GetRasterDataType(), 0, 0); + } + + CPLFree(pafScanline); + + // Read each source image and write into the destination image + for (const QString& inputFile : inputFiles) { + GDALDataset* poSrcDS = (GDALDataset*)GDALOpen(inputFile.toUtf8().constData(), GA_ReadOnly); + if (poSrcDS == nullptr) { + fprintf(stderr, "Failed to open %s\n", inputFile.toUtf8().constData()); + continue; + } + + double adfThisTransform[6]; + poSrcDS->GetGeoTransform(adfThisTransform); + + int srcXSize = poSrcDS->GetRasterXSize(); + int srcYSize = poSrcDS->GetRasterYSize(); + + int dstXOffset = static_cast(std::round((adfThisTransform[0] - minX) / pixelWidth)); + int dstYOffset = static_cast(std::round((maxY - adfThisTransform[3]) / (-pixelHeight))); + + GDALRasterBand* poSrcBand = poSrcDS->GetRasterBand(1); + GDALRasterBand* poDstBand = poDstDS->GetRasterBand(1); + + void* pafBuffer = CPLMalloc(GDALGetDataTypeSizeBytes(poFirstDS->GetRasterBand(1)->GetRasterDataType()) * srcXSize * srcYSize); + poSrcBand->RasterIO(GF_Read, 0, 0, srcXSize, srcYSize, pafBuffer, srcXSize, srcYSize, poFirstDS->GetRasterBand(1)->GetRasterDataType(), 0, 0); + + poDstBand->RasterIO(GF_Write, dstXOffset, dstYOffset, srcXSize, srcYSize, pafBuffer, srcXSize, srcYSize, poFirstDS->GetRasterBand(1)->GetRasterDataType(), 0, 0); + + CPLFree(pafBuffer); + GDALClose(poSrcDS); + } + + GDALClose(poDstDS); + GDALClose(poFirstDS); + +} + + + diff --git a/BaseCommonLibrary/BaseTool/ShowProessAbstract.cpp b/BaseCommonLibrary/BaseTool/ShowProessAbstract.cpp new file mode 100644 index 0000000..78c90c3 --- /dev/null +++ b/BaseCommonLibrary/BaseTool/ShowProessAbstract.cpp @@ -0,0 +1,43 @@ +#include "stdafx.h" +#include "ImageOperatorBase.h" +#include "BaseTool.h" +#include "GeoOperator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FileOperator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // OGRSpatialReference ڿռοת +#include // GDALWarp + + + + +void ShowProessAbstract::showProcess(double precent, QString tip) +{ + +} + +void ShowProessAbstract::showToolInfo(QString tip) +{ +} + + diff --git a/BaseCommonLibrary/BaseTool/TestImageOperator.cpp b/BaseCommonLibrary/BaseTool/TestImageOperator.cpp new file mode 100644 index 0000000..d2c9819 --- /dev/null +++ b/BaseCommonLibrary/BaseTool/TestImageOperator.cpp @@ -0,0 +1,146 @@ +#include "stdafx.h" +#include "ImageOperatorBase.h" +#include "BaseTool.h" +#include "GeoOperator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FileOperator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // OGRSpatialReference ڿռοת +#include // GDALWarp + + + +void testOutAmpArr(QString filename, float* amp, long rowcount, long colcount) +{ + + + Eigen::MatrixXd h_amp_img = Eigen::MatrixXd::Zero(rowcount, colcount); + + for (long hii = 0; hii < rowcount; hii++) { + for (long hjj = 0; hjj < colcount; hjj++) { + h_amp_img(hii, hjj) = amp[hii * colcount + hjj]; + } + } + QString ampPath = getDebugDataPath(filename); + saveEigenMatrixXd2Bin(h_amp_img, ampPath); + qDebug() << filename.toLocal8Bit().constData(); + qDebug() << "max:\t" << h_amp_img.maxCoeff(); + qDebug() << "min:\t" << h_amp_img.minCoeff(); +} + +void testOutAmpArr(QString filename, double* amp, long rowcount, long colcount) +{ + + + Eigen::MatrixXd h_amp_img = Eigen::MatrixXd::Zero(rowcount, colcount); + + for (long hii = 0; hii < rowcount; hii++) { + for (long hjj = 0; hjj < colcount; hjj++) { + h_amp_img(hii, hjj) = amp[hii * colcount + hjj]; + } + } + QString ampPath = getDebugDataPath(filename); + saveEigenMatrixXd2Bin(h_amp_img, ampPath); + qDebug() << filename.toLocal8Bit().constData(); + qDebug() << "max:\t" << h_amp_img.maxCoeff(); + qDebug() << "min:\t" << h_amp_img.minCoeff(); +} + + +void testOutClsArr(QString filename, long* amp, long rowcount, long colcount) { + + Eigen::MatrixXd h_amp_img = Eigen::MatrixXd::Zero(rowcount, colcount); + + for (long hii = 0; hii < rowcount; hii++) { + for (long hjj = 0; hjj < colcount; hjj++) { + h_amp_img(hii, hjj) = amp[hii * colcount + hjj]; + } + } + QString ampPath = getDebugDataPath(filename); + saveEigenMatrixXd2Bin(h_amp_img, ampPath); + qDebug() << filename.toLocal8Bit().constData(); + qDebug() << "max:\t" << h_amp_img.maxCoeff(); + qDebug() << "min:\t" << h_amp_img.minCoeff(); + +} + +void testOutComplexDoubleArr(QString filename, std::complex* data, long rowcount, long colcount) +{ + QString ampPath = getDebugDataPath(filename); + gdalImageComplex compleximg = CreateEchoComplex(ampPath, rowcount, colcount, 1); + compleximg.saveImage(data, 0, 0, rowcount, colcount, 1); + + return; +} + +void testOutDataArr(QString filename, double* data, long rowcount, long colcount) +{ + return testOutAmpArr(filename, data, rowcount, colcount); +} + +void testOutDataArr(QString filename, float* data, long rowcount, long colcount) +{ + return testOutAmpArr(filename, data, rowcount, colcount); +} + +void 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, + long thetanum, long phinum) +{ + + + Eigen::MatrixXd antPatternMatrix(thetanum, phinum); + for (long t = 0; t < thetanum; ++t) { + for (long p = 0; p < phinum; ++p) { + long index = t * phinum + p; + if (index < thetanum * phinum) { + antPatternMatrix(t, p) = static_cast(antPatternArr[index]); // Copy to Eigen matrix + } + } + } + + Eigen::MatrixXd gt(2, 3); + gt(0, 0) = startphi;//x + gt(0, 1) = deltaphi; + gt(0, 2) = 0; + + gt(1, 0) = starttheta; + gt(1, 1) = 0; + gt(1, 2) = deltetheta; + + QString antpatternfilepath = getDebugDataPath(antpatternfilename); + gdalImage ds = CreategdalImageDouble(antpatternfilepath, thetanum, phinum, 1, gt, "", true, true, true); + ds.saveImage(antPatternMatrix, 0, 0, 1); +} + + + + + + diff --git a/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp b/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp new file mode 100644 index 0000000..9e42e09 --- /dev/null +++ b/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp @@ -0,0 +1,497 @@ +#include "stdafx.h" +#include "ImageOperatorBase.h" +#include "BaseTool.h" +#include "GeoOperator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FileOperator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // OGRSpatialReference ڿռοת +#include // GDALWarp + + + + + + + + + +gdalImageComplex::gdalImageComplex(const QString& raster_path) +{ + omp_lock_t lock; + omp_init_lock(&lock); + omp_set_lock(&lock); + this->img_path = raster_path; + + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( + raster_path.toUtf8().constData(), GA_ReadOnly)); + this->width = rasterDataset->GetRasterXSize(); + this->height = rasterDataset->GetRasterYSize(); + this->band_num = rasterDataset->GetRasterCount(); + + double* gt = new double[6]; + rasterDataset->GetGeoTransform(gt); + this->gt = Eigen::MatrixXd(2, 3); + this->gt << gt[0], gt[1], gt[2], gt[3], gt[4], gt[5]; + + double a = this->gt(0, 0); + double b = this->gt(0, 1); + double c = this->gt(0, 2); + double d = this->gt(1, 0); + double e = this->gt(1, 1); + double f = this->gt(1, 2); + + this->projection = rasterDataset->GetProjectionRef(); + + // ͷͶӰ + GDALFlushCache((GDALDatasetH)rasterDataset); + GDALClose((GDALDatasetH)rasterDataset); + rasterDataset = NULL; // ָÿ� + this->InitInv_gt(); + delete[] gt; + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + omp_unset_lock(&lock); // �ͷŻ�� + omp_destroy_lock(&lock); // ٻ�� +} + +gdalImageComplex::~gdalImageComplex() {} + +void gdalImageComplex::setData(Eigen::MatrixXcd data) +{ + this->data = data; +} + +void gdalImageComplex::saveImage(Eigen::MatrixXcd data, int start_row, int start_col, int band_ids) +{ + + + + 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; + qDebug() << tip; + throw std::exception(tip.toUtf8().constData()); + } + 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; + } + + int datarows = data.rows(); + int datacols = data.cols(); + + double* databuffer = new double[data.size() * 2]; + for (int i = 0; i < data.rows(); i++) { + for (int j = 0; j < data.cols(); j++) { + databuffer[i * data.cols() * 2 + j * 2] = data(i, j).real(); + databuffer[i * data.cols() * 2 + j * 2 + 1] = data(i, 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, datacols, datarows, + databuffer, datacols, datarows, 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); // +} + +void gdalImageComplex::saveImage(std::shared_ptr> 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.get()[i * colCount + j].real(); + databuffer[i * colCount * 2 + j * 2 + 1] = data.get()[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); // + +} + +void gdalImageComplex::saveImage(std::complex* data, long start_row, long start_col, long rowCount, long colCount, int band_ids) +{ + omp_lock_t lock; + omp_init_lock(&lock); + omp_set_lock(&lock); + if (start_row + rowCount > this->height || start_col + colCount > this->width) { + QString tip = u8"file path: " + this->img_path; + qDebug() << tip; + throw std::exception(tip.toUtf8().constData()); + return; + } + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); + GDALDataset* poDstDS = nullptr; + if (exists_test(this->img_path)) { + poDstDS = (GDALDataset*)(GDALOpen(this->img_path.toUtf8().constData(), GA_Update)); + } + else { + poDstDS = poDriver->Create(this->img_path.toUtf8().constData(), this->width, this->height, + this->band_num, GDT_CFloat64, NULL); // ��� + poDstDS->SetProjection(this->projection.toUtf8().constData()); + + double gt_ptr[6]; + for (int i = 0; i < this->gt.rows(); i++) { + for (int j = 0; j < this->gt.cols(); j++) { + gt_ptr[i * 3 + j] = this->gt(i, j); + } + } + poDstDS->SetGeoTransform(gt_ptr); + //delete[] gt_ptr; + } + + double* databuffer = new double[rowCount * colCount * 2]; + for (long i = 0; i < rowCount; i++) { + for (long j = 0; j < colCount; j++) { + databuffer[i * colCount * 2 + j * 2] = data[i * colCount + j].real(); + databuffer[i * colCount * 2 + j * 2 + 1] = data[i * colCount + j].imag(); + } + } + + // poDstDS->RasterIO(GF_Write,start_col, start_row, datacols, datarows, databuffer, datacols, + // datarows, GDT_Float32,band_ids, num,0,0,0); + poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_col, start_row, colCount, rowCount, + databuffer, colCount, rowCount, GDT_CFloat64, 0, 0); + GDALFlushCache(poDstDS); + delete databuffer; + GDALClose((GDALDatasetH)poDstDS); + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + omp_unset_lock(&lock); // + omp_destroy_lock(&lock); // +} + +Eigen::MatrixXcd gdalImageComplex::getDataComplex(int start_row, int start_col, int rows_count, + int cols_count, int band_ids) +{ + GDALDataset* poDataset; + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + + // TIFFļ + poDataset = (GDALDataset*)GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly); + if (poDataset == nullptr) { + QMessageBox::warning(nullptr, u8"", u8"޷ļ" + this->img_path); + qDebug() << u8"޷ļ" + this->img_path; + } + + // ȡݼĵһ + GDALRasterBand* poBand; + poBand = poDataset->GetRasterBand(1); + + // ȡϢǸ + int nXSize = cols_count; poBand->GetXSize(); + int nYSize = rows_count; poBand->GetYSize(); + + double* databuffer = new double[nXSize * nYSize * 2]; + poBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, databuffer, cols_count, + rows_count, GDT_CFloat64, 0, 0); + GDALClose((GDALDatasetH)poDataset); + Eigen::MatrixXcd rasterData(nYSize, nXSize); // ʹEigenMatrixXcd + for (size_t i = 0; i < nYSize; i++) { + for (size_t j = 0; j < nXSize; j++) { + rasterData(i, j) = std::complex(databuffer[i * nXSize * 2 + j * 2], + databuffer[i * nXSize * 2 + j * 2 + 1]); + } + } + + delete[] databuffer; + return rasterData; +} + +std::shared_ptr> gdalImageComplex::getDataComplexSharePtr(int start_row, int start_col, int rows_count, int cols_count, int band_ids) +{ + GDALDataset* poDataset; + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + + // TIFFļ + poDataset = (GDALDataset*)GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly); + if (poDataset == nullptr) { + QMessageBox::warning(nullptr, u8"", u8"޷ļ" + this->img_path); + qDebug() << u8"޷ļ" + this->img_path; + } + + // ȡݼĵһ + GDALRasterBand* poBand; + poBand = poDataset->GetRasterBand(1); + + // ȡϢǸ + + + double* databuffer = new double[rows_count * cols_count * 2]; + poBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, databuffer, cols_count, + rows_count, GDT_CFloat64, 0, 0); + GDALClose((GDALDatasetH)poDataset); + + std::shared_ptr> rasterData(new std::complex[rows_count * cols_count], delArrPtr); + + for (size_t i = 0; i < rows_count; i++) { + for (size_t j = 0; j < cols_count; j++) { + rasterData.get()[i * cols_count + j] = std::complex(databuffer[i * cols_count * 2 + j * 2], + databuffer[i * cols_count * 2 + j * 2 + 1]); + } + } + + delete[] databuffer; + return rasterData; +} + +void gdalImageComplex::saveImage() +{ + this->saveImage(this->data, this->start_row, this->start_col, this->data_band_ids); +} +void gdalImageComplex::savePreViewImage() +{ + qDebug() << "void gdalImageComplex::savePreViewImage()"; + Eigen::MatrixXd data_abs = Eigen::MatrixXd::Zero(this->height, this->width); + data_abs = (this->data.array().real().pow(2) + this->data.array().imag().pow(2)) + .array() + .log10() * 10.0; // + + double min_abs = data_abs.minCoeff(); // ֵ + double max_abs = data_abs.maxCoeff(); // Сֵ + double delta = (max_abs - min_abs) / 1000; // 1000λ + Eigen::MatrixX data_idx = + ((data_abs.array() - min_abs).array() / delta).array().floor().cast(); + + // ʼ + double hist[1001]; + for (size_t i = 0; i < 1001; i++) { + hist[i] = 0; // ʼ + } + for (size_t i = 0; i < this->height; i++) { + for (size_t j = 0; j < this->width; j++) { + hist[data_idx(i, j)]++; + } + } + + // ͳ + size_t count = this->height * this->width; + double precent = 0; + size_t curCount = 0; + double pre2 = 0; + bool findprec_2 = true; + double pre98 = 0; + bool findprec_98 = true; + for (size_t i = 0; i < 1001; i++) { + precent = precent + hist[i]; + if (findprec_2 & precent / count > 0.02) { + pre2 = i * delta + min_abs; + findprec_2 = false; + } + if (findprec_98 & precent / count > 0.98) { + pre98 = (i - 1) * delta + min_abs; + findprec_98 = false; + } + } + // + delta = (pre98 - pre2) / 200; + data_idx = + ((data_abs.array() - pre2).array() / delta).array().floor().cast(); + + for (size_t i = 0; i < this->height; i++) { + for (size_t j = 0; j < this->width; j++) { + if (data_idx(i, j) < 0) { + data_idx(i, j) = 0; + } + else if (data_idx(i, j) > 255) { + data_idx(i, j) = 255; + } + else { + + } + } + } + + // ֵ + QString filePath = this->img_path; + QFile file(filePath); + QFileInfo fileInfo(file); + + QString directory = fileInfo.absolutePath(); + qDebug() << "ļĿ¼" << directory; + QString baseName = fileInfo.completeBaseName(); + qDebug() << "޺׺ļ" << baseName; + + // ļ· + QString previewImagePath = JoinPath(directory, baseName + "_preview.png"); + cv::Mat img(this->height, this->width, CV_8U, cv::Scalar(0)); + + for (size_t i = 0; i < this->height; i++) { + for (size_t j = 0; j < this->width; j++) { + img.at(i, j) = (uchar)(data_idx(i, j)); + } + } + //std::string outimgpath=previewImagePath.toUtf8().data(); + cv::imwrite(previewImagePath.toUtf8().data(), img); +} + + + +gdalImageComplex CreategdalImageComplex(const QString& img_path, int height, int width, + int band_num, Eigen::MatrixXd gt, QString projection, + bool need_gt, bool overwrite) +{ + if (exists_test(img_path.toUtf8().constData())) { + if (overwrite) { + gdalImageComplex result_img(img_path); + return result_img; + } + else { + throw "file has exist!!!"; + exit(1); + } + } + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); + GDALDataset* poDstDS = poDriver->Create(img_path.toUtf8().constData(), width, height, band_num, + GDT_CFloat64, NULL); + if (need_gt) { + poDstDS->SetProjection(projection.toUtf8().constData()); + + // ����ת������ + double gt_ptr[6] = { 0 }; + for (int i = 0; i < gt.rows(); i++) { + for (int j = 0; j < gt.cols(); j++) { + gt_ptr[i * 3 + j] = gt(i, j); + } + } + poDstDS->SetGeoTransform(gt_ptr); + } + //for(int i = 1; i <= band_num; i++) { + // poDstDS->GetRasterBand(i)->SetNoDataValue(0); // ز + //} + GDALFlushCache((GDALDatasetH)poDstDS); + GDALClose((GDALDatasetH)poDstDS); + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + gdalImageComplex result_img(img_path); + return result_img; +} + +gdalImageComplex CreategdalImageComplexNoProj(const QString& img_path, int height, int width, int band_num, bool overwrite) +{ + + // ļ + omp_lock_t lock; + omp_init_lock(&lock); + omp_set_lock(&lock); + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); + GDALDataset* poDstDS = (poDriver->Create(img_path.toUtf8().constData(), width, height, band_num, GDT_CFloat64, NULL)); + GDALFlushCache((GDALDatasetH)poDstDS); + GDALClose((GDALDatasetH)poDstDS); + //poDstDS.reset(); + omp_unset_lock(&lock); // + omp_destroy_lock(&lock); // + + gdalImageComplex result_img(img_path); + return result_img; +} + +gdalImageComplex CreateEchoComplex(const QString& img_path, int height, int width, int band_num) +{ + // ͼ + Eigen::MatrixXd gt = Eigen::MatrixXd::Zero(2, 3); + //Xgeo = GeoTransform[0] + Xpixel * GeoTransform[1] + Ypixel * GeoTransform[2] + //Ygeo = GeoTransform[3] + Xpixel * GeoTransform[4] + Ypixel * GeoTransform[5] + // X + gt(0, 0) = 0; gt(0, 2) = 1; gt(0, 2) = 0; + gt(1, 0) = 0; gt(1, 1) = 0; gt(1, 2) = 1; + // Y + QString projection = ""; + gdalImageComplex echodata = CreategdalImageComplex(img_path, height, width, 1, gt, projection, false, true); + return echodata; + +} + diff --git a/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp b/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp new file mode 100644 index 0000000..622ca9d --- /dev/null +++ b/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp @@ -0,0 +1,1477 @@ +#include "stdafx.h" +#include "ImageOperatorBase.h" +#include "BaseTool.h" +#include "GeoOperator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FileOperator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // OGRSpatialReference ڿռοת +#include // GDALWarp + + + + + +gdalImage::gdalImage() +{ + this->height = 0; + this->width = 0; + this->data_band_ids = 1; + this->start_row = 0; + this->start_col = 0; +} + +/// +/// �ͼȡӰ�?1?7 +/// +/// +gdalImage::gdalImage(const QString& raster_path) +{ + omp_lock_t lock; + omp_init_lock(&lock); // ��ʼ�� + omp_set_lock(&lock); // ��û�?1?7 + this->img_path = raster_path; + + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // עʽ��?1?7 + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + // ��DEMӰ�� + GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen(raster_path.toUtf8().constData(), GA_ReadOnly)); + if (nullptr == rasterDataset || NULL == rasterDataset) { + QMessageBox::warning(nullptr, u8"", QString(u8"ļ޷򿪣") + QString(raster_path)); + exit(1); + } + this->width = rasterDataset->GetRasterXSize(); + this->height = rasterDataset->GetRasterYSize(); + this->band_num = rasterDataset->GetRasterCount(); + + double* gt = new double[6]; + // ��÷��� + rasterDataset->GetGeoTransform(gt); + this->gt = Eigen::MatrixXd(2, 3); + this->gt << gt[0], gt[1], gt[2], gt[3], gt[4], gt[5]; + + this->projection = rasterDataset->GetProjectionRef(); + // �� + // double* inv_gt = new double[6];; + // GDALInvGeoTransform(gt, inv_gt); // �� + // �ͶӰ + GDALFlushCache((GDALDatasetH)rasterDataset); + GDALClose((GDALDatasetH)rasterDataset); + rasterDataset = NULL; // ָÿ� + this->InitInv_gt(); + delete[] gt; + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + omp_unset_lock(&lock); // �ͷŻ�� + omp_destroy_lock(&lock); // ٻ�� +} + +gdalImage::~gdalImage() {} + +void gdalImage::setHeight(int height) +{ + this->height = height; +} + +void gdalImage::setWidth(int width) +{ + this->width = width; +} + +void gdalImage::setTranslationMatrix(Eigen::MatrixXd gt) +{ + this->gt = gt; +} + +void gdalImage::setData(Eigen::MatrixXd, int data_band_ids) +{ + this->data = data; + this->data_band_ids = data_band_ids; +} + +Eigen::MatrixXd gdalImage::getData(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::MatrixXd 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) = long(temp[i * cols_count + j]) * 1.0; + } + } + 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) = long(temp[i * cols_count + j]) * 1.0; + } + } + 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) = long(temp[i * cols_count + j]) * 1.0; + } + } + 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) = long(temp[i * cols_count + j]) * 1.0; + } + } + 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::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; + 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::MatrixXi 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; +} + +ErrorCode gdalImage::getData(double* data, int start_row, int start_col, int rows_count, int cols_count, int band_ids) +{ + ErrorCode state = ErrorCode::SUCCESS; + 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; + + + + if (gdal_datatype == GDT_Float64) { + demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, data, cols_count, rows_count, gdal_datatype, 0, 0); + } + else { + state = ErrorCode::FAIL; + } + GDALClose((GDALDatasetH)rasterDataset); + omp_unset_lock(&lock); // �ͷŻ�� + omp_destroy_lock(&lock); // ٻ�� + return state; +} + +ErrorCode gdalImage::getData(long* data, int start_row, int start_col, int rows_count, int cols_count, int band_ids) +{ + ErrorCode state = ErrorCode::SUCCESS; + 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; + + if (gdal_datatype == GDT_Int32) { + demBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, data, cols_count, rows_count, gdal_datatype, 0, 0); + } + else { + state = ErrorCode::FAIL; + } + GDALClose((GDALDatasetH)rasterDataset); + omp_unset_lock(&lock); // �ͷŻ�� + omp_destroy_lock(&lock); // ٻ�� + return state; +} + +Eigen::MatrixXd gdalImage::getGeoTranslation() +{ + return this->gt; +} + +GDALDataType gdalImage::getDataType() +{ + GDALDataset* rasterDataset = + (GDALDataset*)(GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly)); + GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); + return gdal_datatype; +} + +/// +/// +/// +/// +/// +/// +/// +void gdalImage::saveImage(Eigen::MatrixXd 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::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); + 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, 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); + //delete gt_ptr; + } + + long datarows = data.rows(); + long datacols = data.cols(); + + long* databuffer = new long[datarows * datacols]; // (float*)malloc(datarows * datacols * sizeof(float)); + + for (long i = 0; i < datarows; i++) { + for (long j = 0; j < datacols; j++) { + databuffer[i * datacols + j] = data(i, 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 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_Float64, 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 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); + //delete poDstDS; + //poDstDS = nullptr; + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + delete[] databuffer; + omp_unset_lock(&lock); // �ͷŻ�� + omp_destroy_lock(&lock); // ٻ�� +} + + +void gdalImage::saveImage(std::shared_ptr 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); +} + +void gdalImage::setNoDataValue(double nodatavalue = -9999, int band_ids = 1) +{ + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // עʽ��?1?7 + // GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + GDALDataset* poDstDS = (GDALDataset*)(GDALOpen(img_path.toUtf8().constData(), GA_Update)); + poDstDS->GetRasterBand(band_ids)->SetNoDataValue(nodatavalue); + GDALFlushCache((GDALDatasetH)poDstDS); + GDALClose((GDALDatasetH)poDstDS); +} + +void gdalImage::setNoDataValuei(int nodatavalue, int band_ids) +{ + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // עʽ��?1?7 + // GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + GDALDataset* poDstDS = (GDALDataset*)(GDALOpen(img_path.toUtf8().constData(), GA_Update)); + poDstDS->GetRasterBand(band_ids)->SetNoDataValue(nodatavalue); + GDALFlushCache((GDALDatasetH)poDstDS); + GDALClose((GDALDatasetH)poDstDS); +} + +double gdalImage::getNoDataValue(int band_ids) +{ + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // עʽ��?1?7 + // GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + GDALDataset* poDstDS = (GDALDataset*)(GDALOpen(img_path.toUtf8().constData(), GA_Update)); + double v = poDstDS->GetRasterBand(band_ids)->GetNoDataValue(); + GDALFlushCache((GDALDatasetH)poDstDS); + GDALClose((GDALDatasetH)poDstDS); + return v; +} + +int gdalImage::getNoDataValuei(int band_ids) +{ + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // עʽ��?1?7 + // GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + GDALDataset* poDstDS = (GDALDataset*)(GDALOpen(img_path.toUtf8().constData(), GA_Update)); + int v = poDstDS->GetRasterBand(band_ids)->GetNoDataValue(); + GDALFlushCache((GDALDatasetH)poDstDS); + GDALClose((GDALDatasetH)poDstDS); + return v; +} + + +int gdalImage::InitInv_gt() +{ + // 1 lon lat = x + // 1 lon lat = y + Eigen::MatrixXd temp = Eigen::MatrixXd::Zero(2, 3); + this->inv_gt = temp; + double a = this->gt(0, 0); + double b = this->gt(0, 1); + double c = this->gt(0, 2); + double d = this->gt(1, 0); + double e = this->gt(1, 1); + double f = this->gt(1, 2); + double g = 1; + double det_gt = b * f - c * e; + if (det_gt == 0) { + return 0; + } + this->inv_gt(0, 0) = (c * d - a * f) / det_gt; // 2 + this->inv_gt(0, 1) = f / det_gt; // lon + this->inv_gt(0, 2) = -c / det_gt; // lat + this->inv_gt(1, 0) = (a * e - b * d) / det_gt; // 1 + this->inv_gt(1, 1) = -e / det_gt; // lon + this->inv_gt(1, 2) = b / det_gt; // lat + return 1; +} + +Landpoint gdalImage::getRow_Col(double lon, double lat) +{ + Landpoint p{ 0, 0, 0 }; + p.lon = this->inv_gt(0, 0) + lon * this->inv_gt(0, 1) + lat * this->inv_gt(0, 2); // x + p.lat = this->inv_gt(1, 0) + lon * this->inv_gt(1, 1) + lat * this->inv_gt(1, 2); // y + return p; +} + +Landpoint gdalImage::getLandPoint(double row, double col, double ati = 0) +{ + Landpoint p{ 0, 0, 0 }; + p.lon = this->gt(0, 0) + col * this->gt(0, 1) + row * this->gt(0, 2); // x + p.lat = this->gt(1, 0) + col * this->gt(1, 1) + row * this->gt(1, 2); // y + p.ati = ati; + return p; +} + +void gdalImage::getLandPoint(double row, double col, double ati, Landpoint& Lp) +{ + Lp.lon = this->gt(0, 0) + col * this->gt(0, 1) + row * this->gt(0, 2); // x + Lp.lat = this->gt(1, 0) + col * this->gt(1, 1) + row * this->gt(1, 2); // y + Lp.ati = ati; + +} + + + + + + +double gdalImage::mean(int bandids) +{ + double mean_value = 0; + double count = this->height * this->width; + int line_invert = 100; + int start_ids = 0; + do { + Eigen::MatrixXd sar_a = this->getData(start_ids, 0, line_invert, this->width, bandids); + mean_value = mean_value + sar_a.sum() / count; + start_ids = start_ids + line_invert; + } while (start_ids < this->height); + return mean_value; +} + +double gdalImage::BandmaxValue(int bandids) +{ + double max_value = 0; + bool state_max = true; + int line_invert = 100; + int start_ids = 0; + double temp_max = 0; + do { + Eigen::MatrixXd sar_a = this->getData(start_ids, 0, line_invert, this->width, bandids); + if (state_max) { + state_max = false; + max_value = sar_a.maxCoeff(); + } + else { + temp_max = sar_a.maxCoeff(); + if (max_value < temp_max) { + max_value = temp_max; + } + } + start_ids = start_ids + line_invert; + } while (start_ids < this->height); + return max_value; +} + +double gdalImage::BandminValue(int bandids) +{ + double min_value = 0; + bool state_min = true; + int line_invert = 100; + int start_ids = 0; + double temp_min = 0; + do { + Eigen::MatrixXd sar_a = this->getData(start_ids, 0, line_invert, this->width, bandids); + if (state_min) { + state_min = false; + min_value = sar_a.minCoeff(); + } + else { + temp_min = sar_a.minCoeff(); + if (min_value < temp_min) { + min_value = temp_min; + } + } + start_ids = start_ids + line_invert; + } while (start_ids < this->height); + return min_value; +} + +GDALRPCInfo gdalImage::getRPC() +{ + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); + CPLSetConfigOption("GDAL_DATA", "./data"); + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // ע��� + // ��� + GDALDataset* pDS = (GDALDataset*)GDALOpen(this->img_path.toUtf8().constData(), GA_ReadOnly); + // ��Ԫ��л�ȡRPC��Ϣ + char** papszRPC = pDS->GetMetadata("RPC"); + + // �ȡ��RPC��Ϣ�ɽṹ�?1?7 + GDALRPCInfo oInfo; + GDALExtractRPCInfo(papszRPC, &oInfo); + + GDALClose((GDALDatasetH)pDS); + + return oInfo; +} + +Eigen::MatrixXd gdalImage::getLandPoint(Eigen::MatrixXd points) +{ + if (points.cols() != 3) { + throw new std::exception("the size of points is equit 3!!!"); + } + + Eigen::MatrixXd result(points.rows(), 3); + result.col(2) = points.col(2); // �߳� + points.col(2) = points.col(2).array() * 0 + 1; + points.col(0).swap(points.col(2)); // � + Eigen::MatrixXd gts(3, 2); + gts.col(0) = this->gt.row(0); + gts.col(1) = this->gt.row(1); + + result.block(0, 0, points.rows(), 2) = points * gts; + return result; +} + +Eigen::MatrixXd gdalImage::getHist(int bandids) +{ + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // עʽ��?1?7 + // ��DEMӰ�� + GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( + this->img_path.toUtf8().constData(), GA_ReadOnly)); // ��ֻ�ʽ��ȡ�Ӱ�� + + GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); + GDALRasterBand* xBand = rasterDataset->GetRasterBand(bandids); + + double dfMin = this->BandminValue(bandids); + double dfMax = this->BandmaxValue(bandids); + int count = int((dfMax - dfMin) / 0.01); + count = count > 255 ? count : 255; + GUIntBig* panHistogram = new GUIntBig[count]; + xBand->GetHistogram(dfMin, dfMax, count, panHistogram, TRUE, FALSE, NULL, NULL); + Eigen::MatrixXd result(count, 2); + double delta = (dfMax - dfMin) / count; + for (int i = 0; i < count; i++) { + result(i, 0) = dfMin + i * delta; + result(i, 1) = double(panHistogram[i]); + } + delete[] panHistogram; + GDALClose((GDALDatasetH)rasterDataset); + return result; +} + +RasterExtend gdalImage::getExtend() +{ + RasterExtend extend{ 0,0,0,0 }; + double x1 = this->gt(0, 0); + double y1 = this->gt(1, 0); + + double x2 = this->gt(0, 0) + (this->width - 1) * gt(0, 1) + (0) * gt(0, 2); + double y2 = this->gt(1, 0) + (this->width - 1) * gt(1, 1) + (0) * gt(1, 2); + + double x3 = this->gt(0, 0) + (0) * gt(0, 1) + (this->height - 1) * gt(0, 2); + double y3 = this->gt(1, 0) + (0) * gt(1, 1) + (this->height - 1) * gt(1, 2); + + double x4 = this->gt(0, 0) + (this->width - 1) * gt(0, 1) + (this->height - 1) * gt(0, 2); + double y4 = this->gt(1, 0) + (this->width - 1) * gt(1, 1) + (this->height - 1) * gt(1, 2); + + + extend.min_x = x1 < x2 ? x1 : x2; + extend.max_x = x1 < x2 ? x2 : x1; + extend.min_y = y1 < y2 ? y1 : y2; + extend.max_y = y1 < y2 ? y2 : y1; + + + extend.min_x = extend.min_x < x3 ? extend.min_x : x3; + extend.max_x = extend.max_x > x3 ? extend.max_x : x3; + extend.min_y = extend.min_y < y3 ? extend.min_y : y3; + extend.max_y = extend.max_y > y3 ? extend.max_y : y3; + + + extend.min_x = extend.min_x < x4 ? extend.min_x : x4; + extend.max_x = extend.max_x > x4 ? extend.max_x : x4; + extend.min_y = extend.min_y < y4 ? extend.min_y : y4; + extend.max_y = extend.max_y > y4 ? extend.max_y : y4; + + return extend; +} + + + + + + +gdalImage 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 CreategdalImageFloat(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_Float32, 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())) { + 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); // ������ + if (need_gt) { + if (!projection.isEmpty()) { + poDstDS->SetProjection(projection.toUtf8().constData()); + } + double gt_ptr[6] = { 0 }; + for (int i = 0; i < gt.rows(); i++) { + for (int j = 0; j < gt.cols(); j++) { + gt_ptr[i * 3 + j] = gt(i, j); + } + } + poDstDS->SetGeoTransform(gt_ptr); + } + for (int i = 1; i <= band_num; i++) { + poDstDS->GetRasterBand(i)->SetNoDataValue(-9999); + } + GDALFlushCache((GDALDatasetH)poDstDS); + GDALClose((GDALDatasetH)poDstDS); + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + gdalImage result_img(img_path); + return result_img; +} + +gdalImage CreategdalImage(const QString& img_path, int height, int width, int band_num, + Eigen::MatrixXd gt, QString projection, bool need_gt, bool overwrite, bool isEnvi, GDALDataType datetype) +{ + 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, + datetype, NULL); // ������ + if (need_gt) { + if (!projection.isEmpty()) { + poDstDS->SetProjection(projection.toUtf8().constData()); + } + double gt_ptr[6] = { 0 }; + for (int i = 0; i < gt.rows(); i++) { + for (int j = 0; j < gt.cols(); j++) { + gt_ptr[i * 3 + j] = gt(i, j); + } + } + poDstDS->SetGeoTransform(gt_ptr); + } + for (int i = 1; i <= band_num; i++) { + poDstDS->GetRasterBand(i)->SetNoDataValue(-9999); + } + GDALFlushCache((GDALDatasetH)poDstDS); + GDALClose((GDALDatasetH)poDstDS); + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + gdalImage result_img(img_path); + return result_img; +} + +gdalImage CreategdalImage(const QString& img_path, int height, int width, int band_num, Eigen::MatrixXd gt, long epsgCode, GDALDataType eType, bool need_gt, 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 = isENVI ? GetGDALDriverManager()->GetDriverByName("ENVI") : GetGDALDriverManager()->GetDriverByName("GTiff"); + GDALDataset* poDstDS = poDriver->Create(img_path.toUtf8().constData(), width, height, band_num, eType, NULL); // ������ + if (need_gt) { + OGRSpatialReference oSRS; + + if (oSRS.importFromEPSG(epsgCode) != OGRERR_NONE) { + qDebug() << "Failed to import EPSG code " << epsgCode; + throw "Failed to import EPSG code "; + exit(1); + } + char* pszWKT = NULL; + oSRS.exportToWkt(&pszWKT); + qDebug() << "WKT of EPSG:" << epsgCode << " :\n" << pszWKT; + poDstDS->SetProjection(pszWKT); + double gt_ptr[6] = { 0 }; + for (int i = 0; i < gt.rows(); i++) { + for (int j = 0; j < gt.cols(); j++) { + gt_ptr[i * 3 + j] = gt(i, j); + } + } + poDstDS->SetGeoTransform(gt_ptr); + } + for (int i = 1; i <= band_num; i++) { + poDstDS->GetRasterBand(i)->SetNoDataValue(-9999); + } + GDALFlushCache((GDALDatasetH)poDstDS); + GDALClose((GDALDatasetH)poDstDS); + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + gdalImage result_img(img_path); + return result_img; +} + + + + + + + + + + From 54a4273ecd6c3f62f775eb03277421ed2508c097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 25 Mar 2025 17:30:03 +0800 Subject: [PATCH 40/94] =?UTF-8?q?=E6=8B=86=E5=88=86imageOperatorBase.cpp?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=20=E5=B9=B6=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E4=BA=86=20=E5=BC=95=E8=B5=B7=E7=BC=96=E8=AF=91=E5=99=A8?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/BaseCommonLibrary.vcxproj | 14 +- .../BaseCommonLibrary.vcxproj.filters | 47 +- .../BaseTool/BaseConstVariable.h | 20 +- .../BaseTool/ImageOperatorBase.cpp | 24 +- .../BaseTool/ImageOperatorBase.h | 15 +- BaseCommonLibrary/BaseTool/RasterToolBase.cpp | 3 + .../BaseTool/ShowProessAbstract.cpp | 29 +- .../BaseTool/gdalImageComplexOperator.cpp | 2 +- .../BaseTool/gdalImageOperator.cpp | 7 +- BaseCommonLibrary/ImageOperatorFuntion.cpp | 1849 +++++++++++++++++ BaseCommonLibrary/ShowProessAbstract.h | 15 + 11 files changed, 1923 insertions(+), 102 deletions(-) create mode 100644 BaseCommonLibrary/ImageOperatorFuntion.cpp create mode 100644 BaseCommonLibrary/ShowProessAbstract.h diff --git a/BaseCommonLibrary/BaseCommonLibrary.vcxproj b/BaseCommonLibrary/BaseCommonLibrary.vcxproj index e3ba449..cf486a6 100644 --- a/BaseCommonLibrary/BaseCommonLibrary.vcxproj +++ b/BaseCommonLibrary/BaseCommonLibrary.vcxproj @@ -220,10 +220,11 @@ pch.h true true - StreamingSIMDExtensions2 + NotSet true stdcpp14 stdc11 + true Windows @@ -269,38 +270,33 @@ - - + + - - - - - - + Create Create diff --git a/BaseCommonLibrary/BaseCommonLibrary.vcxproj.filters b/BaseCommonLibrary/BaseCommonLibrary.vcxproj.filters index f3a4c49..9b1842a 100644 --- a/BaseCommonLibrary/BaseCommonLibrary.vcxproj.filters +++ b/BaseCommonLibrary/BaseCommonLibrary.vcxproj.filters @@ -33,33 +33,30 @@ BaseTool - - BaseTool - BaseTool BaseTool - - BaseTool - BaseTool BaseTool - - BaseTool - BaseTool BaseTool + + BaseTool + + + BaseTool + @@ -71,30 +68,18 @@ BaseTool - - BaseTool - BaseTool BaseTool - - BaseTool - BaseTool - - BaseTool - BaseTool - - BaseTool - BaseTool @@ -104,31 +89,33 @@ BaseTool + + BaseTool + BaseTool BaseTool - + BaseTool - - 源文件 - - + BaseTool - - 头文件 - ToolAbstract + + BaseTool + - + + BaseTool + \ No newline at end of file diff --git a/BaseCommonLibrary/BaseTool/BaseConstVariable.h b/BaseCommonLibrary/BaseTool/BaseConstVariable.h index f16210d..ca0a981 100644 --- a/BaseCommonLibrary/BaseTool/BaseConstVariable.h +++ b/BaseCommonLibrary/BaseTool/BaseConstVariable.h @@ -39,17 +39,17 @@ #include /** 打印时间 ***************************************************************/ -inline char* get_cur_time() { - static char s[20]; - time_t t; - struct tm* ltime; - time(&t); - ltime = localtime(&t); - strftime(s, 20, "%Y-%m-%d %H:%M:%S", ltime); - return s; -} +//inline char* get_cur_time() { +// static char s[20]; +// time_t t; +// struct tm* ltime; +// time(&t); +// ltime = localtime(&t); +// strftime(s, 20, "%Y-%m-%d %H:%M:%S", ltime); +// return s; +//} -#define PRINT(fmt, ...) printf("%s " fmt, get_cur_time(), ##__VA_ARGS__); +//#define PRINT(fmt, ...) printf("%s " fmt, get_cur_time(), ##__VA_ARGS__); diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp index 777afd5..0edf2f0 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.cpp @@ -746,18 +746,6 @@ void clipRaster(QString inRasterPath, QString outRasterPath, long minRow, long m } -bool saveEigenMatrixXd2Bin(Eigen::MatrixXd data, QString dataStrPath) -{ - - Eigen::MatrixXd gt = Eigen::MatrixXd::Zero(2, 3); - - gdalImage img= CreategdalImageDouble(dataStrPath, data.rows(), data.cols(), 1, gt, "", false, true,true); - - img.saveImage(data, 0,0,1); - - return true; -} - long getProjectEPSGCodeByLon_Lat(double long, double lat, ProjectStripDelta stripState) @@ -1788,7 +1776,17 @@ void CreateSARIntensityByLookTable(QString IntensityRasterPath, } - +bool saveEigenMatrixXd2Bin(Eigen::MatrixXd data, QString dataStrPath) +{ + + Eigen::MatrixXd gt = Eigen::MatrixXd::Zero(2, 3); + + gdalImage img = CreategdalImageDouble(dataStrPath, data.rows(), data.cols(), 1, gt, "", false, true, true); + + img.saveImage(data, 0, 0, 1); + + return true; +} diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h index 7a024de..060df9a 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h @@ -28,6 +28,9 @@ #include #include #include +#include "ShowProessAbstract.h" + + enum ProjectStripDelta { Strip_6, // 6度带 @@ -76,13 +79,6 @@ enum GDALREADARRCOPYMETHOD { -class BASECONSTVARIABLEAPI ShowProessAbstract { - -public: - virtual void showProcess(double precent, QString tip); - virtual void showToolInfo(QString tip); -}; - @@ -234,7 +230,7 @@ public: // 方法 Eigen::MatrixXcd getDataComplex(int start_row, int start_col, int rows_count, int cols_count, int band_ids); std::shared_ptr> getDataComplexSharePtr(int start_row, int start_col, int rows_count, int cols_count, int band_ids); - void saveImage() override; + void saveComplexImage();//override; void savePreViewImage(); public: Eigen::MatrixXcd data; @@ -316,6 +312,9 @@ void BASECONSTVARIABLEAPI CreateSARIntensityByLookTable(QString IntensityRaster //--------------------- 图像文件读写 ------------------------------ + + + template inline std::shared_ptr readDataArr(gdalImage& imgds, long start_row, long start_col, long& rows_count, long& cols_count, int band_ids, GDALREADARRCOPYMETHOD method) { diff --git a/BaseCommonLibrary/BaseTool/RasterToolBase.cpp b/BaseCommonLibrary/BaseTool/RasterToolBase.cpp index 82a50be..32711fb 100644 --- a/BaseCommonLibrary/BaseTool/RasterToolBase.cpp +++ b/BaseCommonLibrary/BaseTool/RasterToolBase.cpp @@ -261,6 +261,9 @@ namespace RasterToolBase { } else if(oSRS.IsProjected()) { return CoordinateSystemType::ProjectCoordinateSystem; } + else { + return CoordinateSystemType::UNKNOW; + } } else { return CoordinateSystemType::UNKNOW; } diff --git a/BaseCommonLibrary/BaseTool/ShowProessAbstract.cpp b/BaseCommonLibrary/BaseTool/ShowProessAbstract.cpp index 78c90c3..e862722 100644 --- a/BaseCommonLibrary/BaseTool/ShowProessAbstract.cpp +++ b/BaseCommonLibrary/BaseTool/ShowProessAbstract.cpp @@ -1,34 +1,9 @@ #include "stdafx.h" -#include "ImageOperatorBase.h" +#include "ShowProessAbstract.h" #include "BaseTool.h" #include "GeoOperator.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "FileOperator.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include // OGRSpatialReference ڿռοת -#include // GDALWarp - - +#include void ShowProessAbstract::showProcess(double precent, QString tip) diff --git a/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp b/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp index 9e42e09..bc8a0a9 100644 --- a/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp +++ b/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp @@ -324,7 +324,7 @@ std::shared_ptr> gdalImageComplex::getDataComplexSharePtr(i return rasterData; } -void gdalImageComplex::saveImage() +void gdalImageComplex::saveComplexImage() { this->saveImage(this->data, this->start_row, this->start_col, this->data_band_ids); } diff --git a/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp b/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp index 622ca9d..bce0668 100644 --- a/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp +++ b/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp @@ -988,6 +988,9 @@ void gdalImage::saveImage() this->saveImage(this->data, this->start_row, this->start_col, this->data_band_ids); } + + + void gdalImage::setNoDataValue(double nodatavalue = -9999, int band_ids = 1) { GDALAllRegister(); @@ -1471,7 +1474,3 @@ gdalImage CreategdalImage(const QString& img_path, int height, int width, int ba - - - - diff --git a/BaseCommonLibrary/ImageOperatorFuntion.cpp b/BaseCommonLibrary/ImageOperatorFuntion.cpp new file mode 100644 index 0000000..aa1c062 --- /dev/null +++ b/BaseCommonLibrary/ImageOperatorFuntion.cpp @@ -0,0 +1,1849 @@ +#include "stdafx.h" +#include "ImageOperatorBase.h" +#include "BaseTool.h" +#include "GeoOperator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FileOperator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // OGRSpatialReference ڿռοת +#include // GDALWarp + + +std::shared_ptr OpenDataset(const QString& in_path, GDALAccess rwmode) +{ + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + GDALDataset* dataset_ptr = (GDALDataset*)(GDALOpen(in_path.toUtf8().constData(), rwmode)); + std::shared_ptr rasterDataset(dataset_ptr, CloseDataset); + return rasterDataset; +} + + +void CloseDataset(GDALDataset* ptr) +{ + GDALClose(ptr); + ptr = NULL; +} + + +int CreateDataset(QString new_file_path, int height, int width, int band_num, double* gt, + QString projection, GDALDataType gdal_dtype, bool need_gt) +{ + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); + std::shared_ptr poDstDS(poDriver->Create(new_file_path.toUtf8().constData(), width, + height, band_num, gdal_dtype, NULL)); + if (need_gt) { + poDstDS->SetProjection(projection.toUtf8().constData()); + poDstDS->SetGeoTransform(gt); + } + else { + } + GDALFlushCache((GDALDatasetH)poDstDS.get()); + return 0; +} + +int saveDataset(QString new_file_path, int start_line, int start_cols, int band_ids, int datacols, + int datarows, void* databuffer) +{ + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + std::shared_ptr poDstDS = OpenDataset(new_file_path, GA_Update); + GDALDataType gdal_datatype = poDstDS->GetRasterBand(1)->GetRasterDataType(); + poDstDS->GetRasterBand(band_ids)->RasterIO(GF_Write, start_cols, start_line, datacols, datarows, + databuffer, datacols, datarows, gdal_datatype, 0, 0); + GDALFlushCache(poDstDS.get()); + return 0; +} + + + + +ImageGEOINFO getImageINFO(QString in_path) +{ + std::shared_ptr df = OpenDataset(in_path); + int width = df->GetRasterXSize(); + int heigh = df->GetRasterYSize(); + int band_num = df->GetRasterCount(); + ImageGEOINFO result; + result.width = width; + result.height = heigh; + result.bandnum = band_num; + + return result; +} + +GDALDataType getGDALDataType(QString fileptah) +{ + omp_lock_t lock; + omp_init_lock(&lock); + omp_set_lock(&lock); + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( + fileptah.toUtf8().constData(), GA_ReadOnly)); // ��ֻ�ʽ��ȡ�Ӱ�� + + GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); + + GDALClose((GDALDatasetH)rasterDataset); + omp_unset_lock(&lock); // �ͷŻ�� + omp_destroy_lock(&lock); // ٻ�� + + return gdal_datatype; +} + + + + + + + +int block_num_pre_memory(int block_width, int height, GDALDataType gdal_datatype, double memey_size) +{ + // С + int size_meta = 0; + + if (gdal_datatype == GDT_Byte) { + size_meta = 1; + } + else if (gdal_datatype == GDT_UInt16) { + size_meta = 2; // ֻ˫ܹͨ + } + else if (gdal_datatype == GDT_UInt16) { + size_meta = 2; + } + else if (gdal_datatype == GDT_Int16) { + size_meta = 2; + } + else if (gdal_datatype == GDT_UInt32) { + size_meta = 4; + } + else if (gdal_datatype == GDT_Int32) { + size_meta = 4; + } + // else if (gdal_datatype == GDT_UInt64) { + // size_meta = 8; + // } + // else if (gdal_datatype == GDT_Int64) { + // size_meta = 8; + // } + else if (gdal_datatype == GDT_Float32) { + size_meta = 4; + } + else if (gdal_datatype == GDT_Float64) { + size_meta = 4; + } + else if (gdal_datatype == GDT_CInt16) { + size_meta = 2; + } + else if (gdal_datatype == GDT_CInt32) { + size_meta = 2; + } + else if (gdal_datatype == GDT_CFloat32) { + size_meta = 4; + } + else if (gdal_datatype == GDT_CFloat64) { + size_meta = 8; + } + else { + } + int block_num = int(memey_size / (size_meta * block_width)); + block_num = block_num > height ? height : block_num; // + block_num = block_num < 1 ? 1 : block_num; + return block_num; +} + + + + +int TIFF2ENVI(QString in_tiff_path, QString out_envi_path) +{ + std::shared_ptr ds = OpenDataset(in_tiff_path); + const char* args[] = { "-of", "ENVI", NULL }; + GDALTranslateOptions* psOptions = GDALTranslateOptionsNew((char**)args, NULL); + GDALClose(GDALTranslate(out_envi_path.toUtf8().constData(), ds.get(), psOptions, NULL)); + GDALTranslateOptionsFree(psOptions); + return 0; +} + +int ENVI2TIFF(QString in_envi_path, QString out_tiff_path) +{ + std::shared_ptr ds = OpenDataset(in_envi_path); + const char* args[] = { "-of", "Gtiff", NULL }; + GDALTranslateOptions* psOptions = GDALTranslateOptionsNew((char**)args, NULL); + GDALClose(GDALTranslate(out_tiff_path.toUtf8().constData(), ds.get(), psOptions, NULL)); + GDALTranslateOptionsFree(psOptions); + return 0; +} + + + +void ConvertCoordinateSystem(QString inRasterPath, QString outRasterPath, long outepsgcode) { + // עGDAL + GDALAllRegister(); + + // դļ + GDALDataset* srcDataset = (GDALDataset*)GDALOpen(inRasterPath.toUtf8().constData(), GA_ReadOnly); + if (!srcDataset) { + // ļʧ + // qDebug() << "޷ļ" << inRasterPath; + return; + } + + // Ŀϵ + OGRSpatialReference targetSRS; + if (targetSRS.importFromEPSG(outepsgcode) != OGRERR_NONE) { + GDALClose(srcDataset); + // qDebug() << "ЧEPSG룺" << outepsgcode; + return; + } + GDALDataType datetype = srcDataset->GetRasterBand(1)->GetRasterDataType(); + // ȡĿϵWKTʾ + char* targetSRSWkt = nullptr; + targetSRS.exportToWkt(&targetSRSWkt); + + bool flag = (datetype == GDT_Byte || datetype == GDT_Int8 || datetype == GDT_Int16 || datetype == GDT_UInt16 || datetype == GDT_Int32 || datetype == GDT_UInt32 || datetype == GDT_Int64 || datetype == GDT_UInt64); + + // ͶӰݼWarped VRT + GDALDataset* warpedVRT = flag ? (GDALDataset*)GDALAutoCreateWarpedVRT( + srcDataset, + nullptr, // ϵĬʹԴݣ + targetSRSWkt, // Ŀϵ + GRA_NearestNeighbour, // ز˫Բֵ + 0.0, // 0ʾԶ㣩 + nullptr // ѡ + ) : (GDALDataset*)GDALAutoCreateWarpedVRT( + srcDataset, + nullptr, // ϵĬʹԴݣ + targetSRSWkt, // Ŀϵ + GRA_Bilinear, // ز˫Բֵ + 0.0, // 0ʾԶ㣩 + nullptr // ѡ + ); + CPLFree(targetSRSWkt); // ͷWKTڴ + + if (!warpedVRT) { + GDALClose(srcDataset); + qDebug() << u8"ͶӰתVRTʧ"; + return; + } + + // ȡGeoTIFFʽ + QString filesuffer = getFileExtension(outRasterPath).toLower(); + bool isTiff = filesuffer.contains("tif"); + GDALDriver* driver = isTiff ? GetGDALDriverManager()->GetDriverByName("GTiff") : GetGDALDriverManager()->GetDriverByName("ENVI"); + if (!driver) { + GDALClose(warpedVRT); + GDALClose(srcDataset); + // qDebug() << "޷ȡGeoTIFF"; + return; + } + + // դļ + GDALDataset* dstDataset = driver->CreateCopy( + outRasterPath.toUtf8().constData(), // ļ· + warpedVRT, // ݼVRT + false, // Ƿϸ + nullptr, // ѡ + nullptr, // Ȼص + nullptr // ص + ); + + if (!dstDataset) { + // qDebug() << "ļʧܣ" << outRasterPath; + GDALClose(warpedVRT); + GDALClose(srcDataset); + return; + } + + // ͷԴ + GDALClose(dstDataset); + GDALClose(warpedVRT); + GDALClose(srcDataset); +} + + +void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QString pszOutFile, GDALResampleAlg eResample) { + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); + GDALDataset* pDSrc = (GDALDataset*)GDALOpen(pszSrcFile.toLocal8Bit().constData(), GA_ReadOnly); + if (pDSrc == NULL) { + qDebug() << u8"do not open In Raster file: " << pszSrcFile; + return; + } + + GDALDataset* pDRef = (GDALDataset*)GDALOpen(RefrasterBPath.toLocal8Bit().constData(), GA_ReadOnly); + if (pDRef == NULL) { + qDebug() << u8"do not open Ref Raster file: " << RefrasterBPath; + return; + } + + QString filesuffer = getFileExtension(pszOutFile).toLower(); + bool isTiff = filesuffer.contains("tif"); + GDALDriver* pDriver = isTiff ? GetGDALDriverManager()->GetDriverByName("GTiff") : GetGDALDriverManager()->GetDriverByName("ENVI"); + + if (pDriver == NULL) { + qDebug() << "not open driver"; + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + return; + } + int width = pDSrc->GetRasterXSize(); + int height = pDSrc->GetRasterYSize(); + int nBandCount = pDSrc->GetRasterCount(); + GDALDataType dataType = pDSrc->GetRasterBand(1)->GetRasterDataType(); + + char* pszSrcWKT = NULL; + pszSrcWKT = const_cast(pDSrc->GetProjectionRef()); + + // ���û��ͶӰ����?���һ�?1?7 + if (strlen(pszSrcWKT) <= 0) { + OGRSpatialReference oSRS; + oSRS.importFromEPSG(4326); + // oSRS.SetUTM(50, true); //������ ����120�� + // oSRS.SetWellKnownGeogCS("WGS84"); + oSRS.exportToWkt(&pszSrcWKT); + } + + char* pdstSrcWKT = NULL; + pdstSrcWKT = const_cast(pDRef->GetProjectionRef()); + + // ���û��ͶӰ����?���һ�?1?7 + if (strlen(pdstSrcWKT) <= 0) + { + OGRSpatialReference oSRS; + oSRS.importFromEPSG(4326); + // oSRS.SetUTM(50, true); //������ ����120�� + // oSRS.SetWellKnownGeogCS("WGS84"); + oSRS.exportToWkt(&pdstSrcWKT); + } + + + int new_width = pDRef->GetRasterXSize(); + int new_height = pDRef->GetRasterYSize(); + double gt[6]; + pDRef->GetGeoTransform(gt); + + // GDALDestroyGenImgProjTransformer(hTransformArg); + qDebug() << "create init GDALDataset "; + GDALDataset* pDDst = + pDriver->Create(pszOutFile.toLocal8Bit().constData(), new_width, new_height, nBandCount, dataType, NULL); + if (pDDst == NULL) { + qDebug() << "not create init GDALDataset "; + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); + GDALClose((GDALDatasetH)(GDALDatasetH)pDRef); + return; + } + + pDDst->SetProjection(pdstSrcWKT); + pDDst->SetGeoTransform(gt); + + + qDebug() << "GDALCreateGenImgProjTransformer " << Qt::endl; + void* hTransformArg; + hTransformArg = GDALCreateGenImgProjTransformer((GDALDatasetH)pDSrc, pszSrcWKT, NULL, pszSrcWKT, + FALSE, 0.0, 1); + qDebug() << "no proj "; + //(û��ͶӰ��Ӱ��������߲�??1?7) + if (hTransformArg == NULL) { + qDebug() << "hTransformArg create failure"; + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); + GDALClose((GDALDatasetH)(GDALDatasetH)pDRef); + return; + } + qDebug() << "has proj "; + double dGeoTrans[6] = { 0 }; + int nNewWidth = 0, nNewHeight = 0; + if (GDALSuggestedWarpOutput((GDALDatasetH)pDSrc, GDALGenImgProjTransform, hTransformArg, + dGeoTrans, &nNewWidth, &nNewHeight) + != CE_None) { + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); + GDALClose((GDALDatasetH)(GDALDatasetH)pDRef); + return; + } + + + + 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; + + psWo->hSrcDS = (GDALDatasetH)pDSrc; + psWo->hDstDS = (GDALDatasetH)pDDst; + qDebug() << "GDALCreateGenImgProjTransformer"; + psWo->pfnTransformer = GDALGenImgProjTransform; + psWo->pTransformerArg = GDALCreateGenImgProjTransformer( + (GDALDatasetH)pDSrc, pszSrcWKT, (GDALDatasetH)pDDst, pszSrcWKT, FALSE, 0.0, 1); + ; + + qDebug() << "GDALCreateGenImgProjTransformer has created" << Qt::endl; + psWo->nBandCount = nBandCount; + psWo->panSrcBands = (int*)CPLMalloc(nBandCount * sizeof(int)); + psWo->panDstBands = (int*)CPLMalloc(nBandCount * sizeof(int)); + for (int i = 0; i < nBandCount; i++) { + psWo->panSrcBands[i] = i + 1; + psWo->panDstBands[i] = i + 1; + } + + GDALWarpOperation oWo; + if (oWo.Initialize(psWo) != CE_None) { + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); + GDALClose((GDALDatasetH)(GDALDatasetH)pDRef); + return; + } + qDebug() << "ChunkAndWarpImage:" << new_width << "," << new_height << Qt::endl; + oWo.ChunkAndWarpMulti(0, 0, new_width, new_height); + GDALFlushCache(pDDst); + qDebug() << "ChunkAndWarpImage over" << Qt::endl; + // GDALDestroyGenImgProjTransformer(psWo->pTransformerArg); + // GDALDestroyWarpOptions(psWo); + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); + GDALClose((GDALDatasetH)(GDALDatasetH)pDRef); + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + return; +} + + +void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, QString OutrasterCPath) { + // עGDAL + GDALAllRegister(); + + // 򿪲οդB + GDALDataset* refDS = (GDALDataset*)GDALOpen(RefrasterBPath.toUtf8().constData(), GA_ReadOnly); + if (!refDS) { + qDebug() << "޷򿪲οդB" << RefrasterBPath; + return; + } + + // ȡοդĵ任ͶӰͳߴ + double geotransform[6]; + if (refDS->GetGeoTransform(geotransform) != CE_None) { + qDebug() << "ȡοդĵ任ʧܡ"; + GDALClose(refDS); + return; + } + + const char* proj = refDS->GetProjectionRef(); + int cols = refDS->GetRasterXSize(); + int rows = refDS->GetRasterYSize(); + GDALClose(refDS); // ȡϢرղοդ + + // դA + GDALDataset* srcDS = (GDALDataset*)GDALOpen(InrasterAPath.toUtf8().constData(), GA_ReadOnly); + if (!srcDS) { + qDebug() << "޷դA" << InrasterAPath; + return; + } + + // ȡդIJ + int nBands = srcDS->GetRasterCount(); + if (nBands == 0) { + qDebug() << "դûвݡ"; + GDALClose(srcDS); + return; + } + GDALDataType dataType = srcDS->GetRasterBand(1)->GetRasterDataType(); + + // դC + GDALDriver* driver = GetGDALDriverManager()->GetDriverByName("GTiff"); + if (!driver) { + qDebug() << "޷ȡGeoTIFF"; + GDALClose(srcDS); + return; + } + + GDALDataset* dstDS = driver->Create( + OutrasterCPath.toUtf8().constData(), + cols, + rows, + nBands, + dataType, + nullptr + ); + if (!dstDS) { + qDebug() << "޷դ" << OutrasterCPath; + GDALClose(srcDS); + return; + } + + // դĵ任ͶӰ + dstDS->SetGeoTransform(geotransform); + dstDS->SetProjection(proj); + + // GDAL Warpѡ + GDALWarpOptions* psWO = GDALCreateWarpOptions(); + psWO->hSrcDS = srcDS; + psWO->hDstDS = dstDS; + psWO->nBandCount = nBands; + psWO->panSrcBands = (int*)CPLMalloc(nBands * sizeof(int)); + psWO->panDstBands = (int*)CPLMalloc(nBands * sizeof(int)); + for (int i = 0; i < nBands; ++i) { + psWO->panSrcBands[i] = i + 1; + psWO->panDstBands[i] = i + 1; + } + psWO->eResampleAlg = GRA_NearestNeighbour; // ʹز + + // ʼת + psWO->pfnTransformer = GDALGenImgProjTransform; + psWO->pTransformerArg = GDALCreateGenImgProjTransformer( + srcDS, GDALGetProjectionRef(srcDS), + dstDS, GDALGetProjectionRef(dstDS), + FALSE, 0.0, 1 + ); + if (!psWO->pTransformerArg) { + qDebug() << "תʧܡ"; + GDALDestroyWarpOptions(psWO); + GDALClose(srcDS); + GDALClose(dstDS); + return; + } + + // ִWarp + GDALWarpOperation oWarp; + if (oWarp.Initialize(psWO) != CE_None) { + qDebug() << "ʼWarpʧܡ"; + GDALDestroyGenImgProjTransformer(psWO->pTransformerArg); + GDALDestroyWarpOptions(psWO); + GDALClose(srcDS); + GDALClose(dstDS); + return; + } + + CPLErr eErr = oWarp.ChunkAndWarpImage(0, 0, cols, rows); + if (eErr != CE_None) { + qDebug() << "ִWarpʧܡ"; + } + + // Դ + GDALDestroyGenImgProjTransformer(psWO->pTransformerArg); + GDALDestroyWarpOptions(psWO); + GDALClose(srcDS); + GDALClose(dstDS); + + qDebug() << "زɣѱ" << OutrasterCPath; +} + +void cropRasterByLatLon(const char* inputFile, const char* outputFile, double minLon, double maxLon, double minLat, double maxLat) { + // ʼ GDAL + GDALAllRegister(); + + // դݼ + GDALDataset* poDataset = (GDALDataset*)GDALOpen(inputFile, GA_ReadOnly); + if (poDataset == nullptr) { + std::cerr << "Failed to open input raster." << std::endl; + return; + } + + // ȡդݵĵοϢ + double adfGeoTransform[6]; + if (poDataset->GetGeoTransform(adfGeoTransform) != CE_None) { + std::cerr << "Failed to get geotransform." << std::endl; + GDALClose(poDataset); + return; + } + + // ȡӰͶӰϢ + const char* projection = poDataset->GetProjectionRef(); + + // ݾγȼüӦդ + int xMin = (int)((minLon - adfGeoTransform[0]) / adfGeoTransform[1]); + int xMax = (int)((maxLon - adfGeoTransform[0]) / adfGeoTransform[1]); + int yMin = (int)((maxLat - adfGeoTransform[3]) / adfGeoTransform[5]); + int yMax = (int)((minLat - adfGeoTransform[3]) / adfGeoTransform[5]); + + // üĿդݼ + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + if (poDriver == nullptr) { + std::cerr << "Failed to get GTiff driver." << std::endl; + GDALClose(poDataset); + return; + } + + // դݼָߴ + int width = xMax - xMin; + int height = yMax - yMin; + GDALDataset* poOutDataset = poDriver->Create(outputFile, width, height, poDataset->GetRasterCount(), GDT_Float32, nullptr); + if (poOutDataset == nullptr) { + std::cerr << "Failed to create output raster." << std::endl; + GDALClose(poDataset); + return; + } + + // դͶӰϢ͵任 + poOutDataset->SetProjection(projection); + double newGeoTransform[6] = { adfGeoTransform[0] + xMin * adfGeoTransform[1], adfGeoTransform[1], 0.0, adfGeoTransform[3] + yMin * adfGeoTransform[5], 0.0, adfGeoTransform[5] }; + poOutDataset->SetGeoTransform(newGeoTransform); + + // ѭȡԴݲдĿݼ + for (int i = 0; i < poDataset->GetRasterCount(); ++i) { + GDALRasterBand* poBand = poDataset->GetRasterBand(i + 1); + GDALRasterBand* poOutBand = poOutDataset->GetRasterBand(i + 1); + + // ȡԴ + int* pData = new int[width * height]; + poBand->RasterIO(GF_Read, xMin, yMin, width, height, pData, width, height, GDT_Int32, 0, 0); + + // дĿ + poOutBand->RasterIO(GF_Write, 0, 0, width, height, pData, width, height, GDT_Int32, 0, 0); + + delete[] pData; + } + + qDebug() << "Raster cropped and saved to: " << outputFile; + + // + GDALClose(poDataset); + GDALClose(poOutDataset); +} + +ErrorCode transformCoordinate(double x, double y, int sourceEPSG, int targetEPSG, Point2& p) { + // Դϵԭʼϵ + OGRSpatialReference sourceSRS; + sourceSRS.importFromEPSG(sourceEPSG); // ʹ EPSG ָϵ + + // ĿϵĿϵ + OGRSpatialReference targetSRS; + targetSRS.importFromEPSG(targetEPSG); // WGS84 ϵ EPSG:4326 + + // 任 + OGRCoordinateTransformation* transform = OGRCreateCoordinateTransformation(&sourceSRS, &targetSRS); + if (transform == nullptr) { + qDebug() << "Failed to create coordinate transformation."; + return ErrorCode::FAIL; + } + + // ת + double transformedX = x; + double transformedY = y; + if (transform->Transform(1, &transformedX, &transformedY)) { + qDebug() << "Original Coordinates: (" << x << ", " << y << ")"; + qDebug() << "Transformed Coordinates (EPSG:" << targetEPSG << "): (" << transformedX << ", " << transformedY << ")"; + } + else { + qDebug() << "Coordinate transformation failed."; + } + + // + delete transform; + p.x = transformedX; + p.y = transformedY; + return ErrorCode::SUCCESS; + +} + + +void transformRaster(const char* inputFile, const char* outputFile, int sourceEPSG, int targetEPSG) { + // ʼ GDAL + GDALAllRegister(); + + // Դդļ + GDALDataset* poSrcDS = (GDALDataset*)GDALOpen(inputFile, GA_ReadOnly); + if (poSrcDS == nullptr) { + qDebug() << "Failed to open input file:" << inputFile; + return; + } + + // ȡԴդĻϢ + int nXSize = poSrcDS->GetRasterXSize(); + int nYSize = poSrcDS->GetRasterYSize(); + int nBands = poSrcDS->GetRasterCount(); + GDALDataType eDT = poSrcDS->GetRasterBand(1)->GetRasterDataType(); + + // Ŀդļ + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + if (poDriver == nullptr) { + qDebug() << "GTiff driver not available."; + GDALClose(poSrcDS); + return; + } + + GDALDataset* poDstDS = poDriver->Create(outputFile, nXSize, nYSize, nBands, eDT, nullptr); + if (poDstDS == nullptr) { + qDebug() << "Failed to create output file:" << outputFile; + GDALClose(poSrcDS); + return; + } + + // ĿդĿռοϵͳ + OGRSpatialReference oSRS; + oSRS.importFromEPSG(targetEPSG); + + char* pszWKT = nullptr; + oSRS.exportToWkt(&pszWKT); + poDstDS->SetProjection(pszWKT); + CPLFree(pszWKT); + + // Ԫ + poDstDS->SetMetadata(poSrcDS->GetMetadata()); + + // ÿε + for (int i = 1; i <= nBands; ++i) { + GDALRasterBand* poSrcBand = poSrcDS->GetRasterBand(i); + GDALRasterBand* poDstBand = poDstDS->GetRasterBand(i); + + float* pafScanline = (float*)CPLMalloc(sizeof(float) * nXSize); + + for (int j = 0; j < nYSize; ++j) { + poSrcBand->RasterIO(GF_Read, 0, j, nXSize, 1, pafScanline, nXSize, 1, GDT_Float32, 0, 0); + poDstBand->RasterIO(GF_Write, 0, j, nXSize, 1, pafScanline, nXSize, 1, GDT_Float32, 0, 0); + } + + CPLFree(pafScanline); + } + + // رݼ + GDALClose(poSrcDS); + GDALClose(poDstDS); + + qDebug() << "Raster transformation completed successfully."; +} + + +void resampleRaster(const char* inputRaster, const char* outputRaster, double targetPixelSizeX, double targetPixelSizeY) { + // ʼGDAL + GDALAllRegister(); + // դļ + GDALDataset* poDataset = (GDALDataset*)GDALOpen(inputRaster, GA_ReadOnly); + if (poDataset == nullptr) { + std::cerr << "Failed to open raster file." << std::endl; + return; + } + + // ȡԭʼդĿռο + double adfGeoTransform[6]; + if (poDataset->GetGeoTransform(adfGeoTransform) != CE_None) { + std::cerr << "Failed to get geotransform." << std::endl; + GDALClose(poDataset); + return; + } + + // ȡԭʼդijߴ + int nXSize = poDataset->GetRasterXSize(); + int nYSize = poDataset->GetRasterYSize(); + + // Ŀդijߴ + double targetXSize = (adfGeoTransform[1] * nXSize) / targetPixelSizeX; + double targetYSize = (adfGeoTransform[5] * nYSize) / targetPixelSizeY; + + // Ŀݼդ + GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + if (poDriver == nullptr) { + std::cerr << "Failed to get GTiff driver." << std::endl; + GDALClose(poDataset); + return; + } + + // ݼ + GDALDataset* poOutDataset = poDriver->Create(outputRaster, (int)targetXSize, (int)targetYSize, poDataset->GetRasterCount(), GDT_Float32, nullptr); + if (poOutDataset == nullptr) { + std::cerr << "Failed to create output raster." << std::endl; + GDALClose(poDataset); + return; + } + + // ݼĵ任ϵ + double targetGeoTransform[6] = { + adfGeoTransform[0], targetPixelSizeX, 0, adfGeoTransform[3], 0, -targetPixelSizeY + }; + poOutDataset->SetGeoTransform(targetGeoTransform); + + // ݼͶӰϢ + poOutDataset->SetProjection(poDataset->GetProjectionRef()); + + // ز + for (int i = 0; i < poDataset->GetRasterCount(); i++) { + GDALRasterBand* poBand = poDataset->GetRasterBand(i + 1); + GDALRasterBand* poOutBand = poOutDataset->GetRasterBand(i + 1); + + // ʹGDALزѡһʵزʽ + poOutBand->RasterIO(GF_Write, 0, 0, (int)targetXSize, (int)targetYSize, + nullptr, (int)targetXSize, (int)targetYSize, + poBand->GetRasterDataType(), 0, 0, nullptr); + } + + // رݼ + GDALClose(poDataset); + GDALClose(poOutDataset); + + qDebug() << "Resampling completed."; +} + +std::shared_ptr GetCenterPointInRaster(QString filepath) +{ + qDebug() << "============= GetCenterPointInRaster ======================"; + // QTextCodec* codec = QTextCodec::codecForLocale(); // ȡϵͳĬϱı + // QByteArray byteArray = codec->fromUnicode(filepath); // QStringתΪQByteArray + //,ӦûԶͷ const char* charArray = byteArray.constData(); // + // ȡQByteArrayconst char*ָ + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + // qDebug()<GetGeoTransform(adfGeoTransform) != CE_None) { + qDebug() << "Failed to get GeoTransform"; + return nullptr; + } + + double dfWidth = poDataset->GetRasterXSize(); + double dfHeight = poDataset->GetRasterYSize(); + + // ĵ꣨꣩ + double dfCenterX = adfGeoTransform[0] + dfWidth * adfGeoTransform[1] / 2.0 + + dfHeight * adfGeoTransform[2] / 2.0; + double dfCenterY = adfGeoTransform[3] + dfWidth * adfGeoTransform[4] / 2.0 + + dfHeight * adfGeoTransform[5] / 2.0; + + OGRSpatialReference oSRS; + oSRS.importFromWkt(poDataset->GetProjectionRef()); + + if (oSRS.IsGeographic()) { + qDebug() << "Center coords (already in geographic): (" + QString::number(dfCenterX) + + ", " + QString::number(dfCenterY) + ")"; + flag = true; + x = dfCenterX; + y = dfCenterY; + } + else { + // ǵϵתWGS84 + OGRSpatialReference oSRS_WGS84; + oSRS_WGS84.SetWellKnownGeogCS("WGS84"); + + OGRCoordinateTransformation* poCT = + OGRCreateCoordinateTransformation(&oSRS, &oSRS_WGS84); + if (poCT == nullptr) { + qDebug() << "Failed to create coordinate transformation"; + return nullptr; + } + + // double dfLon, dfLat; + if (poCT->Transform(1, &dfCenterX, &dfCenterY)) { + qDebug() << "Center coords (transformed to WGS84): (" + + QString::number(dfCenterX) + ", " + QString::number(dfCenterY) + << ")"; + flag = true; + x = dfCenterX; + y = dfCenterY; + } + else { + qDebug() << "Transformation failed."; + } + OGRCoordinateTransformation::DestroyCT(poCT); + } + } + if (nullptr == poDataset || NULL == poDataset) {} + else { + GDALClose(poDataset); + } + + if (flag) { + std::shared_ptr RasterCenterPoint = std::make_shared(); + RasterCenterPoint->x = x; + RasterCenterPoint->y = y; + RasterCenterPoint->z = 0; + return RasterCenterPoint; + } + else { + return nullptr; + } +} + + + +long GetEPSGFromRasterFile(QString filepath) +{ + qDebug() << "============= GetEPSGFromRasterFile ======================"; + // QTextCodec* codec = QTextCodec::codecForLocale(); // ȡϵͳĬϱı + // QByteArray byteArray = codec->fromUnicode(filepath); // QStringתΪQByteArray + //,ӦûԶͷ const char* charArray = byteArray.constData(); // + // ȡQByteArrayconst char*ָ + + { + if (QFile(filepath).exists()) { + qDebug() << "info: the image found.\n"; + } + else { + return -1; + } + + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // עGDAL + // qDebug()<GetProjectionRef(); + + qDebug() << QString::fromUtf8(pszProjection); + + // SpatialReference + OGRSpatialReference oSRS; + if (oSRS.importFromWkt((char**)&pszProjection) != OGRERR_NONE) { + qDebug() << ("Error: Unable to import projection information.\n"); + GDALClose(poDataset); + return -1; + } + + qDebug() << pszProjection; + + const char* epscodestr = oSRS.GetAuthorityCode(nullptr); + if (NULL == epscodestr || nullptr == epscodestr) { + qDebug() << "EPSG code string could not be determined from the spatial reference."; + GDALClose(poDataset); + + return -1; + } + long epsgCode = atoi(epscodestr); // ȡEPSG + + if (epsgCode != 0) { + GDALClose(poDataset); + qDebug() << QString("file %1 :epsg Code %2").arg(filepath).arg(epsgCode); + return epsgCode; + } + else { + qDebug() << "EPSG code could not be determined from the spatial reference."; + GDALClose(poDataset); + + return -1; + } + } +} + + + +long getProjectEPSGCodeByLon_Lat(double long, double lat, ProjectStripDelta stripState) +{ + long EPSGCode = 0; + switch (stripState) { + case ProjectStripDelta::Strip_3: { + break; + }; + case ProjectStripDelta::Strip_6: { + break; + } + default: { + EPSGCode = -1; + break; + } + } + qDebug() << QString(" EPSG code : %1").arg(EPSGCode); + return EPSGCode; +} +long getProjectEPSGCodeByLon_Lat_inStrip3(double lon, double lat) +{ + // EPSG 4534 ~ 4554 3 ȴ + // жǷ йΧ + // ľȷΧ 75E ~ 135E ʵʷΧ 73.5E ~ 136.5E, + // γȷΧ 3N ~ 54Nſ 0N~ 60N + if (73.5 <= lon && lon <= 136.5 && 0 <= lat && lat <= 60) { // й + long code = trunc((lon - 73.5) / 3) + 4534; + return code; + } + else { // й ʹ ˹ + bool isSouth = lat < 0; // жϱΪʾʵӦÿҪϸµ߼ + long prefix = isSouth ? 327000 : 326000; + // std::string prefix = isSouth ? "327" : "326"; + lon = fmod(lon + 360.0, 360.0); + long zone = std::floor((lon + 180.0) / 3.0); + prefix = prefix + zone; + return prefix; + } + return 0; +} +long getProjectEPSGCodeByLon_Lat_inStrip6(double lon, double lat) +{ + // EPSG 4502 ~ 4512 6ȴ + // жǷ йΧ + // ľȷΧ 75E ~ 135E ʵʷΧ 72.0E ~ 138E, + // γȷΧ 3N ~ 54Nſ 0N~ 60N + if (73.5 <= lon && lon <= 136.5 && 0 <= lat && lat <= 60) { // й + long code = trunc((lon - 72.0) / 6) + 4502; + return code; + } + else { // й ʹ UTM// ȷţ6ȴ1ʼ60ÿ6һ + int zone = static_cast((lon + 180.0) / 6.0) + 1; + bool isSouth = lon < 0; // жǷϰ + long epsgCodeBase = isSouth ? 32700 : 32600; // EPSG + long prefix = static_cast(epsgCodeBase + zone); + return prefix; + } + return 0; +} + +QString GetProjectionNameFromEPSG(long epsgCode) +{ + qDebug() << "============= GetProjectionNameFromEPSG ======================"; + OGRSpatialReference oSRS; + + // EPSG + if (oSRS.importFromEPSG(epsgCode) != OGRERR_NONE) { + qDebug() << "epsgcode not recognition"; + return ""; + } + + // ȡϵƣ + const char* pszName = oSRS.GetAttrValue("GEOGCS"); + if (pszName) { + qDebug() << "Coordinate system name for EPSG " + QString::number(epsgCode) + << " is: " + QString::fromStdString(pszName); + return QString::fromStdString(pszName); + } + else { + qDebug() << "Unable to retrieve the name for EPSG " + QString::number(epsgCode); + return ""; + } + + // char* wkt = NULL; + // // תΪWKTʽ + // oSRS.exportToWkt(&wkt); + // + // qDebug() << wkt; + // + // // WKTнͶӰƣ򻯴ʵʿҪӵ߼׼ȷȡ + // std::string wktStr(wkt); + // long start = wktStr.find("PROJCS[\"") + 8; // ҵ"PROJCS["ĵһ˫λ + // // startλÿʼһ˫ţ֮ݼΪͶӰ + // int end = wktStr.find('\"', start); + // QString projName = QString::fromStdString(wktStr.substr(start, end - start)); + // + // // ͷWKTַڴ + // CPLFree(wkt); + + // return projName; +} + + + +CoordinateSystemType getCoordinateSystemTypeByEPSGCode(long epsg_code) +{ + OGRSpatialReference oSRS; + if (oSRS.importFromEPSG(epsg_code) == OGRERR_NONE) { + if (oSRS.IsGeographic()) { + return CoordinateSystemType::GeoCoordinateSystem; + } + else if (oSRS.IsProjected()) { + return CoordinateSystemType::ProjectCoordinateSystem; + } + else { + return CoordinateSystemType::UNKNOW; + } + } + else { + return CoordinateSystemType::UNKNOW; + } +} + + + +int ResampleGDAL(const char* pszSrcFile, const char* pszOutFile, double* gt, int new_width, + int new_height, GDALResampleAlg eResample) +{ + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); + GDALDataset* pDSrc = (GDALDataset*)GDALOpen(pszSrcFile, GA_ReadOnly); + if (pDSrc == NULL) { + return -1; + } + + GDALDriver* pDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + if (pDriver == NULL) { + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + return -2; + } + int width = pDSrc->GetRasterXSize(); + int height = pDSrc->GetRasterYSize(); + int nBandCount = pDSrc->GetRasterCount(); + GDALDataType dataType = pDSrc->GetRasterBand(1)->GetRasterDataType(); + + char* pszSrcWKT = NULL; + pszSrcWKT = const_cast(pDSrc->GetProjectionRef()); + + // ���û��ͶӰ����?���һ�?1?7 + if (strlen(pszSrcWKT) <= 0) { + OGRSpatialReference oSRS; + oSRS.importFromEPSG(4326); + // oSRS.SetUTM(50, true); //������ ����120�� + // oSRS.SetWellKnownGeogCS("WGS84"); + oSRS.exportToWkt(&pszSrcWKT); + } + qDebug() << "GDALCreateGenImgProjTransformer " << Qt::endl; + void* hTransformArg; + hTransformArg = GDALCreateGenImgProjTransformer((GDALDatasetH)pDSrc, pszSrcWKT, NULL, pszSrcWKT, + FALSE, 0.0, 1); + qDebug() << "no proj " << Qt::endl; + //(û��ͶӰ��Ӱ��������߲�??1?7) + if (hTransformArg == NULL) { + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + return -3; + } + qDebug() << "has proj " << Qt::endl; + double dGeoTrans[6] = { 0 }; + int nNewWidth = 0, nNewHeight = 0; + if (GDALSuggestedWarpOutput((GDALDatasetH)pDSrc, GDALGenImgProjTransform, hTransformArg, + dGeoTrans, &nNewWidth, &nNewHeight) + != CE_None) { + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + return -3; + } + + // GDALDestroyGenImgProjTransformer(hTransformArg); + qDebug() << "create init GDALDataset "; + GDALDataset* pDDst = + pDriver->Create(pszOutFile, new_width, new_height, nBandCount, dataType, NULL); + if (pDDst == NULL) { + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + return -2; + } + + pDDst->SetProjection(pszSrcWKT); + 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; + + psWo->hSrcDS = (GDALDatasetH)pDSrc; + psWo->hDstDS = (GDALDatasetH)pDDst; + qDebug() << "GDALCreateGenImgProjTransformer" << Qt::endl; + psWo->pfnTransformer = GDALGenImgProjTransform; + psWo->pTransformerArg = GDALCreateGenImgProjTransformer( + (GDALDatasetH)pDSrc, pszSrcWKT, (GDALDatasetH)pDDst, pszSrcWKT, FALSE, 0.0, 1); + ; + + qDebug() << "GDALCreateGenImgProjTransformer has created" << Qt::endl; + psWo->nBandCount = nBandCount; + psWo->panSrcBands = (int*)CPLMalloc(nBandCount * sizeof(int)); + psWo->panDstBands = (int*)CPLMalloc(nBandCount * sizeof(int)); + for (int i = 0; i < nBandCount; i++) { + psWo->panSrcBands[i] = i + 1; + psWo->panDstBands[i] = i + 1; + } + + GDALWarpOperation oWo; + if (oWo.Initialize(psWo) != CE_None) { + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); + return -3; + } + qDebug() << "ChunkAndWarpImage:" << new_width << "," << new_height << Qt::endl; + oWo.ChunkAndWarpMulti(0, 0, new_width, new_height); + GDALFlushCache(pDDst); + qDebug() << "ChunkAndWarpImage over" << Qt::endl; + // GDALDestroyGenImgProjTransformer(psWo->pTransformerArg); + // GDALDestroyWarpOptions(psWo); + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + return 0; +} + +int ResampleGDALs(const char* pszSrcFile, int band_ids, GDALRIOResampleAlg eResample) +{ + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); + GDALDataset* pDSrc = (GDALDataset*)GDALOpen(pszSrcFile, GA_Update); + if (pDSrc == NULL) { + return -1; + } + + GDALDataType gdal_datatype = pDSrc->GetRasterBand(1)->GetRasterDataType(); + + GDALRasterBand* demBand = pDSrc->GetRasterBand(band_ids); + + int width = pDSrc->GetRasterXSize(); + int height = pDSrc->GetRasterYSize(); + int start_col = 0, start_row = 0, rows_count = 0, cols_count; + + int row_delta = int(120000000 / width); + + GDALRasterIOExtraArg psExtraArg; + INIT_RASTERIO_EXTRA_ARG(psExtraArg); + psExtraArg.eResampleAlg = eResample; + + do { + rows_count = start_row + row_delta < height ? row_delta : height - start_row; + cols_count = width; + + if (gdal_datatype == GDALDataType::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); + demBand->RasterIO(GF_Write, start_col, start_row, cols_count, rows_count, temp, + cols_count, rows_count, gdal_datatype, 0, 0, &psExtraArg); + delete[] temp; + + } + else if (gdal_datatype == GDALDataType::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); + demBand->RasterIO(GF_Write, start_col, start_row, cols_count, rows_count, temp, + cols_count, rows_count, gdal_datatype, 0, 0, &psExtraArg); + delete[] temp; + } + else if (gdal_datatype == GDALDataType::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); + demBand->RasterIO(GF_Write, start_col, start_row, cols_count, rows_count, temp, + cols_count, rows_count, gdal_datatype, 0, 0, &psExtraArg); + delete[] temp; + } + start_row = start_row + rows_count; + } while (start_row < height); + GDALClose((GDALDatasetH)pDSrc); + + return 0; +} + +int alignRaster(QString inputPath, QString referencePath, QString outputPath, GDALResampleAlg eResample) +{ + + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + + GDALDataset* pDSrc = (GDALDataset*)GDALOpen(inputPath.toUtf8().constData(), GA_ReadOnly); + if (pDSrc == NULL) { + return -1; + } + + GDALDataset* tDSrc = (GDALDataset*)GDALOpen(referencePath.toUtf8().constData(), GA_ReadOnly); + if (tDSrc == NULL) { + return -1; + } + + long new_width = tDSrc->GetRasterXSize(); + long new_height = tDSrc->GetRasterYSize(); + + GDALDriver* pDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); + if (pDriver == NULL) { + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + return -2; + } + int width = pDSrc->GetRasterXSize(); + int height = pDSrc->GetRasterYSize(); + int nBandCount = pDSrc->GetRasterCount(); + GDALDataType dataType = pDSrc->GetRasterBand(1)->GetRasterDataType(); + + char* pszSrcWKT = NULL; + pszSrcWKT = const_cast(pDSrc->GetProjectionRef()); + + if (strlen(pszSrcWKT) <= 0) { + OGRSpatialReference oSRS; + oSRS.importFromEPSG(4326); + oSRS.exportToWkt(&pszSrcWKT); + } + qDebug() << "GDALCreateGenImgProjTransformer " << Qt::endl; + void* hTransformArg; + hTransformArg = GDALCreateGenImgProjTransformer((GDALDatasetH)pDSrc, pszSrcWKT, NULL, pszSrcWKT, FALSE, 0.0, 1); + qDebug() << "no proj " << Qt::endl; + if (hTransformArg == NULL) { + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + return -3; + } + qDebug() << "has proj " << Qt::endl; + std::shared_ptr dGeoTrans(new double[6], delArrPtr); + int nNewWidth = 0, + nNewHeight = 0; + + if (GDALSuggestedWarpOutput((GDALDatasetH)pDSrc, GDALGenImgProjTransform, hTransformArg, dGeoTrans.get(), &nNewWidth, &nNewHeight) != CE_None) { + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + return -3; + } + + GDALDataset* pDDst = pDriver->Create(outputPath.toUtf8().constData(), new_width, new_height, pDSrc->GetRasterCount(), dataType, NULL); + if (pDDst == NULL) { + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + return -2; + } + + std::shared_ptr gt(new double[6], delArrPtr); + tDSrc->GetGeoTransform(gt.get()); + pDDst->SetProjection(pszSrcWKT); + pDDst->SetGeoTransform(gt.get()); + + GDALWarpOptions* psWo = GDALCreateWarpOptions(); + + psWo->eWorkingDataType = dataType; + psWo->eResampleAlg = eResample; + + psWo->hSrcDS = (GDALDatasetH)pDSrc; + psWo->hDstDS = (GDALDatasetH)pDDst; + + psWo->pfnTransformer = GDALGenImgProjTransform; + psWo->pTransformerArg = GDALCreateGenImgProjTransformer((GDALDatasetH)pDSrc, pszSrcWKT, (GDALDatasetH)pDDst, pszSrcWKT, FALSE, 0.0, 1); + + + qDebug() << "GDALCreateGenImgProjTransformer has created" << Qt::endl; + psWo->nBandCount = nBandCount; + psWo->panSrcBands = (int*)CPLMalloc(nBandCount * sizeof(int)); + psWo->panDstBands = (int*)CPLMalloc(nBandCount * sizeof(int)); + for (int i = 0; i < nBandCount; i++) { + psWo->panSrcBands[i] = i + 1; + psWo->panDstBands[i] = i + 1; + } + + GDALWarpOperation oWo; + if (oWo.Initialize(psWo) != CE_None) { + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); + GDALClose((GDALDatasetH)(GDALDatasetH)tDSrc); + return -3; + } + qDebug() << "ChunkAndWarpImage:" << new_width << "," << new_height << Qt::endl; + oWo.ChunkAndWarpMulti(0, 0, new_width, new_height); + GDALFlushCache(pDDst); + qDebug() << "ChunkAndWarpImage over" << Qt::endl; + GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); + GDALClose((GDALDatasetH)(GDALDatasetH)pDDst); + GDALClose((GDALDatasetH)(GDALDatasetH)tDSrc); + return 0; + + +} + + + +/** 2025.03.25 ĺ Eigenʹ****************************/ + + + +bool saveEigenMatrixXd2Bin(Eigen::MatrixXd data, QString dataStrPath) +{ + + Eigen::MatrixXd gt = Eigen::MatrixXd::Zero(2, 3); + + gdalImage img = CreategdalImageDouble(dataStrPath, data.rows(), data.cols(), 1, gt, "", false, true, true); + + img.saveImage(data, 0, 0, 1); + + return true; +} + + +Eigen::MatrixXd getGeoTranslationArray(QString in_path) +{ + return Eigen::MatrixXd(); +} + + +int saveMatrixXcd2TiFF(Eigen::MatrixXcd data, QString out_tiff_path) +{ + int rows = data.rows(); + int cols = data.cols(); + + Eigen::MatrixXd gt = Eigen::MatrixXd::Zero(2, 3); + + gdalImage image_tiff = + CreategdalImage(out_tiff_path, rows, cols, 2, gt, "", false, true); // עﱣ + // ļ + Eigen::MatrixXd real_img = data.array().real(); + Eigen::MatrixXd imag_img = data.array().imag(); + image_tiff.saveImage(real_img, 0, 0, 1); + image_tiff.saveImage(imag_img, 0, 0, 2); + return -1; +} + +void clipRaster(QString inRasterPath, QString outRasterPath, long minRow, long maxRow, long minCol, long maxCol) +{ + long rownum = maxRow - minRow + 1; + long colnum = maxCol - minCol + 1; + + gdalImage inimg(inRasterPath); + Eigen::MatrixXd gt = inimg.gt; + + Landpoint lp = inimg.getLandPoint(minRow, minCol, 0); + + gt(0, 0) = lp.lon; + gt(1, 0) = lp.lat; + + gdalImage outimg = CreategdalImageDouble(outRasterPath, rownum, colnum, inimg.band_num, gt, inimg.projection, true, true, true); + + for (long bi = 1; bi < inimg.band_num + 1; bi++) { + Eigen::MatrixXd brasterData = inimg.getData(minRow, minCol, rownum, colnum, bi); + outimg.saveImage(brasterData, 0, 0, bi); + qDebug() << "writer raster band : " << bi; + } + + qDebug() << "writer raster overring"; + +} + + + +ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QString demsloperPath) +{ + gdalImage demds(dempath); + gdalImage demxyz = CreategdalImage(demxyzpath, demds.height, demds.width, 3, demds.gt, demds.projection, true, true);// X,Y,Z + + // ֿ㲢תΪXYZ + + Eigen::MatrixXd demArr = demds.getData(0, 0, demds.height, demds.width, 1); + Eigen::MatrixXd demR = demArr; + Landpoint LandP{ 0,0,0 }; + Point3 GERpoint{ 0,0,0 }; + double R = 0; + double dem_row = 0, dem_col = 0, dem_alt = 0; + + long line_invert = 1000; + + double rowidx = 0; + double colidx = 0; + for (int max_rows_ids = 0; max_rows_ids < demds.height; max_rows_ids = max_rows_ids + line_invert) { + Eigen::MatrixXd demdata = demds.getData(max_rows_ids, 0, line_invert, demds.width, 1); + Eigen::MatrixXd xyzdata_x = demdata.array() * 0; + Eigen::MatrixXd xyzdata_y = demdata.array() * 0; + Eigen::MatrixXd xyzdata_z = demdata.array() * 0; + + int datarows = demdata.rows(); + int datacols = demdata.cols(); + + for (int i = 0; i < datarows; i++) { + for (int j = 0; j < datacols; j++) { + rowidx = i + max_rows_ids; + colidx = j; + demds.getLandPoint(rowidx, colidx, demdata(i, j), LandP); // ȡ + LLA2XYZ(LandP, GERpoint); // γתΪϵ + xyzdata_x(i, j) = GERpoint.x; + xyzdata_y(i, j) = GERpoint.y; + xyzdata_z(i, j) = GERpoint.z; + } + } + demxyz.saveImage(xyzdata_x, max_rows_ids, 0, 1); + demxyz.saveImage(xyzdata_y, max_rows_ids, 0, 2); + demxyz.saveImage(xyzdata_z, max_rows_ids, 0, 3); + } + + + // + gdalImage demsloperxyz = CreategdalImage(demsloperPath, demds.height, demds.width, 4, demds.gt, demds.projection, true, true);// X,Y,Z,cosangle + + line_invert = 1000; + long start_ids = 0; + long dem_rows = 0, dem_cols = 0; + + for (start_ids = 1; start_ids < demds.height; start_ids = start_ids + line_invert) { + Eigen::MatrixXd demdata = demds.getData(start_ids - 1, 0, line_invert + 2, demxyz.width, 1); + long startlineid = start_ids; + Eigen::MatrixXd demsloper_x = demsloperxyz.getData(start_ids - 1, 0, line_invert + 2, demxyz.width, 1); + Eigen::MatrixXd demsloper_y = demsloperxyz.getData(start_ids - 1, 0, line_invert + 2, demxyz.width, 2); + Eigen::MatrixXd demsloper_z = demsloperxyz.getData(start_ids - 1, 0, line_invert + 2, demxyz.width, 3); + Eigen::MatrixXd demsloper_angle = demsloperxyz.getData(start_ids - 1, 0, line_invert + 2, demxyz.width, 4); + + Landpoint p0, p1, p2, p3, p4, pslopeVector, pp; + Vector3D slopeVector; + + dem_rows = demsloper_y.rows(); + dem_cols = demsloper_y.cols(); + double sloperAngle = 0; + Vector3D Zaxis = { 0,0,1 }; + + double rowidx = 0, colidx = 0; + + for (long i = 1; i < dem_rows - 1; i++) { + for (long j = 1; j < dem_cols - 1; j++) { + rowidx = i + startlineid; + colidx = j; + demds.getLandPoint(rowidx, colidx, demdata(i, j), p0); + demds.getLandPoint(rowidx - 1, colidx, demdata(i - 1, j), p1); + demds.getLandPoint(rowidx, colidx - 1, demdata(i, j - 1), p2); + demds.getLandPoint(rowidx + 1, colidx, demdata(i + 1, j), p3); + demds.getLandPoint(rowidx, colidx + 1, demdata(i, j + 1), p4); + + pslopeVector = getSlopeVector(p0, p1, p2, p3, p4); // ʸ + slopeVector = { pslopeVector.lon,pslopeVector.lat,pslopeVector.ati }; + pp = LLA2XYZ(p0); + Zaxis.x = pp.lon; + Zaxis.y = pp.lat; + Zaxis.z = pp.ati; + sloperAngle = getCosAngle(slopeVector, Zaxis); // + + demsloper_x(i, j) = slopeVector.x; + demsloper_y(i, j) = slopeVector.y; + demsloper_z(i, j) = slopeVector.z; + demsloper_angle(i, j) = sloperAngle; + } + } + demsloperxyz.saveImage(demsloper_x, start_ids - 1, 0, 1); + demsloperxyz.saveImage(demsloper_y, start_ids - 1, 0, 2); + demsloperxyz.saveImage(demsloper_z, start_ids - 1, 0, 3); + demsloperxyz.saveImage(demsloper_angle, start_ids - 1, 0, 4); + } + + + return ErrorCode::SUCCESS; +} + + + +void CreateSARIntensityByLookTable(QString IntensityRasterPath, + QString LookTableRasterPath, + QString SARIntensityPath, + long min_rid, long max_rid, + long min_cid, long max_cid, + std::function processBarShow +) +{ + gdalImage looktableds(LookTableRasterPath); + gdalImage geoIntensity(IntensityRasterPath); + gdalImage SARIntensity = CreategdalImageDouble(SARIntensityPath, max_rid - min_rid, max_cid - min_cid, 1); + + long blockYSize = Memory1GB / looktableds.width / 8 * 2; + + Eigen::MatrixXd SARData = SARIntensity.getData(0, 0, SARIntensity.height, SARIntensity.width, 1); + SARData = SARData.array() * 0; + // ֿ鴦 + for (int yOff = 0; yOff < looktableds.height; yOff += blockYSize) + { + processBarShow(yOff, looktableds.height); + qDebug() << "Process : [" << yOff * 100.0 / looktableds.height << " % ]"; + Eigen::MatrixXd rowData = looktableds.getData(yOff, 0, blockYSize, looktableds.width, 1); + Eigen::MatrixXd colData = looktableds.getData(yOff, 0, blockYSize, looktableds.width, 2); + Eigen::MatrixXd geoData = geoIntensity.getData(yOff, 0, blockYSize, looktableds.width, 1); + + for (long i = 0; i < rowData.rows(); i++) { + for (long j = 0; j < rowData.cols(); j++) { + long r = round(rowData(i, j)) - min_rid; + long c = round(colData(i, j)) - min_cid; + + if (r >= 0 && r < SARIntensity.height && c >= 0 && c < SARIntensity.width) { + SARData(r, c) = SARData(r, c) + geoData(i, j); + } + } + } + } + SARIntensity.saveImage(SARData, 0, 0, 1); + qDebug() << "Process : [ 100 % ]"; + processBarShow(1000, 1000); +} + + +/* ĺᵼ±󣬿Eigen bugأŲ飬̫ʱ䣬ҲһŲ +* +*** + +Eigen::Matrix ReadComplexMatrixData(int start_line, int width, int line_num, + std::shared_ptr rasterDataset, GDALDataType gdal_datatype) +{ + int band_num = rasterDataset->GetRasterCount(); + if (gdal_datatype == 0) { + return Eigen::Matrix(0, 0); + } + else if (gdal_datatype < 8) { + if (band_num != 2) { + return Eigen::Matrix(0, 0); + } + } + else if (gdal_datatype < 12) { + if (band_num != 1) { + return Eigen::Matrix(0, 0); + } + + } + else { + } + bool _flag = false; + Eigen::Matrix data_mat( + line_num * width, 2); // ǿ + if (gdal_datatype == GDT_Byte) { + Eigen::MatrixX real_mat(line_num * width, 1); + Eigen::MatrixX imag_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag + data_mat.col(0) = (real_mat.array().cast()).array(); + data_mat.col(1) = (imag_mat.array().cast()).array(); + _flag = true; + } + else if (gdal_datatype == GDT_UInt16) { + Eigen::MatrixX real_mat(line_num * width, 1); + Eigen::MatrixX imag_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag + data_mat.col(0) = (real_mat.array().cast()).array(); + data_mat.col(1) = (imag_mat.array().cast()).array(); + _flag = true; + } + else if (gdal_datatype == GDT_Int16) { + Eigen::MatrixX real_mat(line_num * width, 1); + Eigen::MatrixX imag_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag + data_mat.col(0) = (real_mat.array().cast()).array(); + data_mat.col(1) = (imag_mat.array().cast()).array(); + _flag = true; + } + else if (gdal_datatype == GDT_UInt32) { + Eigen::MatrixX real_mat(line_num * width, 1); + Eigen::MatrixX imag_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag + data_mat.col(0) = (real_mat.array().cast()).array(); + data_mat.col(1) = (imag_mat.array().cast()).array(); + _flag = true; + } + else if (gdal_datatype == GDT_Int32) { + Eigen::MatrixX real_mat(line_num * width, 1); + Eigen::MatrixX imag_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag + data_mat.col(0) = (real_mat.array().cast()).array(); + data_mat.col(1) = (imag_mat.array().cast()).array(); + _flag = true; + } + // else if (gdal_datatype == GDT_UInt64) { + // Eigen::MatrixX real_mat(line_num * width, 1); + // Eigen::MatrixX imag_mat(line_num * width, 1); + // rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + //real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + // rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + //imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag data_mat.col(0) = + //(real_mat.array().cast()).array(); data_mat.col(1) = + //(imag_mat.array().cast()).array(); _flag = true; + // } + // else if (gdal_datatype == GDT_Int64) { + // Eigen::MatrixX real_mat(line_num * width, 1); + // Eigen::MatrixX imag_mat(line_num * width, 1); + // rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + //real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real + // rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + //imag_mat.data(), width, line_num, gdal_datatype, 0, 0); // imag data_mat.col(0) = + //(real_mat.array().cast()).array(); data_mat.col(1) = + //(imag_mat.array().cast()).array(); _flag = true; + // } + else if (gdal_datatype == GDT_Float32) { + Eigen::MatrixX real_mat(line_num * width, 1); + Eigen::MatrixX imag_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag + data_mat.col(0) = (real_mat.array().cast()).array(); + data_mat.col(1) = (imag_mat.array().cast()).array(); + _flag = true; + } + else if (gdal_datatype == GDT_Float64) { + Eigen::MatrixX real_mat(line_num * width, 1); + Eigen::MatrixX imag_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, gdal_datatype, + 0, 0); // real + rasterDataset->GetRasterBand(2)->RasterIO(GF_Read, 0, start_line, width, line_num, + imag_mat.data(), width, line_num, gdal_datatype, + 0, 0); // imag + data_mat.col(0) = (real_mat.array().cast()).array(); + data_mat.col(1) = (imag_mat.array().cast()).array(); + _flag = true; + } + else if (gdal_datatype == GDT_CInt16) { + Eigen::MatrixX> complex_short_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + complex_short_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real + data_mat.col(0) = (complex_short_mat.real().array().cast()).array(); + data_mat.col(1) = (complex_short_mat.imag().array().cast()).array(); + _flag = true; + } + else if (gdal_datatype == GDT_CInt32) { + Eigen::MatrixX> complex_short_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + complex_short_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real + data_mat.col(0) = (complex_short_mat.real().array().cast()).array(); + data_mat.col(1) = (complex_short_mat.imag().array().cast()).array(); + _flag = true; + } + else if (gdal_datatype == GDT_CFloat32) { + Eigen::MatrixX> complex_short_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + complex_short_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real + data_mat.col(0) = (complex_short_mat.real().array().cast()).array(); + data_mat.col(1) = (complex_short_mat.imag().array().cast()).array(); + _flag = true; + } + else if (gdal_datatype == GDT_CFloat64) { + Eigen::MatrixX> complex_short_mat(line_num * width, 1); + rasterDataset->GetRasterBand(1)->RasterIO(GF_Read, 0, start_line, width, line_num, + complex_short_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real + data_mat.col(0) = (complex_short_mat.real().array().cast()).array(); + data_mat.col(1) = (complex_short_mat.imag().array().cast()).array(); + _flag = true; + } + else { + } + // + + if (_flag) { + return data_mat; + } + else { + return Eigen::Matrix( + 0, 0); // ǿ; + } +} + +Eigen::Matrix +ReadMatrixDoubleData(int start_line, int width, int line_num, + std::shared_ptr rasterDataset, GDALDataType gdal_datatype, + int band_idx) +{ + // 飬ʹeigen о㣬ټ + bool _flag = false; + Eigen::Matrix data_mat( + line_num * width, 1); // ǿ + if (gdal_datatype == GDT_Byte) { + Eigen::MatrixX real_mat(line_num * width, 1); + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real + data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; + _flag = true; + } + else if (gdal_datatype == GDT_UInt16) { + Eigen::MatrixX real_mat(line_num * width, 1); + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real + data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; + _flag = true; + } + else if (gdal_datatype == GDT_Int16) { + Eigen::MatrixX real_mat(line_num * width, 1); + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real + data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; + _flag = true; + } + else if (gdal_datatype == GDT_UInt32) { + Eigen::MatrixX real_mat(line_num * width, 1); + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real + data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; + _flag = true; + } + else if (gdal_datatype == GDT_Int32) { + Eigen::MatrixX real_mat(line_num * width, 1); + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real + data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; + _flag = true; + } + // else if (gdal_datatype == GDT_UInt64) { + // Eigen::MatrixX real_mat(line_num * width, 1); + // rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + //real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real data_mat.col(0) = + //((real_mat.array().cast()).array().pow(2)).log10() * 10.0; _flag = true; + // } + // else if (gdal_datatype == GDT_Int64) { + // Eigen::MatrixX real_mat(line_num * width, 1); + // rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + //real_mat.data(), width, line_num, gdal_datatype, 0, 0); // real data_mat.col(0) = + //((real_mat.array().cast()).array().pow(2)).log10() * 10.0; _flag = true; + // } + else if (gdal_datatype == GDT_Float32) { + Eigen::MatrixX real_mat(line_num * width, 1); + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real + data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; + _flag = true; + } + else if (gdal_datatype == GDT_Float64) { + Eigen::MatrixX real_mat(line_num * width, 1); + rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, + real_mat.data(), width, line_num, + gdal_datatype, 0, 0); // real + data_mat.col(0) = ((real_mat.array().cast()).array().pow(2)).log10() * 10.0; + _flag = true; + } + else { + } + + return data_mat; +} + + +****/ diff --git a/BaseCommonLibrary/ShowProessAbstract.h b/BaseCommonLibrary/ShowProessAbstract.h new file mode 100644 index 0000000..957b9b0 --- /dev/null +++ b/BaseCommonLibrary/ShowProessAbstract.h @@ -0,0 +1,15 @@ + +#ifndef __SHOWPROCESSABSTRACT_H__ +#define __SHOWPROCESSABSTRACT_H__ +#include "BaseConstVariable.h" +#include + + +class BASECONSTVARIABLEAPI ShowProessAbstract { + +public: + virtual void showProcess(double precent, QString tip); + virtual void showToolInfo(QString tip); +}; + +#endif \ No newline at end of file From ad377e31655c64c76cffc30f61dbd6c9a500a946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 25 Mar 2025 17:36:07 +0800 Subject: [PATCH 41/94] =?UTF-8?q?1.=20=E8=A1=A5=E5=85=85=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E7=9A=84=E5=87=BD=E6=95=B0=E6=96=87=E4=BB=B6=202.=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E7=BC=96=E8=AF=91=E8=A7=A3=E5=86=B3=20=E5=81=87?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=99=A8=E9=94=99=E8=AF=AF=20=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/BaseCommonLibrary.vcxproj | 6 ++++++ .../BaseCommonLibrary.vcxproj.filters | 18 +++++++++++++++++ .../BaseTool/BaseConstVariable.h | 20 +++++++++---------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/BaseCommonLibrary/BaseCommonLibrary.vcxproj b/BaseCommonLibrary/BaseCommonLibrary.vcxproj index cf486a6..d7c78f9 100644 --- a/BaseCommonLibrary/BaseCommonLibrary.vcxproj +++ b/BaseCommonLibrary/BaseCommonLibrary.vcxproj @@ -270,11 +270,13 @@ + + @@ -285,16 +287,20 @@ + + + + diff --git a/BaseCommonLibrary/BaseCommonLibrary.vcxproj.filters b/BaseCommonLibrary/BaseCommonLibrary.vcxproj.filters index 9b1842a..74f915b 100644 --- a/BaseCommonLibrary/BaseCommonLibrary.vcxproj.filters +++ b/BaseCommonLibrary/BaseCommonLibrary.vcxproj.filters @@ -57,6 +57,12 @@ BaseTool + + BaseTool + + + BaseTool + @@ -104,6 +110,18 @@ BaseTool + + BaseTool + + + BaseTool + + + BaseTool + + + BaseTool + diff --git a/BaseCommonLibrary/BaseTool/BaseConstVariable.h b/BaseCommonLibrary/BaseTool/BaseConstVariable.h index ca0a981..f16210d 100644 --- a/BaseCommonLibrary/BaseTool/BaseConstVariable.h +++ b/BaseCommonLibrary/BaseTool/BaseConstVariable.h @@ -39,17 +39,17 @@ #include /** 打印时间 ***************************************************************/ -//inline char* get_cur_time() { -// static char s[20]; -// time_t t; -// struct tm* ltime; -// time(&t); -// ltime = localtime(&t); -// strftime(s, 20, "%Y-%m-%d %H:%M:%S", ltime); -// return s; -//} +inline char* get_cur_time() { + static char s[20]; + time_t t; + struct tm* ltime; + time(&t); + ltime = localtime(&t); + strftime(s, 20, "%Y-%m-%d %H:%M:%S", ltime); + return s; +} -//#define PRINT(fmt, ...) printf("%s " fmt, get_cur_time(), ##__VA_ARGS__); +#define PRINT(fmt, ...) printf("%s " fmt, get_cur_time(), ##__VA_ARGS__); From ab8ca4802fd90bd42b1a7d6b68078ab9ee2ccb82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 25 Mar 2025 23:54:47 +0800 Subject: [PATCH 42/94] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSAR/GPURFPC.cu | 30 ++++++++++++++----- .../SimulationSAR/RFPCProcessCls.cpp | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index 66787d9..d058274 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -484,12 +484,24 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( long long prfId = idx / SHAREMEMORY_FLOAT_HALF; long long posId = idx % SHAREMEMORY_FLOAT_HALF + startPosId; // ǰ̶߳ӦӰ + //if (prfId > 20000) { + // printf("prfid %d,PRFCount : %d\n", prfId, PRFCount); + //} + if (prfId < PRFCount && posId < pixelcount) { double RstX = antlist[prfId].Px - goallist[posId].Tx; // ʸ double RstY = antlist[prfId].Py - goallist[posId].Ty; double RstZ = antlist[prfId].Pz - goallist[posId].Tz; double RstR = sqrt(RstX * RstX + RstY * RstY + RstZ * RstZ); // ʸ + + //if (prfId > 20000) { + // printf("prfid %d,nearR R Rfar %e %e %e ant=[%e,%e,%e] dem_G=[%e,%e,%e]\n", prfId,NearR,RstR,FarR, + // antlist[prfId].Px , antlist[prfId].Py , antlist[prfId].Pz , + // goallist[posId].Tx, goallist[posId].Ty, goallist[posId].Tz + // ); + //} + if (RstRFarR) { d_temp_R[idx] = 0; d_temp_amps[idx] = 0; @@ -525,7 +537,9 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( d_temp_amps[idx] = temp_amp * isNan; d_temp_R[idx] = temp_R * isNan; - //printf("out R amp : %f %e %d %e\n", d_temp_R[idx], d_temp_amps[idx], isNan, sigma); + + + return; } } @@ -570,10 +584,11 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( __syncthreads(); // ȷдݶѾ - - if (fId < maxfreqnum && prfId < temp_PRF_Count) { + + + long echo_ID = prfId * maxfreqnum + fId; // ӦĻزλ float factorjTemp = RFPCPIDIVLIGHT * (f0 + fId * dfreq); cuComplex echo = make_cuComplex(0, 0); @@ -583,7 +598,7 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( for (long dataid = 0; dataid < SHAREMEMORY_FLOAT_HALF; dataid++) { temp_phi = s_R[dataid] * factorjTemp; - temp_amp = 1; s_amp[dataid]; + temp_amp = s_amp[dataid]; echo.x += (temp_amp * cosf(temp_phi)); echo.y += (temp_amp * sinf(temp_phi)); //if (dataid > 5000) { @@ -596,7 +611,7 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( } } - + echodata[echo_ID] = cuCaddf(echodata[echo_ID], echo); } @@ -695,7 +710,7 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) { size_t pixelcount = task.prfNum * task.freqNum; size_t grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; - printf("computer pixelcount goalnum gridsize blocksize %zu,%zu ,%zu,%d\n", pixelcount, task.targetnum, grid_size, BLOCK_SIZE); + printf("computer pixelcount goalnum gridsize blocksize prfnum %zu,%zu ,%zu,%d ,%d \n", pixelcount, task.targetnum, grid_size, BLOCK_SIZE,task.prfNum); double* d_R = (double*)mallocCUDADevice(task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(double), devid); double* d_amps = (double*)mallocCUDADevice(task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(double), devid); @@ -706,12 +721,13 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) long freqpoints = BLOCK_FREQNUM; printf("freqpoints:%d\n", freqpoints); + long prfcount = task.prfNum; long process = 0; for (long sTi = 0; sTi < task.targetnum; sTi = sTi + SHAREMEMORY_FLOAT_HALF) { cudaBlocknum = (task.prfNum * SHAREMEMORY_FLOAT_HALF + BLOCK_SIZE - 1) / BLOCK_SIZE; Kernel_Computer_R_amp_NoAntPattern << > >( task.antlist, - task.prfNum, + prfcount, task.goallist, task.targetnum, sTi, task.targetnum, diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index c63353c..36f190f 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1092,7 +1092,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si } task.antlist = (SateState*)mallocCUDADevice(prfcount * sizeof(SateState), devId); - HostToDevice(h_antlist.get(), task.antlist, sizeof(double) * prfcount); + HostToDevice(h_antlist.get(), task.antlist, sizeof(SateState) * prfcount); } From 3bf201b4ca0f5de4700a8db2e15fdc44611441c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Wed, 26 Mar 2025 00:27:22 +0800 Subject: [PATCH 43/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=A8=A1?= =?UTF-8?q?=E6=8B=9F=E5=A4=A9=E7=BA=BF=E6=96=B9=E5=90=91=E5=9B=BE=E8=A1=B0?= =?UTF-8?q?=E5=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSAR/GPURFPC.cu | 54 +++++++++++++------ .../SimulationSAR/GPURFPC.cuh | 7 ++- .../SimulationSAR/RFPCProcessCls.cpp | 21 +++++++- 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index d058274..0bdc36c 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -466,8 +466,15 @@ void CUDA_RFPC_MainProcess( + /* ˺ ****************************************************************************************************************************/ +__device__ double SincTarg(double x) { + return 1 - (pow(x, 2) / 6) + (pow(x, 4) / 120) - (pow(x, 6) / 5040); +} + + + __global__ void Kernel_Computer_R_amp_NoAntPattern( SateState* antlist, long PRFCount, @@ -478,6 +485,7 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( double Pt, double refPhaseRange, double NearR, double FarR, + double maxGain,double GainWeight, double* d_temp_R, double* d_temp_amps// ) { long long idx = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ @@ -489,18 +497,14 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( //} if (prfId < PRFCount && posId < pixelcount) { - double RstX = antlist[prfId].Px - goallist[posId].Tx; // ʸ - double RstY = antlist[prfId].Py - goallist[posId].Ty; - double RstZ = antlist[prfId].Pz - goallist[posId].Tz; - + SateState antp = antlist[prfId]; + GoalState gp = goallist[posId]; + double RstX = antp.Px - gp.Tx; // ʸ T->S + double RstY = antp.Py - gp.Ty; + double RstZ = antp.Pz - gp.Tz; double RstR = sqrt(RstX * RstX + RstY * RstY + RstZ * RstZ); // ʸ - //if (prfId > 20000) { - // printf("prfid %d,nearR R Rfar %e %e %e ant=[%e,%e,%e] dem_G=[%e,%e,%e]\n", prfId,NearR,RstR,FarR, - // antlist[prfId].Px , antlist[prfId].Py , antlist[prfId].Pz , - // goallist[posId].Tx, goallist[posId].Ty, goallist[posId].Tz - // ); - //} + if (RstRFarR) { d_temp_R[idx] = 0; @@ -508,9 +512,9 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( return; } else { - double slopeX = goallist[posId].TsX; - double slopeY = goallist[posId].TsY; - double slopeZ = goallist[posId].TsZ; + double slopeX = gp.TsX; + double slopeY = gp.TsY; + double slopeZ = gp.TsZ; double slopR = sqrtf(slopeX * slopeX + slopeY * slopeY + slopeZ * slopeZ); // if (abs(slopR - 0) > 1e-3) { @@ -524,7 +528,20 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( } else {} - double ampGain = 1; + + // б˥ + + double antDirectR = sqrt(antp.antDirectX * antp.antDirectX + + antp.antDirectY * antp.antDirectY + + antp.antDirectZ * antp.antDirectZ); + + double diectAngle = -1*(RstX*antp.antDirectX+ + RstY*antp.antDirectY+ + RstZ*antp.antDirectZ) / (antDirectR* RstR); + + diectAngle = acos(diectAngle);// + + double ampGain = 2*maxGain*SincTarg(GainWeight*diectAngle); ampGain = ampGain / (powf(4 * LAMP_CUDA_PI, 2) * powf(RstR, 4)); // ǿ double sigma = GPU_getSigma0dB(sigma0Params, localangle); sigma = powf(10.0, sigma / 10.0); @@ -549,6 +566,11 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( + + + + + __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( double* d_temp_R, double* d_temp_amps, long posNum, double f0, double dfreq, @@ -586,9 +608,6 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( if (fId < maxfreqnum && prfId < temp_PRF_Count) { - - - long echo_ID = prfId * maxfreqnum + fId; // ӦĻزλ float factorjTemp = RFPCPIDIVLIGHT * (f0 + fId * dfreq); cuComplex echo = make_cuComplex(0, 0); @@ -735,6 +754,7 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) task.Pt, task.Rref, task.Rnear, task.Rfar, + task.maxGain,task.GainWeight, d_R, d_amps// ); PrintLasterError("CUDA_Kernel_Computer_R_amp"); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh index 04d6de4..e4904fe 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh @@ -17,6 +17,10 @@ extern "C" struct SateState { double Px, Py, Pz, Vx, Vy, Vz; + //double antXaxisX, antXaxisY, antXaxisZ; + //double antYaxisX, antYaxisY, antYaxisZ; + //double antZaxisX, antZaxisY, antZaxisZ; + double antDirectX, antDirectY, antDirectZ; }; @@ -86,7 +90,8 @@ extern "C" struct RFPCTask GoalState* goallist = nullptr; cuComplex* d_echoData = nullptr; // ز CUDASigmaParam sigma0_cls; - + double maxGain=48; + double GainWeight=300; size_t targetnum; diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 36f190f..adcf889 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -929,8 +929,8 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { ErrorCode RFPCProcessCls::RFPCMainProcess_MultiGPU_NoAntPattern() { - int num_devices=1; - //cudaGetDeviceCount(&num_devices); + int num_devices=0; + cudaGetDeviceCount(&num_devices); PRINT("GPU Count : %d \n", num_devices); long prfcount = this->EchoSimulationData->getPluseCount(); @@ -1089,6 +1089,23 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si h_antlist.get()[i].Vx = antplise.get()[i + startprfid].Vx; h_antlist.get()[i].Vy = antplise.get()[i + startprfid].Vy; h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; + h_antlist.get()[i].antDirectX = antplise.get()[i + startprfid].AntDirectX; + h_antlist.get()[i].antDirectY = antplise.get()[i + startprfid].AntDirectY; + h_antlist.get()[i].antDirectZ = antplise.get()[i + startprfid].AntDirectZ; + h_antlist.get()[i].antXaxisX = antplise.get()[i + startprfid].x; + h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; + h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; + h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; + h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; + h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; + h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; + h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; + + + + + + } task.antlist = (SateState*)mallocCUDADevice(prfcount * sizeof(SateState), devId); From 25f2daee96cc12deaaccdb9da65053942bb10589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Wed, 26 Mar 2025 00:28:41 +0800 Subject: [PATCH 44/94] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=A9=E7=BA=BF?= =?UTF-8?q?=E6=96=B9=E5=90=91bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSAR/RFPCProcessCls.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index adcf889..445aaef 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1092,18 +1092,6 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si h_antlist.get()[i].antDirectX = antplise.get()[i + startprfid].AntDirectX; h_antlist.get()[i].antDirectY = antplise.get()[i + startprfid].AntDirectY; h_antlist.get()[i].antDirectZ = antplise.get()[i + startprfid].AntDirectZ; - h_antlist.get()[i].antXaxisX = antplise.get()[i + startprfid].x; - h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; - h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; - h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; - h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; - h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; - h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; - h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; - - - - } From 7cb06427b620c764099f92b218c53974107d7dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Wed, 26 Mar 2025 10:14:42 +0800 Subject: [PATCH 45/94] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E8=AF=AF?= =?UTF-8?q?=E5=B7=AE=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GPUBaseLib/GPUTool/GPUTool.cuh | 3 --- .../SimulationSAR/GPURFPC.cu | 13 ++++----- .../SimulationSAR/RFPCProcessCls.cpp | 10 ++++++- .../SimulationSAR/SigmaDatabase.cpp | 27 +++++++++++-------- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/GPUBaseLib/GPUTool/GPUTool.cuh b/GPUBaseLib/GPUTool/GPUTool.cuh index a1730d8..e9becf7 100644 --- a/GPUBaseLib/GPUTool/GPUTool.cuh +++ b/GPUBaseLib/GPUTool/GPUTool.cuh @@ -117,8 +117,5 @@ extern "C" GPUBASELIBAPI void shared_complexPtrToHostCuComplex(std::complex* dst, size_t len); - - - #endif #endif diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index 0bdc36c..b5c1ee5 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -468,13 +468,11 @@ void CUDA_RFPC_MainProcess( /* ˺ ****************************************************************************************************************************/ - -__device__ double SincTarg(double x) { - return 1 - (pow(x, 2) / 6) + (pow(x, 4) / 120) - (pow(x, 6) / 5040); +inline double SincTarg(double x) { + return 1 - (x * x / 6) + (x * x * x * x / 120) - (x * x * x * x * x * x / 5040); } - __global__ void Kernel_Computer_R_amp_NoAntPattern( SateState* antlist, long PRFCount, @@ -539,9 +537,12 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( RstY*antp.antDirectY+ RstZ*antp.antDirectZ) / (antDirectR* RstR); - diectAngle = acos(diectAngle);// + diectAngle = acosf(diectAngle);// + diectAngle = diectAngle * GainWeight; + double ampGain = 2 * maxGain * (1 - (diectAngle * diectAngle / 6) + + (diectAngle * diectAngle * diectAngle * diectAngle / 120) + - (diectAngle * diectAngle * diectAngle * diectAngle * diectAngle * diectAngle / 5040)); - double ampGain = 2*maxGain*SincTarg(GainWeight*diectAngle); ampGain = ampGain / (powf(4 * LAMP_CUDA_PI, 2) * powf(RstR, 4)); // ǿ double sigma = GPU_getSigma0dB(sigma0Params, localangle); sigma = powf(10.0, sigma / 10.0); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 445aaef..b3d17b8 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -978,6 +978,14 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si pair.second.p5, pair.second.p6 })); + printf("clsid:%d, params: %e,%e,%e,%e,%e,%e \n", pair.first, + pair.second.p1, + pair.second.p2, + pair.second.p3, + pair.second.p4, + pair.second.p5, + pair.second.p6 + ); } @@ -1152,7 +1160,7 @@ ErrorCode RFPCProcessCls::SaveBlockSimulationEchoArr(cuComplex* d_echoData,size_ qDebug() << "write echo :\t " << "prfcount:\t" << prfcount << " freqnum:\t" << freqNum; - testOutComplexDoubleArr(QString("testoutEcho.dat"),fileEchoArr.get(), prfcount_read, freqNum); + //testOutComplexDoubleArr(QString("testoutEcho.dat"),fileEchoArr.get(), prfcount_read, freqNum); this->EchoSimulationData->saveEchoArr(fileEchoArr, startprfid, prfcount_read); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp index 9d38d40..dbd5f65 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp @@ -78,18 +78,23 @@ SigmaDatabase::SigmaDatabase() //this->VH_sigmaParam.insert(std::pair(90, SigmaParam{ -26.8776515733889, 10.4251866500052, 8.43273666535992, 4.33165922141213, 8.68204389555939, - 2.51718779582920 })); //this->VV_sigmaParam.insert(std::pair(90, SigmaParam{ -20.1761798059391, 13.2752519275021, 2.74667225608397, 3.63052241744923, 8.99932188120922, 34.8246533269446 })); - this->HH_sigmaParam.insert(std::pair(10, SigmaParam{ 28.15,-39.73,0.0986,2.863,4.356,-6.279 })); - this->HH_sigmaParam.insert(std::pair(20, SigmaParam{ 36.13,-48.2,0.1299,-1.838,5.404,-4.015 })); - this->HH_sigmaParam.insert(std::pair(30, SigmaParam{ 183.5,-194.6,0.0167,2.952,-4.1,6.026 })); - this->HH_sigmaParam.insert(std::pair(40, SigmaParam{ 50.97,-62.9,0.0968,1.604,4.637,6.108 })); - this->HH_sigmaParam.insert(std::pair(50, SigmaParam{ -10.31,15.96,37.73,-4.584,4.997,-3.569 })); - this->HH_sigmaParam.insert(std::pair(60, SigmaParam{ -12.45,0.1561,-3.187,-2.482,8.244,0.3632 })); - this->HH_sigmaParam.insert(std::pair(80, SigmaParam{ -19.23,0.3623,-2.209,9.649,0.1292,-0.264 })); - this->HH_sigmaParam.insert(std::pair(100, SigmaParam{ 56.61,-62.29,0.01388,2.767,-3.943,5.995 })); - - - + //this->HH_sigmaParam.insert(std::pair(10, SigmaParam{ 28.15,-39.73,0.0986,2.863,4.356,-6.279 })); + //this->HH_sigmaParam.insert(std::pair(20, SigmaParam{ 36.13,-48.2,0.1299,-1.838,5.404,-4.015 })); + //this->HH_sigmaParam.insert(std::pair(30, SigmaParam{ 183.5,-194.6,0.0167,2.952,-4.1,6.026 })); + //this->HH_sigmaParam.insert(std::pair(40, SigmaParam{ 50.97,-62.9,0.0968,1.604,4.637,6.108 })); + //this->HH_sigmaParam.insert(std::pair(50, SigmaParam{ -10.31,15.96,37.73,-4.584,4.997,-3.569 })); + //this->HH_sigmaParam.insert(std::pair(60, SigmaParam{ -12.45,0.1561,-3.187,-2.482,8.244,0.3632 })); + //this->HH_sigmaParam.insert(std::pair(80, SigmaParam{ -19.23,0.3623,-2.209,9.649,0.1292,-0.264 })); + //this->HH_sigmaParam.insert(std::pair(100, SigmaParam{ 56.61,-62.29,0.01388,2.767,-3.943,5.995 })); + this->HH_sigmaParam.insert(std::pair(10, SigmaParam{ -3.296,-0.1284,2.792,-5.418,1.417,-0.7571 })); // DQ + this->HH_sigmaParam.insert(std::pair(20, SigmaParam{ -9.976,-0.00288,4.404,1.875,1.045,6.801 })); + this->HH_sigmaParam.insert(std::pair(30, SigmaParam{ 3.172,-3.725,1.066,-6.938,-1.397,0.1646 })); + this->HH_sigmaParam.insert(std::pair(40, SigmaParam{ 86.51,-93.16,0.0408,-0.4571,5.286,-0.07259 })); + this->HH_sigmaParam.insert(std::pair(50, SigmaParam{ 9.03,-18.38,0.1604,-2.208,-6.042,3.596 })); + this->HH_sigmaParam.insert(std::pair(60, SigmaParam{ 13.71,-24.14,0.1177,-2.107,6.382,-4.156 })); + this->HH_sigmaParam.insert(std::pair(80, SigmaParam{ 136.6,-0.009549,3.246,143.9,0.0496,2.978 })); + this->HH_sigmaParam.insert(std::pair(90, SigmaParam{ -8.716,-3.019,-0.9396,-0.977,-6.411,2.33 })); } SigmaDatabase::~SigmaDatabase() From 0e66711d3a6a7b58b088fef39207d6af2a35dddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Wed, 26 Mar 2025 10:54:47 +0800 Subject: [PATCH 46/94] =?UTF-8?q?=E7=BC=96=E8=AF=91=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=BA=A7=E5=88=AB=20=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/SimulationSARTool/SimulationSARTool.vcxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 1072389..1f5abbb 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -124,8 +124,8 @@ true stdcpp14 stdc11 - false - true + true + false true From 2309c750e7de1f38582dc889d6803024e65fdea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Wed, 26 Mar 2025 10:59:11 +0800 Subject: [PATCH 47/94] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSAR/QImageSARRFPC.ui | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui b/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui index e80d621..3d6693a 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui +++ b/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui @@ -38,7 +38,7 @@ - LT1B_Simulation + LT1B_DQ_165665_Simulation @@ -51,7 +51,7 @@ - D:/FZSimulation/LT1AB_FZ/Input01/tempEcho + D:/FZSimulation/LTDQ/Input/xml/xml/165665/echodata @@ -90,7 +90,7 @@ - D:/FZSimulation/LT1AB_FZ/Input01/LT1B_Simulation_Setting.xml + D:/FZSimulation/LTDQ/Input/xml/xml/165665/LT1_Simulation_Setting.xml @@ -103,7 +103,7 @@ - D:/FZSimulation/LT1AB_FZ/Input01/landacover_Resample.dat + D:/FZSimulation/LTDQ/Input/LandCover.dat @@ -142,7 +142,7 @@ - D:/FZSimulation/LT1AB_FZ/Input01/LT1B_GPSPoints.xml + D:/FZSimulation/LTDQ/Input/xml/xml/165665/LT1_Simulation_GPSNode.xml @@ -233,7 +233,7 @@ - D:/FZSimulation/LT1AB_FZ/Input01/ASTGTM2_N28E087_dem_XYZ.dat + D:/FZSimulation/LTDQ/Input/DEM_XYZ.dat @@ -350,7 +350,7 @@ - D:/FZSimulation/LT1AB_FZ/Input01/ASTGTM2_N28E087_dem_Sloper.dat + D:/FZSimulation/LTDQ/Input/DEM_Sloper.dat From 7f4a8de726612aecbdf9e54f522188c825cb1864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Fri, 28 Mar 2025 19:06:59 +0800 Subject: [PATCH 48/94] =?UTF-8?q?=E5=B9=85=E5=BA=A6=E6=9B=B4=E6=8D=A2?= =?UTF-8?q?=E4=B8=BAfloat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSAR/GPURFPC.cu | 37 ++++++++++++------- .../SimulationSAR/GPURFPC.cuh | 16 ++++---- .../SimulationSAR/RFPCProcessCls.cpp | 24 ++++++------ 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index b5c1ee5..14925c4 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -14,9 +14,13 @@ /* ****************************************************************************************************************************/ -extern __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; +__device__ double GPU_getSigma0dB(CUDASigmaParam param, double theta) +{ + return param.p1 + param.p2 * exp(-param.p3 * theta) + param.p4 * cos(param.p5 * theta + param.p6); +} + +extern __device__ float GPU_getSigma0dB(CUDASigmaParam param, float theta) {//ֵ + return param.p1 + param.p2 * expf(-param.p3 * theta) + param.p4 * cosf(param.p5 * theta + param.p6);; } @@ -510,14 +514,19 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( return; } else { + + RstX = RstX / RstR; + RstY = RstY / RstR; + RstZ = RstZ / RstR; + double slopeX = gp.TsX; double slopeY = gp.TsY; double slopeZ = gp.TsZ; double slopR = sqrtf(slopeX * slopeX + slopeY * slopeY + slopeZ * slopeZ); // if (abs(slopR - 0) > 1e-3) { - double dotAB = RstX * slopeX + RstY * slopeY + RstZ * slopeZ; - double localangle = acos(dotAB / (RstR * slopR)); + float dotAB = RstX * slopeX + RstY * slopeY + RstZ * slopeZ; + float localangle = acosf(dotAB / ( slopR)); if (localangle < 0 || localangle >= LAMP_CUDA_PI / 2 || isnan(localangle)) { d_temp_R[idx] = 0; @@ -529,19 +538,24 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( // б˥ - double antDirectR = sqrt(antp.antDirectX * antp.antDirectX + float antDirectR = sqrtf(antp.antDirectX * antp.antDirectX + antp.antDirectY * antp.antDirectY + antp.antDirectZ * antp.antDirectZ); - double diectAngle = -1*(RstX*antp.antDirectX+ + float diectAngle = -1*(RstX*antp.antDirectX+ RstY*antp.antDirectY+ - RstZ*antp.antDirectZ) / (antDirectR* RstR); + RstZ*antp.antDirectZ) / (antDirectR ); diectAngle = acosf(diectAngle);// + //if (diectAngle * r2d <3) { + // printf("idx: %d, antAngle : %e \n", prfId, diectAngle * r2d); + //} + diectAngle = diectAngle * GainWeight; - double ampGain = 2 * maxGain * (1 - (diectAngle * diectAngle / 6) + float ampGain = 2 * maxGain * (1 - (diectAngle * diectAngle / 6) + (diectAngle * diectAngle * diectAngle * diectAngle / 120) - - (diectAngle * diectAngle * diectAngle * diectAngle * diectAngle * diectAngle / 5040)); + - (diectAngle * diectAngle * diectAngle * diectAngle * diectAngle * diectAngle / 5040)); //dB + ampGain = powf(10.0, ampGain / 10.0); ampGain = ampGain / (powf(4 * LAMP_CUDA_PI, 2) * powf(RstR, 4)); // ǿ double sigma = GPU_getSigma0dB(sigma0Params, localangle); @@ -552,12 +566,9 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( bool isNan = !(isnan(temp_amp) || isnan(temp_R) || isinf(temp_amp) || isinf(temp_R)); - d_temp_amps[idx] = temp_amp * isNan; d_temp_R[idx] = temp_R * isNan; - - return; } } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh index e4904fe..394856b 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh @@ -33,12 +33,12 @@ extern "C" struct GoalState { extern "C" struct CUDASigmaParam { - double p1; - double p2; - double p3; - double p4; - double p5; - double p6; + float p1; + float p2; + float p3; + float p4; + float p5; + float p6; }; extern "C" struct SloperDs @@ -91,7 +91,7 @@ extern "C" struct RFPCTask cuComplex* d_echoData = nullptr; // ز CUDASigmaParam sigma0_cls; double maxGain=48; - double GainWeight=300; + double GainWeight=20; // 2ȷΧ size_t targetnum; @@ -103,6 +103,8 @@ extern __device__ double GPU_getSigma0dB_params( double theta); extern __device__ double GPU_getSigma0dB(CUDASigmaParam param, double theta); +extern __device__ float GPU_getSigma0dB(CUDASigmaParam param, float theta); + extern __device__ CUDAVectorEllipsoidal GPU_SatelliteAntDirectNormal( double RstX, double RstY, double RstZ, diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index b3d17b8..ea3377a 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -971,20 +971,20 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si for (const auto& pair : clssigmaParamsDict) { clsCUDASigmaParamsDict.insert(std::pair(pair.first, CUDASigmaParam{ - pair.second.p1, - pair.second.p2, - pair.second.p3, - pair.second.p4, - pair.second.p5, - pair.second.p6 + float(pair.second.p1), + float(pair.second.p2), + float(pair.second.p3), + float(pair.second.p4), + float(pair.second.p5), + float(pair.second.p6) })); printf("clsid:%d, params: %e,%e,%e,%e,%e,%e \n", pair.first, - pair.second.p1, - pair.second.p2, - pair.second.p3, - pair.second.p4, - pair.second.p5, - pair.second.p6 + float(pair.second.p1), + float(pair.second.p2), + float(pair.second.p3), + float(pair.second.p4), + float(pair.second.p5), + float(pair.second.p6) ); } From 1b373e6de1977fd89d59b24f2f67105bb55ad7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 30 Mar 2025 17:03:45 +0800 Subject: [PATCH 49/94] =?UTF-8?q?=E8=BF=9B=E4=B8=80=E6=AD=A5=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=80=A7=E8=83=BD=EF=BC=8C=E5=87=8F=E5=B0=91=E5=88=A4?= =?UTF-8?q?=E6=96=AD=EF=BC=8C=E5=87=8F=E5=B0=91=E8=AE=BF=E9=97=AE=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GPUBaseLib/GPUTool/GPUTool.cuh | 1 + .../SimulationSAR/GPURFPC.cu | 202 ++++++++---------- .../SimulationSAR/QImageSARRFPC.cpp | 10 +- 3 files changed, 96 insertions(+), 117 deletions(-) diff --git a/GPUBaseLib/GPUTool/GPUTool.cuh b/GPUBaseLib/GPUTool/GPUTool.cuh index e9becf7..6c513e3 100644 --- a/GPUBaseLib/GPUTool/GPUTool.cuh +++ b/GPUBaseLib/GPUTool/GPUTool.cuh @@ -14,6 +14,7 @@ #define CUDAMEMORY Memory1MB*100 #define LAMP_CUDA_PI 3.141592653589793238462643383279 +#define PI4POW2 157.91367041742973 // SHAREMEMORY_FLOAT_HALF_STEP * BLOCK_SIZE = SHAREMEMORY_FLOAT_HALF /** CUDA ò ************************************************************************************/ diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index 14925c4..c65a095 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -3,7 +3,7 @@ #include #include #include - +#include #include "BaseConstVariable.h" #include "GPURFPC.cuh" @@ -525,8 +525,8 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( double slopR = sqrtf(slopeX * slopeX + slopeY * slopeY + slopeZ * slopeZ); // if (abs(slopR - 0) > 1e-3) { - float dotAB = RstX * slopeX + RstY * slopeY + RstZ * slopeZ; - float localangle = acosf(dotAB / ( slopR)); + + float localangle = acosf((RstX * slopeX + RstY * slopeY + RstZ * slopeZ) / ( slopR)); if (localangle < 0 || localangle >= LAMP_CUDA_PI / 2 || isnan(localangle)) { d_temp_R[idx] = 0; @@ -547,17 +547,15 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( RstZ*antp.antDirectZ) / (antDirectR ); diectAngle = acosf(diectAngle);// - //if (diectAngle * r2d <3) { - // printf("idx: %d, antAngle : %e \n", prfId, diectAngle * r2d); - //} - diectAngle = diectAngle * GainWeight; - float ampGain = 2 * maxGain * (1 - (diectAngle * diectAngle / 6) - + (diectAngle * diectAngle * diectAngle * diectAngle / 120) - - (diectAngle * diectAngle * diectAngle * diectAngle * diectAngle * diectAngle / 5040)); //dB + + float ampGain = 1; + ampGain=2 * maxGain * (1 - (powf(diectAngle,2) / 6) + + (powf(diectAngle, 4) / 120) + - (powf(diectAngle, 6) / 5040)); //dB ampGain = powf(10.0, ampGain / 10.0); - ampGain = ampGain / (powf(4 * LAMP_CUDA_PI, 2) * powf(RstR, 4)); // ǿ + ampGain = ampGain / (PI4POW2 * powf(RstR, 4)); // ǿ double sigma = GPU_getSigma0dB(sigma0Params, localangle); sigma = powf(10.0, sigma / 10.0); @@ -576,13 +574,6 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( } - - - - - - - __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( double* d_temp_R, double* d_temp_amps, long posNum, double f0, double dfreq, @@ -623,6 +614,7 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( long echo_ID = prfId * maxfreqnum + fId; // ӦĻزλ float factorjTemp = RFPCPIDIVLIGHT * (f0 + fId * dfreq); cuComplex echo = make_cuComplex(0, 0); + float temp_phi = 0; float temp_amp = 0; @@ -635,11 +627,11 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( //if (dataid > 5000) { // printf("echo_ID=%d; dataid=%d;ehodata=(%f,%f);R=%f;amp=%f;\n", echo_ID, dataid, temp_real, temp_imag, s_R[0], s_amp[0]); //} - if (isnan(temp_phi) || isnan(temp_amp) || isnan(echo.x) || isnan(echo.y) - || isinf(temp_phi) || isinf(temp_amp) || isinf(echo.x) || isinf(echo.y) - ) { - printf("[amp,phi,real,imag]=[%f,%f,%f,%f];\n", temp_amp, temp_phi, echo.x, echo.y); - } + //if (isnan(temp_phi) || isnan(temp_amp) || isnan(echo.x) || isnan(echo.y) + // || isinf(temp_phi) || isinf(temp_amp) || isinf(echo.x) || isinf(echo.y) + // ) { + // printf("[amp,phi,real,imag]=[%f,%f,%f,%f];\n", temp_amp, temp_phi, echo.x, echo.y); + //} } @@ -651,98 +643,73 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( +__global__ void CUDA_Kernel_Computer_echo_NoAntPattern_Optimized( + double* d_temp_R, double* d_temp_amps, long posNum, + double f0, double dfreq, + long FreqPoints, // ǰƵʵķֿ + long maxfreqnum, // ֵ + cuComplex* echodata, + long temp_PRF_Count +) { + // ʹö̬ڴ棬߳̿С + extern __shared__ float s_data[]; + float* s_R = s_data; + float* s_amp = s_data + blockDim.x; + const int tid = threadIdx.x; + const int prfId = blockIdx.x; + const int fId = tid; // ÿ̴߳һƵʵ + float factorjTemp = RFPCPIDIVLIGHT * (f0 + fId * dfreq); + cuComplex echo = make_cuComplex(0.0f, 0.0f); + // ֿݲ + for (int block_offset = 0; block_offset < posNum; block_offset += blockDim.x) { + int psid = block_offset + tid; + int pixelId = prfId * posNum + psid; - - - - -__global__ void CUDA_Kernel_RFPC( - SateState* antlist, - long PRFCount, long Freqcount, // - GoalState* goallist, - long demLen, - double StartFreqGHz, double FreqStep, - double refPhaseRange, - double NearR, double FarR, - CUDASigmaParam clsSigma0, - cuComplex* echodata -) -{ - __shared__ GoalState Ts[SHAREMEMORY_DEM_STEP]; - - size_t threadid = threadIdx.x; - - size_t idx = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ - size_t prfid = floorf(idx / Freqcount); - size_t freqid = idx % Freqcount; - // printf("%d,%d ",prfid,freqid); - if (prfid < PRFCount && freqid < Freqcount) - { - SateState antPos = antlist[prfid]; - double factorjTemp = RFPCPIDIVLIGHT * (StartFreqGHz + freqid * FreqStep); - - double Tx = 0; - double Ty = 0; - double Tz = 0; - - double R = 0; - double incAngle = 0; - - double echo_real = 0; - double echo_imag = 0; - - cuComplex echo = make_cuComplex(0, 0); - - - - for (long tid = 0; tid < demLen; tid++) { - GoalState p = goallist[tid]; - Tx = p.Tx; - Ty = p.Ty; - Tz = p.Tz; - - Tx = antPos.Px - Tx; // T->P - Ty = antPos.Py - Ty; - Tz = antPos.Pz - Tz; - - R = sqrt(Tx * Tx + Ty * Ty + Tz * Tz); - bool isNearFar = (R < NearR || R > FarR) && ((abs(p.TsX) > 1000) || (abs(p.TsY) > 1000) || (abs(p.TsZ) > 1000)); - - - incAngle = sqrt(p.TsX * p.TsX + p.TsY * p.TsY + p.TsZ * p.TsZ); - incAngle = acos((Tx * p.TsX + Ty * p.TsY + Tz * p.TsZ) / (R * incAngle)); - incAngle = GPU_getSigma0dB_params(clsSigma0.p1, clsSigma0.p2, clsSigma0.p3, clsSigma0.p4, clsSigma0.p5, clsSigma0.p6, incAngle); // sigma - incAngle = pow(10.0, incAngle / 10.0); // amp - incAngle = incAngle / (powf(4 * LAMP_CUDA_PI, 2) * powf(R, 4)); // - - R = (R - refPhaseRange); - R = factorjTemp * R; - - echo_real = incAngle * cos(R) * isNearFar; - echo_imag = incAngle * sin(R) * isNearFar; - echo.x = echo.x + echo_real; - echo.y = echo.y + echo_imag; - - if (idx == 0 && tid % (10 * SHAREMEMORY_DEM_STEP) == 0) { - printf("Idx:%d , TsID: %d, TSCOUNT: %d \n", idx, tid, demLen); - } + // صǰ鵽ڴ + if (psid < posNum) { + s_R[tid] = static_cast(d_temp_R[pixelId]); + s_amp[tid] = static_cast(d_temp_amps[pixelId]); } + else { + s_R[tid] = 0.0f; + s_amp[tid] = 0.0f; + } + __syncthreads(); - echodata[idx] = cuCaddf(echodata[idx], echo); + // 㵱ǰĹ + for (int dataid = 0; dataid < blockDim.x; ++dataid) { + float temp_phi = s_R[dataid] * factorjTemp; + float temp_amp = s_amp[dataid]; + float sin_phi, cos_phi; + sincosf(temp_phi, &sin_phi, &cos_phi); + echo.x += temp_amp * cos_phi; + echo.y += temp_amp * sin_phi; + } + __syncthreads(); + } + + // ֻЧƵʵPRF + if (prfId < temp_PRF_Count && fId < FreqPoints && fId < maxfreqnum) { + const int echo_ID = prfId * maxfreqnum + fId; + atomicAdd(&echodata[echo_ID].x, echo.x); + atomicAdd(&echodata[echo_ID].y, echo.y); } } + + /** ֿ鴦 ****************************************************************************************************************/ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) { size_t pixelcount = task.prfNum * task.freqNum; size_t grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; printf("computer pixelcount goalnum gridsize blocksize prfnum %zu,%zu ,%zu,%d ,%d \n", pixelcount, task.targetnum, grid_size, BLOCK_SIZE,task.prfNum); - + printf("Dev:%d ,freqnum%d , prfnum:%d ,Rref: %e ,Rnear : %e ,Rfar: %e , StartFreq: %e ,DeletFreq: %e \n", + devid, task.freqNum, task.prfNum, task.Rref, task.Rnear, task.Rfar, task.startFreq, task.stepFreq); double* d_R = (double*)mallocCUDADevice(task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(double), devid); double* d_amps = (double*)mallocCUDADevice(task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(double), devid); @@ -772,23 +739,34 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) PrintLasterError("CUDA_Kernel_Computer_R_amp"); cudaDeviceSynchronize(); - cudaBlocknum = (task.prfNum * BLOCK_FREQNUM + BLOCK_SIZE - 1) / BLOCK_SIZE; - CUDA_Kernel_Computer_echo_NoAntPattern << > > ( - d_R, d_amps, SHAREMEMORY_FLOAT_HALF, - task.startFreq, task.stepFreq, - freqpoints, task.freqNum, - task.d_echoData, - task.prfNum - ); - PrintLasterError("CUDA_Kernel_Computer_echo"); + + dim3 blocks(task.prfNum); + dim3 threads(BLOCK_SIZE); + + size_t shared_mem_size = 2 * BLOCK_SIZE * sizeof(float); + + CUDA_Kernel_Computer_echo_NoAntPattern_Optimized << > > ( + d_R, d_amps, SHAREMEMORY_FLOAT_HALF, + task.startFreq/1e9, task.stepFreq / 1e9, + freqpoints, task.freqNum, + task.d_echoData, + task.prfNum + ); + + //cudaBlocknum = (task.prfNum * BLOCK_FREQNUM + BLOCK_SIZE - 1) / BLOCK_SIZE; + //CUDA_Kernel_Computer_echo_NoAntPattern << > > ( + // d_R, d_amps, SHAREMEMORY_FLOAT_HALF, + // task.startFreq/1e9, task.stepFreq / 1e9, + // freqpoints, task.freqNum, + // task.d_echoData, + // task.prfNum + // ); + //PrintLasterError("CUDA_Kernel_Computer_echo"); cudaDeviceSynchronize(); if ((sTi * 100.0 / task.targetnum) - process >= 1) { process = sTi * 100.0 / task.targetnum; PRINT("TargetID [%f]: %d / %d finished %d\n", sTi * 100.0 / task.targetnum, sTi, task.targetnum,devid); } - - - } @@ -798,7 +776,7 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) FreeCUDADevice(d_amps); } - + #endif diff --git a/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.cpp b/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.cpp index a1cc69f..813d506 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.cpp @@ -82,7 +82,7 @@ void QImageSARRFPC::onpushButtonEchoClieck() void QImageSARRFPC::onpushButtongpxmlClieck() { // ļѡԻѡһ .tif ļ - QString fileName = QFileDialog::getSaveFileName(this, + QString fileName = QFileDialog::getOpenFileName(this, u8"GPS xml", // Ի "", // ʼĿ¼Ϊ· u8"xml Files (*.xml);;All Files (*)"); // ļ͹ @@ -98,7 +98,7 @@ void QImageSARRFPC::onpushButtongpxmlClieck() void QImageSARRFPC::onpushButtonTaskxmlClieck() { // ļѡԻѡһ .tif ļ - QString fileName = QFileDialog::getSaveFileName(this, + QString fileName = QFileDialog::getOpenFileName(this, u8"xml", // Ի "", // ʼĿ¼Ϊ· u8"xml Files (*.xml);;All Files (*)"); // ļ͹ @@ -117,7 +117,7 @@ void QImageSARRFPC::onpushButtondemClieck() QString fileName = QFileDialog::getOpenFileName(this, u8"demļ", // Ի "", // ʼĿ¼Ϊ· - u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)"); // ļ͹ + u8"All Files (*);;tif Files (*.tif);;data Files (*.dat);;bin Files (*.bin)"); // ļ͹ if (!fileName.isEmpty()) { this->ui->demTiffPathEdit->setText(fileName); @@ -133,7 +133,7 @@ void QImageSARRFPC::onpushButtonSloperClieck() QString fileName = QFileDialog::getOpenFileName(this, u8"sloperļ", // Ի "", // ʼĿ¼Ϊ· - u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)"); // ļ͹ + u8"All Files (*);;tif Files (*.tif);;data Files (*.dat);;bin Files (*.bin)"); // ļ͹ if (!fileName.isEmpty()) { this->ui->sloperPathEdit->setText(fileName); @@ -149,7 +149,7 @@ void QImageSARRFPC::onpushButtonlandcoverClieck() QString fileName = QFileDialog::getOpenFileName(this, u8"ر", // Ի "", // ʼĿ¼Ϊ· - u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)"); // ļ͹ + u8"All Files (*);;tif Files (*.tif);;data Files (*.dat);;bin Files (*.bin)"); // ļ͹ if (!fileName.isEmpty()) { this->ui->landCoverPathEdit->setText(fileName); From 997471cba1272d3ef8e4d196eec55aa717e13c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 31 Mar 2025 02:14:22 +0800 Subject: [PATCH 50/94] =?UTF-8?q?=E8=B0=83=E8=AF=95=E5=9B=9E=E6=B3=A2?= =?UTF-8?q?=E4=BB=BF=E7=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/ImageOperatorFuntion.cpp | 2 +- .../SimulationSAR/BPBasic0_CUDA.cu | 4 +- .../SimulationSAR/GPURFPC.cu | 105 +---- .../SimulationSAR/GPURFPC.cuh | 2 +- .../SimulationSAR/RFPCProcessCls.cpp | 413 +++++++++--------- 5 files changed, 233 insertions(+), 293 deletions(-) diff --git a/BaseCommonLibrary/ImageOperatorFuntion.cpp b/BaseCommonLibrary/ImageOperatorFuntion.cpp index aa1c062..67c620a 100644 --- a/BaseCommonLibrary/ImageOperatorFuntion.cpp +++ b/BaseCommonLibrary/ImageOperatorFuntion.cpp @@ -1153,7 +1153,7 @@ int ResampleGDAL(const char* pszSrcFile, const char* pszOutFile, double* gt, int GDALWarpOptions* psWo = GDALCreateWarpOptions(); CPLSetConfigOption("GDAL_NUM_THREADS", "ALL_CPUS"); // ʹпõCPU - CPLSetConfigOption("GDAL_CACHEMAX", "16000"); // ûСΪ500MB + CPLSetConfigOption("GDAL_CACHEMAX", "4000"); // ûСΪ500MB // psWo->papszWarpOptions = CSLDuplicate(NULL); psWo->eWorkingDataType = dataType; psWo->eResampleAlg = eResample; diff --git a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu index cdf1705..718d73b 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu @@ -110,7 +110,7 @@ __global__ void processPulseKernel( im_final[idx].x += phCorr.x; im_final[idx].y += phCorr.y; //printf("r_start=%e;dr=%e;nR=%d\n", r_start, dr, nR); - if (abs(phCorr.x) > 1e-100 || abs(phCorr.y > 1e-100)) { + //if (abs(phCorr.x) > 1e-100 || abs(phCorr.y > 1e-100)) { //printf( // "[DEBUG] prfid=%-4ld | idx=%-8lld\n" // " Ant: X=%-18.10e Y=%-18.10e Z=%-18.10e\n" @@ -133,7 +133,7 @@ __global__ void processPulseKernel( // phCorr.x, phCorr.y, // im_final[idx].x, im_final[idx].y //); - } + //} } void bpBasic0CUDA(GPUDATA& data, int flag,double* h_R) { diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index c65a095..0f92e29 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -519,12 +519,12 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( RstY = RstY / RstR; RstZ = RstZ / RstR; - double slopeX = gp.TsX; - double slopeY = gp.TsY; - double slopeZ = gp.TsZ; + float slopeX = gp.TsX; + float slopeY = gp.TsY; + float slopeZ = gp.TsZ; - double slopR = sqrtf(slopeX * slopeX + slopeY * slopeY + slopeZ * slopeZ); // - if (abs(slopR - 0) > 1e-3) { + float slopR = sqrtf(slopeX * slopeX + slopeY * slopeY + slopeZ * slopeZ); // + if (slopR > 1e-3) { float localangle = acosf((RstX * slopeX + RstY * slopeY + RstZ * slopeZ) / ( slopR)); @@ -553,10 +553,11 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( ampGain=2 * maxGain * (1 - (powf(diectAngle,2) / 6) + (powf(diectAngle, 4) / 120) - (powf(diectAngle, 6) / 5040)); //dB + ampGain = powf(10.0, ampGain / 10.0); ampGain = ampGain / (PI4POW2 * powf(RstR, 4)); // ǿ - double sigma = GPU_getSigma0dB(sigma0Params, localangle); + float sigma = GPU_getSigma0dB(sigma0Params, localangle); sigma = powf(10.0, sigma / 10.0); double temp_amp = double(ampGain * Pt * sigma); @@ -573,76 +574,6 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( } } - -__global__ void CUDA_Kernel_Computer_echo_NoAntPattern( - double* d_temp_R, double* d_temp_amps, long posNum, - double f0, double dfreq, - long FreqPoints, // ǰƵʵķֿ - long maxfreqnum, // ֵ - cuComplex* echodata, - long temp_PRF_Count -) { - __shared__ float s_R[SHAREMEMORY_FLOAT_HALF]; // עһblock_size ͬڴ - __shared__ float s_amp[SHAREMEMORY_FLOAT_HALF]; - - long long tid = threadIdx.x; - long long bid = blockIdx.x; - long long idx = bid * blockDim.x + tid; - long long prfId = idx / FreqPoints; // ID - long long fId = idx % FreqPoints;//ƵID - - long long psid = 0; - long long pixelId = 0; - for (long ii = 0; ii < SHAREMEMORY_FLOAT_HALF_STEP; ii++) { // SHAREMEMORY_FLOAT_HALF_STEP * BLOCK_SIZE=SHAREMEMORY_FLOAT_HALF - psid = tid * SHAREMEMORY_FLOAT_HALF_STEP + ii; - pixelId = prfId * posNum + psid; // - if (psid < posNum) { - s_R[psid] = d_temp_R[pixelId]; - s_amp[psid] = d_temp_amps[pixelId]; - } - else { - s_R[psid] = 0; - s_amp[psid] = 0; - } - - } - - __syncthreads(); // ȷдݶѾ - - if (fId < maxfreqnum && prfId < temp_PRF_Count) { - - long echo_ID = prfId * maxfreqnum + fId; // ӦĻزλ - float factorjTemp = RFPCPIDIVLIGHT * (f0 + fId * dfreq); - cuComplex echo = make_cuComplex(0, 0); - - float temp_phi = 0; - float temp_amp = 0; - - for (long dataid = 0; dataid < SHAREMEMORY_FLOAT_HALF; dataid++) { - - temp_phi = s_R[dataid] * factorjTemp; - temp_amp = s_amp[dataid]; - echo.x += (temp_amp * cosf(temp_phi)); - echo.y += (temp_amp * sinf(temp_phi)); - //if (dataid > 5000) { - // printf("echo_ID=%d; dataid=%d;ehodata=(%f,%f);R=%f;amp=%f;\n", echo_ID, dataid, temp_real, temp_imag, s_R[0], s_amp[0]); - //} - //if (isnan(temp_phi) || isnan(temp_amp) || isnan(echo.x) || isnan(echo.y) - // || isinf(temp_phi) || isinf(temp_amp) || isinf(echo.x) || isinf(echo.y) - // ) { - // printf("[amp,phi,real,imag]=[%f,%f,%f,%f];\n", temp_amp, temp_phi, echo.x, echo.y); - //} - - } - - echodata[echo_ID] = cuCaddf(echodata[echo_ID], echo); - - } -} - - - - __global__ void CUDA_Kernel_Computer_echo_NoAntPattern_Optimized( double* d_temp_R, double* d_temp_amps, long posNum, double f0, double dfreq, @@ -652,15 +583,15 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern_Optimized( long temp_PRF_Count ) { // ʹö̬ڴ棬߳̿С - extern __shared__ float s_data[]; - float* s_R = s_data; - float* s_amp = s_data + blockDim.x; + extern __shared__ double s_data[]; + double* s_R = s_data; + double* s_amp = s_data + blockDim.x; const int tid = threadIdx.x; const int prfId = blockIdx.x; const int fId = tid; // ÿ̴߳һƵʵ - float factorjTemp = RFPCPIDIVLIGHT * (f0 + fId * dfreq); + double factorjTemp = RFPCPIDIVLIGHT * (f0 + fId * dfreq); cuComplex echo = make_cuComplex(0.0f, 0.0f); // ֿݲ @@ -670,8 +601,8 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern_Optimized( // صǰ鵽ڴ if (psid < posNum) { - s_R[tid] = static_cast(d_temp_R[pixelId]); - s_amp[tid] = static_cast(d_temp_amps[pixelId]); + s_R[tid] = static_cast(d_temp_R[pixelId]); + s_amp[tid] = static_cast(d_temp_amps[pixelId]); } else { s_R[tid] = 0.0f; @@ -681,7 +612,7 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern_Optimized( // 㵱ǰĹ for (int dataid = 0; dataid < blockDim.x; ++dataid) { - float temp_phi = s_R[dataid] * factorjTemp; + float temp_phi =fmod( s_R[dataid] * factorjTemp,2*PI); float temp_amp = s_amp[dataid]; float sin_phi, cos_phi; sincosf(temp_phi, &sin_phi, &cos_phi); @@ -743,7 +674,7 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) dim3 blocks(task.prfNum); dim3 threads(BLOCK_SIZE); - size_t shared_mem_size = 2 * BLOCK_SIZE * sizeof(float); + size_t shared_mem_size = 2 * BLOCK_SIZE * sizeof(double); CUDA_Kernel_Computer_echo_NoAntPattern_Optimized << > > ( d_R, d_amps, SHAREMEMORY_FLOAT_HALF, @@ -761,11 +692,11 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) // task.d_echoData, // task.prfNum // ); - //PrintLasterError("CUDA_Kernel_Computer_echo"); + PrintLasterError("CUDA_Kernel_Computer_echo"); cudaDeviceSynchronize(); - if ((sTi * 100.0 / task.targetnum) - process >= 1) { + if ((sTi * 100.0 / task.targetnum) - process >= 10) { process = sTi * 100.0 / task.targetnum; - PRINT("TargetID [%f]: %d / %d finished %d\n", sTi * 100.0 / task.targetnum, sTi, task.targetnum,devid); + PRINT("device ID : %d , TargetID [%f]: %d / %d finished %d\n",devid, sTi * 100.0 / task.targetnum, sTi, task.targetnum,devid); } } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh index 394856b..48ec1be 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh @@ -91,7 +91,7 @@ extern "C" struct RFPCTask cuComplex* d_echoData = nullptr; // ز CUDASigmaParam sigma0_cls; double maxGain=48; - double GainWeight=20; // 2ȷΧ + double GainWeight=10; // 2ȷΧ size_t targetnum; diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index ea3377a..43b9459 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -223,12 +223,12 @@ RFPCProcessCls::RFPCProcessCls() this->PlusePoint = 0; this->TaskSetting = nullptr; this->EchoSimulationData = nullptr; - this->LandCoverPath = ""; - this->OutEchoPath = ""; + this->LandCoverPath = ""; + this->OutEchoPath = ""; + - this->LandCoverPath.clear(); - this->OutEchoPath.clear(); + this->OutEchoPath.clear(); this->SigmaDatabasePtr = std::shared_ptr(new SigmaDatabase); } @@ -286,7 +286,7 @@ ErrorCode RFPCProcessCls::Process(long num_thread) return stateCode; } else {} - + qDebug() << "RFPCMainProcess"; //return ErrorCode::SUCCESS; stateCode = this->InitEchoMaskArray(); @@ -299,7 +299,7 @@ ErrorCode RFPCProcessCls::Process(long num_thread) //stateCode = this->RFPCMainProcess(num_thread); // 初始化回波 this->EchoSimulationData->initEchoArr(std::complex(0, 0)); - + //return ErrorCode::SUCCESS; @@ -339,7 +339,7 @@ ErrorCode RFPCProcessCls::InitParams() this->PlusePoint = freqnum;// ceil((this->TaskSetting->getFarRange() - this->TaskSetting->getNearRange()) / LIGHTSPEED * 2 * this->TaskSetting->getBandWidth()); - this->TaskSetting->setFarRange(this->TaskSetting->getNearRange() + (this->PlusePoint-1) * drange); + this->TaskSetting->setFarRange(this->TaskSetting->getNearRange() + (this->PlusePoint - 1) * drange); //ceil(rangeTimeSample * this->TaskSetting->getFs()); @@ -363,7 +363,7 @@ ErrorCode RFPCProcessCls::InitParams() this->tmpfolderPath = tmpfolderPath; return ErrorCode::SUCCESS; } - + ErrorCode RFPCProcessCls::InitEchoMaskArray() { QString name = this->EchoSimulationData->getSimulationTaskName(); @@ -454,9 +454,9 @@ std::shared_ptr RFPCProcessCls::getSatelliteOribtNodes(dou void RFPCProcessMain(long num_thread, - QString TansformPatternFilePath, QString ReceivePatternFilePath, - QString simulationtaskName, QString OutEchoPath, - QString GPSXmlPath, QString TaskXmlPath,QString demTiffPath, QString sloperPath, QString LandCoverPath) + QString TansformPatternFilePath, QString ReceivePatternFilePath, + QString simulationtaskName, QString OutEchoPath, + QString GPSXmlPath, QString TaskXmlPath, QString demTiffPath, QString sloperPath, QString LandCoverPath) { std::shared_ptr < AbstractSARSatelliteModel> task = ReadSimulationSettingsXML(TaskXmlPath); @@ -563,7 +563,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { double* h_TantPattern = nullptr; double* d_TantPattern = nullptr; double maxTransAntPatternValue = 0; - + { // 处理发射天线方向图 double Tminphi = TransformPattern->getMinPhi(); @@ -631,7 +631,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { h_RantPattern = (double*)mallocCUDAHost(sizeof(double) * Rthetanum * Rphinum); d_RantPattern = (double*)mallocCUDADevice(sizeof(double) * Rthetanum * Rphinum); - + for (long i = 0; i < Rthetanum; i++) { for (long j = 0; j < Rphinum; j++) { //h_RantPattern[i * Rphinum + j] = ReceivePattern->getGainLearThetaPhi(RstartTheta + i * Rdtheta, RstartPhi + j * Rdphi); @@ -666,8 +666,8 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { gdalImage demlandcls(this->LandCoverPath);// 地表覆盖类型 gdalImage demsloperxyz(this->demsloperPath);// 地面坡向 - long demRow = demxyz.height; - long demCol = demxyz.width; + long demRow = demxyz.height; + long demCol = demxyz.width; //处理地表覆盖 @@ -676,7 +676,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { long startline = 0; { - long blokline = getBlockRows(2e4, demCol, sizeof(double),demRow); + long blokline = getBlockRows(2e4, demCol, sizeof(double), demRow); for (startline = 0; startline < demRow; startline = startline + blokline) { Eigen::MatrixXd clsland = demlandcls.getData(startline, 0, blokline, demlandcls.width, 1); long clsrows = clsland.rows(); @@ -694,9 +694,9 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { } } - qDebug() << "class id recoding" ; + qDebug() << "class id recoding"; for (long id : clamap.keys()) { - qDebug() << id << " -> " << clamap[id] ; + qDebug() << id << " -> " << clamap[id]; } } @@ -716,15 +716,15 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { } // 打印日志 - qDebug() << "sigma params:" ; - qDebug() << "classid:\tp1\tp2\tp3\tp4\tp5\tp6" ; + qDebug() << "sigma params:"; + qDebug() << "classid:\tp1\tp2\tp3\tp4\tp5\tp6"; for (long ii = 0; ii < clamapid; ii++) { qDebug() << ii << ":\t" << h_clsSigmaParam[ii].p1; qDebug() << "\t" << h_clsSigmaParam[ii].p2; qDebug() << "\t" << h_clsSigmaParam[ii].p3; qDebug() << "\t" << h_clsSigmaParam[ii].p4; qDebug() << "\t" << h_clsSigmaParam[ii].p5; - qDebug() << "\t" << h_clsSigmaParam[ii].p6 ; + qDebug() << "\t" << h_clsSigmaParam[ii].p6; } qDebug() << ""; } @@ -733,39 +733,39 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { qDebug() << "CUDA class Proces finished!!!"; // 处理地面坐标 - long blockline = getBlockRows(TargetMemoryMB, demCol, sizeof(double), demRow); - - double* h_dem_x = (double*)mallocCUDAHost(sizeof(double) * blockline * demCol); - double* h_dem_y = (double*)mallocCUDAHost(sizeof(double) * blockline * demCol); - double* h_dem_z = (double*)mallocCUDAHost(sizeof(double) * blockline * demCol); - double* h_demsloper_x = (double*)mallocCUDAHost(sizeof(double) * blockline * demCol); - double* h_demsloper_y = (double*)mallocCUDAHost(sizeof(double) * blockline * demCol); - double* h_demsloper_z = (double*)mallocCUDAHost(sizeof(double) * blockline * demCol); - - long* h_demcls = (long*)mallocCUDAHost(sizeof(long) * blockline * demCol); + long blockline = getBlockRows(TargetMemoryMB, demCol, sizeof(double), demRow); + + double* h_dem_x = (double*)mallocCUDAHost(sizeof(double) * blockline * demCol); + double* h_dem_y = (double*)mallocCUDAHost(sizeof(double) * blockline * demCol); + double* h_dem_z = (double*)mallocCUDAHost(sizeof(double) * blockline * demCol); + double* h_demsloper_x = (double*)mallocCUDAHost(sizeof(double) * blockline * demCol); + double* h_demsloper_y = (double*)mallocCUDAHost(sizeof(double) * blockline * demCol); + double* h_demsloper_z = (double*)mallocCUDAHost(sizeof(double) * blockline * demCol); + + long* h_demcls = (long*)mallocCUDAHost(sizeof(long) * blockline * demCol); - double* d_dem_x = (double*)mallocCUDADevice(sizeof(double) * blockline * demCol); - double* d_dem_y = (double*)mallocCUDADevice(sizeof(double) * blockline * demCol); - double* d_dem_z = (double*)mallocCUDADevice(sizeof(double) * blockline * demCol); - double* d_demsloper_x = (double*)mallocCUDADevice(sizeof(double) * blockline * demCol); - double* d_demsloper_y = (double*)mallocCUDADevice(sizeof(double) * blockline * demCol); - double* d_demsloper_z = (double*)mallocCUDADevice(sizeof(double) * blockline * demCol); - - long* d_demcls = (long*) mallocCUDADevice(sizeof(long) * blockline * demCol); + double* d_dem_x = (double*)mallocCUDADevice(sizeof(double) * blockline * demCol); + double* d_dem_y = (double*)mallocCUDADevice(sizeof(double) * blockline * demCol); + double* d_dem_z = (double*)mallocCUDADevice(sizeof(double) * blockline * demCol); + double* d_demsloper_x = (double*)mallocCUDADevice(sizeof(double) * blockline * demCol); + double* d_demsloper_y = (double*)mallocCUDADevice(sizeof(double) * blockline * demCol); + double* d_demsloper_z = (double*)mallocCUDADevice(sizeof(double) * blockline * demCol); + + long* d_demcls = (long*)mallocCUDADevice(sizeof(long) * blockline * demCol); /** 处理回波***************************************************/ - long echo_block_rows = getBlockRows(1000, freqnum, sizeof(float)*2, PRFCount); - - float* h_echo_block_real = (float*)mallocCUDAHost(sizeof(float) * echo_block_rows * freqnum); + long echo_block_rows = getBlockRows(1000, freqnum, sizeof(float) * 2, PRFCount); + + float* h_echo_block_real = (float*)mallocCUDAHost(sizeof(float) * echo_block_rows * freqnum); float* h_echo_block_imag = (float*)mallocCUDAHost(sizeof(float) * echo_block_rows * freqnum); float* d_echo_block_real = (float*)mallocCUDADevice(sizeof(float) * echo_block_rows * freqnum); float* d_echo_block_imag = (float*)mallocCUDADevice(sizeof(float) * echo_block_rows * freqnum); - float* d_temp_R = (float*)mallocCUDADevice(sizeof(float) * echo_block_rows * SHAREMEMORY_FLOAT_HALF); //2GB 距离 + float* d_temp_R = (float*)mallocCUDADevice(sizeof(float) * echo_block_rows * SHAREMEMORY_FLOAT_HALF); //2GB 距离 float* d_temp_amp = (float*)mallocCUDADevice(sizeof(float) * echo_block_rows * SHAREMEMORY_FLOAT_HALF);//2GB 强度 @@ -783,16 +783,16 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { qDebug() << "freqnum: " << freqnum << " f0: " << f0 << " dfreq: " << dfreq << "freqnum_temp: " << freqnum_temp; qDebug() << "Start PRF: " << sprfid << "\t-\t" << sprfid + PRF_len << "\t:copy echo data list host -> GPU"; std::shared_ptr> echo_temp = this->EchoSimulationData->getEchoArr(sprfid, PRF_len); - + for (long ii = 0; ii < PRF_len; ii++) { for (long jj = 0; jj < freqnum; jj++) { - h_echo_block_real[ii * freqnum + jj]=echo_temp.get()[ii * freqnum + jj].real(); - h_echo_block_imag[ii * freqnum + jj]=echo_temp.get()[ii * freqnum + jj].imag(); + h_echo_block_real[ii * freqnum + jj] = echo_temp.get()[ii * freqnum + jj].real(); + h_echo_block_imag[ii * freqnum + jj] = echo_temp.get()[ii * freqnum + jj].imag(); } } - HostToDevice(h_echo_block_real, d_echo_block_real, sizeof(float) * PRF_len* freqnum); - HostToDevice(h_echo_block_imag, d_echo_block_imag, sizeof(float) * PRF_len* freqnum); + HostToDevice(h_echo_block_real, d_echo_block_real, sizeof(float) * PRF_len * freqnum); + HostToDevice(h_echo_block_imag, d_echo_block_imag, sizeof(float) * PRF_len * freqnum); for (startline = 0; startline < demRow; startline = startline + blockline) { @@ -804,12 +804,12 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { Eigen::MatrixXd demsloper_z = demsloperxyz.getData(startline, 0, blockline, demCol, 3); Eigen::MatrixXd landcover = demlandcls.getData(startline, 0, blockline, demCol, 1); - long temp_dem_row = dem_x.rows(); + long temp_dem_row = dem_x.rows(); long temp_dem_col = dem_x.cols(); long temp_dem_count = dem_x.count(); - + // 更新数据格式 for (long i = 0; i < temp_dem_row; i++) { for (long j = 0; j < temp_dem_col; j++) { @@ -819,32 +819,32 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { h_demsloper_x[i * temp_dem_col + j] = double(demsloper_x(i, j)); h_demsloper_y[i * temp_dem_col + j] = double(demsloper_y(i, j)); h_demsloper_z[i * temp_dem_col + j] = double(demsloper_z(i, j)); - + h_demcls[i * temp_dem_col + j] = clamap[long(landcover(i, j))]; } } - - qDebug() << "Start PRF: " << sprfid << "\t-\t" << sprfid + PRF_len << "\t:copy target data ("<< startline<<" - "<< startline + blockline << ") host -> GPU"; - HostToDevice(h_dem_x, d_dem_x , sizeof(double) * blockline * demCol); - HostToDevice(h_dem_y, d_dem_y , sizeof(double) * blockline * demCol); - HostToDevice(h_dem_z, d_dem_z , sizeof(double) * blockline * demCol); - HostToDevice(h_demsloper_x, d_demsloper_x , sizeof(double) * blockline * demCol); - HostToDevice(h_demsloper_y, d_demsloper_y , sizeof(double) * blockline * demCol); - HostToDevice(h_demsloper_z, d_demsloper_z , sizeof(double) * blockline * demCol); - HostToDevice(h_demcls, d_demcls ,sizeof(long)* blockline* demCol); + + qDebug() << "Start PRF: " << sprfid << "\t-\t" << sprfid + PRF_len << "\t:copy target data (" << startline << " - " << startline + blockline << ") host -> GPU"; + HostToDevice(h_dem_x, d_dem_x, sizeof(double) * blockline * demCol); + HostToDevice(h_dem_y, d_dem_y, sizeof(double) * blockline * demCol); + HostToDevice(h_dem_z, d_dem_z, sizeof(double) * blockline * demCol); + HostToDevice(h_demsloper_x, d_demsloper_x, sizeof(double) * blockline * demCol); + HostToDevice(h_demsloper_y, d_demsloper_y, sizeof(double) * blockline * demCol); + HostToDevice(h_demsloper_z, d_demsloper_z, sizeof(double) * blockline * demCol); + HostToDevice(h_demcls, d_demcls, sizeof(long) * blockline * demCol); // 分块处理 qDebug() << "Start PRF: " << sprfid << "\t-\t" << sprfid + PRF_len << "\t:GPU Computer target data (" << startline << "-" << startline + blockline << ")"; CUDA_RFPC_MainProcess( - antptrlist->d_antpx, antptrlist->d_antpy, antptrlist->d_antpz, - antptrlist->d_antXaxisX, antptrlist->d_antXaxisY, antptrlist->d_antXaxisZ, // 天线坐标系的X轴 - antptrlist->d_antYaxisX, antptrlist->d_antYaxisY, antptrlist->d_antYaxisZ,// 天线坐标系的Y轴 - antptrlist->d_antZaxisX, antptrlist->d_antZaxisY, antptrlist->d_antZaxisZ,// 天线坐标系的Z轴 - antptrlist->d_antdirectx, antptrlist->d_antdirecty, antptrlist->d_antdirectz,// 天线的指向 + antptrlist->d_antpx, antptrlist->d_antpy, antptrlist->d_antpz, + antptrlist->d_antXaxisX, antptrlist->d_antXaxisY, antptrlist->d_antXaxisZ, // 天线坐标系的X轴 + antptrlist->d_antYaxisX, antptrlist->d_antYaxisY, antptrlist->d_antYaxisZ,// 天线坐标系的Y轴 + antptrlist->d_antZaxisX, antptrlist->d_antZaxisY, antptrlist->d_antZaxisZ,// 天线坐标系的Z轴 + antptrlist->d_antdirectx, antptrlist->d_antdirecty, antptrlist->d_antdirectz,// 天线的指向 PRF_len, freqnum, - f0,dfreq, - Pt, + f0, dfreq, + Pt, refphaseRange, // 天线方向图 d_TantPattern, @@ -861,7 +861,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { d_temp_R, d_temp_amp ); - PRINT("dem : %d ~ %d / %d , echo: %d ~ %d / %d \n", startline, startline+ temp_dem_row, demRow, sprfid, sprfid+ PRF_len, PRFCount); + PRINT("dem : %d ~ %d / %d , echo: %d ~ %d / %d \n", startline, startline + temp_dem_row, demRow, sprfid, sprfid + PRF_len, PRFCount); } #if (defined __PRFDEBUG__) && (defined __PRFDEBUG_PRFINF__) @@ -888,7 +888,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { } this->EchoSimulationData->saveEchoArr(echo_temp, sprfid, PRF_len); - + } @@ -920,7 +920,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { FreeCUDADevice(d_demcls); FreeCUDADevice(d_echo_block_real); FreeCUDADevice(d_echo_block_imag); - + FreeCUDADevice(d_temp_R); FreeCUDADevice(d_temp_amp); @@ -929,19 +929,19 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { ErrorCode RFPCProcessCls::RFPCMainProcess_MultiGPU_NoAntPattern() { - int num_devices=0; + int num_devices = 0; cudaGetDeviceCount(&num_devices); PRINT("GPU Count : %d \n", num_devices); long prfcount = this->EchoSimulationData->getPluseCount(); - size_t prfblockcount = (prfcount + num_devices +2- 1) / num_devices; + size_t prfblockcount = (prfcount + num_devices + 2 - 1) / num_devices; PRINT("PRF COUNT : %d , child PRF COUNT: %d\n", prfcount, prfblockcount); double prf_time = 0; double dt = 1 / this->TaskSetting->getPRF();// 获取每次脉冲的时间间隔 bool antflag = true; // 计算天线方向图 long double imageStarttime = this->TaskSetting->getSARImageStartTime(); std::shared_ptr sateOirbtNodes = this->getSatelliteOribtNodes(prf_time, dt, antflag, imageStarttime); - + @@ -961,22 +961,22 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_MultiGPU_NoAntPattern() ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, size_t prfcount, int devId) { - PRINT("dev ID:%d,start PRF ID: %d , PRF COUNT: %d \n", devId,startprfid,prfcount); - + PRINT("dev ID:%d,start PRF ID: %d , PRF COUNT: %d \n", devId, startprfid, prfcount); + /// 显存不限制 cudaSetDevice(devId); // 确保当前线程操作指定的GPU设备 POLARTYPEENUM polartype = this->TaskSetting->getPolarType(); std::map clssigmaParamsDict = this->SigmaDatabasePtr->getsigmaParams(polartype);; std::map clsCUDASigmaParamsDict; for (const auto& pair : clssigmaParamsDict) { - clsCUDASigmaParamsDict.insert(std::pair(pair.first, - CUDASigmaParam{ + clsCUDASigmaParamsDict.insert(std::pair(pair.first, + CUDASigmaParam{ float(pair.second.p1), float(pair.second.p2), float(pair.second.p3), float(pair.second.p4), float(pair.second.p5), - float(pair.second.p6) + float(pair.second.p6) })); printf("clsid:%d, params: %e,%e,%e,%e,%e,%e \n", pair.first, float(pair.second.p1), @@ -993,147 +993,156 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si gdalImage demxyz(this->demxyzPath);// 地面点坐标 gdalImage demlandcls(this->LandCoverPath);// 地表覆盖类型 gdalImage slpxyz(this->demsloperPath);// 地面坡向 - // 处理地面坐标 - long demRow = demxyz.height; - long demCol = demxyz.width; - size_t demCount = size_t(demRow) * size_t(demCol); - std::shared_ptr demX = readDataArr(demxyz, 0, 0, demRow, demCol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - std::shared_ptr demY = readDataArr(demxyz, 0, 0, demRow, demCol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - std::shared_ptr demZ = readDataArr(demxyz, 0, 0, demRow, demCol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - std::shared_ptr slpX = readDataArr(slpxyz, 0, 0, demRow, demCol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - std::shared_ptr slpY = readDataArr(slpxyz, 0, 0, demRow, demCol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - std::shared_ptr slpZ = readDataArr(slpxyz, 0, 0, demRow, demCol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - std::shared_ptr clsArr = readDataArr(demlandcls, 0, 0, demRow, demCol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + long allDemRow = Memory1MB/demxyz.width/8/3*6000; + //allDemRow = allDemRow < demxyz.height ? allDemRow : demxyz.height; + for(long demId=0;demId< demxyz.height;demId=demId+ allDemRow){ + PRINT("dem cover processbar: [%f precent]\n", demId * 100.0 / demxyz.height); + long demRow = allDemRow; + demRow = demRow + demId < demxyz.height ? demRow : demxyz.height - demId; + long demCol = demxyz.width; + long long demCount = long long(demRow) * long long(demCol); - // 检索类别数量 - std::map clsCountDict; - for (const auto& pair : clssigmaParamsDict) { - clsCountDict.insert(std::pair(pair.first, 0)); - } + std::shared_ptr demX = readDataArr(demxyz, demId, 0, demRow, demCol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demY = readDataArr(demxyz, demId, 0, demRow, demCol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demZ = readDataArr(demxyz, demId, 0, demRow, demCol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr slpX = readDataArr(slpxyz, demId, 0, demRow, demCol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr slpY = readDataArr(slpxyz, demId, 0, demRow, demCol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr slpZ = readDataArr(slpxyz, demId, 0, demRow, demCol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr clsArr = readDataArr(demlandcls, demId, 0, demRow, demCol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + PRINT("demRow: %d , demCol:%d \n", demRow, demCol); - for (size_t i = 0; i < demCount; i++) { - long clsid = clsArr.get()[i]; - if (clsCountDict.find(clsid) != clsCountDict.end()) { - clsCountDict[clsid] = clsCountDict[clsid] + 1; - } - } - - std::map> clsGoalStateDict; - for (const auto& pair : clsCountDict) { - if (pair.second > 0) { - clsGoalStateDict.insert( - std::pair>( - pair.first, - std::shared_ptr((GoalState*)mallocCUDAHost(sizeof(GoalState) * pair.second), FreeCUDAHost))); - PRINT("clsid : %d ,Count: %d\n", pair.first, pair.second); - } - } - - // 分块处理大小 - size_t blocksize = 1000; - - std::map clsCountDictTemp; - for (const auto& pair : clsCountDict) { - clsCountDictTemp.insert(std::pair(pair.first, pair.second)); - } - - double sumdemx = 0; - for (long i = 0; i < demCount; i++) { - sumdemx= sumdemx+demX.get()[i]; - } - - - - for (long i = 0; i < demCount; i++) { - long clsid = clsArr.get()[i]; - size_t Currentclscount = clsCountDictTemp[clsid]; - size_t allclscount = clsCountDict[clsid]; - - if (clsGoalStateDict.find(clsid) == clsGoalStateDict.end()) { - continue; + // 检索类别数量 + std::map clsCountDict; + for (const auto& pair : clssigmaParamsDict) { + clsCountDict.insert(std::pair(pair.first, 0)); } - clsGoalStateDict[clsid].get()[Currentclscount - allclscount]; - + for (long long i = 0; i < demCount; i++) { + long clsid = clsArr.get()[i]; + if (clsCountDict.find(clsid) != clsCountDict.end()) { + clsCountDict[clsid] = clsCountDict[clsid] + 1; + } + } - clsGoalStateDict[clsid].get()[allclscount- Currentclscount].Tx = demX.get()[i]; - clsGoalStateDict[clsid].get()[allclscount - Currentclscount].Ty = demY.get()[i]; - clsGoalStateDict[clsid].get()[allclscount - Currentclscount].Tz = demZ.get()[i]; - clsGoalStateDict[clsid].get()[allclscount - Currentclscount].TsX = slpX.get()[i]; - clsGoalStateDict[clsid].get()[allclscount - Currentclscount].TsY = slpY.get()[i]; - clsGoalStateDict[clsid].get()[allclscount - Currentclscount].TsZ = slpZ.get()[i]; - clsGoalStateDict[clsid].get()[allclscount - Currentclscount].cls = clsArr.get()[i]; - clsCountDictTemp[clsid] = clsCountDictTemp[clsid] - 1; - } + std::map> clsGoalStateDict; + for (const auto& pair : clsCountDict) { + if (pair.second > 0) { + clsGoalStateDict.insert( + std::pair>( + pair.first, + std::shared_ptr((GoalState*)mallocCUDAHost(sizeof(GoalState) * pair.second), FreeCUDAHost))); + PRINT("clsid : %d ,Count: %d\n", pair.first, pair.second); + } + } + + // 分块处理大小 + size_t blocksize = 1000; + + std::map clsCountDictTemp; + for (const auto& pair : clsCountDict) { + clsCountDictTemp.insert(std::pair(pair.first, pair.second)); + } + + double sumdemx = 0; + for (long i = 0; i < demCount; i++) { + sumdemx = sumdemx + demX.get()[i]; + } - RFPCTask task; - // 参数声明 - task.freqNum = this->EchoSimulationData->getPlusePoints(); - task.prfNum = prfcount; - task.Rref = this->EchoSimulationData->getRefPhaseRange(); - task.Rnear = this->EchoSimulationData->getNearRange(); - task.Rfar = this->EchoSimulationData->getFarRange(); - task.Pt = this->TaskSetting->getPt(); - task.startFreq = this->EchoSimulationData->getCenterFreq() - this->EchoSimulationData->getBandwidth() / 2; - task.stepFreq = this->EchoSimulationData->getBandwidth() / (task.freqNum - 1); - task.d_echoData = (cuComplex*)mallocCUDADevice(prfcount * task.freqNum * sizeof(cuComplex), devId); + for (long i = 0; i < demCount; i++) { + long clsid = clsArr.get()[i]; + size_t Currentclscount = clsCountDictTemp[clsid]; + size_t allclscount = clsCountDict[clsid]; - PRINT("Dev:%d ,freqnum:%d , prfnum:%d ,Rref: %e ,Rnear : %e ,Rfar: %e , StartFreq: %e ,DeletFreq: %e \n", - devId,task.freqNum,task.prfNum,task.Rref,task.Rnear,task.Rfar,task.startFreq,task.stepFreq); + if (clsGoalStateDict.find(clsid) == clsGoalStateDict.end()) { + continue; + } - // 天线位置 - { - std::shared_ptr antplise = this->EchoSimulationData->getAntPosVelc(); - std::shared_ptr h_antlist((SateState*)mallocCUDAHost(prfcount * sizeof(SateState)), FreeCUDAHost); + clsGoalStateDict[clsid].get()[Currentclscount - allclscount]; - for (long i = 0; i < prfcount; i++) { - h_antlist.get()[i].Px = antplise.get()[i + startprfid].Px; - h_antlist.get()[i].Py = antplise.get()[i + startprfid].Py; - h_antlist.get()[i].Pz = antplise.get()[i + startprfid].Pz; - h_antlist.get()[i].Vx = antplise.get()[i + startprfid].Vx; - h_antlist.get()[i].Vy = antplise.get()[i + startprfid].Vy; - h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; - h_antlist.get()[i].antDirectX = antplise.get()[i + startprfid].AntDirectX; - h_antlist.get()[i].antDirectY = antplise.get()[i + startprfid].AntDirectY; - h_antlist.get()[i].antDirectZ = antplise.get()[i + startprfid].AntDirectZ; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].Tx = demX.get()[i]; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].Ty = demY.get()[i]; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].Tz = demZ.get()[i]; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].TsX = slpX.get()[i]; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].TsY = slpY.get()[i]; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].TsZ = slpZ.get()[i]; + clsGoalStateDict[clsid].get()[allclscount - Currentclscount].cls = clsArr.get()[i]; + clsCountDictTemp[clsid] = clsCountDictTemp[clsid] - 1; + } + + + + RFPCTask task; + // 参数声明 + task.freqNum = this->EchoSimulationData->getPlusePoints(); + task.prfNum = prfcount; + task.Rref = this->EchoSimulationData->getRefPhaseRange(); + task.Rnear = this->EchoSimulationData->getNearRange(); + task.Rfar = this->EchoSimulationData->getFarRange(); + task.Pt = this->TaskSetting->getPt(); + task.startFreq = this->EchoSimulationData->getCenterFreq() - this->EchoSimulationData->getBandwidth() / 2; + task.stepFreq = this->EchoSimulationData->getBandwidth() / (task.freqNum - 1); + task.d_echoData = (cuComplex*)mallocCUDADevice(prfcount * task.freqNum * sizeof(cuComplex), devId); + + PRINT("Dev:%d ,freqnum:%d , prfnum:%d ,Rref: %e ,Rnear : %e ,Rfar: %e , StartFreq: %e ,DeletFreq: %e \n", + devId, task.freqNum, task.prfNum, task.Rref, task.Rnear, task.Rfar, task.startFreq, task.stepFreq); + + // 天线位置 + { + std::shared_ptr antplise = this->EchoSimulationData->getAntPosVelc(); + std::shared_ptr h_antlist((SateState*)mallocCUDAHost(prfcount * sizeof(SateState)), FreeCUDAHost); + + for (long i = 0; i < prfcount; i++) { + h_antlist.get()[i].Px = antplise.get()[i + startprfid].Px; + h_antlist.get()[i].Py = antplise.get()[i + startprfid].Py; + h_antlist.get()[i].Pz = antplise.get()[i + startprfid].Pz; + h_antlist.get()[i].Vx = antplise.get()[i + startprfid].Vx; + h_antlist.get()[i].Vy = antplise.get()[i + startprfid].Vy; + h_antlist.get()[i].Vz = antplise.get()[i + startprfid].Vz; + h_antlist.get()[i].antDirectX = antplise.get()[i + startprfid].AntDirectX; + h_antlist.get()[i].antDirectY = antplise.get()[i + startprfid].AntDirectY; + h_antlist.get()[i].antDirectZ = antplise.get()[i + startprfid].AntDirectZ; + + + } + + task.antlist = (SateState*)mallocCUDADevice(prfcount * sizeof(SateState), devId); + HostToDevice(h_antlist.get(), task.antlist, sizeof(SateState) * prfcount); } - task.antlist = (SateState*)mallocCUDADevice(prfcount * sizeof(SateState), devId); - HostToDevice(h_antlist.get(), task.antlist, sizeof(SateState) * prfcount); + // 分块计算 + for (const auto& pair : clsGoalStateDict) { + long clsid = pair.first; + size_t clscount = clsCountDict[clsid]; + PRINT("Process Class ID : %d , Count: %d Device: %d\n", clsid, clscount,devId); + task.targetnum = clscount; + task.goallist = (GoalState*)mallocCUDADevice(clscount * sizeof(GoalState), devId); + HostToDevice(clsGoalStateDict[clsid].get(), task.goallist, sizeof(GoalState) * clscount); + task.sigma0_cls = clsCUDASigmaParamsDict[clsid]; + ProcessRFPCTask(task, devId); + FreeCUDADevice(task.goallist); + } + + + this->SaveBlockSimulationEchoArr(task.d_echoData, prfcount, task.freqNum, startprfid); + + + FreeCUDADevice(task.d_echoData); + FreeCUDADevice(task.antlist); + //FreeCUDADevice(task.goallist); + } - - // 分块计算 - for (const auto& pair : clsGoalStateDict) { - long clsid = pair.first; - size_t clscount = clsCountDict[clsid]; - PRINT("Process Class ID : %d , Count: %d\n", clsid, clscount); - task.targetnum = clscount; - task.goallist = (GoalState*)mallocCUDADevice(clscount * sizeof(GoalState), devId); - HostToDevice(clsGoalStateDict[clsid].get(), task.goallist, sizeof(GoalState) * clscount); - task.sigma0_cls = clsCUDASigmaParamsDict[clsid]; - ProcessRFPCTask(task,devId); - FreeCUDADevice(task.goallist); - } - - - this->SaveBlockSimulationEchoArr(task.d_echoData, prfcount, task.freqNum, startprfid); - - - FreeCUDADevice(task.d_echoData); - FreeCUDADevice(task.antlist); - //FreeCUDADevice(task.goallist); - + PRINT("dem cover processbar: [100 precent]\n"); return ErrorCode::SUCCESS; } -ErrorCode RFPCProcessCls::SaveBlockSimulationEchoArr(cuComplex* d_echoData,size_t prfcount,size_t freqNum,long startprfid) +ErrorCode RFPCProcessCls::SaveBlockSimulationEchoArr(cuComplex* d_echoData, size_t prfcount, size_t freqNum, long startprfid) { // 文件读写 @@ -1143,18 +1152,18 @@ ErrorCode RFPCProcessCls::SaveBlockSimulationEchoArr(cuComplex* d_echoData,size_ cuComplex* h_echoData = (cuComplex*)mallocCUDAHost(prfcount * freqNum * sizeof(cuComplex)); - DeviceToHost(h_echoData, d_echoData, prfcount * freqNum * sizeof(cuComplex)); + DeviceToHost(h_echoData, d_echoData, prfcount * freqNum * sizeof(cuComplex)); long prfcount_read = prfcount; std::shared_ptr> fileEchoArr = this->EchoSimulationData->getEchoArr(startprfid, prfcount_read); for (size_t i = 0; i < prfcount; i++) { - for (size_t j = 0; j < freqNum; j++) { + for (size_t j = 0; j < freqNum; j++) { std::complex temp = fileEchoArr.get()[i * freqNum + j]; fileEchoArr.get()[i * freqNum + j] = std::complex( - temp.real() + h_echoData[i * freqNum + j].x, - temp.imag() + h_echoData[i * freqNum + j].y - ); + temp.real() + h_echoData[i * freqNum + j].x, + temp.imag() + h_echoData[i * freqNum + j].y + ); } } From 947146320e68e89a6f643ad9bdbdb1a18d35027d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 31 Mar 2025 09:38:13 +0800 Subject: [PATCH 51/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 43b9459..65b8203 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1087,6 +1087,8 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si task.startFreq = this->EchoSimulationData->getCenterFreq() - this->EchoSimulationData->getBandwidth() / 2; task.stepFreq = this->EchoSimulationData->getBandwidth() / (task.freqNum - 1); task.d_echoData = (cuComplex*)mallocCUDADevice(prfcount * task.freqNum * sizeof(cuComplex), devId); + CUDA_MemsetBlock(task.d_echoData, make_cuComplex(0, 0), prfcount * task.freqNum); + PRINT("Dev:%d ,freqnum:%d , prfnum:%d ,Rref: %e ,Rnear : %e ,Rfar: %e , StartFreq: %e ,DeletFreq: %e \n", devId, task.freqNum, task.prfNum, task.Rref, task.Rnear, task.Rfar, task.startFreq, task.stepFreq); From bdaa4f22f77d9bce53c79abe13e0488c4bd95bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Wed, 2 Apr 2025 03:00:56 +0800 Subject: [PATCH 52/94] =?UTF-8?q?=E4=BF=9D=E7=95=99=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GPUBaseLib/GPUTool/GPUTool.cuh | 6 +- .../SimulationSAR/BPBasic0_CUDA.cu | 4 +- .../SimulationSAR/GPURFPC.cu | 204 ++++++++++-------- .../SimulationSAR/RFPCProcessCls.cpp | 6 +- .../SimulationSAR/SigmaDatabase.cpp | 21 +- .../SimulationSAR/TBPImageAlgCls.cpp | 1 + 6 files changed, 136 insertions(+), 106 deletions(-) diff --git a/GPUBaseLib/GPUTool/GPUTool.cuh b/GPUBaseLib/GPUTool/GPUTool.cuh index 6c513e3..b380dc5 100644 --- a/GPUBaseLib/GPUTool/GPUTool.cuh +++ b/GPUBaseLib/GPUTool/GPUTool.cuh @@ -20,13 +20,15 @@ /** CUDA ò ************************************************************************************/ #define BLOCK_SIZE 256 #define SHAREMEMORY_BYTE 49152 -#define SHAREMEMORY_FLOAT_HALF 6144 -#define SHAREMEMORY_FLOAT_HALF_STEP 24 +#define SHAREMEMORY_FLOAT_HALF_STEP 2 +#define SHAREMEMORY_FLOAT_HALF SHAREMEMORY_FLOAT_HALF_STEP*BLOCK_SIZE + #define SHAREMEMORY_DEM_STEP 768 #define SHAREMEMORY_Reflect 612 + enum LAMPGPUDATETYPE { LAMP_LONG, LAMP_FLOAT, diff --git a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu index 718d73b..cdf1705 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu @@ -110,7 +110,7 @@ __global__ void processPulseKernel( im_final[idx].x += phCorr.x; im_final[idx].y += phCorr.y; //printf("r_start=%e;dr=%e;nR=%d\n", r_start, dr, nR); - //if (abs(phCorr.x) > 1e-100 || abs(phCorr.y > 1e-100)) { + if (abs(phCorr.x) > 1e-100 || abs(phCorr.y > 1e-100)) { //printf( // "[DEBUG] prfid=%-4ld | idx=%-8lld\n" // " Ant: X=%-18.10e Y=%-18.10e Z=%-18.10e\n" @@ -133,7 +133,7 @@ __global__ void processPulseKernel( // phCorr.x, phCorr.y, // im_final[idx].x, im_final[idx].y //); - //} + } } void bpBasic0CUDA(GPUDATA& data, int flag,double* h_R) { diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index 0f92e29..049b07b 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -487,8 +487,8 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( double Pt, double refPhaseRange, double NearR, double FarR, - double maxGain,double GainWeight, - double* d_temp_R, double* d_temp_amps// + double maxGain, double GainWeight, + float* d_temp_R, float* d_temp_amps// ) { long long idx = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ long long prfId = idx / SHAREMEMORY_FLOAT_HALF; @@ -509,12 +509,23 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( if (RstRFarR) { + + if (prfId > 200) { + printf("error prfId:%d ,idx:%d RstR:%e antP=[%e,%e,%e] ,gp=[%e,%e,%e]\n", prfId, idx, RstR, + antp.Px, antp.Py, antp.Pz, gp.Tx, gp.Ty, gp.Tz + ); + } + d_temp_R[idx] = 0; d_temp_amps[idx] = 0; return; } else { - + if (prfId > 200) { + printf(" prfId:%d ,idx:%d RstR:%e antP=[%e,%e,%e] ,gp=[%e,%e,%e]\n", prfId, idx, RstR, + antp.Px, antp.Py, antp.Pz, gp.Tx, gp.Ty, gp.Tz + ); + } RstX = RstX / RstR; RstY = RstY / RstR; RstZ = RstZ / RstR; @@ -525,8 +536,8 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( float slopR = sqrtf(slopeX * slopeX + slopeY * slopeY + slopeZ * slopeZ); // if (slopR > 1e-3) { - - float localangle = acosf((RstX * slopeX + RstY * slopeY + RstZ * slopeZ) / ( slopR)); + float dotAB = RstX * slopeX + RstY * slopeY + RstZ * slopeZ; + float localangle = acosf(dotAB / (slopR)); if (localangle < 0 || localangle >= LAMP_CUDA_PI / 2 || isnan(localangle)) { d_temp_R[idx] = 0; @@ -542,91 +553,113 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( + antp.antDirectY * antp.antDirectY + antp.antDirectZ * antp.antDirectZ); - float diectAngle = -1*(RstX*antp.antDirectX+ - RstY*antp.antDirectY+ - RstZ*antp.antDirectZ) / (antDirectR ); + float diectAngle = -1 * (RstX * antp.antDirectX + + RstY * antp.antDirectY + + RstZ * antp.antDirectZ) / (antDirectR); diectAngle = acosf(diectAngle);// diectAngle = diectAngle * GainWeight; float ampGain = 1; - ampGain=2 * maxGain * (1 - (powf(diectAngle,2) / 6) + ampGain = 2 * maxGain * (1 - (powf(diectAngle, 2) / 6) + (powf(diectAngle, 4) / 120) - (powf(diectAngle, 6) / 5040)); //dB - + ampGain = powf(10.0, ampGain / 10.0); ampGain = ampGain / (PI4POW2 * powf(RstR, 4)); // ǿ float sigma = GPU_getSigma0dB(sigma0Params, localangle); sigma = powf(10.0, sigma / 10.0); - double temp_amp = double(ampGain * Pt * sigma); - double temp_R = double(RstR - refPhaseRange); + float temp_amp = float(ampGain * Pt * sigma); + float temp_R = float(double(RstR - refPhaseRange)); - bool isNan = !(isnan(temp_amp) || isnan(temp_R) || isinf(temp_amp) || isinf(temp_R)); + if (isnan(temp_amp) || isnan(temp_R) || isinf(temp_amp) || isinf(temp_R)) { + printf("amp is nan or R is nan,amp=%f;R=%f; \n", temp_amp, temp_R); + d_temp_R[idx] = 0; + d_temp_amps[idx] = 0; + return; + } + else { - d_temp_amps[idx] = temp_amp * isNan; - d_temp_R[idx] = temp_R * isNan; + d_temp_amps[idx] = temp_amp ; + d_temp_R[idx] = temp_R; - return; + return; + } } } } + else { + d_temp_R[idx] = 0; + d_temp_amps[idx] = 0; + return; + } + } -__global__ void CUDA_Kernel_Computer_echo_NoAntPattern_Optimized( - double* d_temp_R, double* d_temp_amps, long posNum, +__global__ void CUDA_Kernel_Computer_echo_NoAntPattern( + float* d_temp_R, float* d_temp_amps, double f0, double dfreq, - long FreqPoints, // ǰƵʵķֿ - long maxfreqnum, // ֵ + long maxfreqnum, long nextfreqNum,// ֵ cuComplex* echodata, long temp_PRF_Count ) { - // ʹö̬ڴ棬߳̿С - extern __shared__ double s_data[]; - double* s_R = s_data; - double* s_amp = s_data + blockDim.x; + __shared__ float s_R[SHAREMEMORY_FLOAT_HALF]; // עһblock_size ͬڴ + __shared__ float s_amp[SHAREMEMORY_FLOAT_HALF]; - const int tid = threadIdx.x; - const int prfId = blockIdx.x; - const int fId = tid; // ÿ̴߳һƵʵ + long long tid = threadIdx.x; + long long bid = blockIdx.x; + long long idx = bid * blockDim.x + tid; + long long prfId = idx / nextfreqNum; // ID + long long fId = idx % nextfreqNum;//ƵID - double factorjTemp = RFPCPIDIVLIGHT * (f0 + fId * dfreq); - cuComplex echo = make_cuComplex(0.0f, 0.0f); - - // ֿݲ - for (int block_offset = 0; block_offset < posNum; block_offset += blockDim.x) { - int psid = block_offset + tid; - int pixelId = prfId * posNum + psid; - - // صǰ鵽ڴ - if (psid < posNum) { - s_R[tid] = static_cast(d_temp_R[pixelId]); - s_amp[tid] = static_cast(d_temp_amps[pixelId]); + long long psid = 0; + long long pixelId = 0; + for (long ii = 0; ii < SHAREMEMORY_FLOAT_HALF_STEP; ii++) { // SHAREMEMORY_FLOAT_HALF_STEP * BLOCK_SIZE=SHAREMEMORY_FLOAT_HALF + psid = ii * BLOCK_SIZE + tid; + pixelId = prfId * SHAREMEMORY_FLOAT_HALF + psid; + s_R[psid] = d_temp_R[pixelId]; + s_amp[psid] = d_temp_amps[pixelId]; + if (prfId > 200) { + printf("prfId:%d ,idx:%d s_R:%f S_amp:%f \n", prfId, idx, s_R[psid], s_amp[psid]); } - else { - s_R[tid] = 0.0f; - s_amp[tid] = 0.0f; - } - __syncthreads(); - - // 㵱ǰĹ - for (int dataid = 0; dataid < blockDim.x; ++dataid) { - float temp_phi =fmod( s_R[dataid] * factorjTemp,2*PI); - float temp_amp = s_amp[dataid]; - float sin_phi, cos_phi; - sincosf(temp_phi, &sin_phi, &cos_phi); - echo.x += temp_amp * cos_phi; - echo.y += temp_amp * sin_phi; - } - __syncthreads(); } - // ֻЧƵʵPRF - if (prfId < temp_PRF_Count && fId < FreqPoints && fId < maxfreqnum) { - const int echo_ID = prfId * maxfreqnum + fId; - atomicAdd(&echodata[echo_ID].x, echo.x); - atomicAdd(&echodata[echo_ID].y, echo.y); + __syncthreads(); // ȷдݶѾ + + + + + if (fId < maxfreqnum && prfId < temp_PRF_Count) { + + long echo_ID = prfId * maxfreqnum + fId; // ӦĻزλ + double factorjTemp = RFPCPIDIVLIGHT * (f0 + fId * dfreq); + cuComplex echo = make_cuComplex(0, 0); + + for (long dataid = 0; dataid < SHAREMEMORY_FLOAT_HALF; dataid++) { + + float temp_real = 0; + float temp_imag = 0; + double R = s_R[dataid]; + float temp_phi = fmod(R * factorjTemp, 2 * PI); + float temp_amp = s_amp[dataid]; + sincosf(temp_phi, &temp_imag, &temp_real); + echo.x = echo.x + (temp_amp * temp_real); + echo.y = echo.y + (temp_amp * temp_imag); + //if (dataid > 5000) { + // printf("echo_ID=%d; dataid=%d;ehodata=(%f,%f);R=%f;amp=%f;\n", echo_ID, dataid, temp_real, temp_imag, s_R[0], s_amp[0]); + //} + if (isnan(temp_phi) || isnan(temp_amp) || isnan(echo.x) || isnan(echo.y) + || isinf(temp_phi) || isinf(temp_amp) || isinf(echo.x) || isinf(echo.y) + ) { + printf("[amp,phi,real,imag]=[%f,%f,%f,%f];\n", temp_amp, temp_phi, echo.x, echo.y); + } + + } + + echodata[echo_ID] = cuCaddf(echodata[echo_ID], echo); + } } @@ -638,23 +671,23 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) { size_t pixelcount = task.prfNum * task.freqNum; size_t grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; - printf("computer pixelcount goalnum gridsize blocksize prfnum %zu,%zu ,%zu,%d ,%d \n", pixelcount, task.targetnum, grid_size, BLOCK_SIZE,task.prfNum); + printf("computer pixelcount goalnum gridsize blocksize prfnum %zu,%zu ,%zu,%d ,%d \n", pixelcount, task.targetnum, grid_size, BLOCK_SIZE, task.prfNum); printf("Dev:%d ,freqnum%d , prfnum:%d ,Rref: %e ,Rnear : %e ,Rfar: %e , StartFreq: %e ,DeletFreq: %e \n", devid, task.freqNum, task.prfNum, task.Rref, task.Rnear, task.Rfar, task.startFreq, task.stepFreq); - double* d_R = (double*)mallocCUDADevice(task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(double), devid); - double* d_amps = (double*)mallocCUDADevice(task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(double), devid); + float* d_R = (float*)mallocCUDADevice(task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(float), devid); + float* d_amps = (float*)mallocCUDADevice(task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(float), devid); long BLOCK_FREQNUM = NextBlockPad(task.freqNum, BLOCK_SIZE); // 256*freqBlockID long cudaBlocknum = 0; - long freqpoints = BLOCK_FREQNUM; - - printf("freqpoints:%d\n", freqpoints); + long freqpoints = BLOCK_SIZE; + + printf("freqpoints:%d\n", task.freqNum); long prfcount = task.prfNum; long process = 0; for (long sTi = 0; sTi < task.targetnum; sTi = sTi + SHAREMEMORY_FLOAT_HALF) { cudaBlocknum = (task.prfNum * SHAREMEMORY_FLOAT_HALF + BLOCK_SIZE - 1) / BLOCK_SIZE; - Kernel_Computer_R_amp_NoAntPattern << > >( + Kernel_Computer_R_amp_NoAntPattern << > > ( task.antlist, prfcount, task.goallist, @@ -664,39 +697,26 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) task.Pt, task.Rref, task.Rnear, task.Rfar, - task.maxGain,task.GainWeight, + task.maxGain, task.GainWeight, d_R, d_amps// - ); + ); PrintLasterError("CUDA_Kernel_Computer_R_amp"); cudaDeviceSynchronize(); - dim3 blocks(task.prfNum); - dim3 threads(BLOCK_SIZE); - - size_t shared_mem_size = 2 * BLOCK_SIZE * sizeof(double); - - CUDA_Kernel_Computer_echo_NoAntPattern_Optimized << > > ( - d_R, d_amps, SHAREMEMORY_FLOAT_HALF, - task.startFreq/1e9, task.stepFreq / 1e9, - freqpoints, task.freqNum, - task.d_echoData, - task.prfNum - ); - - //cudaBlocknum = (task.prfNum * BLOCK_FREQNUM + BLOCK_SIZE - 1) / BLOCK_SIZE; - //CUDA_Kernel_Computer_echo_NoAntPattern << > > ( - // d_R, d_amps, SHAREMEMORY_FLOAT_HALF, - // task.startFreq/1e9, task.stepFreq / 1e9, - // freqpoints, task.freqNum, - // task.d_echoData, - // task.prfNum - // ); + cudaBlocknum = (task.prfNum * BLOCK_FREQNUM + BLOCK_SIZE- 1) / BLOCK_SIZE; + CUDA_Kernel_Computer_echo_NoAntPattern << > > ( + d_R, d_amps, + task.startFreq / 1e9, task.stepFreq / 1e9, + task.freqNum, BLOCK_FREQNUM, + task.d_echoData, + task.prfNum + ); PrintLasterError("CUDA_Kernel_Computer_echo"); cudaDeviceSynchronize(); if ((sTi * 100.0 / task.targetnum) - process >= 10) { process = sTi * 100.0 / task.targetnum; - PRINT("device ID : %d , TargetID [%f]: %d / %d finished %d\n",devid, sTi * 100.0 / task.targetnum, sTi, task.targetnum,devid); + PRINT("device ID : %d , TargetID [%f]: %d / %d finished %d\n", devid, sTi * 100.0 / task.targetnum, sTi, task.targetnum, devid); } } @@ -707,7 +727,7 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) FreeCUDADevice(d_amps); } - + #endif diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 65b8203..e704c0f 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1120,12 +1120,14 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si // 分块计算 for (const auto& pair : clsGoalStateDict) { long clsid = pair.first; + task.sigma0_cls = clsCUDASigmaParamsDict[clsid]; size_t clscount = clsCountDict[clsid]; - PRINT("Process Class ID : %d , Count: %d Device: %d\n", clsid, clscount,devId); + PRINT("Process Class ID : %d , Count: %d Device: %d , sigma Prams :[%f,%f,%f,%f,%f,%F]\n", clsid, clscount,devId, + task.sigma0_cls.p1, task.sigma0_cls.p2, task.sigma0_cls.p3, task.sigma0_cls.p4, task.sigma0_cls.p5, task.sigma0_cls.p6); task.targetnum = clscount; task.goallist = (GoalState*)mallocCUDADevice(clscount * sizeof(GoalState), devId); HostToDevice(clsGoalStateDict[clsid].get(), task.goallist, sizeof(GoalState) * clscount); - task.sigma0_cls = clsCUDASigmaParamsDict[clsid]; + ProcessRFPCTask(task, devId); FreeCUDADevice(task.goallist); } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp index dbd5f65..1ac11b5 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp @@ -30,50 +30,55 @@ SigmaDatabase::SigmaDatabase() this->VH_sigmaParam.insert(std::pair(0, SigmaParam{ 0,0,0, 0, 0,0 })); this->VV_sigmaParam.insert(std::pair(0, SigmaParam{ 0,0,0, 0, 0,0 })); + this->HH_sigmaParam.insert(std::pair(10, SigmaParam{ -21.1019701821713, 9.00621457243906, 6.52932182540331, -1.11157376729893, -15.8022895411007, 11.4690828129602 })); + this->HH_sigmaParam.insert(std::pair(20, SigmaParam{ -43.6677042155964, 32.0245140457417, 0.511060658303930, -2.68482232690106, 6.29783274559538, 1.96648609622833 })); + this->HH_sigmaParam.insert(std::pair(40, SigmaParam{ 50.97, -62.9, -0.0968, 1.604, -4.637, 6.108 })); + this->HH_sigmaParam.insert(std::pair(60, SigmaParam{ -12.45,23.3097,3.187,-2.482,8.244,0.3632 })); + ////12 - //this->HH_sigmaParam.insert(std::pair(12, SigmaParam{ -21.1019701821713, 9.00621457243906, 6.52932182540331, - 1.11157376729893, - 15.8022895411007, 11.4690828129602 })); + this->HH_sigmaParam.insert(std::pair(12, SigmaParam{ -21.1019701821713, 9.00621457243906, 6.52932182540331, - 1.11157376729893, - 15.8022895411007, 11.4690828129602 })); //this->HV_sigmaParam.insert(std::pair(12, SigmaParam{ -30.0103645753547, 27.1700862271921, 11.8007376386356, - 0.933835390422269, - 16.4640776105300, 11.8318838032267 })); //this->VH_sigmaParam.insert(std::pair(12, SigmaParam{ -30.0103645753547, 27.1700862271921, 11.8007376386356, -0.933835390422269, -16.4640776105300, 11.8318838032267 })); //this->VV_sigmaParam.insert(std::pair(12, SigmaParam{ -21.1019701821713, 9.00621457243906, 6.52932182540331, -1.11157376729893, -15.8022895411007, 11.4690828129602 })); ////22 - //this->HH_sigmaParam.insert(std::pair(22, SigmaParam{ -43.6677042155964, 32.0245140457417, 0.511060658303930, - 2.68482232690106, 6.29783274559538, 1.96648609622833 })); + this->HH_sigmaParam.insert(std::pair(22, SigmaParam{ -43.6677042155964, 32.0245140457417, 0.511060658303930, - 2.68482232690106, 6.29783274559538, 1.96648609622833 })); //this->HV_sigmaParam.insert(std::pair(22, SigmaParam{ -36.3971634075803, 13.1296247093899, 1.12707368693158, - 1.88195857790977, 6.57450737122974, 2.11755051297951 })); //this->VH_sigmaParam.insert(std::pair(22, SigmaParam{ -36.3971634075803, 13.1296247093899, 1.12707368693158, -1.88195857790977, 6.57450737122974, 2.11755051297951 })); //this->VV_sigmaParam.insert(std::pair(22, SigmaParam{ -43.6677042155964, 32.0245140457417, 0.511060658303930, -2.68482232690106, 6.29783274559538, 1.96648609622833 })); ////30 - //this->HH_sigmaParam.insert(std::pair(30, SigmaParam{ -59.1080014669385, 47.6710707363975, 0.300193452564135, - 3.93463636916976, 5.99799798331127, - 10.3772604045974 })); + this->HH_sigmaParam.insert(std::pair(30, SigmaParam{ -59.1080014669385, 47.6710707363975, 0.300193452564135, - 3.93463636916976, 5.99799798331127, - 10.3772604045974 })); //this->HV_sigmaParam.insert(std::pair(30, SigmaParam{ -55.1864353240982, 32.2453149408716, 0.333758208816865, - 3.38774208141056, 6.12774897769798, - 10.1192846531823 })); //this->VH_sigmaParam.insert(std::pair(30, SigmaParam{ -55.1864353240982, 32.2453149408716, 0.333758208816865, - 3.38774208141056, 6.12774897769798, - 10.1192846531823 })); //this->VV_sigmaParam.insert(std::pair(30, SigmaParam{ -59.1080014669385, 47.6710707363975, 0.300193452564135, -3.93463636916976, 5.99799798331127, -10.3772604045974 })); ////50 - //this->HH_sigmaParam.insert(std::pair(50, SigmaParam{ -22.9105602882378, 8170.54100628307, 15.4916054293135, - 0.970580847008280, 28.9025325818511, - 21.4319176514170 })); + this->HH_sigmaParam.insert(std::pair(50, SigmaParam{ -22.9105602882378, 8170.54100628307, 15.4916054293135, - 0.970580847008280, 28.9025325818511, - 21.4319176514170 })); //this->HV_sigmaParam.insert(std::pair(50, SigmaParam{ -39.7459019584805, 151.391039247574, 5.17117231380975, - 4.10303899418773, 8.04893424718507, - 3.17171678851531 })); //this->VH_sigmaParam.insert(std::pair(50, SigmaParam{ -39.7459019584805, 151.391039247574, 5.17117231380975, -4.10303899418773, 8.04893424718507, -3.17171678851531 })); //this->VV_sigmaParam.insert(std::pair(50, SigmaParam{ -22.9105602882378, 8170.54100628307, 15.4916054293135, -0.970580847008280, 28.9025325818511, -21.4319176514170 })); ////61 - //this->HH_sigmaParam.insert(std::pair(61, SigmaParam{ 27.2590864500905, 95.6840751800642, 3.98975084647232, 50.3262749621072, 3.09962879546370, - 5.10400310274333 })); + this->HH_sigmaParam.insert(std::pair(61, SigmaParam{ 27.2590864500905, 95.6840751800642, 3.98975084647232, 50.3262749621072, 3.09962879546370, - 5.10400310274333 })); //this->HV_sigmaParam.insert(std::pair(61, SigmaParam{ -65.9799383836613, 106.831320929437, 1.53821651203361, 0.704332523237733, 36.3654715437260, - 13.7449876973719 })); //this->VH_sigmaParam.insert(std::pair(61, SigmaParam{ -65.9799383836613, 106.831320929437, 1.53821651203361, 0.704332523237733, 36.3654715437260, -13.7449876973719 })); //this->VV_sigmaParam.insert(std::pair(61, SigmaParam{ 27.2590864500905, 95.6840751800642, 3.98975084647232, 50.3262749621072, 3.09962879546370, -5.10400310274333 })); ////62 - //this->HH_sigmaParam.insert(std::pair(62, SigmaParam{ -34.3961764495281, 21.7503968763591, 1.15914650010176, - 2.83950292185421, 10.3519995095232, 2.75293811408200 })); + this->HH_sigmaParam.insert(std::pair(62, SigmaParam{ -34.3961764495281, 21.7503968763591, 1.15914650010176, - 2.83950292185421, 10.3519995095232, 2.75293811408200 })); //this->HV_sigmaParam.insert(std::pair(62, SigmaParam{ -34.0710914034599, 14.1778732014224, 3.47049853590805, - 1.73813229616801, 10.9627971440838, 2.19731364578002 })); //this->VH_sigmaParam.insert(std::pair(62, SigmaParam{ -34.0710914034599, 14.1778732014224, 3.47049853590805, -1.73813229616801, 10.9627971440838, 2.19731364578002 })); //this->VV_sigmaParam.insert(std::pair(62, SigmaParam{ -34.3961764495281, 21.7503968763591, 1.15914650010176, -2.83950292185421, 10.3519995095232, 2.75293811408200 })); ////80 - //this->HH_sigmaParam.insert(std::pair(80, SigmaParam{ -5.76486750987210, - 7.80014668607246, 0.0880097904597720, - 5.44564720816575, - 0.530358195545799, 1.04332202699956 })); + this->HH_sigmaParam.insert(std::pair(80, SigmaParam{ -5.76486750987210, - 7.80014668607246, 0.0880097904597720, - 5.44564720816575, - 0.530358195545799, 1.04332202699956 })); //this->HV_sigmaParam.insert(std::pair(80, SigmaParam{ 484.928701445606, - 0.992170190244375, - 1.98914783519718, - 507.127544388772, 0.195180814149377, 6.21339949756719 })); //this->VH_sigmaParam.insert(std::pair(80, SigmaParam{ 484.928701445606, -0.992170190244375, -1.98914783519718, -507.127544388772, 0.195180814149377, 6.21339949756719 })); //this->VV_sigmaParam.insert(std::pair(80, SigmaParam{ -5.76486750987210, -7.80014668607246, 0.0880097904597720, -5.44564720816575, -0.530358195545799, 1.04332202699956 })); ////90 - //this->HH_sigmaParam.insert(std::pair(90, SigmaParam{ -20.1761798059391, 13.2752519275021, 2.74667225608397, 3.63052241744923, 8.99932188120922, 34.8246533269446 })); + this->HH_sigmaParam.insert(std::pair(90, SigmaParam{ -20.1761798059391, 13.2752519275021, 2.74667225608397, 3.63052241744923, 8.99932188120922, 34.8246533269446 })); //this->HV_sigmaParam.insert(std::pair(90, SigmaParam{ -26.8776515733889, 10.4251866500052, 8.43273666535992, 4.33165922141213, 8.68204389555939, - 2.51718779582920 })); //this->VH_sigmaParam.insert(std::pair(90, SigmaParam{ -26.8776515733889, 10.4251866500052, 8.43273666535992, 4.33165922141213, 8.68204389555939, - 2.51718779582920 })); //this->VV_sigmaParam.insert(std::pair(90, SigmaParam{ -20.1761798059391, 13.2752519275021, 2.74667225608397, 3.63052241744923, 8.99932188120922, 34.8246533269446 })); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp index 8286a6b..7e2cd86 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp @@ -337,6 +337,7 @@ ErrorCode TBPImageAlgCls::ProcessGPU() h_data.AntZ = (double*)mallocCUDAHost(sizeof(double) * block_pfrcount); qDebug() << "r_vec [0]:\t" << h_data.r_vec[0]; + qDebug() << "r_vec [end]:\t" << h_data.r_vec[h_data.Nfft-1]; qDebug() << "Range resolution(m):\t" << step; qDebug() << "range Scence(m):\t" << maxWr; qDebug() << "start Freq:\t" << centerFreq - bandwidth / 2; From 934a39cbff8c61d8eba7b0b5d484f94f50bde8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Wed, 2 Apr 2025 10:28:51 +0800 Subject: [PATCH 53/94] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=8C=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSAR/GPURFPC.cu | 73 +++++++++++-------- .../SimulationSAR/GPURFPC.cuh | 8 +- .../SimulationSAR/QImageSARRFPC.ui | 6 +- .../SimulationSAR/RFPCProcessCls.cpp | 18 ++++- 4 files changed, 65 insertions(+), 40 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index 049b07b..bb27ce1 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -490,7 +490,10 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( double maxGain, double GainWeight, float* d_temp_R, float* d_temp_amps// ) { - long long idx = blockIdx.x * blockDim.x + threadIdx.x; // ȡǰ̱߳ + long long tid = threadIdx.x; + long long bid = blockIdx.x; + long long dmx = blockDim.x; + long long idx = bid*dmx+tid; // ȡǰ̱߳ long long prfId = idx / SHAREMEMORY_FLOAT_HALF; long long posId = idx % SHAREMEMORY_FLOAT_HALF + startPosId; // ǰ̶߳ӦӰ @@ -506,26 +509,13 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( double RstZ = antp.Pz - gp.Tz; double RstR = sqrt(RstX * RstX + RstY * RstY + RstZ * RstZ); // ʸ - - if (RstRFarR) { - - if (prfId > 200) { - printf("error prfId:%d ,idx:%d RstR:%e antP=[%e,%e,%e] ,gp=[%e,%e,%e]\n", prfId, idx, RstR, - antp.Px, antp.Py, antp.Pz, gp.Tx, gp.Ty, gp.Tz - ); - } - - d_temp_R[idx] = 0; + d_temp_R[idx] = RstR; d_temp_amps[idx] = 0; return; } else { - if (prfId > 200) { - printf(" prfId:%d ,idx:%d RstR:%e antP=[%e,%e,%e] ,gp=[%e,%e,%e]\n", prfId, idx, RstR, - antp.Px, antp.Py, antp.Pz, gp.Tx, gp.Ty, gp.Tz - ); - } + RstX = RstX / RstR; RstY = RstY / RstR; RstZ = RstZ / RstR; @@ -540,8 +530,8 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( float localangle = acosf(dotAB / (slopR)); if (localangle < 0 || localangle >= LAMP_CUDA_PI / 2 || isnan(localangle)) { - d_temp_R[idx] = 0; - d_temp_amps[idx] = 0; + d_temp_R[idx] = RstR; + d_temp_amps[idx] = localangle; return; } else {} @@ -572,21 +562,35 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( sigma = powf(10.0, sigma / 10.0); float temp_amp = float(ampGain * Pt * sigma); - float temp_R = float(double(RstR - refPhaseRange)); + float temp_R = float(RstR - refPhaseRange); if (isnan(temp_amp) || isnan(temp_R) || isinf(temp_amp) || isinf(temp_R)) { - printf("amp is nan or R is nan,amp=%f;R=%f; \n", temp_amp, temp_R); - d_temp_R[idx] = 0; - d_temp_amps[idx] = 0; return; } else { - - d_temp_amps[idx] = temp_amp ; - d_temp_R[idx] = temp_R; - - return; + d_temp_amps[idx] = temp_amp ; + d_temp_R[idx] = temp_R ; + //if (prfId > 200) { + // printf("idx:%lld , prfid:%lld , d_temp_amp=%e,d_temp_R=%e\n", idx, prfId,d_temp_amps[idx], d_temp_R[idx]); + //} + //return; } + //if (isnan(temp_amp) || isnan(temp_R) || isinf(temp_amp) || isinf(temp_R)) { + // printf("amp is nan or R is nan,amp=%f;R=%f; \n", temp_amp, temp_R); + // d_temp_R[idx] = 0; + // d_temp_amps[idx] = 0; + // return; + //} + //else { + // if (prfId > 200) { + // printf("error prfId:%ld RstR:%e antP=[%e,%e,%e] ,gp=[%e,%e,%e],temp_amp=%e,temp_R=%e\n", prfId, RstR, + // antp.Px, antp.Py, antp.Pz, gp.Tx, gp.Ty, gp.Tz, + // temp_amp, temp_R); + // } + // d_temp_amps[idx] = temp_amp; + // d_temp_R[idx] = temp_R; + // return; + //} } } } @@ -622,7 +626,9 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( s_R[psid] = d_temp_R[pixelId]; s_amp[psid] = d_temp_amps[pixelId]; if (prfId > 200) { - printf("prfId:%d ,idx:%d s_R:%f S_amp:%f \n", prfId, idx, s_R[psid], s_amp[psid]); + printf(" s_R=%e S_amp=%e d_temp_R=%e d_temp_amps=%e idx=%lld prfid=%lld\n", s_R[psid], s_amp[psid], + d_temp_R[pixelId], d_temp_amps[pixelId], idx, prfId + ); } } @@ -667,7 +673,7 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( /** ֿ鴦 ****************************************************************************************************************/ -extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) +extern "C" void ProcessRFPCTask(RFPCTask& task, long devid, float* h_R, float* h_amp) { size_t pixelcount = task.prfNum * task.freqNum; size_t grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; @@ -686,6 +692,7 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) long prfcount = task.prfNum; long process = 0; for (long sTi = 0; sTi < task.targetnum; sTi = sTi + SHAREMEMORY_FLOAT_HALF) { + cudaBlocknum = (task.prfNum * SHAREMEMORY_FLOAT_HALF + BLOCK_SIZE - 1) / BLOCK_SIZE; Kernel_Computer_R_amp_NoAntPattern << > > ( task.antlist, @@ -703,6 +710,9 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) PrintLasterError("CUDA_Kernel_Computer_R_amp"); cudaDeviceSynchronize(); + DeviceToHost(h_R, d_R, task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(float)); + DeviceToHost(h_amp, d_amps, task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(float)); + break; cudaBlocknum = (task.prfNum * BLOCK_FREQNUM + BLOCK_SIZE- 1) / BLOCK_SIZE; CUDA_Kernel_Computer_echo_NoAntPattern << > > ( @@ -718,6 +728,11 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid) process = sTi * 100.0 / task.targetnum; PRINT("device ID : %d , TargetID [%f]: %d / %d finished %d\n", devid, sTi * 100.0 / task.targetnum, sTi, task.targetnum, devid); } + + + + + } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh index 48ec1be..0515694 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cuh @@ -16,11 +16,7 @@ extern "C" struct SateState { - double Px, Py, Pz, Vx, Vy, Vz; - //double antXaxisX, antXaxisY, antXaxisZ; - //double antYaxisX, antYaxisY, antYaxisZ; - //double antZaxisX, antZaxisY, antZaxisZ; - double antDirectX, antDirectY, antDirectZ; + double Px, Py, Pz, Vx, Vy, Vz,antDirectX, antDirectY, antDirectZ; }; @@ -152,7 +148,7 @@ extern "C" void CUDA_RFPC_MainProcess( extern "C" double* hostSigmaData_toDevice(int devid); -extern "C" void ProcessRFPCTask(RFPCTask& task,long devid); +extern "C" void ProcessRFPCTask(RFPCTask& task,long devid,float* h_R,float* h_amp); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui b/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui index 3d6693a..5d7afcf 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui +++ b/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui @@ -103,7 +103,7 @@ - D:/FZSimulation/LTDQ/Input/LandCover.dat + D:/FZSimulation/LTDQ/Input/testEcho/LandCover.dat @@ -233,7 +233,7 @@ - D:/FZSimulation/LTDQ/Input/DEM_XYZ.dat + D:/FZSimulation/LTDQ/Input/testEcho/DEMXYZ.dat @@ -350,7 +350,7 @@ - D:/FZSimulation/LTDQ/Input/DEM_Sloper.dat + D:/FZSimulation/LTDQ/Input/testEcho/DEMSloper.dat diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index e704c0f..fe5dc8a 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1114,9 +1114,18 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si task.antlist = (SateState*)mallocCUDADevice(prfcount * sizeof(SateState), devId); HostToDevice(h_antlist.get(), task.antlist, sizeof(SateState) * prfcount); - + printf("h_antlist: %e,%e,%e,%e,%e,%e,%e,%e,%e \n", + h_antlist.get()[0].Px, h_antlist.get()[0].Py, h_antlist.get()[0].Pz, + h_antlist.get()[0].Vx, h_antlist.get()[0].Vy, h_antlist.get()[0].Vz, + h_antlist.get()[0].antDirectX, h_antlist.get()[0].antDirectY, h_antlist.get()[0].antDirectZ + ); + testOutAmpArr(QString("antlist_%1.dat").arg(devId), (double*)(h_antlist.get()), prfcount, 9); } + + float* h_R = (float*)mallocCUDAHost(sizeof(float) * prfcount * SHAREMEMORY_FLOAT_HALF); //2GB 距离 + float* h_amp = (float*)mallocCUDAHost(sizeof(float) * prfcount * SHAREMEMORY_FLOAT_HALF);//2GB 强度 + // 分块计算 for (const auto& pair : clsGoalStateDict) { long clsid = pair.first; @@ -1128,7 +1137,12 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si task.goallist = (GoalState*)mallocCUDADevice(clscount * sizeof(GoalState), devId); HostToDevice(clsGoalStateDict[clsid].get(), task.goallist, sizeof(GoalState) * clscount); - ProcessRFPCTask(task, devId); + + + + ProcessRFPCTask(task, devId, h_R, h_amp); + testOutDataArr(QString("h_R_%1.bin").arg(devId), h_R, prfcount, SHAREMEMORY_FLOAT_HALF); + exit(-1); FreeCUDADevice(task.goallist); } From 3c1fd3a91a57f57063a6dc9cae590277f284cac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Wed, 2 Apr 2025 16:47:01 +0800 Subject: [PATCH 54/94] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=E6=88=90?= =?UTF-8?q?=E5=83=8F=E6=A3=80=E7=B4=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GPUBaseLib/GPUTool/GPUTool.cuh | 2 +- .../SimulationSAR/GPURFPC.cu | 93 +++++++------------ .../SimulationSAR/QImageSARRFPC.ui | 6 +- .../SimulationSAR/RFPCProcessCls.cpp | 13 ++- 4 files changed, 45 insertions(+), 69 deletions(-) diff --git a/GPUBaseLib/GPUTool/GPUTool.cuh b/GPUBaseLib/GPUTool/GPUTool.cuh index b380dc5..c2bd1d4 100644 --- a/GPUBaseLib/GPUTool/GPUTool.cuh +++ b/GPUBaseLib/GPUTool/GPUTool.cuh @@ -21,7 +21,7 @@ #define BLOCK_SIZE 256 #define SHAREMEMORY_BYTE 49152 #define SHAREMEMORY_FLOAT_HALF_STEP 2 -#define SHAREMEMORY_FLOAT_HALF SHAREMEMORY_FLOAT_HALF_STEP*BLOCK_SIZE +#define SHAREMEMORY_FLOAT_HALF 512 #define SHAREMEMORY_DEM_STEP 768 #define SHAREMEMORY_Reflect 612 diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index bb27ce1..62b3a4d 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -490,16 +490,14 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( double maxGain, double GainWeight, float* d_temp_R, float* d_temp_amps// ) { - long long tid = threadIdx.x; - long long bid = blockIdx.x; - long long dmx = blockDim.x; - long long idx = bid*dmx+tid; // ȡǰ̱߳ - long long prfId = idx / SHAREMEMORY_FLOAT_HALF; - long long posId = idx % SHAREMEMORY_FLOAT_HALF + startPosId; // ǰ̶߳ӦӰ - - //if (prfId > 20000) { - // printf("prfid %d,PRFCount : %d\n", prfId, PRFCount); - //} + int tid = threadIdx.x; + int bid = blockIdx.x; + int dmx = blockDim.x; + int idx = bid*dmx+tid; // ȡǰ̱߳ + int prfId = idx / SHAREMEMORY_FLOAT_HALF; + int posId = idx % SHAREMEMORY_FLOAT_HALF + startPosId; // ǰ̶߳ӦӰ + //d_temp_R[idx] = pixelcount; + //d_temp_amps[idx] = posId; if (prfId < PRFCount && posId < pixelcount) { SateState antp = antlist[prfId]; @@ -510,7 +508,7 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( double RstR = sqrt(RstX * RstX + RstY * RstY + RstZ * RstZ); // ʸ if (RstRFarR) { - d_temp_R[idx] = RstR; + d_temp_R[idx] = 0; d_temp_amps[idx] = 0; return; } @@ -530,8 +528,8 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( float localangle = acosf(dotAB / (slopR)); if (localangle < 0 || localangle >= LAMP_CUDA_PI / 2 || isnan(localangle)) { - d_temp_R[idx] = RstR; - d_temp_amps[idx] = localangle; + d_temp_R[idx] = 0; + d_temp_amps[idx] = 0; return; } else {} @@ -562,41 +560,24 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( sigma = powf(10.0, sigma / 10.0); float temp_amp = float(ampGain * Pt * sigma); - float temp_R = float(RstR - refPhaseRange); - + double temp_R = RstR - refPhaseRange; if (isnan(temp_amp) || isnan(temp_R) || isinf(temp_amp) || isinf(temp_R)) { + d_temp_R[idx] = 0; + d_temp_amps[idx] = 0; return; } else { - d_temp_amps[idx] = temp_amp ; - d_temp_R[idx] = temp_R ; - //if (prfId > 200) { - // printf("idx:%lld , prfid:%lld , d_temp_amp=%e,d_temp_R=%e\n", idx, prfId,d_temp_amps[idx], d_temp_R[idx]); - //} - //return; + d_temp_amps[idx] = temp_amp; + d_temp_R[idx] =static_cast(temp_R); + return; } - //if (isnan(temp_amp) || isnan(temp_R) || isinf(temp_amp) || isinf(temp_R)) { - // printf("amp is nan or R is nan,amp=%f;R=%f; \n", temp_amp, temp_R); - // d_temp_R[idx] = 0; - // d_temp_amps[idx] = 0; - // return; - //} - //else { - // if (prfId > 200) { - // printf("error prfId:%ld RstR:%e antP=[%e,%e,%e] ,gp=[%e,%e,%e],temp_amp=%e,temp_R=%e\n", prfId, RstR, - // antp.Px, antp.Py, antp.Pz, gp.Tx, gp.Ty, gp.Tz, - // temp_amp, temp_R); - // } - // d_temp_amps[idx] = temp_amp; - // d_temp_R[idx] = temp_R; - // return; - //} + } } } else { d_temp_R[idx] = 0; - d_temp_amps[idx] = 0; + d_temp_amps[idx] =0; return; } @@ -612,24 +593,20 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( __shared__ float s_R[SHAREMEMORY_FLOAT_HALF]; // עһblock_size ͬڴ __shared__ float s_amp[SHAREMEMORY_FLOAT_HALF]; - long long tid = threadIdx.x; - long long bid = blockIdx.x; - long long idx = bid * blockDim.x + tid; - long long prfId = idx / nextfreqNum; // ID - long long fId = idx % nextfreqNum;//ƵID + long tid = threadIdx.x; + long bid = blockIdx.x; + long idx = bid * blockDim.x + tid; + long prfId = idx / nextfreqNum; // ID + long fId = idx % nextfreqNum;//ƵID - long long psid = 0; - long long pixelId = 0; + long psid = 0; + long pixelId = 0; for (long ii = 0; ii < SHAREMEMORY_FLOAT_HALF_STEP; ii++) { // SHAREMEMORY_FLOAT_HALF_STEP * BLOCK_SIZE=SHAREMEMORY_FLOAT_HALF psid = ii * BLOCK_SIZE + tid; pixelId = prfId * SHAREMEMORY_FLOAT_HALF + psid; s_R[psid] = d_temp_R[pixelId]; s_amp[psid] = d_temp_amps[pixelId]; - if (prfId > 200) { - printf(" s_R=%e S_amp=%e d_temp_R=%e d_temp_amps=%e idx=%lld prfid=%lld\n", s_R[psid], s_amp[psid], - d_temp_R[pixelId], d_temp_amps[pixelId], idx, prfId - ); - } + } __syncthreads(); // ȷдݶѾ @@ -656,11 +633,11 @@ __global__ void CUDA_Kernel_Computer_echo_NoAntPattern( //if (dataid > 5000) { // printf("echo_ID=%d; dataid=%d;ehodata=(%f,%f);R=%f;amp=%f;\n", echo_ID, dataid, temp_real, temp_imag, s_R[0], s_amp[0]); //} - if (isnan(temp_phi) || isnan(temp_amp) || isnan(echo.x) || isnan(echo.y) - || isinf(temp_phi) || isinf(temp_amp) || isinf(echo.x) || isinf(echo.y) - ) { - printf("[amp,phi,real,imag]=[%f,%f,%f,%f];\n", temp_amp, temp_phi, echo.x, echo.y); - } + //if (isnan(temp_phi) || isnan(temp_amp) || isnan(echo.x) || isnan(echo.y) + // || isinf(temp_phi) || isinf(temp_amp) || isinf(echo.x) || isinf(echo.y) + // ) { + // printf("[amp,phi,real,imag]=[%f,%f,%f,%f];\n", temp_amp, temp_phi, echo.x, echo.y); + //} } @@ -710,9 +687,9 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid, float* h_R, float* h PrintLasterError("CUDA_Kernel_Computer_R_amp"); cudaDeviceSynchronize(); - DeviceToHost(h_R, d_R, task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(float)); - DeviceToHost(h_amp, d_amps, task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(float)); - break; + //DeviceToHost(h_R, d_R, task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(float)); + //DeviceToHost(h_amp, d_amps, task.prfNum * SHAREMEMORY_FLOAT_HALF * sizeof(float)); + //break; cudaBlocknum = (task.prfNum * BLOCK_FREQNUM + BLOCK_SIZE- 1) / BLOCK_SIZE; CUDA_Kernel_Computer_echo_NoAntPattern << > > ( diff --git a/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui b/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui index 5d7afcf..9ff2ec6 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui +++ b/Toolbox/SimulationSARTool/SimulationSAR/QImageSARRFPC.ui @@ -103,7 +103,7 @@ - D:/FZSimulation/LTDQ/Input/testEcho/LandCover.dat + D:/FZSimulation/LTDQ/Input/DEM30/LandCover.dat @@ -233,7 +233,7 @@ - D:/FZSimulation/LTDQ/Input/testEcho/DEMXYZ.dat + D:/FZSimulation/LTDQ/Input/DEM30/DEM_XYZ.dat @@ -350,7 +350,7 @@ - D:/FZSimulation/LTDQ/Input/testEcho/DEMSloper.dat + D:/FZSimulation/LTDQ/Input/DEM30/DEM_Sloper.dat diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index fe5dc8a..7001179 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1119,7 +1119,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si h_antlist.get()[0].Vx, h_antlist.get()[0].Vy, h_antlist.get()[0].Vz, h_antlist.get()[0].antDirectX, h_antlist.get()[0].antDirectY, h_antlist.get()[0].antDirectZ ); - testOutAmpArr(QString("antlist_%1.dat").arg(devId), (double*)(h_antlist.get()), prfcount, 9); + //testOutAmpArr(QString("antlist_%1.dat").arg(devId), (double*)(h_antlist.get()), prfcount, 9); } @@ -1136,13 +1136,11 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si task.targetnum = clscount; task.goallist = (GoalState*)mallocCUDADevice(clscount * sizeof(GoalState), devId); HostToDevice(clsGoalStateDict[clsid].get(), task.goallist, sizeof(GoalState) * clscount); - - - ProcessRFPCTask(task, devId, h_R, h_amp); - testOutDataArr(QString("h_R_%1.bin").arg(devId), h_R, prfcount, SHAREMEMORY_FLOAT_HALF); - exit(-1); + //testOutDataArr(QString("h_R_%1.bin").arg(devId), h_R, prfcount, SHAREMEMORY_FLOAT_HALF); + //testOutDataArr(QString("h_amp_%1.bin").arg(devId), h_amp, prfcount, SHAREMEMORY_FLOAT_HALF); + //exit(-1); FreeCUDADevice(task.goallist); } @@ -1153,7 +1151,8 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si FreeCUDADevice(task.d_echoData); FreeCUDADevice(task.antlist); //FreeCUDADevice(task.goallist); - + FreeCUDAHost(h_R); + FreeCUDAHost(h_amp); } PRINT("dem cover processbar: [100 precent]\n"); From 45535219911847bc3a2319d472f78d4198e33753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sat, 5 Apr 2025 12:16:22 +0800 Subject: [PATCH 55/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=9C=E8=B7=9D?= =?UTF-8?q?=E6=88=90=E5=83=8F=E7=AC=AC=E4=B8=80=E4=B8=AA=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=EF=BC=9A=20=E6=88=90=E5=83=8F=E6=8A=95=E5=BD=B1=E7=B2=97?= =?UTF-8?q?=E5=B9=B3=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/BaseConstVariable.h | 6 +- BaseCommonLibrary/BaseTool/GeoOperator.cpp | 38 ++ BaseCommonLibrary/BaseTool/GeoOperator.h | 1 + .../ToolAbstract/QToolAbstract.cpp | 5 + .../ToolAbstract/QToolAbstract.h | 2 + .../SARImage/GPUBPImageNet.cu | 204 +++++++++++ .../SARImage/GPUBPImageNet.cuh | 28 ++ .../SARImage/ImageNetOperator.cpp | 173 ++++++++++ .../SARImage/ImageNetOperator.h | 16 + .../SARImage/InitCreateImageXYZDialog.cpp | 77 +++++ .../SARImage/InitCreateImageXYZDialog.h | 36 ++ .../SARImage/InitCreateImageXYZDialog.ui | 250 ++++++++++++++ .../SimulationSAR/GPUBPTool.cuh | 7 +- .../SimulationSAR/GPUTBPImage.cu | 165 --------- .../SimulationSAR/GPUTBPImage.cuh | 9 - .../SimulationSAR/QSimulationBPImage.cpp | 11 +- .../SimulationSAR/TBPImageAlgCls.cpp | 325 ++++++++---------- .../SimulationSAR/TBPImageAlgCls.h | 22 +- .../SimulationSARTool/SimulationSARTool.cpp | 24 +- Toolbox/SimulationSARTool/SimulationSARTool.h | 9 + .../SimulationSARTool.vcxproj | 9 +- .../SimulationSARTool.vcxproj.filters | 24 ++ 22 files changed, 1056 insertions(+), 385 deletions(-) create mode 100644 Toolbox/SimulationSARTool/SARImage/GPUBPImageNet.cu create mode 100644 Toolbox/SimulationSARTool/SARImage/GPUBPImageNet.cuh create mode 100644 Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp create mode 100644 Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h create mode 100644 Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.cpp create mode 100644 Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.h create mode 100644 Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.ui diff --git a/BaseCommonLibrary/BaseTool/BaseConstVariable.h b/BaseCommonLibrary/BaseTool/BaseConstVariable.h index f16210d..9707cb0 100644 --- a/BaseCommonLibrary/BaseTool/BaseConstVariable.h +++ b/BaseCommonLibrary/BaseTool/BaseConstVariable.h @@ -154,7 +154,7 @@ struct Vector3_single { /*********************************************** FEKO仿真参数 ********************************************************************/ -struct SatellitePos { +extern "C" struct SatellitePos { double time; double Px ; double Py ; @@ -165,7 +165,7 @@ struct SatellitePos { }; -struct SatelliteAntPos { +extern "C" struct SatelliteAntPos { double time; // 0 double Px; double Py; @@ -188,7 +188,7 @@ struct SatelliteAntPos { }; -struct PatternImageDesc { +extern "C" struct PatternImageDesc { long phinum; long thetanum; double startTheta; diff --git a/BaseCommonLibrary/BaseTool/GeoOperator.cpp b/BaseCommonLibrary/BaseTool/GeoOperator.cpp index 9784c3a..5a1d12a 100644 --- a/BaseCommonLibrary/BaseTool/GeoOperator.cpp +++ b/BaseCommonLibrary/BaseTool/GeoOperator.cpp @@ -135,6 +135,44 @@ Landpoint XYZ2LLA(const Landpoint& XYZ) { +void XYZ2BLH_FixedHeight(double x, double y, double z,double ati, Landpoint& point) { + const double a = 6378137.0; // WGS84 + const double f = 1.0 / 298.257223563; + const double e2 = 2 * f - f * f; // һƫƽ + + // 㾭L () + const double L_rad = std::atan2(y, x); + point.lon = L_rad * 180.0 / M_PI; // תΪ + + const double p = std::sqrt(x * x + y * y); + const double H = ati; // ʹ֪߶ + + // ʼγȹ㣨֪߶H + double B_rad = std::atan2(z, p * (1 - e2 * (a / (a + H)))); + + // γB̶H + for (int i = 0; i < 10; ++i) { // ֪Hʱ + const double sin_B = std::sin(B_rad); + const double N = a / std::sqrt(1 - e2 * sin_B * sin_B); + const double delta = e2 * N / (N + H); // ߶ȹ̶ʱ + + const double B_new = std::atan2(z, p * (1 - delta)); + + if (std::abs(B_new - B_rad) < 1e-9) { + B_rad = B_new; + break; + } + B_rad = B_new; + } + + point.lat = B_rad * 180.0 / M_PI; // ת + + // ȷΧ [-180, 180] + point.lon = std::fmod(point.lon + 360.0, 360.0); + if (point.lon > 180.0) point.lon -= 360.0; + point.ati = ati; +} + double getAngle(const Landpoint& a, const Landpoint& b) { diff --git a/BaseCommonLibrary/BaseTool/GeoOperator.h b/BaseCommonLibrary/BaseTool/GeoOperator.h index 6d4eb8a..a2c42cc 100644 --- a/BaseCommonLibrary/BaseTool/GeoOperator.h +++ b/BaseCommonLibrary/BaseTool/GeoOperator.h @@ -30,6 +30,7 @@ Eigen::MatrixXd BASECONSTVARIABLEAPI LLA2XYZ(Eigen::MatrixXd landpoint); /// 经纬度--degree Landpoint BASECONSTVARIABLEAPI XYZ2LLA(const Landpoint& XYZ); +void BASECONSTVARIABLEAPI XYZ2BLH_FixedHeight(double x, double y, double z, double ati, Landpoint& point); Landpoint BASECONSTVARIABLEAPI operator +(const Landpoint& p1, const Landpoint& p2); diff --git a/BaseCommonLibrary/ToolAbstract/QToolAbstract.cpp b/BaseCommonLibrary/ToolAbstract/QToolAbstract.cpp index 302abc3..a20a9c5 100644 --- a/BaseCommonLibrary/ToolAbstract/QToolAbstract.cpp +++ b/BaseCommonLibrary/ToolAbstract/QToolAbstract.cpp @@ -32,5 +32,10 @@ QString QToolAbstract::getToolName() } void QToolAbstract::excute() +{ + this->run(); +} + +void QToolAbstract::run() { } diff --git a/BaseCommonLibrary/ToolAbstract/QToolAbstract.h b/BaseCommonLibrary/ToolAbstract/QToolAbstract.h index 5f00324..fda74f6 100644 --- a/BaseCommonLibrary/ToolAbstract/QToolAbstract.h +++ b/BaseCommonLibrary/ToolAbstract/QToolAbstract.h @@ -27,6 +27,8 @@ public slots: public: QVector toolPath; QString toolname; +public: + virtual void run(); }; /* diff --git a/Toolbox/SimulationSARTool/SARImage/GPUBPImageNet.cu b/Toolbox/SimulationSARTool/SARImage/GPUBPImageNet.cu new file mode 100644 index 0000000..c5e94a2 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/GPUBPImageNet.cu @@ -0,0 +1,204 @@ +#include "GPUBaseTool.h" +#include "GPUBPTool.cuh" +#include +#include +#include +#include +#include +#include +#include +#include + +#include "BaseConstVariable.h" +#include "GPUBPImageNet.cuh" + +#ifndef MAX_ITER +#define EPSILON 1e-12 +#define MAX_ITER 50 +#endif + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + + +__global__ void kernel_TimeBPImageGridNet( + double* antPx, double* antPy, double* antPz, + double* antDirx, double* antDiry, double* antDirz, + double* imgx, double* imgy, double* imgz, + long prfcount, long freqpoints, double meanH, + double Rnear, double dx) { + + long idx = blockIdx.x * blockDim.x + threadIdx.x; + long pixelcount = prfcount * freqpoints; + long prfid = idx / freqpoints; + long Rid = idx % freqpoints; + if (idx < pixelcount) { + // + Vector3 S = { antPx[prfid], antPy[prfid], antPz[prfid] }; // λ (m) + Vector3 ray = { antDirx[prfid], antDiry[prfid], antDirz[prfid] }; // ߷ + double H = meanH; // ƽ߳ + double R = Rnear + dx * Rid; // Ŀ + // У + if (R <= 0 || H < -WGS84_A * 0.1 || H > WGS84_A * 0.1) { + //printf("\n HΧ%.1f km\n R>0\n", WGS84_A * 0.1 / 1000); + imgx[idx] = 0; + imgy[idx] = 0; + imgz[idx] = 0; + return; + //printf("idx=%d;prfid=%d;Rid=%d;S=[%f , %f ,%f ];ray=[%f ,%f ,%f ];H=%f;R=%f,imgP=[%f ,%f , %f ];Rextend\n", + // idx, prfid, Rid, S.x, S.y, S.z, ray.x, ray.y, ray.z, H, R,imgx[idx],imgy[idx],imgz[idx]); + // У + //return; + } + + // Step 1: 㽻T + Vector3 T = compute_T(S, ray, H); + if (isnan(T.x)) { + imgx[idx] = 0; + imgy[idx] = 0; + imgz[idx] = 0; + //printf("idx=%d;prfid=%d;Rid=%d;Tnan\n", + // idx, prfid, Rid, S.x, S.y, S.z, ray.x, ray.y, ray.z, H, R,T.x,T.y,T.z, imgx[idx], imgy[idx], imgz[idx]); + return; + } + + // Step 2: ĿP + + Vector3 P;// = compute_P(S, T, R, H); + { // P + Vector3 ex, ey, ez; // ƽ + Vector3 ST = vec_normalize(vec_sub(T, S));// S->T + Vector3 SO = vec_normalize(vec_sub(Vector3{ 0, 0, 0 }, S)); // S->O + + + Vector3 st1 = vec_sub(T, S); + double R0 = sqrt(st1.x * st1.x + st1.y * st1.y + st1.z * st1.z); + ez = vec_normalize(vec_cross(SO, ST)); // Z + ey = vec_normalize(vec_cross(ez, SO)); // Y ST ͬ --ǵؼԼȻģ + ex = vec_normalize(SO); //X + + + + double h2 = (WGS84_A + H) * (WGS84_A + H); + double b2 = WGS84_B * WGS84_B; + double R2 = R * R; + double A = R2 * ((ex.x * ex.x + ex.y * ex.y) / h2 + (ex.z * ex.z) / b2); + double B = R2 * ((ex.x * ey.x + ex.y * ey.y) / h2 + (ex.z * ey.z) / b2) * 2; + double C = R2 * ((ey.x * ey.x + ey.y * ey.y) / h2 + (ey.z * ey.z) / b2); + double D = 1 - ((S.x * S.x + S.y * S.y) / h2 + (S.z * S.z) / b2); + double E = 2 * R * ((S.x * ex.x + S.y * ex.y) / h2 + (S.z * ex.z) / b2); + double F = 2 * R * ((S.x * ey.x + S.y * ey.y) / h2 + (S.z * ey.z) / b2); + double Q0 = angleBetweenVectors(SO, ST, false); + double dQ = 0; + double fQ = 0; + double dfQ = 0; + double Q = R < R0 ? Q0 - 1e-3 : Q0 + 1e-3; + + //printf("A=%f;B=%f;C=%f;D=%f;E=%f;F=%f;Q=%f;\ + // S=[%f , %f ,%f ];\ + // T=[%f , %f ,%f ];\ + // ex=[%f , %f ,%f ];\ + // ey=[%f , %f ,%f ];\ + // ez=[%f , %f ,%f ];\ + //ray=[%f ,%f ,%f ];\ + //H=%f;R=%f;;\n",A,B,C,D,E,F,Q, + // S.x,S.y,S.z, + // T.x,T.y,T.z , + // ex.x,ex.y,ex.z, + // ey.x,ey.y,ey.z, + // ez.x,ez.y,ez.z, + // ray.x, ray.y, ray.z, + // H, R); + // return; + + // ţٵ + for (int iter = 0; iter < MAX_ITER * 10; ++iter) { + fQ = A * cos(Q) * cos(Q) + B * sin(Q) * cos(Q) + C * sin(Q) * sin(Q) + E * cos(Q) + F * sin(Q) - D; + dfQ = (C - A) * sin(2 * Q) + B * cos(2 * Q) - E * sin(Q) + F * cos(Q); + dQ = fQ / dfQ; + if (abs(dQ) < 1e-8) { + //printf("iter=%d;check Q0=%f;Q=%f;dQ=%f;fQ=%f;dfQ=%f;break\n", iter, Q0, Q, dQ, fQ, dfQ); + break; + } + else { + dQ = (abs(dQ) < d2r * 3) ? dQ : (abs(dQ) / dQ * d2r * 3); + Q = Q - dQ; + //printf("iter=%d;check Q0=%f;Q=%f;dQ=%f;fQ=%f;dfQ=%f;\n", iter, Q0, Q, dQ, fQ, dfQ); + } + + } + //printf("check Q0=%f;Q=%f;\n", Q0, Q); + double t1 = R * cos(Q); + double t2 = R * sin(Q); + P = Vector3{ + S.x + t1 * ex.x + t2 * ey.x, //Ϊ t3=0 + S.y + t1 * ex.y + t2 * ey.y, + S.z + t1 * ex.z + t2 * ey.z, + }; + double check = (P.x * P.x + P.y * P.y) / ((WGS84_A + H) * (WGS84_A + H)) + + P.z * P.z / (WGS84_B * WGS84_B); + if (isnan(Q) || isinf(Q) || fabs(check - 1.0) > 1e-6) { + P = Vector3{ 0,0,0 }; + imgx[idx] = 0; + imgy[idx] = 0; + imgz[idx] = 0; + return; + } + } + + double Rt = sqrt(pow(S.x - T.x, 2) + pow(S.y - T.y, 2) + pow(S.z - T.z, 2)); + double Rp = sqrt(pow(S.x - P.x, 2) + pow(S.y - P.y, 2) + pow(S.z - P.z, 2)); + double Rop = sqrt(pow(P.x, 2) + pow(P.y, 2) + pow(P.z, 2)); + + if (!isnan(P.x) && (Rop > WGS84_A * 0.3) && (Rop < WGS84_A * 3)) { + + imgx[idx] = P.x; + imgy[idx] = P.y; + imgz[idx] = P.z; + return; + //printf("idx=%d; S=[%f , %f ,%f ]; H=%f;R=%f;RP=%f;Rr=%f;imgT=[%f ,%f ,%f ];imgP=[%f ,%f , %f ]; \n", + // idx, S.x, S.y, S.z, H, R, Rp, Rt,T.x, T.y, T.z, P.x, P.y, P.z); + } + else { + imgx[idx] = 0; + imgy[idx] = 0; + imgz[idx] = 0; + printf("idx=%d; S=[%f , %f ,%f ]; H=%f;R=%f;RP=%f;Rr=%f;imgT=[%f ,%f ,%f ];imgP=[%f ,%f , %f ]; ERROR\n", + idx, S.x, S.y, S.z, H, R, Rp, Rt, T.x, T.y, T.z, P.x, P.y, P.z); + return; + } + } + +} + + + + + + + + + + + + +void TIMEBPCreateImageGrid(double* antPx, double* antPy, double* antPz, + double* antDirx, double* antDiry, double* antDirz, + double* imgx, double* imgy, double* imgz, + long prfcount, long freqpoints, double meanH, + double Rnear, double dx +) +{ + long pixelcount = prfcount * freqpoints; + int grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; + + kernel_TimeBPImageGridNet << > > ( + antPx, antPy, antPz, + antDirx, antDiry, antDirz, + imgx, imgy, imgz, + prfcount, freqpoints, meanH, + Rnear, dx); + PrintLasterError("TIMEBPCreateImageGrid"); + cudaDeviceSynchronize(); +} diff --git a/Toolbox/SimulationSARTool/SARImage/GPUBPImageNet.cuh b/Toolbox/SimulationSARTool/SARImage/GPUBPImageNet.cuh new file mode 100644 index 0000000..e62e525 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/GPUBPImageNet.cuh @@ -0,0 +1,28 @@ +#ifndef __GPUBPIMAGENET_CUH___ +#define __GPUBPIMAGENET_CUH___ + + +#include "BaseConstVariable.h" +#include "GPUTool.cuh" +#include +#include +#include +#include +#include "GPUTool.cuh" +#include "GPUBPTool.cuh" + + + + + +extern "C" void TIMEBPCreateImageGrid( + double* antPx, double* antPy, double* antPz, // S + double* antDirx, double* antDiry, double* antDirz, // + double* imgx, double* imgy, double* imgz, + long prfcount, long freqpoints, double meanH, + double Rnear, double dx +); + + + +#endif \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp new file mode 100644 index 0000000..08011a9 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -0,0 +1,173 @@ +#include "ImageNetOperator.h" +#include "LogInfoCls.h" +#include "PrintMsgToQDebug.h" +#include +#include "ImageOperatorBase.h" +#include "GPUBaseTool.h" +#include "GPUBPImageNet.cuh" + + +void InitCreateImageXYZProcess(QString& outImageLLPath, QString& outImageXYZPath, QString& InEchoGPSDataPath, + double& NearRange, double& RangeResolution, int64_t& RangeNum) +{ + qDebug() << "---------------------------------------------------------------------------------"; + qDebug() << u8"ֳƽбͶӰ"; + gdalImage antimg(InEchoGPSDataPath); + qDebug() << u8"1. زGPSļ\t"; + qDebug() << u8"ļ·\t" << InEchoGPSDataPath; + qDebug() << u8"GPS \t" << antimg.height; + qDebug() << u8"ļ\t" << antimg.width; + qDebug() << u8"2.б"; + qDebug() << u8"룺\t" << NearRange; + qDebug() << u8"ֱʣ\t" << RangeResolution; + qDebug() << u8"\t" << RangeNum; + qDebug() << u8"3.ļ"; + gdalImage outimgll = CreategdalImageDouble(outImageLLPath, antimg.height,RangeNum, 3,true,true); + gdalImage outimgxyz = CreategdalImageDouble(outImageXYZPath, antimg.height, RangeNum, 3, true, true); + qDebug() << u8"ƽļγȣ·\t" << outImageLLPath; + qDebug() << u8"ƽļXYZ·\t" << outImageXYZPath; + qDebug() << u8"4.ʼXYZ"; + long prfcount = antimg.height; + long rangeNum = RangeNum; + double Rnear = NearRange; + double dx = RangeResolution; + + long blockRangeCount = Memory1GB / sizeof(double) / 4 / prfcount *6; + blockRangeCount = blockRangeCount < 1 ? 1 : blockRangeCount; + + std::shared_ptr Pxs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr Pys((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr Pzs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectX((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectY((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectZ((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + + { + long colnum = 19; + std::shared_ptr antpos =readDataArr(antimg,0,0,prfcount, colnum,1,GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + double time = 0; + double Px = 0; + double Py = 0; + double Pz = 0; + for (long i = 0; i < prfcount; i++) { + + Pxs.get()[i] = antpos.get()[i * 19 + 1]; // + Pys.get()[i] = antpos.get()[i * 19 + 2]; + Pzs.get()[i] = antpos.get()[i * 19 + 3]; + AntDirectX.get()[i] = antpos.get()[i * 19 + 13];// zero doppler + AntDirectY.get()[i] = antpos.get()[i * 19 + 14]; + AntDirectZ.get()[i] = antpos.get()[i * 19 + 15]; + + double NormAnt = std::sqrt(AntDirectX.get()[i] * AntDirectX.get()[i] + + AntDirectY.get()[i] * AntDirectY.get()[i] + + AntDirectZ.get()[i] * AntDirectZ.get()[i]); + AntDirectX.get()[i] = AntDirectX.get()[i] / NormAnt; + AntDirectY.get()[i] = AntDirectY.get()[i] / NormAnt; + AntDirectZ.get()[i] = AntDirectZ.get()[i] / NormAnt;// һ + } + antpos.reset(); + } + + std::shared_ptr d_Pxs((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); + std::shared_ptr d_Pys((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); + std::shared_ptr d_Pzs((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); + std::shared_ptr d_AntDirectX((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); + std::shared_ptr d_AntDirectY((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); + std::shared_ptr d_AntDirectZ((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); + + HostToDevice(Pxs.get(), d_Pxs.get(), sizeof(double) * prfcount); + HostToDevice(Pys.get(), d_Pys.get(), sizeof(double) * prfcount); + HostToDevice(Pzs.get(), d_Pzs.get(), sizeof(double) * prfcount); + HostToDevice(AntDirectX.get(), d_AntDirectX.get(), sizeof(double) * prfcount); + HostToDevice(AntDirectY.get(), d_AntDirectY.get(), sizeof(double) * prfcount); + HostToDevice(AntDirectZ.get(), d_AntDirectZ.get(), sizeof(double) * prfcount); + + + for (long startcolidx = 0; startcolidx < RangeNum; startcolidx = startcolidx + blockRangeCount) { + + long tempechocol = blockRangeCount; + if (startcolidx + tempechocol >= RangeNum) { + tempechocol = RangeNum - startcolidx; + } + qDebug() << " imgxyz :\t" << startcolidx << "\t-\t" << startcolidx + tempechocol << " / " << RangeNum; + + std::shared_ptr demx = readDataArr(outimgxyz, 0, startcolidx, prfcount, tempechocol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demy = readDataArr(outimgxyz, 0, startcolidx, prfcount, tempechocol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demz = readDataArr(outimgxyz, 0, startcolidx, prfcount, tempechocol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + std::shared_ptr h_demx((double*)mallocCUDAHost(sizeof(double) * prfcount * tempechocol), FreeCUDAHost); + std::shared_ptr h_demy((double*)mallocCUDAHost(sizeof(double) * prfcount * tempechocol), FreeCUDAHost); + std::shared_ptr h_demz((double*)mallocCUDAHost(sizeof(double) * prfcount * tempechocol), FreeCUDAHost); + +#pragma omp parallel for + for (long ii = 0; ii < prfcount; ii++) { + for (long jj = 0; jj < tempechocol; jj++) { + h_demx.get()[ii * tempechocol + jj] = demx.get()[ii * tempechocol + jj]; + h_demy.get()[ii * tempechocol + jj] = demy.get()[ii * tempechocol + jj]; + h_demz.get()[ii * tempechocol + jj] = demz.get()[ii * tempechocol + jj]; + } + } + + std::shared_ptr d_demx((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); + std::shared_ptr d_demy((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); + std::shared_ptr d_demz((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); + + HostToDevice(h_demx.get(), d_demx.get(), sizeof(double) * prfcount * tempechocol); + HostToDevice(h_demy.get(), d_demy.get(), sizeof(double) * prfcount * tempechocol); + HostToDevice(h_demz.get(), d_demz.get(), sizeof(double) * prfcount * tempechocol); + + + TIMEBPCreateImageGrid( + d_Pxs.get(), d_Pys.get(), d_Pzs.get(), + d_AntDirectX.get(), d_AntDirectY.get(), d_AntDirectZ.get(), + d_demx.get(), d_demy.get(), d_demz.get(), + prfcount, tempechocol, 0, + Rnear + dx * startcolidx, dx // ޶ + ); + + DeviceToHost(h_demx.get(), d_demx.get(), sizeof(double) * prfcount * tempechocol); + DeviceToHost(h_demy.get(), d_demy.get(), sizeof(double) * prfcount * tempechocol); + DeviceToHost(h_demz.get(), d_demz.get(), sizeof(double) * prfcount * tempechocol); + +#pragma omp parallel for + for (long ii = 0; ii < prfcount; ii++) { + for (long jj = 0; jj < tempechocol; jj++) { + demx.get()[ii * tempechocol + jj] = h_demx.get()[ii * tempechocol + jj]; + demy.get()[ii * tempechocol + jj] = h_demy.get()[ii * tempechocol + jj]; + demz.get()[ii * tempechocol + jj] = h_demz.get()[ii * tempechocol + jj]; + } + } + + outimgxyz.saveImage(demx, 0, startcolidx, prfcount, tempechocol, 1); + outimgxyz.saveImage(demy, 0, startcolidx, prfcount, tempechocol, 2); + outimgxyz.saveImage(demz, 0, startcolidx, prfcount, tempechocol, 3); + + // XYZתΪγ + std::shared_ptr demllx = readDataArr(outimgll, 0, startcolidx, prfcount, tempechocol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demlly = readDataArr(outimgll, 0, startcolidx, prfcount, tempechocol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demllz = readDataArr(outimgll, 0, startcolidx, prfcount, tempechocol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + +#pragma omp parallel for + for (long ii = 0; ii < prfcount; ii++) { + for (long jj = 0; jj < tempechocol; jj++) { + double x = demx.get()[ii * tempechocol + jj]; + double y = demy.get()[ii * tempechocol + jj]; + double z = demz.get()[ii * tempechocol + jj]; + Landpoint point; + XYZ2BLH_FixedHeight(x, y, z, 0, point); + demllx.get()[ii * tempechocol + jj] = point.lon; + demlly.get()[ii * tempechocol + jj] = point.lat; + demllz.get()[ii * tempechocol + jj] = point.ati; + } + } + + + outimgll.saveImage(demllx, 0, startcolidx, prfcount, tempechocol, 1); + outimgll.saveImage(demlly, 0, startcolidx, prfcount, tempechocol, 2); + outimgll.saveImage(demllz, 0, startcolidx, prfcount, tempechocol, 3); + + } + + qDebug() << u8"6."; + qDebug() << "---------------------------------------------------------------------------------"; +} diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h new file mode 100644 index 0000000..3410a8f --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h @@ -0,0 +1,16 @@ +#pragma once +#ifndef __ImageNetOperator__H_ +#define __ImageNetOperator__H_ +#include "BaseConstVariable.h" +#include + + +void InitCreateImageXYZProcess(QString& outImageLLPath, QString& outImageXYZPath, QString& InEchoGPSDataPath, double& NearRange, double& RangeResolution, int64_t& RangeNum); + + + + + + + +#endif diff --git a/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.cpp b/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.cpp new file mode 100644 index 0000000..68228d8 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.cpp @@ -0,0 +1,77 @@ +#include "InitCreateImageXYZDialog.h" +#include "ui_InitCreateImageXYZDialog.h" +#include +#include +#include "ImageNetOperator.h" + +InitCreateImageXYZDialog::InitCreateImageXYZDialog(QWidget *parent) + : QDialog(parent), ui(new Ui::InitCreateImageXYZDialogClass) +{ + ui->setupUi(this); +} + +InitCreateImageXYZDialog::~InitCreateImageXYZDialog() +{} + +void InitCreateImageXYZDialog::on_pushButtonImageLLSelect_clicked() +{ + QString fileNamePath = QFileDialog::getSaveFileName( + this, // + tr(u8"澭γȳ"), // + QString(), // Ĭ· + tr(u8"ENVI Bin(*.bin);;ENVI Data(*.dat);;ENVI Data(*.data);;tiffӰ(*.tif);;tiffӰ(*.tiff)") // ļ + ); + +} + +void InitCreateImageXYZDialog::on_pushButtonImageXYZSelect_clicked() +{ + QString fileNamePath = QFileDialog::getSaveFileName( + this, // + tr(u8"XYZ"), // + QString(), // Ĭ· + tr(u8"ENVI Bin(*.bin);;ENVI Data(*.dat);;ENVI Data(*.data);;tiffӰ(*.tif);;tiffӰ(*.tiff)") // ļ + ); +} + +void InitCreateImageXYZDialog::on_pushButtonEchoGPSDataSelect_clicked() +{ + + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡزGPSļ"), // + QString(), // Ĭ· + tr(u8"GPSļ(*.gpspos.data);;All Files(*.*)") // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditEchoGPSDataPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void InitCreateImageXYZDialog::on_buttonBox_accepted() +{ + double NearRange = this->ui->doubleSpinBoxNearRange->value(); + double RangeResolution = this->ui->doubleSpinBoxRangeResolution->value(); + int64_t RangeNum = this->ui->spinBoxRangeNum->value(); + QString imageLLPath = this->ui->lineEditImageLLPath->text().trimmed(); + QString imageXYZPath = this->ui->lineEditImageXYZPath->text().trimmed(); + QString echoGPSDataPath = this->ui->lineEditEchoGPSDataPath->text().trimmed(); + + InitCreateImageXYZProcess(imageLLPath, imageXYZPath, echoGPSDataPath, NearRange, RangeResolution, RangeNum); + if (imageLLPath.isEmpty() || imageXYZPath.isEmpty() || echoGPSDataPath.isEmpty()) { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + return; + } + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"")); + +} + +void InitCreateImageXYZDialog::on_buttonBox_rejected() +{ + this->close(); +} diff --git a/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.h b/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.h new file mode 100644 index 0000000..a334c35 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.h @@ -0,0 +1,36 @@ +#pragma once +#ifndef __InitCreateImageXYZDialog__HH__ +#define __InitCreateImageXYZDialog__HH__ + + +#include + + +namespace Ui { + class InitCreateImageXYZDialogClass; +} + + +class InitCreateImageXYZDialog : public QDialog +{ + Q_OBJECT + +public: + InitCreateImageXYZDialog(QWidget *parent = nullptr); + ~InitCreateImageXYZDialog(); + + +public : + void on_pushButtonImageLLSelect_clicked(); + void on_pushButtonImageXYZSelect_clicked(); + void on_pushButtonEchoGPSDataSelect_clicked(); + void on_buttonBox_accepted(); + void on_buttonBox_rejected(); + + +private: + Ui::InitCreateImageXYZDialogClass* ui; +}; + + +#endif \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.ui b/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.ui new file mode 100644 index 0000000..9ca01ed --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.ui @@ -0,0 +1,250 @@ + + + InitCreateImageXYZDialogClass + + + + 0 + 0 + 600 + 400 + + + + 初始化成像平面网格 + + + + + + + 0 + 30 + + + + 成像网格(XYZ): + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + D:\Programme\vs2022\RasterMergeTest\LAMPCAE_SCANE-all-scane\BPImage\GF3BPImage + + + + + + + + 0 + 30 + + + + 成像网格(经纬度): + + + + + + + + 0 + 30 + + + + 回波GPS轨道节点: + + + + + + + + 0 + 30 + + + + D:\Programme\vs2022\RasterMergeTest\LAMPCAE_SCANE-all-scane\GF3_Simulation.xml + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 0 + 30 + + + + D:\Programme\vs2022\RasterMergeTest\LAMPCAE_SCANE-all-scane\BPImage\GF3BPImage + + + + + + + true + + + + + 0 + 0 + 580 + 236 + + + + + + + 方位向参数 + + + + + + 方位向的像素数与回波GPS脉冲数一致 + + + + + + + + + + 距离向参数 + + + + + + 近斜距 + + + + + + + 3 + + + 1000000000000000000.000000000000000 + + + 0.010000000000000 + + + + + + + 5 + + + 99999999999999991611392.000000000000000 + + + 0.000100000000000 + + + + + + + 距离向间隔 + + + + + + + 距离向像素数 + + + + + + + 999999999 + + + + + + + + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPUBPTool.cuh b/Toolbox/SimulationSARTool/SimulationSAR/GPUBPTool.cuh index 58bdca9..49682a8 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPUBPTool.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPUBPTool.cuh @@ -1,3 +1,7 @@ +#ifndef __GPUBPTOOL_CUH___ +#define __GPUBPTOOL_CUH___ + + #include "BaseConstVariable.h" #include "GPUTool.cuh" #include @@ -7,7 +11,6 @@ #include "GPUTool.cuh" - extern __device__ double angleBetweenVectors(Vector3 a, Vector3 b, bool returnDegrees = false); extern __device__ Vector3 vec_sub(Vector3 a, Vector3 b); extern __device__ double vec_dot(Vector3 a, Vector3 b); @@ -21,3 +24,5 @@ extern __device__ double angleBetweenVectors_single(Vector3_single a, Vector3_s extern __device__ Vector3_single vec_sub_single(Vector3_single a, Vector3_single b); extern __device__ float vec_dot_single(Vector3_single a, Vector3_single b); extern __device__ Vector3_single vec_cross_single(Vector3_single a, Vector3_single b); + +#endif \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPUTBPImage.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPUTBPImage.cu index 31b021b..2d7061d 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPUTBPImage.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPUTBPImage.cu @@ -24,152 +24,6 @@ -__global__ void kernel_TimeBPImageGridNet(double* antPx, double* antPy, double* antPz, - double* antDirx, double* antDiry, double* antDirz, - double* imgx, double* imgy, double* imgz, - long prfcount, long freqpoints, double meanH, - double Rnear, double dx, double RefRange) { - - long idx = blockIdx.x * blockDim.x + threadIdx.x; - long pixelcount = prfcount * freqpoints; - long prfid = idx / freqpoints; - long Rid = idx % freqpoints; - if (idx < pixelcount) { - // 计算坐标 - Vector3 S = { antPx[prfid], antPy[prfid], antPz[prfid] }; // 卫星位置 (m) - Vector3 ray = { antDirx[prfid], antDiry[prfid], antDirz[prfid] }; // 视线方向 - double H = meanH; // 平均高程 - double R = Rnear + dx * Rid; // 目标距离 - // 参数校验 - if (R <= 0 || H < -WGS84_A * 0.1 || H > WGS84_A * 0.1) { - //printf("参数错误:\n H范围:±%.1f km\n R必须>0\n", WGS84_A * 0.1 / 1000); - imgx[idx] = NAN; - imgy[idx] = NAN; - imgz[idx] = NAN; - //printf("idx=%d;prfid=%d;Rid=%d;S=[%f , %f ,%f ];ray=[%f ,%f ,%f ];H=%f;R=%f,imgP=[%f ,%f , %f ];Rextend\n", - // idx, prfid, Rid, S.x, S.y, S.z, ray.x, ray.y, ray.z, H, R,imgx[idx],imgy[idx],imgz[idx]); - // 参数校验 - return; - } - - // Step 1: 计算交点T - Vector3 T = compute_T(S, ray, H); - if (isnan(T.x)) { - imgx[idx] = NAN; - imgy[idx] = NAN; - imgz[idx] = NAN; - //printf("idx=%d;prfid=%d;Rid=%d;Tnan\n", - // idx, prfid, Rid, S.x, S.y, S.z, ray.x, ray.y, ray.z, H, R,T.x,T.y,T.z, imgx[idx], imgy[idx], imgz[idx]); - return; - } - - // Step 2: 计算目标点P - - Vector3 P;// = compute_P(S, T, R, H); - { // 计算P - Vector3 ex, ey, ez; // 平面基函数 - Vector3 ST = vec_normalize(vec_sub(T, S));// S->T - Vector3 SO = vec_normalize(vec_sub(Vector3{ 0, 0, 0 }, S)); // S->O - - - Vector3 st1 = vec_sub(T, S); - double R0 = sqrt(st1.x * st1.x + st1.y * st1.y + st1.z * st1.z); - ez = vec_normalize(vec_cross(SO, ST)); // Z 轴 - ey = vec_normalize(vec_cross(ez, SO)); // Y 轴 与 ST 同向 --这个结论在星地几何约束,便是显然的; - ex = vec_normalize(SO); //X轴 - - - - double h2 = (WGS84_A + H) * (WGS84_A + H); - double b2 = WGS84_B * WGS84_B; - double R2 = R * R; - double A = R2 * ((ex.x * ex.x + ex.y * ex.y) / h2 + (ex.z * ex.z) / b2); - double B = R2 * ((ex.x * ey.x + ex.y * ey.y) / h2 + (ex.z * ey.z) / b2) * 2; - double C = R2 * ((ey.x * ey.x + ey.y * ey.y) / h2 + (ey.z * ey.z) / b2); - double D = 1 - ((S.x * S.x + S.y * S.y) / h2 + (S.z * S.z) / b2); - double E = 2*R * ((S.x * ex.x + S.y * ex.y) / h2 + (S.z * ex.z) / b2); - double F = 2*R * ((S.x * ey.x + S.y * ey.y) / h2 + (S.z * ey.z) / b2); - double Q0 = angleBetweenVectors(SO, ST, false); - double dQ = 0; - double fQ = 0; - double dfQ = 0; - double Q = R < R0 ? Q0 - 1e-3 : Q0 + 1e-3; - - //printf("A=%f;B=%f;C=%f;D=%f;E=%f;F=%f;Q=%f;\ - // S=[%f , %f ,%f ];\ - // T=[%f , %f ,%f ];\ - // ex=[%f , %f ,%f ];\ - // ey=[%f , %f ,%f ];\ - // ez=[%f , %f ,%f ];\ - //ray=[%f ,%f ,%f ];\ - //H=%f;R=%f;;\n",A,B,C,D,E,F,Q, - // S.x,S.y,S.z, - // T.x,T.y,T.z , - // ex.x,ex.y,ex.z, - // ey.x,ey.y,ey.z, - // ez.x,ez.y,ez.z, - // ray.x, ray.y, ray.z, - // H, R); - // return; - - // 牛顿迭代法 - for (int iter = 0; iter < MAX_ITER * 10; ++iter) { - fQ = A * cos(Q) * cos(Q) + B * sin(Q) * cos(Q) + C * sin(Q) * sin(Q) + E * cos(Q) + F * sin(Q) - D; - dfQ = (C - A) * sin(2 * Q) + B * cos(2 * Q) - E * sin(Q) + F * cos(Q); - dQ = fQ / dfQ; - if (abs(dQ) < 1e-8) { - //printf("iter=%d;check Q0=%f;Q=%f;dQ=%f;fQ=%f;dfQ=%f;break\n", iter, Q0, Q, dQ, fQ, dfQ); - break; - } - else { - dQ = (abs(dQ) < d2r * 3) ? dQ :( abs(dQ) / dQ * d2r* 3); - Q = Q - dQ; - //printf("iter=%d;check Q0=%f;Q=%f;dQ=%f;fQ=%f;dfQ=%f;\n", iter, Q0, Q, dQ, fQ, dfQ); - } - - } - //printf("check Q0=%f;Q=%f;\n", Q0, Q); - double t1 = R * cos(Q); - double t2 = R * sin(Q); - P = Vector3{ - S.x + t1 * ex.x + t2 * ey.x, //因为 t3=0; - S.y + t1 * ex.y + t2 * ey.y, - S.z + t1 * ex.z + t2 * ey.z, - }; - double check = (P.x * P.x + P.y * P.y) / ((WGS84_A + H) * (WGS84_A + H)) - + P.z * P.z / (WGS84_B * WGS84_B); - if (isnan(Q) || isinf(Q) || fabs(check - 1.0) > 1e-6) { - P = Vector3{ NAN,NAN,NAN }; - } - } - - double Rt = sqrt(pow(S.x - T.x, 2) + pow(S.y - T.y, 2) + pow(S.z - T.z, 2)); - double Rp = sqrt(pow(S.x - P.x, 2) + pow(S.y - P.y, 2) + pow(S.z - P.z, 2)); - double Rop = sqrt(pow( P.x, 2) + pow( P.y, 2) + pow( P.z, 2)); - - if (!isnan(P.x)&&( Rop>WGS84_A*0.3)&&(Rop> > ( - antPx, antPy, antPz, - antDirx, antDiry, antDirz, - imgx, imgy, imgz, - prfcount, freqpoints, meanH, - Rnear, dx, RefRange); - PrintLasterError("TIMEBPCreateImageGrid"); - cudaDeviceSynchronize(); - } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPUTBPImage.cuh b/Toolbox/SimulationSARTool/SimulationSAR/GPUTBPImage.cuh index 91314b9..f7d6989 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPUTBPImage.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPUTBPImage.cuh @@ -11,15 +11,6 @@ -extern "C" void TIMEBPCreateImageGrid( - double* antPx,double* antPy,double* antPz, // S - double* antDirx,double* antDiry,double* antDirz, // - double* imgx,double* imgy,double* imgz, - long prfcount,long freqpoints,double meanH, - double Rnear,double dx,double RefRange -); - - extern "C" void TimeBPImage( double* antPx, double* antPy, double* antPz, diff --git a/Toolbox/SimulationSARTool/SimulationSAR/QSimulationBPImage.cpp b/Toolbox/SimulationSARTool/SimulationSAR/QSimulationBPImage.cpp index d70ccfd..918731d 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/QSimulationBPImage.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/QSimulationBPImage.cpp @@ -12,6 +12,9 @@ QSimulationBPImage::QSimulationBPImage(QWidget *parent) : QDialog(parent),ui(new Ui::QSimulationBPImageClass) { ui->setupUi(this); + ui->checkBox->setEnabled(false); + ui->checkBox->setCheckable(true); + ui->checkBox->setChecked(true); QObject::connect(ui->pushButtonEchoSelect, SIGNAL(clicked()), this, SLOT(onpushButtonEchoSelectClicked())); QObject::connect(ui->pushButtonImageSelect, SIGNAL(clicked()), this, SLOT(onpushButtonImageSelectClicked())); @@ -97,12 +100,8 @@ void QSimulationBPImage::onbtnaccepted() TBPimag.setImageL1(imagL1); long cpucore_num = std::thread::hardware_concurrency(); TBPimag.setGPU(true); - if (ui->checkBox->isChecked()) { - TBPimag.ProcessWithGridNet(cpucore_num,ui->lineEdit->text().trimmed()); - } - else { - TBPimag.Process(cpucore_num); - } + TBPimag.ProcessWithGridNet(cpucore_num,ui->lineEdit->text().trimmed()); + this->show(); QMessageBox::information(this,u8"",u8""); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp index 7e2cd86..9b64590 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp @@ -14,171 +14,6 @@ #include -void CreatePixelXYZ(std::shared_ptr echoL0ds, QString outPixelXYZPath) -{ - long bandwidth = echoL0ds->getBandwidth(); - double Rnear = echoL0ds->getNearRange(); - double Rfar = echoL0ds->getFarRange(); - double refRange = echoL0ds->getRefPhaseRange(); - double dx = LIGHTSPEED / 2.0 / bandwidth; // c/2b - - - // 创建坐标系统 - long prfcount = echoL0ds->getPluseCount(); - long freqcount = echoL0ds->getPlusePoints(); - Eigen::MatrixXd gt = Eigen::MatrixXd::Zero(2, 3); - gt(0, 0) = 0; - gt(0, 1) = 1; - gt(0, 2) = 0; - gt(1, 0) = 0; - gt(1, 1) = 0; - gt(1, 2) = 1; - gdalImage xyzRaster = CreategdalImage(outPixelXYZPath, prfcount, freqcount, 3, gt, QString(""), false, true,true,GDT_Float64); - std::shared_ptr antpos = echoL0ds->getAntPos(); - dx = (echoL0ds->getFarRange()-echoL0ds->getNearRange())/(echoL0ds->getPlusePoints()-1); - Rnear = echoL0ds->getNearRange(); - double Rref = echoL0ds->getRefPhaseRange(); - double centerInc = echoL0ds->getCenterAngle()*d2r; - long echocol = Memory1GB * 1.0 / 8 / 4 / prfcount * 6; - qDebug() << "echocol:\t " << echocol ; - echocol = echocol < 1 ? 1: echocol; - - - std::shared_ptr Pxs((double*)mallocCUDAHost(sizeof(double)*prfcount), FreeCUDAHost); - std::shared_ptr Pys((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr Pzs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr AntDirectX((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr AntDirectY((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr AntDirectZ((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - - { - std::shared_ptr antpos = echoL0ds->getAntPos(); - double time = 0; - double Px = 0; - double Py = 0; - double Pz = 0; - for (long i = 0; i < prfcount; i++) { - - Pxs.get()[i] = antpos.get()[i * 19 + 1]; // 卫星坐标 - Pys.get()[i] = antpos.get()[i * 19 + 2]; - Pzs.get()[i] = antpos.get()[i * 19 + 3]; - AntDirectX.get()[i] = antpos.get()[i * 19 + 13];// zero doppler - AntDirectY.get()[i] = antpos.get()[i * 19 + 14]; - AntDirectZ.get()[i] = antpos.get()[i * 19 + 15]; - - double NormAnt = std::sqrt(AntDirectX.get()[i] * AntDirectX.get()[i] + - AntDirectY.get()[i] * AntDirectY.get()[i] + - AntDirectZ.get()[i] * AntDirectZ.get()[i]); - AntDirectX.get()[i] = AntDirectX.get()[i] / NormAnt; - AntDirectY.get()[i] = AntDirectY.get()[i] / NormAnt; - AntDirectZ.get()[i] = AntDirectZ.get()[i] / NormAnt;// 归一化 - } - antpos.reset(); - } - - std::shared_ptr d_Pxs((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); - std::shared_ptr d_Pys((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); - std::shared_ptr d_Pzs((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); - std::shared_ptr d_AntDirectX((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); - std::shared_ptr d_AntDirectY((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); - std::shared_ptr d_AntDirectZ((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); - - HostToDevice(Pxs.get(), d_Pxs.get(), sizeof(double) * prfcount); - HostToDevice(Pys.get(), d_Pys.get(), sizeof(double) * prfcount); - HostToDevice(Pzs.get(), d_Pzs.get(), sizeof(double) * prfcount); - HostToDevice(AntDirectX.get(), d_AntDirectX.get(), sizeof(double) * prfcount); - HostToDevice(AntDirectY.get(), d_AntDirectY.get(), sizeof(double) * prfcount); - HostToDevice(AntDirectZ.get(), d_AntDirectZ.get(), sizeof(double) * prfcount); - - - for (long startcolidx = 0; startcolidx < freqcount; startcolidx = startcolidx + echocol) { - - long tempechocol = echocol; - if (startcolidx + tempechocol >= freqcount) { - tempechocol = freqcount - startcolidx; - } - qDebug() << "\r[" << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") << "] imgxyz :\t" << startcolidx << "\t-\t" << startcolidx + tempechocol << " / " << freqcount ; - - std::shared_ptr demx = readDataArr(xyzRaster, 0, startcolidx, prfcount, tempechocol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - std::shared_ptr demy = readDataArr(xyzRaster, 0, startcolidx, prfcount, tempechocol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - std::shared_ptr demz = readDataArr(xyzRaster, 0, startcolidx, prfcount, tempechocol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - - std::shared_ptr h_demx((double*)mallocCUDAHost(sizeof(double) * prfcount*tempechocol), FreeCUDAHost); - std::shared_ptr h_demy((double*)mallocCUDAHost(sizeof(double) * prfcount*tempechocol), FreeCUDAHost); - std::shared_ptr h_demz((double*)mallocCUDAHost(sizeof(double) * prfcount*tempechocol), FreeCUDAHost); - -#pragma omp parallel for - for (long ii = 0; ii < prfcount; ii++) { - for (long jj = 0; jj < tempechocol; jj++) { - h_demx.get()[ii*tempechocol+jj]=demx.get()[ii*tempechocol+jj]; - h_demy.get()[ii*tempechocol+jj]=demy.get()[ii*tempechocol+jj]; - h_demz.get()[ii*tempechocol+jj]=demz.get()[ii*tempechocol+jj]; - } - } - - std::shared_ptr d_demx((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); - std::shared_ptr d_demy((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); - std::shared_ptr d_demz((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); - - HostToDevice(h_demx.get(), d_demx.get(), sizeof(double) * prfcount * tempechocol); - HostToDevice(h_demy.get(), d_demy.get(), sizeof(double) * prfcount * tempechocol); - HostToDevice(h_demz.get(), d_demz.get(), sizeof(double) * prfcount * tempechocol); - - - TIMEBPCreateImageGrid( - d_Pxs.get(), d_Pys.get(), d_Pzs.get(), - d_AntDirectX.get(), d_AntDirectY.get(), d_AntDirectZ.get(), - d_demx.get(), d_demy.get(), d_demz.get(), - prfcount, tempechocol, 1000, - Rnear+dx* startcolidx, dx, refRange // 更新最近修读 - ); - - DeviceToHost(h_demx.get(), d_demx.get(), sizeof(double) * prfcount * tempechocol); - DeviceToHost(h_demy.get(), d_demy.get(), sizeof(double) * prfcount * tempechocol); - DeviceToHost(h_demz.get(), d_demz.get(), sizeof(double) * prfcount * tempechocol); - -#pragma omp parallel for - for (long ii = 0; ii < prfcount; ii++) { - for (long jj = 0; jj < tempechocol; jj++) { - demx.get()[ii * tempechocol + jj]=h_demx.get()[ii * tempechocol + jj] ; - demy.get()[ii * tempechocol + jj]=h_demy.get()[ii * tempechocol + jj] ; - demz.get()[ii * tempechocol + jj]=h_demz.get()[ii * tempechocol + jj] ; - } - } - - xyzRaster.saveImage(demx, 0, startcolidx,prfcount,tempechocol, 1); - xyzRaster.saveImage(demy, 0, startcolidx,prfcount,tempechocol, 2); - xyzRaster.saveImage(demz, 0, startcolidx,prfcount,tempechocol, 3); - } - -} - -void TBPImageProcess(QString echofile, QString outImageFolder, QString imagePlanePath,long num_thread) -{ - std::shared_ptr 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, echoL0ds->getSimulationTaskName(), echoL0ds->getPluseCount(), echoL0ds->getPlusePoints()); - - - TBPImageAlgCls TBPimag; - TBPimag.setEchoL0(echoL0ds); - TBPimag.setImageL1(imagL1); - TBPimag.setImagePlanePath(imagePlanePath); - - TBPimag.Process(num_thread); -} - - void TBPImageAlgCls::setImagePlanePath(QString INimagePlanePath) { @@ -209,20 +44,7 @@ std::shared_ptr TBPImageAlgCls::getImageL0() { return this->L1ds; } - -ErrorCode TBPImageAlgCls::Process(long num_thread) -{ - - qDebug() << u8"开始成像"; - - - qDebug() << u8"创建成像平面的XYZ"; - QString outRasterXYZ = JoinPath(this->L1ds->getoutFolderPath(), this->L0ds->getSimulationTaskName() + "_xyz.bin"); - CreatePixelXYZ(this->L0ds, outRasterXYZ); - return this->ProcessWithGridNet(num_thread, outRasterXYZ); - -} ErrorCode TBPImageAlgCls::ProcessWithGridNet(long num_thread,QString xyzRasterPath) { @@ -490,6 +312,7 @@ void TBPImageAlgCls::EchoFreqToTime() host_echoArr.get()[ii * outColCount + jj] = make_cuComplex(echoArr.get()[ii * inColCount + jj].real(), echoArr.get()[ii * inColCount + jj].imag()); } } + #pragma omp parallel for for (long ii = 0; ii < tempechoBlockline * outColCount; ii++) { host_IFFTechoArr.get()[ii] = make_cuComplex(0, 0); @@ -538,3 +361,149 @@ bool TBPImageAlgCls::checkZeros(double* data, long long len) return flag; } + + + +// + +// +//void CreatePixelXYZ(std::shared_ptr echoL0ds, QString outPixelXYZPath) +//{ +// long bandwidth = echoL0ds->getBandwidth(); +// double Rnear = echoL0ds->getNearRange(); +// double Rfar = echoL0ds->getFarRange(); +// double refRange = echoL0ds->getRefPhaseRange(); +// double dx = LIGHTSPEED / 2.0 / bandwidth; // c/2b +// +// +// // 创建坐标系统 +// long prfcount = echoL0ds->getPluseCount(); +// long freqcount = echoL0ds->getPlusePoints(); +// Eigen::MatrixXd gt = Eigen::MatrixXd::Zero(2, 3); +// gt(0, 0) = 0; +// gt(0, 1) = 1; +// gt(0, 2) = 0; +// gt(1, 0) = 0; +// gt(1, 1) = 0; +// gt(1, 2) = 1; +// gdalImage xyzRaster = CreategdalImage(outPixelXYZPath, prfcount, freqcount, 3, gt, QString(""), false, true,true,GDT_Float64); +// std::shared_ptr antpos = echoL0ds->getAntPos(); +// dx = (echoL0ds->getFarRange()-echoL0ds->getNearRange())/(echoL0ds->getPlusePoints()-1); +// Rnear = echoL0ds->getNearRange(); +// double Rref = echoL0ds->getRefPhaseRange(); +// double centerInc = echoL0ds->getCenterAngle()*d2r; +// long echocol = Memory1GB * 1.0 / 8 / 4 / prfcount * 6; +// qDebug() << "echocol:\t " << echocol ; +// echocol = echocol < 1 ? 1: echocol; +// +// +// std::shared_ptr Pxs((double*)mallocCUDAHost(sizeof(double)*prfcount), FreeCUDAHost); +// std::shared_ptr Pys((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); +// std::shared_ptr Pzs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); +// std::shared_ptr AntDirectX((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); +// std::shared_ptr AntDirectY((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); +// std::shared_ptr AntDirectZ((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); +// +// { +// std::shared_ptr antpos = echoL0ds->getAntPos(); +// double time = 0; +// double Px = 0; +// double Py = 0; +// double Pz = 0; +// for (long i = 0; i < prfcount; i++) { +// +// Pxs.get()[i] = antpos.get()[i * 19 + 1]; // 卫星坐标 +// Pys.get()[i] = antpos.get()[i * 19 + 2]; +// Pzs.get()[i] = antpos.get()[i * 19 + 3]; +// AntDirectX.get()[i] = antpos.get()[i * 19 + 13];// zero doppler +// AntDirectY.get()[i] = antpos.get()[i * 19 + 14]; +// AntDirectZ.get()[i] = antpos.get()[i * 19 + 15]; +// +// double NormAnt = std::sqrt(AntDirectX.get()[i] * AntDirectX.get()[i] + +// AntDirectY.get()[i] * AntDirectY.get()[i] + +// AntDirectZ.get()[i] * AntDirectZ.get()[i]); +// AntDirectX.get()[i] = AntDirectX.get()[i] / NormAnt; +// AntDirectY.get()[i] = AntDirectY.get()[i] / NormAnt; +// AntDirectZ.get()[i] = AntDirectZ.get()[i] / NormAnt;// 归一化 +// } +// antpos.reset(); +// } +// +// std::shared_ptr d_Pxs((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); +// std::shared_ptr d_Pys((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); +// std::shared_ptr d_Pzs((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); +// std::shared_ptr d_AntDirectX((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); +// std::shared_ptr d_AntDirectY((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); +// std::shared_ptr d_AntDirectZ((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); +// +// HostToDevice(Pxs.get(), d_Pxs.get(), sizeof(double) * prfcount); +// HostToDevice(Pys.get(), d_Pys.get(), sizeof(double) * prfcount); +// HostToDevice(Pzs.get(), d_Pzs.get(), sizeof(double) * prfcount); +// HostToDevice(AntDirectX.get(), d_AntDirectX.get(), sizeof(double) * prfcount); +// HostToDevice(AntDirectY.get(), d_AntDirectY.get(), sizeof(double) * prfcount); +// HostToDevice(AntDirectZ.get(), d_AntDirectZ.get(), sizeof(double) * prfcount); +// +// +// for (long startcolidx = 0; startcolidx < freqcount; startcolidx = startcolidx + echocol) { +// +// long tempechocol = echocol; +// if (startcolidx + tempechocol >= freqcount) { +// tempechocol = freqcount - startcolidx; +// } +// qDebug() << "\r[" << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") << "] imgxyz :\t" << startcolidx << "\t-\t" << startcolidx + tempechocol << " / " << freqcount ; +// +// std::shared_ptr demx = readDataArr(xyzRaster, 0, startcolidx, prfcount, tempechocol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); +// std::shared_ptr demy = readDataArr(xyzRaster, 0, startcolidx, prfcount, tempechocol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); +// std::shared_ptr demz = readDataArr(xyzRaster, 0, startcolidx, prfcount, tempechocol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); +// +// std::shared_ptr h_demx((double*)mallocCUDAHost(sizeof(double) * prfcount*tempechocol), FreeCUDAHost); +// std::shared_ptr h_demy((double*)mallocCUDAHost(sizeof(double) * prfcount*tempechocol), FreeCUDAHost); +// std::shared_ptr h_demz((double*)mallocCUDAHost(sizeof(double) * prfcount*tempechocol), FreeCUDAHost); +// +//#pragma omp parallel for +// for (long ii = 0; ii < prfcount; ii++) { +// for (long jj = 0; jj < tempechocol; jj++) { +// h_demx.get()[ii*tempechocol+jj]=demx.get()[ii*tempechocol+jj]; +// h_demy.get()[ii*tempechocol+jj]=demy.get()[ii*tempechocol+jj]; +// h_demz.get()[ii*tempechocol+jj]=demz.get()[ii*tempechocol+jj]; +// } +// } +// +// std::shared_ptr d_demx((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); +// std::shared_ptr d_demy((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); +// std::shared_ptr d_demz((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); +// +// HostToDevice(h_demx.get(), d_demx.get(), sizeof(double) * prfcount * tempechocol); +// HostToDevice(h_demy.get(), d_demy.get(), sizeof(double) * prfcount * tempechocol); +// HostToDevice(h_demz.get(), d_demz.get(), sizeof(double) * prfcount * tempechocol); +// +// +// TIMEBPCreateImageGrid( +// d_Pxs.get(), d_Pys.get(), d_Pzs.get(), +// d_AntDirectX.get(), d_AntDirectY.get(), d_AntDirectZ.get(), +// d_demx.get(), d_demy.get(), d_demz.get(), +// prfcount, tempechocol, 0, +// Rnear+dx* startcolidx, dx, refRange // 更新最近修读 +// ); +// +// DeviceToHost(h_demx.get(), d_demx.get(), sizeof(double) * prfcount * tempechocol); +// DeviceToHost(h_demy.get(), d_demy.get(), sizeof(double) * prfcount * tempechocol); +// DeviceToHost(h_demz.get(), d_demz.get(), sizeof(double) * prfcount * tempechocol); +// +//#pragma omp parallel for +// for (long ii = 0; ii < prfcount; ii++) { +// for (long jj = 0; jj < tempechocol; jj++) { +// demx.get()[ii * tempechocol + jj]=h_demx.get()[ii * tempechocol + jj] ; +// demy.get()[ii * tempechocol + jj]=h_demy.get()[ii * tempechocol + jj] ; +// demz.get()[ii * tempechocol + jj]=h_demz.get()[ii * tempechocol + jj] ; +// } +// } +// +// xyzRaster.saveImage(demx, 0, startcolidx,prfcount,tempechocol, 1); +// xyzRaster.saveImage(demy, 0, startcolidx,prfcount,tempechocol, 2); +// xyzRaster.saveImage(demz, 0, startcolidx,prfcount,tempechocol, 3); +// } +// +//} + + diff --git a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.h b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.h index 61b925c..4fe8618 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.h +++ b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.h @@ -50,7 +50,7 @@ public: std::shared_ptr getImageL0(); public: - ErrorCode Process(long num_thread); + ErrorCode ProcessWithGridNet(long num_thread, QString xyzRasterPath); void setGPU(bool flag); bool getGPU(); @@ -69,23 +69,3 @@ private:// private: bool checkZeros(double* data, long long len); }; - - - - -void CreatePixelXYZ(std::shared_ptr echoL0ds,QString outPixelXYZPath); - - -void TBPImageProcess(QString echofile,QString outImageFolder,QString imagePlanePath,long num_thread); - -// -//void TBPImageGridNet( -// std::shared_ptr antPx, std::shared_ptr antPy, std::shared_ptr antPz, -// std::shared_ptr img_x, std::shared_ptr img_y, std::shared_ptr img_z, -// std::shared_ptr> echoArr, -// std::shared_ptr> img_arr, -// double freq, double dx, double Rnear, double Rfar, double refRange, -// long rowcount, long colcount, -// long prfcount, long freqcount, -// long startPRFId, long startRowID -//); diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index e726c24..8161f52 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -7,6 +7,7 @@ #include "QCreateSARIntensityByLookTableDialog.h" #include "QtSimulationGeoSARSigma0Dialog.h" #include "QtLinearToIntenisityDialog.h" +#include "InitCreateImageXYZDialog.h" SARSimlulationRFPCToolButton::SARSimlulationRFPCToolButton(QWidget* parent) { @@ -75,6 +76,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QCreateSARIntensityByLookTableToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QtSimulationGeoSARSigma0ToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QtLinearToIntenisityToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new InitCreateImageXYZToolButton(toolbox)); } @@ -141,4 +143,24 @@ void QtLinearToIntenisityToolButton::excute() { QtLinearToIntenisityDialog* dialog = new QtLinearToIntenisityDialog; dialog->show(); -} \ No newline at end of file +} + +InitCreateImageXYZToolButton::InitCreateImageXYZToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"񹤾߿"); + this->toolname = QString(u8"1.ƽ"); +} + +InitCreateImageXYZToolButton::~InitCreateImageXYZToolButton() +{ + +} + +void InitCreateImageXYZToolButton::run() +{ + InitCreateImageXYZDialog* dialog = new InitCreateImageXYZDialog; + dialog->show(); +} + + \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.h b/Toolbox/SimulationSARTool/SimulationSARTool.h index ae6cf44..58459d2 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.h +++ b/Toolbox/SimulationSARTool/SimulationSARTool.h @@ -98,6 +98,15 @@ public slots: }; +class SIMULATIONSARTOOL_EXPORT InitCreateImageXYZToolButton : public QToolAbstract { + Q_OBJECT +public: + InitCreateImageXYZToolButton(QWidget* parent = nullptr); + ~InitCreateImageXYZToolButton(); +public : + virtual void run() override; + +}; extern "C" SIMULATIONSARTOOL_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 1f5abbb..5df57ed 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -105,7 +105,7 @@ - ..\..\BaseCommonLibrary;..\..\BaseCommonLibrary\BaseTool;..\..\BaseCommonLibrary\ToolAbstract;..\..\GPUBaseLib\GPUTool;.\SimulationSAR;.;..\..\LAMPSARProcessProgram\ToolBoxManager;..\..\RasterMainWidgetGUI\RasterMainWidget;..\..\RasterProcessToolWidget;..\..\RasterMainWidgetGUI;.\PowerSimulationIncoherent;..\..\ImageshowTool;..\..\ImageshowTool\Imageshow;$(VC_IncludePath);$(WindowsSDK_IncludePath) + ..\..\BaseCommonLibrary;..\..\BaseCommonLibrary\BaseTool;..\..\BaseCommonLibrary\ToolAbstract;..\..\GPUBaseLib\GPUTool;.\SARImage;.\SimulationSAR;.;..\..\LAMPSARProcessProgram\ToolBoxManager;..\..\RasterMainWidgetGUI\RasterMainWidget;..\..\RasterProcessToolWidget;..\..\RasterMainWidgetGUI;.\PowerSimulationIncoherent;..\..\ImageshowTool;..\..\ImageshowTool\Imageshow;$(VC_IncludePath);$(WindowsSDK_IncludePath) $(SolutionDir)$(Platform)\$(Configuration)\Toolbox\ PluginTool_$(ProjectName) true @@ -214,6 +214,8 @@ + + @@ -226,6 +228,7 @@ + @@ -237,6 +240,9 @@ + + + @@ -271,6 +277,7 @@ + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index 6ca9c53..1399a37 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -27,6 +27,9 @@ {9b848585-2348-400d-b12a-dd79a2a71007} + + {3380934c-6b95-45eb-8d70-d8b58e0e9de3} + @@ -71,6 +74,12 @@ SimulationSAR + + SARImage + + + SARImage + @@ -124,6 +133,12 @@ PowerSimulationIncoherent + + SARImage + + + SARImage + @@ -153,6 +168,9 @@ PowerSimulationIncoherent + + SARImage + @@ -185,6 +203,9 @@ PowerSimulationIncoherent + + SARImage + @@ -220,5 +241,8 @@ SimulationSAR + + SARImage + \ No newline at end of file From 033db9e56995bd049eb7cf8313a9d6f2152172b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 6 Apr 2025 14:23:44 +0800 Subject: [PATCH 56/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SARImage/InitCreateImageXYZDialog.cpp | 31 ++++++++++++++++--- .../SARImage/InitCreateImageXYZDialog.h | 12 +++---- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.cpp b/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.cpp index 68228d8..45b5fce 100644 --- a/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.cpp @@ -8,12 +8,17 @@ InitCreateImageXYZDialog::InitCreateImageXYZDialog(QWidget *parent) : QDialog(parent), ui(new Ui::InitCreateImageXYZDialogClass) { ui->setupUi(this); + connect(ui->pushButtonEchoGPSDataSelect, SIGNAL(clicked()), this, SLOT(onpushButtonEchoGPSDataSelect_clicked())); + connect(ui->pushButtonImageXYZSelect, SIGNAL(clicked()), this, SLOT(onpushButtonImageXYZSelect_clicked())); + connect(ui->pushButtonImageLLSelect, SIGNAL(clicked()), this, SLOT(onpushButtonImageLLSelect_clicked())); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbuttonBox_accepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbuttonBox_rejected())); } InitCreateImageXYZDialog::~InitCreateImageXYZDialog() {} -void InitCreateImageXYZDialog::on_pushButtonImageLLSelect_clicked() +void InitCreateImageXYZDialog::onpushButtonImageLLSelect_clicked() { QString fileNamePath = QFileDialog::getSaveFileName( this, // @@ -21,10 +26,18 @@ void InitCreateImageXYZDialog::on_pushButtonImageLLSelect_clicked() QString(), // Ĭ· tr(u8"ENVI Bin(*.bin);;ENVI Data(*.dat);;ENVI Data(*.data);;tiffӰ(*.tif);;tiffӰ(*.tiff)") // ļ ); + // ûѡļ + if (!fileNamePath.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditImageLLPath->setText(fileNamePath); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } } -void InitCreateImageXYZDialog::on_pushButtonImageXYZSelect_clicked() +void InitCreateImageXYZDialog::onpushButtonImageXYZSelect_clicked() { QString fileNamePath = QFileDialog::getSaveFileName( this, // @@ -32,9 +45,17 @@ void InitCreateImageXYZDialog::on_pushButtonImageXYZSelect_clicked() QString(), // Ĭ· tr(u8"ENVI Bin(*.bin);;ENVI Data(*.dat);;ENVI Data(*.data);;tiffӰ(*.tif);;tiffӰ(*.tiff)") // ļ ); + // ûѡļ + if (!fileNamePath.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditImageXYZPath->setText(fileNamePath); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } } -void InitCreateImageXYZDialog::on_pushButtonEchoGPSDataSelect_clicked() +void InitCreateImageXYZDialog::onpushButtonEchoGPSDataSelect_clicked() { QString fileNames = QFileDialog::getOpenFileName( @@ -53,7 +74,7 @@ void InitCreateImageXYZDialog::on_pushButtonEchoGPSDataSelect_clicked() } } -void InitCreateImageXYZDialog::on_buttonBox_accepted() +void InitCreateImageXYZDialog::onbuttonBox_accepted() { double NearRange = this->ui->doubleSpinBoxNearRange->value(); double RangeResolution = this->ui->doubleSpinBoxRangeResolution->value(); @@ -71,7 +92,7 @@ void InitCreateImageXYZDialog::on_buttonBox_accepted() } -void InitCreateImageXYZDialog::on_buttonBox_rejected() +void InitCreateImageXYZDialog::onbuttonBox_rejected() { this->close(); } diff --git a/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.h b/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.h index a334c35..d4fb229 100644 --- a/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.h +++ b/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.h @@ -20,12 +20,12 @@ public: ~InitCreateImageXYZDialog(); -public : - void on_pushButtonImageLLSelect_clicked(); - void on_pushButtonImageXYZSelect_clicked(); - void on_pushButtonEchoGPSDataSelect_clicked(); - void on_buttonBox_accepted(); - void on_buttonBox_rejected(); +public slots : + void onpushButtonImageLLSelect_clicked(); + void onpushButtonImageXYZSelect_clicked(); + void onpushButtonEchoGPSDataSelect_clicked(); + void onbuttonBox_accepted(); + void onbuttonBox_rejected(); private: From 5f7b8ae9ea1f3813e5587feec100be0ad513fd74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 6 Apr 2025 14:29:35 +0800 Subject: [PATCH 57/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=87=E6=A0=B7?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/BaseConstVariable.h | 3 + BaseCommonLibrary/BaseTool/FileOperator.h | 10 +- .../BaseTool/ImageOperatorBase.h | 8 +- .../BaseTool/gdalImageOperator.cpp | 4 +- .../SARImage/ImageNetOperator.cpp | 118 ++++++++++++++ .../SARImage/ImageNetOperator.h | 4 +- .../SARImage/ImagePlaneAtiInterpDialog.cpp | 112 +++++++++++++ .../SARImage/ImagePlaneAtiInterpDialog.h | 35 ++++ .../SARImage/ImagePlaneAtiInterpDialog.ui | 152 ++++++++++++++++++ .../SARImage/InitCreateImageXYZDialog.ui | 4 +- .../SimulationSARTool/SimulationSARTool.cpp | 19 ++- Toolbox/SimulationSARTool/SimulationSARTool.h | 10 ++ .../SimulationSARTool.vcxproj | 3 + .../SimulationSARTool.vcxproj.filters | 9 ++ 14 files changed, 475 insertions(+), 16 deletions(-) create mode 100644 Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp create mode 100644 Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.h create mode 100644 Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui diff --git a/BaseCommonLibrary/BaseTool/BaseConstVariable.h b/BaseCommonLibrary/BaseTool/BaseConstVariable.h index 9707cb0..9c16a9d 100644 --- a/BaseCommonLibrary/BaseTool/BaseConstVariable.h +++ b/BaseCommonLibrary/BaseTool/BaseConstVariable.h @@ -15,6 +15,9 @@ +/** 定义常见文件格式*********/ +#define ENVI_FILE_FORMAT_FILTER u8"ALL File(*.*);;ENVI Bin(*.bin);;ENVI Data(*.dat);;ENVI Data(*.data);;tiff影像(*.tif);;tiff影像(*.tiff)" +#define XML_FILE_FORMAT_FILTER u8"ALL File(*.*);;XML File(*.xml);;tiff影像(*.tiff)" // diff --git a/BaseCommonLibrary/BaseTool/FileOperator.h b/BaseCommonLibrary/BaseTool/FileOperator.h index 72d542a..b016ede 100644 --- a/BaseCommonLibrary/BaseTool/FileOperator.h +++ b/BaseCommonLibrary/BaseTool/FileOperator.h @@ -16,7 +16,7 @@ #include #include #include - + bool BASECONSTVARIABLEAPI isDirectory(const QString& path); bool BASECONSTVARIABLEAPI isExists(const QString& path); @@ -29,7 +29,7 @@ unsigned long BASECONSTVARIABLEAPI convertToULong(const QString& input); /// /// /// -std::vector BASECONSTVARIABLEAPI getFilelist(const QString& folderpath, const QString& FilenameExtension = ".*",int (*logfun)(QString logtext,int value)=nullptr); +std::vector BASECONSTVARIABLEAPI getFilelist(const QString& folderpath, const QString& FilenameExtension = ".*", int (*logfun)(QString logtext, int value) = nullptr); QString BASECONSTVARIABLEAPI getParantFolderNameFromPath(const QString& path); @@ -41,11 +41,11 @@ 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); +char* read_textfile(char* text_path, int* length); -bool BASECONSTVARIABLEAPI exists_test(const QString& name); +bool BASECONSTVARIABLEAPI exists_test(const QString& name); -size_t BASECONSTVARIABLEAPI fsize(FILE* fp); +size_t BASECONSTVARIABLEAPI fsize(FILE* fp); QString BASECONSTVARIABLEAPI getParantFromPath(const QString& path); void BASECONSTVARIABLEAPI copyFile(const QString& sourcePath, const QString& destinationPath); diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h index 060df9a..8b0b7ba 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h @@ -135,10 +135,10 @@ GDALDataType BASECONSTVARIABLEAPI getGDALDataType(QString fileptah); struct RasterExtend { - double min_x; //纬度 - double min_y;//经度 - double max_x;//纬度 - double max_y;//经度 + double min_x; + double min_y; + double max_x; + double max_y; }; diff --git a/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp b/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp index bce0668..d0c8c77 100644 --- a/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp +++ b/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp @@ -1228,8 +1228,8 @@ RasterExtend gdalImage::getExtend() double x1 = this->gt(0, 0); double y1 = this->gt(1, 0); - double x2 = this->gt(0, 0) + (this->width - 1) * gt(0, 1) + (0) * gt(0, 2); - double y2 = this->gt(1, 0) + (this->width - 1) * gt(1, 1) + (0) * gt(1, 2); + double x2 = this->gt(0, 0) + (this->width - 1) * gt(0, 1) + (0) * gt(0, 2); // + double y2 = this->gt(1, 0) + (this->width - 1) * gt(1, 1) + (0) * gt(1, 2); // γ double x3 = this->gt(0, 0) + (0) * gt(0, 1) + (this->height - 1) * gt(0, 2); double y3 = this->gt(1, 0) + (0) * gt(1, 1) + (this->height - 1) * gt(1, 2); diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 08011a9..065151d 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -5,6 +5,7 @@ #include "ImageOperatorBase.h" #include "GPUBaseTool.h" #include "GPUBPImageNet.cuh" +#include "BaseTool.h" void InitCreateImageXYZProcess(QString& outImageLLPath, QString& outImageXYZPath, QString& InEchoGPSDataPath, @@ -171,3 +172,120 @@ void InitCreateImageXYZProcess(QString& outImageLLPath, QString& outImageXYZPath qDebug() << u8"6."; qDebug() << "---------------------------------------------------------------------------------"; } + +bool OverlapCheck(QString& ImageLLPath, QString& ImageDEMPath) +{ + // DEMǷWGS84ϵ + long demEPSG = GetEPSGFromRasterFile(ImageDEMPath); + if (demEPSG != 4326) { + qDebug() << u8"DEMϵWGS84ϵ"; + return false; + } + + gdalImage demimg(ImageDEMPath); + gdalImage imgll(ImageLLPath); + + long imgheight = imgll.height; + long imgwidth = imgll.width; + Eigen::MatrixXd imglonArr = imgll.getData(0, 0, imgheight, imgwidth, 1); + Eigen::MatrixXd imglatArr = imgll.getData(0, 0, imgheight, imgwidth, 2); + + for (long i = 0; i < imgheight; i++) + { + for (long j = 0; j < imgwidth; j++) + { + double lon = imglonArr(i, j); // X + double lat = imglatArr(i, j); // Y + Landpoint point = imgll.getRow_Col(lon, lat); + imglonArr(i, j) = point.lon; + imglatArr(i, j) = point.lat; + } + } + + double minX = imglonArr.minCoeff(); + double maxX = imglonArr.maxCoeff(); + double minY = imglatArr.minCoeff(); + double maxY = imglatArr.maxCoeff(); + + if (minX<1 || maxX>demimg.width - 1 || minY<1 || maxY>demimg.height - 1) { + return false; + } + else { + return true; + } + + + +} + +void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath) +{ + gdalImage demimg(ImageDEMPath); + gdalImage imgll(ImageLLPath); + gdalImage outimgll = CreategdalImageDouble(outImageLLAPath, imgll.height, imgll.width, 3, true, true); + + long imgheight = imgll.height; + long imgwidth = imgll.width; + + Eigen::MatrixXd imglonArr = imgll.getData(0, 0, imgheight, imgwidth, 1); + Eigen::MatrixXd imglatArr = imgll.getData(0, 0, imgheight, imgwidth, 2); + Eigen::MatrixXd imgatiArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); + + outimgll.saveImage(imglonArr, 0, 0, 1); + outimgll.saveImage(imglatArr, 0, 0, 2); + + for (long i = 0; i < imgheight; i++) { + for (long j = 0; j < imgwidth; j++) { + double lon = imglonArr(i, j); // X + double lat = imglatArr(i, j); // Y + Landpoint point = imgll.getRow_Col(lon, lat); + imglonArr(i, j) = point.lon; + imglatArr(i, j) = point.lat; + } + } + + for (long i = 0; i < imgheight; i++) { + for (long j = 0; j < imgwidth; j++) { + double imX = imglonArr(i, j); + double imY = imglatArr(i, j); + + Landpoint p0, p11, p21, p12, p22; + p0.lon = imX; + p0.lat = imY; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + Bilinear_interpolation(p0, p11, p21, p12, p22); + imgatiArr(i, j) = p0.ati; + + } + } + outimgll.saveImage(imgatiArr, 0, 0, 3); + + qDebug() << u8"ֵ"; +} diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h index 3410a8f..bef2c34 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h @@ -7,9 +7,9 @@ void InitCreateImageXYZProcess(QString& outImageLLPath, QString& outImageXYZPath, QString& InEchoGPSDataPath, double& NearRange, double& RangeResolution, int64_t& RangeNum); +bool OverlapCheck(QString& ImageLLPath, QString& ImageDEMPath); - - +void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath); diff --git a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp new file mode 100644 index 0000000..775312e --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp @@ -0,0 +1,112 @@ +#include "ImagePlaneAtiInterpDialog.h" +#include "ui_ImagePlaneAtiInterpDialog.h" +#include +#include +#include "BaseConstVariable.h" +#include "ImageNetOperator.h" + +ImagePlaneAtiInterpDialog::ImagePlaneAtiInterpDialog(QWidget *parent) + : QDialog(parent) + , ui(new Ui::ImagePlaneAtiInterpDialogClass) +{ + ui->setupUi(this); + + connect(ui->pushButtonImageLLASelect, SIGNAL(clicked()), this, SLOT(onpushButtonImageLLASelect_clicked())); + connect(ui->pushButtonImageNet0Select, SIGNAL(clicked()), this, SLOT(onpushButtonImageNet0Select_clicked())); + connect(ui->pushButtonRefRangeDEMSelect, SIGNAL(clicked()), this, SLOT(onpushButtonRefRangeDEMSelect_clicked())); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbuttonBoxAccepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbuttonBoxRejected())); + + +} + +ImagePlaneAtiInterpDialog::~ImagePlaneAtiInterpDialog() +{} + +void ImagePlaneAtiInterpDialog::onpushButtonImageNet0Select_clicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, + tr(u8"ѡƽļ"), + QString(), + tr(ENVI_FILE_FORMAT_FILTER) + ); + + if (!fileNames.isEmpty()) { + QString message = "ѡļ\n"; + this->ui->lineEditImageNet0Path->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"ûѡļ")); + } +} + +void ImagePlaneAtiInterpDialog::onpushButtonRefRangeDEMSelect_clicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // ?????? + tr(u8"ѡοDEM"), // ???? + QString(), // ????? + tr(ENVI_FILE_FORMAT_FILTER) // ????????? + ); + // ?????????????? + if (!fileNames.isEmpty()) { + QString message = "ѡļ\n"; + this->ui->lineEditRefRangeDEMPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"ûѡļ")); + } +} + +void ImagePlaneAtiInterpDialog::onpushButtonImageLLASelect_clicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // ?????? + tr(u8"ʾ"), // ???? + QString(), // ????? + tr(ENVI_FILE_FORMAT_FILTER) // ????????? + ); + // ?????????????? + if (!fileNames.isEmpty()) { + QString message = "?????????\n"; + this->ui->lineEditImageLLAPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"ûѡļ")); + } +} + +void ImagePlaneAtiInterpDialog::onbuttonBoxAccepted() +{ + QString imageNet0Path = this->ui->lineEditImageNet0Path->text().trimmed(); + QString refRangeDEMPath = this->ui->lineEditRefRangeDEMPath->text().trimmed(); + QString imageLLAPath = this->ui->lineEditImageLLAPath->text().trimmed(); + + if (imageNet0Path.isEmpty() || refRangeDEMPath.isEmpty() || imageLLAPath.isEmpty()) { + QMessageBox::warning(this, tr(u8"ʾ"), tr(u8"ûѡļ")); + return; + } + else { + + } + + if (OverlapCheck(imageNet0Path, refRangeDEMPath)) { // ????DEM??? + InterploateAtiByRefDEM(imageNet0Path, refRangeDEMPath, imageLLAPath); + + QMessageBox::information(nullptr, u8"ʾ", u8"completed!!"); + return; + + } + else { + QMessageBox::warning(nullptr,u8"",u8"DEMӰСڳƽҪ"); + return; + } +} + +void ImagePlaneAtiInterpDialog::onbuttonBoxRejected() +{ + this->close(); +} + + \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.h b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.h new file mode 100644 index 0000000..1c59bd0 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.h @@ -0,0 +1,35 @@ +#pragma once + +#ifndef __ImagePlaneAtiInterpDialog__HH__ +#define __ImagePlaneAtiInterpDialog__HH__ + +#include + +namespace Ui { + class ImagePlaneAtiInterpDialogClass; +} + + +class ImagePlaneAtiInterpDialog : public QDialog +{ + Q_OBJECT + +public: + ImagePlaneAtiInterpDialog(QWidget *parent = nullptr); + ~ImagePlaneAtiInterpDialog(); + +public /*slots*/: + + void onpushButtonImageNet0Select_clicked(); + void onpushButtonRefRangeDEMSelect_clicked(); + void onpushButtonImageLLASelect_clicked(); + void onbuttonBoxAccepted(); + void onbuttonBoxRejected(); + + +private: + Ui::ImagePlaneAtiInterpDialogClass* ui; +}; + + +#endif \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui new file mode 100644 index 0000000..00cbfeb --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui @@ -0,0 +1,152 @@ + + + ImagePlaneAtiInterpDialogClass + + + + 0 + 0 + 661 + 266 + + + + 根据经纬度插值高程数据 + + + + + + + 0 + 30 + + + + 成像网格(经纬度): + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 参考DEM: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 成像粗网格(高程): + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.ui b/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.ui index 9ca01ed..38293bd 100644 --- a/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.ui +++ b/Toolbox/SimulationSARTool/SARImage/InitCreateImageXYZDialog.ui @@ -7,7 +7,7 @@ 0 0 600 - 400 + 403 @@ -155,7 +155,7 @@ 0 0 580 - 236 + 239 diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index 8161f52..bee3038 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -8,6 +8,8 @@ #include "QtSimulationGeoSARSigma0Dialog.h" #include "QtLinearToIntenisityDialog.h" #include "InitCreateImageXYZDialog.h" +#include "ImagePlaneAtiInterpDialog.h" + SARSimlulationRFPCToolButton::SARSimlulationRFPCToolButton(QWidget* parent) { @@ -77,6 +79,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QtSimulationGeoSARSigma0ToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QtLinearToIntenisityToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new InitCreateImageXYZToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new ImagePlaneAtiInterpToolButton(toolbox)); } @@ -163,4 +166,18 @@ void InitCreateImageXYZToolButton::run() dialog->show(); } - \ No newline at end of file +ImagePlaneAtiInterpToolButton::ImagePlaneAtiInterpToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"񹤾߿"); + this->toolname = QString(u8"2.ƽӳDEM"); +} +ImagePlaneAtiInterpToolButton::~ImagePlaneAtiInterpToolButton() +{ +} + +void ImagePlaneAtiInterpToolButton::run() +{ + ImagePlaneAtiInterpDialog* dialog = new ImagePlaneAtiInterpDialog; + dialog->show(); +} diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.h b/Toolbox/SimulationSARTool/SimulationSARTool.h index 58459d2..1d356f2 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.h +++ b/Toolbox/SimulationSARTool/SimulationSARTool.h @@ -109,6 +109,16 @@ public : }; +class SIMULATIONSARTOOL_EXPORT ImagePlaneAtiInterpToolButton : public QToolAbstract { + Q_OBJECT +public: + ImagePlaneAtiInterpToolButton(QWidget* parent = nullptr); + ~ImagePlaneAtiInterpToolButton(); +public: + virtual void run() override; + +}; + extern "C" SIMULATIONSARTOOL_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 5df57ed..2cf6ee0 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -215,6 +215,7 @@ + @@ -243,6 +244,7 @@ + @@ -277,6 +279,7 @@ + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index 1399a37..6c8fd72 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -80,6 +80,9 @@ SARImage + + SARImage + @@ -139,6 +142,9 @@ SARImage + + SARImage + @@ -171,6 +177,9 @@ SARImage + + SARImage + From c43df32af50117dd3cd2b7c81ff8af80c1dfdd21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 6 Apr 2025 15:20:09 +0800 Subject: [PATCH 58/94] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=85=8D=E7=BD=AEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/SimulationSARTool/SimulationSARTool.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 2cf6ee0..1562e03 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -244,7 +244,7 @@ - + From da92aff9dc7c8355dd2465b2def80b3f5af28fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 6 Apr 2025 16:36:33 +0800 Subject: [PATCH 59/94] =?UTF-8?q?=E8=B0=83=E6=95=B4DEM=E6=8F=92=E5=80=BC?= =?UTF-8?q?=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 065151d..805d0a0 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -222,7 +222,7 @@ void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString { gdalImage demimg(ImageDEMPath); gdalImage imgll(ImageLLPath); - gdalImage outimgll = CreategdalImageDouble(outImageLLAPath, imgll.height, imgll.width, 3, true, true); + gdalImage outimgll = CreategdalImageDouble(outImageLLAPath, imgll.height, imgll.width, 4, true, true); // ȡγȡ̡߳б long imgheight = imgll.height; long imgwidth = imgll.width; From a4f195c88315179bceedbd2fe67164e7c49440a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 6 Apr 2025 16:48:37 +0800 Subject: [PATCH 60/94] =?UTF-8?q?=E5=9C=A8=E9=AB=98=E7=A8=8B=E6=8F=92?= =?UTF-8?q?=E5=80=BC=E4=B9=8B=E5=90=8E=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=96=9C=E8=B7=9D=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SARImage/ImageNetOperator.cpp | 84 +++++- .../SARImage/ImageNetOperator.h | 5 +- .../SARImage/ImagePlaneAtiInterpDialog.cpp | 32 ++- .../SARImage/ImagePlaneAtiInterpDialog.h | 3 +- .../SARImage/ImagePlaneAtiInterpDialog.ui | 248 ++++++++++-------- 5 files changed, 259 insertions(+), 113 deletions(-) diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 805d0a0..9f264cc 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -218,7 +218,16 @@ bool OverlapCheck(QString& ImageLLPath, QString& ImageDEMPath) } -void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath) +bool GPSPointsNumberEqualCheck(QString& ImageLLPath, QString& InEchoGPSDataPath) +{ + + gdalImage antimg(InEchoGPSDataPath); + gdalImage imgll(ImageLLPath); + return antimg.height == imgll.height; + +} + +void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath) { gdalImage demimg(ImageDEMPath); gdalImage imgll(ImageLLPath); @@ -230,10 +239,11 @@ void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString Eigen::MatrixXd imglonArr = imgll.getData(0, 0, imgheight, imgwidth, 1); Eigen::MatrixXd imglatArr = imgll.getData(0, 0, imgheight, imgwidth, 2); Eigen::MatrixXd imgatiArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); + Eigen::MatrixXd imgRArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); outimgll.saveImage(imglonArr, 0, 0, 1); outimgll.saveImage(imglatArr, 0, 0, 2); - +#pragma omp parallel for for (long i = 0; i < imgheight; i++) { for (long j = 0; j < imgwidth; j++) { double lon = imglonArr(i, j); // X @@ -286,6 +296,76 @@ void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString } } outimgll.saveImage(imgatiArr, 0, 0, 3); + qDebug() << u8"ÿбֵ"; + + + gdalImage antimg(InEchoGPSDataPath); + qDebug() << u8"1. زGPSļ\t"; + qDebug() << u8"ļ·\t" << InEchoGPSDataPath; + qDebug() << u8"GPS \t" << antimg.height; + qDebug() << u8"ļ\t" << antimg.width; + long prfcount = antimg.height; + + + std::shared_ptr Pxs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr Pys((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr Pzs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectX((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectY((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectZ((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + + { + long colnum = 19; + std::shared_ptr antpos = readDataArr(antimg, 0, 0, prfcount, colnum, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + double time = 0; + double Px = 0; + double Py = 0; + double Pz = 0; + for (long i = 0; i < prfcount; i++) { + + Pxs.get()[i] = antpos.get()[i * 19 + 1]; // + Pys.get()[i] = antpos.get()[i * 19 + 2]; + Pzs.get()[i] = antpos.get()[i * 19 + 3]; + AntDirectX.get()[i] = antpos.get()[i * 19 + 13];// zero doppler + AntDirectY.get()[i] = antpos.get()[i * 19 + 14]; + AntDirectZ.get()[i] = antpos.get()[i * 19 + 15]; + + double NormAnt = std::sqrt(AntDirectX.get()[i] * AntDirectX.get()[i] + + AntDirectY.get()[i] * AntDirectY.get()[i] + + AntDirectZ.get()[i] * AntDirectZ.get()[i]); + AntDirectX.get()[i] = AntDirectX.get()[i] / NormAnt; + AntDirectY.get()[i] = AntDirectY.get()[i] / NormAnt; + AntDirectZ.get()[i] = AntDirectZ.get()[i] / NormAnt;// һ + } + antpos.reset(); + } + + + +#pragma omp parallel for + for (long prfid = 0; prfid < prfcount; prfid++) { + double Px = Pxs.get()[prfid]; + double Py = Pys.get()[prfid]; + double Pz = Pzs.get()[prfid]; + double R = 0; + Landpoint LLA = {}; + Point3 XYZ = {}; + for (long j = 0; j < imgwidth; j++) { + LLA.lon = imglonArr(prfid, j); + LLA.lat = imglatArr(prfid, j); + LLA.ati = imgatiArr(prfid, j); + + LLA2XYZ(LLA, XYZ); + + R = sqrt(pow(Px - XYZ.x, 2) + + pow(Py - XYZ.y, 2) + + pow(Pz - XYZ.z, 2)); + imgRArr(prfid, j) = R; + } + } + + outimgll.saveImage(imgRArr, 0, 0, 4); + qDebug() << u8"ֵ"; } diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h index bef2c34..89b49e3 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h @@ -9,7 +9,10 @@ void InitCreateImageXYZProcess(QString& outImageLLPath, QString& outImageXYZPath bool OverlapCheck(QString& ImageLLPath, QString& ImageDEMPath); -void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath); +bool GPSPointsNumberEqualCheck(QString& ImageLLPath, QString& InEchoGPSDataPath); + + +void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath); diff --git a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp index 775312e..ead5077 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp @@ -41,6 +41,24 @@ void ImagePlaneAtiInterpDialog::onpushButtonImageNet0Select_clicked() } } +void ImagePlaneAtiInterpDialog::onpushButtonEchoGPSPointSelect_clicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡزGPSļ"), // + QString(), // Ĭ· + tr(u8"GPSļ(*.gpspos.data);;All Files(*.*)") // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditGPSPointsPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + void ImagePlaneAtiInterpDialog::onpushButtonRefRangeDEMSelect_clicked() { QString fileNames = QFileDialog::getOpenFileName( @@ -82,8 +100,8 @@ void ImagePlaneAtiInterpDialog::onbuttonBoxAccepted() QString imageNet0Path = this->ui->lineEditImageNet0Path->text().trimmed(); QString refRangeDEMPath = this->ui->lineEditRefRangeDEMPath->text().trimmed(); QString imageLLAPath = this->ui->lineEditImageLLAPath->text().trimmed(); - - if (imageNet0Path.isEmpty() || refRangeDEMPath.isEmpty() || imageLLAPath.isEmpty()) { + QString echoGPSDataPath = this->ui->lineEditGPSPointsPath->text().trimmed(); + if (imageNet0Path.isEmpty() || refRangeDEMPath.isEmpty() || imageLLAPath.isEmpty()||echoGPSDataPath.isEmpty()) { QMessageBox::warning(this, tr(u8"ʾ"), tr(u8"ûѡļ")); return; } @@ -91,8 +109,16 @@ void ImagePlaneAtiInterpDialog::onbuttonBoxAccepted() } + if (GPSPointsNumberEqualCheck(imageNet0Path, echoGPSDataPath)) { + } + else { + QMessageBox::warning(nullptr, u8"", u8"زGPSĿһ"); + return; + } + + if (OverlapCheck(imageNet0Path, refRangeDEMPath)) { // ????DEM??? - InterploateAtiByRefDEM(imageNet0Path, refRangeDEMPath, imageLLAPath); + InterploateAtiByRefDEM(imageNet0Path, refRangeDEMPath, imageLLAPath,echoGPSDataPath); QMessageBox::information(nullptr, u8"ʾ", u8"completed!!"); return; diff --git a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.h b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.h index 1c59bd0..5b37329 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.h +++ b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.h @@ -18,9 +18,10 @@ public: ImagePlaneAtiInterpDialog(QWidget *parent = nullptr); ~ImagePlaneAtiInterpDialog(); -public /*slots*/: +public slots: void onpushButtonImageNet0Select_clicked(); + void onpushButtonEchoGPSPointSelect_clicked(); void onpushButtonRefRangeDEMSelect_clicked(); void onpushButtonImageLLASelect_clicked(); void onbuttonBoxAccepted(); diff --git a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui index 00cbfeb..7c6e718 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui +++ b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui @@ -14,111 +14,7 @@ 根据经纬度插值高程数据 - - - - - 0 - 30 - - - - 成像网格(经纬度): - - - - - - - - 0 - 30 - - - - - - - - - - - - 0 - 30 - - - - 选择 - - - - - - - - 0 - 30 - - - - 参考DEM: - - - - - - - - 0 - 30 - - - - - - - - - - - - 0 - 30 - - - - 选择 - - - - - - - - 0 - 30 - - - - 成像粗网格(高程): - - - - - - - - 0 - 30 - - - - - - - - + @@ -131,7 +27,46 @@ - + + + + + 0 + 30 + + + + 参考DEM: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + + + + + @@ -144,6 +79,107 @@ + + + + + 0 + 30 + + + + 成像网格(经纬度): + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 成像粗网格(高程): + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 回波GPS点 + + + + + + + + 0 + 30 + + + + + + + + + 0 + 30 + + + + 选择 + + + From a8c39794ce52f945538c6e941d186cd1855e40a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Sun, 6 Apr 2025 16:52:33 +0800 Subject: [PATCH 61/94] =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=BA=86=E5=9B=9E?= =?UTF-8?q?=E6=B3=A2=E6=96=87=E4=BB=B6=E9=80=89=E6=8B=A9=E6=93=8D=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp | 1 + Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp index ead5077..6c241fa 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp @@ -14,6 +14,7 @@ ImagePlaneAtiInterpDialog::ImagePlaneAtiInterpDialog(QWidget *parent) connect(ui->pushButtonImageLLASelect, SIGNAL(clicked()), this, SLOT(onpushButtonImageLLASelect_clicked())); connect(ui->pushButtonImageNet0Select, SIGNAL(clicked()), this, SLOT(onpushButtonImageNet0Select_clicked())); connect(ui->pushButtonRefRangeDEMSelect, SIGNAL(clicked()), this, SLOT(onpushButtonRefRangeDEMSelect_clicked())); + connect(ui->pushButtonEchoGPSPointDataSelect, SIGNAL(clicked()), this, SLOT(onpushButtonEchoGPSPointSelect_clicked())); connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbuttonBoxAccepted())); connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbuttonBoxRejected())); diff --git a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui index 7c6e718..fa3a5f2 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui +++ b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui @@ -168,7 +168,7 @@ - + 0 From eca5bc45757fdc20b36f0dbc12526599191257c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 7 Apr 2025 01:27:57 +0800 Subject: [PATCH 62/94] =?UTF-8?q?=E6=8F=92=E5=80=BC=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E8=8A=82=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SARImage/ImageNetOperator.cpp | 79 +++++++++++++------ .../SARImage/ImagePlaneAtiInterpDialog.cpp | 4 +- 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 9f264cc..8aa33c1 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -176,11 +176,11 @@ void InitCreateImageXYZProcess(QString& outImageLLPath, QString& outImageXYZPath bool OverlapCheck(QString& ImageLLPath, QString& ImageDEMPath) { // DEMǷWGS84ϵ - long demEPSG = GetEPSGFromRasterFile(ImageDEMPath); - if (demEPSG != 4326) { - qDebug() << u8"DEMϵWGS84ϵ"; - return false; - } + //long demEPSG = GetEPSGFromRasterFile(ImageDEMPath); + //if (demEPSG != 4326) { + // qDebug() << u8"DEMϵWGS84ϵ,ESPG:"<< demEPSG; + // return false; + //} gdalImage demimg(ImageDEMPath); gdalImage imgll(ImageLLPath); @@ -190,13 +190,29 @@ bool OverlapCheck(QString& ImageLLPath, QString& ImageDEMPath) Eigen::MatrixXd imglonArr = imgll.getData(0, 0, imgheight, imgwidth, 1); Eigen::MatrixXd imglatArr = imgll.getData(0, 0, imgheight, imgwidth, 2); + // ӡΧ + qDebug() << u8"ӰΧ"; + qDebug() << u8"Сȣ\t" << imglonArr.minCoeff(); + qDebug() << u8"󾭶ȣ\t" << imglonArr.maxCoeff(); + qDebug() << u8"Сγȣ\t" << imglatArr.minCoeff(); + qDebug() << u8"γȣ\t" << imglatArr.maxCoeff(); + qDebug() << u8"DEMΧ"; + RasterExtend demextend = demimg.getExtend(); + qDebug() << u8"Сȣ\t" << demextend.min_x; + qDebug() << u8"󾭶ȣ\t" << demextend.max_x; + qDebug() << u8"Сγȣ\t" << demextend.min_y; + qDebug() << u8"γȣ\t" << demextend.max_y; + qDebug() << u8"ӰС\t" << demimg.height << " * " << demimg.width; + + + for (long i = 0; i < imgheight; i++) { for (long j = 0; j < imgwidth; j++) { double lon = imglonArr(i, j); // X double lat = imglatArr(i, j); // Y - Landpoint point = imgll.getRow_Col(lon, lat); + Landpoint point = demimg.getRow_Col(lon, lat); imglonArr(i, j) = point.lon; imglatArr(i, j) = point.lat; } @@ -207,6 +223,14 @@ bool OverlapCheck(QString& ImageLLPath, QString& ImageDEMPath) double minY = imglatArr.minCoeff(); double maxY = imglatArr.maxCoeff(); + //ӡΧ + qDebug() << u8"dem ķΧ"; + qDebug() << u8"minX:"<demimg.width - 1 || minY<1 || maxY>demimg.height - 1) { return false; } @@ -238,42 +262,53 @@ void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString Eigen::MatrixXd imglonArr = imgll.getData(0, 0, imgheight, imgwidth, 1); Eigen::MatrixXd imglatArr = imgll.getData(0, 0, imgheight, imgwidth, 2); + Eigen::MatrixXd demArr = demimg.getData(0, 0, demimg.height, demimg.width, 1); Eigen::MatrixXd imgatiArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); Eigen::MatrixXd imgRArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); outimgll.saveImage(imglonArr, 0, 0, 1); outimgll.saveImage(imglatArr, 0, 0, 2); -#pragma omp parallel for - for (long i = 0; i < imgheight; i++) { - for (long j = 0; j < imgwidth; j++) { - double lon = imglonArr(i, j); // X - double lat = imglatArr(i, j); // Y - Landpoint point = imgll.getRow_Col(lon, lat); - imglonArr(i, j) = point.lon; - imglatArr(i, j) = point.lat; - } - } + + + double minX = imglonArr.minCoeff(); + double maxX = imglonArr.maxCoeff(); + double minY = imglatArr.minCoeff(); + double maxY = imglatArr.maxCoeff(); + //ӡΧ + qDebug() << u8"dem ķΧ"; + qDebug() << u8"minX:" << minX << "\t" << demimg.width; + qDebug() << u8"maxX:" << maxX << "\t" << demimg.width; + qDebug() << u8"minY:" << minY << "\t" << demimg.height; + qDebug() << u8"maxY:" << maxY << "\t" << demimg.height; + qDebug() << u8"ͼУ\t" << demimg.height << " , " << demimg.width; + + for (long i = 0; i < imgheight; i++) { + //printf("\rprocess:%f precent\t\t\t",i*100.0/imgheight); for (long j = 0; j < imgwidth; j++) { - double imX = imglonArr(i, j); - double imY = imglatArr(i, j); - + double lon = imglonArr(i, j); + double lat = imglatArr(i, j); + Landpoint point = demimg.getRow_Col(lon, lat); Landpoint p0, p11, p21, p12, p22; - p0.lon = imX; - p0.lat = imY; + p0.lon = point.lon; + p0.lat = point.lat; p11.lon = floor(p0.lon); p11.lat = floor(p0.lat); + p11.ati = demArr(long(p11.lat), long(p11.lon)); p12.lon = ceil(p0.lon); p12.lat = floor(p0.lat); + p12.ati = demArr(long(p12.lat), long(p12.lon)); p21.lon = floor(p0.lon); p21.lat = ceil(p0.lat); + p21.ati = demArr(long(p21.lat), long(p21.lon)); p22.lon = ceil(p0.lon); p22.lat = ceil(p0.lat); + p22.ati = demArr(long(p22.lat), long(p22.lon)); p0.lon = p0.lon - p11.lon; p0.lat = p0.lat - p11.lat; @@ -290,7 +325,7 @@ void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString p11.lon = p11.lon - p11.lon; p11.lat = p11.lat - p11.lat; - Bilinear_interpolation(p0, p11, p21, p12, p22); + p0.ati=Bilinear_interpolation(p0, p11, p21, p12, p22); imgatiArr(i, j) = p0.ati; } diff --git a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp index 6c241fa..54c7de1 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp @@ -80,7 +80,7 @@ void ImagePlaneAtiInterpDialog::onpushButtonRefRangeDEMSelect_clicked() void ImagePlaneAtiInterpDialog::onpushButtonImageLLASelect_clicked() { - QString fileNames = QFileDialog::getOpenFileName( + QString fileNames = QFileDialog::getSaveFileName( this, // ?????? tr(u8"ʾ"), // ???? QString(), // ????? @@ -88,7 +88,7 @@ void ImagePlaneAtiInterpDialog::onpushButtonImageLLASelect_clicked() ); // ?????????????? if (!fileNames.isEmpty()) { - QString message = "?????????\n"; + QString message = "ѡļ\n"; this->ui->lineEditImageLLAPath->setText(fileNames); } else { From 5bc08bb24258d6e855a17f844fe07c5d80be2e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 7 Apr 2025 10:33:12 +0800 Subject: [PATCH 63/94] =?UTF-8?q?=E8=A1=A5=E5=85=85InSAR=E7=9A=84=E6=88=90?= =?UTF-8?q?=E5=83=8F=E7=9A=84=E7=9B=B8=E5=85=B3=E5=B7=A5=E5=85=B7=E7=AE=B1?= =?UTF-8?q?=201.=20=E5=A2=9E=E5=8A=A0=E4=BA=86InSAR=E6=88=90=E5=83=8F?= =?UTF-8?q?=E5=B9=B3=E9=9D=A2=E6=96=87=E4=BB=B6=E7=94=9F=E6=88=90=202.=20B?= =?UTF-8?q?P=E6=88=90=E5=83=8F=E4=B8=AD=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E5=8F=82=E8=80=83=E8=B7=9D=E7=A6=BB=E7=9A=84=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LookTableSimulationComputer.cu | 126 ++++++ .../LookTableSimulationComputer.cuh | 18 + .../QCreateInSARImagePlaneXYZRDialog.cpp | 385 ++++++++++++++++++ .../QCreateInSARImagePlaneXYZRDialog.h | 70 ++++ .../QCreateInSARImagePlaneXYZRDialog.ui | 293 +++++++++++++ .../SimulationSAR/BPBasic0_CUDA.cu | 18 +- .../SimulationSAR/BPBasic0_CUDA.cuh | 2 +- .../SimulationSAR/TBPImageAlgCls.cpp | 12 + .../SimulationSARTool/SimulationSARTool.cpp | 19 + Toolbox/SimulationSARTool/SimulationSARTool.h | 11 + .../SimulationSARTool.vcxproj | 3 + .../SimulationSARTool.vcxproj.filters | 11 +- 12 files changed, 961 insertions(+), 7 deletions(-) create mode 100644 Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.cpp create mode 100644 Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.h create mode 100644 Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.ui diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cu b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cu index 6d6e7ef..2252520 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cu +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cu @@ -145,6 +145,87 @@ __global__ void Kernel_RDProcess_doppler( +__global__ void Kernel_RDProcess_doppler_calRangeDistance( + double* demX, double* demY, double* demZ, + double* outR, + long pixelcount, + double Xp0, double Yp0, double Zp0, double Xv0, double Yv0, double Zv0, + double Xp1, double Yp1, double Zp1, double Xv1, double Yv1, double Zv1, + double Xp2, double Yp2, double Zp2, double Xv2, double Yv2, double Zv2, + double Xp3, double Yp3, double Zp3, double Xv3, double Yv3, double Zv3, + double Xp4, double Yp4, double Zp4, double Xv4, double Yv4, double Zv4, + double Xp5, double Yp5, double Zp5, double Xv5, double Yv5, double Zv5, + double reftime, double r0, double r1, double r2, double r3, double r4, + double starttime, double nearRange, double farRange, + double PRF, double Fs, + double fact_lamda +) { + long idx = blockIdx.x * blockDim.x + threadIdx.x; + if (idx < pixelcount) { + double demx = demX[idx]; + double demy = demY[idx]; + double demz = demZ[idx]; + double dt = 1.0 / PRF / 3; + double Spx = 0, Spy = 0, Spz = 0, Svx = 0, Svy = 0, Svz = 0; + double Rx = 0, Ry = 0, Rz = 0, R = 0; + + double dp1 = 0, dpn1 = 0, dp2 = 0, dpn2 = 0; + + double ti = 0; + double inct = 0; + for (long i = 0; i < 10000; i++) { // Χ + Spx = getPolyfitNumber(ti + dt, Xp0, Xp1, Xp2, Xp3, Xp4, Xp5); + Spy = getPolyfitNumber(ti + dt, Yp0, Yp1, Yp2, Yp3, Yp4, Yp5); + Spz = getPolyfitNumber(ti + dt, Zp0, Zp1, Zp2, Zp3, Zp4, Zp5); + Svx = getPolyfitNumber(ti + dt, Xv0, Xv1, Xv2, Xv3, Xv4, Xv5); + Svy = getPolyfitNumber(ti + dt, Yv0, Yv1, Yv2, Yv3, Yv4, Yv5); + Svz = getPolyfitNumber(ti + dt, Zv0, Zv1, Zv2, Zv3, Zv4, Zv5); + + Rx = Spx - demx; + Ry = Spy - demy; + Rz = Spz - demz; + R = sqrt(Rx * Rx + Ry * Ry + Rz * Rz); + Rx = Rx / R; + Ry = Ry / R; + Rz = Rz / R; + + dp2 = getDopplerCenterRate(Rx, Ry, Rz, Svx, Svy, Svz, fact_lamda); + dpn2 = getNumberDopplerCenterRate(R, r0, r1, r2, r3, r4, reftime); + + // ti + Spx = getPolyfitNumber(ti, Xp0, Xp1, Xp2, Xp3, Xp4, Xp5); + Spy = getPolyfitNumber(ti, Yp0, Yp1, Yp2, Yp3, Yp4, Yp5); + Spz = getPolyfitNumber(ti, Zp0, Zp1, Zp2, Zp3, Zp4, Zp5); + Svx = getPolyfitNumber(ti, Xv0, Xv1, Xv2, Xv3, Xv4, Xv5); + Svy = getPolyfitNumber(ti, Yv0, Yv1, Yv2, Yv3, Yv4, Yv5); + Svz = getPolyfitNumber(ti, Zv0, Zv1, Zv2, Zv3, Zv4, Zv5); + + Rx = Spx - demx; + Ry = Spy - demy; + Rz = Spz - demz; + R = sqrt(Rx * Rx + Ry * Ry + Rz * Rz); + Rx = Rx / R; + Ry = Ry / R; + Rz = Rz / R; + + dp1 = getDopplerCenterRate(Rx, Ry, Rz, Svx, Svy, Svz, fact_lamda); + dpn1 = getNumberDopplerCenterRate(R, r0, r1, r2, r3, r4, reftime); + + // iter + inct = dt * (dp2 - dpn1) / (dp1 - dp2); + + if (abs(inct) <= dt || isnan(inct)) { + outR[idx] = R;//Rd_c; + return; + } + ti = ti + inct; + } + outR[idx] = 0; + } +} + + + void RDProcess_dopplerGPU( @@ -185,6 +266,51 @@ void RDProcess_dopplerGPU( cudaDeviceSynchronize(); } + + +void RDProcess_dopplerGPU_InSARImagePlaneXYZR( + double* demX, double* demY, double* demZ, + double* outR, + long rowcount, long colcount, + double starttime, double nearRange, double farRange, + double PRF, double Fs, + double fact_lamda, + double Xp0, double Yp0, double Zp0, double Xv0, double Yv0, double Zv0, + double Xp1, double Yp1, double Zp1, double Xv1, double Yv1, double Zv1, + double Xp2, double Yp2, double Zp2, double Xv2, double Yv2, double Zv2, + double Xp3, double Yp3, double Zp3, double Xv3, double Yv3, double Zv3, + double Xp4, double Yp4, double Zp4, double Xv4, double Yv4, double Zv4, + double Xp5, double Yp5, double Zp5, double Xv5, double Yv5, double Zv5, + double reftime, double r0, double r1, double r2, double r3, double r4 + +) +{ + long pixelcount = rowcount * colcount; + int numBlocks = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; + Kernel_RDProcess_doppler_calRangeDistance << > > ( + demX, demY, demZ, + outR, + pixelcount, + Xp0, Yp0, Zp0, Xv0, Yv0, Zv0, + Xp1, Yp1, Zp1, Xv1, Yv1, Zv1, + Xp2, Yp2, Zp2, Xv2, Yv2, Zv2, + Xp3, Yp3, Zp3, Xv3, Yv3, Zv3, + Xp4, Yp4, Zp4, Xv4, Yv4, Zv4, + Xp5, Yp5, Zp5, Xv5, Yv5, Zv5, + reftime, r0, r1, r2, r3, r4, + starttime, nearRange, farRange, + PRF, Fs, + fact_lamda + ); + PrintLasterError("RD with doppler function"); + cudaDeviceSynchronize(); +} + + + + + + __device__ double calculateIncidenceAngle(double Rx, double Ry, double Rz, double Sx, double Sy, double Sz) { double dotProduct = Rx * Sx + Ry * Sy + Rz * Sz; double magnitudeR = sqrt(Rx * Rx + Ry * Ry + Rz * Rz); diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cuh b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cuh index 1ce140e..a697719 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cuh +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/LookTableSimulationComputer.cuh @@ -57,3 +57,21 @@ extern "C" void RDProcess_demSloperGPU( ); + + + +extern "C" void RDProcess_dopplerGPU_InSARImagePlaneXYZR( + double* demX, double* demY, double* demZ, + double* outR, + long rowcount, long colcount, + double starttime, double nearRange, double farRange, + double PRF, double Fs, + double fact_lamda, + double Xp0, double Yp0, double Zp0, double Xv0, double Yv0, double Zv0, + double Xp1, double Yp1, double Zp1, double Xv1, double Yv1, double Zv1, + double Xp2, double Yp2, double Zp2, double Xv2, double Yv2, double Zv2, + double Xp3, double Yp3, double Zp3, double Xv3, double Yv3, double Zv3, + double Xp4, double Yp4, double Zp4, double Xv4, double Yv4, double Zv4, + double Xp5, double Yp5, double Zp5, double Xv5, double Yv5, double Zv5, + double reftime, double r0, double r1, double r2, double r3, double r4 +); \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.cpp b/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.cpp new file mode 100644 index 0000000..732557c --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.cpp @@ -0,0 +1,385 @@ +#include "QCreateInSARImagePlaneXYZRDialog.h" +#include "ui_QCreateInSARImagePlaneXYZRDialog.h" +#include +#include + +#include "SatelliteOribtModel.h" +#include "SARSimulationTaskSetting.h" +#include "ImageOperatorBase.h" +#include "FileOperator.h" +#include "BaseConstVariable.h" +#include "GPUTool.cuh" +#include "LookTableSimulationComputer.cuh" +#include + +#include "ImageShowDialogClass.h" +#include "QToolProcessBarDialog.h" + +QCreateInSARImagePlaneXYZRDialog::QCreateInSARImagePlaneXYZRDialog(QWidget* parent) + : QDialog(parent), ui(new Ui::QCreateInSARImagePlaneXYZRDialogClass) +{ + ui->setupUi(this); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onaccepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onrejected())); + connect(ui->pushButtonDEM, SIGNAL(clicked(bool)), this, SLOT(onpushButtonDEMClicked(bool))); + connect(ui->pushButtonSloper, SIGNAL(clicked(bool)), this, SLOT(onpushButtonSloperClicked(bool))); + connect(ui->pushButtonOrbitModel, SIGNAL(clicked(bool)), this, SLOT(onpushButtonOrbitModelClicked(bool))); + connect(ui->pushButtonOutDir, SIGNAL(clicked(bool)), this, SLOT(onpushButtonOutDirClicked(bool))); + connect(ui->pushButtonSataSetting, SIGNAL(clicked(bool)), this, SLOT(onpushButtonSataSettingClicked(bool))); + + + +} + +QCreateInSARImagePlaneXYZRDialog::~QCreateInSARImagePlaneXYZRDialog() +{ + +} + +void QCreateInSARImagePlaneXYZRDialog::onrejected() +{ + this->close(); +} + +void QCreateInSARImagePlaneXYZRDialog::onpushButtonOrbitModelClicked(bool) +{ + // ļѡԻѡһ .tif ļ + QString fileName = QFileDialog::getOpenFileName(this, + u8"GPS Orbit Model xml", // Ի + "", // ʼĿ¼Ϊ· + u8"xml Files (*.xml)"); // ļ͹ + + if (!fileName.isEmpty()) { + this->ui->OrbitModelPathLineEdit->setText(fileName); + } + else { + QMessageBox::information(this, u8"ûѡļ", u8"ûѡκļ"); + } +} + +void QCreateInSARImagePlaneXYZRDialog::onpushButtonSataSettingClicked(bool) +{ + // ļѡԻѡһ .tif ļ + QString fileName = QFileDialog::getOpenFileName(this, + u8"Satellite Params setting xml", // Ի + "", // ʼĿ¼Ϊ· + u8"xml Files (*.xml)"); // ļ͹ + + if (!fileName.isEmpty()) { + this->ui->SateSettingLineEdit->setText(fileName); + } + else { + QMessageBox::information(this, u8"ûѡļ", u8"ûѡκļ"); + } +} + +void QCreateInSARImagePlaneXYZRDialog::onpushButtonDEMClicked(bool) +{ + // ļѡԻѡһ .tif ļ + QString fileName = QFileDialog::getOpenFileName(this, + u8"DEM XYZ Raster Select", // Ի + "", // ʼĿ¼Ϊ· + u8"tiff Files (*.tiff);;tif Files (*.tif);;dat Files (*.dat);;All Files (*.*)"); // ļ͹ + + if (!fileName.isEmpty()) { + this->ui->DEMLineEdit->setText(fileName); + } + else { + QMessageBox::information(this, u8"ûѡļ", u8"ûѡκļ"); + } +} + +void QCreateInSARImagePlaneXYZRDialog::onpushButtonSloperClicked(bool) +{ + // ļѡԻѡһ .tif ļ + QString fileName = QFileDialog::getOpenFileName(this, + u8"DEM Sloper Raster Select", // Ի + "", // ʼĿ¼Ϊ· + u8"tiff Files (*.tiff);;tif Files (*.tif);;dat Files (*.dat);;All Files (*.*)"); // ļ͹ + + if (!fileName.isEmpty()) { + this->ui->SloperLineEdit->setText(fileName); + } + else { + QMessageBox::information(this, u8"ûѡļ", u8"ûѡκļ"); + } +} + +void QCreateInSARImagePlaneXYZRDialog::onpushButtonOutDirClicked(bool) +{ + // ļѡԻѡһ .tif ļ + QString fileName = QFileDialog::getExistingDirectory(this, + u8"DEM Raster Select", // Ի + "" // ʼĿ¼Ϊ· + ); + if (!fileName.isEmpty()) { + this->ui->outDirLineEdit->setText(fileName); + } + else { + QMessageBox::information(this, u8"ûѡļ", u8"ûѡκļ"); + } +} + +void QCreateInSARImagePlaneXYZRDialog::LookTableSimualtionMainProcess(QString sateName, QString orbitpath, QString SatePath, QString DEMPath, QString outDirPath) +{ + + 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; + orbitmodel.loadFromXml(orbitpath); + + // + long double OribtStartTime = orbitmodel.getOribtStartTime(); + std::vector PolyfitPx = orbitmodel.getPolyfitPx(); + std::vector PolyfitPy = orbitmodel.getPolyfitPy(); + std::vector PolyfitPz = orbitmodel.getPolyfitPz(); + std::vector PolyfitVx = orbitmodel.getPolyfitVx(); + std::vector PolyfitVy = orbitmodel.getPolyfitVy(); + std::vector PolyfitVz = orbitmodel.getPolyfitVz(); + + + // ģ + qDebug() << "load simulation setting params from xml :" << orbitpath; + std::shared_ptr SARSetting = ReadSimulationSettingsXML(SatePath); + + // ղ + double dopplerRefrenceTime = SARSetting->getDopplerParametersReferenceTime(); + std::vector DopplerCentroidCoefficients = SARSetting->getDopplerCentroidCoefficients(); + std::vector 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); + + + outLookTablePath = JoinPath(outDirPath, sateName + "_looktable.bin"); + + this->ui->label_tip->setText(u8"look table create..."); + + this->LookTableSimulationDopplerProcess( + DEMPath, + outLookTablePath, + OribtStartTime, + PolyfitPx, PolyfitPy, PolyfitPz, + PolyfitVx, PolyfitVy, PolyfitVz, + dopplerRefrenceTime, + DopplerCentroidCoefficients, + startTime, + endTime, + nearRange, + farRange, + PRF, + Fs, + lamda + ); +} + +void QCreateInSARImagePlaneXYZRDialog::LookTableSimulationDopplerProcess(QString DEMPath, QString outLookTablePath, long double OribtStartTime, std::vector PolyfitPx, std::vector PolyfitPy, std::vector PolyfitPz, std::vector PolyfitVx, std::vector PolyfitVy, std::vector PolyfitVz, double dopplerRefrenceTime, std::vector DopplerCentroidCoefficients, double starttime, double endtime, double nearRange, double farRange, double PRF, double Fs, double lamda) +{ + qDebug() << "generate look table "; + qDebug() << "DEMPath\t" << DEMPath; + qDebug() << "outLookTablePath\t" << outLookTablePath; + + gdalImage demimg(DEMPath); + gdalImage outLookTable = CreategdalImage( // ұ + outLookTablePath, + demimg.height, demimg.width, 4, + 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 * 2000));//2GB + GPUMemoryline = GPUMemoryline < 1 ? 1 : GPUMemoryline; + + // ڴԤ + + double fact_lamda = 1 / lamda; + for (long rid = 0; rid < demimg.height; rid = rid + GPUMemoryline) { + long rowcount = GPUMemoryline; + long colcount = demimg.width; + qDebug() << "computer read file : " << rid << "~" << rowcount + rid << "\t:" << demimg.height; + //double* tmep = new double[rowcount * colcount]; + std::shared_ptr demX = readDataArr(demimg, rid, 0, rowcount, colcount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD);// ޸ + std::shared_ptr demY = readDataArr(demimg, rid, 0, rowcount, colcount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demZ = readDataArr(demimg, rid, 0, rowcount, colcount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + // + std::shared_ptr host_R((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + + std::shared_ptr device_R((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); + + // + std::shared_ptr host_demX((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + std::shared_ptr host_demY((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + std::shared_ptr host_demZ((double*)mallocCUDAHost(sizeof(double) * rowcount * demimg.width), FreeCUDAHost); + + std::shared_ptr device_demX((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); + std::shared_ptr device_demY((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); + std::shared_ptr device_demZ((double*)mallocCUDADevice(sizeof(double) * rowcount * demimg.width), FreeCUDADevice); + + // ݸ + 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) * rowcount * demimg.width); + HostToDevice(host_demY.get(), device_demY.get(), sizeof(double) * rowcount * demimg.width); + HostToDevice(host_demZ.get(), device_demZ.get(), sizeof(double) * rowcount * demimg.width); + + qDebug() << "GPU computer start: " << rid << "~" << rowcount + rid << "\t:" << demimg.height; + RDProcess_dopplerGPU_InSARImagePlaneXYZR( + device_demX.get(), device_demY.get(), device_demZ.get(), + device_R.get(), + rowcount, colcount, + starttime, nearRange, farRange, + PRF, Fs, + fact_lamda, + Xp0, Yp0, Zp0, Xv0, Yv0, Zv0, + Xp1, Yp1, Zp1, Xv1, Yv1, Zv1, + Xp2, Yp2, Zp2, Xv2, Yv2, Zv2, + Xp3, Yp3, Zp3, Xv3, Yv3, Zv3, + Xp4, Yp4, Zp4, Xv4, Yv4, Zv4, + Xp5, Yp5, Zp5, Xv5, Yv5, Zv5, + dopplerRefrenceTime, r0, r1, r2, r3, r4); + + + // GPU -> ڴ + DeviceToHost(host_R.get(), device_R.get(), sizeof(double) * rowcount * demimg.width); + qDebug() << "GPU computer finished!!: " << rid << "~" << rowcount + rid << "\t:" << demimg.height; + //exit(-1); + // ݴ洢 + outLookTable.saveImage(demX, rid, 0, rowcount, colcount, 1); + outLookTable.saveImage(demY, rid, 0, rowcount, colcount, 2); + outLookTable.saveImage(demZ, rid, 0, rowcount, colcount, 3); + outLookTable.saveImage(host_R, rid, 0, rowcount, colcount, 4); + + qDebug() << "GPU computer result write finished: " << rid << " ~ " << rowcount + rid << "\t:" << demimg.height; + + } + + qDebug() << "look table computed finished!!!"; + } + +void QCreateInSARImagePlaneXYZRDialog::onaccepted() +{ + QString orbitpath = this->ui->OrbitModelPathLineEdit->text(); + QString SatePath = this->ui->SateSettingLineEdit->text(); + QString DEMPath = this->ui->DEMLineEdit->text(); + QString outDirPath = this->ui->outDirLineEdit->text(); + + QString simulationName = this->ui->lineEditLookName->text(); + this->LookTableSimualtionMainProcess( + simulationName, + orbitpath, SatePath, DEMPath, outDirPath + ); + QMessageBox::information(this, u8"info", u8"completed!!!"); + +} diff --git a/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.h b/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.h new file mode 100644 index 0000000..d071ee9 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.h @@ -0,0 +1,70 @@ +#pragma once + +#include + + +namespace Ui { + class QCreateInSARImagePlaneXYZRDialogClass; +} + +class QCreateInSARImagePlaneXYZRDialog : public QDialog +{ + Q_OBJECT + +public: + QCreateInSARImagePlaneXYZRDialog(QWidget *parent = nullptr); + ~QCreateInSARImagePlaneXYZRDialog(); + +private: + Ui::QCreateInSARImagePlaneXYZRDialogClass* ui; + + +public slots: + void onaccepted(); + void onrejected(); + + void onpushButtonOrbitModelClicked(bool); + void onpushButtonSataSettingClicked(bool); + void onpushButtonDEMClicked(bool); + void onpushButtonSloperClicked(bool); + void onpushButtonOutDirClicked(bool); + + + +private: // doppler + void LookTableSimualtionMainProcess( + QString sateName, + QString orbitpath, QString SatePath, QString DEMPath, QString outDirPath + ); + + void LookTableSimulationDopplerProcess( + QString DEMPath, + QString outLookTablePath, + + // ʽ + long double OribtStartTime, // ģͲοʱ + std::vector PolyfitPx, // 50 + std::vector PolyfitPy, // 50 + std::vector PolyfitPz, // 50 + std::vector PolyfitVx, // 50 + std::vector PolyfitVy, // 50 + std::vector PolyfitVz, // 50 + + + // ղ + double dopplerRefrenceTime, + std::vector DopplerCentroidCoefficients,// d0 ~ d5 + + // + double starttime, // ʼʱ + double endtime, // ʱ + double nearRange, // б + double farRange, // Զб + double PRF, // ظƵ + double Fs, // Ƶ + double lamda + ); + + + +}; diff --git a/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.ui b/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.ui new file mode 100644 index 0000000..c90b83d --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.ui @@ -0,0 +1,293 @@ + + + QCreateInSARImagePlaneXYZRDialogClass + + + + 0 + 0 + 763 + 498 + + + + QCreateInSARImagePlaneXYZR + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\LT1A_DEM_20250210_resampleXYZ.dat + + + + + + + 采用多普勒参数 + + + true + + + + + + + + 0 + 30 + + + + 卫星仿真参数: + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + DEM文件(XYZ) + + + + + + + + 0 + 30 + + + + 坡度法向文件(sloper) + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\LT1_Simulation_OrbitModel.xml + + + + + + + + 0 + 30 + + + + LT1A_20250210 + + + + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\Looktable + + + + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 多项式轨道模型参数: + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\LT1A_DEM_20250210_resampleXYZ.dat + + + + + + + + 0 + 30 + + + + 结果文件保存地址: + + + + + + + + 0 + 30 + + + + 成像平面文件名 + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + D:\FZSimulation\LT1A\L20250210\LT1_Simulation_Setting.xml + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu index cdf1705..761114b 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu @@ -56,7 +56,7 @@ __global__ void fftshiftKernel(cufftComplex* data, int Nfft, int Np) { __global__ void processPulseKernel( long prfid, int nx, int ny, - const double* x_mat, const double* y_mat, const double* z_mat, + const double* x_mat, const double* y_mat, const double* z_mat,const double* R_mat, double AntX, double AntY, double AntZ, double R0, double minF, const cufftComplex* rc_pulse, @@ -78,6 +78,7 @@ __global__ void processPulseKernel( double dx = AntX - x_mat[idx]; double dy = AntY - y_mat[idx]; double dz = AntZ - z_mat[idx]; + double initR = R_mat[idx]; //printf("processPulseKernel xmat !!\n"); double R = sqrt(dx * dx + dy * dy + dz * dz); @@ -98,7 +99,7 @@ __global__ void processPulseKernel( rc_interp.y = rc_low.y * (1 - weight) + rc_high.y * weight; // Phase correction - double phase = 4 * PI * minF / c * dR; + double phase = 4 * PI * minF / c * (dR- initR); // 䵱ǰIJο double cos_phase = cos(phase); double sin_phase = sin(phase); @@ -109,8 +110,12 @@ __global__ void processPulseKernel( // Accumulate im_final[idx].x += phCorr.x; im_final[idx].y += phCorr.y; + + + + //printf("r_start=%e;dr=%e;nR=%d\n", r_start, dr, nR); - if (abs(phCorr.x) > 1e-100 || abs(phCorr.y > 1e-100)) { + //if (abs(phCorr.x) > 1e-100 || abs(phCorr.y > 1e-100)) { //printf( // "[DEBUG] prfid=%-4ld | idx=%-8lld\n" // " Ant: X=%-18.10e Y=%-18.10e Z=%-18.10e\n" @@ -133,7 +138,7 @@ __global__ void processPulseKernel( // phCorr.x, phCorr.y, // im_final[idx].x, im_final[idx].y //); - } + //} } void bpBasic0CUDA(GPUDATA& data, int flag,double* h_R) { @@ -177,7 +182,7 @@ void bpBasic0CUDA(GPUDATA& data, int flag,double* h_R) { processPulseKernel << > > ( ii, data.nx, data.ny, - data.x_mat, data.y_mat, data.z_mat, + data.x_mat, data.y_mat, data.z_mat,data.R_mat, data.AntX[ii], data.AntY[ii], data.AntZ[ii], data.R0, data.minF[ii], data.phdata, @@ -206,6 +211,7 @@ void initGPUData(GPUDATA& h_data, GPUDATA& d_data) { d_data.x_mat = (double*)mallocCUDADevice(sizeof(double) * h_data.nx * h_data.ny); d_data.y_mat = (double*)mallocCUDADevice(sizeof(double) * h_data.nx * h_data.ny); d_data.z_mat = (double*)mallocCUDADevice(sizeof(double) * h_data.nx * h_data.ny); + d_data.R_mat = (double*)mallocCUDADevice(sizeof(double) * h_data.nx * h_data.ny); d_data.r_vec = h_data.r_vec;// (double*)mallocCUDADevice(sizeof(double) * h_data.Nfft); d_data.Freq = (double*)mallocCUDADevice(sizeof(double) * h_data.Nfft); d_data.phdata = (cuComplex*)mallocCUDADevice(sizeof(cuComplex) * h_data.Nfft * h_data.Np); @@ -218,6 +224,7 @@ void initGPUData(GPUDATA& h_data, GPUDATA& d_data) { HostToDevice(h_data.x_mat, d_data.x_mat,sizeof(double) * h_data.nx * h_data.ny); printf("image X Copy finished!!!\n"); HostToDevice(h_data.y_mat, d_data.y_mat,sizeof(double) * h_data.nx * h_data.ny); printf("image Y Copy finished!!!\n"); HostToDevice(h_data.z_mat, d_data.z_mat, sizeof(double) * h_data.nx * h_data.ny); printf("image Z Copy finished!!!\n"); + HostToDevice(h_data.R_mat, d_data.R_mat, sizeof(double) * h_data.nx * h_data.ny); printf("image R Copy finished!!!\n"); HostToDevice(h_data.Freq, d_data.Freq, sizeof(double) * h_data.Nfft); //HostToDevice(h_data.r_vec, d_data.r_vec, sizeof(double) * h_data.Nfft); HostToDevice(h_data.phdata, d_data.phdata, sizeof(cuComplex) * h_data.Nfft * h_data.Np); printf("image echo Copy finished!!!\n"); @@ -242,6 +249,7 @@ void freeGPUData(GPUDATA& d_data) { FreeCUDADevice((d_data.x_mat)); FreeCUDADevice((d_data.y_mat)); FreeCUDADevice((d_data.z_mat)); + FreeCUDADevice((d_data.R_mat)); //FreeCUDADevice((d_data.r_vec)); FreeCUDADevice((d_data.Freq)); FreeCUDADevice((d_data.phdata)); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cuh b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cuh index c971640..8cfd5cd 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cuh +++ b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cuh @@ -21,7 +21,7 @@ struct GPUDATA { long Nfft, K, Np, nx, ny; // ҶƵͼСͼ double* AntX, * AntY, * AntZ, * minF; // ꡢʼƵ - double* x_mat, * y_mat, * z_mat;// + double* x_mat, * y_mat, * z_mat,*R_mat;// double* r_vec; // 귶Χ double* Freq;// Ƶ cuComplex* phdata;// ز diff --git a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp index 9b64590..50b4422 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp @@ -178,6 +178,18 @@ ErrorCode TBPImageAlgCls::ProcessGPU() std::shared_ptr demX = readDataArr(demgridimg, img_start_rid, 0, img_blockRowCount, img_blockColCount, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); std::shared_ptr demY = readDataArr(demgridimg, img_start_rid, 0, img_blockRowCount, img_blockColCount, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); std::shared_ptr demZ = readDataArr(demgridimg, img_start_rid, 0, img_blockRowCount, img_blockColCount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demR= demgridimg.band_num==3? + readDataArr(demgridimg, img_start_rid, 0, img_blockRowCount, img_blockColCount, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD): + readDataArr(demgridimg, img_start_rid, 0, img_blockRowCount, img_blockColCount, 4, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + if (nullptr == demR) { + for (long i = 0; i < img_blockRowCount; i++) { + for (long j = 0; j < img_blockColCount; j++) { + demR.get()[i * img_blockColCount + j] = 0; + } + } + } + h_data.x_mat = (double*)mallocCUDAHost(sizeof(double) * img_blockRowCount * img_blockColCount); // 成像网格 h_data.y_mat = (double*)mallocCUDAHost(sizeof(double) * img_blockRowCount * img_blockColCount); diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index bee3038..d1afb96 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -9,6 +9,7 @@ #include "QtLinearToIntenisityDialog.h" #include "InitCreateImageXYZDialog.h" #include "ImagePlaneAtiInterpDialog.h" +#include "QCreateInSARImagePlaneXYZRDialog.h" SARSimlulationRFPCToolButton::SARSimlulationRFPCToolButton(QWidget* parent) @@ -80,6 +81,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QtLinearToIntenisityToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new InitCreateImageXYZToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new ImagePlaneAtiInterpToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QCreateInSARImagePlaneXYZRToolButton(toolbox)); } @@ -181,3 +183,20 @@ void ImagePlaneAtiInterpToolButton::run() ImagePlaneAtiInterpDialog* dialog = new ImagePlaneAtiInterpDialog; dialog->show(); } + +QCreateInSARImagePlaneXYZRToolButton::QCreateInSARImagePlaneXYZRToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"񹤾߿"); + this->toolname = QString(u8"1.InSARƽ"); +} + +QCreateInSARImagePlaneXYZRToolButton::~QCreateInSARImagePlaneXYZRToolButton() +{ +} + +void QCreateInSARImagePlaneXYZRToolButton::run() +{ + QCreateInSARImagePlaneXYZRDialog* dialog = new QCreateInSARImagePlaneXYZRDialog; + dialog->show(); +} diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.h b/Toolbox/SimulationSARTool/SimulationSARTool.h index 1d356f2..61d9f4e 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.h +++ b/Toolbox/SimulationSARTool/SimulationSARTool.h @@ -119,6 +119,17 @@ public: }; + +class SIMULATIONSARTOOL_EXPORT QCreateInSARImagePlaneXYZRToolButton : public QToolAbstract { + Q_OBJECT +public: + QCreateInSARImagePlaneXYZRToolButton(QWidget* parent = nullptr); + ~QCreateInSARImagePlaneXYZRToolButton(); +public: + virtual void run() override; + +}; + extern "C" SIMULATIONSARTOOL_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 1562e03..105c02d 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -217,6 +217,7 @@ + @@ -245,6 +246,7 @@ + @@ -281,6 +283,7 @@ + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index 6c8fd72..82c544b 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -80,7 +80,7 @@ SARImage - + SARImage @@ -145,6 +145,9 @@ SARImage + + SARImage + @@ -180,6 +183,9 @@ SARImage + + SARImage + @@ -215,6 +221,9 @@ SARImage + + Header Files + From 747c6399afb1d1a8ba145605563e3e684140013c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 7 Apr 2025 10:36:51 +0800 Subject: [PATCH 64/94] =?UTF-8?q?=E8=BE=93=E5=87=BA=E8=BD=A8=E9=81=93?= =?UTF-8?q?=E5=A4=9A=E9=A1=B9=E5=BC=8F=E6=A8=A1=E5=9E=8B=E7=9A=84=E7=B2=BE?= =?UTF-8?q?=E5=BA=A6=E4=B8=BA=2036=20=E4=B8=AA=E6=9C=89=E6=95=88=E6=95=B0?= =?UTF-8?q?=E5=AD=97=EF=BC=88=E5=B9=B6=E4=B8=8D=E6=84=8F=E5=91=B3=E5=AE=9E?= =?UTF-8?q?=E9=99=85=E7=B2=BE=E5=BA=A6=E8=83=BD=E5=88=B036=E4=B8=AA?= =?UTF-8?q?=E6=9C=89=E6=95=88=E6=95=B0=E5=AD=97=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSAR/SatelliteOribtModel.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SatelliteOribtModel.cpp b/Toolbox/SimulationSARTool/SimulationSAR/SatelliteOribtModel.cpp index fb99f27..6ad68c4 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SatelliteOribtModel.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/SatelliteOribtModel.cpp @@ -467,12 +467,12 @@ void PolyfitSatelliteOribtModel::saveToXml(const QString& filePath) { // Write polyfit parameters xmlWriter.writeStartElement("PolyfitParameters"); - xmlWriter.writeAttribute("Pxchisq", QString::number(Pxchisq)); - xmlWriter.writeAttribute("Pychisq", QString::number(Pychisq)); - xmlWriter.writeAttribute("Pzchisq", QString::number(Pzchisq)); - xmlWriter.writeAttribute("Vxchisq", QString::number(Vxchisq)); - xmlWriter.writeAttribute("Vychisq", QString::number(Vychisq)); - xmlWriter.writeAttribute("Vzchisq", QString::number(Vzchisq)); + xmlWriter.writeAttribute("Pxchisq", QString::number(Pxchisq,'e',35)); + xmlWriter.writeAttribute("Pychisq", QString::number(Pychisq,'e',35)); + xmlWriter.writeAttribute("Pzchisq", QString::number(Pzchisq,'e',35)); + xmlWriter.writeAttribute("Vxchisq", QString::number(Vxchisq,'e',35)); + xmlWriter.writeAttribute("Vychisq", QString::number(Vychisq,'e',35)); + xmlWriter.writeAttribute("Vzchisq", QString::number(Vzchisq,'e',35)); writeVector(xmlWriter, "polyfitPx", polyfitPx); writeVector(xmlWriter, "polyfitPy", polyfitPy); @@ -491,7 +491,7 @@ void PolyfitSatelliteOribtModel::saveToXml(const QString& filePath) { void PolyfitSatelliteOribtModel::writeVector(QXmlStreamWriter& xmlWriter, const QString& name, const std::vector& vec) { xmlWriter.writeStartElement(name); for (double val : vec) { - xmlWriter.writeTextElement("Value", QString::number(val)); + xmlWriter.writeTextElement("Value", QString::number(val,'e',35)); } xmlWriter.writeEndElement(); } From 6e956d69723f43e8d1c1fb11efe04b2c8f4df69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 7 Apr 2025 10:44:35 +0800 Subject: [PATCH 65/94] =?UTF-8?q?=E6=8B=86=E5=88=86=E8=BD=AF=E4=BB=B6?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=AE=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSARTool/SimulationSARTool.cpp | 23 ++++++++++++++++--- Toolbox/SimulationSARTool/SimulationSARTool.h | 12 ++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index d1afb96..0ab1eca 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -82,7 +82,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new InitCreateImageXYZToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new ImagePlaneAtiInterpToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QCreateInSARImagePlaneXYZRToolButton(toolbox)); - + emit toolbox->addBoxToolItemSIGNAL(new QInSARBPImageToolButton(toolbox)); } LookTableComputerClassToolButton::LookTableComputerClassToolButton(QWidget* parent) @@ -187,8 +187,8 @@ void ImagePlaneAtiInterpToolButton::run() QCreateInSARImagePlaneXYZRToolButton::QCreateInSARImagePlaneXYZRToolButton(QWidget* parent) { this->toolPath = QVector(0); - this->toolPath.push_back(u8"񹤾߿"); - this->toolname = QString(u8"1.InSARƽ"); + this->toolPath.push_back(u8"InSAR湤߿"); + this->toolname = QString(u8"1.InSARؾƽ"); } QCreateInSARImagePlaneXYZRToolButton::~QCreateInSARImagePlaneXYZRToolButton() @@ -200,3 +200,20 @@ void QCreateInSARImagePlaneXYZRToolButton::run() QCreateInSARImagePlaneXYZRDialog* dialog = new QCreateInSARImagePlaneXYZRDialog; dialog->show(); } + +QInSARBPImageToolButton::QInSARBPImageToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"InSAR湤߿"); + this->toolname = QString(u8"2.InSARؾBP"); +} + +QInSARBPImageToolButton::~QInSARBPImageToolButton() +{ +} + +void QInSARBPImageToolButton::run() +{ + QSimulationBPImage* dialog = new QSimulationBPImage; + dialog->show(); +} diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.h b/Toolbox/SimulationSARTool/SimulationSARTool.h index 61d9f4e..89c51dc 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.h +++ b/Toolbox/SimulationSARTool/SimulationSARTool.h @@ -130,6 +130,18 @@ public: }; +class SIMULATIONSARTOOL_EXPORT QInSARBPImageToolButton : public QToolAbstract { + Q_OBJECT +public: + QInSARBPImageToolButton(QWidget* parent = nullptr); + ~QInSARBPImageToolButton(); +public: + virtual void run() override; + +}; + + + extern "C" SIMULATIONSARTOOL_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); From 1d2c6dbd7257cc31a179cebe8e0fbc0637ee4eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 7 Apr 2025 11:01:25 +0800 Subject: [PATCH 66/94] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=88=90=E5=83=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp index 50b4422..4766922 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp @@ -194,6 +194,8 @@ ErrorCode TBPImageAlgCls::ProcessGPU() h_data.x_mat = (double*)mallocCUDAHost(sizeof(double) * img_blockRowCount * img_blockColCount); // 成像网格 h_data.y_mat = (double*)mallocCUDAHost(sizeof(double) * img_blockRowCount * img_blockColCount); h_data.z_mat = (double*)mallocCUDAHost(sizeof(double) * img_blockRowCount * img_blockColCount); + h_data.R_mat = (double*)mallocCUDAHost(sizeof(double) * img_blockRowCount * img_blockColCount); + h_data.nx = img_blockColCount; h_data.ny = img_blockRowCount; @@ -202,6 +204,7 @@ ErrorCode TBPImageAlgCls::ProcessGPU() h_data.x_mat[i * h_data.nx + j] = demX.get()[i * h_data.nx + j]; h_data.y_mat[i * h_data.nx + j] = demY.get()[i * h_data.nx + j]; h_data.z_mat[i * h_data.nx + j] = demZ.get()[i * h_data.nx + j]; + h_data.R_mat[i * h_data.nx + j] = demR.get()[i * h_data.nx + j]; } } From d125abf0d4c53a1614bd49b5937a6046dceda362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 7 Apr 2025 11:51:47 +0800 Subject: [PATCH 67/94] =?UTF-8?q?=E4=BF=AE=E5=A4=8DInSARBPImage=E7=9A=84bu?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SARImage/QCreateInSARImagePlaneXYZRDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.cpp b/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.cpp index 732557c..52338a7 100644 --- a/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.cpp @@ -204,7 +204,7 @@ void QCreateInSARImagePlaneXYZRDialog::LookTableSimulationDopplerProcess(QString qDebug() << "outLookTablePath\t" << outLookTablePath; gdalImage demimg(DEMPath); - gdalImage outLookTable = CreategdalImage( // ұ + gdalImage outLookTable = CreategdalImageDouble( // ұ outLookTablePath, demimg.height, demimg.width, 4, demimg.gt, From 99a2d7af0f118a36eafbe3335ce370a3cb034abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 7 Apr 2025 15:22:53 +0800 Subject: [PATCH 68/94] =?UTF-8?q?=E6=88=90=E5=83=8F=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=A0=A1=E6=AD=A3=E5=9B=9E=E6=B3=A2=E9=9A=8F=E8=B7=9D=E7=A6=BB?= =?UTF-8?q?=E8=A1=B0=E5=87=8F=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h | 2 -- .../SARImage/QCreateInSARImagePlaneXYZRDialog.cpp | 5 +++-- Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h index 89b49e3..cafdfc8 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h @@ -14,6 +14,4 @@ bool GPSPointsNumberEqualCheck(QString& ImageLLPath, QString& InEchoGPSDataPath) void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath); - - #endif diff --git a/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.cpp b/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.cpp index 52338a7..44f0859 100644 --- a/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/QCreateInSARImagePlaneXYZRDialog.cpp @@ -349,8 +349,6 @@ void QCreateInSARImagePlaneXYZRDialog::LookTableSimulationDopplerProcess(QString Xp4, Yp4, Zp4, Xv4, Yv4, Zv4, Xp5, Yp5, Zp5, Xv5, Yv5, Zv5, dopplerRefrenceTime, r0, r1, r2, r3, r4); - - // GPU -> ڴ DeviceToHost(host_R.get(), device_R.get(), sizeof(double) * rowcount * demimg.width); qDebug() << "GPU computer finished!!: " << rid << "~" << rowcount + rid << "\t:" << demimg.height; @@ -383,3 +381,6 @@ void QCreateInSARImagePlaneXYZRDialog::onaccepted() QMessageBox::information(this, u8"info", u8"completed!!!"); } + + + diff --git a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu index 761114b..4a83f7a 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu @@ -82,6 +82,7 @@ __global__ void processPulseKernel( //printf("processPulseKernel xmat !!\n"); double R = sqrt(dx * dx + dy * dy + dz * dz); + double ampcorrect = (powf(4 * LAMP_CUDA_PI, 2) * powf(R, 4)); double dR = R - R0; if (dR < r_start || dR >= (r_start + dr * (nR - 1))) return; @@ -107,6 +108,10 @@ __global__ void processPulseKernel( phCorr.x = rc_interp.x * cos_phase - rc_interp.y * sin_phase; phCorr.y = rc_interp.x * sin_phase + rc_interp.y * cos_phase; + // amp correction + phCorr.x = ampcorrect * phCorr.x; + phCorr.y = ampcorrect * phCorr.y; + // Accumulate im_final[idx].x += phCorr.x; im_final[idx].y += phCorr.y; From 6d31efe86813228d8a6b5d27c16809c7b5a754fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 7 Apr 2025 17:19:55 +0800 Subject: [PATCH 69/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0112=20~120=20=E4=BD=9C?= =?UTF-8?q?=E4=B8=BA2~=2010=20=20=E7=B1=B3=E8=BE=B9=E9=95=BF=E5=AE=9A?= =?UTF-8?q?=E6=A0=87=E5=99=A8=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu | 4 +--- .../SimulationSAR/RFPCProcessCls.cpp | 8 ++++++++ .../SimulationSARTool/SimulationSAR/SigmaDatabase.cpp | 11 +++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu index 4a83f7a..f88f3f7 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu @@ -116,9 +116,7 @@ __global__ void processPulseKernel( im_final[idx].x += phCorr.x; im_final[idx].y += phCorr.y; - - - + //printf("r_start=%e;dr=%e;nR=%d\n", r_start, dr, nR); //if (abs(phCorr.x) > 1e-100 || abs(phCorr.y > 1e-100)) { //printf( diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 7001179..160d4b1 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -1133,6 +1133,14 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si size_t clscount = clsCountDict[clsid]; PRINT("Process Class ID : %d , Count: %d Device: %d , sigma Prams :[%f,%f,%f,%f,%f,%F]\n", clsid, clscount,devId, task.sigma0_cls.p1, task.sigma0_cls.p2, task.sigma0_cls.p3, task.sigma0_cls.p4, task.sigma0_cls.p5, task.sigma0_cls.p6); + if (abs(task.sigma0_cls.p1) < 1e-6 && + abs(task.sigma0_cls.p2) < 1e-6 && + abs(task.sigma0_cls.p3) < 1e-6 && + abs(task.sigma0_cls.p4) < 1e-6 && + abs(task.sigma0_cls.p5) < 1e-6 && + abs(task.sigma0_cls.p6) < 1e-6) { + continue; + } task.targetnum = clscount; task.goallist = (GoalState*)mallocCUDADevice(clscount * sizeof(GoalState), devId); HostToDevice(clsGoalStateDict[clsid].get(), task.goallist, sizeof(GoalState) * clscount); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp index 1ac11b5..366f977 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp @@ -30,6 +30,17 @@ SigmaDatabase::SigmaDatabase() this->VH_sigmaParam.insert(std::pair(0, SigmaParam{ 0,0,0, 0, 0,0 })); this->VV_sigmaParam.insert(std::pair(0, SigmaParam{ 0,0,0, 0, 0,0 })); + this->HH_sigmaParam.insert(std::pair(112, SigmaParam{ 30.5876,0,0, 0, 0,0 })); // Lζ + this->HH_sigmaParam.insert(std::pair(113, SigmaParam{ 37.6313,0,0, 0, 0,0 })); // Lζ + this->HH_sigmaParam.insert(std::pair(114, SigmaParam{ 42.6288,0,0, 0, 0,0 })); // Lζ + this->HH_sigmaParam.insert(std::pair(115, SigmaParam{ 46.5052,0,0, 0, 0,0 })); // Lζ + this->HH_sigmaParam.insert(std::pair(116, SigmaParam{ 49.6725,0,0, 0, 0,0 })); // Lζ + this->HH_sigmaParam.insert(std::pair(117, SigmaParam{ 52.3504,0,0, 0, 0,0 })); // Lζ + this->HH_sigmaParam.insert(std::pair(118, SigmaParam{ 54.67,0,0, 0, 0,0 })); // Lζ + this->HH_sigmaParam.insert(std::pair(119, SigmaParam{ 56.7161,0,0, 0, 0,0 })); // Lζ + this->HH_sigmaParam.insert(std::pair(120, SigmaParam{ 58.5464,0,0, 0, 0,0 })); // Lζ + + this->HH_sigmaParam.insert(std::pair(10, SigmaParam{ -21.1019701821713, 9.00621457243906, 6.52932182540331, -1.11157376729893, -15.8022895411007, 11.4690828129602 })); this->HH_sigmaParam.insert(std::pair(20, SigmaParam{ -43.6677042155964, 32.0245140457417, 0.511060658303930, -2.68482232690106, 6.29783274559538, 1.96648609622833 })); this->HH_sigmaParam.insert(std::pair(40, SigmaParam{ 50.97, -62.9, -0.0968, 1.604, -4.637, 6.108 })); From e19d0390141e6e50dd512fb4cbe29b4fd67cb32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 7 Apr 2025 21:46:53 +0800 Subject: [PATCH 70/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=20WGS84=20?= =?UTF-8?q?=E5=88=B0=E6=96=9C=E8=B7=9D=E5=B9=B3=E9=9D=A2=E6=9F=A5=E6=89=BE?= =?UTF-8?q?=E8=A1=A8=E7=BB=93=E6=9E=9C=E5=8F=8D=E5=90=91=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/BaseConstVariable.h | 8 + .../QLookTableResampleFromWGS84ToRange.cpp | 97 +++++++++ .../QLookTableResampleFromWGS84ToRange.h | 30 +++ .../QLookTableResampleFromWGS84ToRange.ui | 201 ++++++++++++++++++ .../SARImage/ImageNetOperator.cpp | 172 +++++++++++++++ .../SARImage/ImageNetOperator.h | 2 +- .../SimulationSAR/QEcoherentAndAdditive.cpp | 74 +++++++ .../SimulationSAR/QEcoherentAndAdditive.h | 29 +++ .../SimulationSAR/QEcoherentAndAdditive.ui | 126 +++++++++++ .../SimulationSARTool.vcxproj | 6 + .../SimulationSARTool.vcxproj.filters | 30 ++- 11 files changed, 768 insertions(+), 7 deletions(-) create mode 100644 Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp create mode 100644 Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.h create mode 100644 Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.ui create mode 100644 Toolbox/SimulationSARTool/SimulationSAR/QEcoherentAndAdditive.cpp create mode 100644 Toolbox/SimulationSARTool/SimulationSAR/QEcoherentAndAdditive.h create mode 100644 Toolbox/SimulationSARTool/SimulationSAR/QEcoherentAndAdditive.ui diff --git a/BaseCommonLibrary/BaseTool/BaseConstVariable.h b/BaseCommonLibrary/BaseTool/BaseConstVariable.h index 9c16a9d..67114db 100644 --- a/BaseCommonLibrary/BaseTool/BaseConstVariable.h +++ b/BaseCommonLibrary/BaseTool/BaseConstVariable.h @@ -139,6 +139,14 @@ struct Point3 { void setZ(double iz) { z = iz; } }; +struct Point_3d { + double x; + double y; + double z; +}; + + + struct DemBox { double min_lon; double max_lon; diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp new file mode 100644 index 0000000..ce63880 --- /dev/null +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp @@ -0,0 +1,97 @@ +#include "QLookTableResampleFromWGS84ToRange.h" +#include "BaseConstVariable.h" +#include "BaseTool.h" +#include +#include +#include "ui_QLookTableResampleFromWGS84ToRange.h" +#include "ImageNetOperator.h" + +QLookTableResampleFromWGS84ToRange::QLookTableResampleFromWGS84ToRange(QWidget *parent) + : QDialog(parent) + ,ui(new Ui::QLookTableResampleFromWGS84ToRangeClass) +{ + ui->setupUi(this); + + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onaccepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onrejected())); + connect(ui->pushButtonLookTableWGS84Select, SIGNAL(clicked(bool)), this, SLOT(onpushButtonLookTableWGS84SelectClicked(bool))); + connect(ui->pushButtonLookTableRangeSelect, SIGNAL(clicked(bool)), this, SLOT(onpushButtonLookTableRangeSelectClicked(bool))); + connect(ui->pushButtonLookTableCountSelect, SIGNAL(clicked(bool)), this, SLOT(onpushButtonLookTableCountSelectClicked(bool))); + + +} + +QLookTableResampleFromWGS84ToRange::~QLookTableResampleFromWGS84ToRange() +{} + +void QLookTableResampleFromWGS84ToRange::onaccepted() +{ + QString looktableWGS84Ptah = ui->lineEditLookTableWGS84Path->text(); + QString looktableRangePtah = ui->lineEditLookTableRangePath->text(); + QString looktableCountPtah = ui->lineEditLookTableCountPath->text(); + + long Oriheight = ui->spinBoxRowCount->value(); + long OriWidth = ui->spinBoxColCount->value(); + + ReflectTable_WGS2Range(looktableWGS84Ptah, looktableRangePtah, looktableCountPtah, Oriheight, OriWidth); + QMessageBox::information(nullptr, u8"ʾ", u8""); +} + +void QLookTableResampleFromWGS84ToRange::onrejected() +{ + this->close(); +} + +void QLookTableResampleFromWGS84ToRange::onpushButtonLookTableWGS84SelectClicked(bool) +{ + QString fileNames = QFileDialog::getOpenFileName( + this, + tr(u8"ѡƽļ"), + QString(), + tr(ENVI_FILE_FORMAT_FILTER) + ); + + if (!fileNames.isEmpty()) { + QString message = "ѡļ\n"; + this->ui->lineEditLookTableWGS84Path->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"ûѡļ")); + } +} + +void QLookTableResampleFromWGS84ToRange::onpushButtonLookTableRangeSelectClicked(bool) +{ + QString fileNames = QFileDialog::getOpenFileName( + this, + tr(u8"ѡƽļ"), + QString(), + tr(ENVI_FILE_FORMAT_FILTER) + ); + + if (!fileNames.isEmpty()) { + QString message = "ѡļ\n"; + this->ui->lineEditLookTableRangePath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"ûѡļ")); + } +} + +void QLookTableResampleFromWGS84ToRange::onpushButtonLookTableCountSelectClicked(bool) +{ + QString fileNames = QFileDialog::getOpenFileName( + this, + tr(u8"ѡƽļ"), + QString(), + tr(ENVI_FILE_FORMAT_FILTER) + ); + + if (!fileNames.isEmpty()) { + QString message = "ѡļ\n"; + this->ui->lineEditLookTableCountPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"ûѡļ")); + } +} diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.h b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.h new file mode 100644 index 0000000..6f90bf2 --- /dev/null +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.h @@ -0,0 +1,30 @@ +#pragma once + +#include + + +namespace Ui { + class QLookTableResampleFromWGS84ToRangeClass; +} + +class QLookTableResampleFromWGS84ToRange : public QDialog +{ + Q_OBJECT + +public: + QLookTableResampleFromWGS84ToRange(QWidget *parent = nullptr); + ~QLookTableResampleFromWGS84ToRange(); + + +public slots: + + void onaccepted(); + void onrejected(); + void onpushButtonLookTableWGS84SelectClicked(bool); + void onpushButtonLookTableRangeSelectClicked(bool); + void onpushButtonLookTableCountSelectClicked(bool); + + +private: + Ui::QLookTableResampleFromWGS84ToRangeClass* ui; +}; diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.ui b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.ui new file mode 100644 index 0000000..42e6ae2 --- /dev/null +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.ui @@ -0,0 +1,201 @@ + + + QLookTableResampleFromWGS84ToRangeClass + + + + 0 + 0 + 747 + 293 + + + + QLookTableResampleFromWGS84ToRange + + + + + + + 0 + 30 + + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 行数 + + + + + + + + 0 + 30 + + + + 查找表(斜距) + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 查找表(WGS84) + + + + + + + + 0 + 30 + + + + 查找表采样点数 + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 列数 + + + + + + + + 0 + 30 + + + + 999999999 + + + + + + + + 0 + 30 + + + + 999999999 + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 8aa33c1..2529380 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -6,6 +6,7 @@ #include "GPUBaseTool.h" #include "GPUBPImageNet.cuh" #include "BaseTool.h" +#include "BaseConstVariable.h" void InitCreateImageXYZProcess(QString& outImageLLPath, QString& outImageXYZPath, QString& InEchoGPSDataPath, @@ -251,6 +252,8 @@ bool GPSPointsNumberEqualCheck(QString& ImageLLPath, QString& InEchoGPSDataPath) } + + void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath) { gdalImage demimg(ImageDEMPath); @@ -404,3 +407,172 @@ void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString qDebug() << u8"ֵ"; } + + + +int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QString ori_sim_count_tiffPath,long OriHeight,long OriWidth) +{ + gdalImage sim_rc(dem_rc_path); + gdalImage sim_sar_img = CreategdalImage(outOriSimTiffPath, OriHeight, OriWidth, 2, sim_rc.gt, sim_rc.projection, false);// עﱣ + gdalImage sim_sar_count_img = CreategdalImage(ori_sim_count_tiffPath, OriHeight, OriWidth, 1, sim_rc.gt, sim_rc.projection, false);// עﱣ + for (int max_rows_ids = 0; max_rows_ids < OriHeight; max_rows_ids = max_rows_ids + 1000) { + Eigen::MatrixXd sim_sar = sim_sar_img.getData(max_rows_ids, 0, 1000, OriWidth, 1); + Eigen::MatrixXd sim_sarc = sim_sar_img.getData(max_rows_ids, 0, 1000, OriWidth, 2); + Eigen::MatrixXd sim_sar_count = sim_sar_count_img.getData(max_rows_ids, 0, 1000, OriWidth, 1); + sim_sar = sim_sar.array() * 0 - 9999; + sim_sarc = sim_sar.array() * 0 - 9999; + sim_sar_count = sim_sar_count.array() * 0; + sim_sar_img.saveImage(sim_sar, max_rows_ids, 0, 1); + sim_sar_img.saveImage(sim_sarc, max_rows_ids, 0, 2); + sim_sar_count_img.saveImage(sim_sar_count, max_rows_ids, 0, 1); + } + sim_sar_img.setNoDataValue(-9999, 1); + sim_sar_img.setNoDataValue(-9999, 2); + int conver_lines = 5000; + int line_invert = 4000;// ص + int line_offset = 60; + // + omp_lock_t lock; + omp_init_lock(&lock); // ʼ + int allCount = 0; + + for (int max_rows_ids = 0; max_rows_ids < sim_rc.height; max_rows_ids = max_rows_ids + line_invert) { + Eigen::MatrixXd dem_r = sim_rc.getData(max_rows_ids, 0, conver_lines, sim_rc.width, 1); + Eigen::MatrixXd dem_c = sim_rc.getData(max_rows_ids, 0, conver_lines, sim_rc.width, 2); + int dem_rows_num = dem_r.rows(); + int dem_cols_num = dem_r.cols(); + // ²ֵγ + //Eigen::MatrixXd dem_lon = dem_r; + //Eigen::MatrixXd dem_lat = dem_c; + // ¾γȲ + + int temp_r, temp_c; + + int min_row = dem_r.minCoeff() + 1; + int max_row = dem_r.maxCoeff() + 1; + + if (max_row < 0) { + continue; + } + + int len_rows = max_row - min_row; + min_row = min_row < 0 ? 0 : min_row; + Eigen::MatrixXd sar_r = sim_sar_img.getData(min_row, 0, len_rows, OriWidth, 1); + Eigen::MatrixXd sar_c = sim_sar_img.getData(min_row, 0, len_rows, OriWidth, 2); + len_rows = sar_r.rows(); + + +#pragma omp parallel for num_threads(8) // NEW ADD + for (int i = 0; i < dem_rows_num - 1; i++) { + for (int j = 0; j < dem_cols_num - 1; j++) { + Point3 p, p1, p2, p3, p4; + Landpoint lp1, lp2, lp3, lp4; + lp1 = sim_rc.getLandPoint(i + max_rows_ids, j, 0); + lp2 = sim_rc.getLandPoint(i + max_rows_ids, j + 1, 0); + lp3 = sim_rc.getLandPoint(i + 1 + max_rows_ids, j + 1, 0); + lp4 = sim_rc.getLandPoint(i + 1 + max_rows_ids, j, 0); + + p1 = { dem_r(i,j),dem_c(i,j) }; + p2 = { dem_r(i,j + 1),dem_c(i,j + 1) }; + p3 = { dem_r(i + 1,j + 1),dem_c(i + 1,j + 1) }; + p4 = { dem_r(i + 1,j),dem_c(i + 1,j) }; + + //if (angle(i, j) >= 90 && angle(i, j + 1) >= 90 && angle(i + 1, j) >= 90 && angle(i + 1, j + 1) >= 90) { + // continue; + //} + + double temp_min_r = dem_r.block(i, j, 2, 2).minCoeff(); + double temp_max_r = dem_r.block(i, j, 2, 2).maxCoeff(); + double temp_min_c = dem_c.block(i, j, 2, 2).minCoeff(); + double temp_max_c = dem_c.block(i, j, 2, 2).maxCoeff(); + if ((int(temp_min_r) != int(temp_max_r)) && (int(temp_min_c) != int(temp_max_c))) { + for (int ii = int(temp_min_r); ii <= temp_max_r + 1; ii++) { + for (int jj = int(temp_min_c); jj < temp_max_c + 1; jj++) { + if (ii < min_row || ii - min_row >= len_rows || jj < 0 || jj >= OriWidth) { + continue; + } + p = { double(ii),double(jj),0 }; + //if (PtInRect(p, p1, p2, p3, p4)) { + p1.z = lp1.lon; + p2.z = lp2.lon; + p3.z = lp3.lon; + p4.z = lp4.lon; + + p = invBilinear(p, p1, p2, p3, p4); + if (isnan(p.z)) { + continue; + } + + if (p.x < 0) { + continue; + } + double mean = (p1.z + p2.z + p3.z + p4.z) / 4; + if (p.z > p1.z && p.z > p2.z && p.z > p3.z && p.z > p4.z) { + p.z = mean; + } + if (p.z < p1.z && p.z < p2.z && p.z < p3.z && p.z < p4.z) { + p.z = mean; + } + sar_r(ii - min_row, jj) = p.z; + p1.z = lp1.lat; + p2.z = lp2.lat; + p3.z = lp3.lat; + p4.z = lp4.lat; + p = invBilinear(p, p1, p2, p3, p4); + if (isnan(p.z)) { + continue; + } + + if (p.x < 0) { + continue; + } + mean = (p1.z + p2.z + p3.z + p4.z) / 4; + if (p.z > p1.z && p.z > p2.z && p.z > p3.z && p.z > p4.z) { + p.z = mean; + } + if (p.z < p1.z && p.z < p2.z && p.z < p3.z && p.z < p4.z) { + p.z = mean; + } + sar_c(ii - min_row, jj) = p.z; + //} + } + } + + } + } + } + + omp_set_lock(&lock); //û + sim_sar_img.saveImage(sar_r, min_row, 0, 1); + sim_sar_img.saveImage(sar_c, min_row, 0, 2); + allCount = allCount + conver_lines; + qDebug() << "rows:\t" << allCount << "/" << sim_rc.height << "\t computing.....\t" ; + omp_unset_lock(&lock); //ͷŻ + + + } + + qDebug() << "\t resample computing.....\t"; + { + int conver = 5000; + int line_invert = 4000;// ص + + ResampleGDALs(ori_sim_count_tiffPath.toUtf8().constData(), 1, GRIORA_Bilinear); + ResampleGDALs(ori_sim_count_tiffPath.toUtf8().constData(), 2, GRIORA_Bilinear); + } + + return 0; +} + + + + + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h index cafdfc8..a18718a 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h @@ -13,5 +13,5 @@ bool GPSPointsNumberEqualCheck(QString& ImageLLPath, QString& InEchoGPSDataPath) void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath); - +int ReflectTable_WGS2Range(QString dem_rc_path, QString outOriSimTiffPath, QString ori_sim_count_tiffPath, long OriHeight, long OriWidth); #endif diff --git a/Toolbox/SimulationSARTool/SimulationSAR/QEcoherentAndAdditive.cpp b/Toolbox/SimulationSARTool/SimulationSAR/QEcoherentAndAdditive.cpp new file mode 100644 index 0000000..a0a1d66 --- /dev/null +++ b/Toolbox/SimulationSARTool/SimulationSAR/QEcoherentAndAdditive.cpp @@ -0,0 +1,74 @@ +#include "QEcoherentAndAdditive.h" +#include "ui_QEcoherentAndAdditive.h" +#include +#include + + +QEcoherentAndAdditiveDialog::QEcoherentAndAdditiveDialog(QWidget *parent) + : QDialog(parent) + ,ui(new Ui::QEcoherentAndAdditiveClass) +{ + ui->setupUi(this); + + QObject::connect(ui->pushButtonEchoDataAddSelect, SIGNAL(clicked()), this, SLOT(onpushButtonEchoDataAddSelectClicked())); + QObject::connect(ui->pushButtonEchoDataSelect, SIGNAL(clicked()), this, SLOT(onpushButtonEchoDataSelectClicked())); + QObject::connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onaccepted())); + QObject::connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onrejected())); + } + +QEcoherentAndAdditiveDialog::~QEcoherentAndAdditiveDialog() +{} + +void QEcoherentAndAdditiveDialog::onpushButtonEchoDataAddSelectClicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡӰļ"), // + QString(), // Ĭ· + tr(u8"xml Files (*.xml);;All Files (*)") // ļ + ); + + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditEchoDataAddPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QEcoherentAndAdditiveDialog::onpushButtonEchoDataSelectClicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡӰļ"), // + QString(), // Ĭ· + tr(u8"xml Files (*.xml);;All Files (*)") // ļ + ); + + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditEchoDataAdd2Path->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QEcoherentAndAdditiveDialog::onaccepted() +{ + QString echo1Path = this->ui->lineEditEchoDataAddPath->text(); + QString echo2Path = this->ui->lineEditEchoDataAdd2Path->text(); + + + + + + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"")); +} + +void QEcoherentAndAdditiveDialog::onrejected() +{ +} diff --git a/Toolbox/SimulationSARTool/SimulationSAR/QEcoherentAndAdditive.h b/Toolbox/SimulationSARTool/SimulationSAR/QEcoherentAndAdditive.h new file mode 100644 index 0000000..4b53e85 --- /dev/null +++ b/Toolbox/SimulationSARTool/SimulationSAR/QEcoherentAndAdditive.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include + + +namespace Ui { + class QEcoherentAndAdditiveClass; +} + +class QEcoherentAndAdditiveDialog : public QDialog +{ + Q_OBJECT + +public: + QEcoherentAndAdditiveDialog(QWidget *parent = nullptr); + ~QEcoherentAndAdditiveDialog(); + + +public slots: + + void onpushButtonEchoDataAddSelectClicked(); + void onpushButtonEchoDataSelectClicked(); + void onaccepted(); + void onrejected(); + +private: + Ui::QEcoherentAndAdditiveClass* ui; +}; diff --git a/Toolbox/SimulationSARTool/SimulationSAR/QEcoherentAndAdditive.ui b/Toolbox/SimulationSARTool/SimulationSAR/QEcoherentAndAdditive.ui new file mode 100644 index 0000000..bf67d40 --- /dev/null +++ b/Toolbox/SimulationSARTool/SimulationSAR/QEcoherentAndAdditive.ui @@ -0,0 +1,126 @@ + + + QEcoherentAndAdditiveClass + + + + 0 + 0 + 747 + 239 + + + + 仿真回波叠加 + + + + + + + + + + 0 + 30 + + + + + + + + + 0 + 30 + + + + 带叠加回波: + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 30 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 0 + 30 + + + + 被叠加回波 + + + + + + + + 0 + 30 + + + + + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 105c02d..0e39cf3 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -210,6 +210,7 @@ + @@ -218,6 +219,7 @@ + @@ -243,6 +245,7 @@ + @@ -258,6 +261,7 @@ + @@ -277,6 +281,7 @@ + @@ -284,6 +289,7 @@ + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index 82c544b..88f0bab 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -13,10 +13,6 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - {99349809-55BA-4b9d-BF79-8FDBB0286EB3} - ui - {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C} ts @@ -30,6 +26,10 @@ {3380934c-6b95-45eb-8d70-d8b58e0e9de3} + + {99349809-55BA-4b9d-BF79-8FDBB0286EB3} + ui + @@ -80,8 +80,8 @@ SARImage - - SARImage + + PowerSimulationIncoherent @@ -148,6 +148,12 @@ SARImage + + SimulationSAR + + + PowerSimulationIncoherent + @@ -186,6 +192,12 @@ SARImage + + SimulationSAR + + + PowerSimulationIncoherent + @@ -224,6 +236,12 @@ Header Files + + Header Files + + + Header Files + From 357cf2ec6670b2a9a361ed9674c773fcb915c5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 7 Apr 2025 23:15:18 +0800 Subject: [PATCH 71/94] =?UTF-8?q?=E4=BB=BF=E7=9C=9F=E5=9B=BE=E5=83=8F?= =?UTF-8?q?=E9=87=87=E6=A0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QLookTableResampleFromWGS84ToRange.cpp | 10 +-- .../SARImage/ImageNetOperator.cpp | 20 ++--- .../SARImage/ImagePlaneAtiInterpDialog.cpp | 6 +- .../SARImage/ImagePlaneAtiInterpDialog.ui | 89 +++++++++++-------- .../SimulationSARTool/SimulationSARTool.cpp | 19 ++++ Toolbox/SimulationSARTool/SimulationSARTool.h | 8 ++ 6 files changed, 94 insertions(+), 58 deletions(-) diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp index ce63880..981ee1f 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp @@ -46,7 +46,7 @@ void QLookTableResampleFromWGS84ToRange::onpushButtonLookTableWGS84SelectClicked { QString fileNames = QFileDialog::getOpenFileName( this, - tr(u8"ѡƽļ"), + tr(u8"ѡWGS84ļ"), QString(), tr(ENVI_FILE_FORMAT_FILTER) ); @@ -62,9 +62,9 @@ void QLookTableResampleFromWGS84ToRange::onpushButtonLookTableWGS84SelectClicked void QLookTableResampleFromWGS84ToRange::onpushButtonLookTableRangeSelectClicked(bool) { - QString fileNames = QFileDialog::getOpenFileName( + QString fileNames = QFileDialog::getSaveFileName( this, - tr(u8"ѡƽļ"), + tr(u8"бƽļ"), QString(), tr(ENVI_FILE_FORMAT_FILTER) ); @@ -80,9 +80,9 @@ void QLookTableResampleFromWGS84ToRange::onpushButtonLookTableRangeSelectClicked void QLookTableResampleFromWGS84ToRange::onpushButtonLookTableCountSelectClicked(bool) { - QString fileNames = QFileDialog::getOpenFileName( + QString fileNames = QFileDialog::getSaveFileName( this, - tr(u8"ѡƽļ"), + tr(u8"ͳƲƽļ"), QString(), tr(ENVI_FILE_FORMAT_FILTER) ); diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 2529380..698a017 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -293,7 +293,14 @@ void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString double lon = imglonArr(i, j); double lat = imglatArr(i, j); Landpoint point = demimg.getRow_Col(lon, lat); + + if (point.lon<1 || point.lon>demimg.width - 2 || point.lat < 1 || point.lat - 2) { + continue; + } + else {} + Landpoint p0, p11, p21, p12, p22; + p0.lon = point.lon; p0.lat = point.lat; @@ -414,17 +421,13 @@ int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QStrin { gdalImage sim_rc(dem_rc_path); gdalImage sim_sar_img = CreategdalImage(outOriSimTiffPath, OriHeight, OriWidth, 2, sim_rc.gt, sim_rc.projection, false);// עﱣ - gdalImage sim_sar_count_img = CreategdalImage(ori_sim_count_tiffPath, OriHeight, OriWidth, 1, sim_rc.gt, sim_rc.projection, false);// עﱣ for (int max_rows_ids = 0; max_rows_ids < OriHeight; max_rows_ids = max_rows_ids + 1000) { Eigen::MatrixXd sim_sar = sim_sar_img.getData(max_rows_ids, 0, 1000, OriWidth, 1); Eigen::MatrixXd sim_sarc = sim_sar_img.getData(max_rows_ids, 0, 1000, OriWidth, 2); - Eigen::MatrixXd sim_sar_count = sim_sar_count_img.getData(max_rows_ids, 0, 1000, OriWidth, 1); sim_sar = sim_sar.array() * 0 - 9999; sim_sarc = sim_sar.array() * 0 - 9999; - sim_sar_count = sim_sar_count.array() * 0; sim_sar_img.saveImage(sim_sar, max_rows_ids, 0, 1); sim_sar_img.saveImage(sim_sarc, max_rows_ids, 0, 2); - sim_sar_count_img.saveImage(sim_sar_count, max_rows_ids, 0, 1); } sim_sar_img.setNoDataValue(-9999, 1); sim_sar_img.setNoDataValue(-9999, 2); @@ -552,15 +555,6 @@ int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QStrin } - qDebug() << "\t resample computing.....\t"; - { - int conver = 5000; - int line_invert = 4000;// ص - - ResampleGDALs(ori_sim_count_tiffPath.toUtf8().constData(), 1, GRIORA_Bilinear); - ResampleGDALs(ori_sim_count_tiffPath.toUtf8().constData(), 2, GRIORA_Bilinear); - } - return 0; } diff --git a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp index 54c7de1..e4ec753 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp @@ -2,6 +2,7 @@ #include "ui_ImagePlaneAtiInterpDialog.h" #include #include +#include #include "BaseConstVariable.h" #include "ImageNetOperator.h" @@ -116,9 +117,10 @@ void ImagePlaneAtiInterpDialog::onbuttonBoxAccepted() QMessageBox::warning(nullptr, u8"", u8"زGPSĿһ"); return; } + + bool checkflag= this->ui->checkBoxOverLap->isChecked(); - - if (OverlapCheck(imageNet0Path, refRangeDEMPath)) { // ????DEM??? + if (checkflag || OverlapCheck(imageNet0Path, refRangeDEMPath)) { // ????DEM??? InterploateAtiByRefDEM(imageNet0Path, refRangeDEMPath, imageLLAPath,echoGPSDataPath); QMessageBox::information(nullptr, u8"ʾ", u8"completed!!"); diff --git a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui index fa3a5f2..db72143 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui +++ b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.ui @@ -7,15 +7,28 @@ 0 0 661 - 266 + 305 根据经纬度插值高程数据 - - + + + + + 0 + 30 + + + + 成像网格(经纬度): + + + + + 0 @@ -27,6 +40,19 @@ + + + + + 0 + 30 + + + + 回波GPS点 + + + @@ -40,8 +66,8 @@ - - + + 0 @@ -49,7 +75,7 @@ - + 选择 @@ -66,7 +92,7 @@ - + @@ -79,8 +105,8 @@ - - + + 0 @@ -88,12 +114,22 @@ - 成像网格(经纬度): + - - + + + + + 0 + 30 + + + + + + 0 @@ -144,8 +180,8 @@ - - + + 0 @@ -153,30 +189,7 @@ - 回波GPS点 - - - - - - - - 0 - 30 - - - - - - - - - 0 - 30 - - - - 选择 + 强制采样 diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index 0ab1eca..bf4d73d 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -10,6 +10,7 @@ #include "InitCreateImageXYZDialog.h" #include "ImagePlaneAtiInterpDialog.h" #include "QCreateInSARImagePlaneXYZRDialog.h" +#include "QLookTableResampleFromWGS84ToRange.h" SARSimlulationRFPCToolButton::SARSimlulationRFPCToolButton(QWidget* parent) @@ -83,6 +84,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new ImagePlaneAtiInterpToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QCreateInSARImagePlaneXYZRToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QInSARBPImageToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QLookTableResampleFromWGS84ToRangeToolButton(toolbox)); } LookTableComputerClassToolButton::LookTableComputerClassToolButton(QWidget* parent) @@ -217,3 +219,20 @@ void QInSARBPImageToolButton::run() QSimulationBPImage* dialog = new QSimulationBPImage; dialog->show(); } + +QLookTableResampleFromWGS84ToRangeToolButton::QLookTableResampleFromWGS84ToRangeToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"湤߿"); + this->toolname = QString(u8"ұķֵ"); +} + +QLookTableResampleFromWGS84ToRangeToolButton::~QLookTableResampleFromWGS84ToRangeToolButton() +{ +} + +void QLookTableResampleFromWGS84ToRangeToolButton::run() +{ + QLookTableResampleFromWGS84ToRange* dialog = new QLookTableResampleFromWGS84ToRange; + dialog->show(); +} diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.h b/Toolbox/SimulationSARTool/SimulationSARTool.h index 89c51dc..93725cc 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.h +++ b/Toolbox/SimulationSARTool/SimulationSARTool.h @@ -140,7 +140,15 @@ public: }; +class SIMULATIONSARTOOL_EXPORT QLookTableResampleFromWGS84ToRangeToolButton : public QToolAbstract { + Q_OBJECT +public: + QLookTableResampleFromWGS84ToRangeToolButton(QWidget* parent = nullptr); + ~QLookTableResampleFromWGS84ToRangeToolButton(); +public: + virtual void run() override; +}; extern "C" SIMULATIONSARTOOL_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); From 9df7c8b1a0df57a84b124476e5a4859a4ba892b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 8 Apr 2025 00:13:36 +0800 Subject: [PATCH 72/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9---?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=88=90=E5=83=8F=E8=8C=83=E5=9B=B4=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=A3=81=E5=89=AA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QLookTableResampleFromWGS84ToRange.cpp | 1 - .../SARImage/ImageNetOperator.cpp | 226 +++++++++++++++++- .../SARImage/ImageNetOperator.h | 2 +- .../SARImage/ImagePlaneAtiInterpDialog.cpp | 41 ++-- 4 files changed, 249 insertions(+), 21 deletions(-) diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp index 981ee1f..b94c71c 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp @@ -17,7 +17,6 @@ QLookTableResampleFromWGS84ToRange::QLookTableResampleFromWGS84ToRange(QWidget * connect(ui->pushButtonLookTableWGS84Select, SIGNAL(clicked(bool)), this, SLOT(onpushButtonLookTableWGS84SelectClicked(bool))); connect(ui->pushButtonLookTableRangeSelect, SIGNAL(clicked(bool)), this, SLOT(onpushButtonLookTableRangeSelectClicked(bool))); connect(ui->pushButtonLookTableCountSelect, SIGNAL(clicked(bool)), this, SLOT(onpushButtonLookTableCountSelectClicked(bool))); - } diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 698a017..a88bf24 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -286,7 +286,6 @@ void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString qDebug() << u8"ͼУ\t" << demimg.height << " , " << demimg.width; - for (long i = 0; i < imgheight; i++) { //printf("\rprocess:%f precent\t\t\t",i*100.0/imgheight); for (long j = 0; j < imgwidth; j++) { @@ -416,6 +415,231 @@ void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString } +void InterploateClipAtiByRefDEM(QString ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath) { + + gdalImage demimg(ImageDEMPath); + gdalImage imgll(ImageLLPath); + + // ü + long imgheight = imgll.height; + long imgwidth = imgll.width; + + long minRow = -1; + long maxRow = imgheight; + long minCol = -1; + long maxCol = imgwidth; + + + Eigen::MatrixXd imglonArr = imgll.getData(0, 0, imgheight, imgwidth, 1); + Eigen::MatrixXd imglatArr = imgll.getData(0, 0, imgheight, imgwidth, 2); + +#pragma omp parallel for + for (long i = 0; i < imgheight; i++) { + for (long j = 0; j < imgwidth; j++) { + double lon = imglonArr(i, j); + double lat = imglatArr(i, j); + Landpoint point = demimg.getRow_Col(lon, lat); + imglonArr(i, j) = point.lon; + imglatArr(i, j) = point.lat; + } + } + + // ʼɨ + + bool minRowFlag=true, maxRowFlag= true, minColFlag = true, maxColFlag = true; + + for (long i = 0; i < imgheight; i++) { + for (long j = 0; j < imgwidth; j++) { + if (imglonArr(i, j) > 0 && minRowFlag) { + minRowFlag = false; + minRow = i; + break; + } + if (imglonArr(i, j) < imgheight) { + maxRow = i; + } + } + } + + for (long j = 0; j < imgwidth; j++) { + for (long i = 0; i < imgheight; i++) { + if (imglatArr(i, j) > 0 && minColFlag) { + minColFlag = false; + minCol = j; + break; + } + if (imglatArr(i, j) < imgheight) { + maxCol = j; + } + } + } + + + long RowCount = maxRow - minRow; + long ColCount = maxCol - minCol; + + gdalImage outimgll = CreategdalImageDouble(outImageLLAPath, RowCount, ColCount, 4, true, true); // ȡγȡ̡߳б + + long imgheight = outimgll.height; + long imgwidth = outimgll.width; + + Eigen::MatrixXd imglonArr = imgll.getData(minRow, minCol, RowCount, ColCount, 1); + Eigen::MatrixXd imglatArr = imgll.getData(minRow, minCol, RowCount, ColCount, 2); + + Eigen::MatrixXd demArr = demimg.getData(0, 0, demimg.height, demimg.width, 1); + + Eigen::MatrixXd imgatiArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); + Eigen::MatrixXd imgRArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); + + outimgll.saveImage(imglonArr, 0, 0, 1); + outimgll.saveImage(imglatArr, 0, 0, 2); + + + double minX = imglonArr.minCoeff(); + double maxX = imglonArr.maxCoeff(); + double minY = imglatArr.minCoeff(); + double maxY = imglatArr.maxCoeff(); + + //ӡΧ + qDebug() << u8"dem ķΧ"; + qDebug() << u8"minX:" << minX << "\t" << demimg.width; + qDebug() << u8"maxX:" << maxX << "\t" << demimg.width; + qDebug() << u8"minY:" << minY << "\t" << demimg.height; + qDebug() << u8"maxY:" << maxY << "\t" << demimg.height; + qDebug() << u8"ͼУ\t" << demimg.height << " , " << demimg.width; + + + for (long i = 0; i < imgheight; i++) { + //printf("\rprocess:%f precent\t\t\t",i*100.0/imgheight); + for (long j = 0; j < imgwidth; j++) { + double lon = imglonArr(i, j); + double lat = imglatArr(i, j); + Landpoint point = demimg.getRow_Col(lon, lat); + + if (point.lon<1 || point.lon>demimg.width - 2 || point.lat < 1 || point.lat - 2) { + continue; + } + else {} + + Landpoint p0, p11, p21, p12, p22; + + p0.lon = point.lon; + p0.lat = point.lat; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + p11.ati = demArr(long(p11.lat), long(p11.lon)); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + p12.ati = demArr(long(p12.lat), long(p12.lon)); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + p21.ati = demArr(long(p21.lat), long(p21.lon)); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + p22.ati = demArr(long(p22.lat), long(p22.lon)); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); + imgatiArr(i, j) = p0.ati; + } + } + + outimgll.saveImage(imgatiArr, 0, 0, 3); + qDebug() << u8"ÿбֵ"; + + + gdalImage antimg(InEchoGPSDataPath); + qDebug() << u8"1. زGPSļ\t"; + qDebug() << u8"ļ·\t" << InEchoGPSDataPath; + qDebug() << u8"GPS \t" << antimg.height; + qDebug() << u8"ļ\t" << antimg.width; + + long prfcount = antimg.height; + + + std::shared_ptr Pxs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr Pys((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr Pzs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectX((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectY((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectZ((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + + { + long colnum = 19; + std::shared_ptr antpos = readDataArr(antimg, 0, 0, prfcount, colnum, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + double time = 0; + double Px = 0; + double Py = 0; + double Pz = 0; + for (long i = 0; i < prfcount; i++) { + + Pxs.get()[i] = antpos.get()[i * 19 + 1]; // + Pys.get()[i] = antpos.get()[i * 19 + 2]; + Pzs.get()[i] = antpos.get()[i * 19 + 3]; + AntDirectX.get()[i] = antpos.get()[i * 19 + 13];// zero doppler + AntDirectY.get()[i] = antpos.get()[i * 19 + 14]; + AntDirectZ.get()[i] = antpos.get()[i * 19 + 15]; + + double NormAnt = std::sqrt(AntDirectX.get()[i] * AntDirectX.get()[i] + + AntDirectY.get()[i] * AntDirectY.get()[i] + + AntDirectZ.get()[i] * AntDirectZ.get()[i]); + AntDirectX.get()[i] = AntDirectX.get()[i] / NormAnt; + AntDirectY.get()[i] = AntDirectY.get()[i] / NormAnt; + AntDirectZ.get()[i] = AntDirectZ.get()[i] / NormAnt;// һ + } + antpos.reset(); + } + + + +#pragma omp parallel for + for (long prfid = minRow; prfid < maxRow; prfid++) { + double Px = Pxs.get()[prfid]; + double Py = Pys.get()[prfid]; + double Pz = Pzs.get()[prfid]; + double R = 0; + Landpoint LLA = {}; + Point3 XYZ = {}; + for (long j = 0; j < imgwidth; j++) { + LLA.lon = imglonArr(prfid-minRow, j); + LLA.lat = imglatArr(prfid - minRow, j); + LLA.ati = imgatiArr(prfid - minRow, j); + + LLA2XYZ(LLA, XYZ); + + R = sqrt(pow(Px - XYZ.x, 2) + + pow(Py - XYZ.y, 2) + + pow(Pz - XYZ.z, 2)); + imgRArr(prfid - minRow, j) = R; + } + } + + outimgll.saveImage(imgRArr, 0, 0, 4); + + qDebug() << u8"ֵ"; + +} + + + int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QString ori_sim_count_tiffPath,long OriHeight,long OriWidth) { diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h index a18718a..88ae6a1 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h @@ -11,7 +11,7 @@ bool OverlapCheck(QString& ImageLLPath, QString& ImageDEMPath); bool GPSPointsNumberEqualCheck(QString& ImageLLPath, QString& InEchoGPSDataPath); - +void InterploateClipAtiByRefDEM(QString ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath); void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath); int ReflectTable_WGS2Range(QString dem_rc_path, QString outOriSimTiffPath, QString ori_sim_count_tiffPath, long OriHeight, long OriWidth); #endif diff --git a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp index e4ec753..4c78e3b 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImagePlaneAtiInterpDialog.cpp @@ -64,12 +64,11 @@ void ImagePlaneAtiInterpDialog::onpushButtonEchoGPSPointSelect_clicked() void ImagePlaneAtiInterpDialog::onpushButtonRefRangeDEMSelect_clicked() { QString fileNames = QFileDialog::getOpenFileName( - this, // ?????? - tr(u8"ѡοDEM"), // ???? - QString(), // ????? - tr(ENVI_FILE_FORMAT_FILTER) // ????????? + this, + tr(u8"ѡοDEM"), + QString(), + tr(ENVI_FILE_FORMAT_FILTER) ); - // ?????????????? if (!fileNames.isEmpty()) { QString message = "ѡļ\n"; this->ui->lineEditRefRangeDEMPath->setText(fileNames); @@ -82,12 +81,12 @@ void ImagePlaneAtiInterpDialog::onpushButtonRefRangeDEMSelect_clicked() void ImagePlaneAtiInterpDialog::onpushButtonImageLLASelect_clicked() { QString fileNames = QFileDialog::getSaveFileName( - this, // ?????? - tr(u8"ʾ"), // ???? - QString(), // ????? - tr(ENVI_FILE_FORMAT_FILTER) // ????????? + this, + tr(u8"ʾ"), + QString(), + tr(ENVI_FILE_FORMAT_FILTER) ); - // ?????????????? + if (!fileNames.isEmpty()) { QString message = "ѡļ\n"; this->ui->lineEditImageLLAPath->setText(fileNames); @@ -119,17 +118,23 @@ void ImagePlaneAtiInterpDialog::onbuttonBoxAccepted() } bool checkflag= this->ui->checkBoxOverLap->isChecked(); - - if (checkflag || OverlapCheck(imageNet0Path, refRangeDEMPath)) { // ????DEM??? - InterploateAtiByRefDEM(imageNet0Path, refRangeDEMPath, imageLLAPath,echoGPSDataPath); - - QMessageBox::information(nullptr, u8"ʾ", u8"completed!!"); + if (checkflag) { + InterploateClipAtiByRefDEM(imageNet0Path, refRangeDEMPath, imageLLAPath, echoGPSDataPath); + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"")); return; - } else { - QMessageBox::warning(nullptr,u8"",u8"DEMӰСڳƽҪ"); - return; + if (OverlapCheck(imageNet0Path, refRangeDEMPath)) { // ????DEM??? + InterploateAtiByRefDEM(imageNet0Path, refRangeDEMPath, imageLLAPath, echoGPSDataPath); + + QMessageBox::information(nullptr, u8"ʾ", u8"completed!!"); + return; + + } + else { + QMessageBox::warning(nullptr, u8"", u8"DEMӰСڳƽҪ"); + return; + } } } From 97608b5626de64b98648877b886ad943080ba4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 8 Apr 2025 10:08:19 +0800 Subject: [PATCH 73/94] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=86=E6=88=90?= =?UTF-8?q?=E5=83=8F=E7=BD=91=E6=A0=BC=E7=9A=84=E5=9D=90=E6=A0=87=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/ImageOperatorBase.h | 10 ++++- .../BaseTool/gdalImageOperator.cpp | 45 +++++++++++++++++++ .../QLookTableResampleFromWGS84ToRange.cpp | 1 - .../SimulationSAR/TBPImageAlgCls.cpp | 5 +++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h index 8b0b7ba..d47ad7c 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h @@ -174,8 +174,6 @@ public: // 方法 virtual void saveImage(std::shared_ptr, int start_row, int start_col, int rowcount, int colcount, int band_ids); virtual void saveImage(std::shared_ptr, 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); @@ -197,6 +195,10 @@ public: // 方法 virtual RasterExtend getExtend(); + + + + public: QString img_path; // 图像文件 int height; // 高 @@ -236,6 +238,10 @@ public: Eigen::MatrixXcd data; }; + +bool BASECONSTVARIABLEAPI CopyProjectTransformMatrixFromRasterAToRasterB(QString RasterAPath, QString RasterBPath); + + // 创建影像 gdalImage BASECONSTVARIABLEAPI CreategdalImageDouble(QString& img_path, int height, int width, int band_num, bool overwrite = false, bool isEnvi = false); gdalImage BASECONSTVARIABLEAPI CreategdalImageFloat(QString& img_path, int height, int width, int band_num, bool overwrite = false, bool isEnvi = false); diff --git a/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp b/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp index d0c8c77..c695822 100644 --- a/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp +++ b/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp @@ -1470,6 +1470,51 @@ gdalImage CreategdalImage(const QString& img_path, int height, int width, int ba } +bool CopyProjectTransformMatrixFromRasterAToRasterB(QString RasterAPath, QString RasterBPath) { + // עGDAL + GDALAllRegister(); + + // ӰAֻģʽ + GDALDataset* ds_a = (GDALDataset*)GDALOpen(RasterAPath.toUtf8().constData(), GA_ReadOnly); + if (ds_a == nullptr) { + std::cerr << "޷ӰA" << std::endl; + return false; + } + + // ȡAķͶӰϢ + double geotransform[6]; + ds_a->GetGeoTransform(geotransform); // 任 + const char* projection = ds_a->GetProjectionRef(); // WKTʽͶӰ + + // ӰBģʽ + GDALDataset* ds_b = (GDALDataset*)GDALOpen(RasterBPath.toUtf8().constData(), GA_Update); + if (ds_b == nullptr) { + std::cerr << "޷ӰB" << std::endl; + GDALClose(ds_a); + return false; + } + + // ÷ + if (ds_b->SetGeoTransform(geotransform) != CE_None) { + std::cerr << "÷ʧ" << std::endl; + } + + // ͶӰϵ + if (ds_b->SetProjection(projection) != CE_None) { + std::cerr << "ͶӰʧ" << std::endl; + } + + // ͷԴ + GDALClose(ds_a); + GDALClose(ds_b); + + return true; + + + + + +} diff --git a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp index b94c71c..38004a5 100644 --- a/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp +++ b/Toolbox/SimulationSARTool/PowerSimulationIncoherent/QLookTableResampleFromWGS84ToRange.cpp @@ -17,7 +17,6 @@ QLookTableResampleFromWGS84ToRange::QLookTableResampleFromWGS84ToRange(QWidget * connect(ui->pushButtonLookTableWGS84Select, SIGNAL(clicked(bool)), this, SLOT(onpushButtonLookTableWGS84SelectClicked(bool))); connect(ui->pushButtonLookTableRangeSelect, SIGNAL(clicked(bool)), this, SLOT(onpushButtonLookTableRangeSelectClicked(bool))); connect(ui->pushButtonLookTableCountSelect, SIGNAL(clicked(bool)), this, SLOT(onpushButtonLookTableCountSelectClicked(bool))); - } QLookTableResampleFromWGS84ToRange::~QLookTableResampleFromWGS84ToRange() diff --git a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp index 4766922..dc32916 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp @@ -90,6 +90,11 @@ ErrorCode TBPImageAlgCls::ProcessWithGridNet(long num_thread,QString xyzRasterPa QMessageBox::information(nullptr, u8"提示", u8"目前只支持显卡"); return ErrorCode::FAIL; } + + // 处理成像映射 + CopyProjectTransformMatrixFromRasterAToRasterB(this->outRasterXYZPath, this->L1ds->getImageRasterPath()); + + return ErrorCode::SUCCESS; } From 6d642675ee0bac951582ab6c77017aa46176fcbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 8 Apr 2025 10:18:00 +0800 Subject: [PATCH 74/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SARImage/ImageNetOperator.cpp | 19 ++- .../SARImage/ImageNetOperator.h | 3 + .../QSARSimulationComplexEchoDataDialog.cpp | 100 ++++++++++++ .../QSARSimulationComplexEchoDataDialog.h | 27 ++++ .../QSARSimulationComplexEchoDataDialog.ui | 149 ++++++++++++++++++ .../SimulationSARTool.vcxproj | 3 + .../SimulationSARTool.vcxproj.filters | 15 +- 7 files changed, 308 insertions(+), 8 deletions(-) create mode 100644 Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp create mode 100644 Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.h create mode 100644 Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.ui diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index a88bf24..44f98c9 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -480,11 +480,11 @@ void InterploateClipAtiByRefDEM(QString ImageLLPath, QString& ImageDEMPath, QStr gdalImage outimgll = CreategdalImageDouble(outImageLLAPath, RowCount, ColCount, 4, true, true); // ȡγȡ̡߳б - long imgheight = outimgll.height; - long imgwidth = outimgll.width; + imgheight = outimgll.height; + imgwidth = outimgll.width; - Eigen::MatrixXd imglonArr = imgll.getData(minRow, minCol, RowCount, ColCount, 1); - Eigen::MatrixXd imglatArr = imgll.getData(minRow, minCol, RowCount, ColCount, 2); + imglonArr = imgll.getData(minRow, minCol, RowCount, ColCount, 1); + imglatArr = imgll.getData(minRow, minCol, RowCount, ColCount, 2); Eigen::MatrixXd demArr = demimg.getData(0, 0, demimg.height, demimg.width, 1); @@ -784,7 +784,16 @@ int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QStrin - +int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePath, QString L1AEchoDataPath) { + gdalImageComplex echodata(L2echodataPath); + gdalImage looktable(RangeLooktablePath); + + + + + + +} diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h index 88ae6a1..b3a0be9 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h @@ -14,4 +14,7 @@ bool GPSPointsNumberEqualCheck(QString& ImageLLPath, QString& InEchoGPSDataPath) void InterploateClipAtiByRefDEM(QString ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath); void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath); int ReflectTable_WGS2Range(QString dem_rc_path, QString outOriSimTiffPath, QString ori_sim_count_tiffPath, long OriHeight, long OriWidth); + +int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePath, QString L1AEchoDataPath); + #endif diff --git a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp new file mode 100644 index 0000000..b1057d2 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp @@ -0,0 +1,100 @@ +#include "QSARSimulationComplexEchoDataDialog.h" +#include "ui_QSARSimulationComplexEchoDataDialog.h" +#include +#include +#include "BaseConstVariable.h" +#include "BaseTool.h" +#include "ImageNetOperator.h" +#include + + +QSARSimulationComplexEchoDataDialog::QSARSimulationComplexEchoDataDialog(QWidget *parent) + : QDialog(parent) + , ui(new Ui::QSARSimulationComplexEchoDataDialogClass) +{ + ui->setupUi(this); + + + connect(ui->pushButtonEchoDataSelect, SIGNAL(clicked()), this, SLOT(onpushButtonEchoDataSelect_clicked())); + connect(ui->pushButtonLookTableSelect, SIGNAL(clicked()), this, SLOT(onpushButtonLookTableSelect_clicked())); + connect(ui->pushButtonL1AEchoDataSelect, SIGNAL(clicked()), this, SLOT(onpushButtonL1AEchoDataSelect_clicked())); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbuttonBox_accepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbuttonBox_rejected())); + +} + +QSARSimulationComplexEchoDataDialog::~QSARSimulationComplexEchoDataDialog() +{ + + +} + +void QSARSimulationComplexEchoDataDialog::onpushButtonEchoDataSelect_clicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡL1Aزļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditL1AEchoDataPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QSARSimulationComplexEchoDataDialog::onpushButtonLookTableSelect_clicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡL1Aزļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditL1AEchoDataPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QSARSimulationComplexEchoDataDialog::onpushButtonL1AEchoDataSelect_clicked() +{ + QString fileNames = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡL1Aزļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditL1AEchoDataPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QSARSimulationComplexEchoDataDialog::onbuttonBox_accepted() +{ + QString echoDataPath = this->ui->lineEditEchoDataPath->text().trimmed(); + QString RangelookTablePath = this->ui->lineEditLookTablePath->text().trimmed(); + QString l1AEchoDataPath = this->ui->lineEditL1AEchoDataPath->text().trimmed(); + + + + +} + +void QSARSimulationComplexEchoDataDialog::onbuttonBox_rejected() +{ + this->close(); +} diff --git a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.h b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.h new file mode 100644 index 0000000..b586769 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +namespace Ui +{ + class QSARSimulationComplexEchoDataDialogClass; +} + +class QSARSimulationComplexEchoDataDialog : public QDialog +{ + Q_OBJECT + +public: + QSARSimulationComplexEchoDataDialog(QWidget *parent = nullptr); + ~QSARSimulationComplexEchoDataDialog(); + + +public slots: + void onpushButtonEchoDataSelect_clicked(); + void onpushButtonLookTableSelect_clicked(); + void onpushButtonL1AEchoDataSelect_clicked(); + void onbuttonBox_accepted(); + void onbuttonBox_rejected(); +private: + Ui::QSARSimulationComplexEchoDataDialogClass* ui; +}; diff --git a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.ui b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.ui new file mode 100644 index 0000000..ceed9c6 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.ui @@ -0,0 +1,149 @@ + + + QSARSimulationComplexEchoDataDialogClass + + + + 0 + 0 + 916 + 400 + + + + QSARSimulationComplexEchoDataDialog + + + + + + + 0 + 30 + + + + 成像文件: + + + + + + + + 0 + 30 + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 查找表: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + L1A回波: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 0e39cf3..34f3688 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -219,6 +219,7 @@ + @@ -250,6 +251,7 @@ + @@ -289,6 +291,7 @@ + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index 88f0bab..1516d1b 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -80,9 +80,6 @@ SARImage - - PowerSimulationIncoherent - @@ -154,6 +151,9 @@ PowerSimulationIncoherent + + SARImage + @@ -198,6 +198,9 @@ PowerSimulationIncoherent + + SARImage + @@ -242,6 +245,12 @@ Header Files + + Header Files + + + SARImage + From d12a2b7d89ae1569fabffdf2bf9d4c98970598a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 8 Apr 2025 10:43:31 +0800 Subject: [PATCH 75/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SARImage/ImageNetOperator.cpp | 107 +++++++++ .../QSARSimulationComplexEchoDataDialog.cpp | 4 +- .../QSimulationBPImageMultiProduction.cpp | 138 ++++++++++++ .../QSimulationBPImageMultiProduction.h | 31 +++ .../QSimulationBPImageMultiProduction.ui | 210 ++++++++++++++++++ .../SimulationSAR/QSimulationBPImage.ui | 2 +- .../SimulationSARTool/SimulationSARTool.cpp | 27 ++- Toolbox/SimulationSARTool/SimulationSARTool.h | 15 +- .../SimulationSARTool.vcxproj | 3 + .../SimulationSARTool.vcxproj.filters | 9 + 10 files changed, 541 insertions(+), 5 deletions(-) create mode 100644 Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.cpp create mode 100644 Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.h create mode 100644 Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.ui diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 44f98c9..4f013c4 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -787,11 +787,118 @@ int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QStrin int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePath, QString L1AEchoDataPath) { gdalImageComplex echodata(L2echodataPath); gdalImage looktable(RangeLooktablePath); + gdalImageComplex l1adata = CreategdalImageComplexNoProj(L1AEchoDataPath, looktable.height, looktable.width, 1, true); + + Eigen::MatrixXd imglonArr = looktable.getData(0, 0, looktable.height, looktable.width, 1); + Eigen::MatrixXd imglatArr = looktable.getData(0, 0, looktable.height, looktable.width, 2); + + Eigen::MatrixXcd echoArr = echodata.getDataComplex(0, 0, echodata.height, echodata.width, 1); + Eigen::MatrixXcd l1aArr= l1adata.getDataComplex(0, 0, l1adata.height, l1adata.width, 1); + l1aArr = l1aArr.array() * 0; + long imgheight = looktable.height; + long imgwidth = looktable.width; + for (long i = 0; i < imgheight; i++) { + //printf("\rprocess:%f precent\t\t\t",i*100.0/imgheight); + for (long j = 0; j < imgwidth; j++) { + double lon = imglonArr(i, j); + double lat = imglatArr(i, j); + Landpoint point = echodata.getRow_Col(lon, lat); + if (point.lon<1 || point.lon>echodata.width - 2 || point.lat < 1 || point.lat >echodata.height - 2) { + continue; + } + else {} + // ʵֵ + { + Landpoint p0, p11, p21, p12, p22; + p0.lon = point.lon; + p0.lat = point.lat; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + p11.ati = echoArr(long(p11.lat), long(p11.lon)).real(); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + p12.ati = echoArr(long(p12.lat), long(p12.lon)).real(); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + p21.ati = echoArr(long(p21.lat), long(p21.lon)).real(); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + p22.ati = echoArr(long(p22.lat), long(p22.lon)).real(); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); + l1aArr(i, j).real(p0.ati); + } + //鲿ֵ + { + Landpoint p0, p11, p21, p12, p22; + + p0.lon = point.lon; + p0.lat = point.lat; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + p11.ati = echoArr(long(p11.lat), long(p11.lon)).imag(); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + p12.ati = echoArr(long(p12.lat), long(p12.lon)).imag(); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + p21.ati = echoArr(long(p21.lat), long(p21.lon)).imag(); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + p22.ati = echoArr(long(p22.lat), long(p22.lon)).imag(); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); + l1aArr(i, j).imag(p0.ati); + } + + } + } + + l1adata.saveImage(l1aArr, 0, 0, 1); + return 0; } diff --git a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp index b1057d2..48a8d51 100644 --- a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp @@ -90,8 +90,8 @@ void QSARSimulationComplexEchoDataDialog::onbuttonBox_accepted() QString l1AEchoDataPath = this->ui->lineEditL1AEchoDataPath->text().trimmed(); - - + ResampleEChoDataFromGeoEcho(echoDataPath, RangelookTablePath, l1AEchoDataPath); + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"ûѡκļ")); } void QSARSimulationComplexEchoDataDialog::onbuttonBox_rejected() diff --git a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.cpp b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.cpp new file mode 100644 index 0000000..aade224 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.cpp @@ -0,0 +1,138 @@ +#include "QSimulationBPImageMultiProduction.h" +#include +#include +#include "TBPImageAlgCls.h" +#include "EchoDataFormat.h" +#include +#include +#include "ui_QSimulationBPImageMultiProduction.h" + + +QSimulationBPImageMultiProduction::QSimulationBPImageMultiProduction(QWidget *parent) + : QDialog(parent),ui(new Ui::QSimulationBPImageMultiProductionClass) +{ + ui->setupUi(this); + ui->checkBox->setEnabled(false); + ui->checkBox->setCheckable(true); + ui->checkBox->setChecked(true); + + QObject::connect(ui->pushButtonEchoSelect, SIGNAL(clicked()), this, SLOT(onpushButtonEchoSelectClicked())); + QObject::connect(ui->pushButtonImageSelect, SIGNAL(clicked()), this, SLOT(onpushButtonImageSelectClicked())); + QObject::connect(ui->GridNetBtn, SIGNAL(clicked()), this, SLOT(onpushButtonGridNetSelectClicked())); + QObject::connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbtnaccepted())); + QObject::connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbtnrejected())); + QObject::connect(ui->checkBox, SIGNAL(stateChanged(int)), this, SLOT(oncheckboxTrigged(int))); + + + + +} + +QSimulationBPImageMultiProduction::~QSimulationBPImageMultiProduction() +{} + +void QSimulationBPImageMultiProduction::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 QSimulationBPImageMultiProduction::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 QSimulationBPImageMultiProduction::onbtnaccepted() +{ + this->hide(); + 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 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()); + + if (ui->checkBox->isChecked()) { + gdalImage imgxyzimg(ui->lineEdit->text().trimmed()); + imagL1->OpenOrNew(outImageFolder, imagename, imgxyzimg.height, imgxyzimg.width); + } + else { + imagL1->OpenOrNew(outImageFolder, imagename, echoL0ds->getPluseCount(), echoL0ds->getPlusePoints()); + } + + + TBPImageAlgCls TBPimag; + TBPimag.setEchoL0(echoL0ds); + TBPimag.setImageL1(imagL1); + long cpucore_num = std::thread::hardware_concurrency(); + TBPimag.setGPU(true); + TBPimag.ProcessWithGridNet(cpucore_num,ui->lineEdit->text().trimmed()); + + this->show(); + QMessageBox::information(this,u8"",u8""); + +} + +void QSimulationBPImageMultiProduction::onbtnrejected() +{ + this->close(); +} + +void QSimulationBPImageMultiProduction::oncheckboxTrigged(int) +{ + this->ui->lineEdit->setEnabled(this->ui->checkBox->isChecked()); + this->ui->GridNetBtn->setEnabled(this->ui->checkBox->isChecked()); + +} + +void QSimulationBPImageMultiProduction::onpushButtonGridNetSelectClicked( ) +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡӰļ"), // + QString(), // Ĭ· + tr(u8"All Files(*);;dat(*.dat);;tif(*.tif);;tiff(*.tiff)") // ļ + ); + + // ûѡļ + if (!fileNames.isEmpty()) { + this->ui->lineEdit->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} diff --git a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.h b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.h new file mode 100644 index 0000000..dc84ee7 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.h @@ -0,0 +1,31 @@ +#pragma once +#include "simulationsartool_global.h" +#include + +namespace Ui { + class QSimulationBPImageMultiProductionClass; +} + + + +class SIMULATIONSARTOOL_EXPORT QSimulationBPImageMultiProduction : public QDialog +{ + Q_OBJECT + +public: + QSimulationBPImageMultiProduction(QWidget *parent = nullptr); + ~QSimulationBPImageMultiProduction(); + + +public slots: + void onpushButtonEchoSelectClicked(); + void onpushButtonImageSelectClicked(); + void onbtnaccepted(); + void onbtnrejected(); + + void oncheckboxTrigged(int); + void onpushButtonGridNetSelectClicked( ); + +private: + Ui::QSimulationBPImageMultiProductionClass* ui; +}; diff --git a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.ui b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.ui new file mode 100644 index 0000000..a3e110a --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.ui @@ -0,0 +1,210 @@ + + + QSimulationBPImageMultiProductionClass + + + + 0 + 0 + 813 + 400 + + + + 仿真图像TimeBP方法 + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 30 + + + + 回波地址: + + + + + + + + 0 + 30 + + + + D:\Programme\vs2022\RasterMergeTest\LAMPCAE_SCANE-all-scane\GF3_Simulation.xml + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 30 + + + + 图像网格 + + + true + + + + + + + true + + + + 0 + 30 + + + + D:\Programme\vs2022\RasterMergeTest\simulationData\demdataset\demxyz.bin + + + + + + + true + + + + 0 + 30 + + + + 选择 + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 0 + 30 + + + + 仿真图像: + + + + + + + + 0 + 30 + + + + D:\Programme\vs2022\RasterMergeTest\LAMPCAE_SCANE-all-scane\BPImage\GF3BPImage + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 30 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SimulationSAR/QSimulationBPImage.ui b/Toolbox/SimulationSARTool/SimulationSAR/QSimulationBPImage.ui index 39d7fa4..79f3686 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/QSimulationBPImage.ui +++ b/Toolbox/SimulationSARTool/SimulationSAR/QSimulationBPImage.ui @@ -6,7 +6,7 @@ 0 0 - 995 + 813 400 diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index bf4d73d..a9b9d11 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -11,6 +11,7 @@ #include "ImagePlaneAtiInterpDialog.h" #include "QCreateInSARImagePlaneXYZRDialog.h" #include "QLookTableResampleFromWGS84ToRange.h" +#include "QSARSimulationComplexEchoDataDialog.h" SARSimlulationRFPCToolButton::SARSimlulationRFPCToolButton(QWidget* parent) @@ -73,7 +74,7 @@ void QSimulationSAROrbitModelToolButton::excute() void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox) { - emit toolbox->addBoxToolItemSIGNAL(new SARSimlulationRFPCToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new SARSimlulationRFPCToolButton(toolbox)); // 300 emit toolbox->addBoxToolItemSIGNAL(new SARSimulationTBPImageToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QSimulationSAROrbitModelToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new LookTableComputerClassToolButton(toolbox)); @@ -85,6 +86,8 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QCreateInSARImagePlaneXYZRToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QInSARBPImageToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QLookTableResampleFromWGS84ToRangeToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QSARSimulationComplexEchoDataDialogToolButton(toolbox)); + } LookTableComputerClassToolButton::LookTableComputerClassToolButton(QWidget* parent) @@ -236,3 +239,25 @@ void QLookTableResampleFromWGS84ToRangeToolButton::run() QLookTableResampleFromWGS84ToRange* dialog = new QLookTableResampleFromWGS84ToRange; dialog->show(); } + + + + +//QSARSimulationComplexEchoDataDialog + +QSARSimulationComplexEchoDataDialogToolButton::QSARSimulationComplexEchoDataDialogToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"񹤾߿"); + this->toolname = QString(u8"زߣԣ"); +} + +QSARSimulationComplexEchoDataDialogToolButton::~QSARSimulationComplexEchoDataDialogToolButton() +{ +} + +void QSARSimulationComplexEchoDataDialogToolButton::run() +{ + QSARSimulationComplexEchoDataDialog* dialog = new QSARSimulationComplexEchoDataDialog; + dialog->show(); +} diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.h b/Toolbox/SimulationSARTool/SimulationSARTool.h index 93725cc..1a6212c 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.h +++ b/Toolbox/SimulationSARTool/SimulationSARTool.h @@ -13,6 +13,10 @@ namespace LAMPMainWidget { class ToolBoxWidget; +extern "C" SIMULATIONSARTOOL_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); + + + class SIMULATIONSARTOOL_EXPORT SARSimlulationRFPCToolButton : public QToolAbstract { Q_OBJECT @@ -150,6 +154,15 @@ public: }; -extern "C" SIMULATIONSARTOOL_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); + +class SIMULATIONSARTOOL_EXPORT QSARSimulationComplexEchoDataDialogToolButton : public QToolAbstract { + Q_OBJECT +public: + QSARSimulationComplexEchoDataDialogToolButton(QWidget* parent = nullptr); + ~QSARSimulationComplexEchoDataDialogToolButton(); +public: + virtual void run() override; + +}; diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 34f3688..b228c81 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -220,6 +220,7 @@ + @@ -252,6 +253,7 @@ + @@ -292,6 +294,7 @@ + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index 1516d1b..e53b120 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -154,6 +154,9 @@ SARImage + + SARImage + @@ -201,6 +204,9 @@ SARImage + + SARImage + @@ -251,6 +257,9 @@ SARImage + + SARImage + From 95f7bef2b52f6d5c9223dc883ba0c59a093919a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 8 Apr 2025 11:01:52 +0800 Subject: [PATCH 76/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=9A=E7=BA=A7?= =?UTF-8?q?=E4=BA=A7=E5=93=81=E7=94=9F=E4=BA=A7=E5=B7=A5=E5=85=B7-?= =?UTF-8?q?=E5=BE=85=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SARImage/ImageNetOperator.cpp | 2 +- .../QSimulationBPImageMultiProduction.cpp | 138 ++++++++++++------ .../QSimulationBPImageMultiProduction.h | 9 +- .../QSimulationBPImageMultiProduction.ui | 125 ++++++++++++++-- .../SimulationSARTool/SimulationSARTool.cpp | 22 ++- Toolbox/SimulationSARTool/SimulationSARTool.h | 9 ++ 6 files changed, 233 insertions(+), 72 deletions(-) diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 4f013c4..f75c122 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -801,7 +801,7 @@ int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePa for (long i = 0; i < imgheight; i++) { - //printf("\rprocess:%f precent\t\t\t",i*100.0/imgheight); + printf("\rGEC: process:%f precent\t\t\t",i*100.0/imgheight); for (long j = 0; j < imgwidth; j++) { double lon = imglonArr(i, j); double lat = imglatArr(i, j); diff --git a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.cpp b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.cpp index aade224..6c7a5ab 100644 --- a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.cpp +++ b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.cpp @@ -6,22 +6,21 @@ #include #include #include "ui_QSimulationBPImageMultiProduction.h" - +#include "ImageNetOperator.h" QSimulationBPImageMultiProduction::QSimulationBPImageMultiProduction(QWidget *parent) : QDialog(parent),ui(new Ui::QSimulationBPImageMultiProductionClass) { ui->setupUi(this); - ui->checkBox->setEnabled(false); - ui->checkBox->setCheckable(true); - ui->checkBox->setChecked(true); QObject::connect(ui->pushButtonEchoSelect, SIGNAL(clicked()), this, SLOT(onpushButtonEchoSelectClicked())); - QObject::connect(ui->pushButtonImageSelect, SIGNAL(clicked()), this, SLOT(onpushButtonImageSelectClicked())); - QObject::connect(ui->GridNetBtn, SIGNAL(clicked()), this, SLOT(onpushButtonGridNetSelectClicked())); + QObject::connect(ui->LookTableBtn, SIGNAL(clicked()), this, SLOT(onpushButtonLookTableBtnClicked())); + QObject::connect(ui->GridNetBtn, SIGNAL(clicked()), this, SLOT(onpushButtonGridNetBtnSelectClicked())); + QObject::connect(ui->L1ASelectBtn, SIGNAL(clicked()), this, SLOT(onpushButtonL1ASelectBtnClicked())); + QObject::connect(ui->L2SelectSelect, SIGNAL(clicked()), this, SLOT(onpushButtonL2SelectSelectClicked())); QObject::connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbtnaccepted())); QObject::connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbtnrejected())); - QObject::connect(ui->checkBox, SIGNAL(stateChanged(int)), this, SLOT(oncheckboxTrigged(int))); + @@ -50,7 +49,44 @@ void QSimulationBPImageMultiProduction::onpushButtonEchoSelectClicked() } } -void QSimulationBPImageMultiProduction::onpushButtonImageSelectClicked() + +void QSimulationBPImageMultiProduction::onpushButtonLookTableBtnClicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡұļ"), // + QString(), // Ĭ· + tr(u8"All Files(*)") // ļ + ); + + // ûѡļ + if (!fileNames.isEmpty()) { + this->ui->lineEditLookTablePath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QSimulationBPImageMultiProduction::onpushButtonGridNetBtnSelectClicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡļ"), // + QString(), // Ĭ· + tr(u8"All Files(*)") // ļ + ); + + // ûѡļ + if (!fileNames.isEmpty()) { + this->ui->lineEditImageNetPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QSimulationBPImageMultiProduction::onpushButtonL1ASelectBtnClicked() { QString fileNames = QFileDialog::getSaveFileName( this, // @@ -61,7 +97,25 @@ void QSimulationBPImageMultiProduction::onpushButtonImageSelectClicked() // ûѡļ if (!fileNames.isEmpty()) { - this->ui->lineEditImagePath->setText(fileNames); + this->ui->lineEditL1AProductionPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QSimulationBPImageMultiProduction::onpushButtonL2SelectSelectClicked() +{ + QString fileNames = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡӰļ"), // + QString(), // Ĭ· + tr(u8"All Files(*)") // ļ + ); + + // ûѡļ + if (!fileNames.isEmpty()) { + this->ui->lineEditL2ProductionPath->setText(fileNames); } else { QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); @@ -70,10 +124,22 @@ void QSimulationBPImageMultiProduction::onpushButtonImageSelectClicked() void QSimulationBPImageMultiProduction::onbtnaccepted() { + QString L1ADataPath = this->ui->lineEditL1AProductionPath->text().trimmed(); + QString L2DataPath = this->ui->lineEditL2ProductionPath->text().trimmed(); + QString looktablePath = this->ui->lineEditLookTablePath->text().trimmed(); + QString imgNetPath = this->ui->lineEditImageNetPath->text().trimmed(); + QString echoDataPath = this->ui->lineEditEchoPath->text().trimmed(); + + + + + + + this->hide(); - QString echofile = this->ui->lineEditEchoPath->text().trimmed(); - QString outImageFolder = getParantFromPath(this->ui->lineEditImagePath->text().trimmed()); - QString imagename = getFileNameFromPath(this->ui->lineEditImagePath->text().trimmed()); + QString echofile = echoDataPath; + QString outImageFolder = getParantFromPath(L2DataPath); + QString imagename = getFileNameFromPath(L2DataPath); std::shared_ptr echoL0ds(new EchoL0Dataset); echoL0ds->Open(echofile); @@ -86,53 +152,31 @@ void QSimulationBPImageMultiProduction::onbtnaccepted() imagL1->setFs(echoL0ds->getFs()); imagL1->setLookSide(echoL0ds->getLookSide()); - if (ui->checkBox->isChecked()) { - gdalImage imgxyzimg(ui->lineEdit->text().trimmed()); - imagL1->OpenOrNew(outImageFolder, imagename, imgxyzimg.height, imgxyzimg.width); - } - else { - imagL1->OpenOrNew(outImageFolder, imagename, echoL0ds->getPluseCount(), echoL0ds->getPlusePoints()); - } - + gdalImage imgxyzimg(imgNetPath); + imagL1->OpenOrNew(outImageFolder, imagename, imgxyzimg.height, imgxyzimg.width); + qDebug() << u8""; TBPImageAlgCls TBPimag; TBPimag.setEchoL0(echoL0ds); TBPimag.setImageL1(imagL1); long cpucore_num = std::thread::hardware_concurrency(); TBPimag.setGPU(true); - TBPimag.ProcessWithGridNet(cpucore_num,ui->lineEdit->text().trimmed()); - + TBPimag.ProcessWithGridNet(cpucore_num, imgNetPath); + qDebug() << u8"ϵͳУ"; + + + ResampleEChoDataFromGeoEcho(imagL1->getImageRasterPath(), looktablePath, L1ADataPath); + this->show(); + QMessageBox::information(this,u8"",u8""); + + } void QSimulationBPImageMultiProduction::onbtnrejected() { this->close(); } - -void QSimulationBPImageMultiProduction::oncheckboxTrigged(int) -{ - this->ui->lineEdit->setEnabled(this->ui->checkBox->isChecked()); - this->ui->GridNetBtn->setEnabled(this->ui->checkBox->isChecked()); - -} - -void QSimulationBPImageMultiProduction::onpushButtonGridNetSelectClicked( ) -{ - QString fileNames = QFileDialog::getOpenFileName( - this, // - tr(u8"ѡӰļ"), // - QString(), // Ĭ· - tr(u8"All Files(*);;dat(*.dat);;tif(*.tif);;tiff(*.tiff)") // ļ - ); - - // ûѡļ - if (!fileNames.isEmpty()) { - this->ui->lineEdit->setText(fileNames); - } - else { - QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); - } -} + \ No newline at end of file diff --git a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.h b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.h index dc84ee7..45222a6 100644 --- a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.h +++ b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.h @@ -19,12 +19,13 @@ public: public slots: void onpushButtonEchoSelectClicked(); - void onpushButtonImageSelectClicked(); + void onpushButtonLookTableBtnClicked(); + void onpushButtonGridNetBtnSelectClicked(); + void onpushButtonL1ASelectBtnClicked(); + void onpushButtonL2SelectSelectClicked(); void onbtnaccepted(); void onbtnrejected(); - - void oncheckboxTrigged(int); - void onpushButtonGridNetSelectClicked( ); + private: Ui::QSimulationBPImageMultiProductionClass* ui; diff --git a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.ui b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.ui index a3e110a..fd5d9fd 100644 --- a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.ui +++ b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.ui @@ -32,7 +32,7 @@ - 回波地址: + 回波地址: @@ -75,23 +75,14 @@ - - - - 0 - 30 - - + - 图像网格 - - - true + 成像区域网格: - + true @@ -125,6 +116,108 @@ + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + 查找表: + + + + + + + true + + + + 0 + 30 + + + + D:\Programme\vs2022\RasterMergeTest\simulationData\demdataset\demxyz.bin + + + + + + + true + + + + 0 + 30 + + + + 选择 + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + 1级产品: + + + + + + + true + + + + 0 + 30 + + + + D:\Programme\vs2022\RasterMergeTest\simulationData\demdataset\demxyz.bin + + + + + + + true + + + + 0 + 30 + + + + 选择 + + + + + + @@ -143,12 +236,12 @@ - 仿真图像: + 2级产品: - + 0 @@ -161,7 +254,7 @@ - + 0 diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index a9b9d11..8361b9d 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -12,7 +12,7 @@ #include "QCreateInSARImagePlaneXYZRDialog.h" #include "QLookTableResampleFromWGS84ToRange.h" #include "QSARSimulationComplexEchoDataDialog.h" - +#include "QSimulationBPImageMultiProduction.h" SARSimlulationRFPCToolButton::SARSimlulationRFPCToolButton(QWidget* parent) { @@ -240,9 +240,6 @@ void QLookTableResampleFromWGS84ToRangeToolButton::run() dialog->show(); } - - - //QSARSimulationComplexEchoDataDialog QSARSimulationComplexEchoDataDialogToolButton::QSARSimulationComplexEchoDataDialogToolButton(QWidget* parent) @@ -261,3 +258,20 @@ void QSARSimulationComplexEchoDataDialogToolButton::run() QSARSimulationComplexEchoDataDialog* dialog = new QSARSimulationComplexEchoDataDialog; dialog->show(); } + +QSimulationBPImageMultiProductionToolButton::QSimulationBPImageMultiProductionToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"񹤾߿"); + this->toolname = QString(u8"1-2Ʒ"); +} + +QSimulationBPImageMultiProductionToolButton::~QSimulationBPImageMultiProductionToolButton() +{ +} + +void QSimulationBPImageMultiProductionToolButton::run() +{ + QSimulationBPImageMultiProduction* dialog = new QSimulationBPImageMultiProduction; + dialog->show(); +} diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.h b/Toolbox/SimulationSARTool/SimulationSARTool.h index 1a6212c..011b236 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.h +++ b/Toolbox/SimulationSARTool/SimulationSARTool.h @@ -165,4 +165,13 @@ public: }; +class SIMULATIONSARTOOL_EXPORT QSimulationBPImageMultiProductionToolButton : public QToolAbstract { + Q_OBJECT +public: + QSimulationBPImageMultiProductionToolButton(QWidget* parent = nullptr); + ~QSimulationBPImageMultiProductionToolButton(); +public: + virtual void run() override; + +}; From fbb2a3707eacdf6179508e7541995b7425059106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 8 Apr 2025 12:06:27 +0800 Subject: [PATCH 77/94] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E8=BF=87=E5=A4=A7=E6=97=B6=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/gdalImageComplexOperator.cpp | 41 +- .../SARImage/ImageNetOperator.cpp | 13 +- .../QSARSimulationComplexEchoDataDialog.cpp | 4 +- .../SimulationSARTool/SimulationSARTool.cpp | 40 +- .../ImageNetOperator.cpp | 912 ++++++++++++++++++ 5 files changed, 976 insertions(+), 34 deletions(-) create mode 100644 enc_temp_folder/3775b1ace76665ec73ebcf8cc5579a/ImageNetOperator.cpp diff --git a/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp b/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp index bc8a0a9..9d746f3 100644 --- a/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp +++ b/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp @@ -269,20 +269,41 @@ Eigen::MatrixXcd gdalImageComplex::getDataComplex(int start_row, int start_col, // ȡϢǸ int nXSize = cols_count; poBand->GetXSize(); int nYSize = rows_count; poBand->GetYSize(); - - double* databuffer = new double[nXSize * nYSize * 2]; - poBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, databuffer, cols_count, - rows_count, GDT_CFloat64, 0, 0); - GDALClose((GDALDatasetH)poDataset); Eigen::MatrixXcd rasterData(nYSize, nXSize); // ʹEigenMatrixXcd - for (size_t i = 0; i < nYSize; i++) { - for (size_t j = 0; j < nXSize; j++) { - rasterData(i, j) = std::complex(databuffer[i * nXSize * 2 + j * 2], - databuffer[i * nXSize * 2 + j * 2 + 1]); + if (this->getDataType() == GDT_CFloat64) + { + long long pixelCount =long long( nXSize) *long long( nYSize); + double* databuffer = new double[pixelCount * 2]; + poBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, databuffer, cols_count, rows_count, GDT_CFloat64, 0, 0); + GDALClose((GDALDatasetH)poDataset); + + for (long long i = 0; i < nYSize; i++) { + for (long long j = 0; j < nXSize; j++) { + rasterData(i, j) = std::complex(databuffer[i * nXSize * 2 + j * 2], + databuffer[i * nXSize * 2 + j * 2 + 1]); + } } + + delete[] databuffer; + } + else if(this->getDataType()==GDT_CFloat32) + { + long long pixelCount = long long(nXSize) * long long(nYSize); + float* databuffer = new float[pixelCount * 2]; + poBand->RasterIO(GF_Read, start_col, start_row, cols_count, rows_count, databuffer, cols_count, rows_count, GDT_CFloat32, 0, 0); + GDALClose((GDALDatasetH)poDataset); + + for (long long i = 0; i < nYSize; i++) { + for (long long j = 0; j < nXSize; j++) { + rasterData(i, j) = std::complex(databuffer[i * nXSize * 2 + j * 2], + databuffer[i * nXSize * 2 + j * 2 + 1]); + } + } + + delete[] databuffer; } - delete[] databuffer; + return rasterData; } diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index f75c122..5995b9f 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -789,17 +789,18 @@ int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePa gdalImage looktable(RangeLooktablePath); gdalImageComplex l1adata = CreategdalImageComplexNoProj(L1AEchoDataPath, looktable.height, looktable.width, 1, true); - Eigen::MatrixXd imglonArr = looktable.getData(0, 0, looktable.height, looktable.width, 1); - Eigen::MatrixXd imglatArr = looktable.getData(0, 0, looktable.height, looktable.width, 2); + Eigen::MatrixXcd echoArr = echodata.getDataComplex(0, 0, echodata.height, echodata.width, 1); + + + Eigen::MatrixXd imglonArr = looktable.getData(0, 0, looktable.height, looktable.width, 1); + Eigen::MatrixXd imglatArr = looktable.getData(0, 0, looktable.height, looktable.width, 2); Eigen::MatrixXcd l1aArr= l1adata.getDataComplex(0, 0, l1adata.height, l1adata.width, 1); l1aArr = l1aArr.array() * 0; long imgheight = looktable.height; long imgwidth = looktable.width; - - for (long i = 0; i < imgheight; i++) { printf("\rGEC: process:%f precent\t\t\t",i*100.0/imgheight); for (long j = 0; j < imgwidth; j++) { @@ -898,6 +899,10 @@ int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePa } l1adata.saveImage(l1aArr, 0, 0, 1); + + + + return 0; } diff --git a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp index 48a8d51..c5b8b7b 100644 --- a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp @@ -40,7 +40,7 @@ void QSARSimulationComplexEchoDataDialog::onpushButtonEchoDataSelect_clicked() // ûѡļ if (!fileNames.isEmpty()) { QString message = "ѡļУ\n"; - this->ui->lineEditL1AEchoDataPath->setText(fileNames); + this->ui->lineEditEchoDataPath->setText(fileNames); } else { QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); @@ -58,7 +58,7 @@ void QSARSimulationComplexEchoDataDialog::onpushButtonLookTableSelect_clicked() // ûѡļ if (!fileNames.isEmpty()) { QString message = "ѡļУ\n"; - this->ui->lineEditL1AEchoDataPath->setText(fileNames); + this->ui->lineEditLookTablePath->setText(fileNames); } else { QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index 8361b9d..0d16cc6 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -14,6 +14,28 @@ #include "QSARSimulationComplexEchoDataDialog.h" #include "QSimulationBPImageMultiProduction.h" + +void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox) +{ + emit toolbox->addBoxToolItemSIGNAL(new SARSimlulationRFPCToolButton(toolbox)); // 300 + emit toolbox->addBoxToolItemSIGNAL(new SARSimulationTBPImageToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QSimulationSAROrbitModelToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new LookTableComputerClassToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QCreateSARIntensityByLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QtSimulationGeoSARSigma0ToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QtLinearToIntenisityToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new InitCreateImageXYZToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new ImagePlaneAtiInterpToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QCreateInSARImagePlaneXYZRToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QInSARBPImageToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QLookTableResampleFromWGS84ToRangeToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QSARSimulationComplexEchoDataDialogToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QSimulationBPImageMultiProductionToolButton(toolbox)); + +} + + + SARSimlulationRFPCToolButton::SARSimlulationRFPCToolButton(QWidget* parent) { this->toolPath = QVector(0); @@ -72,24 +94,6 @@ void QSimulationSAROrbitModelToolButton::excute() -void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox) -{ - emit toolbox->addBoxToolItemSIGNAL(new SARSimlulationRFPCToolButton(toolbox)); // 300 - emit toolbox->addBoxToolItemSIGNAL(new SARSimulationTBPImageToolButton(toolbox)); - emit toolbox->addBoxToolItemSIGNAL(new QSimulationSAROrbitModelToolButton(toolbox)); - emit toolbox->addBoxToolItemSIGNAL(new LookTableComputerClassToolButton(toolbox)); - emit toolbox->addBoxToolItemSIGNAL(new QCreateSARIntensityByLookTableToolButton(toolbox)); - emit toolbox->addBoxToolItemSIGNAL(new QtSimulationGeoSARSigma0ToolButton(toolbox)); - emit toolbox->addBoxToolItemSIGNAL(new QtLinearToIntenisityToolButton(toolbox)); - emit toolbox->addBoxToolItemSIGNAL(new InitCreateImageXYZToolButton(toolbox)); - emit toolbox->addBoxToolItemSIGNAL(new ImagePlaneAtiInterpToolButton(toolbox)); - emit toolbox->addBoxToolItemSIGNAL(new QCreateInSARImagePlaneXYZRToolButton(toolbox)); - emit toolbox->addBoxToolItemSIGNAL(new QInSARBPImageToolButton(toolbox)); - emit toolbox->addBoxToolItemSIGNAL(new QLookTableResampleFromWGS84ToRangeToolButton(toolbox)); - emit toolbox->addBoxToolItemSIGNAL(new QSARSimulationComplexEchoDataDialogToolButton(toolbox)); - -} - LookTableComputerClassToolButton::LookTableComputerClassToolButton(QWidget* parent) { this->toolPath = QVector(0); diff --git a/enc_temp_folder/3775b1ace76665ec73ebcf8cc5579a/ImageNetOperator.cpp b/enc_temp_folder/3775b1ace76665ec73ebcf8cc5579a/ImageNetOperator.cpp new file mode 100644 index 0000000..f75c122 --- /dev/null +++ b/enc_temp_folder/3775b1ace76665ec73ebcf8cc5579a/ImageNetOperator.cpp @@ -0,0 +1,912 @@ +#include "ImageNetOperator.h" +#include "LogInfoCls.h" +#include "PrintMsgToQDebug.h" +#include +#include "ImageOperatorBase.h" +#include "GPUBaseTool.h" +#include "GPUBPImageNet.cuh" +#include "BaseTool.h" +#include "BaseConstVariable.h" + + +void InitCreateImageXYZProcess(QString& outImageLLPath, QString& outImageXYZPath, QString& InEchoGPSDataPath, + double& NearRange, double& RangeResolution, int64_t& RangeNum) +{ + qDebug() << "---------------------------------------------------------------------------------"; + qDebug() << u8"ֳƽбͶӰ"; + gdalImage antimg(InEchoGPSDataPath); + qDebug() << u8"1. زGPSļ\t"; + qDebug() << u8"ļ·\t" << InEchoGPSDataPath; + qDebug() << u8"GPS \t" << antimg.height; + qDebug() << u8"ļ\t" << antimg.width; + qDebug() << u8"2.б"; + qDebug() << u8"룺\t" << NearRange; + qDebug() << u8"ֱʣ\t" << RangeResolution; + qDebug() << u8"\t" << RangeNum; + qDebug() << u8"3.ļ"; + gdalImage outimgll = CreategdalImageDouble(outImageLLPath, antimg.height,RangeNum, 3,true,true); + gdalImage outimgxyz = CreategdalImageDouble(outImageXYZPath, antimg.height, RangeNum, 3, true, true); + qDebug() << u8"ƽļγȣ·\t" << outImageLLPath; + qDebug() << u8"ƽļXYZ·\t" << outImageXYZPath; + qDebug() << u8"4.ʼXYZ"; + long prfcount = antimg.height; + long rangeNum = RangeNum; + double Rnear = NearRange; + double dx = RangeResolution; + + long blockRangeCount = Memory1GB / sizeof(double) / 4 / prfcount *6; + blockRangeCount = blockRangeCount < 1 ? 1 : blockRangeCount; + + std::shared_ptr Pxs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr Pys((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr Pzs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectX((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectY((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectZ((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + + { + long colnum = 19; + std::shared_ptr antpos =readDataArr(antimg,0,0,prfcount, colnum,1,GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + double time = 0; + double Px = 0; + double Py = 0; + double Pz = 0; + for (long i = 0; i < prfcount; i++) { + + Pxs.get()[i] = antpos.get()[i * 19 + 1]; // + Pys.get()[i] = antpos.get()[i * 19 + 2]; + Pzs.get()[i] = antpos.get()[i * 19 + 3]; + AntDirectX.get()[i] = antpos.get()[i * 19 + 13];// zero doppler + AntDirectY.get()[i] = antpos.get()[i * 19 + 14]; + AntDirectZ.get()[i] = antpos.get()[i * 19 + 15]; + + double NormAnt = std::sqrt(AntDirectX.get()[i] * AntDirectX.get()[i] + + AntDirectY.get()[i] * AntDirectY.get()[i] + + AntDirectZ.get()[i] * AntDirectZ.get()[i]); + AntDirectX.get()[i] = AntDirectX.get()[i] / NormAnt; + AntDirectY.get()[i] = AntDirectY.get()[i] / NormAnt; + AntDirectZ.get()[i] = AntDirectZ.get()[i] / NormAnt;// һ + } + antpos.reset(); + } + + std::shared_ptr d_Pxs((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); + std::shared_ptr d_Pys((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); + std::shared_ptr d_Pzs((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); + std::shared_ptr d_AntDirectX((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); + std::shared_ptr d_AntDirectY((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); + std::shared_ptr d_AntDirectZ((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); + + HostToDevice(Pxs.get(), d_Pxs.get(), sizeof(double) * prfcount); + HostToDevice(Pys.get(), d_Pys.get(), sizeof(double) * prfcount); + HostToDevice(Pzs.get(), d_Pzs.get(), sizeof(double) * prfcount); + HostToDevice(AntDirectX.get(), d_AntDirectX.get(), sizeof(double) * prfcount); + HostToDevice(AntDirectY.get(), d_AntDirectY.get(), sizeof(double) * prfcount); + HostToDevice(AntDirectZ.get(), d_AntDirectZ.get(), sizeof(double) * prfcount); + + + for (long startcolidx = 0; startcolidx < RangeNum; startcolidx = startcolidx + blockRangeCount) { + + long tempechocol = blockRangeCount; + if (startcolidx + tempechocol >= RangeNum) { + tempechocol = RangeNum - startcolidx; + } + qDebug() << " imgxyz :\t" << startcolidx << "\t-\t" << startcolidx + tempechocol << " / " << RangeNum; + + std::shared_ptr demx = readDataArr(outimgxyz, 0, startcolidx, prfcount, tempechocol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demy = readDataArr(outimgxyz, 0, startcolidx, prfcount, tempechocol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demz = readDataArr(outimgxyz, 0, startcolidx, prfcount, tempechocol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + + std::shared_ptr h_demx((double*)mallocCUDAHost(sizeof(double) * prfcount * tempechocol), FreeCUDAHost); + std::shared_ptr h_demy((double*)mallocCUDAHost(sizeof(double) * prfcount * tempechocol), FreeCUDAHost); + std::shared_ptr h_demz((double*)mallocCUDAHost(sizeof(double) * prfcount * tempechocol), FreeCUDAHost); + +#pragma omp parallel for + for (long ii = 0; ii < prfcount; ii++) { + for (long jj = 0; jj < tempechocol; jj++) { + h_demx.get()[ii * tempechocol + jj] = demx.get()[ii * tempechocol + jj]; + h_demy.get()[ii * tempechocol + jj] = demy.get()[ii * tempechocol + jj]; + h_demz.get()[ii * tempechocol + jj] = demz.get()[ii * tempechocol + jj]; + } + } + + std::shared_ptr d_demx((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); + std::shared_ptr d_demy((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); + std::shared_ptr d_demz((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); + + HostToDevice(h_demx.get(), d_demx.get(), sizeof(double) * prfcount * tempechocol); + HostToDevice(h_demy.get(), d_demy.get(), sizeof(double) * prfcount * tempechocol); + HostToDevice(h_demz.get(), d_demz.get(), sizeof(double) * prfcount * tempechocol); + + + TIMEBPCreateImageGrid( + d_Pxs.get(), d_Pys.get(), d_Pzs.get(), + d_AntDirectX.get(), d_AntDirectY.get(), d_AntDirectZ.get(), + d_demx.get(), d_demy.get(), d_demz.get(), + prfcount, tempechocol, 0, + Rnear + dx * startcolidx, dx // ޶ + ); + + DeviceToHost(h_demx.get(), d_demx.get(), sizeof(double) * prfcount * tempechocol); + DeviceToHost(h_demy.get(), d_demy.get(), sizeof(double) * prfcount * tempechocol); + DeviceToHost(h_demz.get(), d_demz.get(), sizeof(double) * prfcount * tempechocol); + +#pragma omp parallel for + for (long ii = 0; ii < prfcount; ii++) { + for (long jj = 0; jj < tempechocol; jj++) { + demx.get()[ii * tempechocol + jj] = h_demx.get()[ii * tempechocol + jj]; + demy.get()[ii * tempechocol + jj] = h_demy.get()[ii * tempechocol + jj]; + demz.get()[ii * tempechocol + jj] = h_demz.get()[ii * tempechocol + jj]; + } + } + + outimgxyz.saveImage(demx, 0, startcolidx, prfcount, tempechocol, 1); + outimgxyz.saveImage(demy, 0, startcolidx, prfcount, tempechocol, 2); + outimgxyz.saveImage(demz, 0, startcolidx, prfcount, tempechocol, 3); + + // XYZתΪγ + std::shared_ptr demllx = readDataArr(outimgll, 0, startcolidx, prfcount, tempechocol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demlly = readDataArr(outimgll, 0, startcolidx, prfcount, tempechocol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + std::shared_ptr demllz = readDataArr(outimgll, 0, startcolidx, prfcount, tempechocol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + +#pragma omp parallel for + for (long ii = 0; ii < prfcount; ii++) { + for (long jj = 0; jj < tempechocol; jj++) { + double x = demx.get()[ii * tempechocol + jj]; + double y = demy.get()[ii * tempechocol + jj]; + double z = demz.get()[ii * tempechocol + jj]; + Landpoint point; + XYZ2BLH_FixedHeight(x, y, z, 0, point); + demllx.get()[ii * tempechocol + jj] = point.lon; + demlly.get()[ii * tempechocol + jj] = point.lat; + demllz.get()[ii * tempechocol + jj] = point.ati; + } + } + + + outimgll.saveImage(demllx, 0, startcolidx, prfcount, tempechocol, 1); + outimgll.saveImage(demlly, 0, startcolidx, prfcount, tempechocol, 2); + outimgll.saveImage(demllz, 0, startcolidx, prfcount, tempechocol, 3); + + } + + qDebug() << u8"6."; + qDebug() << "---------------------------------------------------------------------------------"; +} + +bool OverlapCheck(QString& ImageLLPath, QString& ImageDEMPath) +{ + // DEMǷWGS84ϵ + //long demEPSG = GetEPSGFromRasterFile(ImageDEMPath); + //if (demEPSG != 4326) { + // qDebug() << u8"DEMϵWGS84ϵ,ESPG:"<< demEPSG; + // return false; + //} + + gdalImage demimg(ImageDEMPath); + gdalImage imgll(ImageLLPath); + + long imgheight = imgll.height; + long imgwidth = imgll.width; + Eigen::MatrixXd imglonArr = imgll.getData(0, 0, imgheight, imgwidth, 1); + Eigen::MatrixXd imglatArr = imgll.getData(0, 0, imgheight, imgwidth, 2); + + // ӡΧ + qDebug() << u8"ӰΧ"; + qDebug() << u8"Сȣ\t" << imglonArr.minCoeff(); + qDebug() << u8"󾭶ȣ\t" << imglonArr.maxCoeff(); + qDebug() << u8"Сγȣ\t" << imglatArr.minCoeff(); + qDebug() << u8"γȣ\t" << imglatArr.maxCoeff(); + qDebug() << u8"DEMΧ"; + RasterExtend demextend = demimg.getExtend(); + qDebug() << u8"Сȣ\t" << demextend.min_x; + qDebug() << u8"󾭶ȣ\t" << demextend.max_x; + qDebug() << u8"Сγȣ\t" << demextend.min_y; + qDebug() << u8"γȣ\t" << demextend.max_y; + qDebug() << u8"ӰС\t" << demimg.height << " * " << demimg.width; + + + + for (long i = 0; i < imgheight; i++) + { + for (long j = 0; j < imgwidth; j++) + { + double lon = imglonArr(i, j); // X + double lat = imglatArr(i, j); // Y + Landpoint point = demimg.getRow_Col(lon, lat); + imglonArr(i, j) = point.lon; + imglatArr(i, j) = point.lat; + } + } + + double minX = imglonArr.minCoeff(); + double maxX = imglonArr.maxCoeff(); + double minY = imglatArr.minCoeff(); + double maxY = imglatArr.maxCoeff(); + + //ӡΧ + qDebug() << u8"dem ķΧ"; + qDebug() << u8"minX:"<demimg.width - 1 || minY<1 || maxY>demimg.height - 1) { + return false; + } + else { + return true; + } + + + +} + +bool GPSPointsNumberEqualCheck(QString& ImageLLPath, QString& InEchoGPSDataPath) +{ + + gdalImage antimg(InEchoGPSDataPath); + gdalImage imgll(ImageLLPath); + return antimg.height == imgll.height; + +} + + + +void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath) +{ + gdalImage demimg(ImageDEMPath); + gdalImage imgll(ImageLLPath); + gdalImage outimgll = CreategdalImageDouble(outImageLLAPath, imgll.height, imgll.width, 4, true, true); // ȡγȡ̡߳б + + long imgheight = imgll.height; + long imgwidth = imgll.width; + + Eigen::MatrixXd imglonArr = imgll.getData(0, 0, imgheight, imgwidth, 1); + Eigen::MatrixXd imglatArr = imgll.getData(0, 0, imgheight, imgwidth, 2); + Eigen::MatrixXd demArr = demimg.getData(0, 0, demimg.height, demimg.width, 1); + Eigen::MatrixXd imgatiArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); + Eigen::MatrixXd imgRArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); + + outimgll.saveImage(imglonArr, 0, 0, 1); + outimgll.saveImage(imglatArr, 0, 0, 2); + + + double minX = imglonArr.minCoeff(); + double maxX = imglonArr.maxCoeff(); + double minY = imglatArr.minCoeff(); + double maxY = imglatArr.maxCoeff(); + //ӡΧ + qDebug() << u8"dem ķΧ"; + qDebug() << u8"minX:" << minX << "\t" << demimg.width; + qDebug() << u8"maxX:" << maxX << "\t" << demimg.width; + qDebug() << u8"minY:" << minY << "\t" << demimg.height; + qDebug() << u8"maxY:" << maxY << "\t" << demimg.height; + qDebug() << u8"ͼУ\t" << demimg.height << " , " << demimg.width; + + + for (long i = 0; i < imgheight; i++) { + //printf("\rprocess:%f precent\t\t\t",i*100.0/imgheight); + for (long j = 0; j < imgwidth; j++) { + double lon = imglonArr(i, j); + double lat = imglatArr(i, j); + Landpoint point = demimg.getRow_Col(lon, lat); + + if (point.lon<1 || point.lon>demimg.width - 2 || point.lat < 1 || point.lat - 2) { + continue; + } + else {} + + Landpoint p0, p11, p21, p12, p22; + + p0.lon = point.lon; + p0.lat = point.lat; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + p11.ati = demArr(long(p11.lat), long(p11.lon)); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + p12.ati = demArr(long(p12.lat), long(p12.lon)); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + p21.ati = demArr(long(p21.lat), long(p21.lon)); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + p22.ati = demArr(long(p22.lat), long(p22.lon)); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + p0.ati=Bilinear_interpolation(p0, p11, p21, p12, p22); + imgatiArr(i, j) = p0.ati; + + } + } + outimgll.saveImage(imgatiArr, 0, 0, 3); + qDebug() << u8"ÿбֵ"; + + + gdalImage antimg(InEchoGPSDataPath); + qDebug() << u8"1. زGPSļ\t"; + qDebug() << u8"ļ·\t" << InEchoGPSDataPath; + qDebug() << u8"GPS \t" << antimg.height; + qDebug() << u8"ļ\t" << antimg.width; + + long prfcount = antimg.height; + + + std::shared_ptr Pxs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr Pys((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr Pzs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectX((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectY((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectZ((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + + { + long colnum = 19; + std::shared_ptr antpos = readDataArr(antimg, 0, 0, prfcount, colnum, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + double time = 0; + double Px = 0; + double Py = 0; + double Pz = 0; + for (long i = 0; i < prfcount; i++) { + + Pxs.get()[i] = antpos.get()[i * 19 + 1]; // + Pys.get()[i] = antpos.get()[i * 19 + 2]; + Pzs.get()[i] = antpos.get()[i * 19 + 3]; + AntDirectX.get()[i] = antpos.get()[i * 19 + 13];// zero doppler + AntDirectY.get()[i] = antpos.get()[i * 19 + 14]; + AntDirectZ.get()[i] = antpos.get()[i * 19 + 15]; + + double NormAnt = std::sqrt(AntDirectX.get()[i] * AntDirectX.get()[i] + + AntDirectY.get()[i] * AntDirectY.get()[i] + + AntDirectZ.get()[i] * AntDirectZ.get()[i]); + AntDirectX.get()[i] = AntDirectX.get()[i] / NormAnt; + AntDirectY.get()[i] = AntDirectY.get()[i] / NormAnt; + AntDirectZ.get()[i] = AntDirectZ.get()[i] / NormAnt;// һ + } + antpos.reset(); + } + + + +#pragma omp parallel for + for (long prfid = 0; prfid < prfcount; prfid++) { + double Px = Pxs.get()[prfid]; + double Py = Pys.get()[prfid]; + double Pz = Pzs.get()[prfid]; + double R = 0; + Landpoint LLA = {}; + Point3 XYZ = {}; + for (long j = 0; j < imgwidth; j++) { + LLA.lon = imglonArr(prfid, j); + LLA.lat = imglatArr(prfid, j); + LLA.ati = imgatiArr(prfid, j); + + LLA2XYZ(LLA, XYZ); + + R = sqrt(pow(Px - XYZ.x, 2) + + pow(Py - XYZ.y, 2) + + pow(Pz - XYZ.z, 2)); + imgRArr(prfid, j) = R; + } + } + + outimgll.saveImage(imgRArr, 0, 0, 4); + + qDebug() << u8"ֵ"; +} + + +void InterploateClipAtiByRefDEM(QString ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath) { + + gdalImage demimg(ImageDEMPath); + gdalImage imgll(ImageLLPath); + + // ü + long imgheight = imgll.height; + long imgwidth = imgll.width; + + long minRow = -1; + long maxRow = imgheight; + long minCol = -1; + long maxCol = imgwidth; + + + Eigen::MatrixXd imglonArr = imgll.getData(0, 0, imgheight, imgwidth, 1); + Eigen::MatrixXd imglatArr = imgll.getData(0, 0, imgheight, imgwidth, 2); + +#pragma omp parallel for + for (long i = 0; i < imgheight; i++) { + for (long j = 0; j < imgwidth; j++) { + double lon = imglonArr(i, j); + double lat = imglatArr(i, j); + Landpoint point = demimg.getRow_Col(lon, lat); + imglonArr(i, j) = point.lon; + imglatArr(i, j) = point.lat; + } + } + + // ʼɨ + + bool minRowFlag=true, maxRowFlag= true, minColFlag = true, maxColFlag = true; + + for (long i = 0; i < imgheight; i++) { + for (long j = 0; j < imgwidth; j++) { + if (imglonArr(i, j) > 0 && minRowFlag) { + minRowFlag = false; + minRow = i; + break; + } + if (imglonArr(i, j) < imgheight) { + maxRow = i; + } + } + } + + for (long j = 0; j < imgwidth; j++) { + for (long i = 0; i < imgheight; i++) { + if (imglatArr(i, j) > 0 && minColFlag) { + minColFlag = false; + minCol = j; + break; + } + if (imglatArr(i, j) < imgheight) { + maxCol = j; + } + } + } + + + long RowCount = maxRow - minRow; + long ColCount = maxCol - minCol; + + gdalImage outimgll = CreategdalImageDouble(outImageLLAPath, RowCount, ColCount, 4, true, true); // ȡγȡ̡߳б + + imgheight = outimgll.height; + imgwidth = outimgll.width; + + imglonArr = imgll.getData(minRow, minCol, RowCount, ColCount, 1); + imglatArr = imgll.getData(minRow, minCol, RowCount, ColCount, 2); + + Eigen::MatrixXd demArr = demimg.getData(0, 0, demimg.height, demimg.width, 1); + + Eigen::MatrixXd imgatiArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); + Eigen::MatrixXd imgRArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); + + outimgll.saveImage(imglonArr, 0, 0, 1); + outimgll.saveImage(imglatArr, 0, 0, 2); + + + double minX = imglonArr.minCoeff(); + double maxX = imglonArr.maxCoeff(); + double minY = imglatArr.minCoeff(); + double maxY = imglatArr.maxCoeff(); + + //ӡΧ + qDebug() << u8"dem ķΧ"; + qDebug() << u8"minX:" << minX << "\t" << demimg.width; + qDebug() << u8"maxX:" << maxX << "\t" << demimg.width; + qDebug() << u8"minY:" << minY << "\t" << demimg.height; + qDebug() << u8"maxY:" << maxY << "\t" << demimg.height; + qDebug() << u8"ͼУ\t" << demimg.height << " , " << demimg.width; + + + for (long i = 0; i < imgheight; i++) { + //printf("\rprocess:%f precent\t\t\t",i*100.0/imgheight); + for (long j = 0; j < imgwidth; j++) { + double lon = imglonArr(i, j); + double lat = imglatArr(i, j); + Landpoint point = demimg.getRow_Col(lon, lat); + + if (point.lon<1 || point.lon>demimg.width - 2 || point.lat < 1 || point.lat - 2) { + continue; + } + else {} + + Landpoint p0, p11, p21, p12, p22; + + p0.lon = point.lon; + p0.lat = point.lat; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + p11.ati = demArr(long(p11.lat), long(p11.lon)); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + p12.ati = demArr(long(p12.lat), long(p12.lon)); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + p21.ati = demArr(long(p21.lat), long(p21.lon)); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + p22.ati = demArr(long(p22.lat), long(p22.lon)); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); + imgatiArr(i, j) = p0.ati; + } + } + + outimgll.saveImage(imgatiArr, 0, 0, 3); + qDebug() << u8"ÿбֵ"; + + + gdalImage antimg(InEchoGPSDataPath); + qDebug() << u8"1. زGPSļ\t"; + qDebug() << u8"ļ·\t" << InEchoGPSDataPath; + qDebug() << u8"GPS \t" << antimg.height; + qDebug() << u8"ļ\t" << antimg.width; + + long prfcount = antimg.height; + + + std::shared_ptr Pxs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr Pys((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr Pzs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectX((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectY((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + std::shared_ptr AntDirectZ((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); + + { + long colnum = 19; + std::shared_ptr antpos = readDataArr(antimg, 0, 0, prfcount, colnum, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); + double time = 0; + double Px = 0; + double Py = 0; + double Pz = 0; + for (long i = 0; i < prfcount; i++) { + + Pxs.get()[i] = antpos.get()[i * 19 + 1]; // + Pys.get()[i] = antpos.get()[i * 19 + 2]; + Pzs.get()[i] = antpos.get()[i * 19 + 3]; + AntDirectX.get()[i] = antpos.get()[i * 19 + 13];// zero doppler + AntDirectY.get()[i] = antpos.get()[i * 19 + 14]; + AntDirectZ.get()[i] = antpos.get()[i * 19 + 15]; + + double NormAnt = std::sqrt(AntDirectX.get()[i] * AntDirectX.get()[i] + + AntDirectY.get()[i] * AntDirectY.get()[i] + + AntDirectZ.get()[i] * AntDirectZ.get()[i]); + AntDirectX.get()[i] = AntDirectX.get()[i] / NormAnt; + AntDirectY.get()[i] = AntDirectY.get()[i] / NormAnt; + AntDirectZ.get()[i] = AntDirectZ.get()[i] / NormAnt;// һ + } + antpos.reset(); + } + + + +#pragma omp parallel for + for (long prfid = minRow; prfid < maxRow; prfid++) { + double Px = Pxs.get()[prfid]; + double Py = Pys.get()[prfid]; + double Pz = Pzs.get()[prfid]; + double R = 0; + Landpoint LLA = {}; + Point3 XYZ = {}; + for (long j = 0; j < imgwidth; j++) { + LLA.lon = imglonArr(prfid-minRow, j); + LLA.lat = imglatArr(prfid - minRow, j); + LLA.ati = imgatiArr(prfid - minRow, j); + + LLA2XYZ(LLA, XYZ); + + R = sqrt(pow(Px - XYZ.x, 2) + + pow(Py - XYZ.y, 2) + + pow(Pz - XYZ.z, 2)); + imgRArr(prfid - minRow, j) = R; + } + } + + outimgll.saveImage(imgRArr, 0, 0, 4); + + qDebug() << u8"ֵ"; + +} + + + + +int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QString ori_sim_count_tiffPath,long OriHeight,long OriWidth) +{ + gdalImage sim_rc(dem_rc_path); + gdalImage sim_sar_img = CreategdalImage(outOriSimTiffPath, OriHeight, OriWidth, 2, sim_rc.gt, sim_rc.projection, false);// עﱣ + for (int max_rows_ids = 0; max_rows_ids < OriHeight; max_rows_ids = max_rows_ids + 1000) { + Eigen::MatrixXd sim_sar = sim_sar_img.getData(max_rows_ids, 0, 1000, OriWidth, 1); + Eigen::MatrixXd sim_sarc = sim_sar_img.getData(max_rows_ids, 0, 1000, OriWidth, 2); + sim_sar = sim_sar.array() * 0 - 9999; + sim_sarc = sim_sar.array() * 0 - 9999; + sim_sar_img.saveImage(sim_sar, max_rows_ids, 0, 1); + sim_sar_img.saveImage(sim_sarc, max_rows_ids, 0, 2); + } + sim_sar_img.setNoDataValue(-9999, 1); + sim_sar_img.setNoDataValue(-9999, 2); + int conver_lines = 5000; + int line_invert = 4000;// ص + int line_offset = 60; + // + omp_lock_t lock; + omp_init_lock(&lock); // ʼ + int allCount = 0; + + for (int max_rows_ids = 0; max_rows_ids < sim_rc.height; max_rows_ids = max_rows_ids + line_invert) { + Eigen::MatrixXd dem_r = sim_rc.getData(max_rows_ids, 0, conver_lines, sim_rc.width, 1); + Eigen::MatrixXd dem_c = sim_rc.getData(max_rows_ids, 0, conver_lines, sim_rc.width, 2); + int dem_rows_num = dem_r.rows(); + int dem_cols_num = dem_r.cols(); + // ²ֵγ + //Eigen::MatrixXd dem_lon = dem_r; + //Eigen::MatrixXd dem_lat = dem_c; + // ¾γȲ + + int temp_r, temp_c; + + int min_row = dem_r.minCoeff() + 1; + int max_row = dem_r.maxCoeff() + 1; + + if (max_row < 0) { + continue; + } + + int len_rows = max_row - min_row; + min_row = min_row < 0 ? 0 : min_row; + Eigen::MatrixXd sar_r = sim_sar_img.getData(min_row, 0, len_rows, OriWidth, 1); + Eigen::MatrixXd sar_c = sim_sar_img.getData(min_row, 0, len_rows, OriWidth, 2); + len_rows = sar_r.rows(); + + +#pragma omp parallel for num_threads(8) // NEW ADD + for (int i = 0; i < dem_rows_num - 1; i++) { + for (int j = 0; j < dem_cols_num - 1; j++) { + Point3 p, p1, p2, p3, p4; + Landpoint lp1, lp2, lp3, lp4; + lp1 = sim_rc.getLandPoint(i + max_rows_ids, j, 0); + lp2 = sim_rc.getLandPoint(i + max_rows_ids, j + 1, 0); + lp3 = sim_rc.getLandPoint(i + 1 + max_rows_ids, j + 1, 0); + lp4 = sim_rc.getLandPoint(i + 1 + max_rows_ids, j, 0); + + p1 = { dem_r(i,j),dem_c(i,j) }; + p2 = { dem_r(i,j + 1),dem_c(i,j + 1) }; + p3 = { dem_r(i + 1,j + 1),dem_c(i + 1,j + 1) }; + p4 = { dem_r(i + 1,j),dem_c(i + 1,j) }; + + //if (angle(i, j) >= 90 && angle(i, j + 1) >= 90 && angle(i + 1, j) >= 90 && angle(i + 1, j + 1) >= 90) { + // continue; + //} + + double temp_min_r = dem_r.block(i, j, 2, 2).minCoeff(); + double temp_max_r = dem_r.block(i, j, 2, 2).maxCoeff(); + double temp_min_c = dem_c.block(i, j, 2, 2).minCoeff(); + double temp_max_c = dem_c.block(i, j, 2, 2).maxCoeff(); + if ((int(temp_min_r) != int(temp_max_r)) && (int(temp_min_c) != int(temp_max_c))) { + for (int ii = int(temp_min_r); ii <= temp_max_r + 1; ii++) { + for (int jj = int(temp_min_c); jj < temp_max_c + 1; jj++) { + if (ii < min_row || ii - min_row >= len_rows || jj < 0 || jj >= OriWidth) { + continue; + } + p = { double(ii),double(jj),0 }; + //if (PtInRect(p, p1, p2, p3, p4)) { + p1.z = lp1.lon; + p2.z = lp2.lon; + p3.z = lp3.lon; + p4.z = lp4.lon; + + p = invBilinear(p, p1, p2, p3, p4); + if (isnan(p.z)) { + continue; + } + + if (p.x < 0) { + continue; + } + double mean = (p1.z + p2.z + p3.z + p4.z) / 4; + if (p.z > p1.z && p.z > p2.z && p.z > p3.z && p.z > p4.z) { + p.z = mean; + } + if (p.z < p1.z && p.z < p2.z && p.z < p3.z && p.z < p4.z) { + p.z = mean; + } + sar_r(ii - min_row, jj) = p.z; + p1.z = lp1.lat; + p2.z = lp2.lat; + p3.z = lp3.lat; + p4.z = lp4.lat; + p = invBilinear(p, p1, p2, p3, p4); + if (isnan(p.z)) { + continue; + } + + if (p.x < 0) { + continue; + } + mean = (p1.z + p2.z + p3.z + p4.z) / 4; + if (p.z > p1.z && p.z > p2.z && p.z > p3.z && p.z > p4.z) { + p.z = mean; + } + if (p.z < p1.z && p.z < p2.z && p.z < p3.z && p.z < p4.z) { + p.z = mean; + } + sar_c(ii - min_row, jj) = p.z; + //} + } + } + + } + } + } + + omp_set_lock(&lock); //û + sim_sar_img.saveImage(sar_r, min_row, 0, 1); + sim_sar_img.saveImage(sar_c, min_row, 0, 2); + allCount = allCount + conver_lines; + qDebug() << "rows:\t" << allCount << "/" << sim_rc.height << "\t computing.....\t" ; + omp_unset_lock(&lock); //ͷŻ + + + } + + return 0; +} + + + +int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePath, QString L1AEchoDataPath) { + gdalImageComplex echodata(L2echodataPath); + gdalImage looktable(RangeLooktablePath); + gdalImageComplex l1adata = CreategdalImageComplexNoProj(L1AEchoDataPath, looktable.height, looktable.width, 1, true); + + Eigen::MatrixXd imglonArr = looktable.getData(0, 0, looktable.height, looktable.width, 1); + Eigen::MatrixXd imglatArr = looktable.getData(0, 0, looktable.height, looktable.width, 2); + + Eigen::MatrixXcd echoArr = echodata.getDataComplex(0, 0, echodata.height, echodata.width, 1); + Eigen::MatrixXcd l1aArr= l1adata.getDataComplex(0, 0, l1adata.height, l1adata.width, 1); + l1aArr = l1aArr.array() * 0; + + long imgheight = looktable.height; + long imgwidth = looktable.width; + + + for (long i = 0; i < imgheight; i++) { + printf("\rGEC: process:%f precent\t\t\t",i*100.0/imgheight); + for (long j = 0; j < imgwidth; j++) { + double lon = imglonArr(i, j); + double lat = imglatArr(i, j); + Landpoint point = echodata.getRow_Col(lon, lat); + + if (point.lon<1 || point.lon>echodata.width - 2 || point.lat < 1 || point.lat >echodata.height - 2) { + continue; + } + else {} + // ʵֵ + { + Landpoint p0, p11, p21, p12, p22; + + p0.lon = point.lon; + p0.lat = point.lat; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + p11.ati = echoArr(long(p11.lat), long(p11.lon)).real(); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + p12.ati = echoArr(long(p12.lat), long(p12.lon)).real(); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + p21.ati = echoArr(long(p21.lat), long(p21.lon)).real(); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + p22.ati = echoArr(long(p22.lat), long(p22.lon)).real(); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); + l1aArr(i, j).real(p0.ati); + } + //鲿ֵ + { + Landpoint p0, p11, p21, p12, p22; + + p0.lon = point.lon; + p0.lat = point.lat; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + p11.ati = echoArr(long(p11.lat), long(p11.lon)).imag(); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + p12.ati = echoArr(long(p12.lat), long(p12.lon)).imag(); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + p21.ati = echoArr(long(p21.lat), long(p21.lon)).imag(); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + p22.ati = echoArr(long(p22.lat), long(p22.lon)).imag(); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); + l1aArr(i, j).imag(p0.ati); + } + + } + } + + l1adata.saveImage(l1aArr, 0, 0, 1); + return 0; + +} + + + + + + + + + From 1e2b811c73acdbf0f9d35c455f36c238259636d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Tue, 8 Apr 2025 12:19:06 +0800 Subject: [PATCH 78/94] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=88=86?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SARImage/ImageNetOperator.cpp | 211 +++++++++--------- 1 file changed, 106 insertions(+), 105 deletions(-) diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 5995b9f..0c8095d 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -788,118 +788,119 @@ int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePa gdalImageComplex echodata(L2echodataPath); gdalImage looktable(RangeLooktablePath); gdalImageComplex l1adata = CreategdalImageComplexNoProj(L1AEchoDataPath, looktable.height, looktable.width, 1, true); - - - Eigen::MatrixXcd echoArr = echodata.getDataComplex(0, 0, echodata.height, echodata.width, 1); + long blockHeight = Memory1GB / looktable.width / 8 * 2; - Eigen::MatrixXd imglonArr = looktable.getData(0, 0, looktable.height, looktable.width, 1); - Eigen::MatrixXd imglatArr = looktable.getData(0, 0, looktable.height, looktable.width, 2); - Eigen::MatrixXcd l1aArr= l1adata.getDataComplex(0, 0, l1adata.height, l1adata.width, 1); - l1aArr = l1aArr.array() * 0; - - long imgheight = looktable.height; - long imgwidth = looktable.width; - for (long i = 0; i < imgheight; i++) { - printf("\rGEC: process:%f precent\t\t\t",i*100.0/imgheight); - for (long j = 0; j < imgwidth; j++) { - double lon = imglonArr(i, j); - double lat = imglatArr(i, j); - Landpoint point = echodata.getRow_Col(lon, lat); + for (long startRow = 0; startRow < looktable.height; startRow = startRow + blockHeight) { + printf("\rGEC: process:%f precent\t\t\t", startRow * 100.0 / looktable.height); + blockHeight = blockHeight + startRow < looktable.height ? blockHeight : looktable.height - startRow; + Eigen::MatrixXd imglonArr = looktable.getData(startRow, 0, blockHeight, looktable.width, 1); + Eigen::MatrixXd imglatArr = looktable.getData(startRow, 0, blockHeight, looktable.width, 2); + Eigen::MatrixXcd l1aArr = l1adata.getDataComplex(0, 0, blockHeight, l1adata.width, 1); + l1aArr = l1aArr.array() * 0; + + long imgheight = blockHeight; + long imgwidth = looktable.width; + for (long i = 0; i < imgheight; i++) { + + for (long j = 0; j < imgwidth; j++) { + double lon = imglonArr(i, j); + double lat = imglatArr(i, j); + Landpoint point = echodata.getRow_Col(lon, lat); + + if (point.lon<1 || point.lon>echodata.width - 2 || point.lat < 1 || point.lat >echodata.height - 2) { + continue; + } + else {} + // ʵֵ + { + Landpoint p0, p11, p21, p12, p22; + + p0.lon = point.lon; + p0.lat = point.lat; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + p11.ati = echoArr(long(p11.lat), long(p11.lon)).real(); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + p12.ati = echoArr(long(p12.lat), long(p12.lon)).real(); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + p21.ati = echoArr(long(p21.lat), long(p21.lon)).real(); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + p22.ati = echoArr(long(p22.lat), long(p22.lon)).real(); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); + l1aArr(i, j).real(p0.ati); + } + //鲿ֵ + { + Landpoint p0, p11, p21, p12, p22; + + p0.lon = point.lon; + p0.lat = point.lat; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + p11.ati = echoArr(long(p11.lat), long(p11.lon)).imag(); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + p12.ati = echoArr(long(p12.lat), long(p12.lon)).imag(); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + p21.ati = echoArr(long(p21.lat), long(p21.lon)).imag(); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + p22.ati = echoArr(long(p22.lat), long(p22.lon)).imag(); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); + l1aArr(i, j).imag(p0.ati); + } - if (point.lon<1 || point.lon>echodata.width - 2 || point.lat < 1 || point.lat >echodata.height - 2) { - continue; } - else {} - // ʵֵ - { - Landpoint p0, p11, p21, p12, p22; - - p0.lon = point.lon; - p0.lat = point.lat; - - p11.lon = floor(p0.lon); - p11.lat = floor(p0.lat); - p11.ati = echoArr(long(p11.lat), long(p11.lon)).real(); - - p12.lon = ceil(p0.lon); - p12.lat = floor(p0.lat); - p12.ati = echoArr(long(p12.lat), long(p12.lon)).real(); - - p21.lon = floor(p0.lon); - p21.lat = ceil(p0.lat); - p21.ati = echoArr(long(p21.lat), long(p21.lon)).real(); - - p22.lon = ceil(p0.lon); - p22.lat = ceil(p0.lat); - p22.ati = echoArr(long(p22.lat), long(p22.lon)).real(); - - p0.lon = p0.lon - p11.lon; - p0.lat = p0.lat - p11.lat; - - p12.lon = p12.lon - p11.lon; - p12.lat = p12.lat - p11.lat; - - p21.lon = p21.lon - p11.lon; - p21.lat = p21.lat - p11.lat; - - p22.lon = p22.lon - p11.lon; - p22.lat = p22.lat - p11.lat; - - p11.lon = p11.lon - p11.lon; - p11.lat = p11.lat - p11.lat; - - p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); - l1aArr(i, j).real(p0.ati); - } - //鲿ֵ - { - Landpoint p0, p11, p21, p12, p22; - - p0.lon = point.lon; - p0.lat = point.lat; - - p11.lon = floor(p0.lon); - p11.lat = floor(p0.lat); - p11.ati = echoArr(long(p11.lat), long(p11.lon)).imag(); - - p12.lon = ceil(p0.lon); - p12.lat = floor(p0.lat); - p12.ati = echoArr(long(p12.lat), long(p12.lon)).imag(); - - p21.lon = floor(p0.lon); - p21.lat = ceil(p0.lat); - p21.ati = echoArr(long(p21.lat), long(p21.lon)).imag(); - - p22.lon = ceil(p0.lon); - p22.lat = ceil(p0.lat); - p22.ati = echoArr(long(p22.lat), long(p22.lon)).imag(); - - p0.lon = p0.lon - p11.lon; - p0.lat = p0.lat - p11.lat; - - p12.lon = p12.lon - p11.lon; - p12.lat = p12.lat - p11.lat; - - p21.lon = p21.lon - p11.lon; - p21.lat = p21.lat - p11.lat; - - p22.lon = p22.lon - p11.lon; - p22.lat = p22.lat - p11.lat; - - p11.lon = p11.lon - p11.lon; - p11.lat = p11.lat - p11.lat; - - p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); - l1aArr(i, j).imag(p0.ati); - } - } - } - l1adata.saveImage(l1aArr, 0, 0, 1); - + l1adata.saveImage(l1aArr, startRow, 0, 1); + } From 6b87c8431192714dbdb4b81a577f75a7354041f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Wed, 9 Apr 2025 15:06:06 +0800 Subject: [PATCH 79/94] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=861-3=E7=BA=A7?= =?UTF-8?q?=E5=9B=9E=E6=B3=A2=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/BaseCommonLibrary.vcxproj | 4 +- .../BaseTool/gdalImageComplexOperator.cpp | 50 +- .../SARImage/ImageNetOperator.cpp | 3 +- .../QSARSimulationComplexEchoDataDialog.cpp | 2 +- .../QSimulationBPImageMultiProduction.cpp | 31 +- .../QSimulationBPImageMultiProduction.ui | 10 +- .../SimulationSAR/GPURFPC.cu | 25 +- .../SimulationSAR/TBPImageAlgCls.cpp | 6 +- .../SimulationSARTool.vcxproj | 6 +- .../SimulationSARTool.vcxproj.filters | 4 +- .../ImageNetOperator.cpp | 912 ------------------ 11 files changed, 93 insertions(+), 960 deletions(-) delete mode 100644 enc_temp_folder/3775b1ace76665ec73ebcf8cc5579a/ImageNetOperator.cpp diff --git a/BaseCommonLibrary/BaseCommonLibrary.vcxproj b/BaseCommonLibrary/BaseCommonLibrary.vcxproj index d7c78f9..002db1e 100644 --- a/BaseCommonLibrary/BaseCommonLibrary.vcxproj +++ b/BaseCommonLibrary/BaseCommonLibrary.vcxproj @@ -220,11 +220,13 @@ pch.h true true - NotSet + NoExtensions true stdcpp14 stdc11 true + false + MaxSpeed Windows diff --git a/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp b/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp index 9d746f3..6676b66 100644 --- a/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp +++ b/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp @@ -121,20 +121,48 @@ void gdalImageComplex::saveImage(Eigen::MatrixXcd data, int start_row, int start int datarows = data.rows(); int datacols = data.cols(); - double* databuffer = new double[data.size() * 2]; - for (int i = 0; i < data.rows(); i++) { - for (int j = 0; j < data.cols(); j++) { - databuffer[i * data.cols() * 2 + j * 2] = data(i, j).real(); - databuffer[i * data.cols() * 2 + j * 2 + 1] = data(i, j).imag(); + if (this->getDataType() == GDT_CFloat64) + { + + double* databuffer = new double[data.size() * 2]; + for (int i = 0; i < data.rows(); i++) { + for (int j = 0; j < data.cols(); j++) { + databuffer[i * data.cols() * 2 + j * 2] = data(i, j).real(); + databuffer[i * data.cols() * 2 + j * 2 + 1] = data(i, 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, datacols, datarows, + databuffer, datacols, datarows, GDT_CFloat64, 0, 0); + GDALFlushCache(poDstDS); + delete databuffer; + + } + else if (this->getDataType() == GDT_CFloat32) { + + float* databuffer = new float[data.size() * 2]; + for (int i = 0; i < data.rows(); i++) { + for (int j = 0; j < data.cols(); j++) { + databuffer[i * data.cols() * 2 + j * 2] = float(data(i, j).real()); + databuffer[i * data.cols() * 2 + j * 2 + 1] =float( data(i, 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, datacols, datarows, + databuffer, datacols, datarows, GDT_CFloat32, 0, 0); + GDALFlushCache(poDstDS); + delete databuffer; + } + else { + throw std::exception("gdalImageComplex::saveImage: data type error"); } - // 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, GDT_CFloat64, 0, 0); - GDALFlushCache(poDstDS); - delete databuffer; + + GDALClose((GDALDatasetH)poDstDS); GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH omp_unset_lock(&lock); // diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 0c8095d..36a432d 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -787,7 +787,7 @@ int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QStrin int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePath, QString L1AEchoDataPath) { gdalImageComplex echodata(L2echodataPath); gdalImage looktable(RangeLooktablePath); - gdalImageComplex l1adata = CreategdalImageComplexNoProj(L1AEchoDataPath, looktable.height, looktable.width, 1, true); + gdalImageComplex l1adata(L1AEchoDataPath); Eigen::MatrixXcd echoArr = echodata.getDataComplex(0, 0, echodata.height, echodata.width, 1); long blockHeight = Memory1GB / looktable.width / 8 * 2; @@ -802,6 +802,7 @@ int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePa long imgheight = blockHeight; long imgwidth = looktable.width; +#pragma omp parallel for for (long i = 0; i < imgheight; i++) { for (long j = 0; j < imgwidth; j++) { diff --git a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp index c5b8b7b..39648cb 100644 --- a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp @@ -51,7 +51,7 @@ void QSARSimulationComplexEchoDataDialog::onpushButtonLookTableSelect_clicked() { QString fileNames = QFileDialog::getOpenFileName( this, // - tr(u8"ѡL1Aزļ"), // + tr(u8"ѡұزļ"), // QString(), // Ĭ· tr(ENVI_FILE_FORMAT_FILTER) // ļ ); diff --git a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.cpp b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.cpp index 6c7a5ab..3fe90be 100644 --- a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.cpp +++ b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.cpp @@ -130,12 +130,6 @@ void QSimulationBPImageMultiProduction::onbtnaccepted() QString imgNetPath = this->ui->lineEditImageNetPath->text().trimmed(); QString echoDataPath = this->ui->lineEditEchoPath->text().trimmed(); - - - - - - this->hide(); QString echofile = echoDataPath; QString outImageFolder = getParantFromPath(L2DataPath); @@ -164,15 +158,32 @@ void QSimulationBPImageMultiProduction::onbtnaccepted() TBPimag.ProcessWithGridNet(cpucore_num, imgNetPath); qDebug() << u8"ϵͳУ"; + // ӳ + std::shared_ptr< SARSimulationImageL1Dataset> imagL2(new SARSimulationImageL1Dataset); + imagL2->setCenterAngle(echoL0ds->getCenterAngle()); + imagL2->setCenterFreq(echoL0ds->getCenterFreq()); + imagL2->setNearRange(echoL0ds->getNearRange()); + imagL2->setRefRange((echoL0ds->getNearRange() + echoL0ds->getFarRange()) / 2); + imagL2->setFarRange(echoL0ds->getFarRange()); + imagL2->setFs(echoL0ds->getFs()); + imagL2->setLookSide(echoL0ds->getLookSide()); + + + QString outL1AImageFolder = getParantFromPath(L1ADataPath); + QString L1Aimagename = getFileNameFromPath(L1ADataPath); + + gdalImage Looktableimg(looktablePath); + imagL2->OpenOrNew(outL1AImageFolder, L1Aimagename, Looktableimg.height, Looktableimg.width); + + QString L1AEchoDataPath =imagL2->getImageRasterPath(); + + ResampleEChoDataFromGeoEcho(imagL1->getImageRasterPath(), looktablePath, L1AEchoDataPath); - ResampleEChoDataFromGeoEcho(imagL1->getImageRasterPath(), looktablePath, L1ADataPath); this->show(); QMessageBox::information(this,u8"",u8""); - - - + } void QSimulationBPImageMultiProduction::onbtnrejected() diff --git a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.ui b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.ui index fd5d9fd..4712523 100644 --- a/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.ui +++ b/Toolbox/SimulationSARTool/SARImage/QSimulationBPImageMultiProduction.ui @@ -45,7 +45,7 @@ - D:\Programme\vs2022\RasterMergeTest\LAMPCAE_SCANE-all-scane\GF3_Simulation.xml + D:/FZSimulation/LTDQ/Input/xml/xml/165665/echodata/LT1B_DQ_165665_Simulation.xml @@ -93,7 +93,7 @@ - D:\Programme\vs2022\RasterMergeTest\simulationData\demdataset\demxyz.bin + D:/FZSimulation/LTDQ/Input/xml/xml/165665/InSARImageXYZ/LT1A_165665_InSAR_ImageXYZ_looktable.bin @@ -144,7 +144,7 @@ - D:\Programme\vs2022\RasterMergeTest\simulationData\demdataset\demxyz.bin + D:/FZSimulation/LTDQ/Input/DEM1/looktable165665/LT1A_65665_looktable_Range.bin @@ -195,7 +195,7 @@ - D:\Programme\vs2022\RasterMergeTest\simulationData\demdataset\demxyz.bin + D:/FZSimulation/LTDQ/Input/xml/xml/165665/TBPImageProduction/L1/LT1A_165665_L1A @@ -249,7 +249,7 @@ - D:\Programme\vs2022\RasterMergeTest\LAMPCAE_SCANE-all-scane\BPImage\GF3BPImage + D:/FZSimulation/LTDQ/Input/xml/xml/165665/TBPImageProduction/L2/LT1A_165665_L2 diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index 62b3a4d..afd43d1 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -537,23 +537,23 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( // б˥ - float antDirectR = sqrtf(antp.antDirectX * antp.antDirectX - + antp.antDirectY * antp.antDirectY - + antp.antDirectZ * antp.antDirectZ); + //float antDirectR = sqrtf(antp.antDirectX * antp.antDirectX + // + antp.antDirectY * antp.antDirectY + // + antp.antDirectZ * antp.antDirectZ); - float diectAngle = -1 * (RstX * antp.antDirectX + - RstY * antp.antDirectY + - RstZ * antp.antDirectZ) / (antDirectR); + //float diectAngle = -1 * (RstX * antp.antDirectX + + // RstY * antp.antDirectY + + // RstZ * antp.antDirectZ) / (antDirectR); - diectAngle = acosf(diectAngle);// - diectAngle = diectAngle * GainWeight; + //diectAngle = acosf(diectAngle);// + //diectAngle = diectAngle * GainWeight; float ampGain = 1; - ampGain = 2 * maxGain * (1 - (powf(diectAngle, 2) / 6) - + (powf(diectAngle, 4) / 120) - - (powf(diectAngle, 6) / 5040)); //dB + //ampGain = 2 * maxGain * (1 - (powf(diectAngle, 2) / 6) + // + (powf(diectAngle, 4) / 120) + // - (powf(diectAngle, 6) / 5040)); //dB - ampGain = powf(10.0, ampGain / 10.0); + //ampGain = powf(10.0, ampGain / 10.0); ampGain = ampGain / (PI4POW2 * powf(RstR, 4)); // ǿ float sigma = GPU_getSigma0dB(sigma0Params, localangle); @@ -571,7 +571,6 @@ __global__ void Kernel_Computer_R_amp_NoAntPattern( d_temp_R[idx] =static_cast(temp_R); return; } - } } } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp index dc32916..6d50619 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp @@ -81,6 +81,10 @@ ErrorCode TBPImageAlgCls::ProcessWithGridNet(long num_thread,QString xyzRasterPa } + // 处理成像映射 + CopyProjectTransformMatrixFromRasterAToRasterB(this->outRasterXYZPath, this->L1ds->getImageRasterPath()); + + qDebug() << u8"频域回波-> 时域回波 结束"; if (GPURUN) { @@ -91,8 +95,6 @@ ErrorCode TBPImageAlgCls::ProcessWithGridNet(long num_thread,QString xyzRasterPa return ErrorCode::FAIL; } - // 处理成像映射 - CopyProjectTransformMatrixFromRasterAToRasterB(this->outRasterXYZPath, this->L1ds->getImageRasterPath()); return ErrorCode::SUCCESS; diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index b228c81..62fb8ce 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -124,8 +124,10 @@ true stdcpp14 stdc11 - true - false + false + true + NoExtensions + MaxSpeed true diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index e53b120..b8510fa 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -151,10 +151,10 @@ PowerSimulationIncoherent - + SARImage - + SARImage diff --git a/enc_temp_folder/3775b1ace76665ec73ebcf8cc5579a/ImageNetOperator.cpp b/enc_temp_folder/3775b1ace76665ec73ebcf8cc5579a/ImageNetOperator.cpp deleted file mode 100644 index f75c122..0000000 --- a/enc_temp_folder/3775b1ace76665ec73ebcf8cc5579a/ImageNetOperator.cpp +++ /dev/null @@ -1,912 +0,0 @@ -#include "ImageNetOperator.h" -#include "LogInfoCls.h" -#include "PrintMsgToQDebug.h" -#include -#include "ImageOperatorBase.h" -#include "GPUBaseTool.h" -#include "GPUBPImageNet.cuh" -#include "BaseTool.h" -#include "BaseConstVariable.h" - - -void InitCreateImageXYZProcess(QString& outImageLLPath, QString& outImageXYZPath, QString& InEchoGPSDataPath, - double& NearRange, double& RangeResolution, int64_t& RangeNum) -{ - qDebug() << "---------------------------------------------------------------------------------"; - qDebug() << u8"ֳƽбͶӰ"; - gdalImage antimg(InEchoGPSDataPath); - qDebug() << u8"1. زGPSļ\t"; - qDebug() << u8"ļ·\t" << InEchoGPSDataPath; - qDebug() << u8"GPS \t" << antimg.height; - qDebug() << u8"ļ\t" << antimg.width; - qDebug() << u8"2.б"; - qDebug() << u8"룺\t" << NearRange; - qDebug() << u8"ֱʣ\t" << RangeResolution; - qDebug() << u8"\t" << RangeNum; - qDebug() << u8"3.ļ"; - gdalImage outimgll = CreategdalImageDouble(outImageLLPath, antimg.height,RangeNum, 3,true,true); - gdalImage outimgxyz = CreategdalImageDouble(outImageXYZPath, antimg.height, RangeNum, 3, true, true); - qDebug() << u8"ƽļγȣ·\t" << outImageLLPath; - qDebug() << u8"ƽļXYZ·\t" << outImageXYZPath; - qDebug() << u8"4.ʼXYZ"; - long prfcount = antimg.height; - long rangeNum = RangeNum; - double Rnear = NearRange; - double dx = RangeResolution; - - long blockRangeCount = Memory1GB / sizeof(double) / 4 / prfcount *6; - blockRangeCount = blockRangeCount < 1 ? 1 : blockRangeCount; - - std::shared_ptr Pxs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr Pys((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr Pzs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr AntDirectX((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr AntDirectY((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr AntDirectZ((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - - { - long colnum = 19; - std::shared_ptr antpos =readDataArr(antimg,0,0,prfcount, colnum,1,GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - double time = 0; - double Px = 0; - double Py = 0; - double Pz = 0; - for (long i = 0; i < prfcount; i++) { - - Pxs.get()[i] = antpos.get()[i * 19 + 1]; // - Pys.get()[i] = antpos.get()[i * 19 + 2]; - Pzs.get()[i] = antpos.get()[i * 19 + 3]; - AntDirectX.get()[i] = antpos.get()[i * 19 + 13];// zero doppler - AntDirectY.get()[i] = antpos.get()[i * 19 + 14]; - AntDirectZ.get()[i] = antpos.get()[i * 19 + 15]; - - double NormAnt = std::sqrt(AntDirectX.get()[i] * AntDirectX.get()[i] + - AntDirectY.get()[i] * AntDirectY.get()[i] + - AntDirectZ.get()[i] * AntDirectZ.get()[i]); - AntDirectX.get()[i] = AntDirectX.get()[i] / NormAnt; - AntDirectY.get()[i] = AntDirectY.get()[i] / NormAnt; - AntDirectZ.get()[i] = AntDirectZ.get()[i] / NormAnt;// һ - } - antpos.reset(); - } - - std::shared_ptr d_Pxs((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); - std::shared_ptr d_Pys((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); - std::shared_ptr d_Pzs((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); - std::shared_ptr d_AntDirectX((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); - std::shared_ptr d_AntDirectY((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); - std::shared_ptr d_AntDirectZ((double*)mallocCUDADevice(sizeof(double) * prfcount), FreeCUDADevice); - - HostToDevice(Pxs.get(), d_Pxs.get(), sizeof(double) * prfcount); - HostToDevice(Pys.get(), d_Pys.get(), sizeof(double) * prfcount); - HostToDevice(Pzs.get(), d_Pzs.get(), sizeof(double) * prfcount); - HostToDevice(AntDirectX.get(), d_AntDirectX.get(), sizeof(double) * prfcount); - HostToDevice(AntDirectY.get(), d_AntDirectY.get(), sizeof(double) * prfcount); - HostToDevice(AntDirectZ.get(), d_AntDirectZ.get(), sizeof(double) * prfcount); - - - for (long startcolidx = 0; startcolidx < RangeNum; startcolidx = startcolidx + blockRangeCount) { - - long tempechocol = blockRangeCount; - if (startcolidx + tempechocol >= RangeNum) { - tempechocol = RangeNum - startcolidx; - } - qDebug() << " imgxyz :\t" << startcolidx << "\t-\t" << startcolidx + tempechocol << " / " << RangeNum; - - std::shared_ptr demx = readDataArr(outimgxyz, 0, startcolidx, prfcount, tempechocol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - std::shared_ptr demy = readDataArr(outimgxyz, 0, startcolidx, prfcount, tempechocol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - std::shared_ptr demz = readDataArr(outimgxyz, 0, startcolidx, prfcount, tempechocol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - - std::shared_ptr h_demx((double*)mallocCUDAHost(sizeof(double) * prfcount * tempechocol), FreeCUDAHost); - std::shared_ptr h_demy((double*)mallocCUDAHost(sizeof(double) * prfcount * tempechocol), FreeCUDAHost); - std::shared_ptr h_demz((double*)mallocCUDAHost(sizeof(double) * prfcount * tempechocol), FreeCUDAHost); - -#pragma omp parallel for - for (long ii = 0; ii < prfcount; ii++) { - for (long jj = 0; jj < tempechocol; jj++) { - h_demx.get()[ii * tempechocol + jj] = demx.get()[ii * tempechocol + jj]; - h_demy.get()[ii * tempechocol + jj] = demy.get()[ii * tempechocol + jj]; - h_demz.get()[ii * tempechocol + jj] = demz.get()[ii * tempechocol + jj]; - } - } - - std::shared_ptr d_demx((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); - std::shared_ptr d_demy((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); - std::shared_ptr d_demz((double*)mallocCUDADevice(sizeof(double) * prfcount * tempechocol), FreeCUDADevice); - - HostToDevice(h_demx.get(), d_demx.get(), sizeof(double) * prfcount * tempechocol); - HostToDevice(h_demy.get(), d_demy.get(), sizeof(double) * prfcount * tempechocol); - HostToDevice(h_demz.get(), d_demz.get(), sizeof(double) * prfcount * tempechocol); - - - TIMEBPCreateImageGrid( - d_Pxs.get(), d_Pys.get(), d_Pzs.get(), - d_AntDirectX.get(), d_AntDirectY.get(), d_AntDirectZ.get(), - d_demx.get(), d_demy.get(), d_demz.get(), - prfcount, tempechocol, 0, - Rnear + dx * startcolidx, dx // ޶ - ); - - DeviceToHost(h_demx.get(), d_demx.get(), sizeof(double) * prfcount * tempechocol); - DeviceToHost(h_demy.get(), d_demy.get(), sizeof(double) * prfcount * tempechocol); - DeviceToHost(h_demz.get(), d_demz.get(), sizeof(double) * prfcount * tempechocol); - -#pragma omp parallel for - for (long ii = 0; ii < prfcount; ii++) { - for (long jj = 0; jj < tempechocol; jj++) { - demx.get()[ii * tempechocol + jj] = h_demx.get()[ii * tempechocol + jj]; - demy.get()[ii * tempechocol + jj] = h_demy.get()[ii * tempechocol + jj]; - demz.get()[ii * tempechocol + jj] = h_demz.get()[ii * tempechocol + jj]; - } - } - - outimgxyz.saveImage(demx, 0, startcolidx, prfcount, tempechocol, 1); - outimgxyz.saveImage(demy, 0, startcolidx, prfcount, tempechocol, 2); - outimgxyz.saveImage(demz, 0, startcolidx, prfcount, tempechocol, 3); - - // XYZתΪγ - std::shared_ptr demllx = readDataArr(outimgll, 0, startcolidx, prfcount, tempechocol, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - std::shared_ptr demlly = readDataArr(outimgll, 0, startcolidx, prfcount, tempechocol, 2, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - std::shared_ptr demllz = readDataArr(outimgll, 0, startcolidx, prfcount, tempechocol, 3, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - -#pragma omp parallel for - for (long ii = 0; ii < prfcount; ii++) { - for (long jj = 0; jj < tempechocol; jj++) { - double x = demx.get()[ii * tempechocol + jj]; - double y = demy.get()[ii * tempechocol + jj]; - double z = demz.get()[ii * tempechocol + jj]; - Landpoint point; - XYZ2BLH_FixedHeight(x, y, z, 0, point); - demllx.get()[ii * tempechocol + jj] = point.lon; - demlly.get()[ii * tempechocol + jj] = point.lat; - demllz.get()[ii * tempechocol + jj] = point.ati; - } - } - - - outimgll.saveImage(demllx, 0, startcolidx, prfcount, tempechocol, 1); - outimgll.saveImage(demlly, 0, startcolidx, prfcount, tempechocol, 2); - outimgll.saveImage(demllz, 0, startcolidx, prfcount, tempechocol, 3); - - } - - qDebug() << u8"6."; - qDebug() << "---------------------------------------------------------------------------------"; -} - -bool OverlapCheck(QString& ImageLLPath, QString& ImageDEMPath) -{ - // DEMǷWGS84ϵ - //long demEPSG = GetEPSGFromRasterFile(ImageDEMPath); - //if (demEPSG != 4326) { - // qDebug() << u8"DEMϵWGS84ϵ,ESPG:"<< demEPSG; - // return false; - //} - - gdalImage demimg(ImageDEMPath); - gdalImage imgll(ImageLLPath); - - long imgheight = imgll.height; - long imgwidth = imgll.width; - Eigen::MatrixXd imglonArr = imgll.getData(0, 0, imgheight, imgwidth, 1); - Eigen::MatrixXd imglatArr = imgll.getData(0, 0, imgheight, imgwidth, 2); - - // ӡΧ - qDebug() << u8"ӰΧ"; - qDebug() << u8"Сȣ\t" << imglonArr.minCoeff(); - qDebug() << u8"󾭶ȣ\t" << imglonArr.maxCoeff(); - qDebug() << u8"Сγȣ\t" << imglatArr.minCoeff(); - qDebug() << u8"γȣ\t" << imglatArr.maxCoeff(); - qDebug() << u8"DEMΧ"; - RasterExtend demextend = demimg.getExtend(); - qDebug() << u8"Сȣ\t" << demextend.min_x; - qDebug() << u8"󾭶ȣ\t" << demextend.max_x; - qDebug() << u8"Сγȣ\t" << demextend.min_y; - qDebug() << u8"γȣ\t" << demextend.max_y; - qDebug() << u8"ӰС\t" << demimg.height << " * " << demimg.width; - - - - for (long i = 0; i < imgheight; i++) - { - for (long j = 0; j < imgwidth; j++) - { - double lon = imglonArr(i, j); // X - double lat = imglatArr(i, j); // Y - Landpoint point = demimg.getRow_Col(lon, lat); - imglonArr(i, j) = point.lon; - imglatArr(i, j) = point.lat; - } - } - - double minX = imglonArr.minCoeff(); - double maxX = imglonArr.maxCoeff(); - double minY = imglatArr.minCoeff(); - double maxY = imglatArr.maxCoeff(); - - //ӡΧ - qDebug() << u8"dem ķΧ"; - qDebug() << u8"minX:"<demimg.width - 1 || minY<1 || maxY>demimg.height - 1) { - return false; - } - else { - return true; - } - - - -} - -bool GPSPointsNumberEqualCheck(QString& ImageLLPath, QString& InEchoGPSDataPath) -{ - - gdalImage antimg(InEchoGPSDataPath); - gdalImage imgll(ImageLLPath); - return antimg.height == imgll.height; - -} - - - -void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath) -{ - gdalImage demimg(ImageDEMPath); - gdalImage imgll(ImageLLPath); - gdalImage outimgll = CreategdalImageDouble(outImageLLAPath, imgll.height, imgll.width, 4, true, true); // ȡγȡ̡߳б - - long imgheight = imgll.height; - long imgwidth = imgll.width; - - Eigen::MatrixXd imglonArr = imgll.getData(0, 0, imgheight, imgwidth, 1); - Eigen::MatrixXd imglatArr = imgll.getData(0, 0, imgheight, imgwidth, 2); - Eigen::MatrixXd demArr = demimg.getData(0, 0, demimg.height, demimg.width, 1); - Eigen::MatrixXd imgatiArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); - Eigen::MatrixXd imgRArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); - - outimgll.saveImage(imglonArr, 0, 0, 1); - outimgll.saveImage(imglatArr, 0, 0, 2); - - - double minX = imglonArr.minCoeff(); - double maxX = imglonArr.maxCoeff(); - double minY = imglatArr.minCoeff(); - double maxY = imglatArr.maxCoeff(); - //ӡΧ - qDebug() << u8"dem ķΧ"; - qDebug() << u8"minX:" << minX << "\t" << demimg.width; - qDebug() << u8"maxX:" << maxX << "\t" << demimg.width; - qDebug() << u8"minY:" << minY << "\t" << demimg.height; - qDebug() << u8"maxY:" << maxY << "\t" << demimg.height; - qDebug() << u8"ͼУ\t" << demimg.height << " , " << demimg.width; - - - for (long i = 0; i < imgheight; i++) { - //printf("\rprocess:%f precent\t\t\t",i*100.0/imgheight); - for (long j = 0; j < imgwidth; j++) { - double lon = imglonArr(i, j); - double lat = imglatArr(i, j); - Landpoint point = demimg.getRow_Col(lon, lat); - - if (point.lon<1 || point.lon>demimg.width - 2 || point.lat < 1 || point.lat - 2) { - continue; - } - else {} - - Landpoint p0, p11, p21, p12, p22; - - p0.lon = point.lon; - p0.lat = point.lat; - - p11.lon = floor(p0.lon); - p11.lat = floor(p0.lat); - p11.ati = demArr(long(p11.lat), long(p11.lon)); - - p12.lon = ceil(p0.lon); - p12.lat = floor(p0.lat); - p12.ati = demArr(long(p12.lat), long(p12.lon)); - - p21.lon = floor(p0.lon); - p21.lat = ceil(p0.lat); - p21.ati = demArr(long(p21.lat), long(p21.lon)); - - p22.lon = ceil(p0.lon); - p22.lat = ceil(p0.lat); - p22.ati = demArr(long(p22.lat), long(p22.lon)); - - p0.lon = p0.lon - p11.lon; - p0.lat = p0.lat - p11.lat; - - p12.lon = p12.lon - p11.lon; - p12.lat = p12.lat - p11.lat; - - p21.lon = p21.lon - p11.lon; - p21.lat = p21.lat - p11.lat; - - p22.lon = p22.lon - p11.lon; - p22.lat = p22.lat - p11.lat; - - p11.lon = p11.lon - p11.lon; - p11.lat = p11.lat - p11.lat; - - p0.ati=Bilinear_interpolation(p0, p11, p21, p12, p22); - imgatiArr(i, j) = p0.ati; - - } - } - outimgll.saveImage(imgatiArr, 0, 0, 3); - qDebug() << u8"ÿбֵ"; - - - gdalImage antimg(InEchoGPSDataPath); - qDebug() << u8"1. زGPSļ\t"; - qDebug() << u8"ļ·\t" << InEchoGPSDataPath; - qDebug() << u8"GPS \t" << antimg.height; - qDebug() << u8"ļ\t" << antimg.width; - - long prfcount = antimg.height; - - - std::shared_ptr Pxs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr Pys((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr Pzs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr AntDirectX((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr AntDirectY((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr AntDirectZ((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - - { - long colnum = 19; - std::shared_ptr antpos = readDataArr(antimg, 0, 0, prfcount, colnum, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - double time = 0; - double Px = 0; - double Py = 0; - double Pz = 0; - for (long i = 0; i < prfcount; i++) { - - Pxs.get()[i] = antpos.get()[i * 19 + 1]; // - Pys.get()[i] = antpos.get()[i * 19 + 2]; - Pzs.get()[i] = antpos.get()[i * 19 + 3]; - AntDirectX.get()[i] = antpos.get()[i * 19 + 13];// zero doppler - AntDirectY.get()[i] = antpos.get()[i * 19 + 14]; - AntDirectZ.get()[i] = antpos.get()[i * 19 + 15]; - - double NormAnt = std::sqrt(AntDirectX.get()[i] * AntDirectX.get()[i] + - AntDirectY.get()[i] * AntDirectY.get()[i] + - AntDirectZ.get()[i] * AntDirectZ.get()[i]); - AntDirectX.get()[i] = AntDirectX.get()[i] / NormAnt; - AntDirectY.get()[i] = AntDirectY.get()[i] / NormAnt; - AntDirectZ.get()[i] = AntDirectZ.get()[i] / NormAnt;// һ - } - antpos.reset(); - } - - - -#pragma omp parallel for - for (long prfid = 0; prfid < prfcount; prfid++) { - double Px = Pxs.get()[prfid]; - double Py = Pys.get()[prfid]; - double Pz = Pzs.get()[prfid]; - double R = 0; - Landpoint LLA = {}; - Point3 XYZ = {}; - for (long j = 0; j < imgwidth; j++) { - LLA.lon = imglonArr(prfid, j); - LLA.lat = imglatArr(prfid, j); - LLA.ati = imgatiArr(prfid, j); - - LLA2XYZ(LLA, XYZ); - - R = sqrt(pow(Px - XYZ.x, 2) + - pow(Py - XYZ.y, 2) + - pow(Pz - XYZ.z, 2)); - imgRArr(prfid, j) = R; - } - } - - outimgll.saveImage(imgRArr, 0, 0, 4); - - qDebug() << u8"ֵ"; -} - - -void InterploateClipAtiByRefDEM(QString ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath) { - - gdalImage demimg(ImageDEMPath); - gdalImage imgll(ImageLLPath); - - // ü - long imgheight = imgll.height; - long imgwidth = imgll.width; - - long minRow = -1; - long maxRow = imgheight; - long minCol = -1; - long maxCol = imgwidth; - - - Eigen::MatrixXd imglonArr = imgll.getData(0, 0, imgheight, imgwidth, 1); - Eigen::MatrixXd imglatArr = imgll.getData(0, 0, imgheight, imgwidth, 2); - -#pragma omp parallel for - for (long i = 0; i < imgheight; i++) { - for (long j = 0; j < imgwidth; j++) { - double lon = imglonArr(i, j); - double lat = imglatArr(i, j); - Landpoint point = demimg.getRow_Col(lon, lat); - imglonArr(i, j) = point.lon; - imglatArr(i, j) = point.lat; - } - } - - // ʼɨ - - bool minRowFlag=true, maxRowFlag= true, minColFlag = true, maxColFlag = true; - - for (long i = 0; i < imgheight; i++) { - for (long j = 0; j < imgwidth; j++) { - if (imglonArr(i, j) > 0 && minRowFlag) { - minRowFlag = false; - minRow = i; - break; - } - if (imglonArr(i, j) < imgheight) { - maxRow = i; - } - } - } - - for (long j = 0; j < imgwidth; j++) { - for (long i = 0; i < imgheight; i++) { - if (imglatArr(i, j) > 0 && minColFlag) { - minColFlag = false; - minCol = j; - break; - } - if (imglatArr(i, j) < imgheight) { - maxCol = j; - } - } - } - - - long RowCount = maxRow - minRow; - long ColCount = maxCol - minCol; - - gdalImage outimgll = CreategdalImageDouble(outImageLLAPath, RowCount, ColCount, 4, true, true); // ȡγȡ̡߳б - - imgheight = outimgll.height; - imgwidth = outimgll.width; - - imglonArr = imgll.getData(minRow, minCol, RowCount, ColCount, 1); - imglatArr = imgll.getData(minRow, minCol, RowCount, ColCount, 2); - - Eigen::MatrixXd demArr = demimg.getData(0, 0, demimg.height, demimg.width, 1); - - Eigen::MatrixXd imgatiArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); - Eigen::MatrixXd imgRArr = Eigen::MatrixXd::Zero(imgheight, imgwidth); - - outimgll.saveImage(imglonArr, 0, 0, 1); - outimgll.saveImage(imglatArr, 0, 0, 2); - - - double minX = imglonArr.minCoeff(); - double maxX = imglonArr.maxCoeff(); - double minY = imglatArr.minCoeff(); - double maxY = imglatArr.maxCoeff(); - - //ӡΧ - qDebug() << u8"dem ķΧ"; - qDebug() << u8"minX:" << minX << "\t" << demimg.width; - qDebug() << u8"maxX:" << maxX << "\t" << demimg.width; - qDebug() << u8"minY:" << minY << "\t" << demimg.height; - qDebug() << u8"maxY:" << maxY << "\t" << demimg.height; - qDebug() << u8"ͼУ\t" << demimg.height << " , " << demimg.width; - - - for (long i = 0; i < imgheight; i++) { - //printf("\rprocess:%f precent\t\t\t",i*100.0/imgheight); - for (long j = 0; j < imgwidth; j++) { - double lon = imglonArr(i, j); - double lat = imglatArr(i, j); - Landpoint point = demimg.getRow_Col(lon, lat); - - if (point.lon<1 || point.lon>demimg.width - 2 || point.lat < 1 || point.lat - 2) { - continue; - } - else {} - - Landpoint p0, p11, p21, p12, p22; - - p0.lon = point.lon; - p0.lat = point.lat; - - p11.lon = floor(p0.lon); - p11.lat = floor(p0.lat); - p11.ati = demArr(long(p11.lat), long(p11.lon)); - - p12.lon = ceil(p0.lon); - p12.lat = floor(p0.lat); - p12.ati = demArr(long(p12.lat), long(p12.lon)); - - p21.lon = floor(p0.lon); - p21.lat = ceil(p0.lat); - p21.ati = demArr(long(p21.lat), long(p21.lon)); - - p22.lon = ceil(p0.lon); - p22.lat = ceil(p0.lat); - p22.ati = demArr(long(p22.lat), long(p22.lon)); - - p0.lon = p0.lon - p11.lon; - p0.lat = p0.lat - p11.lat; - - p12.lon = p12.lon - p11.lon; - p12.lat = p12.lat - p11.lat; - - p21.lon = p21.lon - p11.lon; - p21.lat = p21.lat - p11.lat; - - p22.lon = p22.lon - p11.lon; - p22.lat = p22.lat - p11.lat; - - p11.lon = p11.lon - p11.lon; - p11.lat = p11.lat - p11.lat; - - p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); - imgatiArr(i, j) = p0.ati; - } - } - - outimgll.saveImage(imgatiArr, 0, 0, 3); - qDebug() << u8"ÿбֵ"; - - - gdalImage antimg(InEchoGPSDataPath); - qDebug() << u8"1. زGPSļ\t"; - qDebug() << u8"ļ·\t" << InEchoGPSDataPath; - qDebug() << u8"GPS \t" << antimg.height; - qDebug() << u8"ļ\t" << antimg.width; - - long prfcount = antimg.height; - - - std::shared_ptr Pxs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr Pys((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr Pzs((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr AntDirectX((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr AntDirectY((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - std::shared_ptr AntDirectZ((double*)mallocCUDAHost(sizeof(double) * prfcount), FreeCUDAHost); - - { - long colnum = 19; - std::shared_ptr antpos = readDataArr(antimg, 0, 0, prfcount, colnum, 1, GDALREADARRCOPYMETHOD::VARIABLEMETHOD); - double time = 0; - double Px = 0; - double Py = 0; - double Pz = 0; - for (long i = 0; i < prfcount; i++) { - - Pxs.get()[i] = antpos.get()[i * 19 + 1]; // - Pys.get()[i] = antpos.get()[i * 19 + 2]; - Pzs.get()[i] = antpos.get()[i * 19 + 3]; - AntDirectX.get()[i] = antpos.get()[i * 19 + 13];// zero doppler - AntDirectY.get()[i] = antpos.get()[i * 19 + 14]; - AntDirectZ.get()[i] = antpos.get()[i * 19 + 15]; - - double NormAnt = std::sqrt(AntDirectX.get()[i] * AntDirectX.get()[i] + - AntDirectY.get()[i] * AntDirectY.get()[i] + - AntDirectZ.get()[i] * AntDirectZ.get()[i]); - AntDirectX.get()[i] = AntDirectX.get()[i] / NormAnt; - AntDirectY.get()[i] = AntDirectY.get()[i] / NormAnt; - AntDirectZ.get()[i] = AntDirectZ.get()[i] / NormAnt;// һ - } - antpos.reset(); - } - - - -#pragma omp parallel for - for (long prfid = minRow; prfid < maxRow; prfid++) { - double Px = Pxs.get()[prfid]; - double Py = Pys.get()[prfid]; - double Pz = Pzs.get()[prfid]; - double R = 0; - Landpoint LLA = {}; - Point3 XYZ = {}; - for (long j = 0; j < imgwidth; j++) { - LLA.lon = imglonArr(prfid-minRow, j); - LLA.lat = imglatArr(prfid - minRow, j); - LLA.ati = imgatiArr(prfid - minRow, j); - - LLA2XYZ(LLA, XYZ); - - R = sqrt(pow(Px - XYZ.x, 2) + - pow(Py - XYZ.y, 2) + - pow(Pz - XYZ.z, 2)); - imgRArr(prfid - minRow, j) = R; - } - } - - outimgll.saveImage(imgRArr, 0, 0, 4); - - qDebug() << u8"ֵ"; - -} - - - - -int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QString ori_sim_count_tiffPath,long OriHeight,long OriWidth) -{ - gdalImage sim_rc(dem_rc_path); - gdalImage sim_sar_img = CreategdalImage(outOriSimTiffPath, OriHeight, OriWidth, 2, sim_rc.gt, sim_rc.projection, false);// עﱣ - for (int max_rows_ids = 0; max_rows_ids < OriHeight; max_rows_ids = max_rows_ids + 1000) { - Eigen::MatrixXd sim_sar = sim_sar_img.getData(max_rows_ids, 0, 1000, OriWidth, 1); - Eigen::MatrixXd sim_sarc = sim_sar_img.getData(max_rows_ids, 0, 1000, OriWidth, 2); - sim_sar = sim_sar.array() * 0 - 9999; - sim_sarc = sim_sar.array() * 0 - 9999; - sim_sar_img.saveImage(sim_sar, max_rows_ids, 0, 1); - sim_sar_img.saveImage(sim_sarc, max_rows_ids, 0, 2); - } - sim_sar_img.setNoDataValue(-9999, 1); - sim_sar_img.setNoDataValue(-9999, 2); - int conver_lines = 5000; - int line_invert = 4000;// ص - int line_offset = 60; - // - omp_lock_t lock; - omp_init_lock(&lock); // ʼ - int allCount = 0; - - for (int max_rows_ids = 0; max_rows_ids < sim_rc.height; max_rows_ids = max_rows_ids + line_invert) { - Eigen::MatrixXd dem_r = sim_rc.getData(max_rows_ids, 0, conver_lines, sim_rc.width, 1); - Eigen::MatrixXd dem_c = sim_rc.getData(max_rows_ids, 0, conver_lines, sim_rc.width, 2); - int dem_rows_num = dem_r.rows(); - int dem_cols_num = dem_r.cols(); - // ²ֵγ - //Eigen::MatrixXd dem_lon = dem_r; - //Eigen::MatrixXd dem_lat = dem_c; - // ¾γȲ - - int temp_r, temp_c; - - int min_row = dem_r.minCoeff() + 1; - int max_row = dem_r.maxCoeff() + 1; - - if (max_row < 0) { - continue; - } - - int len_rows = max_row - min_row; - min_row = min_row < 0 ? 0 : min_row; - Eigen::MatrixXd sar_r = sim_sar_img.getData(min_row, 0, len_rows, OriWidth, 1); - Eigen::MatrixXd sar_c = sim_sar_img.getData(min_row, 0, len_rows, OriWidth, 2); - len_rows = sar_r.rows(); - - -#pragma omp parallel for num_threads(8) // NEW ADD - for (int i = 0; i < dem_rows_num - 1; i++) { - for (int j = 0; j < dem_cols_num - 1; j++) { - Point3 p, p1, p2, p3, p4; - Landpoint lp1, lp2, lp3, lp4; - lp1 = sim_rc.getLandPoint(i + max_rows_ids, j, 0); - lp2 = sim_rc.getLandPoint(i + max_rows_ids, j + 1, 0); - lp3 = sim_rc.getLandPoint(i + 1 + max_rows_ids, j + 1, 0); - lp4 = sim_rc.getLandPoint(i + 1 + max_rows_ids, j, 0); - - p1 = { dem_r(i,j),dem_c(i,j) }; - p2 = { dem_r(i,j + 1),dem_c(i,j + 1) }; - p3 = { dem_r(i + 1,j + 1),dem_c(i + 1,j + 1) }; - p4 = { dem_r(i + 1,j),dem_c(i + 1,j) }; - - //if (angle(i, j) >= 90 && angle(i, j + 1) >= 90 && angle(i + 1, j) >= 90 && angle(i + 1, j + 1) >= 90) { - // continue; - //} - - double temp_min_r = dem_r.block(i, j, 2, 2).minCoeff(); - double temp_max_r = dem_r.block(i, j, 2, 2).maxCoeff(); - double temp_min_c = dem_c.block(i, j, 2, 2).minCoeff(); - double temp_max_c = dem_c.block(i, j, 2, 2).maxCoeff(); - if ((int(temp_min_r) != int(temp_max_r)) && (int(temp_min_c) != int(temp_max_c))) { - for (int ii = int(temp_min_r); ii <= temp_max_r + 1; ii++) { - for (int jj = int(temp_min_c); jj < temp_max_c + 1; jj++) { - if (ii < min_row || ii - min_row >= len_rows || jj < 0 || jj >= OriWidth) { - continue; - } - p = { double(ii),double(jj),0 }; - //if (PtInRect(p, p1, p2, p3, p4)) { - p1.z = lp1.lon; - p2.z = lp2.lon; - p3.z = lp3.lon; - p4.z = lp4.lon; - - p = invBilinear(p, p1, p2, p3, p4); - if (isnan(p.z)) { - continue; - } - - if (p.x < 0) { - continue; - } - double mean = (p1.z + p2.z + p3.z + p4.z) / 4; - if (p.z > p1.z && p.z > p2.z && p.z > p3.z && p.z > p4.z) { - p.z = mean; - } - if (p.z < p1.z && p.z < p2.z && p.z < p3.z && p.z < p4.z) { - p.z = mean; - } - sar_r(ii - min_row, jj) = p.z; - p1.z = lp1.lat; - p2.z = lp2.lat; - p3.z = lp3.lat; - p4.z = lp4.lat; - p = invBilinear(p, p1, p2, p3, p4); - if (isnan(p.z)) { - continue; - } - - if (p.x < 0) { - continue; - } - mean = (p1.z + p2.z + p3.z + p4.z) / 4; - if (p.z > p1.z && p.z > p2.z && p.z > p3.z && p.z > p4.z) { - p.z = mean; - } - if (p.z < p1.z && p.z < p2.z && p.z < p3.z && p.z < p4.z) { - p.z = mean; - } - sar_c(ii - min_row, jj) = p.z; - //} - } - } - - } - } - } - - omp_set_lock(&lock); //û - sim_sar_img.saveImage(sar_r, min_row, 0, 1); - sim_sar_img.saveImage(sar_c, min_row, 0, 2); - allCount = allCount + conver_lines; - qDebug() << "rows:\t" << allCount << "/" << sim_rc.height << "\t computing.....\t" ; - omp_unset_lock(&lock); //ͷŻ - - - } - - return 0; -} - - - -int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePath, QString L1AEchoDataPath) { - gdalImageComplex echodata(L2echodataPath); - gdalImage looktable(RangeLooktablePath); - gdalImageComplex l1adata = CreategdalImageComplexNoProj(L1AEchoDataPath, looktable.height, looktable.width, 1, true); - - Eigen::MatrixXd imglonArr = looktable.getData(0, 0, looktable.height, looktable.width, 1); - Eigen::MatrixXd imglatArr = looktable.getData(0, 0, looktable.height, looktable.width, 2); - - Eigen::MatrixXcd echoArr = echodata.getDataComplex(0, 0, echodata.height, echodata.width, 1); - Eigen::MatrixXcd l1aArr= l1adata.getDataComplex(0, 0, l1adata.height, l1adata.width, 1); - l1aArr = l1aArr.array() * 0; - - long imgheight = looktable.height; - long imgwidth = looktable.width; - - - for (long i = 0; i < imgheight; i++) { - printf("\rGEC: process:%f precent\t\t\t",i*100.0/imgheight); - for (long j = 0; j < imgwidth; j++) { - double lon = imglonArr(i, j); - double lat = imglatArr(i, j); - Landpoint point = echodata.getRow_Col(lon, lat); - - if (point.lon<1 || point.lon>echodata.width - 2 || point.lat < 1 || point.lat >echodata.height - 2) { - continue; - } - else {} - // ʵֵ - { - Landpoint p0, p11, p21, p12, p22; - - p0.lon = point.lon; - p0.lat = point.lat; - - p11.lon = floor(p0.lon); - p11.lat = floor(p0.lat); - p11.ati = echoArr(long(p11.lat), long(p11.lon)).real(); - - p12.lon = ceil(p0.lon); - p12.lat = floor(p0.lat); - p12.ati = echoArr(long(p12.lat), long(p12.lon)).real(); - - p21.lon = floor(p0.lon); - p21.lat = ceil(p0.lat); - p21.ati = echoArr(long(p21.lat), long(p21.lon)).real(); - - p22.lon = ceil(p0.lon); - p22.lat = ceil(p0.lat); - p22.ati = echoArr(long(p22.lat), long(p22.lon)).real(); - - p0.lon = p0.lon - p11.lon; - p0.lat = p0.lat - p11.lat; - - p12.lon = p12.lon - p11.lon; - p12.lat = p12.lat - p11.lat; - - p21.lon = p21.lon - p11.lon; - p21.lat = p21.lat - p11.lat; - - p22.lon = p22.lon - p11.lon; - p22.lat = p22.lat - p11.lat; - - p11.lon = p11.lon - p11.lon; - p11.lat = p11.lat - p11.lat; - - p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); - l1aArr(i, j).real(p0.ati); - } - //鲿ֵ - { - Landpoint p0, p11, p21, p12, p22; - - p0.lon = point.lon; - p0.lat = point.lat; - - p11.lon = floor(p0.lon); - p11.lat = floor(p0.lat); - p11.ati = echoArr(long(p11.lat), long(p11.lon)).imag(); - - p12.lon = ceil(p0.lon); - p12.lat = floor(p0.lat); - p12.ati = echoArr(long(p12.lat), long(p12.lon)).imag(); - - p21.lon = floor(p0.lon); - p21.lat = ceil(p0.lat); - p21.ati = echoArr(long(p21.lat), long(p21.lon)).imag(); - - p22.lon = ceil(p0.lon); - p22.lat = ceil(p0.lat); - p22.ati = echoArr(long(p22.lat), long(p22.lon)).imag(); - - p0.lon = p0.lon - p11.lon; - p0.lat = p0.lat - p11.lat; - - p12.lon = p12.lon - p11.lon; - p12.lat = p12.lat - p11.lat; - - p21.lon = p21.lon - p11.lon; - p21.lat = p21.lat - p11.lat; - - p22.lon = p22.lon - p11.lon; - p22.lat = p22.lat - p11.lat; - - p11.lon = p11.lon - p11.lon; - p11.lat = p11.lat - p11.lat; - - p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); - l1aArr(i, j).imag(p0.ati); - } - - } - } - - l1adata.saveImage(l1aArr, 0, 0, 1); - return 0; - -} - - - - - - - - - From cd293e4a8e19150c8d4965a086621a2e7bef8cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Thu, 10 Apr 2025 01:15:55 +0800 Subject: [PATCH 80/94] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=86=E5=90=8E?= =?UTF-8?q?=E5=90=91=E6=95=A3=E5=B0=84=E7=B3=BB=E6=95=B0=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp index 366f977..8f612f7 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/SigmaDatabase.cpp @@ -44,7 +44,7 @@ SigmaDatabase::SigmaDatabase() this->HH_sigmaParam.insert(std::pair(10, SigmaParam{ -21.1019701821713, 9.00621457243906, 6.52932182540331, -1.11157376729893, -15.8022895411007, 11.4690828129602 })); this->HH_sigmaParam.insert(std::pair(20, SigmaParam{ -43.6677042155964, 32.0245140457417, 0.511060658303930, -2.68482232690106, 6.29783274559538, 1.96648609622833 })); this->HH_sigmaParam.insert(std::pair(40, SigmaParam{ 50.97, -62.9, -0.0968, 1.604, -4.637, 6.108 })); - this->HH_sigmaParam.insert(std::pair(60, SigmaParam{ -12.45,23.3097,3.187,-2.482,8.244,0.3632 })); + this->HH_sigmaParam.insert(std::pair(60, SigmaParam{ -32.45, 23.3097, 3.187, -2.482, 8.244, 0.3632 })); ////12 this->HH_sigmaParam.insert(std::pair(12, SigmaParam{ -21.1019701821713, 9.00621457243906, 6.52932182540331, - 1.11157376729893, - 15.8022895411007, 11.4690828129602 })); @@ -65,7 +65,7 @@ SigmaDatabase::SigmaDatabase() //this->VV_sigmaParam.insert(std::pair(30, SigmaParam{ -59.1080014669385, 47.6710707363975, 0.300193452564135, -3.93463636916976, 5.99799798331127, -10.3772604045974 })); ////50 - this->HH_sigmaParam.insert(std::pair(50, SigmaParam{ -22.9105602882378, 8170.54100628307, 15.4916054293135, - 0.970580847008280, 28.9025325818511, - 21.4319176514170 })); + this->HH_sigmaParam.insert(std::pair(50, SigmaParam{ -22.9105602882378, 30.54100628307, 15.4916054293135, - 0.970580847008280, 28.9025325818511, - 21.4319176514170 })); //this->HV_sigmaParam.insert(std::pair(50, SigmaParam{ -39.7459019584805, 151.391039247574, 5.17117231380975, - 4.10303899418773, 8.04893424718507, - 3.17171678851531 })); //this->VH_sigmaParam.insert(std::pair(50, SigmaParam{ -39.7459019584805, 151.391039247574, 5.17117231380975, -4.10303899418773, 8.04893424718507, -3.17171678851531 })); //this->VV_sigmaParam.insert(std::pair(50, SigmaParam{ -22.9105602882378, 8170.54100628307, 15.4916054293135, -0.970580847008280, 28.9025325818511, -21.4319176514170 })); From a074003d6f4a74c886c7251ca3d5d7eaae4e1934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Thu, 10 Apr 2025 18:32:25 +0800 Subject: [PATCH 81/94] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E4=BA=86L1B=E7=BA=A7?= =?UTF-8?q?=E4=BA=A7=E5=93=81=E7=94=9F=E4=BA=A7=E5=8A=9F=E8=83=BD=202.?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9F=BA=E4=BA=8E=E7=BB=8F=E7=BA=AC=E5=BA=A6?= =?UTF-8?q?=E9=87=87=E6=A0=B7=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/ImageOperatorBase.h | 15 + BaseCommonLibrary/BaseTool/RasterToolBase.cpp | 7 +- BaseCommonLibrary/BaseTool/RasterToolBase.h | 42 +- .../BaseTool/SARSimulationImageL1.h | 6 + BaseCommonLibrary/ImageOperatorFuntion.cpp | 616 +++++++++++++----- Toolbox/BaseToolbox/BaseToolbox.vcxproj | 4 +- .../GF3CalibrationAndGeocodingClass.cpp | 88 --- .../GF3CalibrationAndGeocodingClass.h | 10 - .../BaseToolbox/QComplex2AmpPhase.cpp | 1 + .../SARImage/ImageNetOperator.cpp | 123 +++- .../SARImage/ImageNetOperator.h | 6 + .../SARImage/QL1ASARProcessDialog.cpp | 114 ++++ .../SARImage/QL1ASARProcessDialog.h | 30 + .../SARImage/QL1ASARProcessDialog.ui | 232 +++++++ .../SARImage/QLonLatInterpAtiFromDEM.cpp | 124 ++++ .../SARImage/QLonLatInterpAtiFromDEM.h | 29 + .../SARImage/QLonLatInterpAtiFromDEM.ui | 191 ++++++ .../SimulationSARTool/SimulationSARTool.cpp | 37 ++ Toolbox/SimulationSARTool/SimulationSARTool.h | 28 + .../SimulationSARTool.vcxproj | 6 + .../SimulationSARTool.vcxproj.filters | 18 + 21 files changed, 1433 insertions(+), 294 deletions(-) create mode 100644 Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.cpp create mode 100644 Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.h create mode 100644 Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.ui create mode 100644 Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.cpp create mode 100644 Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.h create mode 100644 Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.ui diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h index d47ad7c..2f52328 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h @@ -316,6 +316,21 @@ void BASECONSTVARIABLEAPI testOutDataArr(QString filename, long* data, long row void BASECONSTVARIABLEAPI CreateSARIntensityByLookTable(QString IntensityRasterPath, QString LookTableRasterPath, QString SARIntensityPath, long min_rid, long max_rid, long min_cid, long max_cid, std::function processBarShow = {}); +bool BASECONSTVARIABLEAPI ConvertVrtToEnvi(QString vrtPath, QString outPath); + + + + +void BASECONSTVARIABLEAPI MultiLookRaster(QString inRasterPath, QString outRasterPath, long looklineNumrow, long looklineNumCol); +ErrorCode BASECONSTVARIABLEAPI Complex2PhaseRaster(QString inComplexPath, QString outRasterPath); +ErrorCode BASECONSTVARIABLEAPI Complex2dBRaster(QString inComplexPath, QString outRasterPath); +ErrorCode BASECONSTVARIABLEAPI Complex2AmpRaster(QString inComplexPath, QString outRasterPath); +ErrorCode BASECONSTVARIABLEAPI ResampleDEM(QString indemPath, QString outdemPath, double gridx, double gridy); + + + + + //--------------------- 图像文件读写 ------------------------------ diff --git a/BaseCommonLibrary/BaseTool/RasterToolBase.cpp b/BaseCommonLibrary/BaseTool/RasterToolBase.cpp index 32711fb..5debe6f 100644 --- a/BaseCommonLibrary/BaseTool/RasterToolBase.cpp +++ b/BaseCommonLibrary/BaseTool/RasterToolBase.cpp @@ -15,6 +15,8 @@ #include #include #include +#include "SARSimulationImageL1.h" +#include namespace RasterToolBase { long getProjectEPSGCodeByLon_Lat(double lon, double lat, ProjectStripDelta stripState) @@ -268,4 +270,7 @@ namespace RasterToolBase { return CoordinateSystemType::UNKNOW; } } -} // namespace RasterToolBase \ No newline at end of file +}; // namespace RasterToolBase + + + diff --git a/BaseCommonLibrary/BaseTool/RasterToolBase.h b/BaseCommonLibrary/BaseTool/RasterToolBase.h index bc6842f..254d4bb 100644 --- a/BaseCommonLibrary/BaseTool/RasterToolBase.h +++ b/BaseCommonLibrary/BaseTool/RasterToolBase.h @@ -12,40 +12,42 @@ #include "BaseConstVariable.h" #include "gdal_priv.h" #include +#include "LogInfoCls.h" + namespace RasterToolBase { - static bool GDALAllRegisterEnable=false; + static bool GDALAllRegisterEnable = false; - enum ProjectStripDelta{ + enum ProjectStripDelta { Strip_6, // 6度带 Strip_3 }; - enum CoordinateSystemType{ // 坐标系类型 + enum CoordinateSystemType { // 坐标系类型 GeoCoordinateSystem, ProjectCoordinateSystem, UNKNOW }; - struct PointRaster{ // 影像坐标点 + struct PointRaster { // 影像坐标点 double x; double y; double z; }; - struct PointXYZ{ - double x,y,z; + struct PointXYZ { + double x, y, z; }; - struct PointGeo{ - double lon,lat,ati; + struct PointGeo { + double lon, lat, ati; }; - struct PointImage{ - double pixel_x,pixel_y; + struct PointImage { + double pixel_x, pixel_y; }; /// 根据经纬度获取 @@ -56,14 +58,14 @@ namespace RasterToolBase { /// \param lat 纬度 /// \return 对应投影坐标系统的 EPSG编码,-1 表示计算错误 long BASECONSTVARIABLEAPI getProjectEPSGCodeByLon_Lat(double long, double lat, - ProjectStripDelta stripState = ProjectStripDelta::Strip_3); + ProjectStripDelta stripState = ProjectStripDelta::Strip_3); long BASECONSTVARIABLEAPI getProjectEPSGCodeByLon_Lat_inStrip3(double lon, double lat); long BASECONSTVARIABLEAPI getProjectEPSGCodeByLon_Lat_inStrip6(double lon, double lat); - QString BASECONSTVARIABLEAPI GetProjectionNameFromEPSG(long epsgCode) ; + QString BASECONSTVARIABLEAPI GetProjectionNameFromEPSG(long epsgCode); long BASECONSTVARIABLEAPI GetEPSGFromRasterFile(QString filepath); @@ -72,9 +74,23 @@ namespace RasterToolBase { CoordinateSystemType BASECONSTVARIABLEAPI getCoordinateSystemTypeByEPSGCode(long EPSGCODE); +};// namespace RasterProjectConvertor + + + + +// 遥感类常用数据 + + + + + + + + + -} // namespace RasterProjectConvertor #endif // LAMPCAE_RASTERTOOLBASE_H diff --git a/BaseCommonLibrary/BaseTool/SARSimulationImageL1.h b/BaseCommonLibrary/BaseTool/SARSimulationImageL1.h index c2abecf..3d85682 100644 --- a/BaseCommonLibrary/BaseTool/SARSimulationImageL1.h +++ b/BaseCommonLibrary/BaseTool/SARSimulationImageL1.h @@ -208,3 +208,9 @@ private: }; + + + + + + diff --git a/BaseCommonLibrary/ImageOperatorFuntion.cpp b/BaseCommonLibrary/ImageOperatorFuntion.cpp index 67c620a..6313329 100644 --- a/BaseCommonLibrary/ImageOperatorFuntion.cpp +++ b/BaseCommonLibrary/ImageOperatorFuntion.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include "stdafx.h" #include "ImageOperatorBase.h" #include "BaseTool.h" #include "GeoOperator.h" @@ -25,8 +25,12 @@ #include #include #include -#include // OGRSpatialReference ڿռοת -#include // GDALWarp +#include // OGRSpatialReference 用于空间参考转换 +#include // 用于 GDALWarp 操作 + +#include "gdal_priv.h" +#include "cpl_conv.h" +#include std::shared_ptr OpenDataset(const QString& in_path, GDALAccess rwmode) @@ -105,13 +109,13 @@ GDALDataType getGDALDataType(QString fileptah) CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( - fileptah.toUtf8().constData(), GA_ReadOnly)); // ��ֻ�ʽ��ȡ�Ӱ�� + fileptah.toUtf8().constData(), GA_ReadOnly)); // 锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); GDALClose((GDALDatasetH)rasterDataset); - omp_unset_lock(&lock); // �ͷŻ�� - omp_destroy_lock(&lock); // ٻ�� + omp_unset_lock(&lock); // 锟酵放伙拷斤拷 + omp_destroy_lock(&lock); // 劫伙拷斤拷 return gdal_datatype; } @@ -124,14 +128,14 @@ GDALDataType getGDALDataType(QString fileptah) int block_num_pre_memory(int block_width, int height, GDALDataType gdal_datatype, double memey_size) { - // С + // 计算大小 int size_meta = 0; if (gdal_datatype == GDT_Byte) { size_meta = 1; } else if (gdal_datatype == GDT_UInt16) { - size_meta = 2; // ֻ˫ܹͨ + size_meta = 2; // 只有双通道才能构建 复数矩阵 } else if (gdal_datatype == GDT_UInt16) { size_meta = 2; @@ -172,7 +176,7 @@ int block_num_pre_memory(int block_width, int height, GDALDataType gdal_datatype else { } int block_num = int(memey_size / (size_meta * block_width)); - block_num = block_num > height ? height : block_num; // + block_num = block_num > height ? height : block_num; // 行数 block_num = block_num < 1 ? 1 : block_num; return block_num; } @@ -203,84 +207,84 @@ int ENVI2TIFF(QString in_envi_path, QString out_tiff_path) void ConvertCoordinateSystem(QString inRasterPath, QString outRasterPath, long outepsgcode) { - // עGDAL + // 注册所有GDAL驱动 GDALAllRegister(); - // դļ + // 打开输入栅格文件 GDALDataset* srcDataset = (GDALDataset*)GDALOpen(inRasterPath.toUtf8().constData(), GA_ReadOnly); if (!srcDataset) { - // ļʧ - // qDebug() << "޷ļ" << inRasterPath; + // 错误处理:输出文件打开失败 + // qDebug() << "无法打开输入文件:" << inRasterPath; return; } - // Ŀϵ + // 创建目标坐标系 OGRSpatialReference targetSRS; if (targetSRS.importFromEPSG(outepsgcode) != OGRERR_NONE) { GDALClose(srcDataset); - // qDebug() << "ЧEPSG룺" << outepsgcode; + // qDebug() << "无效的EPSG代码:" << outepsgcode; return; } GDALDataType datetype = srcDataset->GetRasterBand(1)->GetRasterDataType(); - // ȡĿϵWKTʾ + // 获取目标坐标系的WKT表示 char* targetSRSWkt = nullptr; targetSRS.exportToWkt(&targetSRSWkt); bool flag = (datetype == GDT_Byte || datetype == GDT_Int8 || datetype == GDT_Int16 || datetype == GDT_UInt16 || datetype == GDT_Int32 || datetype == GDT_UInt32 || datetype == GDT_Int64 || datetype == GDT_UInt64); - // ͶӰݼWarped VRT + // 创建重投影后的虚拟数据集(Warped VRT) GDALDataset* warpedVRT = flag ? (GDALDataset*)GDALAutoCreateWarpedVRT( srcDataset, - nullptr, // ϵĬʹԴݣ - targetSRSWkt, // Ŀϵ - GRA_NearestNeighbour, // ز˫Բֵ - 0.0, // 0ʾԶ㣩 - nullptr // ѡ + nullptr, // 输入坐标系(默认使用源数据) + targetSRSWkt, // 目标坐标系 + GRA_NearestNeighbour, // 重采样方法:双线性插值 + 0.0, // 最大误差(0表示自动计算) + nullptr // 其他选项 ) : (GDALDataset*)GDALAutoCreateWarpedVRT( srcDataset, - nullptr, // ϵĬʹԴݣ - targetSRSWkt, // Ŀϵ - GRA_Bilinear, // ز˫Բֵ - 0.0, // 0ʾԶ㣩 - nullptr // ѡ + nullptr, // 输入坐标系(默认使用源数据) + targetSRSWkt, // 目标坐标系 + GRA_Bilinear, // 重采样方法:双线性插值 + 0.0, // 最大误差(0表示自动计算) + nullptr // 其他选项 ); - CPLFree(targetSRSWkt); // ͷWKTڴ + CPLFree(targetSRSWkt); // 释放WKT内存 if (!warpedVRT) { GDALClose(srcDataset); - qDebug() << u8"ͶӰתVRTʧ"; + qDebug() << u8"创建投影转换VRT失败"; return; } - // ȡGeoTIFFʽ + // 获取输出驱动(GeoTIFF格式) QString filesuffer = getFileExtension(outRasterPath).toLower(); bool isTiff = filesuffer.contains("tif"); GDALDriver* driver = isTiff ? GetGDALDriverManager()->GetDriverByName("GTiff") : GetGDALDriverManager()->GetDriverByName("ENVI"); if (!driver) { GDALClose(warpedVRT); GDALClose(srcDataset); - // qDebug() << "޷ȡGeoTIFF"; + // qDebug() << "无法获取GeoTIFF驱动"; return; } - // դļ + // 创建输出栅格文件 GDALDataset* dstDataset = driver->CreateCopy( - outRasterPath.toUtf8().constData(), // ļ· - warpedVRT, // ݼVRT - false, // Ƿϸ - nullptr, // ѡ - nullptr, // Ȼص - nullptr // ص + outRasterPath.toUtf8().constData(), // 输出文件路径 + warpedVRT, // 输入数据集(VRT) + false, // 是否严格复制 + nullptr, // 创建选项 + nullptr, // 进度回调 + nullptr // 回调参数 ); if (!dstDataset) { - // qDebug() << "ļʧܣ" << outRasterPath; + // qDebug() << "创建输出文件失败:" << outRasterPath; GDALClose(warpedVRT); GDALClose(srcDataset); return; } - // ͷԴ + // 释放资源 GDALClose(dstDataset); GDALClose(warpedVRT); GDALClose(srcDataset); @@ -320,11 +324,11 @@ void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QStr char* pszSrcWKT = NULL; pszSrcWKT = const_cast(pDSrc->GetProjectionRef()); - // ���û��ͶӰ����?���һ�?1?7 + // 锟斤拷锟矫伙拷锟酵队帮拷锟斤拷锟轿?拷锟斤拷锟揭伙拷锟?1锟?7 if (strlen(pszSrcWKT) <= 0) { OGRSpatialReference oSRS; oSRS.importFromEPSG(4326); - // oSRS.SetUTM(50, true); //������ ����120�� + // oSRS.SetUTM(50, true); //锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷120锟斤拷 // oSRS.SetWellKnownGeogCS("WGS84"); oSRS.exportToWkt(&pszSrcWKT); } @@ -332,12 +336,12 @@ void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QStr char* pdstSrcWKT = NULL; pdstSrcWKT = const_cast(pDRef->GetProjectionRef()); - // ���û��ͶӰ����?���һ�?1?7 + // 锟斤拷锟矫伙拷锟酵队帮拷锟斤拷锟轿?拷锟斤拷锟揭伙拷锟?1锟?7 if (strlen(pdstSrcWKT) <= 0) { OGRSpatialReference oSRS; oSRS.importFromEPSG(4326); - // oSRS.SetUTM(50, true); //������ ����120�� + // oSRS.SetUTM(50, true); //锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷120锟斤拷 // oSRS.SetWellKnownGeogCS("WGS84"); oSRS.exportToWkt(&pdstSrcWKT); } @@ -369,7 +373,7 @@ void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QStr hTransformArg = GDALCreateGenImgProjTransformer((GDALDatasetH)pDSrc, pszSrcWKT, NULL, pszSrcWKT, FALSE, 0.0, 1); qDebug() << "no proj "; - //(û��ͶӰ��Ӱ��������߲�??1?7) + //(没锟斤拷投影锟斤拷影锟斤拷锟斤拷锟斤拷锟斤拷卟锟酵?拷锟?1锟?7) if (hTransformArg == NULL) { qDebug() << "hTransformArg create failure"; GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); @@ -392,8 +396,8 @@ void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QStr GDALWarpOptions* psWo = GDALCreateWarpOptions(); - CPLSetConfigOption("GDAL_NUM_THREADS", "ALL_CPUS"); // ʹпõCPU - CPLSetConfigOption("GDAL_CACHEMAX", "16000"); // ûСΪ500MB + CPLSetConfigOption("GDAL_NUM_THREADS", "ALL_CPUS"); // 使用所有可用的CPU核心 + CPLSetConfigOption("GDAL_CACHEMAX", "16000"); // 设置缓存大小为500MB // psWo->papszWarpOptions = CSLDuplicate(NULL); psWo->eWorkingDataType = dataType; @@ -440,20 +444,20 @@ void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QStr void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, QString OutrasterCPath) { - // עGDAL + // 注册所有GDAL驱动 GDALAllRegister(); - // 򿪲οդB + // 打开参考栅格B GDALDataset* refDS = (GDALDataset*)GDALOpen(RefrasterBPath.toUtf8().constData(), GA_ReadOnly); if (!refDS) { - qDebug() << "޷򿪲οդB" << RefrasterBPath; + qDebug() << "无法打开参考栅格B:" << RefrasterBPath; return; } - // ȡοդĵ任ͶӰͳߴ + // 获取参考栅格的地理变换、投影和尺寸 double geotransform[6]; if (refDS->GetGeoTransform(geotransform) != CE_None) { - qDebug() << "ȡοդĵ任ʧܡ"; + qDebug() << "获取参考栅格的地理变换失败。"; GDALClose(refDS); return; } @@ -461,28 +465,28 @@ void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, Q const char* proj = refDS->GetProjectionRef(); int cols = refDS->GetRasterXSize(); int rows = refDS->GetRasterYSize(); - GDALClose(refDS); // ȡϢرղοդ + GDALClose(refDS); // 获取信息后关闭参考栅格 - // դA + // 打开输入栅格A GDALDataset* srcDS = (GDALDataset*)GDALOpen(InrasterAPath.toUtf8().constData(), GA_ReadOnly); if (!srcDS) { - qDebug() << "޷դA" << InrasterAPath; + qDebug() << "无法打开输入栅格A:" << InrasterAPath; return; } - // ȡդIJ + // 获取输入栅格的波段数和数据类型 int nBands = srcDS->GetRasterCount(); if (nBands == 0) { - qDebug() << "դûвݡ"; + qDebug() << "输入栅格没有波段数据。"; GDALClose(srcDS); return; } GDALDataType dataType = srcDS->GetRasterBand(1)->GetRasterDataType(); - // դC + // 创建输出栅格C GDALDriver* driver = GetGDALDriverManager()->GetDriverByName("GTiff"); if (!driver) { - qDebug() << "޷ȡGeoTIFF"; + qDebug() << "无法获取GeoTIFF驱动。"; GDALClose(srcDS); return; } @@ -496,16 +500,16 @@ void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, Q nullptr ); if (!dstDS) { - qDebug() << "޷դ" << OutrasterCPath; + qDebug() << "无法创建输出栅格:" << OutrasterCPath; GDALClose(srcDS); return; } - // դĵ任ͶӰ + // 设置输出栅格的地理变换和投影 dstDS->SetGeoTransform(geotransform); dstDS->SetProjection(proj); - // GDAL Warpѡ + // 配置GDAL Warp选项 GDALWarpOptions* psWO = GDALCreateWarpOptions(); psWO->hSrcDS = srcDS; psWO->hDstDS = dstDS; @@ -516,9 +520,9 @@ void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, Q psWO->panSrcBands[i] = i + 1; psWO->panDstBands[i] = i + 1; } - psWO->eResampleAlg = GRA_NearestNeighbour; // ʹز + psWO->eResampleAlg = GRA_NearestNeighbour; // 使用最近邻重采样 - // ʼת + // 初始化坐标转换器 psWO->pfnTransformer = GDALGenImgProjTransform; psWO->pTransformerArg = GDALCreateGenImgProjTransformer( srcDS, GDALGetProjectionRef(srcDS), @@ -526,17 +530,17 @@ void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, Q FALSE, 0.0, 1 ); if (!psWO->pTransformerArg) { - qDebug() << "תʧܡ"; + qDebug() << "创建坐标转换器失败。"; GDALDestroyWarpOptions(psWO); GDALClose(srcDS); GDALClose(dstDS); return; } - // ִWarp + // 执行Warp操作 GDALWarpOperation oWarp; if (oWarp.Initialize(psWO) != CE_None) { - qDebug() << "ʼWarpʧܡ"; + qDebug() << "初始化Warp操作失败。"; GDALDestroyGenImgProjTransformer(psWO->pTransformerArg); GDALDestroyWarpOptions(psWO); GDALClose(srcDS); @@ -546,79 +550,79 @@ void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, Q CPLErr eErr = oWarp.ChunkAndWarpImage(0, 0, cols, rows); if (eErr != CE_None) { - qDebug() << "ִWarpʧܡ"; + qDebug() << "执行Warp操作失败。"; } - // Դ + // 清理资源 GDALDestroyGenImgProjTransformer(psWO->pTransformerArg); GDALDestroyWarpOptions(psWO); GDALClose(srcDS); GDALClose(dstDS); - qDebug() << "زɣѱ" << OutrasterCPath; + qDebug() << "重采样完成,结果已保存至:" << OutrasterCPath; } void cropRasterByLatLon(const char* inputFile, const char* outputFile, double minLon, double maxLon, double minLat, double maxLat) { - // ʼ GDAL + // 初始化 GDAL 库 GDALAllRegister(); - // դݼ + // 打开栅格数据集 GDALDataset* poDataset = (GDALDataset*)GDALOpen(inputFile, GA_ReadOnly); if (poDataset == nullptr) { - std::cerr << "Failed to open input raster." << std::endl; + qDebug() << "Failed to open input raster." ; return; } - // ȡդݵĵοϢ + // 获取栅格数据的地理参考信息 double adfGeoTransform[6]; if (poDataset->GetGeoTransform(adfGeoTransform) != CE_None) { - std::cerr << "Failed to get geotransform." << std::endl; + qDebug() << "Failed to get geotransform." ; GDALClose(poDataset); return; } - // ȡӰͶӰϢ + // 获取输入影像的投影信息 const char* projection = poDataset->GetProjectionRef(); - // ݾγȼüӦդ + // 根据经纬度计算出裁剪区域对应的栅格像素坐标 int xMin = (int)((minLon - adfGeoTransform[0]) / adfGeoTransform[1]); int xMax = (int)((maxLon - adfGeoTransform[0]) / adfGeoTransform[1]); int yMin = (int)((maxLat - adfGeoTransform[3]) / adfGeoTransform[5]); int yMax = (int)((minLat - adfGeoTransform[3]) / adfGeoTransform[5]); - // üĿդݼ + // 创建裁剪区域的目标栅格数据集 GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); if (poDriver == nullptr) { - std::cerr << "Failed to get GTiff driver." << std::endl; + qDebug() << "Failed to get GTiff driver." ; GDALClose(poDataset); return; } - // դݼָߴ + // 创建输出栅格数据集,指定尺寸 int width = xMax - xMin; int height = yMax - yMin; GDALDataset* poOutDataset = poDriver->Create(outputFile, width, height, poDataset->GetRasterCount(), GDT_Float32, nullptr); if (poOutDataset == nullptr) { - std::cerr << "Failed to create output raster." << std::endl; + qDebug() << "Failed to create output raster." ; GDALClose(poDataset); return; } - // դͶӰϢ͵任 + // 设置输出栅格的投影信息和地理变换 poOutDataset->SetProjection(projection); double newGeoTransform[6] = { adfGeoTransform[0] + xMin * adfGeoTransform[1], adfGeoTransform[1], 0.0, adfGeoTransform[3] + yMin * adfGeoTransform[5], 0.0, adfGeoTransform[5] }; poOutDataset->SetGeoTransform(newGeoTransform); - // ѭȡԴݲдĿݼ + // 循环读取源数据并写入目标数据集 for (int i = 0; i < poDataset->GetRasterCount(); ++i) { GDALRasterBand* poBand = poDataset->GetRasterBand(i + 1); GDALRasterBand* poOutBand = poOutDataset->GetRasterBand(i + 1); - // ȡԴ + // 读取源数据 int* pData = new int[width * height]; poBand->RasterIO(GF_Read, xMin, yMin, width, height, pData, width, height, GDT_Int32, 0, 0); - // дĿ + // 写入目标数据 poOutBand->RasterIO(GF_Write, 0, 0, width, height, pData, width, height, GDT_Int32, 0, 0); delete[] pData; @@ -626,28 +630,28 @@ void cropRasterByLatLon(const char* inputFile, const char* outputFile, double mi qDebug() << "Raster cropped and saved to: " << outputFile; - // + // 清理 GDALClose(poDataset); GDALClose(poOutDataset); } ErrorCode transformCoordinate(double x, double y, int sourceEPSG, int targetEPSG, Point2& p) { - // Դϵԭʼϵ + // 创建源坐标系(原始坐标系) OGRSpatialReference sourceSRS; - sourceSRS.importFromEPSG(sourceEPSG); // ʹ EPSG ָϵ + sourceSRS.importFromEPSG(sourceEPSG); // 使用 EPSG 编码来指定坐标系 - // ĿϵĿϵ + // 创建目标坐标系(目标坐标系) OGRSpatialReference targetSRS; - targetSRS.importFromEPSG(targetEPSG); // WGS84 ϵ EPSG:4326 + targetSRS.importFromEPSG(targetEPSG); // WGS84 坐标系 EPSG:4326 - // 任 + // 创建坐标变换对象 OGRCoordinateTransformation* transform = OGRCreateCoordinateTransformation(&sourceSRS, &targetSRS); if (transform == nullptr) { qDebug() << "Failed to create coordinate transformation."; return ErrorCode::FAIL; } - // ת + // 转换坐标 double transformedX = x; double transformedY = y; if (transform->Transform(1, &transformedX, &transformedY)) { @@ -658,7 +662,7 @@ ErrorCode transformCoordinate(double x, double y, int sourceEPSG, int targetEPSG qDebug() << "Coordinate transformation failed."; } - // + // 清理 delete transform; p.x = transformedX; p.y = transformedY; @@ -668,23 +672,23 @@ ErrorCode transformCoordinate(double x, double y, int sourceEPSG, int targetEPSG void transformRaster(const char* inputFile, const char* outputFile, int sourceEPSG, int targetEPSG) { - // ʼ GDAL + // 初始化 GDAL 库 GDALAllRegister(); - // Դդļ + // 打开源栅格文件 GDALDataset* poSrcDS = (GDALDataset*)GDALOpen(inputFile, GA_ReadOnly); if (poSrcDS == nullptr) { qDebug() << "Failed to open input file:" << inputFile; return; } - // ȡԴդĻϢ + // 获取源栅格的基本信息 int nXSize = poSrcDS->GetRasterXSize(); int nYSize = poSrcDS->GetRasterYSize(); int nBands = poSrcDS->GetRasterCount(); GDALDataType eDT = poSrcDS->GetRasterBand(1)->GetRasterDataType(); - // Ŀդļ + // 创建目标栅格文件 GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); if (poDriver == nullptr) { qDebug() << "GTiff driver not available."; @@ -699,7 +703,7 @@ void transformRaster(const char* inputFile, const char* outputFile, int sourceEP return; } - // ĿդĿռοϵͳ + // 设置目标栅格的空间参考系统 OGRSpatialReference oSRS; oSRS.importFromEPSG(targetEPSG); @@ -708,10 +712,10 @@ void transformRaster(const char* inputFile, const char* outputFile, int sourceEP poDstDS->SetProjection(pszWKT); CPLFree(pszWKT); - // Ԫ + // 复制元数据 poDstDS->SetMetadata(poSrcDS->GetMetadata()); - // ÿε + // 复制每个波段的数据 for (int i = 1; i <= nBands; ++i) { GDALRasterBand* poSrcBand = poSrcDS->GetRasterBand(i); GDALRasterBand* poDstBand = poDstDS->GetRasterBand(i); @@ -726,7 +730,7 @@ void transformRaster(const char* inputFile, const char* outputFile, int sourceEP CPLFree(pafScanline); } - // رݼ + // 关闭数据集 GDALClose(poSrcDS); GDALClose(poDstDS); @@ -735,68 +739,68 @@ void transformRaster(const char* inputFile, const char* outputFile, int sourceEP void resampleRaster(const char* inputRaster, const char* outputRaster, double targetPixelSizeX, double targetPixelSizeY) { - // ʼGDAL + // 初始化GDAL GDALAllRegister(); - // դļ + // 打开输入栅格文件 GDALDataset* poDataset = (GDALDataset*)GDALOpen(inputRaster, GA_ReadOnly); if (poDataset == nullptr) { - std::cerr << "Failed to open raster file." << std::endl; + qDebug() << "Failed to open raster file." ; return; } - // ȡԭʼդĿռο + // 获取原始栅格的空间参考 double adfGeoTransform[6]; if (poDataset->GetGeoTransform(adfGeoTransform) != CE_None) { - std::cerr << "Failed to get geotransform." << std::endl; + qDebug() << "Failed to get geotransform." ; GDALClose(poDataset); return; } - // ȡԭʼդijߴ + // 获取原始栅格的尺寸 int nXSize = poDataset->GetRasterXSize(); int nYSize = poDataset->GetRasterYSize(); - // Ŀդijߴ + // 计算目标栅格的尺寸 double targetXSize = (adfGeoTransform[1] * nXSize) / targetPixelSizeX; double targetYSize = (adfGeoTransform[5] * nYSize) / targetPixelSizeY; - // Ŀݼդ + // 创建目标数据集(输出栅格) GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); if (poDriver == nullptr) { - std::cerr << "Failed to get GTiff driver." << std::endl; + qDebug() << "Failed to get GTiff driver." ; GDALClose(poDataset); return; } - // ݼ + // 创建输出数据集 GDALDataset* poOutDataset = poDriver->Create(outputRaster, (int)targetXSize, (int)targetYSize, poDataset->GetRasterCount(), GDT_Float32, nullptr); if (poOutDataset == nullptr) { - std::cerr << "Failed to create output raster." << std::endl; + qDebug() << "Failed to create output raster." ; GDALClose(poDataset); return; } - // ݼĵ任ϵ + // 设置输出数据集的地理变换(坐标系) double targetGeoTransform[6] = { adfGeoTransform[0], targetPixelSizeX, 0, adfGeoTransform[3], 0, -targetPixelSizeY }; poOutDataset->SetGeoTransform(targetGeoTransform); - // ݼͶӰϢ + // 设置输出数据集的投影信息 poOutDataset->SetProjection(poDataset->GetProjectionRef()); - // ز + // 进行重采样 for (int i = 0; i < poDataset->GetRasterCount(); i++) { GDALRasterBand* poBand = poDataset->GetRasterBand(i + 1); GDALRasterBand* poOutBand = poOutDataset->GetRasterBand(i + 1); - // ʹGDALزѡһʵزʽ + // 使用GDAL的重采样方法,选择一个适当的重采样方式 poOutBand->RasterIO(GF_Write, 0, 0, (int)targetXSize, (int)targetYSize, nullptr, (int)targetXSize, (int)targetYSize, poBand->GetRasterDataType(), 0, 0, nullptr); } - // رݼ + // 关闭数据集 GDALClose(poDataset); GDALClose(poOutDataset); @@ -806,10 +810,10 @@ void resampleRaster(const char* inputRaster, const char* outputRaster, double ta std::shared_ptr GetCenterPointInRaster(QString filepath) { qDebug() << "============= GetCenterPointInRaster ======================"; - // QTextCodec* codec = QTextCodec::codecForLocale(); // ȡϵͳĬϱı - // QByteArray byteArray = codec->fromUnicode(filepath); // QStringתΪQByteArray - //,ӦûԶͷ const char* charArray = byteArray.constData(); // - // ȡQByteArrayconst char*ָ + // QTextCodec* codec = QTextCodec::codecForLocale(); // 获取系统默认编码的文本编解码器 + // QByteArray byteArray = codec->fromUnicode(filepath); // 将QString转换为QByteArray + //,这个应该会自动释放 const char* charArray = byteArray.constData(); // + // 获取QByteArray的const char*指针 GDALAllRegister(); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); @@ -817,7 +821,7 @@ std::shared_ptr GetCenterPointInRaster(QString filepath) GDALDataset* poDataset = (GDALDataset*)GDALOpen(filepath.toUtf8().data(), GA_ReadOnly); if (nullptr == poDataset || NULL == poDataset) { qDebug() << "Could not open dataset"; - return nullptr; // ʾȡʧ + return nullptr; // 表示读取失败 } double x, y, z; @@ -834,7 +838,7 @@ std::shared_ptr GetCenterPointInRaster(QString filepath) double dfWidth = poDataset->GetRasterXSize(); double dfHeight = poDataset->GetRasterYSize(); - // ĵ꣨꣩ + // 计算中心点坐标(像素坐标) double dfCenterX = adfGeoTransform[0] + dfWidth * adfGeoTransform[1] / 2.0 + dfHeight * adfGeoTransform[2] / 2.0; double dfCenterY = adfGeoTransform[3] + dfWidth * adfGeoTransform[4] / 2.0 @@ -851,7 +855,7 @@ std::shared_ptr GetCenterPointInRaster(QString filepath) y = dfCenterY; } else { - // ǵϵתWGS84 + // 如果不是地理坐标系,转换到WGS84 OGRSpatialReference oSRS_WGS84; oSRS_WGS84.SetWellKnownGeogCS("WGS84"); @@ -899,10 +903,10 @@ std::shared_ptr GetCenterPointInRaster(QString filepath) long GetEPSGFromRasterFile(QString filepath) { qDebug() << "============= GetEPSGFromRasterFile ======================"; - // QTextCodec* codec = QTextCodec::codecForLocale(); // ȡϵͳĬϱı - // QByteArray byteArray = codec->fromUnicode(filepath); // QStringתΪQByteArray - //,ӦûԶͷ const char* charArray = byteArray.constData(); // - // ȡQByteArrayconst char*ָ + // QTextCodec* codec = QTextCodec::codecForLocale(); // 获取系统默认编码的文本编解码器 + // QByteArray byteArray = codec->fromUnicode(filepath); // 将QString转换为QByteArray + //,这个应该会自动释放 const char* charArray = byteArray.constData(); // + // 获取QByteArray的const char*指针 { if (QFile(filepath).exists()) { @@ -913,9 +917,9 @@ long GetEPSGFromRasterFile(QString filepath) } GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // עGDAL + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注册GDAL驱动 // qDebug()<GetProjectionRef(); qDebug() << QString::fromUtf8(pszProjection); - // SpatialReference + // 创建SpatialReference对象 OGRSpatialReference oSRS; if (oSRS.importFromWkt((char**)&pszProjection) != OGRERR_NONE) { qDebug() << ("Error: Unable to import projection information.\n"); @@ -945,7 +949,7 @@ long GetEPSGFromRasterFile(QString filepath) return -1; } - long epsgCode = atoi(epscodestr); // ȡEPSG + long epsgCode = atoi(epscodestr); // 获取EPSG代码 if (epsgCode != 0) { GDALClose(poDataset); @@ -983,16 +987,16 @@ long getProjectEPSGCodeByLon_Lat(double long, double lat, ProjectStripDelta stri } long getProjectEPSGCodeByLon_Lat_inStrip3(double lon, double lat) { - // EPSG 4534 ~ 4554 3 ȴ - // жǷ йΧ - // ľȷΧ 75E ~ 135E ʵʷΧ 73.5E ~ 136.5E, - // γȷΧ 3N ~ 54Nſ 0N~ 60N - if (73.5 <= lon && lon <= 136.5 && 0 <= lat && lat <= 60) { // й + // EPSG 4534 ~ 4554 3 度带 + // 首先判断是否是在 中国带宽范围 + // 中心经度范围 :75E ~ 135E 实际范围 73.5E ~ 136.5E, + // 纬度范围 3N ~ 54N,放宽到 0N~ 60N + if (73.5 <= lon && lon <= 136.5 && 0 <= lat && lat <= 60) { // 中国境内 long code = trunc((lon - 73.5) / 3) + 4534; return code; } - else { // й ʹ ˹ - bool isSouth = lat < 0; // жϱΪʾʵӦÿҪϸµ߼ + else { // 非中国境内 使用 高斯克吕格 + bool isSouth = lat < 0; // 简单判断南北半球,这里仅为示例,实际应用可能需要更细致的逻辑 long prefix = isSouth ? 327000 : 326000; // std::string prefix = isSouth ? "327" : "326"; lon = fmod(lon + 360.0, 360.0); @@ -1004,18 +1008,18 @@ long getProjectEPSGCodeByLon_Lat_inStrip3(double lon, double lat) } long getProjectEPSGCodeByLon_Lat_inStrip6(double lon, double lat) { - // EPSG 4502 ~ 4512 6ȴ - // жǷ йΧ - // ľȷΧ 75E ~ 135E ʵʷΧ 72.0E ~ 138E, - // γȷΧ 3N ~ 54Nſ 0N~ 60N - if (73.5 <= lon && lon <= 136.5 && 0 <= lat && lat <= 60) { // й + // EPSG 4502 ~ 4512 6度带 + // 首先判断是否是在 中国带宽范围 + // 中心经度范围 :75E ~ 135E 实际范围 72.0E ~ 138E, + // 纬度范围 3N ~ 54N,放宽到 0N~ 60N + if (73.5 <= lon && lon <= 136.5 && 0 <= lat && lat <= 60) { // 中国境内 long code = trunc((lon - 72.0) / 6) + 4502; return code; } - else { // й ʹ UTM// ȷţ6ȴ1ʼ60ÿ6һ + else { // 非中国境内 使用 UTM// 确定带号,6度带从1开始到60,每6度一个带 int zone = static_cast((lon + 180.0) / 6.0) + 1; - bool isSouth = lon < 0; // жǷϰ - long epsgCodeBase = isSouth ? 32700 : 32600; // EPSG + bool isSouth = lon < 0; // 判断是否在南半球 + long epsgCodeBase = isSouth ? 32700 : 32600; // 计算EPSG代码 long prefix = static_cast(epsgCodeBase + zone); return prefix; } @@ -1027,13 +1031,13 @@ QString GetProjectionNameFromEPSG(long epsgCode) qDebug() << "============= GetProjectionNameFromEPSG ======================"; OGRSpatialReference oSRS; - // EPSG + // 设置EPSG代码 if (oSRS.importFromEPSG(epsgCode) != OGRERR_NONE) { qDebug() << "epsgcode not recognition"; return ""; } - // ȡϵƣ + // 获取并输出坐标系的描述(名称) const char* pszName = oSRS.GetAttrValue("GEOGCS"); if (pszName) { qDebug() << "Coordinate system name for EPSG " + QString::number(epsgCode) @@ -1046,19 +1050,19 @@ QString GetProjectionNameFromEPSG(long epsgCode) } // char* wkt = NULL; - // // תΪWKTʽ + // // 转换为WKT格式 // oSRS.exportToWkt(&wkt); // // qDebug() << wkt; // - // // WKTнͶӰƣ򻯴ʵʿҪӵ߼׼ȷȡ + // // 从WKT中解析投影名称,这里简化处理,实际可能需要更复杂的逻辑来准确提取名称 // std::string wktStr(wkt); - // long start = wktStr.find("PROJCS[\"") + 8; // ҵ"PROJCS["ĵһ˫λ - // // startλÿʼһ˫ţ֮ݼΪͶӰ + // long start = wktStr.find("PROJCS[\"") + 8; // 找到"PROJCS["后的第一个双引号位置 + // // 从start位置开始找下一个双引号,这之间的内容即为投影名称 // int end = wktStr.find('\"', start); // QString projName = QString::fromStdString(wktStr.substr(start, end - start)); // - // // ͷWKTַڴ + // // 释放WKT字符串内存 // CPLFree(wkt); // return projName; @@ -1111,11 +1115,11 @@ int ResampleGDAL(const char* pszSrcFile, const char* pszOutFile, double* gt, int char* pszSrcWKT = NULL; pszSrcWKT = const_cast(pDSrc->GetProjectionRef()); - // ���û��ͶӰ����?���һ�?1?7 + // 锟斤拷锟矫伙拷锟酵队帮拷锟斤拷锟轿?拷锟斤拷锟揭伙拷锟?1锟?7 if (strlen(pszSrcWKT) <= 0) { OGRSpatialReference oSRS; oSRS.importFromEPSG(4326); - // oSRS.SetUTM(50, true); //������ ����120�� + // oSRS.SetUTM(50, true); //锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷120锟斤拷 // oSRS.SetWellKnownGeogCS("WGS84"); oSRS.exportToWkt(&pszSrcWKT); } @@ -1124,7 +1128,7 @@ int ResampleGDAL(const char* pszSrcFile, const char* pszOutFile, double* gt, int hTransformArg = GDALCreateGenImgProjTransformer((GDALDatasetH)pDSrc, pszSrcWKT, NULL, pszSrcWKT, FALSE, 0.0, 1); qDebug() << "no proj " << Qt::endl; - //(û��ͶӰ��Ӱ��������߲�??1?7) + //(没锟斤拷投影锟斤拷影锟斤拷锟斤拷锟斤拷锟斤拷卟锟酵?拷锟?1锟?7) if (hTransformArg == NULL) { GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); return -3; @@ -1152,8 +1156,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", "4000"); // ûСΪ500MB + CPLSetConfigOption("GDAL_NUM_THREADS", "ALL_CPUS"); // 使用所有可用的CPU核心 + CPLSetConfigOption("GDAL_CACHEMAX", "4000"); // 设置缓存大小为500MB // psWo->papszWarpOptions = CSLDuplicate(NULL); psWo->eWorkingDataType = dataType; psWo->eResampleAlg = eResample; @@ -1361,7 +1365,7 @@ int alignRaster(QString inputPath, QString referencePath, QString outputPath, GD -/** 2025.03.25 ĺ Eigenʹ****************************/ +/** 2025.03.25 下面的函数存在 Eigen使用****************************/ @@ -1392,8 +1396,8 @@ int saveMatrixXcd2TiFF(Eigen::MatrixXcd data, QString out_tiff_path) Eigen::MatrixXd gt = Eigen::MatrixXd::Zero(2, 3); gdalImage image_tiff = - CreategdalImage(out_tiff_path, rows, cols, 2, gt, "", false, true); // עﱣ - // ļ + CreategdalImage(out_tiff_path, rows, cols, 2, gt, "", false, true); // 注意这里保留仿真结果 + // 保存二进制文件 Eigen::MatrixXd real_img = data.array().real(); Eigen::MatrixXd imag_img = data.array().imag(); image_tiff.saveImage(real_img, 0, 0, 1); @@ -1433,7 +1437,7 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri gdalImage demds(dempath); gdalImage demxyz = CreategdalImage(demxyzpath, demds.height, demds.width, 3, demds.gt, demds.projection, true, true);// X,Y,Z - // ֿ㲢תΪXYZ + // 分块计算并转换为XYZ Eigen::MatrixXd demArr = demds.getData(0, 0, demds.height, demds.width, 1); Eigen::MatrixXd demR = demArr; @@ -1459,8 +1463,8 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri for (int j = 0; j < datacols; j++) { rowidx = i + max_rows_ids; colidx = j; - demds.getLandPoint(rowidx, colidx, demdata(i, j), LandP); // ȡ - LLA2XYZ(LandP, GERpoint); // γתΪϵ + demds.getLandPoint(rowidx, colidx, demdata(i, j), LandP); // 获取地理坐标 + LLA2XYZ(LandP, GERpoint); // 经纬度转换为地心坐标系 xyzdata_x(i, j) = GERpoint.x; xyzdata_y(i, j) = GERpoint.y; xyzdata_z(i, j) = GERpoint.z; @@ -1472,7 +1476,7 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri } - // + // 计算坡向角 gdalImage demsloperxyz = CreategdalImage(demsloperPath, demds.height, demds.width, 4, demds.gt, demds.projection, true, true);// X,Y,Z,cosangle line_invert = 1000; @@ -1507,13 +1511,13 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri demds.getLandPoint(rowidx + 1, colidx, demdata(i + 1, j), p3); demds.getLandPoint(rowidx, colidx + 1, demdata(i, j + 1), p4); - pslopeVector = getSlopeVector(p0, p1, p2, p3, p4); // ʸ + pslopeVector = getSlopeVector(p0, p1, p2, p3, p4); // 地面坡向矢量 slopeVector = { pslopeVector.lon,pslopeVector.lat,pslopeVector.ati }; pp = LLA2XYZ(p0); Zaxis.x = pp.lon; Zaxis.y = pp.lat; Zaxis.z = pp.ati; - sloperAngle = getCosAngle(slopeVector, Zaxis); // + sloperAngle = getCosAngle(slopeVector, Zaxis); // 地面坡向角 demsloper_x(i, j) = slopeVector.x; demsloper_y(i, j) = slopeVector.y; @@ -1549,7 +1553,7 @@ void CreateSARIntensityByLookTable(QString IntensityRasterPath, Eigen::MatrixXd SARData = SARIntensity.getData(0, 0, SARIntensity.height, SARIntensity.width, 1); SARData = SARData.array() * 0; - // ֿ鴦 + // 分块处理 for (int yOff = 0; yOff < looktableds.height; yOff += blockYSize) { processBarShow(yOff, looktableds.height); @@ -1575,9 +1579,267 @@ void CreateSARIntensityByLookTable(QString IntensityRasterPath, } -/* ĺᵼ±󣬿Eigen bugأŲ飬̫ʱ䣬ҲһŲ + + + + + + +/**​ +* @brief 将VRT文件转换为ENVI格式(生成.dat和.hdr文件) +* @param inputVrtPath 输入VRT文件路径 +* @param outputEnviPath 输出ENVI数据文件路径(不含扩展名,自动生成.dat和.hdr) +* @param papszOptions GDAL创建选项(如压缩参数、存储顺序等,默认NULL) +* @return 成功返回true,失败返回false +*/ +bool ConvertVrtToEnvi(QString vrtPath, QString outPath) { + + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7 + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + + const char* inputVrtPath = vrtPath.toUtf8().constData(); + const char* outputEnviPath = outPath.toUtf8().constData(); + + // 注册所有GDAL驱动[7](@ref) + GDALAllRegister(); + + // 打开输入VRT文件[1,3](@ref) + GDALDataset* poVRTDataset = (GDALDataset*)GDALOpen(inputVrtPath, GA_ReadOnly); + if (!poVRTDataset) { + qDebug() << "错误:无法打开VRT文件 " << inputVrtPath ; + return false; + } + + // 获取ENVI驱动[4,7](@ref) + GDALDriver* poENVIDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); + if (!poENVIDriver) { + qDebug() << "错误:ENVI驱动未加载" ; + GDALClose(poVRTDataset); + return false; + } + + // 构造输出文件名(强制添加.dat后缀)[4](@ref) + std::string outputPath = std::string(outputEnviPath) + ".dat"; + + // 执行格式转换(自动生成.hdr头文件)[4,7](@ref) + GDALDataset* poENVIDataset = poENVIDriver->CreateCopy( + outputPath.c_str(), // 输出路径 + poVRTDataset, // 输入数据集 + FALSE, // 非严格模式(允许格式调整) + nullptr, // 用户自定义选项(如压缩参数) + nullptr, nullptr // 进度条和参数(暂不启用) + ); + + // 检查转换结果 + bool success = (poENVIDataset != nullptr); + if (!success) { + qDebug() << "错误:ENVI文件创建失败" ; + } + else { + GDALClose(poENVIDataset); + } + + // 关闭输入数据集 + GDALClose(poVRTDataset); + return success; +} + + + + +// 遥感类 +ErrorCode ResampleDEM(QString indemPath, QString outdemPath, double gridx, double gridy) +{ + double gridlat = gridy / 110000.0; + double gridlon = gridx / 100000.0; + + long espgcode = GetEPSGFromRasterFile(indemPath.toUtf8().constData()); + if (espgcode == 4326) { + resampleRaster(indemPath.toUtf8().constData(), outdemPath.toUtf8().constData(), gridlon, gridlat); + return ErrorCode::SUCCESS; + } + else { + QMessageBox::warning(nullptr, u8"警告", u8"请输入WGS84坐标的DEM影像"); + return ErrorCode::FAIL; + } +} + + + +ErrorCode Complex2AmpRaster(QString inComplexPath, QString outRasterPath) +{ + gdalImageComplex inimg(inComplexPath); + gdalImage ampimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); + + long blocklines = Memory1GB * 2 / 8 / inimg.width; + blocklines = blocklines < 100 ? 100 : blocklines; + Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); + Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); + + long startrow = 0; + for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { + + imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); + imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); + imgArrb1 = imgArr.array().abs(); + ampimg.saveImage(imgArrb1, startrow, 0, 1); + } + qDebug() << "影像写入到:" << outRasterPath; + return ErrorCode::SUCCESS; +} + +ErrorCode Complex2PhaseRaster(QString inComplexPath, QString outRasterPath) +{ + gdalImageComplex inimg(inComplexPath); + gdalImage ampimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); + + + long blocklines = Memory1GB * 2 / 8 / inimg.width; + blocklines = blocklines < 100 ? 100 : blocklines; + Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); + Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); + + long startrow = 0; + for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { + + imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); + imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); + imgArrb1 = imgArr.array().arg(); + ampimg.saveImage(imgArrb1, startrow, 0, 1); + } + qDebug() << "影像写入到:" << outRasterPath; + return ErrorCode::SUCCESS; +} + +ErrorCode Complex2dBRaster(QString inComplexPath, QString outRasterPath) +{ + gdalImageComplex inimg(inComplexPath); + gdalImage ampimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); + + + long blocklines = Memory1GB * 2 / 8 / inimg.width; + blocklines = blocklines < 100 ? 100 : blocklines; + Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); + Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); + + long startrow = 0; + for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { + + imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); + imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); + imgArrb1 = imgArr.array().abs().log10() * 20.0; + ampimg.saveImage(imgArrb1, startrow, 0, 1); + } + qDebug() << "影像写入到:" << outRasterPath; + return ErrorCode::SUCCESS; +} + + + + + +void MultiLookRaster(QString inRasterPath, QString outRasterPath, long looklineNumrow, long looklineNumCol) +{ + gdalImage inRaster(inRasterPath); + + int outRows = inRaster.height / looklineNumrow; + int outCols = inRaster.width / looklineNumCol; + int bandnum = 1; + QString project = inRaster.projection; + Eigen::MatrixXd inRasterGt = inRaster.gt; + GDALDataType datetype = inRaster.getDataType(); + + gdalImage outRaster = CreategdalImage(outRasterPath, outRows, outCols, 1, inRasterGt, project, true, true, true, datetype); + + Eigen::MatrixXd inRasterArr = inRaster.getData(0, 0, inRaster.height, inRaster.width, 1); + Eigen::MatrixXd outRasterArr = outRaster.getData(0, 0, outRows, outCols, 1); + + + // 多视处理 +#pragma omp parallel for collapse(2) + for (int row = 0; row < outRows; ++row) { + for (int col = 0; col < outCols; ++col) { + // 计算输入矩阵的窗口位置[2,3](@ref) + const int inputRow = row * looklineNumrow; + const int inputCol = col * looklineNumCol; + + // 动态计算实际窗口大小(处理边界情况)[3](@ref) + const int actualRows = (row == outRows - 1) ? + (inRaster.height - inputRow) : looklineNumrow; + const int actualCols = (col == outCols - 1) ? + (inRaster.width - inputCol) : looklineNumCol; + + // 提取当前窗口数据块[7](@ref) + Eigen::MatrixXd window = inRasterArr.block(inputRow, inputCol, actualRows, actualCols); + + // 计算多视平均值(自动处理数据类型转换)[2,7](@ref) + double sum = 0.0; + if constexpr (std::is_integral_v) { + sum = window.cast().sum(); // 整型数据转换为双精度计算 + } + else { + sum = window.sum(); + } + outRasterArr(row, col) = sum / (actualRows * actualCols); + } + } + + // 可选:处理残留边界(当输入尺寸不是整数倍时) + if ((inRaster.height % looklineNumrow != 0) || (inRaster.width % looklineNumCol != 0)) { + // 底部边界处理[3](@ref) + const int residualRowStart = outRows * looklineNumrow; + const int residualRowSize = inRaster.height - residualRowStart; + if (residualRowSize > 0) { +#pragma omp parallel for + for (int col = 0; col < outCols; ++col) { + const int inputCol = col * looklineNumCol; + const int actualCols = (col == outCols - 1) ? + (inRaster.width - inputCol) : looklineNumCol; + + Eigen::MatrixXd window = inRasterArr.block(residualRowStart, inputCol, + residualRowSize, actualCols); + outRasterArr(outRows - 1, col) = window.mean(); + } + } + + // 右侧边界处理[3](@ref) + const int residualColStart = outCols * looklineNumCol; + const int residualColSize = inRaster.width - residualColStart; + if (residualColSize > 0) { +#pragma omp parallel for + for (int row = 0; row < outRows; ++row) { + const int inputRow = row * looklineNumrow; + const int actualRows = (row == outRows - 1) ? + (inRaster.height - inputRow) : looklineNumrow; + + Eigen::MatrixXd window = inRasterArr.block(inputRow, residualColStart, + actualRows, residualColSize); + outRasterArr(row, outCols - 1) = window.mean(); + } + } + } + + // 保存结果 + outRaster.saveImage(outRasterArr, 0, 0, 1); + +} + + + + + + + + + + + + + +/* 启动下面的函数,会导致编译器错误,可能与Eigen 库 本身的bug相关,不建议排查,太费时间,而且不一定能排查出来 * -*** +*** Eigen::Matrix ReadComplexMatrixData(int start_line, int width, int line_num, std::shared_ptr rasterDataset, GDALDataType gdal_datatype) @@ -1601,7 +1863,7 @@ Eigen::Matrix ReadCompl } bool _flag = false; Eigen::Matrix data_mat( - line_num * width, 2); // ǿ + line_num * width, 2); // 必须强制行优先 if (gdal_datatype == GDT_Byte) { Eigen::MatrixX real_mat(line_num * width, 1); Eigen::MatrixX imag_mat(line_num * width, 1); @@ -1751,14 +2013,14 @@ Eigen::Matrix ReadCompl } else { } - // + // 保存数据 if (_flag) { return data_mat; } else { return Eigen::Matrix( - 0, 0); // ǿ; + 0, 0); // 必须强制行优先; } } @@ -1767,10 +2029,10 @@ ReadMatrixDoubleData(int start_line, int width, int line_num, std::shared_ptr rasterDataset, GDALDataType gdal_datatype, int band_idx) { - // 飬ʹeigen о㣬ټ + // 构建矩阵块,使用eigen 进行矩阵计算,加速计算 bool _flag = false; Eigen::Matrix data_mat( - line_num * width, 1); // ǿ + line_num * width, 1); // 必须强制行优先 if (gdal_datatype == GDT_Byte) { Eigen::MatrixX real_mat(line_num * width, 1); rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, diff --git a/Toolbox/BaseToolbox/BaseToolbox.vcxproj b/Toolbox/BaseToolbox/BaseToolbox.vcxproj index 5384b55..5ec3f82 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.vcxproj +++ b/Toolbox/BaseToolbox/BaseToolbox.vcxproj @@ -60,12 +60,12 @@ tools_qt5 - core + core;gui;widgets debug tools_qt5 - core + core;gui;widgets debug diff --git a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp index 76188ba..1e5fdcd 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp @@ -209,90 +209,6 @@ ErrorCode ImportGF3L1AProcess(QString inMetaxmlPath, QString outWorkDirPath) return errorcode; } -ErrorCode Complex2AmpRaster(QString inComplexPath, QString outRasterPath) -{ - gdalImageComplex inimg(inComplexPath); - gdalImage ampimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); - - long blocklines = Memory1GB * 2 / 8 / inimg.width; - blocklines = blocklines < 100 ? 100 : blocklines; - Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); - Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); - - long startrow = 0; - for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { - - imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); - imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); - imgArrb1 = imgArr.array().abs(); - ampimg.saveImage(imgArrb1, startrow, 0, 1); - } - qDebug() << "Ӱд뵽" << outRasterPath; - return ErrorCode::SUCCESS; -} - -ErrorCode Complex2PhaseRaster(QString inComplexPath, QString outRasterPath) -{ - gdalImageComplex inimg(inComplexPath); - gdalImage ampimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); - - - long blocklines = Memory1GB * 2 / 8 / inimg.width; - blocklines = blocklines < 100 ? 100 : blocklines; - Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); - Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); - - long startrow = 0; - for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { - - imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); - imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); - imgArrb1 = imgArr.array().arg(); - ampimg.saveImage(imgArrb1, startrow, 0, 1); - } - qDebug() << "Ӱд뵽" << outRasterPath; - return ErrorCode::SUCCESS; -} - -ErrorCode Complex2dBRaster(QString inComplexPath, QString outRasterPath) -{ - gdalImageComplex inimg(inComplexPath); - gdalImage ampimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); - - - long blocklines = Memory1GB * 2 / 8 / inimg.width; - blocklines = blocklines < 100 ? 100 : blocklines; - Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); - Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); - - long startrow = 0; - for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { - - imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); - imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); - imgArrb1 = imgArr.array().abs().log10() * 20.0; - ampimg.saveImage(imgArrb1, startrow, 0, 1); - } - qDebug() << "Ӱд뵽" << outRasterPath; - return ErrorCode::SUCCESS; -} - -ErrorCode ResampleDEM(QString indemPath, QString outdemPath, double gridx, double gridy) -{ - double gridlat = gridy / 110000.0; - double gridlon = gridx / 100000.0; - - long espgcode = GetEPSGFromRasterFile(indemPath.toUtf8().constData()); - if (espgcode == 4326) { - resampleRaster(indemPath.toUtf8().constData(), outdemPath.toUtf8().constData(), gridlon, gridlat); - return ErrorCode::SUCCESS; - } - else { - QMessageBox::warning(nullptr, u8"", u8"WGS84DEMӰ"); - return ErrorCode::FAIL; - } -} - ErrorCode RD_PSTN(double& refrange, double& lamda, double& timeR, double& R, double& tx, double& ty, double& tz, double& slopex, double& slopey, double& slopez, GF3PolyfitSatelliteOribtModel& polyfitmodel, SatelliteOribtNode& node, double& d0, double& d1, double& d2, double& d3, double& d4) { @@ -605,7 +521,3 @@ ErrorCode GF3RDProcess(QString inxmlPath, QString indemPath, QString outworkdir, } return ErrorCode::SUCCESS; } - - - - diff --git a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.h b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.h index 2309c4c..db71e8c 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.h +++ b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.h @@ -17,14 +17,7 @@ QVector SearchGF3DataTiff(QString inMetaxmlPath); POLARTYPEENUM getDatasetGF3FilePolsarType(QString fileName); ErrorCode ImportGF3L1AProcess(QString inMetaxmlPath, QString outWorkDirPath); -// תʵ -ErrorCode Complex2AmpRaster(QString inComplexPath, QString outRasterPath); -//תλ -ErrorCode Complex2PhaseRaster(QString inComplexPath, QString outRasterPath); -ErrorCode Complex2dBRaster(QString inComplexPath, QString outRasterPath); - -ErrorCode ResampleDEM(QString indemPath, QString outdemPath, double gridx, double gridy); // RD 㷨 ErrorCode RD_PSTN(double& refrange,double& lamda, double& timeR, double& R, double& tx, double& ty, double& tz, double& slopex, double& slopey, double& slopez, GF3PolyfitSatelliteOribtModel& polyfitmodel, SatelliteOribtNode& node,double& d0,double& d1, double& d2, double& d3, double& d4); @@ -36,6 +29,3 @@ ErrorCode GF3OrthSLC( QString inRasterPath, QString inlooktablePath, QString out // 䴦 ErrorCode GF3RDProcess(QString inxmlPath, QString indemPath, QString outworkdir, double gridx, double gridy); - - - diff --git a/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp b/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp index 90b6580..af2d5a6 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp @@ -5,6 +5,7 @@ #include "BaseTool.h" #include "SARSimulationImageL1.h" #include "GF3CalibrationAndGeocodingClass.h" +#include "RasterToolBase.h" QComplex2AmpPhase::QComplex2AmpPhase(QWidget *parent) : QDialog(parent) diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 36a432d..334bc9c 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -639,8 +639,6 @@ void InterploateClipAtiByRefDEM(QString ImageLLPath, QString& ImageDEMPath, QStr } - - int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QString ori_sim_count_tiffPath,long OriHeight,long OriWidth) { gdalImage sim_rc(dem_rc_path); @@ -783,7 +781,6 @@ int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QStrin } - int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePath, QString L1AEchoDataPath) { gdalImageComplex echodata(L2echodataPath); gdalImage looktable(RangeLooktablePath); @@ -909,6 +906,126 @@ int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePa } +void InterpLookTableRfromDEM(QString lonlatPath, QString DEMPath, QString outllrpath) +{ + gdalImage LLimg(lonlatPath); + gdalImage demimg(DEMPath); + gdalImage LLRimg = CreategdalImageDouble(outllrpath, LLimg.height, LLimg.width, 3, true, true); + + long llimgheight = LLimg.height; + long llimgWidth = LLimg.width; + + Eigen::MatrixXd imglonArr = LLimg.getData(0, 0, llimgheight, llimgWidth, 1); + Eigen::MatrixXd imglatArr = LLimg.getData(0, 0, llimgheight, llimgWidth, 2); + Eigen::MatrixXd demArr = demimg.getData(0, 0, demimg.height, demimg.width, 1); + + Eigen::MatrixXd outRArr = imglonArr.array() * 0; + + LLRimg.saveImage(imglonArr, 0, 0, 1); + LLRimg.saveImage(imglatArr, 0, 0, 2); + + + for (long i = 0; i < llimgheight; i++) { + for (long j = 0; j < llimgWidth; j++) { + double lon = imglonArr(i, j); + double lat = imglatArr(i, j); + Landpoint point = demimg.getRow_Col(lon, lat); + + if (point.lon<1 || point.lon>demimg.width - 2 || point.lat < 1 || point.lat - 2) { + continue; + } + else {} + + Landpoint p0, p11, p21, p12, p22; + + p0.lon = point.lon; + p0.lat = point.lat; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + p11.ati = demArr(long(p11.lat), long(p11.lon)); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + p12.ati = demArr(long(p12.lat), long(p12.lon)); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + p21.ati = demArr(long(p21.lat), long(p21.lon)); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + p22.ati = demArr(long(p22.lat), long(p22.lon)); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); + outRArr(i, j) = p0.ati; + + } + } + + LLRimg.saveImage(outRArr, 0, 0, 3); + + return; +} + +void RangeLooktableLLA_2_RangeLooktableXYZ(QString LLAPath, QString outXYZPath) +{ + + gdalImage LLAimg(LLAPath); + gdalImage xyzimg = CreategdalImageDouble(outXYZPath, LLAimg.height, LLAimg.width, 3, true, true); + + long llimgheight = LLAimg.height; + long llimgWidth = LLAimg.width; + + Eigen::MatrixXd lonArr = LLAimg.getData(0, 0, llimgheight, llimgWidth, 1); + Eigen::MatrixXd latArr = LLAimg.getData(0, 0, llimgheight, llimgWidth, 2); + Eigen::MatrixXd atiArr = LLAimg.getData(0, 0, llimgheight, llimgWidth, 3); + + // ʹLLAץΪXYZ + Eigen::MatrixXd xArr = lonArr.array() * 0; + Eigen::MatrixXd yArr = lonArr.array() * 0; + Eigen::MatrixXd zArr = lonArr.array() * 0; + + + + for (long i = 0; i < llimgheight; i++) { + for (long j = 0; j < llimgWidth; j++) { + double lon = lonArr(i, j); + double lat = latArr(i, j); + double ati = atiArr(i, j); + Landpoint p{ lon,lat,ati }; + Landpoint XYZP=LLA2XYZ(p); + + xArr(i, j) = XYZP.lon; + yArr(i, j) = XYZP.lat; + zArr(i, j) = XYZP.ati; + + + } + } + + xyzimg.saveImage(xArr, 0, 0, 1); + xyzimg.saveImage(yArr, 0, 0, 2); + xyzimg.saveImage(zArr, 0, 0, 3); + + return; +} + diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h index b3a0be9..bf329ae 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h @@ -17,4 +17,10 @@ int ReflectTable_WGS2Range(QString dem_rc_path, QString outOriSimTiffPath, QStr int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePath, QString L1AEchoDataPath); + +void InterpLookTableRfromDEM(QString lonlatPath, QString DEMPath, QString outllrpath); + +void RangeLooktableLLA_2_RangeLooktableXYZ(QString LLAPath, QString outXYZPath); + + #endif diff --git a/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.cpp b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.cpp new file mode 100644 index 0000000..09b37cd --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.cpp @@ -0,0 +1,114 @@ +#include "QL1ASARProcessDialog.h" +#include "ui_QL1ASARProcessDialog.h" +#include "BaseConstVariable.h" +#include "BaseTool.h" +#include "RasterToolBase.h" +#include "LogInfoCls.h" +#include +#include +#include "ImageNetOperator.h" +#include "ImageOperatorBase.h" + +QL1ASARProcessDialog::QL1ASARProcessDialog(QWidget *parent) + : QDialog(parent) + ,ui(new Ui::QL1ASARProcessDialogClass) +{ + ui->setupUi(this); + + + connect(ui->pushButtonL1BSelect, SIGNAL(clicked()), this, SLOT(onpushButtonL1BSelect_clicked())); + connect(ui->pushButtonL1ASelect, SIGNAL(clicked()), this, SLOT(onpushButtonL1ASelect_clicked())); + connect(ui->pushButtonS1ASelect, SIGNAL(clicked()), this, SLOT(onpushButtonS1ASelect_clicked())); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbuttonBox_accepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbuttonBox_rejected())); + + + + +} + +QL1ASARProcessDialog::~QL1ASARProcessDialog() +{ + + + +} + +void QL1ASARProcessDialog::onpushButtonL1BSelect_clicked() +{ + + QString fileNames = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡL1Bļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditL1ADataPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } + +} + +void QL1ASARProcessDialog::onpushButtonL1ASelect_clicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡL1Aļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditL1ADataPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QL1ASARProcessDialog::onpushButtonS1ASelect_clicked() +{ + QString fileNames = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡбƷļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineSlAPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QL1ASARProcessDialog::onbuttonBox_accepted() +{ + QString l1arasterpath = ui->lineEditL1ADataPath->text(); + QString s1arasterpath = ui->lineSlAPath->text(); + QString l1brasterpath = ui->lineEditL1BDataPath->text(); + + long nlaz = ui->spinBoxLNAz->value(); + long nlra = ui->spinBoxLNRa->value(); + + qDebug() << "бิƷ ת бȲƷ"; + Complex2AmpRaster(l1arasterpath, s1arasterpath); + + qDebug() << "бȲƷ ת бȲƷ"; + MultiLookRaster(s1arasterpath, l1brasterpath, nlaz, nlra); + + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"Ӵ")); +} + +void QL1ASARProcessDialog::onbuttonBox_rejected() +{ + this->close(); +} diff --git a/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.h b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.h new file mode 100644 index 0000000..3e27297 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.h @@ -0,0 +1,30 @@ +#pragma once + +#include + + +namespace Ui { + class QL1ASARProcessDialogClass; + +}; + +class QL1ASARProcessDialog : public QDialog +{ + Q_OBJECT + +public: + QL1ASARProcessDialog(QWidget *parent = nullptr); + ~QL1ASARProcessDialog(); + + +public slots: + + void onpushButtonL1BSelect_clicked(); + void onpushButtonL1ASelect_clicked(); + void onpushButtonS1ASelect_clicked(); + void onbuttonBox_accepted(); + void onbuttonBox_rejected(); + +private: + Ui::QL1ASARProcessDialogClass* ui; +}; diff --git a/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.ui b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.ui new file mode 100644 index 0000000..b3957fd --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.ui @@ -0,0 +1,232 @@ + + + QL1ASARProcessDialogClass + + + + 0 + 0 + 475 + 354 + + + + QL1ASARProcessDialog + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 0 + 30 + + + + 单视振幅产品: + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + L1B: + + + + + + + + 0 + 30 + + + + L1A产品: + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + + + + + + + + 多视参数 + + + + + + + 0 + 30 + + + + + 100 + 16777215 + + + + 方位向视数: + + + + + + + + 0 + 30 + + + + + + + + + 0 + 30 + + + + + 100 + 16777215 + + + + 方位向视数: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.cpp b/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.cpp new file mode 100644 index 0000000..4fbc603 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.cpp @@ -0,0 +1,124 @@ +#include "QLonLatInterpAtiFromDEM.h" +#include "ui_QLonLatInterpAtiFromDEM.h" +#include "BaseConstVariable.h" +#include "BaseTool.h" +#include "RasterToolBase.h" +#include "LogInfoCls.h" +#include +#include +#include "ImageNetOperator.h" + +QLonLatInterpAtiFromDEM::QLonLatInterpAtiFromDEM(QWidget *parent) + : QDialog(parent) + ,ui(new Ui::QLonLatInterpAtiFromDEMClass) +{ + ui->setupUi(this); + + connect(ui->pushButtonLonLatRasterSelect, SIGNAL(clicked()), this, SLOT(onpushButtonLonLatRasterSelect_clicked())); + connect(ui->pushButtonDEMRasterSelect, SIGNAL(clicked()), this, SLOT(onpushButtonDEMRasterSelect_clicked())); + connect(ui->pushButtonLLARasterSelect, SIGNAL(clicked()), this, SLOT(onpushButtonLLARasterSelect_clicked())); + connect(ui->pushButtonXYZRasterSelect, SIGNAL(clicked()), this, SLOT(onpushButtonXYZRasterSelect_clicked())); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbuttonBox_accepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbuttonBox_rejected())); + + +} + +QLonLatInterpAtiFromDEM::~QLonLatInterpAtiFromDEM() +{ + +} + +void QLonLatInterpAtiFromDEM::onpushButtonLonLatRasterSelect_clicked() +{ + + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditLonLatRasterPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } + +} + +void QLonLatInterpAtiFromDEM::onpushButtonDEMRasterSelect_clicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡDEMļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditDEMRasterPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QLonLatInterpAtiFromDEM::onpushButtonLLARasterSelect_clicked() +{ + QString fileNames = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡ񱣴ļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditLLARasterPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QLonLatInterpAtiFromDEM::onpushButtonXYZRasterSelect_clicked() +{ + QString fileNames = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡתļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditXYZRasterPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QLonLatInterpAtiFromDEM::onbuttonBox_accepted() +{ + QString llrasterpath = ui->lineEditLonLatRasterPath->text(); + QString demrasterpath = ui->lineEditDEMRasterPath->text(); + QString llarasterpath = ui->lineEditLLARasterPath->text(); + QString xyzrasterpath = ui->lineEditXYZRasterPath->text(); + + qDebug() << "DEM߳С"; + InterpLookTableRfromDEM(llrasterpath, demrasterpath, llarasterpath); + qDebug() << "γתΪXYZС"; + RangeLooktableLLA_2_RangeLooktableXYZ(llarasterpath, xyzrasterpath); + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"")); +} + +void QLonLatInterpAtiFromDEM::onbuttonBox_rejected() +{ + this->close(); +} + diff --git a/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.h b/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.h new file mode 100644 index 0000000..b728ef8 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +namespace Ui { + class QLonLatInterpAtiFromDEMClass; +} + +class QLonLatInterpAtiFromDEM : public QDialog +{ + Q_OBJECT + +public: + QLonLatInterpAtiFromDEM(QWidget *parent = nullptr); + ~QLonLatInterpAtiFromDEM(); + + +public slots: + void onpushButtonLonLatRasterSelect_clicked(); + void onpushButtonDEMRasterSelect_clicked(); + void onpushButtonLLARasterSelect_clicked(); + void onpushButtonXYZRasterSelect_clicked(); + void onbuttonBox_accepted(); + void onbuttonBox_rejected(); + + +private: + Ui::QLonLatInterpAtiFromDEMClass* ui; +}; diff --git a/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.ui b/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.ui new file mode 100644 index 0000000..4a31eca --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.ui @@ -0,0 +1,191 @@ + + + QLonLatInterpAtiFromDEMClass + + + + 0 + 0 + 600 + 400 + + + + QLonLatInterpAtiFromDEM + + + + + + + 0 + 30 + + + + 经纬度数据矩阵: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 待采样DEM: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 采样矩阵(LLA): + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 采样矩阵(XYZ): + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index 0d16cc6..0d01313 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -13,6 +13,8 @@ #include "QLookTableResampleFromWGS84ToRange.h" #include "QSARSimulationComplexEchoDataDialog.h" #include "QSimulationBPImageMultiProduction.h" +#include "QLonLatInterpAtiFromDEM.h" +#include "QL1ASARProcessDialog.h" void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox) @@ -31,6 +33,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QLookTableResampleFromWGS84ToRangeToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QSARSimulationComplexEchoDataDialogToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QSimulationBPImageMultiProductionToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QLonLatInterpAtiFromDEMToolButton(toolbox)); } @@ -279,3 +282,37 @@ void QSimulationBPImageMultiProductionToolButton::run() QSimulationBPImageMultiProduction* dialog = new QSimulationBPImageMultiProduction; dialog->show(); } + +QLonLatInterpAtiFromDEMToolButton::QLonLatInterpAtiFromDEMToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"񹤾߿"); + this->toolname = QString(u8"бƽ"); +} + +QLonLatInterpAtiFromDEMToolButton::~QLonLatInterpAtiFromDEMToolButton() +{ +} + +void QLonLatInterpAtiFromDEMToolButton::run() +{ + QLonLatInterpAtiFromDEM* dialog = new QLonLatInterpAtiFromDEM; + dialog->show(); +} + +QL1ASARProcessDialogToolButton::QL1ASARProcessDialogToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"񹤾߿"); + this->toolname = QString(u8"L1AƷ"); +} + +QL1ASARProcessDialogToolButton::~QL1ASARProcessDialogToolButton() +{ +} + +void QL1ASARProcessDialogToolButton::run() +{ + QL1ASARProcessDialog* dialog = new QL1ASARProcessDialog; + dialog->show(); +} diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.h b/Toolbox/SimulationSARTool/SimulationSARTool.h index 011b236..9c20a47 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.h +++ b/Toolbox/SimulationSARTool/SimulationSARTool.h @@ -175,3 +175,31 @@ public: }; + + + + +class SIMULATIONSARTOOL_EXPORT QLonLatInterpAtiFromDEMToolButton : public QToolAbstract { + Q_OBJECT +public: + QLonLatInterpAtiFromDEMToolButton(QWidget* parent = nullptr); + ~QLonLatInterpAtiFromDEMToolButton(); +public: + virtual void run() override; + +}; + + + + + +class SIMULATIONSARTOOL_EXPORT QL1ASARProcessDialogToolButton : public QToolAbstract { + Q_OBJECT +public: + QL1ASARProcessDialogToolButton(QWidget* parent = nullptr); + ~QL1ASARProcessDialogToolButton(); +public: + virtual void run() override; + +}; + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 62fb8ce..e4bdf9f 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -221,6 +221,8 @@ + + @@ -256,6 +258,8 @@ + + @@ -295,6 +299,8 @@ + + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index b8510fa..e32b42e 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -157,6 +157,12 @@ SARImage + + SARImage + + + SARImage + @@ -207,6 +213,12 @@ SARImage + + SARImage + + + SARImage + @@ -260,6 +272,12 @@ SARImage + + SARImage + + + SARImage + From baa5f446a6280b03d01d78e75bc19bfe9e34cdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Thu, 10 Apr 2025 18:40:27 +0800 Subject: [PATCH 82/94] =?UTF-8?q?=E5=9C=A8=E5=B7=A5=E5=85=B7=E7=AE=B1?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0L1B=E4=BA=A7=E5=93=81=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/SimulationSARTool/SimulationSARTool.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index 0d01313..438dd61 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -34,6 +34,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QSARSimulationComplexEchoDataDialogToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QSimulationBPImageMultiProductionToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QLonLatInterpAtiFromDEMToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QL1ASARProcessDialogToolButton(toolbox)); } @@ -304,7 +305,7 @@ QL1ASARProcessDialogToolButton::QL1ASARProcessDialogToolButton(QWidget* parent) { this->toolPath = QVector(0); this->toolPath.push_back(u8"񹤾߿"); - this->toolname = QString(u8"L1AƷ"); + this->toolname = QString(u8"L1BƷ"); } QL1ASARProcessDialogToolButton::~QL1ASARProcessDialogToolButton() From 005abdb827b5efd5b382a482d5ef5c4f4b249144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Thu, 10 Apr 2025 19:15:14 +0800 Subject: [PATCH 83/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0vrt=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BD=AC=20envidata=E6=A0=BC=E5=BC=8F=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/BaseToolbox/BaseToolbox.cpp | 21 ++- Toolbox/BaseToolbox/BaseToolbox.h | 18 ++- Toolbox/BaseToolbox/BaseToolbox.vcxproj | 3 + .../BaseToolbox/BaseToolbox.vcxproj.filters | 9 ++ .../BaseToolbox/RasterVRT2ENVIdataDialog.cpp | 78 +++++++++++ .../BaseToolbox/RasterVRT2ENVIdataDialog.h | 26 ++++ .../BaseToolbox/RasterVRT2ENVIdataDialog.ui | 126 ++++++++++++++++++ 7 files changed, 279 insertions(+), 2 deletions(-) create mode 100644 Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.cpp create mode 100644 Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.h create mode 100644 Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.ui diff --git a/Toolbox/BaseToolbox/BaseToolbox.cpp b/Toolbox/BaseToolbox/BaseToolbox.cpp index 1bad4fa..8d35a95 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox.cpp @@ -13,6 +13,7 @@ #include "QResampleRefrenceRaster.h" #include "QtLookTableCorrectOffsetDialog.h" #include "QtCreateGPSPointsDialog.h" +#include "RasterVRT2ENVIdataDialog.h" GF3ImportDataToolButton::GF3ImportDataToolButton(QWidget* parent) :QToolAbstract(parent) { @@ -115,6 +116,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QResampleRefrenceRasterToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QLookTableCorrectOffsetToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QCreateGPSPointsToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new RasterVRT2ENVIdataDialogToolButton(toolbox)); } QDEMResampleDialogToolButton::QDEMResampleDialogToolButton(QWidget* parent) @@ -215,4 +217,21 @@ void QCreateGPSPointsToolButton::excute() { QtCreateGPSPointsDialog* dialog = new QtCreateGPSPointsDialog; dialog->show(); -} \ No newline at end of file +} + +RasterVRT2ENVIdataDialogToolButton::RasterVRT2ENVIdataDialogToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8""); + this->toolname = QString(u8"vrtļתenviݸʽ"); +} + +RasterVRT2ENVIdataDialogToolButton::~RasterVRT2ENVIdataDialogToolButton() +{ +} + +void RasterVRT2ENVIdataDialogToolButton::run() +{ + RasterVRT2ENVIdataDialog* dialog = new RasterVRT2ENVIdataDialog; + dialog->show(); +} diff --git a/Toolbox/BaseToolbox/BaseToolbox.h b/Toolbox/BaseToolbox/BaseToolbox.h index 5c15ea7..42a024b 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.h +++ b/Toolbox/BaseToolbox/BaseToolbox.h @@ -10,6 +10,8 @@ namespace LAMPMainWidget { class ToolBoxWidget; +extern "C" BASETOOLBOX_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); + class BASETOOLBOX_EXPORT GF3ImportDataToolButton : public QToolAbstract { Q_OBJECT public: @@ -132,4 +134,18 @@ public slots: }; -extern "C" BASETOOLBOX_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox); + + + + +class BASETOOLBOX_EXPORT RasterVRT2ENVIdataDialogToolButton : public QToolAbstract { + Q_OBJECT +public: + RasterVRT2ENVIdataDialogToolButton(QWidget* parent = nullptr); + ~RasterVRT2ENVIdataDialogToolButton(); +public : + virtual void run() override; + +}; + + diff --git a/Toolbox/BaseToolbox/BaseToolbox.vcxproj b/Toolbox/BaseToolbox/BaseToolbox.vcxproj index 5ec3f82..699771e 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.vcxproj +++ b/Toolbox/BaseToolbox/BaseToolbox.vcxproj @@ -207,6 +207,7 @@ + @@ -225,6 +226,7 @@ + @@ -246,6 +248,7 @@ + diff --git a/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters b/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters index 03e37b6..0eb5ad3 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters +++ b/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters @@ -106,6 +106,9 @@ BaseToolbox + + BaseToolbox + @@ -147,6 +150,9 @@ BaseToolbox + + BaseToolbox + @@ -185,5 +191,8 @@ BaseToolbox + + BaseToolbox + \ No newline at end of file diff --git a/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.cpp b/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.cpp new file mode 100644 index 0000000..42e2ed3 --- /dev/null +++ b/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.cpp @@ -0,0 +1,78 @@ +#include "RasterVRT2ENVIdataDialog.h" +#include "ui_RasterVRT2ENVIdataDialog.h" +#include "BaseConstVariable.h" +#include "BaseTool.h" +#include "RasterToolBase.h" +#include "LogInfoCls.h" +#include +#include +#include "ImageNetOperator.h" +#include "ImageOperatorBase.h" + +RasterVRT2ENVIdataDialog::RasterVRT2ENVIdataDialog(QWidget *parent) + : QDialog(parent) + ,ui(new Ui::RasterVRT2ENVIdataDialogClass) +{ + ui->setupUi(this); + + connect(ui->pushButtonVRTSelect, SIGNAL(clicked()), this, SLOT(onpushButtonVRTSelect_clicked())); + connect(ui->pushButtonENVIDatSelect, SIGNAL(clicked()), this, SLOT(onpushButtonENVIDatSelect_clicked())); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbuttonBox_accepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbuttonBox_rejected())); + +} + +RasterVRT2ENVIdataDialog::~RasterVRT2ENVIdataDialog() +{} + +void RasterVRT2ENVIdataDialog::onpushButtonVRTSelect_clicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡL1Bļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditVRTPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void RasterVRT2ENVIdataDialog::onpushButtonENVIDatSelect_clicked() +{ + QString fileNames = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡL1Bļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditENVIDatPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void RasterVRT2ENVIdataDialog::onbuttonBox_accepted() +{ + QString vrtrasterpath = ui->lineEditVRTPath->text(); + QString envidatapath = ui->lineEditENVIDatPath->text(); + + ConvertVrtToEnvi(vrtrasterpath, envidatapath); + + + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"")); +} + +void RasterVRT2ENVIdataDialog::onbuttonBox_rejected() +{ + this->close(); +} diff --git a/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.h b/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.h new file mode 100644 index 0000000..b4123c8 --- /dev/null +++ b/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace Ui { + class RasterVRT2ENVIdataDialogClass; +} + + +class RasterVRT2ENVIdataDialog : public QDialog +{ + Q_OBJECT + +public: + RasterVRT2ENVIdataDialog(QWidget *parent = nullptr); + ~RasterVRT2ENVIdataDialog(); + + +public slots: + void onpushButtonVRTSelect_clicked(); + void onpushButtonENVIDatSelect_clicked(); + void onbuttonBox_accepted(); + void onbuttonBox_rejected(); +private: + Ui::RasterVRT2ENVIdataDialogClass* ui; +}; diff --git a/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.ui b/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.ui new file mode 100644 index 0000000..9e76517 --- /dev/null +++ b/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.ui @@ -0,0 +1,126 @@ + + + RasterVRT2ENVIdataDialogClass + + + + 0 + 0 + 396 + 156 + + + + RasterVRT2ENVIdataDialog + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 0 + 30 + + + + vrt文件地址: + + + + + + + + 0 + 30 + + + + 输出dat地址: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + From b799682817ba654eec647553beae33357933907a Mon Sep 17 00:00:00 2001 From: chenzenghui <3045316072@qq.com> Date: Thu, 10 Apr 2025 20:51:54 +0800 Subject: [PATCH 84/94] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dvrt=E8=BD=ACenvi=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.cpp b/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.cpp index 42e2ed3..85964ab 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/RasterVRT2ENVIdataDialog.cpp @@ -6,7 +6,6 @@ #include "LogInfoCls.h" #include #include -#include "ImageNetOperator.h" #include "ImageOperatorBase.h" RasterVRT2ENVIdataDialog::RasterVRT2ENVIdataDialog(QWidget *parent) @@ -47,7 +46,7 @@ void RasterVRT2ENVIdataDialog::onpushButtonENVIDatSelect_clicked() { QString fileNames = QFileDialog::getSaveFileName( this, // - tr(u8"ѡL1Bļ"), // + tr(u8"ѡENVIDataļ"), // QString(), // Ĭ· tr(ENVI_FILE_FORMAT_FILTER) // ļ ); From 115e11b56824f74bb51d3d79965f31b82c16abbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Thu, 10 Apr 2025 21:28:06 +0800 Subject: [PATCH 85/94] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.ui | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.ui b/RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.ui index af85019..2a2bc0c 100644 --- a/RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.ui +++ b/RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.ui @@ -85,7 +85,7 @@ 0 0 906 - 23 + 22 @@ -117,6 +117,7 @@ 工具 + @@ -513,6 +514,11 @@ p, li { white-space: pre-wrap; } 飞机 + + + 释放影像文件 + + From 609e140bd912090f08876173acf698c0d3fb8fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Fri, 11 Apr 2025 10:57:49 +0800 Subject: [PATCH 86/94] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=86=E6=98=BE?= =?UTF-8?q?=E5=AD=98=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SimulationSAR/BPBasic0_CUDA.cu | 13 ++++++------- .../SimulationSAR/TBPImageAlgCls.cpp | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu index f88f3f7..46c7d37 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu @@ -65,16 +65,16 @@ __global__ void processPulseKernel( ) { // - long long idx = blockIdx.x * blockDim.x + threadIdx.x; - long long pixelcount = nx * ny; - if (idx >= pixelcount) return; + int64_t idx = int64_t(blockIdx.x) * int64_t(blockDim.x) + int64_t(threadIdx.x); + int64_t pixelcount = int64_t(nx) * int64_t(ny); + if (idx >= pixelcount) { return; } //printf("processPulseKernel start!!\n"); //if (x >= nx || y >= ny) return; //int idx = x * ny + y; - + double dx = AntX - x_mat[idx]; double dy = AntY - y_mat[idx]; double dz = AntZ - z_mat[idx]; @@ -169,13 +169,12 @@ void bpBasic0CUDA(GPUDATA& data, int flag,double* h_R) { printfinfo("fft finished!!\n"); // ͼؽ - double r_start = data.r_vec[0]; double dr = (data.r_vec[data.Nfft - 1] - r_start) / (data.Nfft - 1); printfinfo("dr = %f\n",dr); - long pixelcount = data.nx* data.ny; - long grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; + int64_t pixelcount = int64_t(data.nx)* int64_t(data.ny); + int64_t grid_size = (pixelcount + BLOCK_SIZE - 1) / BLOCK_SIZE; printfinfo("grid finished!!\n"); //double* d_R = (double*)mallocCUDADevice(sizeof(double) * data.nx * data.ny); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp index 6d50619..235ad8c 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/TBPImageAlgCls.cpp @@ -119,7 +119,7 @@ ErrorCode TBPImageAlgCls::ProcessGPU() size_t img_rowCont = L1ds->getrowCount(); size_t img_colCont = L1ds->getcolCount(); - size_t block_imgRowCount = Memory1GB / img_colCont / 8 / 3 * 1;// 4GB-- 可以分配内存 + size_t block_imgRowCount = Memory1GB / img_colCont / 8 / 3 * 12;// 4GB-- 可以分配内存 gdalImage demgridimg(imgXYZPath); gdalImageComplex im_finalds(outimgDataPath); @@ -310,7 +310,7 @@ void TBPImageAlgCls::EchoFreqToTime() gdalImageComplex outTimeEchoImg = CreategdalImageComplexNoProj(this->TimeEchoDataPath, this->TimeEchoRowCount, this->TimeEchoColCount, 1); // 分块 - long echoBlockline = Memory1GB / 8 / 2 / outColCount * 3; //1GB + long echoBlockline = Memory1GB / 8 / 2 / outColCount *2; //1GB echoBlockline = echoBlockline < 1 ? 1 : echoBlockline; From 0a1497ac5e3e5bac2591a8575c6b41212b5d3d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Fri, 11 Apr 2025 11:29:12 +0800 Subject: [PATCH 87/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/BaseTool/ImageOperatorBase.h | 2 +- BaseCommonLibrary/ImageOperatorFuntion.cpp | 6 ++++++ .../RasterMainWidget/RasterMainWidget.cpp | 9 +++++++-- RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.h | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h index 2f52328..633dd9e 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h @@ -328,7 +328,7 @@ ErrorCode BASECONSTVARIABLEAPI Complex2AmpRaster(QString inComplexPath, QString ErrorCode BASECONSTVARIABLEAPI ResampleDEM(QString indemPath, QString outdemPath, double gridx, double gridy); - +void BASECONSTVARIABLEAPI CloseAllGDALRaster(); diff --git a/BaseCommonLibrary/ImageOperatorFuntion.cpp b/BaseCommonLibrary/ImageOperatorFuntion.cpp index 6313329..2397a00 100644 --- a/BaseCommonLibrary/ImageOperatorFuntion.cpp +++ b/BaseCommonLibrary/ImageOperatorFuntion.cpp @@ -1665,6 +1665,12 @@ ErrorCode ResampleDEM(QString indemPath, QString outdemPath, double gridx, doubl } } +void BASECONSTVARIABLEAPI CloseAllGDALRaster() +{ + GDALDestroyDriverManager(); + return ; +} + ErrorCode Complex2AmpRaster(QString inComplexPath, QString outRasterPath) diff --git a/RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.cpp b/RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.cpp index eb4f02a..d985f06 100644 --- a/RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.cpp +++ b/RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.cpp @@ -14,7 +14,7 @@ #include "FileOperator.h" #include "RasterWidgetMessageShow.h" - +#include "ImageOperatorBase.h" #pragma execution_character_set("utf-8") @@ -59,7 +59,7 @@ RasterMainWidget::RasterMainWidget(QWidget *parent) //mUi->layerList->setCurrentItem(mLayerList.first()); - + connect(mUi->actioncloseAllRasterFile, SIGNAL(triggered()), this, SLOT(onactioncloseAllRasterFile_triggered())); } @@ -341,6 +341,11 @@ void RasterMainWidget::on_addPlaneaction_triggered() mMapConvas->selectTool("addplane_tool"); } +void RasterMainWidget::onactioncloseAllRasterFile_triggered() +{ + CloseAllGDALRaster(); +} + QTableWidget* RasterMainWidget::getTaskTable() { return this->mUi->taskTable; diff --git a/RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.h b/RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.h index a64eb49..f4f3316 100644 --- a/RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.h +++ b/RasterMainWidgetGUI/RasterMainWidget/RasterMainWidget.h @@ -77,7 +77,7 @@ namespace LAMPMainWidget { private slots: void on_drawArea_triggered(); void on_addPlaneaction_triggered(); - + void onactioncloseAllRasterFile_triggered(); private: Ui::RasterMainWidget* mUi; MapCanvas* mMapConvas; From e3bcfe3e9825117ea7cd70b6fb88f5db3a57f9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Fri, 11 Apr 2025 17:39:55 +0800 Subject: [PATCH 88/94] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=87=87=E6=A0=B7?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SARImage/ImageNetOperator.cpp | 82 +++++++++++++++++++ .../SARImage/ImageNetOperator.h | 4 +- .../QSARSimulationComplexEchoDataDialog.cpp | 32 +++++++- .../QSARSimulationComplexEchoDataDialog.ui | 4 +- 4 files changed, 115 insertions(+), 7 deletions(-) diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 334bc9c..cd5078d 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -906,6 +906,88 @@ int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePa } +int ResampleRangeDataFromGeoImage(QString geodataPath, QString RangeLooktablePath, QString RangeDataPath) +{ + gdalImage echodata(geodataPath); + gdalImage looktable(RangeLooktablePath); + gdalImage l1adata(RangeDataPath); + Eigen::MatrixXd echoArr = echodata.getData(0, 0, echodata.height, echodata.width, 1); + + long blockHeight = Memory1GB / looktable.width / 8 * 2; + + for (long startRow = 0; startRow < looktable.height; startRow = startRow + blockHeight) { + printf("\rGEC: process:%f precent\t\t\t", startRow * 100.0 / looktable.height); + blockHeight = blockHeight + startRow < looktable.height ? blockHeight : looktable.height - startRow; + Eigen::MatrixXd imglonArr = looktable.getData(startRow, 0, blockHeight, looktable.width, 1); + Eigen::MatrixXd imglatArr = looktable.getData(startRow, 0, blockHeight, looktable.width, 2); + Eigen::MatrixXd l1aArr = l1adata.getData(0, 0, blockHeight, l1adata.width, 1); + l1aArr = l1aArr.array() * 0; + + long imgheight = blockHeight; + long imgwidth = looktable.width; +#pragma omp parallel for + for (long i = 0; i < imgheight; i++) { + + for (long j = 0; j < imgwidth; j++) { + double lon = imglonArr(i, j); + double lat = imglatArr(i, j); + Landpoint point = echodata.getRow_Col(lon, lat); + + if (point.lon<1 || point.lon>echodata.width - 2 || point.lat < 1 || point.lat >echodata.height - 2) { + continue; + } + else {} + { + Landpoint p0, p11, p21, p12, p22; + + p0.lon = point.lon; + p0.lat = point.lat; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + p11.ati = echoArr(long(p11.lat), long(p11.lon)); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + p12.ati = echoArr(long(p12.lat), long(p12.lon)); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + p21.ati = echoArr(long(p21.lat), long(p21.lon)); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + p22.ati = echoArr(long(p22.lat), long(p22.lon)); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); + l1aArr(i, j)=p0.ati; + } + } + } + + l1adata.saveImage(l1aArr, startRow, 0, 1); + } + + + + return 0; +} + void InterpLookTableRfromDEM(QString lonlatPath, QString DEMPath, QString outllrpath) { gdalImage LLimg(lonlatPath); diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h index bf329ae..59f5920 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h @@ -15,7 +15,9 @@ void InterploateClipAtiByRefDEM(QString ImageLLPath, QString& ImageDEMPath, QStr void InterploateAtiByRefDEM(QString& ImageLLPath, QString& ImageDEMPath, QString& outImageLLAPath, QString& InEchoGPSDataPath); int ReflectTable_WGS2Range(QString dem_rc_path, QString outOriSimTiffPath, QString ori_sim_count_tiffPath, long OriHeight, long OriWidth); -int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePath, QString L1AEchoDataPath); +int ResampleEChoDataFromGeoEcho(QString L2complexechodataPath, QString RangeLooktablePath, QString L1AEchoDataPath); + +int ResampleRangeDataFromGeoImage(QString geodataPath, QString RangeLooktablePath, QString RangeDataPath); void InterpLookTableRfromDEM(QString lonlatPath, QString DEMPath, QString outllrpath); diff --git a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp index 39648cb..5082835 100644 --- a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.cpp @@ -6,6 +6,8 @@ #include "BaseTool.h" #include "ImageNetOperator.h" #include +#include "FileOperator.h" +#include "ImageOperatorBase.h" QSARSimulationComplexEchoDataDialog::QSARSimulationComplexEchoDataDialog(QWidget *parent) @@ -33,7 +35,7 @@ void QSARSimulationComplexEchoDataDialog::onpushButtonEchoDataSelect_clicked() { QString fileNames = QFileDialog::getOpenFileName( this, // - tr(u8"ѡL1Aزļ"), // + tr(u8"ѡؾļ"), // QString(), // Ĭ· tr(ENVI_FILE_FORMAT_FILTER) // ļ ); @@ -69,7 +71,7 @@ void QSARSimulationComplexEchoDataDialog::onpushButtonL1AEchoDataSelect_clicked( { QString fileNames = QFileDialog::getSaveFileName( this, // - tr(u8"ѡL1Aزļ"), // + tr(u8"ѡбļ"), // QString(), // Ĭ· tr(ENVI_FILE_FORMAT_FILTER) // ļ ); @@ -89,9 +91,31 @@ void QSARSimulationComplexEchoDataDialog::onbuttonBox_accepted() QString RangelookTablePath = this->ui->lineEditLookTablePath->text().trimmed(); QString l1AEchoDataPath = this->ui->lineEditL1AEchoDataPath->text().trimmed(); + if (isExists(echoDataPath) && isExists(RangelookTablePath)) { + gdalImage echoData(echoDataPath); + gdalImage RangelookTable(RangelookTablePath); + if (echoData.getDataType() == GDT_CFloat32 + ||echoData.getDataType()==GDT_CFloat64 + || echoData.getDataType() == GDT_CInt16 + || echoData.getDataType()==GDT_CInt32 + ) { - ResampleEChoDataFromGeoEcho(echoDataPath, RangelookTablePath, l1AEchoDataPath); - QMessageBox::information(this, tr(u8"ʾ"), tr(u8"ûѡκļ")); + CreategdalImageComplex(l1AEchoDataPath, RangelookTable.height, RangelookTable.width,1, RangelookTable.gt, RangelookTable.projection, true, true); + + + ResampleEChoDataFromGeoEcho(echoDataPath, RangelookTablePath, l1AEchoDataPath); + } + else { + CreategdalImage(l1AEchoDataPath, RangelookTable.height, RangelookTable.width, 1, RangelookTable.gt, RangelookTable.projection, true, true); + ResampleRangeDataFromGeoImage(echoDataPath, RangelookTablePath, l1AEchoDataPath); + } + + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"")); + } + else { + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"ûѡκļ")); + } + } void QSARSimulationComplexEchoDataDialog::onbuttonBox_rejected() diff --git a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.ui b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.ui index ceed9c6..6e3e09b 100644 --- a/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.ui +++ b/Toolbox/SimulationSARTool/SARImage/QSARSimulationComplexEchoDataDialog.ui @@ -23,7 +23,7 @@ - 成像文件: + 地距文件: @@ -98,7 +98,7 @@ - L1A回波: + 斜距文件: From 9fd7bab1f364998cd50d82b733ba7b35196e60e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 14 Apr 2025 17:54:55 +0800 Subject: [PATCH 89/94] =?UTF-8?q?=E4=BF=AE=E8=A1=A5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/gdalImageComplexOperator.cpp | 3 ++- BaseCommonLibrary/ImageOperatorFuntion.cpp | 8 +++----- .../SARImage/QL1ASARProcessDialog.cpp | 12 +++++------ .../SimulationSAR/BPBasic0_CUDA.cu | 4 ++-- .../SimulationSAR/GPURFPC.cu | 7 +------ .../SimulationSAR/RFPCProcessCls.cpp | 20 +++++++++++++++++-- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp b/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp index 6676b66..7d0df86 100644 --- a/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp +++ b/BaseCommonLibrary/BaseTool/gdalImageComplexOperator.cpp @@ -293,7 +293,8 @@ Eigen::MatrixXcd gdalImageComplex::getDataComplex(int start_row, int start_col, // ȡݼĵһ GDALRasterBand* poBand; poBand = poDataset->GetRasterBand(1); - + 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; // ȡϢǸ int nXSize = cols_count; poBand->GetXSize(); int nYSize = rows_count; poBand->GetYSize(); diff --git a/BaseCommonLibrary/ImageOperatorFuntion.cpp b/BaseCommonLibrary/ImageOperatorFuntion.cpp index 2397a00..5154807 100644 --- a/BaseCommonLibrary/ImageOperatorFuntion.cpp +++ b/BaseCommonLibrary/ImageOperatorFuntion.cpp @@ -1680,18 +1680,16 @@ ErrorCode Complex2AmpRaster(QString inComplexPath, QString outRasterPath) long blocklines = Memory1GB * 2 / 8 / inimg.width; blocklines = blocklines < 100 ? 100 : blocklines; - Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); - Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); long startrow = 0; for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { - imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); - imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); + Eigen::MatrixXd imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); + Eigen::MatrixXcd imgArr = inimg.getDataComplex(startrow, 0, blocklines, inimg.width, 1); imgArrb1 = imgArr.array().abs(); ampimg.saveImage(imgArrb1, startrow, 0, 1); } - qDebug() << "影像写入到:" << outRasterPath; + qDebug() << u8"影像写入到:" << outRasterPath; return ErrorCode::SUCCESS; } diff --git a/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.cpp b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.cpp index 09b37cd..88338e9 100644 --- a/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.cpp +++ b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.cpp @@ -45,8 +45,8 @@ void QL1ASARProcessDialog::onpushButtonL1BSelect_clicked() ); // ûѡļ if (!fileNames.isEmpty()) { - QString message = "ѡļУ\n"; - this->ui->lineEditL1ADataPath->setText(fileNames); + QString message = u8"ѡļУ\n"; + this->ui->lineEditL1BDataPath->setText(fileNames); } else { QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); @@ -64,7 +64,7 @@ void QL1ASARProcessDialog::onpushButtonL1ASelect_clicked() ); // ûѡļ if (!fileNames.isEmpty()) { - QString message = "ѡļУ\n"; + QString message = u8"ѡļУ\n"; this->ui->lineEditL1ADataPath->setText(fileNames); } else { @@ -82,7 +82,7 @@ void QL1ASARProcessDialog::onpushButtonS1ASelect_clicked() ); // ûѡļ if (!fileNames.isEmpty()) { - QString message = "ѡļУ\n"; + QString message = u8"ѡļУ\n"; this->ui->lineSlAPath->setText(fileNames); } else { @@ -99,10 +99,10 @@ void QL1ASARProcessDialog::onbuttonBox_accepted() long nlaz = ui->spinBoxLNAz->value(); long nlra = ui->spinBoxLNRa->value(); - qDebug() << "бิƷ ת бȲƷ"; + qDebug() << u8"бิƷ ת бȲƷ"; Complex2AmpRaster(l1arasterpath, s1arasterpath); - qDebug() << "бȲƷ ת бȲƷ"; + qDebug() << u8"бȲƷ ת бȲƷ"; MultiLookRaster(s1arasterpath, l1brasterpath, nlaz, nlra); QMessageBox::information(this, tr(u8"ʾ"), tr(u8"Ӵ")); diff --git a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu index 46c7d37..045ebbd 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/BPBasic0_CUDA.cu @@ -109,8 +109,8 @@ __global__ void processPulseKernel( phCorr.y = rc_interp.x * sin_phase + rc_interp.y * cos_phase; // amp correction - phCorr.x = ampcorrect * phCorr.x; - phCorr.y = ampcorrect * phCorr.y; + //phCorr.x = ampcorrect * phCorr.x; + //phCorr.y = ampcorrect * phCorr.y; // Accumulate im_final[idx].x += phCorr.x; diff --git a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu index afd43d1..aa33c8a 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu +++ b/Toolbox/SimulationSARTool/SimulationSAR/GPURFPC.cu @@ -700,15 +700,10 @@ extern "C" void ProcessRFPCTask(RFPCTask& task, long devid, float* h_R, float* h ); PrintLasterError("CUDA_Kernel_Computer_echo"); cudaDeviceSynchronize(); - if ((sTi * 100.0 / task.targetnum) - process >= 10) { + if ((sTi * 100.0 / task.targetnum) - process >= 1) { process = sTi * 100.0 / task.targetnum; PRINT("device ID : %d , TargetID [%f]: %d / %d finished %d\n", devid, sTi * 100.0 / task.targetnum, sTi, task.targetnum, devid); } - - - - - } diff --git a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp index 160d4b1..e8ae0b6 100644 --- a/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp +++ b/Toolbox/SimulationSARTool/SimulationSAR/RFPCProcessCls.cpp @@ -929,6 +929,8 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU() { ErrorCode RFPCProcessCls::RFPCMainProcess_MultiGPU_NoAntPattern() { + + int num_devices = 0; cudaGetDeviceCount(&num_devices); PRINT("GPU Count : %d \n", num_devices); @@ -943,7 +945,11 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_MultiGPU_NoAntPattern() std::shared_ptr sateOirbtNodes = this->getSatelliteOribtNodes(prf_time, dt, antflag, imageStarttime); - + for (int devid = 0; devid < num_devices; devid++) { + printf("GPU ID: %d \n", devid); + printDeviceInfo(devid); + printf("----------------------------------------\n"); + } #pragma omp parallel for for (int devid = 0; devid < num_devices; devid++) { @@ -969,6 +975,16 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si std::map clssigmaParamsDict = this->SigmaDatabasePtr->getsigmaParams(polartype);; std::map clsCUDASigmaParamsDict; for (const auto& pair : clssigmaParamsDict) { + + if (abs(pair.second.p1)<1e-5&& + abs(pair.second.p2) < 1e-5 && + abs(pair.second.p3) < 1e-5 && + abs(pair.second.p4) < 1e-5 && + abs(pair.second.p5) < 1e-5 && + abs(pair.second.p6) < 1e-5) { + continue; + } + clsCUDASigmaParamsDict.insert(std::pair(pair.first, CUDASigmaParam{ float(pair.second.p1), @@ -994,7 +1010,7 @@ ErrorCode RFPCProcessCls::RFPCMainProcess_GPU_NoAntPattern(size_t startprfid, si gdalImage demlandcls(this->LandCoverPath);// 地表覆盖类型 gdalImage slpxyz(this->demsloperPath);// 地面坡向 - long allDemRow = Memory1MB/demxyz.width/8/3*6000; + long allDemRow = Memory1GB/demxyz.width/8/3*6; //allDemRow = allDemRow < demxyz.height ? allDemRow : demxyz.height; for(long demId=0;demId< demxyz.height;demId=demId+ allDemRow){ From d2ee22b0f196c47616df64a48f6d856647cdee3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Fri, 18 Apr 2025 03:30:28 +0800 Subject: [PATCH 90/94] =?UTF-8?q?=E4=BF=AE=E8=A1=A5=E9=AB=98=E5=88=86?= =?UTF-8?q?=E4=B8=89=E5=8F=B7=E6=96=87=E4=BB=B6=E8=AF=BB=E5=86=99=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseCommonLibrary/BaseTool/BaseTool.cpp | 73 +++++- BaseCommonLibrary/BaseTool/BaseTool.h | 18 +- BaseCommonLibrary/BaseTool/FileOperator.cpp | 3 +- BaseCommonLibrary/BaseTool/GeoOperator.cpp | 54 ++++- BaseCommonLibrary/BaseTool/GeoOperator.h | 20 ++ .../BaseTool/ImageOperatorBase.h | 2 +- .../BaseTool/SARSimulationImageL1.cpp | 110 ++++----- .../BaseTool/gdalImageOperator.cpp | 9 + BaseCommonLibrary/ImageOperatorFuntion.cpp | 10 +- .../GF3CalibrationAndGeocodingClass.cpp | 79 +++++-- .../BaseToolbox/BaseToolbox/GF3PSTNClass.cpp | 2 +- .../BaseToolbox/QComplex2AmpPhase.cpp | 11 +- .../BaseToolbox/QImportGF3StripL1ADataset.cpp | 7 +- .../BaseToolbox/QRDOrthProcessClass.cpp | 4 +- .../BaseToolbox/SatelliteGF3xmlParser.cpp | 217 ++++++++++-------- 15 files changed, 428 insertions(+), 191 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/BaseTool.cpp b/BaseCommonLibrary/BaseTool/BaseTool.cpp index 64d6252..5ea4ed0 100644 --- a/BaseCommonLibrary/BaseTool/BaseTool.cpp +++ b/BaseCommonLibrary/BaseTool/BaseTool.cpp @@ -38,7 +38,10 @@ #include // 包含SSE指令集头文件 #include // 包含SSE2指令集头文件 #include // 包含OpenMP头文件 - +#include +#include +#include +#include QString longDoubleToQStringScientific(long double value) { std::ostringstream stream; @@ -702,3 +705,71 @@ Eigen::MatrixXd BASECONSTVARIABLEAPI dB2Amp(Eigen::MatrixXd& sigma0) } + +QDateTime parseCustomDateTime(const QString& dateTimeStr) { + // 手动解析日期时间字符串 + int year = dateTimeStr.left(4).toInt(); + int month = dateTimeStr.mid(5, 2).toInt(); + int day = dateTimeStr.mid(8, 2).toInt(); + int hour = dateTimeStr.mid(11, 2).toInt(); + int minute = dateTimeStr.mid(14, 2).toInt(); + int second = dateTimeStr.mid(17, 2).toInt(); + int msec = dateTimeStr.mid(20, 6).toInt(); // 只取毫秒的前三位,因为QDateTime支持到毫秒 + + // 创建 QDate 和 QTime 对象 + QDate date(year, month, day); + QTime time(hour, minute, second, msec ); // 转换为微秒,但QTime只支持毫秒精度 + + // 构造 QDateTime 对象 + QDateTime result(date, time); + + return result; +} + + +bool isLeapYear(int year) { + return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); +} + +int daysInMonth(int year, int month) { + if (month == 2) return isLeapYear(year) ? 29 : 28; + else if (month == 4 || month == 6 || month == 9 || month == 11) return 30; + else return 31; +} + + +TimestampMicroseconds parseAndConvert( std::string dateTimeStr) { + // 解析年、月、日、时、分、秒和微秒 + int year = std::stoi(dateTimeStr.substr(0, 4)); + int month = std::stoi(dateTimeStr.substr(5, 2)); + int day = std::stoi(dateTimeStr.substr(8, 2)); + int hour = std::stoi(dateTimeStr.substr(11, 2)); + int minute = std::stoi(dateTimeStr.substr(14, 2)); + int second = std::stoi(dateTimeStr.substr(17, 2)); + int microsec = std::stoi(dateTimeStr.substr(20, 6)); + + // 计算从1970年至目标年份前一年的总天数 + long long totalDays = 0; + for (int y = 1970; y < year; ++y) { + totalDays += isLeapYear(y) ? 366 : 365; + } + + // 加上目标年份从1月到上一个月的天数 + for (int m = 1; m < month; ++m) { + totalDays += daysInMonth(year, m); + } + + // 加上本月的天数 + totalDays += day - 1; + + // 转换为总秒数,再加上小时、分钟、秒 + long long totalSeconds = totalDays * 24 * 60 * 60 + hour * 60 * 60 + minute * 60 + second; + + // 转换为毫秒和微秒 + long long msecsSinceEpoch = totalSeconds * 1000 + microsec / 1000; + int microseconds = microsec % 1000; + + return { msecsSinceEpoch, microseconds }; +} + + diff --git a/BaseCommonLibrary/BaseTool/BaseTool.h b/BaseCommonLibrary/BaseTool/BaseTool.h index 9bc6296..6ad57ff 100644 --- a/BaseCommonLibrary/BaseTool/BaseTool.h +++ b/BaseCommonLibrary/BaseTool/BaseTool.h @@ -31,7 +31,8 @@ #include #include #include - +#include +#include ///////////////////////////////////// 基础数学函数 ///////////////////////////////////////////////////////////// @@ -101,7 +102,7 @@ Eigen::Matrix3d BASECONSTVARIABLEAPI rotationMatrix(const Eigen::Vector3d& axis long double BASECONSTVARIABLEAPI convertToMilliseconds(const std::string& dateTimeStr); - +QDateTime BASECONSTVARIABLEAPI parseCustomDateTime(const QString& dateTimeStr); /// /// list 应该是按照从小到大的顺序排好 /// @@ -132,6 +133,19 @@ void initializeMatrixWithSSE2(Eigen::MatrixXf& mat, const float* data, long rowc Eigen::MatrixXd BASECONSTVARIABLEAPI MuhlemanSigmaArray(Eigen::MatrixXd& eta_deg); Eigen::MatrixXd BASECONSTVARIABLEAPI dB2Amp(Eigen::MatrixXd& sigma0); + +struct TimestampMicroseconds { + boost::int64_t msecsSinceEpoch; // 自1970-01-01T00:00:00 UTC以来的毫秒数 + int microseconds; // 额外的微秒(精确到微秒) +}; + + +bool BASECONSTVARIABLEAPI isLeapYear(int year); +int BASECONSTVARIABLEAPI daysInMonth(int year, int month); + +TimestampMicroseconds BASECONSTVARIABLEAPI parseAndConvert( std::string dateTimeStr); + + /** 模板函数类 ***********************************************************************************************************/ inline double calculate_MuhlemanSigma(double eta_deg) { diff --git a/BaseCommonLibrary/BaseTool/FileOperator.cpp b/BaseCommonLibrary/BaseTool/FileOperator.cpp index d2b1343..6d6ba6c 100644 --- a/BaseCommonLibrary/BaseTool/FileOperator.cpp +++ b/BaseCommonLibrary/BaseTool/FileOperator.cpp @@ -93,7 +93,8 @@ QString getFileNameFromPath(const QString& path) QString getFileNameWidthoutExtend(QString path) { QFileInfo fileInfo(path); - QString fileNameWithoutExtension = fileInfo.baseName(); // 获取无后缀文件名 + QString fileNameWithoutExtension = fileInfo.completeBaseName(); // 获取无后缀文件名 + qDebug() << u8"File name without extension: " << fileNameWithoutExtension; return fileNameWithoutExtension; } diff --git a/BaseCommonLibrary/BaseTool/GeoOperator.cpp b/BaseCommonLibrary/BaseTool/GeoOperator.cpp index 5a1d12a..ce49a3e 100644 --- a/BaseCommonLibrary/BaseTool/GeoOperator.cpp +++ b/BaseCommonLibrary/BaseTool/GeoOperator.cpp @@ -18,7 +18,9 @@ #include #include #include "GeoOperator.h" - +#include // OGRSpatialReference ڿռοת +#include // GDALWarp +#include Landpoint operator +(const Landpoint& p1, const Landpoint& p2) @@ -446,3 +448,53 @@ double getlocalIncAngle(Vector3D& satepoint, Vector3D& landpoint, Vector3D& slop return angle; } } + +bool BASECONSTVARIABLEAPI ConvertResolutionToDegrees(int sourceEPSG, double resolutionMeters, double refLon, double refLat, double& degreePerPixelX, double& degreePerPixelY){ + // ʼԴϵƽͶӰĿϵWGS84 γȣ + OGRSpatialReference sourceSRS, targetSRS; + sourceSRS.importFromEPSG(sourceEPSG); // Դϵȷ EPSG + targetSRS.importFromEPSG(4326); // ĿΪ WGS84 γ + + // תγ -> ƽ + OGRCoordinateTransformation* toPlane = OGRCreateCoordinateTransformation(&targetSRS, &sourceSRS); + if (!toPlane) return false; + + // ο㾭γתΪƽ + double x = refLon, y = refLat; + if (!toPlane->Transform(1, &x, &y)) { + OGRCoordinateTransformation::DestroyCT(toPlane); + return false; + } + + // תƽ -> γ + OGRCoordinateTransformation* toGeo = OGRCreateCoordinateTransformation(&sourceSRS, &targetSRS); + if (!toGeo) { + OGRCoordinateTransformation::DestroyCT(toPlane); + return false; + } + + // 㶫ֱʣȱ仯 + double eastX = x + resolutionMeters, eastY = y; + double eastLon = eastX, eastLat = eastY; + if (!toGeo->Transform(1, &eastLon, &eastLat)) { + OGRCoordinateTransformation::DestroyCT(toPlane); + OGRCoordinateTransformation::DestroyCT(toGeo); + return false; + } + degreePerPixelX = (eastLon - refLon) / resolutionMeters; // ȷÿ׶Ӧ + + // 㱱ֱʣγȱ仯 + double northX = x, northY = y + resolutionMeters; + double northLon = northX, northLat = northY; + if (!toGeo->Transform(1, &northLon, &northLat)) { + OGRCoordinateTransformation::DestroyCT(toPlane); + OGRCoordinateTransformation::DestroyCT(toGeo); + return false; + } + degreePerPixelY = (northLat - refLat) / resolutionMeters; // γȷÿ׶Ӧ + + // ͷԴ + OGRCoordinateTransformation::DestroyCT(toPlane); + OGRCoordinateTransformation::DestroyCT(toGeo); + return true; +} diff --git a/BaseCommonLibrary/BaseTool/GeoOperator.h b/BaseCommonLibrary/BaseTool/GeoOperator.h index a2c42cc..66ce525 100644 --- a/BaseCommonLibrary/BaseTool/GeoOperator.h +++ b/BaseCommonLibrary/BaseTool/GeoOperator.h @@ -124,4 +124,24 @@ CartesianCoordinates BASECONSTVARIABLEAPI sphericalToCartesian(const Spheric double BASECONSTVARIABLEAPI getlocalIncAngle(Vector3D& satepoint, Vector3D& landpoint, Vector3D& slopeVector); + +/** + * @brief 将平面坐标分辨率(米)转换为经纬度分辨率(度) + * @param sourceEPSG 平面坐标系 EPSG 码(如 UTM Zone 50N 对应 32650) + * @param resolutionMeters 输入分辨率(单位:米) + * @param refLon 参考点经度(十进制度,用于计算局部转换系数) + * @param refLat 参考点纬度(十进制度,用于计算局部转换系数) + * @param[out] degreePerPixelX 经度方向分辨率(度/像素) + * @param[out] degreePerPixelY 纬度方向分辨率(度/像素) + * @return 是否转换成功 + */ +bool BASECONSTVARIABLEAPI ConvertResolutionToDegrees( + int sourceEPSG, + double resolutionMeters, + double refLon, + double refLat, + double& degreePerPixelX, + double& degreePerPixelY +); + #endif \ No newline at end of file diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h index 633dd9e..9b52766 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h @@ -89,7 +89,7 @@ enum GDALREADARRCOPYMETHOD { /// \param long 经度 /// \param lat 纬度 /// \return 对应投影坐标系统的 EPSG编码,-1 表示计算错误 -long BASECONSTVARIABLEAPI getProjectEPSGCodeByLon_Lat(double long, double lat, ProjectStripDelta stripState); +long BASECONSTVARIABLEAPI getProjectEPSGCodeByLon_Lat(double lon, double lat, ProjectStripDelta stripState= ProjectStripDelta::Strip_6); long BASECONSTVARIABLEAPI getProjectEPSGCodeByLon_Lat_inStrip3(double lon, double lat); diff --git a/BaseCommonLibrary/BaseTool/SARSimulationImageL1.cpp b/BaseCommonLibrary/BaseTool/SARSimulationImageL1.cpp index 16134d2..8bc4245 100644 --- a/BaseCommonLibrary/BaseTool/SARSimulationImageL1.cpp +++ b/BaseCommonLibrary/BaseTool/SARSimulationImageL1.cpp @@ -106,7 +106,7 @@ ErrorCode SARSimulationImageL1Dataset::OpenOrNew(QString folder, QString filenam this->saveToXml(); } - if (this->Rasterlevel!=RasterL2||QFile(this->GPSPointFilePath).exists() == false) { + if (this->Rasterlevel==RasterL2||QFile(this->GPSPointFilePath).exists() == false) { // ļ omp_lock_t lock; omp_init_lock(&lock); @@ -122,7 +122,7 @@ ErrorCode SARSimulationImageL1Dataset::OpenOrNew(QString folder, QString filenam omp_destroy_lock(&lock); } - if (this->Rasterlevel == RasterLevel::RasterSLC || QFile(this->ImageRasterPath).exists() == false) { + else if (this->Rasterlevel == RasterLevel::RasterSLC || QFile(this->ImageRasterPath).exists() == false) { // ļ omp_lock_t lock; @@ -140,7 +140,7 @@ ErrorCode SARSimulationImageL1Dataset::OpenOrNew(QString folder, QString filenam } - if (this->Rasterlevel != RasterLevel::RasterSLC || QFile(this->ImageRasterPath).exists() == false) { + else if (this->Rasterlevel == RasterLevel::RasterL1B || QFile(this->ImageRasterPath).exists() == false) { // ļ omp_lock_t lock; @@ -150,11 +150,11 @@ ErrorCode SARSimulationImageL1Dataset::OpenOrNew(QString folder, QString filenam CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); - std::shared_ptr poDstDS(poDriver->Create(this->ImageRasterPath.toUtf8().constData(), colCount, rowCount, 1, GDT_CFloat32, NULL)); + std::shared_ptr poDstDS(poDriver->Create(this->GPSPointFilePath.toUtf8().constData(), 19, rowCount, 1, GDT_Float64, NULL)); GDALFlushCache((GDALDatasetH)poDstDS.get()); poDstDS.reset(); - omp_unset_lock(&lock); // - omp_destroy_lock(&lock); // + omp_unset_lock(&lock); + omp_destroy_lock(&lock); } @@ -203,7 +203,7 @@ ErrorCode SARSimulationImageL1Dataset::Open(QString xmlPath) QFileInfo fileInfo(xmlPath); QString fileName = fileInfo.fileName(); // ȡļ QString fileSuffix = fileInfo.suffix(); // ȡ׺ - QString fileNameWithoutSuffix = fileInfo.baseName(); // ȡ׺ļ + QString fileNameWithoutSuffix = fileInfo.completeBaseName(); // ȡ׺ļ QString directoryPath = fileInfo.path(); // ȡļ· if (fileSuffix.toLower() == "xml" || fileSuffix.toLower() == ".xml") { return this->Open(directoryPath, fileNameWithoutSuffix); @@ -246,12 +246,12 @@ void SARSimulationImageL1Dataset::saveToXml() 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("Rnear", QString::number(this->Rnear, 'e', 18)); + xmlWriter.writeTextElement("Rfar", QString::number(this->Rfar, 'e', 18)); + xmlWriter.writeTextElement("Rref", QString::number(this->Rref, 'e', 18)); + xmlWriter.writeTextElement("CenterFreq", QString::number(this->centerFreq, 'e', 18)); + xmlWriter.writeTextElement("Fs", QString::number(this->Fs, 'e', 18)); + xmlWriter.writeTextElement("CenterAngle", QString::number(this->CenterAngle, 'e', 18)); xmlWriter.writeTextElement("LookSide", this->LookSide); // sateantpos @@ -259,60 +259,60 @@ void SARSimulationImageL1Dataset::saveToXml() for (long i = 0; i < this->sateposes.count(); i++) { xmlWriter.writeStartElement("AntPosParam"); - xmlWriter.writeTextElement("time", QString::number(this->sateposes[i].time)); // time - xmlWriter.writeTextElement("Px", QString::number(this->sateposes[i].Px)); // Px - xmlWriter.writeTextElement("Py", QString::number(this->sateposes[i].Py)); // Py - xmlWriter.writeTextElement("Pz", QString::number(this->sateposes[i].Pz)); // Pz - xmlWriter.writeTextElement("Vx", QString::number(this->sateposes[i].Vx)); // Vx - xmlWriter.writeTextElement("Vy", QString::number(this->sateposes[i].Vy)); // Vy - xmlWriter.writeTextElement("Vz", QString::number(this->sateposes[i].Vz)); // Vz - xmlWriter.writeTextElement("AntDirectX", QString::number(this->sateposes[i].AntDirectX)); // AntDirectX - xmlWriter.writeTextElement("AntDirectY", QString::number(this->sateposes[i].AntDirectY)); // AntDirectY - xmlWriter.writeTextElement("AntDirectZ", QString::number(this->sateposes[i].AntDirectZ)); // AntDirectZ - xmlWriter.writeTextElement("AVx", QString::number(this->sateposes[i].AVx)); // AVx - xmlWriter.writeTextElement("AVy", QString::number(this->sateposes[i].AVy)); // AVy - xmlWriter.writeTextElement("AVz", QString::number(this->sateposes[i].AVz)); // AVz - xmlWriter.writeTextElement("lon", QString::number(this->sateposes[i].lon)); // lon - xmlWriter.writeTextElement("lat", QString::number(this->sateposes[i].lat)); // lat - xmlWriter.writeTextElement("ati", QString::number(this->sateposes[i].ati)); // ati + xmlWriter.writeTextElement("time", QString::number(this->sateposes[i].time, 'e', 18)); // time + xmlWriter.writeTextElement("Px", QString::number(this->sateposes[i].Px, 'e', 18)); // Px + xmlWriter.writeTextElement("Py", QString::number(this->sateposes[i].Py, 'e', 18)); // Py + xmlWriter.writeTextElement("Pz", QString::number(this->sateposes[i].Pz, 'e', 18)); // Pz + xmlWriter.writeTextElement("Vx", QString::number(this->sateposes[i].Vx, 'e', 18)); // Vx + xmlWriter.writeTextElement("Vy", QString::number(this->sateposes[i].Vy, 'e', 18)); // Vy + xmlWriter.writeTextElement("Vz", QString::number(this->sateposes[i].Vz, 'e', 18)); // Vz + xmlWriter.writeTextElement("AntDirectX", QString::number(this->sateposes[i].AntDirectX, 'e', 18)); // AntDirectX + xmlWriter.writeTextElement("AntDirectY", QString::number(this->sateposes[i].AntDirectY, 'e', 18)); // AntDirectY + xmlWriter.writeTextElement("AntDirectZ", QString::number(this->sateposes[i].AntDirectZ, 'e', 18)); // AntDirectZ + xmlWriter.writeTextElement("AVx", QString::number(this->sateposes[i].AVx, 'e', 18)); // AVx + xmlWriter.writeTextElement("AVy", QString::number(this->sateposes[i].AVy, 'e', 18)); // AVy + xmlWriter.writeTextElement("AVz", QString::number(this->sateposes[i].AVz, 'e', 18)); // AVz + xmlWriter.writeTextElement("lon", QString::number(this->sateposes[i].lon, 'e', 18)); // lon + xmlWriter.writeTextElement("lat", QString::number(this->sateposes[i].lat, 'e', 18)); // lat + xmlWriter.writeTextElement("ati", QString::number(this->sateposes[i].ati, 'e', 18)); // ati xmlWriter.writeEndElement(); // } - xmlWriter.writeTextElement("ImageStartTime", QString::number(this->startImageTime)); - xmlWriter.writeTextElement("ImageEndTime", QString::number(this->EndImageTime)); + xmlWriter.writeTextElement("ImageStartTime", QString::number(this->startImageTime, 'e', 18)); + xmlWriter.writeTextElement("ImageEndTime", QString::number(this->EndImageTime, 'e', 18)); - xmlWriter.writeTextElement("incidenceAngleNearRange", QString::number(this->incidenceAngleNearRange)); - xmlWriter.writeTextElement("incidenceAngleFarRange", QString::number(this->incidenceAngleFarRange)); - xmlWriter.writeTextElement("TotalProcessedAzimuthBandWidth", QString::number(this->TotalProcessedAzimuthBandWidth)); - xmlWriter.writeTextElement("DopplerParametersReferenceTime", QString::number(this->DopplerParametersReferenceTime)); + xmlWriter.writeTextElement("incidenceAngleNearRange", QString::number(this->incidenceAngleNearRange, 'e', 18)); + xmlWriter.writeTextElement("incidenceAngleFarRange", QString::number(this->incidenceAngleFarRange, 'e', 18)); + xmlWriter.writeTextElement("TotalProcessedAzimuthBandWidth", QString::number(this->TotalProcessedAzimuthBandWidth, 'e', 18)); + xmlWriter.writeTextElement("DopplerParametersReferenceTime", QString::number(this->DopplerParametersReferenceTime, 'e', 18)); xmlWriter.writeStartElement("DopplerCentroidCoefficients"); - xmlWriter.writeTextElement("d0", QString::number(this->d0)); - xmlWriter.writeTextElement("d1", QString::number(this->d1)); - xmlWriter.writeTextElement("d2", QString::number(this->d2)); - xmlWriter.writeTextElement("d3", QString::number(this->d3)); - xmlWriter.writeTextElement("d4", QString::number(this->d4)); + xmlWriter.writeTextElement("d0", QString::number(this->d0, 'e', 18)); + xmlWriter.writeTextElement("d1", QString::number(this->d1, 'e', 18)); + xmlWriter.writeTextElement("d2", QString::number(this->d2, 'e', 18)); + xmlWriter.writeTextElement("d3", QString::number(this->d3, 'e', 18)); + xmlWriter.writeTextElement("d4", QString::number(this->d4, 'e', 18)); xmlWriter.writeEndElement(); // DopplerCentroidCoefficients xmlWriter.writeStartElement("DopplerRateValuesCoefficients"); - xmlWriter.writeTextElement("r0", QString::number(this->r0)); - xmlWriter.writeTextElement("r1", QString::number(this->r1)); - xmlWriter.writeTextElement("r2", QString::number(this->r2)); - xmlWriter.writeTextElement("r3", QString::number(this->r3)); - xmlWriter.writeTextElement("r4", QString::number(this->r4)); + xmlWriter.writeTextElement("r0", QString::number(this->r0, 'e', 18)); + xmlWriter.writeTextElement("r1", QString::number(this->r1, 'e', 18)); + xmlWriter.writeTextElement("r2", QString::number(this->r2, 'e', 18)); + xmlWriter.writeTextElement("r3", QString::number(this->r3, 'e', 18)); + xmlWriter.writeTextElement("r4", QString::number(this->r4, 'e', 18)); xmlWriter.writeEndElement(); // DopplerRateValuesCoefficients - xmlWriter.writeTextElement("latitude_center", QString::number(this->latitude_center)); - xmlWriter.writeTextElement("longitude_center", QString::number(this->longitude_center)); - xmlWriter.writeTextElement("latitude_topLeft", QString::number(this->latitude_topLeft)); - xmlWriter.writeTextElement("longitude_topLeft", QString::number(this->longitude_topLeft)); - xmlWriter.writeTextElement("latitude_topRight", QString::number(this->latitude_topRight)); - xmlWriter.writeTextElement("longitude_topRight", QString::number(this->longitude_topRight)); - xmlWriter.writeTextElement("latitude_bottomLeft", QString::number(this->latitude_bottomLeft)); - xmlWriter.writeTextElement("longitude_bottomLeft", QString::number(this->longitude_bottomLeft)); - xmlWriter.writeTextElement("latitude_bottomRight", QString::number(this->latitude_bottomRight)); - xmlWriter.writeTextElement("longitude_bottomRight", QString::number(this->longitude_bottomRight)); + xmlWriter.writeTextElement("latitude_center", QString::number(this->latitude_center, 'e', 18)); + xmlWriter.writeTextElement("longitude_center", QString::number(this->longitude_center, 'e', 18)); + xmlWriter.writeTextElement("latitude_topLeft", QString::number(this->latitude_topLeft, 'e', 18)); + xmlWriter.writeTextElement("longitude_topLeft", QString::number(this->longitude_topLeft, 'e', 18)); + xmlWriter.writeTextElement("latitude_topRight", QString::number(this->latitude_topRight, 'e', 18)); + xmlWriter.writeTextElement("longitude_topRight", QString::number(this->longitude_topRight, 'e', 18)); + xmlWriter.writeTextElement("latitude_bottomLeft", QString::number(this->latitude_bottomLeft, 'e', 18)); + xmlWriter.writeTextElement("longitude_bottomLeft", QString::number(this->longitude_bottomLeft, 'e', 18)); + xmlWriter.writeTextElement("latitude_bottomRight", QString::number(this->latitude_bottomRight, 'e', 18)); + xmlWriter.writeTextElement("longitude_bottomRight", QString::number(this->longitude_bottomRight, 'e', 18)); xmlWriter.writeEndElement(); // Parameters xmlWriter.writeEndDocument(); diff --git a/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp b/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp index c695822..9fe8bfd 100644 --- a/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp +++ b/BaseCommonLibrary/BaseTool/gdalImageOperator.cpp @@ -1401,6 +1401,15 @@ gdalImage CreategdalImage(const QString& img_path, int height, int width, int ba GDALDataset* poDstDS = poDriver->Create(img_path.toUtf8().constData(), width, height, band_num, datetype, NULL); // ������ + + if (NULL == poDstDS) + { + qDebug() << "Create image failed!"; + throw "Create image failed!"; + exit(1); + } + + if (need_gt) { if (!projection.isEmpty()) { poDstDS->SetProjection(projection.toUtf8().constData()); diff --git a/BaseCommonLibrary/ImageOperatorFuntion.cpp b/BaseCommonLibrary/ImageOperatorFuntion.cpp index 5154807..ae75a14 100644 --- a/BaseCommonLibrary/ImageOperatorFuntion.cpp +++ b/BaseCommonLibrary/ImageOperatorFuntion.cpp @@ -209,6 +209,7 @@ int ENVI2TIFF(QString in_envi_path, QString out_tiff_path) void ConvertCoordinateSystem(QString inRasterPath, QString outRasterPath, long outepsgcode) { // 注册所有GDAL驱动 GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 打开输入栅格文件 GDALDataset* srcDataset = (GDALDataset*)GDALOpen(inRasterPath.toUtf8().constData(), GA_ReadOnly); @@ -294,7 +295,7 @@ void ConvertCoordinateSystem(QString inRasterPath, QString outRasterPath, long o void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QString pszOutFile, GDALResampleAlg eResample) { GDALAllRegister(); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); + GDALDataset* pDSrc = (GDALDataset*)GDALOpen(pszSrcFile.toLocal8Bit().constData(), GA_ReadOnly); if (pDSrc == NULL) { qDebug() << u8"do not open In Raster file: " << pszSrcFile; @@ -565,6 +566,7 @@ void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, Q void cropRasterByLatLon(const char* inputFile, const char* outputFile, double minLon, double maxLon, double minLat, double maxLat) { // 初始化 GDAL 库 GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 打开栅格数据集 GDALDataset* poDataset = (GDALDataset*)GDALOpen(inputFile, GA_ReadOnly); @@ -762,7 +764,7 @@ void resampleRaster(const char* inputRaster, const char* outputRaster, double ta // 计算目标栅格的尺寸 double targetXSize = (adfGeoTransform[1] * nXSize) / targetPixelSizeX; - double targetYSize = (adfGeoTransform[5] * nYSize) / targetPixelSizeY; + double targetYSize = std::abs((adfGeoTransform[5] * nYSize) / targetPixelSizeY); // 创建目标数据集(输出栅格) GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); @@ -967,14 +969,16 @@ long GetEPSGFromRasterFile(QString filepath) -long getProjectEPSGCodeByLon_Lat(double long, double lat, ProjectStripDelta stripState) +long getProjectEPSGCodeByLon_Lat(double lon, double lat, ProjectStripDelta stripState) { long EPSGCode = 0; switch (stripState) { case ProjectStripDelta::Strip_3: { + EPSGCode = getProjectEPSGCodeByLon_Lat_inStrip3(lon, lat); break; }; case ProjectStripDelta::Strip_6: { + EPSGCode = getProjectEPSGCodeByLon_Lat_inStrip6(lon, lat); break; } default: { diff --git a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp index 1e5fdcd..dc3c8f9 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp @@ -26,7 +26,7 @@ ErrorCode GF3CalibrationRaster(QString inRasterPath, QString outRasterPath, doub double quayCoff = Qualifyvalue * 1.0 / 32767; double caliCoff = std::pow(10.0, (calibrationConst * 1.0 / 20)); - qDebug() << "ϵ:\t" << quayCoff / caliCoff; + qDebug() << u8"ϵ:\t" << quayCoff / caliCoff; long startrow = 0; for (startrow = 0; startrow < imgraster.height; startrow = startrow + blocklines) { @@ -37,7 +37,7 @@ ErrorCode GF3CalibrationRaster(QString inRasterPath, QString outRasterPath, doub imgArr.imag() = imgArrb2.array() * quayCoff / caliCoff; outraster.saveImage(imgArr, startrow, 0, 1); } - qDebug() << "Ӱд뵽" << outRasterPath; + qDebug() << u8"Ӱд뵽" << outRasterPath; return ErrorCode::SUCCESS; } @@ -80,29 +80,29 @@ ErrorCode ImportGF3L1ARasterToWorkspace(QString inMetaxmlPath, QString inRasterP QString outRasterpath = l1dataset.getImageRasterPath(); ErrorCode errorcode = ErrorCode::SUCCESS; - qDebug() << ":\t" << inRasterPath; + qDebug() << u8":\t" << inRasterPath; switch (polsartype) { case POLARHH: - qDebug() << "HH"; + qDebug() << u8"HH"; errorcode = GF3CalibrationRaster(inRasterPath, outRasterpath, gf3xml.HH_QualifyValue, gf3xml.HH_CalibrationConst); break; case POLARHV: - qDebug() << "HH"; + qDebug() << u8"HH"; errorcode = GF3CalibrationRaster(inRasterPath, outRasterpath, gf3xml.HV_QualifyValue, gf3xml.HV_CalibrationConst); break; case POLARVH: - qDebug() << "VH"; + qDebug() << u8"VH"; errorcode = GF3CalibrationRaster(inRasterPath, outRasterpath, gf3xml.VH_QualifyValue, gf3xml.VH_CalibrationConst); break; case POLARVV: - qDebug() << "VV"; + qDebug() << u8"VV"; errorcode = GF3CalibrationRaster(inRasterPath, outRasterpath, gf3xml.VV_QualifyValue, gf3xml.VV_CalibrationConst); break; default: break; } - qDebug() << "״̬\t" << QString::fromStdString(errorCode2errInfo(errorcode)); + qDebug() << u8"״̬\t" << QString::fromStdString(errorCode2errInfo(errorcode)); return errorcode; } @@ -115,7 +115,7 @@ QVector SearchGF3DataTiff(QString inMetaxmlPath) // ȡ·ڵĿ¼ QDir directory(absPath); if (!directory.exists()) { - qDebug() << "Directory does not exist:" << directory.absolutePath(); + qDebug() << u8"Directory does not exist:" << directory.absolutePath(); return QVector(0); } @@ -124,7 +124,7 @@ QVector SearchGF3DataTiff(QString inMetaxmlPath) filters << "*.tif" << "*.TIF" << "*.tiff" << "*.TIFF"; QStringList files = directory.entryList(filters, QDir::Files); - qDebug() << "TIFF Files in the directory" << directory.absolutePath() << ":"; + qDebug() << u8"TIFF Files in the directory" << directory.absolutePath() << ":"; QVector filepath(0); for (long i = 0; i < files.count(); i++) { @@ -144,7 +144,7 @@ POLARTYPEENUM getDatasetGF3FilePolsarType(QString fileName) if (match.hasMatch()) { polarization = match.captured(1); polarization = polarization.toLower().replace("_", ""); - qDebug() << "Polarization extracted:" << polarization; + qDebug() << u8"Polarization extracted:" << polarization; if (polarization == "hh") { return POLARTYPEENUM::POLARHH; } @@ -162,7 +162,7 @@ POLARTYPEENUM getDatasetGF3FilePolsarType(QString fileName) } } else { - qDebug() << "No polarization found in the path."; + qDebug() << u8"No polarization found in the path."; return POLARTYPEENUM::POLARUNKOWN; } @@ -199,7 +199,7 @@ ErrorCode ImportGF3L1AProcess(QString inMetaxmlPath, QString outWorkDirPath) break; } if (errorcode == ErrorCode::SUCCESS) { - return errorcode; + continue; } else { QMessageBox::warning(nullptr, u8"", u8"ݵ"); @@ -305,18 +305,18 @@ ErrorCode GF3RDCreateLookTable(QString inxmlPath, QString indemPath, QString out polyfitmodel.polyFit(3, false); qDebug() << "-----------------------------------"; - qDebug() << "satellite polyfit model params:\n"; + qDebug() << u8"satellite polyfit model params:\n"; qDebug() << polyfitmodel.getSatelliteOribtModelParamsString(); qDebug() << "-----------------------------------"; // ʼұ //1.ֿ long cpucore_num = std::thread::hardware_concurrency(); - long blockline = Memory1MB * 500 / 8 / cpucore_num / 4 / l1dataset.getcolCount(); - blockline = blockline < 50 ? 50 : blockline; + long blocklineinit = Memory1MB / 8 / cpucore_num / 4 / l1dataset.getcolCount() * 4000; + blocklineinit = blocklineinit < 50 ? 50 : blocklineinit; //2. - long colcount = l1dataset.getcolCount(); - long rowcount = l1dataset.getrowCount(); + long colcount = rasterRC.width;//l1dataset.getcolCount(); + long rowcount = rasterRC.height;//l1dataset.getrowCount(); long startRId = 0; long processNumber = 0; @@ -334,7 +334,11 @@ ErrorCode GF3RDCreateLookTable(QString inxmlPath, QString indemPath, QString out #pragma omp parallel for num_threads(cpucore_num-1) - for (startRId = 0; startRId < rowcount; startRId = startRId + blockline) { + for (startRId = 0; startRId < rowcount; startRId = startRId + blocklineinit) { + long blockline = blocklineinit; + if (startRId + blockline > rowcount) { + blockline = rowcount - startRId; + } Eigen::MatrixXd sar_r = rasterRC.getData(startRId, 0, blockline, colcount, 1); Eigen::MatrixXd sar_c = rasterRC.getData(startRId, 0, blockline, colcount, 2); Eigen::MatrixXd dem_x = demxyz.getData(startRId, 0, blockline, colcount, 1); @@ -409,7 +413,7 @@ ErrorCode GF3RDCreateLookTable(QString inxmlPath, QString indemPath, QString out } else {} processNumber = processNumber + blockrows; - qDebug() << "\rprocess bar:\t" << processNumber * 100.0 / rowcount << " % " << "\t\t\t"; + qDebug() << u8"\rprocess bar:\t" << processNumber * 100.0 / rowcount << " % " << "\t\t\t"; if (progressDialog.maximum() <= processNumber) { processNumber = progressDialog.maximum() - 1; } @@ -430,7 +434,7 @@ ErrorCode GF3OrthSLC( QString inRasterPath, QString inlooktablePath, QString out gdalImage outRaster(outRasterPath);// if (outRaster.height != looktableRaster.height || outRaster.width != looktableRaster.width) { - qDebug() << "look table size is not same as outRaster size"<< looktableRaster.height <<"!="<polyfitVz[i], 'e', 6) + "\n"; } result += "------------------------------------------------------\n"; - + printf("%s\n", result.toUtf8().constData()); return result; } diff --git a/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp b/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp index af2d5a6..ea9936f 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp @@ -16,7 +16,8 @@ QComplex2AmpPhase::QComplex2AmpPhase(QWidget *parent) QObject::connect(ui.radioButtonAmp,SIGNAL(toggled(bool)),this,SLOT(radioButtonAmptoggled(bool))); QObject::connect(ui.radioButtonPhase, SIGNAL(toggled(bool)), this, SLOT(radioButtonPhasetoggled(bool))); QObject::connect(ui.radioButtonSigma0, SIGNAL(toggled(bool)), this, SLOT(radioButtonSigma0toggled(bool))); - QObject::connect(ui.buttonBox, SIGNAL(accept()), this, SLOT(onaccept())); + QObject::connect(ui.pushButtonWorkSpace, SIGNAL(clicked(bool)), this, SLOT(onpushButtonWorkSpaceClicked(bool))); + QObject::connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(onaccept())); QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(onreject())); //toggled(bool ) } @@ -47,19 +48,19 @@ void QComplex2AmpPhase::onaccept() slcl1.Open(folderpath, filename); QString l2bfilename = filename + ui.lineEditHZ->text(); SARSimulationImageL1Dataset l1B(RasterLevel::RasterL1B); - slcl1.OpenOrNew(outworkdir, l2bfilename,slcl1.getrowCount(),slcl1.getcolCount()); + l1B.OpenOrNew(outworkdir, l2bfilename,slcl1.getrowCount(),slcl1.getcolCount()); QString srcxmlpath = slcl1.getxmlFilePath(); QString tarxmlpath = l1B.getxmlFilePath(); copyAndReplaceFile(srcxmlpath, tarxmlpath); l1B.loadFromXml(); if (ui.radioButtonAmp->isChecked()) { - Complex2AmpRaster(imgfilepath, slcl1.getImageRasterPath()); + Complex2AmpRaster(imgfilepath, l1B.getImageRasterPath()); } else if (ui.radioButtonPhase->isChecked()) { - Complex2PhaseRaster(imgfilepath, slcl1.getImageRasterPath()); + Complex2PhaseRaster(imgfilepath, l1B.getImageRasterPath()); } else if (ui.radioButtonSigma0->isChecked()) { - Complex2dBRaster(imgfilepath, slcl1.getImageRasterPath()); + Complex2dBRaster(imgfilepath, l1B.getImageRasterPath()); } progressDialog.setValue(i); } diff --git a/Toolbox/BaseToolbox/BaseToolbox/QImportGF3StripL1ADataset.cpp b/Toolbox/BaseToolbox/BaseToolbox/QImportGF3StripL1ADataset.cpp index 12793e3..e6146f0 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QImportGF3StripL1ADataset.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QImportGF3StripL1ADataset.cpp @@ -7,10 +7,9 @@ QImportGF3StripL1ADataset::QImportGF3StripL1ADataset(QWidget *parent) { ui.setupUi(this); - QListWidget* listWidgetMetaxml; - QObject::connect(ui.pushButtonAdd,SIGNAL(clicked(clicked)),this,SLOT(onpushButtonAddClicked(bool))); - QObject::connect(ui.pushButtonRemove, SIGNAL(clicked(clicked)), this, SLOT(onpushButtonRemoveClicked(bool))); - QObject::connect(ui.pushButtonWorkSpace, SIGNAL(clicked(clicked)), this, SLOT(onpushButtonWorkSpaceClicked(bool))); + QObject::connect(ui.pushButtonAdd,SIGNAL(clicked(bool)),this,SLOT(onpushButtonAddClicked(bool))); + QObject::connect(ui.pushButtonRemove, SIGNAL(clicked(bool)), this, SLOT(onpushButtonRemoveClicked(bool))); + QObject::connect(ui.pushButtonWorkSpace, SIGNAL(clicked(bool)), this, SLOT(onpushButtonWorkSpaceClicked(bool))); QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(onreject())); QObject::connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(onaccept())); diff --git a/Toolbox/BaseToolbox/BaseToolbox/QRDOrthProcessClass.cpp b/Toolbox/BaseToolbox/BaseToolbox/QRDOrthProcessClass.cpp index 2ad3480..c9ec7cc 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QRDOrthProcessClass.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QRDOrthProcessClass.cpp @@ -10,8 +10,8 @@ QRDOrthProcessClass::QRDOrthProcessClass(QWidget *parent) connect(ui.pushButtonAdd,SIGNAL(clicked(bool)),this,SLOT(onpushButtonAddClicked(bool))); connect(ui.pushButtonRemove,SIGNAL(clicked(bool)),this,SLOT(onpushButtonRemoveClicked(bool))); - connect(ui.pushButtonDEMSelect,SIGNAL(clicked(bool)),this,SLOT(onpushButtonWorkSpaceClicked(bool))); - connect(ui.pushButtonWorkSpace, SIGNAL(clicked(bool)), this, SLOT(pushButtonDEMSelectClicked(bool))); + connect(ui.pushButtonWorkSpace,SIGNAL(clicked(bool)),this,SLOT(onpushButtonWorkSpaceClicked(bool))); + connect(ui.pushButtonDEMSelect, SIGNAL(clicked(bool)), this, SLOT(pushButtonDEMSelectClicked(bool))); QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(onreject())); QObject::connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(onaccept())); // QDialogButtonBox* buttonBox; diff --git a/Toolbox/BaseToolbox/BaseToolbox/SatelliteGF3xmlParser.cpp b/Toolbox/BaseToolbox/BaseToolbox/SatelliteGF3xmlParser.cpp index 4cae6ee..5c8ae39 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/SatelliteGF3xmlParser.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/SatelliteGF3xmlParser.cpp @@ -5,24 +5,41 @@ bool SatelliteGF3xmlParser::loadFile(const QString& filename) { QFile file(filename); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qWarning() << "Cannot open file:" << filename; + qWarning() << u8"Cannot open file:" << filename; return false; } QDomDocument doc; if (!doc.setContent(&file)) { file.close(); - qWarning() << "Failed to parse the file into a DOM tree."; + qWarning() << u8"Failed to parse the file into a DOM tree."; return false; } file.close(); xml = doc; + + this->parseAdditionalData(); + this->parseImageInfo(); + this->parsePlatform(); + this->parseGPS(); + + //ʱ + double tempreftime = start + (end - start) / 2; + for (long i = 0;i < antposs.size();i++) + { + antposs[i].time = antposs[i].time - tempreftime; + } + + start = start- tempreftime; + end = end- tempreftime; + + return true; } void SatelliteGF3xmlParser::parsePlatform() { - QDomElement platform = xml.firstChildElement("root").firstChildElement("platform"); + QDomElement platform = xml.firstChildElement("product").firstChildElement("platform"); if (!platform.isNull()) { CenterTime = platform.firstChildElement("CenterTime").text(); Rs = platform.firstChildElement("Rs").text().toDouble(); @@ -37,24 +54,24 @@ void SatelliteGF3xmlParser::parsePlatform() { Vys = platform.firstChildElement("Vys").text().toDouble(); Vzs = platform.firstChildElement("Vzs").text().toDouble(); - qDebug() << "Platform Data:"; - qDebug() << "CenterTime:" << CenterTime; - qDebug() << "Rs:" << Rs; - qDebug() << "satVelocity:" << satVelocity; - qDebug() << "RollAngle:" << RollAngle; - qDebug() << "PitchAngle:" << PitchAngle; - qDebug() << "YawAngle:" << YawAngle; - qDebug() << "Xs:" << Xs; - qDebug() << "Ys:" << Ys; - qDebug() << "Zs:" << Zs; - qDebug() << "Vxs:" << Vxs; - qDebug() << "Vys:" << Vys; - qDebug() << "Vzs:" << Vzs; + qDebug() << u8"Platform Data:"; + qDebug() << u8"CenterTime:" << CenterTime; + qDebug() << u8"Rs:" << Rs; + qDebug() << u8"satVelocity:" << satVelocity; + qDebug() << u8"RollAngle:" << RollAngle; + qDebug() << u8"PitchAngle:" << PitchAngle; + qDebug() << u8"YawAngle:" << YawAngle; + qDebug() << u8"Xs:" << Xs; + qDebug() << u8"Ys:" << Ys; + qDebug() << u8"Zs:" << Zs; + qDebug() << u8"Vxs:" << Vxs; + qDebug() << u8"Vys:" << Vys; + qDebug() << u8"Vzs:" << Vzs; } } void SatelliteGF3xmlParser::parseGPS() { - QDomElement GPS = xml.firstChildElement("root").firstChildElement("GPS"); + QDomElement GPS = xml.firstChildElement("product").firstChildElement("GPS"); if (!GPS.isNull()) { QDomNodeList GPSParams = GPS.elementsByTagName("GPSParam"); for (int i = 0; i < GPSParams.count(); ++i) { @@ -69,37 +86,52 @@ void SatelliteGF3xmlParser::parseGPS() { QString yVelocity = GPSParam.firstChildElement("yVelocity").text(); QString zVelocity = GPSParam.firstChildElement("zVelocity").text(); - QDateTime dateTime = QDateTime::fromString(TimeStamp, "yyyy-MM-dd HH:mm:ss.zzzzzz"); - satepos.time = dateTime.toMSecsSinceEpoch() / 1000.0; - satepos.Px = xPosition.toDouble(); - satepos.Py = yPosition.toDouble(); - satepos.Pz = zPosition.toDouble(); - satepos.Vx = xVelocity.toDouble(); - satepos.Vy = yVelocity.toDouble(); - satepos.Vz = zVelocity.toDouble(); + + TimestampMicroseconds dateTime = parseAndConvert(TimeStamp.toStdString()); + satepos.time = dateTime.msecsSinceEpoch / 1000.0 + dateTime.microseconds / 100000.0; + satepos.Px = xPosition.toDouble(); + satepos.Py = yPosition.toDouble(); + satepos.Pz = zPosition.toDouble(); + satepos.Vx = xVelocity.toDouble(); + satepos.Vy = yVelocity.toDouble(); + satepos.Vz = zVelocity.toDouble(); this->antposs.append(satepos); - qDebug() << "\nGPS Param Data:"; - qDebug() << "TimeStamp:" << TimeStamp; - qDebug() << "xPosition:" << xPosition; - qDebug() << "yPosition:" << yPosition; - qDebug() << "zPosition:" << zPosition; - qDebug() << "xVelocity:" << xVelocity; - qDebug() << "yVelocity:" << yVelocity; - qDebug() << "zVelocity:" << zVelocity; + qDebug() << u8"\nGPS Param Data:"; + qDebug() << u8"TimeStamp:" << TimeStamp; + qDebug() << u8"xPosition:" << xPosition; + qDebug() << u8"yPosition:" << yPosition; + qDebug() << u8"zPosition:" << zPosition; + qDebug() << u8"xVelocity:" << xVelocity; + qDebug() << u8"yVelocity:" << yVelocity; + qDebug() << u8"zVelocity:" << zVelocity; } } } void SatelliteGF3xmlParser::parseImageInfo() { - QDomElement imageinfo = xml.firstChildElement("root").firstChildElement("imageinfo"); + QDomElement imageinfo = xml.firstChildElement("product").firstChildElement("imageinfo"); if (!imageinfo.isNull()) { QDomElement imagingTime = imageinfo.firstChildElement("imagingTime"); - ; - start = QDateTime::fromString(imagingTime.firstChildElement("start").text(), "yyyy-MM-dd HH:mm:ss.zzzzzz").toMSecsSinceEpoch()/1000.0; - end = QDateTime::fromString(imagingTime.firstChildElement("end").text(), "yyyy-MM-dd HH:mm:ss.zzzzzz").toMSecsSinceEpoch() / 1000.0; - + + QString starttimestr = imagingTime.firstChildElement("start").text().trimmed(); + QString endtimestr = imagingTime.firstChildElement("end").text().trimmed(); + + TimestampMicroseconds starttime = parseAndConvert(starttimestr.toStdString()); + TimestampMicroseconds endtime = parseAndConvert(endtimestr.toStdString()); + + start = starttime.msecsSinceEpoch / 1000.0 + starttime.microseconds / 100000.0; + end = endtime.msecsSinceEpoch / 1000.0 + endtime.microseconds / 100000.0; + + // ӡstarttime,endtime + qDebug() << u8"ʼʱ(parse)" << starttime.msecsSinceEpoch << "\t" << starttime.microseconds; + qDebug() << u8"ʱ(parse)" << endtime.msecsSinceEpoch << "\t" << endtime.microseconds; + + qDebug() << u8"ʼʱ䣺" << start <<"\t"<< starttimestr; + qDebug() << u8"ʱ䣺" << end << "\t" << endtimestr; + + nearRange = imageinfo.firstChildElement("nearRange").text().toDouble(); refRange = imageinfo.firstChildElement("refRange").text().toDouble(); eqvFs = imageinfo.firstChildElement("eqvFs").text().toDouble(); @@ -154,35 +186,36 @@ void SatelliteGF3xmlParser::parseImageInfo() { incidenceAngleNearRange = imageinfo.firstChildElement("incidenceAngleNearRange").text().toDouble(); incidenceAngleFarRange = imageinfo.firstChildElement("incidenceAngleFarRange").text().toDouble(); - qDebug() << "\nImage Info Data:"; - qDebug() << "Start:" << start; - qDebug() << "End:" << end; - qDebug() << "Near Range:" << nearRange; - qDebug() << "Ref Range:" << refRange; - qDebug() << "Eqv Fs:" << eqvFs; - qDebug() << "Eqv PRF:" << eqvPRF; - qDebug() << "Center Latitude:" << latitude_center << ", Longitude:" << longitude_center; - qDebug() << "Top Left Corner Latitude:" << latitude_topLeft << ", Longitude:" << longitude_topLeft; - qDebug() << "Top Right Corner Latitude:" << latitude_topRight << ", Longitude:" << longitude_topRight; - qDebug() << "Bottom Left Corner Latitude:" << latitude_bottomLeft << ", Longitude:" << longitude_bottomLeft; - qDebug() << "Bottom Right Corner Latitude:" << latitude_bottomRight << ", Longitude:" << longitude_bottomRight; - qDebug() << "Width:" << width; - qDebug() << "Height:" << height; - qDebug() << "Width Space:" << widthspace; - qDebug() << "Height Space:" << heightspace; - qDebug() << "Scene Shift:" << sceneShift; - qDebug() << "Image Bit:" << imagebit; - qDebug() << "HH Qualify Value:" << HH_QualifyValue; - qDebug() << "HV Qualify Value:" << HV_QualifyValue; - qDebug() << "HH Echo Saturation:" << HH_echoSaturation; - qDebug() << "HV Echo Saturation:" << HV_echoSaturation; - qDebug() << "incidenceAngleNearRange:" << incidenceAngleNearRange; - qDebug() << "incidenceAngleFarRange:" << incidenceAngleFarRange; + qDebug() << u8"\nImage Info Data:"; + qDebug() << u8"Start:" << start; + qDebug() << u8"End:" << end; + qDebug() << u8"Near Range:" << nearRange; + qDebug() << u8"Ref Range:" << refRange; + qDebug() << u8"Eqv Fs:" << eqvFs; + qDebug() << u8"Eqv PRF:" << eqvPRF; + qDebug() << u8"Center Latitude:" << latitude_center << ", Longitude:" << longitude_center; + qDebug() << u8"Top Left Corner Latitude:" << latitude_topLeft << ", Longitude:" << longitude_topLeft; + qDebug() << u8"Top Right Corner Latitude:" << latitude_topRight << ", Longitude:" << longitude_topRight; + qDebug() << u8"Bottom Left Corner Latitude:" << latitude_bottomLeft << ", Longitude:" << longitude_bottomLeft; + qDebug() << u8"Bottom Right Corner Latitude:" << latitude_bottomRight << ", Longitude:" << longitude_bottomRight; + qDebug() << u8"Width:" << width; + qDebug() << u8"Height:" << height; + qDebug() << u8"Width Space:" << widthspace; + qDebug() << u8"Height Space:" << heightspace; + qDebug() << u8"Scene Shift:" << sceneShift; + qDebug() << u8"Image Bit:" << imagebit; + qDebug() << u8"HH Qualify Value:" << HH_QualifyValue; + qDebug() << u8"HV Qualify Value:" << HV_QualifyValue; + qDebug() << u8"HH Echo Saturation:" << HH_echoSaturation; + qDebug() << u8"HV Echo Saturation:" << HV_echoSaturation; + qDebug() << u8"incidenceAngleNearRange:" << incidenceAngleNearRange; + qDebug() << u8"incidenceAngleFarRange:" << incidenceAngleFarRange; } } void SatelliteGF3xmlParser::parseAdditionalData() { - QDomElement calibrationConst = xml.firstChildElement("root").firstChildElement("CalibrationConst"); + QDomElement processinfo = xml.firstChildElement("product").firstChildElement("processinfo"); + QDomElement calibrationConst = processinfo.firstChildElement("CalibrationConst"); if (!calibrationConst.isNull()) { bool HH_CalibrationConstISNULL=false; @@ -201,50 +234,50 @@ void SatelliteGF3xmlParser::parseAdditionalData() { - qDebug() << "\nCalibration Const Data:"; - qDebug() << "HH Calibration Const:" << HH_CalibrationConst; - qDebug() << "HV Calibration Const:" << HV_CalibrationConst; - qDebug() << "VH Calibration Const:" << VH_CalibrationConst; - qDebug() << "VV Calibration Const:" << VV_CalibrationConst; + qDebug() << u8"\nCalibration Const Data:"; + qDebug() << u8"HH Calibration Const:" << HH_CalibrationConst; + qDebug() << u8"HV Calibration Const:" << HV_CalibrationConst; + qDebug() << u8"VH Calibration Const:" << VH_CalibrationConst; + qDebug() << u8"VV Calibration Const:" << VV_CalibrationConst; } - AzFdc0 = xml.firstChildElement("root").firstChildElement("AzFdc0").text().toDouble(); - AzFdc1 = xml.firstChildElement("root").firstChildElement("AzFdc1").text().toDouble(); + AzFdc0 = processinfo.firstChildElement("AzFdc0").text().toDouble(); + AzFdc1 = processinfo.firstChildElement("AzFdc1").text().toDouble(); + QDomElement sensorNode = xml.firstChildElement("product").firstChildElement("sensor"); + sensorID = sensorNode.firstChildElement("sensorID").text(); + imagingMode = sensorNode.firstChildElement("imagingMode").text(); + lamda = sensorNode.firstChildElement("lamda").text().toDouble(); + RadarCenterFrequency = sensorNode.firstChildElement("RadarCenterFrequency").text().toDouble(); - sensorID = xml.firstChildElement("root").firstChildElement("sensorID").text(); - imagingMode = xml.firstChildElement("root").firstChildElement("imagingMode").text(); - lamda = xml.firstChildElement("root").firstChildElement("lamda").text().toDouble(); - RadarCenterFrequency = xml.firstChildElement("root").firstChildElement("RadarCenterFrequency").text().toDouble(); + TotalProcessedAzimuthBandWidth = processinfo.firstChildElement("TotalProcessedAzimuthBandWidth").text().toDouble(); + DopplerParametersReferenceTime = processinfo.firstChildElement("DopplerParametersReferenceTime").text().toDouble(); - TotalProcessedAzimuthBandWidth = xml.firstChildElement("root").firstChildElement("TotalProcessedAzimuthBandWidth").text().toDouble(); - DopplerParametersReferenceTime = xml.firstChildElement("root").firstChildElement("DopplerParametersReferenceTime").text().toDouble(); - - QDomElement dopplerCentroidCoefficients = xml.firstChildElement("root").firstChildElement("DopplerCentroidCoefficients"); + QDomElement dopplerCentroidCoefficients = processinfo.firstChildElement("DopplerCentroidCoefficients"); d0 = dopplerCentroidCoefficients.firstChildElement("d0").text().toDouble(); d1 = dopplerCentroidCoefficients.firstChildElement("d1").text().toDouble(); d2 = dopplerCentroidCoefficients.firstChildElement("d2").text().toDouble(); d3 = dopplerCentroidCoefficients.firstChildElement("d3").text().toDouble(); d4 = dopplerCentroidCoefficients.firstChildElement("d4").text().toDouble(); - QDomElement dopplerRateValuesCoefficients = xml.firstChildElement("root").firstChildElement("DopplerRateValuesCoefficients"); + QDomElement dopplerRateValuesCoefficients = processinfo.firstChildElement("DopplerRateValuesCoefficients"); r0 = dopplerRateValuesCoefficients.firstChildElement("r0").text().toDouble(); r1 = dopplerRateValuesCoefficients.firstChildElement("r1").text().toDouble(); r2 = dopplerRateValuesCoefficients.firstChildElement("r2").text().toDouble(); r3 = dopplerRateValuesCoefficients.firstChildElement("r3").text().toDouble(); r4 = dopplerRateValuesCoefficients.firstChildElement("r4").text().toDouble(); - DEM = xml.firstChildElement("root").firstChildElement("DEM").text().toDouble(); + DEM = processinfo.firstChildElement("DEM").text().toDouble(); - qDebug() << "\nAdditional Data:"; - qDebug() << "AzFdc0:" << AzFdc0; - qDebug() << "AzFdc1:" << AzFdc1; - qDebug() << "Sensor ID:" << sensorID; - qDebug() << "Imaging Mode:" << imagingMode; - qDebug() << "Lambda:" << lamda; - qDebug() << "Radar Center Frequency:" << RadarCenterFrequency; - qDebug() << "Total Processed Azimuth Band Width:" << TotalProcessedAzimuthBandWidth; - qDebug() << "Doppler Parameters Reference Time:" << DopplerParametersReferenceTime; - qDebug() << "Doppler Centroid Coefficients: d0=" << d0 << ", d1=" << d1 << ", d2=" << d2 << ", d3=" << d3 << ", d4=" << d4; - qDebug() << "Doppler Rate Values Coefficients: r0=" << r0 << ", r1=" << r1 << ", r2=" << r2 << ", r3=" << r3 << ", r4=" << r4; - qDebug() << "DEM:" << DEM; + qDebug() << u8"\nAdditional Data:"; + qDebug() << u8"AzFdc0:" << AzFdc0; + qDebug() << u8"AzFdc1:" << AzFdc1; + qDebug() << u8"Sensor ID:" << sensorID; + qDebug() << u8"Imaging Mode:" << imagingMode; + qDebug() << u8"Lambda:" << lamda; + qDebug() << u8"Radar Center Frequency:" << RadarCenterFrequency; + qDebug() << u8"Total Processed Azimuth Band Width:" << TotalProcessedAzimuthBandWidth; + qDebug() << u8"Doppler Parameters Reference Time:" << DopplerParametersReferenceTime; + qDebug() << u8"Doppler Centroid Coefficients: d0=" << d0 << ", d1=" << d1 << ", d2=" << d2 << ", d3=" << d3 << ", d4=" << d4; + qDebug() << u8"Doppler Rate Values Coefficients: r0=" << r0 << ", r1=" << r1 << ", r2=" << r2 << ", r3=" << r3 << ", r4=" << r4; + qDebug() << u8"DEM:" << DEM; } From d45b3975608e479fb07cc387fc8d4784779777b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Fri, 18 Apr 2025 16:38:06 +0800 Subject: [PATCH 91/94] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=A4=9A=E6=99=AE?= =?UTF-8?q?=E5=8B=92=E8=AE=A1=E7=AE=97=E5=85=AC=E5=BC=8F=EF=BC=88=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E5=9C=B0=E9=80=9F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/SARSimulationImageL1.cpp | 17 +- .../BaseTool/SARSimulationImageL1.h | 2 + BaseCommonLibrary/ImageOperatorFuntion.cpp | 89 +++++------ Toolbox/BaseToolbox/BaseToolbox.vcxproj | 1 + .../GF3CalibrationAndGeocodingClass.cpp | 147 ++++++++++++------ .../BaseToolbox/QOrthSlrRaster.cpp | 8 +- 6 files changed, 163 insertions(+), 101 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/SARSimulationImageL1.cpp b/BaseCommonLibrary/BaseTool/SARSimulationImageL1.cpp index 8bc4245..2fbfbb8 100644 --- a/BaseCommonLibrary/BaseTool/SARSimulationImageL1.cpp +++ b/BaseCommonLibrary/BaseTool/SARSimulationImageL1.cpp @@ -251,6 +251,7 @@ void SARSimulationImageL1Dataset::saveToXml() xmlWriter.writeTextElement("Rref", QString::number(this->Rref, 'e', 18)); xmlWriter.writeTextElement("CenterFreq", QString::number(this->centerFreq, 'e', 18)); xmlWriter.writeTextElement("Fs", QString::number(this->Fs, 'e', 18)); + xmlWriter.writeTextElement("PRF", QString::number(this->prf, 'e', 18)); xmlWriter.writeTextElement("CenterAngle", QString::number(this->CenterAngle, 'e', 18)); xmlWriter.writeTextElement("LookSide", this->LookSide); @@ -371,6 +372,9 @@ ErrorCode SARSimulationImageL1Dataset::loadFromXml() else if (xmlReader.name() == "Fs") { this->Fs = xmlReader.readElementText().toDouble(); } + else if (xmlReader.name() == "PRF") { + this->prf = xmlReader.readElementText().toDouble(); + } else if(xmlReader.name() == "ImageStartTime"){ this->startImageTime = xmlReader.readElementText().toDouble(); } @@ -873,6 +877,7 @@ QVector SARSimulationImageL1Dataset::getDopplerParams() result[2] = d2; result[3] = d3; result[4] = d4; + return result; } @@ -888,11 +893,13 @@ void SARSimulationImageL1Dataset::setDopplerParams(double id0, double id1, doubl QVector SARSimulationImageL1Dataset::getDopplerCenterCoff() { QVector result(5); - result[0]=r0; - result[1]=r1; - result[2]=r2; - result[3]=r3; - result[4]=r4; + result[0] = r0; + result[1] = r1; + result[2] = r2; + result[3] = r3; + result[4] = r4; + + return result; } diff --git a/BaseCommonLibrary/BaseTool/SARSimulationImageL1.h b/BaseCommonLibrary/BaseTool/SARSimulationImageL1.h index 3d85682..6d8325a 100644 --- a/BaseCommonLibrary/BaseTool/SARSimulationImageL1.h +++ b/BaseCommonLibrary/BaseTool/SARSimulationImageL1.h @@ -143,9 +143,11 @@ public: double getDopplerParametersReferenceTime(); void setDopplerParametersReferenceTime(double v); + // ղ QVector getDopplerParams(); void setDopplerParams(double d0, double d1, double d2, double d3, double d4); + // ϵ QVector getDopplerCenterCoff(); void setDopplerCenterCoff(double r0, double r1, double r2, double r3, double r4); diff --git a/BaseCommonLibrary/ImageOperatorFuntion.cpp b/BaseCommonLibrary/ImageOperatorFuntion.cpp index ae75a14..a7ec078 100644 --- a/BaseCommonLibrary/ImageOperatorFuntion.cpp +++ b/BaseCommonLibrary/ImageOperatorFuntion.cpp @@ -633,8 +633,10 @@ void cropRasterByLatLon(const char* inputFile, const char* outputFile, double mi qDebug() << "Raster cropped and saved to: " << outputFile; // 清理 - GDALClose(poDataset); - GDALClose(poOutDataset); + + GDALClose((GDALDatasetH)(GDALDatasetH)poDataset); + GDALClose((GDALDatasetH)(GDALDatasetH)poOutDataset); + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH } ErrorCode transformCoordinate(double x, double y, int sourceEPSG, int targetEPSG, Point2& p) { @@ -763,8 +765,8 @@ void resampleRaster(const char* inputRaster, const char* outputRaster, double ta int nYSize = poDataset->GetRasterYSize(); // 计算目标栅格的尺寸 - double targetXSize = (adfGeoTransform[1] * nXSize) / targetPixelSizeX; - double targetYSize = std::abs((adfGeoTransform[5] * nYSize) / targetPixelSizeY); + double targetXSize = ceil((adfGeoTransform[1] * nXSize) / targetPixelSizeX); + double targetYSize = ceil(std::abs((adfGeoTransform[5] * nYSize) / targetPixelSizeY)); // 创建目标数据集(输出栅格) GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); @@ -774,38 +776,13 @@ void resampleRaster(const char* inputRaster, const char* outputRaster, double ta return; } - // 创建输出数据集 - GDALDataset* poOutDataset = poDriver->Create(outputRaster, (int)targetXSize, (int)targetYSize, poDataset->GetRasterCount(), GDT_Float32, nullptr); - if (poOutDataset == nullptr) { - qDebug() << "Failed to create output raster." ; - GDALClose(poDataset); - return; - } - // 设置输出数据集的地理变换(坐标系) double targetGeoTransform[6] = { adfGeoTransform[0], targetPixelSizeX, 0, adfGeoTransform[3], 0, -targetPixelSizeY }; - poOutDataset->SetGeoTransform(targetGeoTransform); - - // 设置输出数据集的投影信息 - poOutDataset->SetProjection(poDataset->GetProjectionRef()); - - // 进行重采样 - for (int i = 0; i < poDataset->GetRasterCount(); i++) { - GDALRasterBand* poBand = poDataset->GetRasterBand(i + 1); - GDALRasterBand* poOutBand = poOutDataset->GetRasterBand(i + 1); - - // 使用GDAL的重采样方法,选择一个适当的重采样方式 - poOutBand->RasterIO(GF_Write, 0, 0, (int)targetXSize, (int)targetYSize, - nullptr, (int)targetXSize, (int)targetYSize, - poBand->GetRasterDataType(), 0, 0, nullptr); - } - - // 关闭数据集 - GDALClose(poDataset); - GDALClose(poOutDataset); - + GDALClose((GDALDatasetH)(GDALDatasetH)poDataset); + GDALDestroy(); // or, DllMain at DLL_PROCESS_DETACH + ResampleGDAL(inputRaster, outputRaster, targetGeoTransform, targetXSize, targetYSize,GRA_Bilinear); qDebug() << "Resampling completed."; } @@ -1438,23 +1415,30 @@ void clipRaster(QString inRasterPath, QString outRasterPath, long minRow, long m ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QString demsloperPath) { - gdalImage demds(dempath); - gdalImage demxyz = CreategdalImage(demxyzpath, demds.height, demds.width, 3, demds.gt, demds.projection, true, true);// X,Y,Z + QString DEMPath = dempath; + QString XYZPath = demxyzpath; + QString SLOPERPath = demsloperPath; + + + + gdalImage demds(DEMPath); + gdalImage demxyz = CreategdalImageDouble(XYZPath, demds.height, demds.width, 3, demds.gt, demds.projection, true, true, false);// X,Y,Z // 分块计算并转换为XYZ - Eigen::MatrixXd demArr = demds.getData(0, 0, demds.height, demds.width, 1); - Eigen::MatrixXd demR = demArr; - Landpoint LandP{ 0,0,0 }; - Point3 GERpoint{ 0,0,0 }; + //Eigen::MatrixXd demArr = demds.getData(0, 0, demds.height, demds.width, 1); + //Eigen::MatrixXd demR = demArr; + double R = 0; double dem_row = 0, dem_col = 0, dem_alt = 0; - long line_invert = 1000; + long line_invert = Memory1MB / 8.0 / demds.width * 1000; + + - double rowidx = 0; - double colidx = 0; for (int max_rows_ids = 0; max_rows_ids < demds.height; max_rows_ids = max_rows_ids + line_invert) { + + Eigen::MatrixXd demdata = demds.getData(max_rows_ids, 0, line_invert, demds.width, 1); Eigen::MatrixXd xyzdata_x = demdata.array() * 0; Eigen::MatrixXd xyzdata_y = demdata.array() * 0; @@ -1463,7 +1447,12 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri int datarows = demdata.rows(); int datacols = demdata.cols(); +#pragma omp parallel for for (int i = 0; i < datarows; i++) { + Landpoint LandP{ 0,0,0 }; + Point3 GERpoint{ 0,0,0 }; + double rowidx = 0; + double colidx = 0; for (int j = 0; j < datacols; j++) { rowidx = i + max_rows_ids; colidx = j; @@ -1477,19 +1466,23 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri demxyz.saveImage(xyzdata_x, max_rows_ids, 0, 1); demxyz.saveImage(xyzdata_y, max_rows_ids, 0, 2); demxyz.saveImage(xyzdata_z, max_rows_ids, 0, 3); + } // 计算坡向角 - gdalImage demsloperxyz = CreategdalImage(demsloperPath, demds.height, demds.width, 4, demds.gt, demds.projection, true, true);// X,Y,Z,cosangle + + + + gdalImage demsloperxyz = CreategdalImageDouble(SLOPERPath, demds.height, demds.width, 4, demds.gt, demds.projection, true, true, false);// X,Y,Z,cosangle line_invert = 1000; long start_ids = 0; long dem_rows = 0, dem_cols = 0; - for (start_ids = 1; start_ids < demds.height; start_ids = start_ids + line_invert) { Eigen::MatrixXd demdata = demds.getData(start_ids - 1, 0, line_invert + 2, demxyz.width, 1); long startlineid = start_ids; + Eigen::MatrixXd demsloper_x = demsloperxyz.getData(start_ids - 1, 0, line_invert + 2, demxyz.width, 1); Eigen::MatrixXd demsloper_y = demsloperxyz.getData(start_ids - 1, 0, line_invert + 2, demxyz.width, 2); Eigen::MatrixXd demsloper_z = demsloperxyz.getData(start_ids - 1, 0, line_invert + 2, demxyz.width, 3); @@ -1498,13 +1491,13 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri Landpoint p0, p1, p2, p3, p4, pslopeVector, pp; Vector3D slopeVector; - dem_rows = demsloper_y.rows(); - dem_cols = demsloper_y.cols(); + dem_rows = demsloper_x.rows(); + dem_cols = demsloper_x.cols(); double sloperAngle = 0; Vector3D Zaxis = { 0,0,1 }; double rowidx = 0, colidx = 0; - + //#pragma omp parallel for for (long i = 1; i < dem_rows - 1; i++) { for (long j = 1; j < dem_cols - 1; j++) { rowidx = i + startlineid; @@ -1527,15 +1520,19 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri demsloper_y(i, j) = slopeVector.y; demsloper_z(i, j) = slopeVector.z; demsloper_angle(i, j) = sloperAngle; + } } + demsloperxyz.saveImage(demsloper_x, start_ids - 1, 0, 1); demsloperxyz.saveImage(demsloper_y, start_ids - 1, 0, 2); demsloperxyz.saveImage(demsloper_z, start_ids - 1, 0, 3); demsloperxyz.saveImage(demsloper_angle, start_ids - 1, 0, 4); + } + return ErrorCode::SUCCESS; } diff --git a/Toolbox/BaseToolbox/BaseToolbox.vcxproj b/Toolbox/BaseToolbox/BaseToolbox.vcxproj index 699771e..7fe5c9a 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.vcxproj +++ b/Toolbox/BaseToolbox/BaseToolbox.vcxproj @@ -122,6 +122,7 @@ true stdcpp14 stdc11 + Disabled diff --git a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp index dc3c8f9..a78cae3 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp @@ -212,7 +212,7 @@ ErrorCode ImportGF3L1AProcess(QString inMetaxmlPath, QString outWorkDirPath) ErrorCode RD_PSTN(double& refrange, double& lamda, double& timeR, double& R, double& tx, double& ty, double& tz, double& slopex, double& slopey, double& slopez, GF3PolyfitSatelliteOribtModel& polyfitmodel, SatelliteOribtNode& node, double& d0, double& d1, double& d2, double& d3, double& d4) { - double dt = 1e-6; + double dt = 1e-4; double inct = 0; bool antfalg = false; double timeR2 = 0; @@ -231,21 +231,21 @@ ErrorCode RD_PSTN(double& refrange, double& lamda, double& timeR, double& R, dou for (int i = 0; i < 50; i++) { polyfitmodel.getSatelliteOribtNode(timeR, node, antfalg); R1 = std::sqrt(std::pow(node.Px - tx, 2) + std::pow(node.Py - ty, 2) + std::pow(node.Pz - tz, 2)); - dplerTheory1 = (-2 / lamda) * (((node.Px - tx) * (node.Vx + EARTHWE * ty) + (node.Py - ty) * (node.Vy - EARTHWE * tz) + (node.Pz - tz) * (node.Vz - 0)) / R1); - dplerR = (R1 - refrange) * 1e6 / LIGHTSPEED; + dplerTheory1 = (-2 / lamda / R1) * ((node.Px - tx) * (node.Vx /*+ EARTHWE * ty*/) + (node.Py - ty) * (node.Vy /*- EARTHWE * tz*/) + (node.Pz - tz) * (node.Vz - 0)); + dplerR = (R1 - refrange) * 1e6 / LIGHTSPEED; // GF3 㹫ʽ dplerNumber1 = d0 + dplerR * d1 + std::pow(dplerR, 2) * d2 + std::pow(dplerR, 3) * d3 + std::pow(dplerR, 4) * d4; timeR2 = timeR + dt; polyfitmodel.getSatelliteOribtNode(timeR2, node, antfalg); R2 = std::sqrt(std::pow(node.Px - tx, 2) + std::pow(node.Py - ty, 2) + std::pow(node.Pz - tz, 2)); - dplerTheory2 = (-2 / lamda) * (((node.Px - tx) * (node.Vx + EARTHWE * ty) + (node.Py - ty) * (node.Vy - EARTHWE * tz) + (node.Pz - tz) * (node.Vz - 0)) / R2); - dplerR = (R2 - refrange) * 1e6 / LIGHTSPEED; - dplerNumber2 = d0 + dplerR * d1 + std::pow(dplerR, 2) * d2 + std::pow(dplerR, 3) * d3 + std::pow(dplerR, 4) * d4; - - inct = dt * (dplerTheory2 - dplerNumber1) / (dplerTheory1 - dplerTheory2); - if (std::abs(dplerTheory1 - dplerTheory2) < 1e-9 || std::abs(inct) < dt) { + dplerTheory2 = (-2 / lamda/R2) * ((node.Px - tx) * (node.Vx/* + EARTHWE * ty*/) + (node.Py - ty) * (node.Vy /*- EARTHWE * tz*/) + (node.Pz - tz) * (node.Vz - 0)); + + + inct = (dplerTheory2-dplerNumber1) / (dplerTheory2-dplerTheory1 ); + if (std::abs(dplerNumber1 - dplerTheory2) < 1e-6 || std::abs(inct) < 1.0e-4) { break; } + inct = std::abs(inct) < 10 ?inct*1.0e-2:inct*dt; timeR = timeR - inct; } R = R1; // б @@ -265,7 +265,7 @@ ErrorCode GF3RDCreateLookTable(QString inxmlPath, QString indemPath, QString out gdalImage rasterRC = CreategdalImage(outlooktablePath, demxyz.height, demxyz.width, 2, demxyz.gt, demxyz.projection, true, true);// X,Y,Z gdalImage localincangleRaster; if (localincAngleFlag) { - localincangleRaster = CreategdalImage(outLocalIncidenceAnglePath, demxyz.height, demxyz.width, 2, demxyz.gt, demxyz.projection, true, true);// X,Y,Z + localincangleRaster = CreategdalImage(outLocalIncidenceAnglePath, demxyz.height, demxyz.width, 1, demxyz.gt, demxyz.projection, true, true);// X,Y,Z } @@ -279,28 +279,48 @@ ErrorCode GF3RDCreateLookTable(QString inxmlPath, QString indemPath, QString out double d3 = dopplers[3]; double d4 = dopplers[4]; - double fs = l1dataset.getFs();// Fs - double prf = (l1dataset.getEndImageTime() - l1dataset.getStartImageTime()) / (l1dataset.getrowCount() - 1);// PRF + double fs = l1dataset.getFs()*1e6;// Fs + double prf = l1dataset.getPRF();// PRF double nearRange = l1dataset.getNearRange(); double imagestarttime = l1dataset.getStartImageTime(); + double imageendtime = l1dataset.getEndImageTime(); double refrange = l1dataset.getRefRange(); - double lamda = (LIGHTSPEED*1e-6)/ l1dataset.getCenterFreq(); + double lamda = (LIGHTSPEED*1.0e-9)/ l1dataset.getCenterFreq(); + // ӡ + qDebug() << "Fs:\t" << fs; + qDebug() << "prf:\t" << prf; + qDebug() << "nearRange:\t" << nearRange; + qDebug() << "imagestarttime:\t" << imagestarttime; + qDebug() << "imageendtime:\t" << imageendtime; + qDebug() << "refrange:\t" << refrange; + qDebug() << "lamda:\t" << lamda; + //ӡ۲ + qDebug() << u8"-----------------------------------"; + qDebug() << u8"ղ\n"; + qDebug() << u8"d0:\t" << d0; + qDebug() << u8"d1:\t" << d1; + qDebug() << u8"d2:\t" << d2; + qDebug() << u8"d3:\t" << d3; + qDebug() << u8"d4:\t" << d4; + qDebug() << u8"-----------------------------------"; // ģ GF3PolyfitSatelliteOribtModel polyfitmodel; QVector < SatelliteAntPos > antposes = l1dataset.getXmlSateAntPos(); - polyfitmodel.setSatelliteOribtStartTime(imagestarttime); + polyfitmodel.setSatelliteOribtStartTime((imagestarttime+imageendtime)/2); for (long i = 0; i < antposes.size(); i++) { - SatelliteOribtNode node; - node.time = antposes[i].time; - node.Px = antposes[i].Px; - node.Py = antposes[i].Py; - node.Pz = antposes[i].Pz; - node.Vx = antposes[i].Vx; - node.Vy = antposes[i].Vy; - node.Vz = antposes[i].Vz; - polyfitmodel.addOribtNode(node); + if (antposes[i].time > imagestarttime - 5 && antposes[i].time < imageendtime + 5) { + SatelliteOribtNode node; + node.time = antposes[i].time; + node.Px = antposes[i].Px; + node.Py = antposes[i].Py; + node.Pz = antposes[i].Pz; + node.Vx = antposes[i].Vx; + node.Vy = antposes[i].Vy; + node.Vz = antposes[i].Vz; + polyfitmodel.addOribtNode(node); + } } polyfitmodel.polyFit(3, false); @@ -312,7 +332,7 @@ ErrorCode GF3RDCreateLookTable(QString inxmlPath, QString indemPath, QString out // ʼұ //1.ֿ long cpucore_num = std::thread::hardware_concurrency(); - long blocklineinit = Memory1MB / 8 / cpucore_num / 4 / l1dataset.getcolCount() * 4000; + long blocklineinit = Memory1MB / 8 / cpucore_num / 4 / l1dataset.getcolCount() * 8000; blocklineinit = blocklineinit < 50 ? 50 : blocklineinit; //2. long colcount = rasterRC.width;//l1dataset.getcolCount(); @@ -333,7 +353,7 @@ ErrorCode GF3RDCreateLookTable(QString inxmlPath, QString indemPath, QString out -#pragma omp parallel for num_threads(cpucore_num-1) + for (startRId = 0; startRId < rowcount; startRId = startRId + blocklineinit) { long blockline = blocklineinit; if (startRId + blockline > rowcount) { @@ -345,25 +365,29 @@ ErrorCode GF3RDCreateLookTable(QString inxmlPath, QString indemPath, QString out Eigen::MatrixXd dem_y = demxyz.getData(startRId, 0, blockline, colcount, 2); Eigen::MatrixXd dem_z = demxyz.getData(startRId, 0, blockline, colcount, 3); - // ص - double timeR = 0; + long blockrows = sar_r.rows(); long blockcols = sar_r.cols(); - double tx = 0; - double ty = 0; - double tz = 0; - double R = 0; - double slopex=0, slopey=0, slopez=0; - SatelliteOribtNode node{0,0,0,0,0,0,0,0}; - bool antflag = false; + +#pragma omp parallel for for (long i = 0; i < blockrows; i++) { + // ص + double timeR = 0; + double tx = 0; + double ty = 0; + double tz = 0; + double R = 0; + double slopex = 0, slopey = 0, slopez = 0; + SatelliteOribtNode node{ 0,0,0,0,0,0,0,0 }; + bool antflag = false; for (long j = 0; j < blockcols; j++) { + tx = dem_x(i, j); ty = dem_y(i, j); tz = dem_z(i, j); if (RD_PSTN(refrange,lamda, timeR,R,tx,ty,tz,slopex,slopey,slopez,polyfitmodel,node,d0,d1,d2,d3,d4) == ErrorCode::SUCCESS) { - sar_r(i, j) = timeR * prf; - sar_c(i, j) = ((R - nearRange) / 2 / LIGHTSPEED) * fs; + sar_r(i, j) =( timeR+ (imagestarttime + imageendtime) / 2 -imagestarttime) * prf; + sar_c(i, j) = ((R - nearRange) * 2 / LIGHTSPEED) * fs; } else { sar_r(i, j) = -1; @@ -372,6 +396,14 @@ ErrorCode GF3RDCreateLookTable(QString inxmlPath, QString indemPath, QString out } } + // + omp_set_lock(&lock); + rasterRC.saveImage(sar_r, startRId, 0, 1); + rasterRC.saveImage(sar_c, startRId, 0, 2); + + omp_unset_lock(&lock); + + Eigen::MatrixXd Angle_Arr = Eigen::MatrixXd::Zero(dem_x.rows(),dem_x.cols()).array()+181; if (localincAngleFlag) { Eigen::MatrixXd demslope_x = demslope.getData(startRId, 0, blockline, colcount, 1); @@ -381,7 +413,20 @@ ErrorCode GF3RDCreateLookTable(QString inxmlPath, QString indemPath, QString out double Rst_x = 0, Rst_y = 0, Rst_z = 0, localangle = 0; double slopeR = 0; +#pragma omp parallel for for (long i = 0; i < blockrows; i++) { + // ص + double timeR = 0; + double tx = 0; + double ty = 0; + double tz = 0; + double R = 0; + double slopex = 0, slopey = 0, slopez = 0; + SatelliteOribtNode node{ 0,0,0,0,0,0,0,0 }; + bool antflag = false; + + + for (long j = 0; j < blockcols; j++) { timeR = sar_r(i, j) / prf; slopex = demslope_x(i, j); @@ -402,16 +447,23 @@ ErrorCode GF3RDCreateLookTable(QString inxmlPath, QString indemPath, QString out Angle_Arr(i, j) = localangle; } } + + // + omp_set_lock(&lock); + + if (localincAngleFlag) { + localincangleRaster.saveImage(Angle_Arr, startRId, 0, 1); + } + else {} + + omp_unset_lock(&lock); + } + // omp_set_lock(&lock); - rasterRC.saveImage(sar_r, startRId, 0, 1); - rasterRC.saveImage(sar_c, startRId, 0, 2); - if (localincAngleFlag) { - localincangleRaster.saveImage(Angle_Arr, startRId, 0, 1); - } - else {} + processNumber = processNumber + blockrows; qDebug() << u8"\rprocess bar:\t" << processNumber * 100.0 / rowcount << " % " << "\t\t\t"; if (progressDialog.maximum() <= processNumber) { @@ -431,7 +483,8 @@ ErrorCode GF3OrthSLC( QString inRasterPath, QString inlooktablePath, QString out gdalImage slcRaster(inRasterPath);// gdalImage looktableRaster(inlooktablePath);// - gdalImage outRaster(outRasterPath);// + gdalImage outRaster = CreategdalImage(outRasterPath, looktableRaster.height, looktableRaster.width, 1, looktableRaster.gt, looktableRaster.projection, true, true);// X,Y,Z + //gdalImage outRaster(outRasterPath);// if (outRaster.height != looktableRaster.height || outRaster.width != looktableRaster.width) { qDebug() << u8"look table size is not same as outRaster size"<< looktableRaster.height <<"!="< Date: Mon, 21 Apr 2025 09:56:53 +0800 Subject: [PATCH 92/94] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=20amp=20?= =?UTF-8?q?=E8=BD=ACdB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/ImageOperatorBase.h | 3 ++ BaseCommonLibrary/ImageOperatorFuntion.cpp | 42 ++++++++++++++----- .../GF3CalibrationAndGeocodingClass.cpp | 15 ++++--- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h index 9b52766..b16127d 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h @@ -325,6 +325,9 @@ void BASECONSTVARIABLEAPI MultiLookRaster(QString inRasterPath, QString outRast ErrorCode BASECONSTVARIABLEAPI Complex2PhaseRaster(QString inComplexPath, QString outRasterPath); ErrorCode BASECONSTVARIABLEAPI Complex2dBRaster(QString inComplexPath, QString outRasterPath); ErrorCode BASECONSTVARIABLEAPI Complex2AmpRaster(QString inComplexPath, QString outRasterPath); +ErrorCode BASECONSTVARIABLEAPI amp2dBRaster(QString inPath, QString outRasterPath); + + ErrorCode BASECONSTVARIABLEAPI ResampleDEM(QString indemPath, QString outdemPath, double gridx, double gridy); diff --git a/BaseCommonLibrary/ImageOperatorFuntion.cpp b/BaseCommonLibrary/ImageOperatorFuntion.cpp index a7ec078..ee94390 100644 --- a/BaseCommonLibrary/ImageOperatorFuntion.cpp +++ b/BaseCommonLibrary/ImageOperatorFuntion.cpp @@ -1437,7 +1437,7 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri for (int max_rows_ids = 0; max_rows_ids < demds.height; max_rows_ids = max_rows_ids + line_invert) { - + qDebug() << "dem -> XYZ [" << max_rows_ids*100.0/ demds.height << "] %" ; Eigen::MatrixXd demdata = demds.getData(max_rows_ids, 0, line_invert, demds.width, 1); Eigen::MatrixXd xyzdata_x = demdata.array() * 0; @@ -1488,17 +1488,17 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri Eigen::MatrixXd demsloper_z = demsloperxyz.getData(start_ids - 1, 0, line_invert + 2, demxyz.width, 3); Eigen::MatrixXd demsloper_angle = demsloperxyz.getData(start_ids - 1, 0, line_invert + 2, demxyz.width, 4); - Landpoint p0, p1, p2, p3, p4, pslopeVector, pp; - Vector3D slopeVector; - dem_rows = demsloper_x.rows(); dem_cols = demsloper_x.cols(); - double sloperAngle = 0; - Vector3D Zaxis = { 0,0,1 }; - double rowidx = 0, colidx = 0; - //#pragma omp parallel for +#pragma omp parallel for for (long i = 1; i < dem_rows - 1; i++) { + Landpoint p0, p1, p2, p3, p4, pslopeVector, pp; + Vector3D slopeVector; + double sloperAngle = 0; + Vector3D Zaxis = { 0,0,1 }; + + double rowidx = 0, colidx = 0; for (long j = 1; j < dem_cols - 1; j++) { rowidx = i + startlineid; colidx = j; @@ -1709,7 +1709,7 @@ ErrorCode Complex2PhaseRaster(QString inComplexPath, QString outRasterPath) for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); - imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); + imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 1); imgArrb1 = imgArr.array().arg(); ampimg.saveImage(imgArrb1, startrow, 0, 1); } @@ -1732,7 +1732,7 @@ ErrorCode Complex2dBRaster(QString inComplexPath, QString outRasterPath) for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); - imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); + imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 1); imgArrb1 = imgArr.array().abs().log10() * 20.0; ampimg.saveImage(imgArrb1, startrow, 0, 1); } @@ -1742,6 +1742,28 @@ ErrorCode Complex2dBRaster(QString inComplexPath, QString outRasterPath) +ErrorCode BASECONSTVARIABLEAPI amp2dBRaster(QString inPath, QString outRasterPath) +{ + gdalImage inimg(inPath); + gdalImage dBimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); + + long blocklines = Memory1GB * 2 / 8 / inimg.width; + blocklines = blocklines < 100 ? 100 : blocklines; + Eigen::MatrixXd imgArrdB = Eigen::MatrixXd::Zero(blocklines, dBimg.width); + Eigen::MatrixXd imgArr = Eigen::MatrixXd::Zero(blocklines, inimg.width); + + long startrow = 0; + for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { + + imgArrdB = dBimg.getData(startrow, 0, blocklines, inimg.width, 1); + imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 1); + imgArrdB = imgArr.array().log10() * 20.0; + dBimg.saveImage(imgArrdB, startrow, 0, 1); + } + qDebug() << "影像写入到:" << outRasterPath; + return ErrorCode::SUCCESS; +} + void MultiLookRaster(QString inRasterPath, QString outRasterPath, long looklineNumrow, long looklineNumCol) diff --git a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp index a78cae3..aadbd71 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp @@ -231,21 +231,24 @@ ErrorCode RD_PSTN(double& refrange, double& lamda, double& timeR, double& R, dou for (int i = 0; i < 50; i++) { polyfitmodel.getSatelliteOribtNode(timeR, node, antfalg); R1 = std::sqrt(std::pow(node.Px - tx, 2) + std::pow(node.Py - ty, 2) + std::pow(node.Pz - tz, 2)); - dplerTheory1 = (-2 / lamda / R1) * ((node.Px - tx) * (node.Vx /*+ EARTHWE * ty*/) + (node.Py - ty) * (node.Vy /*- EARTHWE * tz*/) + (node.Pz - tz) * (node.Vz - 0)); + //dplerTheory1 = (-2 / lamda / R1) * ((node.Px - tx) * (node.Vx + EARTHWE * ty) + (node.Py - ty) * (node.Vy - EARTHWE * tx) + (node.Pz - tz) * (node.Vz - 0)); + dplerTheory1 = (-2 / lamda / R1) * ((node.Px - tx) * (node.Vx + 0) + (node.Py - ty) * (node.Vy -0) + (node.Pz - tz) * (node.Vz - 0)); dplerR = (R1 - refrange) * 1e6 / LIGHTSPEED; // GF3 㹫ʽ dplerNumber1 = d0 + dplerR * d1 + std::pow(dplerR, 2) * d2 + std::pow(dplerR, 3) * d3 + std::pow(dplerR, 4) * d4; timeR2 = timeR + dt; polyfitmodel.getSatelliteOribtNode(timeR2, node, antfalg); R2 = std::sqrt(std::pow(node.Px - tx, 2) + std::pow(node.Py - ty, 2) + std::pow(node.Pz - tz, 2)); - dplerTheory2 = (-2 / lamda/R2) * ((node.Px - tx) * (node.Vx/* + EARTHWE * ty*/) + (node.Py - ty) * (node.Vy /*- EARTHWE * tz*/) + (node.Pz - tz) * (node.Vz - 0)); + //dplerTheory2 = (-2 / lamda/R2) * ((node.Px - tx) * (node.Vx + EARTHWE * ty) + (node.Py - ty) * (node.Vy - EARTHWE * tx) + (node.Pz - tz) * (node.Vz - 0)); + dplerTheory2 = (-2 / lamda/R2) * ((node.Px - tx) * (node.Vx +0) + (node.Py - ty) * (node.Vy -0) + (node.Pz - tz) * (node.Vz - 0)); + //dplerR = (R2 - refrange) * 1e6 / LIGHTSPEED; // GF3 㹫ʽ + //dplerNumber2 = d0 + dplerR * d1 + std::pow(dplerR, 2) * d2 + std::pow(dplerR, 3) * d3 + std::pow(dplerR, 4) * d4; - - inct = (dplerTheory2-dplerNumber1) / (dplerTheory2-dplerTheory1 ); + inct = dt*(dplerTheory2-dplerNumber1) / (dplerTheory2 - dplerTheory1); if (std::abs(dplerNumber1 - dplerTheory2) < 1e-6 || std::abs(inct) < 1.0e-4) { break; } - inct = std::abs(inct) < 10 ?inct*1.0e-2:inct*dt; + inct = std::abs(inct) < 10 ?inct:inct*1e-2; timeR = timeR - inct; } R = R1; // б @@ -603,7 +606,7 @@ ErrorCode GF3RDProcess(QString inxmlPath, QString indemPath, QString outworkdir, QString outlocalAnglePath = JoinPath(outworkdir, getFileNameWidthoutExtend(l1dataset.getxmlFilePath()) + "_localAngle.tif"); QString outOrthPath=JoinPath(outworkdir, getFileNameWidthoutExtend(l1dataset.getxmlFilePath()) + "_orth.tif"); - if (GF3RDCreateLookTable(inxmlPath, resampleDEMPath, outworkdir, outlooktablePath, outlocalAnglePath,true) != ErrorCode::SUCCESS) { + if (GF3RDCreateLookTable(inxmlPath, resampleDEMPath, outworkdir, outlooktablePath, outlocalAnglePath,true) != ErrorCode::SUCCESS) { qDebug() << u8"ұɴ\t" + getFileNameWidthoutExtend(inxmlPath); return ErrorCode::FAIL; } From e7849cbdeb34c0fef58f72ed3f7f5c0f62b53a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 21 Apr 2025 13:26:35 +0800 Subject: [PATCH 93/94] =?UTF-8?q?=E6=8B=86=E5=88=86=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E4=BB=BF=E7=9C=9F=E7=BA=A7=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RasterProcessToolWidget/ToolBoxWidget.cpp | 32 ++ RasterProcessToolWidget/ToolBoxWidget.h | 2 + Toolbox/BaseToolbox/BaseToolbox.cpp | 14 + Toolbox/BaseToolbox/BaseToolbox.vcxproj | 2 + .../BaseToolbox/BaseToolbox.vcxproj.filters | 6 + .../SARSatalliteSimulationWorkflow.cpp | 90 ++++++ .../SARSatalliteSimulationWorkflow.h | 64 ++++ .../SimulationSARTool/SimulationSARTool.cpp | 8 + .../SimulationSARTool.vcxproj | 2 + .../SimulationSARTool.vcxproj.filters | 6 + ...nSARToolSARSatalliteSimulationWorkflow.cpp | 273 ++++++++++++++++++ ...ionSARToolSARSatalliteSimulationWorkflow.h | 109 +++++++ 12 files changed, 608 insertions(+) create mode 100644 Toolbox/BaseToolbox/SARSatalliteSimulationWorkflow.cpp create mode 100644 Toolbox/BaseToolbox/SARSatalliteSimulationWorkflow.h create mode 100644 Toolbox/SimulationSARTool/SimulationSARToolSARSatalliteSimulationWorkflow.cpp create mode 100644 Toolbox/SimulationSARTool/SimulationSARToolSARSatalliteSimulationWorkflow.h diff --git a/RasterProcessToolWidget/ToolBoxWidget.cpp b/RasterProcessToolWidget/ToolBoxWidget.cpp index 5bb44ae..86a5234 100644 --- a/RasterProcessToolWidget/ToolBoxWidget.cpp +++ b/RasterProcessToolWidget/ToolBoxWidget.cpp @@ -25,6 +25,7 @@ ToolBoxWidget::ToolBoxWidget(LAMPMainWidget::RasterMainWidget* mainWindows, QWid ui->setupUi(this); setContextMenuPolicy(Qt::CustomContextMenu); // Ҽݲ˵ QObject::connect(this, SIGNAL(addBoxToolItemSIGNAL(QToolAbstract*)), this, SLOT(addBoxToolItemSLOT(QToolAbstract*))); + QObject::connect(this, SIGNAL(addBoxToolItemInPathSIGNAL(QVector , QToolAbstract* )), this, SLOT(addBoxToolItemInPathSLOT(QVector, QToolAbstract * ))); } @@ -122,6 +123,37 @@ void ToolBoxWidget::addBoxToolItemSLOT(QToolAbstract* item) } +void ToolBoxWidget::addBoxToolItemInPathSLOT(QVector xnodepath, QToolAbstract* item) +{ + QString toolName = item->getToolName(); + + QTreeWidgetItem* parentItem = findOrCreateParentItem(xnodepath); + + // øǷѾ toolButton + if (parentItem && ui->treeWidgetToolBox->itemWidget(parentItem, 0) == nullptr) { + + toollist.append(QToolboxTreeWidgetItem(ui->treeWidgetToolBox, parentItem, item)); + + + //QTreeWidgetItem* actionItem = new QTreeWidgetItem(parentItem); + //parentItem->addChild(actionItem); + //actionItem->setText(0,toolName); + //QIcon icon(QString::fromUtf8(":/ToolBoxWidget/toolicon")); + //QPushButton* button = new QPushButton(ui->treeWidgetToolBox); + //button->setIcon(icon); + //button->setText(toolName); + //button->setLayoutDirection(Qt::LeftToRight); + //button->setStyleSheet("QPushButton { text-align: left; }"); + //ui->treeWidgetToolBox->setItemWidget(actionItem, 0, button); + //connect(button, SIGNAL(clicked()), item, SLOT(excute())); + //item->setParent(ui->treeWidgetToolBox); + //qDebug() << "ToolButton bound to parent:" << actionItem->text(0); + } + else { + qDebug() << "ToolButton already bound to parent:" << parentItem->text(0); + } +} + // ·һ򴴽 QTreeWidgetItem* ToolBoxWidget::findOrCreateParentItem( QVector& path) { QTreeWidgetItem* currentItem = nullptr; diff --git a/RasterProcessToolWidget/ToolBoxWidget.h b/RasterProcessToolWidget/ToolBoxWidget.h index 39f7c48..fc84b7b 100644 --- a/RasterProcessToolWidget/ToolBoxWidget.h +++ b/RasterProcessToolWidget/ToolBoxWidget.h @@ -49,9 +49,11 @@ private: signals: void addBoxToolItemSIGNAL(QToolAbstract* item); + void addBoxToolItemInPathSIGNAL(QVector xnodepath, QToolAbstract* item); public slots: void addBoxToolItemSLOT(QToolAbstract* item); + void addBoxToolItemInPathSLOT(QVector xnodepath, QToolAbstract* item); QTreeWidgetItem* findOrCreateParentItem( QVector& path); QTreeWidgetItem* findOrCreateTopLevelItem( QString& name); QTreeWidgetItem* findChildItemByName(QTreeWidgetItem* parentItem, QString& name); diff --git a/Toolbox/BaseToolbox/BaseToolbox.cpp b/Toolbox/BaseToolbox/BaseToolbox.cpp index 8d35a95..22ed9c8 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox.cpp @@ -15,6 +15,8 @@ #include "QtCreateGPSPointsDialog.h" #include "RasterVRT2ENVIdataDialog.h" +#include "SARSatalliteSimulationWorkflow.h" // 󳡾 + GF3ImportDataToolButton::GF3ImportDataToolButton(QWidget* parent) :QToolAbstract(parent) { this->toolPath = QVector(0); @@ -117,6 +119,18 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QLookTableCorrectOffsetToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QCreateGPSPointsToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new RasterVRT2ENVIdataDialogToolButton(toolbox)); + + + // 󳡾 +#ifdef __BASETOOLBOX__SARSATALLITESIMULATIONWORKFLOW__H__ + initBaseToolSARSateSimulationWorkflow(toolbox); +#endif // __BASETOOLBOX__SARSATALLITESIMULATIONWORKFLOW__H__ + + + + + + } QDEMResampleDialogToolButton::QDEMResampleDialogToolButton(QWidget* parent) diff --git a/Toolbox/BaseToolbox/BaseToolbox.vcxproj b/Toolbox/BaseToolbox/BaseToolbox.vcxproj index 7fe5c9a..1ace8fc 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.vcxproj +++ b/Toolbox/BaseToolbox/BaseToolbox.vcxproj @@ -213,6 +213,8 @@ + + diff --git a/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters b/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters index 0eb5ad3..dbe0ff5 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters +++ b/Toolbox/BaseToolbox/BaseToolbox.vcxproj.filters @@ -109,6 +109,9 @@ BaseToolbox + + Source Files + @@ -153,6 +156,9 @@ BaseToolbox + + Header Files + diff --git a/Toolbox/BaseToolbox/SARSatalliteSimulationWorkflow.cpp b/Toolbox/BaseToolbox/SARSatalliteSimulationWorkflow.cpp new file mode 100644 index 0000000..4abfdf5 --- /dev/null +++ b/Toolbox/BaseToolbox/SARSatalliteSimulationWorkflow.cpp @@ -0,0 +1,90 @@ +#include "SARSatalliteSimulationWorkflow.h" +#include "QtCreateGPSPointsDialog.h" +#include "QResampleRefrenceRaster.h" +#include "DEMLLA2XYZTool.h" + + +void initBaseToolSARSateSimulationWorkflow(ToolBoxWidget* toolbox) +{ + // 1. иɹڵ + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B"}, new TLE2SatePositionVelocityToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C"}, new TLE2SatePositionVelocityToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A"}, new TLE2SatePositionVelocityToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B"}, new TLE2SatePositionVelocityToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E"}, new TLE2SatePositionVelocityToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F"}, new TLE2SatePositionVelocityToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04"}, new TLE2SatePositionVelocityToolButton(toolbox)); + + // 3. Ӱ + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B"}, new QAligendLandClsAndDEMToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C"}, new QAligendLandClsAndDEMToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A"}, new QAligendLandClsAndDEMToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B"}, new QAligendLandClsAndDEMToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E"}, new QAligendLandClsAndDEMToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F"}, new QAligendLandClsAndDEMToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04"}, new QAligendLandClsAndDEMToolButton(toolbox)); + + + // 4. عʸӰ + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B"}, new QDEMLLA2XYZSloperVectorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C"}, new QDEMLLA2XYZSloperVectorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A"}, new QDEMLLA2XYZSloperVectorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B"}, new QDEMLLA2XYZSloperVectorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E"}, new QDEMLLA2XYZSloperVectorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F"}, new QDEMLLA2XYZSloperVectorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04"}, new QDEMLLA2XYZSloperVectorToolButton(toolbox)); + + + + + + +} + +TLE2SatePositionVelocityToolButton::TLE2SatePositionVelocityToolButton(QWidget* parent) +{ + this->toolname = QString(u8"1.иɹڵ"); +} + +TLE2SatePositionVelocityToolButton::~TLE2SatePositionVelocityToolButton() +{ +} + +void TLE2SatePositionVelocityToolButton::run() +{ + QtCreateGPSPointsDialog* dialog = new QtCreateGPSPointsDialog; + dialog->setWindowTitle(u8"иɹڵ"); + dialog->show(); +} + +QAligendLandClsAndDEMToolButton::QAligendLandClsAndDEMToolButton(QWidget* parent) +{ + this->toolname = QString(u8"3.Ӱ"); +} + +QAligendLandClsAndDEMToolButton::~QAligendLandClsAndDEMToolButton() +{ +} + +void QAligendLandClsAndDEMToolButton::run() +{ + QResampleRefrenceRaster* dialog = new QResampleRefrenceRaster; + dialog->setWindowTitle(u8"ΣݵդزӰ"); + dialog->show(); +} + +QDEMLLA2XYZSloperVectorToolButton::QDEMLLA2XYZSloperVectorToolButton(QWidget* parent) +{ + this->toolname = QString(u8"4.ɵĿʸ"); +} + +QDEMLLA2XYZSloperVectorToolButton::~QDEMLLA2XYZSloperVectorToolButton() +{ +} + +void QDEMLLA2XYZSloperVectorToolButton::run() +{ + DEMLLA2XYZTool* dialog = new DEMLLA2XYZTool(); + dialog->setWindowTitle(u8"ݵդɵĿʸ"); + dialog->show(); +} diff --git a/Toolbox/BaseToolbox/SARSatalliteSimulationWorkflow.h b/Toolbox/BaseToolbox/SARSatalliteSimulationWorkflow.h new file mode 100644 index 0000000..9f447b9 --- /dev/null +++ b/Toolbox/BaseToolbox/SARSatalliteSimulationWorkflow.h @@ -0,0 +1,64 @@ +#pragma once + + +#ifndef __BASETOOLBOX__SARSATALLITESIMULATIONWORKFLOW__H__ +#define __BASETOOLBOX__SARSATALLITESIMULATIONWORKFLOW__H__ + + +/** + * \file SARSatalliteSimulationWorkflow.h + * \brief 󳡾洦˵ + * + * \author 30453 + * \date April 2025 + * + **/ +#include "basetoolbox_global.h" +#include "ToolBoxWidget.h" + + +extern "C" BASETOOLBOX_EXPORT void initBaseToolSARSateSimulationWorkflow(ToolBoxWidget* toolbox); + + + + +class BASETOOLBOX_EXPORT TLE2SatePositionVelocityToolButton : public QToolAbstract { + Q_OBJECT +public: + TLE2SatePositionVelocityToolButton(QWidget* parent = nullptr); + ~TLE2SatePositionVelocityToolButton(); +public: + virtual void run() override; + +}; + + + +class BASETOOLBOX_EXPORT QAligendLandClsAndDEMToolButton : public QToolAbstract { + Q_OBJECT +public: + QAligendLandClsAndDEMToolButton(QWidget* parent = nullptr); + ~QAligendLandClsAndDEMToolButton(); +public : + virtual void run() override; + +}; + +class BASETOOLBOX_EXPORT QDEMLLA2XYZSloperVectorToolButton : public QToolAbstract { + Q_OBJECT +public: + QDEMLLA2XYZSloperVectorToolButton(QWidget* parent = nullptr); + ~QDEMLLA2XYZSloperVectorToolButton(); +public: + virtual void run() override; + +}; + + + + + +#endif + + + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index 438dd61..0065394 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -16,6 +16,7 @@ #include "QLonLatInterpAtiFromDEM.h" #include "QL1ASARProcessDialog.h" +#include "SimulationSARToolSARSatalliteSimulationWorkflow.h" void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox) { @@ -36,6 +37,13 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QLonLatInterpAtiFromDEMToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QL1ASARProcessDialogToolButton(toolbox)); +#ifdef __SIMULATIONSARTOOL__SARSATALLITESIMULATIONWORKFLOW__H__ + + initSimulationSARToolSARSateSimulationWorkflow(toolbox); +#endif + + + } diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index e4bdf9f..6c19a14 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -225,6 +225,7 @@ + @@ -260,6 +261,7 @@ + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index e32b42e..20c001f 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -163,6 +163,9 @@ SARImage + + Source Files + @@ -278,6 +281,9 @@ SARImage + + Header Files + diff --git a/Toolbox/SimulationSARTool/SimulationSARToolSARSatalliteSimulationWorkflow.cpp b/Toolbox/SimulationSARTool/SimulationSARToolSARSatalliteSimulationWorkflow.cpp new file mode 100644 index 0000000..46cab17 --- /dev/null +++ b/Toolbox/SimulationSARTool/SimulationSARToolSARSatalliteSimulationWorkflow.cpp @@ -0,0 +1,273 @@ +#include "SimulationSARToolSARSatalliteSimulationWorkflow.h" +#include "QSimulationSARPolynomialOrbitModel.h" +#include "QtSimulationGeoSARSigma0Dialog.h" +#include +#include +#include +#include +#include +#include +#include + +SIMULATIONSARTOOL_EXPORT void initSimulationSARToolSARSateSimulationWorkflow(ToolBoxWidget* toolbox) +{ + // 2. ڵģ + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B"}, new QPolyfitSatelliteGPSModelToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C"}, new QPolyfitSatelliteGPSModelToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A"}, new QPolyfitSatelliteGPSModelToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B"}, new QPolyfitSatelliteGPSModelToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E"}, new QPolyfitSatelliteGPSModelToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F"}, new QPolyfitSatelliteGPSModelToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04"}, new QPolyfitSatelliteGPSModelToolButton(toolbox)); + + + // 5. DEMͷϢSARͼģ + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B",u8"DEMͷϢSARͼģ"}, new QGeneratorGeoSimulationRsaterToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C",u8"DEMͷϢSARͼģ"}, new QGeneratorGeoSimulationRsaterToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A",u8"DEMͷϢSARͼģ"}, new QGeneratorGeoSimulationRsaterToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B",u8"DEMͷϢSARͼģ"}, new QGeneratorGeoSimulationRsaterToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E",u8"DEMͷϢSARͼģ"}, new QGeneratorGeoSimulationRsaterToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F",u8"DEMͷϢSARͼģ"}, new QGeneratorGeoSimulationRsaterToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04",u8"DEMͷϢSARͼģ"}, new QGeneratorGeoSimulationRsaterToolButton(toolbox)); + + + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"DEMͷϢSARͼģ"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"DEMͷϢSARͼģ"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"DEMͷϢSARͼģ"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"DEMͷϢSARͼģ"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"DEMͷϢSARͼģ"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"DEMͷϢSARͼģ"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"DEMͷϢSARͼģ"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + + + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"DEMͷϢSARͼģ"}, new QSimulationSlrSARRasterToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"DEMͷϢSARͼģ"}, new QSimulationSlrSARRasterToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"DEMͷϢSARͼģ"}, new QSimulationSlrSARRasterToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"DEMͷϢSARͼģ"}, new QSimulationSlrSARRasterToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"DEMͷϢSARͼģ"}, new QSimulationSlrSARRasterToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"DEMͷϢSARͼģ"}, new QSimulationSlrSARRasterToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"DEMͷϢSARͼģ"}, new QSimulationSlrSARRasterToolButton(toolbox)); + + + + + //6. ڻز + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"ڻز"}, new QEchoDataSimulationSARRFPCToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"ڻز"}, new QEchoDataSimulationSARRFPCToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"ڻز"}, new QEchoDataSimulationSARRFPCToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"ڻز"}, new QEchoDataSimulationSARRFPCToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"ڻز"}, new QEchoDataSimulationSARRFPCToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"ڻز"}, new QEchoDataSimulationSARRFPCToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"ڻز"}, new QEchoDataSimulationSARRFPCToolButton(toolbox)); + + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + + + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); + + + + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + + + + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); + + + + + + + + + + + + + + + + + + + + + return ; +} + +QPolyfitSatelliteGPSModelToolButton::QPolyfitSatelliteGPSModelToolButton(QWidget* parent) +{ + this->toolname = QString(u8"2.ݹڵϹģ"); +} + +QPolyfitSatelliteGPSModelToolButton::~QPolyfitSatelliteGPSModelToolButton() +{ +} + +void QPolyfitSatelliteGPSModelToolButton::run() +{ + QSimulationPolynomialSAROrbitModel* dialog = new QSimulationPolynomialSAROrbitModel; + dialog->setWindowTitle(u8"ݹڵϹģ"); + dialog->show(); +} + +QGeneratorGeoSimulationRsaterToolButton::QGeneratorGeoSimulationRsaterToolButton(QWidget* parent) +{ + this->toolname = QString(u8"1.ɵؾģӰ"); +} + +QGeneratorGeoSimulationRsaterToolButton::~QGeneratorGeoSimulationRsaterToolButton() +{ +} + +void QGeneratorGeoSimulationRsaterToolButton::run() +{ + QtSimulationGeoSARSigma0Dialog* dialog = new QtSimulationGeoSARSigma0Dialog; + dialog->setWindowTitle(u8"ɵؾģӰ"); + dialog->show(); +} + +QGeneratorMapGeoAndSltLookTableToolButton::QGeneratorMapGeoAndSltLookTableToolButton(QWidget* parent) +{ + this->toolname = QString(u8"2.ӳ"); +} + +QGeneratorMapGeoAndSltLookTableToolButton::~QGeneratorMapGeoAndSltLookTableToolButton() +{ +} + +void QGeneratorMapGeoAndSltLookTableToolButton::run() +{ + QSimulationLookTableDialog* dialog = new QSimulationLookTableDialog; + dialog->setWindowTitle(u8"ؾ-бӳ"); + dialog->show(); +} + +QSimulationSlrSARRasterToolButton::QSimulationSlrSARRasterToolButton(QWidget* parent) +{ + this->toolname = QString(u8"3.бģӰ"); +} + +QSimulationSlrSARRasterToolButton::~QSimulationSlrSARRasterToolButton() +{ +} + +void QSimulationSlrSARRasterToolButton::run() +{ + QCreateSARIntensityByLookTableDialog* dialog = new QCreateSARIntensityByLookTableDialog; + dialog->setWindowTitle(u8"бģӰ"); + dialog->show(); +} + +QEchoDataSimulationSARRFPCToolButton::QEchoDataSimulationSARRFPCToolButton(QWidget* parent) +{ + this->toolname = QString(u8"1.Ƶɷ"); +} + +QEchoDataSimulationSARRFPCToolButton::~QEchoDataSimulationSARRFPCToolButton() +{ +} + +void QEchoDataSimulationSARRFPCToolButton::run() +{ + QImageSARRFPC* dialog = new QImageSARRFPC(); + dialog->setWindowTitle(u8"ɻز-Ƶɷ"); + dialog->show(); +} + +QInSARImageNetGeneratorToolButton::QInSARImageNetGeneratorToolButton(QWidget* parent) +{ + this->toolname = QString(u8"1."); +} + +QInSARImageNetGeneratorToolButton::~QInSARImageNetGeneratorToolButton() +{ +} + +void QInSARImageNetGeneratorToolButton::run() +{ + QCreateInSARImagePlaneXYZRDialog* dialog = new QCreateInSARImagePlaneXYZRDialog; + dialog->setWindowTitle(u8"ƽ񻮷"); + dialog->show(); +} + +QMapLooktableToolButton::QMapLooktableToolButton(QWidget* parent) +{ + this->toolname = QString(u8"3.ұ"); +} + +QMapLooktableToolButton::~QMapLooktableToolButton() +{ +} + +void QMapLooktableToolButton::run() +{ + QLookTableResampleFromWGS84ToRange* dialog = new QLookTableResampleFromWGS84ToRange; + dialog->setWindowTitle(u8"˫ұ"); + dialog->show(); +} + +QSimulationBPImageMultiProductionLevel1_2ToolButton::QSimulationBPImageMultiProductionLevel1_2ToolButton(QWidget* parent) +{ + this->toolname = QString(u8"4. 1~2Ʒ"); +} + +QSimulationBPImageMultiProductionLevel1_2ToolButton::~QSimulationBPImageMultiProductionLevel1_2ToolButton() +{ +} + +void QSimulationBPImageMultiProductionLevel1_2ToolButton::run() +{ + QSimulationBPImageMultiProduction* dialog = new QSimulationBPImageMultiProduction; + dialog->setWindowTitle(u8"1~2Ʒ"); + dialog->show(); +} + +QSimulationBPImageL1BToolButton::QSimulationBPImageL1BToolButton(QWidget* parent) +{ + this->toolname = QString(u8"4. L1BƷ"); + +} + +QSimulationBPImageL1BToolButton::~QSimulationBPImageL1BToolButton() +{ +} + +void QSimulationBPImageL1BToolButton::run() +{ + QL1ASARProcessDialog* dialog = new QL1ASARProcessDialog; + dialog->setWindowTitle(u8"L1BƷ"); + dialog->show(); +} diff --git a/Toolbox/SimulationSARTool/SimulationSARToolSARSatalliteSimulationWorkflow.h b/Toolbox/SimulationSARTool/SimulationSARToolSARSatalliteSimulationWorkflow.h new file mode 100644 index 0000000..c5893d9 --- /dev/null +++ b/Toolbox/SimulationSARTool/SimulationSARToolSARSatalliteSimulationWorkflow.h @@ -0,0 +1,109 @@ +#pragma once +#ifndef __SIMULATIONSARTOOL__SARSATALLITESIMULATIONWORKFLOW__H__ +#define __SIMULATIONSARTOOL__SARSATALLITESIMULATIONWORKFLOW__H__ +#include "simulationsartool_global.h" +#include +#include "ToolBoxWidget.h" +#include "QToolAbstract.h" + + +extern "C" SIMULATIONSARTOOL_EXPORT void initSimulationSARToolSARSateSimulationWorkflow(ToolBoxWidget* toolbox); + + + +class SIMULATIONSARTOOL_EXPORT QPolyfitSatelliteGPSModelToolButton : public QToolAbstract { + Q_OBJECT +public: + QPolyfitSatelliteGPSModelToolButton(QWidget* parent = nullptr); + ~QPolyfitSatelliteGPSModelToolButton(); +public: + virtual void run() override; + +}; + +class SIMULATIONSARTOOL_EXPORT QGeneratorGeoSimulationRsaterToolButton : public QToolAbstract { + Q_OBJECT +public: + QGeneratorGeoSimulationRsaterToolButton(QWidget* parent = nullptr); + ~QGeneratorGeoSimulationRsaterToolButton(); +public: + virtual void run() override; + +}; + +class SIMULATIONSARTOOL_EXPORT QGeneratorMapGeoAndSltLookTableToolButton : public QToolAbstract { + Q_OBJECT +public: + QGeneratorMapGeoAndSltLookTableToolButton(QWidget* parent = nullptr); + ~QGeneratorMapGeoAndSltLookTableToolButton(); +public: + virtual void run() override; + +}; + +class SIMULATIONSARTOOL_EXPORT QSimulationSlrSARRasterToolButton : public QToolAbstract { + Q_OBJECT +public: + QSimulationSlrSARRasterToolButton(QWidget* parent = nullptr); + ~QSimulationSlrSARRasterToolButton(); +public: + virtual void run() override; + +}; + + + + +class SIMULATIONSARTOOL_EXPORT QEchoDataSimulationSARRFPCToolButton : public QToolAbstract { + Q_OBJECT +public: + QEchoDataSimulationSARRFPCToolButton(QWidget* parent = nullptr); + ~QEchoDataSimulationSARRFPCToolButton(); +public: + virtual void run() override; + +}; + + +class SIMULATIONSARTOOL_EXPORT QInSARImageNetGeneratorToolButton : public QToolAbstract { + Q_OBJECT +public: + QInSARImageNetGeneratorToolButton(QWidget* parent = nullptr); + ~QInSARImageNetGeneratorToolButton(); +public: + virtual void run() override; + +}; + +class SIMULATIONSARTOOL_EXPORT QMapLooktableToolButton : public QToolAbstract { + Q_OBJECT +public: + QMapLooktableToolButton(QWidget* parent = nullptr); + ~QMapLooktableToolButton(); +public: + virtual void run() override; + +}; + +class SIMULATIONSARTOOL_EXPORT QSimulationBPImageMultiProductionLevel1_2ToolButton : public QToolAbstract { + Q_OBJECT +public: + QSimulationBPImageMultiProductionLevel1_2ToolButton(QWidget* parent = nullptr); + ~QSimulationBPImageMultiProductionLevel1_2ToolButton(); +public: + virtual void run() override; + +}; + +class SIMULATIONSARTOOL_EXPORT QSimulationBPImageL1BToolButton : public QToolAbstract { + Q_OBJECT +public: + QSimulationBPImageL1BToolButton(QWidget* parent = nullptr); + ~QSimulationBPImageL1BToolButton(); +public: + virtual void run() override; + +}; + + +#endif From 1bb5b168c1d3ba368f0904ffeae8dcd942beee0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Mon, 21 Apr 2025 14:51:40 +0800 Subject: [PATCH 94/94] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=AE=B1=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LAMPDataProcess.sln | 28 +++--- RasterProcessToolWidget/ToolBoxWidget.cpp | 12 ++- .../SARSatalliteSimulationWorkflow.cpp | 6 +- ...nSARToolSARSatalliteSimulationWorkflow.cpp | 90 ++++++++----------- 4 files changed, 64 insertions(+), 72 deletions(-) diff --git a/LAMPDataProcess.sln b/LAMPDataProcess.sln index 1f54f80..0559e59 100644 --- a/LAMPDataProcess.sln +++ b/LAMPDataProcess.sln @@ -38,10 +38,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RasterMainWidgetGUI", "Rast EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImageshowTool", "ImageshowTool\ImageshowTool.vcxproj", "{8C8CA066-A93A-4098-9A46-B855EFEAADF2}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SPG4Tool", "SPG4Tool\SPG4Tool.vcxproj", "{80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pluginToolboxLibrary", "pluginToolboxLibrary\pluginToolboxLibrary.vcxproj", "{667625A5-8DE2-4373-99F0-8BAD2CCED011}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SPG4Tool", "SPG4Tool\SPG4Tool.vcxproj", "{80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM = Debug|ARM @@ -172,18 +172,6 @@ Global {8C8CA066-A93A-4098-9A46-B855EFEAADF2}.Release|x64.Build.0 = Release|x64 {8C8CA066-A93A-4098-9A46-B855EFEAADF2}.Release|x86.ActiveCfg = Release|x64 {8C8CA066-A93A-4098-9A46-B855EFEAADF2}.Release|x86.Build.0 = Release|x64 - {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|ARM.ActiveCfg = Debug|x64 - {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|ARM.Build.0 = Debug|x64 - {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|x64.ActiveCfg = Debug|x64 - {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|x64.Build.0 = Debug|x64 - {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|x86.ActiveCfg = Debug|x64 - {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|x86.Build.0 = Debug|x64 - {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|ARM.ActiveCfg = Release|x64 - {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|ARM.Build.0 = Release|x64 - {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x64.ActiveCfg = Release|x64 - {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x64.Build.0 = Release|x64 - {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x86.ActiveCfg = Release|x64 - {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x86.Build.0 = Release|x64 {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Debug|ARM.ActiveCfg = Debug|x64 {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Debug|ARM.Build.0 = Debug|x64 {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Debug|x64.ActiveCfg = Debug|x64 @@ -196,6 +184,18 @@ Global {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Release|x64.Build.0 = Release|x64 {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Release|x86.ActiveCfg = Release|Win32 {667625A5-8DE2-4373-99F0-8BAD2CCED011}.Release|x86.Build.0 = Release|Win32 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|ARM.ActiveCfg = Debug|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|ARM.Build.0 = Debug|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|x64.ActiveCfg = Debug|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|x64.Build.0 = Debug|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|x86.ActiveCfg = Debug|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Debug|x86.Build.0 = Debug|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|ARM.ActiveCfg = Release|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|ARM.Build.0 = Release|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x64.ActiveCfg = Release|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x64.Build.0 = Release|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x86.ActiveCfg = Release|x64 + {80A5854F-6F80-4EC2-9F73-84E0F4DB8D7E}.Release|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/RasterProcessToolWidget/ToolBoxWidget.cpp b/RasterProcessToolWidget/ToolBoxWidget.cpp index 86a5234..d0a9ae4 100644 --- a/RasterProcessToolWidget/ToolBoxWidget.cpp +++ b/RasterProcessToolWidget/ToolBoxWidget.cpp @@ -203,7 +203,17 @@ QTreeWidgetItem* ToolBoxWidget::findChildItemByName(QTreeWidgetItem* parentItem, return childItem; } } - return nullptr; + + + // ûҵµĶڵ + QTreeWidgetItem* newItem = new QTreeWidgetItem(parentItem); + QIcon icon(QString::fromUtf8(":/RasterProcessTool/toolboxIcon")); + newItem->setIcon(0, icon); + newItem->setTextAlignment(0, Qt::AlignLeft); + newItem->setText(0, name); + parentItem->addChild(newItem); + return newItem; + // return nullptr; } void ToolBoxWidget::OpenToolboxManagerWidget() diff --git a/Toolbox/BaseToolbox/SARSatalliteSimulationWorkflow.cpp b/Toolbox/BaseToolbox/SARSatalliteSimulationWorkflow.cpp index 4abfdf5..a7d7db9 100644 --- a/Toolbox/BaseToolbox/SARSatalliteSimulationWorkflow.cpp +++ b/Toolbox/BaseToolbox/SARSatalliteSimulationWorkflow.cpp @@ -43,7 +43,7 @@ void initBaseToolSARSateSimulationWorkflow(ToolBoxWidget* toolbox) TLE2SatePositionVelocityToolButton::TLE2SatePositionVelocityToolButton(QWidget* parent) { - this->toolname = QString(u8"1.иɹڵ"); + this->toolname = QString(u8" иɹڵ"); } TLE2SatePositionVelocityToolButton::~TLE2SatePositionVelocityToolButton() @@ -59,7 +59,7 @@ void TLE2SatePositionVelocityToolButton::run() QAligendLandClsAndDEMToolButton::QAligendLandClsAndDEMToolButton(QWidget* parent) { - this->toolname = QString(u8"3.Ӱ"); + this->toolname = QString(u8" Ӱ"); } QAligendLandClsAndDEMToolButton::~QAligendLandClsAndDEMToolButton() @@ -75,7 +75,7 @@ void QAligendLandClsAndDEMToolButton::run() QDEMLLA2XYZSloperVectorToolButton::QDEMLLA2XYZSloperVectorToolButton(QWidget* parent) { - this->toolname = QString(u8"4.ɵĿʸ"); + this->toolname = QString(u8" ɵĿʸ"); } QDEMLLA2XYZSloperVectorToolButton::~QDEMLLA2XYZSloperVectorToolButton() diff --git a/Toolbox/SimulationSARTool/SimulationSARToolSARSatalliteSimulationWorkflow.cpp b/Toolbox/SimulationSARTool/SimulationSARToolSARSatalliteSimulationWorkflow.cpp index 46cab17..b926a8a 100644 --- a/Toolbox/SimulationSARTool/SimulationSARToolSARSatalliteSimulationWorkflow.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARToolSARSatalliteSimulationWorkflow.cpp @@ -60,76 +60,58 @@ SIMULATIONSARTOOL_EXPORT void initSimulationSARToolSARSateSimulationWorkflow(Too emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"ڻز"}, new QEchoDataSimulationSARRFPCToolButton(toolbox)); emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"ڻز"}, new QEchoDataSimulationSARRFPCToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"1~3ز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"ڻز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"ڻز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"ڻز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"ڻز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"ڻز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"ڻز"}, new QInSARImageNetGeneratorToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"ڻز"}, new QInSARImageNetGeneratorToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"1~3ز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B",u8"ڻز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C",u8"ڻز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A",u8"ڻز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B",u8"ڻز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E",u8"ڻز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F",u8"ڻز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04",u8"ڻز"}, new QGeneratorMapGeoAndSltLookTableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"1~3ز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"ڻز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"ڻز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"ڻز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"ڻز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"ڻز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"ڻز"}, new QMapLooktableToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"ڻز"}, new QMapLooktableToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"1~3ز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); - - - - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); - emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"1~3ز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"ڻز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"ڻز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"ڻز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"ڻز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"ڻز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"ڻز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"ڻز"}, new QSimulationBPImageMultiProductionLevel1_2ToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3B", u8"ڻز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"GF3C", u8"ڻز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1A", u8"ڻز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT1B", u8"ڻز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2E", u8"ڻز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"HJ2F", u8"ڻز"}, new QSimulationBPImageL1BToolButton(toolbox)); + emit toolbox->addBoxToolItemInPathSIGNAL(QVector{u8"󳡾", u8"LT04", u8"ڻز"}, new QSimulationBPImageL1BToolButton(toolbox)); - - - - - - - - - - - - - - - return ; } QPolyfitSatelliteGPSModelToolButton::QPolyfitSatelliteGPSModelToolButton(QWidget* parent) { - this->toolname = QString(u8"2.ݹڵϹģ"); + this->toolname = QString(u8"ݹڵϹģ"); } QPolyfitSatelliteGPSModelToolButton::~QPolyfitSatelliteGPSModelToolButton()