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

Uploaded Python 3

File details

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

File metadata

  • Download URL: regOct-1.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 5e2570fe6e3b9bfc51dcde6db03cbfe9c5f2408b2f3a3dfdc186b29596ab994c
MD5 669de5058e420b31db228b3e32851bfb
BLAKE2b-256 4ca8121899eeee57f16edcea37fd4cc123b60187f34de2555f803a5a927cc457

See more details on using hashes here.

File details

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

File metadata

  • Download URL: regOct-1.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 103d6c177140ef77ea93817ad74190bcf1448611d9002694de832cfea89e9e4f
MD5 ec38330fe8336a52fc3ac02288e5e3c9
BLAKE2b-256 5edaa7d801fae714930a2ab7a0c452192943853b1510dfb923b9dedbb9adf99a

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