prusaslicer/tests/test_utils.hpp
Lukas Matena 7e3781a72a SPE-3317: Refactor OBJ format handling to slic3r-shared, modernize API, allow OBJ import from GUI:
- Moved OBJ and objparser format logic from libslic3r to slic3r-shared/Biz.
- Replaced BOOST_LOG_TRIVIAL with explicit error strings formatted via fmt.
- Modernized load_obj to return tl::expected<TriangleMesh, std::string> instead of a bool.
- Registered .obj as a supported file type in FileLoadingLogic and Wildcards, allowing it to appear in standard Open/Import dialogs alongside STL and 3MF.
- Tweaked import file dialog so that it has the "all supported" file extension filter.
- Updated CLI ProcessActions to utilize the new Slic3r::Biz namespace for OBJ export.
2026-01-14 13:00:42 +01:00

42 lines
1 KiB
C++

#ifndef SLIC3R_TEST_UTILS
#define SLIC3R_TEST_UTILS
#include "Slic3r/Biz/Algorithms/TriangleMesh.hpp"
#include "Slic3r/Biz/Format/OBJ.hpp"
#include "Slic3r/Assert.hpp"
#include <random>
#if defined(WIN32) || defined(_WIN32)
#define PATH_SEPARATOR R"(\)"
#else
#define PATH_SEPARATOR R"(/)"
#endif
inline Slic3r::Domain::TriangleMesh load_model(const std::string &obj_filename)
{
auto fpath = TEST_DATA_DIR PATH_SEPARATOR + obj_filename;
auto mesh = Slic3r::Biz::load_obj(fpath.c_str());
ASSERT(mesh);
return mesh.value();
}
template<class T>
std::enable_if_t<std::is_floating_point<T>::value, T> random_value(T minv, T maxv)
{
static std::mt19937 rng(std::random_device{}());
std::uniform_real_distribution<T> dist(minv, maxv);
return dist(rng);
}
template<class T>
std::enable_if_t<std::is_integral<T>::value, T> random_value(T minv, T maxv)
{
static std::mt19937 rng(std::random_device{}());
std::uniform_int_distribution<T> dist(minv, maxv);
return dist(rng);
}
#endif // SLIC3R_TEST_UTILS