Skip to main content

Python bindings for SlamDunk

Project description


SlamDunk is a powerful and user-friendly C++/Python library for making live 3D and 2D visualizations for prototyping, data exploration, and algorithm development.

It is very lightweight, built using OpenGL and ImGui.

The project is in very early development with many improvements coming in the near future.

Examples

Hello world

Here is a simple "hello world" program for a SlamDunk visualization.

# python
import slamd

if __name__ == "__main__":
    window = slamd.Window("Hello world", 1000, 1000)

    scene = slamd.scene()

    scene.set_object("/origin", slamd.geom.triad())

    window.add_scene("scene", scene)

    window.wait_for_close()
// C++
#include <slamd/slamd.hpp>

int main() {
    slamd::Window window("Hello world", 1000, 1000);

    auto scene = slamd::scene();

    scene->set_object("/origin", slamd::geom::triad());

    window.add_scene("scene", scene);

    window.wait_for_close();
}

This example highlights the main components of SlamDunk.

  1. The Window object handles the actual display window.
  2. A Scene object represents and contains a tree of 3D objects.
  3. Geometry objects can be added to Scenes with a path in the tree.
  4. To display a scene, we must add it to the window - this creates a view of the scene.

Running this program results in the following interactive visualization:

Multiple scenes

We use ImGui to allow multiple sub-windows with floating and docking support inside the SlamDunk viewer. The following example illustrates creating two windows, each showing its own scene.

# python
import slamd
import numpy as np

if __name__ == "__main__":
    window = slamd.Window("two windows", 1000, 1000)

    scene1 = slamd.scene()
    scene2 = slamd.scene()

    window.add_scene("scene 1", scene1)
    scene1.set_object("/box", slamd.geom.box())

    window.add_scene("scene 2", scene2)
    scene2.set_object("/origin", slamd.geom.triad())

    scene2.set_object("/ball", slamd.geom.sphere(2.0))

    sphere_transform = np.identity(4, dtype=np.float32)
    sphere_transform[:, 3] = np.array([5.0, 1.0, 2.0, 1.0])

    scene2.set_transform("/ball", sphere_transform)

    window.wait_for_close()
// C++
#include <glm/glm.hpp>
#include <slamd/slamd.hpp>

int main() {
    slamd::Window window("two windows", 1000, 1000);

    auto scene1 = slamd::scene();
    auto scene2 = slamd::scene();

    window.add_scene("scene 1", scene1);
    scene1->set_object("/box", slamd::geom::box());

    window.add_scene("scene 2", scene2);
    scene2->set_object("/origin", slamd::geom::triad());
    scene2->set_object("/ball", slamd::geom::sphere(2.0f));

    glm::mat4 sphere_transform(1.0);
    sphere_transform[3] += glm::vec4(5.0, 1.0, 2.0, 1.0);

    scene2->set_transform("/ball", sphere_transform);

    window.wait_for_close();
}

The resulting window looks like this:

The windows are fully controllable - you can drag then around, make tabs, use them in floating mode, dock them to the sides like you see in the screenshot. All of this is supported by ImGui.

Further reading

The examples in the /examples folder showcase some more features of SlamDunk, like

  • Canvases for 2D visualizations
  • Multiple views of the same scene
  • Moving objects around.
  • Taking control of the render loop to create fully-fletced GUIs around SlamDunk using the power of ImGui.

Installation

Python

The python binding wheels are available on PyPi, so you can simply

pip install slamd

C++

With FetchContent

You can use CMake's FetchContent. Add this to your CMakeLists.txt:

include(FetchContent)

FetchContent_Declare(
  slamd
  GIT_REPOSITORY https://github.com/Robertleoj/slam_dunk.git
  GIT_TAG main
  SOURCE_SUBDIR slamd
)

FetchContent_MakeAvailable(slamd)

Linking to it then looks like:

target_link_libraries(
    your_target PRIVATE

    slamd::slamd
)

With git submodules

If you add the repo as a submodule in your project, you can add it as a subdirectory with

add_subdirectory(path/to/slam_dunk/slamd)

Just make sure to

git submodule update --init --recursive

inside the submodule, as all necessary dependencies are vendored.

You can then link it to your executable or library with

target_link_libraries(
    your_target PRIVATE

    slamd::slamd
)

Contributions

All contributions are welcome! SlamDunk is in very early development, so there is enough work to do, and multiple things to improve.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

slamd-0.1.6-cp313-cp313-manylinux_2_28_x86_64.whl (48.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

slamd-0.1.6-cp312-cp312-manylinux_2_28_x86_64.whl (48.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

slamd-0.1.6-cp311-cp311-manylinux_2_28_x86_64.whl (48.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

File details

Details for the file slamd-0.1.6-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for slamd-0.1.6-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eb2b5a7e0cf8fdd0642278b2623818f0cb76f705b9a8ddcf37601415c64b7408
MD5 92af09701d125fbb6598153747a5eea3
BLAKE2b-256 2c3b5bf3147ca1ac7240ce0a45a4317ef44d8393e01e6d49e88f78fd762f5ef0

See more details on using hashes here.

Provenance

The following attestation bundles were made for slamd-0.1.6-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: pip_publish.yml on Robertleoj/slam_dunk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slamd-0.1.6-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for slamd-0.1.6-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1a019d488caaed916e6905d11f8c2817f7baac77e914f460da3b0605fe028b2c
MD5 7543658b0edf6f6784a0c2762e1326d8
BLAKE2b-256 4dd861b2670be20089d3dc2ec034e496b909722e897cb7955d6fa65e27e32bf7

See more details on using hashes here.

Provenance

The following attestation bundles were made for slamd-0.1.6-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: pip_publish.yml on Robertleoj/slam_dunk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slamd-0.1.6-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for slamd-0.1.6-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7edaf32183deb930fdc7b26ed6718d3f9999eecdb86dcb285918bb7020fb13da
MD5 0b41ffbe70910a4839266feafbd4c741
BLAKE2b-256 15a45d0752d2c1951b956dc0fe758b22b030f9dd95eb371d9fab543525d80d25

See more details on using hashes here.

Provenance

The following attestation bundles were made for slamd-0.1.6-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: pip_publish.yml on Robertleoj/slam_dunk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page