Renamed MeshClipper.cpp/.hpp to MeshUtils.cpp/.hpp

More helper classes like the MeshClipper could live here
Moved ClippingPlane class in here to start
This commit is contained in:
Lukas Matena 2019-09-13 11:30:50 +02:00
parent 9782701dd4
commit 70c0c87598
8 changed files with 116 additions and 94 deletions

View file

@ -85,8 +85,8 @@ set(SLIC3R_GUI_SOURCES
GUI/GUI_ObjectLayers.hpp GUI/GUI_ObjectLayers.hpp
GUI/LambdaObjectDialog.cpp GUI/LambdaObjectDialog.cpp
GUI/LambdaObjectDialog.hpp GUI/LambdaObjectDialog.hpp
GUI/MeshClipper.cpp GUI/MeshUtils.cpp
GUI/MeshClipper.hpp GUI/MeshUtils.hpp
GUI/Tab.cpp GUI/Tab.cpp
GUI/Tab.hpp GUI/Tab.hpp
GUI/ConfigManipulation.cpp GUI/ConfigManipulation.cpp

View file

@ -12,6 +12,7 @@
#include "Selection.hpp" #include "Selection.hpp"
#include "Gizmos/GLGizmosManager.hpp" #include "Gizmos/GLGizmosManager.hpp"
#include "GUI_ObjectLayers.hpp" #include "GUI_ObjectLayers.hpp"
#include "MeshUtils.hpp"
#include <float.h> #include <float.h>
@ -67,54 +68,6 @@ public:
}; };
class ClippingPlane
{
double m_data[4];
public:
ClippingPlane()
{
m_data[0] = 0.0;
m_data[1] = 0.0;
m_data[2] = 1.0;
m_data[3] = 0.0;
}
ClippingPlane(const Vec3d& direction, double offset)
{
Vec3d norm_dir = direction.normalized();
m_data[0] = norm_dir(0);
m_data[1] = norm_dir(1);
m_data[2] = norm_dir(2);
m_data[3] = offset;
}
bool operator==(const ClippingPlane& cp) const {
return m_data[0]==cp.m_data[0] && m_data[1]==cp.m_data[1] && m_data[2]==cp.m_data[2] && m_data[3]==cp.m_data[3];
}
bool operator!=(const ClippingPlane& cp) const { return ! (*this==cp); }
double distance(const Vec3d& pt) const {
assert(is_approx(get_normal().norm(), 1.));
return (-get_normal().dot(pt) + m_data[3]);
}
void set_normal(const Vec3d& normal) { for (size_t i=0; i<3; ++i) m_data[i] = normal(i); }
void set_offset(double offset) { m_data[3] = offset; }
Vec3d get_normal() const { return Vec3d(m_data[0], m_data[1], m_data[2]); }
bool is_active() const { return m_data[3] != DBL_MAX; }
static ClippingPlane ClipsNothing() { return ClippingPlane(Vec3d(0., 0., 1.), DBL_MAX); }
const double* get_data() const { return m_data; }
// Serialization through cereal library
template <class Archive>
void serialize( Archive & ar )
{
ar( m_data[0], m_data[1], m_data[2], m_data[3] );
}
};
wxDECLARE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, SimpleEvent);
using Vec2dEvent = Event<Vec2d>; using Vec2dEvent = Event<Vec2d>;

View file

