Skip to content

Commit

Permalink
ENH: Add .gitattributes to allow running ITK clang-formatting scripts
Browse files Browse the repository at this point in the history
```
git filter-branch -f \
--tree-filter "~/ITK/Utilities/Maintenance/clang-format.bash --clang-format ~/Dashboard/src/ITK-clang11/clang-format-Linux --tracked" \
    master..
```
  • Loading branch information
hjmjohnson committed Feb 21, 2020
1 parent 3dbdaaf commit d807af8
Show file tree
Hide file tree
Showing 14 changed files with 967 additions and 768 deletions.
151 changes: 151 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
## This config file is only relevant for clang-format version 8.0.0
##
## Examples of each format style can be found on the in the clang-format documentation
## See: https://clang.llvm.org/docs/ClangFormatStyleOptions.html for details of each option
##
## The clang-format binaries can be downloaded as part of the clang binary distributions
## from http://releases.llvm.org/download.html
##
## Use the script Utilities/Maintenance/clang-format.bash to faciliate
## maintaining a consistent code style.
##
## EXAMPLE apply code style enforcement before commit:
# Utilities/Maintenance/clang-format.bash --clang ${PATH_TO_CLANG_FORMAT_8.0.0} --modified
## EXAMPLE apply code style enforcement after commit:
# Utilities/Maintenance/clang-format.bash --clang ${PATH_TO_CLANG_FORMAT_8.0.0} --last
---
# This configuration requires clang-format version 8.0.0 exactly.
BasedOnStyle: Mozilla
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
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
# clang 9.0 AllowShortLambdasOnASingleLine: All
# clang 9.0 features AllowShortIfStatementsOnASingleLine: Never
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: All
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
BraceWrapping:
# clang 9.0 feature AfterCaseLabel: false
AfterClass: true
AfterControlStatement: true
AfterEnum: 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.
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
#clang 6.0 BreakBeforeInheritanceComma: true
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
#clang 6.0 BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
## 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
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
## The following line allows larger lines in non-documentation code
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Middle
ReflowComments: true
# We may want to sort the includes as a separate pass
SortIncludes: false
# We may want to revisit this later
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
# SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 2
UseTab: Never
...
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Custom attribute to mark sources as using our C++/C code style.
[attr]our-c-style whitespace=tab-in-indent,no-lf-at-eof hooks.style=KWStyle,clangformat

*.c our-c-style
*.h our-c-style
*.cxx our-c-style
*.hxx our-c-style
*.txx our-c-style
*.txt whitespace=tab-in-indent,no-lf-at-eof
*.cmake whitespace=tab-in-indent,no-lf-at-eof

# ExternalData content links must have LF newlines
*.md5 crlf=input
*.sha512 crlf=input
40 changes: 20 additions & 20 deletions Examples/CreatingObjects.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ write the object map out to a file.
#include "itkAnalyzeObjectMap.h"
#include "itkAnalyzeObjectLabelMapImageIOFactory.h"

