From 73e0908c6cfe66915c20f852305dd297a6494843 Mon Sep 17 00:00:00 2001 From: Zhengyu Peng Date: Sat, 6 Apr 2024 21:40:16 -0400 Subject: [PATCH] freetier build --- .github/workflows/release_linux_freetier.yml | 46 +++++ .github/workflows/release_macos_freetier.yml | 45 +++++ .../workflows/release_windows_freetier.yml | 42 +++++ build_linux_freetier.sh | 60 +++++++ build_macos_freetier.sh | 60 +++++++ build_win_freetier.bat | 72 ++++++++ setup_cuda_freetier.py | 158 ++++++++++++++++++ setup_freetier.py | 84 ++++++++++ src/radarsimcpp | 2 +- src/radarsimpy/includes/radarsimc.pxd | 3 + src/radarsimpy/lib/cp_radarsimc.pyx | 9 + src/radarsimpy/raytracing/rcs.pyx | 6 + src/radarsimpy/raytracing/scene.pyx | 11 ++ src/radarsimpy/simulator.pyx | 11 ++ 14 files changed, 608 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release_linux_freetier.yml create mode 100644 .github/workflows/release_macos_freetier.yml create mode 100644 .github/workflows/release_windows_freetier.yml create mode 100644 build_linux_freetier.sh create mode 100644 build_macos_freetier.sh create mode 100644 build_win_freetier.bat create mode 100644 setup_cuda_freetier.py create mode 100644 setup_freetier.py diff --git a/.github/workflows/release_linux_freetier.yml b/.github/workflows/release_linux_freetier.yml new file mode 100644 index 0000000..2eed38f --- /dev/null +++ b/.github/workflows/release_linux_freetier.yml @@ -0,0 +1,46 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Release on Linux + +on: + push: + tags: + - "*" + +jobs: + build: + runs-on: ubuntu-22.04 + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + c_compiler: [gcc-12] + cxx_compiler: [g++-12] + + steps: + - uses: actions/checkout@v4 + with: + ssh-key: ${{ secrets.RADARSIMC }} + submodules: true + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Build + env: + CC: ${{ matrix.c_compiler }} + CXX: ${{ matrix.cxx_compiler }} + run: | + sudo chown -R $USER:$USER /home/runner/work/radarsimpy + chmod +x build_linux_freetier.sh + ./build_linux_freetier.sh + - name: Archive built module + uses: actions/upload-artifact@v4 + if: success() + with: + name: radarsimpy_linux_py${{ matrix.python-version }}_freetier + path: ./radarsimpy diff --git a/.github/workflows/release_macos_freetier.yml b/.github/workflows/release_macos_freetier.yml new file mode 100644 index 0000000..c583849 --- /dev/null +++ b/.github/workflows/release_macos_freetier.yml @@ -0,0 +1,45 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Release on MacOS + +on: + push: + tags: + - "*" + +jobs: + build: + runs-on: macos-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + c_compiler: [gcc-12] + cxx_compiler: [g++-12] + + steps: + - uses: actions/checkout@v4 + with: + ssh-key: ${{ secrets.RADARSIMC }} + submodules: true + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Build + env: + CC: ${{ matrix.c_compiler }} + CXX: ${{ matrix.cxx_compiler }} + run: | + chmod +x build_macos_freetier.sh + ./build_macos_freetier.sh + - name: Archive built module + uses: actions/upload-artifact@v4 + if: success() + with: + name: radarsimpy_macos_py${{ matrix.python-version }}_freetier + path: ./radarsimpy diff --git a/.github/workflows/release_windows_freetier.yml b/.github/workflows/release_windows_freetier.yml new file mode 100644 index 0000000..8b6f7ba --- /dev/null +++ b/.github/workflows/release_windows_freetier.yml @@ -0,0 +1,42 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Release on Windows + +on: + push: + tags: + - "*" + +jobs: + build: + runs-on: windows-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + + steps: + - uses: actions/checkout@v4 + - name: Checkout private tools + uses: actions/checkout@v4 + with: + repository: rookiepeng/radarsimcpp + ssh-key: ${{ secrets.RADARSIMC }} + path: src/radarsimcpp + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Build + run: | + .\build_win_freetier.bat + - name: Archive built module + uses: actions/upload-artifact@v4 + if: success() + with: + name: radarsimpy_win_py${{ matrix.python-version }}_freetier + path: .\radarsimpy diff --git a/build_linux_freetier.sh b/build_linux_freetier.sh new file mode 100644 index 0000000..d23fc50 --- /dev/null +++ b/build_linux_freetier.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +echo "Automatic build script of radarsimcpp/radarsimpy for Linux" +echo "" +echo "----------" +echo "RadarSimPy - A Radar Simulator Built with Python" +echo "Copyright (C) 2018 - PRESENT radarsimx.com" +echo "E-mail: info@radarsimx.com" +echo "Website: https://radarsimx.com" +echo "" +echo "██████╗ █████╗ ██████╗ █████╗ ██████╗ ███████╗██╗███╗ ███╗██╗ ██╗" +echo "██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔════╝██║████╗ ████║╚██╗██╔╝" +echo "██████╔╝███████║██║ ██║███████║██████╔╝███████╗██║██╔████╔██║ ╚███╔╝ " +echo "██╔══██╗██╔══██║██║ ██║██╔══██║██╔══██╗╚════██║██║██║╚██╔╝██║ ██╔██╗ " +echo "██║ ██║██║ ██║██████╔╝██║ ██║██║ ██║███████║██║██║ ╚═╝ ██║██╔╝ ██╗" +echo "╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝" + +workpath=$(pwd) + +echo "## Clean old build files ##" +rm -rf ./src/radarsimcpp/build +rm -rf ./radarsimpy + +echo "## Building libradarsimcpp.so with CPU ##" +mkdir ./src/radarsimcpp/build +cd ./src/radarsimcpp/build + +cmake -DCMAKE_BUILD_TYPE=Release -DGTEST=ON .. +cmake --build . + +echo "## Building radarsimpy with Cython ##" +cd $workpath +python setup_freetier.py build_ext -b ./ + +echo "## Copying lib files to ./radarsimpy ##" +# mkdir ./radarsimpy/lib +cp ./src/radarsimpy/*.py ./radarsimpy +cp ./src/radarsimpy/lib/__init__.py ./radarsimpy/lib +cp ./src/radarsimcpp/build/*.so ./radarsimpy + +echo "## Cleaning radarsimpy builds ##" +rm -rf build + +rm -f ./src/radarsimpy/*.c +rm -f ./src/radarsimpy/*.cpp +rm -f ./src/radarsimpy/*.html +rm -f ./src/radarsimpy/raytracing/*.c +rm -f ./src/radarsimpy/raytracing/*.cpp +rm -f ./src/radarsimpy/raytracing/*.html +rm -f ./src/radarsimpy/lib/*.cpp +rm -f ./src/radarsimpy/lib/*.html +rm -f ./src/*.cpp +rm -f ./src/*.html + +echo "## Copying lib files to unit test folder ##" +rm -rf ./tests/radarsimpy +mkdir ./tests/radarsimpy +cp -rf ./radarsimpy/* ./tests/radarsimpy + +echo "## Build completed ##" diff --git a/build_macos_freetier.sh b/build_macos_freetier.sh new file mode 100644 index 0000000..608094b --- /dev/null +++ b/build_macos_freetier.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +echo "Automatic build script of radarsimcpp/radarsimpy for macOS" +echo "" +echo "----------" +echo "RadarSimPy - A Radar Simulator Built with Python" +echo "Copyright (C) 2018 - PRESENT radarsimx.com" +echo "E-mail: info@radarsimx.com" +echo "Website: https://radarsimx.com" +echo "" +echo "██████╗ █████╗ ██████╗ █████╗ ██████╗ ███████╗██╗███╗ ███╗██╗ ██╗" +echo "██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔════╝██║████╗ ████║╚██╗██╔╝" +echo "██████╔╝███████║██║ ██║███████║██████╔╝███████╗██║██╔████╔██║ ╚███╔╝ " +echo "██╔══██╗██╔══██║██║ ██║██╔══██║██╔══██╗╚════██║██║██║╚██╔╝██║ ██╔██╗ " +echo "██║ ██║██║ ██║██████╔╝██║ ██║██║ ██║███████║██║██║ ╚═╝ ██║██╔╝ ██╗" +echo "╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝" + +workpath=$(pwd) + +echo "## Clean old build files ##" +rm -rf ./src/radarsimcpp/build +rm -rf ./radarsimpy + +echo "## Building libradarsimcpp.so with CPU ##" +mkdir ./src/radarsimcpp/build +cd ./src/radarsimcpp/build + +cmake -DCMAKE_BUILD_TYPE=Release -DGTEST=ON .. +cmake --build . + +echo "## Building radarsimpy with Cython ##" +cd $workpath +python setup_freetier.py build_ext -b ./ + +echo "## Copying lib files to ./radarsimpy ##" +# mkdir ./radarsimpy/lib +cp ./src/radarsimpy/*.py ./radarsimpy +cp ./src/radarsimpy/lib/__init__.py ./radarsimpy/lib +cp ./src/radarsimcpp/build/*.dylib ./radarsimpy + +echo "## Cleaning radarsimpy builds ##" +rm -rf build + +rm -f ./src/radarsimpy/*.c +rm -f ./src/radarsimpy/*.cpp +rm -f ./src/radarsimpy/*.html +rm -f ./src/radarsimpy/raytracing/*.c +rm -f ./src/radarsimpy/raytracing/*.cpp +rm -f ./src/radarsimpy/raytracing/*.html +rm -f ./src/radarsimpy/lib/*.cpp +rm -f ./src/radarsimpy/lib/*.html +rm -f ./src/*.cpp +rm -f ./src/*.html + +echo "## Copying lib files to unit test folder ##" +rm -rf ./tests/radarsimpy +mkdir ./tests/radarsimpy +cp -rf ./radarsimpy/* ./tests/radarsimpy + +echo "## Build completed ##" diff --git a/build_win_freetier.bat b/build_win_freetier.bat new file mode 100644 index 0000000..329d171 --- /dev/null +++ b/build_win_freetier.bat @@ -0,0 +1,72 @@ +@ECHO OFF + +ECHO Automatic build script of radarsimcpp/radarsimpy for Windows +ECHO: +ECHO ---------- +ECHO RadarSimPy - A Radar Simulator Built with Python +ECHO Copyright (C) 2018 - PRESENT radarsimx.com +ECHO E-mail: info@radarsimx.com +ECHO Website: https://radarsimx.com +ECHO: +ECHO ******* ** ******** ** ** ** +ECHO /**////** /** **////// // //** ** +ECHO /** /** ****** /** ****** ******/** ** ********** //** ** +ECHO /******* //////** ****** //////** //**//*/*********/**//**//**//** //*** +ECHO /**///** ******* **///** ******* /** / ////////**/** /** /** /** **/** +ECHO /** //** **////** /** /** **////** /** /**/** /** /** /** ** //** +ECHO /** //**//********//******//********/*** ******** /** *** /** /** ** //** +ECHO // // //////// ////// //////// /// //////// // /// // // // // +ECHO: + +SET pwd=%cd% + +ECHO clean old build files +RMDIR /Q/S .\src\radarsimcpp\build + +ECHO clean old radarsimpy module +RMDIR /Q/S .\radarsimpy + +@REM go to the build folder +MD ".\src\radarsimcpp\build" +CD ".\src\radarsimcpp\build" + +ECHO ## Building radarsimcpp.dll with MSVC ## +@REM MSVC needs to set the build type using '--config Relesae' +cmake -DGTEST=ON .. +cmake --build . --config Release + +ECHO ## Building radarsimpy with Cython ## +CD %pwd% +python setup_freetier.py build_ext -b ./ + +ECHO ## Copying dll files to ./radarsimpy ## +XCOPY ".\src\radarsimcpp\build\Release\radarsimcpp.dll" ".\radarsimpy\" +XCOPY ".\src\radarsimpy\*.py" ".\radarsimpy\" +XCOPY ".\src\radarsimpy\lib\__init__.py" ".\radarsimpy\lib\" + +ECHO ## Cleaning radarsimpy builds ## +RMDIR build /s /q + +DEL ".\src\radarsimpy\*.c" +DEL ".\src\radarsimpy\*.cpp" +DEL ".\src\radarsimpy\*.html" +DEL ".\src\radarsimpy\raytracing\*.c" +DEL ".\src\radarsimpy\raytracing\*.cpp" +DEL ".\src\radarsimpy\raytracing\*.html" +DEL ".\src\radarsimpy\lib\*.cpp" +DEL ".\src\radarsimpy\lib\*.html" +DEL ".\src\*.cpp" +DEL ".\src\*.html" + +ECHO ## Copying lib files to unit test folder ## + +RMDIR /Q/S .\tests\radarsimpy +XCOPY /E /I .\radarsimpy .\tests\radarsimpy + +ECHO ## Build completed ## + +@REM ECHO ## Run Google test ## +@REM .\src\radarsimcpp\build\Release\radarsimcpp_test.exe + +@REM ECHO ## Pytest ## +@REM pytest diff --git a/setup_cuda_freetier.py b/setup_cuda_freetier.py new file mode 100644 index 0000000..38408b4 --- /dev/null +++ b/setup_cuda_freetier.py @@ -0,0 +1,158 @@ +""" +Setup script for a Python package "radarsimpy" with CUDA + +--- + +- Copyright (C) 2018 - PRESENT radarsimx.com +- E-mail: info@radarsimx.com +- Website: https://radarsimx.com + +:: + + ██████╗ █████╗ ██████╗ █████╗ ██████╗ ███████╗██╗███╗ ███╗██╗ ██╗ + ██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔════╝██║████╗ ████║╚██╗██╔╝ + ██████╔╝███████║██║ ██║███████║██████╔╝███████╗██║██╔████╔██║ ╚███╔╝ + ██╔══██╗██╔══██║██║ ██║██╔══██║██╔══██╗╚════██║██║██║╚██╔╝██║ ██╔██╗ + ██║ ██║██║ ██║██████╔╝██║ ██║██║ ██║███████║██║██║ ╚═╝ ██║██╔╝ ██╗ + ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ + +""" + +import platform + +import os +from os.path import join as pjoin +from setuptools import setup +from setuptools import Extension +from Cython.Distutils import build_ext +from Cython.Build import cythonize +import numpy + + +def find_in_path(name, path): + """Iterates over the directories in the search path by splitting the path string using + os.pathsep as the delimiter. os.pathsep is a string that represents the separator + used in the PATH environment variable on the current operating system + (e.g., : on Unix-like systems and ; on Windows). + + :param name: The name of the file + :type name: str + :param path: The search path + :type path: str + :return: The absolute path of the file + :rtype: str + """ + + for path_name in path.split(os.pathsep): + binpath = pjoin(path_name, name) + if os.path.exists(binpath): + return os.path.abspath(binpath) + return None + + +def locate_cuda(): + """Locate the CUDA installation on the system + + :raises EnvironmentError: The nvcc binary could not be located in your $PATH. + Either add it to your path, or set $CUDA_PATH + :raises EnvironmentError: The CUDA path could not be located in + :return: dict with keys 'home', 'nvcc', 'include', and 'lib64' + and values giving the absolute path to each directory. + :rtype: dict + """ + + # The code first checks if the CUDA_PATH environment variable is set. + # If it is, it uses the value of CUDA_PATH as the CUDA installation directory + # and constructs the path to the nvcc binary (NVIDIA CUDA Compiler) inside that directory. + if "CUDA_PATH" in os.environ: + home = os.environ["CUDA_PATH"] + nvcc = pjoin(home, "bin", NVCC) + else: + # If the CUDA_PATH environment variable is not set, it searches for the nvcc + # binary in the system's PATH environment variable. If nvcc is not found in + # the PATH, it raises an EnvironmentError. Otherwise, it sets the home variable + # to the parent directory of nvcc. + default_path = pjoin(os.sep, "usr", "local", "cuda", "bin") + nvcc = find_in_path(NVCC, os.environ["PATH"] + os.pathsep + default_path) + if nvcc is None: + raise EnvironmentError( + "The nvcc binary could not be located in your $PATH. " + "Either add it to your path, or set $CUDA_PATH" + ) + home = os.path.dirname(os.path.dirname(nvcc)) + + cudaconfig = { + "home": home, + "nvcc": nvcc, + "include": pjoin(home, "include"), + "lib64": pjoin(home, CUDALIB), + } + for key, val in cudaconfig.items(): + if not os.path.exists(val): + raise EnvironmentError( + "The CUDA " + key + " path could not be located in " + val + ) + + return cudaconfig + + +os_type = platform.system() # 'Linux', 'Windows' + + +if os_type == "Linux": + LINK_ARGS = ["-Wl,-rpath,$ORIGIN"] + NVCC = "nvcc" + CUDALIB = "lib64" + LIBRARY_DIRS = ["src/radarsimcpp/build"] +elif os_type == "Windows": + LINK_ARGS = [] + NVCC = "nvcc.exe" + CUDALIB = "lib\\x64" + LIBRARY_DIRS = ["src/radarsimcpp/build/Release"] + +CUDA = locate_cuda() + +MACROS = [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"), ("_CUDA_", None)] +INCLUDE_DIRS = ["src/radarsimcpp/includes", "src/radarsimcpp/includes/zpvector"] + + +ext_modules = [ + Extension( + "radarsimpy.lib.cp_radarsimc", + ["src/radarsimpy/lib/cp_radarsimc.pyx"], + define_macros=MACROS, + include_dirs=INCLUDE_DIRS + [CUDA["include"]], + libraries=["radarsimcpp"], + library_dirs=LIBRARY_DIRS + [CUDA["lib64"]], + extra_link_args=LINK_ARGS, + ), + Extension( + "radarsimpy.rt", + ["src/radarsimpy/raytracing/rt.pyx"], + define_macros=MACROS, + include_dirs=INCLUDE_DIRS + [CUDA["include"]], + libraries=["radarsimcpp"], + library_dirs=LIBRARY_DIRS + [CUDA["lib64"]], + extra_link_args=LINK_ARGS, + ), + Extension( + "radarsimpy.simulator", + ["src/radarsimpy/simulator.pyx"], + define_macros=MACROS, + include_dirs=INCLUDE_DIRS + [CUDA["include"]], + libraries=["radarsimcpp"], + library_dirs=LIBRARY_DIRS + [CUDA["lib64"]], + extra_link_args=LINK_ARGS, + ), +] + +setup( + name="radarsimpy", + cmdclass={"build_ext": build_ext}, + ext_modules=cythonize( + ext_modules, + annotate=False, + compiler_directives={"language_level": "3"}, + ), + include_dirs=[numpy.get_include()], +) diff --git a/setup_freetier.py b/setup_freetier.py new file mode 100644 index 0000000..081ece8 --- /dev/null +++ b/setup_freetier.py @@ -0,0 +1,84 @@ +""" +Setup script for a Python package "radarsimpy" + +--- + +- Copyright (C) 2018 - PRESENT radarsimx.com +- E-mail: info@radarsimx.com +- Website: https://radarsimx.com + +:: + + ██████╗ █████╗ ██████╗ █████╗ ██████╗ ███████╗██╗███╗ ███╗██╗ ██╗ + ██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔════╝██║████╗ ████║╚██╗██╔╝ + ██████╔╝███████║██║ ██║███████║██████╔╝███████╗██║██╔████╔██║ ╚███╔╝ + ██╔══██╗██╔══██║██║ ██║██╔══██║██╔══██╗╚════██║██║██║╚██╔╝██║ ██╔██╗ + ██║ ██║██║ ██║██████╔╝██║ ██║██║ ██║███████║██║██║ ╚═╝ ██║██╔╝ ██╗ + ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ + +""" + +import platform + +from setuptools import setup +from setuptools import Extension +from Cython.Distutils import build_ext +from Cython.Build import cythonize +import numpy + + +os_type = platform.system() # 'Linux', 'Windows', 'macOS' + +if os_type == "Linux": + LINK_ARGS = ["-Wl,-rpath,$ORIGIN"] + LIBRARY_DIRS = ["src/radarsimcpp/build"] +elif os_type == "Darwin": + LINK_ARGS = ["-Wl,-rpath,$ORIGIN"] + LIBRARY_DIRS = ["src/radarsimcpp/build"] +elif os_type == "Windows": + LINK_ARGS = [] + LIBRARY_DIRS = ["src/radarsimcpp/build/Release"] + +MACROS = [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"),("_FREETIER_", 1)] +INCLUDE_DIRS = ["src/radarsimcpp/includes", "src/radarsimcpp/includes/zpvector"] + +ext_modules = [ + Extension( + "radarsimpy.lib.cp_radarsimc", + ["src/radarsimpy/lib/cp_radarsimc.pyx"], + define_macros=MACROS, + include_dirs=INCLUDE_DIRS, + libraries=["radarsimcpp"], + library_dirs=LIBRARY_DIRS, + extra_link_args=LINK_ARGS, + ), + Extension( + "radarsimpy.rt", + ["src/radarsimpy/raytracing/rt.pyx"], + define_macros=MACROS, + include_dirs=INCLUDE_DIRS, + libraries=["radarsimcpp"], + library_dirs=LIBRARY_DIRS, + extra_link_args=LINK_ARGS, + ), + Extension( + "radarsimpy.simulator", + ["src/radarsimpy/simulator.pyx"], + define_macros=MACROS, + include_dirs=INCLUDE_DIRS, + libraries=["radarsimcpp"], + library_dirs=LIBRARY_DIRS, + extra_link_args=LINK_ARGS, + ), +] + +setup( + name="radarsimpy", + cmdclass={"build_ext": build_ext}, + ext_modules=cythonize( + ext_modules, + annotate=False, + compiler_directives={"language_level": "3"}, + ), + include_dirs=[numpy.get_include()], +) diff --git a/src/radarsimcpp b/src/radarsimcpp index 6d92d89..cfa5318 160000 --- a/src/radarsimcpp +++ b/src/radarsimcpp @@ -1 +1 @@ -Subproject commit 6d92d89c2ebd02f3ed46e3dad94943e4f4fe3a3d +Subproject commit cfa53181963b946db1431d0091ef88d4fefc5bab diff --git a/src/radarsimpy/includes/radarsimc.pxd b/src/radarsimpy/includes/radarsimc.pxd index 7c2825d..fd17e7f 100644 --- a/src/radarsimpy/includes/radarsimc.pxd +++ b/src/radarsimpy/includes/radarsimc.pxd @@ -44,6 +44,9 @@ cdef extern from "libs/mem_lib.hpp": int_t size, vector[Vec3[T]] &vect) except + +cdef extern from "libs/free_tier.hpp": + cdef int IsFreeTier() except + + """ Target """ diff --git a/src/radarsimpy/lib/cp_radarsimc.pyx b/src/radarsimpy/lib/cp_radarsimc.pyx index 378016b..27a3889 100644 --- a/src/radarsimpy/lib/cp_radarsimc.pyx +++ b/src/radarsimpy/lib/cp_radarsimc.pyx @@ -33,6 +33,7 @@ from radarsimpy.includes.type_def cimport vector from radarsimpy.includes.radarsimc cimport Mem_Copy from radarsimpy.includes.radarsimc cimport Mem_Copy_Vec3 from radarsimpy.includes.radarsimc cimport Mem_Copy_Complex +from radarsimpy.includes.radarsimc cimport IsFreeTier from libcpp.complex cimport complex as cpp_complex from libcpp cimport bool @@ -409,6 +410,10 @@ cdef Target[float_t] cp_Target(radar, points_mv = np.ascontiguousarray(v_matrix).astype(np_float) cells_mv = np.ascontiguousarray(f_matrix).astype(np.int32) ms.clear() + + if IsFreeTier(): + if cells_mv.shape[0] > 32: + raise Exception("You're currently using RadarSimPy's FreeTier, which imposes a restriction on the maximum mesh size of a target to 32. Please consider supporting my work by upgrading to the standard version. Just choose any amount greater than zero on https://radarsimx.com/product/radarsimpy/ to access the standard version download links. Your support will help improve the software. Thank you for considering it.") cdef float_t[:] origin_mv = np.array(target.get("origin", (0, 0, 0)), dtype=np_float) @@ -569,6 +574,10 @@ cdef Target[float_t] cp_RCS_Target(target): points_mv = np.ascontiguousarray(v_matrix).astype(np_float) cells_mv = np.ascontiguousarray(f_matrix).astype(np.int32) ms.clear() + + if IsFreeTier(): + if cells_mv.shape[0] > 32: + raise Exception("You are presently utilizing RadarSimPy's FreeTier plan, which imposes a restriction on the maximum mesh size of a target to 32. Please consider supporting my work by upgrading to the standard version. Just choose any amount greater than zero on https://radarsimx.com/product/radarsimpy/ to access the standard version download links. Your support will help improve the software. Thank you for considering it.") cdef float_t[:] origin_mv = np.array(target.get("origin", (0, 0, 0)), dtype=np_float) diff --git a/src/radarsimpy/raytracing/rcs.pyx b/src/radarsimpy/raytracing/rcs.pyx index 677ca0b..0ffb62f 100644 --- a/src/radarsimpy/raytracing/rcs.pyx +++ b/src/radarsimpy/raytracing/rcs.pyx @@ -25,6 +25,8 @@ from radarsimpy.includes.type_def cimport vector from radarsimpy.lib.cp_radarsimc cimport cp_RCS_Target from radarsimpy.includes.radarsimc cimport Target, Rcs +from radarsimpy.includes.radarsimc cimport IsFreeTier + from libcpp.complex cimport complex as cpp_complex import numpy as np @@ -97,6 +99,10 @@ cpdef rcs_sbr(targets, :return: Target's RCS (m^2), use 10*log10(RCS) to convert to dBsm :rtype: float """ + if IsFreeTier(): + if len(targets) > 3: + raise Exception("You're currently using RadarSimPy's FreeTier, which limits RCS simulation to 3 maximum targets. Please consider supporting my work by upgrading to the standard version. Just choose any amount greater than zero on https://radarsimx.com/product/radarsimpy/ to access the standard version download links. Your support will help improve the software. Thank you for considering it.") + cdef vector[Target[float]] targets_vt cdef Vec3[cpp_complex[double]] inc_pol_cpp diff --git a/src/radarsimpy/raytracing/scene.pyx b/src/radarsimpy/raytracing/scene.pyx index dcb6ee2..52bc2f7 100644 --- a/src/radarsimpy/raytracing/scene.pyx +++ b/src/radarsimpy/raytracing/scene.pyx @@ -31,6 +31,7 @@ from radarsimpy.includes.radarsimc cimport Transmitter from radarsimpy.includes.radarsimc cimport Receiver from radarsimpy.includes.radarsimc cimport Snapshot, Scene from radarsimpy.includes.radarsimc cimport Mem_Copy_Vec3 +from radarsimpy.includes.radarsimc cimport IsFreeTier from libc.stdlib cimport malloc, free cimport cython @@ -165,6 +166,16 @@ cpdef scene(radar, targets, density=1, level=None, noise=True, debug=False): cdef int_t psstride_c = samples_c cdef int_t idx_c + + if IsFreeTier(): + if len(targets) > 3: + raise Exception("You're currently using RadarSimPy's FreeTier, which limits RCS simulation to 3 maximum targets. Please consider supporting my work by upgrading to the standard version. Just choose any amount greater than zero on https://radarsimx.com/product/radarsimpy/ to access the standard version download links. Your support will help improve the software. Thank you for considering it.") + + if radar.radar_prop["transmitter"].txchannel_prop["size"] > 2: + raise Exception("You're currently using RadarSimPy's FreeTier, which imposes a restriction on the maximum number of transmitter channels to 2. Please consider supporting my work by upgrading to the standard version. Just choose any amount greater than zero on https://radarsimx.com/product/radarsimpy/ to access the standard version download links. Your support will help improve the software. Thank you for considering it.") + + if radar.radar_prop["receiver"].rxchannel_prop["size"] > 2: + raise Exception("You're currently using RadarSimPy's FreeTier, which imposes a restriction on the maximum number of receiver channels to 2. Please consider supporting my work by upgrading to the standard version. Just choose any amount greater than zero on https://radarsimx.com/product/radarsimpy/ to access the standard version download links. Your support will help improve the software. Thank you for considering it.") """ Targets diff --git a/src/radarsimpy/simulator.pyx b/src/radarsimpy/simulator.pyx index dd7029c..497b398 100644 --- a/src/radarsimpy/simulator.pyx +++ b/src/radarsimpy/simulator.pyx @@ -32,6 +32,7 @@ from radarsimpy.includes.radarsimc cimport Radar from radarsimpy.lib.cp_radarsimc cimport cp_TxChannel, cp_Transmitter from radarsimpy.includes.radarsimc cimport Transmitter from radarsimpy.includes.radarsimc cimport Mem_Copy_Vec3 +from radarsimpy.includes.radarsimc cimport IsFreeTier from radarsimpy.lib.cp_radarsimc cimport cp_Point from radarsimpy.includes.radarsimc cimport Point @@ -146,6 +147,16 @@ cpdef simc(radar, targets, noise=True): cdef int_t idx_c + if IsFreeTier(): + if len(targets) > 3: + raise Exception("You're currently using RadarSimPy's FreeTier, which limits RCS simulation to 3 maximum targets. Please consider supporting my work by upgrading to the standard version. Just choose any amount greater than zero on https://radarsimx.com/product/radarsimpy/ to access the standard version download links. Your support will help improve the software. Thank you for considering it.") + + if radar.radar_prop["transmitter"].txchannel_prop["size"] > 2: + raise Exception("You're currently using RadarSimPy's FreeTier, which imposes a restriction on the maximum number of transmitter channels to 2. Please consider supporting my work by upgrading to the standard version. Just choose any amount greater than zero on https://radarsimx.com/product/radarsimpy/ to access the standard version download links. Your support will help improve the software. Thank you for considering it.") + + if radar.radar_prop["receiver"].rxchannel_prop["size"] > 2: + raise Exception("You're currently using RadarSimPy's FreeTier, which imposes a restriction on the maximum number of receiver channels to 2. Please consider supporting my work by upgrading to the standard version. Just choose any amount greater than zero on https://radarsimx.com/product/radarsimpy/ to access the standard version download links. Your support will help improve the software. Thank you for considering it.") + ts_shape = np.shape(radar.time_prop["timestamp"]) # Point Targets