mirror of
https://github.com/CHN-beta/ufo.git
synced 2024-10-23 04:08:45 +08:00
bug fix
This commit is contained in:
parent
b6d10cd394
commit
3f16f0b930
@ -807,11 +807,11 @@
|
|||||||
"touchix": "touchix"
|
"touchix": "touchix"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1695703232,
|
"lastModified": 1695866766,
|
||||||
"narHash": "sha256-JqKKV5Zh3r4SAmK1Y0WdZaN5chRuaWRxw5hv9YPCRlQ=",
|
"narHash": "sha256-EdTNjwCmgug/NXdxGsLapSOpwJebf0ruU5qkmXjY9eg=",
|
||||||
"owner": "CHN-beta",
|
"owner": "CHN-beta",
|
||||||
"repo": "nixos",
|
"repo": "nixos",
|
||||||
"rev": "6318b938c2b3742874982d5d1a338656a50e493b",
|
"rev": "1957d682473ee67f96ace3ce3320c89b77aec8ae",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -16,12 +16,9 @@
|
|||||||
devShell.x86_64-linux = pkgs.mkShell.override { stdenv = pkgs.gcc13Stdenv; }
|
devShell.x86_64-linux = pkgs.mkShell.override { stdenv = pkgs.gcc13Stdenv; }
|
||||||
{
|
{
|
||||||
packages = with pkgs; [ pkg-config cmake ninja ];
|
packages = with pkgs; [ pkg-config cmake ninja ];
|
||||||
buildInputs = with pkgs;
|
buildInputs = (with pkgs; [ eigen yaml-cpp fmt highfive tbb_2021_8.dev ])
|
||||||
[
|
++ (with localPackages; [ concurrencpp matplotplusplus zpp-bits ]);
|
||||||
yaml-cpp eigen fmt localPackages.concurrencpp highfive tbb_2021_8.dev localPackages.matplotplusplus
|
# hardeningDisable = [ "all" ];
|
||||||
localPackages.zpp-bits
|
|
||||||
];
|
|
||||||
hardeningDisable = [ "all" ];
|
|
||||||
# NIX_DEBUG = "1";
|
# NIX_DEBUG = "1";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -17,8 +17,10 @@
|
|||||||
# include <concurrencpp/concurrencpp.h>
|
# include <concurrencpp/concurrencpp.h>
|
||||||
# include <fmt/format.h>
|
# include <fmt/format.h>
|
||||||
# include <fmt/std.h>
|
# include <fmt/std.h>
|
||||||
|
# include <fmt/ranges.h>
|
||||||
# include <highfive/H5File.hpp>
|
# include <highfive/H5File.hpp>
|
||||||
# include <zpp_bits.h>
|
# include <zpp_bits.h>
|
||||||
|
# include <matplot/matplot.h>
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
|
@ -239,11 +239,18 @@ inline void Output::write(std::string filename, std::string format, unsigned per
|
|||||||
|
|
||||||
inline Output::Output(std::string filename)
|
inline Output::Output(std::string filename)
|
||||||
{
|
{
|
||||||
auto [data, in] = zpp::bits::data_in();
|
auto input = std::ifstream(filename, std::ios::binary | std::ios::in);
|
||||||
auto input = std::basic_ifstream<std::byte>
|
|
||||||
(filename, std::ios::binary | std::ios::in);
|
|
||||||
input.exceptions(std::ios::badbit | std::ios::failbit);
|
input.exceptions(std::ios::badbit | std::ios::failbit);
|
||||||
data.assign(std::istreambuf_iterator<std::byte>(input), {});
|
std::vector<std::byte> data;
|
||||||
|
{
|
||||||
|
std::vector<char> string(std::istreambuf_iterator<char>(input), {});
|
||||||
|
data.assign
|
||||||
|
(
|
||||||
|
reinterpret_cast<std::byte*>(string.data()),
|
||||||
|
reinterpret_cast<std::byte*>(string.data() + string.size())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
auto in = zpp::bits::in(data);
|
||||||
in(*this).or_throw();
|
in(*this).or_throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
src/plot.cpp
31
src/plot.cpp
@ -90,25 +90,48 @@ int main(int argc, char** argv)
|
|||||||
auto current_distance = i * total_distance / 1024;
|
auto current_distance = i * total_distance / 1024;
|
||||||
auto& _ = interpolated_points.emplace_back();
|
auto& _ = interpolated_points.emplace_back();
|
||||||
_.Distance = current_distance;
|
_.Distance = current_distance;
|
||||||
|
auto it = std::lower_bound(Points.begin(), Points.end(), current_distance,
|
||||||
|
[](const Point& a, double b) { return a.Distance < b; });
|
||||||
// 如果是开头或者结尾, 直接赋值, 否则插值
|
// 如果是开头或者结尾, 直接赋值, 否则插值
|
||||||
if (current_distance < Points.front().Distance)
|
if (it == Points.begin())
|
||||||
{
|
{
|
||||||
_.Frequency = Points.front().Frequency;
|
_.Frequency = Points.front().Frequency;
|
||||||
_.Weight = Points.front().Weight;
|
_.Weight = Points.front().Weight;
|
||||||
}
|
}
|
||||||
else if (current_distance > Points.back().Distance)
|
else if (it == Points.end() - 1)
|
||||||
{
|
{
|
||||||
_.Frequency = Points.back().Frequency;
|
_.Frequency = Points.back().Frequency;
|
||||||
_.Weight = Points.back().Weight;
|
_.Weight = Points.back().Weight;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto it = std::lower_bound(Points.begin(), Points.end(), current_distance,
|
|
||||||
[](const Point& a, double b) { return a.Distance < b; });
|
|
||||||
_.Frequency = (it->Frequency * (it->Distance - current_distance)
|
_.Frequency = (it->Frequency * (it->Distance - current_distance)
|
||||||
+ (it - 1)->Frequency * (current_distance - (it - 1)->Distance)) / (it->Distance - (it - 1)->Distance);
|
+ (it - 1)->Frequency * (current_distance - (it - 1)->Distance)) / (it->Distance - (it - 1)->Distance);
|
||||||
_.Weight = (it->Weight * (it->Distance - current_distance)
|
_.Weight = (it->Weight * (it->Distance - current_distance)
|
||||||
+ (it - 1)->Weight * (current_distance - (it - 1)->Distance)) / (it->Distance - (it - 1)->Distance);
|
+ (it - 1)->Weight * (current_distance - (it - 1)->Distance)) / (it->Distance - (it - 1)->Distance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将结果对应到像素上的值
|
||||||
|
std::vector<std::vector<double>> weight(400, std::vector<double>(1024, 0));
|
||||||
|
for (auto& point : interpolated_points)
|
||||||
|
{
|
||||||
|
int x = point.Distance / total_distance * 1024;
|
||||||
|
if (x < 0)
|
||||||
|
x = 0;
|
||||||
|
else if (x >= 1024)
|
||||||
|
x = 1023;
|
||||||
|
for (unsigned i = 0; i < point.Frequency.size(); i++)
|
||||||
|
{
|
||||||
|
auto y = (point.Frequency(i) + 5) * 10;
|
||||||
|
if (y < 0)
|
||||||
|
y = 0;
|
||||||
|
else if (y >= 400)
|
||||||
|
y = 399;
|
||||||
|
weight[y][x] += point.Weight(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
matplot::image(weight);
|
||||||
|
matplot::show();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user