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 authored and dzenanz committed Feb 20, 2020
1 parent a75f398 commit a672191
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 115 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
45 changes: 23 additions & 22 deletions include/itkLabelImageGenericInterpolateImageFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ namespace itk
* * \ingroup GenericLabelInterpolator
*/

template <typename TInputImage,template<typename, typename> class TInterpolator, typename TCoordRep=double >
class ITK_EXPORT LabelImageGenericInterpolateImageFunction :
public InterpolateImageFunction<TInputImage, TCoordRep>
template <typename TInputImage, template <typename, typename> class TInterpolator, typename TCoordRep = double>
class ITK_EXPORT LabelImageGenericInterpolateImageFunction : public InterpolateImageFunction<TInputImage, TCoordRep>
{
public:
ITK_DISALLOW_COPY_AND_ASSIGN(LabelImageGenericInterpolateImageFunction);
Expand All @@ -52,10 +51,10 @@ class ITK_EXPORT LabelImageGenericInterpolateImageFunction :
using InputPixelType = typename TInputImage::PixelType;

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

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

/** ImageDimension constant */
static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
Expand All @@ -78,53 +77,55 @@ class ITK_EXPORT LabelImageGenericInterpolateImageFunction :
/** ContinuousIndex type alias support. */
using ContinuousIndexType = typename Superclass::ContinuousIndexType;

using LabelSelectionAdaptorType = LabelSelectionImageAdaptor<TInputImage,double>;
using LabelSelectionAdaptorType = LabelSelectionImageAdaptor<TInputImage, double>;

// The interpolator used for individual binary masks corresponding to each label
using InternalInterpolatorType = TInterpolator<LabelSelectionAdaptorType,TCoordRep>;
using InternalInterpolatorType = TInterpolator<LabelSelectionAdaptorType, TCoordRep>;

/**
* Evaluate at the given index
*/
OutputType EvaluateAtContinuousIndex(
const ContinuousIndexType & cindex ) const override
{
return this->EvaluateAtContinuousIndex( cindex, nullptr );
}
OutputType
EvaluateAtContinuousIndex(const ContinuousIndexType & cindex) const override
{
return this->EvaluateAtContinuousIndex(cindex, nullptr);
}

void SetInputImage( const TInputImage *image ) override;
void
SetInputImage(const TInputImage * image) override;

/** Get the radius required for interpolation.
*
* This defines the number of surrounding pixels required to interpolate at
* a given point.
*/
virtual SizeType GetRadius() const override
{
virtual SizeType
GetRadius() const override
{
return SizeType::Filled(1);
}
}

protected:
LabelImageGenericInterpolateImageFunction() = default;
~LabelImageGenericInterpolateImageFunction() override= default;
~LabelImageGenericInterpolateImageFunction() override = default;

std::vector<typename InternalInterpolatorType::Pointer> m_InternalInterpolators;
std::vector<typename LabelSelectionAdaptorType::Pointer> m_LabelSelectionAdaptors;
std::vector<typename InternalInterpolatorType::Pointer> m_InternalInterpolators;
std::vector<typename LabelSelectionAdaptorType::Pointer> m_LabelSelectionAdaptors;
using LabelSetType = std::set<typename TInputImage::PixelType>;
LabelSetType m_Labels;

private:
/**
* Evaluate function value at the given index
*/
virtual OutputType EvaluateAtContinuousIndex(
const ContinuousIndexType &, OutputType * ) const;
virtual OutputType
EvaluateAtContinuousIndex(const ContinuousIndexType &, OutputType *) const;
};

} // end namespace itk

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

