Skip to content
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

ENH: Addition of ctk_cli #493

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace
{

template <typename TPixel>
int DoIt( int argc, char * argv[], T )
int DoIt( int argc, char * argv[], TPixel )
{
PARSE_ARGS;

Expand Down
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)
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>CLIPythonModuleTemplate</title>
<description><![CDATA[This is a CLI module that can be bundled in an extension]]></description>
<version>0.0.1</version>
<documentation-url>http://www.example.com/Slicer/Modules/CLIPythonModuleTemplate</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

#-----------------------------------------------------------------------------
set(MODULE_NAME CLIModuleTemplate)

#-----------------------------------------------------------------------------

set(PYTHON_MODULE_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_NAME}Python.py)

#-----------------------------------------------------------------------------
if(BUILD_TESTING)
add_subdirectory(Testing)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fc6170ceeff3d8217a9dd6a1add2ec8c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0749d4d3f07a217030f9ae33d94c4559
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6e5c289c73e14ba7a1b0f8aaf6ed249a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3ebd710c9cf9d75750f4569b8caf6d07
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(Python)
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}PythonTest)
ExternalData_add_test(${CLP}PythonData NAME ${testname} COMMAND ${Slicer_LAUNCHER_EXECUTABLE} ${PYTHON_MODULE_SCRIPT}
--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}PythonData)
1 change: 1 addition & 0 deletions Extensions/Testing/CLIExtensionTemplate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include(${Slicer_USE_FILE})
#-----------------------------------------------------------------------------
# Extension modules
add_subdirectory(CLIModuleTemplate)
add_subdirectory(CLIModuleTemplatePython)
## NEXT_MODULE

#-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ if(Slicer_USE_SimpleITK)
endif()

if(Slicer_BUILD_CLI_SUPPORT)
list(APPEND Slicer_DEPENDENCIES SlicerExecutionModel)
list(APPEND Slicer_DEPENDENCIES SlicerExecutionModel python-ctk_cli)
endif()

if(Slicer_BUILD_EXTENSIONMANAGER_SUPPORT)
Expand Down
36 changes: 36 additions & 0 deletions SuperBuild/External_python-ctk_cli.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
set(proj python-ctk_cli)

# Set dependency list
set(${proj}_DEPENDENCIES python python-setuptools)

# Include dependent projects if any
ExternalProject_Include_Dependencies(${proj} PROJECT_VAR proj DEPENDS_VAR ${proj}_DEPENDENCIES)

if(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
# XXX - Add a test checking if <proj> is available
endif()

if(NOT DEFINED ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
set(${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj} ${${CMAKE_PROJECT_NAME}_USE_SYSTEM_python})
endif()

set(ctk_cli_REPOSITORY ${git_protocol}://github.com/commontk/ctk-cli.git)
set(ctk_cli_GIT_TAG 4346a22618b299c8eff84c6a179067ca68db43b9)

if(NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})

ExternalProject_Add(${proj}
${${proj}_EP_ARGS}
GIT_REPOSITORY ${ctk_cli_REPOSITORY}
GIT_TAG ${ctk_cli_GIT_TAG}
SOURCE_DIR ${proj}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${PYTHON_EXECUTABLE} setup.py install
DEPENDS
${${proj}_DEPENDENCIES}
)
else()
ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
endif()