Skip to content

Commit 67f7ea3

Browse files
committed
ENH: Add .gitattributes to allow running ITK clang-formatting scripts
``` git filter-branch -f \ --tree-filter "~/ITK/Utilities/Maintenance/clang-format.bash --clang-format ~/Dashboard/src/ITK-clang11/clang-format-Linux --tracked" \ master.. ```
1 parent 38faf6e commit 67f7ea3

25 files changed

+1556
-1425
lines changed

.clang-format

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
## This config file is only relevant for clang-format version 8.0.0
2+
##
3+
## Examples of each format style can be found on the in the clang-format documentation
4+
## See: https://clang.llvm.org/docs/ClangFormatStyleOptions.html for details of each option
5+
##
6+
## The clang-format binaries can be downloaded as part of the clang binary distributions
7+
## from http://releases.llvm.org/download.html
8+
##
9+
## Use the script Utilities/Maintenance/clang-format.bash to faciliate
10+
## maintaining a consistent code style.
11+
##
12+
## EXAMPLE apply code style enforcement before commit:
13+
# Utilities/Maintenance/clang-format.bash --clang ${PATH_TO_CLANG_FORMAT_8.0.0} --modified
14+
## EXAMPLE apply code style enforcement after commit:
15+
# Utilities/Maintenance/clang-format.bash --clang ${PATH_TO_CLANG_FORMAT_8.0.0} --last
16+
---
17+
# This configuration requires clang-format version 8.0.0 exactly.
18+
BasedOnStyle: Mozilla
19+
Language: Cpp
20+
AccessModifierOffset: -2
21+
AlignAfterOpenBracket: Align
22+
AlignConsecutiveAssignments: false
23+
AlignConsecutiveDeclarations: true
24+
AlignEscapedNewlines: Right
25+
AlignOperands: true
26+
AlignTrailingComments: true
27+
# clang 9.0 AllowAllArgumentsOnNextLine: true
28+
# clang 9.0 AllowAllConstructorInitializersOnNextLine: true
29+
AllowAllParametersOfDeclarationOnNextLine: false
30+
AllowShortBlocksOnASingleLine: false
31+
AllowShortCaseLabelsOnASingleLine: false
32+
AllowShortFunctionsOnASingleLine: Inline
33+
# clang 9.0 AllowShortLambdasOnASingleLine: All
34+
# clang 9.0 features AllowShortIfStatementsOnASingleLine: Never
35+
AllowShortIfStatementsOnASingleLine: false
36+
AllowShortLoopsOnASingleLine: false
37+
AlwaysBreakAfterDefinitionReturnType: None
38+
AlwaysBreakAfterReturnType: All
39+
AlwaysBreakBeforeMultilineStrings: false
40+
AlwaysBreakTemplateDeclarations: Yes
41+
BinPackArguments: false
42+
BinPackParameters: false
43+
BreakBeforeBraces: Custom
44+
BraceWrapping:
45+
# clang 9.0 feature AfterCaseLabel: false
46+
AfterClass: true
47+
AfterControlStatement: true
48+
AfterEnum: true
49+
AfterFunction: true
50+
AfterNamespace: true
51+
AfterObjCDeclaration: true
52+
AfterStruct: true
53+
AfterUnion: true
54+
AfterExternBlock: true
55+
BeforeCatch: true
56+
BeforeElse: true
57+
## This is the big change from historical ITK formatting!
58+
# Historically ITK used a style similar to https://en.wikipedia.org/wiki/Indentation_style#Whitesmiths_style
59+
# with indented braces, and not indented code. This style is very difficult to automatically
60+
# maintain with code beautification tools. Not indenting braces is more common among
61+
# formatting tools.
62+
IndentBraces: false
63+
SplitEmptyFunction: false
64+
SplitEmptyRecord: false
65+
SplitEmptyNamespace: false
66+
BreakBeforeBinaryOperators: None
67+
#clang 6.0 BreakBeforeInheritanceComma: true
68+
BreakInheritanceList: BeforeComma
69+
BreakBeforeTernaryOperators: true
70+
#clang 6.0 BreakConstructorInitializersBeforeComma: true
71+
BreakConstructorInitializers: BeforeComma
72+
BreakAfterJavaFieldAnnotations: false
73+
BreakStringLiterals: true
74+
## The following line allows larger lines in non-documentation code
75+
ColumnLimit: 120
76+
CommentPragmas: '^ IWYU pragma:'
77+
CompactNamespaces: false
78+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
79+
ConstructorInitializerIndentWidth: 2
80+
ContinuationIndentWidth: 2
81+
Cpp11BracedListStyle: false
82+
DerivePointerAlignment: false
83+
DisableFormat: false
84+
ExperimentalAutoDetectBinPacking: false
85+
FixNamespaceComments: true
86+
ForEachMacros:
87+
- foreach
88+
- Q_FOREACH
89+
- BOOST_FOREACH
90+
IncludeBlocks: Preserve
91+
IncludeCategories:
92+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
93+
Priority: 2
94+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
95+
Priority: 3
96+
- Regex: '.*'
97+
Priority: 1
98+
IncludeIsMainRegex: '(Test)?$'
99+
IndentCaseLabels: true
100+
IndentPPDirectives: AfterHash
101+
IndentWidth: 2
102+
IndentWrappedFunctionNames: false
103+
JavaScriptQuotes: Leave
104+
JavaScriptWrapImports: true
105+
KeepEmptyLinesAtTheStartOfBlocks: true
106+
MacroBlockBegin: ''
107+
MacroBlockEnd: ''
108+
MaxEmptyLinesToKeep: 2
109+
NamespaceIndentation: None
110+
ObjCBinPackProtocolList: Auto
111+
ObjCBlockIndentWidth: 2
112+
ObjCSpaceAfterProperty: true
113+
ObjCSpaceBeforeProtocolList: false
114+
PenaltyBreakAssignment: 2
115+
PenaltyBreakBeforeFirstCallParameter: 19
116+
PenaltyBreakComment: 300
117+
## The following line allows larger lines in non-documentation code
118+
PenaltyBreakFirstLessLess: 120
119+
PenaltyBreakString: 1000
120+
PenaltyBreakTemplateDeclaration: 10
121+
PenaltyExcessCharacter: 1000000
122+
PenaltyReturnTypeOnItsOwnLine: 200
123+
PointerAlignment: Middle
124+
ReflowComments: true
125+
# We may want to sort the includes as a separate pass
126+
SortIncludes: false
127+
# We may want to revisit this later
128+
SortUsingDeclarations: false
129+
SpaceAfterCStyleCast: false
130+
# SpaceAfterLogicalNot: false
131+
SpaceAfterTemplateKeyword: true
132+
SpaceBeforeAssignmentOperators: true
133+
SpaceBeforeCpp11BracedList: false
134+
SpaceBeforeCtorInitializerColon: true
135+
SpaceBeforeInheritanceColon: true
136+
SpaceBeforeParens: ControlStatements
137+
SpaceBeforeRangeBasedForLoopColon: true
138+
SpaceInEmptyParentheses: false
139+
SpacesBeforeTrailingComments: 1
140+
SpacesInAngles: false
141+
SpacesInContainerLiterals: false
142+
SpacesInCStyleCastParentheses: false
143+
SpacesInParentheses: false
144+
SpacesInSquareBrackets: false
145+
Standard: Cpp11
146+
StatementMacros:
147+
- Q_UNUSED
148+
- QT_REQUIRE_VERSION
149+
TabWidth: 2
150+
UseTab: Never
151+
...

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Custom attribute to mark sources as using our C++/C code style.
2+
[attr]our-c-style whitespace=tab-in-indent,no-lf-at-eof hooks.style=KWStyle,clangformat
3+
4+
*.c our-c-style
5+
*.h our-c-style
6+
*.cxx our-c-style
7+
*.hxx our-c-style
8+
*.txx our-c-style
9+
*.txt whitespace=tab-in-indent,no-lf-at-eof
10+
*.cmake whitespace=tab-in-indent,no-lf-at-eof
11+
12+
# ExternalData content links must have LF newlines
13+
*.md5 crlf=input
14+
*.sha512 crlf=input

