From b717ae497454abe1215bd7fd7bfba8c889ead714 Mon Sep 17 00:00:00 2001 From: Jan Kleinert Date: Wed, 20 Dec 2023 11:49:02 +0100 Subject: [PATCH] add algorithm enum to CTiglMakeLoft --- src/CMakeLists.txt | 1 + src/geometry/CTiglMakeLoft.cpp | 31 +++++++++++++++++-------------- src/geometry/CTiglMakeLoft.h | 18 +++++++++++++++++- tests/unittests/tiglMakeLoft.cpp | 2 +- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1c21be844..9c720009d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -83,6 +83,7 @@ target_compile_features(tigl3_objects PRIVATE cxx_std_11) set_property(TARGET tigl3_objects PROPERTY POSITION_INDEPENDENT_CODE ON) # needed for shared libraries option(TIGL_GORDON_SURFACE "Loft curve networks using the Gordon surface algorithm (instead of using Coons patches)" OFF) +mark_as_advanced(TIGL_GORDON_SURFACE) if (TIGL_GORDON_SURFACE) target_compile_definitions(tigl3_objects PUBLIC TIGL_GORDON_SURFACE) endif(TIGL_GORDON_SURFACE) diff --git a/src/geometry/CTiglMakeLoft.cpp b/src/geometry/CTiglMakeLoft.cpp index 8c75a6c1c..2ec46507f 100644 --- a/src/geometry/CTiglMakeLoft.cpp +++ b/src/geometry/CTiglMakeLoft.cpp @@ -67,13 +67,10 @@ namespace { CTiglMakeLoft::CTiglMakeLoft(double tolerance, double sameKnotTolerance) : _hasPerformed{false} , _makeSolid{true} + , _makeSmooth{false} , _myTolerance{tolerance} , _mySameKnotTolerance{sameKnotTolerance} - #ifdef TIGL_GORDON_SURFACE - , _use_gordon_surface_algorithm(true) - #else - , _use_gordon_surface_algorithm(false) - #endif + , _algorithm(Algorithm::COONS_PATCHES) { _result.Nullify(); } @@ -148,10 +145,6 @@ void CTiglMakeLoft::Perform() _hasPerformed = true; } -void CTiglMakeLoft::useGordonSurfaceAlgorithm(bool enabled) { - _use_gordon_surface_algorithm = enabled; -} - void CTiglMakeLoft::setMakeSolid(bool enabled) { _makeSolid = enabled; @@ -162,16 +155,26 @@ void CTiglMakeLoft::setMakeSmooth(bool enabled) _makeSmooth = enabled; } +void CTiglMakeLoft::setAlgorithm(Algorithm algorithm) +{ + _algorithm = algorithm; +} + /** * @brief Builds the loft using profiles and guide curves */ void CTiglMakeLoft::makeLoftWithGuides() { - if (_use_gordon_surface_algorithm) { - makeLoftGordon(); - } - else { - makeLoftCoons(); + switch(_algorithm) { + case Algorithm::GORDON_SURFACE: { + makeLoftGordon(); + break; + } + case Algorithm::COONS_PATCHES: { + makeLoftCoons(); + break; + } + default: throw tigl::CTiglError("Invalid algorithm. Currently only Algorithm::GORDON_SURFACE and Algorithm::COONS_PATCHES are supported.", TIGL_ERROR); } } diff --git a/src/geometry/CTiglMakeLoft.h b/src/geometry/CTiglMakeLoft.h index c7bcf5eb7..a7c548b5f 100644 --- a/src/geometry/CTiglMakeLoft.h +++ b/src/geometry/CTiglMakeLoft.h @@ -24,6 +24,7 @@ #include #include #include + /** * @brief The CTiglMakeLoft class is used to create loft topologies using cross sections * and optional guide curves. By default, the resulting topology is a solid. In order to @@ -33,6 +34,12 @@ class CTiglMakeLoft { public: + enum class Algorithm { + COONS_PATCHES, + GORDON_SURFACE + }; + + TIGL_EXPORT CTiglMakeLoft(double tolerance = 1e-6, double sameKnotTolerance = 1e-6); TIGL_EXPORT CTiglMakeLoft(const TopoDS_Shape& profiles, const TopoDS_Shape& guides, double tolerance = 1e-6, double sameKnotTolerance = 1e-6); @@ -59,6 +66,14 @@ class CTiglMakeLoft */ TIGL_EXPORT void setMakeSolid(bool enabled); + /** + * @brief use this function to select the internal algorithm used by the lofter. + * + * @param algorithm enum for the algorithm (default: Algorithm::COONS_PATCHES) + */ + TIGL_EXPORT void setAlgorithm(Algorithm algorithm); + + /** * @brief Use the function to enable the Gordon surface algorithm to * interpolate curve networks. @@ -116,8 +131,9 @@ class CTiglMakeLoft double _mySameKnotTolerance; std::vector guides, profiles; std::vector uparams, vparams; - bool _hasPerformed, _makeSolid, _use_gordon_surface_algorithm; + bool _hasPerformed, _makeSolid; bool _makeSmooth = false; + Algorithm _algorithm; TopoDS_Shape _result; }; diff --git a/tests/unittests/tiglMakeLoft.cpp b/tests/unittests/tiglMakeLoft.cpp index acb3907e3..ad664a105 100644 --- a/tests/unittests/tiglMakeLoft.cpp +++ b/tests/unittests/tiglMakeLoft.cpp @@ -232,7 +232,7 @@ TEST_P(CurveNetworkCoons, testFromBRep) CTiglMakeLoft lofter(1e-6, 1e-4); lofter.setMakeSolid(false); - lofter.useGordonSurfaceAlgorithm(false); + lofter.setAlgorithm(CTiglMakeLoft::Algorithm::COONS_PATCHES); for (std::vector::const_iterator it = splines_u_vector.begin(); it != splines_u_vector.end(); ++it) { const Handle(Geom_BSplineCurve)& curve = *it;