Incorporate individual support point radius.

This commit is contained in:
tamasmeszaros 2019-02-26 17:13:33 +01:00
parent 61f8e4f6f7
commit 43f03b8032
5 changed files with 462 additions and 451 deletions

View file

@ -2,6 +2,7 @@
#define SLACOMMON_HPP
#include <Eigen/Geometry>
#include <memory>
// #define SLIC3R_SLA_NEEDS_WINDTREE
@ -36,7 +37,6 @@ struct SupportPoint {
bool operator!=(const SupportPoint& sp) const { return !(sp == (*this)); }
};
/// An index-triangle structure for libIGL functions. Also serves as an
/// alternative (raw) input format for the SLASupportTree
/*struct EigenMesh3D {
@ -125,6 +125,8 @@ public:
bool inside(const Vec3d& p) const;
#endif /* SLIC3R_SLA_NEEDS_WINDTREE */
double squared_distance(const Vec3d& p, int& i, Vec3d& c) const;
};
@ -134,4 +136,4 @@ public:
} // namespace Slic3r
#endif // SLASUPPORTTREE_HPP
#endif // SLASUPPORTTREE_HPP

File diff suppressed because it is too large Load diff

View file

@ -74,7 +74,7 @@ struct SupportConfig {
double base_height_mm = 1.0;
// The default angle for connecting support sticks and junctions.
double tilt = M_PI/4;
double head_slope = M_PI/4;
// The max length of a bridge in mm
double max_bridge_length_mm = 15.0;
@ -116,18 +116,11 @@ using PointSet = Eigen::MatrixXd;
//EigenMesh3D to_eigenmesh(const ModelObject& model);
// Simple conversion of 'vector of points' to an Eigen matrix
PointSet to_point_set(const std::vector<sla::SupportPoint>&);
//PointSet to_point_set(const std::vector<sla::SupportPoint>&);
/* ************************************************************************** */
/// Just a wrapper to the runtime error to be recognizable in try blocks
class SLASupportsStoppedException: public std::runtime_error {
public:
using std::runtime_error::runtime_error;
SLASupportsStoppedException();
};
/// The class containing mesh data for the generated supports.
class SLASupportTree {
class Impl;
@ -141,7 +134,12 @@ class SLASupportTree {
const Controller&);
/// Generate the 3D supports for a model intended for SLA print.
bool generate(const PointSet& pts,
bool generate(const std::vector<SupportPoint>& pts,
const EigenMesh3D& mesh,
const SupportConfig& cfg = {},
const Controller& ctl = {});
bool _generate(const std::vector<SupportPoint>& pts,
const EigenMesh3D& mesh,
const SupportConfig& cfg = {},
const Controller& ctl = {});
@ -149,7 +147,7 @@ public:
SLASupportTree();
SLASupportTree(const PointSet& pts,
SLASupportTree(const std::vector<SupportPoint>& pts,
const EigenMesh3D& em,
const SupportConfig& cfg = {},
const Controller& ctl = {});

View file

@ -17,6 +17,8 @@
#include <igl/remove_duplicate_vertices.h>
#include <igl/signed_distance.h>
#include <tbb/parallel_for.h>
#include "SLASpatIndex.hpp"
#include "ClipperUtils.hpp"
@ -186,6 +188,15 @@ bool EigenMesh3D::inside(const Vec3d &p) const {
}
#endif /* SLIC3R_SLA_NEEDS_WINDTREE */
double EigenMesh3D::squared_distance(const Vec3d &p, int& i, Vec3d& c) const {
double sqdst = 0;
Eigen::Matrix<double, 1, 3> pp = p;
Eigen::Matrix<double, 1, 3> cc;
sqdst = m_aabb->squared_distance(m_V, m_F, pp, i, cc);
c = cc;
return sqdst;
}
/* ****************************************************************************
* Misc functions
* ****************************************************************************/
@ -208,21 +219,40 @@ template<class Vec> double distance(const Vec& pp1, const Vec& pp2) {
PointSet normals(const PointSet& points,
const EigenMesh3D& mesh,
double eps,
std::function<void()> throw_on_cancel)
std::function<void()> throw_on_cancel,
const std::vector<unsigned>& pt_indices = {})
{
if(points.rows() == 0 || mesh.V().rows() == 0 || mesh.F().rows() == 0)
return {};
Eigen::VectorXd dists;
Eigen::VectorXi I;
PointSet C;
std::vector<unsigned> range = pt_indices;
if(range.empty()) {
range.resize(size_t(points.rows()), 0);
std::iota(range.begin(), range.end(), 0);
}
igl::point_mesh_squared_distance( points, mesh.V(), mesh.F(), dists, I, C);
std::vector<double> dists(range.size());
std::vector<int> I(range.size());
PointSet C(Eigen::Index(range.size()), 3);
PointSet ret(I.rows(), 3);
for(int i = 0; i < I.rows(); i++) {
tbb::parallel_for(size_t(0), range.size(),
[&range, &mesh, &points, &dists, &I, &C](size_t idx)
{
auto eidx = Eigen::Index(range[idx]);
int i = 0;
Vec3d c;
dists[idx] = mesh.squared_distance(points.row(eidx), i, c);
C.row(eidx) = c;
I[range[idx]] = i;
});
// igl::point_mesh_squared_distance( points, mesh.V(), mesh.F(), dists, I, C);
PointSet ret(I.size(), 3);
for(unsigned i = 0; i < I.size(); i++) {
throw_on_cancel();
auto idx = I(i);
auto idx = I[i];
auto trindex = mesh.F().row(idx);
const Vec3d& p1 = mesh.V().row(trindex(0));
@ -332,7 +362,7 @@ PointSet normals(const PointSet& points,
ClusteredPoints cluster(
const sla::PointSet& points,
std::function<bool(const SpatElement&, const SpatElement&)> pred,
unsigned max_points = 0)
unsigned max_points = 0, const std::vector<unsigned>& indices = {})
{
namespace bgi = boost::geometry::index;
@ -342,8 +372,12 @@ ClusteredPoints cluster(
Index3D sindex;
// Build the index
for(unsigned idx = 0; idx < points.rows(); idx++)
sindex.insert( std::make_pair(points.row(idx), idx));
if(indices.empty())
for(unsigned idx = 0; idx < points.rows(); idx++)
sindex.insert( std::make_pair(points.row(idx), idx));
else
for(unsigned idx : indices)
sindex.insert( std::make_pair(points.row(idx), idx));
using Elems = std::vector<SpatElement>;