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 19, 2020
1 parent 539c26e commit 30da2a1
Show file tree
Hide file tree
Showing 14 changed files with 708 additions and 573 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
32 changes: 17 additions & 15 deletions include/itkSplitComponentsImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ namespace itk
* \sa DiffusionTensor3D
* \sa NthElementImageAdaptor
*/
template< typename TInputImage, typename TOutputImage, unsigned int TComponents = TInputImage::ImageDimension >
class SplitComponentsImageFilter:
public ImageToImageFilter< TInputImage, TOutputImage >
template <typename TInputImage, typename TOutputImage, unsigned int TComponents = TInputImage::ImageDimension>
class SplitComponentsImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
{
public:
ITK_DISALLOW_COPY_AND_ASSIGN(SplitComponentsImageFilter);
Expand All @@ -65,34 +64,37 @@ class SplitComponentsImageFilter:

/** Standard class type alias. */
using Self = SplitComponentsImageFilter;
using Superclass = ImageToImageFilter< InputImageType, OutputImageType >;
using Pointer = SmartPointer< Self >;
using ConstPointer = SmartPointer< const Self >;
using Superclass = ImageToImageFilter<InputImageType, OutputImageType>;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;

using ComponentsMaskType = FixedArray< bool, TComponents >;
using ComponentsMaskType = FixedArray<bool, TComponents>;

/** Run-time type information (and related methods). */
itkTypeMacro( SplitComponentsImageFilter, ImageToImageFilter );
itkTypeMacro(SplitComponentsImageFilter, ImageToImageFilter);

/** Method of creation through the object factory. */
itkNewMacro( Self );
itkNewMacro(Self);

/** Set/Get the components mask. The mask is as long as the number of
* components, and only values in the mask that evaluate are true will be
* populated in the output. The default is all true. */
itkSetMacro( ComponentsMask, ComponentsMaskType );
itkGetConstReferenceMacro( ComponentsMask, ComponentsMaskType );
itkSetMacro(ComponentsMask, ComponentsMaskType);
itkGetConstReferenceMacro(ComponentsMask, ComponentsMaskType);

protected:
SplitComponentsImageFilter();
~SplitComponentsImageFilter() override {}

/** Do not allocate outputs that we will not populate. */
void AllocateOutputs() override;
void
AllocateOutputs() override;

void DynamicThreadedGenerateData( const OutputRegionType& outputRegion ) override;
void
DynamicThreadedGenerateData(const OutputRegionType & outputRegion) override;

void PrintSelf ( std::ostream& os, Indent indent ) const override;
void
PrintSelf(std::ostream & os, Indent indent) const override;

private:
ComponentsMaskType m_ComponentsMask;
Expand All @@ -101,7 +103,7 @@ class SplitComponentsImageFilter:
} // end namespace itk

#ifndef ITK_MANUAL_INSTANTIATION
#include "itkSplitComponentsImageFilter.hxx"
# include "itkSplitComponentsImageFilter.hxx"
#endif

