mapteksdk.data.primitives.block_properties module

Support for block primitives.

Block primitives are three dimensional cubes or rectangular prisms defined by a centroid and a block size. Given a block with centroid [0, 0, 0] and size [2, 4, 8] then the block will be the rectangular prism centred at [0, 0, 0] and 2 metres by 4 metres by 8 metres in size.

class BlockProperties

Bases: object

Mixin class which provides spatial object support for block primitives.

Functions and properties defined on this class are available on all classes which support blocks.

property block_count

The count of blocks in the model.

property block_resolution

The resolution of the block model.

This is the x_res, y_res and z_res values used when creating the model in an array. Once the block model has been created, these values cannot be changed.

property block_centroids

The centroids of the blocks. This is represented as an ndarray of shape (block_count, 3) of the form: [[x1, y1, z1], [x2, y2, z2], …, [xN, yN, zN]] Where N is the block_count.

property block_sizes

The block sizes represented as an ndarray of shape (block_count, 3). Each row represents the size of one block in the form [x, y, z] where x, y and z are positive numbers.

This means that the extent for the block with index i is calculated as: (block_centroids[i] - block_sizes[i] / 2, block_centroids[i] + block_sizes[i] / 2)

Notes

For DenseBlockModels, all block_sizes are the same.

property block_colours

The colour of the blocks, represented as a ndarray of shape (block_count, 4) with each row i representing the colour of the ith block in the model in the form [Red, Green, Blue, Alpha].

When setting block colours, you may omit the Alpha component.

property slice_count

The number of slices in the underlying block model.

This can be thought of as the number of blocks in the Z direction (assuming no rotation is made). This can only be set by the block model’s constructor.

property row_count

The number of rows in the underlying block model.

This can be thought of as the number of blocks in the Y direction (assuming no rotation is made). This can only be set by the block model’s constructor.

property column_count

The number of columns in the underlying block model.

This can be thought of as the number of blocks in the X direction (assuming no rotation is made). This can only be set by the block model’s constructor.

property block_selection

The block selection represented as an ndarray of bools with shape: (block_count,). True indicates the block is selected; False indicates it is not selected.

Notes

In mapteksdk version 1.0, block_selection returned a 3D ndarray. To get the same functionality, see block_selection_3d property of dense block models.

property block_visibility

The block visibility represented as an ndarray of bools with shape: (block_count,). True indicates the block is visible, False indicates it is not visible.

Notes

In mapteksdk version 1.0 block_visibility returned a 3D ndarray. To get the same functionality, see block_visibility_3d property of dense block models.

property origin

The origin of the block model represented as a point.

Setting the origin will translate the entire block model to be centred around the new origin.

Notes

For DenseBlockModels the resulting changes to the block_centroids will not occur until save is called. For SubblockedBlockModels the resulting changes to the block_centroids are immediately available, however changing the origin of such a model is slower.

Examples

Changing the origin will change the block model centroids, in this case by translating them by 1 unit in the X direction, 2 units in the Y direction and 3 units in the Z direction. Note that as this is a DenseBlockModel, the model needs to be saved (in this case via closing ending the with block) before the changes to the centroids will occur.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel
>>> project = Project()
>>> with project.new("blockmodels/model", DenseBlockModel(
...         x_res=2, y_res=3, z_res=4,
...         x_count=2, y_count=2, z_count=2)) as new_model:
...     new_model.origin = [1, 2, 3]
>>> with project.edit("blockmodels/model") as edit_model:
...     print(edit_model.block_centroids)
[[1, 2, 3], [3, 2, 3], [1, 5, 3], [3, 5, 3], [1, 2, 7], [3, 2, 7],
[1, 5, 7], [3, 5, 7]]
property block_to_grid_index

An ndarray containing the mapping of the blocks to the row, column and slice their centroid lies within. This has shape (N, 3) where N is the block_count and each item is of the form [column, row, slice].

This means that the column, row and slice of the block centred at block_centroids[i] is block_to_grid_index[i].

For DenseBlockModels, there is only one block per grid cell and thus each item of the block_to_grid_index will be unique.

grid_index(start, stop=None)

