nndt.space2 package#

Submodules#

nndt.space2.abstracts module#

class nndt.space2.abstracts.AbstractBBoxNode(name: str, bbox=((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), _print_color='\x1b[39m', _nodetype='UNDEFINED', parent=None)[source]#

Bases: nndt.space2.abstracts.AbstractTreeElement

Element of the space model tree with a boundary box

__init__(name: str, bbox=((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), _print_color='\x1b[39m', _nodetype='UNDEFINED', parent=None)[source]#

Create an element of the space model tree with a boundary box

Parameters
  • name – name of the tree node

  • bbox – boundary box in form ((X_min, Y_min, Z_min), (X_max, Y_max, Z_max))

  • parent – parent node

plot(mode: Optional[str] = 'default', filepath: Optional[str] = None, **kwargs)[source]#

Iterate over all Object3D in the tree and show the plot if the filepath is None. Save the plot in a file if the filepath is None.

Parameters
  • mode (Optional[str], optional) – Only the “default” mode is supported yet. Defaults to “default”.

  • filepath (Optional[str], optional) – File name. If it exists save there otherwise show it. Defaults to None.

print(mode: Optional[str] = 'default')[source]#

Print tree view for this element and all children’s elements

Parameters

mode (Optional[str], optional) – “default” print 3D objects and methods; “source” prints only space, groups, and file sources; “full” prints all nodes of the tree; Defaults to “default”.

Returns

tree representation string

Return type

str

unload_from_memory()[source]#
class nndt.space2.abstracts.AbstractLoader[source]#

Bases: object

calc_bbox() -> ((<class 'float'>, <class 'float'>, <class 'float'>), (<class 'float'>, <class 'float'>, <class 'float'>))[source]#

Return the boundary box size of a 3D object.

Returns

boundary box: (Xmin, Xmax, Ymin), (Ymax, Zmin, Zmax)

Return type

(tuple), (tuple)

abstract is_load() bool[source]#

Check if the data is already loaded

abstract load_data()[source]#

Load data to memory

abstract unload_data()[source]#

Remove references to the uploaded data. This method NO NOT call the garbage collectors

class nndt.space2.abstracts.AbstractTreeElement(name: str, _print_color: str = '\x1b[39m', _nodetype: str = 'UNDEFINED', parent=None)[source]#

Bases: anytree.node.nodemixin.NodeMixin

Abstract element of the space model tree

__init__(name: str, _print_color: str = '\x1b[39m', _nodetype: str = 'UNDEFINED', parent=None)[source]#

Create an abstract element of space model tree

Parameters
  • name – name of the tree node

  • _print_color – color of this node for print()

  • _nodetype – type of the code in form of string literal

  • parent – parent node

class nndt.space2.abstracts.IterAccessMixin[source]#

Bases: object

nndt.space2.abstracts.node_method(helpstr=None)[source]#

This decorator mark method for attachments to the space model tree

Parameters

helpstr – Short information about a performed transformation of data

Returns

wrapper

nndt.space2.filesource module#

class nndt.space2.filesource.FileSource(name, filepath: str, loader_type: str, bbox=((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), parent=None)[source]#

Bases: nndt.space2.abstracts.AbstractBBoxNode, nndt.space2.abstracts.IterAccessMixin

This class keeps the location of the file for processing.

Parameters
  • name (str) – name of the node

  • filepath (str) – a file path. If it does not exist raise FileNotFoundError.

  • loader_type (str) – loader type, this string notes type of information for uploading

  • bbox (tuple, optional) – boundary box in form ((X_min, Y_min, Z_min), (X_max, Y_max, Z_max)). Defaults to ((0., 0., 0.), (0., 0., 0.)).

  • parent (_type_, optional) – parent node. Defaults to None.

Raises

FileNotFoundError – file or directory is requested but doesn’t exist.

nndt.space2.group module#

class nndt.space2.group.Group(name, bbox=((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), parent=None)[source]#

Bases: nndt.space2.abstracts.AbstractBBoxNode, nndt.space2.abstracts.IterAccessMixin

Group is a tree element that can contain other groups and 3D objects.

Parameters
  • name (str) – name of the tree node.

  • bbox (tuple, optional) – boundary box in form ((X_min, Y_min, Z_min), (X_max, Y_max, Z_max)). Defaults to ((0., 0., 0.), (0., 0., 0.)).

  • parent (_type_, optional) – parent node. Defaults to None.

nndt.space2.implicit_representation module#

class nndt.space2.implicit_representation.IR1SDF(func: nndt.trainable_task.SimpleSDF.FUNC, params, bbox)[source]#

Bases: nndt.primitive_sdf.AbstractSDF

property bbox: ((<class 'float'>, <class 'float'>, <class 'float'>), (<class 'float'>, <class 'float'>, <class 'float'>))#

Return the minimal bounding box around the implicitly defined object. :return: (X_min, Y_min, Z_min) , (X_max, Y_max, Z_max)

class nndt.space2.implicit_representation.ImpRepr(name: str, abstract_sdf: nndt.primitive_sdf.AbstractSDF, parent=None)[source]#

Bases: nndt.space2.abstracts.AbstractBBoxNode, nndt.space2.abstracts.IterAccessMixin

purefun_sdf()[source]#
purefun_vec_sdf()[source]#
purefun_vec_sdf_dx()[source]#
purefun_vec_sdf_dy()[source]#
purefun_vec_sdf_dz()[source]#

nndt.space2.loader module#

class nndt.space2.loader.EmptyLoader(filepath: str)[source]#

Bases: nndt.space2.abstracts.AbstractLoader

Dummy loader, that does nothing.

Parameters

filepath (str) – path to the file

is_load() bool[source]#

Check if the data is already loaded

load_data()[source]#

Load data to memory

unload_data()[source]#

Remove references to the uploaded data. This method NO NOT call the garbage collectors

class nndt.space2.loader.IR1Loader(filepath: str)[source]#

Bases: nndt.space2.abstracts.AbstractLoader

property bbox#
calc_bbox() -> ((<class 'float'>, <class 'float'>, <class 'float'>), (<class 'float'>, <class 'float'>, <class 'float'>))[source]#

Return the boundary box size of a 3D object.

Returns

boundary box: (Xmin, Xmax, Ymin), (Ymax, Zmin, Zmax)

Return type

(tuple), (tuple)

property functions#
is_load() bool[source]#

Return is file loaded.

Returns

File load status.

Return type

bool

property json#
load_data()[source]#

Load data to memory

property params#
unload_data()[source]#

Remove references to the uploaded data. This method NO NOT call the garbage collectors

class nndt.space2.loader.MeshObjLoader(filepath: str)[source]#

Bases: nndt.space2.abstracts.AbstractLoader

Load .obj file with mesh.

Parameters

filepath (str) – path to the file

calc_bbox() -> ((<class 'float'>, <class 'float'>, <class 'float'>), (<class 'float'>, <class 'float'>, <class 'float'>))[source]#

Return the boundary box size of a 3D object.

Returns

boundary box: (Xmin, Xmax, Ymin), (Ymax, Zmin, Zmax)

Return type

(tuple), (tuple)

is_load() bool[source]#

Return is file loaded.

Returns

File load status.

Return type

bool

property kdtree: pykdtree.kdtree.KDTree#

Return KDTree of a 3D object.

Returns

KDTree.

Return type

KDTree

load_data()[source]#

Load data from the file

property mesh: vtkmodules.vtkCommonDataModel.vtkPolyData#

Return the mesh of a 3D object.

Returns

Mesh.

Return type

vtk.vtkPolyData

property points: jax.Array#

Return points of a 3D object.

Returns

Points of the object.

Return type

jnp.ndarray

property rgba: Optional[jax.Array]#

Return colors of all mesh vertex

Returns

RGBA color

Return type

Optional[jnp.ndarray]

unload_data()[source]#

Clear data

class nndt.space2.loader.SDTLoader(filepath: str)[source]#

Bases: nndt.space2.abstracts.AbstractLoader

Load signed distance tensor file.

Parameters

filepath (str) – path to the file

calc_bbox() -> ((<class 'float'>, <class 'float'>, <class 'float'>), (<class 'float'>, <class 'float'>, <class 'float'>))[source]#

Return the boundary box size of the object.

Returns

boundary box: (Xmin, Xmax, Ymin), (Ymax, Zmin, Zmax)

Return type

(tuple), (tuple)

is_load() bool[source]#

Check if the data is already loaded

load_data()[source]#

Load data from the file

request(ps_xyz: jax.Array) jax.Array[source]#

Calculate the distance from points to the surface

Parameters

ps_xyz – points in the normalized space

Returns

distances in SDT form

property sdt#

Return full STD data.

Returns

STD

Return type

jnp.ndarray

unload_data()[source]#

Remove references to the uploaded data. This method NO NOT call the garbage collectors

class nndt.space2.loader.TXTLoader(filepath: str)[source]#

Bases: nndt.space2.abstracts.AbstractLoader

Load txt file

Parameters

filepath (str) – path to the file

is_load() bool[source]#

Check if the data is already loaded

load_data()[source]#

Load data to memory

property text#

Return text from the file.

Returns

File content.

Return type

str

unload_data()[source]#

Remove references to the uploaded data. This method NO NOT call the garbage collectors

nndt.space2.method_set module#

class nndt.space2.method_set.ColorMethodSetNode(object_3d: nndt.space2.abstracts.AbstractBBoxNode, mesh: nndt.space2.filesource.FileSource, transform: nndt.space2.transformation.AbstractTransformation, parent: Optional[nndt.space2.abstracts.AbstractBBoxNode] = None)[source]#

Bases: nndt.space2.method_set.MethodSetNode

surface_ind2rgba(ind: jax.Array) jax.Array[source]#

Convert indexes of the surface vertex to their colors

Data transformation surface_ind2rgba(ind[..,1]) -> rgba[..,4]

Parameters

ind – index of surface vertexes

Returns

colors in RGBA format

surface_rgba() jax.Array[source]#

Get colors of all surface vertexes

Data transformation surface_rgba() -> xyz[N,4]

Returns

colors in RGBA format

surface_xyz2rgba(ns_xyz: jax.Array) jax.Array[source]#

Convert coordinates of points to colors of the nearest vertex on the surface.

Data transformation surface_xyz2rgba(ns_xyz[..,3]) -> rgba[..,4]

Parameters

ns_xyz – coordinates of points in normalized space

Returns

colors in RGBA format

class nndt.space2.method_set.MeshObjMethodSetNode(object_3d: nndt.space2.abstracts.AbstractBBoxNode, mesh: nndt.space2.filesource.FileSource, transform: nndt.space2.transformation.AbstractTransformation, parent: Optional[nndt.space2.abstracts.AbstractBBoxNode] = None)[source]#

Bases: nndt.space2.method_set.MethodSetNode

sampling_eachN_from_mesh(count=1, step=1, shift=0) -> (<class 'jax.Array'>, <class 'jax.Array'>)[source]#

Sample points from the mesh. This is a deterministic sampler, that returns each step point from the mesh vertex sequence. If an iteration pointer overcomes the array length, then it brings it to the beginning.

Data transformation sampling_eachN_from_mesh(count=N, step=M, shift=K) -> (ns_ind[N], ns_xyz[N])

Parameters
  • count – Number of the requested points

  • step – Step of the iterator

  • shift – Shift of the first iteration from the zero indexes.

Returns

array of indexes and array of values

save_mesh(filepath: str, name_value: dict)[source]#

Save a surface mesh to .vtp file. Dictionary may include data for storage. The dictionary key is an array name, the dictionary value is an array for storage.

Data transformation save_mesh(filepath, {name, array})

Parameters
  • filepath – Path to the .vtp file

  • name_value – Dictionary with name of vtk-arrays and data for the storage.

Returns

surface_ind2xyz(ind: jax.Array) jax.Array[source]#

Convert indexes of the surface mesh vertexes to their coordinates.

This transformation keeps the shape of the tensor. Transformation is performed along the last axis.

Data transformation surface_ind2xyz(ind[..,1]) -> ns_xyz[..,3]

Parameters

ind – indexes of points

Returns

tensor, the last axis is (x,y,z) point position

surface_xyz() jax.Array[source]#

Return the position of the surface mesh vertexes.

Data transformation surface_xyz() -> xyz[N,3]

Returns

tensor, the last axis is (x,y,z) point position

surface_xyz2ind(ns_xyz: jax.Array) -> (<class 'jax.Array'>, <class 'jax.Array'>)[source]#

Convert coordinates of the surface mesh vertexes to their indexes. If coordinates not corresponding to a mesh vertex, then the nearest vertex is detected. This transformation keeps the shape of the tensor. Transformation is performed along the last axis. Note, this method work wraps low-level KDTree implementation.

Data transformation surface_xyz2ind(ns_xyz[..,3]) -> ns_dist[..,1], ns_ind[..,1]

Parameters

ns_xyz – points in the normalized space

Returns

distances and indexes of the surface mesh points

class nndt.space2.method_set.MethodNode(name: str, docstring: Optional[str], parent=None)[source]#

Bases: nndt.space2.abstracts.AbstractTreeElement

class nndt.space2.method_set.MethodSetNode(name: str, parent=None)[source]#

Bases: nndt.space2.abstracts.AbstractTreeElement

class nndt.space2.method_set.SDTMethodSetNode(object_3d: nndt.space2.abstracts.AbstractBBoxNode, sdt: Union[nndt.space2.filesource.FileSource, nndt.space2.implicit_representation.ImpRepr], transform: nndt.space2.transformation.AbstractTransformation, parent: Optional[nndt.space2.abstracts.AbstractBBoxNode] = None)[source]#

Bases: nndt.space2.method_set.MethodSetNode

surface_xyz2localsdt(ns_xyz: jax.Array, spacing=(2, 2, 2), scale=1.0) -> (<class 'jax.Array'>, <class 'jax.Array'>)[source]#

This method is an encoding of geometrical features for the point’s surroundings. The method creates boxes around the requested points. Then, it defines a uniform grid (UG) with the requested spacing inside the bbox. Each vertex of the uniform grid (UG) is converted to the value of the signed distance function. Thus, the method convert points to signed distance tensors (SDF) of their surroundings.

Data transformation: surface_xyz2localsdt(ns_xyz[3], spacing=(D,H,W), scale=1.) -> ns_xyz[D,H,W,3], ns_localsdt[D,H,W,1]

Parameters
  • ns_xyz – coordinates of points in normalized space

  • spacing – Number of slices for each coordinates of the box

  • scale – scale factor for the box in normalized space

Returns

tensor of UG and SDF

surface_xyz2sdt(ns_xyz: jax.Array) jax.Array[source]#

Converts coordinates of points to signed distance from the points to an object surface. The result of the method is a tensor with values of the signed distance function (SDT). This transformation keeps the shape of the tensor. Transformation is performed along the last axis.

Data transformation surface_xyz2sdt(ns_xyz[..,3]) -> ns_sdt[..,1]

Parameters

ns_xyz – coordinates in the normalized space

Returns

tensor with distances from points to the surface

class nndt.space2.method_set.SamplingMethodSetNode(parent: Optional[nndt.space2.abstracts.AbstractBBoxNode] = None)[source]#

Bases: nndt.space2.method_set.MethodSetNode

sampling_grid(spacing: (<class 'int'>, <class 'int'>, <class 'int'>) = (2, 2, 2)) jax.Array[source]#

Sample points from a bounding box (bbox) according to the vertex of the uniform mesh. This method work for the normalized space.

Data transformation sampling_grid(spacing=(D,H,W)) -> ns_xyz[D,H,W,3]

Parameters

spacing – Number of slices for each coordinate of the bbox.

Returns

4-dimensional tensor, the last axis is (x,y,z) point position.

sampling_grid_with_noise(rng_key: jax._src.prng.PRNGKeyArray, spacing: (<class 'int'>, <class 'int'>, <class 'int'>) = (2, 2, 2), sigma=0.1) jax.Array[source]#

Sample points from a bounding box (bbox) according to the vertex of the uniform mesh. Then, the method adds Gaussian noise N(0, sigma) to the point positions. This method work for the normalized space.

Data transformation sampling_grid_with_noise(key, spacing=(D,H,W), sigma) -> ns_xyz[N,3]

Parameters
  • rng_key – a key for JAX’s random generators

  • spacing – Number of slices for each coordinate of the bbox

  • sigma – Standard deviation of the Gaussian spatial noise

Returns

4-dimensional tensor, the last axis is (x,y,z) point position

sampling_uniform(rng_key: jax._src.prng.PRNGKeyArray, count: int = 100) jax.Array[source]#

Sample points from a bounding box (bbox) according to the multidimensional uniform distribution.

Data transformation sampling_uniform(key, N) -> ns_xyz[N,3]

Parameters
  • rng_key – a key for JAX’s random generators

  • count – number of points for generation

Returns

2-dimensional tensor, the last axis is (x,y,z) point position

nndt.space2.method_set_train_task module#

class nndt.space2.method_set_train_task.TrainTaskSetNode(object_3d: nndt.space2.abstracts.AbstractBBoxNode, sdt: Union[nndt.space2.filesource.FileSource, nndt.space2.implicit_representation.ImpRepr], transform: nndt.space2.transformation.AbstractTransformation, parent: Optional[nndt.space2.abstracts.AbstractBBoxNode] = None)[source]#

Bases: nndt.space2.method_set.MethodSetNode

load_batch(spacing)[source]#
train_task_sdt2sdf(filename, spacing=(64, 64, 64), width=32, depth=8, learning_rate=0.006, epochs=10001)[source]#

nndt.space2.object3D module#

class nndt.space2.object3D.Object3D(name, bbox=((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), parent=None)[source]#

Bases: nndt.space2.abstracts.AbstractBBoxNode, nndt.space2.abstracts.IterAccessMixin

Object3D is a representation of an object as a whole one. This node can contain data sources, method sets, transformations, and methods. Object3D cannot include other objects. One object may be defined by multiple files with various extensions and schemes of data storage.

Parameters
  • name (str) – Name of the object.

  • bbox (tuple, optional) – boundary box in form ((X_min, Y_min, Z_min), (X_max, Y_max, Z_max)).

  • parent (_type_, optional) – parent node. Defaults to None.

nndt.space2.plot_tree module#

nndt.space2.print_tree module#

class nndt.space2.print_tree.PrintContainer(text)[source]#

Bases: object

nndt.space2.simple_api module#

nndt.space2.simple_api.add_sphere(tree_path: nndt.space2.abstracts.AbstractBBoxNode, name, center: (<class 'float'>, <class 'float'>, <class 'float'>), radius: float)[source]#

Add sphere primitive to the space model tree

Parameters
  • tree_path – node in the space model tree

  • name – name of the primitive

  • center – center of the sphere

  • radius – radius of the sphere

Returns

the root of the tree

nndt.space2.simple_api.from_json(json: str)[source]#

Create the space model tree from the json string.

Parameters

json – json string

Returns

the space model

nndt.space2.simple_api.load_from_file_lists(name_list, mesh_list: Optional[Sequence[str]] = None, sdt_list: Optional[Sequence[str]] = None, ir1_list: Optional[Sequence[str]] = None, test_size: Optional[float] = None) nndt.space2.space.Space[source]#

Create the space model tree with a default structure from the lists of files. If the test_size is None, the tree includes root and group with the name default. If the test_size is set, the tree includes root and groups with the name test and train.

Note, the current version of NNDT can load only SDT or only IR. Both types of files together are not yet supported.

Parameters
  • name_list – list of the node names

  • mesh_list – list of the meshes. Only the .obj is supported now.

  • sdt_list – list of the SDT array. Only the .npy is supported now.

  • ir1_list – list of implicit representations. Only the .ir1 is supported now.

  • test_size – the size of the test subset from the whole dataset.

Returns

the root of the space model tree

nndt.space2.simple_api.load_from_path(root_path, template_txt='*.txt', template_sdt='*sd[ft]*.npy', template_mesh_obj='*.obj', template_implicit_ir1='*.ir1')[source]#

Load all data from the directory as a space model tree. Folders determine groups and 3D objects. Files become a FileSources. Templates allow a user to mask some files from consideration.

NOTE, This version of NNDT only supports folder structures with equal depth. FileSources must be located in terminated folders.

Parameters
  • root_path – path to folder with dataset

  • template_txt – template for text files. None value forces the method to ignore all .txt files.

  • template_sdt – template for .npy files with SDT data. None value forces the method to ignore all .npy files.

  • template_mesh_obj – template for .obj files with surface mesh data. None value forces the method to ignore all .obj files.

  • template_implicit_ir1 – template for .ir1 files with surface mesh data. None value forces the method to ignore all .ir1 files.

Returns

the root of the space model tree

nndt.space2.simple_api.load_implicit_ir1(fullpath)[source]#

Create a space model tree with group default and one 3D object. 3D object includes FileSource for .ir1 files.

Parameters

fullpath – path to files

Returns

the root of the space model tree

nndt.space2.simple_api.load_mesh_obj(fullpath)[source]#

Load .obj mesh to the default space model

Parameters

fullpath (str) – Path to the .obj file.

Returns

initialized space.

Return type

Space

nndt.space2.simple_api.load_only_one_file(fullpath, loader_type='txt')[source]#

Load one file to the default space model. Allowed types of file: txt, sdt, mesh_obj.

Parameters
  • fullpath (str) – Path to file.

  • loader_type (str, optional) – Loader type. Allowed: txt, sdt, mes_obj. Defaults to “txt”.

Raises

ValueError – loader_type is unknown.

Returns

initialized space.

Return type

Space

nndt.space2.simple_api.load_sdt(fullpath)[source]#

Load signed distance tensor (SDT) to the default space model

Parameters

fullpath (str) – Path to the SDT file.

Returns

initialized space.

Return type

Space

nndt.space2.simple_api.load_txt(fullpath)[source]#

Load text to the default space model

Parameters

fullpath (str) – Path to the txt file.

Returns

space with default nodes.

Return type

Space

nndt.space2.simple_api.read_space_from_file(filepath: str)[source]#

Create the space model from the .space file or any file with proper JSON inside. :param filepath: path to file :return: the root of the space model tree

nndt.space2.simple_api.save_space_to_file(space: nndt.space2.space.Space, filepath: str)[source]#

Store a space model tree to a .space file using JSON format

Parameters
  • space – the root of a space model tree

  • filepath – path to file

Returns

nndt.space2.simple_api.split_node_kfold(tree_path: nndt.space2.abstracts.AbstractBBoxNode, n_fold: int = 5, k_for_test: Union[Sequence[int], int] = 0)[source]#

Split the node into several nodes according to the k-fold approach. This method creates nodes with test and train names. New nodes are attached as new groups.

Parameters
  • tree_path – node of the space model tree for the split

  • n_fold – number of folds

  • k_for_test – index or list of indexes that were attached as the test group

Returns

the root of the space model tree

nndt.space2.simple_api.split_node_namelist(tree_path: nndt.space2.abstracts.AbstractBBoxNode, dict_nodename_namelist: Dict[str, Sequence[str]])[source]#

Split node to several nodes according to the dictionary. New nodes are attached as new groups.

Parameters
  • tree_path – node of the space model tree for the split

  • dict_nodename_namelist – the key is a name for the new group. value is a list of children for the new group.

Returns

the root of the space model tree

nndt.space2.simple_api.split_node_test_train(rng_key: jax._src.prng.PRNGKeyArray, tree_path: nndt.space2.abstracts.AbstractBBoxNode, test_size: float = 0.3)[source]#

Split the node into two nodes according to the requested proportion. This method creates nodes with test and train names. New nodes are attached as new groups.

Parameters
  • rng_key – a key for JAX’s random generators

  • tree_path – node of the space model tree for the split

  • test_size – the size of the test subset. the value must range between 0 and 1.

Returns

the root of the space model tree

nndt.space2.simple_api.to_json(space: nndt.space2.space.Space)[source]#

Convert a space model tree to the JSON format

Parameters

space – the root of a space model tree

Returns

JSON as a string

nndt.space2.space module#

class nndt.space2.space.Space(name, bbox=((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), parent=None)[source]#

Bases: nndt.space2.abstracts.AbstractBBoxNode, nndt.space2.abstracts.IterAccessMixin

init()[source]#

Makes initialization for Space

preload(mode='identity', scale=50, keep_in_memory=True, ps_padding=(0.0, 0.0, 0.0), ns_padding=(0.0, 0.0, 0.0), verbose=True)[source]#

Makes preload for Space if it was not done. Otherwise does nothing

Parameters
  • mode (str, optional) – Mode. Defaults to “identity”.

  • scale (int, optional) – Scale. Defaults to 50.

  • keep_in_memory (bool, optional) – Keep in memory. Defaults to True.

save_space_to_file(filepath: str)[source]#

Writes Space in file

Parameters

filepath (str) – file name

to_json()[source]#

Converts Space to the JSON format

Returns

space in json format

Return type

json

nndt.space2.space_preloader module#

class nndt.space2.space_preloader.DefaultPreloader(mode='identity', scale=50, keep_in_memory=True, ps_padding=(0.0, 0.0, 0.0), ns_padding=(0.0, 0.0, 0.0))[source]#

Bases: object

preload(space: nndt.space2.space.Space, verbose=True)[source]#

nndt.space2.transformation module#

class nndt.space2.transformation.AbstractTransformation(name: str, bbox=((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), parent=None)[source]#

Bases: nndt.space2.abstracts.AbstractBBoxNode

abstract transform_sdt_ns2ps(sdt: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#
abstract transform_sdt_ps2ns(sdt: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#
abstract transform_xyz_ns2ps(xyz: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#
abstract transform_xyz_ps2ns(xyz: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#
class nndt.space2.transformation.IdentityTransform(ps_bbox: ((<class 'float'>, <class 'float'>, <class 'float'>), (<class 'float'>, <class 'float'>, <class 'float'>)), parent=None)[source]#

Bases: nndt.space2.transformation.AbstractTransformation

Transfer object of the physical space to normalized space without any changes.

Parameters
  • ps_bbox (tuple, optional) – boundary box in form ((X_min, Y_min, Z_min), (X_max, Y_max, Z_max)).

  • parent (_type_, optional) – parent node. Defaults to None.

transform_sdt_ns2ps(sdt: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#

Transforms signed distance tensor of normalized space to physical space.

Parameters

sdt (Union[onp.ndarray, jnp.ndarray]) – Signed distance tensor in normalized space.

Returns

Signed distance tensor in physical space.

Return type

Union[onp.ndarray, jnp.ndarray]

transform_sdt_ps2ns(sdt: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#

Transforms signed distance tensor of physical space to normalized space.

Parameters

sdt (Union[onp.ndarray, jnp.ndarray]) – Signed distance tensor in physical space.

Returns

Signed distance tensor in normalized space.

Return type

Union[onp.ndarray, jnp.ndarray]

transform_xyz_ns2ps(xyz: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#

Transforms xyz normalized space to physical space

Parameters

xyz (Union[onp.ndarray, jnp.ndarray]) – xyz in normalized space.

Returns

xyz in physical space.

Return type

Union[onp.ndarray, jnp.ndarray]

transform_xyz_ps2ns(xyz: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#

Transforms xyz physical space to normalized space

Parameters

xyz (Union[onp.ndarray, jnp.ndarray]) – xyz in physical space.

Returns

xyz in normalized space.

Return type

Union[onp.ndarray, jnp.ndarray]

class nndt.space2.transformation.ShiftAndScaleTransform(ps_bbox: ((<class 'float'>, <class 'float'>, <class 'float'>), (<class 'float'>, <class 'float'>, <class 'float'>)), ps_center: (<class 'float'>, <class 'float'>, <class 'float'>), ns_center: (<class 'float'>, <class 'float'>, <class 'float'>), scale_ps2ns: float, parent=None)[source]#

Bases: nndt.space2.transformation.AbstractTransformation

Transfer objects from a physical space to a normalized space using shift and scale transformation.

Parameters
  • ps_bbox (float, float, float) – boundary box in a form.

  • ps_center (float, float, float) – Physical space center.

  • ns_center (float, float, float) – Normalized space center.

  • scale_ps2ns (float) – Scale.

  • parent (_type_, optional) – parent node. Defaults to None.

transform_sdt_ns2ps(sdt: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#

Transforms signed distance tensor of normalized space to physical space.

Parameters

sdt (Union[onp.ndarray, jnp.ndarray]) – Signed distance tensor in normalized space.

Returns

Signed distance tensor in physical space.

Return type

Union[onp.ndarray, jnp.ndarray]

transform_sdt_ps2ns(sdt: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#

Transforms signed distance tensor of physical space to normalized space.

Parameters

sdt (Union[onp.ndarray, jnp.ndarray]) – Signed distance tensor in physical space.

Returns

Signed distance tensor in normalized space.

Return type

Union[onp.ndarray, jnp.ndarray]

transform_xyz_ns2ps(xyz: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#

Transforms xyz normalized space to physical space

Parameters

xyz (Union[onp.ndarray, jnp.ndarray]) – xyz in normalized space.

Returns

xyz in physical space.

Return type

Union[onp.ndarray, jnp.ndarray]

transform_xyz_ps2ns(xyz: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#

Transforms xyz physical space to normalized space

Parameters

xyz (Union[onp.ndarray, jnp.ndarray]) – xyz in physical space.

Returns

xyz in normalized space.

Return type

Union[onp.ndarray, jnp.ndarray]

class nndt.space2.transformation.ToNormalCubeTransform(ps_bbox: ((<class 'float'>, <class 'float'>, <class 'float'>), (<class 'float'>, <class 'float'>, <class 'float'>)), parent=None)[source]#

Bases: nndt.space2.transformation.AbstractTransformation

Transfer objects from a physical space to a normalized space. All objects are scaled to cubes with coordinates from -1 to 1. This approach is similar to NormalScaler in scikit-learn.

Parameters
  • ps_bbox (float, float, float) – boundary box in the form.

  • parent (_type_, optional) – parent node. Defaults to None.

transform_sdt_ns2ps(sdt: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#

Transforms signed distance tensor of normalized space to physical space.

Parameters

sdt (Union[onp.ndarray, jnp.ndarray]) – Signed distance tensor in normalized space.

Returns

Signed distance tensor in physical space.

Return type

Union[onp.ndarray, jnp.ndarray]

transform_sdt_ps2ns(sdt: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#

Transforms signed distance tensor of physical space to normalized space.

Parameters

sdt (Union[onp.ndarray, jnp.ndarray]) – Signed distance tensor in physical space.

Returns

Signed distance tensor in normalized space.

Return type

Union[onp.ndarray, jnp.ndarray]

transform_xyz_ns2ps(xyz: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#

Transforms xyz normalized space to physical space

Parameters

xyz (Union[onp.ndarray, jnp.ndarray]) – xyz in normalized space.

Returns

xyz in physical space.

Return type

Union[onp.ndarray, jnp.ndarray]

transform_xyz_ps2ns(xyz: Union[numpy.ndarray, jax.Array]) Union[numpy.ndarray, jax.Array][source]#

Transforms xyz physical space to normalized space

Parameters

xyz (Union[onp.ndarray, jnp.ndarray]) – xyz in physical space.

Returns

xyz in normalized space.

Return type

Union[onp.ndarray, jnp.ndarray]

nndt.space2.tree_utils module#

nndt.space2.tree_utils.update_bbox_from_children(node)[source]#

Update the boundary box size for the node according to the boundary box size of all children.

Parameters

node – Node to update.

nndt.space2.tree_utils.update_bbox_with_float_over_tree(node: anytree.node.nodemixin.NodeMixin)[source]#

Update box size for node. This method iterates over all parents and ancestors of the node and updates the boundary box according to the node boundary box.

Parameters

node (NodeMixin) – start node.

nndt.space2.utils module#

nndt.space2.utils.array_to_vert_and_faces(array: Union[jax.Array, numpy.ndarray], level: float = 0.0, for_vtk_cell_array: bool = False)[source]#
nndt.space2.utils.calc_ret_shape(array: Union[jax.Array, numpy.ndarray], last_axis: int)[source]#
nndt.space2.utils.fix_file_extension(path: str, ext: str)[source]#
nndt.space2.utils.pad_bbox(bbox1: ((<class 'float'>, <class 'float'>, <class 'float'>), (<class 'float'>, <class 'float'>, <class 'float'>)), pad: (<class 'float'>, <class 'float'>, <class 'float'>))[source]#

Expand the bbox of the tree node with padding

Parameters
  • bbox1 – bbox of some node in the space tree

  • pad – padding for the box

Returns

new bbox of the node

nndt.space2.utils.save_verts_and_faces_to_obj(filepath: str, verts, faces)[source]#
nndt.space2.utils.update_bbox(bbox1: ((<class 'float'>, <class 'float'>, <class 'float'>), (<class 'float'>, <class 'float'>, <class 'float'>)), bbox2: ((<class 'float'>, <class 'float'>, <class 'float'>), (<class 'float'>, <class 'float'>, <class 'float'>)))[source]#

Module contents#