• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SciKit-Surgery / scikit-surgeryvtk / 4323596638

pending completion
4323596638

push

github-actions

Miguel Xochicale
refactors unit tests skipif messages (#187)

332 of 1997 relevant lines covered (16.62%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

12.9
/sksurgeryvtk/utils/polydata_utils.py
1
# -*- coding: utf-8 -*-
2

3

4
"""
4✔
5
Utilities for operations on vtk polydata
6
"""
7

8
from vtk import vtkMassProperties, vtkBooleanOperationPolyDataFilter
4✔
9

10
def check_overlapping_bounds(polydata_0, polydata_1):
4✔
11
    """
12
    Checks whether two polydata have overlapping bounds
13

14
    :param polydata_0: vtkPolyData representing a 3D mesh
15
    :param polydata_1: vtkPolyData representing a 3D mesh
16

17
    :return : True if bounding boxes overlap, False otherwise
18
    """
19

20
    bounds_0 = polydata_0.GetBounds()
×
21
    bounds_1 = polydata_1.GetBounds()
×
22
    overlapping = True
×
23
    for i in range(0, 3):
×
24
        #This assumes that GetBounds always returns lower, upper
25
        if bounds_0[i*2] > bounds_1[i*2+1]:
×
26
            overlapping = False
×
27
        else:
28
            if bounds_1[i*2] > bounds_0[i*2+1]:
×
29
                overlapping = False
×
30

31
    return overlapping
×
32

33

34
def two_polydata_dice(polydata_0, polydata_1):
4✔
35
    """
36
    Calculates the DICE score for two polydata.
37
    Will probably struggle with complex topologies,
38
    but should be fine for vaguely spherical shape.
39
    This function uses vtk.vtkMassProperties() so does not
40
    convert polydata to image data
41

42
    :param polydata_0: vtkPolyData representing a 3D mesh
43
    :param polydata_1: vtkPolyData representing a 3D mesh
44

45
    :return dice: The DICE score
46
    :return volume_0: The enclosed volume of polydata_0
47
    :return volume_1: The enclosed volume of polydata_1
48
    :return volume_01: The enclosed volume of the intersection
49
    """
50
    measured_polydata = vtkMassProperties()
×
51
    measured_polydata.SetInputData(polydata_0)
×
52
    volume_0 = measured_polydata.GetVolume()
×
53

54
    measured_polydata.SetInputData(polydata_1)
×
55
    volume_1 = measured_polydata.GetVolume()
×
56

57
    intersector = vtkBooleanOperationPolyDataFilter()
×
58
    intersector.SetOperationToIntersection()
×
59

60
    intersector.SetInputData(0, polydata_0)
×
61
    intersector.SetInputData(1, polydata_1)
×
62

63
    if check_overlapping_bounds(polydata_0, polydata_1):
×
64
        intersector.Update()
×
65
        intersection = intersector.GetOutput()
×
66
        measured_polydata.SetInputData(intersection)
×
67
        volume_01 = measured_polydata.GetVolume()
×
68
    else:
69
        volume_01 = 0.0
×
70
        dice = 0.0
×
71

72
    dice = 2 *  volume_01 / (volume_0 + volume_1)
×
73
    return dice, volume_0, volume_1, volume_01
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc