├── .clang-format ├── .github └── workflows │ ├── ci.yml │ ├── gh-pages.yml │ └── pre-commit.yml ├── .gitignore ├── .gitmodules ├── .pre-commit-config.yaml ├── .readthedocs.yml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cppcolormap.pc.in ├── cppcolormapConfig.cmake ├── docs ├── api_cpp.rst ├── api_python.rst ├── conf.py ├── index.rst └── make.bat ├── environment.yaml ├── examples ├── cpp │ ├── CMakeLists.txt │ └── match.cpp ├── overview │ ├── Colorcycles.png │ ├── Diverging.png │ ├── Qualitative.png │ ├── Sequential.png │ ├── matplotlib.png │ ├── monocolor.png │ ├── monocolor_dvips_1.png │ ├── monocolor_dvips_2.png │ ├── order_dvips.py │ ├── overview.py │ └── trim.sh └── python │ └── match.py ├── include └── cppcolormap.h ├── pyproject.toml ├── python ├── cppcolormap │ └── __init__.py └── main.cpp ├── setup.py └── tests ├── cpp ├── CMakeLists.txt └── main.cpp └── python └── main.py /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | IndentWidth: 4 3 | ColumnLimit: 100 4 | Language: Cpp 5 | DerivePointerAlignment: false 6 | PointerAlignment: Left 7 | AccessModifierOffset: -4 8 | AlignConsecutiveAssignments: false 9 | AlignEscapedNewlines: DontAlign 10 | AllowShortBlocksOnASingleLine: false 11 | AllowShortCaseLabelsOnASingleLine: false 12 | AllowShortFunctionsOnASingleLine: false 13 | AllowShortIfStatementsOnASingleLine: false 14 | AllowShortLoopsOnASingleLine: false 15 | AlwaysBreakTemplateDeclarations: Yes 16 | PenaltyBreakBeforeFirstCallParameter: 1 17 | PenaltyReturnTypeOnItsOwnLine: 100 18 | PointerBindsToType: true 19 | BreakBeforeBraces: Stroustrup 20 | 21 | # Do not align consecutive comments that follow a line of code 22 | AlignTrailingComments: false 23 | 24 | # force argument on one line each 25 | BinPackArguments: false 26 | BinPackParameters: false 27 | ExperimentalAutoDetectBinPacking: false 28 | AllowAllParametersOfDeclarationOnNextLine: false 29 | AlignAfterOpenBracket: BlockIndent 30 | # AlwaysBreakAfterDefinitionReturnType: All 31 | 32 | BraceWrapping: 33 | AfterFunction: true 34 | AfterClass: false 35 | BeforeCatch: true 36 | BeforeElse: true 37 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | workflow_dispatch: 5 | pull_request: 6 | push: 7 | branches: 8 | - main 9 | 10 | jobs: 11 | 12 | standard: 13 | 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | runs-on: [ubuntu-latest, macos-latest, windows-latest] 18 | 19 | defaults: 20 | run: 21 | shell: bash -e -l {0} 22 | 23 | name: ${{ matrix.runs-on }} 24 | runs-on: ${{ matrix.runs-on }} 25 | 26 | steps: 27 | 28 | - name: Clone this library 29 | uses: actions/checkout@v3 30 | with: 31 | fetch-depth: 0 32 | 33 | - name: Create conda environment 34 | uses: mamba-org/setup-micromamba@main 35 | with: 36 | environment-file: environment.yaml 37 | environment-name: myenv 38 | init-shell: bash 39 | cache-downloads: true 40 | post-cleanup: all 41 | condarc: | 42 | channels: 43 | - conda-forge 44 | create-args: >- 45 | matplotlib 46 | ${{ runner.os == 'Windows' && 'clang_win-64' || '' }} 47 | 48 | - name: Export version of this library 49 | run: | 50 | LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) 51 | echo "SETUPTOOLS_SCM_PRETEND_VERSION=$LATEST_TAG" >> $GITHUB_ENV 52 | 53 | - name: Configure using CMake 54 | run: | 55 | export MYARGS="${{ runner.os == 'Windows' && '-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++' || '' }}" 56 | cmake -G Ninja -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_ALL=1 ${MYARGS} 57 | 58 | - name: Build C++ 59 | working-directory: build 60 | run: cmake --build . 61 | 62 | - name: Run C++ 63 | working-directory: build 64 | run: ctest --output-on-failure 65 | 66 | - name: Build and install Python module 67 | run: python -m pip install . -v --no-build-isolation 68 | 69 | - name: Run Python tests 70 | run: python tests/python/main.py 71 | 72 | - name: Run Python examples 73 | run: | 74 | python examples/python/match.py 75 | python examples/overview/overview.py 76 | 77 | - name: Build doxygen-docs (error on warning) 78 | working-directory: build 79 | run: cmake --build . --target html 80 | -------------------------------------------------------------------------------- /.github/workflows/gh-pages.yml: -------------------------------------------------------------------------------- 1 | name: gh-pages 2 | 3 | on: 4 | 5 | push: 6 | branches: 7 | - main 8 | 9 | release: 10 | types: [released] 11 | 12 | jobs: 13 | 14 | publish: 15 | 16 | runs-on: [ubuntu-latest] 17 | 18 | defaults: 19 | run: 20 | shell: bash -e -l {0} 21 | 22 | steps: 23 | 24 | - name: Clone this library 25 | uses: actions/checkout@v3 26 | with: 27 | fetch-depth: 0 28 | 29 | - name: Create conda environment 30 | uses: mamba-org/setup-micromamba@main 31 | with: 32 | environment-file: environment.yaml 33 | environment-name: myenv 34 | init-shell: bash 35 | cache-downloads: true 36 | post-cleanup: all 37 | 38 | - name: Export version of this library 39 | run: | 40 | LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) 41 | echo "SETUPTOOLS_SCM_PRETEND_VERSION=$LATEST_TAG" >> $GITHUB_ENV 42 | 43 | - name: Configure using CMake 44 | run: cmake -Bbuild -DBUILD_DOCS=1 45 | 46 | - name: Build the docs 47 | working-directory: build 48 | run: make html 49 | 50 | - name: Deploy to GitHub Pages 51 | if: success() 52 | uses: crazy-max/ghaction-github-pages@v2 53 | with: 54 | target_branch: gh-pages 55 | build_dir: build/html 56 | jekyll: false 57 | keep_history: false 58 | env: 59 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 60 | -------------------------------------------------------------------------------- /.github/workflows/pre-commit.yml: -------------------------------------------------------------------------------- 1 | name: pre-commit 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: [main] 7 | 8 | jobs: 9 | pre-commit: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | - uses: actions/setup-python@v4 14 | - uses: pre-commit/action@main 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | docs/_doxygen 2 | _skbuild 3 | _cmake_test_compile 4 | 5 | # Prerequisites 6 | *.d 7 | 8 | # Compiled Object files 9 | *.slo 10 | *.lo 11 | *.o 12 | *.obj 13 | 14 | # Precompiled Headers 15 | *.gch 16 | *.pch 17 | 18 | # Compiled Dynamic libraries 19 | *.so 20 | *.dylib 21 | *.dll 22 | 23 | # Fortran module files 24 | *.mod 25 | *.smod 26 | 27 | # Compiled Static libraries 28 | *.lai 29 | *.la 30 | *.a 31 | *.lib 32 | 33 | # Executables 34 | *.exe 35 | *.out 36 | *.app 37 | CMakeCache.txt 38 | CMakeFiles 39 | CMakeScripts 40 | Testing 41 | Makefile 42 | cmake_install.cmake 43 | install_manifest.txt 44 | compile_commands.json 45 | CTestTestfile.cmake 46 | # Byte-compiled / optimized / DLL files 47 | __pycache__/ 48 | *.py[cod] 49 | *$py.class 50 | 51 | # C extensions 52 | *.so 53 | 54 | # Distribution / packaging 55 | .Python 56 | build/ 57 | develop-eggs/ 58 | dist/ 59 | downloads/ 60 | eggs/ 61 | .eggs/ 62 | lib/ 63 | lib64/ 64 | parts/ 65 | sdist/ 66 | var/ 67 | wheels/ 68 | *.egg-info/ 69 | .installed.cfg 70 | *.egg 71 | MANIFEST 72 | 73 | # PyInstaller 74 | # Usually these files are written by a python script from a template 75 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 76 | *.manifest 77 | *.spec 78 | 79 | # Installer logs 80 | pip-log.txt 81 | pip-delete-this-directory.txt 82 | 83 | # Unit test / coverage reports 84 | htmlcov/ 85 | .tox/ 86 | .coverage 87 | .coverage.* 88 | .cache 89 | nosetests.xml 90 | coverage.xml 91 | *.cover 92 | .hypothesis/ 93 | .pytest_cache/ 94 | 95 | # Translations 96 | *.mo 97 | *.pot 98 | 99 | # Django stuff: 100 | *.log 101 | local_settings.py 102 | db.sqlite3 103 | 104 | # Flask stuff: 105 | instance/ 106 | .webassets-cache 107 | 108 | # Scrapy stuff: 109 | .scrapy 110 | 111 | # Sphinx documentation 112 | docs/_build/ 113 | 114 | # PyBuilder 115 | target/ 116 | 117 | # Jupyter Notebook 118 | .ipynb_checkpoints 119 | 120 | # pyenv 121 | .python-version 122 | 123 | # celery beat schedule file 124 | celerybeat-schedule 125 | 126 | # SageMath parsed files 127 | *.sage.py 128 | 129 | # Environments 130 | .env 131 | .venv 132 | env/ 133 | venv/ 134 | ENV/ 135 | env.bak/ 136 | venv.bak/ 137 | 138 | # Spyder project settings 139 | .spyderproject 140 | .spyproject 141 | 142 | # Rope project settings 143 | .ropeproject 144 | 145 | # mkdocs documentation 146 | /site 147 | 148 | # mypy 149 | .mypy_cache/ 150 | ## Core latex/pdflatex auxiliary files: 151 | *.aux 152 | *.lof 153 | *.log 154 | *.lot 155 | *.fls 156 | *.out 157 | *.toc 158 | *.fmt 159 | *.fot 160 | *.cb 161 | *.cb2 162 | .*.lb 163 | 164 | ## Intermediate documents: 165 | *.dvi 166 | *.xdv 167 | *-converted-to.* 168 | # these rules might exclude image files for figures etc. 169 | # *.ps 170 | # *.eps 171 | # *.pdf 172 | 173 | ## Generated if empty string is given at "Please type another file name for output:" 174 | .pdf 175 | 176 | ## Bibliography auxiliary files (bibtex/biblatex/biber): 177 | *.bbl 178 | *.bcf 179 | *.blg 180 | *-blx.aux 181 | *-blx.bib 182 | *.run.xml 183 | 184 | ## Build tool auxiliary files: 185 | *.fdb_latexmk 186 | *.synctex 187 | *.synctex(busy) 188 | *.synctex.gz 189 | *.synctex.gz(busy) 190 | *.pdfsync 191 | 192 | ## Build tool directories for auxiliary files 193 | # latexrun 194 | latex.out/ 195 | 196 | ## Auxiliary and intermediate files from other packages: 197 | # algorithms 198 | *.alg 199 | *.loa 200 | 201 | # achemso 202 | acs-*.bib 203 | 204 | # amsthm 205 | *.thm 206 | 207 | # beamer 208 | *.nav 209 | *.pre 210 | *.snm 211 | *.vrb 212 | 213 | # changes 214 | *.soc 215 | 216 | # cprotect 217 | *.cpt 218 | 219 | # elsarticle (documentclass of Elsevier journals) 220 | *.spl 221 | 222 | # endnotes 223 | *.ent 224 | 225 | # fixme 226 | *.lox 227 | 228 | # feynmf/feynmp 229 | *.mf 230 | *.mp 231 | *.t[1-9] 232 | *.t[1-9][0-9] 233 | *.tfm 234 | 235 | #(r)(e)ledmac/(r)(e)ledpar 236 | *.end 237 | *.?end 238 | *.[1-9] 239 | *.[1-9][0-9] 240 | *.[1-9][0-9][0-9] 241 | *.[1-9]R 242 | *.[1-9][0-9]R 243 | *.[1-9][0-9][0-9]R 244 | *.eledsec[1-9] 245 | *.eledsec[1-9]R 246 | *.eledsec[1-9][0-9] 247 | *.eledsec[1-9][0-9]R 248 | *.eledsec[1-9][0-9][0-9] 249 | *.eledsec[1-9][0-9][0-9]R 250 | 251 | # glossaries 252 | *.acn 253 | *.acr 254 | *.glg 255 | *.glo 256 | *.gls 257 | *.glsdefs 258 | 259 | # gnuplottex 260 | *-gnuplottex-* 261 | 262 | # gregoriotex 263 | *.gaux 264 | *.gtex 265 | 266 | # htlatex 267 | *.4ct 268 | *.4tc 269 | *.idv 270 | *.lg 271 | *.trc 272 | *.xref 273 | 274 | # hyperref 275 | *.brf 276 | 277 | # knitr 278 | *-concordance.tex 279 | # TODO Comment the next line if you want to keep your tikz graphics files 280 | *.tikz 281 | *-tikzDictionary 282 | 283 | # listings 284 | *.lol 285 | 286 | # makeidx 287 | *.idx 288 | *.ilg 289 | *.ind 290 | *.ist 291 | 292 | # minitoc 293 | *.maf 294 | *.mlf 295 | *.mlt 296 | *.mtc[0-9]* 297 | *.slf[0-9]* 298 | *.slt[0-9]* 299 | *.stc[0-9]* 300 | 301 | # minted 302 | _minted* 303 | *.pyg 304 | 305 | # morewrites 306 | *.mw 307 | 308 | # nomencl 309 | *.nlg 310 | *.nlo 311 | *.nls 312 | 313 | # pax 314 | *.pax 315 | 316 | # pdfpcnotes 317 | *.pdfpc 318 | 319 | # sagetex 320 | *.sagetex.sage 321 | *.sagetex.py 322 | *.sagetex.scmd 323 | 324 | # scrwfile 325 | *.wrt 326 | 327 | # sympy 328 | *.sout 329 | *.sympy 330 | sympy-plots-for-*.tex/ 331 | 332 | # pdfcomment 333 | *.upa 334 | *.upb 335 | 336 | # pythontex 337 | *.pytxcode 338 | pythontex-files-*/ 339 | 340 | # thmtools 341 | *.loe 342 | 343 | # TikZ & PGF 344 | *.dpth 345 | *.md5 346 | *.auxlock 347 | 348 | # todonotes 349 | *.tdo 350 | 351 | # easy-todo 352 | *.lod 353 | 354 | # xmpincl 355 | *.xmpi 356 | 357 | # xindy 358 | *.xdy 359 | 360 | # xypic precompiled matrices 361 | *.xyc 362 | 363 | # endfloat 364 | *.ttt 365 | *.fff 366 | 367 | # Latexian 368 | TSWLatexianTemp* 369 | 370 | ## Editors: 371 | # WinEdt 372 | *.bak 373 | *.sav 374 | 375 | # Texpad 376 | .texpadtmp 377 | 378 | # LyX 379 | *.lyx~ 380 | 381 | # Kile 382 | *.backup 383 | 384 | # KBibTeX 385 | *~[0-9]* 386 | 387 | # auto folder when using emacs and auctex 388 | ./auto/* 389 | *.el 390 | 391 | # expex forward references with \gathertags 392 | *-tags.tex 393 | 394 | # standalone packages 395 | *.sta 396 | .DS_Store 397 | applet 398 | application.linux32 399 | application.linux64 400 | application.windows32 401 | application.windows64 402 | application.macosx 403 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tdegeus/cppcolormap/f6e75517772699d38cadfc9101d29092ead2a1e7/.gitmodules -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v4.5.0 4 | hooks: 5 | - id: trailing-whitespace 6 | - id: end-of-file-fixer 7 | - id: check-yaml 8 | - id: check-toml 9 | - id: debug-statements 10 | - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks 11 | rev: v2.11.0 12 | hooks: 13 | - id: pretty-format-yaml 14 | args: [--preserve-quotes, --autofix, --indent, '2'] 15 | - id: pretty-format-toml 16 | args: [--autofix] 17 | - repo: https://github.com/psf/black 18 | rev: 23.9.1 19 | hooks: 20 | - id: black 21 | args: [--safe, --quiet, --line-length=100] 22 | - repo: https://github.com/humitos/mirrors-autoflake.git 23 | rev: v1.1 24 | hooks: 25 | - id: autoflake 26 | args: [--in-place, --remove-unused-variable, --remove-all-unused-imports] 27 | - repo: https://github.com/asottile/reorder_python_imports 28 | rev: v3.12.0 29 | hooks: 30 | - id: reorder-python-imports 31 | - repo: https://github.com/asottile/pyupgrade 32 | rev: v3.15.0 33 | hooks: 34 | - id: pyupgrade 35 | args: [--py36-plus] 36 | - repo: https://github.com/PyCQA/flake8 37 | rev: 6.1.0 38 | hooks: 39 | - id: flake8 40 | args: [--max-line-length=100] 41 | - repo: https://github.com/asottile/setup-cfg-fmt 42 | rev: v2.5.0 43 | hooks: 44 | - id: setup-cfg-fmt 45 | - repo: https://github.com/tdegeus/cpp_comment_format 46 | rev: v0.2.0 47 | hooks: 48 | - id: cpp_comment_format 49 | - repo: https://github.com/pre-commit/mirrors-clang-format 50 | rev: v17.0.2 51 | hooks: 52 | - id: clang-format 53 | args: [-i] 54 | - repo: https://github.com/tdegeus/conda_envfile 55 | rev: v0.4.2 56 | hooks: 57 | - id: conda_envfile_parse 58 | files: environment.yaml 59 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | sphinx: 4 | configuration: docs/conf.py 5 | 6 | conda: 7 | environment: environment.yaml 8 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.18..3.21) 2 | 3 | project(cppcolormap) 4 | 5 | string(TOUPPER "${PROJECT_NAME}" PROJECT_NAME_UPPER) 6 | 7 | # Command-line options 8 | # ==================== 9 | 10 | option(BUILD_ALL "${PROJECT_NAME}: Build tests, Python API & docs" OFF) 11 | option(BUILD_TESTS "${PROJECT_NAME}: Build tests" OFF) 12 | option(BUILD_EXAMPLES "${PROJECT_NAME}: Build examples" OFF) 13 | option(BUILD_PYTHON "${PROJECT_NAME}: Build Python API" OFF) 14 | option(BUILD_DOCS "${PROJECT_NAME}: Build docs (use `make html`)" OFF) 15 | 16 | if(SKBUILD) 17 | set(BUILD_ALL 0) 18 | set(BUILD_TESTS 0) 19 | set(BUILD_PYTHON 1) 20 | set(BUILD_DOCS 0) 21 | endif() 22 | 23 | # Read version 24 | # ============ 25 | 26 | if (DEFINED ENV{SETUPTOOLS_SCM_PRETEND_VERSION}) 27 | set(PROJECT_VERSION $ENV{SETUPTOOLS_SCM_PRETEND_VERSION}) 28 | message(STATUS "Building ${PROJECT_NAME} ${PROJECT_VERSION} (read from SETUPTOOLS_SCM_PRETEND_VERSION)") 29 | else() 30 | execute_process( 31 | COMMAND python -c "from setuptools_scm import get_version; print(get_version())" 32 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 33 | OUTPUT_VARIABLE PROJECT_VERSION 34 | OUTPUT_STRIP_TRAILING_WHITESPACE) 35 | 36 | message(STATUS "Building ${PROJECT_NAME} ${PROJECT_VERSION}") 37 | endif() 38 | 39 | # Set target 40 | # ========== 41 | 42 | find_package(xtensor REQUIRED) 43 | 44 | add_library(${PROJECT_NAME} INTERFACE) 45 | 46 | target_include_directories(${PROJECT_NAME} INTERFACE 47 | $ 48 | $) 49 | 50 | target_link_libraries(${PROJECT_NAME} INTERFACE xtensor) 51 | 52 | target_compile_definitions(${PROJECT_NAME} INTERFACE 53 | ${PROJECT_NAME_UPPER}_VERSION="${PROJECT_VERSION}") 54 | 55 | # Libraries 56 | # ========= 57 | 58 | include(CMakePackageConfigHelpers) 59 | include(GNUInstallDirs) 60 | include(CTest) 61 | include("${PROJECT_NAME}Config.cmake") 62 | 63 | # Installation headers / CMake / pkg-config 64 | # ========================================= 65 | 66 | if(NOT SKBUILD) 67 | 68 | install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION include) 69 | 70 | configure_file("include/cppcolormap.h" 71 | "${CMAKE_CURRENT_BINARY_DIR}/cppcolormap.h" 72 | @ONLY) 73 | 74 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cppcolormap.h" 75 | DESTINATION "include/") 76 | 77 | install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets) 78 | 79 | install( 80 | EXPORT ${PROJECT_NAME}-targets 81 | FILE "${PROJECT_NAME}Targets.cmake" 82 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") 83 | 84 | set(${PROJECT_NAME}_TMP ${CMAKE_SIZEOF_VOID_P}) 85 | unset(CMAKE_SIZEOF_VOID_P) 86 | 87 | write_basic_package_version_file( 88 | "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" 89 | VERSION "${PROJECT_VERSION}" 90 | COMPATIBILITY AnyNewerVersion) 91 | 92 | set(CMAKE_SIZEOF_VOID_P ${${PROJECT_NAME}_TMP}) 93 | 94 | install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake" 95 | "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" 96 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") 97 | 98 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in" 99 | "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY) 100 | 101 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" 102 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") 103 | 104 | endif() 105 | 106 | # Build tests 107 | # =========== 108 | 109 | if(BUILD_TESTS OR BUILD_ALL) 110 | 111 | enable_testing() 112 | add_subdirectory(tests/cpp) 113 | 114 | endif() 115 | 116 | # Build examples 117 | # ============== 118 | 119 | if(BUILD_EXAMPLES OR BUILD_ALL) 120 | 121 | enable_testing() 122 | add_subdirectory(examples/cpp) 123 | 124 | endif() 125 | 126 | # Build Python API 127 | # ================ 128 | 129 | if(BUILD_PYTHON OR BUILD_ALL) 130 | 131 | # The C++ functions are build to a library with name "_${PROJECT_NAME}" 132 | # The Python library simply loads all functions 133 | set(PYPROJECT_NAME "_${PROJECT_NAME}") 134 | 135 | if(NOT CMAKE_BUILD_TYPE) 136 | set(CMAKE_BUILD_TYPE Release) 137 | endif() 138 | 139 | find_package(pybind11 REQUIRED CONFIG) 140 | find_package(xtensor-python REQUIRED) 141 | 142 | if (SKBUILD) 143 | find_package(NumPy REQUIRED) 144 | else() 145 | find_package(Python REQUIRED COMPONENTS Interpreter Development NumPy) 146 | endif() 147 | 148 | pybind11_add_module(${PYPROJECT_NAME} python/main.cpp) 149 | 150 | target_compile_definitions(${PYPROJECT_NAME} PUBLIC VERSION_INFO=${PROJECT_VERSION}) 151 | target_compile_definitions(${PYPROJECT_NAME} PUBLIC CPPCOLORMAP_ENABLE_ASSERT) 152 | target_link_libraries(${PYPROJECT_NAME} PUBLIC ${PROJECT_NAME} xtensor-python) 153 | 154 | if (SKBUILD) 155 | target_include_directories(${PYPROJECT_NAME} PUBLIC ${NumPy_INCLUDE_DIRS}) 156 | else() 157 | target_link_libraries(${PYPROJECT_NAME} PUBLIC ${PROJECT_NAME} pybind11::module Python::NumPy) 158 | endif() 159 | 160 | if (SKBUILD) 161 | if(APPLE) 162 | set_target_properties(${PYPROJECT_NAME} PROPERTIES INSTALL_RPATH "@loader_path/${CMAKE_INSTALL_LIBDIR}") 163 | else() 164 | set_target_properties(${PYPROJECT_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/${CMAKE_INSTALL_LIBDIR}") 165 | endif() 166 | install(TARGETS ${PYPROJECT_NAME} DESTINATION .) 167 | endif() 168 | 169 | endif() 170 | 171 | # Build documentation 172 | # =================== 173 | 174 | if(BUILD_DOCS OR BUILD_ALL) 175 | 176 | find_package(Doxygen REQUIRED) 177 | 178 | set(DOXYGEN_EXCLUDE_SYMBOLS detail) 179 | set(DOXYGEN_CASE_SENSE_NAMES YES) 180 | set(DOXYGEN_USE_MATHJAX YES) 181 | set(DOXYGEN_GENERATE_TREEVIEW YES) 182 | set(DOXYGEN_JAVADOC_AUTOBRIEF YES) 183 | set(DOXYGEN_MACRO_EXPANSION YES) 184 | set(DOXYGEN_SOURCE_BROWSER YES) 185 | set(DOXYGEN_GENERATE_XML YES) 186 | set(DOXYGEN_QUIET YES) 187 | set(DOXYGEN_WARN_IF_UNDOCUMENTED YES) 188 | set(DOXYGEN_WARN_AS_ERROR YES) 189 | set(DOXYGEN_HTML_COLORSTYLE TOGGLE) 190 | set(DOXYGEN_ALIASES "license=@par License:") 191 | set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "README.md") 192 | set(DOXYGEN_STRIP_FROM_INC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include") 193 | set(DOXYGEN_STRIP_FROM_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include") 194 | doxygen_add_docs(html "${CMAKE_CURRENT_SOURCE_DIR}/include" "README.md") 195 | 196 | endif() 197 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![CI](https://github.com/tdegeus/cppcolormap/workflows/CI/badge.svg)](https://github.com/tdegeus/cppcolormap/actions) 2 | [![Doxygen -> gh-pages](https://github.com/tdegeus/cppcolormap/workflows/gh-pages/badge.svg)](https://tdegeus.github.io/cppcolormap) 3 | [![Documentation Status](https://readthedocs.org/projects/cppcolormap/badge/?version=latest)](https://readthedocs.org/projects/cppcolormap/badge/?version=latest) 4 | [![Conda Version](https://img.shields.io/conda/vn/conda-forge/cppcolormap.svg)](https://anaconda.org/conda-forge/cppcolormap) 5 | [![Conda Version](https://img.shields.io/conda/vn/conda-forge/python-cppcolormap.svg)](https://anaconda.org/conda-forge/python-cppcolormap) 6 | 7 | Documentation: [cppcolormap.readthedocs.org](https://cppcolormap.readthedocs.org) 8 | 9 | Doxygen documentation: [tdegeus.github.io/cppcolormap](https://tdegeus.github.io/cppcolormap) 10 | 11 | # cppcolormap 12 | 13 | C++ and Python library specifying colormaps. 14 | 15 |