example/computeGLCMFeatures.cxx

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,53 @@
66
#include "itkImageFileWriter.h"
77
#include "itkNeighborhood.h"
88

9-
int main(int argc, char * argv[])
9+
int
10+
main(int argc, char * argv[])
1011
{
11-
if( argc != 8 )
12-
{
13-
std::cerr << "Usage: "<< std::endl;
12+
if (argc != 8)
13+
{
14+
std::cerr << "Usage: " << std::endl;
1415
std::cerr << argv[0];
1516
std::cerr << " <InputFilePath> <MaskFilePath> <OutputFilePath> ";
1617
std::cerr << " <NumberOfBinsPerAxis> <PixelValueMin> ";
1718
std::cerr << " <PixelValueMax> <NeighborhoodRadius> ";
1819
std::cerr << std::endl;
1920
return EXIT_FAILURE;
20-
}
21-
22-
// Setup types
23-
using InputImageType = itk::Image< int, 3 >;
24-
using OutputImageType = itk::Image< itk::Vector< float, 10 > , 3 >;
25-
using readerType = itk::ImageFileReader< InputImageType >;
26-
using NeighborhoodType = itk::Neighborhood<typename InputImageType::PixelType,
27-
InputImageType::ImageDimension>;
28-
NeighborhoodType neighborhood;
29-
30-
// Create and setup a reader
31-
readerType::Pointer reader = readerType::New();
32-
reader->SetFileName( argv[1] );
33-
34-
// Create and setup a maskReader
35-
readerType::Pointer maskReader = readerType::New();
36-
maskReader->SetFileName( argv[2] );
37-
38-
// Apply the filter
39-
using FilterType = itk::Statistics::CoocurrenceTextureFeaturesImageFilter
40-
< InputImageType, OutputImageType >;
41-
FilterType::Pointer filter = FilterType::New();
42-
filter->SetInput(reader->GetOutput());
43-
filter->SetMaskImage(maskReader->GetOutput());
44-
filter->SetNumberOfBinsPerAxis(std::stoi(argv[4]));
45-
filter->SetHistogramMinimum(std::stod(argv[5]));
46-
filter->SetHistogramMaximum(std::stod(argv[6]));
47-
neighborhood.SetRadius( std::stoi(argv[7]) );
48-
filter->SetNeighborhoodRadius(neighborhood.GetRadius());
49-
50-
// Create and setup a writter
51-
using WriterType = itk::ImageFileWriter< OutputImageType >;
52-
WriterType::Pointer writer = WriterType::New();
53-
std::string outputFilename = argv[3];
54-
writer->SetFileName(outputFilename.c_str());
55-
writer->SetInput(filter->GetOutput());
56-
writer->Update();
21+
}
22+
23+
// Setup types
24+
using InputImageType = itk::Image<int, 3>;
25+
using OutputImageType = itk::Image<itk::Vector<float, 10>, 3>;
26+
using readerType = itk::ImageFileReader<InputImageType>;
27+
using NeighborhoodType = itk::Neighborhood<typename InputImageType::PixelType, InputImageType::ImageDimension>;
28+
NeighborhoodType neighborhood;
29+
30+
// Create and setup a reader
31+
readerType::Pointer reader = readerType::New();
32+
reader->SetFileName(argv[1]);
33+
34+
// Create and setup a maskReader
35+
readerType::Pointer maskReader = readerType::New();
36+
maskReader->SetFileName(argv[2]);
37+
38+
// Apply the filter
39+
using FilterType = itk::Statistics::CoocurrenceTextureFeaturesImageFilter<InputImageType, OutputImageType>;
40+
FilterType::Pointer filter = FilterType::New();
41+
filter->SetInput(reader->GetOutput());
42+
filter->SetMaskImage(maskReader->GetOutput());
43+
filter->SetNumberOfBinsPerAxis(std::stoi(argv[4]));
44+
filter->SetHistogramMinimum(std::stod(argv[5]));
45+
filter->SetHistogramMaximum(std::stod(argv[6]));
46+
neighborhood.SetRadius(std::stoi(argv[7]));
47+
filter->SetNeighborhoodRadius(neighborhood.GetRadius());
48+
49+
// Create and setup a writter
50+
using WriterType = itk::ImageFileWriter<OutputImageType>;
51+
WriterType::Pointer writer = WriterType::New();
52+
std::string outputFilename = argv[3];
53+
writer->SetFileName(outputFilename.c_str());
54+
writer->SetInput(filter->GetOutput());
55+
writer->Update();
5756

5857
return EXIT_SUCCESS;
5958
}

