From c3c0006b8dc4b32db02e758e868824ae79cdfacb Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 26 Jan 2025 08:59:37 -0600 Subject: [PATCH 1/7] STYLE: Add itkVirtualGetNameOfClassMacro + itkOverrideGetNameOfClassMacro Added two new macro's, intended to replace the old 'itkTypeMacro' and 'itkTypeMacroNoParent'. The main aim is to be clearer about what those macro's do: add a virtual 'GetNameOfClass()' member function and override it. Unlike 'itkTypeMacro', 'itkOverrideGetNameOfClassMacro' does not have a 'superclass' parameter, as it was not used anyway. Note that originally 'itkTypeMacro' did not use its 'superclass' parameter either, looking at commit 699b66cb04d410e555656828e8892107add38ccb, Will Schroeder, June 27, 2001: https://github.com/InsightSoftwareConsortium/ITK/blob/699b66cb04d410e555656828e8892107add38ccb/Code/Common/itkMacro.h#L331-L337 --- include/itkImageToPointSetFilter.h | 2 +- include/itkMeshToPolyDataFilter.h | 2 +- include/itkPolyData.h | 2 +- include/itkPolyDataToMeshFilter.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/itkImageToPointSetFilter.h b/include/itkImageToPointSetFilter.h index 9fd4a10..bd95f55 100644 --- a/include/itkImageToPointSetFilter.h +++ b/include/itkImageToPointSetFilter.h @@ -50,7 +50,7 @@ class ITK_TEMPLATE_EXPORT ImageToPointSetFilter: public ImageToMeshFilter< TInpu itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(ImageToPointSetFilter, ImageToMeshFilter); + itkOverrideGetNameOfClassMacro(ImageToPointSetFilter); /** Some convenient type alias. */ using InputImageType = TInputImage; diff --git a/include/itkMeshToPolyDataFilter.h b/include/itkMeshToPolyDataFilter.h index 8e7b4a3..5611fcd 100644 --- a/include/itkMeshToPolyDataFilter.h +++ b/include/itkMeshToPolyDataFilter.h @@ -73,7 +73,7 @@ class MeshToPolyDataFilter: public ProcessObject using PolyDataType = PolyData< typename InputMeshType::PixelType >; /** Run-time type information. */ - itkTypeMacro( MeshToPolyDataFilter, ProcessObject ); + itkOverrideGetNameOfClassMacro( MeshToPolyDataFilter); /** Standard New macro. */ itkNewMacro( Self ); diff --git a/include/itkPolyData.h b/include/itkPolyData.h index 1a33614..56dee89 100644 --- a/include/itkPolyData.h +++ b/include/itkPolyData.h @@ -49,7 +49,7 @@ class ITK_TEMPLATE_EXPORT PolyData: public DataObject itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(PolyData, DataObject); + itkOverrideGetNameOfClassMacro(PolyData); /** Type of PointData or CellData */ using PixelType = TPixel; diff --git a/include/itkPolyDataToMeshFilter.h b/include/itkPolyDataToMeshFilter.h index 637e310..ee06491 100644 --- a/include/itkPolyDataToMeshFilter.h +++ b/include/itkPolyDataToMeshFilter.h @@ -51,7 +51,7 @@ class PolyDataToMeshFilter : public ProcessObject itkNewMacro(Self); /** Run-time type information. */ - itkTypeMacro(PolyDataToMeshFilter, ProcessObject); + itkOverrideGetNameOfClassMacro(PolyDataToMeshFilter); static constexpr unsigned int PointDimension = TInputPolyData::PointDimension; From 86435bd038a2537cc5cdcb9f3e158456eb10d54c Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 26 Jan 2025 12:00:48 -0600 Subject: [PATCH 2/7] STYLE: Replace itkStaticConstMacro with static constexpr Use static constexpr directly now that C++11 conformance is required by all compilers. :%s/itkStaticConstMacro *( *\([^,]*\),[ \_s]*\([^,]*\),\_s*\([^)]*\)) */static constexpr \2 \1 = \3/ge 'itkStaticConstMacro(name, type, value)' became unconditionally identical to 'static constexpr type name = value' with ITK commit aec95193ab00e1322039911e1032da00f3a103b6 "ENH: Update compiler macros (#810)", maekclena, 7 May 2019. 'itkGetStaticConstMacro(name)' became unconditionally identical to '(Self::name)' with ITK commit 84e490b81e3f3c2b0edb89ae7b9de53bfc52f2b2 "Removing some outdated compiler conditionals", Hans Johnson, 31 July 2010. Most 'itkStaticConstMacro' calls were removed by ITK commit 5c14741e1e063a132ea7e7ee69c5bd0a4e49af74 --- include/itkImageToPointSetFilter.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/itkImageToPointSetFilter.h b/include/itkImageToPointSetFilter.h index bd95f55..5c8a866 100644 --- a/include/itkImageToPointSetFilter.h +++ b/include/itkImageToPointSetFilter.h @@ -71,10 +71,10 @@ class ITK_TEMPLATE_EXPORT ImageToPointSetFilter: public ImageToMeshFilter< TInpu using PointDataContainerIterator = typename PointDataContainer::Iterator; /** The dimension of the output mesh. */ - itkStaticConstMacro(PointDimension, unsigned int, TOutputMesh::PointDimension); + static constexpr unsigned int PointDimension = TOutputMesh::PointDimension; /** ImageDimension constant */ - itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension); + static constexpr unsigned int ImageDimension = TInputImage::ImageDimension; protected: ImageToPointSetFilter() {} From d90e542771e88b8ab9c3959881a730c175ef2cbd Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 26 Jan 2025 12:55:48 -0600 Subject: [PATCH 3/7] STYLE: CoordRepType -> CoordinateType code readability For the sake of code readability, a new 'CoordinateType' alias is added for each nested 'CoordRepType' alias. The old 'CoordRepType' aliases will still be available with ITK 6.0, but it is recommended to use 'CoordinateType' instead. The 'CoordRepType' aliases will be removed when 'ITK_FUTURE_LEGACY_REMOVE' is enabled. Similarly, 'InputCoordinateType', 'OutputCoordinateType', and 'ImagePointCoordinateType' replace 'InputCoordRepType', 'OutputCoordRepType', and 'ImagePointCoordRepType', respectively. --- include/itkPolyData.h | 2 +- include/itkPolyDataToMeshFilter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/itkPolyData.h b/include/itkPolyData.h index 56dee89..c89e3a7 100644 --- a/include/itkPolyData.h +++ b/include/itkPolyData.h @@ -57,7 +57,7 @@ class ITK_TEMPLATE_EXPORT PolyData: public DataObject using MeshTraits = DefaultStaticMeshTraits< PixelType, PointDimension, PointDimension, float, float, CellPixelType >; /** Convenient type alias obtained from TMeshTraits template parameter. */ - using CoordRepType = typename MeshTraits::CoordRepType; + using CoordinateType = typename MeshTraits::CoordinateType; using PointIdentifier = typename MeshTraits::PointIdentifier; using PointType = typename MeshTraits::PointType; using PointsContainer = typename MeshTraits::PointsContainer; diff --git a/include/itkPolyDataToMeshFilter.h b/include/itkPolyDataToMeshFilter.h index ee06491..8aeeabe 100644 --- a/include/itkPolyDataToMeshFilter.h +++ b/include/itkPolyDataToMeshFilter.h @@ -60,7 +60,7 @@ class PolyDataToMeshFilter : public ProcessObject using OutputMeshType = Mesh; using MeshType = OutputMeshType; - using OutputCoordRepType = typename OutputMeshType::CoordRepType; + using OutputCoordinateType = typename OutputMeshType::CoordinateType; using OutputPointPixelType = typename OutputMeshType::PixelType; using OutputCellPixelType = typename OutputMeshType::CellPixelType; using OutputPointType = typename OutputMeshType::PointType; From 6aa2abf3eb4895ef7df5e2c9f785fa996b39a58a Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Mon, 27 Jan 2025 17:53:55 -0600 Subject: [PATCH 4/7] STYLE: Update to match clang-format-19 from ITK --- .clang-format | 251 +++++-- ...convert-itk-poly-data-to-vtk-poly-data.cxx | 228 +++---- include/itkImageToPointSetFilter.h | 15 +- include/itkImageToPointSetFilter.hxx | 45 +- include/itkMeshToPolyDataFilter.h | 84 ++- include/itkMeshToPolyDataFilter.hxx | 632 +++++++++--------- include/itkPolyData.h | 103 ++- include/itkPolyData.hxx | 363 +++++----- include/itkPolyDataToMeshFilter.hxx | 8 +- test/itkImageToPointSetFilterTest.cxx | 37 +- test/itkMeshToPolyDataFilterTest.cxx | 92 +-- test/itkPolyDataTest.cxx | 147 ++-- wasm/mesh-to-poly-data.cxx | 26 +- wasm/poly-data-to-mesh.cxx | 12 +- 14 files changed, 1120 insertions(+), 923 deletions(-) diff --git a/.clang-format b/.clang-format index 411b009..45b9502 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,4 @@ -## This config file is only relevant for clang-format version 8.0.0 +## 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 @@ -10,142 +10,309 @@ ## maintaining a consistent code style. ## ## EXAMPLE apply code style enforcement before commit: -# Utilities/Maintenance/clang-format.bash --clang ${PATH_TO_CLANG_FORMAT_8.0.0} --modified +# 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_8.0.0} --last +# Utilities/Maintenance/clang-format.bash --clang ${PATH_TO_CLANG_FORMAT_19.1.4} --last --- -# This configuration requires clang-format version 8.0.0 exactly. -BasedOnStyle: Mozilla +# This configuration requires clang-format version 19.1.4 exactly. Language: Cpp AccessModifierOffset: -2 AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: true -AlignEscapedNewlines: Right -AlignOperands: true -AlignTrailingComments: true -# clang 9.0 AllowAllArgumentsOnNextLine: true -# clang 9.0 AllowAllConstructorInitializersOnNextLine: true +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 -AllowShortBlocksOnASingleLine: false +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Never +AllowShortCaseExpressionOnASingleLine: true AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Inline -# clang 9.0 AllowShortLambdasOnASingleLine: All -# clang 9.0 features AllowShortIfStatementsOnASingleLine: Never -AllowShortIfStatementsOnASingleLine: 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 -AlwaysBreakAfterReturnType: All AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: + - __capability BinPackArguments: false BinPackParameters: false -BreakBeforeBraces: Custom +BitFieldColonSpacing: Both BraceWrapping: - # clang 9.0 feature AfterCaseLabel: false + AfterCaseLabel: true AfterClass: true - AfterControlStatement: true + AfterControlStatement: Always AfterEnum: true + AfterExternBlock: true AfterFunction: true AfterNamespace: true AfterObjCDeclaration: true AfterStruct: true AfterUnion: true - AfterExternBlock: true BeforeCatch: true BeforeElse: true -## This is the big change from historical ITK formatting! -# Historically ITK used a style similar to https://en.wikipedia.org/wiki/Indentation_style#Whitesmiths_style -# with indented braces, and not indented code. This style is very difficult to automatically -# maintain with code beautification tools. Not indenting braces is more common among -# formatting tools. + BeforeLambdaBody: false + BeforeWhile: false IndentBraces: false SplitEmptyFunction: false SplitEmptyRecord: false SplitEmptyNamespace: false +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakAfterReturnType: All +BreakArrays: true BreakBeforeBinaryOperators: None -#clang 6.0 BreakBeforeInheritanceComma: true -BreakInheritanceList: BeforeComma +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Custom +BreakBeforeInlineASMColon: OnlyMultiline BreakBeforeTernaryOperators: true -#clang 6.0 BreakConstructorInitializersBeforeComma: true BreakConstructorInitializers: BeforeComma -BreakAfterJavaFieldAnnotations: false +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 -ConstructorInitializerAllOnOneLineOrOnePerLine: 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 -KeepEmptyLinesAtTheStartOfBlocks: 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: false +SortIncludes: Never +SortJavaStaticImport: Before # We may want to revisit this later -SortUsingDeclarations: false +SortUsingDeclarations: Never SpaceAfterCStyleCast: false -# SpaceAfterLogicalNot: 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 -SpaceInEmptyParentheses: false +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false SpacesBeforeTrailingComments: 1 -SpacesInAngles: false +SpacesInAngles: Never SpacesInContainerLiterals: false -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + ExceptDoubleParentheses: false + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false SpacesInSquareBrackets: false -Standard: Cpp11 +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/convert-itk-poly-data-to-vtk-poly-data.cxx b/examples/convert-itk-poly-data-to-vtk-poly-data.cxx index 88ff726..54bb30e 100644 --- a/examples/convert-itk-poly-data-to-vtk-poly-data.cxx +++ b/examples/convert-itk-poly-data-to-vtk-poly-data.cxx @@ -9,138 +9,140 @@ using MeshType = itk::Mesh; // Function to convert itk::Mesh to vtkPolyData -vtkSmartPointer ConvertITKMeshToVTKPolyData(MeshType::Pointer itkMesh) +vtkSmartPointer +ConvertITKMeshToVTKPolyData(MeshType::Pointer itkMesh) { - typedef itk::MeshToPolyDataFilter MeshToPolyDataType; - MeshToPolyDataType::Pointer meshToPolyData = MeshToPolyDataType::New(); - meshToPolyData->SetInput(itkMesh); - meshToPolyData->Update(); - - const auto polyDataItk = meshToPolyData->GetOutput(); - - vtkSmartPointer polyDataVtk = vtkSmartPointer::New(); - - // Transfer the points from polyDataItk to polyDataVtk - vtkSmartPointer points = vtkSmartPointer::New(); - const auto itkPoints = polyDataItk->GetPoints(); - for (itk::IdentifierType i = 0; i < itkPoints->size(); ++i) + typedef itk::MeshToPolyDataFilter MeshToPolyDataType; + MeshToPolyDataType::Pointer meshToPolyData = MeshToPolyDataType::New(); + meshToPolyData->SetInput(itkMesh); + meshToPolyData->Update(); + + const auto polyDataItk = meshToPolyData->GetOutput(); + + vtkSmartPointer polyDataVtk = vtkSmartPointer::New(); + + // Transfer the points from polyDataItk to polyDataVtk + vtkSmartPointer points = vtkSmartPointer::New(); + const auto itkPoints = polyDataItk->GetPoints(); + for (itk::IdentifierType i = 0; i < itkPoints->size(); ++i) + { + const auto point = itkPoints->GetElement(i); + points->InsertNextPoint(point[0], point[1], point[2]); + } + polyDataVtk->SetPoints(points); + + // Transfer the vertices from polyDataItk to polyDataVtk + const auto verticesItk = polyDataItk->GetVertices(); + vtkNew verticesVtk; + for (itk::IdentifierType i = 0; i < verticesItk->size() / 2; ++i) + { + const vtkIdType vertex = static_cast(verticesItk->GetElement(i * 2 + 1)); + verticesVtk->InsertNextCell(1, &vertex); + } + polyDataVtk->SetVerts(verticesVtk); + + // Transfer the lines from polyDataItk to polyDataVtk + const auto linesItk = polyDataItk->GetLines(); + vtkNew linesVtk; + auto linesIt = linesItk->begin(); + while (linesIt != linesItk->end()) + { + const auto numberOfPoints = *linesIt; + ++linesIt; + vtkNew line; + for (itk::IdentifierType i = 0; i < numberOfPoints; ++i) { - const auto point = itkPoints->GetElement(i); - points->InsertNextPoint(point[0], point[1], point[2]); + const vtkIdType pointId = static_cast(*linesIt); + line->InsertNextId(pointId); + ++linesIt; } - polyDataVtk->SetPoints(points); - - // Transfer the vertices from polyDataItk to polyDataVtk - const auto verticesItk = polyDataItk->GetVertices(); - vtkNew verticesVtk; - for (itk::IdentifierType i = 0; i < verticesItk->size() / 2; ++i) + linesVtk->InsertNextCell(line); + } + polyDataVtk->SetLines(linesVtk); + + // Transfer the polygons from polyDataItk to polyDataVtk + const auto polygonsItk = polyDataItk->GetPolygons(); + vtkNew polygonsVtk; + auto polygonsIt = polygonsItk->begin(); + while (polygonsIt != polygonsItk->end()) + { + const auto numberOfPoints = *polygonsIt; + ++polygonsIt; + vtkNew polygon; + for (itk::IdentifierType i = 0; i < numberOfPoints; ++i) { - const vtkIdType vertex = static_cast(verticesItk->GetElement(i*2+1)); - verticesVtk->InsertNextCell(1, &vertex); + const vtkIdType pointId = static_cast(*polygonsIt); + polygon->InsertNextId(pointId); + ++polygonsIt; } - polyDataVtk->SetVerts(verticesVtk); - - // Transfer the lines from polyDataItk to polyDataVtk - const auto linesItk = polyDataItk->GetLines(); - vtkNew linesVtk; - auto linesIt = linesItk->begin(); - while(linesIt != linesItk->end()) + polygonsVtk->InsertNextCell(polygon); + } + polyDataVtk->SetPolys(polygonsVtk); + + // Transfer the triangle strips from polyDataItk to polyDataVtk + const auto triangleStripsItk = polyDataItk->GetTriangleStrips(); + vtkNew triangleStripsVtk; + auto triangleStripsIt = triangleStripsItk->begin(); + while (triangleStripsIt != triangleStripsItk->end()) + { + const auto numberOfPoints = *triangleStripsIt; + ++triangleStripsIt; + vtkNew triangleStrip; + for (itk::IdentifierType i = 0; i < numberOfPoints; ++i) { - const auto numberOfPoints = *linesIt; - ++linesIt; - vtkNew line; - for (itk::IdentifierType i = 0; i < numberOfPoints; ++i) - { - const vtkIdType pointId = static_cast(*linesIt); - line->InsertNextId(pointId); - ++linesIt; - } - linesVtk->InsertNextCell(line); + const vtkIdType pointId = static_cast(*triangleStripsIt); + triangleStrip->InsertNextId(pointId); + ++triangleStripsIt; } - polyDataVtk->SetLines(linesVtk); + triangleStripsVtk->InsertNextCell(triangleStrip); + } + polyDataVtk->SetStrips(triangleStripsVtk); - // Transfer the polygons from polyDataItk to polyDataVtk - const auto polygonsItk = polyDataItk->GetPolygons(); - vtkNew polygonsVtk; - auto polygonsIt = polygonsItk->begin(); - while (polygonsIt != polygonsItk->end()) - { - const auto numberOfPoints = *polygonsIt; - ++polygonsIt; - vtkNew polygon; - for (itk::IdentifierType i = 0; i < numberOfPoints; ++i) - { - const vtkIdType pointId = static_cast(*polygonsIt); - polygon->InsertNextId(pointId); - ++polygonsIt; - } - polygonsVtk->InsertNextCell(polygon); - } - polyDataVtk->SetPolys(polygonsVtk); + // PointData and CellData could also be transferred, if needed. - // Transfer the triangle strips from polyDataItk to polyDataVtk - const auto triangleStripsItk = polyDataItk->GetTriangleStrips(); - vtkNew triangleStripsVtk; - auto triangleStripsIt = triangleStripsItk->begin(); - while (triangleStripsIt != triangleStripsItk->end()) - { - const auto numberOfPoints = *triangleStripsIt; - ++triangleStripsIt; - vtkNew triangleStrip; - for (itk::IdentifierType i = 0; i < numberOfPoints; ++i) - { - const vtkIdType pointId = static_cast(*triangleStripsIt); - triangleStrip->InsertNextId(pointId); - ++triangleStripsIt; - } - triangleStripsVtk->InsertNextCell(triangleStrip); - } - polyDataVtk->SetStrips(triangleStripsVtk); - - // PointData and CellData could also be transferred, if needed. - - return polyDataVtk; + return polyDataVtk; } -int main(int argc, char *argv[]) +int +main(int argc, char * argv[]) { - if (argc < 3) - { - std::cerr << "Usage: " << argv[0] << " " << std::endl; - return EXIT_FAILURE; - } + if (argc < 3) + { + std::cerr << "Usage: " << argv[0] << " " << std::endl; + return EXIT_FAILURE; + } - const char *inputFilename = argv[1]; - const char *outputFilename = argv[2]; + const char * inputFilename = argv[1]; + const char * outputFilename = argv[2]; - // Read the input ITK mesh - typedef itk::MeshFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputFilename); + // Read the input ITK mesh + typedef itk::MeshFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(inputFilename); - try - { - reader->Update(); - } - catch (itk::ExceptionObject &error) - { - std::cerr << "Error reading ITK mesh: " << error << std::endl; - return EXIT_FAILURE; - } + try + { + reader->Update(); + } + catch (itk::ExceptionObject & error) + { + std::cerr << "Error reading ITK mesh: " << error << std::endl; + return EXIT_FAILURE; + } - MeshType::Pointer itkMesh = reader->GetOutput(); + MeshType::Pointer itkMesh = reader->GetOutput(); - // Convert ITK mesh to VTK PolyData - vtkSmartPointer vtkPolyData = ConvertITKMeshToVTKPolyData(itkMesh); + // Convert ITK mesh to VTK PolyData + vtkSmartPointer vtkPolyData = ConvertITKMeshToVTKPolyData(itkMesh); - // Write the VTK PolyData to file - vtkSmartPointer writer = vtkSmartPointer::New(); - writer->SetFileName(outputFilename); - writer->SetInputData(vtkPolyData); + // Write the VTK PolyData to file + vtkSmartPointer writer = vtkSmartPointer::New(); + writer->SetFileName(outputFilename); + writer->SetInputData(vtkPolyData); - writer->Write(); + writer->Write(); - std::cout << "Successfully converted ITK mesh to VTK PolyData and saved to " << outputFilename << std::endl; + std::cout << "Successfully converted ITK mesh to VTK PolyData and saved to " << outputFilename << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/include/itkImageToPointSetFilter.h b/include/itkImageToPointSetFilter.h index 5c8a866..37580f9 100644 --- a/include/itkImageToPointSetFilter.h +++ b/include/itkImageToPointSetFilter.h @@ -34,17 +34,17 @@ namespace itk * * \ingroup MeshToPolyData */ -template< typename TInputImage, typename TOutputMesh > -class ITK_TEMPLATE_EXPORT ImageToPointSetFilter: public ImageToMeshFilter< TInputImage, TOutputMesh > +template +class ITK_TEMPLATE_EXPORT ImageToPointSetFilter : public ImageToMeshFilter { public: ITK_DISALLOW_COPY_AND_MOVE(ImageToPointSetFilter); /** Standard class type alias. */ using Self = ImageToPointSetFilter; - using Superclass = ImageToMeshFilter< TInputImage, TOutputMesh >; - using Pointer = SmartPointer< Self >; - using ConstPointer = SmartPointer< const Self >; + using Superclass = ImageToMeshFilter; + using Pointer = SmartPointer; + using ConstPointer = SmartPointer; /** Method for creation through the object factory. */ itkNewMacro(Self); @@ -80,7 +80,8 @@ class ITK_TEMPLATE_EXPORT ImageToPointSetFilter: public ImageToMeshFilter< TInpu ImageToPointSetFilter() {} virtual ~ImageToPointSetFilter() {} - void GenerateData() override; + void + GenerateData() override; private: }; @@ -88,7 +89,7 @@ class ITK_TEMPLATE_EXPORT ImageToPointSetFilter: public ImageToMeshFilter< TInpu } // end namespace itk #ifndef ITK_MANUAL_INSTANTIATION -#include "itkImageToPointSetFilter.hxx" +# include "itkImageToPointSetFilter.hxx" #endif #endif diff --git a/include/itkImageToPointSetFilter.hxx b/include/itkImageToPointSetFilter.hxx index fbdfa1a..ab21b98 100644 --- a/include/itkImageToPointSetFilter.hxx +++ b/include/itkImageToPointSetFilter.hxx @@ -26,52 +26,49 @@ namespace itk { -template< typename TInputImage, typename TOutputMesh > +template void -ImageToPointSetFilter< TInputImage, TOutputMesh > -::GenerateData() +ImageToPointSetFilter::GenerateData() { // " from itkBinaryMask3DMeshSource: // This indicates that the current BufferedRegion is equal to the // requested region. This action prevents useless rexecutions of // the pipeline. - this->GetOutput()->SetBufferedRegion( this->GetOutput()->GetRequestedRegion() ); + this->GetOutput()->SetBufferedRegion(this->GetOutput()->GetRequestedRegion()); - OutputMeshPointer mesh = this->GetOutput(); - PointsContainerPointer points = mesh->GetPoints(); - InputImageConstPointer image = this->GetInput(0); + OutputMeshPointer mesh = this->GetOutput(); + PointsContainerPointer points = mesh->GetPoints(); + InputImageConstPointer image = this->GetInput(0); PointDataContainerPointer pointData; - if ( mesh->GetPointData() ) - { + if (mesh->GetPointData()) + { pointData = mesh->GetPointData(); - } + } else - { // Create - pointData = PointDataContainer::New(); - } + { // Create + pointData = PointDataContainer::New(); + } - const unsigned long numberOfPixels = - image->GetRequestedRegion().GetNumberOfPixels(); - ProgressReporter progress(this, 0, numberOfPixels); + const unsigned long numberOfPixels = image->GetRequestedRegion().GetNumberOfPixels(); + ProgressReporter progress(this, 0, numberOfPixels); points->Reserve(numberOfPixels); pointData->Reserve(numberOfPixels); - mesh->SetPointData( pointData.GetPointer() ); + mesh->SetPointData(pointData.GetPointer()); - typename itk::ImageRegionConstIteratorWithIndex< InputImageType > - imageIt( image, image->GetRequestedRegion() ); + typename itk::ImageRegionConstIteratorWithIndex imageIt(image, image->GetRequestedRegion()); imageIt.GoToBegin(); PointsContainerIterator pointsIt = points->Begin(); PointDataContainerIterator pointDataIt = pointData->Begin(); - while( !imageIt.IsAtEnd() ) - { - image->TransformIndexToPhysicalPoint( imageIt.GetIndex(), pointsIt.Value() ); - ( pointDataIt.Value() ) = imageIt.Get(); + while (!imageIt.IsAtEnd()) + { + image->TransformIndexToPhysicalPoint(imageIt.GetIndex(), pointsIt.Value()); + (pointDataIt.Value()) = imageIt.Get(); ++pointsIt; ++pointDataIt; ++imageIt; progress.CompletedPixel(); - } + } } } // end namespace itk diff --git a/include/itkMeshToPolyDataFilter.h b/include/itkMeshToPolyDataFilter.h index 5611fcd..ccf2ce4 100644 --- a/include/itkMeshToPolyDataFilter.h +++ b/include/itkMeshToPolyDataFilter.h @@ -26,14 +26,19 @@ namespace itk { -template -class HasCellTraits { - typedef char Yes[1]; - typedef char No[2]; - template static Yes& test(typename C::CellTraits *); // selected if C is a class type - template static No& test(...); // selected otherwise - public: - static bool const value = sizeof(test(0)) == sizeof(Yes); +template +class HasCellTraits +{ + typedef char Yes[1]; + typedef char No[2]; + template + static Yes & + test(typename C::CellTraits *); // selected if C is a class type + template + static No & + test(...); // selected otherwise +public: + static bool const value = sizeof(test(0)) == sizeof(Yes); }; /** \class MeshToPolyDataFilter @@ -54,8 +59,8 @@ class HasCellTraits { * \ingroup MeshToPolyData * */ -template< typename TInputMesh > -class MeshToPolyDataFilter: public ProcessObject +template +class MeshToPolyDataFilter : public ProcessObject { public: ITK_DISALLOW_COPY_AND_MOVE(MeshToPolyDataFilter); @@ -65,57 +70,70 @@ class MeshToPolyDataFilter: public ProcessObject using InputMeshType = TInputMesh; /** Standard class typedefs. */ - using Self = MeshToPolyDataFilter< InputMeshType >; + using Self = MeshToPolyDataFilter; using Superclass = ProcessObject; - using Pointer = SmartPointer< Self >; - using ConstPointer = SmartPointer< const Self >; + using Pointer = SmartPointer; + using ConstPointer = SmartPointer; - using PolyDataType = PolyData< typename InputMeshType::PixelType >; + using PolyDataType = PolyData; /** Run-time type information. */ - itkOverrideGetNameOfClassMacro( MeshToPolyDataFilter); + itkOverrideGetNameOfClassMacro(MeshToPolyDataFilter); /** Standard New macro. */ - itkNewMacro( Self ); + itkNewMacro(Self); /** Set the mesh input of this process object. */ using Superclass::SetInput; - void SetInput(const InputMeshType *input); + void + SetInput(const InputMeshType * input); /** Get the mesh input of this process object. */ - const InputMeshType * GetInput() const; + const InputMeshType * + GetInput() const; - const InputMeshType * GetInput(unsigned int idx) const; + const InputMeshType * + GetInput(unsigned int idx) const; - PolyDataType * GetOutput(); - const PolyDataType * GetOutput() const; + PolyDataType * + GetOutput(); + const PolyDataType * + GetOutput() const; - PolyDataType * GetOutput(unsigned int idx); + PolyDataType * + GetOutput(unsigned int idx); protected: MeshToPolyDataFilter(); ~MeshToPolyDataFilter() override = default; - void PrintSelf( std::ostream& os, Indent indent ) const override; + void + PrintSelf(std::ostream & os, Indent indent) const override; - void GenerateData() override; + void + GenerateData() override; - template < typename TInputMeshDispatch, typename std::enable_if< !HasCellTraits::value, int>::type = 0 > - void GenerateDataDispatch(); + template ::value, int>::type = 0> + void + GenerateDataDispatch(); - template < typename TInputMeshDispatch, typename std::enable_if< HasCellTraits::value, int>::type = 0 > - void GenerateDataDispatch(); + template ::value, int>::type = 0> + void + GenerateDataDispatch(); - ProcessObject::DataObjectPointer MakeOutput(ProcessObject::DataObjectPointerArraySizeType idx) override; - ProcessObject::DataObjectPointer MakeOutput(const ProcessObject::DataObjectIdentifierType &) override; + ProcessObject::DataObjectPointer + MakeOutput(ProcessObject::DataObjectPointerArraySizeType idx) override; + ProcessObject::DataObjectPointer + MakeOutput(const ProcessObject::DataObjectIdentifierType &) override; private: - }; -} +} // namespace itk #ifndef ITK_MANUAL_INSTANTIATION -#include "itkMeshToPolyDataFilter.hxx" +# include "itkMeshToPolyDataFilter.hxx" #endif #endif // itkMeshToPolyDataFilter diff --git a/include/itkMeshToPolyDataFilter.hxx b/include/itkMeshToPolyDataFilter.hxx index be302c8..f4d98a7 100644 --- a/include/itkMeshToPolyDataFilter.hxx +++ b/include/itkMeshToPolyDataFilter.hxx @@ -33,14 +33,14 @@ namespace { -template< typename TMesh, typename TPolyData > +template class VisitCellsClass { public: using MeshType = TMesh; using PolyDataType = TPolyData; // typedef the itk cells we are interested in - using CellInterfaceType = itk::CellInterface< typename MeshType::PixelType, typename MeshType::CellTraits >; + using CellInterfaceType = itk::CellInterface; using CellsContainerType = typename TPolyData::CellsContainer; @@ -54,189 +54,209 @@ public: using HexahedronCellType = itk::HexahedronCell; // Set the output polydata vertices container - void SetVertices(CellsContainerType* vertices) + void + SetVertices(CellsContainerType * vertices) { m_Vertices = vertices; } // Set the output polydata polygons container - void SetLines(CellsContainerType* lines) + void + SetLines(CellsContainerType * lines) { m_Lines = lines; } // Set the output polydata polygons container - void SetPolygons(CellsContainerType* polygons) + void + SetPolygons(CellsContainerType * polygons) { m_Polygons = polygons; } // Set the output polydata triangleStrips container - void SetTriangleStrips(CellsContainerType* triangleStrips) + void + SetTriangleStrips(CellsContainerType * triangleStrips) { m_TriangleStrips = triangleStrips; } // Set the associated input cell id container - void SetVerticesCellIds(CellsContainerType* cellIds) + void + SetVerticesCellIds(CellsContainerType * cellIds) { m_VerticesCellIds = cellIds; } // Set the associated input cell id container - void SetLinesCellIds(CellsContainerType* cellIds) + void + SetLinesCellIds(CellsContainerType * cellIds) { m_LinesCellIds = cellIds; } // Set the associated input cell id container - void SetPolygonsCellIds(CellsContainerType* cellIds) + void + SetPolygonsCellIds(CellsContainerType * cellIds) { m_PolygonsCellIds = cellIds; } // Set the associated input cell id container - void SetTriangleStripsCellIds(CellsContainerType* cellIds) + void + SetTriangleStripsCellIds(CellsContainerType * cellIds) { m_TriangleStripsCellIds = cellIds; } // Visit a vertex and create a vertex in the output - void Visit(unsigned long cellId, VertexCellType* cell) + void + Visit(unsigned long cellId, VertexCellType * cell) { constexpr unsigned int numberOfPoints = VertexCellType::NumberOfPoints; - m_Vertices->push_back( numberOfPoints ); - m_Vertices->push_back( cell->GetPointId() ); - m_VerticesCellIds->push_back( static_cast< unsigned int >( cellId ) ); + m_Vertices->push_back(numberOfPoints); + m_Vertices->push_back(cell->GetPointId()); + m_VerticesCellIds->push_back(static_cast(cellId)); } // Visit a line and create a line in the output - void Visit(unsigned long cellId, LineCellType* cell) + void + Visit(unsigned long cellId, LineCellType * cell) { constexpr unsigned int numberOfPoints = LineCellType::NumberOfPoints; - m_Lines->push_back( numberOfPoints ); + m_Lines->push_back(numberOfPoints); const typename LineCellType::PointIdConstIterator pointIdEnd = cell->PointIdsEnd(); - for( typename LineCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; ++pointIdIt ) + for (typename LineCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; + ++pointIdIt) { - m_Lines->push_back( *pointIdIt ); + m_Lines->push_back(*pointIdIt); } - m_LinesCellIds->push_back( static_cast< unsigned int >( cellId ) ); + m_LinesCellIds->push_back(static_cast(cellId)); } // Visit a polyline and create a polyline in the output - void Visit(unsigned long cellId, PolyLineCellType* cell) + void + Visit(unsigned long cellId, PolyLineCellType * cell) { int numberOfPoints = cell->GetNumberOfPoints(); - m_Lines->push_back( numberOfPoints ); + m_Lines->push_back(numberOfPoints); const typename PolyLineCellType::PointIdConstIterator pointIdEnd = cell->PointIdsEnd(); - for( typename PolyLineCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; ++pointIdIt ) + for (typename PolyLineCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; + ++pointIdIt) { - m_Lines->push_back( *pointIdIt ); + m_Lines->push_back(*pointIdIt); } - m_LinesCellIds->push_back( static_cast< unsigned int >( cellId ) ); + m_LinesCellIds->push_back(static_cast(cellId)); } // Visit a triangle and create a triangle in the output - void Visit(unsigned long cellId, TriangleCellType* cell) + void + Visit(unsigned long cellId, TriangleCellType * cell) { constexpr unsigned int numberOfPoints = TriangleCellType::NumberOfPoints; - m_Polygons->push_back( numberOfPoints ); + m_Polygons->push_back(numberOfPoints); const typename TriangleCellType::PointIdConstIterator pointIdEnd = cell->PointIdsEnd(); - for( typename TriangleCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; ++pointIdIt ) - { - m_Polygons->push_back( *pointIdIt ); - } - m_PolygonsCellIds->push_back( static_cast< unsigned int >( cellId ) ); + for (typename TriangleCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; + ++pointIdIt) + { + m_Polygons->push_back(*pointIdIt); + } + m_PolygonsCellIds->push_back(static_cast(cellId)); } // Visit a quadrilateral and create a quadrilateral in the output - void Visit(unsigned long cellId, QuadrilateralCellType* cell) + void + Visit(unsigned long cellId, QuadrilateralCellType * cell) { constexpr unsigned int numberOfPoints = QuadrilateralCellType::NumberOfPoints; - m_Polygons->push_back( numberOfPoints ); + m_Polygons->push_back(numberOfPoints); const typename QuadrilateralCellType::PointIdConstIterator pointIdEnd = cell->PointIdsEnd(); - for( typename QuadrilateralCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; ++pointIdIt ) - { - m_Polygons->push_back( *pointIdIt ); - } - m_PolygonsCellIds->push_back( static_cast< unsigned int >( cellId ) ); + for (typename QuadrilateralCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); + pointIdIt != pointIdEnd; + ++pointIdIt) + { + m_Polygons->push_back(*pointIdIt); + } + m_PolygonsCellIds->push_back(static_cast(cellId)); } // Visit a polygon and create a polygon in the output - void Visit(unsigned long cellId, PolygonCellType* cell) + void + Visit(unsigned long cellId, PolygonCellType * cell) { const unsigned int numberOfPoints = cell->GetNumberOfPoints(); - m_Polygons->push_back( numberOfPoints ); + m_Polygons->push_back(numberOfPoints); const typename PolygonCellType::PointIdConstIterator pointIdEnd = cell->PointIdsEnd(); - for( typename PolygonCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; ++pointIdIt ) - { - m_Polygons->push_back( *pointIdIt ); - } - m_PolygonsCellIds->push_back( static_cast< unsigned int >( cellId ) ); + for (typename PolygonCellType::PointIdConstIterator pointIdIt = cell->PointIdsBegin(); pointIdIt != pointIdEnd; + ++pointIdIt) + { + m_Polygons->push_back(*pointIdIt); + } + m_PolygonsCellIds->push_back(static_cast(cellId)); } //// Visit a tetrahedron and create a tetrahedron in the output - //void Visit(unsigned long, TetrahedronCellType* cell) + // void Visit(unsigned long, TetrahedronCellType* cell) //{ - //constexpr unsigned int numberOfPoints = TetrahedronCellType::NumberOfPoints; - //constexpr unsigned int numberOfFaces = TetrahedronCellType::NumberOfFaces; - //constexpr unsigned int numberOfEdges = TetrahedronCellType::NumberOfFaces; - //for( unsigned int faceId = 0; faceId < numberOfFaces; ++faceId ) - //{ - //typename TetrahedronCellType::FaceAutoPointer facePointer; - //cell->GetFace( faceId, facePointer ); - //// TODO - ////faceIds = vtkIdList::New(); - ////case VTK_TETRA: - ////for (faceId = 0; faceId < 4; faceId++) - ////{ - ////faceIds->Reset(); - ////faceVerts = vtkTetra::GetFaceArray(faceId); - ////faceIds->InsertNextId(pts[faceVerts[0]]); - ////faceIds->InsertNextId(pts[faceVerts[1]]); - ////faceIds->InsertNextId(pts[faceVerts[2]]); - ////numFacePts = 3; - ////input->GetCellNeighbors(cellId, faceIds, cellIds); - ////if ( cellIds->GetNumberOfIds() <= 0 ) - ////{ - ////polys->InsertNextCell(numFacePts); - ////for ( int i=0; i < numFacePts; i++) - ////{ - ////polys->InsertCellPoint(pts[faceVerts[i]]); - ////} - ////polyCellIds.push_back(cellId); - ////} - ////} - ////break; - //} + // constexpr unsigned int numberOfPoints = TetrahedronCellType::NumberOfPoints; + // constexpr unsigned int numberOfFaces = TetrahedronCellType::NumberOfFaces; + // constexpr unsigned int numberOfEdges = TetrahedronCellType::NumberOfFaces; + // for( unsigned int faceId = 0; faceId < numberOfFaces; ++faceId ) + //{ + // typename TetrahedronCellType::FaceAutoPointer facePointer; + // cell->GetFace( faceId, facePointer ); + //// TODO + ////faceIds = vtkIdList::New(); + ////case VTK_TETRA: + ////for (faceId = 0; faceId < 4; faceId++) + ////{ + ////faceIds->Reset(); + ////faceVerts = vtkTetra::GetFaceArray(faceId); + ////faceIds->InsertNextId(pts[faceVerts[0]]); + ////faceIds->InsertNextId(pts[faceVerts[1]]); + ////faceIds->InsertNextId(pts[faceVerts[2]]); + ////numFacePts = 3; + ////input->GetCellNeighbors(cellId, faceIds, cellIds); + ////if ( cellIds->GetNumberOfIds() <= 0 ) + ////{ + ////polys->InsertNextCell(numFacePts); + ////for ( int i=0; i < numFacePts; i++) + ////{ + ////polys->InsertCellPoint(pts[faceVerts[i]]); + ////} + ////polyCellIds.push_back(cellId); + ////} + ////} + ////break; + //} //} //// Visit a hexahedron and create a hexahedron in the output - //void Visit(unsigned long, HexahedronCellType* cell) + // void Visit(unsigned long, HexahedronCellType* cell) //{ - //// TODO - ////case VTK_HEXAHEDRON: - ////for (faceId = 0; faceId < 6; faceId++) - ////{ - ////faceIds->Reset(); - ////faceVerts = vtkHexahedron::GetFaceArray(faceId); - ////faceIds->InsertNextId(pts[faceVerts[0]]); - ////faceIds->InsertNextId(pts[faceVerts[1]]); - ////faceIds->InsertNextId(pts[faceVerts[2]]); - ////faceIds->InsertNextId(pts[faceVerts[3]]); - ////numFacePts = 4; - ////input->GetCellNeighbors(cellId, faceIds, cellIds); - ////if ( cellIds->GetNumberOfIds() <= 0 ) - ////{ - ////polys->InsertNextCell(numFacePts); - ////for ( int i=0; i < numFacePts; i++) - ////{ - ////polys->InsertCellPoint(pts[faceVerts[i]]); - ////} - ////polyCellIds.push_back(cellId); - ////} - ////} - ////break; + //// TODO + ////case VTK_HEXAHEDRON: + ////for (faceId = 0; faceId < 6; faceId++) + ////{ + ////faceIds->Reset(); + ////faceVerts = vtkHexahedron::GetFaceArray(faceId); + ////faceIds->InsertNextId(pts[faceVerts[0]]); + ////faceIds->InsertNextId(pts[faceVerts[1]]); + ////faceIds->InsertNextId(pts[faceVerts[2]]); + ////faceIds->InsertNextId(pts[faceVerts[3]]); + ////numFacePts = 4; + ////input->GetCellNeighbors(cellId, faceIds, cellIds); + ////if ( cellIds->GetNumberOfIds() <= 0 ) + ////{ + ////polys->InsertNextCell(numFacePts); + ////for ( int i=0; i < numFacePts; i++) + ////{ + ////polys->InsertCellPoint(pts[faceVerts[i]]); + ////} + ////polyCellIds.push_back(cellId); + ////} + ////} + ////break; //} private: @@ -256,322 +276,314 @@ private: namespace itk { -template< typename TInputMesh > -MeshToPolyDataFilter< TInputMesh > -::MeshToPolyDataFilter() +template +MeshToPolyDataFilter::MeshToPolyDataFilter() { // Modify superclass default values, can be overridden by subclasses this->SetNumberOfRequiredInputs(1); - typename PolyDataType::Pointer output = - static_cast< PolyDataType * >( this->MakeOutput(0).GetPointer() ); + typename PolyDataType::Pointer output = static_cast(this->MakeOutput(0).GetPointer()); this->ProcessObject::SetNumberOfRequiredOutputs(1); - this->ProcessObject::SetNthOutput( 0, output.GetPointer() ); + this->ProcessObject::SetNthOutput(0, output.GetPointer()); } -template< typename TInputMesh > +template void -MeshToPolyDataFilter< TInputMesh > -::PrintSelf( std::ostream& os, Indent indent ) const +MeshToPolyDataFilter::PrintSelf(std::ostream & os, Indent indent) const { - Superclass::PrintSelf( os, indent ); + Superclass::PrintSelf(os, indent); } -template< typename TInputMesh > +template void -MeshToPolyDataFilter< TInputMesh > -::SetInput(const TInputMesh *input) +MeshToPolyDataFilter::SetInput(const TInputMesh * input) { // Process object is not const-correct so the const_cast is required here - this->ProcessObject::SetNthInput( 0, const_cast< TInputMesh * >( input ) ); + this->ProcessObject::SetNthInput(0, const_cast(input)); } -template< typename TInputMesh > -const typename MeshToPolyDataFilter< TInputMesh >::InputMeshType * -MeshToPolyDataFilter< TInputMesh > -::GetInput() const +template +const typename MeshToPolyDataFilter::InputMeshType * +MeshToPolyDataFilter::GetInput() const { - return itkDynamicCastInDebugMode< const TInputMesh * >( this->GetPrimaryInput() ); + return itkDynamicCastInDebugMode(this->GetPrimaryInput()); } -template< typename TInputMesh > -const typename MeshToPolyDataFilter< TInputMesh >::InputMeshType * -MeshToPolyDataFilter< TInputMesh > -::GetInput(unsigned int idx) const +template +const typename MeshToPolyDataFilter::InputMeshType * +MeshToPolyDataFilter::GetInput(unsigned int idx) const { - return dynamic_cast< const TInputMesh * > ( this->ProcessObject::GetInput(idx) ); + return dynamic_cast(this->ProcessObject::GetInput(idx)); } -template< typename TInputMesh > +template ProcessObject::DataObjectPointer -MeshToPolyDataFilter< TInputMesh > -::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) +MeshToPolyDataFilter::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) { return PolyDataType::New().GetPointer(); } -template< typename TInputMesh > +template ProcessObject::DataObjectPointer -MeshToPolyDataFilter< TInputMesh > -::MakeOutput(const ProcessObject::DataObjectIdentifierType &) +MeshToPolyDataFilter::MakeOutput(const ProcessObject::DataObjectIdentifierType &) { return PolyDataType::New().GetPointer(); } -template< typename TInputMesh > -typename MeshToPolyDataFilter< TInputMesh >::PolyDataType * -MeshToPolyDataFilter< TInputMesh > -::GetOutput() +template +typename MeshToPolyDataFilter::PolyDataType * +MeshToPolyDataFilter::GetOutput() { // we assume that the first output is of the templated type - return itkDynamicCastInDebugMode< PolyDataType * >( this->GetPrimaryOutput() ); + return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); } -template< typename TInputMesh > -const typename MeshToPolyDataFilter< TInputMesh >::PolyDataType * -MeshToPolyDataFilter< TInputMesh > -::GetOutput() const +template +const typename MeshToPolyDataFilter::PolyDataType * +MeshToPolyDataFilter::GetOutput() const { // we assume that the first output is of the templated type - return itkDynamicCastInDebugMode< const PolyDataType * >( this->GetPrimaryOutput() ); + return itkDynamicCastInDebugMode(this->GetPrimaryOutput()); } -template< typename TInputMesh > -typename MeshToPolyDataFilter< TInputMesh >::PolyDataType * -MeshToPolyDataFilter< TInputMesh > -::GetOutput(unsigned int idx) +template +typename MeshToPolyDataFilter::PolyDataType * +MeshToPolyDataFilter::GetOutput(unsigned int idx) { - auto * out = dynamic_cast< PolyDataType * > ( this->ProcessObject::GetOutput(idx) ); + auto * out = dynamic_cast(this->ProcessObject::GetOutput(idx)); - if ( out == nullptr && this->ProcessObject::GetOutput(idx) != nullptr ) - { - itkWarningMacro (<< "Unable to convert output number " << idx << " to type " << typeid( PolyDataType ).name () ); - } + if (out == nullptr && this->ProcessObject::GetOutput(idx) != nullptr) + { + itkWarningMacro(<< "Unable to convert output number " << idx << " to type " << typeid(PolyDataType).name()); + } return out; } -template< typename TInputMesh > +template void -MeshToPolyDataFilter< TInputMesh > -::GenerateData() +MeshToPolyDataFilter::GenerateData() { const InputMeshType * inputMesh = this->GetInput(); - PolyDataType * outputPolyData = this->GetOutput(); + PolyDataType * outputPolyData = this->GetOutput(); using MeshPointsContainerType = typename InputMeshType::PointsContainer; using PolyDataPointsContainerType = typename PolyDataType::PointsContainer; - const MeshPointsContainerType * inputPoints = inputMesh->GetPoints(); + const MeshPointsContainerType * inputPoints = inputMesh->GetPoints(); typename PolyDataPointsContainerType::Pointer outputPoints = PolyDataPointsContainerType::New(); - outputPoints->resize( inputPoints->Size() ); + outputPoints->resize(inputPoints->Size()); // 2D Mesh -> 3D PolyData, third dimension point locations defaults to 0.0. typename PolyDataType::PointType nullPoint{ 0.0f }; - outputPoints->assign( inputPoints->Size(), nullPoint ); + outputPoints->assign(inputPoints->Size(), nullPoint); typename MeshPointsContainerType::ConstIterator inputPointItr = inputPoints->Begin(); typename MeshPointsContainerType::ConstIterator inputPointEnd = inputPoints->End(); typename PolyDataPointsContainerType::Iterator outputPointItr = outputPoints->Begin(); - while ( inputPointItr != inputPointEnd ) + while (inputPointItr != inputPointEnd) + { + for (unsigned int ii = 0; ii < InputMeshType::PointDimension; ++ii) { - for( unsigned int ii = 0; ii < InputMeshType::PointDimension; ++ii ) - { outputPointItr.Value()[ii] = inputPointItr.Value()[ii]; - } + } ++inputPointItr; ++outputPointItr; - } - outputPolyData->SetPoints( outputPoints ); + } + outputPolyData->SetPoints(outputPoints); using PointDataContainerType = typename PolyDataType::PointDataContainer; const PointDataContainerType * inputPointData = inputMesh->GetPointData(); - if( inputPointData ) - { + if (inputPointData) + { typename PointDataContainerType::Pointer outputPointData = PointDataContainerType::New(); - outputPointData->Reserve( inputPointData->Size() ); + outputPointData->Reserve(inputPointData->Size()); typename PointDataContainerType::ConstIterator inputPointDataItr = inputPointData->Begin(); typename PointDataContainerType::ConstIterator inputPointDataEnd = inputPointData->End(); typename PointDataContainerType::Iterator outputPointDataItr = outputPointData->Begin(); - while( inputPointDataItr != inputPointDataEnd ) - { + while (inputPointDataItr != inputPointDataEnd) + { outputPointDataItr.Value() = inputPointDataItr.Value(); ++inputPointDataItr; ++outputPointDataItr; - } - outputPolyData->SetPointData( outputPointData ); } + outputPolyData->SetPointData(outputPointData); + } - GenerateDataDispatch< TInputMesh >(); + GenerateDataDispatch(); } -template< typename TInputMesh > -template < typename TInputMeshDispatch, typename std::enable_if< !HasCellTraits::value, int>::type > +template +template ::value, int>::type> void -MeshToPolyDataFilter< TInputMesh > -::GenerateDataDispatch() +MeshToPolyDataFilter::GenerateDataDispatch() { // Nothing else to do } -template< typename TInputMesh > -template < typename TInputMeshDispatch, typename std::enable_if< HasCellTraits::value, int>::type > +template +template ::value, int>::type> void -MeshToPolyDataFilter< TInputMesh > -::GenerateDataDispatch() +MeshToPolyDataFilter::GenerateDataDispatch() { // Also propagate cells and cell data const InputMeshType * inputMesh = this->GetInput(); - PolyDataType * outputPolyData = this->GetOutput(); + PolyDataType * outputPolyData = this->GetOutput(); const IdentifierType numberOfCells = inputMesh->GetNumberOfCells(); using CellsContainerType = typename PolyDataType::CellsContainer; typename CellsContainerType::Pointer vertices = CellsContainerType::New(); - vertices->reserve( numberOfCells / 4 + 1 ); + vertices->reserve(numberOfCells / 4 + 1); typename CellsContainerType::Pointer lines = CellsContainerType::New(); - lines->reserve( numberOfCells / 4 + 1 ); + lines->reserve(numberOfCells / 4 + 1); typename CellsContainerType::Pointer polylines = CellsContainerType::New(); - polylines->reserve( numberOfCells / 4 + 1 ); + polylines->reserve(numberOfCells / 4 + 1); typename CellsContainerType::Pointer polygons = CellsContainerType::New(); - polygons->reserve( numberOfCells / 4 + 1 ); - //typename CellsContainerType::Pointer triangleStrips = CellsContainerType::New(); - //triangleStrips->reserve( numberOfCells / 4 + 1 ); + polygons->reserve(numberOfCells / 4 + 1); + // typename CellsContainerType::Pointer triangleStrips = CellsContainerType::New(); + // triangleStrips->reserve( numberOfCells / 4 + 1 ); // These store the cell ids of the input that map to the // new vert/line/poly/strip cells, for copying cell data // in appropriate order. typename CellsContainerType::Pointer verticesCellIds = CellsContainerType::New(); - verticesCellIds->Reserve( numberOfCells / 4 + 1 ); + verticesCellIds->Reserve(numberOfCells / 4 + 1); typename CellsContainerType::Pointer linesCellIds = CellsContainerType::New(); - linesCellIds->Reserve( numberOfCells / 4 + 1 ); + linesCellIds->Reserve(numberOfCells / 4 + 1); typename CellsContainerType::Pointer polygonsCellIds = CellsContainerType::New(); - polygonsCellIds->Reserve( numberOfCells / 4 + 1 ); - //typename CellsContainerType::Pointer triangleStripsCellIds = CellsContainerType::New(); - //triangleStripsCellIds->Reserve( numberOfCells / 4 + 1 ); + polygonsCellIds->Reserve(numberOfCells / 4 + 1); + // typename CellsContainerType::Pointer triangleStripsCellIds = CellsContainerType::New(); + // triangleStripsCellIds->Reserve( numberOfCells / 4 + 1 ); using CellTraits = typename InputMeshType::CellTraits; using PixelType = typename InputMeshType::PixelType; // Setup the vertex visitor - typedef CellInterfaceVisitorImplementation< - PixelType, CellTraits, - VertexCell< CellInterface< PixelType, CellTraits > >, - VisitCellsClass< InputMeshType, PolyDataType > > VertexVisitor; + typedef CellInterfaceVisitorImplementation>, + VisitCellsClass> + VertexVisitor; typename VertexVisitor::Pointer vertexVisitor = VertexVisitor::New(); - vertexVisitor->SetVertices( vertices ); - vertexVisitor->SetLines( lines ); - vertexVisitor->SetPolygons( polygons ); - //vertexVisitor->SetTriangleStrips( triangleStrips ); - vertexVisitor->SetVerticesCellIds( verticesCellIds ); - vertexVisitor->SetLinesCellIds( linesCellIds ); - vertexVisitor->SetPolygonsCellIds( polygonsCellIds ); - //vertexVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); + vertexVisitor->SetVertices(vertices); + vertexVisitor->SetLines(lines); + vertexVisitor->SetPolygons(polygons); + // vertexVisitor->SetTriangleStrips( triangleStrips ); + vertexVisitor->SetVerticesCellIds(verticesCellIds); + vertexVisitor->SetLinesCellIds(linesCellIds); + vertexVisitor->SetPolygonsCellIds(polygonsCellIds); + // vertexVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); // Setup the poly line visitor - typedef CellInterfaceVisitorImplementation< - PixelType, CellTraits, - PolyLineCell< CellInterface< PixelType, CellTraits > >, - VisitCellsClass< InputMeshType, PolyDataType > > PolyLineVisitor; + typedef CellInterfaceVisitorImplementation>, + VisitCellsClass> + PolyLineVisitor; typename PolyLineVisitor::Pointer polyLineVisitor = PolyLineVisitor::New(); - polyLineVisitor->SetVertices( vertices ); - polyLineVisitor->SetLines( polylines ); - polyLineVisitor->SetPolygons( polygons ); - //lineVisitor->SetTriangleStrips( triangleStrips ); - polyLineVisitor->SetVerticesCellIds( verticesCellIds ); - polyLineVisitor->SetLinesCellIds( linesCellIds ); - polyLineVisitor->SetPolygonsCellIds( polygonsCellIds ); - //lineVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); + polyLineVisitor->SetVertices(vertices); + polyLineVisitor->SetLines(polylines); + polyLineVisitor->SetPolygons(polygons); + // lineVisitor->SetTriangleStrips( triangleStrips ); + polyLineVisitor->SetVerticesCellIds(verticesCellIds); + polyLineVisitor->SetLinesCellIds(linesCellIds); + polyLineVisitor->SetPolygonsCellIds(polygonsCellIds); + // lineVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); // Setup the line visitor - typedef CellInterfaceVisitorImplementation< - PixelType, CellTraits, - LineCell< CellInterface< PixelType, CellTraits > >, - VisitCellsClass< InputMeshType, PolyDataType > > LineVisitor; + typedef CellInterfaceVisitorImplementation>, + VisitCellsClass> + LineVisitor; typename LineVisitor::Pointer lineVisitor = LineVisitor::New(); - lineVisitor->SetVertices( vertices ); - lineVisitor->SetLines( lines ); - lineVisitor->SetPolygons( polygons ); - //lineVisitor->SetTriangleStrips( triangleStrips ); - lineVisitor->SetVerticesCellIds( verticesCellIds ); - lineVisitor->SetLinesCellIds( linesCellIds ); - lineVisitor->SetPolygonsCellIds( polygonsCellIds ); - //lineVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); + lineVisitor->SetVertices(vertices); + lineVisitor->SetLines(lines); + lineVisitor->SetPolygons(polygons); + // lineVisitor->SetTriangleStrips( triangleStrips ); + lineVisitor->SetVerticesCellIds(verticesCellIds); + lineVisitor->SetLinesCellIds(linesCellIds); + lineVisitor->SetPolygonsCellIds(polygonsCellIds); + // lineVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); // Setup the triangle visitor - typedef CellInterfaceVisitorImplementation< - PixelType, CellTraits, - TriangleCell< CellInterface< PixelType, CellTraits > >, - VisitCellsClass< InputMeshType, PolyDataType > > TriangleVisitor; + typedef CellInterfaceVisitorImplementation>, + VisitCellsClass> + TriangleVisitor; typename TriangleVisitor::Pointer triangleVisitor = TriangleVisitor::New(); - triangleVisitor->SetVertices( vertices ); - triangleVisitor->SetLines( lines ); - triangleVisitor->SetPolygons( polygons ); - //triangleVisitor->SetTriangleStrips( triangleStrips ); - triangleVisitor->SetVerticesCellIds( verticesCellIds ); - triangleVisitor->SetLinesCellIds( linesCellIds ); - triangleVisitor->SetPolygonsCellIds( polygonsCellIds ); - //triangleVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); + triangleVisitor->SetVertices(vertices); + triangleVisitor->SetLines(lines); + triangleVisitor->SetPolygons(polygons); + // triangleVisitor->SetTriangleStrips( triangleStrips ); + triangleVisitor->SetVerticesCellIds(verticesCellIds); + triangleVisitor->SetLinesCellIds(linesCellIds); + triangleVisitor->SetPolygonsCellIds(polygonsCellIds); + // triangleVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); // Setup the quadrilateral visitor - typedef CellInterfaceVisitorImplementation< - PixelType, CellTraits, - QuadrilateralCell< CellInterface< PixelType, CellTraits > >, - VisitCellsClass< InputMeshType, PolyDataType > > QuadrilateralVisitor; + typedef CellInterfaceVisitorImplementation>, + VisitCellsClass> + QuadrilateralVisitor; typename QuadrilateralVisitor::Pointer quadrilateralVisitor = QuadrilateralVisitor::New(); - quadrilateralVisitor->SetVertices( vertices ); - quadrilateralVisitor->SetLines( lines ); - quadrilateralVisitor->SetPolygons( polygons ); - //quadrilateralVisitor->SetTriangleStrips( triangleStrips ); - quadrilateralVisitor->SetVerticesCellIds( verticesCellIds ); - quadrilateralVisitor->SetLinesCellIds( linesCellIds ); - quadrilateralVisitor->SetPolygonsCellIds( polygonsCellIds ); - //quadrilateralVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); + quadrilateralVisitor->SetVertices(vertices); + quadrilateralVisitor->SetLines(lines); + quadrilateralVisitor->SetPolygons(polygons); + // quadrilateralVisitor->SetTriangleStrips( triangleStrips ); + quadrilateralVisitor->SetVerticesCellIds(verticesCellIds); + quadrilateralVisitor->SetLinesCellIds(linesCellIds); + quadrilateralVisitor->SetPolygonsCellIds(polygonsCellIds); + // quadrilateralVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); // Setup the polygon visitor - typedef CellInterfaceVisitorImplementation< - PixelType, CellTraits, - PolygonCell< CellInterface< PixelType, CellTraits > >, - VisitCellsClass< InputMeshType, PolyDataType > > PolygonVisitor; + typedef CellInterfaceVisitorImplementation>, + VisitCellsClass> + PolygonVisitor; typename PolygonVisitor::Pointer polygonVisitor = PolygonVisitor::New(); - polygonVisitor->SetVertices( vertices ); - polygonVisitor->SetLines( lines ); - polygonVisitor->SetPolygons( polygons ); - //polygonVisitor->SetTriangleStrips( triangleStrips ); - polygonVisitor->SetVerticesCellIds( verticesCellIds ); - polygonVisitor->SetLinesCellIds( linesCellIds ); - polygonVisitor->SetPolygonsCellIds( polygonsCellIds ); - //polygonVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); + polygonVisitor->SetVertices(vertices); + polygonVisitor->SetLines(lines); + polygonVisitor->SetPolygons(polygons); + // polygonVisitor->SetTriangleStrips( triangleStrips ); + polygonVisitor->SetVerticesCellIds(verticesCellIds); + polygonVisitor->SetLinesCellIds(linesCellIds); + polygonVisitor->SetPolygonsCellIds(polygonsCellIds); + // polygonVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); // TODO // Setup the tetrahedron visitor - //typedef CellInterfaceVisitorImplementation< - //PixelType, CellTraits, - //TetrahedronCell< CellInterface< PixelType, CellTraits > >, - //VisitCellsClass< InputMeshType, PolyDataType > > TetrahedronVisitor; - //typename TetrahedronVisitor::Pointer tetrahedronVisitor = TetrahedronVisitor::New(); - //tetrahedronVisitor->SetVertices( vertices ); - //tetrahedronVisitor->SetLines( lines ); - //tetrahedronVisitor->SetPolygons( polygons ); - //tetrahedronVisitor->SetTriangleStrips( triangleStrips ); - //tetrahedronVisitor->SetVerticesCellIds( verticesCellIds ); - //tetrahedronVisitor->SetLinesCellIds( linesCellIds ); - //tetrahedronVisitor->SettetrahedronsCellIds( tetrahedronsCellIds ); - //tetrahedronVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); + // typedef CellInterfaceVisitorImplementation< + // PixelType, CellTraits, + // TetrahedronCell< CellInterface< PixelType, CellTraits > >, + // VisitCellsClass< InputMeshType, PolyDataType > > TetrahedronVisitor; + // typename TetrahedronVisitor::Pointer tetrahedronVisitor = TetrahedronVisitor::New(); + // tetrahedronVisitor->SetVertices( vertices ); + // tetrahedronVisitor->SetLines( lines ); + // tetrahedronVisitor->SetPolygons( polygons ); + // tetrahedronVisitor->SetTriangleStrips( triangleStrips ); + // tetrahedronVisitor->SetVerticesCellIds( verticesCellIds ); + // tetrahedronVisitor->SetLinesCellIds( linesCellIds ); + // tetrahedronVisitor->SettetrahedronsCellIds( tetrahedronsCellIds ); + // tetrahedronVisitor->SetTriangleStripsCellIds( triangleStripsCellIds ); typename InputMeshType::CellType::MultiVisitor::Pointer multiVisitor = InputMeshType::CellType::MultiVisitor::New(); @@ -581,18 +593,18 @@ MeshToPolyDataFilter< TInputMesh > multiVisitor->AddVisitor(triangleVisitor.GetPointer()); multiVisitor->AddVisitor(quadrilateralVisitor.GetPointer()); multiVisitor->AddVisitor(polygonVisitor.GetPointer()); - //multiVisitor->AddVisitor(tetrahedronVisitor.GetPointer()); + // multiVisitor->AddVisitor(tetrahedronVisitor.GetPointer()); // Now ask the mesh to accept the multivisitor which // will Call Visit for each cell in the mesh that matches the // cell types of the visitors added to the MultiVisitor - if( numberOfCells ) + if (numberOfCells) { inputMesh->Accept(multiVisitor); } vertices->shrink_to_fit(); - outputPolyData->SetVertices( vertices ); + outputPolyData->SetVertices(vertices); // Append lines to polylines before calling SetLines lines->shrink_to_fit(); @@ -601,54 +613,50 @@ MeshToPolyDataFilter< TInputMesh > auto iterator_start_lines = lines->begin(); auto iterator_end_lines = lines->end(); auto iterator_end_polylines = polylines->end(); - polylines->insert(iterator_end_polylines, iterator_start_lines, iterator_end_lines); - - outputPolyData->SetLines( polylines); + polylines->insert(iterator_end_polylines, iterator_start_lines, iterator_end_lines); + + outputPolyData->SetLines(polylines); polygons->shrink_to_fit(); - outputPolyData->SetPolygons( polygons ); - //triangleStrips->shrink_to_fit(); - //outputPolyData->SetTriangleStrips( triangleStrips ); + outputPolyData->SetPolygons(polygons); + // triangleStrips->shrink_to_fit(); + // outputPolyData->SetTriangleStrips( triangleStrips ); using CellDataContainerType = typename PolyDataType::CellDataContainer; const CellDataContainerType * inputCellData = inputMesh->GetCellData(); - if( inputCellData && inputCellData->Size() ) + if (inputCellData && inputCellData->Size()) { typename CellDataContainerType::Pointer outputCellData = CellDataContainerType::New(); - outputCellData->Reserve( inputCellData->Size() ); + outputCellData->Reserve(inputCellData->Size()); SizeValueType offset = 0; SizeValueType size = verticesCellIds->Size(); // Copy the cell data in appropriate order : verts / lines / polys / strips - for( SizeValueType ii = 0; ii < verticesCellIds->Size(); ++ii ) - { - outputCellData->InsertElement( ii, - inputCellData->ElementAt( verticesCellIds->ElementAt( ii ) ) ); - } + for (SizeValueType ii = 0; ii < verticesCellIds->Size(); ++ii) + { + outputCellData->InsertElement(ii, inputCellData->ElementAt(verticesCellIds->ElementAt(ii))); + } offset += size; size = linesCellIds->Size(); - for( SizeValueType ii = 0; ii < size; ++ii ) - { - outputCellData->InsertElement( offset + ii, - inputCellData->ElementAt( linesCellIds->ElementAt( ii ) ) ); - } + for (SizeValueType ii = 0; ii < size; ++ii) + { + outputCellData->InsertElement(offset + ii, inputCellData->ElementAt(linesCellIds->ElementAt(ii))); + } offset += size; size = polygonsCellIds->Size(); - for( SizeValueType ii = 0; ii < size; ++ii ) - { - outputCellData->InsertElement( offset + ii, - inputCellData->ElementAt( polygonsCellIds->ElementAt( ii ) ) ); - } - offset += size; - //size = triangleStripsCellIds->Size(); - //for( SizeValueType ii = 0; ii < size; ++ii ) - //{ - //outputCellData->InsertElement( offset + ii, - //inputCellData->ElementAt( triangleStripsCellIds->ElementAt( ii ) ) ); - //} - - outputPolyData->SetCellData( outputCellData ); + for (SizeValueType ii = 0; ii < size; ++ii) + { + outputCellData->InsertElement(offset + ii, inputCellData->ElementAt(polygonsCellIds->ElementAt(ii))); } - + offset += size; + // size = triangleStripsCellIds->Size(); + // for( SizeValueType ii = 0; ii < size; ++ii ) + //{ + // outputCellData->InsertElement( offset + ii, + // inputCellData->ElementAt( triangleStripsCellIds->ElementAt( ii ) ) ); + //} + + outputPolyData->SetCellData(outputCellData); + } } diff --git a/include/itkPolyData.h b/include/itkPolyData.h index c89e3a7..d315564 100644 --- a/include/itkPolyData.h +++ b/include/itkPolyData.h @@ -31,16 +31,16 @@ namespace itk * * \ingroup MeshToPolyData */ -template< typename TPixel, typename TCellPixel = TPixel > -class ITK_TEMPLATE_EXPORT PolyData: public DataObject +template +class ITK_TEMPLATE_EXPORT PolyData : public DataObject { public: ITK_DISALLOW_COPY_AND_MOVE(PolyData); using Self = PolyData; using Superclass = DataObject; - using Pointer = SmartPointer< Self >; - using ConstPointer = SmartPointer< const Self >; + using Pointer = SmartPointer; + using ConstPointer = SmartPointer; static constexpr unsigned int PointDimension = 3; @@ -54,7 +54,7 @@ class ITK_TEMPLATE_EXPORT PolyData: public DataObject /** Type of PointData or CellData */ using PixelType = TPixel; using CellPixelType = TCellPixel; - using MeshTraits = DefaultStaticMeshTraits< PixelType, PointDimension, PointDimension, float, float, CellPixelType >; + using MeshTraits = DefaultStaticMeshTraits; /** Convenient type alias obtained from TMeshTraits template parameter. */ using CoordinateType = typename MeshTraits::CoordinateType; @@ -64,72 +64,100 @@ class ITK_TEMPLATE_EXPORT PolyData: public DataObject using PointDataContainer = typename MeshTraits::PointDataContainer; using CellIdentifier = typename MeshTraits::CellIdentifier; using CellDataContainer = typename MeshTraits::CellDataContainer; - using CellsContainer = VectorContainer< CellIdentifier, uint32_t >; + using CellsContainer = VectorContainer; - void Initialize() override; + void + Initialize() override; - PointIdentifier GetNumberOfPoints() const; + PointIdentifier + GetNumberOfPoints() const; /** Define Set/Get access routines for each internal container. * Methods also exist to add points, cells, etc. one at a time * rather than through an entire container. */ - void SetPoints(PointsContainer *); - PointsContainer * GetPoints(); - const PointsContainer * GetPoints() const; + void + SetPoints(PointsContainer *); + PointsContainer * + GetPoints(); + const PointsContainer * + GetPoints() const; /** Vertices in format [1 pointIndex1 1 pointIndex2 1 pointIndex3 ... ] */ - void SetVertices(CellsContainer *); - CellsContainer * GetVertices(); - const CellsContainer* GetVertices() const; + void + SetVertices(CellsContainer *); + CellsContainer * + GetVertices(); + const CellsContainer * + GetVertices() const; /** Lines in format [nPointsLine1 pointIndex1 pointIndex2 nPointsLine2 pointIndex1 pointIndex2 ... ] */ - void SetLines(CellsContainer *); - CellsContainer * GetLines(); - const CellsContainer* GetLines() const; + void + SetLines(CellsContainer *); + CellsContainer * + GetLines(); + const CellsContainer * + GetLines() const; /** Polygons in format [nPointsPolygon1 pointIndex1 pointIndex2 nPointsPolygon2 pointIndex1 pointIndex2 ... ] */ - void SetPolygons(CellsContainer *); - CellsContainer * GetPolygons(); - const CellsContainer* GetPolygons() const; - - /** TriangleStrips in format [nPointsTriangleStrip1 pointIndex1 pointIndex2 nPointsTriangleStrip2 pointIndex1 pointIndex2 ... ] */ - void SetTriangleStrips(CellsContainer *); - CellsContainer * GetTriangleStrips(); - const CellsContainer* GetTriangleStrips() const; - - void SetPointData(PointDataContainer *); - PointDataContainer * GetPointData(); - const PointDataContainer * GetPointData() const; + void + SetPolygons(CellsContainer *); + CellsContainer * + GetPolygons(); + const CellsContainer * + GetPolygons() const; + + /** TriangleStrips in format [nPointsTriangleStrip1 pointIndex1 pointIndex2 nPointsTriangleStrip2 pointIndex1 + * pointIndex2 ... ] */ + void + SetTriangleStrips(CellsContainer *); + CellsContainer * + GetTriangleStrips(); + const CellsContainer * + GetTriangleStrips() const; + + void + SetPointData(PointDataContainer *); + PointDataContainer * + GetPointData(); + const PointDataContainer * + GetPointData() const; /** Access routines to fill the Points container, and get information * from it. */ void SetPoint(PointIdentifier, PointType); - bool GetPoint(PointIdentifier, PointType *) const; + bool + GetPoint(PointIdentifier, PointType *) const; PointType GetPoint(PointIdentifier) const; /** Access routines to fill the PointData container, and get information * from it. */ void SetPointData(PointIdentifier, PixelType); - bool GetPointData(PointIdentifier, PixelType *) const; + bool + GetPointData(PointIdentifier, PixelType *) const; /** Access m_CellDataContainer, which contains data associated with * the mesh's cells. Optionally, this can be nullptr, indicating that * no data are associated with the cells. The data for a cell can * be accessed through its cell identifier. */ - void SetCellData(CellDataContainer *); - CellDataContainer * GetCellData(); - const CellDataContainer * GetCellData() const; + void + SetCellData(CellDataContainer *); + CellDataContainer * + GetCellData(); + const CellDataContainer * + GetCellData() const; /** Access routines to fill the CellData container, and get information * from it. */ void SetCellData(CellIdentifier, CellPixelType); - bool GetCellData(CellIdentifier, CellPixelType *) const; + bool + GetCellData(CellIdentifier, CellPixelType *) const; protected: PolyData(); ~PolyData() override = default; - void PrintSelf(std::ostream & os, Indent indent) const override; + void + PrintSelf(std::ostream & os, Indent indent) const override; /** An object containing points used by the mesh. Individual points are * accessed through point identifiers. */ @@ -147,13 +175,14 @@ class ITK_TEMPLATE_EXPORT PolyData: public DataObject typename PointDataContainer::Pointer m_PointDataContainer; typename CellDataContainer::Pointer m_CellDataContainer; + private: }; } // end namespace itk #ifndef ITK_MANUAL_INSTANTIATION -#include "itkPolyData.hxx" +# include "itkPolyData.hxx" #endif #endif // itkPolyData_h diff --git a/include/itkPolyData.hxx b/include/itkPolyData.hxx index 2a4c48a..b26425f 100644 --- a/include/itkPolyData.hxx +++ b/include/itkPolyData.hxx @@ -23,281 +23,263 @@ namespace itk { -template< typename TPixelType, typename TCellPixel > -PolyData< TPixelType, TCellPixel > -::PolyData(): - m_PointsContainer(nullptr), - m_VerticesContainer(nullptr), - m_LinesContainer(nullptr), - m_PolygonsContainer(nullptr), - m_TriangleStripsContainer(nullptr), - m_PointDataContainer(nullptr), - m_CellDataContainer(nullptr) -{ -} - - -template< typename TPixelType, typename TCellPixel > +template +PolyData::PolyData() + : m_PointsContainer(nullptr) + , m_VerticesContainer(nullptr) + , m_LinesContainer(nullptr) + , m_PolygonsContainer(nullptr) + , m_TriangleStripsContainer(nullptr) + , m_PointDataContainer(nullptr) + , m_CellDataContainer(nullptr) +{} + + +template void -PolyData< TPixelType, TCellPixel > -::PrintSelf(std::ostream & os, Indent indent) const +PolyData::PrintSelf(std::ostream & os, Indent indent) const { - Superclass::PrintSelf( os, indent ); - os << indent << "Number Of Points: " - << this->GetNumberOfPoints() << std::endl; + Superclass::PrintSelf(os, indent); + os << indent << "Number Of Points: " << this->GetNumberOfPoints() << std::endl; os << indent << "Point Data Container pointer: " - << ( ( this->m_PointDataContainer ) ? this->m_PointDataContainer.GetPointer() : nullptr ) << std::endl; - os << indent << "Size of Point Data Container: " - << ( ( this->m_PointDataContainer ) ? this->m_PointDataContainer->Size() : 0 ) << std::endl; - os << indent << "Cell Data Container pointer: " - << ( ( m_CellDataContainer ) ? m_CellDataContainer.GetPointer() : nullptr ) << std::endl; - os << indent << "Size of Cell Data Container: " - << ( ( m_CellDataContainer ) ? m_CellDataContainer->Size() : 0 ) << std::endl; + << ((this->m_PointDataContainer) ? this->m_PointDataContainer.GetPointer() : nullptr) << std::endl; + os << indent + << "Size of Point Data Container: " << ((this->m_PointDataContainer) ? this->m_PointDataContainer->Size() : 0) + << std::endl; + os << indent + << "Cell Data Container pointer: " << ((m_CellDataContainer) ? m_CellDataContainer.GetPointer() : nullptr) + << std::endl; + os << indent << "Size of Cell Data Container: " << ((m_CellDataContainer) ? m_CellDataContainer->Size() : 0) + << std::endl; } -template< typename TPixelType, typename TCellPixel > +template void -PolyData< TPixelType, TCellPixel > -::SetPoints(PointsContainer *points) +PolyData::SetPoints(PointsContainer * points) { itkDebugMacro("setting Points container to " << points); - if ( m_PointsContainer != points ) - { + if (m_PointsContainer != points) + { m_PointsContainer = points; this->Modified(); - } + } } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetPoints() -> PointsContainer * +PolyData::GetPoints() -> PointsContainer * { itkDebugMacro("Starting GetPoints()"); - if ( !m_PointsContainer ) - { - this->SetPoints( PointsContainer::New() ); - } + if (!m_PointsContainer) + { + this->SetPoints(PointsContainer::New()); + } itkDebugMacro("returning Points container of " << m_PointsContainer); return m_PointsContainer; } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetPoints() const -> const PointsContainer * +PolyData::GetPoints() const -> const PointsContainer * { itkDebugMacro("returning Points container of " << m_PointsContainer); return m_PointsContainer.GetPointer(); } -template< typename TPixelType, typename TCellPixel > +template void -PolyData< TPixelType, TCellPixel > -::SetVertices(CellsContainer *vertices) +PolyData::SetVertices(CellsContainer * vertices) { itkDebugMacro("setting Vertices container to " << vertices); - if ( m_VerticesContainer != vertices ) - { + if (m_VerticesContainer != vertices) + { m_VerticesContainer = vertices; this->Modified(); - } + } } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetVertices() -> CellsContainer * +PolyData::GetVertices() -> CellsContainer * { itkDebugMacro("Starting GetVertices()"); - if ( !m_VerticesContainer ) { - this->SetVertices( CellsContainer::New() ); - } + if (!m_VerticesContainer) + { + this->SetVertices(CellsContainer::New()); + } itkDebugMacro("returning Vertices container of " << m_VerticesContainer); return m_VerticesContainer.GetPointer(); } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetVertices() const -> const CellsContainer * +PolyData::GetVertices() const -> const CellsContainer * { itkDebugMacro("returning Vertices container of " << m_VerticesContainer); return m_VerticesContainer.GetPointer(); } -template< typename TPixelType, typename TCellPixel > +template void -PolyData< TPixelType, TCellPixel > -::SetLines(CellsContainer *lines) +PolyData::SetLines(CellsContainer * lines) { itkDebugMacro("setting Lines container to " << lines); - if ( m_LinesContainer != lines ) - { - m_LinesContainer = lines; - this->Modified(); - } + if (m_LinesContainer != lines) + { + m_LinesContainer = lines; + this->Modified(); + } } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetLines() -> CellsContainer * +PolyData::GetLines() -> CellsContainer * { itkDebugMacro("Starting GetLines()"); - if ( !m_LinesContainer ) { - this->SetLines( CellsContainer::New() ); - } + if (!m_LinesContainer) + { + this->SetLines(CellsContainer::New()); + } itkDebugMacro("returning Lines container of " << m_LinesContainer); return m_LinesContainer.GetPointer(); } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetLines() const -> const CellsContainer * +PolyData::GetLines() const -> const CellsContainer * { itkDebugMacro("returning Lines container of " << m_LinesContainer); return m_LinesContainer.GetPointer(); } -template< typename TPixelType, typename TCellPixel > +template void -PolyData< TPixelType, TCellPixel > -::SetPolygons(CellsContainer *polygons) +PolyData::SetPolygons(CellsContainer * polygons) { itkDebugMacro("setting Polygons container to " << polygons); - if ( m_PolygonsContainer != polygons ) - { + if (m_PolygonsContainer != polygons) + { m_PolygonsContainer = polygons; this->Modified(); - } + } } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetPolygons() -> CellsContainer * +PolyData::GetPolygons() -> CellsContainer * { itkDebugMacro("Starting GetPolygons()"); - if ( !m_PolygonsContainer ) { - this->SetPolygons( CellsContainer::New() ); - } + if (!m_PolygonsContainer) + { + this->SetPolygons(CellsContainer::New()); + } itkDebugMacro("returning Polygons container of " << m_PolygonsContainer); return m_PolygonsContainer.GetPointer(); } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetPolygons() const -> const CellsContainer * +PolyData::GetPolygons() const -> const CellsContainer * { itkDebugMacro("returning Polygons container of " << m_PolygonsContainer); return m_PolygonsContainer.GetPointer(); } -template< typename TPixelType, typename TCellPixel > +template void -PolyData< TPixelType, TCellPixel > -::SetTriangleStrips(CellsContainer *polygons) +PolyData::SetTriangleStrips(CellsContainer * polygons) { itkDebugMacro("setting TriangleStrips container to " << polygons); - if ( m_TriangleStripsContainer != polygons ) - { + if (m_TriangleStripsContainer != polygons) + { m_TriangleStripsContainer = polygons; this->Modified(); - } + } } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetTriangleStrips() -> CellsContainer * +PolyData::GetTriangleStrips() -> CellsContainer * { itkDebugMacro("Starting GetTriangleStrips()"); - if ( !m_TriangleStripsContainer ) { - this->SetTriangleStrips( CellsContainer::New() ); - } + if (!m_TriangleStripsContainer) + { + this->SetTriangleStrips(CellsContainer::New()); + } itkDebugMacro("returning TriangleStrips container of " << m_TriangleStripsContainer); return m_TriangleStripsContainer.GetPointer(); } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetTriangleStrips() const -> const CellsContainer * +PolyData::GetTriangleStrips() const -> const CellsContainer * { itkDebugMacro("returning TriangleStrips container of " << m_TriangleStripsContainer); return m_TriangleStripsContainer.GetPointer(); } -template< typename TPixelType, typename TCellPixel > +template void -PolyData< TPixelType, TCellPixel > -::SetPointData(PointDataContainer *pointData) +PolyData::SetPointData(PointDataContainer * pointData) { itkDebugMacro("setting PointData container to " << pointData); - if ( m_PointDataContainer != pointData ) - { + if (m_PointDataContainer != pointData) + { m_PointDataContainer = pointData; this->Modified(); - } + } } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetPointData() -> PointDataContainer * +PolyData::GetPointData() -> PointDataContainer * { - if ( !m_PointDataContainer ) - { - this->SetPointData( PointDataContainer::New() ); - } + if (!m_PointDataContainer) + { + this->SetPointData(PointDataContainer::New()); + } itkDebugMacro("returning PointData container of " << m_PointDataContainer); return m_PointDataContainer; } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetPointData() const -> const PointDataContainer * +PolyData::GetPointData() const -> const PointDataContainer * { - itkDebugMacro("returning PointData container of " - << m_PointDataContainer); + itkDebugMacro("returning PointData container of " << m_PointDataContainer); return m_PointDataContainer.GetPointer(); } -template< typename TPixelType, typename TCellPixel > +template void -PolyData< TPixelType, TCellPixel > -::SetPoint(PointIdentifier ptId, PointType point) +PolyData::SetPoint(PointIdentifier ptId, PointType point) { /** * Make sure a points container exists. */ - if ( !m_PointsContainer ) - { - this->SetPoints( PointsContainer::New() ); - } + if (!m_PointsContainer) + { + this->SetPoints(PointsContainer::New()); + } /** * Insert the point into the container with the given identifier. @@ -306,18 +288,17 @@ PolyData< TPixelType, TCellPixel > } -template< typename TPixelType, typename TCellPixel > +template bool -PolyData< TPixelType, TCellPixel > -::GetPoint(PointIdentifier ptId, PointType *point) const +PolyData::GetPoint(PointIdentifier ptId, PointType * point) const { /** * If the points container doesn't exist, then the point doesn't either. */ - if ( !m_PointsContainer ) - { + if (!m_PointsContainer) + { return false; - } + } /** * Ask the container if the point identifier exists. @@ -326,44 +307,42 @@ PolyData< TPixelType, TCellPixel > } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetPoint(PointIdentifier ptId) const -> PointType +PolyData::GetPoint(PointIdentifier ptId) const -> PointType { /** * If the points container doesn't exist, then the point doesn't either. */ - if ( !m_PointsContainer ) - { + if (!m_PointsContainer) + { itkExceptionMacro("Point container doesn't exist."); - } + } /** * Ask the container if the point identifier exists. */ PointType point; - bool exist = m_PointsContainer->GetElementIfIndexExists(ptId, &point); - if( ! exist ) - { + bool exist = m_PointsContainer->GetElementIfIndexExists(ptId, &point); + if (!exist) + { itkExceptionMacro("Point id doesn't exist: " << ptId); - } + } return point; } -template< typename TPixelType, typename TCellPixel > +template void -PolyData< TPixelType, TCellPixel > -::SetPointData(PointIdentifier ptId, PixelType data) +PolyData::SetPointData(PointIdentifier ptId, PixelType data) { /** * Make sure a point data container exists. */ - if ( !m_PointDataContainer ) - { - this->SetPointData( PointDataContainer::New() ); - } + if (!m_PointDataContainer) + { + this->SetPointData(PointDataContainer::New()); + } /** * Insert the point data into the container with the given identifier. @@ -372,19 +351,18 @@ PolyData< TPixelType, TCellPixel > } -template< typename TPixelType, typename TCellPixel > +template bool -PolyData< TPixelType, TCellPixel > -::GetPointData(PointIdentifier ptId, PixelType *data) const +PolyData::GetPointData(PointIdentifier ptId, PixelType * data) const { /** * If the point data container doesn't exist, then the point data doesn't * either. */ - if ( !m_PointDataContainer ) - { + if (!m_PointDataContainer) + { return false; - } + } /** * Ask the container if the point identifier exists. @@ -393,59 +371,52 @@ PolyData< TPixelType, TCellPixel > } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetNumberOfPoints() const -> PointIdentifier +PolyData::GetNumberOfPoints() const -> PointIdentifier { - if ( m_PointsContainer ) - { + if (m_PointsContainer) + { return m_PointsContainer->Size(); - } + } return 0; } -template< typename TPixelType, typename TCellPixel > +template void -PolyData< TPixelType, TCellPixel > -::SetCellData(CellDataContainer *cellData) +PolyData::SetCellData(CellDataContainer * cellData) { itkDebugMacro("setting CellData container to " << cellData); - if ( m_CellDataContainer != cellData ) - { + if (m_CellDataContainer != cellData) + { m_CellDataContainer = cellData; this->Modified(); - } + } } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetCellData() -> CellDataContainer * +PolyData::GetCellData() -> CellDataContainer * { - itkDebugMacro("returning CellData container of " - << m_CellDataContainer); + itkDebugMacro("returning CellData container of " << m_CellDataContainer); return m_CellDataContainer; } -template< typename TPixelType, typename TCellPixel > +template auto -PolyData< TPixelType, TCellPixel > -::GetCellData() const -> const CellDataContainer * +PolyData::GetCellData() const -> const CellDataContainer * { - itkDebugMacro("returning CellData container of " - << m_CellDataContainer); + itkDebugMacro("returning CellData container of " << m_CellDataContainer); return m_CellDataContainer; } -template< typename TPixelType, typename TCellPixel > +template void -PolyData< TPixelType, TCellPixel > -::SetCellData(CellIdentifier cellId, TCellPixel data) +PolyData::SetCellData(CellIdentifier cellId, TCellPixel data) { /** * Assign data to a cell identifier. If a spot for the cell identifier @@ -456,10 +427,10 @@ PolyData< TPixelType, TCellPixel > /** * Make sure a cell data container exists. */ - if ( !m_CellDataContainer ) - { - this->SetCellData( CellDataContainer::New() ); - } + if (!m_CellDataContainer) + { + this->SetCellData(CellDataContainer::New()); + } /** * Insert the cell data into the container with the given identifier. @@ -468,10 +439,9 @@ PolyData< TPixelType, TCellPixel > } -template< typename TPixelType, typename TCellPixel > +template bool -PolyData< TPixelType, TCellPixel > -::GetCellData(CellIdentifier cellId, TCellPixel *data) const +PolyData::GetCellData(CellIdentifier cellId, TCellPixel * data) const { /** * Check if cell data exists for a given cell identifier. If a spot for @@ -485,10 +455,10 @@ PolyData< TPixelType, TCellPixel > * If the cell data container doesn't exist, then the cell data doesn't * either. */ - if ( !m_CellDataContainer ) - { + if (!m_CellDataContainer) + { return false; - } + } /** * Ask the container if the cell identifier exists. @@ -497,10 +467,9 @@ PolyData< TPixelType, TCellPixel > } -template< typename TPixelType, typename TCellPixel > +template void -PolyData< TPixelType, TCellPixel > -::Initialize() +PolyData::Initialize() { Superclass::Initialize(); diff --git a/include/itkPolyDataToMeshFilter.hxx b/include/itkPolyDataToMeshFilter.hxx index bed0421..a60ad2e 100644 --- a/include/itkPolyDataToMeshFilter.hxx +++ b/include/itkPolyDataToMeshFilter.hxx @@ -77,8 +77,8 @@ PolyDataToMeshFilter::GetInput(unsigned int idx) const template -ProcessObject::DataObjectPointer PolyDataToMeshFilter::MakeOutput( - ProcessObject::DataObjectPointerArraySizeType) +ProcessObject::DataObjectPointer +PolyDataToMeshFilter::MakeOutput(ProcessObject::DataObjectPointerArraySizeType) { return MeshType::New().GetPointer(); } @@ -206,9 +206,9 @@ PolyDataToMeshFilter::GenerateData() while (inputCellItr != inputCellEnd) { - #ifndef NDEBUG +#ifndef NDEBUG auto numPoints = inputCellItr.Value(); - #endif +#endif ++inputCellItr; // Verify vertex contains exactly one point ID diff --git a/test/itkImageToPointSetFilterTest.cxx b/test/itkImageToPointSetFilterTest.cxx index db95f2b..5c1e99e 100644 --- a/test/itkImageToPointSetFilterTest.cxx +++ b/test/itkImageToPointSetFilterTest.cxx @@ -21,44 +21,45 @@ #include "itkImageToPointSetFilter.h" -int itkImageToPointSetFilterTest( int argc, char *argv[] ) +int +itkImageToPointSetFilterTest(int argc, char * argv[]) { - if ( argc < 3 ) - { + if (argc < 3) + { std::cerr << "Usage: " << argv[0]; std::cerr << " inputImage outputMesh"; std::cerr << std::endl; return EXIT_FAILURE; - } + } const unsigned int Dimension = 2; using PixelType = float; - using InputImageType = itk::Image< PixelType, Dimension >; - using OutputMeshType = itk::Mesh< PixelType, Dimension >; + using InputImageType = itk::Image; + using OutputMeshType = itk::Mesh; - using ReaderType = itk::ImageFileReader< InputImageType >; + using ReaderType = itk::ImageFileReader; ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( argv[1] ); + reader->SetFileName(argv[1]); - using FilterType = itk::ImageToPointSetFilter< InputImageType, OutputMeshType >; + using FilterType = itk::ImageToPointSetFilter; FilterType::Pointer filter = FilterType::New(); - filter->SetInput(0, reader->GetOutput() ); + filter->SetInput(0, reader->GetOutput()); - using WriterType = itk::MeshFileWriter< OutputMeshType >; + using WriterType = itk::MeshFileWriter; WriterType::Pointer writer = WriterType::New(); - writer->SetInput( filter->GetOutput() ); - writer->SetFileName( argv[2] ); + writer->SetInput(filter->GetOutput()); + writer->SetFileName(argv[2]); try - { + { writer->Update(); - } - catch( itk::ExceptionObject& ex ) - { + } + catch (itk::ExceptionObject & ex) + { std::cerr << "Exception caught!" << std::endl; std::cerr << ex << std::endl; return EXIT_FAILURE; - } + } return EXIT_SUCCESS; } diff --git a/test/itkMeshToPolyDataFilterTest.cxx b/test/itkMeshToPolyDataFilterTest.cxx index 8c43faa..9570f66 100644 --- a/test/itkMeshToPolyDataFilterTest.cxx +++ b/test/itkMeshToPolyDataFilterTest.cxx @@ -26,100 +26,102 @@ #include "itkTestingMacros.h" #include "itkMath.h" -namespace{ +namespace +{ class ShowProgress : public itk::Command { public: - itkNewMacro( ShowProgress ); + itkNewMacro(ShowProgress); void - Execute( itk::Object* caller, const itk::EventObject& event ) override + Execute(itk::Object * caller, const itk::EventObject & event) override { - Execute( (const itk::Object*)caller, event ); + Execute((const itk::Object *)caller, event); } void - Execute( const itk::Object* caller, const itk::EventObject& event ) override + Execute(const itk::Object * caller, const itk::EventObject & event) override { - if ( !itk::ProgressEvent().CheckEvent( &event ) ) - { + if (!itk::ProgressEvent().CheckEvent(&event)) + { return; - } - const auto* processObject = dynamic_cast< const itk::ProcessObject* >( caller ); - if ( !processObject ) - { + } + const auto * processObject = dynamic_cast(caller); + if (!processObject) + { return; - } + } std::cout << " " << processObject->GetProgress(); } }; -} +} // namespace -int itkMeshToPolyDataFilterTest( int argc, char * argv[] ) +int +itkMeshToPolyDataFilterTest(int argc, char * argv[]) { - if( argc < 3 ) - { + if (argc < 3) + { std::cerr << "Usage: " << argv[0]; std::cerr << " inputMesh outputPolyData"; std::cerr << std::endl; return EXIT_FAILURE; - } + } const char * inputMeshFileName = argv[1]; const char * outputPolyDataFileName = argv[1]; const unsigned int Dimension = 3; using PixelType = float; - using MeshType = itk::Mesh< PixelType, Dimension >; + using MeshType = itk::Mesh; - using MeshReaderType = itk::MeshFileReader< MeshType >; + using MeshReaderType = itk::MeshFileReader; MeshReaderType::Pointer meshReader = MeshReaderType::New(); - meshReader->SetFileName( inputMeshFileName ); + meshReader->SetFileName(inputMeshFileName); meshReader->Update(); - using FilterType = itk::MeshToPolyDataFilter< MeshType >; + using FilterType = itk::MeshToPolyDataFilter; FilterType::Pointer filter = FilterType::New(); - ITK_EXERCISE_BASIC_OBJECT_METHODS( filter, MeshToPolyDataFilter, ProcessObject ); + ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, MeshToPolyDataFilter, ProcessObject); - filter->SetInput( meshReader->GetOutput() ); + filter->SetInput(meshReader->GetOutput()); ShowProgress::Pointer showProgress = ShowProgress::New(); - filter->AddObserver( itk::ProgressEvent(), showProgress ); + filter->AddObserver(itk::ProgressEvent(), showProgress); - ITK_TRY_EXPECT_NO_EXCEPTION( filter->Update() ); + ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); using PolyDataType = FilterType::PolyDataType; PolyDataType::ConstPointer polyData = filter->GetOutput(); - ITK_TEST_EXPECT_EQUAL( polyData->GetNumberOfPoints(), 2903 ); + ITK_TEST_EXPECT_EQUAL(polyData->GetNumberOfPoints(), 2903); PolyDataType::PointsContainer::ConstPointer points = polyData->GetPoints(); - ITK_TEST_EXPECT_TRUE( itk::Math::FloatAlmostEqual< float >( points->GetElement( 0 )[0], 3.71636, 10, 1e-4 ) ); - ITK_TEST_EXPECT_TRUE( itk::Math::FloatAlmostEqual< float >( points->GetElement( 0 )[1], 2.34339, 10, 1e-4 ) ); - ITK_TEST_EXPECT_TRUE( itk::Math::FloatAlmostEqual< float >( points->GetElement( 0 )[2], 0.0, 10, 1e-4 ) ); - - ITK_TEST_EXPECT_EQUAL( polyData->GetVertices()->size(), 0 ); - ITK_TEST_EXPECT_EQUAL( polyData->GetLines()->size(), 0 ); - - ITK_TEST_EXPECT_EQUAL( polyData->GetPolygons()->size(), 15593 ); - ITK_TEST_EXPECT_EQUAL( polyData->GetPolygons()->GetElement( 0 ), 4 ); - ITK_TEST_EXPECT_EQUAL( polyData->GetPolygons()->GetElement( 1 ), 250 ); - ITK_TEST_EXPECT_EQUAL( polyData->GetPolygons()->GetElement( 2 ), 251 ); - ITK_TEST_EXPECT_EQUAL( polyData->GetPolygons()->GetElement( 3 ), 210 ); - ITK_TEST_EXPECT_EQUAL( polyData->GetPolygons()->GetElement( 4 ), 252 ); - ITK_TEST_EXPECT_EQUAL( polyData->GetPolygons()->GetElement( 5 ), 4 ); - ITK_TEST_EXPECT_EQUAL( polyData->GetPolygons()->GetElement( 6 ), 252 ); + ITK_TEST_EXPECT_TRUE(itk::Math::FloatAlmostEqual(points->GetElement(0)[0], 3.71636, 10, 1e-4)); + ITK_TEST_EXPECT_TRUE(itk::Math::FloatAlmostEqual(points->GetElement(0)[1], 2.34339, 10, 1e-4)); + ITK_TEST_EXPECT_TRUE(itk::Math::FloatAlmostEqual(points->GetElement(0)[2], 0.0, 10, 1e-4)); + + ITK_TEST_EXPECT_EQUAL(polyData->GetVertices()->size(), 0); + ITK_TEST_EXPECT_EQUAL(polyData->GetLines()->size(), 0); + + ITK_TEST_EXPECT_EQUAL(polyData->GetPolygons()->size(), 15593); + ITK_TEST_EXPECT_EQUAL(polyData->GetPolygons()->GetElement(0), 4); + ITK_TEST_EXPECT_EQUAL(polyData->GetPolygons()->GetElement(1), 250); + ITK_TEST_EXPECT_EQUAL(polyData->GetPolygons()->GetElement(2), 251); + ITK_TEST_EXPECT_EQUAL(polyData->GetPolygons()->GetElement(3), 210); + ITK_TEST_EXPECT_EQUAL(polyData->GetPolygons()->GetElement(4), 252); + ITK_TEST_EXPECT_EQUAL(polyData->GetPolygons()->GetElement(5), 4); + ITK_TEST_EXPECT_EQUAL(polyData->GetPolygons()->GetElement(6), 252); using PolyDataToMeshFilterType = itk::PolyDataToMeshFilter; auto polyDataToMeshFilter = PolyDataToMeshFilterType::New(); - polyDataToMeshFilter->SetInput( polyData ); + polyDataToMeshFilter->SetInput(polyData); using MeshWriterType = itk::MeshFileWriter; auto meshWriter = MeshWriterType::New(); - meshWriter->SetFileName( outputPolyDataFileName ); - meshWriter->SetInput( polyDataToMeshFilter->GetOutput() ); - ITK_TRY_EXPECT_NO_EXCEPTION( meshWriter->Update() ); + meshWriter->SetFileName(outputPolyDataFileName); + meshWriter->SetInput(polyDataToMeshFilter->GetOutput()); + ITK_TRY_EXPECT_NO_EXCEPTION(meshWriter->Update()); return EXIT_SUCCESS; } diff --git a/test/itkPolyDataTest.cxx b/test/itkPolyDataTest.cxx index 3e21ca9..08da506 100644 --- a/test/itkPolyDataTest.cxx +++ b/test/itkPolyDataTest.cxx @@ -19,12 +19,13 @@ #include "itkTestingMacros.h" -int itkPolyDataTest( int, char *[] ) +int +itkPolyDataTest(int, char *[]) { using PixelType = double; - using PolyDataType = itk::PolyData< PixelType >; - PolyDataType::Pointer polyData = PolyDataType::New(); + using PolyDataType = itk::PolyData; + PolyDataType::Pointer polyData = PolyDataType::New(); constexpr unsigned int PointDimension = PolyDataType::PointDimension; polyData->Initialize(); @@ -36,99 +37,99 @@ int itkPolyDataTest( int, char *[] ) point[0] = 1.0; point[1] = 3.0; point[2] = 5.0; - pointsContainer->InsertElement( 0, point ); + pointsContainer->InsertElement(0, point); point[0] = 2.0; point[1] = 4.0; point[2] = 6.0; - pointsContainer->InsertElement( 1, point ); - polyData->SetPoints( pointsContainer ); + pointsContainer->InsertElement(1, point); + polyData->SetPoints(pointsContainer); - for( unsigned int dim = 0; dim < PointDimension; ++dim ) - { - ITK_TEST_SET_GET_VALUE( point[dim], polyData->GetPoint( 1 )[dim] ); - } + for (unsigned int dim = 0; dim < PointDimension; ++dim) + { + ITK_TEST_SET_GET_VALUE(point[dim], polyData->GetPoint(1)[dim]); + } point[0] = 3.0; point[1] = 5.0; point[2] = 7.0; - polyData->SetPoint( 2, point ); - for( unsigned int dim = 0; dim < PointDimension; ++dim ) - { - ITK_TEST_SET_GET_VALUE( point[dim], polyData->GetPoint( 2 )[dim] ); - } - polyData->SetPoint( 1, point ); - for( unsigned int dim = 0; dim < PointDimension; ++dim ) - { - ITK_TEST_SET_GET_VALUE( point[dim], polyData->GetPoint( 1 )[dim] ); - } + polyData->SetPoint(2, point); + for (unsigned int dim = 0; dim < PointDimension; ++dim) + { + ITK_TEST_SET_GET_VALUE(point[dim], polyData->GetPoint(2)[dim]); + } + polyData->SetPoint(1, point); + for (unsigned int dim = 0; dim < PointDimension; ++dim) + { + ITK_TEST_SET_GET_VALUE(point[dim], polyData->GetPoint(1)[dim]); + } PolyDataType::CellsContainer::Pointer vertices = PolyDataType::CellsContainer::New(); - vertices->InsertElement( 0, 1 ); - vertices->InsertElement( 1, 4 ); - vertices->InsertElement( 2, 1 ); - vertices->InsertElement( 3, 7 ); - polyData->SetVertices( vertices ); - ITK_TEST_SET_GET_VALUE( vertices.GetPointer(), polyData->GetVertices() ); + vertices->InsertElement(0, 1); + vertices->InsertElement(1, 4); + vertices->InsertElement(2, 1); + vertices->InsertElement(3, 7); + polyData->SetVertices(vertices); + ITK_TEST_SET_GET_VALUE(vertices.GetPointer(), polyData->GetVertices()); PolyDataType::CellsContainer::Pointer lines = PolyDataType::CellsContainer::New(); - lines->InsertElement( 0, 2 ); - lines->InsertElement( 1, 4 ); - lines->InsertElement( 2, 5 ); - lines->InsertElement( 3, 2 ); - lines->InsertElement( 4, 7 ); - lines->InsertElement( 5, 8 ); - polyData->SetLines( lines ); - ITK_TEST_SET_GET_VALUE( lines.GetPointer(), polyData->GetLines() ); + lines->InsertElement(0, 2); + lines->InsertElement(1, 4); + lines->InsertElement(2, 5); + lines->InsertElement(3, 2); + lines->InsertElement(4, 7); + lines->InsertElement(5, 8); + polyData->SetLines(lines); + ITK_TEST_SET_GET_VALUE(lines.GetPointer(), polyData->GetLines()); PolyDataType::CellsContainer::Pointer polygons = PolyDataType::CellsContainer::New(); - polygons->InsertElement( 0, 4 ); - polygons->InsertElement( 1, 4 ); - polygons->InsertElement( 2, 5 ); - polygons->InsertElement( 3, 6 ); - polygons->InsertElement( 4, 7 ); - polygons->InsertElement( 5, 4 ); - polygons->InsertElement( 6, 8 ); - polygons->InsertElement( 7, 9 ); - polygons->InsertElement( 8, 10 ); - polygons->InsertElement( 9, 11 ); - polyData->SetPolygons( polygons ); - ITK_TEST_SET_GET_VALUE( polygons.GetPointer(), polyData->GetPolygons() ); + polygons->InsertElement(0, 4); + polygons->InsertElement(1, 4); + polygons->InsertElement(2, 5); + polygons->InsertElement(3, 6); + polygons->InsertElement(4, 7); + polygons->InsertElement(5, 4); + polygons->InsertElement(6, 8); + polygons->InsertElement(7, 9); + polygons->InsertElement(8, 10); + polygons->InsertElement(9, 11); + polyData->SetPolygons(polygons); + ITK_TEST_SET_GET_VALUE(polygons.GetPointer(), polyData->GetPolygons()); PolyDataType::CellsContainer::Pointer triangleStrips = PolyDataType::CellsContainer::New(); - triangleStrips->InsertElement( 0, 3 ); - triangleStrips->InsertElement( 1, 4 ); - triangleStrips->InsertElement( 2, 5 ); - triangleStrips->InsertElement( 3, 6 ); - triangleStrips->InsertElement( 4, 3 ); - triangleStrips->InsertElement( 5, 8 ); - triangleStrips->InsertElement( 6, 9 ); - triangleStrips->InsertElement( 7, 10 ); - polyData->SetTriangleStrips( triangleStrips ); - ITK_TEST_SET_GET_VALUE( triangleStrips.GetPointer(), polyData->GetTriangleStrips() ); + triangleStrips->InsertElement(0, 3); + triangleStrips->InsertElement(1, 4); + triangleStrips->InsertElement(2, 5); + triangleStrips->InsertElement(3, 6); + triangleStrips->InsertElement(4, 3); + triangleStrips->InsertElement(5, 8); + triangleStrips->InsertElement(6, 9); + triangleStrips->InsertElement(7, 10); + polyData->SetTriangleStrips(triangleStrips); + ITK_TEST_SET_GET_VALUE(triangleStrips.GetPointer(), polyData->GetTriangleStrips()); PolyDataType::PointDataContainer::Pointer pointDataContainer = PolyDataType::PointDataContainer::New(); - pointDataContainer->InsertElement( 0, 2.0 ); - pointDataContainer->InsertElement( 1, 7.0 ); - polyData->SetPointData( pointDataContainer ); + pointDataContainer->InsertElement(0, 2.0); + pointDataContainer->InsertElement(1, 7.0); + polyData->SetPointData(pointDataContainer); double pointData; - polyData->GetPointData( 1, &pointData ); - ITK_TEST_SET_GET_VALUE( 7.0, pointData ); - polyData->SetPointData( 2, 9.9 ); - polyData->GetPointData( 2, &pointData ); - ITK_TEST_SET_GET_VALUE( 9.9, pointData ); + polyData->GetPointData(1, &pointData); + ITK_TEST_SET_GET_VALUE(7.0, pointData); + polyData->SetPointData(2, 9.9); + polyData->GetPointData(2, &pointData); + ITK_TEST_SET_GET_VALUE(9.9, pointData); PolyDataType::CellDataContainer::Pointer cellDataContainer = PolyDataType::CellDataContainer::New(); - cellDataContainer->InsertElement( 0, 2.0 ); - cellDataContainer->InsertElement( 1, 7.0 ); - polyData->SetCellData( cellDataContainer ); + cellDataContainer->InsertElement(0, 2.0); + cellDataContainer->InsertElement(1, 7.0); + polyData->SetCellData(cellDataContainer); double cellData; - polyData->GetCellData( 1, &cellData ); - ITK_TEST_SET_GET_VALUE( 7.0, cellData ); - polyData->SetCellData( 2, 9.9 ); - polyData->GetCellData( 2, &cellData ); - ITK_TEST_SET_GET_VALUE( 9.9, cellData ); + polyData->GetCellData(1, &cellData); + ITK_TEST_SET_GET_VALUE(7.0, cellData); + polyData->SetCellData(2, 9.9); + polyData->GetCellData(2, &cellData); + ITK_TEST_SET_GET_VALUE(9.9, cellData); - ITK_EXERCISE_BASIC_OBJECT_METHODS( polyData, PolyData, DataObject ); + ITK_EXERCISE_BASIC_OBJECT_METHODS(polyData, PolyData, DataObject); return EXIT_SUCCESS; } diff --git a/wasm/mesh-to-poly-data.cxx b/wasm/mesh-to-poly-data.cxx index 4ddf8d5..f581e68 100644 --- a/wasm/mesh-to-poly-data.cxx +++ b/wasm/mesh-to-poly-data.cxx @@ -25,11 +25,12 @@ #include "itkMeshToPolyDataFilter.h" #include "itkVector.h" -template +template class PipelineFunctor { public: - int operator()(itk::wasm::Pipeline & pipeline) + int + operator()(itk::wasm::Pipeline & pipeline) { using MeshType = TMesh; @@ -56,21 +57,20 @@ class PipelineFunctor } }; -int main (int argc, char * argv[]) +int +main(int argc, char * argv[]) { itk::wasm::Pipeline pipeline("mesh-to-poly-data", "Convert an itk::Mesh to an itk::PolyData", argc, argv); itk::WasmMeshIOFactory::RegisterOneFactory(); return itk::wasm::SupportInputMeshTypes, - itk::Vector, - itk::VariableLengthVector, - itk::VariableLengthVector - > - ::Dimensions<2U,3U>("mesh", pipeline); + uint8_t, + int8_t, + float, + double, + itk::Vector, + itk::Vector, + itk::VariableLengthVector, + itk::VariableLengthVector>::Dimensions<2U, 3U>("mesh", pipeline); } diff --git a/wasm/poly-data-to-mesh.cxx b/wasm/poly-data-to-mesh.cxx index 1d8364f..1783497 100644 --- a/wasm/poly-data-to-mesh.cxx +++ b/wasm/poly-data-to-mesh.cxx @@ -24,11 +24,12 @@ #include "itkWasmMeshIOFactory.h" #include "itkPolyDataToMeshFilter.h" -template +template class PipelineFunctor { public: - int operator()(itk::wasm::Pipeline & pipeline) + int + operator()(itk::wasm::Pipeline & pipeline) { using PolyDataType = TPolyData; @@ -55,12 +56,13 @@ class PipelineFunctor } }; -int main (int argc, char * argv[]) +int +main(int argc, char * argv[]) { itk::wasm::Pipeline pipeline("poly-data-to-mesh", "Convert an itk::PolyData to an itk::Mesh", argc, argv); itk::WasmMeshIOFactory::RegisterOneFactory(); - return itk::wasm::SupportInputPolyDataTypes - ::PixelTypes("poly-data", pipeline); + return itk::wasm::SupportInputPolyDataTypes::PixelTypes("poly-data", + pipeline); } From 8aed3c7f010f47de0e51689b0bde248501f96063 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 9 Mar 2025 09:41:49 -0500 Subject: [PATCH 5/7] ENH: Use latest actions, do not pin to latest version The convention of only specifying the MAJOR version is the indicator that the latest version in that series should be used. By not specifying the MINOR and PATCH, the exact versions is not pinned, but the latest in that series is chosen. (i.e. the v5 tag is updated every time a new MINOR or PATCH tag is generated). This allows benefiting from minor patch fixes without needing to update workflows. --- .github/workflows/documentation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 294b578..3921118 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -61,7 +61,7 @@ jobs: rsync -a wasm/typescript/demo-app/ docs/ts/app/ - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.11' From 597c78075403d24df0d7ab3a2e559e355cde20c2 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 9 Mar 2025 10:29:13 -0500 Subject: [PATCH 6/7] STYLE: Fix KWStyleError itkMeshToPolyDataFilter.h:34: error: Template definition (C) doesn't match regular itkMeshToPolyDataFilter.h:37: error: Template definition (C) doesn't match regular --- include/itkMeshToPolyDataFilter.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/itkMeshToPolyDataFilter.h b/include/itkMeshToPolyDataFilter.h index ccf2ce4..b77e56f 100644 --- a/include/itkMeshToPolyDataFilter.h +++ b/include/itkMeshToPolyDataFilter.h @@ -26,19 +26,19 @@ namespace itk { -template +template class HasCellTraits { typedef char Yes[1]; typedef char No[2]; - template + template static Yes & - test(typename C::CellTraits *); // selected if C is a class type - template + test(typename CellType::CellTraits *); // selected if CellType is a class type + template static No & test(...); // selected otherwise public: - static bool const value = sizeof(test(0)) == sizeof(Yes); + static bool const value = sizeof(test(0)) == sizeof(Yes); }; /** \class MeshToPolyDataFilter From 9c0209b571f1d4ee5bafa4dd172bff5679dfe016 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 9 Mar 2025 10:49:04 -0500 Subject: [PATCH 7/7] ENH: Use tag v5.4.2 for the build packages tags Set the default build package tags to v5.4.2 for capturing the ITKRemoteModuleBuildTestPackageAction shared scripts. This pulls the default configuration items needed to build against ITK version v5.4.2. --- .github/workflows/build-test-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test-package.yml b/.github/workflows/build-test-package.yml index dae7153..1e0bda2 100644 --- a/.github/workflows/build-test-package.yml +++ b/.github/workflows/build-test-package.yml @@ -4,10 +4,10 @@ on: [push,pull_request] jobs: cxx-build-workflow: - uses: InsightSoftwareConsortium/ITKRemoteModuleBuildTestPackageAction/.github/workflows/build-test-cxx.yml@main + uses: InsightSoftwareConsortium/ITKRemoteModuleBuildTestPackageAction/.github/workflows/build-test-cxx.yml@v5.4.2 python-build-workflow: - uses: InsightSoftwareConsortium/ITKRemoteModuleBuildTestPackageAction/.github/workflows/build-test-package-python.yml@main + uses: InsightSoftwareConsortium/ITKRemoteModuleBuildTestPackageAction/.github/workflows/build-test-package-python.yml@v5.4.2 with: test-notebooks: false secrets: