+ Comment debug output
+ Add was_canceled in cut surface
This commit is contained in:
Filip Sykala - NTB T15p 2022-10-12 19:26:45 +02:00
parent 6d4830823e
commit 8343e81053
6 changed files with 28 additions and 19 deletions

View File

@ -91,18 +91,19 @@ inline AABBTreeIndirect::Tree<2, typename LineType::Scalar> build_aabb_tree_over
// Finding a closest line, its closest point and squared distance to the closest point // Finding a closest line, its closest point and squared distance to the closest point
// Returns squared distance to the closest point or -1 if the input is empty. // Returns squared distance to the closest point or -1 if the input is empty.
// or no closer point than max_sq_dist // or no closer point than max_sq_dist
template<typename LineType, typename TreeType, typename VectorType, typename Scalar = typename VectorType::Scalar> template<typename LineType, typename TreeType, typename VectorType>
inline typename Scalar squared_distance_to_indexed_lines(const std::vector<LineType> &lines, inline typename VectorType::Scalar squared_distance_to_indexed_lines(
const TreeType &tree, const std::vector<LineType> &lines,
const VectorType &point, const TreeType &tree,
size_t &hit_idx_out, const VectorType &point,
Eigen::PlainObjectBase<VectorType> &hit_point_out, size_t &hit_idx_out,
Scalar max_sqr_dist = std::numeric_limits<Scalar>::infinity()) Eigen::PlainObjectBase<VectorType> &hit_point_out,
typename VectorType::Scalar max_sqr_dist = std::numeric_limits<typename VectorType::Scalar>::infinity())
{ {
if (tree.empty()) return Scalar(-1); if (tree.empty()) return VectorType::Scalar(-1);
auto distancer = detail::IndexedLinesDistancer<LineType, TreeType, VectorType>{lines, tree, point}; auto distancer = detail::IndexedLinesDistancer<LineType, TreeType, VectorType>{lines, tree, point};
return AABBTreeIndirect::detail::squared_distance_to_indexed_primitives_recursive( return AABBTreeIndirect::detail::squared_distance_to_indexed_primitives_recursive(
distancer, size_t(0), Scalar(0), max_sqr_dist, hit_idx_out, hit_point_out); distancer, size_t(0), VectorType::Scalar(0), max_sqr_dist, hit_idx_out, hit_point_out);
} }
// Returns all lines within the given radius limit // Returns all lines within the given radius limit

View File