Generates a boolean index for accessing block properties by row, column and slice instead of by block. The boolean index will include all subblocks between primary block start (inclusive) and primary block stop (exclusive), or all subblocks within primary block start if stop is not specified.

Parameters
  • start (array_like or int) – An array_like containing three elements - [column, row, slice]. The returned boolean index will include all blocks in a greater column, row and slice. If this is an integer, that integer is interpreted as the column, row and slice.

  • end (array_like or int) – An array_like containing three elements - [column, row, slice]. If None (Default) this is start + 1 (The resulting index will contain all blocks within primary block start). If not None, the boolean index will include all blocks between start (inclusive) and end (exclusive). If this is an integer, that integer is interpreted as the column, row and slice index.

Returns

A boolean index into the block property arrays. This is an array of booleans of shape (block_count,). If element i is True then subblock i is within the range specified by start and stop. If False it is not within that range.

Return type

ndarray

Raises
  • TypeError – If start or stop are invalid types.

  • ValueError – If start or stop are incorrect shapes.

Examples

These examples require a block model to be at “blockmodels/target”

This example selects all subblocks within the primary block in column 0, row 0 and slice 0:

>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.edit("blockmodels/target") as edit_model:
...     index = edit_model.grid_index([0, 0, 0])
...     edit_model.block_selection[index] = True

By passing two values to grid index, it is possible to operate on all subblocks within a range of subblocks. This example passes [0, 2, 2] and [4, 5, 6] meaning all subblocks which have 0 <= column < 4 and 2 <= row < 5 and 2 <= slice < 6 will be selected by grid_index. By passing this index to block visibility, all subblocks within those primary blocks are made invisible.

>>> from mapteksdk.project import Project
>>> project = Project()
>>> with project.edit("blockmodels/target") as edit_model:
...     index = edit_model.grid_index([0, 2, 2], [4, 5, 6])
...     edit_model.block_visibility[index] = False
convert_to_block_coordinates(world_coordinates)

Converts points in world coordinates to points in block coordinates.

The block coordinate system for a particular model is defined such that [0, 0, 0] is the centre of the block in row 0, column 0 and slice 0. The X axis is aligned with the columns, the Y axis is aligned with the rows and the Z axis is aligned with the slices of the model. This makes the centre of the primary block in column i, row j and slice k to be: [x_res * i, y_res * j, z_res * k].

This function performs no error checking that the points lies within the model.

Parameters

world_coordinates (array_like) – Points in world coordinates to convert to block coordinates.

Returns

Numpy array containing world_coordinates converted to be in block_coordinates.

Return type

numpy.ndarray

Raises

ValueError – If world_coordinates has an invalid shape.

Notes

If a block model has origin = [0, 0, 0] and has not been rotated, then the block and world coordinate systems are identical.

Block models of differing size, origin or rotation will have different block coordinate systems.

convert_to_world_coordinates(block_coordinates)

Converts points in block coordinates to points in world coordinates.

This is the inverse of the transformation performed by convert_to_block_coordinates.

Parameters

block_coordinates (array_like) – Points in block coordinates to convert to world coordinates.

Returns

Numpy array containing block_coordinates converted to world_coordinates.

Return type

numpy.ndarray

Raises

ValueError – If block_coordinates has an invalid shape.

Notes

Block models of differing size, origin or rotation will have different block coordinate systems.

save_block_attribute(attribute_name, data)

Create a new block attribute with the specified name and associate the specified data.

Parameters
  • attribute_name (str) – The name of attribute.

  • data (array_like) – Data for the associated attribute. This should be a ndarray of shape (block_count,). The ith entry in this array is the value of this primitive attribute for the ith block.

Raises
  • Exception – If the object is opened in read-only mode.

  • ValueError – If the type of the attribute is not supported.

delete_block_attribute(attribute_name)

Delete a block attribute.

Parameters

attribute_name (str) – The name of attribute to delete.

Raises

Exception – If the object is opened in read-only mode.

property block_attributes

Access block attributes.

block_model.block_attributes[“Blocktastic”] will return the block attribute called “Blocktastic”.

Returns

Access to the block attributes.

Return type

PrimitiveAttributes