-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ctk cli2 #497
Open
fbudin69500
wants to merge
4
commits into
Slicer:master
Choose a base branch
from
fbudin69500:add_ctk_cli2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add ctk cli2 #497
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a98459d
ENH: Addition of ctk_cli
fbudin69500 bae311d
BUG: Template argument name was modified in template declaration
fbudin69500 4b216a9
ENH: Addition of an example to use ctk_cli
fbudin69500 70a7aff
ENH: Generating new extension based on new module type.
fbudin69500 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#----------------------------------------------------------------------------- | ||
set(MODULE_NAME PythonCLIModuleTemplate) | ||
|
||
#----------------------------------------------------------------------------- | ||
set(MODULE_PYTHON_SCRIPTS | ||
${MODULE_NAME}.py | ||
) | ||
|
||
set(MODULE_PYTHON_RESOURCES | ||
${MODULE_NAME}.xml | ||
) | ||
|
||
#----------------------------------------------------------------------------- | ||
slicerMacroBuildScriptedModule( | ||
NAME ${MODULE_NAME} | ||
SCRIPTS ${MODULE_PYTHON_SCRIPTS} | ||
RESOURCES ${MODULE_PYTHON_RESOURCES} | ||
) | ||
|
||
#----------------------------------------------------------------------------- | ||
if(BUILD_TESTING) | ||
# Additional build-time testing | ||
add_subdirectory(Testing) | ||
endif() |
1 change: 1 addition & 0 deletions
1
Utilities/Templates/Modules/PythonCLI/Data/Baseline/PythonCLIModuleTemplateTest.nhdr.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 @@ | ||
fc6170ceeff3d8217a9dd6a1add2ec8c |
1 change: 1 addition & 0 deletions
1
Utilities/Templates/Modules/PythonCLI/Data/Baseline/PythonCLIModuleTemplateTest.raw.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 @@ | ||
0749d4d3f07a217030f9ae33d94c4559 |
1 change: 1 addition & 0 deletions
1
Utilities/Templates/Modules/PythonCLI/Data/Input/CTHeadAxial.nhdr.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 @@ | ||
6e5c289c73e14ba7a1b0f8aaf6ed249a |
1 change: 1 addition & 0 deletions
1
Utilities/Templates/Modules/PythonCLI/Data/Input/CTHeadAxial.raw.gz.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 @@ | ||
3ebd710c9cf9d75750f4569b8caf6d07 |
36 changes: 36 additions & 0 deletions
36
Utilities/Templates/Modules/PythonCLI/PythonCLIModuleTemplate.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,36 @@ | ||
import itk | ||
from ctk_cli import * | ||
import sys | ||
import logging | ||
|
||
def SmoothingRecursiveGaussianImageFilter(inputVolume, outputVolume, sigma): | ||
reader = itk.ImageFileReader.New(FileName=inputVolume) | ||
filter = itk.SmoothingRecursiveGaussianImageFilter.New(reader) | ||
filter.SetSigma(sigma) | ||
writer = itk.ImageFileWriter.New(filter,FileName=outputVolume) | ||
writer.SetUseCompression(True) | ||
writer.Update() | ||
return 1 | ||
|
||
|
||
def main(): | ||
"""Parsing command line arguments and reading input files.""" | ||
logging.basicConfig(level=logging.INFO) | ||
args=CLIArgumentParser().parse_args() | ||
# Run processing | ||
SmoothingRecursiveGaussianImageFilter(args.inputVolume,args.outputVolume,args.sigma) | ||
# Compare output with baseline | ||
reader1 = itk.ImageFileReader.New(FileName=args.outputVolume) | ||
reader2 = itk.ImageFileReader.New(FileName=args.baselineVolume) | ||
compareFilter=itk.ComparisonImageFilter.New(reader1) | ||
compareFilter.SetTestInput(reader1) | ||
compareFilter.SetValidInput(reader2) | ||
diff=compareFilter.GetTotalDifference() | ||
if diff < args.tolerance: | ||
return 0 | ||
return 1 | ||
|
||
if __name__ == "__main__": | ||
ret=main() | ||
if ret: | ||
sys.exit(ret) |
52 changes: 52 additions & 0 deletions
52
Utilities/Templates/Modules/PythonCLI/PythonCLIModuleTemplate.xml
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,52 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<executable> | ||
<category>Examples</category> | ||
<title>PythonCLIModuleTemplate</title> | ||
<description><![CDATA[This is a Python CLI module that can be bundled in an extension]]></description> | ||
<version>0.0.1</version> | ||
<documentation-url>http://www.example.com/Slicer/Modules/PythonCLIModuleTemplate</documentation-url> | ||
<license>Slicer</license> | ||
<contributor>FirstName LastName (Institution), FirstName LastName (Institution)</contributor> | ||
<acknowledgements>This work was partially funded by NIH grant NXNNXXNNNNNN-NNXN</acknowledgements> | ||
<parameters> | ||
<label>IO</label> | ||
<description><![CDATA[Input/output parameters]]></description> | ||
<double> | ||
<name>sigma</name> | ||
<longflag>sigma</longflag> | ||
<flag>s</flag> | ||
<label>Sigma</label> | ||
<description><![CDATA[A double value (in units of mm) passed to the algorithm]]></description> | ||
<default>1.0</default> | ||
</double> | ||
<image> | ||
<name>inputVolume</name> | ||
<label>Input Volume</label> | ||
<channel>input</channel> | ||
<index>0</index> | ||
<description><![CDATA[Input volume]]></description> | ||
</image> | ||
<image> | ||
<name>outputVolume</name> | ||
<label>Output Volume</label> | ||
<channel>output</channel> | ||
<index>1</index> | ||
<description><![CDATA[Output Volume]]></description> | ||
</image> | ||
<image> | ||
<name>baselineVolume</name> | ||
<label>Baseline Volume</label> | ||
<channel>input</channel> | ||
<index>2</index> | ||
<description><![CDATA[Output Volume]]></description> | ||
</image> | ||
<double> | ||
<name>tolerance</name> | ||
<longflag>tolerance</longflag> | ||
<flag>t</flag> | ||
<label>Tolerance</label> | ||
<description><![CDATA[Tolerance between the output image and the baseline (sum)]]></description> | ||
<default>0.0001</default> | ||
</double> | ||
</parameters> | ||
</executable> |
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 @@ | ||
add_subdirectory(Python) |
17 changes: 17 additions & 0 deletions
17
Utilities/Templates/Modules/PythonCLI/Testing/Python/CMakeLists.txt
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,17 @@ | ||
#----------------------------------------------------------------------------- | ||
set(BASELINE ${CMAKE_CURRENT_SOURCE_DIR}/../../Data/Baseline) | ||
set(INPUT ${CMAKE_CURRENT_SOURCE_DIR}/../../Data/Input) | ||
set(TEMP "${CMAKE_BINARY_DIR}/Testing/Temporary") | ||
|
||
set(CLP ${MODULE_NAME}) | ||
|
||
#----------------------------------------------------------------------------- | ||
set(testname ${CLP}Test) | ||
ExternalData_add_test(${CLP}Data NAME ${testname} COMMAND ${Slicer_LAUNCHER_EXECUTABLE} ${MODULE_NAME}.py | ||
--sigma 2.5 DATA{${INPUT}/CTHeadAxial.nhdr,CTHeadAxial.raw.gz} ${TEMP}/${CLP}Test.nhdr | ||
DATA{${BASELINE}/${CLP}Test.nhdr,${CLP}Test.raw} | ||
) | ||
set_property(TEST ${testname} PROPERTY LABELS ${CLP}) | ||
|
||
#----------------------------------------------------------------------------- | ||
ExternalData_add_target(${CLP}Data) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://pypi.python.org/pypi/flake8-import-order
Useful resrouces: https://pypi.python.org/pypi/flake8-import-order and
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, would it be possible to use
SimpleITK
, wrapped ITK is not yet enabled by default.Thanks for your help