mapteksdk.data.primitives.block_properties module

Module containing the BlockProperties Mixin class which provides support for block primitives.

class mapteksdk.data.primitives.block_properties.BlockProperties

Bases: object

A mixin class used by spatial objects to provide 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] which is 2 units by 4 units by 8 units.

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.

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).

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).

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).

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
property orientation

The rotation of the block model representing as Vulcan-style dip, plunge and bearing. This will return the tuple: (dip, plunge, bearing)

The returned values are in radians.

Notes

This is a derived property. It is recalculated each time this is called.

rotate(angle, axis)

Rotates the block model by the specified angle around the specified axis.

Parameters
  • angle (float) – The angle to rotate by in radians.

  • axis (Axis) – The axis to rotate by.

Examples

Create a 2x2x2 dense block model which is rotated by pi / 4 radians (45 degrees) around the X axis.

>>> import math
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel, Axis
>>> project = Project()
>>> with project.new("blockmodels/dense_rotated", DenseBlockModel(
...         x_res=1, y_res=1, z_res=1,
...         x_count=2, y_count=2, z_count=3)) as new_model:
...     new_model.rotate(math.pi / 4, Axis.X)

If you want to specify the angle in degrees instead of radians, use the math.radians function. Additionally rotate can be called multiple times to rotate the block model in multiple axes. Both of these are shown in the below example. The resulting block model is rotated 32 degrees around the Y axis and 97 degrees around the Z axis.

>>> import math
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel, Axis
>>> project = Project()
>>> with project.new("blockmodels/dense_rotated_degrees", DenseBlockModel(
...         x_res=1, y_res=1, z_res=1,
...         x_count=2, y_count=2, z_count=3)) as new_model:
...     new_model.rotate(math.radians(32), Axis.Y)
...     new_model.rotate(math.radians(97), Axis.Z)
rotate_2d(angle)

Rotates the block model in two dimensions. This is equivalent to rotate with axis=Axis.Z

Parameters

angle (float) – The angle to rotate by in radians.

set_rotation(angle, axis)

Overwrites the existing rotation with a rotation around the specified axis by the specified angle.

This is useful for resetting the rotation to a known point.

Parameters
  • angle (float) – Angle to set the rotation to in radians.

  • axis (Axis) – Axis to rotate around.

set_rotation_2d(angle)

Overwrite the existing rotation with a simple 2d rotation.

Parameters

angle (float) – Angle to set the rotation to in radians.

set_orientation(dip, plunge, bearing)

Overwrite the existing rotation with a rotation defined by the specified dip, plunge and bearing.

An orientation of (dip, plunge, bearing) radians is equivalent to rotating the model -dip radians around the X axis, -plunge radians around the Y axis and -(bearing - pi / 2) radians around the Z axis.

Parameters
  • dip (float) – Relative rotation of the Y axis around the X axis in radians. This should be between -pi and pi (inclusive).

  • plunge (float) – Relative rotation of the X axis around the Y axis in radians. This should be between -pi / 2 and pi / 2 (exclusive).

  • bearing (float) – Absolute bearing of the X axis around the Z axis in radians. This should be between -pi and pi (inclusive).

Raises

TypeError – If dip, plunge or bearing are not numbers.

Examples

Set orientation of a new 3x3x3 block model to be plunge = 45 degrees, dip = 30 degrees and bearing = -50 degrees

>>> import math
>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel
>>> project = Project()
>>> with project.new("blockmodels/model_1", DenseBlockModel(
...         x_res=1, y_res=1, z_res=1,
...         x_count=3, y_count=3, z_count=3)) as new_model:
>>>     new_model.set_orientation(math.radians(45),
...                               math.radians(30),
...                               math.radians(-50))

Copy the rotation from one block model to another. Requires two block models.

>>> from mapteksdk.project import Project
>>> from mapteksdk.data import DenseBlockModel
>>> project = Project()
>>> with project.edit("blockmodels/model_1") as model_1:
...     with project.edit("blockmodels/model_2") as model_2:
...         model_2.set_orientation(*model_1.orientation)
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()

Saves block primitives within inheriting object. This should be called during the save of an inheriting object. This function should not be called directly.

Raises

Exception – If in read-only mode.

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