int main( int argc, char * * argv )
int
main(int argc, char ** argv)
{
int error_count = 0;

if( argc != 3 )
{
if (argc != 3)
{
std::cerr << "USAGE: " << argv[0] << "<inputFileName> <outputFileName>" << std::endl;
}
const char *NiftiFile = argv[1];
const char *CreatingObject = argv[2];
}
const char * NiftiFile = argv[1];
const char * CreatingObject = argv[2];
using InputPixelType = unsigned char;
using OutputPixelType = unsigned char;
constexpr unsigned int Dimension = 3;

using InputImageType = itk::Image<InputPixelType, Dimension>;
using InputImageType = itk::Image<InputPixelType, Dimension>;
using OutputImageType = itk::Image<OutputPixelType, Dimension>;

using ReaderType = itk::ImageFileReader<InputImageType>;
Expand All @@ -31,7 +32,7 @@ int main( int argc, char * * argv )
// This is very important to use if you are not going to install the Analyze Object map code directly into
// itk. This means that you can build the Analyze Object map outside of ITK and still use it and treat
// the code as if it is in ITK.
itk::ObjectFactoryBase::RegisterFactory( itk::AnalyzeObjectLabelMapImageIOFactory::New() );
itk::ObjectFactoryBase::RegisterFactory(itk::AnalyzeObjectLabelMapImageIOFactory::New());

ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
Expand All @@ -40,15 +41,15 @@ int main( int argc, char * * argv )
// different intensity values.
reader->SetFileName(NiftiFile);
try
{
{
reader->Update();
}
catch( itk::ExceptionObject & err )
{
}
catch (itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
}
itk::AnalyzeObjectMap<InputImageType>::Pointer CreateObjectMap = itk::AnalyzeObjectMap<InputImageType>::New();

// Add one entry to the object map named "You Can Delete Me", this entry corresponds to 1 if you do a pickOneEntry
Expand All @@ -66,7 +67,7 @@ int main( int argc, char * * argv )
CreateObjectMap->AddObjectEntryBasedOnImagePixel(reader->GetOutput(), 128, "Circle", 0, 250, 0);

// This entry corrsponds to 4 if you do a pickOneEntry
CreateObjectMap->AddObjectEntryBasedOnImagePixel(reader->GetOutput(), 45, "SquareTwo", 0, 0, 250);
CreateObjectMap->AddObjectEntryBasedOnImagePixel(reader->GetOutput(), 45, "SquareTwo", 0, 0, 250);

// Then anoter entry is added, this entry corrsponds to 5 if you do a pickOneEntry
CreateObjectMap->AddAnalyzeObjectEntry("Nothing In Here");
Expand All @@ -79,16 +80,15 @@ int main( int argc, char * * argv )
writer->SetFileName(CreatingObject);

try
{
{
writer->Update();
}
catch( itk::ExceptionObject & err )
{
}
catch (itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
}

return EXIT_SUCCESS;

}
23 changes: 12 additions & 11 deletions Examples/DisplayingObjectMaps.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,34 @@ using ReaderType = itk::ImageFileReader<ImageType>;

// using ConnectorType = itk::ImageToVTKImageFilter<RGBImageType>;

int main(int argc, char * argv [] )
int
main(int argc, char * argv[])
{
if( argc != 2 )
{
if (argc != 2)
{
std::cerr << "USAGE: " << argv[0] << "<inputFileName>" << std::endl;
}
const char *DisplayImage = argv[1];
}
const char * DisplayImage = argv[1];

// This is very important to use if you are not going to install the Analyze Object map code directly into
// itk. This means that you can build the Analyze Object map outside of ITK and still use it and treat
// the code as if it is in ITK.
itk::ObjectFactoryBase::RegisterFactory( itk::AnalyzeObjectLabelMapImageIOFactory::New() );
itk::ObjectFactoryBase::RegisterFactory(itk::AnalyzeObjectLabelMapImageIOFactory::New());

ReaderType::Pointer reader = ReaderType::New();
ReaderType::Pointer reader = ReaderType::New();

// The input should be an Anaylze Object Map file
reader->SetFileName( DisplayImage );
reader->SetFileName(DisplayImage);

// try
// {

reader->Update();

// This will convert the output of the reader into an object map
itk::AnalyzeObjectMap<ImageType,
RGBImageType>::Pointer Objectmap = itk::AnalyzeObjectMap<ImageType, RGBImageType>::New();
Objectmap->ImageToObjectMap(reader->GetOutput() );
itk::AnalyzeObjectMap<ImageType, RGBImageType>::Pointer Objectmap =
itk::AnalyzeObjectMap<ImageType, RGBImageType>::New();
Objectmap->ImageToObjectMap(reader->GetOutput());

// If you have vtk and itkApplications installed then you can uncomment this out to display
// an object map to the screen. Otherwise you can see how to display an object map using vtk.
Expand Down
40 changes: 20 additions & 20 deletions Examples/PickOneObjectEntry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ then write out the new object map with the one entry only.
#include "itkAnalyzeObjectMap.h"
#include "itkAnalyzeObjectLabelMapImageIOFactory.h"

int main( int argc, char * * argv )
int
main(int argc, char ** argv)
{
int error_count = 0;

if( argc != 3 )
{
if (argc != 3)
{
std::cerr << "USAGE: " << argv[0] << "<inputFileName> <outputFileName>" << std::endl;
}
const char *NiftiFile = argv[1];
const char *CreatingObject = argv[2];
}
const char * NiftiFile = argv[1];
const char * CreatingObject = argv[2];
using InputPixelType = unsigned char;
using OutputPixelType = unsigned char;
constexpr unsigned int Dimension = 3;

using InputImageType = itk::Image<InputPixelType, Dimension>;
using InputImageType = itk::Image<InputPixelType, Dimension>;
using OutputImageType = itk::Image<OutputPixelType, Dimension>;

using ReaderType = itk::ImageFileReader<InputImageType>;
Expand All @@ -31,7 +32,7 @@ int main( int argc, char * * argv )
// This is very important to use if you are not going to install the Analyze Object map code directly into
// itk. This means that you can build the Analyze Object map outside of ITK and still use it and treat
// the code as if it is in ITK.
itk::ObjectFactoryBase::RegisterFactory( itk::AnalyzeObjectLabelMapImageIOFactory::New() );
itk::ObjectFactoryBase::RegisterFactory(itk::AnalyzeObjectLabelMapImageIOFactory::New());

ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
Expand All @@ -40,15 +41,15 @@ int main( int argc, char * * argv )
// different intensity values.
reader->SetFileName(NiftiFile);
try
{
{
reader->Update();
}
catch( itk::ExceptionObject & err )
{
}
catch (itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
}
itk::AnalyzeObjectMap<InputImageType>::Pointer CreateObjectMap = itk::AnalyzeObjectMap<InputImageType>::New();

// Add another two entries that will be based on the image that is passed into
Expand All @@ -57,7 +58,7 @@ int main( int argc, char * * argv )
// you would like the entry to have for the regions that are found.
CreateObjectMap->AddObjectEntryBasedOnImagePixel(reader->GetOutput(), 200, "Square", 250, 0, 0);
CreateObjectMap->AddObjectEntryBasedOnImagePixel(reader->GetOutput(), 128, "Circle", 0, 250, 0);
CreateObjectMap->AddObjectEntryBasedOnImagePixel(reader->GetOutput(), 45, "SquareTwo", 0, 0, 250);
CreateObjectMap->AddObjectEntryBasedOnImagePixel(reader->GetOutput(), 45, "SquareTwo", 0, 0, 250);

// Pick the circle entry and have it put into CreateObjectMap two. These means
// that there is only one entry in CreateObjectMapTwo and the image has also
Expand All @@ -69,16 +70,15 @@ int main( int argc, char * * argv )
writer->SetFileName(CreatingObject);

try
{
{
writer->Update();
}
catch( itk::ExceptionObject & err )
{
}
catch (itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
}

return EXIT_SUCCESS;

}
Loading

0 comments on commit d807af8

Please sign in to comment.