add new cgal as technology

This commit is contained in:
Filip Sykala 2022-03-22 15:47:34 +01:00
parent 65909c74c4
commit e6838f7e18
3 changed files with 71 additions and 53 deletions

View File

@ -1,5 +1,37 @@
#include "CutSurface.hpp"
using namespace Slic3r;
void Slic3r::append(SurfaceCut &sc, SurfaceCut &&sc_add)
{
if (sc.empty()) {
sc = std::move(sc_add);
return;
}
if (!sc_add.cut.empty()) {
SurfaceCut::Index offset = static_cast<SurfaceCut::Index>(
sc.vertices.size());
size_t require = sc.cut.size() + sc_add.cut.size();
if (sc.cut.capacity() < require) sc.cut.reserve(require);
for (std::vector<SurfaceCut::Index> &cut : sc_add.cut)
for (SurfaceCut::Index &i : cut) i += offset;
append(sc.cut, std::move(sc_add.cut));
}
its_merge(sc, std::move(sc_add));
}
#if !ENABLE_NEW_CGAL
SurfaceCuts Slic3r::cut_surface(const indexed_triangle_set &model,
const ExPolygons &shapes,
const Emboss::IProject &projection)
{
return {};
}
#else
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Exact_integer.h>
#include <CGAL/Surface_mesh.h>
@ -9,8 +41,6 @@
#include "TriangleMesh.hpp" // its_merge
#include "Utils.hpp" // next_highest_power_of_2
using namespace Slic3r;
namespace priv {
using EpicKernel = CGAL::Exact_predicates_inexact_constructions_kernel;
@ -336,25 +366,6 @@ void store(CutMesh &mesh, const ReductionMap &reduction_map, const std::string &
void store(const SurfaceCuts &cut, const std::string &file_prefix);
} // namespace privat
void Slic3r::append(SurfaceCut &sc, SurfaceCut &&sc_add)
{
if (sc.empty()) {
sc = std::move(sc_add);
return;
}
if (!sc_add.cut.empty()) {
SurfaceCut::Index offset = static_cast<SurfaceCut::Index>(
sc.vertices.size());
size_t require = sc.cut.size() + sc_add.cut.size();
if (sc.cut.capacity() < require) sc.cut.reserve(require);
for (std::vector<SurfaceCut::Index> &cut : sc_add.cut)
for (SurfaceCut::Index &i : cut) i += offset;
append(sc.cut, std::move(sc_add.cut));
}
its_merge(sc, std::move(sc_add));
}
SurfaceCuts Slic3r::cut_surface(const indexed_triangle_set &model,
const ExPolygons &shapes,
const Emboss::IProject &projection)
@ -1056,3 +1067,5 @@ void priv::store(const SurfaceCuts &cut, const std::string &file_prefix) {
its_write_obj(c, file.c_str());
}
}
#endif // ENABLE_NEW_CGAL

View File

@ -58,7 +58,7 @@
// Enable using vertex attributes and matrices in shaders
#define ENABLE_GL_SHADERS_ATTRIBUTES (1 && ENABLE_LEGACY_OPENGL_REMOVAL)
// Enable rendering imgui using shaders
#define ENABLE_GL_IMGUI_SHADERS (1 && ENABLE_GL_SHADERS_ATTRIBUTES)
#define ENABLE_GL_IMGUI_SHADERS (0 && ENABLE_GL_SHADERS_ATTRIBUTES)
// Shows an imgui dialog with GLModel statistics data
#define ENABLE_GLMODEL_STATISTICS (0 && ENABLE_LEGACY_OPENGL_REMOVAL)
// Enable show non-manifold edges
@ -87,6 +87,7 @@
#define ENABLE_WORLD_COORDINATE_SHOW_AXES (1 && ENABLE_WORLD_COORDINATE)
// Enable alternate implementation of manipulating scale for instances and volumes
#define ENABLE_WORLD_COORDINATE_SCALE_REVISITED (1 && ENABLE_WORLD_COORDINATE)
// Enable using of new CGAL for emboss text
#define ENABLE_NEW_CGAL (0 && ENABLE_2_5_0_ALPHA1)
#endif // _prusaslicer_technologies_h_

View File

@ -216,35 +216,6 @@ TEST_CASE("triangle intersection", "[]")
CHECK(abs(i.y() - 1.) < std::numeric_limits<double>::epsilon());
}
#include "libslic3r/CutSurface.hpp"
TEST_CASE("Cut surface", "[]")
{
std::string font_path = get_font_filepath();
char letter = '%';
float flatness = 2.;
auto font = Emboss::create_font_file(font_path.c_str());
REQUIRE(font != nullptr);
std::optional<Emboss::Glyph> glyph = Emboss::letter2glyph(*font, letter, flatness);
REQUIRE(glyph.has_value());
ExPolygons shape = glyph->shape;
REQUIRE(!shape.empty());
float z_depth = 50.f;
Emboss::ProjectZ projection(z_depth);
auto object = its_make_cube(782 - 49 + 50, 724 + 10 + 50, 5);
its_translate(object, Vec3f(49 - 25, -10 - 25, 2.5));
auto cube2 = object; // copy
its_translate(cube2, Vec3f(100, -40, 40));
its_merge(object, std::move(cube2));
auto surfaces = cut_surface(object, shape, projection);
CHECK(!surfaces.empty());
}
#ifndef __APPLE__
#include <string>
#include <iostream>
@ -295,6 +266,38 @@ TEST_CASE("Italic check", "[Emboss]")
}
#endif // not __APPLE__
#if ENABLE_NEW_CGAL
#include "libslic3r/CutSurface.hpp"
TEST_CASE("Cut surface", "[]")
{
std::string font_path = get_font_filepath();
char letter = '%';
float flatness = 2.;
auto font = Emboss::create_font_file(font_path.c_str());
REQUIRE(font != nullptr);
std::optional<Emboss::Glyph> glyph = Emboss::letter2glyph(*font, letter,
flatness);
REQUIRE(glyph.has_value());
ExPolygons shape = glyph->shape;
REQUIRE(!shape.empty());
float z_depth = 50.f;
Emboss::ProjectZ projection(z_depth);
auto object = its_make_cube(782 - 49 + 50, 724 + 10 + 50, 5);
its_translate(object, Vec3f(49 - 25, -10 - 25, 2.5));
auto cube2 = object; // copy
its_translate(cube2, Vec3f(100, -40, 40));
its_merge(object, std::move(cube2));
auto surfaces = cut_surface(object, shape, projection);
CHECK(!surfaces.empty());
}
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Exact_integer.h>
#include <CGAL/Surface_mesh.h>
@ -1045,3 +1048,4 @@ TEST_CASE("Emboss extrude cut", "[Emboss-Cut]")
// REQUIRE(!MeshBoolean::cgal::does_self_intersect(cube));
}
#endif // ENABLE_NEW_CGAL