Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CURA 10724 smooth operator #1891

Merged
merged 52 commits into from
Jul 4, 2023
Merged

CURA 10724 smooth operator #1891

merged 52 commits into from
Jul 4, 2023

Commits on Jun 24, 2023

  1. Smooth operator

    Add a smooth action, which will smooth small segments (maximum resolution) of a polygon,
    whom deviate more than a certain angle (wall transition angle) compared to a fluid motion
    line between the segment before and after.
    
    Smoothing is done by moving the first point of the small middle segment to the first point
    of the previous point with a smooth distance (need to add this to the front end).
    The second point of the middle segment is moved to the second point of the last segment.
    If either the previous or next segment is shorter then the smooth distance, then that point
    in the middle segment is removed
    
    Contributes to CURA-10724
    Contributes to Ultimaker/Cura#14811
    jellespijker committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    0e93b77 View commit details
    Browse the repository at this point in the history
  2. reverted premature optimization

    First make sure that the smoothing works, by not skipping any math steps.
    
    Contributes to Ultimaker/Cura#14811
    Contributes to CURA-10724
    jellespijker committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    9789cf0 View commit details
    Browse the repository at this point in the history
  3. Don't use costly angle calculations

    Shift with vectors instead
    
    Contributes to Ultimaker/Cura#14811
    Contributes to CURA-10724
    jellespijker committed Jun 24, 2023
    Configuration menu
    Copy the full SHA
    e17eb83 View commit details
    Browse the repository at this point in the history

Commits on Jun 25, 2023

  1. Moved concepts to types and util namespace

    Bring a bit more order to this
    
    [CURA-10724]
    jellespijker committed Jun 25, 2023
    Configuration menu
    Copy the full SHA
    4097e93 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    42093f7 View commit details
    Browse the repository at this point in the history
  3. Allow uniform coordinate query with std::get

    This would allow for getting a x,y,z coordinate for a IntPoint, or 3D point,
    described as a struct or vector/array/tuple etc. Will be expanded to accommodate
    Arachne types.
    
    ```
    struct Point{ int X; int Y; }
    Point p_struct{ .X = 1, .Y = 2. };
    
    std::array<int, 2> p_array { 1, 2 };
    
    auto x_struct = std::get<"X">(p_struct);
    auto x_array = std::get<"X">(p_array);
    ```
    
    [CURA-10724]
    jellespijker committed Jun 25, 2023
    Configuration menu
    Copy the full SHA
    46d414b View commit details
    Browse the repository at this point in the history
  4. Use std::get to obtain X,Y

    This allows for reusing the logic for Arachne types.
    
    [CURA-10724]
    jellespijker committed Jun 25, 2023
    Configuration menu
    Copy the full SHA
    f834149 View commit details
    Browse the repository at this point in the history

Commits on Jun 26, 2023

  1. Configuration menu
    Copy the full SHA
    7f2f1cf View commit details
    Browse the repository at this point in the history
  2. Fixed failing UT

    jellespijker committed Jun 26, 2023
    Configuration menu
    Copy the full SHA
    726fd09 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    a455e3a View commit details
    Browse the repository at this point in the history

Commits on Jun 27, 2023

  1. Configuration menu
    Copy the full SHA
    fc19696 View commit details
    Browse the repository at this point in the history
  2. Refactor smooth action and fix pointer issues

    Update smooth action to handle changing path size, cycle views, and filtering out removed points. The previous implementation had issues with sliding views due to the path size change. Also, fix range constraints and improve readability.
    
    This refactor improves the algorithm's accuracy and performance by better handling the changing path size and filtering out points marked for removal. Additionally, the updated range constraints and readability make it easier to understand and maintain the code.
    
    Contributes to CURA-10724
    jellespijker committed Jun 27, 2023
    Configuration menu
    Copy the full SHA
    34858fa View commit details
    Browse the repository at this point in the history

Commits on Jun 28, 2023

  1. Refactor smooth action in utils codebase

    The `smooth` action codebase has been heavily refactored to improve
    readability, avoid redundancy and make the codebase more efficient.
    Importantly, third-party library RangeV3 has been more efficiently used,
    unnecessary headers were removed, and unnecessary debug logs were
    deleted. Also, reusable shifting operation for p1 (towards p0) and p2
    (towards p3) were extracted to a new function, `shiftPointTowards`.
    
    Contributes to CURA-10724
    jellespijker committed Jun 28, 2023
    Configuration menu
    Copy the full SHA
    24a795a View commit details
    Browse the repository at this point in the history

