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/hello-world/hello.cxx b/examples/hello-world/hello.cxx index ce2b524c1..e83232aa6 100644 --- a/examples/hello-world/hello.cxx +++ b/examples/hello-world/hello.cxx @@ -1,6 +1,8 @@ #include -int main() { +int +main() +{ std::cout << "Hello Wasm world!" << std::endl; return 0; } 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 441771e4e..4c7065a72 100644 --- a/include/itkMeshJSON.h +++ b/include/itkMeshJSON.h @@ -32,55 +32,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; @@ -91,13 +92,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(); @@ -124,7 +127,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; @@ -132,7 +135,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:"; @@ -142,7 +145,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:"; @@ -152,10 +155,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 36fd2afae..475cf540e 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 4b3f92025..8917977b9 100644 --- a/include/itkOutputMesh.h +++ b/include/itkOutputMesh.h @@ -23,12 +23,12 @@ #include "itkMesh.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 @@ -51,49 +51,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); } @@ -102,8 +110,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); } @@ -111,33 +121,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; @@ -145,7 +158,8 @@ class ITK_TEMPLATE_EXPORT 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