forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New class for extracting surfaces from label masks
The discrete flying edges classes extract isocontours from label masks. Label masks are not continuous so special interpolation and treatment is required. Each contour value generates a separate region. Also, documentation in the form of cross referencing other contouring classes was added. The discrete isocontouring classes are not well known but very powerful and should be used more often.
- Loading branch information
Showing
19 changed files
with
2,962 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Filters/General/Testing/Data/Baseline/TestDiscreteFlyingEdges2D.png.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
571c2c61232b41a961352e2fd036d984 |
1 change: 1 addition & 0 deletions
1
Filters/General/Testing/Data/Baseline/TestDiscreteFlyingEdges2D_1.png.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ebac6173f98ecd9d5eeb37a16ae17377 |
1 change: 1 addition & 0 deletions
1
Filters/General/Testing/Data/Baseline/TestDiscreteFlyingEdges2D_2.png.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20753aecfc1b8ff6ca4880d4ed8945dc |
1 change: 1 addition & 0 deletions
1
Filters/General/Testing/Data/Baseline/TestDiscreteFlyingEdges2D_3.png.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20753aecfc1b8ff6ca4880d4ed8945dc |
1 change: 1 addition & 0 deletions
1
Filters/General/Testing/Data/Baseline/TestDiscreteFlyingEdges3D.png.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7c4def60144af2d5fd57976222bd5d26 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
Filters/General/Testing/Python/TestDiscreteFlyingEdges2D.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python | ||
import vtk | ||
from vtk.util.misc import vtkGetDataRoot | ||
VTK_DATA_ROOT = vtkGetDataRoot() | ||
|
||
# Create the RenderWindow, Renderer and both Actors | ||
# | ||
ren1 = vtk.vtkRenderer() | ||
ren1.SetBackground(1,1,1) | ||
renWin = vtk.vtkRenderWindow() | ||
renWin.AddRenderer(ren1) | ||
iren = vtk.vtkRenderWindowInteractor() | ||
iren.SetRenderWindow(renWin) | ||
|
||
# Read the data. Note this creates a 3-component scalar. | ||
red = vtk.vtkPNGReader() | ||
red.SetFileName(VTK_DATA_ROOT + "/Data/RedCircle.png") | ||
red.Update() | ||
|
||
# Next filter can only handle RGB *(&&*@ | ||
extract = vtk.vtkImageExtractComponents() | ||
extract.SetInputConnection(red.GetOutputPort()) | ||
extract.SetComponents(0,1,2) | ||
|
||
# Quantize the image into an index | ||
quantize = vtk.vtkImageQuantizeRGBToIndex() | ||
quantize.SetInputConnection(extract.GetOutputPort()) | ||
quantize.SetNumberOfColors(3) | ||
|
||
# Create the pipeline | ||
discrete = vtk.vtkDiscreteFlyingEdges2D() | ||
discrete.SetInputConnection(quantize.GetOutputPort()) | ||
discrete.SetValue(0,0) | ||
|
||
# Create polgons | ||
polyLoops = vtk.vtkContourLoopExtraction() | ||
polyLoops.SetInputConnection(discrete.GetOutputPort()) | ||
|
||
# Triangle filter because concave polygons are not rendered correctly | ||
triF = vtk.vtkTriangleFilter() | ||
triF.SetInputConnection(polyLoops.GetOutputPort()) | ||
|
||
# Polylines are generated | ||
mapper = vtk.vtkPolyDataMapper() | ||
mapper.SetInputConnection(discrete.GetOutputPort()) | ||
mapper.ScalarVisibilityOff() | ||
|
||
actor = vtk.vtkActor() | ||
actor.SetMapper(mapper) | ||
actor.GetProperty().SetColor(0,0,0) | ||
|
||
# Polygons are displayed | ||
polyMapper = vtk.vtkPolyDataMapper() | ||
polyMapper.SetInputConnection(triF.GetOutputPort()) | ||
|
||
polyActor = vtk.vtkActor() | ||
polyActor.SetMapper(polyMapper) | ||
|
||
ren1.AddActor(actor) | ||
ren1.AddActor(polyActor) | ||
|
||
renWin.Render() | ||
iren.Start() |
90 changes: 90 additions & 0 deletions
90
Filters/General/Testing/Python/TestDiscreteFlyingEdges3D.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env python | ||
import vtk | ||
from vtk.util.misc import vtkGetDataRoot | ||
VTK_DATA_ROOT = vtkGetDataRoot() | ||
|
||
# Create the RenderWindow, Renderer and both Actors | ||
# | ||
ren1 = vtk.vtkRenderer() | ||
renWin = vtk.vtkRenderWindow() | ||
renWin.AddRenderer(ren1) | ||
iren = vtk.vtkRenderWindowInteractor() | ||
iren.SetRenderWindow(renWin) | ||
|
||
math = vtk.vtkMath() | ||
|
||
# Generate some random colors | ||
def MakeColors (lut, n): | ||
lut.SetNumberOfColors(n) | ||
lut.SetTableRange(0, n - 1) | ||
lut.SetScaleToLinear() | ||
lut.Build() | ||
lut.SetTableValue(0, 0, 0, 0, 1) | ||
math.RandomSeed(5071) | ||
i = 1 | ||
while i < n: | ||
lut.SetTableValue(i, math.Random(.2, 1), | ||
math.Random(.2, 1), math.Random(.2, 1), 1) | ||
i += 1 | ||
|
||
lut = vtk.vtkLookupTable() | ||
MakeColors(lut, 256) | ||
n = 20 | ||
radius = 10 | ||
|
||
# This has been moved outside the loop so that the code can be correctly | ||
# translated to python | ||
blobImage = vtk.vtkImageData() | ||
|
||
i = 0 | ||
while i < n: | ||
sphere = vtk.vtkSphere() | ||
sphere.SetRadius(radius) | ||
max = 50 - radius | ||
sphere.SetCenter(int(math.Random(-max, max)), | ||
int(math.Random(-max, max)), int(math.Random(-max, max))) | ||
|
||
sampler = vtk.vtkSampleFunction() | ||
sampler.SetImplicitFunction(sphere) | ||
sampler.SetOutputScalarTypeToFloat() | ||
sampler.SetSampleDimensions(51, 51, 51) | ||
sampler.SetModelBounds(-50, 50, -50, 50, -50, 50) | ||
|
||
thres = vtk.vtkImageThreshold() | ||
thres.SetInputConnection(sampler.GetOutputPort()) | ||
thres.ThresholdByLower(radius * radius) | ||
thres.ReplaceInOn() | ||
thres.ReplaceOutOn() | ||
thres.SetInValue(i + 1) | ||
thres.SetOutValue(0) | ||
thres.Update() | ||
if (i == 0): | ||
blobImage.DeepCopy(thres.GetOutput()) | ||
|
||
maxValue = vtk.vtkImageMathematics() | ||
maxValue.SetInputData(0, blobImage) | ||
maxValue.SetInputData(1, thres.GetOutput()) | ||
maxValue.SetOperationToMax() | ||
maxValue.Modified() | ||
maxValue.Update() | ||
|
||
blobImage.DeepCopy(maxValue.GetOutput()) | ||
|
||
i += 1 | ||
|
||
discrete = vtk.vtkDiscreteFlyingEdges3D() | ||
discrete.SetInputData(blobImage) | ||
discrete.GenerateValues(n, 1, n) | ||
|
||
mapper = vtk.vtkPolyDataMapper() | ||
mapper.SetInputConnection(discrete.GetOutputPort()) | ||
mapper.SetLookupTable(lut) | ||
mapper.SetScalarRange(0, lut.GetNumberOfColors()) | ||
|
||
actor = vtk.vtkActor() | ||
actor.SetMapper(mapper) | ||
|
||
ren1.AddActor(actor) | ||
|
||
renWin.Render() | ||
iren.Start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,5 +87,4 @@ def MakeColors (lut, n): | |
ren1.AddActor(actor) | ||
|
||
renWin.Render() | ||
|
||
#iren.Start() | ||
iren.Start() |
Oops, something went wrong.