Skip to content

Commit 7581a15

Browse files
jhlegarretadzenanz
authored andcommitted
ENH: Add examples to the template.
Add a hint to foster writing examples for the contributed classes.
1 parent 6ecddff commit 7581a15

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

cookiecutter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"module_name": "{{ cookiecutter.project_name[3:] }}",
66
"filter_name": "MyFilter",
77
"python_package_name": "itk-{{ cookiecutter.project_name[3:].lower() }}",
8+
"example_name": "MyFilterApplicationWholePipeline",
89
"download_url": "https://github.com/InsightSoftwareConsortium/{{ cookiecutter.project_name }}",
910
"project_short_description": "This is a template that serves as a starting point for a new module.",
1011
"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."

{{cookiecutter.project_name}}/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ else()
1111
set(ITK_DIR ${CMAKE_BINARY_DIR})
1212
itk_module_impl()
1313
endif()
14+
15+
itk_module_examples()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required(VERSION 3.16.3)
2+
project({{ cookiecutter.module_name }}Examples)
3+
4+
set(ExampleSpecificComponents
5+
{{ cookiecutter.module_name }}
6+
)
7+
8+
if(NOT ITK_SOURCE_DIR)
9+
find_package(ITK REQUIRED COMPONENTS ITKImageIO ITKTransformIO ${ExampleSpecificComponents})
10+
else()
11+
# When being built as part of ITK, ITKImageIO and ITKTransformIO
12+
# lists of modules are not yet ready, causing a configure error
13+
find_package(ITK REQUIRED COMPONENTS ${ExampleSpecificComponents})
14+
endif()
15+
include(${ITK_USE_FILE})
16+
17+
add_executable({{ cookiecutter.example_name }} {{ cookiecutter.example_name }}.cxx )
18+
target_link_libraries({{ cookiecutter.example_name }} ${ITK_LIBRARIES})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*=========================================================================
2+
*
3+
* Copyright NumFOCUS
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0.txt
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*=========================================================================*/
18+
19+
#include "itk{{cookiecutter.filter_name}}.h"
20+
21+
#include "itkCommand.h"
22+
#include "itkImageFileReader.h"
23+
#include "itkImageFileWriter.h"
24+
25+
26+
int main( int argc, char * argv[] )
27+
{
28+
if( argc < 4 )
29+
{
30+
std::cerr << "Missing parameters." << std::endl;
31+
std::cerr << "Usage: " << argv[0]
32+
<< " inputImage"
33+
<< " outputImage"
34+
<< " parameters" << std::endl;
35+
return EXIT_FAILURE;
36+
}
37+
38+
39+
// Please, write a complete, self-containted and useful example that
40+
// demonstrate a class when being used along with other ITK classes or in
41+
// the context of a wider or specific application.
42+
43+
44+
return EXIT_SUCCESS;
45+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright NumFOCUS
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0.txt
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Run with:
18+
# ./{{ cookiecutter.example_name }}.py <input_image> <output_image>
19+
# <parameters>
20+
# e.g.
21+
# ./{{ cookiecutter.example_name }}.py MyImage.mha Output.mha 2 0.2
22+
# (A rule of thumb is to set the Threshold to be about 1 / 100 of the Level.)
23+
#
24+
# parameter_1: absolute minimum...
25+
# The assumption is that...
26+
# parameter_2: controls the..
27+
# A tradeoff between...
28+
29+
import argparse
30+
31+
import itk
32+
33+
34+
parser = argparse.ArgumentParser(description="Example short description.")
35+
parser.add_argument("input_image")
36+
parser.add_argument("output_image")
37+
parser.add_argument("parameter_1")
38+
args = parser.parse_args()
39+
40+
# Please, write a complete, self-containted and useful example that
41+
# demonstrate a class when being used along with other ITK classes or in
42+
# the context of a wider or specific application.

0 commit comments

Comments
 (0)