mirror of
https://github.com/CHN-beta/ufo.git
synced 2024-10-22 19:58:44 +08:00
bug fix
This commit is contained in:
parent
b6d10cd394
commit
3f16f0b930
@ -807,11 +807,11 @@
|
||||
"touchix": "touchix"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1695703232,
|
||||
"narHash": "sha256-JqKKV5Zh3r4SAmK1Y0WdZaN5chRuaWRxw5hv9YPCRlQ=",
|
||||
"lastModified": 1695866766,
|
||||
"narHash": "sha256-EdTNjwCmgug/NXdxGsLapSOpwJebf0ruU5qkmXjY9eg=",
|
||||
"owner": "CHN-beta",
|
||||
"repo": "nixos",
|
||||
"rev": "6318b938c2b3742874982d5d1a338656a50e493b",
|
||||
"rev": "1957d682473ee67f96ace3ce3320c89b77aec8ae",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -16,12 +16,9 @@
|
||||
devShell.x86_64-linux = pkgs.mkShell.override { stdenv = pkgs.gcc13Stdenv; }
|
||||
{
|
||||
packages = with pkgs; [ pkg-config cmake ninja ];
|
||||
buildInputs = with pkgs;
|
||||
[
|
||||
yaml-cpp eigen fmt localPackages.concurrencpp highfive tbb_2021_8.dev localPackages.matplotplusplus
|
||||
localPackages.zpp-bits
|
||||
];
|
||||
hardeningDisable = [ "all" ];
|
||||
buildInputs = (with pkgs; [ eigen yaml-cpp fmt highfive tbb_2021_8.dev ])
|
||||
++ (with localPackages; [ concurrencpp matplotplusplus zpp-bits ]);
|
||||
# hardeningDisable = [ "all" ];
|
||||
# NIX_DEBUG = "1";
|
||||
};
|
||||
};
|
||||
|
@ -17,8 +17,10 @@
|
||||
# include <concurrencpp/concurrencpp.h>
|
||||
# include <fmt/format.h>
|
||||
# include <fmt/std.h>
|
||||
# include <fmt/ranges.h>
|
||||
# include <highfive/H5File.hpp>
|
||||
# include <zpp_bits.h>
|
||||
# include <matplot/matplot.h>
|
||||
|
||||
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)
|
||||
{
|
||||
auto [data, in] = zpp::bits::data_in();
|
||||
auto input = std::basic_ifstream<std::byte>
|
||||
(filename, std::ios::binary | std::ios::in);
|
||||
auto input = std::ifstream(filename, std::ios::binary | std::ios::in);
|
||||
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();
|
||||
}
|
||||
|
||||
|
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& _ = interpolated_points.emplace_back();
|
||||
_.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;
|
||||
_.Weight = Points.front().Weight;
|
||||
}
|
||||
else if (current_distance > Points.back().Distance)
|
||||
else if (it == Points.end() - 1)
|
||||
{
|
||||
_.Frequency = Points.back().Frequency;
|
||||
_.Weight = Points.back().Weight;
|
||||
}
|
||||
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)
|
||||
+ (it - 1)->Frequency * (current_distance - (it - 1)->Distance)) / (it->Distance - (it - 1)->Distance);
|
||||
_.Weight = (it->Weight * (it->Distance - current_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