Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VTK Examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VTK
VTK Examples
Merge requests
!296
Adding ContourTriangulator.py
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Adding ContourTriangulator.py
Add-ContourTriangulator-for-Python
into
master
Overview
0
Commits
1
Pipelines
0
Changes
3
Merged
Andrew Maclean
requested to merge
Add-ContourTriangulator-for-Python
into
master
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
3
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
be2a20ee
1 commit,
1 year ago
3 files
+
100
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
src/Python/Modelling/ContourTriangulator.py
0 → 100755
+
96
−
0
Options
#!/usr/bin/env python3
# noinspection PyUnresolvedReferences
import
vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import
vtkmodules.vtkRenderingOpenGL2
from
vtkmodules.vtkCommonColor
import
vtkNamedColors
from
vtkmodules.vtkFiltersCore
import
vtkMarchingSquares
from
vtkmodules.vtkFiltersGeneral
import
vtkContourTriangulator
from
vtkmodules.vtkIOImage
import
vtkPNGReader
from
vtkmodules.vtkRenderingCore
import
(
vtkActor
,
vtkDataSetMapper
,
vtkRenderWindow
,
vtkRenderWindowInteractor
,
vtkRenderer
)
def
get_program_parameters
():
import
argparse
description
=
'
Create a contour from a structured point set (image) and triangulate it.
'
epilogue
=
'''
Try with different iso values e.g. -i1000.
'''
parser
=
argparse
.
ArgumentParser
(
description
=
description
,
epilog
=
epilogue
)
parser
.
add_argument
(
'
file_name
'
,
help
=
'
The path to the image file to use e.g fullhead15.png.
'
)
parser
.
add_argument
(
'
-i
'
,
'
--iso_value
'
,
help
=
'
The contour value for generating the isoline.
'
,
default
=
500
,
type
=
int
)
args
=
parser
.
parse_args
()
return
args
.
file_name
,
args
.
iso_value
def
main
():
file_name
,
iso_value
=
get_program_parameters
()
colors
=
vtkNamedColors
()
reader
=
vtkPNGReader
()
if
not
reader
.
CanReadFile
(
file_name
):
print
(
'
Error: Could not read
'
,
file_name
)
return
reader
.
SetFileName
(
file_name
)
reader
.
Update
()
iso
=
vtkMarchingSquares
()
iso
.
SetInputConnection
(
reader
.
GetOutputPort
())
iso
.
SetValue
(
0
,
iso_value
)
iso_mapper
=
vtkDataSetMapper
()
iso_mapper
.
SetInputConnection
(
iso
.
GetOutputPort
())
iso_mapper
.
ScalarVisibilityOff
()
iso_actor
=
vtkActor
()
iso_actor
.
SetMapper
(
iso_mapper
)
iso_actor
.
GetProperty
().
SetColor
(
colors
.
GetColor3d
(
'
MediumOrchid
'
))
poly
=
vtkContourTriangulator
()
poly
.
SetInputConnection
(
iso
.
GetOutputPort
())
poly_mapper
=
vtkDataSetMapper
()
poly_mapper
.
SetInputConnection
(
poly
.
GetOutputPort
())
poly_mapper
.
ScalarVisibilityOff
()
poly_actor
=
vtkActor
()
poly_actor
.
SetMapper
(
poly_mapper
)
poly_actor
.
GetProperty
().
SetColor
(
colors
.
GetColor3d
(
'
Gray
'
))
# Standard rendering classes.
renderer
=
vtkRenderer
()
ren_win
=
vtkRenderWindow
()
ren_win
.
SetMultiSamples
(
0
)
ren_win
.
AddRenderer
(
renderer
)
ren_win
.
SetWindowName
(
'
ContourTriangulator
'
)
iren
=
vtkRenderWindowInteractor
()
iren
.
SetRenderWindow
(
ren_win
)
renderer
.
AddActor
(
poly_actor
)
renderer
.
AddActor
(
iso_actor
)
renderer
.
SetBackground
(
colors
.
GetColor3d
(
'
DarkSlateGray
'
))
ren_win
.
SetSize
(
300
,
300
)
camera
=
renderer
.
GetActiveCamera
()
renderer
.
ResetCamera
()
camera
.
Azimuth
(
180
)
ren_win
.
Render
()
iren
.
Initialize
()
iren
.
Start
()
if
__name__
==
'
__main__
'
:
main
()
Loading