Commits on Jun 29, 2023

  1. Optimize smoothing function and fix error in shift_points

    The smoothing function has been optimized and a bug with the
    shift_points function has been fixed. The operator in the smoothing
    function has been made "constexpr" to potentially improve performance.
    The way "windows" are generated has been restructured to make it clearer
    and eliminate redundancy. In shift_points, the subtraction used to alter
    point's coordinates was replaced with addition to rectify a mistake. The
    distance calculation in the smoothing function has been adjusted from an
    incorrect dot product into a correct hypotenuse calculation. These
    changes should help in improving the efficiency and correctness of the
    smoothing function.
    
    Contributes to CURA-10724
    jellespijker committed Jun 29, 2023
    Configuration menu
    Copy the full SHA
    5b86ae8 View commit details
    Browse the repository at this point in the history
  2. Refactor SmoothTest for more reliable results

    The existing tests for the smooth function were simplified and adjusted.
    It applies the smoothing function to those points and then verifies that
    the original polygon remains the same after smoothing. This change will
    make the test more reliable as it verifies that smoothing algorithm
    doesn't alter essential data.
    
    Contributes to CURA-10724
    jellespijker committed Jun 29, 2023
    Configuration menu
    Copy the full SHA
    5c36cce View commit details
    Browse the repository at this point in the history

Commits on Jul 1, 2023

  1. Extended geometrical type concepts

    This commit adds more granular checks for geometrical types (2D & 3D
    points) in the geometry header. It introduces concepts to inspect
    whether types are represented as tuple, range, or named fields.
    Moreover, it checks if an object is of type segment or a range of
    segments. This refactoring enhances versatility for geometrical types,
    ensuring greater type safety and readability in the code.
    
    Contribute to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    4a15a2c View commit details
    Browse the repository at this point in the history
  2. Add functionality to access 2D and 3D point coordinates by index or c…

    …haracter
    
    This commit addresses the need of accessing point coordinates more
    flexibly. It introduces functions to access the coordinates of 2D and 3D
    points either by coordinate index (e.g. 0 for X, 1 for Y in a 2D point)
    or by character (e.g. 'x' or 'X' for X-coordinate). It makes handling
    points more intuitive and comes in handy when the specific type of point
    (2D or 3D) is not of interest. Additionally, accessing coordinates of a
    junction by index or character is also implemented, further enhancing
    the ease of use.
    
    Contributes to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    db25559 View commit details
    Browse the repository at this point in the history
  3. Update comment syntax in geometry.h

    In this commit, the syntax for the comments in the geometry.h file has
    been updated. The "\\" syntax was replaced by "@" as the latter is more
    standard for Doxygen usage. This change allows for better parsing and
    generation of documentation by Doxygen, and aligns with common practices
    in the software industry.
    
    Contributes to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    6027c54 View commit details
    Browse the repository at this point in the history
  4. Refactor smoothing function, remove unused parameter and improve read…

    …ability
    
    The smoothing function in `smooth.h` was refactored to improve code
    readability and maintainability. The 'smooth_distance' parameter was
    removed as it was not being utilized. The core logic of the function
    remains unchanged, and several variable names were updated to better
    reflect their context and function. Introduced a clearer, more accurate
    method to calculate the cosine of the angle deviation which is also
    generally optimized for smaller values of the `fluid_angle`. This is a
    more computational efficient approach since for 'Curved' interpolations,
    the `fluid_angle` is usually small which solves the primary problem.
    
    Contributes to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    4e1c55f View commit details
    Browse the repository at this point in the history
  5. Refactor smoother functionality in WallToolPaths

    Moved the 'smoother' logic from the 'slicer' and 'WallToolPaths'
    execution to occur earlier in the 'prepared_outline' execution. This
    change intentional to reduce redundancy and improve the efficiency of
    our slicing process by ensuring we're smoothing the polygons just once.
    This could also help reduce the amount of crashes in the Voronoi
    generation/usage
    
    An unnecessary smoother function call with redundant parameters was also
    removed from src/slicer.cpp."
    
    Contributes to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    41e260a View commit details
    Browse the repository at this point in the history
  6. Refine path smoothing algorithm

    Updated the path smoothing algorithm by refining the condition checks
    and optimizing certain calculations for better efficiency.
    
    - Introduced a condition to handle open paths.
    - Corrections in comments for better understanding.
    - Loop stop condition refined to prevent unwanted iterations.
    - Compute function introduced to calculate magnitudes, making the code
       cleaner.
    - Reorganized functions for better readability.
    - Deviation calculation and filtering methods optimized for better
       performance.
    
    This update is aimed at enhancing the performance of path smoothing.
    
    Contributes to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    099a636 View commit details
    Browse the repository at this point in the history
  7. Merge branch '5.4' into CURA-10724_smooth_operator

    # Conflicts:
    #	src/WallToolPaths.cpp
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    f4756d0 View commit details
    Browse the repository at this point in the history
  8. Update smoothing parameters in test

    Updated the parameters in the SmoothTest of CURA utility tests.
    The third parameter of the smoothing function has been removed due to
    recent changes in the CURA engine algorithm. Consequently, the expected
    results of test were also updated to match the output from the updated
    smoothing function.
    
    Contributes to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    5b6bdc7 View commit details
    Browse the repository at this point in the history
  9. Add missing import

    Contributes to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    f8544c1 View commit details
    Browse the repository at this point in the history
  10. fix ranged 2d and 3d point concepts on Apple Clang 13

    I hate Apple Clang!
    
    Contribute to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    925c8ff View commit details
    Browse the repository at this point in the history
  11. Update Geometry checks for compiler support of std::integral

    Due to varying support for the C++20 feature std::integral, preprocessor
    checks were added to the Geometry utility. This ensures that the
    Geometry utility functions will compile and run as expected across
    different compilers, especially older ones or those that don't fully
    support C++20 yet. Additionally, if std::integral is not supported,
    standard member accessing is used instead. This modification enhances
    the code's robustness and compatibility.
    
    Contributes to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    eda05c1 View commit details
    Browse the repository at this point in the history
  12. Add note with stack-overflow comment

    Such that future developers are aware of struggles we had to
    support Apple Clang.
    
    _The pain is real... never give up... word!_
    
    Contributes to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    5cd147b View commit details
    Browse the repository at this point in the history
  13. Adjust Arachne type checks for different C++ versions

    This commit addresses potential compatibility issues with different
    versions of C++ by adding conditionals to the `junction` concept in the
    `arachne.h` utility file. As some versions may not support the
    `std::integral` check, we fall back to directly assessing `val.w` if
    the C++ version is older or a particular library version with
    compatibility issues is detected. This change ensures successful
    compilation across varying environments.
    
    Contributes to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    414f9c6 View commit details
    Browse the repository at this point in the history
  14. Refactor std::integral usage for C++ compatibility

    This commit removes the preprocessor conditions that were originally put
    in to cope with an issue in Clang13 C++20. A fallback version of the
    integral concept has been added in the std namespace if the C++ version
    is below 201703L or if the library version is lesser than the Clang13
    version. This allows for a cleaner and more compatible codebase across
    various C++ versions. In addition, "include/utils/types/generic.h" is
    now being included in "include/utils/types/geometry.h",
    "include/utils/types/arachne.h" and "include/utils/actions/smooth.h"
    everywhere std::integral might be used.
    
    Contributes to CURA-10724
    jellespijker committed Jul 1, 2023
    Configuration menu
    Copy the full SHA
    973c653 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    1694fdc View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    ab6d68c View commit details
    Browse the repository at this point in the history