example/computeGLRLMFeatures.cxx

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,56 @@
66
#include "itkImageFileWriter.h"
77
#include "itkNeighborhood.h"
88

9-
int main(int argc, char * argv[])
9+
int
10+
main(int argc, char * argv[])
1011
{
11-
if( argc != 10 )
12-
{
13-
std::cerr << "Usage: "<< std::endl;
12+
if (argc != 10)
13+
{
14+
std::cerr << "Usage: " << std::endl;
1415
std::cerr << argv[0];
1516
std::cerr << " <InputFilePath> <MaskFilePath> <OutputFilePath> ";
1617
std::cerr << " <NumberOfBinsPerAxis> <PixelValueMin> ";
1718
std::cerr << " <PixelValueMax> <DistanceValueMin> ";
1819
std::cerr << " <DistanceValueMax> <NeighborhoodRadius> ";
1920
std::cerr << std::endl;
2021
return EXIT_FAILURE;
21-
}
22-
23-
// Setup types
24-
using InputImageType = itk::Image< int, 3 >;
25-
using OutputImageType = itk::Image< itk::Vector< float, 10 > , 3 >;
26-
using readerType = itk::ImageFileReader< InputImageType >;
27-
using NeighborhoodType = itk::Neighborhood<typename InputImageType::PixelType,
28-
InputImageType::ImageDimension>;
29-
NeighborhoodType neighborhood;
30-
31-
// Create and setup a reader
32-
readerType::Pointer reader = readerType::New();
33-
reader->SetFileName( argv[1] );
34-
35-
// Create and setup a maskReader
36-
readerType::Pointer maskReader = readerType::New();
37-
maskReader->SetFileName( argv[2] );
38-
39-
// Apply the filter
40-
using FilterType = itk::Statistics::RunLengthTextureFeaturesImageFilter
41-
< InputImageType, OutputImageType >;
42-
FilterType::Pointer filter = FilterType::New();
43-
filter->SetInput(reader->GetOutput());
44-
filter->SetMaskImage(maskReader->GetOutput());
45-
filter->SetNumberOfBinsPerAxis(std::stoi(argv[4]));
46-
filter->SetHistogramValueMinimum(std::stod(argv[5]));
47-
filter->SetHistogramValueMaximum(std::stod(argv[6]));
48-
filter->SetHistogramDistanceMinimum(std::stod(argv[7]));
49-
filter->SetHistogramDistanceMaximum(std::stod(argv[8]));
50-
neighborhood.SetRadius( std::stoi(argv[9]) );
51-
filter->SetNeighborhoodRadius(neighborhood.GetRadius());
52-
53-
// Create and setup a writter
54-
using WriterType = itk::ImageFileWriter< OutputImageType >;
55-
WriterType::Pointer writer = WriterType::New();
56-
std::string outputFilename = argv[3];
57-
writer->SetFileName(outputFilename.c_str());
58-
writer->SetInput(filter->GetOutput());
59-
writer->Update();
22+
}
23+
24+
// Setup types
25+
using InputImageType = itk::Image<int, 3>;
26+
using OutputImageType = itk::Image<itk::Vector<float, 10>, 3>;
27+
using readerType = itk::ImageFileReader<InputImageType>;
28+
using NeighborhoodType = itk::Neighborhood<typename InputImageType::PixelType, InputImageType::ImageDimension>;
29+
NeighborhoodType neighborhood;
30+
31+
// Create and setup a reader
32+
readerType::Pointer reader = readerType::New();
33+
reader->SetFileName(argv[1]);
34+
35+
// Create and setup a maskReader
36+
readerType::Pointer maskReader = readerType::New();
37+
maskReader->SetFileName(argv[2]);
38+
39+
// Apply the filter
40+
using FilterType = itk::Statistics::RunLengthTextureFeaturesImageFilter<InputImageType, OutputImageType>;
41+
FilterType::Pointer filter = FilterType::New();
42+
filter->SetInput(reader->GetOutput());
43+
filter->SetMaskImage(maskReader->GetOutput());
44+
filter->SetNumberOfBinsPerAxis(std::stoi(argv[4]));
45+
filter->SetHistogramValueMinimum(std::stod(argv[5]));
46+
filter->SetHistogramValueMaximum(std::stod(argv[6]));
47+
filter->SetHistogramDistanceMinimum(std::stod(argv[7]));
48+
filter->SetHistogramDistanceMaximum(std::stod(argv[8]));
49+
neighborhood.SetRadius(std::stoi(argv[9]));
50+
filter->SetNeighborhoodRadius(neighborhood.GetRadius());
51+
52+
// Create and setup a writter
53+
using WriterType = itk::ImageFileWriter<OutputImageType>;
54+
WriterType::Pointer writer = WriterType::New();
55+
std::string outputFilename = argv[3];
56+
writer->SetFileName(outputFilename.c_str());
57+
writer->SetInput(filter->GetOutput());
58+
writer->Update();
6059

6160
return EXIT_SUCCESS;
6261
}

0 commit comments

Comments
 (0)