This commit is contained in:
Timur A. Fatkhullin
2026-02-12 23:31:17 +03:00
parent 700ed63169
commit affaf176e5
2 changed files with 136 additions and 14 deletions

View File

@@ -238,23 +238,15 @@ endif()
add_library(${PROJECT_NAME} INTERFACE ${MCC_SRC})
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_23)
target_include_directories(
${PROJECT_NAME}
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR};>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)
if(USE_ERFA)
target_link_libraries(${PROJECT_NAME} INTERFACE PkgConfig::ERFALIB)
target_include_directories(
${PROJECT_NAME}
INTERFACE
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR};${ERFALIB_INCLUDE_DIRS};${FITPACK_INCLUDE_DIR};>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR};${ERFALIB_INCLUDE_DIRS};>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)
else()
target_include_directories(
${PROJECT_NAME}
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR};>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)
endif()
if(USE_BSPLINE_PCM)
@@ -282,6 +274,9 @@ if(BUILD_TESTS)
add_executable(mcc_netmsg_test tests/mcc_netmsg_test.cpp)
target_link_libraries(mcc_netmsg_test PRIVATE ${PROJECT_NAME})
add_executable(mcc_fitpack_test tests/mcc_fitpack_test.cpp)
target_link_libraries(mcc_fitpack_test PRIVATE ${PROJECT_NAME})
else()
# This is just a stub to allow access to the path and library settings for the ${PROJECT_NAME} target during development
add_executable(just_stub EXCLUDE_FROM_ALL main.cpp)

127
tests/mcc_fitpack_test.cpp Normal file
View File

@@ -0,0 +1,127 @@
#include <algorithm>
#include <functional>
#include <iostream>
#include <random>
#include <ranges>
#include <mcc_bsplines.h>
int main()
{
size_t nt = 30, np = 60, N = nt * np, i = 1;
// size_t nt = 10, np = 20, N = nt * np, i = 1;
double ts = std::numbers::pi / (nt + 1);
double ps = 2.0 * std::numbers::pi / (np + 1);
std::vector<double> tetha(N), phi(N), func(N);
auto gen_func = [](double st, size_t& idx) {
double v = st * idx;
++idx;
return v;
};
auto print_func = [](const auto& r, std::string_view name) {
std::cout << name << ": ";
for (auto& el : r) {
std::cout << el << " ";
}
std::cout << "\n";
};
// std::ranges::generate(tetha, std::bind(gen_func, ts, i));
// i = 1;
// std::ranges::generate(phi, std::bind(gen_func, ps, i));
size_t k = 1;
i = 0;
for (size_t j = 0; j < nt; ++j) {
std::ranges::fill_n(tetha.begin() + i * np, np, ts * (i + 1));
std::ranges::generate(phi | std::views::drop(i * np) | std::views::take(np), std::bind(gen_func, ps, k));
++i;
k = 1;
}
// std::uniform_real_distribution<double> distr{-0.1, 0.1};
std::normal_distribution<double> distr{0.0, 1.0};
std::random_device device;
std::mt19937 engine{device()};
std::ranges::generate(func, [ii = 0, &distr, &engine, &tetha, &phi]() mutable {
double v = (5.0 + tetha[ii]) * 1.3 + (3.0 + phi[ii]) * 3.1 + distr(engine);
++ii;
return v;
});
int ntk = 24, npk = 29, nf = (ntk + 4) * (npk + 4);
// int ntk = 3, npk = 6, nf = (ntk + 4) * (npk + 4);
std::vector<double> tk(ntk + 8), pk(npk + 8), coeffs(nf);
ts = std::numbers::pi / (ntk + 1);
ps = 2.0 * std::numbers::pi / (npk + 1);
i = 1;
std::ranges::generate(tk | std::views::drop(4) | std::views::take(ntk), std::bind(gen_func, ts, i));
i = 1;
std::ranges::generate(pk | std::views::drop(4) | std::views::take(npk), std::bind(gen_func, ps, i));
double rs = 0.0;
int ec = mcc::bsplines::fitpack_sphere_fit(tetha, phi, func, 1.0, tk, pk, coeffs, rs);
std::cout << "FIT EC = " << ec << "\n";
std::cout << "FIT RESI = " << rs << "\n";
ntk += 8;
npk += 8;
std::ranges::fill(tk, -1);
std::ranges::fill(pk, -1);
ec = mcc::bsplines::fitpack_sphere_smooth(tetha, phi, func, 1.0, 1800.0, ntk, npk, tk, pk, coeffs, rs);
std::cout << "FIT EC = " << ec << "\n";
std::cout << "FIT RESI = " << rs << "\n";
std::cout << "NKNOTS: " << ntk << ", " << npk << "\n";
print_func(coeffs, "coeffs");
// print_func(tetha, "tetha");
// print_func(phi, "phi");
print_func(tk, "tetha_knots");
print_func(pk, "phi_knots");
print_func(func, "func");
std::cout << "\n\n";
k = 1;
ts = std::numbers::pi / (nt + 1);
std::ranges::generate_n(tetha.begin(), nt, std::bind(gen_func, ts, k));
std::vector<double> f_func;
tetha.resize(nt);
phi.resize(np);
tk.resize(ntk);
pk.resize(npk);
print_func(tetha, "TETHA:");
print_func(phi, "PHI:");
ec = mcc::bsplines::fitpack_eval_spl2d(tk, pk, coeffs, tetha, phi, f_func);
// ec = mcc::bsplines::fitpack_eval_spl2d(pk, tk, coeffs, phi, tetha, f_func);
std::cout << "EVAL EC = " << ec << "\n";
print_func(f_func, "func");
std::cout << "\n\n";
for (size_t l = 0; l < f_func.size(); ++l) {
auto r = f_func[l] - func[l];
std::cout << r << " ";
}
std::cout << "\n";
return 0;
}