Commits on Jul 2, 2023

  1. Refactor angle checking in smoothing utility

    The angle checking in the smoothing utility now check against actual
    angles instead of the cosine angle. This is slightly more computational
    heavy but needed since otherwise a lot of points where missed.
    The function `isWithinDeviations` has also been renamed to
    `isWithinAllowedDeviations` for clarity.
    
    Contributes to CURA-10724
    jellespijker committed Jul 2, 2023
    Configuration menu
    Copy the full SHA
    f9a3538 View commit details
    Browse the repository at this point in the history
  2. Start the window at the tail

    Often the first segments weren't filtered, by concatenating the tail to
    the front we also take these last elements into account.
    Also, adjusted the conditions in if-statements for better accuracy and
    introduced variables for allowed deviations and smoothing distance for
    better code consistency.
    
    Contributes to CURA-10724
    jellespijker committed Jul 2, 2023
    Configuration menu
    Copy the full SHA
    f694ca4 View commit details
    Browse the repository at this point in the history
  3. add missing include

    jellespijker committed Jul 2, 2023
    Configuration menu
    Copy the full SHA
    9cc8e97 View commit details
    Browse the repository at this point in the history
  4. Update test

    jellespijker committed Jul 2, 2023
    Configuration menu
    Copy the full SHA
    1edab47 View commit details
    Browse the repository at this point in the history
  5. Replace 'tail' with 'single' in smoothing process

    This change replaces the 'tail' view with a 'single' view in the
    smoothing process of the model. The change ensures that the smoothing
    process takes into consideration the entire model, instead of ignoring
    the first point (head). The 'single' view denotes the single element at
    the back of the range 'tmp'. This small adjustment ensures the smoother
    start of the 3D model's path and addresses a specific corner case where
    the first point was being neglected.
    
    Contributes to CURA-10724
    jellespijker committed Jul 2, 2023
    Configuration menu
    Copy the full SHA
    bc2a8c2 View commit details
    Browse the repository at this point in the history
  6. Less aggressive smoothing

    The filter condition has been altered to be less aggressive, since the
    intend is to smooth out the small sudden deviations. With this in mind
    the removal of points is also discarded since this can introduce self-
    intersecting shapes, which will result in hard crashes, but more
    importantly introduce to much of a deviation from the intended shape.
    
    Contribute to CURA-10724
    jellespijker committed Jul 2, 2023
    Configuration menu
    Copy the full SHA
    6220a38 View commit details
    Browse the repository at this point in the history
  7. Add logging for prepared outline in WallToolPaths

    Added a debug log line for 'prepared_outline' in 'WallToolPaths.cpp' to
    capture and trace its parameters. This is to help troubleshoot issues
    related to polygon simplification and self-intersection fixes in complex
     polygons as it wasn't clear if the existing adjustments solved all
     occurrences.
    
    Contributes to CURA-10724
    jellespijker committed Jul 2, 2023
    Configuration menu
    Copy the full SHA
    8173e59 View commit details
    Browse the repository at this point in the history
  8. Reorder includes and add logging in SkeletalTrapezoidation

    This commit reorders the includes in SkeletonTrapezoidation.cpp for
    better code organization and adds a logging line to aid troubleshooting.
     The logger will now print values of polys, section_type, and layer_idx
     when constructing from polygons, giving better visibility into their
     state in case of issues.
    
     Contributes to CURA-10724
    jellespijker committed Jul 2, 2023
    Configuration menu
    Copy the full SHA
    0ad51a4 View commit details
    Browse the repository at this point in the history
  9. Skip smoothing for support walls

    Added condition to skip smoothing process for sections that are of
    section type 'support'. This is done to improve performance and
    eliminate unnecessary computation as these support walls do not require
    smoothing.
    
    Contributes to CURA-10724
    jellespijker committed Jul 2, 2023
    Configuration menu
    Copy the full SHA
    ded69d4 View commit details
    Browse the repository at this point in the history