16 | 17 |

18 | 19 |

20 | 21 |

22 | 23 |

24 | 25 |

26 | 27 |

28 | 29 |

30 | 31 |

32 | 33 |

34 | 35 |

36 | 37 |

38 | 39 |

40 | 41 |

42 | 43 |

44 | 45 |

46 | 47 | # Contents 48 | 49 | # Disclaimer 50 | 51 | This library is free to use under the [GPLv3 license](https://github.com/tdegeus/cppcolormap/blob/master/LICENSE). Any additions are very much appreciated, in terms of suggested functionality, code, documentation, testimonials, word-of-mouth advertisement, etc. Bug reports or feature requests can be filed on [GitHub](https://github.com/tdegeus/cppcolormap). As always, the code comes with no guarantee. None of the developers can be held responsible for possible mistakes. 52 | 53 | Download: [.zip file](https://github.com/tdegeus/cppcolormap/zipball/master) | [.tar.gz file](https://github.com/tdegeus/cppcolormap/tarball/master). 54 | 55 | (c - [GPLv3](https://github.com/tdegeus/cppcolormap/blob/master/LICENSE)) T.W.J. de Geus (Tom) | tom@geus.me | www.geus.me | [github.com/tdegeus/cppcolormap](https://github.com/tdegeus/cppcolormap) 56 | 57 | **Contributors** 58 | 59 | * [Wolf Vollprecht](https://github.com/wolfv) 60 | 61 | # Usage from C++ 62 | 63 | ## Getting cppcolormap 64 | 65 | ### Using conda 66 | 67 | ``` 68 | conda install -c conda-forge cppcolormap 69 | ``` 70 | 71 | ### From source 72 | 73 | ```bash 74 | # Download cppcolormap 75 | git checkout https://github.com/tdegeus/cppcolormap.git 76 | cd cppcolormap 77 | 78 | # For CMake or pkg-config use 79 | cmake . 80 | make install 81 | ``` 82 | 83 | ## Usage 84 | 85 | The principle interface is with these two functions: 86 | 87 | ```cpp 88 | #include 89 | 90 | int main() 91 | { 92 | std::cout << cppcolormap::colormap("Reds") << std::endl; 93 | std::cout << cppcolormap::colorcycle("tue") << std::endl; 94 | 95 | return 0; 96 | } 97 | ``` 98 | 99 | Lists of colormaps and color-cycles can be found below. 100 | 101 | The colormaps are stored as a matrix whereby each row contains the (R,G,B) colors. Each color value has a range `[0..1]`. The number of colors varies from map to map, but can be interpolated by specifying the number of colors you want: 102 | 103 | ```cpp 104 | #include 105 | 106 | int main() 107 | { 108 | std::cout << cppcolormap::colormap("Reds", 256) << std::endl; 109 | 110 | return 0; 111 | } 112 | ``` 113 | 114 | Note that the colorcycles are not interpolatable. Consequently the functions do have a size option. Note also that the colormaps and colorcycles can also be called directly, e.g. 115 | 116 | ```cpp 117 | #include 118 | 119 | int main() 120 | { 121 | std::cout << cppcolormap::Reds() << std::endl; 122 | std::cout << cppcolormap::Reds(256) << std::endl; 123 | std::cout << cppcolormap::tue() << std::endl; 124 | 125 | return 0; 126 | } 127 | ``` 128 | 129 | ## Find match 130 | 131 | To find the closest match of each color of a colormap in another colormap you can use: 132 | 133 | ```cpp 134 | xt::xtensor idx = cppcolormap::match(cmap1, cmap2); 135 | xt::xtensor idx = cppcolormap::match(cmap1, cmap2, cppcolormap::metric::euclidean); 136 | ``` 137 | 138 | The following metrics can be used: 139 | 140 | * euclidean (default) 141 | * fast_perceptual 142 | * perceptual 143 | 144 | ## Compiling 145 | 146 | ### Using CMake 147 | 148 | Using *cppcolormap* the `CMakeLists.txt` can be as follows 149 | 150 | ```cmake 151 | cmake_minimum_required(VERSION 3.1) 152 | project(example) 153 | find_package(cppcolormap REQUIRED) 154 | add_executable(example example.cpp) 155 | target_link_libraries(example PRIVATE cppcolormap) 156 | ``` 157 | 158 | Note that the target *cppcolormap* includes the target *xtensor* (itself automatically enforcing the minimal C++14 standard), which is automatically searched using `find_package(cppcolormap)`. 159 | 160 | Compilation can then proceed using 161 | 162 | * Unix: 163 | 164 | ``` 165 | cmake . 166 | make 167 | ``` 168 | 169 | * Windows: 170 | 171 | ```none 172 | cmake -G"NMake Makefiles" . 173 | nmake 174 | ``` 175 | 176 | [Download example "CMakeLists.txt"](./example/CMakeLists.txt) 177 | 178 | ### Using pkg-config 179 | 180 | Presuming that the compiler is `c++`, compile using (Unix): 181 | 182 | ``` 183 | c++ `pkg-config --cflags cppcolormap` `pkg-config --cflags xtensor` -std=c++14 ... 184 | ``` 185 | 186 | ### By hand 187 | 188 | Presuming that the compiler is `c++`, compile using (Unix): 189 | 190 | ``` 191 | c++ -I/path/to/cppcolormap/include -I/path/to/xtensor/include -std=c++14 ... 192 | ``` 193 | 194 | # Usage from Python 195 | 196 | ## Getting cppcolormap 197 | 198 | ### Using conda 199 | 200 | ``` 201 | conda install -c conda-forge python-cppcolormap 202 | ``` 203 | 204 | ### From source 205 | 206 | ```bash 207 | # Download cppcolormap 208 | git checkout https://github.com/tdegeus/cppcolormap.git 209 | cd cppcolormap 210 | 211 | # Compile and install 212 | python -m pip install . 213 | ``` 214 | 215 | Note that you have to install the dependencies *pybind11*, *xtensor*, and *pyxtensor* first. 216 | 217 | ## Usage 218 | 219 | There are two principle functions, each returns a 2-d NumPy array: 220 | 221 | ```python 222 | import cppcolormap as cm 223 | 224 | # number of colors in the colormap (optional, may be omitted) 225 | N = 256 226 | 227 | # specify the colormap as string 228 | cols = cm.colormap("Reds", N) 229 | cols = cm.colorcycle("tue") 230 | 231 | # or call the functions directly 232 | cols = cm.Reds(N) 233 | cols = cm.tue() 234 | ``` 235 | 236 | (see lists of colormaps and color-cycles below). 237 | 238 | ## Find match 239 | 240 | To find the closest match of each color of a colormap in another colormap you can use: 241 | 242 | ```cpp 243 | idx = cm.match(cmap1, cmap2) 244 | idx = cm.match(cmap1, cmap2, cm.metric.perceptual) 245 | ``` 246 | 247 | (See metrics above.) 248 | 249 | ## Example 250 | 251 | ```python 252 | import matplotlib 253 | import matplotlib.pyplot as plt 254 | import numpy as np 255 | import cppcolormap as cm 256 | 257 | x, y = np.meshgrid( 258 | np.linspace(0, 1, 100), 259 | np.linspace(0, 1, 100)) 260 | 261 | d = np.sqrt(x ** 2.0 + y ** 2.0) 262 | 263 | C = cm.Reds(256) 264 | C = np.c_[C, np.ones(C.shape[0])] 265 | 266 | cmap = matplotlib.colors.LinearSegmentedColormap.from_list('my_colormap', C) 267 | 268 | fig, ax = plt.subplots() 269 | cax = ax.imshow(d, cmap=cmap) 270 | plt.show() 271 | ``` 272 | 273 | # Available colormaps 274 | 275 | ## ColorBrewer 276 | 277 | | Name | Inverse colormap | 278 | |----------|------------------| 279 | | Accent | Accent_r | 280 | | Dark2 | Dark2_r | 281 | | Paired | Paired_r | 282 | | Spectral | Spectral_r | 283 | | Pastel1 | Pastel1_r | 284 | | Pastel2 | Pastel2_r | 285 | | Set1 | Set1_r | 286 | | Set2 | Set2_r | 287 | | Set3 | Set3_r | 288 | | Blues | Blues_r | 289 | | Greens | Greens_r | 290 | | Greys | Greys_r | 291 | | Oranges | Oranges_r | 292 | | Purples | Purples_r | 293 | | Reds | Reds_r | 294 | | BuPu | BuPu_r | 295 | | GnBu | GnBu_r | 296 | | PuBu | PuBu_r | 297 | | PuBuGn | PuBuGn_r | 298 | | PuRd | PuRd_r | 299 | | RdPu | RdPu_r | 300 | | OrRd | OrRd_r | 301 | | RdOrYl | RdOrYl_r | 302 | | YlGn | YlGn_r | 303 | | YlGnBu | YlGnBu_r | 304 | | YlOrRd | YlOrRd_r | 305 | | BrBG | BrBG_r | 306 | | PuOr | PuOr_r | 307 | | RdBu | RdBu_r | 308 | | RdGy | RdGy_r | 309 | | RdYlBu | RdYlBu_r | 310 | | RdYlGn | RdYlGn_r | 311 | | PiYG | PiYG_r | 312 | | PRGn | PRGn_r | 313 | 314 | > Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State University. 315 | > 316 | > Licensed under the Apache License, Version 2.0 317 | > 318 | > [colorbrewer2.org](http://colorbrewer2.org) 319 | 320 | ## matplotlib 321 | 322 | | Name | Inverse colormap | 323 | |---------------|------------------| 324 | | spring | spring_r | 325 | | summer | summer_r | 326 | | autumn | autumn_r | 327 | | winter | winter_r | 328 | | bone | bone_r | 329 | | cool | cool_r | 330 | | hot | hot_r | 331 | | copper | copper_r | 332 | | hsv | hsv_r | 333 | | nipy_spectral | nipy_spectral_r | 334 | | terrain | terrain_r | 335 | | seismic | seismic_r | 336 | | afmhot | afmhot_r | 337 | | magma | magma_r | 338 | | inferno | inferno_r | 339 | | plasma | plasma_r | 340 | | viridis | viridis_r | 341 | | jet | jet_r | 342 | 343 | > Copyright (c) New matplotlib colormaps by Nathaniel J. Smith, Stefan van der Walt, and 344 | > in the case of viridis) Eric Firing. 345 | > 346 | > Licensed under the CC0 license / public domain dedication. 347 | > 348 | > [GitHub/BIDS](https://github.com/BIDS/colormap) 349 | 350 | ## monocolor 351 | 352 | | Name | Inverse colormap | Source | 353 | |----------------|------------------|--------| 354 | | White | - | | 355 | | Grey | - | | 356 | | Black | - | | 357 | | Red | - | | 358 | | Blue | - | | 359 | | tuedarkblue | - | [1] | 360 | | tueblue | - | [1] | 361 | | tuelightblue | - | [1] | 362 | | tuewarmred | - | [1] | 363 | | Apricot | - | [2] | 364 | | Aquamarine | - | [2] | 365 | | Bittersweet | - | [2] | 366 | | Black | - | [2] | 367 | | Blue | - | [2] | 368 | | BlueGreen | - | [2] | 369 | | BlueViolet | - | [2] | 370 | | BrickRed | - | [2] | 371 | | Brown | - | [2] | 372 | | BurntOrange | - | [2] | 373 | | CadetBlue | - | [2] | 374 | | CarnationPink | - | [2] | 375 | | Cerulean | - | [2] | 376 | | CornflowerBlue | - | [2] | 377 | | Cyan | - | [2] | 378 | | Dandelion | - | [2] | 379 | | DarkOrchid | - | [2] | 380 | | Emerald | - | [2] | 381 | | ForestGreen | - | [2] | 382 | | Fuchsia | - | [2] | 383 | | Goldenrod | - | [2] | 384 | | Gray | - | [2] | 385 | | Green | - | [2] | 386 | | GreenYellow | - | [2] | 387 | | JungleGreen | - | [2] | 388 | | Lavender | - | [2] | 389 | | LimeGreen | - | [2] | 390 | | Magenta | - | [2] | 391 | | Mahogany | - | [2] | 392 | | Maroon | - | [2] | 393 | | Melon | - | [2] | 394 | | MidnightBlue | - | [2] | 395 | | Mulberry | - | [2] | 396 | | NavyBlue | - | [2] | 397 | | OliveGreen | - | [2] | 398 | | Orange | - | [2] | 399 | | OrangeRed | - | [2] | 400 | | Orchid | - | [2] | 401 | | Peach | - | [2] | 402 | | Periwinkle | - | [2] | 403 | | PineGreen | - | [2] | 404 | | Plum | - | [2] | 405 | | ProcessBlue | - | [2] | 406 | | Purple | - | [2] | 407 | | RawSienna | - | [2] | 408 | | Red | - | [2] | 409 | | RedOrange | - | [2] | 410 | | RedViolet | - | [2] | 411 | | Rhodamine | - | [2] | 412 | | RoyalBlue | - | [2] | 413 | | RoyalPurple | - | [2] | 414 | | RubineRed | - | [2] | 415 | | Salmon | - | [2] | 416 | | SeaGreen | - | [2] | 417 | | Sepia | - | [2] | 418 | | SkyBlue | - | [2] | 419 | | SpringGreen | - | [2] | 420 | | Tan | - | [2] | 421 | | TealBlue | - | [2] | 422 | | Thistle | - | [2] | 423 | | Turquoise | - | [2] | 424 | | Violet | - | [2] | 425 | | VioletRed | - | [2] | 426 | | White | - | [2] | 427 | | WildStrawberry | - | [2] | 428 | | Yellow | - | [2] | 429 | | YellowGreen | - | [2] | 430 | | YellowOrange | - | [2] | 431 | 432 | 1. [Eindhoven University of Technology](http://www.tue.nl) 433 | 2. [LaTeX xcolor (dvipsnames)](https://en.wikibooks.org/wiki/LaTeX/Colors) 434 | 435 | # Available colorcycles 436 | 437 | ## Xterm 438 | 439 | | Name | Inverse colormap | 440 | |-------|------------------| 441 | | xterm | xterm_r | 442 | 443 | > See [this site](https://jonasjacek.github.io/colors/) 444 | 445 | ## Eindhoven University of Technology 446 | 447 | | Name | Inverse colormap | 448 | |------|------------------| 449 | | tue | tue_r | 450 | 451 | 452 | > Based on the corporate color scheme of the 453 | > [Eindhoven University of Technology](http://www.tue.nl). 454 | -------------------------------------------------------------------------------- /cppcolormap.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | includedir=${prefix}/include 3 | 4 | Name: @PROJECT_NAME@ 5 | Description: Colormaps for C++. 6 | Version: @PROJECT_VERSION@ 7 | Cflags: -I${includedir} 8 | -------------------------------------------------------------------------------- /cppcolormapConfig.cmake: -------------------------------------------------------------------------------- 1 | # cppcolormap cmake module 2 | # 3 | # This module sets the target: 4 | # 5 | # cppcolormap 6 | # 7 | # In addition, it sets the following variables: 8 | # 9 | # cppcolormap_FOUND - true if cppcolormap found 10 | # cppcolormap_VERSION - cppcolormap's version 11 | # cppcolormap_INCLUDE_DIRS - the directory containing cppcolormap headers 12 | # The following support targets are defined to simplify things: 13 | # 14 | # cppcolormap::compiler_warnings - enable compiler warnings 15 | 16 | include(CMakeFindDependencyMacro) 17 | 18 | find_dependency(xtensor) 19 | 20 | if(NOT TARGET cppcolormap) 21 | include("${CMAKE_CURRENT_LIST_DIR}/cppcolormapTargets.cmake") 22 | get_target_property(cppcolormap_INCLUDE_DIRS cppcolormap INTERFACE_INCLUDE_DIRECTORIES) 23 | endif() 24 | 25 | # Define support target "cppcolormap::compiler_warnings" 26 | 27 | if(NOT TARGET cppcolormap::compiler_warnings) 28 | add_library(cppcolormap::compiler_warnings INTERFACE IMPORTED) 29 | if(MSVC) 30 | set_property( 31 | TARGET cppcolormap::compiler_warnings 32 | PROPERTY INTERFACE_COMPILE_OPTIONS 33 | /W4) 34 | else() 35 | set_property( 36 | TARGET cppcolormap::compiler_warnings 37 | PROPERTY INTERFACE_COMPILE_OPTIONS 38 | -Wall -Wextra -pedantic -Wno-unknown-pragmas) 39 | endif() 40 | endif() 41 | -------------------------------------------------------------------------------- /docs/api_cpp.rst: -------------------------------------------------------------------------------- 1 | ******* 2 | C++ API 3 | ******* 4 | 5 | See doxygen output: tdegeus.github.io/cppcolormap 6 | 7 | .. doxygenfile:: cppcolormap.h 8 | :project: cppcolormap 9 | -------------------------------------------------------------------------------- /docs/api_python.rst: -------------------------------------------------------------------------------- 1 | ********** 2 | Python API 3 | ********** 4 | 5 | Overview 6 | ======== 7 | 8 | Functions 9 | --------- 10 | 11 | .. autosummary:: 12 | 13 | cppcolormap.colormap 14 | cppcolormap.colorcycle 15 | cppcolormap.hex2rgb 16 | cppcolormap.rgb2hex 17 | cppcolormap.as_colors 18 | cppcolormap.match 19 | cppcolormap.version 20 | cppcolormap.version_dependencies 21 | 22 | Colorbrewer 23 | ----------- 24 | 25 | .. autosummary:: 26 | 27 | cppcolormap.Accent 28 | cppcolormap.Dark2 29 | cppcolormap.Paired 30 | cppcolormap.Spectral 31 | cppcolormap.Pastel1 32 | cppcolormap.Pastel2 33 | cppcolormap.Set1 34 | cppcolormap.Set2 35 | cppcolormap.Set3 36 | cppcolormap.Blues 37 | cppcolormap.Greens 38 | cppcolormap.Greys 39 | cppcolormap.Oranges 40 | cppcolormap.Purples 41 | cppcolormap.Reds 42 | cppcolormap.BuPu 43 | cppcolormap.GnBu 44 | cppcolormap.PuBu 45 | cppcolormap.PuBuGn 46 | cppcolormap.PuRd 47 | cppcolormap.RdPu 48 | cppcolormap.OrRd 49 | cppcolormap.RdOrYl 50 | cppcolormap.YlGn 51 | cppcolormap.YlGnBu 52 | cppcolormap.YlOrRd 53 | cppcolormap.BrBG 54 | cppcolormap.PuOr 55 | cppcolormap.RdBu 56 | cppcolormap.RdGy 57 | cppcolormap.RdYlBu 58 | cppcolormap.RdYlGn 59 | cppcolormap.PiYG 60 | cppcolormap.PRGn 61 | 62 | Matplotlib 63 | ---------- 64 | 65 | .. autosummary:: 66 | 67 | cppcolormap.spring 68 | cppcolormap.summer 69 | cppcolormap.autumn 70 | cppcolormap.winter 71 | cppcolormap.bone 72 | cppcolormap.cool 73 | cppcolormap.hot 74 | cppcolormap.copper 75 | cppcolormap.hsv 76 | cppcolormap.nipy_spectral 77 | cppcolormap.terrain 78 | cppcolormap.seismic 79 | cppcolormap.afmhot 80 | cppcolormap.magma 81 | cppcolormap.inferno 82 | cppcolormap.plasma 83 | cppcolormap.viridis 84 | cppcolormap.jet 85 | 86 | Miscelleneous 87 | ------------- 88 | 89 | .. autosummary:: 90 | 91 | cppcolormap.xterm 92 | cppcolormap.tue 93 | 94 | Colors 95 | ------ 96 | 97 | .. autosummary:: 98 | 99 | cppcolormap.Apricot 100 | cppcolormap.Aquamarine 101 | cppcolormap.Bittersweet 102 | cppcolormap.Black 103 | cppcolormap.Blue 104 | cppcolormap.BlueGreen 105 | cppcolormap.BlueViolet 106 | cppcolormap.BrickRed 107 | cppcolormap.Brown 108 | cppcolormap.BurntOrange 109 | cppcolormap.CadetBlue 110 | cppcolormap.CarnationPink 111 | cppcolormap.Cerulean 112 | cppcolormap.CornflowerBlue 113 | cppcolormap.Cyan 114 | cppcolormap.Dandelion 115 | cppcolormap.DarkOrchid 116 | cppcolormap.Emerald 117 | cppcolormap.ForestGreen 118 | cppcolormap.Fuchsia 119 | cppcolormap.Goldenrod 120 | cppcolormap.Gray 121 | cppcolormap.Green 122 | cppcolormap.GreenYellow 123 | cppcolormap.Grey 124 | cppcolormap.JungleGreen 125 | cppcolormap.Lavender 126 | cppcolormap.LimeGreen 127 | cppcolormap.Magenta 128 | cppcolormap.Mahogany 129 | cppcolormap.Maroon 130 | cppcolormap.Melon 131 | cppcolormap.MidnightBlue 132 | cppcolormap.Mulberry 133 | cppcolormap.NavyBlue 134 | cppcolormap.OliveGreen 135 | cppcolormap.Orange 136 | cppcolormap.OrangeRed 137 | cppcolormap.Orchid 138 | cppcolormap.Peach 139 | cppcolormap.Periwinkle 140 | cppcolormap.PineGreen 141 | cppcolormap.Plum 142 | cppcolormap.ProcessBlue 143 | cppcolormap.Purple 144 | cppcolormap.RawSienna 145 | cppcolormap.Red 146 | cppcolormap.RedOrange 147 | cppcolormap.RedViolet 148 | cppcolormap.Rhodamine 149 | cppcolormap.RoyalBlue 150 | cppcolormap.RoyalPurple 151 | cppcolormap.RubineRed 152 | cppcolormap.Salmon 153 | cppcolormap.SeaGreen 154 | cppcolormap.Sepia 155 | cppcolormap.SkyBlue 156 | cppcolormap.SpringGreen 157 | cppcolormap.Tan 158 | cppcolormap.TealBlue 159 | cppcolormap.Thistle 160 | cppcolormap.tueblue 161 | cppcolormap.tuedarkblue 162 | cppcolormap.tuelightblue 163 | cppcolormap.tuewarmred 164 | cppcolormap.Turquoise 165 | cppcolormap.Violet 166 | cppcolormap.VioletRed 167 | cppcolormap.White 168 | cppcolormap.WildStrawberry 169 | cppcolormap.Yellow 170 | cppcolormap.YellowGreen 171 | cppcolormap.YellowOrange 172 | 173 | Reversed color(map)s 174 | -------------------- 175 | 176 | .. autosummary:: 177 | 178 | cppcolormap.Accent_r 179 | cppcolormap.Dark2_r 180 | cppcolormap.Paired_r 181 | cppcolormap.Spectral_r 182 | cppcolormap.Pastel1_r 183 | cppcolormap.Pastel2_r 184 | cppcolormap.Set1_r 185 | cppcolormap.Set2_r 186 | cppcolormap.Set3_r 187 | cppcolormap.Blues_r 188 | cppcolormap.Greens_r 189 | cppcolormap.Greys_r 190 | cppcolormap.Oranges_r 191 | cppcolormap.Purples_r 192 | cppcolormap.Reds_r 193 | cppcolormap.BuPu_r 194 | cppcolormap.GnBu_r 195 | cppcolormap.PuBu_r 196 | cppcolormap.PuBuGn_r 197 | cppcolormap.PuRd_r 198 | cppcolormap.RdPu_r 199 | cppcolormap.OrRd_r 200 | cppcolormap.RdOrYl_r 201 | cppcolormap.YlGn_r 202 | cppcolormap.YlGnBu_r 203 | cppcolormap.YlOrRd_r 204 | cppcolormap.BrBG_r 205 | cppcolormap.PuOr_r 206 | cppcolormap.RdBu_r 207 | cppcolormap.RdGy_r 208 | cppcolormap.RdYlBu_r 209 | cppcolormap.RdYlGn_r 210 | cppcolormap.PiYG_r 211 | cppcolormap.PRGn_r 212 | cppcolormap.spring_r 213 | cppcolormap.summer_r 214 | cppcolormap.autumn_r 215 | cppcolormap.winter_r 216 | cppcolormap.bone_r 217 | cppcolormap.cool_r 218 | cppcolormap.hot_r 219 | cppcolormap.copper_r 220 | cppcolormap.hsv_r 221 | cppcolormap.nipy_spectral_r 222 | cppcolormap.terrain_r 223 | cppcolormap.seismic_r 224 | cppcolormap.afmhot_r 225 | cppcolormap.magma_r 226 | cppcolormap.inferno_r 227 | cppcolormap.plasma_r 228 | cppcolormap.viridis_r 229 | cppcolormap.jet_r 230 | cppcolormap.xterm_r 231 | cppcolormap.tue_r 232 | 233 | Details 234 | ======= 235 | 236 | .. automodule:: cppcolormap 237 | :members: 238 | :special-members: 239 | :undoc-members: 240 | :show-inheritance: 241 | :exclude-members: __weakref__, __doc__, __module__, __dict__, __members__, __getstate__, __setstate__ 242 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | import sys 4 | 5 | project = "cppcolormap" 6 | copyright = "2021-2023, Tom de Geus" 7 | author = "Tom de Geus" 8 | 9 | subprocess.call("cd ..; python setup.py build --build-type Release -vv", shell=True) 10 | mybuild = os.listdir("../_skbuild")[0] 11 | sys.path.insert(0, os.path.abspath(f"../_skbuild/{mybuild}/cmake-install/python")) 12 | 13 | doxydir = "_doxygen" 14 | 15 | if not os.path.isdir(doxydir): 16 | os.mkdir(doxydir) 17 | 18 | subprocess.call(f"cmake .. -B{doxydir:s} -DBUILD_DOCS=1", shell=True) 19 | subprocess.call(f"cd {doxydir:s}; make html", shell=True) 20 | 21 | extensions = [ 22 | "breathe", 23 | "sphinx.ext.autodoc", 24 | "sphinx.ext.autosummary", 25 | "sphinx_mdinclude", 26 | ] 27 | 28 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] 29 | 30 | html_theme = "furo" 31 | 32 | breathe_projects = { 33 | project: f"{doxydir:s}/xml/", 34 | } 35 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | 2 | .. mdinclude:: ../README.md 3 | 4 | Documentation 5 | ============= 6 | 7 | .. toctree:: 8 | :caption: API 9 | :maxdepth: 1 10 | 11 | api_cpp.rst 12 | api_python.rst 13 | 14 | Indices and tables 15 | ================== 16 | 17 | * :ref:`genindex` 18 | * :ref:`modindex` 19 | * :ref:`search` 20 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.https://www.sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /environment.yaml: -------------------------------------------------------------------------------- 1 | channels: 2 | - conda-forge 3 | dependencies: 4 | - breathe 5 | - catch2 >=3.0.0 6 | - cmake 7 | - doxygen 8 | - furo 9 | - ninja 10 | - numpy 11 | - pybind11 12 | - python 13 | - scikit-build 14 | - setuptools_scm 15 | - sphinx 16 | - sphinx-mdinclude 17 | - xtensor 18 | - xtensor-python >=0.25.2 19 | -------------------------------------------------------------------------------- /examples/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.19..3.21) 2 | 3 | if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) 4 | project(cppcolormap) 5 | find_package(cppcolormap REQUIRED CONFIG) 6 | endif() 7 | 8 | set(MYPROJECT "${PROJECT_NAME}-examples") 9 | 10 | if(NOT CMAKE_BUILD_TYPE) 11 | set(CMAKE_BUILD_TYPE Release) 12 | endif() 13 | 14 | find_package(Catch2 REQUIRED) 15 | find_package(xtensor REQUIRED) 16 | 17 | add_library(mytarget INTERFACE IMPORTED) 18 | 19 | target_link_libraries(mytarget INTERFACE 20 | ${PROJECT_NAME} 21 | ${PROJECT_NAME}::compiler_warnings 22 | Catch2::Catch2) 23 | 24 | file(GLOB APP_SOURCES *.cpp) 25 | 26 | foreach(mysource ${APP_SOURCES}) 27 | string(REPLACE ".cpp" "" myexec ${mysource}) 28 | get_filename_component(myexec ${myexec} NAME) 29 | add_executable(${myexec} ${mysource}) 30 | target_link_libraries(${myexec} PRIVATE mytarget) 31 | add_test(NAME ${myexec} COMMAND ${myexec}) 32 | endforeach() 33 | -------------------------------------------------------------------------------- /examples/cpp/match.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | auto cmap = cppcolormap::Reds(); 6 | auto xterm = cppcolormap::xterm(); 7 | auto idx = cppcolormap::match(cmap, xterm, cppcolormap::metric::perceptual); 8 | auto cmap_as_xterm = xt::view(xterm, xt::keep(idx), xt::all()); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /examples/overview/Colorcycles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tdegeus/cppcolormap/f6e75517772699d38cadfc9101d29092ead2a1e7/examples/overview/Colorcycles.png -------------------------------------------------------------------------------- /examples/overview/Diverging.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tdegeus/cppcolormap/f6e75517772699d38cadfc9101d29092ead2a1e7/examples/overview/Diverging.png -------------------------------------------------------------------------------- /examples/overview/Qualitative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tdegeus/cppcolormap/f6e75517772699d38cadfc9101d29092ead2a1e7/examples/overview/Qualitative.png -------------------------------------------------------------------------------- /examples/overview/Sequential.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tdegeus/cppcolormap/f6e75517772699d38cadfc9101d29092ead2a1e7/examples/overview/Sequential.png -------------------------------------------------------------------------------- /examples/overview/matplotlib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tdegeus/cppcolormap/f6e75517772699d38cadfc9101d29092ead2a1e7/examples/overview/matplotlib.png -------------------------------------------------------------------------------- /examples/overview/monocolor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tdegeus/cppcolormap/f6e75517772699d38cadfc9101d29092ead2a1e7/examples/overview/monocolor.png -------------------------------------------------------------------------------- /examples/overview/monocolor_dvips_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tdegeus/cppcolormap/f6e75517772699d38cadfc9101d29092ead2a1e7/examples/overview/monocolor_dvips_1.png -------------------------------------------------------------------------------- /examples/overview/monocolor_dvips_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tdegeus/cppcolormap/f6e75517772699d38cadfc9101d29092ead2a1e7/examples/overview/monocolor_dvips_2.png -------------------------------------------------------------------------------- /examples/overview/order_dvips.py: -------------------------------------------------------------------------------- 1 | import cppcolormap as cm 2 | import numpy as np 3 | 4 | names = ( 5 | "Apricot", 6 | "Aquamarine", 7 | "Bittersweet", 8 | "Black", 9 | "Blue", 10 | "BlueGreen", 11 | "BlueViolet", 12 | "BrickRed", 13 | "Brown", 14 | "BurntOrange", 15 | "CadetBlue", 16 | "CarnationPink", 17 | "Cerulean", 18 | "CornflowerBlue", 19 | "Cyan", 20 | "Dandelion", 21 | "DarkOrchid", 22 | "Emerald", 23 | "ForestGreen", 24 | "Fuchsia", 25 | "Goldenrod", 26 | "Gray", 27 | "Green", 28 | "GreenYellow", 29 | "JungleGreen", 30 | "Lavender", 31 | "LimeGreen", 32 | "Magenta", 33 | "Mahogany", 34 | "Maroon", 35 | "Melon", 36 | "MidnightBlue", 37 | "Mulberry", 38 | "NavyBlue", 39 | "OliveGreen", 40 | "Orange", 41 | "OrangeRed", 42 | "Orchid", 43 | "Peach", 44 | "Periwinkle", 45 | "PineGreen", 46 | "Plum", 47 | "ProcessBlue", 48 | "Purple", 49 | "RawSienna", 50 | "Red", 51 | "RedOrange", 52 | "RedViolet", 53 | "Rhodamine", 54 | "RoyalBlue", 55 | "RoyalPurple", 56 | "RubineRed", 57 | "Salmon", 58 | "SeaGreen", 59 | "Sepia", 60 | "SkyBlue", 61 | "SpringGreen", 62 | "Tan", 63 | "TealBlue", 64 | "Thistle", 65 | "Turquoise", 66 | "Violet", 67 | "VioletRed", 68 | "WildStrawberry", 69 | "Yellow", 70 | "YellowGreen", 71 | "YellowOrange", 72 | ) 73 | 74 | dvips = np.array([list(cm.colormap(name, 1)[0, :]) for name in names]) 75 | jet = cm.jet(256) 76 | 77 | 78 | idx = cm.match(dvips, jet, cm.metric.perceptual) 79 | jdx = np.argsort(idx) 80 | print("\n".join([names[i] for i in jdx])) 81 | -------------------------------------------------------------------------------- /examples/overview/overview.py: -------------------------------------------------------------------------------- 1 | import cppcolormap as cm 2 | import matplotlib as mpl 3 | import matplotlib.pyplot as plt 4 | import numpy as np 5 | 6 | # Colormap 7 | 8 | cmaps = { 9 | "Qualitative": ( 10 | "Accent", 11 | "Dark2", 12 | "Paired", 13 | "Spectral", 14 | "Pastel1", 15 | "Pastel2", 16 | "Set1", 17 | "Set2", 18 | "Set3", 19 | ), 20 | "Sequential": ( 21 | "Blues", 22 | "Greens", 23 | "Greys", 24 | "Oranges", 25 | "Purples", 26 | "Reds", 27 | "BuPu", 28 | "GnBu", 29 | "PuBu", 30 | "PuBuGn", 31 | "PuRd", 32 | "RdPu", 33 | "OrRd", 34 | "YlGn", 35 | "YlGnBu", 36 | "YlOrRd", 37 | "RdOrYl", 38 | ), 39 | "Diverging": ("BrBG", "PuOr", "RdBu", "RdGy", "RdYlBu", "RdYlGn", "PiYG", "PRGn"), 40 | "matplotlib": ( 41 | "spring", 42 | "summer", 43 | "autumn", 44 | "winter", 45 | "cool", 46 | "hot", 47 | "bone", 48 | "copper", 49 | "afmhot", 50 | "terrain", 51 | "seismic", 52 | "magma", 53 | "inferno", 54 | "plasma", 55 | "viridis", 56 | "nipy_spectral", 57 | "hsv", 58 | "jet", 59 | ), 60 | "monocolor": ( 61 | "White", 62 | "Gray", 63 | "Grey", 64 | "Black", 65 | "Red", 66 | "Blue", 67 | "Green", 68 | "Yellow", 69 | "Purple", 70 | "Cyan", 71 | "Orange", 72 | "tuewarmred", 73 | "tuedarkblue", 74 | "tueblue", 75 | "tuelightblue", 76 | ), 77 | "monocolor - dvips (1)": ( 78 | "Plum", 79 | "Fuchsia", 80 | "BlueViolet", 81 | "Violet", 82 | "RoyalPurple", 83 | "MidnightBlue", 84 | "NavyBlue", 85 | "RoyalBlue", 86 | "CadetBlue", 87 | "Periwinkle", 88 | "PineGreen", 89 | "Cerulean", 90 | "JungleGreen", 91 | "Emerald", 92 | "TealBlue", 93 | "CornflowerBlue", 94 | "ProcessBlue", 95 | "Aquamarine", 96 | "BlueGreen", 97 | "Turquoise", 98 | "SkyBlue", 99 | "SeaGreen", 100 | "ForestGreen", 101 | "OliveGreen", 102 | "YellowGreen", 103 | "LimeGreen", 104 | "SpringGreen", 105 | "GreenYellow", 106 | ), 107 | "monocolor - dvips (2)": ( 108 | "Goldenrod", 109 | "Dandelion", 110 | "Apricot", 111 | "YellowOrange", 112 | "Lavender", 113 | "Melon", 114 | "Tan", 115 | "Peach", 116 | "BurntOrange", 117 | "Salmon", 118 | "Thistle", 119 | "CarnationPink", 120 | "Orchid", 121 | "RedOrange", 122 | "VioletRed", 123 | "Rhodamine", 124 | "DarkOrchid", 125 | "Bittersweet", 126 | "WildStrawberry", 127 | "OrangeRed", 128 | "Magenta", 129 | "RubineRed", 130 | "BrickRed", 131 | "Maroon", 132 | "Mulberry", 133 | "Mahogany", 134 | "RedViolet", 135 | "RawSienna", 136 | "Sepia", 137 | "Brown", 138 | ), 139 | } 140 | 141 | nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps.items()) 142 | gradient = np.linspace(0, 1, 256) 143 | gradient = np.vstack((gradient, gradient)) 144 | 145 | 146 | def plot_color_gradients(cmap_category, cmap_list, nrows): 147 | fig, axes = plt.subplots(nrows=nrows) 148 | fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99) 149 | axes[0].set_title(cmap_category + " colormaps", fontsize=14) 150 | 151 | for ax, name in zip(axes, cmap_list): 152 | c = cm.colormap(name) 153 | c = mpl.colors.ListedColormap(c, name=name, N=c.shape[0]) 154 | ax.imshow(gradient, aspect="auto", cmap=c) 155 | pos = list(ax.get_position().bounds) 156 | x_text = pos[0] - 0.01 157 | y_text = pos[1] + pos[3] / 2.0 158 | fig.text(x_text, y_text, name, va="center", ha="right", fontsize=10) 159 | 160 | for ax in axes: 161 | ax.set_axis_off() 162 | 163 | plt.savefig( 164 | cmap_category.replace(" ", "_").replace("(", "").replace(")", "").replace("_-_", "_") 165 | + ".png" 166 | ) 167 | plt.close() 168 | 169 | 170 | for cmap_category, cmap_list in cmaps.items(): 171 | plot_color_gradients(cmap_category, cmap_list, nrows) 172 | 173 | # Colorcyles 174 | 175 | cmaps = ("tue", "xterm") 176 | 177 | 178 | def plot_color_gradients(cmap_category, cmap_list, nrows): 179 | fig, axes = plt.subplots(nrows=nrows) 180 | fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99) 181 | axes[0].set_title(cmap_category, fontsize=14) 182 | 183 | for ax, name in zip(axes, cmap_list): 184 | c = cm.colorcycle(name) 185 | N = c.shape[0] 186 | c = mpl.colors.ListedColormap(c, name=name, N=N) 187 | gradient = np.linspace(0, 1, N) 188 | gradient = np.vstack((gradient, gradient)) 189 | ax.imshow(gradient, aspect="auto", cmap=c) 190 | pos = list(ax.get_position().bounds) 191 | x_text = pos[0] - 0.01 192 | y_text = pos[1] + pos[3] / 2.0 193 | fig.text(x_text, y_text, name, va="center", ha="right", fontsize=10) 194 | 195 | for ax in axes: 196 | ax.set_axis_off() 197 | 198 | plt.savefig( 199 | cmap_category.replace(" ", "_").replace("(", "").replace(")", "").replace("_-_", "_") 200 | + ".png" 201 | ) 202 | plt.close() 203 | 204 | 205 | plot_color_gradients("Colorcycles", cmaps, nrows) 206 | -------------------------------------------------------------------------------- /examples/overview/trim.sh: -------------------------------------------------------------------------------- 1 | convert -trim Colorcycles.png Colorcycles_trimmed.png 2 | convert -trim Diverging.png Diverging_trimmed.png 3 | convert -trim Qualitative.png Qualitative_trimmed.png 4 | convert -trim Sequential.png Sequential_trimmed.png 5 | convert -trim matplotlib.png matplotlib_trimmed.png 6 | convert -trim monocolor.png monocolor_trimmed.png 7 | convert -trim monocolor_dvips_1.png monocolor_dvips_1_trimmed.png 8 | convert -trim monocolor_dvips_2.png monocolor_dvips_2_trimmed.png 9 | 10 | mv Colorcycles_trimmed.png Colorcycles.png 11 | mv Diverging_trimmed.png Diverging.png 12 | mv Qualitative_trimmed.png Qualitative.png 13 | mv Sequential_trimmed.png Sequential.png 14 | mv matplotlib_trimmed.png matplotlib.png 15 | mv monocolor_trimmed.png monocolor.png 16 | mv monocolor_dvips_1_trimmed.png monocolor_dvips_1.png 17 | mv monocolor_dvips_2_trimmed.png monocolor_dvips_2.png 18 | -------------------------------------------------------------------------------- /examples/python/match.py: -------------------------------------------------------------------------------- 1 | import cppcolormap as cm 2 | import matplotlib as mpl 3 | import matplotlib.pyplot as plt 4 | import numpy as np 5 | 6 | cmap = cm.Reds() 7 | m_cmap = mpl.colors.ListedColormap(cmap, name="Reds", N=cmap.shape[0]) 8 | 9 | xterm = cm.xterm() 10 | idx = cm.match(cmap, xterm, cm.metric.perceptual) 11 | m_xterm = mpl.colors.ListedColormap(xterm[idx, :], name="xterm", N=cmap.shape[0]) 12 | 13 | fig, axes = plt.subplots(figsize=(16, 8), ncols=2) 14 | 15 | x, y = np.meshgrid(np.linspace(0, 99, 100), np.linspace(0, 99, 100)) 16 | 17 | z = (x - 50) ** 2.0 + (y - 50) ** 2.0 18 | 19 | im = axes[0].imshow(z, cmap=m_cmap, clim=(0, 5000)) 20 | im = axes[1].imshow(z, cmap=m_xterm, clim=(0, 5000)) 21 | 22 | plt.savefig("match.pdf") 23 | plt.close() 24 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | build-backend = "setuptools.build_meta" 3 | requires = [ 4 | "setuptools>=42", 5 | "scikit-build>=0.13", 6 | "cmake>=3.18", 7 | "setuptools_scm[toml]>=3.4", 8 | "ninja", 9 | "numpy" 10 | ] 11 | 12 | [tool.setuptools_scm] 13 | write_to = "python/cppcolormap/_version.py" 14 | -------------------------------------------------------------------------------- /python/cppcolormap/__init__.py: -------------------------------------------------------------------------------- 1 | from ._cppcolormap import * # noqa: F401, F403 2 | -------------------------------------------------------------------------------- /python/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #define FORCE_IMPORT_ARRAY 6 | #include 7 | #include 8 | 9 | #define CPPCOLORMAP_USE_XTENSOR_PYTHON 10 | #include 11 | 12 | namespace py = pybind11; 13 | 14 | #define DOC(function) \ 15 | (std::string("See C++ API: :cpp:func:`cppcolormap::") + std::string(function) + \ 16 | std::string("`")) \ 17 | .c_str() 18 | 19 | #define ENUM(function) \ 20 | (std::string("See C++ API: :cpp:enum:`cppcolormap::") + std::string(function) + \ 21 | std::string("`")) \ 22 | .c_str() 23 | 24 | /** 25 | * Overrides the `__name__` of a module. 26 | * Classes defined by pybind11 use the `__name__` of the module as of the time they are defined, 27 | * which affects the `__repr__` of the class type objects. 28 | */ 29 | class ScopedModuleNameOverride { 30 | public: 31 | explicit ScopedModuleNameOverride(py::module m, std::string name) : module_(std::move(m)) 32 | { 33 | original_name_ = module_.attr("__name__"); 34 | module_.attr("__name__") = name; 35 | } 36 | ~ScopedModuleNameOverride() 37 | { 38 | module_.attr("__name__") = original_name_; 39 | } 40 | 41 | private: 42 | py::module module_; 43 | py::object original_name_; 44 | }; 45 | 46 | PYBIND11_MODULE(_cppcolormap, m) 47 | { 48 | // Ensure members to display as `cppcolormap.X` rather than `cppcolormap._cppcolormap.X` 49 | ScopedModuleNameOverride name_override(m, "cppcolormap"); 50 | 51 | xt::import_numpy(); 52 | 53 | m.doc() = "Library with colormaps."; 54 | 55 | m.def("version", &cppcolormap::version, DOC("version")); 56 | m.def("version_dependencies", &cppcolormap::version_dependencies, DOC("version_dependencies")); 57 | 58 | m.def( 59 | "rgb2hex", 60 | static_cast&)>(&cppcolormap::rgb2hex), 61 | DOC("rgb2hex") 62 | ); 63 | 64 | m.def( 65 | "rgb2hex", 66 | static_cast (*)(const xt::pytensor&)>( 67 | &cppcolormap::rgb2hex 68 | ), 69 | DOC("rgb2hex") 70 | ); 71 | 72 | m.def( 73 | "hex2rgb", 74 | py::overload_cast&>(&cppcolormap::hex2rgb), 75 | DOC("hex2rgb") 76 | ); 77 | 78 | m.def("hex2rgb", py::overload_cast(&cppcolormap::hex2rgb), DOC("hex2rgb")); 79 | 80 | m.def( 81 | "interp", 82 | &cppcolormap::interp, xt::pytensor>, 83 | DOC("interp"), 84 | py::arg("arg"), 85 | py::arg("N") 86 | ); 87 | 88 | m.def( 89 | "as_colors", 90 | [](const xt::pyarray& data, 91 | const xt::pytensor& colors, 92 | double vmin, 93 | double vmax) { return cppcolormap::as_colors(data, colors, vmin, vmax); }, 94 | DOC("as_colors"), 95 | py::arg("data"), 96 | py::arg("colors"), 97 | py::arg("vmin"), 98 | py::arg("vmax") 99 | ); 100 | 101 | m.def( 102 | "as_colors", 103 | [](const xt::pyarray& data, const xt::pytensor& colors) { 104 | return cppcolormap::as_colors(data, colors); 105 | }, 106 | DOC("as_colors"), 107 | py::arg("data"), 108 | py::arg("colors") 109 | ); 110 | 111 | m.def("Accent", &cppcolormap::Accent, DOC("Accent"), py::arg("N") = 8); 112 | m.def("Dark2", &cppcolormap::Dark2, DOC("Dark2"), py::arg("N") = 8); 113 | m.def("Paired", &cppcolormap::Paired, DOC("Paired"), py::arg("N") = 12); 114 | m.def("Spectral", &cppcolormap::Spectral, DOC("Spectral"), py::arg("N") = 11); 115 | m.def("Pastel1", &cppcolormap::Pastel1, DOC("Pastel1"), py::arg("N") = 9); 116 | m.def("Pastel2", &cppcolormap::Pastel2, DOC("Pastel2"), py::arg("N") = 8); 117 | m.def("Set1", &cppcolormap::Set1, DOC("Set1"), py::arg("N") = 9); 118 | m.def("Set2", &cppcolormap::Set2, DOC("Set2"), py::arg("N") = 8); 119 | m.def("Set3", &cppcolormap::Set3, DOC("Set3"), py::arg("N") = 12); 120 | m.def("Blues", &cppcolormap::Blues, DOC("Blues"), py::arg("N") = 9); 121 | m.def("Greens", &cppcolormap::Greens, DOC("Greens"), py::arg("N") = 9); 122 | m.def("Greys", &cppcolormap::Greys, DOC("Greys"), py::arg("N") = 2); 123 | m.def("Oranges", &cppcolormap::Oranges, DOC("Oranges"), py::arg("N") = 9); 124 | m.def("Purples", &cppcolormap::Purples, DOC("Purples"), py::arg("N") = 9); 125 | m.def("Reds", &cppcolormap::Reds, DOC("Reds"), py::arg("N") = 9); 126 | m.def("BuPu", &cppcolormap::BuPu, DOC("BuPu"), py::arg("N") = 9); 127 | m.def("GnBu", &cppcolormap::GnBu, DOC("GnBu"), py::arg("N") = 9); 128 | m.def("PuBu", &cppcolormap::PuBu, DOC("PuBu"), py::arg("N") = 9); 129 | m.def("PuBuGn", &cppcolormap::PuBuGn, DOC("PuBuGn"), py::arg("N") = 9); 130 | m.def("PuRd", &cppcolormap::PuRd, DOC("PuRd"), py::arg("N") = 9); 131 | m.def("RdPu", &cppcolormap::RdPu, DOC("RdPu"), py::arg("N") = 9); 132 | m.def("OrRd", &cppcolormap::OrRd, DOC("OrRd"), py::arg("N") = 9); 133 | m.def("RdOrYl", &cppcolormap::RdOrYl, DOC("RdOrYl"), py::arg("N") = 9); 134 | m.def("YlGn", &cppcolormap::YlGn, DOC("YlGn"), py::arg("N") = 9); 135 | m.def("YlGnBu", &cppcolormap::YlGnBu, DOC("YlGnBu"), py::arg("N") = 9); 136 | m.def("YlOrRd", &cppcolormap::YlOrRd, DOC("YlOrRd"), py::arg("N") = 9); 137 | m.def("BrBG", &cppcolormap::BrBG, DOC("BrBG"), py::arg("N") = 11); 138 | m.def("PuOr", &cppcolormap::PuOr, DOC("PuOr"), py::arg("N") = 11); 139 | m.def("RdBu", &cppcolormap::RdBu, DOC("RdBu"), py::arg("N") = 11); 140 | m.def("RdGy", &cppcolormap::RdGy, DOC("RdGy"), py::arg("N") = 11); 141 | m.def("RdYlBu", &cppcolormap::RdYlBu, DOC("RdYlBu"), py::arg("N") = 11); 142 | m.def("RdYlGn", &cppcolormap::RdYlGn, DOC("RdYlGn"), py::arg("N") = 11); 143 | m.def("PiYG", &cppcolormap::PiYG, DOC("PiYG"), py::arg("N") = 11); 144 | m.def("PRGn", &cppcolormap::PRGn, DOC("PRGn"), py::arg("N") = 11); 145 | 146 | m.def("Accent_r", &cppcolormap::Accent_r, DOC("Accent_r"), py::arg("N") = 8); 147 | m.def("Dark2_r", &cppcolormap::Dark2_r, DOC("Dark2_r"), py::arg("N") = 8); 148 | m.def("Paired_r", &cppcolormap::Paired_r, DOC("Paired_r"), py::arg("N") = 12); 149 | m.def("Spectral_r", &cppcolormap::Spectral_r, DOC("Spectra_r"), py::arg("N") = 11); 150 | m.def("Pastel1_r", &cppcolormap::Pastel1_r, DOC("Pastel1_r"), py::arg("N") = 9); 151 | m.def("Pastel2_r", &cppcolormap::Pastel2_r, DOC("Pastel2_r"), py::arg("N") = 8); 152 | m.def("Set1_r", &cppcolormap::Set1_r, DOC("Set1_r"), py::arg("N") = 9); 153 | m.def("Set2_r", &cppcolormap::Set2_r, DOC("Set2_r"), py::arg("N") = 8); 154 | m.def("Set3_r", &cppcolormap::Set3_r, DOC("Set3_r"), py::arg("N") = 12); 155 | m.def("Blues_r", &cppcolormap::Blues_r, DOC("Blues_r"), py::arg("N") = 9); 156 | m.def("Greens_r", &cppcolormap::Greens_r, DOC("Greens_r"), py::arg("N") = 9); 157 | m.def("Greys_r", &cppcolormap::Greys_r, DOC("Greys_r"), py::arg("N") = 2); 158 | m.def("Oranges_r", &cppcolormap::Oranges_r, DOC("Oranges_r"), py::arg("N") = 9); 159 | m.def("Purples_r", &cppcolormap::Purples_r, DOC("Purples_r"), py::arg("N") = 9); 160 | m.def("Reds_r", &cppcolormap::Reds_r, DOC("Reds_r"), py::arg("N") = 9); 161 | m.def("BuPu_r", &cppcolormap::BuPu_r, DOC("BuPu_r"), py::arg("N") = 9); 162 | m.def("GnBu_r", &cppcolormap::GnBu_r, DOC("GnBu_r"), py::arg("N") = 9); 163 | m.def("PuBu_r", &cppcolormap::PuBu_r, DOC("PuBu_r"), py::arg("N") = 9); 164 | m.def("PuBuGn_r", &cppcolormap::PuBuGn_r, DOC("PuBuGn_r"), py::arg("N") = 9); 165 | m.def("PuRd_r", &cppcolormap::PuRd_r, DOC("PuRd_r"), py::arg("N") = 9); 166 | m.def("RdPu_r", &cppcolormap::RdPu_r, DOC("RdPu_r"), py::arg("N") = 9); 167 | m.def("OrRd_r", &cppcolormap::OrRd_r, DOC("OrRd_r"), py::arg("N") = 9); 168 | m.def("RdOrYl_r", &cppcolormap::RdOrYl_r, DOC("RdOrYl_r"), py::arg("N") = 9); 169 | m.def("YlGn_r", &cppcolormap::YlGn_r, DOC("YlGn_r"), py::arg("N") = 9); 170 | m.def("YlGnBu_r", &cppcolormap::YlGnBu_r, DOC("YlGnBu_r"), py::arg("N") = 9); 171 | m.def("YlOrRd_r", &cppcolormap::YlOrRd_r, DOC("YlOrRd_r"), py::arg("N") = 9); 172 | m.def("BrBG_r", &cppcolormap::BrBG_r, DOC("BrBG_r"), py::arg("N") = 11); 173 | m.def("PuOr_r", &cppcolormap::PuOr_r, DOC("PuOr_r"), py::arg("N") = 11); 174 | m.def("RdBu_r", &cppcolormap::RdBu_r, DOC("RdBu_r"), py::arg("N") = 11); 175 | m.def("RdGy_r", &cppcolormap::RdGy_r, DOC("RdGy_r"), py::arg("N") = 11); 176 | m.def("RdYlBu_r", &cppcolormap::RdYlBu_r, DOC("RdYlBu_r"), py::arg("N") = 11); 177 | m.def("RdYlGn_r", &cppcolormap::RdYlGn_r, DOC("RdYlGn_r"), py::arg("N") = 11); 178 | m.def("PiYG_r", &cppcolormap::PiYG_r, DOC("PiYG_r"), py::arg("N") = 11); 179 | m.def("PRGn_r", &cppcolormap::PRGn_r, DOC("PRGn_r"), py::arg("N") = 11); 180 | 181 | m.def("spring", &cppcolormap::spring, DOC("spring"), py::arg("N") = 256); 182 | m.def("summer", &cppcolormap::summer, DOC("summer"), py::arg("N") = 256); 183 | m.def("autumn", &cppcolormap::autumn, DOC("autumn"), py::arg("N") = 256); 184 | m.def("winter", &cppcolormap::winter, DOC("winter"), py::arg("N") = 256); 185 | m.def("bone", &cppcolormap::bone, DOC("bone"), py::arg("N") = 256); 186 | m.def("cool", &cppcolormap::cool, DOC("cool"), py::arg("N") = 256); 187 | m.def("hot", &cppcolormap::hot, DOC("hot"), py::arg("N") = 256); 188 | m.def("copper", &cppcolormap::copper, DOC("copper"), py::arg("N") = 256); 189 | m.def("hsv", &cppcolormap::hsv, DOC("hsv"), py::arg("N") = 256); 190 | m.def("nipy_spectral", &cppcolormap::nipy_spectral, DOC("nipy_spectral"), py::arg("N") = 256); 191 | m.def("terrain", &cppcolormap::terrain, DOC("terrain"), py::arg("N") = 6); 192 | m.def("seismic", &cppcolormap::seismic, DOC("seismic"), py::arg("N") = 5); 193 | m.def("afmhot", &cppcolormap::afmhot, DOC("afmhot"), py::arg("N") = 256); 194 | m.def("magma", &cppcolormap::magma, DOC("magma"), py::arg("N") = 256); 195 | m.def("inferno", &cppcolormap::inferno, DOC("inferno"), py::arg("N") = 256); 196 | m.def("plasma", &cppcolormap::plasma, DOC("plasma"), py::arg("N") = 256); 197 | m.def("viridis", &cppcolormap::viridis, DOC("viridis"), py::arg("N") = 256); 198 | m.def("jet", &cppcolormap::jet, DOC("jet"), py::arg("N") = 256); 199 | 200 | m.def("spring_r", &cppcolormap::spring_r, DOC("spring_r"), py::arg("N") = 256); 201 | m.def("summer_r", &cppcolormap::summer_r, DOC("summer_r"), py::arg("N") = 256); 202 | m.def("autumn_r", &cppcolormap::autumn_r, DOC("autumn_r"), py::arg("N") = 256); 203 | m.def("winter_r", &cppcolormap::winter_r, DOC("winter_r"), py::arg("N") = 256); 204 | m.def("bone_r", &cppcolormap::bone_r, DOC("bone_r"), py::arg("N") = 256); 205 | m.def("cool_r", &cppcolormap::cool_r, DOC("cool_r"), py::arg("N") = 256); 206 | m.def("hot_r", &cppcolormap::hot_r, DOC("hot_r"), py::arg("N") = 256); 207 | m.def("copper_r", &cppcolormap::copper_r, DOC("copper_r"), py::arg("N") = 256); 208 | m.def("hsv_r", &cppcolormap::hsv_r, DOC("hsv_r"), py::arg("N") = 256); 209 | m.def( 210 | "nipy_spectral_r", &cppcolormap::nipy_spectral_r, DOC("nipy_spectral_r"), py::arg("N") = 256 211 | ); 212 | m.def("terrain_r", &cppcolormap::terrain_r, DOC("terrain_r"), py::arg("N") = 6); 213 | m.def("seismic_r", &cppcolormap::seismic_r, DOC("seismic_r"), py::arg("N") = 5); 214 | m.def("afmhot_r", &cppcolormap::afmhot_r, DOC("afmhot_r"), py::arg("N") = 256); 215 | m.def("magma_r", &cppcolormap::magma_r, DOC("magma_r"), py::arg("N") = 256); 216 | m.def("inferno_r", &cppcolormap::inferno_r, DOC("inferno_r"), py::arg("N") = 256); 217 | m.def("plasma_r", &cppcolormap::plasma_r, DOC("plasma_r"), py::arg("N") = 256); 218 | m.def("viridis_r", &cppcolormap::viridis_r, DOC("viridis_r"), py::arg("N") = 256); 219 | m.def("jet_r", &cppcolormap::jet_r, DOC("jet_r"), py::arg("N") = 256); 220 | 221 | m.def("Apricot", &cppcolormap::Apricot, DOC("Apricot"), py::arg("N") = 1); 222 | m.def("Aquamarine", &cppcolormap::Aquamarine, DOC("Aquamarine"), py::arg("N") = 1); 223 | m.def("Bittersweet", &cppcolormap::Bittersweet, DOC("Bittersweet"), py::arg("N") = 1); 224 | m.def("Black", &cppcolormap::Black, DOC("Black"), py::arg("N") = 1); 225 | m.def("Blue", &cppcolormap::Blue, DOC("Blue"), py::arg("N") = 1); 226 | m.def("BlueGreen", &cppcolormap::BlueGreen, DOC("BlueGreen"), py::arg("N") = 1); 227 | m.def("BlueViolet", &cppcolormap::BlueViolet, DOC("BlueViolet"), py::arg("N") = 1); 228 | m.def("BrickRed", &cppcolormap::BrickRed, DOC("BrickRed"), py::arg("N") = 1); 229 | m.def("Brown", &cppcolormap::Brown, DOC("Brown"), py::arg("N") = 1); 230 | m.def("BurntOrange", &cppcolormap::BurntOrange, DOC("BurntOrange"), py::arg("N") = 1); 231 | m.def("CadetBlue", &cppcolormap::CadetBlue, DOC("CadetBlue"), py::arg("N") = 1); 232 | m.def("CarnationPink", &cppcolormap::CarnationPink, DOC("CarnationPink"), py::arg("N") = 1); 233 | m.def("Cerulean", &cppcolormap::Cerulean, DOC("Cerulean"), py::arg("N") = 1); 234 | m.def("CornflowerBlue", &cppcolormap::CornflowerBlue, DOC("CornflowerBlue"), py::arg("N") = 1); 235 | m.def("Cyan", &cppcolormap::Cyan, DOC("Cyan"), py::arg("N") = 1); 236 | m.def("Dandelion", &cppcolormap::Dandelion, DOC("Dandelion"), py::arg("N") = 1); 237 | m.def("DarkOrchid", &cppcolormap::DarkOrchid, DOC("DarkOrchid"), py::arg("N") = 1); 238 | m.def("Emerald", &cppcolormap::Emerald, DOC("Emerald"), py::arg("N") = 1); 239 | m.def("ForestGreen", &cppcolormap::ForestGreen, DOC("ForestGreen"), py::arg("N") = 1); 240 | m.def("Fuchsia", &cppcolormap::Fuchsia, DOC("Fuchsia"), py::arg("N") = 1); 241 | m.def("Goldenrod", &cppcolormap::Goldenrod, DOC("Goldenrod"), py::arg("N") = 1); 242 | m.def("Gray", &cppcolormap::Gray, DOC("Gray"), py::arg("N") = 1); 243 | m.def("Green", &cppcolormap::Green, DOC("Green"), py::arg("N") = 1); 244 | m.def("GreenYellow", &cppcolormap::GreenYellow, DOC("GreenYellow"), py::arg("N") = 1); 245 | m.def("Grey", &cppcolormap::Grey, DOC("Grey"), py::arg("N") = 1); 246 | m.def("JungleGreen", &cppcolormap::JungleGreen, DOC("JungleGreen"), py::arg("N") = 1); 247 | m.def("Lavender", &cppcolormap::Lavender, DOC("Lavender"), py::arg("N") = 1); 248 | m.def("LimeGreen", &cppcolormap::LimeGreen, DOC("LimeGreen"), py::arg("N") = 1); 249 | m.def("Magenta", &cppcolormap::Magenta, DOC("Magenta"), py::arg("N") = 1); 250 | m.def("Mahogany", &cppcolormap::Mahogany, DOC("Mahogany"), py::arg("N") = 1); 251 | m.def("Maroon", &cppcolormap::Maroon, DOC("Maroon"), py::arg("N") = 1); 252 | m.def("Melon", &cppcolormap::Melon, DOC("Melon"), py::arg("N") = 1); 253 | m.def("MidnightBlue", &cppcolormap::MidnightBlue, DOC("MidnightBlue"), py::arg("N") = 1); 254 | m.def("Mulberry", &cppcolormap::Mulberry, DOC("Mulberry"), py::arg("N") = 1); 255 | m.def("NavyBlue", &cppcolormap::NavyBlue, DOC("NavyBlue"), py::arg("N") = 1); 256 | m.def("OliveGreen", &cppcolormap::OliveGreen, DOC("OliveGreen"), py::arg("N") = 1); 257 | m.def("Orange", &cppcolormap::Orange, DOC("Orange"), py::arg("N") = 1); 258 | m.def("OrangeRed", &cppcolormap::OrangeRed, DOC("OrangeRed"), py::arg("N") = 1); 259 | m.def("Orchid", &cppcolormap::Orchid, DOC("Orchid"), py::arg("N") = 1); 260 | m.def("Peach", &cppcolormap::Peach, DOC("Peach"), py::arg("N") = 1); 261 | m.def("Periwinkle", &cppcolormap::Periwinkle, DOC("Periwinkle"), py::arg("N") = 1); 262 | m.def("PineGreen", &cppcolormap::PineGreen, DOC("PineGreen"), py::arg("N") = 1); 263 | m.def("Plum", &cppcolormap::Plum, DOC("Plum"), py::arg("N") = 1); 264 | m.def("ProcessBlue", &cppcolormap::ProcessBlue, DOC("ProcessBlue"), py::arg("N") = 1); 265 | m.def("Purple", &cppcolormap::Purple, DOC("Purple"), py::arg("N") = 1); 266 | m.def("RawSienna", &cppcolormap::RawSienna, DOC("RawSienna"), py::arg("N") = 1); 267 | m.def("Red", &cppcolormap::Red, DOC("Red"), py::arg("N") = 1); 268 | m.def("RedOrange", &cppcolormap::RedOrange, DOC("RedOrange"), py::arg("N") = 1); 269 | m.def("RedViolet", &cppcolormap::RedViolet, DOC("RedViolet"), py::arg("N") = 1); 270 | m.def("Rhodamine", &cppcolormap::Rhodamine, DOC("Rhodamine"), py::arg("N") = 1); 271 | m.def("RoyalBlue", &cppcolormap::RoyalBlue, DOC("RoyalBlue"), py::arg("N") = 1); 272 | m.def("RoyalPurple", &cppcolormap::RoyalPurple, DOC("RoyalPurple"), py::arg("N") = 1); 273 | m.def("RubineRed", &cppcolormap::RubineRed, DOC("RubineRed"), py::arg("N") = 1); 274 | m.def("Salmon", &cppcolormap::Salmon, DOC("Salmon"), py::arg("N") = 1); 275 | m.def("SeaGreen", &cppcolormap::SeaGreen, DOC("SeaGreen"), py::arg("N") = 1); 276 | m.def("Sepia", &cppcolormap::Sepia, DOC("Sepia"), py::arg("N") = 1); 277 | m.def("SkyBlue", &cppcolormap::SkyBlue, DOC("SkyBlue"), py::arg("N") = 1); 278 | m.def("SpringGreen", &cppcolormap::SpringGreen, DOC("SpringGreen"), py::arg("N") = 1); 279 | m.def("Tan", &cppcolormap::Tan, DOC("Tan"), py::arg("N") = 1); 280 | m.def("TealBlue", &cppcolormap::TealBlue, DOC("TealBlue"), py::arg("N") = 1); 281 | m.def("Thistle", &cppcolormap::Thistle, DOC("Thistle"), py::arg("N") = 1); 282 | m.def("tueblue", &cppcolormap::tueblue, DOC("tueblue"), py::arg("N") = 1); 283 | m.def("tuedarkblue", &cppcolormap::tuedarkblue, DOC("tuedarkblue"), py::arg("N") = 1); 284 | m.def("tuelightblue", &cppcolormap::tuelightblue, DOC("tuelightblue"), py::arg("N") = 1); 285 | m.def("tuewarmred", &cppcolormap::tuewarmred, DOC("tuewarmred"), py::arg("N") = 1); 286 | m.def("Turquoise", &cppcolormap::Turquoise, DOC("Turquoise"), py::arg("N") = 1); 287 | m.def("Violet", &cppcolormap::Violet, DOC("Violet"), py::arg("N") = 1); 288 | m.def("VioletRed", &cppcolormap::VioletRed, DOC("VioletRed"), py::arg("N") = 1); 289 | m.def("White", &cppcolormap::White, DOC("White"), py::arg("N") = 1); 290 | m.def("WildStrawberry", &cppcolormap::WildStrawberry, DOC("WildStrawberry"), py::arg("N") = 1); 291 | m.def("Yellow", &cppcolormap::Yellow, DOC("Yellow"), py::arg("N") = 1); 292 | m.def("YellowGreen", &cppcolormap::YellowGreen, DOC("YellowGreen"), py::arg("N") = 1); 293 | m.def("YellowOrange", &cppcolormap::YellowOrange, DOC("YellowOrange"), py::arg("N") = 1); 294 | 295 | m.def("xterm", &cppcolormap::xterm, DOC("xterm")); 296 | m.def("tue", &cppcolormap::tue, DOC("tue")); 297 | 298 | m.def("xterm_r", &cppcolormap::xterm_r, DOC("xterm_r")); 299 | m.def("tue_r", &cppcolormap::tue_r, DOC("tue_r")); 300 | 301 | m.def("colormap", &cppcolormap::colormap, DOC("colormap"), py::arg("cmap"), py::arg("N") = 256); 302 | 303 | m.def("colorcycle", &cppcolormap::colorcycle, DOC("colorcycle"), py::arg("cmap")); 304 | 305 | py::enum_(m, "metric", ENUM("metric")) 306 | .value("euclidean", cppcolormap::metric::euclidean) 307 | .value("fast_perceptual", cppcolormap::metric::fast_perceptual) 308 | .value("perceptual", cppcolormap::metric::perceptual) 309 | .export_values(); 310 | 311 | m.def("match", &cppcolormap::match, DOC("match")); 312 | 313 | } // PYBIND11_MODULE 314 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools_scm import get_version 2 | from skbuild import setup 3 | 4 | project_name = "cppcolormap" 5 | 6 | setup( 7 | name=project_name, 8 | description="Library with colormaps", 9 | version=get_version(), 10 | license="MIT", 11 | author="Tom de Geus", 12 | author_email="tom@geus.me", 13 | url=f"https://github.com/tdegeus/{project_name}", 14 | packages=[f"{project_name}"], 15 | package_dir={"": "python"}, 16 | cmake_install_dir=f"python/{project_name}", 17 | cmake_minimum_required_version="3.13", 18 | python_requires=">=3.6", 19 | ) 20 | -------------------------------------------------------------------------------- /tests/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.19..3.21) 2 | 3 | if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) 4 | project(cppcolormap) 5 | find_package(cppcolormap REQUIRED CONFIG) 6 | endif() 7 | 8 | set(MYPROJECT "${PROJECT_NAME}-tests") 9 | 10 | if(NOT CMAKE_BUILD_TYPE) 11 | set(CMAKE_BUILD_TYPE Release) 12 | endif() 13 | 14 | find_package(Catch2 REQUIRED) 15 | 16 | add_library(mytarget INTERFACE IMPORTED) 17 | 18 | target_link_libraries(mytarget INTERFACE 19 | ${PROJECT_NAME} 20 | ${PROJECT_NAME}::compiler_warnings 21 | Catch2::Catch2WithMain) 22 | 23 | file(GLOB APP_SOURCES *.cpp) 24 | 25 | foreach(mysource ${APP_SOURCES}) 26 | string(REPLACE ".cpp" "" myexec ${mysource}) 27 | get_filename_component(myexec ${myexec} NAME) 28 | add_executable(${myexec} ${mysource}) 29 | target_link_libraries(${myexec} PRIVATE mytarget) 30 | add_test(NAME ${myexec} COMMAND ${myexec}) 31 | endforeach() 32 | -------------------------------------------------------------------------------- /tests/cpp/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | TEST_CASE("cppcolormap::colormap", "cppcolormap.h") 6 | { 7 | std::vector cmaps{ 8 | "Accent", 9 | "Dark2", 10 | "Paired", 11 | "Spectral", 12 | "Pastel1", 13 | "Pastel2", 14 | "Set1", 15 | "Set2", 16 | "Set3", 17 | "Blues", 18 | "Greens", 19 | "Greys", 20 | "Oranges", 21 | "Purples", 22 | "Reds", 23 | "BuPu", 24 | "GnBu", 25 | "PuBu", 26 | "PuBuGn", 27 | "PuRd", 28 | "RdPu", 29 | "OrRd", 30 | "RdOrYl", 31 | "YlGn", 32 | "YlGnBu", 33 | "YlOrRd", 34 | "BrBG", 35 | "PuOr", 36 | "RdBu", 37 | "RdGy", 38 | "RdYlBu", 39 | "RdYlGn", 40 | "PiYG", 41 | "PRGn", 42 | "spring", 43 | "summer", 44 | "autumn", 45 | "winter", 46 | "bone", 47 | "cool", 48 | "hot", 49 | "copper", 50 | "hsv", 51 | "nipy_spectral", 52 | "jet", 53 | "terrain", 54 | "seismic", 55 | "afmhot", 56 | "magma", 57 | "inferno", 58 | "plasma", 59 | "viridis", 60 | "Accent_r", 61 | "Dark2_r", 62 | "Paired_r", 63 | "Spectral_r", 64 | "Pastel1_r", 65 | "Pastel2_r", 66 | "Set1_r", 67 | "Set2_r", 68 | "Set3_r", 69 | "Blues_r", 70 | "Greens_r", 71 | "Greys_r", 72 | "Oranges_r", 73 | "Purples_r", 74 | "Reds_r", 75 | "BuPu_r", 76 | "GnBu_r", 77 | "PuBu_r", 78 | "PuBuGn_r", 79 | "PuRd_r", 80 | "RdPu_r", 81 | "OrRd_r", 82 | "RdOrYl_r", 83 | "YlGn_r", 84 | "YlGnBu_r", 85 | "YlOrRd_r", 86 | "BrBG_r", 87 | "PuOr_r", 88 | "RdBu_r", 89 | "RdGy_r", 90 | "RdYlBu_r", 91 | "RdYlGn_r", 92 | "PiYG_r", 93 | "PRGn_r", 94 | "spring_r", 95 | "summer_r", 96 | "autumn_r", 97 | "winter_r", 98 | "bone_r", 99 | "cool_r", 100 | "hot_r", 101 | "copper_r", 102 | "hsv_r", 103 | "nipy_spectral_r", 104 | "jet_r", 105 | "terrain_r", 106 | "seismic_r", 107 | "afmhot_r", 108 | "magma_r", 109 | "inferno_r", 110 | "plasma_r", 111 | "viridis_r", 112 | "White", 113 | "Grey", 114 | "Black", 115 | "Red", 116 | "Blue", 117 | "tuewarmred", 118 | "tuedarkblue", 119 | "tueblue", 120 | "tuelightblue", 121 | "Apricot", 122 | "Aquamarine", 123 | "Bittersweet", 124 | "BlueGreen", 125 | "BlueViolet", 126 | "BrickRed", 127 | "Brown", 128 | "BurntOrange", 129 | "CadetBlue", 130 | "CarnationPink", 131 | "Cerulean", 132 | "CornflowerBlue", 133 | "Cyan", 134 | "Dandelion", 135 | "DarkOrchid", 136 | "Emerald", 137 | "ForestGreen", 138 | "Fuchsia", 139 | "Goldenrod", 140 | "Gray", 141 | "Green", 142 | "GreenYellow", 143 | "JungleGreen", 144 | "Lavender", 145 | "LimeGreen", 146 | "Magenta", 147 | "Mahogany", 148 | "Maroon", 149 | "Melon", 150 | "MidnightBlue", 151 | "Mulberry", 152 | "NavyBlue", 153 | "OliveGreen", 154 | "Orange", 155 | "OrangeRed", 156 | "Orchid", 157 | "Peach", 158 | "Periwinkle", 159 | "PineGreen", 160 | "Plum", 161 | "ProcessBlue", 162 | "Purple", 163 | "RawSienna", 164 | "RedOrange", 165 | "RedViolet", 166 | "Rhodamine", 167 | "RoyalBlue", 168 | "RoyalPurple", 169 | "RubineRed", 170 | "Salmon", 171 | "SeaGreen", 172 | "Sepia", 173 | "SkyBlue", 174 | "SpringGreen", 175 | "Tan", 176 | "TealBlue", 177 | "Thistle", 178 | "Turquoise", 179 | "Violet", 180 | "VioletRed", 181 | "WildStrawberry", 182 | "Yellow", 183 | "YellowGreen", 184 | "YellowOrange" 185 | }; 186 | 187 | for (auto& cmap : cmaps) { 188 | auto c = cppcolormap::colormap(cmap); 189 | REQUIRE(xt::amin(c)() >= 0.0); 190 | REQUIRE(xt::amax(c)() <= 1.0); 191 | } 192 | } 193 | 194 | TEST_CASE("cppcolormap::as_colors", "cppcolormap.h") 195 | { 196 | auto c = cppcolormap::Greys(5); 197 | xt::xtensor data = xt::arange(c.shape(0)); 198 | auto m = cppcolormap::as_colors(data, c); 199 | REQUIRE(xt::allclose(c, m)); 200 | } 201 | -------------------------------------------------------------------------------- /tests/python/main.py: -------------------------------------------------------------------------------- 1 | import cppcolormap 2 | 3 | cmaps = [ 4 | "Accent", 5 | "Dark2", 6 | "Paired", 7 | "Spectral", 8 | "Pastel1", 9 | "Pastel2", 10 | "Set1", 11 | "Set2", 12 | "Set3", 13 | "Blues", 14 | "Greens", 15 | "Greys", 16 | "Oranges", 17 | "Purples", 18 | "Reds", 19 | "BuPu", 20 | "GnBu", 21 | "PuBu", 22 | "PuBuGn", 23 | "PuRd", 24 | "RdPu", 25 | "OrRd", 26 | "RdOrYl", 27 | "YlGn", 28 | "YlGnBu", 29 | "YlOrRd", 30 | "BrBG", 31 | "PuOr", 32 | "RdBu", 33 | "RdGy", 34 | "RdYlBu", 35 | "RdYlGn", 36 | "PiYG", 37 | "PRGn", 38 | "spring", 39 | "summer", 40 | "autumn", 41 | "winter", 42 | "bone", 43 | "cool", 44 | "hot", 45 | "copper", 46 | "hsv", 47 | "nipy_spectral", 48 | "jet", 49 | "terrain", 50 | "seismic", 51 | "afmhot", 52 | "magma", 53 | "inferno", 54 | "plasma", 55 | "viridis", 56 | "Accent_r", 57 | "Dark2_r", 58 | "Paired_r", 59 | "Spectral_r", 60 | "Pastel1_r", 61 | "Pastel2_r", 62 | "Set1_r", 63 | "Set2_r", 64 | "Set3_r", 65 | "Blues_r", 66 | "Greens_r", 67 | "Greys_r", 68 | "Oranges_r", 69 | "Purples_r", 70 | "Reds_r", 71 | "BuPu_r", 72 | "GnBu_r", 73 | "PuBu_r", 74 | "PuBuGn_r", 75 | "PuRd_r", 76 | "RdPu_r", 77 | "OrRd_r", 78 | "RdOrYl_r", 79 | "YlGn_r", 80 | "YlGnBu_r", 81 | "YlOrRd_r", 82 | "BrBG_r", 83 | "PuOr_r", 84 | "RdBu_r", 85 | "RdGy_r", 86 | "RdYlBu_r", 87 | "RdYlGn_r", 88 | "PiYG_r", 89 | "PRGn_r", 90 | "spring_r", 91 | "summer_r", 92 | "autumn_r", 93 | "winter_r", 94 | "bone_r", 95 | "cool_r", 96 | "hot_r", 97 | "copper_r", 98 | "hsv_r", 99 | "nipy_spectral_r", 100 | "jet_r", 101 | "terrain_r", 102 | "seismic_r", 103 | "afmhot_r", 104 | "magma_r", 105 | "inferno_r", 106 | "plasma_r", 107 | "viridis_r", 108 | "White", 109 | "Grey", 110 | "Black", 111 | "Red", 112 | "Blue", 113 | "tuewarmred", 114 | "tuedarkblue", 115 | "tueblue", 116 | "tuelightblue", 117 | "Apricot", 118 | "Aquamarine", 119 | "Bittersweet", 120 | "BlueGreen", 121 | "BlueViolet", 122 | "BrickRed", 123 | "Brown", 124 | "BurntOrange", 125 | "CadetBlue", 126 | "CarnationPink", 127 | "Cerulean", 128 | "CornflowerBlue", 129 | "Cyan", 130 | "Dandelion", 131 | "DarkOrchid", 132 | "Emerald", 133 | "ForestGreen", 134 | "Fuchsia", 135 | "Goldenrod", 136 | "Gray", 137 | "Green", 138 | "GreenYellow", 139 | "JungleGreen", 140 | "Lavender", 141 | "LimeGreen", 142 | "Magenta", 143 | "Mahogany", 144 | "Maroon", 145 | "Melon", 146 | "MidnightBlue", 147 | "Mulberry", 148 | "NavyBlue", 149 | "OliveGreen", 150 | "Orange", 151 | "OrangeRed", 152 | "Orchid", 153 | "Peach", 154 | "Periwinkle", 155 | "PineGreen", 156 | "Plum", 157 | "ProcessBlue", 158 | "Purple", 159 | "RawSienna", 160 | "RedOrange", 161 | "RedViolet", 162 | "Rhodamine", 163 | "RoyalBlue", 164 | "RoyalPurple", 165 | "RubineRed", 166 | "Salmon", 167 | "SeaGreen", 168 | "Sepia", 169 | "SkyBlue", 170 | "SpringGreen", 171 | "Tan", 172 | "TealBlue", 173 | "Thistle", 174 | "Turquoise", 175 | "Violet", 176 | "VioletRed", 177 | "WildStrawberry", 178 | "Yellow", 179 | "YellowGreen", 180 | "YellowOrange", 181 | ] 182 | 183 | for cmap in cmaps: 184 | c = cppcolormap.colormap(cmap) 185 | --------------------------------------------------------------------------------