Skip to content

Commit

Permalink
ENH: Add examples to the template.
Browse files Browse the repository at this point in the history
Add a hint to foster writing examples for the contributed classes.
  • Loading branch information
jhlegarreta authored and dzenanz committed Jul 3, 2024
1 parent 6ecddff commit 7581a15
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module_name": "{{ cookiecutter.project_name[3:] }}",
"filter_name": "MyFilter",
"python_package_name": "itk-{{ cookiecutter.project_name[3:].lower() }}",
"example_name": "MyFilterApplicationWholePipeline",
"download_url": "https://github.com/InsightSoftwareConsortium/{{ cookiecutter.project_name }}",
"project_short_description": "This is a template that serves as a starting point for a new module.",
"project_long_description": "ITK is an open-source, cross-platform library that provides developers with an extensive suite of software tools for image analysis. Developed through extreme programming methodologies, ITK employs leading-edge algorithms for registering and segmenting multidimensional scientific images."
Expand Down
2 changes: 2 additions & 0 deletions {{cookiecutter.project_name}}/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ else()
set(ITK_DIR ${CMAKE_BINARY_DIR})
itk_module_impl()
endif()

itk_module_examples()
18 changes: 18 additions & 0 deletions {{cookiecutter.project_name}}/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.16.3)
project({{ cookiecutter.module_name }}Examples)

set(ExampleSpecificComponents
{{ cookiecutter.module_name }}
)

if(NOT ITK_SOURCE_DIR)
find_package(ITK REQUIRED COMPONENTS ITKImageIO ITKTransformIO ${ExampleSpecificComponents})
else()
# When being built as part of ITK, ITKImageIO and ITKTransformIO
# lists of modules are not yet ready, causing a configure error
find_package(ITK REQUIRED COMPONENTS ${ExampleSpecificComponents})
endif()
include(${ITK_USE_FILE})

add_executable({{ cookiecutter.example_name }} {{ cookiecutter.example_name }}.cxx )
target_link_libraries({{ cookiecutter.example_name }} ${ITK_LIBRARIES})
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/

#include "itk{{cookiecutter.filter_name}}.h"

#include "itkCommand.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"


int main( int argc, char * argv[] )
{
if( argc < 4 )
{
std::cerr << "Missing parameters." << std::endl;
std::cerr << "Usage: " << argv[0]
<< " inputImage"
<< " outputImage"
<< " parameters" << std::endl;
return EXIT_FAILURE;
}


// Please, write a complete, self-containted and useful example that
// demonstrate a class when being used along with other ITK classes or in
// the context of a wider or specific application.


return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python

# Copyright NumFOCUS
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Run with:
# ./{{ cookiecutter.example_name }}.py <input_image> <output_image>
# <parameters>
# e.g.
# ./{{ cookiecutter.example_name }}.py MyImage.mha Output.mha 2 0.2
# (A rule of thumb is to set the Threshold to be about 1 / 100 of the Level.)
#
# parameter_1: absolute minimum...
# The assumption is that...
# parameter_2: controls the..
# A tradeoff between...

import argparse

import itk


parser = argparse.ArgumentParser(description="Example short description.")
parser.add_argument("input_image")
parser.add_argument("output_image")
parser.add_argument("parameter_1")
args = parser.parse_args()

# Please, write a complete, self-containted and useful example that
# demonstrate a class when being used along with other ITK classes or in
# the context of a wider or specific application.

0 comments on commit 7581a15

Please sign in to comment.