From be110b70da06248198464d93ca36d6d8af6620a8 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sat, 25 Jan 2025 14:08:57 -0600 Subject: [PATCH] STYLE: Syncronize with ITK clang-format 19 --- .clang-format | 251 ++++++++++++++++++++++++++++++++------- include/FibHeap.h | 128 ++++++++++++-------- include/itkFastGrowCut.h | 6 +- 3 files changed, 293 insertions(+), 92 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/include/FibHeap.h b/include/FibHeap.h index b0e6838..b925d37 100644 --- a/include/FibHeap.h +++ b/include/FibHeap.h @@ -19,13 +19,13 @@ // exclude from VTK wrapping #ifndef __VTK_WRAP__ -#ifndef FIBHEAP_H -#define FIBHEAP_H +# ifndef FIBHEAP_H +# define FIBHEAP_H -#include -#include +# include +# include -#include "GrowCutExport.h" +# include "GrowCutExport.h" // type for cost function - single precision is enough typedef float NodeKeyValueType; @@ -52,7 +52,7 @@ typedef unsigned int NodeIndexType; class GrowCut_EXPORT FibHeapNode { public: - static const NodeIndexType NullNodeIndex; + static const NodeIndexType NullNodeIndex; static const NodeKeyValueType NegativeInfinity; inline FibHeapNode() @@ -61,44 +61,60 @@ class GrowCut_EXPORT FibHeapNode , m_Parent(NullNodeIndex) , m_Child(NullNodeIndex) , m_Index(NullNodeIndex) - { - } + {} ~FibHeapNode() = default; /// Index stores this node's location in the node array - inline NodeIndexType GetIndexValue() { return m_Index; } - inline void SetIndexValue(NodeIndexType indexValue) { m_Index = indexValue; } + inline NodeIndexType + GetIndexValue() + { + return m_Index; + } + inline void + SetIndexValue(NodeIndexType indexValue) + { + m_Index = indexValue; + } /// Get key value. /// Key value can be set using operator=. - inline NodeKeyValueType GetKeyValue() { return m_Key; } + inline NodeKeyValueType + GetKeyValue() + { + return m_Key; + } /// Set key value (that the nodes are sorted based on) - inline void operator =(NodeKeyValueType newKeyVal) + inline void + operator=(NodeKeyValueType newKeyVal) { m_Key = newKeyVal; } /// Set key value from another node - inline void operator =(FibHeapNode& RHS) + inline void + operator=(FibHeapNode & RHS) { m_Key = RHS.m_Key; } /// Compare key value - inline bool operator ==(FibHeapNode& RHS) + inline bool + operator==(FibHeapNode & RHS) { return m_Key == RHS.m_Key; } /// Compare key value - inline bool operator <(FibHeapNode& RHS) + inline bool + operator<(FibHeapNode & RHS) { return m_Key < RHS.m_Key; } - void Print() + void + Print() { std::cout << m_Key; } @@ -107,11 +123,11 @@ class GrowCut_EXPORT FibHeapNode NodeIndexType m_Right; NodeIndexType m_Parent; NodeIndexType m_Child; - short m_Degree{0}; - bool m_Mark{false}; + short m_Degree{ 0 }; + bool m_Mark{ false }; - NodeKeyValueType m_Key{0}; - NodeIndexType m_Index; + NodeKeyValueType m_Key{ 0 }; + NodeIndexType m_Index; }; // .NAME FibHeap - Fibonacci Heap Class @@ -141,7 +157,8 @@ class GrowCut_EXPORT FibHeap /// instead of a 64-bit pointer. Since each node stores 4 pointer/index, this saves /// 16 bytes per node, which is very significant when e.g., one node corresponds to /// an image voxel and the image contains hundreds of millions of voxels. - void SetHeapNodes(FibHeapNode* heapNodes); + void + SetHeapNodes(FibHeapNode * heapNodes); /// Insert() - O(1) actual; O(2) amortized /// @@ -152,48 +169,58 @@ class GrowCut_EXPORT FibHeap /// /// The child pointer is deliberately not set to nullptr because Insert() /// is also used internally to help put whole trees onto the root list. - void Insert(FibHeapNode *NewNode); + void + Insert(FibHeapNode * NewNode); /// Union() - O(1) actual; O(1) amortized - void Union(FibHeap *OtherHeap); + void + Union(FibHeap * OtherHeap); /// Minimum - O(1) actual; O(1) amortized - inline FibHeapNode *Minimum() + inline FibHeapNode * + Minimum() { return m_MinRoot; } /// ExtractMin() - O(n) worst-case actual; O(lg n) amortized - FibHeapNode *ExtractMin(); + FibHeapNode * + ExtractMin(); /// DecreaseKey() - O(lg n) actual; O(1) amortized /// /// The O(lg n) actual cost stems from the fact that the depth, and /// therefore the number of ancestor parents, is bounded by O(lg n). - int DecreaseKey(FibHeapNode* theNode, NodeKeyValueType keyValue); + int + DecreaseKey(FibHeapNode * theNode, NodeKeyValueType keyValue); /// Delete() - O(lg n) amortized; ExtractMin() dominates /// /// Notice that if we don't own the heap nodes, then we clear the /// m_NegInfinityFlag on the deleted node. Presumably, the programmer /// will be reusing the node. - int Delete(FibHeapNode *theNode); + int + Delete(FibHeapNode * theNode); - inline bool IsEmpty() + inline bool + IsEmpty() { return (m_MinRoot == nullptr); } // Extra utility functions - long GetNumNodes() + long + GetNumNodes() { return m_NumNodes; }; - long GetNumTrees() + long + GetNumTrees() { return m_NumTrees; }; - long GetNumMarkedNodes() + long + GetNumMarkedNodes() { return m_NumMarkedNodes; }; @@ -203,13 +230,15 @@ class GrowCut_EXPORT FibHeap /// Used internally for debugging purposes. The function prints the key /// value for each node along the root list, then it calls itself on each /// child list. - void Print(FibHeapNode *Tree = nullptr, FibHeapNode *theParent=nullptr); + void + Print(FibHeapNode * Tree = nullptr, FibHeapNode * theParent = nullptr); private: // Internal functions that help to implement the Standard Operations - inline void Exchange(FibHeapNode* &N1, FibHeapNode* &N2) + inline void + Exchange(FibHeapNode *& N1, FibHeapNode *& N2) { - FibHeapNode *Temp; + FibHeapNode * Temp; Temp = N1; N1 = N2; N2 = Temp; @@ -230,14 +259,18 @@ class GrowCut_EXPORT FibHeap // the first ExtractMin() is covered by the higher amortized cost of // Insert(), which is the real governing factor in how costly the first // ExtractMin() will be. - void Consolidate(); + void + Consolidate(); // The node y is removed from the root list and becomes a subtree of node x. - void Link(FibHeapNode *, FibHeapNode *); - void AddToRootList(FibHeapNode *); + void + Link(FibHeapNode *, FibHeapNode *); + void + AddToRootList(FibHeapNode *); // Remove node x from the child list of its parent node y - void Cut(FibHeapNode *, FibHeapNode *); + void + Cut(FibHeapNode *, FibHeapNode *); // Cuts each node in parent list, putting successive ancestor nodes on the // root list until we either arrive at the root list or until we find an @@ -246,21 +279,22 @@ class GrowCut_EXPORT FibHeap // second subtree is lost later during another cascading cut, then we move // the node to the root list so that it can be re-balanced on the next // consolidate. - void CascadingCut(FibHeapNode *); + void + CascadingCut(FibHeapNode *); - inline FibHeapNode* HeapNodeFromIndex(NodeIndexType index) + inline FibHeapNode * + HeapNodeFromIndex(NodeIndexType index) { return index == FibHeapNode::NullNodeIndex ? nullptr : m_HeapNodes + index; } - FibHeapNode* m_MinRoot; - long m_NumNodes; - long m_NumTrees; - long m_NumMarkedNodes; - FibHeapNode* m_HeapNodes; // array containing all the heap nodes - + FibHeapNode * m_MinRoot; + long m_NumNodes; + long m_NumTrees; + long m_NumMarkedNodes; + FibHeapNode * m_HeapNodes; // array containing all the heap nodes }; -#endif /* FIBHEAP_H */ +# endif /* FIBHEAP_H */ #endif //__VTK_WRAP__ diff --git a/include/itkFastGrowCut.h b/include/itkFastGrowCut.h index e23b77d..7b1123b 100644 --- a/include/itkFastGrowCut.h +++ b/include/itkFastGrowCut.h @@ -69,7 +69,7 @@ class ITK_TEMPLATE_EXPORT FastGrowCut : public ImageToImageFilter; + // using SeedsContainerType = std::vector; - //using InputRealType = typename NumericTraits::RealType; + // using InputRealType = typename NumericTraits::RealType; /** Reset to initial state. This forces full recomputation of the result label volume.