Skip to content

JeremyBYU/simplifyline

Repository files navigation

Simplify 2D and 3D Lines

PyPI Run Tests Docs License

A high performance 2D and 3D line simplification algorithm. Uses Ramer-Douglas-Peucker Line Simplification.

Key Features

  • Simplify 2D and 3D lines
  • Written in C++ with python bindings. Can be used standalone in a C++ project with CMake as well.
  • Based on high-performance Simplify.js

Install with Python and Use

The python library can be installed as so:

  1. pip install simplifyline

Example Use:

from simplifyline import simplify_line_2d, MatrixDouble 
mat2D = MatrixDouble([[0.0, 0.0], [1.0, 1.0], [2.0, 2.0], [3.0, 3.0]])
results_mat2D = simplify_line_2d(mat2D, max_distance=0.1, high_quality=True)
results = np.array(results_mat2D)
np.testing.assert_array_equal(results, np.array([[0.0, 0.0], [3.0, 3.0]]))

See documentation for more details.

Build Project Manually

You can build the project manually in two ways: using python setup.py, or in pure CMake

Build Manually with Python

The root directory setup.py file has been modified to build with CMake. This is meant for python users that need to build manually (for some reason) but are not actively developing or changing the code.

  1. Install conda or create a python virtual environment (Why?). I recommend conda for Windows users.
  2. pip install . - Call from root directory

Build Manually With CMake

Building happens entirely with CMake. This is meant really only for the library developers who are working on C++ and Python in an edit-compile cycle.

C++ Library

  1. mkdir cmake-build && cd cmake-build
  2. cmake .. - Note - For windows also add -DCMAKE_GENERATOR_PLATFORM=x64
  3. cmake --build . -j$(nproc) --config Release

Build options:

SPL_BUILD_BENCHMARKS:BOOL=ON // SPL - Build Benchmarks
SPL_BUILD_EXAMPLES:BOOL=ON // SPL - Build Examples
SPL_BUILD_PYMODULE:BOOL=ON // SPL -Build Python Module
SPL_BUILD_TESTS:BOOL=ON // SPL - Build Tests
SPL_BUILD_WERROR:BOOL=OFF // SPL - Add Werror flag to build (turns warnings into errors)
SPL_WITH_OPENMP:BOOL=ON // SPL - Build with OpenMP Support

Python Extension

This is meant for advanced python users who are actively developing the extension.

  1. Install conda or create a python virtual environment (Why?). I recommend conda for Windows users.
  2. Perform CMake build as described above
  3. cd cmake-build && cmake --build . --target python-package --config Release
  4. cd lib/python_package && pip install -e . . This installs the library in develop/edit mode. To update the python extension in your python virtual environment all you need to do is run step 3 again.