mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-14 19:31:14 +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.
147 lines
4.8 KiB
C++
147 lines
4.8 KiB
C++
#ifndef PRUSASLICER_AABBMESH_H
|
|
#define PRUSASLICER_AABBMESH_H
|
|
|
|
#include <cstddef>
|
|
#include <limits>
|
|
#include <cmath>
|
|
#include <cassert>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include <libslic3r/Point.hpp>
|
|
#include <libslic3r/TriangleMesh.hpp>
|
|
|
|
// There is an implementation of a hole-aware raycaster that was eventually
|
|
// not used in production version. It is now hidden under following define
|
|
// for possible future use.
|
|
// #define SLIC3R_HOLE_RAYCASTER
|
|
|
|
#ifdef SLIC3R_HOLE_RAYCASTER
|
|
#include "libslic3r/SLA/Hollowing.hpp"
|
|
#endif
|
|
|
|
struct indexed_triangle_set;
|
|
|
|
namespace Slic3r {
|
|
|
|
class TriangleMesh;
|
|
|
|
// An index-triangle structure coupled with an AABB index to support ray
|
|
// casting and other higher level operations.
|
|
class AABBMesh {
|
|
class AABBImpl;
|
|
|
|
const indexed_triangle_set* m_tm;
|
|
|
|
std::unique_ptr<AABBImpl> m_aabb;
|
|
VertexFaceIndex m_vfidx; // vertex-face index
|
|
std::vector<Vec3i32> m_fnidx; // face-neighbor index
|
|
|
|
#ifdef SLIC3R_HOLE_RAYCASTER
|
|
// This holds a copy of holes in the mesh. Initialized externally
|
|
// by load_mesh setter.
|
|
std::vector<sla::DrainHole> m_holes;
|
|
#endif
|
|
|
|
template<class M> void init(const M &mesh, bool calculate_epsilon);
|
|
|
|
public:
|
|
|
|
// calculate_epsilon ... calculate epsilon for triangle-ray intersection from an average triangle edge length.
|
|
// If set to false, a default epsilon is used, which works for "reasonable" meshes.
|
|
explicit AABBMesh(const indexed_triangle_set &tmesh, bool calculate_epsilon = false);
|
|
explicit AABBMesh(const TriangleMesh &mesh, bool calculate_epsilon = false);
|
|
|
|
AABBMesh(const AABBMesh& other);
|
|
AABBMesh& operator=(const AABBMesh&);
|
|
|
|
AABBMesh(AABBMesh &&other);
|
|
AABBMesh& operator=(AABBMesh &&other);
|
|
|
|
~AABBMesh();
|
|
|
|
const std::vector<Vec3f>& vertices() const;
|
|
const std::vector<Vec3i32>& indices() const;
|
|
const Vec3f& vertices(size_t idx) const;
|
|
const Vec3i32& indices(size_t idx) const;
|
|
|
|
// Result of a raycast
|
|
class hit_result {
|
|
// m_t holds a distance from m_source to the intersection.
|
|
double m_t = infty();
|
|
int m_face_id = -1;
|
|
const AABBMesh *m_mesh = nullptr;
|
|
Vec3d m_dir = Vec3d::Zero();
|
|
Vec3d m_source = Vec3d::Zero();
|
|
Vec3d m_normal = Vec3d::Zero();
|
|
friend class AABBMesh;
|
|
|
|
// A valid object of this class can only be obtained from
|
|
// IndexedMesh::query_ray_hit method.
|
|
explicit inline hit_result(const AABBMesh& em): m_mesh(&em) {}
|
|
public:
|
|
// This denotes no hit on the mesh.
|
|
static inline constexpr double infty() { return std::numeric_limits<double>::infinity(); }
|
|
|
|
explicit inline hit_result(double val = infty()) : m_t(val) {}
|
|
|
|
inline double distance() const { return m_t; }
|
|
inline const Vec3d& direction() const { return m_dir; }
|
|
inline const Vec3d& source() const { return m_source; }
|
|
inline Vec3d position() const { return m_source + m_dir * m_t; }
|
|
inline int face() const { return m_face_id; }
|
|
inline bool is_valid() const { return m_mesh != nullptr; }
|
|
inline bool is_hit() const { return m_face_id >= 0 && !std::isinf(m_t); }
|
|
|
|
inline const Vec3d& normal() const {
|
|
assert(is_valid());
|
|
return m_normal;
|
|
}
|
|
|
|
inline bool is_inside() const {
|
|
return is_hit() && normal().dot(m_dir) > 0;
|
|
}
|
|
};
|
|
|
|
#ifdef SLIC3R_HOLE_RAYCASTER
|
|
// Inform the object about location of holes
|
|
// creates internal copy of the vector
|
|
void load_holes(const std::vector<sla::DrainHole>& holes) {
|
|
m_holes = holes;
|
|
}
|
|
|
|
// Iterates over hits and holes and returns the true hit, possibly
|
|
// on the inside of a hole.
|
|
// This function is currently not used anywhere, it was written when the
|
|
// holes were subtracted on slices, that is, before we started using CGAL
|
|
// to actually cut the holes into the mesh.
|
|
hit_result filter_hits(const std::vector<AABBMesh::hit_result>& obj_hits) const;
|
|
#endif
|
|
|
|
// Casting a ray on the mesh, returns the distance where the hit occures.
|
|
hit_result query_ray_hit(const Vec3d &s, const Vec3d &dir) const;
|
|
|
|
// Casts a ray on the mesh and returns all hits
|
|
std::vector<hit_result> query_ray_hits(const Vec3d &s, const Vec3d &dir) const;
|
|
|
|
double squared_distance(const Vec3d& p, int& i, Vec3d& c) const;
|
|
inline double squared_distance(const Vec3d &p) const
|
|
{
|
|
int i;
|
|
Vec3d c;
|
|
return squared_distance(p, i, c);
|
|
}
|
|
|
|
Vec3d normal_by_face_id(int face_id) const;
|
|
|
|
const indexed_triangle_set * get_triangle_mesh() const { return m_tm; }
|
|
|
|
const VertexFaceIndex &vertex_face_index() const { return m_vfidx; }
|
|
const std::vector<Vec3i32> &face_neighbor_index() const { return m_fnidx; }
|
|
};
|
|
|
|
|
|
} // namespace Slic3r::sla
|
|
|
|
#endif // INDEXEDMESH_H
|