From 7581a150c6ab839183ab656870ecda80d01fd684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Sun, 23 Dec 2018 17:02:03 -0500 Subject: [PATCH] ENH: Add examples to the template. Add a hint to foster writing examples for the contributed classes. --- cookiecutter.json | 1 + {{cookiecutter.project_name}}/CMakeLists.txt | 2 + .../examples/CMakeLists.txt | 18 ++++++++ .../{{ cookiecutter.example_name }}.cxx | 45 +++++++++++++++++++ .../{{ cookiecutter.example_name }}.py | 42 +++++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 {{cookiecutter.project_name}}/examples/CMakeLists.txt create mode 100644 {{cookiecutter.project_name}}/examples/{{ cookiecutter.example_name }}.cxx create mode 100644 {{cookiecutter.project_name}}/examples/{{ cookiecutter.example_name }}.py diff --git a/cookiecutter.json b/cookiecutter.json index a7568fc..11ff7e4 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -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." diff --git a/{{cookiecutter.project_name}}/CMakeLists.txt b/{{cookiecutter.project_name}}/CMakeLists.txt index f3ff2bd..93d2437 100644 --- a/{{cookiecutter.project_name}}/CMakeLists.txt +++ b/{{cookiecutter.project_name}}/CMakeLists.txt @@ -11,3 +11,5 @@ else() set(ITK_DIR ${CMAKE_BINARY_DIR}) itk_module_impl() endif() + +itk_module_examples() diff --git a/{{cookiecutter.project_name}}/examples/CMakeLists.txt b/{{cookiecutter.project_name}}/examples/CMakeLists.txt new file mode 100644 index 0000000..204c066 --- /dev/null +++ b/{{cookiecutter.project_name}}/examples/CMakeLists.txt @@ -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}) diff --git a/{{cookiecutter.project_name}}/examples/{{ cookiecutter.example_name }}.cxx b/{{cookiecutter.project_name}}/examples/{{ cookiecutter.example_name }}.cxx new file mode 100644 index 0000000..5341795 --- /dev/null +++ b/{{cookiecutter.project_name}}/examples/{{ cookiecutter.example_name }}.cxx @@ -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; +} diff --git a/{{cookiecutter.project_name}}/examples/{{ cookiecutter.example_name }}.py b/{{cookiecutter.project_name}}/examples/{{ cookiecutter.example_name }}.py new file mode 100644 index 0000000..0185a0e --- /dev/null +++ b/{{cookiecutter.project_name}}/examples/{{ cookiecutter.example_name }}.py @@ -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 +# +# 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.