Skip to main content

A module implementing octrees for python

Project description

regOct

an implementation of an ordered octree system

Design principles

  1. Provide an effective, comprehensive storage medium for cubic, three-dimensional data.
  2. State checks within the octree are relatively processor unintensive.
  3. The Octree is a self-contained system. All information regarding the octree is stored in the file.

Use

1. General use

Every octree has an integer "level", which defines its size. For a given level, the octree takes the form of a cube with ranges of 0 - 2**level.

regoct.Octree(level) -> Octree

# setting a value:
octree[(x, y, z, level)] = new_value
# level may be omitted if it is 0:
octree[(x, y, z)] = new_value

# getting a value:
value = octree[(x, y, z)]

2. Basic octree IO

In case it is necessary to preserve an octree for later use, it may be saved and loaded to the filesystem via as shown below:

import regoct

original_octree = Octree(2)
# load information into octree

file_path = "file_path.onc"
regoct.save(octree, file_path)
loaded_octree = regoct.load(file_path)

assert original_octree == loaded_octree

This however has a major caveat: the octrees serialized this way may only have internal values of python's base data types:

None(wip), Ellipsis(wip), bool(wip), int, float, complex, str, list, dict, set 

This is addressed followingly.

3. Advanced octree IO

regoct provides a API to modify the serialization process. This is useful for implementing routines for class instances.

The ABC regoct.Interface supplies the tools for implementing the API. It requires the methods to_file(obj, saver: "regoct.SavingStream") and from_file(cls, loader: "regoct.LoadingStream"), where the params saver and loader provide access to the data using a set of methods. These methods in loader and saver mirror each other and are as follows:

regoct.SavingStream regoct.LoadingStream description
saver.convert(value) loader.convert() -> any dynamic conversion
saver.i8(value) loader.i8() -> int 8-bit signed integer
saver.i16(value) loader.i16() -> int 16-bit signed integer
saver.i32(value) loader.i32() -> int 32-bit signed integer
saver.i64(value) loader.i64() -> int 64-bit signed integer
saver.u8(value) loader.u8() -> int 8-bit unsigned integer
saver.u16(value) loader.u16() -> int 16-bit unsigned integer
saver.u32(value) loader.u32() -> int 32-bit unsigned integer
saver.u64(value) loader.u64() -> int 64-bit unsigned integer
saver.f32(value) loader.f32() -> float 32-bit float
saver.f64(value) loader.f64() -> float 64-bit float
saver.c64(value) loader.c64() -> complex 2x 32-bit float complex number
saver.c128(value) loader.c128() -> complex 2x 64-bit float complex number
saver.Str(value) loader.Str() -> str variable-length utf-8 string
saver.List(value) loader.List() -> list variable-length dynamic-type list
saver.Dict(value) loader.Dict() -> dict variable-length dynamic-type dict
saver.Set(value) loader.Set() -> set variable-length dynamic-type set

Be aware that the order in which these methods are called in the to_file and from_file methods should be equal to eachother.

import regoct
from regoct import Interface, SavingStream, LoadingStream

class DataPacket(Interface):
    def __init__(self, *args, **kwds):...

    def to_file(obj, saver: SavingStream):...

    def from_file(cls, loader: LoadingStream):...


original_octree = regoct.Octree(2)
# load information into octree

file_path = "file_path.onc"
DataPacket.save(octree, file_path)
loaded_octree = DataPacket.load(file_path)

assert original_octree == loaded_octree

Visualisation:

The module has an interactable viewer to render octrees in 3d. Currently, this is done with the statement regoct.Display(octree).main(), but since this is very verbose, expect it to change.

And now for something completely different

no one expects the spanish inquisition

Project details


Download files

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

Source Distribution

regOct-1.1.3.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

regOct-1.1.3-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file regOct-1.1.3.tar.gz.

File metadata

  • Download URL: regOct-1.1.3.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2

File hashes

Hashes for regOct-1.1.3.tar.gz
Algorithm Hash digest
SHA256 9e492b194cc2718749bcca57942ebbf96227e02688311dc02810d44f22ab4cd6
MD5 d5c577b22a379c8d901af1fde2cd0b95
BLAKE2b-256 f6201cbd5c6e78ea15003636eacc5e493f6acc908b15c6dcc16f562952668c4b

See more details on using hashes here.

File details

Details for the file regOct-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: regOct-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2

File hashes

Hashes for regOct-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f364205e8b784996071124dd595f0610a0bcdf20c5d14dffcc5bc928b7adb1c9
MD5 bd8f074b1102d773e57922dc50167fcc
BLAKE2b-256 abab26305c25415ad8f0bd484eeebbb53c878e70d0d5f866e3581b4a0b9e2aab

See more details on using hashes here.

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