mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-07 15:51:08 +00:00
* Add Missing Includes Across src/libslic3r Every libslic3r source and header now directly includes the headers declaring what it uses, rather than relying on the precompiled header or transitive includes. Generated with clang-tidy misc-include-cleaner, with libslic3r headers spelled libslic3r/... so they resolve outside the library's private include paths. MultiMaterialSegmentation.hpp, Support/SupportParameters.hpp and Format/STEP.hpp are made self-contained by hand. * Make the libslic3r Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Left out: I18N.hpp, which errors on purpose when included from GUI code, and VoxelizeCSGMesh.hpp and SLA/bicubic.h, which nothing includes and which no longer compile at all. * Add the Includes Missing From the Hand-Fixed libslic3r Headers clang-tidy would not edit these headers while they failed to compile on their own, so the first pass skipped them. With the headers now self-contained, a second pass adds the rest. * Keep Windows Setup Ahead of the Added libslic3r Includes Print.cpp and Thread.cpp open with a _WIN32 block that has to come first; without the precompiled header, Print.cpp otherwise reaches windows.h through OCCT with NONLS defined and boost/regex fails. OpenVDBUtils.cpp and SLA/SupportTreeBuilder.cpp had includes inside #ifndef NOMINMAX, which libslic3r defines on Windows, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory. * Re-Add libslic3r Includes After the Clipper2 2.0.1 Migration Rebasing onto main took main's version of the files the Clipper2 migration rewrote, so their added includes are restored here, along with includes for main's new code. Clipper2's individual headers are now ignored by clang-tidy: they only build the Z variant through clipper2_z.hpp, which defines USINGZ first, so including clipper.core.h and the like directly broke ClipperZUtils.cpp.
130 lines
3.8 KiB
C++
130 lines
3.8 KiB
C++
#ifndef EXECUTION_HPP
|
|
#define EXECUTION_HPP
|
|
|
|
#include <functional>
|
|
#include <type_traits>
|
|
#include <utility>
|
|
#include <cstddef>
|
|
#include <iterator>
|
|
|
|
#include "libslic3r/libslic3r.h"
|
|
|
|
namespace Slic3r {
|
|
|
|
// Override for valid execution policies
|
|
template<class EP> struct IsExecutionPolicy_ : public std::false_type {};
|
|
|
|
template<class EP> constexpr bool IsExecutionPolicy =
|
|
IsExecutionPolicy_<remove_cvref_t<EP>>::value;
|
|
|
|
template<class EP, class T = void>
|
|
using ExecutionPolicyOnly = std::enable_if_t<IsExecutionPolicy<EP>, T>;
|
|
|
|
namespace execution {
|
|
|
|
// This struct needs to be specialized for each execution policy.
|
|
// See ExecutionSeq.hpp and ExecutionTBB.hpp for example.
|
|
template<class EP, class En = void> struct Traits {};
|
|
|
|
template<class EP> using AsTraits = Traits<remove_cvref_t<EP>>;
|
|
|
|
// Each execution policy should declare two types of mutexes. A a spin lock and
|
|
// a blocking mutex. These types should satisfy the BasicLockable concept.
|
|
template<class EP> using SpinningMutex = typename Traits<EP>::SpinningMutex;
|
|
template<class EP> using BlockingMutex = typename Traits<EP>::BlockingMutex;
|
|
|
|
// Query the available threads for concurrency.
|
|
template<class EP, class = ExecutionPolicyOnly<EP> >
|
|
size_t max_concurrency(const EP &ep)
|
|
{
|
|
return AsTraits<EP>::max_concurrency(ep);
|
|
}
|
|
|
|
// foreach loop with the execution policy passed as argument. Granularity can
|
|
// be specified explicitly. max_concurrency() can be used for optimal results.
|
|
template<class EP, class It, class Fn, class = ExecutionPolicyOnly<EP>>
|
|
void for_each(const EP &ep, It from, It to, Fn &&fn, size_t granularity = 1)
|
|
{
|
|
AsTraits<EP>::for_each(ep, from, to, std::forward<Fn>(fn), granularity);
|
|
}
|
|
|
|
// A reduce operation with the execution policy passed as argument.
|
|
// mergefn has T(const T&, const T&) signature
|
|
// accessfn has T(I) signature if I is an integral type and
|
|
// T(const I::value_type &) if I is an iterator type.
|
|
template<class EP,
|
|
class I,
|
|
class MergeFn,
|
|
class T,
|
|
class AccessFn,
|
|
class = ExecutionPolicyOnly<EP> >
|
|
T reduce(const EP & ep,
|
|
I from,
|
|
I to,
|
|
const T & init,
|
|
MergeFn && mergefn,
|
|
AccessFn &&accessfn,
|
|
size_t granularity = 1)
|
|
{
|
|
return AsTraits<EP>::reduce(ep, from, to, init,
|
|
std::forward<MergeFn>(mergefn),
|
|
std::forward<AccessFn>(accessfn),
|
|
granularity);
|
|
}
|
|
|
|
// An overload of reduce method to be used with iterators as 'from' and 'to'
|
|
// arguments. Access functor is omitted here.
|
|
template<class EP,
|
|
class I,
|
|
class MergeFn,
|
|
class T,
|
|
class = ExecutionPolicyOnly<EP> >
|
|
T reduce(const EP &ep,
|
|
I from,
|
|
I to,
|
|
const T & init,
|
|
MergeFn &&mergefn,
|
|
size_t granularity = 1)
|
|
{
|
|
return reduce(
|
|
ep, from, to, init, std::forward<MergeFn>(mergefn),
|
|
[](const auto &i) { return i; }, granularity);
|
|
}
|
|
|
|
template<class EP,
|
|
class I,
|
|
class T,
|
|
class AccessFn,
|
|
class = ExecutionPolicyOnly<EP>>
|
|
T accumulate(const EP & ep,
|
|
I from,
|
|
I to,
|
|
const T & init,
|
|
AccessFn &&accessfn,
|
|
size_t granularity = 1)
|
|
{
|
|
return reduce(ep, from, to, init, std::plus<T>{},
|
|
std::forward<AccessFn>(accessfn), granularity);
|
|
}
|
|
|
|
|
|
template<class EP,
|
|
class I,
|
|
class T,
|
|
class = ExecutionPolicyOnly<EP> >
|
|
T accumulate(const EP &ep,
|
|
I from,
|
|
I to,
|
|
const T & init,
|
|
size_t granularity = 1)
|
|
{
|
|
return reduce(
|
|
ep, from, to, init, std::plus<T>{}, [](const auto &i) { return i; },
|
|
granularity);
|
|
}
|
|
|
|
} // namespace execution_policy
|
|
} // namespace Slic3r
|
|
|
|
#endif // EXECUTION_HPP
|