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: Add examples to the template. #46

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
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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()
12 changes: 12 additions & 0 deletions {{cookiecutter.project_name}}/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.10.2)
project({{ cookiecutter.module_name }}Examples)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add CXX or does this help CMake somehow exclude any Python example file that is added along?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python examples don't need to be built -- the default include CXX -> this is good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 So do we need to use

project({{ cookiecutter.module_name }}Examples CXX)

explicitly then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do we need to enable and add tests for the examples?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the example does something, we can use it to write a test, see this. Having test data in there is harder to properly support, that's why I removed it.


find_package(ITK REQUIRED
COMPONENTS
ITKImageIO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is problematic if the example is built as part of ITK. See this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fbudin69500 do you think we should add this to the module template?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems difficult to address cleanly for now as the template would have to explicitly instantiate certain IOs and it is not possible to know ahead of time which IOs should be instantiated. There could be hints in the CMakeLists.txt with commented out lines of code with the IO names that the developer could either uncomment or remove, but that doesn't seem ideal. @dzenanz : Was an issue created in the issue tracker for that Meta module IO issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just created an issue: InsightSoftwareConsortium/ITK#359

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #163.

{{ cookiecutter.module_name }}
)
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 Insight Software Consortium
*
* 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
*
* http://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 Insight Software Consortium
#
# 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
#
# http://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 <InputImageFile> <OutputImageFile>
# <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 sys
import itk

import numpy as np


if len(sys.argv) != 4:
print('Usage: ' + sys.argv[0] +
' <InputFileName> <OutputFileName> <Parameters>')
sys.exit(1)

# 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.