Repository: InsightSoftwareConsortium/ITK-Wasm (language: python)

Issue:
feat(SupportInputImageTypes): Support VectorImage as template special…
…ization

Reduces binary sizes, simplifies usage for pipelines that cannot support VectorImage.


Discussion / hints:
:tada: This PR is included in version 1.0.0-b.45 :tada:

The release is available on:
- [npm package (@beta dist-tag)](https://www.npmjs.com/package/itk-wasm/v/1.0.0-b.45)
- [npm package (@beta dist-tag)](https://www.npmjs.com/package/itk-image-io/v/1.0.0-b.45)
- [npm package (@beta dist-tag)](https://www.npmjs.com/package/itk-mesh-io/v/1.0.0-b.45)
- [GitHub release](https://github.com/InsightSoftwareConsortium/itk-wasm/releases/tag/itk-wasm-v1.0.0-b.45)

Your **[semantic-release](https://github.com/semantic-release/semantic-release)** bot :package::rocket:

Fix patch:
diff --git a/doc/RELEASE.md b/doc/RELEASE.md
deleted file mode 100644
index 2a2dad113..000000000
--- a/doc/RELEASE.md
+++ /dev/null
@@ -1,42 +0,0 @@
-- To release a new version of itk-wasm on npmjs:
-
-Verify the source tree.
-
-```
-git checkout master
-git pull upstream master
-git clean -fdx
-npm ci
-version=6.0.0 # change to correct version
-
-# Update the `defaultImageTag` in src/itk-wasm-cli.js
-# Based on:
-#
-#   echo $(date '+%Y%m%d')-$(git rev-parse --short HEAD)
-#
-./src/docker/build.sh --with-debug
-# DockerHub credential environmental variables must be set
-./src/docker/push.sh
-git add -- src/itk-wasm-cli.js
-git commit -m "feat(itk-wasm-cli): Update default Docker image for ${version}"
-```
-
-Bump `version` in `package.json`, `package-lock.json`, `src/itkConfig.ts`. `itkConfigDevelopment.ts`
-
-```
-git add -- package.json package-lock.json src/itkConfig.ts webpack.config.cjs
-git commit -m "feat(version): Bump version to ${version}"
-npm run build
-npm run test
-npm publish
-cd dist/image-io
-npm publish
-cd -
-cd dist/mesh-io
-npm publish
-cd -
-git tag -m "itk-wasm ${version}" -s itk-wasm-v$version HEAD
-git checkout release
-git merge master
-git push --tags upstream release master
-```
diff --git a/include/itkSupportInputImageTypesNoVectorImage.h b/include/itkSupportInputImageTypesNoVectorImage.h
deleted file mode 100644
index 3502c765d..000000000
--- a/include/itkSupportInputImageTypesNoVectorImage.h
+++ /dev/null
@@ -1,182 +0,0 @@
-/*=========================================================================
- *
- *  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.
- *
- *=========================================================================*/
-#ifndef itkSupportInputImageTypesNoVectorImage_h
-#define itkSupportInputImageTypesNoVectorImage_h
-#include "itkPipeline.h"
-#include "itkWASMPixelTypeFromIOPixelEnum.h"
-#include "itkWASMComponentTypeFromIOComponentEnum.h"
-#include "itkDefaultConvertPixelTraits.h"
-#include "itkWASMMapComponentType.h"
-#include "itkWASMMapPixelType.h"
-
-#include "itkImage.h"
-#include "itkVectorImage.h"
-#include "itkImageIOBase.h"
-#include "itkImageIOFactory.h"
-
-namespace itk
-{
-
-namespace wasm
-{
-
-struct InterfaceImageTypeNoVectorImage
-{
-  unsigned int dimension{2};
-  std::string componentType{"uint8"};
-  std::string pixelType{"Scalar"};
-  unsigned int components{1};
-};
-
-bool lexical_cast(const std::string &input, InterfaceImageTypeNoVectorImage & imageType);
-
-/** \class SupportInputImageTypesNoVectorImage
- *
- * \brief Instantiatiate a Pipeline functor over multiple pixel types and dimensions and match to the input image type.
- *
- * Instantiate the PipelineFunctor (function object) over multiple pixel types and image dimensions.
- *  If the input image matches these pixel types or dimensions, use the compile-time optimized pipeline for that image type.
- *  Otherwise, exit the pipeline with an error identifying the unsupported image type.
- *
- * Example usage:
- *
-```
-template<typename TImage>
-class PipelineFunctor
-{
-public:
-  int operator()(itk::wasm::Pipeline & pipeline)
-  {
-    using ImageType = TImage;
-
-    using InputImageType = itk::wasm::InputImage<ImageType>;
-    InputImageType inputImage;
-    pipeline.add_option("input-image", inputImage, "The input image")->required();
-```
-[...]
-
-```
-int
-main(int argc, char * argv[])
-{
-  itk::wasm::Pipeline pipeline("support-multiple", "Test supporting multiple input image types", argc, argv);
-
-  // Supports the pixels types uint8_t, float
-  // Supports the image dimensions 2, 3
-  return itk::wasm::SupportInputImageTypesNoVectorImage<PipelineFunctor,
-   uint8_t,
-   float>
-  ::Dimensions<2U,3U>("input-image", pipeline);
-}
-```
- *
- * \ingroup WebAssemblyInterface
- */
-template<template <typename TImage> class TPipelineFunctor, typename ...TPixels>
-class
-SupportInputImageTypesNoVectorImage
-{
-public:
-  template<unsigned int ...VDimensions>
-  static int
-  Dimensions(const std::string & inputImageOptionName, Pipeline & pipeline)
-  {
-    InterfaceImageTypeNoVectorImage imageType;
-    const auto iwpArgc = pipeline.get_argc();
-    const auto iwpArgv = pipeline.get_argv();
-    bool passThrough = false;
-    for (int ii = 0; ii < iwpArgc; ++ii)
-      {
-        const std::string arg(iwpArgv[ii]);
-        if (arg == "-h" || arg == "--help")
-        {
-          passThrough = true;
-        }
-      }
-    if (passThrough)
-    {
-      return IterateDimensions<VDimensions...>(pipeline, imageType, passThrough);
-    }
-    auto tempOption = pipeline.add_option(inputImageOptionName, imageType, "Read image type.");
-
-    ITK_WASM_PRE_PARSE(pipeline);
-
-    pipeline.remove_option(tempOption);
-
-    return IterateDimensions<VDimensions...>(pipeline, imageType, passThrough);
-  }
-
-private:
-  template<unsigned int VDimension, typename TPixel, typename ...TPixelsRest>
-  static int
-  IteratePixelTypes(Pipeline & pipeline, const InterfaceImageTypeNoVectorImage & imageType, bool passThrough = false)
-  {
-    constexpr unsigned int Dimension = VDimension;
-    using PixelType = TPixel;
-    using ConvertPixelTraits = DefaultConvertPixelTraits<PixelType>;
-
-    if (passThrough || imageType.componentType == MapComponentType<typename ConvertPixelTraits::ComponentType>::ComponentString && imageType.pixelType == MapPixelType<PixelType>::PixelString)
-    {
-      if (imageType.pixelType == "VariableLengthVector" || imageType.pixelType == "VariableSizeMatrix" )
-      {
-        CLI::Error err("Runtime error", "VectorImage is not supported", 1);
-        return pipeline.exit(err);
-      }
-      else if(passThrough || imageType.components == ConvertPixelTraits::GetNumberOfComponents() )
-      {
-        using ImageType = Image<PixelType, Dimension>;
-
-        using PipelineType = TPipelineFunctor<ImageType>;
-        return PipelineType()(pipeline);
-      }
-    }
-
-    if constexpr (sizeof...(TPixelsRest) > 0) {
-      return IteratePixelTypes<VDimension, TPixelsRest...>(pipeline, imageType);
-    }
-
-    std::ostringstream ostrm;
-    ostrm << "Unsupported pixel type: " << imageType.pixelType << " with component type: " << imageType.componentType << " and components: " << imageType.components;
-    CLI::Error err("Runtime error", ostrm.str(), 1);
-    return pipeline.exit(err);
-  }
-
-  template<unsigned int VDimension, unsigned int ...VDimensions>
-  static int
-  IterateDimensions(Pipeline & pipeline, const InterfaceImageTypeNoVectorImage & imageType, bool passThrough = false)
-  {
-    if (passThrough || VDimension == imageType.dimension)
-    {
-      return IteratePixelTypes<VDimension, TPixels...>(pipeline, imageType, passThrough);
-    }
-
-    if constexpr (sizeof...(VDimensions) > 0) {
-      return IterateDimensions<VDimensions...>(pipeline, imageType);
-    }
-
-    std::ostringstream ostrm;
-    ostrm << "Unsupported image dimension: " << imageType.dimension;
-    CLI::Error err("Runtime error", ostrm.str(), 1);
-    return pipeline.exit(err);
-  }
-};
-
-} // end namespace wasm
-} // end namespace itk
-
-#endif
diff --git a/src/core/InterfaceTypes.ts b/src/core/InterfaceTypes.ts
index 921dba43c..7e4aadfca 100644
--- a/src/core/InterfaceTypes.ts
+++ b/src/core/InterfaceTypes.ts
@@ -7,7 +7,7 @@ const InterfaceTypes = {
   Image: 'InterfaceImage',
   Mesh: 'InterfaceMesh',
   PolyData: 'InterfacePolyData',
-  JsonObject: 'InterfaceJsonObject',
+  JsonObject: 'InterfaceJsonObject'
 } as const
 
 export default InterfaceTypes
diff --git a/src/docker/RELEASE.md b/src/docker/RELEASE.md
new file mode 100644
index 000000000..ff3177446
--- /dev/null
+++ b/src/docker/RELEASE.md
@@ -0,0 +1,21 @@
+- To release a new version of itk-wasm on npmjs:
+
+Verify the source tree.
+
+```
+git checkout master
+git pull upstream master
+git clean -fdx
+npm ci
+
+# Update the `defaultImageTag` in src/itk-wasm-cli.js
+# Based on:
+#
+#   echo $(date '+%Y%m%d')-$(git rev-parse --short HEAD)
+#
+./src/docker/build.sh --with-debug
+# DockerHub credential environmental variables must be set
+./src/docker/push.sh
+git add -- src/itk-wasm-cli.js
+git commit -m "feat(itk-wasm-cli): Update default Docker image for $(date '+%Y%m%d')-$(git rev-parse --short HEAD)"
+```
diff --git a/src/itk-wasm-cli.js b/src/itk-wasm-cli.js
index 319207053..9df38d1bf 100755
--- a/src/itk-wasm-cli.js
+++ b/src/itk-wasm-cli.js
@@ -8,7 +8,8 @@ import { Command, Option } from 'commander/esm.mjs'
 
 const program = new Command()
 
-const defaultImageTag = '20221006-7277a6da'
+
+const defaultImageTag = '20221101-8f65383f'
 
 // Array of types that will require an import from itk-wasm
 const typesRequireImport = ['Image']
diff --git a/src/itkSupportInputImageTypesNoVectorImage.cxx b/src/itkSupportInputImageTypesNoVectorImage.cxx
deleted file mode 100644
index d5760eab6..000000000
--- a/src/itkSupportInputImageTypesNoVectorImage.cxx
+++ /dev/null
@@ -1,77 +0,0 @@
-/*=========================================================================
- *
- *  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 "itkSupportInputImageTypesNoVectorImage.h"
-#include "itkWASMExports.h"
-
-#include "rapidjson/document.h"
-
-namespace itk
-{
-
-namespace wasm
-{
-
-bool lexical_cast(const std::string &input, InterfaceImageTypeNoVectorImage & imageType)
-{
-  if (wasm::Pipeline::get_use_memory_io())
-  {
-#ifndef ITK_WASM_NO_MEMORY_IO
-    const unsigned int index = std::stoi(input);
-    auto json = getMemoryStoreInputJSON(0, index);
-    rapidjson::Document document;
-    if (document.Parse(json.c_str()).HasParseError())
-      {
-      throw std::runtime_error("Could not parse JSON");
-      }
-
-    const rapidjson::Value & jsonImageType = document["imageType"];
-    imageType.dimension = jsonImageType["dimension"].GetInt();
-    imageType.componentType = jsonImageType["componentType"].GetString();
-    imageType.pixelType = jsonImageType["pixelType"].GetString();
-    imageType.components = jsonImageType["components"].GetInt();
-#else
-    return false;
-#endif
-  }
-  else
-  {
-#ifndef ITK_WASM_NO_FILESYSTEM_IO
-    ImageIOBase::Pointer imageIO = ImageIOFactory::CreateImageIO(input.c_str(), CommonEnums::IOFileMode::ReadMode);
-    imageIO->SetFileName(input);
-    imageIO->ReadImageInformation();
-
-    imageType.dimension = imageIO->GetNumberOfDimensions();
-
-    using IOComponentType = itk::IOComponentEnum;
-    const IOComponentType ioComponentEnum = imageIO->GetComponentType();
-    imageType.componentType = WASMComponentTypeFromIOComponentEnum( ioComponentEnum );
-
-    using IOPixelType = itk::IOPixelEnum;
-    const IOPixelType ioPixelEnum = imageIO->GetPixelType();
-    imageType.pixelType = WASMPixelTypeFromIOPixelEnum( ioPixelEnum );
-
-    imageType.components = imageIO->GetNumberOfComponents();
-#else
-    return false;
-#endif
-  }
-  return true;
-}
-
-} // end namespace wasm
-} // end namespace itk


Test patch:
diff --git a/test/pipelines/median-filter-pipeline/median-filter-test.cxx b/test/pipelines/median-filter-pipeline/median-filter-test.cxx
index 00d3098c9..813d884f1 100644
--- a/test/pipelines/median-filter-pipeline/median-filter-test.cxx
+++ b/test/pipelines/median-filter-pipeline/median-filter-test.cxx
@@ -21,7 +21,7 @@
 #include "itkPipeline.h"
 #include "itkInputImage.h"
 #include "itkOutputImage.h"
-#include "itkSupportInputImageTypesNoVectorImage.h"
+#include "itkSupportInputImageTypes.h"
 #include "itkRGBPixel.h"
 #include "itkRGBToLuminanceImageFilter.h"
 #include "itkNumericTraits.h"
@@ -138,7 +138,7 @@ int main( int argc, char * argv[] )
 {
   itk::wasm::Pipeline pipeline("median-filter", "Apply a median filter to an image", argc, argv);
 
-  return itk::wasm::SupportInputImageTypesNoVectorImage<PipelineFunctor,
+  return itk::wasm::SupportInputImageTypes<PipelineFunctor,
    uint8_t,
    itk::RGBPixel< uint8_t >,
    float>