xmsstamper is a library used to generate "feature stamps". Feature stamps refer to the insertion of man-made structures into a natural topography or bathymetry set. In common terms, this means adding an embankment (such as a levy) or dredging a channel. A stamped feature usually a linear object or centerline. More information on feature stamping can be found here https://xmswiki.com/wiki/SMS:Feature_Stamping.
The basic workflow is to first define the land surface or bathymetry as a TIN (triangular surface). Then define a feature stamp consisting of a center line, cross sections along the center line, and end caps. The feature stamp is used to generate a new TIN that is cut off by the land surface or bathemetry.
This example will show how to use the classes in the library with very simple examples.
import numpy as np
import holoviews as hv
from shapely.geometry import Polygon
from holoviews.streams import Params
import hvplot.pandas
import hvplot.xarray
import xmsmesh
import xmsstamper
import xmsinterp
import xmsgrid
import ugrid_tools
hv.extension('bokeh')
# define a tin, used later
surface_pts = [(-5,-15,9.5), (-5,45,9.5), (70, 45,9.5), (70,-15,9.5)]
tin = xmsinterp.triangulate.Tin(pts=surface_pts)
tin.triangulate()
x = [x[0] for x in tin.pts]
y = [y[1] for y in tin.pts]
z = [z[2] for z in tin.pts]
nodes = np.column_stack([x, y, z])
nodes = hv.Points(nodes, vdims=['z'])
stamp_type = "fill"
centerline = [
(0.0, 0.0, 10.0),
(10.0, 0.0, 10.0),
]
# symetric cross section, left and right are equal
left = right = [(0, 10.0), (2.0, 10.0), (3.0, 9.5)]
index_left_shoulder = index_right_shoulder = 1
left_max = right_max = 5.0
cs = xmsstamper.stamper.StampCrossSection(
left=left,
right=right,
index_left_shoulder=index_left_shoulder,
index_right_shoulder=index_right_shoulder,
left_max=left_max,
right_max=right_max,
)
cs_list = [cs] * len(centerline)
stamp_io = xmsstamper.stamper.StamperIo(
stamping_type=stamp_type,
centerline=centerline,
cs=cs_list,
)
xmsstamper.stamper.stamper.stamp(stamp_io)
out_tin = stamp_io.get_out_tin()
# draw the output TIN
tris = [x for x in zip(*[iter(out_tin.tris)] * 3)]
x, y, z = zip(*out_tin.pts)
stamp_nodes = np.column_stack([x, y, z])
stamp_nodes = hv.Points(stamp_nodes, vdims='z')
trimesh = hv.TriMesh((tris, stamp_nodes))
nodes * stamp_nodes * trimesh.opts(
hv.opts.TriMesh(filled=True, colorbar=True, cmap='viridis', edge_color='z', edge_alpha=0.4, node_size=3)
)
centerline.append((50, 0, 10))
left = right = [(0, 10.0), (4.0, 10.0), (3.0, 9.0)]
index_left_shoulder = index_right_shoulder = 1
left_max = right_max = 10.0
cs = xmsstamper.stamper.StampCrossSection(
left=left,
right=right,
index_left_shoulder=index_left_shoulder,
index_right_shoulder=index_right_shoulder,
left_max=left_max,
right_max=right_max,
)
cs_list.append(cs)
stamp_io = xmsstamper.stamper.StamperIo(
stamping_type=stamp_type,
centerline=centerline,
cs=cs_list,
)
xmsstamper.stamper.stamper.stamp(stamp_io)
out_tin = stamp_io.get_out_tin()
# draw the output TIN
tris = [x for x in zip(*[iter(out_tin.tris)] * 3)]
x, y, z = zip(*out_tin.pts)
stamp_nodes = np.column_stack([x, y, z])
stamp_nodes = hv.Points(stamp_nodes, vdims='z')
trimesh = hv.TriMesh((tris, stamp_nodes))
nodes * stamp_nodes * trimesh.opts(
hv.opts.TriMesh(filled=True, colorbar=True, cmap='viridis', edge_color='z', edge_alpha=0.4, node_size=3)
)
wing_wall = xmsstamper.stamper.WingWall(wing_wall_angle = -30)
first_end_cap = xmsstamper.stamper.StamperEndCap(wing_wall=wing_wall)
stamp_io = xmsstamper.stamper.StamperIo(
stamping_type=stamp_type,
centerline=centerline,
cs=cs_list,
first_end_cap=first_end_cap,
)
xmsstamper.stamper.stamper.stamp(stamp_io)
out_tin = stamp_io.get_out_tin()
# draw the output TIN
tris = [x for x in zip(*[iter(out_tin.tris)] * 3)]
x, y, z = zip(*out_tin.pts)
stamp_nodes = np.column_stack([x, y, z])
stamp_nodes = hv.Points(stamp_nodes, vdims='z')
trimesh = hv.TriMesh((tris, stamp_nodes))
nodes * stamp_nodes * trimesh.opts(
hv.opts.TriMesh(filled=True, colorbar=True, cmap='viridis', edge_color='z', edge_alpha=0.4, node_size=3)
)
guidebank = xmsstamper.stamper.Guidebank(n_pts=10, radius1=30, radius2=20, side=0, width=4)
last_end_cap = xmsstamper.stamper.StamperEndCap(guidebank=guidebank)
stamp_io = xmsstamper.stamper.StamperIo(
stamping_type=stamp_type,
centerline=centerline,
cs=cs_list,
first_end_cap=first_end_cap,
last_end_cap=last_end_cap
)
xmsstamper.stamper.stamper.stamp(stamp_io)
out_tin = stamp_io.get_out_tin()
# draw the output TIN
tris = [x for x in zip(*[iter(out_tin.tris)] * 3)]
x, y, z = zip(*out_tin.pts)
stamp_nodes = np.column_stack([x, y, z])
stamp_nodes = hv.Points(stamp_nodes, vdims='z')
trimesh = hv.TriMesh((tris, stamp_nodes))
nodes * stamp_nodes * trimesh.opts(
hv.opts.TriMesh(filled=True, colorbar=True, cmap='viridis', edge_color='z', edge_alpha=0.4, node_size=3)
)
stamp_io = xmsstamper.stamper.StamperIo(
stamping_type=stamp_type,
centerline=centerline,
cs=cs_list,
first_end_cap=first_end_cap,
last_end_cap=last_end_cap,
bathymetry=tin,
)
xmsstamper.stamper.stamper.stamp(stamp_io)
out_tin = stamp_io.get_out_tin()
# draw the output TIN
tris = [x for x in zip(*[iter(out_tin.tris)] * 3)]
x, y, z = zip(*out_tin.pts)
stamp_nodes = np.column_stack([x, y, z])
stamp_nodes = hv.Points(stamp_nodes, vdims='z')
trimesh = hv.TriMesh((tris, stamp_nodes))
nodes *stamp_nodes * trimesh.opts(
hv.opts.TriMesh(filled=True, colorbar=True, cmap='viridis', edge_color='z', edge_alpha=0.4, node_size=3)
)