Commits on Jul 3, 2023

  1. Use ranges concepts instead of std

    Apple Clang 13 doesn't have full support yet.
    
    Contributes to CURA-10724
    jellespijker committed Jul 3, 2023
    Configuration menu
    Copy the full SHA
    40a8fab View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    95234f7 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    140da4e View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    b7ef734 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    4bf339e View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    9fee071 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    3cc85bc View commit details
    Browse the repository at this point in the history
  8. Improve code readability and add assertions

    Applied review comments.
    
    This commit addresses several changes in the code to improve readability
    and add more assertions where necessary. Redundant comments have been
    removed, such as the namespace declaration in geometry.h for
    readability. Grammar mistakes in comments were corrected for the same
    reason in smooth.h.
    
    In get.h and generic.h, a static assertion was added to restrict the
    size of the string value to one character, ensuring concise point
    coordinate inputs. In generic.h, a comment was added to indicate why we
    are adding a manual implementation of integral and floating point, due
    to lack of support in older versions of Apple Clang.
    
    These changes were made to improve the quality and maintainability of
    the code.
    
    Contributes to CURA-10724
    jellespijker committed Jul 3, 2023
    Configuration menu
    Copy the full SHA
    49ea674 View commit details
    Browse the repository at this point in the history
  9. Quick mock test for green marks

    Write some actual tests
    
    CURA-10724
    jellespijker committed Jul 3, 2023
    Configuration menu
    Copy the full SHA
    a7caa49 View commit details
    Browse the repository at this point in the history
  10. Switched the order of the smoothing

    Smoothing can probably introduce some self-intersections.
    
    Which can result in crashes
    
    CURA-10724
    jellespijker committed Jul 3, 2023
    Configuration menu
    Copy the full SHA
    be715bc View commit details
    Browse the repository at this point in the history
  11. Add unit tests

    casperlamboo committed Jul 3, 2023
    Configuration menu
    Copy the full SHA
    d7fd718 View commit details
    Browse the repository at this point in the history

Commits on Jul 4, 2023

  1. Revert "Add unit tests"

    This reverts commit d7fd718.
    casperlamboo committed Jul 4, 2023
    Configuration menu
    Copy the full SHA
    5044f34 View commit details
    Browse the repository at this point in the history