Commit ff18a9fcbf823c6e4a5c3700b1c6cc6619110645

Authored by Paulo Henrique Junqueira Amorim
1 parent 9078f46d

ENH: Add progress in select of surface parts

Showing 1 changed file with 25 additions and 11 deletions   Show diff stats
invesalius/data/polydata_utils.py
... ... @@ -27,7 +27,7 @@ UpdateProgress = vu.ShowProgress()
27 27  
28 28 def ApplyDecimationFilter(polydata, reduction_factor):
29 29 """
30   - Reduce number of triangles of the given vtkPolyData, based on
  30 + Reduce number of triangles of the given vtkPolyData, based on
31 31 reduction_factor.
32 32 """
33 33 # Important: vtkQuadricDecimation presented better results than
... ... @@ -51,19 +51,19 @@ def ApplySmoothFilter(polydata, iterations, relaxation_factor):
51 51 smoother.SetRelaxationFactor(relaxation_factor)
52 52 smoother.FeatureEdgeSmoothingOn()
53 53 smoother.BoundarySmoothingOn()
54   - smoother.GetOutput().ReleaseDataFlagOn()
  54 + smoother.GetOutput().ReleaseDataFlagOn()
55 55 smoother.AddObserver("ProgressEvent", lambda obj, evt:
56 56 UpdateProgress(smoother, "Smoothing surface..."))
57   -
  57 +
58 58 return smoother.GetOutput()
59   -
  59 +
60 60  
61 61  
62 62 def FillSurfaceHole(polydata):
63 63 """
64 64 Fill holes in the given polydata.
65 65 """
66   - # Filter used to detect and fill holes. Only fill
  66 + # Filter used to detect and fill holes. Only fill
67 67 print "Filling polydata"
68 68 filled_polydata = vtk.vtkFillHolesFilter()
69 69 filled_polydata.SetInput(polydata)
... ... @@ -125,8 +125,15 @@ def JoinSeedsParts(polydata, point_id_list):
125 125 conn = vtk.vtkPolyDataConnectivityFilter()
126 126 conn.SetInput(polydata)
127 127 conn.SetExtractionModeToPointSeededRegions()
  128 + UpdateProgress = vu.ShowProgress(1 + len(point_id_list))
  129 + pos = 1
128 130 for seed in point_id_list:
129 131 conn.AddSeed(seed)
  132 + UpdateProgress(pos, _("Getting selected parts"))
  133 + pos += 1
  134 +
  135 + conn.AddObserver("ProgressEvent", lambda obj, evt:
  136 + UpdateProgress(conn, "Getting selected parts"))
130 137 conn.Update()
131 138  
132 139 result = vtk.vtkPolyData()
... ... @@ -137,9 +144,12 @@ def JoinSeedsParts(polydata, point_id_list):
137 144 def SelectLargestPart(polydata):
138 145 """
139 146 """
  147 + UpdateProgress = vu.ShowProgress(1)
140 148 conn = vtk.vtkPolyDataConnectivityFilter()
141 149 conn.SetInput(polydata)
142 150 conn.SetExtractionModeToLargestRegion()
  151 + conn.AddObserver("ProgressEvent", lambda obj, evt:
  152 + UpdateProgress(conn, "Getting largest part..."))
143 153 conn.Update()
144 154  
145 155 result = vtk.vtkPolyData()
... ... @@ -154,24 +164,28 @@ def SplitDisconectedParts(polydata):
154 164 conn.SetInput(polydata)
155 165 conn.SetExtractionModeToAllRegions()
156 166 conn.Update()
157   -
  167 +
158 168 nregions = conn.GetNumberOfExtractedRegions()
159 169  
160 170 conn.SetExtractionModeToSpecifiedRegions()
161 171 conn.Update()
162 172  
163 173 polydata_collection = []
164   -
165   -
  174 +
  175 + # Update progress value in GUI
  176 + UpdateProgress = vu.ShowProgress(nregions)
  177 +
  178 +
166 179 for region in xrange(nregions):
167 180 conn.InitializeSpecifiedRegionList()
168 181 conn.AddSpecifiedRegion(region)
169 182 conn.Update()
170   -
  183 +
171 184 p = vtk.vtkPolyData()
172 185 p.DeepCopy(conn.GetOutput())
173 186 p.Update()
174   -
  187 +
175 188 polydata_collection.append(p)
176   -
  189 + UpdateProgress(region, _("Splitting disconected parts"))
  190 +
177 191 return polydata_collection
... ...