Calculate boundary index
Full example code: examples/meshtools/extract_boundary.py
After obtaining the coords, triangles and scalars of our surface mesh using the parser module, we can call the BoundaryFilter to extract the nodes on each border.
Using the default orientation of a CARTO export, we can automatically label the MV, LPV and RPV. Of course, they need to be cut out of the mesh in the first place else we won't have any boundaries to detect.
# Set boundaries
boundaries = BoundaryFilter.get_boundaries(coords, triangles, scalars)
BoundaryFilter.label(boundaries, "carto")
We now extend our boundaries slightly to get rid of faulty points near the boundary. Next we reduce the number of points and average all points into sections around the boundary. By default, 12 sections are used. You can look at them like supernodes - the average of all nodes in the section - around the boundary.
for bnd in boundaries:
(bnd
.extend(coords, triangles, scalars, distance=6)
.reduce(distance=0.92)
.build_sections(period=period) # Cycle length to have continuous connections
.calc_index(period) # Set index
)
To visualize, we can extract the arrows and labels of each boundary. Arrows are coloured in blue for clockwise and counterclockwise. A neutral connection (unable to determine direction) will be gray.
mesh = SurfaceBuilder(coords, triangles).set_scale(0.95)
arrows, labels = [], []
for bnd in boundaries:
arrows.extend(bnd.get_arrows_object())
labels.append(bnd.get_label_object())
# Add objects to the plot
plot = Plot(640, 480)
plot.renderer.add_object(mesh)
plot.renderer.add_objects(labels)
plot.renderer.add_objects(arrows)
plot.start()
