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.1.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.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: regOct-1.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 548e20d9a70bb08084b549e2025829a78208c664b10976645723396cf3e2c0be
MD5 2a311bef734ca48e36bf4cc9964ab4cd
BLAKE2b-256 5ec56f11961e62469ee30528a559ff6fa80da6e0b1afe29f15dd4c41b47b842c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: regOct-1.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 39cfa5421006ec03f6c9e5ba4fca6d471208e8ec6d50918e150e8fafef47d682
MD5 f0a17177d6b37c44625e19c0f9505e56
BLAKE2b-256 a00da1454cf76ed74e1e90a6dcaeeaf28f736b21dd44d5964086a64d57836ae9

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