Added comments in MeshUtils.hpp
PIMPL in MeshRaycaster now uses std::unique_ptr instead of raw pointer
This commit is contained in:
parent
68812b081f
commit
f6e217171a
2 changed files with 42 additions and 14 deletions
src/slic3r/GUI
|
@ -129,10 +129,9 @@ MeshRaycaster::MeshRaycaster(const TriangleMesh& mesh)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MeshRaycaster::~MeshRaycaster()
|
// Define the default destructor here. This is needed for the PIMPL with
|
||||||
{
|
// unique_ptr to work, the AABBWrapper is complete here.
|
||||||
delete m_AABB_wrapper;
|
MeshRaycaster::~MeshRaycaster() = default;
|
||||||
}
|
|
||||||
|
|
||||||
Vec3f MeshRaycaster::AABBWrapper::get_hit_pos(const igl::Hit& hit) const
|
Vec3f MeshRaycaster::AABBWrapper::get_hit_pos(const igl::Hit& hit) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace GUI {
|
||||||
struct Camera;
|
struct Camera;
|
||||||
|
|
||||||
|
|
||||||
|
// lm_FIXME: Following class might possibly be replaced by Eigen::Hyperplane
|
||||||
class ClippingPlane
|
class ClippingPlane
|
||||||
{
|
{
|
||||||
double m_data[4];
|
double m_data[4];
|
||||||
|
@ -67,13 +67,23 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// MeshClipper class cuts a mesh and is able to return a triangulated cut.
|
||||||
class MeshClipper {
|
class MeshClipper {
|
||||||
public:
|
public:
|
||||||
|
// Inform MeshClipper about which plane we want to use to cut the mesh
|
||||||
|
// This is supposed to be in world coordinates.
|
||||||
void set_plane(const ClippingPlane& plane);
|
void set_plane(const ClippingPlane& plane);
|
||||||
|
|
||||||
|
// Which mesh to cut. MeshClipper remembers const * to it, caller
|
||||||
|
// must make sure that it stays valid.
|
||||||
void set_mesh(const TriangleMesh& mesh);
|
void set_mesh(const TriangleMesh& mesh);
|
||||||
|
|
||||||
|
// Inform the MeshClipper about the transformation that transforms the mesh
|
||||||
|
// into world coordinates.
|
||||||
void set_transformation(const Geometry::Transformation& trafo);
|
void set_transformation(const Geometry::Transformation& trafo);
|
||||||
|
|
||||||
|
// Return the triangulated cut. The points are returned directly
|
||||||
|
// in world coordinates.
|
||||||
const std::vector<Vec3f>& get_triangles();
|
const std::vector<Vec3f>& get_triangles();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -90,26 +100,45 @@ private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// MeshRaycaster class answers queries such as where on the mesh someone clicked,
|
||||||
|
// whether certain points are visible or obscured by the mesh etc.
|
||||||
class MeshRaycaster {
|
class MeshRaycaster {
|
||||||
public:
|
public:
|
||||||
|
// The class saves a const* to the mesh, called is responsible
|
||||||
|
// for making sure it does not get invalid.
|
||||||
MeshRaycaster(const TriangleMesh& mesh);
|
MeshRaycaster(const TriangleMesh& mesh);
|
||||||
|
|
||||||
~MeshRaycaster();
|
~MeshRaycaster();
|
||||||
void set_transformation(const Geometry::Transformation& trafo);
|
|
||||||
void set_camera(const Camera& camera);
|
|
||||||
|
|
||||||
bool unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera,
|
// Given a mouse position, this returns true in case it is on the mesh.
|
||||||
Vec3f& position, Vec3f& normal, const ClippingPlane* clipping_plane = nullptr) const;
|
bool unproject_on_mesh(
|
||||||
|
const Vec2d& mouse_pos,
|
||||||
|
const Transform3d& trafo, // how to get the mesh into world coords
|
||||||
|
const Camera& camera, // current camera position
|
||||||
|
Vec3f& position, // where to save the positibon of the hit (mesh coords)
|
||||||
|
Vec3f& normal, // normal of the triangle that was hit
|
||||||
|
const ClippingPlane* clipping_plane = nullptr // clipping plane (if active)
|
||||||
|
) const;
|
||||||
|
|
||||||
std::vector<unsigned> get_unobscured_idxs(const Geometry::Transformation& trafo, const Camera& camera,
|
// Given a vector of points in woorld coordinates, this returns vector
|
||||||
const std::vector<Vec3f>& points, const ClippingPlane* clipping_plane = nullptr) const;
|
// of indices of points that are visible (i.e. not cut by clipping plane
|
||||||
|
// or obscured by part of the mesh.
|
||||||
|
std::vector<unsigned> get_unobscured_idxs(
|
||||||
|
const Geometry::Transformation& trafo, // how to get the mesh into world coords
|
||||||
|
const Camera& camera, // current camera position
|
||||||
|
const std::vector<Vec3f>& points, // points in world coords
|
||||||
|
const ClippingPlane* clipping_plane = nullptr // clipping plane (if active)
|
||||||
|
) const;
|
||||||
|
|
||||||
|
// Given a point in world coords, the method returns closest point on the mesh.
|
||||||
|
// The output is in mesh coords.
|
||||||
|
// normal* can be used to also get normal of the respective triangle.
|
||||||
Vec3f get_closest_point(const Vec3f& point, Vec3f* normal = nullptr) const;
|
Vec3f get_closest_point(const Vec3f& point, Vec3f* normal = nullptr) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// PIMPL wrapper around igl::AABB so I don't have to include the header-only IGL here
|
// PIMPL wrapper around igl::AABB so I don't have to include the header-only IGL here
|
||||||
class AABBWrapper;
|
class AABBWrapper;
|
||||||
AABBWrapper* m_AABB_wrapper;
|
std::unique_ptr<AABBWrapper> m_AABB_wrapper;
|
||||||
const TriangleMesh* m_mesh = nullptr;
|
const TriangleMesh* m_mesh = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue