mapteksdk.data.facets module¶
This module contains data types where the distinguishing trait is its use of facet primitives.
There is only one such data type at this time which is Surface.
- class mapteksdk.data.facets.Surface(object_id=None, lock_type=LockType.READWRITE)¶
Bases:
mapteksdk.data.primitives.point_properties.PointProperties
,mapteksdk.data.primitives.edge_properties.EdgeProperties
,mapteksdk.data.primitives.facet_properties.FacetProperties
,mapteksdk.data.base.Topology
Surfaces are represented by triangular facets defined by three points. This means a square or rectangle is represented by two facets, a cube is represented as twelve facets (six squares, each made of two facets). More complicated surfaces may require hundreds, thousands or more facets to be represented.
Defining a surface requires the points and the facets to be defined - the edges are automatically populated when the object is saved. A facet is a three element long list where each element is the index of a point, for example the facet [0, 1, 4] would indicate the facet is the triangle between points 0, 1 and 4.
Notes
The edges of a facet network are derived from the points and facets and cannot be directly set.
Examples
Creating a pyramid with a square base.
>>> from mapteksdk.project import Project >>> from mapteksdk.data import Surface >>> project = Project() >>> with project.new("surfaces/pyramid", Surface) as new_pyramid: >>> new_pyramid.points = [[0, 0, 0], [2, 0, 0], [2, 2, 0], >>> [0, 2, 0], [1, 1, 1]] >>> new_pyramid.facets = [[0, 1, 2], [0, 2, 3], [0, 1, 4], [1, 2, 4], >>> [2, 3, 4], [3, 0, 4]]
- classmethod static_type()¶
Return the type of surface as stored in a Project.
This can be used for determining if the type of an object is a surface.
- associate_raster(raster, registration, desired_index=1)¶
Associates a raster to the surface using the passed RasterRegistration object to define how the raster pixels are draped onto the surface.
This edits both the surface and the raster so both objects must be open for read/write to call this function.
- Parameters
raster (Raster) – An open raster to associate with the surface.
registration (RasterRegistration) – Registration object to use to associate the raster with the surface. This will be assigned to the raster’s registration property.
desired_index (int) – The desired raster index for the raster. Rasters with higher indices appear on top of rasters with lower indices. This is 1 by default.
- Returns
The raster index of the associated raster. If the raster is already associated with the object this will be the index given when it was first associated.
- Return type
int
- Raises
ValueError – If the registration object is invalid.
ReadOnlyError – If the raster or the surface are open for read-only.
RuntimeError – If the raster could not be associated with the surface.
TypeError – If raster is not a Raster object.
Examples
This example shows creating a simple square-shaped surface and associates a raster displaying cyan and white horizontal stripes to cover the surface. In particular note that the call to this function is inside both the with statements for creating the surface and creating the raster. And as the raster is immediately associated with an object there is no need to provide a path for it.
>>> import numpy as np >>> from mapteksdk.project import Project >>> from mapteksdk.data import Surface, Raster, RasterRegistrationTwoPoint >>> project = Project() >>> with project.new(f"surfaces/simple-rows", Surface) as new_surface: ... new_surface.points = [[-10, -10, 0], [10, -10, 0], ... [-10, 10, 0], [10, 10, 0]] ... new_surface.facets = [[0, 1, 2], [1, 2, 3]] ... new_surface.facet_colours = [[200, 200, 0], [25, 25, 25]] ... with project.new(None, Raster(width=32, height=32 ... )) as new_raster: ... new_raster.pixels = np.full((new_raster.pixel_count, 4), ... 255, np.uint8) ... new_raster.pixels_2d[::2] = [0, 255, 255, 255] ... registration = RasterRegistrationTwoPoint() ... registration.image_points = [[0, 0], [new_raster.width, ... new_raster.height]] ... registration.world_points = [[-10, -10, 0], [10, 10, 0]] ... registration.orientation = [0, 0, 1] ... new_surface.associate_raster_two_point(new_raster, registration)
- save()¶
Saves the changes to the point primitives. This is called during save() of the inheriting object and should not be called manually.
- Returns
True if successful.
- Return type
bool
- Raises
Exception – If in read-only mode.