Skip to content
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
16 changes: 16 additions & 0 deletions Documentation/Maintenance/Release.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,22 @@ Add any new remote modules to nightly builds. Some builds may be difficult to ad
due to third-party dependencies.


Update Remote Modules
---------------------

In order to have the latest versions for all remote modules, and have them use
the latest ITK tag, the following steps should be performed:

1. Update the ITK tag used in the `azure-pipelines.yml` CI configuration and the
`setup.py` Python setup files using the [](https://github.com/InsightSoftwareConsortium/ITK/tree/master/Utilities/Maintenance/)
script. This will involve merging a new pull request to each remote module
repository.

2. Update the remote modules to their latest commits using the
[UpdateRemoteModules.sh](https://github.com/InsightSoftwareConsortium/ITK/tree/master/Utilities/Maintenance/UpdateRemoteModules.sh)
script.


Create Tarballs
---------------

Expand Down
12 changes: 12 additions & 0 deletions Modules/Filtering/MathematicalMorphology/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,18 @@ itk_add_test(NAME itkRankImageFilterTest10
# some tests will fail if dim=2 and unsigned short are not wrapped
list(FIND ITK_WRAP_IMAGE_DIMS 2 wrap_2_index)
if(ITK_WRAP_unsigned_char AND wrap_2_index GREATER -1)
itk_python_add_test(NAME PythonFlatStructuringElementBall
TEST_DRIVER_ARGS
COMMAND FlatStructuringElementTest.py
Ball
5
)
itk_python_add_test(NAME PythonFlatStructuringElementBox
TEST_DRIVER_ARGS
COMMAND FlatStructuringElementTest.py
Box
5
)
itk_python_add_test(NAME PythonGrayscaleDilateImageFilterTest
TEST_DRIVER_ARGS
--compare ${ITK_TEST_OUTPUT_DIR}/PythonGrayscaleDilateImageFilterTest.png
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,18 @@
#
#==========================================================================*/

from InsightToolkit import *
from numarray import *
from sys import argv

reader = itkImageFileReaderUC2_New()

connector = itkPyBufferUC2_New()

reader.SetFileName(argv[1])

reader.Update()

print "ready to convert image into array"

buffer = connector.GetArrayFromImage(reader.GetOutput())

writer = itkImageFileWriterUC2_New()

writer.SetFileName(argv[2])

print "ready to convert array into image"

writer.SetInput(connector.GetImageFromArray(buffer))

writer.Update()
from __future__ import print_function

import itk
from sys import argv, exit
itk.auto_progress(2)

if argv[1] == "Ball":
print("Ball")
strel = itk.FlatStructuringElement[2].Ball(int(argv[2]))
elif argv[1] == "Box":
print("Box")
strel = itk.FlatStructuringElement[2].Box(int(argv[2]))
else:
print("invalid arguement: " + argv[1])
exit(1)
110 changes: 46 additions & 64 deletions Modules/IO/ImageBase/include/itkImageFileReader.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "itkVectorImage.h"

#include "itksys/SystemTools.hxx"
#include <memory> // For unique_ptr
#include <fstream>

namespace itk
Expand Down Expand Up @@ -388,87 +389,68 @@ void ImageFileReader< TOutputImage, ConvertPixelTraits >
itkDebugMacro (<< "Setting imageIO IORegion to: " << m_ActualIORegion);
m_ImageIO->SetIORegion(m_ActualIORegion);

char *loadBuffer = nullptr;
// the size of the buffer is computed based on the actual number of
// pixels to be read and the actual size of the pixels to be read
// (as opposed to the sizes of the output)
size_t sizeOfActualIORegion = m_ActualIORegion.GetNumberOfPixels()
* ( m_ImageIO->GetComponentSize() * m_ImageIO->GetNumberOfComponents() );

try
ImageIOBase::IOComponentType ioType =
ImageIOBase
::MapPixelType< typename ConvertPixelTraits::ComponentType >::CType;
if ( m_ImageIO->GetComponentType() != ioType
|| ( m_ImageIO->GetNumberOfComponents() !=
ConvertPixelTraits::GetNumberOfComponents() ) )
{
ImageIOBase::IOComponentType ioType =
ImageIOBase
::MapPixelType< typename ConvertPixelTraits::ComponentType >::CType;
if ( m_ImageIO->GetComponentType() != ioType
|| ( m_ImageIO->GetNumberOfComponents() !=
ConvertPixelTraits::GetNumberOfComponents() ) )
{
// the pixel types don't match so a type conversion needs to be
// performed
itkDebugMacro( << "Buffer conversion required from: "
<< m_ImageIO->GetComponentTypeAsString(m_ImageIO->GetComponentType())
<< " to: "
<< m_ImageIO->GetComponentTypeAsString(ioType)
<< " ConvertPixelTraits::NumComponents "
<< ConvertPixelTraits::GetNumberOfComponents()
<< " m_ImageIO->NumComponents "
<< m_ImageIO->GetNumberOfComponents() );

loadBuffer = new char[sizeOfActualIORegion];
m_ImageIO->Read( static_cast< void * >( loadBuffer ) );

// See note below as to why the buffered region is needed and
// not actualIOregion
this->DoConvertBuffer( static_cast< void * >( loadBuffer ),
output->GetBufferedRegion().GetNumberOfPixels() );
}
else if ( m_ActualIORegion.GetNumberOfPixels() !=
output->GetBufferedRegion().GetNumberOfPixels() )
{
// NOTE:
// for the number of pixels read and the number of pixels
// requested to not match, the dimensions of the two regions may
// be different, therefore we buffer and copy the pixels

itkDebugMacro(<< "Buffer required because file dimension is greater then image dimension");
// the pixel types don't match so a type conversion needs to be
// performed
itkDebugMacro( << "Buffer conversion required from: "
<< m_ImageIO->GetComponentTypeAsString(m_ImageIO->GetComponentType())
<< " to: "
<< m_ImageIO->GetComponentTypeAsString(ioType)
<< " ConvertPixelTraits::NumComponents "
<< ConvertPixelTraits::GetNumberOfComponents()
<< " m_ImageIO->NumComponents "
<< m_ImageIO->GetNumberOfComponents() );

const std::unique_ptr<char[]> loadBuffer(new char[sizeOfActualIORegion]);
m_ImageIO->Read( static_cast< void * >( loadBuffer.get() ) );

// See note below as to why the buffered region is needed and
// not actualIOregion
this->DoConvertBuffer( static_cast< void * >( loadBuffer.get() ),
output->GetBufferedRegion().GetNumberOfPixels() );
}
else if ( m_ActualIORegion.GetNumberOfPixels() !=
output->GetBufferedRegion().GetNumberOfPixels() )
{
// NOTE:
// for the number of pixels read and the number of pixels
// requested to not match, the dimensions of the two regions may
// be different, therefore we buffer and copy the pixels

OutputImagePixelType *outputBuffer = output->GetPixelContainer()->GetBufferPointer();
itkDebugMacro(<< "Buffer required because file dimension is greater then image dimension");

loadBuffer = new char[sizeOfActualIORegion];
m_ImageIO->Read( static_cast< void * >( loadBuffer ) );
OutputImagePixelType *outputBuffer = output->GetPixelContainer()->GetBufferPointer();

// we use std::copy here as it should be optimized to memcpy for
// plain old data, but still is oop
std::copy(reinterpret_cast< const OutputImagePixelType * >( loadBuffer ),
reinterpret_cast< const OutputImagePixelType * >( loadBuffer ) + output->GetBufferedRegion().GetNumberOfPixels(),
outputBuffer);
}
else
{
itkDebugMacro(<< "No buffer conversion required.");
const std::unique_ptr<char[]> loadBuffer(new char[sizeOfActualIORegion]);
m_ImageIO->Read( static_cast< void * >( loadBuffer.get() ) );

OutputImagePixelType *outputBuffer = output->GetPixelContainer()->GetBufferPointer();
m_ImageIO->Read(outputBuffer);
}
// we use std::copy_n here as it should be optimized to memcpy for
// plain old data, but still is oop
std::copy_n(reinterpret_cast< const OutputImagePixelType * >( loadBuffer.get() ),
output->GetBufferedRegion().GetNumberOfPixels(),
outputBuffer);
}
catch ( ... )
else
{
// if an exception is thrown catch it

// clean up
delete[] loadBuffer;
loadBuffer = nullptr;
itkDebugMacro(<< "No buffer conversion required.");

// then rethrow
throw;
OutputImagePixelType *outputBuffer = output->GetPixelContainer()->GetBufferPointer();
m_ImageIO->Read(outputBuffer);
}

this->UpdateProgress( 1.0f );

// clean up
delete[] loadBuffer;
loadBuffer = nullptr;
}

template< typename TOutputImage, typename ConvertPixelTraits >
Expand Down
52 changes: 52 additions & 0 deletions Utilities/Maintenance/UpdateRemoteModules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

#==========================================================================
#
# 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.
#
#==========================================================================*/


# Make sure we are inside the repository
cd "${BASH_SOURCE%/*}" &&

remote_modules_path=$(cd ../../Modules/Remote && pwd)

git_repository_tag_label='GIT_REPOSITORY'
git_tag_label='GIT_TAG'

# Loop over the remote modules' CMake files
for filename in ${remote_modules_path}/*.cmake; do

# Get the current commit hash
curr_commit_str=($(grep $git_tag_label $filename))
curr_commit_hash=${curr_commit_str[1]}

# Read the git repository information
repository_str=$(grep $git_repository_tag_label $filename)

repository_arr=($(echo $repository_str | tr "/" " "))
organization=${repository_arr[-2]}
repository_name=${repository_arr[-1]}

# Get the latest git commit hash of the remote module.
# Remotes will usually not be tagged.
latest_commit_hash=$(git ls-remote git://github.com/$organization/$repository_name | \
grep refs/heads/master | cut -f 1)

# Sed the the latest commit hash in the CMake file
sed -i "s/${curr_commit_hash}/${latest_commit_hash}/g" $filename

done
69 changes: 69 additions & 0 deletions Utilities/Maintenance/UpdateRequiredITKVersionInFiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

#==========================================================================
#
# 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.
#
#==========================================================================*/


program_name=$0

function usage {
echo "Usage: ${program_name} "
echo " param1 Azure pipelines file path"
echo " param2 Setup.py file path"
exit 1
}

# Display usage
if [ ${#@} != 2 ]; then
usage
fi

azure_pipelines_ci_filename=$1
python_setup_filename=$2

# Get the latest ITK git tag
latest_git_tag=$(git ls-remote --tags --sort="v:refname" \
git://github.com/InsightSoftwareConsortium/ITK.git | tail -n1 | \
sed 's/.*\///; s/\^{}//')

# Azure pipeline CI file
git_tag_label='ITKGitTag: '

# Read the ITK git tag information
curr_git_str=($(grep $git_tag_label $filename))
curr_git_tag=${curr_git_str[1]}

# Sed the latest ITK git tag in the Azure pipelines config file
sed -i "s/${curr_git_tag}/${latest_git_tag}/g" $azure_pipelines_ci_filename

# Python setup file

# Strip the "v" prefix
latest_git_tag=${latest_git_tag:1}

git_install_req_tag_label='\install_requires=\['

# Read the ITK install requirement git tag information
git_install_req_tag_str=($(grep -A1 -P ${git_install_req_tag_label}$ $filename))
git_install_req_tag=${git_install_req_tag_str[1]}

git_install_req_tag_arr=($(echo $git_install_req_tag | tr "=" " "))
curr_git_tag=${git_install_req_tag_arr[-1]}

# Sed the latest ITK git tag in the Python setup file
sed -i "s/${curr_git_tag}/${latest_git_tag}/g" $python_setup_filename
Loading