aerocaps.geom.geometry_container.GeometryContainer#

class GeometryContainer[source]#

Bases: object

Storage container for geometric objects that adds convenience methods for plotting and export

__init__()[source]#

Storage container for geometric objects that adds convenience methods for plotting and export. The example code below shows how to add a curve and a surface to a new container, plots them in an interactive scene, exports them to IGES, and then removes both of them by varying identifiers:

# Create the geometric objects
curve = BezierCurve3D(np.array([
    [0.0, 0.0, 0.0],
    [0.3, 0.2, 0.1],
    [0.6, 0.1, 0.3],
    [1.0, -0.1, 0.2]
]), name='MyCurve')
surf = BezierSurface(np.array([
    [
        [0.0, 0.0, 0.0],
        [0.3, 0.2, 0.1],
        [0.6, 0.1, 0.3],
        [1.0, -0.1, 0.2]
    ],
    [
        [0.0, 0.0, 1.0],
        [0.3, 0.4, 1.1],
        [0.6, 0.2, 1.3],
        [1.0, -0.3, 1.2]
    ]
]))

# Instantiate a container
container = GeometryContainer()

# Add the geometries to the container
container.add_geometry(point)
container.add_geometry(curve)

# List the geometries inside the container
geom_names = container.geometry_name_list()
print(f'{geom_names = }')

# Plot the geometries in an interactive scene
container.plot()

# Export the geometries to an IGES file
container.export_iges('curve_and_surf.igs', units='meters')

# Remove the curve and surface by different methods
container.remove_geometry('MyCurve')
container.remove_geometry(surf)

# Show that the container is now empty
geom_names = container.geometry_name_list()
print(f'{geom_names = }')

Methods

add_geometry(geom)

Adds a geometric object to the container, renaming the object with a higher index if necessary

export_iges(file_name[, units])

Exports all the exportable objects in the container to an IGES file

export_stl(file_name[, Nu, Nv])

Exports all the exportable objects in the container to an STL file

geometry_by_name(name)

Searches for a geometry in the container by name

geometry_name_list([geom_type])

Gets the list of geometries (by name) that have been added to the container

plot([show, Nu, Nv, Nt, surface_selection, ...])

Plots all the plottable objects in the container onto a pyvista.Plotter scene.

remove_geometry(geom)

Removes a geometric object from the container

add_geometry(geom: Geometry)[source]#

Adds a geometric object to the container, renaming the object with a higher index if necessary

Parameters:

geom (Geometry) – Geometric object to add

export_iges(file_name: str, units: str = 'meters')[source]#

Exports all the exportable objects in the container to an IGES file

Parameters:
export_stl(file_name: str, Nu: int = 50, Nv: int = 50)[source]#

Exports all the exportable objects in the container to an STL file

Parameters:
  • file_name (str) – Path to the STL file

  • Nu (int) – Number of points to evaluate in the \(u\)-parametric direction

  • Nv (int) – Number of points to evaluate in the \(v\)-parametric direction

geometry_by_name(name: str) Geometry[source]#

Searches for a geometry in the container by name

Parameters:

name (str) – Name of the geometric object

Returns:

If found, a geometric object is returned. Otherwise, None is returned

Return type:

Geometry or None

geometry_name_list(geom_type: type = None) List[str][source]#

Gets the list of geometries (by name) that have been added to the container

Parameters:

geom_type (type) – If specified, only geometries with the given type will be returned. Default: None

Returns:

List of geometry names

Return type:

List[str]

plot(show: bool = True, Nu: int = 50, Nv: int = 50, Nt: int = 50, surface_selection: bool = True, random_colors: bool = False, color_seed: int = 42)[source]#

Plots all the plottable objects in the container onto a pyvista.Plotter scene. Also adds a surface picker to dynamically show surface information on right-click.

Parameters:
  • show (bool) – Whether to show the plot. Default: True

  • Nu (int) – The number of points in the \(u\)-direction of each surface to evaluate. Default: 50

  • Nv (int) – The number of points in the \(u\)-direction of each surface to evaluate. Default: 50

  • Nt (int) – The number of points to evaluate along each curve for a trimmed surface evaluation. Default: 50

  • surface_selection (bool) – Whether to allow interactive selection of surfaces. Default: True

  • random_colors (bool) – Whether to paint each surface with a random color. Default: False

  • color_seed (int) – The random number seed used to generate the random colors. Ignored if random_colors==False. Default: 42

remove_geometry(geom: str) Geometry[source]#

Removes a geometric object from the container

Parameters:

geom (str or Geometry) – The geometry to remove. If a str, this must be found in the list of geometry names that have already been added to the container or an exception will be thrown

Returns:

The geometry removed

Return type:

Geometry