From 999c42e343976c877fa9bcb2407642d6ae0f3283 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 26 Jan 2025 09:03:34 -0600 Subject: [PATCH 1/7] style(itk-wasm): Add itkVirtualGetNameOfClassMacro + itkOverrideGetNameOfClassMacro Added two new macro's, intended to replace the old 'itkTypeMacro' and 'itkTypeMacroNoParent'. The main aim is to be clearer about what those macro's do: add a virtual 'GetNameOfClass()' member function and override it. Unlike 'itkTypeMacro', 'itkOverrideGetNameOfClassMacro' does not have a 'superclass' parameter, as it was not used anyway. Note that originally 'itkTypeMacro' did not use its 'superclass' parameter either, looking at commit 699b66cb04d410e555656828e8892107add38ccb, Will Schroeder, June 27, 2001: https://github.com/InsightSoftwareConsortium/ITK/blob/699b66cb04d410e555656828e8892107add38ccb/Code/Common/itkMacro.h#L331-L337 --- include/itkImageToWasmImageFilter.h | 2 +- include/itkImportVectorImageFilter.h | 2 +- include/itkMeshToWasmMeshFilter.h | 2 +- include/itkPointSetToWasmPointSetFilter.h | 2 +- include/itkPolyDataToWasmPolyDataFilter.h | 2 +- include/itkTransformToWasmTransformFilter.h | 2 +- include/itkWasmDataObject.h | 2 +- include/itkWasmImage.h | 2 +- include/itkWasmImageIO.h | 2 +- include/itkWasmImageIOFactory.h | 2 +- include/itkWasmImageToImageFilter.h | 2 +- include/itkWasmMesh.h | 2 +- include/itkWasmMeshIO.h | 2 +- include/itkWasmMeshIOFactory.h | 2 +- include/itkWasmMeshToMeshFilter.h | 2 +- include/itkWasmPointSet.h | 2 +- include/itkWasmPointSetToPointSetFilter.h | 2 +- include/itkWasmPolyData.h | 2 +- include/itkWasmPolyDataToPolyDataFilter.h | 2 +- include/itkWasmStringStream.h | 2 +- include/itkWasmTransform.h | 2 +- include/itkWasmTransformIO.h | 2 +- include/itkWasmTransformIOFactory.h | 2 +- include/itkWasmTransformToTransformFilter.h | 2 +- packages/dicom/gdcm/read-image-dicom-file-series.cxx | 2 +- packages/image-io/itkWasmImageIOBase.h | 2 +- packages/image-io/itkWasmZstdImageIO.h | 2 +- packages/mesh-io/itkWasmMeshIOBase.h | 2 +- packages/mesh-io/itkWasmPointSetIOBase.h | 2 +- packages/mesh-io/itkWasmZstdMeshIO.h | 2 +- packages/transform-io/itkWasmTransformIOBase.h | 2 +- packages/transform-io/itkWasmZstdTransformIO.h | 2 +- 32 files changed, 32 insertions(+), 32 deletions(-) diff --git a/include/itkImageToWasmImageFilter.h b/include/itkImageToWasmImageFilter.h index 05ddbc60f..b3a84cf9d 100644 --- a/include/itkImageToWasmImageFilter.h +++ b/include/itkImageToWasmImageFilter.h @@ -45,7 +45,7 @@ class ITK_TEMPLATE_EXPORT ImageToWasmImageFilter : public ProcessObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(ImageToWasmImageFilter, ProcessObject); + itkOverrideGetNameOfClassMacro(ImageToWasmImageFilter); using DataObjectIdentifierType = Superclass::DataObjectIdentifierType; using DataObjectPointerArraySizeType = Superclass::DataObjectPointerArraySizeType; diff --git a/include/itkImportVectorImageFilter.h b/include/itkImportVectorImageFilter.h index fb73b541a..23f365d03 100644 --- a/include/itkImportVectorImageFilter.h +++ b/include/itkImportVectorImageFilter.h @@ -64,7 +64,7 @@ class ITK_TEMPLATE_EXPORT ImportVectorImageFilter : public ImageSource; diff --git a/include/itkMeshToWasmMeshFilter.h b/include/itkMeshToWasmMeshFilter.h index ebc881367..b9d512dc4 100644 --- a/include/itkMeshToWasmMeshFilter.h +++ b/include/itkMeshToWasmMeshFilter.h @@ -47,7 +47,7 @@ class ITK_TEMPLATE_EXPORT MeshToWasmMeshFilter : public ProcessObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(MeshToWasmMeshFilter, ProcessObject); + itkOverrideGetNameOfClassMacro(MeshToWasmMeshFilter); using DataObjectIdentifierType = Superclass::DataObjectIdentifierType; using DataObjectPointerArraySizeType = Superclass::DataObjectPointerArraySizeType; diff --git a/include/itkPointSetToWasmPointSetFilter.h b/include/itkPointSetToWasmPointSetFilter.h index 74cf39cb6..9c6912239 100644 --- a/include/itkPointSetToWasmPointSetFilter.h +++ b/include/itkPointSetToWasmPointSetFilter.h @@ -45,7 +45,7 @@ class ITK_TEMPLATE_EXPORT PointSetToWasmPointSetFilter : public ProcessObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(PointSetToWasmPointSetFilter, ProcessObject); + itkOverrideGetNameOfClassMacro(PointSetToWasmPointSetFilter); using DataObjectIdentifierType = Superclass::DataObjectIdentifierType; using DataObjectPointerArraySizeType = Superclass::DataObjectPointerArraySizeType; diff --git a/include/itkPolyDataToWasmPolyDataFilter.h b/include/itkPolyDataToWasmPolyDataFilter.h index 4eed0ef17..f6d8fe6cd 100644 --- a/include/itkPolyDataToWasmPolyDataFilter.h +++ b/include/itkPolyDataToWasmPolyDataFilter.h @@ -45,7 +45,7 @@ class ITK_TEMPLATE_EXPORT PolyDataToWasmPolyDataFilter : public ProcessObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(PolyDataToWasmPolyDataFilter, ProcessObject); + itkOverrideGetNameOfClassMacro(PolyDataToWasmPolyDataFilter); using DataObjectIdentifierType = Superclass::DataObjectIdentifierType; using DataObjectPointerArraySizeType = Superclass::DataObjectPointerArraySizeType; diff --git a/include/itkTransformToWasmTransformFilter.h b/include/itkTransformToWasmTransformFilter.h index 0eb539c5d..18da157e4 100644 --- a/include/itkTransformToWasmTransformFilter.h +++ b/include/itkTransformToWasmTransformFilter.h @@ -47,7 +47,7 @@ class ITK_TEMPLATE_EXPORT TransformToWasmTransformFilter : public ProcessObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(TransformToWasmTransformFilter, ProcessObject); + itkOverrideGetNameOfClassMacro(TransformToWasmTransformFilter); using DataObjectIdentifierType = Superclass::DataObjectIdentifierType; using DataObjectPointerArraySizeType = Superclass::DataObjectPointerArraySizeType; diff --git a/include/itkWasmDataObject.h b/include/itkWasmDataObject.h index 55a614468..c1f4b7059 100644 --- a/include/itkWasmDataObject.h +++ b/include/itkWasmDataObject.h @@ -43,7 +43,7 @@ class WebAssemblyInterface_EXPORT WasmDataObject : public DataObject using Pointer = SmartPointer; using ConstPointer = SmartPointer; itkNewMacro(Self); - itkTypeMacro(WasmDataObject, DataObject); + itkOverrideGetNameOfClassMacro(WasmDataObject); /** Get/Set the DataObject JSON representation. */ itkSetStringMacro(JSON); diff --git a/include/itkWasmImage.h b/include/itkWasmImage.h index ab99c4eaf..d89764463 100644 --- a/include/itkWasmImage.h +++ b/include/itkWasmImage.h @@ -51,7 +51,7 @@ class ITK_TEMPLATE_EXPORT WasmImage : public WasmDataObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmImage, WasmDataObject); + itkOverrideGetNameOfClassMacro(WasmImage); using ImageType = TImage; diff --git a/include/itkWasmImageIO.h b/include/itkWasmImageIO.h index 43cfec358..d5d7e354e 100644 --- a/include/itkWasmImageIO.h +++ b/include/itkWasmImageIO.h @@ -51,7 +51,7 @@ class WebAssemblyInterface_EXPORT WasmImageIO: public StreamingImageIOBase itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmImageIO, StreamingImageIOBase); + itkOverrideGetNameOfClassMacro(WasmImageIO); /** The different types of ImageIO's can support data of varying * dimensionality. For example, some file formats are strictly 2D diff --git a/include/itkWasmImageIOFactory.h b/include/itkWasmImageIOFactory.h index 8359fffc8..484656f7b 100644 --- a/include/itkWasmImageIOFactory.h +++ b/include/itkWasmImageIOFactory.h @@ -48,7 +48,7 @@ class WebAssemblyInterface_EXPORT WasmImageIOFactory: public ObjectFactoryBase itkFactorylessNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmImageIOFactory, ObjectFactoryBase); + itkOverrideGetNameOfClassMacro(WasmImageIOFactory); /** Register one factory of this type */ static void RegisterOneFactory(void) diff --git a/include/itkWasmImageToImageFilter.h b/include/itkWasmImageToImageFilter.h index d07b552a7..72eb0f908 100644 --- a/include/itkWasmImageToImageFilter.h +++ b/include/itkWasmImageToImageFilter.h @@ -47,7 +47,7 @@ class ITK_TEMPLATE_EXPORT WasmImageToImageFilter : public ProcessObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmImageToImageFilter, ProcessObject); + itkOverrideGetNameOfClassMacro(WasmImageToImageFilter); using DataObjectIdentifierType = Superclass::DataObjectIdentifierType; using DataObjectPointerArraySizeType = Superclass::DataObjectPointerArraySizeType; diff --git a/include/itkWasmMesh.h b/include/itkWasmMesh.h index da586c30b..32f4efbf1 100644 --- a/include/itkWasmMesh.h +++ b/include/itkWasmMesh.h @@ -53,7 +53,7 @@ class ITK_TEMPLATE_EXPORT WasmMesh : public WasmDataObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmMesh, WasmDataObject); + itkOverrideGetNameOfClassMacro(WasmMesh); using MeshType = TMesh; diff --git a/include/itkWasmMeshIO.h b/include/itkWasmMeshIO.h index d7f473db3..1bef97079 100644 --- a/include/itkWasmMeshIO.h +++ b/include/itkWasmMeshIO.h @@ -53,7 +53,7 @@ class WebAssemblyInterface_EXPORT WasmMeshIO: public MeshIOBase itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmMeshIO, MeshIOBase); + itkOverrideGetNameOfClassMacro(WasmMeshIO); bool CanReadFile(const char *) override; diff --git a/include/itkWasmMeshIOFactory.h b/include/itkWasmMeshIOFactory.h index 9177abb7a..92209ca8a 100644 --- a/include/itkWasmMeshIOFactory.h +++ b/include/itkWasmMeshIOFactory.h @@ -48,7 +48,7 @@ class WebAssemblyInterface_EXPORT WasmMeshIOFactory: public ObjectFactoryBase itkFactorylessNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmMeshIOFactory, ObjectFactoryBase); + itkOverrideGetNameOfClassMacro(WasmMeshIOFactory); /** Register one factory of this type */ static void RegisterOneFactory() diff --git a/include/itkWasmMeshToMeshFilter.h b/include/itkWasmMeshToMeshFilter.h index 7364d3eaf..475309a21 100644 --- a/include/itkWasmMeshToMeshFilter.h +++ b/include/itkWasmMeshToMeshFilter.h @@ -47,7 +47,7 @@ class ITK_TEMPLATE_EXPORT WasmMeshToMeshFilter : public ProcessObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmMeshToMeshFilter, ProcessObject); + itkOverrideGetNameOfClassMacro(WasmMeshToMeshFilter); using DataObjectIdentifierType = Superclass::DataObjectIdentifierType; using DataObjectPointerArraySizeType = Superclass::DataObjectPointerArraySizeType; diff --git a/include/itkWasmPointSet.h b/include/itkWasmPointSet.h index 13a5af577..ba93c056c 100644 --- a/include/itkWasmPointSet.h +++ b/include/itkWasmPointSet.h @@ -50,7 +50,7 @@ class ITK_TEMPLATE_EXPORT WasmPointSet : public WasmDataObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmPointSet, WasmDataObject); + itkOverrideGetNameOfClassMacro(WasmPointSet); using PointSetType = TPointSet; diff --git a/include/itkWasmPointSetToPointSetFilter.h b/include/itkWasmPointSetToPointSetFilter.h index f14ac31b0..1bf9fc4d7 100644 --- a/include/itkWasmPointSetToPointSetFilter.h +++ b/include/itkWasmPointSetToPointSetFilter.h @@ -47,7 +47,7 @@ class ITK_TEMPLATE_EXPORT WasmPointSetToPointSetFilter : public ProcessObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmPointSetToPointSetFilter, ProcessObject); + itkOverrideGetNameOfClassMacro(WasmPointSetToPointSetFilter); using DataObjectIdentifierType = Superclass::DataObjectIdentifierType; using DataObjectPointerArraySizeType = Superclass::DataObjectPointerArraySizeType; diff --git a/include/itkWasmPolyData.h b/include/itkWasmPolyData.h index 1d883d180..f36f0bb05 100644 --- a/include/itkWasmPolyData.h +++ b/include/itkWasmPolyData.h @@ -55,7 +55,7 @@ class ITK_TEMPLATE_EXPORT WasmPolyData : public WasmDataObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmPolyData, WasmDataObject); + itkOverrideGetNameOfClassMacro(WasmPolyData); using PolyDataType = TPolyData; diff --git a/include/itkWasmPolyDataToPolyDataFilter.h b/include/itkWasmPolyDataToPolyDataFilter.h index a52217073..fd2b6d982 100644 --- a/include/itkWasmPolyDataToPolyDataFilter.h +++ b/include/itkWasmPolyDataToPolyDataFilter.h @@ -47,7 +47,7 @@ class ITK_TEMPLATE_EXPORT WasmPolyDataToPolyDataFilter : public ProcessObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmPolyDataToPolyDataFilter, ProcessObject); + itkOverrideGetNameOfClassMacro(WasmPolyDataToPolyDataFilter); using DataObjectIdentifierType = Superclass::DataObjectIdentifierType; using DataObjectPointerArraySizeType = Superclass::DataObjectPointerArraySizeType; diff --git a/include/itkWasmStringStream.h b/include/itkWasmStringStream.h index 396f9fe46..89a6d8083 100644 --- a/include/itkWasmStringStream.h +++ b/include/itkWasmStringStream.h @@ -63,7 +63,7 @@ class WebAssemblyInterface_EXPORT WasmStringStream : public WasmDataObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmStringStream, WasmDataObject); + itkOverrideGetNameOfClassMacro(WasmStringStream); void SetString(const std::string & string) { this->m_StringStream.str(string); diff --git a/include/itkWasmTransform.h b/include/itkWasmTransform.h index ce0f11c69..ed4e11cca 100644 --- a/include/itkWasmTransform.h +++ b/include/itkWasmTransform.h @@ -57,7 +57,7 @@ class ITK_TEMPLATE_EXPORT WasmTransform : public WasmDataObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmTransform, WasmDataObject); + itkOverrideGetNameOfClassMacro(WasmTransform); using TransformType = TTransform; using DecoratorType = DataObjectDecorator; diff --git a/include/itkWasmTransformIO.h b/include/itkWasmTransformIO.h index ad616f673..ad80fc29d 100644 --- a/include/itkWasmTransformIO.h +++ b/include/itkWasmTransformIO.h @@ -62,7 +62,7 @@ class ITK_TEMPLATE_EXPORT WasmTransformIOTemplate : public TransformIOBaseTempla itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmTransformIOTemplate, TransformIOBaseTemplate); + itkOverrideGetNameOfClassMacro(WasmTransformIOTemplate); /** Reads the data from disk into the memory buffer provided. */ void diff --git a/include/itkWasmTransformIOFactory.h b/include/itkWasmTransformIOFactory.h index 87ff92503..b7a9ab06e 100644 --- a/include/itkWasmTransformIOFactory.h +++ b/include/itkWasmTransformIOFactory.h @@ -50,7 +50,7 @@ class WebAssemblyInterface_EXPORT WasmTransformIOFactory : public ObjectFactoryB itkFactorylessNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmTransformIOFactory, ObjectFactoryBase); + itkOverrideGetNameOfClassMacro(WasmTransformIOFactory); /** Register one factory of this type */ static void diff --git a/include/itkWasmTransformToTransformFilter.h b/include/itkWasmTransformToTransformFilter.h index f1a8ea640..7eef724f5 100644 --- a/include/itkWasmTransformToTransformFilter.h +++ b/include/itkWasmTransformToTransformFilter.h @@ -48,7 +48,7 @@ class ITK_TEMPLATE_EXPORT WasmTransformToTransformFilter : public ProcessObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmTransformToTransformFilter, ProcessObject); + itkOverrideGetNameOfClassMacro(WasmTransformToTransformFilter); using DataObjectIdentifierType = Superclass::DataObjectIdentifierType; using DataObjectPointerArraySizeType = Superclass::DataObjectPointerArraySizeType; diff --git a/packages/dicom/gdcm/read-image-dicom-file-series.cxx b/packages/dicom/gdcm/read-image-dicom-file-series.cxx index c93e51ea7..af1f0cc43 100644 --- a/packages/dicom/gdcm/read-image-dicom-file-series.cxx +++ b/packages/dicom/gdcm/read-image-dicom-file-series.cxx @@ -63,7 +63,7 @@ class ITK_TEMPLATE_EXPORT QuickDICOMImageSeriesReader : public ImageSeriesReader itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(QuickDICOMImageSeriesReader, ImageSeriesReader); + itkOverrideGetNameOfClassMacro(QuickDICOMImageSeriesReader); /** The size of the output image. */ using SizeType = typename TOutputImage::SizeType; diff --git a/packages/image-io/itkWasmImageIOBase.h b/packages/image-io/itkWasmImageIOBase.h index 1b4ae5e81..a67a51e69 100644 --- a/packages/image-io/itkWasmImageIOBase.h +++ b/packages/image-io/itkWasmImageIOBase.h @@ -53,7 +53,7 @@ class WebAssemblyInterface_EXPORT WasmImageIOBase : public WasmDataObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmImageIOBase, WasmDataObject); + itkOverrideGetNameOfClassMacro(WasmImageIOBase); using DirectionContainerType = VectorContainer; using PixelDataContainerType = VectorContainer; diff --git a/packages/image-io/itkWasmZstdImageIO.h b/packages/image-io/itkWasmZstdImageIO.h index e508a7729..6988dd541 100644 --- a/packages/image-io/itkWasmZstdImageIO.h +++ b/packages/image-io/itkWasmZstdImageIO.h @@ -50,7 +50,7 @@ class WebAssemblyInterface_EXPORT WasmZstdImageIO: public WasmImageIO itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmZstdImageIO, WasmImageIO); + itkOverrideGetNameOfClassMacro(WasmZstdImageIO); /** Determine the file type. Returns true if this ImageIO can read the * file specified. */ diff --git a/packages/mesh-io/itkWasmMeshIOBase.h b/packages/mesh-io/itkWasmMeshIOBase.h index 25899b04f..18f82e0bb 100644 --- a/packages/mesh-io/itkWasmMeshIOBase.h +++ b/packages/mesh-io/itkWasmMeshIOBase.h @@ -55,7 +55,7 @@ class WebAssemblyInterface_EXPORT WasmMeshIOBase : public WasmPointSetIOBase itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmMeshIOBase, WasmPointSetIOBase); + itkOverrideGetNameOfClassMacro(WasmMeshIOBase); using DataContainerType = Superclass::DataContainerType; diff --git a/packages/mesh-io/itkWasmPointSetIOBase.h b/packages/mesh-io/itkWasmPointSetIOBase.h index d27dab764..33a34b628 100644 --- a/packages/mesh-io/itkWasmPointSetIOBase.h +++ b/packages/mesh-io/itkWasmPointSetIOBase.h @@ -53,7 +53,7 @@ class WebAssemblyInterface_EXPORT WasmPointSetIOBase : public WasmDataObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmPointSetIOBase, WasmDataObject); + itkOverrideGetNameOfClassMacro(WasmPointSetIOBase); using DataContainerType = VectorContainer; diff --git a/packages/mesh-io/itkWasmZstdMeshIO.h b/packages/mesh-io/itkWasmZstdMeshIO.h index 5103a8085..f04d88610 100644 --- a/packages/mesh-io/itkWasmZstdMeshIO.h +++ b/packages/mesh-io/itkWasmZstdMeshIO.h @@ -50,7 +50,7 @@ class WebAssemblyInterface_EXPORT WasmZstdMeshIO: public WasmMeshIO itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmZstdMeshIO, WasmMeshIO); + itkOverrideGetNameOfClassMacro(WasmZstdMeshIO); /** Determine the file type. Returns true if this MeshIO can read the * file specified. */ diff --git a/packages/transform-io/itkWasmTransformIOBase.h b/packages/transform-io/itkWasmTransformIOBase.h index 972cf8e55..e93576e40 100644 --- a/packages/transform-io/itkWasmTransformIOBase.h +++ b/packages/transform-io/itkWasmTransformIOBase.h @@ -67,7 +67,7 @@ class WebAssemblyInterface_EXPORT WasmTransformIOBase : public WasmDataObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmTransformIOBase, WasmDataObject); + itkOverrideGetNameOfClassMacro(WasmTransformIOBase); void SetTransformIO(TransformIOBaseType * transformIO, bool readTransform = true) { diff --git a/packages/transform-io/itkWasmZstdTransformIO.h b/packages/transform-io/itkWasmZstdTransformIO.h index 4715ebb2b..e89d074e6 100644 --- a/packages/transform-io/itkWasmZstdTransformIO.h +++ b/packages/transform-io/itkWasmZstdTransformIO.h @@ -52,7 +52,7 @@ class ITK_TEMPLATE_EXPORT WasmZstdTransformIOTemplate: public WasmTransformIOTem itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(WasmZstdTransformIOTemplate, WasmTransformIOTemplate); + itkOverrideGetNameOfClassMacro(WasmZstdTransformIOTemplate); /** Determine the file type. Returns true if this TransformIO can read the * file specified. */ From e3080f63ede598d65a31512c6e8e5439f8f437f5 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 26 Jan 2025 09:18:39 -0600 Subject: [PATCH 2/7] style(itk-wasm): Rename ITK_DISALLOW_COPY_AND_ASSIGN to ITK_DISALLOW_COPY_AND_MOVE Clarifies that the macro does not just disallow copy and assign, but also move operations. Note that in this context, the term 'move' refers to both move-construct and move-assign. With this commit, the old macro name will remain available, as long as 'ITK_FUTURE_LEGACY_REMOVE = OFF' (which is the default). --- include/itkWasmImageIO.h | 2 +- include/itkWasmImageIOFactory.h | 2 +- include/itkWasmMeshIO.h | 2 +- include/itkWasmMeshIOFactory.h | 2 +- include/itkWasmTransformIO.h | 2 +- include/itkWasmTransformIOFactory.h | 2 +- packages/dicom/gdcm/read-image-dicom-file-series.cxx | 2 +- packages/image-io/itkWasmZstdImageIO.h | 2 +- packages/mesh-io/itkWasmZstdMeshIO.h | 2 +- packages/transform-io/itkWasmZstdTransformIO.h | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/itkWasmImageIO.h b/include/itkWasmImageIO.h index d5d7e354e..5b14f8c92 100644 --- a/include/itkWasmImageIO.h +++ b/include/itkWasmImageIO.h @@ -105,7 +105,7 @@ class WebAssemblyInterface_EXPORT WasmImageIO: public StreamingImageIOBase size_t WriteCBOR(const void * buffer = nullptr, unsigned char ** cborBuffer = nullptr, bool allocateCBORBuffer = false); private: - ITK_DISALLOW_COPY_AND_ASSIGN(WasmImageIO); + ITK_DISALLOW_COPY_AND_MOVE(WasmImageIO); }; } // end namespace itk diff --git a/include/itkWasmImageIOFactory.h b/include/itkWasmImageIOFactory.h index 484656f7b..50a4efc9a 100644 --- a/include/itkWasmImageIOFactory.h +++ b/include/itkWasmImageIOFactory.h @@ -63,7 +63,7 @@ class WebAssemblyInterface_EXPORT WasmImageIOFactory: public ObjectFactoryBase ~WasmImageIOFactory() override; private: - ITK_DISALLOW_COPY_AND_ASSIGN(WasmImageIOFactory); + ITK_DISALLOW_COPY_AND_MOVE(WasmImageIOFactory); }; } // end namespace itk diff --git a/include/itkWasmMeshIO.h b/include/itkWasmMeshIO.h index 1bef97079..d4098a011 100644 --- a/include/itkWasmMeshIO.h +++ b/include/itkWasmMeshIO.h @@ -115,7 +115,7 @@ class WebAssemblyInterface_EXPORT WasmMeshIO: public MeshIOBase cbor_item_t * m_CBORRoot{ nullptr }; private: - ITK_DISALLOW_COPY_AND_ASSIGN(WasmMeshIO); + ITK_DISALLOW_COPY_AND_MOVE(WasmMeshIO); }; } // end namespace itk diff --git a/include/itkWasmMeshIOFactory.h b/include/itkWasmMeshIOFactory.h index 92209ca8a..35f920987 100644 --- a/include/itkWasmMeshIOFactory.h +++ b/include/itkWasmMeshIOFactory.h @@ -63,7 +63,7 @@ class WebAssemblyInterface_EXPORT WasmMeshIOFactory: public ObjectFactoryBase ~WasmMeshIOFactory() override; private: - ITK_DISALLOW_COPY_AND_ASSIGN(WasmMeshIOFactory); + ITK_DISALLOW_COPY_AND_MOVE(WasmMeshIOFactory); }; } // end namespace itk diff --git a/include/itkWasmTransformIO.h b/include/itkWasmTransformIO.h index ad80fc29d..62e53682b 100644 --- a/include/itkWasmTransformIO.h +++ b/include/itkWasmTransformIO.h @@ -115,7 +115,7 @@ class ITK_TEMPLATE_EXPORT WasmTransformIOTemplate : public TransformIOBaseTempla cbor_item_t * m_CBORRoot{ nullptr }; private: - ITK_DISALLOW_COPY_AND_ASSIGN(WasmTransformIOTemplate); + ITK_DISALLOW_COPY_AND_MOVE(WasmTransformIOTemplate); }; } // end namespace itk diff --git a/include/itkWasmTransformIOFactory.h b/include/itkWasmTransformIOFactory.h index b7a9ab06e..672b3032f 100644 --- a/include/itkWasmTransformIOFactory.h +++ b/include/itkWasmTransformIOFactory.h @@ -66,7 +66,7 @@ class WebAssemblyInterface_EXPORT WasmTransformIOFactory : public ObjectFactoryB ~WasmTransformIOFactory() override; private: - ITK_DISALLOW_COPY_AND_ASSIGN(WasmTransformIOFactory); + ITK_DISALLOW_COPY_AND_MOVE(WasmTransformIOFactory); }; } // end namespace itk diff --git a/packages/dicom/gdcm/read-image-dicom-file-series.cxx b/packages/dicom/gdcm/read-image-dicom-file-series.cxx index af1f0cc43..fd486ed23 100644 --- a/packages/dicom/gdcm/read-image-dicom-file-series.cxx +++ b/packages/dicom/gdcm/read-image-dicom-file-series.cxx @@ -52,7 +52,7 @@ template class ITK_TEMPLATE_EXPORT QuickDICOMImageSeriesReader : public ImageSeriesReader { public: - ITK_DISALLOW_COPY_AND_ASSIGN(QuickDICOMImageSeriesReader); + ITK_DISALLOW_COPY_AND_MOVE(QuickDICOMImageSeriesReader); /** Standard class type aliases. */ using Self = QuickDICOMImageSeriesReader; diff --git a/packages/image-io/itkWasmZstdImageIO.h b/packages/image-io/itkWasmZstdImageIO.h index 6988dd541..5c9276f44 100644 --- a/packages/image-io/itkWasmZstdImageIO.h +++ b/packages/image-io/itkWasmZstdImageIO.h @@ -78,7 +78,7 @@ class WebAssemblyInterface_EXPORT WasmZstdImageIO: public WasmImageIO ~WasmZstdImageIO() override; private: - ITK_DISALLOW_COPY_AND_ASSIGN(WasmZstdImageIO); + ITK_DISALLOW_COPY_AND_MOVE(WasmZstdImageIO); }; } // end namespace itk diff --git a/packages/mesh-io/itkWasmZstdMeshIO.h b/packages/mesh-io/itkWasmZstdMeshIO.h index f04d88610..07f7cb2b2 100644 --- a/packages/mesh-io/itkWasmZstdMeshIO.h +++ b/packages/mesh-io/itkWasmZstdMeshIO.h @@ -70,7 +70,7 @@ class WebAssemblyInterface_EXPORT WasmZstdMeshIO: public WasmMeshIO ~WasmZstdMeshIO() override; private: - ITK_DISALLOW_COPY_AND_ASSIGN(WasmZstdMeshIO); + ITK_DISALLOW_COPY_AND_MOVE(WasmZstdMeshIO); }; } // end namespace itk diff --git a/packages/transform-io/itkWasmZstdTransformIO.h b/packages/transform-io/itkWasmZstdTransformIO.h index e89d074e6..0a93fd42e 100644 --- a/packages/transform-io/itkWasmZstdTransformIO.h +++ b/packages/transform-io/itkWasmZstdTransformIO.h @@ -74,7 +74,7 @@ class ITK_TEMPLATE_EXPORT WasmZstdTransformIOTemplate: public WasmTransformIOTem ~WasmZstdTransformIOTemplate() override; private: - ITK_DISALLOW_COPY_AND_ASSIGN(WasmZstdTransformIOTemplate); + ITK_DISALLOW_COPY_AND_MOVE(WasmZstdTransformIOTemplate); }; } // end namespace itk From 7d710dabfeb6b6e2dc30ef718e77240b28d41bd5 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 26 Jan 2025 12:58:26 -0600 Subject: [PATCH 3/7] style(itk-wasm): CoordRepType -> CoordinateType code readability For the sake of code readability, a new 'CoordinateType' alias is added for each nested 'CoordRepType' alias. The old 'CoordRepType' aliases will still be available with ITK 6.0, but it is recommended to use 'CoordinateType' instead. The 'CoordRepType' aliases will be removed when 'ITK_FUTURE_LEGACY_REMOVE' is enabled. Similarly, 'InputCoordinateType', 'OutputCoordinateType', and 'ImagePointCoordinateType' replace 'InputCoordRepType', 'OutputCoordRepType', and 'ImagePointCoordRepType', respectively. --- include/itkMeshJSON.h | 2 +- include/itkOutputMesh.h | 2 +- include/itkOutputPointSet.h | 2 +- include/itkOutputPolyData.h | 2 +- include/itkPointSetJSON.h | 2 +- include/itkWasmMeshToMeshFilter.hxx | 6 +++--- include/itkWasmPointSetToPointSetFilter.hxx | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/itkMeshJSON.h b/include/itkMeshJSON.h index 3cb055036..93cf9a639 100644 --- a/include/itkMeshJSON.h +++ b/include/itkMeshJSON.h @@ -89,7 +89,7 @@ auto meshToMeshJSON(const TMesh * mesh, const WasmMesh * wasmMesh, bool i meshJSON.meshType.dimension = MeshType::PointDimension; - meshJSON.meshType.pointComponentType = wasm::MapComponentType::JSONFloatTypeEnum; + meshJSON.meshType.pointComponentType = wasm::MapComponentType::JSONFloatTypeEnum; using PointPixelType = typename TMesh::PixelType; using ConvertPointPixelTraits = MeshConvertPixelTraits; meshJSON.meshType.pointPixelComponentType = wasm::MapComponentType::JSONComponentEnum; diff --git a/include/itkOutputMesh.h b/include/itkOutputMesh.h index b8c249c45..4fb21145b 100644 --- a/include/itkOutputMesh.h +++ b/include/itkOutputMesh.h @@ -88,7 +88,7 @@ class ITK_TEMPLATE_EXPORT OutputMesh if (this->m_Mesh->GetNumberOfPoints() > 0) { const auto pointsAddress = reinterpret_cast< size_t >( &(wasmMesh->GetMesh()->GetPoints()->at(0)) ); - const auto pointsSize = wasmMesh->GetMesh()->GetPoints()->Size() * sizeof(typename MeshType::CoordRepType) * MeshType::PointDimension; + const auto pointsSize = wasmMesh->GetMesh()->GetPoints()->Size() * sizeof(typename MeshType::CoordinateType) * MeshType::PointDimension; setMemoryStoreOutputArray(0, index, 0, pointsAddress, pointsSize); } diff --git a/include/itkOutputPointSet.h b/include/itkOutputPointSet.h index 7db40e72c..0289c9999 100644 --- a/include/itkOutputPointSet.h +++ b/include/itkOutputPointSet.h @@ -87,7 +87,7 @@ class ITK_TEMPLATE_EXPORT OutputPointSet if (this->m_PointSet->GetNumberOfPoints() > 0) { const auto pointsAddress = reinterpret_cast< size_t >( &(wasmPointSet->GetPointSet()->GetPoints()->at(0)) ); - const auto pointsSize = wasmPointSet->GetPointSet()->GetPoints()->Size() * sizeof(typename PointSetType::CoordRepType) * PointSetType::PointDimension; + const auto pointsSize = wasmPointSet->GetPointSet()->GetPoints()->Size() * sizeof(typename PointSetType::CoordinateType) * PointSetType::PointDimension; setMemoryStoreOutputArray(0, index, 0, pointsAddress, pointsSize); } diff --git a/include/itkOutputPolyData.h b/include/itkOutputPolyData.h index 6ffe7974a..2a9d57d26 100644 --- a/include/itkOutputPolyData.h +++ b/include/itkOutputPolyData.h @@ -87,7 +87,7 @@ class ITK_TEMPLATE_EXPORT OutputPolyData if (this->m_PolyData->GetNumberOfPoints() > 0) { const auto pointsAddress = reinterpret_cast< size_t >( &(wasmPolyData->GetPolyData()->GetPoints()->at(0)) ); - const auto pointsSize = wasmPolyData->GetPolyData()->GetPoints()->Size() * PolyDataType::PointDimension * sizeof(typename PolyDataType::CoordRepType); + const auto pointsSize = wasmPolyData->GetPolyData()->GetPoints()->Size() * PolyDataType::PointDimension * sizeof(typename PolyDataType::CoordinateType); setMemoryStoreOutputArray(0, index, 0, pointsAddress, pointsSize); } diff --git a/include/itkPointSetJSON.h b/include/itkPointSetJSON.h index a58bbe6f1..03f65c4db 100644 --- a/include/itkPointSetJSON.h +++ b/include/itkPointSetJSON.h @@ -77,7 +77,7 @@ auto pointSetToPointSetJSON(const TPointSet * pointSet, const WasmPointSet::JSONFloatTypeEnum; + pointSetJSON.pointSetType.pointComponentType = wasm::MapComponentType::JSONFloatTypeEnum; using PointPixelType = typename TPointSet::PixelType; using ConvertPointPixelTraits = MeshConvertPixelTraits; pointSetJSON.pointSetType.pointPixelComponentType = wasm::MapComponentType::JSONComponentEnum; diff --git a/include/itkWasmMeshToMeshFilter.hxx b/include/itkWasmMeshToMeshFilter.hxx index 17773920d..0e9c26017 100644 --- a/include/itkWasmMeshToMeshFilter.hxx +++ b/include/itkWasmMeshToMeshFilter.hxx @@ -440,7 +440,7 @@ WasmMeshToMeshFilter const std::string pointsString = meshJSON.points; if (numberOfPoints) { - if (pointComponentType == itk::wasm::MapComponentType::JSONFloatTypeEnum) + if (pointComponentType == itk::wasm::MapComponentType::JSONFloatTypeEnum) { const auto * pointsPtr = reinterpret_cast< PointType * >( std::strtoull(pointsString.substr(35).c_str(), nullptr, 10) ); mesh->GetPoints()->assign(pointsPtr, pointsPtr + meshJSON.numberOfPoints); @@ -449,14 +449,14 @@ WasmMeshToMeshFilter { auto * pointsPtr = reinterpret_cast< float * >( std::strtoull(pointsString.substr(35).c_str(), nullptr, 10) ); const size_t pointComponents = numberOfPoints * dimension; - auto * pointsContainerPtr = reinterpret_cast(&(mesh->GetPoints()->at(0)) ); + auto * pointsContainerPtr = reinterpret_cast(&(mesh->GetPoints()->at(0)) ); std::copy(pointsPtr, pointsPtr + pointComponents, pointsContainerPtr); } else if (pointComponentType == itk::wasm::MapComponentType::JSONFloatTypeEnum) { auto * pointsPtr = reinterpret_cast< double * >( std::strtoull(pointsString.substr(35).c_str(), nullptr, 10) ); const size_t pointComponents = numberOfPoints * dimension; - auto * pointsContainerPtr = reinterpret_cast(&(mesh->GetPoints()->at(0)) ); + auto * pointsContainerPtr = reinterpret_cast(&(mesh->GetPoints()->at(0)) ); std::copy(pointsPtr, pointsPtr + pointComponents, pointsContainerPtr); } else diff --git a/include/itkWasmPointSetToPointSetFilter.hxx b/include/itkWasmPointSetToPointSetFilter.hxx index a756bf2f5..cc1ca300a 100644 --- a/include/itkWasmPointSetToPointSetFilter.hxx +++ b/include/itkWasmPointSetToPointSetFilter.hxx @@ -173,7 +173,7 @@ WasmPointSetToPointSetFilter const std::string pointsString = pointSetJSON.points; if (numberOfPoints) { - if (pointComponentType == itk::wasm::MapComponentType::JSONFloatTypeEnum) + if (pointComponentType == itk::wasm::MapComponentType::JSONFloatTypeEnum) { const auto * pointsPtr = reinterpret_cast< PointType * >( std::strtoull(pointsString.substr(35).c_str(), nullptr, 10) ); pointSet->GetPoints()->assign(pointsPtr, pointsPtr + pointSetJSON.numberOfPoints); @@ -182,14 +182,14 @@ WasmPointSetToPointSetFilter { auto * pointsPtr = reinterpret_cast< float * >( std::strtoull(pointsString.substr(35).c_str(), nullptr, 10) ); const size_t pointComponents = numberOfPoints * dimension; - auto * pointsContainerPtr = reinterpret_cast(&(pointSet->GetPoints()->at(0)) ); + auto * pointsContainerPtr = reinterpret_cast(&(pointSet->GetPoints()->at(0)) ); std::copy(pointsPtr, pointsPtr + pointComponents, pointsContainerPtr); } else if (pointComponentType == itk::wasm::MapComponentType::JSONFloatTypeEnum) { auto * pointsPtr = reinterpret_cast< double * >( std::strtoull(pointsString.substr(35).c_str(), nullptr, 10) ); const size_t pointComponents = numberOfPoints * dimension; - auto * pointsContainerPtr = reinterpret_cast(&(pointSet->GetPoints()->at(0)) ); + auto * pointsContainerPtr = reinterpret_cast(&(pointSet->GetPoints()->at(0)) ); std::copy(pointsPtr, pointsPtr + pointComponents, pointsContainerPtr); } else From 78354bbbbd1c89d88081417eb6e2c07d0f7e37c0 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Mon, 27 Jan 2025 20:55:23 -0600 Subject: [PATCH 4/7] style(itk-wasm): Update to match clang-format-19 from ITK --- .clang-format | 318 ++++++++ examples/debugging/DebugMe.cxx | 8 +- .../different-input-types.cxx | 30 +- examples/hello-pipeline/hello-pipeline.cxx | 4 +- examples/inputs-outputs/inputs-outputs.cxx | 6 +- .../mean-squares-versor-registration.cxx | 36 +- include/itkComponentTypesJSON.h | 35 +- include/itkFloatTypesJSON.h | 17 +- include/itkIOPixelEnumFromWasmPixelType.h | 2 +- include/itkImageJSON.h | 100 +-- include/itkImageToWasmImageFilter.h | 2 +- include/itkImageToWasmImageFilter.hxx | 44 +- include/itkImportVectorImageFilter.h | 12 +- include/itkImportVectorImageFilter.hxx | 20 +- include/itkInputBinaryStream.h | 22 +- include/itkInputImage.h | 26 +- include/itkInputMesh.h | 26 +- include/itkInputPointSet.h | 28 +- include/itkInputPolyData.h | 30 +- include/itkInputTextStream.h | 22 +- include/itkInputTransform.h | 26 +- include/itkIntTypesJSON.h | 36 +- include/itkMeshJSON.h | 101 +-- include/itkMeshToWasmMeshFilter.hxx | 44 +- include/itkMetaDataDictionaryCBOR.h | 6 +- include/itkMetaDataDictionaryJSON.h | 6 +- include/itkOutputBinaryStream.h | 28 +- include/itkOutputImage.h | 63 +- include/itkOutputMesh.h | 74 +- include/itkOutputPointSet.h | 80 +- include/itkOutputPolyData.h | 95 ++- include/itkOutputTextStream.h | 28 +- include/itkOutputTransform.h | 70 +- include/itkPipeline.h | 214 +++--- include/itkPixelTypesJSON.h | 75 +- include/itkPointSetJSON.h | 78 +- include/itkPointSetToWasmPointSetFilter.h | 2 +- include/itkPointSetToWasmPointSetFilter.hxx | 44 +- include/itkPolyDataJSON.h | 111 +-- include/itkPolyDataToWasmPolyDataFilter.h | 2 +- include/itkPolyDataToWasmPolyDataFilter.hxx | 44 +- include/itkSpecializedImagePipelineFunctor.h | 22 +- include/itkSupportInputImageTypes.h | 46 +- include/itkSupportInputMeshTypes.h | 52 +- include/itkSupportInputPointSetTypes.h | 52 +- include/itkSupportInputPolyDataTypes.h | 44 +- include/itkTransformJSON.h | 230 +++--- include/itkTransformToWasmTransformFilter.h | 2 +- include/itkTransformToWasmTransformFilter.hxx | 35 +- .../itkWasmComponentTypeFromIOComponentEnum.h | 2 +- include/itkWasmDataObject.h | 11 +- include/itkWasmExports.h | 51 +- include/itkWasmIOCommon.h | 41 +- include/itkWasmImage.h | 13 +- include/itkWasmImageIO.h | 43 +- include/itkWasmImageIOFactory.h | 19 +- include/itkWasmImageToImageFilter.hxx | 67 +- include/itkWasmMapComponentType.h | 66 +- include/itkWasmMapPixelType.h | 34 +- include/itkWasmMesh.h | 15 +- include/itkWasmMesh.hxx | 3 +- include/itkWasmMeshIO.h | 70 +- include/itkWasmMeshIOFactory.h | 19 +- include/itkWasmMeshToMeshFilter.hxx | 96 ++- include/itkWasmPixelTypeFromIOPixelEnum.h | 2 +- include/itkWasmPointSet.h | 12 +- include/itkWasmPointSet.hxx | 3 +- include/itkWasmPointSetToPointSetFilter.hxx | 62 +- include/itkWasmPolyData.h | 12 +- include/itkWasmPolyDataToPolyDataFilter.hxx | 69 +- include/itkWasmStringStream.h | 48 +- include/itkWasmTransform.h | 18 +- include/itkWasmTransform.hxx | 3 +- include/itkWasmTransformIO.h | 10 +- include/itkWasmTransformToTransformFilter.hxx | 59 +- include/itkioComponentEnumFromJSON.h | 3 +- include/itktransformParameterizationString.h | 4 +- .../compare-images/compare-double-images.cxx | 63 +- packages/compare-images/vector-magnitude.cxx | 20 +- .../compare-meshes/compare-meshes.cxx | 226 ++++-- .../compress-stringify/compress-stringify.cxx | 38 +- .../parse-string-decompress.cxx | 34 +- .../bindgen-interface-types-test.cxx | 128 ++-- .../input-output-files-test.cxx | 93 ++- .../input-output-json-test.cxx | 14 +- .../median-filter-test.cxx | 53 +- .../mesh-read-write-test.cxx | 5 +- .../test/pipelines/read-image/read-image.cxx | 7 +- .../stdout-stderr-test.cxx | 3 +- .../transform-read-write-test.cxx | 13 +- .../apply-presentation-state-to-image.cxx | 329 ++++---- .../dcmtk/read-dicom-encapsulated-pdf.cxx | 170 ++-- .../dcmtk/read-overlapping-segmentation.cxx | 44 +- packages/dicom/dcmtk/read-segmentation.cxx | 33 +- .../dicom/dcmtk/structured-report-to-html.cxx | 523 +++++++------ .../dicom/dcmtk/structured-report-to-text.cxx | 83 +- .../dicom/dcmtk/write-multi-segmentation.cxx | 168 ++-- .../dcmtk/write-overlapping-segmentation.cxx | 159 ++-- packages/dicom/dcmtk/write-segmentation.cxx | 145 ++-- packages/dicom/gdcm/read-dicom-tags.cxx | 54 +- .../gdcm/read-image-dicom-file-series.cxx | 323 ++++---- packages/downsample/downsample-bin-shrink.cxx | 42 +- .../downsample/downsample-label-image.cxx | 49 +- packages/downsample/downsample-sigma.cxx | 14 +- packages/downsample/downsample.cxx | 46 +- packages/downsample/downsampleSigma.h | 5 +- .../downsample/gaussian-kernel-radius.cxx | 15 +- packages/image-io/itkInputImageIO.h | 31 +- packages/image-io/itkOutputImageIO.h | 143 ++-- packages/image-io/itkWasmImageIOBase.cxx | 32 +- packages/image-io/itkWasmImageIOBase.h | 30 +- packages/image-io/itkWasmZstdImageIO.cxx | 101 ++- packages/image-io/itkWasmZstdImageIO.h | 26 +- packages/image-io/read-image.cxx | 74 +- packages/image-io/write-image.cxx | 94 ++- packages/mesh-io/itkInputMeshIO.h | 43 +- packages/mesh-io/itkInputPointSetIO.h | 179 ++--- packages/mesh-io/itkOutputMeshIO.h | 342 +++++---- packages/mesh-io/itkOutputPointSetIO.h | 263 +++---- packages/mesh-io/itkWasmMeshIOBase.cxx | 40 +- packages/mesh-io/itkWasmMeshIOBase.h | 18 +- packages/mesh-io/itkWasmPointSetIOBase.cxx | 22 +- packages/mesh-io/itkWasmPointSetIOBase.h | 22 +- packages/mesh-io/itkWasmZstdMeshIO.cxx | 83 +- packages/mesh-io/itkWasmZstdMeshIO.h | 20 +- packages/mesh-io/read-mesh.cxx | 50 +- packages/mesh-io/read-point-set.cxx | 44 +- packages/mesh-io/write-mesh.cxx | 100 ++- packages/mesh-io/write-point-set.cxx | 75 +- packages/transform-io/itkInputTransformIO.h | 20 +- packages/transform-io/itkOutputTransformIO.h | 86 ++- .../transform-io/itkWasmTransformIOBase.h | 22 +- .../transform-io/itkWasmZstdTransformIO.cxx | 82 +- .../transform-io/itkWasmZstdTransformIO.h | 14 +- packages/transform-io/read-transform.cxx | 37 +- packages/transform-io/write-transform.cxx | 45 +- src/cxaThreadAtExitShim.cxx | 21 +- src/exceptionShim.cxx | 22 +- src/getExceptionMessage.cxx | 8 +- src/initialization.cxx | 105 +-- ...tkIOComponentEnumFromWasmComponentType.cxx | 60 +- src/itkIOPixelEnumFromWasmPixelType.cxx | 98 +-- src/itkInputBinaryStream.cxx | 7 +- src/itkInputTextStream.cxx | 7 +- src/itkMetaDataDictionaryCBOR.cxx | 186 +++-- src/itkMetaDataDictionaryJSON.cxx | 18 +- src/itkOutputBinaryStream.cxx | 24 +- src/itkOutputTextStream.cxx | 26 +- src/itkPipeline.cxx | 204 +++-- src/itkSupportInputImageTypes.cxx | 13 +- src/itkSupportInputMeshTypes.cxx | 23 +- src/itkSupportInputPointSetTypes.cxx | 17 +- src/itkSupportInputPolyDataTypes.cxx | 19 +- ...tkWasmComponentTypeFromIOComponentEnum.cxx | 8 +- src/itkWasmExports.cxx | 45 +- src/itkWasmIOCommon.cxx | 165 ++-- src/itkWasmImageIO.cxx | 462 ++++++----- src/itkWasmImageIOFactory.cxx | 29 +- src/itkWasmMeshIO.cxx | 723 +++++++++--------- src/itkWasmMeshIOFactory.cxx | 28 +- src/itkWasmPixelTypeFromIOPixelEnum.cxx | 6 +- src/itkWasmTransformIO.cxx | 44 +- src/itkWasmTransformIOFactory.cxx | 22 +- src/itkioComponentEnumFromJSON.cxx | 9 +- test/itkPipelineMemoryIOTest.cxx | 155 ++-- test/itkPipelineTest.cxx | 36 +- .../itkSupportInputImageTypesMemoryIOTest.cxx | 30 +- test/itkSupportInputImageTypesTest.cxx | 15 +- test/itkSupportInputMeshTypesMemoryIOTest.cxx | 21 +- test/itkSupportInputMeshTypesTest.cxx | 13 +- test/itkSupportInputPolyDataTypesTest.cxx | 15 +- test/itkTransformJSONTest.cxx | 11 +- test/itkWasmImageIOTest.cxx | 19 +- ...asmImageInterfaceWithNegativeIndexTest.cxx | 2 +- test/itkWasmMeshIOTest.cxx | 19 +- test/itkWasmTransformIOTest.cxx | 16 +- ...itkWasmTransformInterfaceCompositeTest.cxx | 3 +- test/itkWasmTransformInterfaceTest.cxx | 3 +- 178 files changed, 6187 insertions(+), 4960 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..45b950284 --- /dev/null +++ b/.clang-format @@ -0,0 +1,318 @@ +## This config file is only relevant for clang-format version 19.1.4 +## +## Examples of each format style can be found on the in the clang-format documentation +## See: https://clang.llvm.org/docs/ClangFormatStyleOptions.html for details of each option +## +## The clang-format binaries can be downloaded as part of the clang binary distributions +## from https://releases.llvm.org/download.html +## +## Use the script Utilities/Maintenance/clang-format.bash to faciliate +## maintaining a consistent code style. +## +## EXAMPLE apply code style enforcement before commit: +# Utilities/Maintenance/clang-format.bash --clang ${PATH_TO_CLANG_FORMAT_19.1.4} --modified +## EXAMPLE apply code style enforcement after commit: +# Utilities/Maintenance/clang-format.bash --clang ${PATH_TO_CLANG_FORMAT_19.1.4} --last +--- +# This configuration requires clang-format version 19.1.4 exactly. +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseArrows: false + AlignCaseColons: false +AlignConsecutiveTableGenBreakingDAGArgColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenCondOperatorColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenDefinitionColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Never +AllowShortCaseExpressionOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +#AllowShortFunctionsOnASingleLine: Inline Only merge functions defined inside a class. Implies empty. +#AllowShortFunctionsOnASingleLine: None (in configuration: None) Never merge functions into a single line. +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AttributeMacros: + - __capability +BinPackArguments: false +BinPackParameters: false +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterExternBlock: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakAfterReturnType: All +BreakArrays: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Custom +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +BreakFunctionDefinitionParameters: false +BreakInheritanceList: BeforeComma +BreakStringLiterals: true +BreakTemplateDeclarations: Yes +## The following line allows larger lines in non-documentation code +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 2 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: true +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: AfterHash +IndentRequiresClause: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLines: + AtEndOfFile: false + AtStartOfBlock: true + AtStartOfFile: true +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MainIncludeChar: Quote +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: false +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +## The following line allows larger lines in non-documentation code +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Middle +PPIndentWidth: -1 +QualifierAlignment: Custom +QualifierOrder: + - friend + - static + - inline + - constexpr + - const + - type +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +# We may want to sort the includes as a separate pass +SortIncludes: Never +SortJavaStaticImport: Before +# We may want to revisit this later +SortUsingDeclarations: Never +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + ExceptDoubleParentheses: false + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION + - ITK_GCC_PRAGMA_PUSH + - ITK_GCC_PRAGMA_POP + - ITK_GCC_SUPPRESS_Wfloat_equal + - ITK_GCC_SUPPRESS_Wformat_nonliteral + - ITK_GCC_SUPPRESS_Warray_bounds + - ITK_CLANG_PRAGMA_PUSH + - ITK_CLANG_PRAGMA_POP + - ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant + - CLANG_PRAGMA_PUSH + - CLANG_PRAGMA_POP + - CLANG_SUPPRESS_Wfloat_equal + - INTEL_PRAGMA_WARN_PUSH + - INTEL_PRAGMA_WARN_POP + - INTEL_SUPPRESS_warning_1292 + - itkTemplateFloatingToIntegerMacro + - itkLegacyMacro +TableGenBreakInsideDAGArg: DontBreak +TabWidth: 2 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE +... diff --git a/examples/debugging/DebugMe.cxx b/examples/debugging/DebugMe.cxx index 94e7ace03..021dfbecf 100644 --- a/examples/debugging/DebugMe.cxx +++ b/examples/debugging/DebugMe.cxx @@ -1,12 +1,14 @@ #include -int main() { +int +main() +{ std::cout << "Hello debugger world!" << std::endl; const char * wasmDetails = "are no longer hidden"; - const int a = 1; - const int b = 2; + const int a = 1; + const int b = 2; const auto c = a + b; // Simulate a crash. diff --git a/examples/different-input-types/different-input-types.cxx b/examples/different-input-types/different-input-types.cxx index ef39a9036..c4f1e8fde 100644 --- a/examples/different-input-types/different-input-types.cxx +++ b/examples/different-input-types/different-input-types.cxx @@ -26,7 +26,7 @@ #include "itkLabelImageToLabelMapFilter.h" #include "itkLabelMapOverlayImageFilter.h" -template +template int OverlayLabelMap(itk::wasm::Pipeline & pipeline, const TImage * inputImage, const TLabelImage * labelImage) { @@ -65,11 +65,12 @@ OverlayLabelMap(itk::wasm::Pipeline & pipeline, const TImage * inputImage, const return EXIT_SUCCESS; } -template +template class InputImagePipelineFunctor { public: - int operator()(itk::wasm::Pipeline & pipeline) + int + operator()(itk::wasm::Pipeline & pipeline) { using InputImageType = itk::wasm::InputImage; InputImageType inputImage; @@ -80,16 +81,17 @@ class InputImagePipelineFunctor typename TImage::ConstPointer image = inputImage.Get(); parsedImage = image; return itk::wasm::SupportInputImageTypes - ::template Dimensions("label-image", pipeline); + uint8_t>::template Dimensions("label-image", + pipeline); } private: - template + template class LabelImagePipelineFunctor { public: - int operator()(itk::wasm::Pipeline & pipeline) + int + operator()(itk::wasm::Pipeline & pipeline) { using LabelImageType = itk::wasm::InputImage; LabelImageType labelImage; @@ -105,13 +107,15 @@ class InputImagePipelineFunctor static inline const TImage * parsedImage; }; -int main( int argc, char * argv[] ) +int +main(int argc, char * argv[]) { // Create the pipeline for parsing arguments. Provide a description. - itk::wasm::Pipeline pipeline("different-input-types", "An itk-wasm pipeline example that demonstrates accepting different input types", argc, argv); + itk::wasm::Pipeline pipeline("different-input-types", + "An itk-wasm pipeline example that demonstrates accepting different input types", + argc, + argv); - return itk::wasm::SupportInputImageTypes - ::Dimensions<2U>("input-image", pipeline); + return itk::wasm::SupportInputImageTypes::Dimensions<2U>("input-image", + pipeline); } diff --git a/examples/hello-pipeline/hello-pipeline.cxx b/examples/hello-pipeline/hello-pipeline.cxx index 78566140e..350d1dc90 100644 --- a/examples/hello-pipeline/hello-pipeline.cxx +++ b/examples/hello-pipeline/hello-pipeline.cxx @@ -19,7 +19,9 @@ #include "itkInputImage.h" #include "itkImage.h" -int main(int argc, char * argv[]) { +int +main(int argc, char * argv[]) +{ // Create the pipeline for parsing arguments. Provide a description. itk::wasm::Pipeline pipeline("hello-pipeline", "A hello world itk::wasm::Pipeline", argc, argv); diff --git a/examples/inputs-outputs/inputs-outputs.cxx b/examples/inputs-outputs/inputs-outputs.cxx index 0183766e3..ff04eff09 100644 --- a/examples/inputs-outputs/inputs-outputs.cxx +++ b/examples/inputs-outputs/inputs-outputs.cxx @@ -22,7 +22,9 @@ #include "itkImage.h" #include "itkMedianImageFilter.h" -int main(int argc, char * argv[]) { +int +main(int argc, char * argv[]) +{ // Create the pipeline for parsing arguments. Provide a description. itk::wasm::Pipeline pipeline("inputs-outputs", "An example with non-trivial inputs and outputs", argc, argv); @@ -51,7 +53,7 @@ int main(int argc, char * argv[]) { ITK_WASM_PARSE(pipeline); // Process our data - using FilterType = itk::MedianImageFilter< ImageType, ImageType >; + using FilterType = itk::MedianImageFilter; auto filter = FilterType::New(); filter->SetInput(inputImage.Get()); filter->SetRadius(radius); diff --git a/examples/mean-squares-versor-registration/mean-squares-versor-registration.cxx b/examples/mean-squares-versor-registration/mean-squares-versor-registration.cxx index dcf5ecb94..ce88fbe87 100644 --- a/examples/mean-squares-versor-registration/mean-squares-versor-registration.cxx +++ b/examples/mean-squares-versor-registration/mean-squares-versor-registration.cxx @@ -134,7 +134,10 @@ class CommandIterationUpdate : public itk::Command int main(int argc, char * argv[]) { - itk::wasm::Pipeline pipeline("mean-squares-versor-registration", "Illustrate the use of the VersorRigid3DTransform for 3D image registration.", argc, argv); + itk::wasm::Pipeline pipeline("mean-squares-versor-registration", + "Illustrate the use of the VersorRigid3DTransform for 3D image registration.", + argc, + argv); constexpr unsigned int Dimension = 3; using PixelType = float; @@ -173,10 +176,8 @@ main(int argc, char * argv[]) // Software Guide : EndCodeSnippet using OptimizerType = itk::RegularStepGradientDescentOptimizerv4; - using MetricType = - itk::MeanSquaresImageToImageMetricv4; - using RegistrationType = itk:: - ImageRegistrationMethodv4; + using MetricType = itk::MeanSquaresImageToImageMetricv4; + using RegistrationType = itk::ImageRegistrationMethodv4; auto metric = MetricType::New(); auto optimizer = OptimizerType::New(); @@ -222,10 +223,7 @@ main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet - using TransformInitializerType = - itk::CenteredTransformInitializer; + using TransformInitializerType = itk::CenteredTransformInitializer; auto initializer = TransformInitializerType::New(); // Software Guide : EndCodeSnippet @@ -310,9 +308,8 @@ main(int argc, char * argv[]) // Software Guide : EndCodeSnippet using OptimizerScalesType = OptimizerType::ScalesType; - OptimizerScalesType optimizerScales( - initialTransform->GetNumberOfParameters()); - const double translationScale = 1.0 / 1000.0; + OptimizerScalesType optimizerScales(initialTransform->GetNumberOfParameters()); + const double translationScale = 1.0 / 1000.0; optimizerScales[0] = 1.0; optimizerScales[1] = 1.0; optimizerScales[2] = 1.0; @@ -349,8 +346,7 @@ main(int argc, char * argv[]) try { registration->Update(); - std::cout << "Optimizer stop condition: " - << registration->GetOptimizer()->GetStopConditionDescription() + std::cout << "Optimizer stop condition: " << registration->GetOptimizer()->GetStopConditionDescription() << std::endl; } catch (const itk::ExceptionObject & err) @@ -360,8 +356,7 @@ main(int argc, char * argv[]) return EXIT_FAILURE; } - const TransformType::ParametersType finalParameters = - registration->GetOutput()->Get()->GetParameters(); + const TransformType::ParametersType finalParameters = registration->GetOutput()->Get()->GetParameters(); const double versorX = finalParameters[0]; const double versorY = finalParameters[1]; @@ -443,8 +438,7 @@ main(int argc, char * argv[]) auto finalTransform = TransformType::New(); - finalTransform->SetFixedParameters( - registration->GetOutput()->Get()->GetFixedParameters()); + finalTransform->SetFixedParameters(registration->GetOutput()->Get()->GetFixedParameters()); finalTransform->SetParameters(finalParameters); // Software Guide : BeginCodeSnippet @@ -551,8 +545,7 @@ main(int argc, char * argv[]) // // Software Guide : EndLatex - using ResampleFilterType = - itk::ResampleImageFilter; + using ResampleFilterType = itk::ResampleImageFilter; auto resampler = ResampleFilterType::New(); @@ -567,8 +560,7 @@ main(int argc, char * argv[]) resampler->SetOutputDirection(fixedImage->GetDirection()); resampler->SetDefaultPixelValue(100); - using CastFilterType = - itk::CastImageFilter; + using CastFilterType = itk::CastImageFilter; auto caster = CastFilterType::New(); diff --git a/include/itkComponentTypesJSON.h b/include/itkComponentTypesJSON.h index 4f6f3faba..b29facf76 100644 --- a/include/itkComponentTypesJSON.h +++ b/include/itkComponentTypesJSON.h @@ -24,33 +24,24 @@ namespace itk { enum class JSONComponentTypesEnum { - int8, - uint8, - int16, - uint16, - int32, - uint32, - int64, - uint64, - float32, - float64 + int8, + uint8, + int16, + uint16, + int32, + uint32, + int64, + uint64, + float32, + float64 }; } // end namespace itk template <> -struct glz::meta { +struct glz::meta +{ using enum itk::JSONComponentTypesEnum; - static constexpr auto value = glz::enumerate( - int8, - uint8, - int16, - uint16, - int32, - uint32, - int64, - float32, - float64 - ); + static constexpr auto value = glz::enumerate(int8, uint8, int16, uint16, int32, uint32, int64, float32, float64); }; #endif // itkComponentTypesJSON_h diff --git a/include/itkFloatTypesJSON.h b/include/itkFloatTypesJSON.h index e072a2256..9eacbcbbb 100644 --- a/include/itkFloatTypesJSON.h +++ b/include/itkFloatTypesJSON.h @@ -22,19 +22,18 @@ namespace itk { - enum class JSONFloatTypesEnum - { - float32, - float64, - }; +enum class JSONFloatTypesEnum +{ + float32, + float64, +}; } // end namespace itk template <> -struct glz::meta { +struct glz::meta +{ using enum itk::JSONFloatTypesEnum; - static constexpr auto value = glz::enumerate(float32, - float64 - ); + static constexpr auto value = glz::enumerate(float32, float64); }; #endif // itkFloatTypesJSON_h diff --git a/include/itkIOPixelEnumFromWasmPixelType.h b/include/itkIOPixelEnumFromWasmPixelType.h index fb8b53d3b..b18c5e65d 100644 --- a/include/itkIOPixelEnumFromWasmPixelType.h +++ b/include/itkIOPixelEnumFromWasmPixelType.h @@ -26,7 +26,7 @@ namespace itk { WebAssemblyInterface_EXPORT IOPixelEnum -IOPixelEnumFromWasmPixelType( const std::string & wasmPixelType ); +IOPixelEnumFromWasmPixelType(const std::string & wasmPixelType); } // end namespace itk #endif diff --git a/include/itkImageJSON.h b/include/itkImageJSON.h index b16cc1e2d..29016a851 100644 --- a/include/itkImageJSON.h +++ b/include/itkImageJSON.h @@ -34,57 +34,58 @@ namespace itk { - /** \class ImageTypeJSON - * - * \brief Image type JSON representation data structure. - * - * \ingroup WebAssemblyInterface - */ - struct ImageTypeJSON - { - unsigned int dimension { 2 }; - JSONComponentTypesEnum componentType { JSONComponentTypesEnum::float32 }; - JSONPixelTypesEnum pixelType { JSONPixelTypesEnum::Scalar }; - unsigned int components { 1 }; - }; - - /** \class ImageRegionJSON - * - * \brief Image region JSON representation data structure. - * - * \ingroup WebAssemblyInterface - */ - struct ImageRegionJSON - { - std::vector index {}; - std::vector size {}; - }; - - /** \class ImageJSON - * - * \brief Image JSON representation data structure. - * - * \ingroup WebAssemblyInterface - */ - struct ImageJSON - { - ImageTypeJSON imageType; +/** \class ImageTypeJSON + * + * \brief Image type JSON representation data structure. + * + * \ingroup WebAssemblyInterface + */ +struct ImageTypeJSON +{ + unsigned int dimension{ 2 }; + JSONComponentTypesEnum componentType{ JSONComponentTypesEnum::float32 }; + JSONPixelTypesEnum pixelType{ JSONPixelTypesEnum::Scalar }; + unsigned int components{ 1 }; +}; + +/** \class ImageRegionJSON + * + * \brief Image region JSON representation data structure. + * + * \ingroup WebAssemblyInterface + */ +struct ImageRegionJSON +{ + std::vector index{}; + std::vector size{}; +}; + +/** \class ImageJSON + * + * \brief Image JSON representation data structure. + * + * \ingroup WebAssemblyInterface + */ +struct ImageJSON +{ + ImageTypeJSON imageType; - std::string name { "Image" }; + std::string name{ "Image" }; - std::vector origin { 0.0, 0.0 }; - std::vector spacing { 1.0, 1.0 }; - std::string direction; - std::vector size { 0, 0 }; - ImageRegionJSON bufferedRegion{}; + std::vector origin{ 0.0, 0.0 }; + std::vector spacing{ 1.0, 1.0 }; + std::string direction; + std::vector size{ 0, 0 }; + ImageRegionJSON bufferedRegion{}; - std::string data; + std::string data; - MetadataJSON metadata; - }; + MetadataJSON metadata; +}; -template -auto imageToImageJSON(const TImage * image, const WasmImage * wasmImage, bool inMemory) -> ImageJSON +template +auto +imageToImageJSON(const TImage * image, const WasmImage * wasmImage, bool inMemory) -> ImageJSON { using ImageType = TImage; @@ -97,7 +98,8 @@ auto imageToImageJSON(const TImage * image, const WasmImage * wasmImage, using IOPixelType = typename TImage::IOPixelType; using ConvertPixelTraits = DefaultConvertPixelTraits; using ComponentType = typename ConvertPixelTraits::ComponentType; - imageJSON.imageType.componentType = wasm::MapComponentType::JSONComponentEnum; + imageJSON.imageType.componentType = + wasm::MapComponentType::JSONComponentEnum; imageJSON.imageType.pixelType = wasm::MapPixelType::JSONPixelEnum; imageJSON.imageType.components = image->GetNumberOfComponentsPerPixel(); @@ -125,7 +127,7 @@ auto imageToImageJSON(const TImage * image, const WasmImage * wasmImage, if (inMemory) { - const auto direction = reinterpret_cast< size_t >( image->GetDirection().GetVnlMatrix().begin() ); + const auto direction = reinterpret_cast(image->GetDirection().GetVnlMatrix().begin()); std::ostringstream directionStream; directionStream << "data:application/vnd.itk.address,0:"; directionStream << direction; @@ -152,7 +154,7 @@ auto imageToImageJSON(const TImage * image, const WasmImage * wasmImage, if (inMemory) { - const auto data = reinterpret_cast< size_t >( image->GetBufferPointer() ); + const auto data = reinterpret_cast(image->GetBufferPointer()); std::ostringstream dataStream; dataStream << "data:application/vnd.itk.address,0:"; dataStream << data; diff --git a/include/itkImageToWasmImageFilter.h b/include/itkImageToWasmImageFilter.h index b3a84cf9d..3318b78ad 100644 --- a/include/itkImageToWasmImageFilter.h +++ b/include/itkImageToWasmImageFilter.h @@ -26,7 +26,7 @@ namespace itk /** *\class ImageToWasmImageFilter * \brief Convert an Image to an WasmImage object. - * + * * \ingroup WebAssemblyInterface */ template diff --git a/include/itkImageToWasmImageFilter.hxx b/include/itkImageToWasmImageFilter.hxx index f9406a95d..e4b1213c4 100644 --- a/include/itkImageToWasmImageFilter.hxx +++ b/include/itkImageToWasmImageFilter.hxx @@ -35,8 +35,7 @@ namespace itk { template -ImageToWasmImageFilter -::ImageToWasmImageFilter() +ImageToWasmImageFilter::ImageToWasmImageFilter() { this->SetNumberOfRequiredInputs(1); @@ -47,24 +46,21 @@ ImageToWasmImageFilter template ProcessObject::DataObjectPointer -ImageToWasmImageFilter -::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) +ImageToWasmImageFilter::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) { return WasmImageType::New().GetPointer(); } template ProcessObject::DataObjectPointer -ImageToWasmImageFilter -::MakeOutput(const ProcessObject::DataObjectIdentifierType &) +ImageToWasmImageFilter::MakeOutput(const ProcessObject::DataObjectIdentifierType &) { return WasmImageType::New().GetPointer(); } template auto -ImageToWasmImageFilter -::GetOutput() -> WasmImageType * +ImageToWasmImageFilter::GetOutput() -> WasmImageType * { // we assume that the first output is of the templated type return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); @@ -72,8 +68,7 @@ ImageToWasmImageFilter template auto -ImageToWasmImageFilter -::GetOutput() const -> const WasmImageType * +ImageToWasmImageFilter::GetOutput() const -> const WasmImageType * { // we assume that the first output is of the templated type return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); @@ -81,8 +76,7 @@ ImageToWasmImageFilter template auto -ImageToWasmImageFilter -::GetOutput(unsigned int idx) -> WasmImageType * +ImageToWasmImageFilter::GetOutput(unsigned int idx) -> WasmImageType * { auto * out = dynamic_cast(this->ProcessObject::GetOutput(idx)); @@ -95,8 +89,7 @@ ImageToWasmImageFilter template void -ImageToWasmImageFilter -::SetInput(const ImageType * input) +ImageToWasmImageFilter::SetInput(const ImageType * input) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(0, const_cast(input)); @@ -104,8 +97,7 @@ ImageToWasmImageFilter template void -ImageToWasmImageFilter -::SetInput(unsigned int index, const ImageType * image) +ImageToWasmImageFilter::SetInput(unsigned int index, const ImageType * image) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(index, const_cast(image)); @@ -113,35 +105,32 @@ ImageToWasmImageFilter template const typename ImageToWasmImageFilter::ImageType * -ImageToWasmImageFilter -::GetInput() +ImageToWasmImageFilter::GetInput() { return itkDynamicCastInDebugMode(this->GetPrimaryInput()); } template const typename ImageToWasmImageFilter::ImageType * -ImageToWasmImageFilter -::GetInput(unsigned int idx) +ImageToWasmImageFilter::GetInput(unsigned int idx) { return itkDynamicCastInDebugMode(this->ProcessObject::GetInput(idx)); } template void -ImageToWasmImageFilter -::GenerateData() +ImageToWasmImageFilter::GenerateData() { // Get the input and output pointers const ImageType * image = this->GetInput(); - WasmImageType * wasmImage = this->GetOutput(); + WasmImageType * wasmImage = this->GetOutput(); wasmImage->SetImage(image); - constexpr bool inMemory = true; + constexpr bool inMemory = true; const ImageJSON imageJSON = imageToImageJSON(image, wasmImage, inMemory); - std::string serialized{}; - auto ec = glz::write(imageJSON, serialized); + std::string serialized{}; + auto ec = glz::write(imageJSON, serialized); if (ec) { itkExceptionMacro("Failed to serialize ImageJSON"); @@ -151,8 +140,7 @@ ImageToWasmImageFilter template void -ImageToWasmImageFilter -::PrintSelf(std::ostream & os, Indent indent) const +ImageToWasmImageFilter::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent); } diff --git a/include/itkImportVectorImageFilter.h b/include/itkImportVectorImageFilter.h index 23f365d03..9471daa76 100644 --- a/include/itkImportVectorImageFilter.h +++ b/include/itkImportVectorImageFilter.h @@ -90,13 +90,13 @@ class ITK_TEMPLATE_EXPORT ImportVectorImageFilter : public ImageSource::ImportVectorImageFilter() template ImportVectorImageFilter::~ImportVectorImageFilter() -{ -} +{} template void @@ -84,17 +83,18 @@ ImportVectorImageFilter::PrintSelf(std::ostream & os, Indent inden template void -ImportVectorImageFilter::SetImportPointer(OutputImageInternalPixelType * ptr, - SizeValueType num, - bool letImageContainerManageMemory, - unsigned int vectorImageComponents) +ImportVectorImageFilter::SetImportPointer(OutputImageInternalPixelType * ptr, + SizeValueType num, + bool letImageContainerManageMemory, + unsigned int vectorImageComponents) { - if (!m_ImportImageContainer || ptr != m_ImportImageContainer->GetImportPointer() || m_Size != num || m_VectorImageComponentsPerPixel != vectorImageComponents) + if (!m_ImportImageContainer || ptr != m_ImportImageContainer->GetImportPointer() || m_Size != num || + m_VectorImageComponentsPerPixel != vectorImageComponents) { m_Size = num; m_VectorImageComponentsPerPixel = vectorImageComponents; m_ImportImageContainer = ImportImageContainerType::New(); - m_ImportImageContainer->SetImportPointer(ptr, m_Size*vectorImageComponents, letImageContainerManageMemory); + m_ImportImageContainer->SetImportPointer(ptr, m_Size * vectorImageComponents, letImageContainerManageMemory); this->Modified(); } } @@ -139,9 +139,9 @@ ImportVectorImageFilter::GenerateOutputInformation() outputPtr->SetLargestPossibleRegion(m_LargestPossibleRegion); if (outputPtr->GetNameOfClass() == std::string("VectorImage")) - { + { outputPtr->SetNumberOfComponentsPerPixel(m_VectorImageComponentsPerPixel); - } + } } template diff --git a/include/itkInputBinaryStream.h b/include/itkInputBinaryStream.h index 29de0c417..4c2e8cd21 100644 --- a/include/itkInputBinaryStream.h +++ b/include/itkInputBinaryStream.h @@ -23,10 +23,10 @@ #include #ifndef ITK_WASM_NO_MEMORY_IO -#include +# include #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include +# include #endif #include "WebAssemblyInterfaceExport.h" @@ -49,11 +49,14 @@ namespace wasm class WebAssemblyInterface_EXPORT InputBinaryStream { public: - std::istream & Get() { + std::istream & + Get() + { return *m_IStream; } - void SetJSON(const std::string & json) + void + SetJSON(const std::string & json) { if (m_DeleteIStream && m_IStream != nullptr) { @@ -66,7 +69,8 @@ class WebAssemblyInterface_EXPORT InputBinaryStream m_IStream = &(m_WasmStringStream->GetStringStream()); } - void SetFileName(const std::string & fileName) + void + SetFileName(const std::string & fileName) { if (m_DeleteIStream && m_IStream != nullptr) { @@ -84,15 +88,17 @@ class WebAssemblyInterface_EXPORT InputBinaryStream delete m_IStream; } } + protected: - std::istream * m_IStream{nullptr}; - bool m_DeleteIStream{false}; + std::istream * m_IStream{ nullptr }; + bool m_DeleteIStream{ false }; WasmStringStream::Pointer m_WasmStringStream; }; -WebAssemblyInterface_EXPORT bool lexical_cast(const std::string &input, InputBinaryStream &inputStream); +WebAssemblyInterface_EXPORT bool +lexical_cast(const std::string & input, InputBinaryStream & inputStream); } // end namespace wasm } // end namespace itk diff --git a/include/itkInputImage.h b/include/itkInputImage.h index 37ede91ea..22413fb35 100644 --- a/include/itkInputImage.h +++ b/include/itkInputImage.h @@ -21,12 +21,12 @@ #include "itkPipeline.h" #ifndef ITK_WASM_NO_MEMORY_IO -#include "itkWasmExports.h" -#include "itkWasmImage.h" -#include "itkWasmImageToImageFilter.h" +# include "itkWasmExports.h" +# include "itkWasmImage.h" +# include "itkWasmImageToImageFilter.h" #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include "itkImageFileReader.h" +# include "itkImageFileReader.h" #endif namespace itk @@ -50,23 +50,29 @@ class ITK_TEMPLATE_EXPORT InputImage public: using ImageType = TImage; - void Set(const ImageType * image) { + void + Set(const ImageType * image) + { this->m_Image = image; } - const ImageType * Get() const { + const ImageType * + Get() const + { return this->m_Image.GetPointer(); } InputImage() = default; ~InputImage() = default; + protected: typename TImage::ConstPointer m_Image; }; template -bool lexical_cast(const std::string &input, InputImage &inputImage) +bool +lexical_cast(const std::string & input, InputImage & inputImage) { if (input.empty()) { @@ -77,10 +83,10 @@ bool lexical_cast(const std::string &input, InputImage &inputImage) { #ifndef ITK_WASM_NO_MEMORY_IO using WasmImageToImageFilterType = WasmImageToImageFilter; - auto wasmImageToImageFilter = WasmImageToImageFilterType::New(); - auto wasmImage = WasmImageToImageFilterType::WasmImageType::New(); + auto wasmImageToImageFilter = WasmImageToImageFilterType::New(); + auto wasmImage = WasmImageToImageFilterType::WasmImageType::New(); const unsigned int index = std::stoi(input); - auto json = getMemoryStoreInputJSON(0, index); + auto json = getMemoryStoreInputJSON(0, index); wasmImage->SetJSON(json); wasmImageToImageFilter->SetInput(wasmImage); wasmImageToImageFilter->Update(); diff --git a/include/itkInputMesh.h b/include/itkInputMesh.h index e48b7e737..5da18092f 100644 --- a/include/itkInputMesh.h +++ b/include/itkInputMesh.h @@ -21,12 +21,12 @@ #include "itkPipeline.h" #ifndef ITK_WASM_NO_MEMORY_IO -#include "itkWasmExports.h" -#include "itkWasmMesh.h" -#include "itkWasmMeshToMeshFilter.h" +# include "itkWasmExports.h" +# include "itkWasmMesh.h" +# include "itkWasmMeshToMeshFilter.h" #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include "itkMeshFileReader.h" +# include "itkMeshFileReader.h" #endif namespace itk @@ -50,23 +50,29 @@ class ITK_TEMPLATE_EXPORT InputMesh public: using MeshType = TMesh; - void Set(const MeshType * mesh) { + void + Set(const MeshType * mesh) + { this->m_Mesh = mesh; } - const MeshType * Get() const { + const MeshType * + Get() const + { return this->m_Mesh.GetPointer(); } InputMesh() = default; ~InputMesh() = default; + protected: typename TMesh::ConstPointer m_Mesh; }; template -bool lexical_cast(const std::string &input, InputMesh &inputMesh) +bool +lexical_cast(const std::string & input, InputMesh & inputMesh) { if (input.empty()) { @@ -77,10 +83,10 @@ bool lexical_cast(const std::string &input, InputMesh &inputMesh) { #ifndef ITK_WASM_NO_MEMORY_IO using WasmMeshToMeshFilterType = WasmMeshToMeshFilter; - auto wasmMeshToMeshFilter = WasmMeshToMeshFilterType::New(); - auto wasmMesh = WasmMeshToMeshFilterType::WasmMeshType::New(); + auto wasmMeshToMeshFilter = WasmMeshToMeshFilterType::New(); + auto wasmMesh = WasmMeshToMeshFilterType::WasmMeshType::New(); const unsigned int index = std::stoi(input); - auto json = getMemoryStoreInputJSON(0, index); + auto json = getMemoryStoreInputJSON(0, index); wasmMesh->SetJSON(json); wasmMeshToMeshFilter->SetInput(wasmMesh); wasmMeshToMeshFilter->Update(); diff --git a/include/itkInputPointSet.h b/include/itkInputPointSet.h index 4eeaff03f..df8275df5 100644 --- a/include/itkInputPointSet.h +++ b/include/itkInputPointSet.h @@ -21,13 +21,13 @@ #include "itkPipeline.h" #ifndef ITK_WASM_NO_MEMORY_IO -#include "itkWasmExports.h" -#include "itkWasmPointSet.h" -#include "itkWasmPointSetToPointSetFilter.h" +# include "itkWasmExports.h" +# include "itkWasmPointSet.h" +# include "itkWasmPointSetToPointSetFilter.h" #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include "itkMesh.h" -#include "itkMeshFileReader.h" +# include "itkMesh.h" +# include "itkMeshFileReader.h" #endif namespace itk @@ -51,23 +51,29 @@ class ITK_TEMPLATE_EXPORT InputPointSet public: using PointSetType = TPointSet; - void Set(const PointSetType * pointSet) { + void + Set(const PointSetType * pointSet) + { this->m_PointSet = pointSet; } - const PointSetType * Get() const { + const PointSetType * + Get() const + { return this->m_PointSet.GetPointer(); } InputPointSet() = default; ~InputPointSet() = default; + protected: typename TPointSet::ConstPointer m_PointSet; }; template -bool lexical_cast(const std::string &input, InputPointSet &inputPointSet) +bool +lexical_cast(const std::string & input, InputPointSet & inputPointSet) { if (input.empty()) { @@ -78,10 +84,10 @@ bool lexical_cast(const std::string &input, InputPointSet &inputPoint { #ifndef ITK_WASM_NO_MEMORY_IO using WasmPointSetToPointSetFilterType = WasmPointSetToPointSetFilter; - auto wasmPointSetToPointSetFilter = WasmPointSetToPointSetFilterType::New(); - auto wasmPointSet = WasmPointSetToPointSetFilterType::WasmPointSetType::New(); + auto wasmPointSetToPointSetFilter = WasmPointSetToPointSetFilterType::New(); + auto wasmPointSet = WasmPointSetToPointSetFilterType::WasmPointSetType::New(); const unsigned int index = std::stoi(input); - auto json = getMemoryStoreInputJSON(0, index); + auto json = getMemoryStoreInputJSON(0, index); wasmPointSet->SetJSON(json); wasmPointSetToPointSetFilter->SetInput(wasmPointSet); wasmPointSetToPointSetFilter->Update(); diff --git a/include/itkInputPolyData.h b/include/itkInputPolyData.h index ad3039059..924d7b646 100644 --- a/include/itkInputPolyData.h +++ b/include/itkInputPolyData.h @@ -21,14 +21,14 @@ #include "itkPipeline.h" #ifndef ITK_WASM_NO_MEMORY_IO -#include "itkWasmExports.h" -#include "itkWasmPolyData.h" -#include "itkWasmPolyDataToPolyDataFilter.h" +# include "itkWasmExports.h" +# include "itkWasmPolyData.h" +# include "itkWasmPolyDataToPolyDataFilter.h" #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include "itkMeshFileReader.h" -#include "itkMeshToPolyDataFilter.h" -#include "itkPolyDataToMeshFilter.h" +# include "itkMeshFileReader.h" +# include "itkMeshToPolyDataFilter.h" +# include "itkPolyDataToMeshFilter.h" #endif namespace itk @@ -52,23 +52,29 @@ class ITK_TEMPLATE_EXPORT InputPolyData public: using PolyDataType = TPolyData; - void Set(const PolyDataType * polyData) { + void + Set(const PolyDataType * polyData) + { this->m_PolyData = polyData; } - const PolyDataType * Get() const { + const PolyDataType * + Get() const + { return this->m_PolyData.GetPointer(); } InputPolyData() = default; ~InputPolyData() = default; + protected: typename TPolyData::ConstPointer m_PolyData; }; template -bool lexical_cast(const std::string &input, InputPolyData &inputPolyData) +bool +lexical_cast(const std::string & input, InputPolyData & inputPolyData) { if (input.empty()) { @@ -79,10 +85,10 @@ bool lexical_cast(const std::string &input, InputPolyData &inputPolyD { #ifndef ITK_WASM_NO_MEMORY_IO using WasmPolyDataToPolyDataFilterType = WasmPolyDataToPolyDataFilter; - auto wasmPolyDataToPolyDataFilter = WasmPolyDataToPolyDataFilterType::New(); - auto wasmPolyData = WasmPolyDataToPolyDataFilterType::WasmPolyDataType::New(); + auto wasmPolyDataToPolyDataFilter = WasmPolyDataToPolyDataFilterType::New(); + auto wasmPolyData = WasmPolyDataToPolyDataFilterType::WasmPolyDataType::New(); const unsigned int index = std::stoi(input); - auto json = getMemoryStoreInputJSON(0, index); + auto json = getMemoryStoreInputJSON(0, index); wasmPolyData->SetJSON(json); wasmPolyDataToPolyDataFilter->SetInput(wasmPolyData); wasmPolyDataToPolyDataFilter->Update(); diff --git a/include/itkInputTextStream.h b/include/itkInputTextStream.h index 4f4cd33c3..a1b9ca451 100644 --- a/include/itkInputTextStream.h +++ b/include/itkInputTextStream.h @@ -45,15 +45,20 @@ namespace wasm class WebAssemblyInterface_EXPORT InputTextStream { public: - std::istream & Get() { + std::istream & + Get() + { return *m_IStream; } - std::istream * GetPointer() { + std::istream * + GetPointer() + { return m_IStream; } - void SetJSON(const std::string & json) + void + SetJSON(const std::string & json) { if (m_DeleteIStream && m_IStream != nullptr) { @@ -66,7 +71,8 @@ class WebAssemblyInterface_EXPORT InputTextStream m_IStream = &(m_WasmStringStream->GetStringStream()); } - void SetFileName(const std::string & fileName) + void + SetFileName(const std::string & fileName) { if (m_DeleteIStream && m_IStream != nullptr) { @@ -84,15 +90,17 @@ class WebAssemblyInterface_EXPORT InputTextStream delete m_IStream; } } + protected: - std::istream * m_IStream{nullptr}; - bool m_DeleteIStream{false}; + std::istream * m_IStream{ nullptr }; + bool m_DeleteIStream{ false }; WasmStringStream::Pointer m_WasmStringStream; }; -WebAssemblyInterface_EXPORT bool lexical_cast(const std::string &input, InputTextStream &inputStream); +WebAssemblyInterface_EXPORT bool +lexical_cast(const std::string & input, InputTextStream & inputStream); } // end namespace wasm } // end namespace itk diff --git a/include/itkInputTransform.h b/include/itkInputTransform.h index d1da70a44..0ab462fe1 100644 --- a/include/itkInputTransform.h +++ b/include/itkInputTransform.h @@ -21,12 +21,12 @@ #include "itkPipeline.h" #ifndef ITK_WASM_NO_MEMORY_IO -#include "itkWasmExports.h" -#include "itkWasmTransform.h" -#include "itkWasmTransformToTransformFilter.h" +# include "itkWasmExports.h" +# include "itkWasmTransform.h" +# include "itkWasmTransformToTransformFilter.h" #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include "itkTransformFileReader.h" +# include "itkTransformFileReader.h" #endif namespace itk @@ -50,23 +50,29 @@ class ITK_TEMPLATE_EXPORT InputTransform public: using TransformType = TTransform; - void Set(const TransformType * transform) { + void + Set(const TransformType * transform) + { this->m_Transform = transform; } - const TransformType * Get() const { + const TransformType * + Get() const + { return this->m_Transform.GetPointer(); } InputTransform() = default; ~InputTransform() = default; + protected: typename TTransform::ConstPointer m_Transform; }; template -bool lexical_cast(const std::string &input, InputTransform &inputTransform) +bool +lexical_cast(const std::string & input, InputTransform & inputTransform) { if (input.empty()) { @@ -77,10 +83,10 @@ bool lexical_cast(const std::string &input, InputTransform &inputTra { #ifndef ITK_WASM_NO_MEMORY_IO using WasmTransformToTransformFilterType = WasmTransformToTransformFilter; - auto wasmTransformToTransformFilter = WasmTransformToTransformFilterType::New(); - auto wasmTransform = WasmTransformToTransformFilterType::WasmTransformType::New(); + auto wasmTransformToTransformFilter = WasmTransformToTransformFilterType::New(); + auto wasmTransform = WasmTransformToTransformFilterType::WasmTransformType::New(); const unsigned int index = std::stoi(input); - auto json = getMemoryStoreInputJSON(0, index); + auto json = getMemoryStoreInputJSON(0, index); wasmTransform->SetJSON(json); wasmTransformToTransformFilter->SetInput(wasmTransform); wasmTransformToTransformFilter->Update(); diff --git a/include/itkIntTypesJSON.h b/include/itkIntTypesJSON.h index 90ee43d8a..b385b18a8 100644 --- a/include/itkIntTypesJSON.h +++ b/include/itkIntTypesJSON.h @@ -22,32 +22,24 @@ namespace itk { - enum class JSONIntTypesEnum - { - int8, - uint8, - int16, - uint16, - int32, - uint32, - int64, - uint64 - }; +enum class JSONIntTypesEnum +{ + int8, + uint8, + int16, + uint16, + int32, + uint32, + int64, + uint64 +}; } // end namespace itk template <> -struct glz::meta { +struct glz::meta +{ using enum itk::JSONIntTypesEnum; - static constexpr auto value = glz::enumerate( - int8, - uint8, - int16, - uint16, - int32, - uint32, - int64, - uint64 - ); + static constexpr auto value = glz::enumerate(int8, uint8, int16, uint16, int32, uint32, int64, uint64); }; #endif // itkIntTypesJSON_h diff --git a/include/itkMeshJSON.h b/include/itkMeshJSON.h index 93cf9a639..1dcda5251 100644 --- a/include/itkMeshJSON.h +++ b/include/itkMeshJSON.h @@ -33,55 +33,56 @@ namespace itk { - /** \class MeshTypeJSON - * - * \brief Mesh type JSON representation data structure. - * - * \ingroup WebAssemblyInterface - */ - struct MeshTypeJSON - { - unsigned int dimension { 2 }; - JSONFloatTypesEnum pointComponentType { JSONFloatTypesEnum::float32 }; - JSONComponentTypesEnum pointPixelComponentType { JSONComponentTypesEnum::float32 }; - JSONPixelTypesEnum pointPixelType { JSONPixelTypesEnum::Scalar }; - unsigned int pointPixelComponents { 1 }; - JSONIntTypesEnum cellComponentType { JSONIntTypesEnum::uint32 }; - JSONComponentTypesEnum cellPixelComponentType { JSONComponentTypesEnum::float32 }; - JSONPixelTypesEnum cellPixelType { JSONPixelTypesEnum::Scalar }; - unsigned int cellPixelComponents { 1 }; - }; - - /** \class MeshJSON - * - * \brief Mesh JSON representation data structure. - * - * \ingroup WebAssemblyInterface - */ - struct MeshJSON - { - MeshTypeJSON meshType; +/** \class MeshTypeJSON + * + * \brief Mesh type JSON representation data structure. + * + * \ingroup WebAssemblyInterface + */ +struct MeshTypeJSON +{ + unsigned int dimension{ 2 }; + JSONFloatTypesEnum pointComponentType{ JSONFloatTypesEnum::float32 }; + JSONComponentTypesEnum pointPixelComponentType{ JSONComponentTypesEnum::float32 }; + JSONPixelTypesEnum pointPixelType{ JSONPixelTypesEnum::Scalar }; + unsigned int pointPixelComponents{ 1 }; + JSONIntTypesEnum cellComponentType{ JSONIntTypesEnum::uint32 }; + JSONComponentTypesEnum cellPixelComponentType{ JSONComponentTypesEnum::float32 }; + JSONPixelTypesEnum cellPixelType{ JSONPixelTypesEnum::Scalar }; + unsigned int cellPixelComponents{ 1 }; +}; + +/** \class MeshJSON + * + * \brief Mesh JSON representation data structure. + * + * \ingroup WebAssemblyInterface + */ +struct MeshJSON +{ + MeshTypeJSON meshType; - std::string name { "Mesh"}; + std::string name{ "Mesh" }; - size_t numberOfPoints{ 0 }; - std::string points; + size_t numberOfPoints{ 0 }; + std::string points; - size_t numberOfPointPixels{ 0 }; - std::string pointData; + size_t numberOfPointPixels{ 0 }; + std::string pointData; - size_t numberOfCells{ 0 }; - std::string cells; - size_t cellBufferSize{ 0 }; + size_t numberOfCells{ 0 }; + std::string cells; + size_t cellBufferSize{ 0 }; - size_t numberOfCellPixels{ 0 }; - std::string cellData; + size_t numberOfCellPixels{ 0 }; + std::string cellData; - MetadataJSON metadata; - }; + MetadataJSON metadata; +}; -template -auto meshToMeshJSON(const TMesh * mesh, const WasmMesh * wasmMesh, bool inMemory) -> MeshJSON +template +auto +meshToMeshJSON(const TMesh * mesh, const WasmMesh * wasmMesh, bool inMemory) -> MeshJSON { using MeshType = TMesh; @@ -92,13 +93,15 @@ auto meshToMeshJSON(const TMesh * mesh, const WasmMesh * wasmMesh, bool i meshJSON.meshType.pointComponentType = wasm::MapComponentType::JSONFloatTypeEnum; using PointPixelType = typename TMesh::PixelType; using ConvertPointPixelTraits = MeshConvertPixelTraits; - meshJSON.meshType.pointPixelComponentType = wasm::MapComponentType::JSONComponentEnum; + meshJSON.meshType.pointPixelComponentType = + wasm::MapComponentType::JSONComponentEnum; meshJSON.meshType.pointPixelType = wasm::MapPixelType::JSONPixelEnum; meshJSON.meshType.pointPixelComponents = ConvertPointPixelTraits::GetNumberOfComponents(); meshJSON.meshType.cellComponentType = wasm::MapComponentType::JSONIntTypeEnum; using CellPixelType = typename TMesh::CellPixelType; using ConvertCellPixelTraits = MeshConvertPixelTraits; - meshJSON.meshType.cellPixelComponentType = wasm::MapComponentType::JSONComponentEnum; + meshJSON.meshType.cellPixelComponentType = + wasm::MapComponentType::JSONComponentEnum; meshJSON.meshType.cellPixelType = wasm::MapPixelType::JSONPixelEnum; meshJSON.meshType.cellPixelComponents = ConvertCellPixelTraits::GetNumberOfComponents(); @@ -125,7 +128,7 @@ auto meshToMeshJSON(const TMesh * mesh, const WasmMesh * wasmMesh, bool i { meshJSON.cellBufferSize = wasmMesh->GetCellBuffer()->Size(); - const auto pointsAddress = reinterpret_cast< size_t >( &(mesh->GetPoints()->at(0)) ); + const auto pointsAddress = reinterpret_cast(&(mesh->GetPoints()->at(0))); std::ostringstream pointsStream; pointsStream << "data:application/vnd.itk.address,0:"; pointsStream << pointsAddress; @@ -133,7 +136,7 @@ auto meshToMeshJSON(const TMesh * mesh, const WasmMesh * wasmMesh, bool i size_t cellsAddress = 0; if (mesh->GetNumberOfCells() > 0) { - cellsAddress = reinterpret_cast< size_t >( &(wasmMesh->GetCellBuffer()->at(0)) ); + cellsAddress = reinterpret_cast(&(wasmMesh->GetCellBuffer()->at(0))); } std::ostringstream cellsStream; cellsStream << "data:application/vnd.itk.address,0:"; @@ -143,7 +146,7 @@ auto meshToMeshJSON(const TMesh * mesh, const WasmMesh * wasmMesh, bool i size_t pointDataAddress = 0; if (mesh->GetPointData() != nullptr && mesh->GetPointData()->Size() > 0) { - pointDataAddress = reinterpret_cast< size_t >( &(mesh->GetPointData()->at(0)) ); + pointDataAddress = reinterpret_cast(&(mesh->GetPointData()->at(0))); } std::ostringstream pointDataStream; pointDataStream << "data:application/vnd.itk.address,0:"; @@ -153,10 +156,10 @@ auto meshToMeshJSON(const TMesh * mesh, const WasmMesh * wasmMesh, bool i size_t cellDataAddress = 0; if (mesh->GetCellData() != nullptr && mesh->GetCellData()->Size() > 0) { - cellDataAddress = reinterpret_cast< size_t >( &(mesh->GetCellData()->at(0)) ); + cellDataAddress = reinterpret_cast(&(mesh->GetCellData()->at(0))); } std::ostringstream cellDataStream; - cellDataStream << "data:application/vnd.itk.address,0:"; + cellDataStream << "data:application/vnd.itk.address,0:"; cellDataStream << cellDataAddress; meshJSON.cellData = cellDataStream.str(); } diff --git a/include/itkMeshToWasmMeshFilter.hxx b/include/itkMeshToWasmMeshFilter.hxx index 48fa249ec..a5faeb23b 100644 --- a/include/itkMeshToWasmMeshFilter.hxx +++ b/include/itkMeshToWasmMeshFilter.hxx @@ -26,8 +26,7 @@ namespace itk { template -MeshToWasmMeshFilter -::MeshToWasmMeshFilter() +MeshToWasmMeshFilter::MeshToWasmMeshFilter() { this->SetNumberOfRequiredInputs(1); @@ -38,24 +37,21 @@ MeshToWasmMeshFilter template ProcessObject::DataObjectPointer -MeshToWasmMeshFilter -::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) +MeshToWasmMeshFilter::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) { return WasmMeshType::New().GetPointer(); } template ProcessObject::DataObjectPointer -MeshToWasmMeshFilter -::MakeOutput(const ProcessObject::DataObjectIdentifierType &) +MeshToWasmMeshFilter::MakeOutput(const ProcessObject::DataObjectIdentifierType &) { return WasmMeshType::New().GetPointer(); } template auto -MeshToWasmMeshFilter -::GetOutput() -> WasmMeshType * +MeshToWasmMeshFilter::GetOutput() -> WasmMeshType * { // we assume that the first output is of the templated type return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); @@ -63,8 +59,7 @@ MeshToWasmMeshFilter template auto -MeshToWasmMeshFilter -::GetOutput() const -> const WasmMeshType * +MeshToWasmMeshFilter::GetOutput() const -> const WasmMeshType * { // we assume that the first output is of the templated type return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); @@ -72,8 +67,7 @@ MeshToWasmMeshFilter template auto -MeshToWasmMeshFilter -::GetOutput(unsigned int idx) -> WasmMeshType * +MeshToWasmMeshFilter::GetOutput(unsigned int idx) -> WasmMeshType * { auto * out = dynamic_cast(this->ProcessObject::GetOutput(idx)); @@ -86,8 +80,7 @@ MeshToWasmMeshFilter template void -MeshToWasmMeshFilter -::SetInput(const MeshType * input) +MeshToWasmMeshFilter::SetInput(const MeshType * input) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(0, const_cast(input)); @@ -95,8 +88,7 @@ MeshToWasmMeshFilter template void -MeshToWasmMeshFilter -::SetInput(unsigned int index, const MeshType * mesh) +MeshToWasmMeshFilter::SetInput(unsigned int index, const MeshType * mesh) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(index, const_cast(mesh)); @@ -104,34 +96,31 @@ MeshToWasmMeshFilter template const typename MeshToWasmMeshFilter::MeshType * -MeshToWasmMeshFilter -::GetInput() +MeshToWasmMeshFilter::GetInput() { return itkDynamicCastInDebugMode(this->GetPrimaryInput()); } template const typename MeshToWasmMeshFilter::MeshType * -MeshToWasmMeshFilter -::GetInput(unsigned int idx) +MeshToWasmMeshFilter::GetInput(unsigned int idx) { return itkDynamicCastInDebugMode(this->ProcessObject::GetInput(idx)); } template void -MeshToWasmMeshFilter -::GenerateData() +MeshToWasmMeshFilter::GenerateData() { // Get the input and output pointers const MeshType * mesh = this->GetInput(); - WasmMeshType * wasmMesh = this->GetOutput(); + WasmMeshType * wasmMesh = this->GetOutput(); wasmMesh->SetMesh(mesh); constexpr bool inMemory = true; - const auto meshJSON = meshToMeshJSON(mesh, wasmMesh, inMemory); - std::string serialized{}; - auto ec = glz::write(meshJSON, serialized); + const auto meshJSON = meshToMeshJSON(mesh, wasmMesh, inMemory); + std::string serialized{}; + auto ec = glz::write(meshJSON, serialized); if (ec) { itkExceptionMacro("Failed to serialize MeshJSON"); @@ -142,8 +131,7 @@ MeshToWasmMeshFilter template void -MeshToWasmMeshFilter -::PrintSelf(std::ostream & os, Indent indent) const +MeshToWasmMeshFilter::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent); } diff --git a/include/itkMetaDataDictionaryCBOR.h b/include/itkMetaDataDictionaryCBOR.h index 54d1fb641..5deff1fa3 100644 --- a/include/itkMetaDataDictionaryCBOR.h +++ b/include/itkMetaDataDictionaryCBOR.h @@ -35,9 +35,11 @@ namespace itk { -WebAssemblyInterface_EXPORT void metaDataDictionaryToCBOR(const itk::MetaDataDictionary & dictionary, cbor_item_t * metadataCbor); +WebAssemblyInterface_EXPORT void +metaDataDictionaryToCBOR(const itk::MetaDataDictionary & dictionary, cbor_item_t * metadataCbor); -WebAssemblyInterface_EXPORT void cborToMetaDataDictionary(const cbor_item_t * metadataCbor, itk::MetaDataDictionary & dictionary); +WebAssemblyInterface_EXPORT void +cborToMetaDataDictionary(const cbor_item_t * metadataCbor, itk::MetaDataDictionary & dictionary); } // end namespace itk diff --git a/include/itkMetaDataDictionaryJSON.h b/include/itkMetaDataDictionaryJSON.h index 25d28c545..abf102eee 100644 --- a/include/itkMetaDataDictionaryJSON.h +++ b/include/itkMetaDataDictionaryJSON.h @@ -39,9 +39,11 @@ using MetadataEntryJSON = std::tuple; using MetadataJSON = std::vector; -WebAssemblyInterface_EXPORT void metaDataDictionaryToJSON(const itk::MetaDataDictionary & dictionary, MetadataJSON & metadataJson); +WebAssemblyInterface_EXPORT void +metaDataDictionaryToJSON(const itk::MetaDataDictionary & dictionary, MetadataJSON & metadataJson); -WebAssemblyInterface_EXPORT void jsonToMetaDataDictionary(const MetadataJSON & metadataJson, itk::MetaDataDictionary & dictionary); +WebAssemblyInterface_EXPORT void +jsonToMetaDataDictionary(const MetadataJSON & metadataJson, itk::MetaDataDictionary & dictionary); } // end namespace itk diff --git a/include/itkOutputBinaryStream.h b/include/itkOutputBinaryStream.h index a48902a35..7821a87dc 100644 --- a/include/itkOutputBinaryStream.h +++ b/include/itkOutputBinaryStream.h @@ -23,10 +23,10 @@ #include #ifndef ITK_WASM_NO_MEMORY_IO -#include +# include #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include +# include #endif #include "WebAssemblyInterfaceExport.h" @@ -41,19 +41,22 @@ namespace wasm * \brief Output text std::ostream for an itk::wasm::Pipeline * * This stream is written to the filesystem or memory when the object goes out of scope. - * + * * Call `Get()` to get the std::ostream & to use an output for a pipeline. - * + * * \ingroup WebAssemblyInterface */ class WebAssemblyInterface_EXPORT OutputBinaryStream { public: - std::ostream & Get() { + std::ostream & + Get() + { return *m_OStream; } - void SetFileName(const std::string & fileName) + void + SetFileName(const std::string & fileName) { if (m_DeleteOStream && m_OStream != nullptr) { @@ -67,7 +70,8 @@ class WebAssemblyInterface_EXPORT OutputBinaryStream ~OutputBinaryStream(); /** Output index. */ - void SetIdentifier(const std::string & identifier) + void + SetIdentifier(const std::string & identifier) { if (m_DeleteOStream && m_OStream != nullptr) { @@ -79,14 +83,15 @@ class WebAssemblyInterface_EXPORT OutputBinaryStream m_OStream = &(m_WasmStringStream->GetStringStream()); this->m_Identifier = identifier; } - const std::string & GetIdentifier() const + const std::string & + GetIdentifier() const { return this->m_Identifier; } protected: - std::ostream * m_OStream{nullptr}; - bool m_DeleteOStream{false}; + std::ostream * m_OStream{ nullptr }; + bool m_DeleteOStream{ false }; std::string m_Identifier; @@ -94,7 +99,8 @@ class WebAssemblyInterface_EXPORT OutputBinaryStream }; -WebAssemblyInterface_EXPORT bool lexical_cast(const std::string &output, OutputBinaryStream &outputStream); +WebAssemblyInterface_EXPORT bool +lexical_cast(const std::string & output, OutputBinaryStream & outputStream); } // end namespace wasm } // end namespace itk diff --git a/include/itkOutputImage.h b/include/itkOutputImage.h index 1f88645b3..13fdf6907 100644 --- a/include/itkOutputImage.h +++ b/include/itkOutputImage.h @@ -21,12 +21,12 @@ #include "itkPipeline.h" #ifndef ITK_WASM_NO_MEMORY_IO -#include "itkWasmExports.h" -#include "itkWasmImage.h" -#include "itkImageToWasmImageFilter.h" +# include "itkWasmExports.h" +# include "itkWasmImage.h" +# include "itkImageToWasmImageFilter.h" #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include "itkImageFileWriter.h" +# include "itkImageFileWriter.h" #endif namespace itk @@ -38,9 +38,9 @@ namespace wasm * \brief Output image for an itk::wasm::Pipeline * * This image is written to the filesystem or memory when it goes out of scope. - * + * * Call `GetImage()` to get the TImage * to use an input to a pipeline. - * + * * \ingroup WebAssemblyInterface */ template @@ -49,45 +49,51 @@ class ITK_TEMPLATE_EXPORT OutputImage public: using ImageType = TImage; - void Set(const ImageType * image) { + void + Set(const ImageType * image) + { this->m_Image = image; } - const ImageType * Get() const { + const ImageType * + Get() const + { return this->m_Image.GetPointer(); } /** FileName or output index. */ - void SetIdentifier(const std::string & identifier) + void + SetIdentifier(const std::string & identifier) { this->m_Identifier = identifier; } - const std::string & GetIdentifier() const + const std::string & + GetIdentifier() const { return this->m_Identifier; } OutputImage() = default; - ~OutputImage() { - if(wasm::Pipeline::get_use_memory_io()) + ~OutputImage() + { + if (wasm::Pipeline::get_use_memory_io()) { #ifndef ITK_WASM_NO_MEMORY_IO - if (!this->m_Image.IsNull() && !this->m_Identifier.empty()) + if (!this->m_Image.IsNull() && !this->m_Identifier.empty()) { using ImageToWasmImageFilterType = ImageToWasmImageFilter; auto imageToWasmImageFilter = ImageToWasmImageFilterType::New(); imageToWasmImageFilter->SetInput(this->m_Image); imageToWasmImageFilter->Update(); - auto wasmImage = imageToWasmImageFilter->GetOutput(); + auto wasmImage = imageToWasmImageFilter->GetOutput(); const auto index = std::stoi(this->m_Identifier); setMemoryStoreOutputDataObject(0, index, wasmImage); - const auto dataAddress = reinterpret_cast< size_t >( wasmImage->GetImage()->GetBufferPointer() ); + const auto dataAddress = reinterpret_cast(wasmImage->GetImage()->GetBufferPointer()); using ConvertPixelTraits = DefaultConvertPixelTraits; - const auto dataSize = - wasmImage->GetImage()->GetBufferedRegion().GetNumberOfPixels() - * sizeof(typename ConvertPixelTraits::ComponentType) - * wasmImage->GetImage()->GetNumberOfComponentsPerPixel(); + const auto dataSize = wasmImage->GetImage()->GetBufferedRegion().GetNumberOfPixels() * + sizeof(typename ConvertPixelTraits::ComponentType) * + wasmImage->GetImage()->GetNumberOfComponentsPerPixel(); if (dataSize <= 0) { std::cerr << "dataSize cannot be zero or negative." << std::endl; @@ -95,28 +101,30 @@ class ITK_TEMPLATE_EXPORT OutputImage } setMemoryStoreOutputArray(0, index, 0, dataAddress, dataSize); - const auto directionAddress = reinterpret_cast< size_t >( wasmImage->GetImage()->GetDirection().GetVnlMatrix().begin() ); + const auto directionAddress = + reinterpret_cast(wasmImage->GetImage()->GetDirection().GetVnlMatrix().begin()); const auto directionSize = wasmImage->GetImage()->GetDirection().GetVnlMatrix().size() * sizeof(double); setMemoryStoreOutputArray(0, index, 1, directionAddress, directionSize); } #else - std::cerr << "Memory IO not supported" << std::endl; - abort(); + std::cerr << "Memory IO not supported" << std::endl; + abort(); #endif } else { #ifndef ITK_WASM_NO_FILESYSTEM_IO - if (!this->m_Image.IsNull() && !this->m_Identifier.empty()) + if (!this->m_Image.IsNull() && !this->m_Identifier.empty()) { - itk::WriteImage(this->m_Image, this->m_Identifier); + itk::WriteImage(this->m_Image, this->m_Identifier); } #else - std::cerr << "Filesystem IO not supported" << std::endl; - abort(); + std::cerr << "Filesystem IO not supported" << std::endl; + abort(); #endif } } + protected: typename TImage::ConstPointer m_Image; @@ -124,7 +132,8 @@ class ITK_TEMPLATE_EXPORT OutputImage }; template -bool lexical_cast(const std::string &input, OutputImage &outputImage) +bool +lexical_cast(const std::string & input, OutputImage & outputImage) { outputImage.SetIdentifier(input); return true; diff --git a/include/itkOutputMesh.h b/include/itkOutputMesh.h index 4fb21145b..8608f418d 100644 --- a/include/itkOutputMesh.h +++ b/include/itkOutputMesh.h @@ -24,12 +24,12 @@ #include "itkQuadEdgeMesh.h" #ifndef ITK_WASM_NO_MEMORY_IO -#include "itkWasmExports.h" -#include "itkWasmMesh.h" -#include "itkMeshToWasmMeshFilter.h" +# include "itkWasmExports.h" +# include "itkWasmMesh.h" +# include "itkMeshToWasmMeshFilter.h" #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include "itkMeshFileWriter.h" +# include "itkMeshFileWriter.h" #endif namespace itk @@ -52,49 +52,57 @@ class ITK_TEMPLATE_EXPORT OutputMesh public: using MeshType = TMesh; - void Set(const MeshType * mesh) { + void + Set(const MeshType * mesh) + { this->m_Mesh = mesh; } - const MeshType * Get() const { + const MeshType * + Get() const + { return this->m_Mesh.GetPointer(); } /** FileName or output index. */ - void SetIdentifier(const std::string & identifier) + void + SetIdentifier(const std::string & identifier) { this->m_Identifier = identifier; } - const std::string & GetIdentifier() const + const std::string & + GetIdentifier() const { return this->m_Identifier; } OutputMesh() = default; - ~OutputMesh() { - if(wasm::Pipeline::get_use_memory_io()) + ~OutputMesh() + { + if (wasm::Pipeline::get_use_memory_io()) { #ifndef ITK_WASM_NO_MEMORY_IO - if (!this->m_Mesh.IsNull() && !this->m_Identifier.empty()) + if (!this->m_Mesh.IsNull() && !this->m_Identifier.empty()) { using MeshToWasmMeshFilterType = MeshToWasmMeshFilter; auto meshToWasmMeshFilter = MeshToWasmMeshFilterType::New(); meshToWasmMeshFilter->SetInput(this->m_Mesh); meshToWasmMeshFilter->Update(); - auto wasmMesh = meshToWasmMeshFilter->GetOutput(); + auto wasmMesh = meshToWasmMeshFilter->GetOutput(); const auto index = std::stoi(this->m_Identifier); setMemoryStoreOutputDataObject(0, index, wasmMesh); if (this->m_Mesh->GetNumberOfPoints() > 0) { - const auto pointsAddress = reinterpret_cast< size_t >( &(wasmMesh->GetMesh()->GetPoints()->at(0)) ); - const auto pointsSize = wasmMesh->GetMesh()->GetPoints()->Size() * sizeof(typename MeshType::CoordinateType) * MeshType::PointDimension; + const auto pointsAddress = reinterpret_cast(&(wasmMesh->GetMesh()->GetPoints()->at(0))); + const auto pointsSize = wasmMesh->GetMesh()->GetPoints()->Size() * sizeof(typename MeshType::CoordinateType) * + MeshType::PointDimension; setMemoryStoreOutputArray(0, index, 0, pointsAddress, pointsSize); } if (this->m_Mesh->GetNumberOfCells() > 0) { - const auto cellsAddress = reinterpret_cast< size_t >( &(wasmMesh->GetCellBuffer()->at(0)) ); + const auto cellsAddress = reinterpret_cast(&(wasmMesh->GetCellBuffer()->at(0))); const auto cellsSize = wasmMesh->GetCellBuffer()->Size() * sizeof(typename MeshType::CellIdentifier); setMemoryStoreOutputArray(0, index, 1, cellsAddress, cellsSize); } @@ -103,8 +111,10 @@ class ITK_TEMPLATE_EXPORT OutputMesh { using PointPixelType = typename MeshType::PixelType; using ConvertPointPixelTraits = MeshConvertPixelTraits; - const auto pointDataAddress = reinterpret_cast< size_t >( &(wasmMesh->GetMesh()->GetPointData()->at(0)) ); - const auto pointDataSize = wasmMesh->GetMesh()->GetPointData()->Size() * sizeof(typename ConvertPointPixelTraits::ComponentType) * ConvertPointPixelTraits::GetNumberOfComponents(); + const auto pointDataAddress = reinterpret_cast(&(wasmMesh->GetMesh()->GetPointData()->at(0))); + const auto pointDataSize = wasmMesh->GetMesh()->GetPointData()->Size() * + sizeof(typename ConvertPointPixelTraits::ComponentType) * + ConvertPointPixelTraits::GetNumberOfComponents(); setMemoryStoreOutputArray(0, index, 2, pointDataAddress, pointDataSize); } @@ -112,33 +122,36 @@ class ITK_TEMPLATE_EXPORT OutputMesh { using CellPixelType = typename MeshType::CellPixelType; using ConvertCellPixelTraits = MeshConvertPixelTraits; - const auto cellDataAddress = reinterpret_cast< size_t >( &(wasmMesh->GetMesh()->GetCellData()->at(0)) ); - const auto cellDataSize = wasmMesh->GetMesh()->GetCellData()->Size() * sizeof(typename ConvertCellPixelTraits::ComponentType) * ConvertCellPixelTraits::GetNumberOfComponents(); + const auto cellDataAddress = reinterpret_cast(&(wasmMesh->GetMesh()->GetCellData()->at(0))); + const auto cellDataSize = wasmMesh->GetMesh()->GetCellData()->Size() * + sizeof(typename ConvertCellPixelTraits::ComponentType) * + ConvertCellPixelTraits::GetNumberOfComponents(); setMemoryStoreOutputArray(0, index, 3, cellDataAddress, cellDataSize); } } #else - std::cerr << "Memory IO not supported" << std::endl; - abort(); + std::cerr << "Memory IO not supported" << std::endl; + abort(); #endif } else { #ifndef ITK_WASM_NO_FILESYSTEM_IO - if (!this->m_Mesh.IsNull() && !this->m_Identifier.empty()) + if (!this->m_Mesh.IsNull() && !this->m_Identifier.empty()) { - using MeshWriterType = itk::MeshFileWriter; - auto meshWriter = MeshWriterType::New(); - meshWriter->SetFileName(this->m_Identifier); - meshWriter->SetInput(this->m_Mesh); - meshWriter->Update(); + using MeshWriterType = itk::MeshFileWriter; + auto meshWriter = MeshWriterType::New(); + meshWriter->SetFileName(this->m_Identifier); + meshWriter->SetInput(this->m_Mesh); + meshWriter->Update(); } #else - std::cerr << "Filesystem IO not supported" << std::endl; - abort(); + std::cerr << "Filesystem IO not supported" << std::endl; + abort(); #endif } } + protected: typename TMesh::ConstPointer m_Mesh; @@ -247,7 +260,8 @@ class OutputMesh> }; template -bool lexical_cast(const std::string &input, OutputMesh &outputMesh) +bool +lexical_cast(const std::string & input, OutputMesh & outputMesh) { outputMesh.SetIdentifier(input); return true; diff --git a/include/itkOutputPointSet.h b/include/itkOutputPointSet.h index 0289c9999..839d8df9e 100644 --- a/include/itkOutputPointSet.h +++ b/include/itkOutputPointSet.h @@ -22,13 +22,13 @@ #include "itkMeshConvertPixelTraits.h" #ifndef ITK_WASM_NO_MEMORY_IO -#include "itkWasmExports.h" -#include "itkWasmPointSet.h" -#include "itkPointSetToWasmPointSetFilter.h" +# include "itkWasmExports.h" +# include "itkWasmPointSet.h" +# include "itkPointSetToWasmPointSetFilter.h" #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include "itkMesh.h" -#include "itkMeshFileWriter.h" +# include "itkMesh.h" +# include "itkMeshFileWriter.h" #endif namespace itk @@ -40,9 +40,9 @@ namespace wasm * \brief Output point set for an itk::wasm::Pipeline * * This point set is written to the filesystem or memory when it goes out of scope. - * + * * Call `GetPointSet()` to get the TPointSet * to use an input to a pipeline. - * + * * \ingroup WebAssemblyInterface */ template @@ -51,43 +51,51 @@ class ITK_TEMPLATE_EXPORT OutputPointSet public: using PointSetType = TPointSet; - void Set(const PointSetType * pointSet) { + void + Set(const PointSetType * pointSet) + { this->m_PointSet = pointSet; } - const PointSetType * Get() const { + const PointSetType * + Get() const + { return this->m_PointSet.GetPointer(); } /** FileName or output index. */ - void SetIdentifier(const std::string & identifier) + void + SetIdentifier(const std::string & identifier) { this->m_Identifier = identifier; } - const std::string & GetIdentifier() const + const std::string & + GetIdentifier() const { return this->m_Identifier; } OutputPointSet() = default; - ~OutputPointSet() { - if(wasm::Pipeline::get_use_memory_io()) + ~OutputPointSet() + { + if (wasm::Pipeline::get_use_memory_io()) { #ifndef ITK_WASM_NO_MEMORY_IO - if (!this->m_PointSet.IsNull() && !this->m_Identifier.empty()) + if (!this->m_PointSet.IsNull() && !this->m_Identifier.empty()) { using PointSetToWasmPointSetFilterType = PointSetToWasmPointSetFilter; auto pointSetToWasmPointSetFilter = PointSetToWasmPointSetFilterType::New(); pointSetToWasmPointSetFilter->SetInput(this->m_PointSet); pointSetToWasmPointSetFilter->Update(); - auto wasmPointSet = pointSetToWasmPointSetFilter->GetOutput(); + auto wasmPointSet = pointSetToWasmPointSetFilter->GetOutput(); const auto index = std::stoi(this->m_Identifier); setMemoryStoreOutputDataObject(0, index, wasmPointSet); if (this->m_PointSet->GetNumberOfPoints() > 0) { - const auto pointsAddress = reinterpret_cast< size_t >( &(wasmPointSet->GetPointSet()->GetPoints()->at(0)) ); - const auto pointsSize = wasmPointSet->GetPointSet()->GetPoints()->Size() * sizeof(typename PointSetType::CoordinateType) * PointSetType::PointDimension; + const auto pointsAddress = reinterpret_cast(&(wasmPointSet->GetPointSet()->GetPoints()->at(0))); + const auto pointsSize = wasmPointSet->GetPointSet()->GetPoints()->Size() * + sizeof(typename PointSetType::CoordinateType) * PointSetType::PointDimension; setMemoryStoreOutputArray(0, index, 0, pointsAddress, pointsSize); } @@ -95,37 +103,40 @@ class ITK_TEMPLATE_EXPORT OutputPointSet { using PointPixelType = typename PointSetType::PixelType; using ConvertPointPixelTraits = MeshConvertPixelTraits; - const auto pointDataAddress = reinterpret_cast< size_t >( &(wasmPointSet->GetPointSet()->GetPointData()->at(0)) ); - const auto pointDataSize = wasmPointSet->GetPointSet()->GetPointData()->Size() * sizeof(typename ConvertPointPixelTraits::ComponentType) * ConvertPointPixelTraits::GetNumberOfComponents(); + const auto pointDataAddress = reinterpret_cast(&(wasmPointSet->GetPointSet()->GetPointData()->at(0))); + const auto pointDataSize = wasmPointSet->GetPointSet()->GetPointData()->Size() * + sizeof(typename ConvertPointPixelTraits::ComponentType) * + ConvertPointPixelTraits::GetNumberOfComponents(); setMemoryStoreOutputArray(0, index, 1, pointDataAddress, pointDataSize); } } #else - std::cerr << "Memory IO not supported" << std::endl; - abort(); + std::cerr << "Memory IO not supported" << std::endl; + abort(); #endif } else { #ifndef ITK_WASM_NO_FILESYSTEM_IO - if (!this->m_PointSet.IsNull() && !this->m_Identifier.empty()) + if (!this->m_PointSet.IsNull() && !this->m_Identifier.empty()) { - using MeshType = Mesh; - using PointSetWriterType = itk::MeshFileWriter; - auto pointSetWriter = PointSetWriterType::New(); - pointSetWriter->SetFileName(this->m_Identifier); - typename MeshType::Pointer mesh = MeshType::New(); - mesh->SetPoints(const_cast(this->m_PointSet->GetPoints())); - mesh->SetPointData(const_cast(this->m_PointSet->GetPointData())); - pointSetWriter->SetInput(mesh); - pointSetWriter->Update(); + using MeshType = Mesh; + using PointSetWriterType = itk::MeshFileWriter; + auto pointSetWriter = PointSetWriterType::New(); + pointSetWriter->SetFileName(this->m_Identifier); + typename MeshType::Pointer mesh = MeshType::New(); + mesh->SetPoints(const_cast(this->m_PointSet->GetPoints())); + mesh->SetPointData(const_cast(this->m_PointSet->GetPointData())); + pointSetWriter->SetInput(mesh); + pointSetWriter->Update(); } #else - std::cerr << "Filesystem IO not supported" << std::endl; - abort(); + std::cerr << "Filesystem IO not supported" << std::endl; + abort(); #endif } } + protected: typename TPointSet::ConstPointer m_PointSet; @@ -133,7 +144,8 @@ class ITK_TEMPLATE_EXPORT OutputPointSet }; template -bool lexical_cast(const std::string &input, OutputPointSet &outputPointSet) +bool +lexical_cast(const std::string & input, OutputPointSet & outputPointSet) { outputPointSet.SetIdentifier(input); return true; diff --git a/include/itkOutputPolyData.h b/include/itkOutputPolyData.h index 2a9d57d26..7c3115a84 100644 --- a/include/itkOutputPolyData.h +++ b/include/itkOutputPolyData.h @@ -22,13 +22,13 @@ #include "itkMeshConvertPixelTraits.h" #ifndef ITK_WASM_NO_MEMORY_IO -#include "itkWasmExports.h" -#include "itkWasmPolyData.h" -#include "itkPolyDataToWasmPolyDataFilter.h" +# include "itkWasmExports.h" +# include "itkWasmPolyData.h" +# include "itkPolyDataToWasmPolyDataFilter.h" #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include "itkMeshFileWriter.h" -#include "itkPolyDataToMeshFilter.h" +# include "itkMeshFileWriter.h" +# include "itkPolyDataToMeshFilter.h" #endif namespace itk @@ -40,9 +40,9 @@ namespace wasm * \brief Output polyData for an itk::wasm::Pipeline * * This polyData is written to the filesystem or memory when it goes out of scope. - * + * * Call `GetPolyData()` to get the TPolyData * to use an input to a pipeline. - * + * * \ingroup WebAssemblyInterface */ template @@ -51,70 +51,79 @@ class ITK_TEMPLATE_EXPORT OutputPolyData public: using PolyDataType = TPolyData; - void Set(const PolyDataType * polyData) { + void + Set(const PolyDataType * polyData) + { this->m_PolyData = polyData; } - const PolyDataType * Get() const { + const PolyDataType * + Get() const + { return this->m_PolyData.GetPointer(); } /** FileName or output index. */ - void SetIdentifier(const std::string & identifier) + void + SetIdentifier(const std::string & identifier) { this->m_Identifier = identifier; } - const std::string & GetIdentifier() const + const std::string & + GetIdentifier() const { return this->m_Identifier; } OutputPolyData() = default; - ~OutputPolyData() { - if(wasm::Pipeline::get_use_memory_io()) + ~OutputPolyData() + { + if (wasm::Pipeline::get_use_memory_io()) { #ifndef ITK_WASM_NO_MEMORY_IO - if (!this->m_PolyData.IsNull() && !this->m_Identifier.empty()) + if (!this->m_PolyData.IsNull() && !this->m_Identifier.empty()) { using PolyDataToWasmPolyDataFilterType = PolyDataToWasmPolyDataFilter; auto polyDataToWasmPolyDataFilter = PolyDataToWasmPolyDataFilterType::New(); polyDataToWasmPolyDataFilter->SetInput(this->m_PolyData); polyDataToWasmPolyDataFilter->Update(); - auto wasmPolyData = polyDataToWasmPolyDataFilter->GetOutput(); + auto wasmPolyData = polyDataToWasmPolyDataFilter->GetOutput(); const auto index = std::stoi(this->m_Identifier); setMemoryStoreOutputDataObject(0, index, wasmPolyData); if (this->m_PolyData->GetNumberOfPoints() > 0) { - const auto pointsAddress = reinterpret_cast< size_t >( &(wasmPolyData->GetPolyData()->GetPoints()->at(0)) ); - const auto pointsSize = wasmPolyData->GetPolyData()->GetPoints()->Size() * PolyDataType::PointDimension * sizeof(typename PolyDataType::CoordinateType); + const auto pointsAddress = reinterpret_cast(&(wasmPolyData->GetPolyData()->GetPoints()->at(0))); + const auto pointsSize = wasmPolyData->GetPolyData()->GetPoints()->Size() * PolyDataType::PointDimension * + sizeof(typename PolyDataType::CoordinateType); setMemoryStoreOutputArray(0, index, 0, pointsAddress, pointsSize); } if (this->m_PolyData->GetVertices() && this->m_PolyData->GetVertices()->Size() > 0) { - const auto verticesAddress = reinterpret_cast< size_t >( &(wasmPolyData->GetPolyData()->GetVertices()->at(0)) ); + const auto verticesAddress = reinterpret_cast(&(wasmPolyData->GetPolyData()->GetVertices()->at(0))); const auto verticesSize = wasmPolyData->GetPolyData()->GetVertices()->Size() * sizeof(uint32_t); setMemoryStoreOutputArray(0, index, 1, verticesAddress, verticesSize); } if (this->m_PolyData->GetLines() && this->m_PolyData->GetLines()->Size() > 0) { - const auto linesAddress = reinterpret_cast< size_t >( &(wasmPolyData->GetPolyData()->GetLines()->at(0)) ); + const auto linesAddress = reinterpret_cast(&(wasmPolyData->GetPolyData()->GetLines()->at(0))); const auto linesSize = wasmPolyData->GetPolyData()->GetLines()->Size() * sizeof(uint32_t); setMemoryStoreOutputArray(0, index, 2, linesAddress, linesSize); } if (this->m_PolyData->GetPolygons() && this->m_PolyData->GetPolygons()->Size() > 0) { - const auto polygonsAddress = reinterpret_cast< size_t >( &(wasmPolyData->GetPolyData()->GetPolygons()->at(0)) ); + const auto polygonsAddress = reinterpret_cast(&(wasmPolyData->GetPolyData()->GetPolygons()->at(0))); const auto polygonsSize = wasmPolyData->GetPolyData()->GetPolygons()->Size() * sizeof(uint32_t); setMemoryStoreOutputArray(0, index, 3, polygonsAddress, polygonsSize); } if (this->m_PolyData->GetTriangleStrips() && this->m_PolyData->GetTriangleStrips()->Size() > 0) { - const auto triangleStripsAddress = reinterpret_cast< size_t >( &(wasmPolyData->GetPolyData()->GetTriangleStrips()->at(0)) ); + const auto triangleStripsAddress = + reinterpret_cast(&(wasmPolyData->GetPolyData()->GetTriangleStrips()->at(0))); const auto triangleStripsSize = wasmPolyData->GetPolyData()->GetTriangleStrips()->Size() * sizeof(uint32_t); setMemoryStoreOutputArray(0, index, 4, triangleStripsAddress, triangleStripsSize); } @@ -123,8 +132,10 @@ class ITK_TEMPLATE_EXPORT OutputPolyData { using PointPixelType = typename PolyDataType::PixelType; using ConvertPointPixelTraits = MeshConvertPixelTraits; - const auto pointDataAddress = reinterpret_cast< size_t >( &(wasmPolyData->GetPolyData()->GetPointData()->at(0)) ); - const auto pointDataSize = wasmPolyData->GetPolyData()->GetPointData()->Size() * sizeof(typename ConvertPointPixelTraits::ComponentType) * ConvertPointPixelTraits::GetNumberOfComponents(); + const auto pointDataAddress = reinterpret_cast(&(wasmPolyData->GetPolyData()->GetPointData()->at(0))); + const auto pointDataSize = wasmPolyData->GetPolyData()->GetPointData()->Size() * + sizeof(typename ConvertPointPixelTraits::ComponentType) * + ConvertPointPixelTraits::GetNumberOfComponents(); setMemoryStoreOutputArray(0, index, 5, pointDataAddress, pointDataSize); } @@ -132,37 +143,40 @@ class ITK_TEMPLATE_EXPORT OutputPolyData { using CellPixelType = typename PolyDataType::CellPixelType; using ConvertCellPixelTraits = MeshConvertPixelTraits; - const auto cellDataAddress = reinterpret_cast< size_t >( &(wasmPolyData->GetPolyData()->GetCellData()->at(0)) ); - const auto cellDataSize = wasmPolyData->GetPolyData()->GetCellData()->Size() * sizeof(typename ConvertCellPixelTraits::ComponentType) * ConvertCellPixelTraits::GetNumberOfComponents(); + const auto cellDataAddress = reinterpret_cast(&(wasmPolyData->GetPolyData()->GetCellData()->at(0))); + const auto cellDataSize = wasmPolyData->GetPolyData()->GetCellData()->Size() * + sizeof(typename ConvertCellPixelTraits::ComponentType) * + ConvertCellPixelTraits::GetNumberOfComponents(); setMemoryStoreOutputArray(0, index, 6, cellDataAddress, cellDataSize); } } #else - std::cerr << "Memory IO not supported" << std::endl; - abort(); + std::cerr << "Memory IO not supported" << std::endl; + abort(); #endif } else { #ifndef ITK_WASM_NO_FILESYSTEM_IO - if (!this->m_PolyData.IsNull() && !this->m_Identifier.empty()) + if (!this->m_PolyData.IsNull() && !this->m_Identifier.empty()) { - using PolyDataToMeshFilterType = PolyDataToMeshFilter; - auto polyDataToMeshFilter = PolyDataToMeshFilterType::New(); - polyDataToMeshFilter->SetInput(this->m_PolyData); - using MeshType = typename PolyDataToMeshFilterType::OutputMeshType; - using MeshWriterType = MeshFileWriter; - auto meshWriter = MeshWriterType::New(); - meshWriter->SetFileName(this->m_Identifier); - meshWriter->SetInput(polyDataToMeshFilter->GetOutput()); - meshWriter->Update(); + using PolyDataToMeshFilterType = PolyDataToMeshFilter; + auto polyDataToMeshFilter = PolyDataToMeshFilterType::New(); + polyDataToMeshFilter->SetInput(this->m_PolyData); + using MeshType = typename PolyDataToMeshFilterType::OutputMeshType; + using MeshWriterType = MeshFileWriter; + auto meshWriter = MeshWriterType::New(); + meshWriter->SetFileName(this->m_Identifier); + meshWriter->SetInput(polyDataToMeshFilter->GetOutput()); + meshWriter->Update(); } #else - std::cerr << "Filesystem IO not supported" << std::endl; - abort(); + std::cerr << "Filesystem IO not supported" << std::endl; + abort(); #endif } } + protected: typename TPolyData::ConstPointer m_PolyData; @@ -170,7 +184,8 @@ class ITK_TEMPLATE_EXPORT OutputPolyData }; template -bool lexical_cast(const std::string &input, OutputPolyData &outputPolyData) +bool +lexical_cast(const std::string & input, OutputPolyData & outputPolyData) { outputPolyData.SetIdentifier(input); return true; diff --git a/include/itkOutputTextStream.h b/include/itkOutputTextStream.h index 63ea14510..42c9cb24d 100644 --- a/include/itkOutputTextStream.h +++ b/include/itkOutputTextStream.h @@ -23,10 +23,10 @@ #include #ifndef ITK_WASM_NO_MEMORY_IO -#include +# include #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include +# include #endif #include "WebAssemblyInterfaceExport.h" @@ -41,19 +41,22 @@ namespace wasm * \brief Output text std::ostream for an itk::wasm::Pipeline * * This stream is written to the filesystem or memory when the object goes out of scope. - * + * * Call `Get()` to get the std::ostream & to use an output for a pipeline. - * + * * \ingroup WebAssemblyInterface */ class WebAssemblyInterface_EXPORT OutputTextStream { public: - std::ostream & Get() { + std::ostream & + Get() + { return *m_OStream; } - void SetFileName(const std::string & fileName) + void + SetFileName(const std::string & fileName) { if (m_DeleteOStream && m_OStream != nullptr) { @@ -67,7 +70,8 @@ class WebAssemblyInterface_EXPORT OutputTextStream ~OutputTextStream(); /** Output index. */ - void SetIdentifier(const std::string & identifier) + void + SetIdentifier(const std::string & identifier) { if (m_DeleteOStream && m_OStream != nullptr) { @@ -79,14 +83,15 @@ class WebAssemblyInterface_EXPORT OutputTextStream m_OStream = &(m_WasmStringStream->GetStringStream()); this->m_Identifier = identifier; } - const std::string & GetIdentifier() const + const std::string & + GetIdentifier() const { return this->m_Identifier; } protected: - std::ostream * m_OStream{nullptr}; - bool m_DeleteOStream{false}; + std::ostream * m_OStream{ nullptr }; + bool m_DeleteOStream{ false }; std::string m_Identifier; @@ -94,7 +99,8 @@ class WebAssemblyInterface_EXPORT OutputTextStream }; -WebAssemblyInterface_EXPORT bool lexical_cast(const std::string &output, OutputTextStream &outputStream); +WebAssemblyInterface_EXPORT bool +lexical_cast(const std::string & output, OutputTextStream & outputStream); } // end namespace wasm } // end namespace itk diff --git a/include/itkOutputTransform.h b/include/itkOutputTransform.h index eee4fc64e..8c8bc745d 100644 --- a/include/itkOutputTransform.h +++ b/include/itkOutputTransform.h @@ -21,14 +21,14 @@ #include "itkPipeline.h" #ifndef ITK_WASM_NO_MEMORY_IO -#include "itkWasmExports.h" -#include "itkWasmTransform.h" -#include "itkTransformToWasmTransformFilter.h" -#include "itkCompositeTransform.h" -#include "itkCompositeTransformIOHelper.h" +# include "itkWasmExports.h" +# include "itkWasmTransform.h" +# include "itkTransformToWasmTransformFilter.h" +# include "itkCompositeTransform.h" +# include "itkCompositeTransformIOHelper.h" #endif #ifndef ITK_WASM_NO_FILESYSTEM_IO -#include "itkTransformFileWriter.h" +# include "itkTransformFileWriter.h" #endif namespace itk @@ -40,9 +40,9 @@ namespace wasm * \brief Output transform for an itk::wasm::Pipeline * * This transform is written to the filesystem or memory when it goes out of scope. - * + * * Call `GetTransform()` to get the TTransform * to use an input to a pipeline. - * + * * \ingroup WebAssemblyInterface */ template @@ -51,36 +51,43 @@ class ITK_TEMPLATE_EXPORT OutputTransform public: using TransformType = TTransform; - void Set(const TransformType * transform) { + void + Set(const TransformType * transform) + { this->m_Transform = transform; } - const TransformType * Get() const { + const TransformType * + Get() const + { return this->m_Transform.GetPointer(); } /** FileName or output index. */ - void SetIdentifier(const std::string & identifier) + void + SetIdentifier(const std::string & identifier) { this->m_Identifier = identifier; } - const std::string & GetIdentifier() const + const std::string & + GetIdentifier() const { return this->m_Identifier; } OutputTransform() = default; - ~OutputTransform() { - if(wasm::Pipeline::get_use_memory_io()) + ~OutputTransform() + { + if (wasm::Pipeline::get_use_memory_io()) { #ifndef ITK_WASM_NO_MEMORY_IO - if (!this->m_Transform.IsNull() && !this->m_Identifier.empty()) + if (!this->m_Transform.IsNull() && !this->m_Identifier.empty()) { using TransformToWasmTransformFilterType = TransformToWasmTransformFilter; auto transformToWasmTransformFilter = TransformToWasmTransformFilterType::New(); transformToWasmTransformFilter->SetTransform(this->m_Transform.GetPointer()); transformToWasmTransformFilter->Update(); - auto wasmTransform = transformToWasmTransformFilter->GetOutput(); + auto wasmTransform = transformToWasmTransformFilter->GetOutput(); const auto index = std::stoi(this->m_Identifier); setMemoryStoreOutputDataObject(0, index, wasmTransform); @@ -90,20 +97,20 @@ class ITK_TEMPLATE_EXPORT OutputTransform auto compositeTransform = dynamic_cast(wasmTransform->GetTransform()); if (compositeTransform) { - unsigned int dataCount = 0; + unsigned int dataCount = 0; CompositeTransformIOHelperTemplate helper; auto transformList = helper.GetTransformList(compositeTransform); // composite transform transformList.pop_front(); // iterate through the transform list and store each transfrom's fixed parameters and parameters - for (const auto & transform: transformList) + for (const auto & transform : transformList) { - const auto fixedParamsAddress = reinterpret_cast< size_t >( transform->GetFixedParameters().data_block() ); + const auto fixedParamsAddress = reinterpret_cast(transform->GetFixedParameters().data_block()); const auto fixedParamsSize = transform->GetFixedParameters().Size() * sizeof(FixedParametersValueType); setMemoryStoreOutputArray(0, index, dataCount, fixedParamsAddress, fixedParamsSize); ++dataCount; - const auto paramsAddress = reinterpret_cast< size_t >( transform->GetParameters().data_block() ); + const auto paramsAddress = reinterpret_cast(transform->GetParameters().data_block()); const auto paramsSize = transform->GetParameters().Size() * sizeof(ParametersValueType); setMemoryStoreOutputArray(0, index, dataCount, paramsAddress, paramsSize); ++dataCount; @@ -111,24 +118,27 @@ class ITK_TEMPLATE_EXPORT OutputTransform } else { - const auto fixedParamsAddress = reinterpret_cast< size_t >( wasmTransform->GetTransform()->GetFixedParameters().data_block() ); - const auto fixedParamsSize = wasmTransform->GetTransform()->GetFixedParameters().Size() * sizeof(FixedParametersValueType); + const auto fixedParamsAddress = + reinterpret_cast(wasmTransform->GetTransform()->GetFixedParameters().data_block()); + const auto fixedParamsSize = + wasmTransform->GetTransform()->GetFixedParameters().Size() * sizeof(FixedParametersValueType); setMemoryStoreOutputArray(0, index, 0, fixedParamsAddress, fixedParamsSize); - const auto paramsAddress = reinterpret_cast< size_t >( wasmTransform->GetTransform()->GetParameters().data_block() ); + const auto paramsAddress = + reinterpret_cast(wasmTransform->GetTransform()->GetParameters().data_block()); const auto paramsSize = wasmTransform->GetTransform()->GetParameters().Size() * sizeof(ParametersValueType); setMemoryStoreOutputArray(0, index, 1, paramsAddress, paramsSize); } } #else - std::cerr << "Memory IO not supported" << std::endl; - abort(); + std::cerr << "Memory IO not supported" << std::endl; + abort(); #endif } else { #ifndef ITK_WASM_NO_FILESYSTEM_IO - if (!this->m_Transform.IsNull() && !this->m_Identifier.empty()) + if (!this->m_Transform.IsNull() && !this->m_Identifier.empty()) { using ParametersValueType = typename TransformType::ParametersValueType; using WriterType = TransformFileWriterTemplate; @@ -138,11 +148,12 @@ class ITK_TEMPLATE_EXPORT OutputTransform writer->Update(); } #else - std::cerr << "Filesystem IO not supported" << std::endl; - abort(); + std::cerr << "Filesystem IO not supported" << std::endl; + abort(); #endif } } + protected: typename TTransform::ConstPointer m_Transform; @@ -150,7 +161,8 @@ class ITK_TEMPLATE_EXPORT OutputTransform }; template -bool lexical_cast(const std::string &input, OutputTransform &outputTransform) +bool +lexical_cast(const std::string & input, OutputTransform & outputTransform) { outputTransform.SetIdentifier(input); return true; diff --git a/include/itkPipeline.h b/include/itkPipeline.h index 6b06a69f0..5863cda1e 100644 --- a/include/itkPipeline.h +++ b/include/itkPipeline.h @@ -33,72 +33,81 @@ // Short circuit help output without raising an exception (currently not // available in WASI) -#define ITK_WASM_PARSE(pipeline) \ - try { \ - const auto iwpArgc = (pipeline).get_argc(); \ - const auto iwpArgv = (pipeline).get_argv(); \ - for (int ii = 0; ii < iwpArgc; ++ii) \ - { \ - const std::string arg(iwpArgv[ii]); \ - if (arg == "-h" || arg == "--help") \ - { \ - (pipeline).exit(CLI::CallForAllHelp()); \ - std::exit(0); \ - } \ - if (arg == "--interface-json") \ - { \ - (pipeline).interface_json(); \ - std::exit(0); \ - } \ - if (arg == "--version") \ - { \ - std::cout << "Version: " << (pipeline).version() << std::endl; \ - std::exit(0); \ - } \ - } \ - (pipeline).parse(); \ - } catch(const CLI::ParseError &e) { \ - return (pipeline).exit(e); \ - } +#define ITK_WASM_PARSE(pipeline) \ + try \ + { \ + const auto iwpArgc = (pipeline).get_argc(); \ + const auto iwpArgv = (pipeline).get_argv(); \ + for (int ii = 0; ii < iwpArgc; ++ii) \ + { \ + const std::string arg(iwpArgv[ii]); \ + if (arg == "-h" || arg == "--help") \ + { \ + (pipeline).exit(CLI::CallForAllHelp()); \ + std::exit(0); \ + } \ + if (arg == "--interface-json") \ + { \ + (pipeline).interface_json(); \ + std::exit(0); \ + } \ + if (arg == "--version") \ + { \ + std::cout << "Version: " << (pipeline).version() << std::endl; \ + std::exit(0); \ + } \ + } \ + (pipeline).parse(); \ + } \ + catch (const CLI::ParseError & e) \ + { \ + return (pipeline).exit(e); \ + } // Parse options while allowing extra flags, not exiting with help flags, and clearing parse state after finished. // Use this to parse some positionals or options before all options have been added. -// WARNING: It is best to only add the pre-parse options and read them through ITK_WASM_PRE_PARSE before adding other options, -// as you may face issues(EXCEPTIONS) generating bindings (bindgen), if you add "required" options/flags before the PRE_PARSE. -#define ITK_WASM_PRE_PARSE(pipeline) \ - try { \ - (pipeline).set_help_flag(); \ - (pipeline).allow_extras(true); \ - (pipeline).parse(); \ - } catch(const CLI::CallForHelp &e) { \ - } catch(const CLI::CallForAllHelp &e) { \ - } catch(const CLI::ParseError &e) { \ - return (pipeline).exit(e); \ - } \ - (pipeline).allow_extras(false); \ - (pipeline).set_help_flag("-h,--help", "Print this help message and exit"); \ - (pipeline).clear(); - -#define ITK_WASM_CATCH_EXCEPTION(pipeline, command) \ - try \ - { \ - command; \ - } \ - catch (const itk::ExceptionObject & excp) \ - { \ - std::ostringstream ostrm; \ - ostrm << excp; \ +// WARNING: It is best to only add the pre-parse options and read them through ITK_WASM_PRE_PARSE before adding other +// options, as you may face issues(EXCEPTIONS) generating bindings (bindgen), if you add "required" options/flags before +// the PRE_PARSE. +#define ITK_WASM_PRE_PARSE(pipeline) \ + try \ + { \ + (pipeline).set_help_flag(); \ + (pipeline).allow_extras(true); \ + (pipeline).parse(); \ + } \ + catch (const CLI::CallForHelp & e) \ + {} \ + catch (const CLI::CallForAllHelp & e) \ + {} \ + catch (const CLI::ParseError & e) \ + { \ + return (pipeline).exit(e); \ + } \ + (pipeline).allow_extras(false); \ + (pipeline).set_help_flag("-h,--help", "Print this help message and exit"); \ + (pipeline).clear(); + +#define ITK_WASM_CATCH_EXCEPTION(pipeline, command) \ + try \ + { \ + command; \ + } \ + catch (const itk::ExceptionObject & excp) \ + { \ + std::ostringstream ostrm; \ + ostrm << excp; \ ostrm << " In " __FILE__ ", line " << __LINE__ << std::endl; \ - CLI::Error err("Runtime error", ostrm.str(), 1); \ - return (pipeline).exit(err); \ - } \ - catch (const std::exception & excp) \ - { \ - std::ostringstream ostrm; \ - ostrm << excp.what(); \ + CLI::Error err("Runtime error", ostrm.str(), 1); \ + return (pipeline).exit(err); \ + } \ + catch (const std::exception & excp) \ + { \ + std::ostringstream ostrm; \ + ostrm << excp.what(); \ ostrm << " In " __FILE__ ", line " << __LINE__ << std::endl; \ - CLI::Error err("Runtime error", ostrm.str(), 1); \ - return (pipeline).exit(err); \ + CLI::Error err("Runtime error", ostrm.str(), 1); \ + return (pipeline).exit(err); \ } namespace itk @@ -125,59 +134,70 @@ using CLI::Config; * @param container Container object. * @return glz::json_t::array_t with the values from the input container. */ -template -glz::json_t::array_t getArrayJson(Iteratorable container) +template +glz::json_t::array_t +getArrayJson(Iteratorable container) { glz::json_t::array_t value(container.begin(), container.end()); return value; } -class WebAssemblyInterface_EXPORT Pipeline: public CLI::App +class WebAssemblyInterface_EXPORT Pipeline : public CLI::App { public: - /** Make a new Pipeline application. `name` should be CamelCase by convention. */ - Pipeline(std::string name, std::string description, int argc, char **argv); + /** Make a new Pipeline application. `name` should be CamelCase by convention. */ + Pipeline(std::string name, std::string description, int argc, char ** argv); + + /** Exit. */ + auto + exit(const CLI::Error & e) -> int; - /** Exit. */ - auto exit(const CLI::Error &e) -> int; + void + parse() + { + CLI::App::parse(m_argc, m_argv); + } - void parse() { - CLI::App::parse(m_argc, m_argv); - } + static auto + get_use_memory_io() + { + return m_UseMemoryIO; + } - static auto get_use_memory_io() - { - return m_UseMemoryIO; - } + int + get_argc() const + { + return m_argc; + } - int get_argc() const - { - return m_argc; - } + char ** + get_argv() const + { + return m_argv; + } - char ** get_argv() const - { - return m_argv; - } + void + set_version(const char * version) + { + m_Version = version; + } - void set_version(const char * version) - { - m_Version = version; - } + std::string + version() const + { + return m_Version; + } - std::string version() const - { - return m_Version; - } + void + interface_json(); - void interface_json(); + ~Pipeline() override; - ~Pipeline() override; private: - static bool m_UseMemoryIO; - int m_argc; - char **m_argv; - std::string m_Version; + static bool m_UseMemoryIO; + int m_argc; + char ** m_argv; + std::string m_Version; }; diff --git a/include/itkPixelTypesJSON.h b/include/itkPixelTypesJSON.h index 558f8bc6a..06ebe0500 100644 --- a/include/itkPixelTypesJSON.h +++ b/include/itkPixelTypesJSON.h @@ -22,48 +22,47 @@ namespace itk { - enum class JSONPixelTypesEnum - { - Unknown, - Scalar, - RGB, - RGBA, - Offset, - Vector, - Point, - CovariantVector, - SymmetricSecondRankTensor, - DiffusionTensor3D, - Complex, - FixedArray, - Array, - Matrix, - VariableLengthVector, - VariableSizeMatrix - }; +enum class JSONPixelTypesEnum +{ + Unknown, + Scalar, + RGB, + RGBA, + Offset, + Vector, + Point, + CovariantVector, + SymmetricSecondRankTensor, + DiffusionTensor3D, + Complex, + FixedArray, + Array, + Matrix, + VariableLengthVector, + VariableSizeMatrix +}; } // end namespace itk template <> -struct glz::meta { +struct glz::meta +{ using enum itk::JSONPixelTypesEnum; - static constexpr auto value = glz::enumerate( - Unknown, - Scalar, - RGB, - RGBA, - Offset, - Vector, - Point, - CovariantVector, - SymmetricSecondRankTensor, - DiffusionTensor3D, - Complex, - FixedArray, - Array, - Matrix, - VariableLengthVector, - VariableSizeMatrix - ); + static constexpr auto value = glz::enumerate(Unknown, + Scalar, + RGB, + RGBA, + Offset, + Vector, + Point, + CovariantVector, + SymmetricSecondRankTensor, + DiffusionTensor3D, + Complex, + FixedArray, + Array, + Matrix, + VariableLengthVector, + VariableSizeMatrix); }; #endif // itkPixelTypesJSON_h diff --git a/include/itkPointSetJSON.h b/include/itkPointSetJSON.h index 03f65c4db..f930dc6ff 100644 --- a/include/itkPointSetJSON.h +++ b/include/itkPointSetJSON.h @@ -32,44 +32,46 @@ namespace itk { - /** \class PointSetTypeJSON - * - * \brief PointSet type JSON representation data structure. - * - * \ingroup WebAssemblyInterface - */ - struct PointSetTypeJSON - { - unsigned int dimension { 2 }; - JSONFloatTypesEnum pointComponentType { JSONFloatTypesEnum::float32 }; - JSONComponentTypesEnum pointPixelComponentType { JSONComponentTypesEnum::float32 }; - JSONPixelTypesEnum pointPixelType { JSONPixelTypesEnum::Scalar }; - unsigned int pointPixelComponents { 1 }; - }; - - /** \class PointSetJSON - * - * \brief PointSet JSON representation data structure. - * - * \ingroup WebAssemblyInterface - */ - struct PointSetJSON - { - PointSetTypeJSON pointSetType; +/** \class PointSetTypeJSON + * + * \brief PointSet type JSON representation data structure. + * + * \ingroup WebAssemblyInterface + */ +struct PointSetTypeJSON +{ + unsigned int dimension{ 2 }; + JSONFloatTypesEnum pointComponentType{ JSONFloatTypesEnum::float32 }; + JSONComponentTypesEnum pointPixelComponentType{ JSONComponentTypesEnum::float32 }; + JSONPixelTypesEnum pointPixelType{ JSONPixelTypesEnum::Scalar }; + unsigned int pointPixelComponents{ 1 }; +}; + +/** \class PointSetJSON + * + * \brief PointSet JSON representation data structure. + * + * \ingroup WebAssemblyInterface + */ +struct PointSetJSON +{ + PointSetTypeJSON pointSetType; - std::string name { "PointSet"}; + std::string name{ "PointSet" }; - size_t numberOfPoints{ 0 }; - std::string points; + size_t numberOfPoints{ 0 }; + std::string points; - size_t numberOfPointPixels{ 0 }; - std::string pointData; + size_t numberOfPointPixels{ 0 }; + std::string pointData; - MetadataJSON metadata; - }; + MetadataJSON metadata; +}; -template -auto pointSetToPointSetJSON(const TPointSet * pointSet, const WasmPointSet * wasmPointSet, bool inMemory) -> PointSetJSON +template +auto +pointSetToPointSetJSON(const TPointSet * pointSet, const WasmPointSet * wasmPointSet, bool inMemory) + -> PointSetJSON { using PointSetType = TPointSet; @@ -77,10 +79,12 @@ auto pointSetToPointSetJSON(const TPointSet * pointSet, const WasmPointSet::JSONFloatTypeEnum; + pointSetJSON.pointSetType.pointComponentType = + wasm::MapComponentType::JSONFloatTypeEnum; using PointPixelType = typename TPointSet::PixelType; using ConvertPointPixelTraits = MeshConvertPixelTraits; - pointSetJSON.pointSetType.pointPixelComponentType = wasm::MapComponentType::JSONComponentEnum; + pointSetJSON.pointSetType.pointPixelComponentType = + wasm::MapComponentType::JSONComponentEnum; pointSetJSON.pointSetType.pointPixelType = wasm::MapPixelType::JSONPixelEnum; pointSetJSON.pointSetType.pointPixelComponents = ConvertPointPixelTraits::GetNumberOfComponents(); @@ -96,7 +100,7 @@ auto pointSetToPointSetJSON(const TPointSet * pointSet, const WasmPointSet( &(pointSet->GetPoints()->at(0)) ); + const auto pointsAddress = reinterpret_cast(&(pointSet->GetPoints()->at(0))); std::ostringstream pointsStream; pointsStream << "data:application/vnd.itk.address,0:"; pointsStream << pointsAddress; @@ -105,7 +109,7 @@ auto pointSetToPointSetJSON(const TPointSet * pointSet, const WasmPointSetGetPointData() != nullptr && pointSet->GetPointData()->Size() > 0) { - pointDataAddress = reinterpret_cast< size_t >( &(pointSet->GetPointData()->at(0)) ); + pointDataAddress = reinterpret_cast(&(pointSet->GetPointData()->at(0))); } std::ostringstream pointDataStream; pointDataStream << "data:application/vnd.itk.address,0:"; diff --git a/include/itkPointSetToWasmPointSetFilter.h b/include/itkPointSetToWasmPointSetFilter.h index 9c6912239..4dfbce8d1 100644 --- a/include/itkPointSetToWasmPointSetFilter.h +++ b/include/itkPointSetToWasmPointSetFilter.h @@ -26,7 +26,7 @@ namespace itk /** *\class PointSetToWasmPointSetFilter * \brief Convert an PointSet to an WasmPointSet object. - * + * * \ingroup WebAssemblyInterface */ template diff --git a/include/itkPointSetToWasmPointSetFilter.hxx b/include/itkPointSetToWasmPointSetFilter.hxx index 5ae40e7a4..21bca7c1a 100644 --- a/include/itkPointSetToWasmPointSetFilter.hxx +++ b/include/itkPointSetToWasmPointSetFilter.hxx @@ -26,8 +26,7 @@ namespace itk { template -PointSetToWasmPointSetFilter -::PointSetToWasmPointSetFilter() +PointSetToWasmPointSetFilter::PointSetToWasmPointSetFilter() { this->SetNumberOfRequiredInputs(1); @@ -38,24 +37,21 @@ PointSetToWasmPointSetFilter template ProcessObject::DataObjectPointer -PointSetToWasmPointSetFilter -::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) +PointSetToWasmPointSetFilter::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) { return WasmPointSetType::New().GetPointer(); } template ProcessObject::DataObjectPointer -PointSetToWasmPointSetFilter -::MakeOutput(const ProcessObject::DataObjectIdentifierType &) +PointSetToWasmPointSetFilter::MakeOutput(const ProcessObject::DataObjectIdentifierType &) { return WasmPointSetType::New().GetPointer(); } template auto -PointSetToWasmPointSetFilter -::GetOutput() -> WasmPointSetType * +PointSetToWasmPointSetFilter::GetOutput() -> WasmPointSetType * { // we assume that the first output is of the templated type return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); @@ -63,8 +59,7 @@ PointSetToWasmPointSetFilter template auto -PointSetToWasmPointSetFilter -::GetOutput() const -> const WasmPointSetType * +PointSetToWasmPointSetFilter::GetOutput() const -> const WasmPointSetType * { // we assume that the first output is of the templated type return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); @@ -72,8 +67,7 @@ PointSetToWasmPointSetFilter template auto -PointSetToWasmPointSetFilter -::GetOutput(unsigned int idx) -> WasmPointSetType * +PointSetToWasmPointSetFilter::GetOutput(unsigned int idx) -> WasmPointSetType * { auto * out = dynamic_cast(this->ProcessObject::GetOutput(idx)); @@ -86,8 +80,7 @@ PointSetToWasmPointSetFilter template void -PointSetToWasmPointSetFilter -::SetInput(const PointSetType * input) +PointSetToWasmPointSetFilter::SetInput(const PointSetType * input) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(0, const_cast(input)); @@ -95,8 +88,7 @@ PointSetToWasmPointSetFilter template void -PointSetToWasmPointSetFilter -::SetInput(unsigned int index, const PointSetType * pointSet) +PointSetToWasmPointSetFilter::SetInput(unsigned int index, const PointSetType * pointSet) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(index, const_cast(pointSet)); @@ -104,34 +96,31 @@ PointSetToWasmPointSetFilter template const typename PointSetToWasmPointSetFilter::PointSetType * -PointSetToWasmPointSetFilter -::GetInput() +PointSetToWasmPointSetFilter::GetInput() { return itkDynamicCastInDebugMode(this->GetPrimaryInput()); } template const typename PointSetToWasmPointSetFilter::PointSetType * -PointSetToWasmPointSetFilter -::GetInput(unsigned int idx) +PointSetToWasmPointSetFilter::GetInput(unsigned int idx) { return itkDynamicCastInDebugMode(this->ProcessObject::GetInput(idx)); } template void -PointSetToWasmPointSetFilter -::GenerateData() +PointSetToWasmPointSetFilter::GenerateData() { // Get the input and output pointers const PointSetType * pointSet = this->GetInput(); - WasmPointSetType * wasmPointSet = this->GetOutput(); + WasmPointSetType * wasmPointSet = this->GetOutput(); wasmPointSet->SetPointSet(pointSet); constexpr bool inMemory = true; - const auto pointSetJSON = pointSetToPointSetJSON(pointSet, wasmPointSet, inMemory); - std::string serialized{}; - auto ec = glz::write(pointSetJSON, serialized); + const auto pointSetJSON = pointSetToPointSetJSON(pointSet, wasmPointSet, inMemory); + std::string serialized{}; + auto ec = glz::write(pointSetJSON, serialized); if (ec) { itkExceptionMacro("Failed to serialize PointSetJSON"); @@ -142,8 +131,7 @@ PointSetToWasmPointSetFilter template void -PointSetToWasmPointSetFilter -::PrintSelf(std::ostream & os, Indent indent) const +PointSetToWasmPointSetFilter::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent); } diff --git a/include/itkPolyDataJSON.h b/include/itkPolyDataJSON.h index f8cd29a8a..b048e85cd 100644 --- a/include/itkPolyDataJSON.h +++ b/include/itkPolyDataJSON.h @@ -32,60 +32,61 @@ namespace itk { - /** \class PolyDataTypeJSON - * - * \brief PolyData type JSON representation data structure. - * - * \ingroup WebAssemblyInterface - */ - struct PolyDataTypeJSON - { - JSONComponentTypesEnum pointPixelComponentType { JSONComponentTypesEnum::float32 }; - JSONPixelTypesEnum pointPixelType { JSONPixelTypesEnum::Scalar }; - unsigned int pointPixelComponents { 1 }; - JSONComponentTypesEnum cellPixelComponentType { JSONComponentTypesEnum::float32 }; - JSONPixelTypesEnum cellPixelType { JSONPixelTypesEnum::Scalar }; - unsigned int cellPixelComponents { 1 }; - }; - - /** \class PolyDataJSON - * - * \brief PolyData JSON representation data structure. - * - * \ingroup WebAssemblyInterface - */ - struct PolyDataJSON - { - PolyDataTypeJSON polyDataType; +/** \class PolyDataTypeJSON + * + * \brief PolyData type JSON representation data structure. + * + * \ingroup WebAssemblyInterface + */ +struct PolyDataTypeJSON +{ + JSONComponentTypesEnum pointPixelComponentType{ JSONComponentTypesEnum::float32 }; + JSONPixelTypesEnum pointPixelType{ JSONPixelTypesEnum::Scalar }; + unsigned int pointPixelComponents{ 1 }; + JSONComponentTypesEnum cellPixelComponentType{ JSONComponentTypesEnum::float32 }; + JSONPixelTypesEnum cellPixelType{ JSONPixelTypesEnum::Scalar }; + unsigned int cellPixelComponents{ 1 }; +}; + +/** \class PolyDataJSON + * + * \brief PolyData JSON representation data structure. + * + * \ingroup WebAssemblyInterface + */ +struct PolyDataJSON +{ + PolyDataTypeJSON polyDataType; - std::string name { "PolyData" }; + std::string name{ "PolyData" }; - size_t numberOfPoints{ 0 }; - std::string points; + size_t numberOfPoints{ 0 }; + std::string points; - size_t verticesBufferSize { 0 }; - std::string vertices; + size_t verticesBufferSize{ 0 }; + std::string vertices; - size_t linesBufferSize { 0 }; - std::string lines; + size_t linesBufferSize{ 0 }; + std::string lines; - size_t polygonsBufferSize { 0 }; - std::string polygons; + size_t polygonsBufferSize{ 0 }; + std::string polygons; - size_t triangleStripsBufferSize { 0 }; - std::string triangleStrips; + size_t triangleStripsBufferSize{ 0 }; + std::string triangleStrips; - size_t numberOfPointPixels { 0 }; - std::string pointData; + size_t numberOfPointPixels{ 0 }; + std::string pointData; - size_t numberOfCellPixels { 0 }; - std::string cellData; + size_t numberOfCellPixels{ 0 }; + std::string cellData; - MetadataJSON metadata; - }; + MetadataJSON metadata; +}; -template -auto polyDataToPolyDataJSON(const TPolyData * polyData, bool inMemory) -> PolyDataJSON +template +auto +polyDataToPolyDataJSON(const TPolyData * polyData, bool inMemory) -> PolyDataJSON { using PolyDataType = TPolyData; @@ -93,13 +94,15 @@ auto polyDataToPolyDataJSON(const TPolyData * polyData, bool inMemory) -> PolyDa using PointPixelType = typename TPolyData::PixelType; using ConvertPointPixelTraits = MeshConvertPixelTraits; - polyDataJSON.polyDataType.pointPixelComponentType = wasm::MapComponentType::JSONComponentEnum; + polyDataJSON.polyDataType.pointPixelComponentType = + wasm::MapComponentType::JSONComponentEnum; polyDataJSON.polyDataType.pointPixelType = wasm::MapPixelType::JSONPixelEnum; polyDataJSON.polyDataType.pointPixelComponents = ConvertPointPixelTraits::GetNumberOfComponents(); using CellPixelType = typename TPolyData::CellPixelType; using ConvertCellPixelTraits = MeshConvertPixelTraits; - polyDataJSON.polyDataType.cellPixelComponentType = wasm::MapComponentType::JSONComponentEnum; + polyDataJSON.polyDataType.cellPixelComponentType = + wasm::MapComponentType::JSONComponentEnum; polyDataJSON.polyDataType.cellPixelType = wasm::MapPixelType::JSONPixelEnum; polyDataJSON.polyDataType.cellPixelComponents = ConvertCellPixelTraits::GetNumberOfComponents(); @@ -139,7 +142,7 @@ auto polyDataToPolyDataJSON(const TPolyData * polyData, bool inMemory) -> PolyDa size_t pointsAddress = 0; if (polyData->GetNumberOfPoints()) { - pointsAddress = reinterpret_cast< size_t >( &(polyData->GetPoints()->at(0)) ); + pointsAddress = reinterpret_cast(&(polyData->GetPoints()->at(0))); } std::ostringstream pointsStream; pointsStream << "data:application/vnd.itk.address,0:"; @@ -149,7 +152,7 @@ auto polyDataToPolyDataJSON(const TPolyData * polyData, bool inMemory) -> PolyDa size_t verticesAddress = 0; if (polyData->GetVertices() != nullptr && polyData->GetVertices()->Size() > 0) { - verticesAddress = reinterpret_cast< size_t >( &(polyData->GetVertices()->at(0)) ); + verticesAddress = reinterpret_cast(&(polyData->GetVertices()->at(0))); } std::ostringstream verticesStream; verticesStream << "data:application/vnd.itk.address,0:"; @@ -159,7 +162,7 @@ auto polyDataToPolyDataJSON(const TPolyData * polyData, bool inMemory) -> PolyDa size_t linesAddress = 0; if (polyData->GetLines() != nullptr && polyData->GetLines()->Size() > 0) { - linesAddress = reinterpret_cast< size_t >( &(polyData->GetLines()->at(0)) ); + linesAddress = reinterpret_cast(&(polyData->GetLines()->at(0))); } std::ostringstream linesStream; linesStream << "data:application/vnd.itk.address,0:"; @@ -169,7 +172,7 @@ auto polyDataToPolyDataJSON(const TPolyData * polyData, bool inMemory) -> PolyDa size_t polygonsAddress = 0; if (polyData->GetPolygons() != nullptr && polyData->GetPolygons()->Size() > 0) { - polygonsAddress = reinterpret_cast< size_t >( &(polyData->GetPolygons()->at(0)) ); + polygonsAddress = reinterpret_cast(&(polyData->GetPolygons()->at(0))); } std::ostringstream polygonsStream; polygonsStream << "data:application/vnd.itk.address,0:"; @@ -179,7 +182,7 @@ auto polyDataToPolyDataJSON(const TPolyData * polyData, bool inMemory) -> PolyDa size_t triangleStripsAddress = 0; if (polyData->GetTriangleStrips() != nullptr && polyData->GetTriangleStrips()->Size() > 0) { - triangleStripsAddress = reinterpret_cast< size_t >( &(polyData->GetTriangleStrips()->at(0)) ); + triangleStripsAddress = reinterpret_cast(&(polyData->GetTriangleStrips()->at(0))); } std::ostringstream triangleStripsStream; triangleStripsStream << "data:application/vnd.itk.address,0:"; @@ -189,7 +192,7 @@ auto polyDataToPolyDataJSON(const TPolyData * polyData, bool inMemory) -> PolyDa size_t pointDataAddress = 0; if (polyData->GetPointData() != nullptr && polyData->GetPointData()->Size() > 0) { - pointDataAddress = reinterpret_cast< size_t >( &(polyData->GetPointData()->at(0)) ); + pointDataAddress = reinterpret_cast(&(polyData->GetPointData()->at(0))); } std::ostringstream pointDataStream; pointDataStream << "data:application/vnd.itk.address,0:"; @@ -199,10 +202,10 @@ auto polyDataToPolyDataJSON(const TPolyData * polyData, bool inMemory) -> PolyDa size_t cellDataAddress = 0; if (polyData->GetCellData() != nullptr && polyData->GetCellData()->Size() > 0) { - cellDataAddress = reinterpret_cast< size_t >( &(polyData->GetCellData()->at(0)) ); + cellDataAddress = reinterpret_cast(&(polyData->GetCellData()->at(0))); } std::ostringstream cellDataStream; - cellDataStream << "data:application/vnd.itk.address,0:"; + cellDataStream << "data:application/vnd.itk.address,0:"; cellDataStream << cellDataAddress; polyDataJSON.cellData = cellDataStream.str(); diff --git a/include/itkPolyDataToWasmPolyDataFilter.h b/include/itkPolyDataToWasmPolyDataFilter.h index f6d8fe6cd..f6cc28f1b 100644 --- a/include/itkPolyDataToWasmPolyDataFilter.h +++ b/include/itkPolyDataToWasmPolyDataFilter.h @@ -26,7 +26,7 @@ namespace itk /** *\class PolyDataToWasmPolyDataFilter * \brief Convert an PolyData to an WasmPolyData object. - * + * * \ingroup WebAssemblyInterface */ template diff --git a/include/itkPolyDataToWasmPolyDataFilter.hxx b/include/itkPolyDataToWasmPolyDataFilter.hxx index c390b62d8..6507aa06c 100644 --- a/include/itkPolyDataToWasmPolyDataFilter.hxx +++ b/include/itkPolyDataToWasmPolyDataFilter.hxx @@ -31,8 +31,7 @@ namespace itk { template -PolyDataToWasmPolyDataFilter -::PolyDataToWasmPolyDataFilter() +PolyDataToWasmPolyDataFilter::PolyDataToWasmPolyDataFilter() { this->SetNumberOfRequiredInputs(1); @@ -43,24 +42,21 @@ PolyDataToWasmPolyDataFilter template ProcessObject::DataObjectPointer -PolyDataToWasmPolyDataFilter -::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) +PolyDataToWasmPolyDataFilter::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) { return WasmPolyDataType::New().GetPointer(); } template ProcessObject::DataObjectPointer -PolyDataToWasmPolyDataFilter -::MakeOutput(const ProcessObject::DataObjectIdentifierType &) +PolyDataToWasmPolyDataFilter::MakeOutput(const ProcessObject::DataObjectIdentifierType &) { return WasmPolyDataType::New().GetPointer(); } template auto -PolyDataToWasmPolyDataFilter -::GetOutput() -> WasmPolyDataType * +PolyDataToWasmPolyDataFilter::GetOutput() -> WasmPolyDataType * { // we assume that the first output is of the templated type return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); @@ -68,8 +64,7 @@ PolyDataToWasmPolyDataFilter template auto -PolyDataToWasmPolyDataFilter -::GetOutput() const -> const WasmPolyDataType * +PolyDataToWasmPolyDataFilter::GetOutput() const -> const WasmPolyDataType * { // we assume that the first output is of the templated type return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); @@ -77,8 +72,7 @@ PolyDataToWasmPolyDataFilter template auto -PolyDataToWasmPolyDataFilter -::GetOutput(unsigned int idx) -> WasmPolyDataType * +PolyDataToWasmPolyDataFilter::GetOutput(unsigned int idx) -> WasmPolyDataType * { auto * out = dynamic_cast(this->ProcessObject::GetOutput(idx)); @@ -91,8 +85,7 @@ PolyDataToWasmPolyDataFilter template void -PolyDataToWasmPolyDataFilter -::SetInput(const PolyDataType * input) +PolyDataToWasmPolyDataFilter::SetInput(const PolyDataType * input) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(0, const_cast(input)); @@ -100,8 +93,7 @@ PolyDataToWasmPolyDataFilter template void -PolyDataToWasmPolyDataFilter -::SetInput(unsigned int index, const PolyDataType * polyData) +PolyDataToWasmPolyDataFilter::SetInput(unsigned int index, const PolyDataType * polyData) { // Process object is not const-correct so the const_cast is required here this->ProcessObject::SetNthInput(index, const_cast(polyData)); @@ -109,35 +101,32 @@ PolyDataToWasmPolyDataFilter template const typename PolyDataToWasmPolyDataFilter::PolyDataType * -PolyDataToWasmPolyDataFilter -::GetInput() +PolyDataToWasmPolyDataFilter::GetInput() { return itkDynamicCastInDebugMode(this->GetPrimaryInput()); } template const typename PolyDataToWasmPolyDataFilter::PolyDataType * -PolyDataToWasmPolyDataFilter -::GetInput(unsigned int idx) +PolyDataToWasmPolyDataFilter::GetInput(unsigned int idx) { return itkDynamicCastInDebugMode(this->ProcessObject::GetInput(idx)); } template void -PolyDataToWasmPolyDataFilter -::GenerateData() +PolyDataToWasmPolyDataFilter::GenerateData() { // Get the input and output pointers const PolyDataType * polyData = this->GetInput(); - WasmPolyDataType * wasmPolyData = this->GetOutput(); + WasmPolyDataType * wasmPolyData = this->GetOutput(); wasmPolyData->SetPolyData(polyData); constexpr bool inMemory = true; - const auto polyDataJSON = polyDataToPolyDataJSON(polyData, inMemory); - std::string serialized{}; - auto ec = glz::write(polyDataJSON, serialized); + const auto polyDataJSON = polyDataToPolyDataJSON(polyData, inMemory); + std::string serialized{}; + auto ec = glz::write(polyDataJSON, serialized); if (ec) { itkExceptionMacro("Failed to serialize PolyDataJSON"); @@ -148,8 +137,7 @@ PolyDataToWasmPolyDataFilter template void -PolyDataToWasmPolyDataFilter -::PrintSelf(std::ostream & os, Indent indent) const +PolyDataToWasmPolyDataFilter::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent); } diff --git a/include/itkSpecializedImagePipelineFunctor.h b/include/itkSpecializedImagePipelineFunctor.h index 862be2c3b..07f34a79c 100644 --- a/include/itkSpecializedImagePipelineFunctor.h +++ b/include/itkSpecializedImagePipelineFunctor.h @@ -32,13 +32,13 @@ namespace wasm * \brief Internal class to dispatch for pipeline execution on itk::Image or itk::VectorImage. * * \ingroup ITKWebAssemblyInterface -*/ -template