Package: regOct
regOctan implementation of an ordered octree systemDesign principlesProvide an effective, comprehensive storage medium for cubic, three-dimensional data.State checks within the octree are relatively processor unintensive.The Octree is a self-contained system. All information regarding the octree is stored in the file.Use1. General useEvery 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 IOIn case it is necessary to preserve an octree for later use, it may be saved and loaded to the filesystem via as shown below:importregoctoriginal_octree=Octree(2)# load information into octreefile_path="file_path.onc"regoct.save(octree,file_path)loaded_octree=regoct.load(file_path)assertoriginal_octree==loaded_octreeThis 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,setThis is addressed followingly.3. Advanced octree IOregoct 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 methodsto_file(obj, saver: "regoct.SavingStream")andfrom_file(cls, loader: "regoct.LoadingStream"), where the paramssaverandloaderprovide access to the data using a set of methods. These methods in loader and saver mirror each other and are as follows:regoct.SavingStreamregoct.LoadingStreamdescriptionsaver.convert(value)loader.convert() -> anydynamic conversionsaver.i8(value)loader.i8() -> int8-bit signed integersaver.i16(value)loader.i16() -> int16-bit signed integersaver.i32(value)loader.i32() -> int32-bit signed integersaver.i64(value)loader.i64() -> int64-bit signed integersaver.u8(value)loader.u8() -> int8-bit unsigned integersaver.u16(value)loader.u16() -> int16-bit unsigned integersaver.u32(value)loader.u32() -> int32-bit unsigned integersaver.u64(value)loader.u64() -> int64-bit unsigned integersaver.f32(value)loader.f32() -> float32-bit floatsaver.f64(value)loader.f64() -> float64-bit floatsaver.c64(value)loader.c64() -> complex2x 32-bit float complex numbersaver.c128(value)loader.c128() -> complex2x 64-bit float complex numbersaver.Str(value)loader.Str() -> strvariable-length utf-8 stringsaver.List(value)loader.List() -> listvariable-length dynamic-type listsaver.Dict(value)loader.Dict() -> dictvariable-length dynamic-type dictsaver.Set(value)loader.Set() -> setvariable-length dynamic-type setBe aware that the order in which these methods are called in the to_file and from_file methods should be equal to eachother.importregoctfromregoctimportInterface,SavingStream,LoadingStreamclassDataPacket(Interface):def__init__(self,*args,**kwds):...defto_file(obj,saver:SavingStream):...deffrom_file(cls,loader:LoadingStream):...original_octree=regoct.Octree(2)# load information into octreefile_path="file_path.onc"DataPacket.save(octree,file_path)loaded_octree=DataPacket.load(file_path)assertoriginal_octree==loaded_octreeVisualisation:The module has an interactable viewer to render octrees in 3d.
Currently, this is done with the statementregoct.Display(octree).main(), but since this is very verbose, expect it to change.And now for something completely different