Commit ff18a9fcbf823c6e4a5c3700b1c6cc6619110645
1 parent
9078f46d
Exists in
master
and in
68 other branches
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,7 +27,7 @@ UpdateProgress = vu.ShowProgress() | ||
27 | 27 | ||
28 | def ApplyDecimationFilter(polydata, reduction_factor): | 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 | reduction_factor. | 31 | reduction_factor. |
32 | """ | 32 | """ |
33 | # Important: vtkQuadricDecimation presented better results than | 33 | # Important: vtkQuadricDecimation presented better results than |
@@ -51,19 +51,19 @@ def ApplySmoothFilter(polydata, iterations, relaxation_factor): | @@ -51,19 +51,19 @@ def ApplySmoothFilter(polydata, iterations, relaxation_factor): | ||
51 | smoother.SetRelaxationFactor(relaxation_factor) | 51 | smoother.SetRelaxationFactor(relaxation_factor) |
52 | smoother.FeatureEdgeSmoothingOn() | 52 | smoother.FeatureEdgeSmoothingOn() |
53 | smoother.BoundarySmoothingOn() | 53 | smoother.BoundarySmoothingOn() |
54 | - smoother.GetOutput().ReleaseDataFlagOn() | 54 | + smoother.GetOutput().ReleaseDataFlagOn() |
55 | smoother.AddObserver("ProgressEvent", lambda obj, evt: | 55 | smoother.AddObserver("ProgressEvent", lambda obj, evt: |
56 | UpdateProgress(smoother, "Smoothing surface...")) | 56 | UpdateProgress(smoother, "Smoothing surface...")) |
57 | - | 57 | + |
58 | return smoother.GetOutput() | 58 | return smoother.GetOutput() |
59 | - | 59 | + |
60 | 60 | ||
61 | 61 | ||
62 | def FillSurfaceHole(polydata): | 62 | def FillSurfaceHole(polydata): |
63 | """ | 63 | """ |
64 | Fill holes in the given polydata. | 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 | print "Filling polydata" | 67 | print "Filling polydata" |
68 | filled_polydata = vtk.vtkFillHolesFilter() | 68 | filled_polydata = vtk.vtkFillHolesFilter() |
69 | filled_polydata.SetInput(polydata) | 69 | filled_polydata.SetInput(polydata) |
@@ -125,8 +125,15 @@ def JoinSeedsParts(polydata, point_id_list): | @@ -125,8 +125,15 @@ def JoinSeedsParts(polydata, point_id_list): | ||
125 | conn = vtk.vtkPolyDataConnectivityFilter() | 125 | conn = vtk.vtkPolyDataConnectivityFilter() |
126 | conn.SetInput(polydata) | 126 | conn.SetInput(polydata) |
127 | conn.SetExtractionModeToPointSeededRegions() | 127 | conn.SetExtractionModeToPointSeededRegions() |
128 | + UpdateProgress = vu.ShowProgress(1 + len(point_id_list)) | ||
129 | + pos = 1 | ||
128 | for seed in point_id_list: | 130 | for seed in point_id_list: |
129 | conn.AddSeed(seed) | 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 | conn.Update() | 137 | conn.Update() |
131 | 138 | ||
132 | result = vtk.vtkPolyData() | 139 | result = vtk.vtkPolyData() |
@@ -137,9 +144,12 @@ def JoinSeedsParts(polydata, point_id_list): | @@ -137,9 +144,12 @@ def JoinSeedsParts(polydata, point_id_list): | ||
137 | def SelectLargestPart(polydata): | 144 | def SelectLargestPart(polydata): |
138 | """ | 145 | """ |
139 | """ | 146 | """ |
147 | + UpdateProgress = vu.ShowProgress(1) | ||
140 | conn = vtk.vtkPolyDataConnectivityFilter() | 148 | conn = vtk.vtkPolyDataConnectivityFilter() |
141 | conn.SetInput(polydata) | 149 | conn.SetInput(polydata) |
142 | conn.SetExtractionModeToLargestRegion() | 150 | conn.SetExtractionModeToLargestRegion() |
151 | + conn.AddObserver("ProgressEvent", lambda obj, evt: | ||
152 | + UpdateProgress(conn, "Getting largest part...")) | ||
143 | conn.Update() | 153 | conn.Update() |
144 | 154 | ||
145 | result = vtk.vtkPolyData() | 155 | result = vtk.vtkPolyData() |
@@ -154,24 +164,28 @@ def SplitDisconectedParts(polydata): | @@ -154,24 +164,28 @@ def SplitDisconectedParts(polydata): | ||
154 | conn.SetInput(polydata) | 164 | conn.SetInput(polydata) |
155 | conn.SetExtractionModeToAllRegions() | 165 | conn.SetExtractionModeToAllRegions() |
156 | conn.Update() | 166 | conn.Update() |
157 | - | 167 | + |
158 | nregions = conn.GetNumberOfExtractedRegions() | 168 | nregions = conn.GetNumberOfExtractedRegions() |
159 | 169 | ||
160 | conn.SetExtractionModeToSpecifiedRegions() | 170 | conn.SetExtractionModeToSpecifiedRegions() |
161 | conn.Update() | 171 | conn.Update() |
162 | 172 | ||
163 | polydata_collection = [] | 173 | polydata_collection = [] |
164 | - | ||
165 | - | 174 | + |
175 | + # Update progress value in GUI | ||
176 | + UpdateProgress = vu.ShowProgress(nregions) | ||
177 | + | ||
178 | + | ||
166 | for region in xrange(nregions): | 179 | for region in xrange(nregions): |
167 | conn.InitializeSpecifiedRegionList() | 180 | conn.InitializeSpecifiedRegionList() |
168 | conn.AddSpecifiedRegion(region) | 181 | conn.AddSpecifiedRegion(region) |
169 | conn.Update() | 182 | conn.Update() |
170 | - | 183 | + |
171 | p = vtk.vtkPolyData() | 184 | p = vtk.vtkPolyData() |
172 | p.DeepCopy(conn.GetOutput()) | 185 | p.DeepCopy(conn.GetOutput()) |
173 | p.Update() | 186 | p.Update() |
174 | - | 187 | + |
175 | polydata_collection.append(p) | 188 | polydata_collection.append(p) |
176 | - | 189 | + UpdateProgress(region, _("Splitting disconected parts")) |
190 | + | ||
177 | return polydata_collection | 191 | return polydata_collection |