#endif
94 changes: 44 additions & 50 deletions include/itkSplitComponentsImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,100 +26,94 @@
namespace itk
{

template< typename TInputImage, typename TOutputImage, unsigned int TComponents >
SplitComponentsImageFilter< TInputImage, TOutputImage, TComponents >
::SplitComponentsImageFilter()
template <typename TInputImage, typename TOutputImage, unsigned int TComponents>
SplitComponentsImageFilter<TInputImage, TOutputImage, TComponents>::SplitComponentsImageFilter()
{
this->m_ComponentsMask.Fill( true );
this->m_ComponentsMask.Fill(true);

this->SetNumberOfIndexedOutputs( Components );
this->SetNumberOfIndexedOutputs(Components);

// ImageSource only does this for the first output.
for ( unsigned int i = 1; i < Components; i++ )
{
this->SetNthOutput( i, this->MakeOutput( i ) );
}
for (unsigned int i = 1; i < Components; i++)
{
this->SetNthOutput(i, this->MakeOutput(i));
}

this->DynamicMultiThreadingOn();
}


template< typename TInputImage, typename TOutputImage, unsigned int TComponents >
template <typename TInputImage, typename TOutputImage, unsigned int TComponents>
void
SplitComponentsImageFilter< TInputImage, TOutputImage, TComponents >
::AllocateOutputs()
SplitComponentsImageFilter<TInputImage, TOutputImage, TComponents>::AllocateOutputs()
{
using ImageBaseType = ImageBase< TOutputImage::ImageDimension >;
using ImageBaseType = ImageBase<TOutputImage::ImageDimension>;
typename ImageBaseType::Pointer outputPtr;

// Allocate the output memory as with ImageSource
unsigned int ii = 0;
for ( OutputDataObjectIterator it(this);
!it.IsAtEnd();
++it, ++ii )
{
for (OutputDataObjectIterator it(this); !it.IsAtEnd(); ++it, ++ii)
{
// Check whether the output is an image of the appropriate
// dimension (use ProcessObject's version of the GetInput()
// method since it returns the input as a pointer to a
// DataObject as opposed to the subclass version which
// static_casts the input to an TInputImage).
outputPtr = dynamic_cast< ImageBaseType * >( it.GetOutput() );
outputPtr = dynamic_cast<ImageBaseType *>(it.GetOutput());

if ( outputPtr && this->m_ComponentsMask[ii] )
{
outputPtr->SetBufferedRegion( outputPtr->GetRequestedRegion() );
if (outputPtr && this->m_ComponentsMask[ii])
{
outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
outputPtr->Allocate();
}
}
}
}

template< typename TInputImage, typename TOutputImage, unsigned int TComponents >
template <typename TInputImage, typename TOutputImage, unsigned int TComponents>
void
SplitComponentsImageFilter< TInputImage, TOutputImage, TComponents >
::DynamicThreadedGenerateData( const OutputRegionType& outputRegion )
SplitComponentsImageFilter<TInputImage, TOutputImage, TComponents>::DynamicThreadedGenerateData(
const OutputRegionType & outputRegion)
{
typename InputImageType::ConstPointer input = this->GetInput();
ProcessObject::DataObjectPointerArray outputs = this->GetOutputs();
const ComponentsMaskType componentsMask = this->m_ComponentsMask;

using OutputIteratorType = ImageRegionIterator< OutputImageType >;
ImageRegionConstIterator< InputImageType > inIt( input, outputRegion );
std::vector< OutputIteratorType > outIts( Components );
for ( unsigned int ii = 0; ii < Components; ++ii )
const ComponentsMaskType componentsMask = this->m_ComponentsMask;

using OutputIteratorType = ImageRegionIterator<OutputImageType>;
ImageRegionConstIterator<InputImageType> inIt(input, outputRegion);
std::vector<OutputIteratorType> outIts(Components);
for (unsigned int ii = 0; ii < Components; ++ii)
{
if (componentsMask[ii])
{
if( componentsMask[ii] )
{
OutputIteratorType outIt( dynamic_cast< OutputImageType* >
( outputs[ii].GetPointer() ), outputRegion );
OutputIteratorType outIt(dynamic_cast<OutputImageType *>(outputs[ii].GetPointer()), outputRegion);
outIt.GoToBegin();
outIts[ii] = outIt;
}
}
}
InputPixelType inputPixel;
for ( inIt.GoToBegin(); !inIt.IsAtEnd(); ++inIt )
{
for (inIt.GoToBegin(); !inIt.IsAtEnd(); ++inIt)
{
inputPixel = inIt.Get();
for ( unsigned int ii = 0; ii < Components; ++ii )
for (unsigned int ii = 0; ii < Components; ++ii)
{
if (componentsMask[ii])
{
if( componentsMask[ii] )
{
outIts[ii].Set( static_cast< OutputPixelType >( inputPixel[ii] ) );
outIts[ii].Set(static_cast<OutputPixelType>(inputPixel[ii]));
++(outIts[ii]);
}
}
}
}
}

template< typename TInputImage, typename TOutputImage, unsigned int TComponents >
template <typename TInputImage, typename TOutputImage, unsigned int TComponents>
void
SplitComponentsImageFilter< TInputImage, TOutputImage, TComponents >
::PrintSelf( std::ostream & os, Indent indent ) const
SplitComponentsImageFilter<TInputImage, TOutputImage, TComponents>::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf( os, indent );
Superclass::PrintSelf(os, indent);

os << indent << "ComponentsMask: "
<< static_cast< typename NumericTraits< ComponentsMaskType >::PrintType >( m_ComponentsMask )
<< std::endl;
os << indent
<< "ComponentsMask: " << static_cast<typename NumericTraits<ComponentsMaskType>::PrintType>(m_ComponentsMask)
<< std::endl;
}
} // end namespace itk

Expand Down
Loading

0 comments on commit 30da2a1

Please sign in to comment.