@ -20,7 +20,7 @@
/// patches/patch{O}.off /// patches/patch{O}.off
/// result.obj - Merged result its /// result.obj - Merged result its
/// result_contours/{O}.obj - visualization of contours for result patches /// result_contours/{O}.obj - visualization of contours for result patches
#define DEBUG_OUTPUT_DIR std::string("C:/data/temp/cutSurface/") //#define DEBUG_OUTPUT_DIR std::string("C:/data/temp/cutSurface/")
using namespace Slic3r; using namespace Slic3r;
#include "ExPolygonsIndex.hpp" #include "ExPolygonsIndex.hpp"
@ -1058,7 +1058,7 @@ priv::CutMesh priv::to_cgal(const ExPolygons &shapes,
for (const Polygon &hole : shape.holes) for (const Polygon &hole : shape.holes)
insert_contour(hole); insert_contour(hole);
} }
assert(!exist_duplicit_point(result)); assert(!exist_duplicit_vertex(result));
return result; return result;
} }
@ -3209,8 +3209,6 @@ std::vector<bool> priv::select_patches(const ProjectionDistances &best_distances
for (uint32_t patch_index : used_shape_patches) { for (uint32_t patch_index : used_shape_patches) {
ExPolygon patch_area = to_expoly(patches[patch_index], projection); ExPolygon patch_area = to_expoly(patches[patch_index], projection);
//*/ //*/
// add save offset extension to cover numerical mistake made by back projection to 2d
const float extend_delta = 5.f;
ExPolygons patch_areas = offset_ex(patch_area, extend_delta); ExPolygons patch_areas = offset_ex(patch_area, extend_delta);
fill.insert(fill.end(), patch_areas.begin(), patch_areas.end()); fill.insert(fill.end(), patch_areas.begin(), patch_areas.end());
/*/ /*/

View File

@ -43,7 +43,6 @@ Point to_point(const stbtt__point &point);
bool remove_same_neighbor(Slic3r::Points &points); bool remove_same_neighbor(Slic3r::Points &points);
bool remove_same_neighbor(Slic3r::Polygons &polygons); bool remove_same_neighbor(Slic3r::Polygons &polygons);
bool remove_same_neighbor(ExPolygons &expolygons); bool remove_same_neighbor(ExPolygons &expolygons);
bool divide_segments_for_close_point(ExPolygons &expolygons, double distance = .6);
// NOTE: expolygons can't contain same_neighbor // NOTE: expolygons can't contain same_neighbor
Points collect_close_points(const ExPolygons &expolygons, double distance = .6); Points collect_close_points(const ExPolygons &expolygons, double distance = .6);
@ -173,13 +172,13 @@ Points priv::collect_close_points(const ExPolygons &expolygons, double distance)
return res; return res;
} }
bool priv::divide_segments_for_close_point(ExPolygons &expolygons, double distance) bool Emboss::divide_segments_for_close_point(ExPolygons &expolygons, double distance)
{ {
if (expolygons.empty()) return false; if (expolygons.empty()) return false;
if (distance < 0.) return false; if (distance < 0.) return false;
// ExPolygons can't contain same neigbours // ExPolygons can't contain same neigbours
remove_same_neighbor(expolygons); priv::remove_same_neighbor(expolygons);
// IMPROVE: use int(insted of double) lines and tree // IMPROVE: use int(insted of double) lines and tree
const ExPolygonsIndices ids(expolygons); const ExPolygonsIndices ids(expolygons);

View File

@ -177,6 +177,17 @@ public:
/// <returns>True when shapes is good otherwise False</returns> /// <returns>True when shapes is good otherwise False</returns>
static bool heal_shape(ExPolygons &shape, unsigned max_iteration = 10); static bool heal_shape(ExPolygons &shape, unsigned max_iteration = 10);
/// <summary>
/// Divide line segments in place near to point
/// (which could lead to self intersection due to preccision)
/// Remove same neighbors
/// Note: Possible part of heal shape
/// </summary>
/// <param name="expolygons">Expolygon to edit</param>
/// <param name="distance">(epsilon)Euclidean distance from point to line which divide line</param>
/// <returns>True when some division was made otherwise false</returns>
static bool divide_segments_for_close_point(ExPolygons &expolygons, double distance);
/// <summary> /// <summary>
/// Use data from font property to modify transformation /// Use data from font property to modify transformation
/// </summary> /// </summary>

View File

@ -356,7 +356,7 @@ void UseSurfaceJob::process(Ctl &ctl) {
const TextConfiguration &tc = m_input.text_configuration; const TextConfiguration &tc = m_input.text_configuration;
const char *text = tc.text.c_str(); const char *text = tc.text.c_str();
const FontProp &fp = tc.style.prop; const FontProp &fp = tc.style.prop;
ExPolygons shapes = Emboss::text2shapes(m_input.font_file, text, fp); ExPolygons shapes = Emboss::text2shapes(m_input.font_file, text, fp, was_canceled);
if (shapes.empty() || shapes.front().contour.empty()) if (shapes.empty() || shapes.front().contour.empty())
throw priv::EmbossJobException( throw priv::EmbossJobException(
_u8L("Font doesn't have any shape for given text.").c_str()); _u8L("Font doesn't have any shape for given text.").c_str());

View File

@ -283,9 +283,9 @@ TEST_CASE("Heal of points close to line", "[Emboss]")
Polygon polygon = polygons.front(); Polygon polygon = polygons.front();
polygon.points.pop_back();// NSVG put first point as last one when polygon is closed polygon.points.pop_back();// NSVG put first point as last one when polygon is closed
ExPolygons expoly({ExPolygon(polygon)}); ExPolygons expoly({ExPolygon(polygon)});
Emboss::heal_shape(expoly); CHECK(Emboss::divide_segments_for_close_point(expoly, .6));
//{ SVG svg("C:/data/temp/healed.svg"); svg.draw(expoly);} //{ SVG svg("C:/data/temp/healed.svg"); svg.draw(expoly);}
CHECK(expoly.size() == 3); CHECK(to_points(expoly).size() >= (to_points(polygon).size() + 2));
} }
TEST_CASE("Convert text with glyph cache to model", "[Emboss]") TEST_CASE("Convert text with glyph cache to model", "[Emboss]")