@ -1,6 +1,7 @@
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. // Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
#include "GLGizmoSlaSupports.hpp" #include "GLGizmoSlaSupports.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/GLCanvas3D.hpp"
#include "slic3r/GUI/Gizmos/GLGizmos.hpp"
#include <GL/glew.h> #include <GL/glew.h>
@ -12,11 +13,10 @@
#include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/GUI_ObjectSettings.hpp" #include "slic3r/GUI/GUI_ObjectSettings.hpp"
#include "slic3r/GUI/GUI_ObjectList.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp"
#include "slic3r/GUI/MeshClipper.hpp" #include "slic3r/GUI/MeshUtils.hpp"
#include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/Plater.hpp"
#include "slic3r/GUI/PresetBundle.hpp" #include "slic3r/GUI/PresetBundle.hpp"
#include "libslic3r/SLAPrint.hpp" #include "libslic3r/SLAPrint.hpp"
#include "libslic3r/Tesselate.hpp"
namespace Slic3r { namespace Slic3r {

View file

@ -2,8 +2,6 @@
#define slic3r_GLGizmoSlaSupports_hpp_ #define slic3r_GLGizmoSlaSupports_hpp_
#include "GLGizmoBase.hpp" #include "GLGizmoBase.hpp"
#include "GLGizmos.hpp"
#include "slic3r/GUI/GLSelectionRectangle.hpp"
#include "slic3r/GUI/GLSelectionRectangle.hpp" #include "slic3r/GUI/GLSelectionRectangle.hpp"
// There is an L function in igl that would be overridden by our localization macro - let's undefine it... // There is an L function in igl that would be overridden by our localization macro - let's undefine it...
@ -22,6 +20,7 @@ namespace GUI {
class ClippingPlane; class ClippingPlane;
class MeshClipper; class MeshClipper;
enum class SLAGizmoEventType : unsigned char;
class GLGizmoSlaSupports : public GLGizmoBase class GLGizmoSlaSupports : public GLGizmoBase
{ {

View file

@ -2,7 +2,10 @@
#define slic3r_GLGizmos_hpp_ #define slic3r_GLGizmos_hpp_
// this describes events being passed from GLCanvas3D to SlaSupport gizmo // this describes events being passed from GLCanvas3D to SlaSupport gizmo
enum class SLAGizmoEventType { namespace Slic3r {
namespace GUI {
enum class SLAGizmoEventType : unsigned char {
LeftDown = 1, LeftDown = 1,
LeftUp, LeftUp,
RightDown, RightDown,
@ -20,6 +23,9 @@ enum class SLAGizmoEventType {
ResetClippingPlane ResetClippingPlane
}; };
} // namespace GUI
} // namespace Slic3r
#include "slic3r/GUI/Gizmos/GLGizmoMove.hpp" #include "slic3r/GUI/Gizmos/GLGizmoMove.hpp"
#include "slic3r/GUI/Gizmos/GLGizmoScale.hpp" #include "slic3r/GUI/Gizmos/GLGizmoScale.hpp"
#include "slic3r/GUI/Gizmos/GLGizmoRotate.hpp" #include "slic3r/GUI/Gizmos/GLGizmoRotate.hpp"

View file

@ -1,36 +0,0 @@
#ifndef slic3r_MeshClipper_hpp_
#define slic3r_MeshClipper_hpp_
#include "libslic3r/Point.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp"
namespace Slic3r {
namespace GUI {
class MeshClipper {
public:
void set_plane(const ClippingPlane& plane);
void set_mesh(const TriangleMesh& mesh);
void set_transformation(const Geometry::Transformation& trafo);
const std::vector<Vec3f>& get_triangles();
private:
void recalculate_triangles();
Geometry::Transformation m_trafo;
const TriangleMesh* m_mesh = nullptr;
ClippingPlane m_plane;
std::vector<Vec2f> m_triangles2d;
std::vector<Vec3f> m_triangles3d;
bool m_triangles_valid = false;
std::unique_ptr<TriangleMeshSlicer> m_tms;
};
} // namespace GUI
} // namespace Slic3r
#endif // slic3r_MeshClipper_hpp_

View file

@ -1,6 +1,7 @@
#include "MeshClipper.hpp" #include "MeshUtils.hpp"
#include "GLCanvas3D.hpp"
#include "libslic3r/Tesselate.hpp" #include "libslic3r/Tesselate.hpp"
#include "libslic3r/TriangleMesh.hpp"
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
@ -13,6 +14,8 @@ void MeshClipper::set_plane(const ClippingPlane& plane)
} }
} }
void MeshClipper::set_mesh(const TriangleMesh& mesh) void MeshClipper::set_mesh(const TriangleMesh& mesh)
{ {
if (m_mesh != &mesh) { if (m_mesh != &mesh) {
@ -24,6 +27,8 @@ void MeshClipper::set_mesh(const TriangleMesh& mesh)
} }
} }
void MeshClipper::set_transformation(const Geometry::Transformation& trafo) void MeshClipper::set_transformation(const Geometry::Transformation& trafo)
{ {
if (! m_trafo.get_matrix().isApprox(trafo.get_matrix())) { if (! m_trafo.get_matrix().isApprox(trafo.get_matrix())) {
@ -44,6 +49,8 @@ const std::vector<Vec3f>& MeshClipper::get_triangles()
return m_triangles3d; return m_triangles3d;
} }
void MeshClipper::recalculate_triangles() void MeshClipper::recalculate_triangles()
{ {
if (! m_tms) { if (! m_tms) {
@ -51,7 +58,6 @@ void MeshClipper::recalculate_triangles()
m_tms->init(m_mesh, [](){}); m_tms->init(m_mesh, [](){});
} }
const Transform3f& instance_matrix_no_translation_no_scaling = m_trafo.get_matrix(true,false,true).cast<float>(); const Transform3f& instance_matrix_no_translation_no_scaling = m_trafo.get_matrix(true,false,true).cast<float>();
const Vec3f& scaling = m_trafo.get_scaling_factor().cast<float>(); const Vec3f& scaling = m_trafo.get_scaling_factor().cast<float>();
// Calculate clipping plane normal in mesh coordinates. // Calculate clipping plane normal in mesh coordinates.

View file

@ -0,0 +1,94 @@
#ifndef slic3r_MeshUtils_hpp_
#define slic3r_MeshUtils_hpp_
#include "libslic3r/Point.hpp"
#include "libslic3r/Geometry.hpp"
#include <cfloat>
namespace Slic3r {
class TriangleMesh;
class TriangleMeshSlicer;
namespace GUI {
class ClippingPlane
{
double m_data[4];
public:
ClippingPlane()
{
m_data[0] = 0.0;
m_data[1] = 0.0;
m_data[2] = 1.0;
m_data[3] = 0.0;
}
ClippingPlane(const Vec3d& direction, double offset)
{
Vec3d norm_dir = direction.normalized();
m_data[0] = norm_dir(0);
m_data[1] = norm_dir(1);
m_data[2] = norm_dir(2);
m_data[3] = offset;
}
bool operator==(const ClippingPlane& cp) const {
return m_data[0]==cp.m_data[0] && m_data[1]==cp.m_data[1] && m_data[2]==cp.m_data[2] && m_data[3]==cp.m_data[3];
}
bool operator!=(const ClippingPlane& cp) const { return ! (*this==cp); }
double distance(const Vec3d& pt) const {
assert(is_approx(get_normal().norm(), 1.));
return (-get_normal().dot(pt) + m_data[3]);
}
void set_normal(const Vec3d& normal) { for (size_t i=0; i<3; ++i) m_data[i] = normal(i); }
void set_offset(double offset) { m_data[3] = offset; }
Vec3d get_normal() const { return Vec3d(m_data[0], m_data[1], m_data[2]); }
bool is_active() const { return m_data[3] != DBL_MAX; }
static ClippingPlane ClipsNothing() { return ClippingPlane(Vec3d(0., 0., 1.), DBL_MAX); }
const double* get_data() const { return m_data; }
// Serialization through cereal library
template <class Archive>
void serialize( Archive & ar )
{
ar( m_data[0], m_data[1], m_data[2], m_data[3] );
}
};
class MeshClipper {
public:
void set_plane(const ClippingPlane& plane);
void set_mesh(const TriangleMesh& mesh);
void set_transformation(const Geometry::Transformation& trafo);
const std::vector<Vec3f>& get_triangles();
private:
void recalculate_triangles();
Geometry::Transformation m_trafo;
const TriangleMesh* m_mesh = nullptr;
ClippingPlane m_plane;
std::vector<Vec2f> m_triangles2d;
std::vector<Vec3f> m_triangles3d;
bool m_triangles_valid = false;
std::unique_ptr<TriangleMeshSlicer> m_tms;
};
} // namespace GUI
} // namespace Slic3r
#endif // slic3r_MeshUtils_hpp_