diff --git a/CMakeLists.txt b/CMakeLists.txt index e28af9b..ed58a1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,13 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(param_parser) +# if (DEFINED UltimaillePath) +# set(ultimaille_SOURCE_DIR ${UltimaillePath}) +# link_directories("${ultimaille_SOURCE_DIR}/build/lib") +# message("Get ultimaille at specified path") +# endif() +# message(${ultimaille_SOURCE_DIR}) # Add ultimaille directory to get ultimaille CMakeLists include_directories(${ultimaille_SOURCE_DIR}) @@ -43,6 +49,8 @@ add_executable(smoother_addon smoother_addon.cpp) add_executable(hex_layer_subdivide_addon hex_layer_subdivide_addon.cpp) add_executable(hex_scaled_jacobian_addon hex_scaled_jacobian_addon.cpp) add_executable(step_loader_addon step_loader_addon.cpp) +add_executable(facet_corners_test facet_corners_test.cpp) +add_executable(tag_feature_lines tag_feature_lines_addon.cpp) # Link binary with ultimaille / param-parser target_link_libraries(delete_facet_addon ${CMAKE_DL_LIBS} param-parser ultimaille $<$:OpenMP::OpenMP_CXX>) @@ -50,6 +58,8 @@ target_link_libraries(smoother_addon ${CMAKE_DL_LIBS} param-parser ultimaille $ target_link_libraries(hex_layer_subdivide_addon ${CMAKE_DL_LIBS} param-parser ultimaille $<$:OpenMP::OpenMP_CXX>) target_link_libraries(hex_scaled_jacobian_addon ${CMAKE_DL_LIBS} param-parser ultimaille $<$:OpenMP::OpenMP_CXX>) target_link_libraries(step_loader_addon ${CMAKE_DL_LIBS} param-parser ultimaille $<$:OpenMP::OpenMP_CXX>) +target_link_libraries(facet_corners_test ${CMAKE_DL_LIBS} param-parser ultimaille $<$:OpenMP::OpenMP_CXX>) +target_link_libraries(tag_feature_lines ${CMAKE_DL_LIBS} param-parser ultimaille $<$:OpenMP::OpenMP_CXX>) IF (NOT WIN32) target_link_libraries(delete_facet_addon m) @@ -57,6 +67,8 @@ IF (NOT WIN32) target_link_libraries(hex_layer_subdivide_addon m) target_link_libraries(hex_scaled_jacobian_addon m) target_link_libraries(step_loader_addon m) + target_link_libraries(facet_corners_test m) + target_link_libraries(tag_feature_lines m) ENDIF() if (NOT DEFINED OSName) @@ -93,5 +105,17 @@ set_target_properties( OUTPUT_NAME "step_loader_addon_${OSName}" ) +set_target_properties( + facet_corners_test + PROPERTIES + OUTPUT_NAME "facet_corners_test_addon_${OSName}" +) + +set_target_properties( + tag_feature_lines + PROPERTIES + OUTPUT_NAME "tag_feature_lines_addon_${OSName}" +) + file(COPY assets/catorus.geogram DESTINATION .) \ No newline at end of file diff --git a/facet_corners_test.cpp b/facet_corners_test.cpp new file mode 100644 index 0000000..50562b3 --- /dev/null +++ b/facet_corners_test.cpp @@ -0,0 +1,50 @@ +#include +#include + +using namespace UM; + +int main(int argc, char** argv) { + + // Add program parameters + // params.add("input", "model", "").description("Model to process"); + + // params.add(Parameters::Type::EdgesInt(1), "edge_attribute", "").description("Edge"); + // params.add(Parameters::Type::FacetCornersInt(1), "facet_attribute", "").description("Facet"); + + // /* Parse program arguments */ + // params.init_from_args(argc, argv); + + // // Get parameters + // std::string filename = params["model"]; + // std::string facet_attribute = params["facet_attribute"]; + + // std::filesystem::path result_path(params.result_path()); + + // // Load mesh and read attributes + // Quads m; + // SurfaceAttributes attributes = read_by_extension(filename, m); + // // Load attribute + // CornerAttribute ca(facet_attribute, attributes, m); + + // std::cout << "n corners: " << m.ncorners() << std::endl; + + // for (int i = 0; i < m.ncorners(); i++) { + // std::cout << "ca: " << ca[i] << std::endl; + // } + + // // Save + + // // Output model to output directory at working dir if no result_path given + // if (result_path.empty() && !std::filesystem::is_directory("output")) { + // std::filesystem::create_directories("output"); + // result_path = "output"; + // } + + // // Get file name and output path + // std::string file = std::filesystem::path(filename).filename().string(); + // std::string out_filename = (result_path / file).string(); + + // write_by_extension(out_filename, m, {{}, {}, {{"ca", ca.ptr}}}); + + return 0; +} diff --git a/step_loader_addon.cpp b/step_loader_addon.cpp index ca1a3a1..c2f5944 100644 --- a/step_loader_addon.cpp +++ b/step_loader_addon.cpp @@ -13,6 +13,8 @@ inline std::string separator() #endif } +using namespace UM; + int main(int argc, char** argv) { // Create parameters @@ -23,8 +25,9 @@ int main(int argc, char** argv) { // Add program parameters params.add(Parameters::Type::File, "gmsh_path", "gmsh").description("GMSH path / name (please add GMSH to you PATH !)"); params.add(Parameters::Type::File, "step_path", "").description("Step file to load"); - params.add(Parameters::Type::Bool, "volume", "true").description("Convert to volume mesh"); + params.add(Parameters::Type::Bool, "volume", "false").description("Convert to volume mesh"); params.add(Parameters::Type::Double, "size_factor", "1").description("Size factor"); + params.add(Parameters::Type::Bool, "to_polyline", "false").description("Extract polyline"); /* Parse program arguments */ params.init_from_args(argc, argv); @@ -33,6 +36,7 @@ int main(int argc, char** argv) { std::string gmsh_path = params["gmsh_path"]; std::string step_path = params["step_path"]; bool volume = params["volume"]; + bool to_polyline = params["to_polyline"]; double size_factor = params["size_factor"]; std::filesystem::path result_path(params.result_path()); @@ -40,6 +44,7 @@ int main(int argc, char** argv) { // Out file std::filesystem::path out_filename = result_path / "out.mesh"; + // std::filesystem::path out_filename = result_path / "out.vtk"; // Write config file for GMSH std::ofstream conf_file; @@ -59,6 +64,42 @@ int main(int argc, char** argv) { int result = system(command.c_str()); std::cout << "call result: " + std::to_string(result) << std::endl; - + + std::cout << "to polyline ? " << to_polyline << std::endl; + + if (!to_polyline) + return 0; + + + PolyLine p; + PolyLineAttributes attributes = read_by_extension(out_filename.string(), p); + EdgeAttribute edge_regions_attr("region", attributes, p); + PointAttribute point_regions_attr("region", attributes, p); + + // Duplicate edge to create bi-directional edge + int n_edges = p.nedges(); + int offset = p.create_edges(n_edges); + + EdgeAttribute new_edge_regions_attr(p); + + + for (int i = 0; i < n_edges; i++) { + int k = offset + i; + p.vert(k, 0) = p.vert(i, 1); + p.vert(k, 1) = p.vert(i, 0); + new_edge_regions_attr[i] = edge_regions_attr[i]; + new_edge_regions_attr[k] = edge_regions_attr[i]; + } + + + std::string geogram_out_filename = out_filename.string() + ".geogram"; + + write_by_extension(geogram_out_filename, p, {{{"region", point_regions_attr.ptr}}, {{"region", new_edge_regions_attr.ptr}}}); + // write_by_extension(geogram_out_filename, p, attributes); + std::cout << "writed to: " << geogram_out_filename << std::endl; + + // std::remove(out_filename.c_str()); + // std::cout << "remove: " << out_filename.string() << std::endl; + return 0; } \ No newline at end of file diff --git a/tag_feature_lines_addon.cpp b/tag_feature_lines_addon.cpp new file mode 100644 index 0000000..299a404 --- /dev/null +++ b/tag_feature_lines_addon.cpp @@ -0,0 +1,67 @@ +#include +#include + +#include +#include + +inline std::string separator() +{ +#ifdef _WIN32 + return "\\"; +#else + return "/"; +#endif +} + +using namespace UM; + +int main(int argc, char** argv) { + + // Create parameters + Parameters params; + + params.help = "Tag feature lines of a surface + polyline model"; + + // Add program parameters + params.add(Parameters::Type::Input, "model", "").description(""); + + /* Parse program arguments */ + params.init_from_args(argc, argv); + + // Get args + std::string model = params["model"]; + std::filesystem::path result_path(params.result_path()); + + // Out file + std::filesystem::path model_path(model); + + std::filesystem::path out_filename = result_path / (model_path.filename().string() + "_tagged.geogram"); + + // Read surface + Triangles m; + read_by_extension(model, m); + CornerAttribute feature_line_attr(m); + + // Read poyline + PolyLine p; + PolyLineAttributes attributes = read_by_extension(model, p); + + m.connect(); + + // Mark halfedge as feature line + // May have a smarter way ? + for (auto e : p.iter_edges()) { + for (auto he : m.iter_halfedges()) { + + if (e.from() == he.from() && e.to() == he.to()) { + feature_line_attr[he] = true; + break; + } + } + } + + write_by_extension(out_filename, m, {{}, {}, {{"feature_line", feature_line_attr.ptr}}}); + std::cout << "writed to: " << out_filename << std::endl; + + return 0; +} \ No newline at end of file