svgfill as plug-in

This commit is contained in:
Thomas Krijnen
2026-05-09 21:03:55 +02:00
parent 2eb2d65710
commit fde502daa1
7 changed files with 50 additions and 30 deletions
+11 -5
View File
@@ -46,14 +46,18 @@ endif()
include_directories(${Boost_INCLUDE_DIRS} ${SVGPP_INCLUDE})
file(GLOB LIB_H_FILES src/*.h)
file(GLOB LIB_CPP_FILES src/svgfill.cpp src/arrange_polygons.cpp)
file(GLOB LIB_CPP_FILES src/svgfill.cpp src/arrange_polygons.cpp src/svgfill_plugin.cpp)
set(LIB_SRC_FILES ${LIB_H_FILES} ${LIB_CPP_FILES})
add_library(svgfill ${LIB_SRC_FILES})
target_link_libraries(svgfill ${Boost_LIBRARIES} ${BCRYPT_LIBRARIES} LibXml2::LibXml2 IFCOPENSHELL_CGAL)
if(BUILD_SHARED_LIBS)
target_compile_definitions(svgfill PUBLIC IFC_SHARED_BUILD)
add_library(svgfill SHARED ${LIB_SRC_FILES})
target_compile_definitions(svgfill PRIVATE BOOST_DLL_USE_STD_FS)
if(NOT WASM_BUILD)
target_link_libraries(svgfill PRIVATE plugin)
endif()
target_link_libraries(svgfill PRIVATE ${Boost_LIBRARIES} ${BCRYPT_LIBRARIES} LibXml2::LibXml2 IFCOPENSHELL_CGAL)
target_compile_definitions(svgfill PUBLIC IFC_SHARED_BUILD)
set_target_properties(svgfill PROPERTIES PUBLIC_HEADER "${LIB_H_FILES}")
set_target_properties(svgfill PROPERTIES OUTPUT_NAME "ifcopenshell.geometry.svgfill")
ifcopenshell_wasm_plugin_link_options(svgfill ifcopenshell_register_linework_processing_plugin_v1)
add_executable(svgfill_exe src/main.cpp)
target_link_libraries(svgfill_exe svgfill)
@@ -69,6 +73,8 @@ if(WIN32)
target_link_options(svgfill_exe PRIVATE "/NOIMPLIB")
endif()
set(linework_processing_libraries svgfill PARENT_SCOPE)
install(
TARGETS svgfill_exe svgfill
EXPORT ${IFCOPENSHELL_EXPORT_TARGETS}
+26 -12
View File
@@ -19,6 +19,7 @@
****************************************************************************/
#include "svgfill.h"
#include "linework_processing_plugin.h"
#include <libxml/parser.h>
@@ -615,23 +616,32 @@ std::string svgfill::polygons_to_svg(const std::vector<polygon_2>& polygons, boo
return polygons_to_svg(pps, random_color);
}
svgfill::abstract_arrangement* svgfill::create_arrangement(solver s) {
if (s == CARTESIAN_DOUBLE) {
return new cgal_arrangement<CGAL::Cartesian<double>>;
} else if (s == CARTESIAN_QUOTIENT) {
return new cgal_arrangement<CGAL::Cartesian<CGAL::Quotient<CGAL::MP_Float>>>;
} else if (s == FILTERED_CARTESIAN_QUOTIENT) {
return new cgal_arrangement<CGAL::Filtered_kernel<CGAL::Cartesian<CGAL::Quotient<CGAL::MP_Float>>>>;
} else if (s == EXACT_PREDICATES) {
return new cgal_arrangement<CGAL::Epick>;
} else if (s == EXACT_CONSTRUCTIONS) {
return new cgal_arrangement<CGAL::Epeck>;
}
return nullptr;
}
void svgfill::destroy_arrangement(abstract_arrangement* arrangement) {
delete arrangement;
}
void svgfill::context::add(const std::vector<line_segment_2>& segments) {
segments_.insert(segments_.end(), segments.begin(), segments.end());
}
bool svgfill::context::build() {
if (solver_ == CARTESIAN_DOUBLE) {
arr_ = new cgal_arrangement<CGAL::Cartesian<double>>;
} else if (solver_ == CARTESIAN_QUOTIENT) {
arr_ = new cgal_arrangement<CGAL::Cartesian<CGAL::Quotient<CGAL::MP_Float>>>;
} else if (solver_ == FILTERED_CARTESIAN_QUOTIENT) {
arr_ = new cgal_arrangement<CGAL::Filtered_kernel<CGAL::Cartesian<CGAL::Quotient<CGAL::MP_Float>>>>;
} else if (solver_ == EXACT_PREDICATES) {
arr_ = new cgal_arrangement<CGAL::Epick>;
} else if (solver_ == EXACT_CONSTRUCTIONS) {
arr_ = new cgal_arrangement<CGAL::Epeck>;
}
return (*arr_)(eps_, segments_, progress_);
arr_ = create_arrangement(solver_);
return arr_ && (*arr_)(eps_, segments_, progress_);
}
void svgfill::context::merge(const std::vector<int>& edge_indices) {
@@ -643,3 +653,7 @@ void svgfill::context::write(std::vector<std::vector<polygon_2>>& p) {
arr_->write(polygons, progress_);
p.push_back(polygons);
}
svgfill::context::~context() {
destroy_arrangement(arr_);
}
+1 -3
View File
@@ -105,9 +105,7 @@ namespace svgfill {
size_t num_faces() { return arr_->num_faces(); }
size_t delete_same_facet_edge_pairs() { return arr_->delete_same_facet_edge_pairs(); }
~context() {
delete arr_;
}
~context();
};
SVGFILL_API bool svg_to_line_segments(const std::string& data, const std::optional<std::string>& class_name, std::vector<std::vector<line_segment_2>>& segments);