Skip to content

Commit

Permalink
Merge pull request #127 from KVSlab/refactor-aneu-tools
Browse files Browse the repository at this point in the history
Rename ToolRepairSTL
  • Loading branch information
hkjeldsberg authored Oct 25, 2023
2 parents 2839153 + 7743277 commit 7f6c1b8
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 265 deletions.
4 changes: 2 additions & 2 deletions src/vampy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .automatedPreprocessing import DisplayData
from .automatedPreprocessing import ImportData
from .automatedPreprocessing import NetworkBoundaryConditions
from .automatedPreprocessing import ToolRepairSTL
from .automatedPreprocessing import repair_tools
from .automatedPreprocessing import automated_preprocessing
from .automatedPreprocessing import preprocessing_common
from .automatedPreprocessing import simulate
Expand Down Expand Up @@ -55,7 +55,7 @@
"ImportData",
"NetworkBoundaryConditions",
"simulate",
"ToolRepairSTL",
"repair_tools",
"visualize",
"vmtk_pointselector",
"Artery",
Expand Down
257 changes: 0 additions & 257 deletions src/vampy/automatedPreprocessing/ToolRepairSTL.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/vampy/automatedPreprocessing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
from . import ImportData
from . import NetworkBoundaryConditions
from . import simulate
from . import ToolRepairSTL
from . import repair_tools
from . import visualize
from . import vmtk_pointselector
10 changes: 5 additions & 5 deletions src/vampy/automatedPreprocessing/automated_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
prepare_output_surface, vmtk_compute_geometric_features

# Local imports
from vampy.automatedPreprocessing import ToolRepairSTL
from vampy.automatedPreprocessing.moving_common import get_point_map, project_displacement, save_displacement
from vampy.automatedPreprocessing.preprocessing_common import read_polydata, get_centers_for_meshing, \
dist_sphere_diam, dist_sphere_curvature, dist_sphere_constant, get_regions_to_refine, add_flow_extension, \
write_mesh, mesh_alternative, generate_mesh, find_boundaries, compute_flow_rate, setup_model_network, \
radiusArrayName, scale_surface, get_furtest_surface_point, check_if_closed_surface, remesh_surface
from vampy.automatedPreprocessing.repair_tools import find_and_delete_nan_triangles, clean_surface, print_surface_info
from vampy.automatedPreprocessing.simulate import run_simulation
from vampy.automatedPreprocessing.visualize import visualize_model

Expand Down Expand Up @@ -121,10 +121,10 @@ def run_pre_processing(input_model, verbose_print, smoothing_method, smoothing_f
surface = vtk_triangulate_surface(surface)

# Check the mesh if there is redundant nodes or NaN triangles.
ToolRepairSTL.surfaceOverview(surface)
ToolRepairSTL.foundAndDeleteNaNTriangles(surface)
surface = ToolRepairSTL.cleanTheSurface(surface)
foundNaN = ToolRepairSTL.foundAndDeleteNaNTriangles(surface)
print_surface_info(surface)
find_and_delete_nan_triangles(surface)
surface = clean_surface(surface)
foundNaN = find_and_delete_nan_triangles(surface)
if foundNaN:
raise RuntimeError(("There is an issue with the surface. "
"Nan coordinates or some other shenanigans."))
Expand Down
80 changes: 80 additions & 0 deletions src/vampy/automatedPreprocessing/repair_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python

# Program: AneuTool
# Module: ToolRepairSTL.py
# Language: Python
# Date: $Date: 2016/17/04 00:00:00 $
# Version: $Revision: 0.0.1 $
# Author: Christophe Chnafa

# Copyright (c) Christophe Chnafa. All rights reserved.

import vtk


def is_nan(num):
return num != num


def print_surface_info(surface):
nTriangles = surface.GetNumberOfCells()
nPoints = surface.GetNumberOfPoints()
print("> --- Surface overview:")
print(("> Total number of triangles: %s." % nTriangles))
print(("> Total number of points: %s." % nPoints))
print(">")


def find_and_delete_nan_triangles(surface):
ctrNaN = 0
foundNaN = False
nTriangles = surface.GetNumberOfCells()
print("> --- Check the surface.")
# The links from points to cells need to be build.
surface.BuildLinks()
for i in range(0, nTriangles):
killThisTriangle = False
nPointsForThisCell = surface.GetCell(i).GetPoints().GetNumberOfPoints()
if nPointsForThisCell > 3:
print("> WARNING: found Cell with more than 3 points: there is more than triangles.")
for j in range(0, nPointsForThisCell):
x = [0.0, 0.0, 0.0]
surface.GetCell(i).GetPoints().GetPoint(j, x)
if is_nan(x[0]) | is_nan(x[1]) | is_nan(x[2]):
ctrNaN += 1
killThisTriangle = True
if killThisTriangle:
surface.DeleteCell(i)
surface.RemoveDeletedCells()
print(("> Found %s NaN cells." % ctrNaN))
print(">")
if ctrNaN > 0:
foundNaN = True

return foundNaN


def clean_surface(surface):
print("> --- Cleaning the surface.")
cleanPolyData = vtk.vtkCleanPolyData()
if vtk.VTK_MAJOR_VERSION <= 5:
cleanPolyData.SetInput(surface)
else:
cleanPolyData.SetInputData(surface)
cleanPolyData.PointMergingOff() # point locator will not be used, and points
# that are not used by any cells will be eliminated,
# but never merged.

# In VTK the tolerance is defined as a fraction
# of the bounding box length.
tol = 0.0 # 0.0005
cleanPolyData.SetTolerance(tol)
cleanPolyData.Update()

cleanPolyData.Update()
outputPolyData = cleanPolyData.GetOutput()

print("> Done.")
print("> ")

return (outputPolyData)

0 comments on commit 7f6c1b8

Please sign in to comment.