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. The order in which the commands are stored in the file imply the position at which they are executed.
  3. State checks within the octree are linear and processor unintensive.
  4. 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.2.tar.gz (11.9 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.2-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: regOct-1.1.2.tar.gz
  • Upload date:
  • Size: 11.9 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.2.tar.gz
Algorithm Hash digest
SHA256 b3ee23bb3e31aa2cdd3b402a3f0546b15c0fee12db3b888f0f6955f9d90dd12d
MD5 7df9c964514f96e46a27ede6ba4f98f7
BLAKE2b-256 6cc30ccb8e15896719a19c618c7827f04bffe8c19f9c731554d7e59429c7c42a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: regOct-1.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 adf7e18b25a710e0a2f4c2b0bdd7fd02c3985745f2cd4d33556dc6a949187c91
MD5 71216c9e6eb1a0f7dfb88c8fed4c4c65
BLAKE2b-256 9f33cbad9d714c82d6d55f52c8a9c7491fff3a574ffa5b2e2a0f55a3443774fd

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