#endif
56 changes: 28 additions & 28 deletions include/itkLabelImageGenericInterpolateImageFunction.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,60 @@
namespace itk
{

template<typename TInputImage, template<typename, typename> class TInterpolator , typename TCoordRep>
void LabelImageGenericInterpolateImageFunction<TInputImage,TInterpolator, TCoordRep>
::SetInputImage( const TInputImage *image ) {
template <typename TInputImage, template <typename, typename> class TInterpolator, typename TCoordRep>
void
LabelImageGenericInterpolateImageFunction<TInputImage, TInterpolator, TCoordRep>::SetInputImage(
const TInputImage * image)
{
/* We have one adaptor and one interpolator per label to keep the class thread-safe:
* changing the adaptor's accepted value wouldn't work when called from a multi-threaded filter */
using IteratorType = itk::ImageRegionConstIterator<TInputImage>;
if (image)
{
{
m_Labels.clear();
IteratorType it(image,image->GetLargestPossibleRegion());
for(it.GoToBegin(); !it.IsAtEnd(); ++it)
{
IteratorType it(image, image->GetLargestPossibleRegion());
for (it.GoToBegin(); !it.IsAtEnd(); ++it)
{
m_Labels.insert(it.Get());
}
}
m_InternalInterpolators.clear();
m_LabelSelectionAdaptors.clear();
for(auto i = m_Labels.begin(); i != m_Labels.end(); ++i)
{
for (auto i = m_Labels.begin(); i != m_Labels.end(); ++i)
{
typename LabelSelectionAdaptorType::Pointer adapt = LabelSelectionAdaptorType::New();
// This adaptor doesn't implement Set() so this should be safe
adapt->SetImage(const_cast<TInputImage*>(image));
adapt->SetImage(const_cast<TInputImage *>(image));
adapt->SetAcceptedValue(*i);
m_LabelSelectionAdaptors.push_back(adapt);
typename InternalInterpolatorType::Pointer interp = InternalInterpolatorType::New();
interp->SetInputImage(adapt);
m_InternalInterpolators.push_back(interp);
}
}
}
Superclass::SetInputImage(image);
}

template<typename TInputImage, template<typename, typename> class TInterpolator , typename TCoordRep>
typename LabelImageGenericInterpolateImageFunction<TInputImage, TInterpolator, TCoordRep>
::OutputType
LabelImageGenericInterpolateImageFunction<TInputImage, TInterpolator, TCoordRep>
::EvaluateAtContinuousIndex( const ContinuousIndexType & cindex, OutputType * itkNotUsed(grad) ) const
template <typename TInputImage, template <typename, typename> class TInterpolator, typename TCoordRep>
typename LabelImageGenericInterpolateImageFunction<TInputImage, TInterpolator, TCoordRep>::OutputType
LabelImageGenericInterpolateImageFunction<TInputImage, TInterpolator, TCoordRep>::EvaluateAtContinuousIndex(
const ContinuousIndexType & cindex,
OutputType * itkNotUsed(grad)) const
{
/* Interpolate the binary mask corresponding to each label and return the label
* with the highest value */
double value=0;
typename TInputImage::PixelType best_label=0;
int i = 0;
for(typename LabelSetType::const_iterator it=m_Labels.begin();
it != m_Labels.end();
++it)
{
double value = 0;
typename TInputImage::PixelType best_label = 0;
int i = 0;
for (typename LabelSetType::const_iterator it = m_Labels.begin(); it != m_Labels.end(); ++it)
{
double tmp = m_InternalInterpolators[i]->EvaluateAtContinuousIndex(cindex);
if( tmp > value)
{
if (tmp > value)
{
value = tmp;
best_label = (*it);
}
++i;
}
++i;
}
return best_label;
}

Expand Down
22 changes: 10 additions & 12 deletions include/itkLabelSelectionImageAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,30 @@ namespace itk
* \ingroup ITKImageAdaptors
* \ingroup GenericLabelInterpolator
*/
template< class TImage, class TOutputPixelType >
class ITK_EXPORT LabelSelectionImageAdaptor:public
ImageAdaptor< TImage,
Accessor::LabelSelectionPixelAccessor<
typename TImage::PixelType,
TOutputPixelType > >
template <class TImage, class TOutputPixelType>
class ITK_EXPORT LabelSelectionImageAdaptor
: public ImageAdaptor<TImage, Accessor::LabelSelectionPixelAccessor<typename TImage::PixelType, TOutputPixelType>>
{
public:
ITK_DISALLOW_COPY_AND_ASSIGN(LabelSelectionImageAdaptor);

/** Standard class type alias. */
using Self = LabelSelectionImageAdaptor;
using Superclass = ImageAdaptor< TImage, Accessor::LabelSelectionPixelAccessor<
typename TImage::PixelType,
TOutputPixelType > >;
using Superclass =
ImageAdaptor<TImage, Accessor::LabelSelectionPixelAccessor<typename TImage::PixelType, TOutputPixelType>>;

using Pointer = SmartPointer< Self >;
using ConstPointer = SmartPointer< const Self >;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;

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

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

void SetAcceptedValue(typename TImage::PixelType value) {
void
SetAcceptedValue(typename TImage::PixelType value)
{
this->GetPixelAccessor().SetAcceptedValue(value);
}

Expand Down
Loading

0 comments on commit a672191

Please sign in to comment.