Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: DO NOT MERGE: Test for Apply Clang Format Action #3574

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@ main(int argc, char * argv[])

for (; itKey != imgMetaKeys.end(); ++itKey)
{
double x, y, z;

itk::ExposeMetaData<std::string>(imgMetaDictionary, *itKey, metaString);
if (itKey->find("DWMRI_gradient") != std::string::npos)
{
std::cout << *itKey << " ---> " << metaString << std::endl;
sscanf(metaString.c_str(), "%lf %lf %lf\n", &x, &y, &z);
vect3d[0] = x;
vect3d[1] = y;
vect3d[2] = z;
sscanf(metaString.c_str(),
"%lf %lf %lf\n",
&(vect3d[0]),
&(vect3d[1]),
&(vect3d[2]));
DiffusionVectors->InsertElement(numberOfImages, vect3d);
++numberOfImages;
// If the direction is 0.0, this is a reference image
Expand Down
6 changes: 3 additions & 3 deletions Examples/IO/ImageReadDicomSeriesWrite.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ main(int argc, char * argv[])
auto namesGenerator = NamesGeneratorType::New();

itk::MetaDataDictionary & dict = gdcmIO->GetMetaDataDictionary();
std::string tagkey, value;
tagkey = "0008|0060"; // Modality
value = "MR";

std::string tagkey = "0008|0060"; // Modality
std::string value = "MR";
itk::EncapsulateMetaData<std::string>(dict, tagkey, value);
tagkey = "0008|0008"; // Image Type
value = "DERIVED\\SECONDARY";
Expand Down
3 changes: 1 addition & 2 deletions Examples/Iterators/ImageSliceIteratorWithIndex.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ main(int argc, char * argv[])
// Software Guide : BeginCodeSnippet
auto projectionDirection = static_cast<unsigned int>(std::stoi(argv[3]));

unsigned int i, j;
unsigned int direction[2];
for (i = 0, j = 0; i < 3; ++i)
for (unsigned int i = 0, j = 0; i < 3; ++i)
{
if (i != projectionDirection)
{
Expand Down
26 changes: 15 additions & 11 deletions Modules/Core/Common/include/itkAnnulusOperator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ auto
AnnulusOperator<TPixel, TDimension, TAllocator>::GenerateCoefficients() -> CoefficientVector
{
// Determine the initial kernel values...
double interiorV, annulusV, exteriorV;
double interiorV;
double annulusV;
double exteriorV;

if (m_Normalize)
{
double bright = (m_BrightCenter ? 1.0 : -1.0);
const double bright = (m_BrightCenter ? 1.0 : -1.0);

// Initial values for a normalized kernel
interiorV = bright;
Expand All @@ -79,14 +81,16 @@ AnnulusOperator<TPixel, TDimension, TAllocator>::GenerateCoefficients() -> Coeff
}

// Compute the size of the kernel in pixels
SizeType r;
unsigned int i, j;
double outerRadius = m_InnerRadius + m_Thickness;
for (i = 0; i < TDimension; ++i)
{
r[i] = Math::Ceil<SizeValueType>(outerRadius / m_Spacing[i]);
SizeType r;

double outerRadius = m_InnerRadius + m_Thickness;
for (unsigned int i = 0; i < TDimension; ++i)
{
r[i] = Math::Ceil<SizeValueType>(outerRadius / m_Spacing[i]);
}
this->SetRadius(r);
}
this->SetRadius(r);

// Use a couple of sphere spatial functions...
using SphereType = SphereSpatialFunction<TDimension>;
Expand All @@ -109,13 +113,13 @@ AnnulusOperator<TPixel, TDimension, TAllocator>::GenerateCoefficients() -> Coeff
OffsetType offset;
typename SphereType::InputType point;

for (i = 0; i < w; ++i)
for (unsigned int i = 0; i < w; ++i)
{
// get the offset from the center pixel
offset = this->GetOffset(i);

// convert to a position
for (j = 0; j < TDimension; ++j)
for (unsigned int j = 0; j < TDimension; ++j)
{
point[j] = m_Spacing[j] * offset[j];
}
Expand Down Expand Up @@ -171,7 +175,7 @@ AnnulusOperator<TPixel, TDimension, TAllocator>::GenerateCoefficients() -> Coeff
// elements that are not exterior to the annulus. This forces the
// kernel to have mean zero and norm 1 AND forces the region
// outside the annulus to have no influence.
for (i = 0; i < w; ++i)
for (unsigned int i = 0; i < w; ++i)
{
// normalize the coefficient if it is inside the outer circle
// (exterior to outer circle is already zero)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::Ev
return table;
}();

unsigned int j, k;

// Find the starting index of the support region
for (j = 0; j < SpaceDimension; ++j)
for (unsigned int j = 0; j < SpaceDimension; ++j)
{
// Note that the expression passed to Math::Floor is adapted to work around
// a compiler bug which caused endless compilations (apparently), by
Expand All @@ -72,22 +70,22 @@ BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::Ev

// Compute the weights
Matrix<double, SpaceDimension, SplineOrder + 1> weights1D;
for (j = 0; j < SpaceDimension; ++j)
for (unsigned int j = 0; j < SpaceDimension; ++j)
{
double x = index[j] - static_cast<double>(startIndex[j]);

for (k = 0; k <= SplineOrder; ++k)
for (unsigned int k = 0; k <= SplineOrder; ++k)
{
weights1D[j][k] = BSplineKernelFunction<SplineOrder>::FastEvaluate(x);
x -= 1.0;
}
}

for (k = 0; k < Self::NumberOfWeights; ++k)
for (unsigned int k = 0; k < Self::NumberOfWeights; ++k)
{
weights[k] = 1.0;

for (j = 0; j < SpaceDimension; ++j)
for (unsigned int j = 0; j < SpaceDimension; ++j)
{
weights[k] *= weights1D[j][offsetToIndexTable[k][j]];
}
Expand Down
43 changes: 19 additions & 24 deletions Modules/Core/Common/include/itkBresenhamLine.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,23 @@ BresenhamLine<VDimension>::BuildLine(LType Direction, IdentifierType length) ->
{
// copied from the line iterator
/** Variables that drive the Bresenham-Algorithm */
// The dimension with the largest difference between start and end
unsigned int m_MainDirection;

// Accumulated error for the other dimensions
IndexType m_AccumulateError;

// Increment for the error for each step. Two times the difference between
// start and end
IndexType m_IncrementError;

// If enough is accumulated for a dimension, the index has to be
// incremented. Will be the number of pixels in the line
IndexType m_MaximalError;

// Direction of increment. -1 or 1
IndexType m_OverflowIncrement;

// After an overflow, the accumulated error is reduced again. Will be
// two times the number of pixels in the line
IndexType m_ReduceErrorAfterIncrement;

OffsetArray result(length);

IndexType m_CurrentImageIndex, LastIndex;

Direction.Normalize();
// we are going to start at 0
m_CurrentImageIndex.Fill(0);
IndexType LastIndex;
constexpr IndexType StartIndex = { { 0 } };
for (unsigned int i = 0; i < VDimension; ++i)
{
LastIndex[i] = (IndexValueType)(length * Direction[i]);
}

// Direction of increment. -1 or 1
IndexType m_OverflowIncrement;
// Increment for the error for each step. Two times the difference between
// start and end
IndexType m_IncrementError;
// Find the dominant direction
IndexValueType maxDistance = 0;
unsigned int maxDistanceDimension = 0;
Expand All @@ -76,11 +60,22 @@ BresenhamLine<VDimension>::BuildLine(LType Direction, IdentifierType length) ->
m_IncrementError[i] = 2 * distance;
m_OverflowIncrement[i] = (LastIndex[i] < 0 ? -1 : 1);
}
m_MainDirection = maxDistanceDimension;
// The dimension with the largest difference between start and end
unsigned int m_MainDirection = maxDistanceDimension;
// If enough is accumulated for a dimension, the index has to be
// incremented. Will be the number of pixels in the line
IndexType m_MaximalError;
m_MaximalError.Fill(maxDistance);

// After an overflow, the accumulated error is reduced again. Will be
// two times the number of pixels in the line
IndexType m_ReduceErrorAfterIncrement;
m_ReduceErrorAfterIncrement.Fill(2 * maxDistance);
// Accumulated error for the other dimensions
IndexType m_AccumulateError;
m_AccumulateError.Fill(0);
unsigned int steps = 1;
IndexType m_CurrentImageIndex{ 0 };
result[0] = m_CurrentImageIndex - StartIndex;
while (steps < length)
{
Expand Down
15 changes: 7 additions & 8 deletions Modules/Core/Common/include/itkColorTable.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,14 @@ template <typename TComponent>
void
ColorTable<TComponent>::UseRandomColors(unsigned int n)
{
unsigned int i;

this->DeleteColors();

m_NumberOfColors = n;
m_Color.resize(m_NumberOfColors);
m_ColorName.resize(m_NumberOfColors);
TComponent r, g, b;
TComponent minimum, maximum;

TComponent minimum;
TComponent maximum;
if (NumericTraits<TComponent>::is_integer)
{
minimum = NumericTraits<TComponent>::NonpositiveMin();
Expand All @@ -241,13 +240,13 @@ ColorTable<TComponent>::UseRandomColors(unsigned int n)
minimum = TComponent{};
maximum = NumericTraits<TComponent>::OneValue();
}
for (i = 0; i < n; ++i)
for (unsigned int i = 0; i < n; ++i)
{
r = static_cast<TComponent>(vnl_sample_uniform(minimum, maximum));
TComponent r = static_cast<TComponent>(vnl_sample_uniform(minimum, maximum));
m_Color[i][0] = r;
g = static_cast<TComponent>(vnl_sample_uniform(minimum, maximum));
TComponent g = static_cast<TComponent>(vnl_sample_uniform(minimum, maximum));
m_Color[i][1] = g;
b = static_cast<TComponent>(vnl_sample_uniform(minimum, maximum));
TComponent b = static_cast<TComponent>(vnl_sample_uniform(minimum, maximum));
m_Color[i][2] = b;
std::ostringstream name;
name << "Random(" << std::fixed << std::setprecision(2) << static_cast<float>(r) << ',' << static_cast<float>(g)
Expand Down
4 changes: 3 additions & 1 deletion Modules/Core/Common/include/itkImageSink.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ ImageSink<TInputImage>::VerifyInputInformation() const
!inputPtr1->GetDirection().GetVnlMatrix().is_equal(inputPtrN->GetDirection().GetVnlMatrix(),
this->m_DirectionTolerance))
{
std::ostringstream originString, spacingString, directionString;
std::ostringstream originString;
if (!inputPtr1->GetOrigin().GetVnlVector().is_equal(inputPtrN->GetOrigin().GetVnlVector(), coordinateTol))
{
originString.setf(std::ios::scientific);
Expand All @@ -219,6 +219,7 @@ ImageSink<TInputImage>::VerifyInputInformation() const
<< " Origin: " << inputPtrN->GetOrigin() << std::endl;
originString << "\tTolerance: " << coordinateTol << std::endl;
}
std::ostringstream spacingString;
if (!inputPtr1->GetSpacing().GetVnlVector().is_equal(inputPtrN->GetSpacing().GetVnlVector(), coordinateTol))
{
spacingString.setf(std::ios::scientific);
Expand All @@ -227,6 +228,7 @@ ImageSink<TInputImage>::VerifyInputInformation() const
<< " Spacing: " << inputPtrN->GetSpacing() << std::endl;
spacingString << "\tTolerance: " << coordinateTol << std::endl;
}
std::ostringstream directionString;
if (!inputPtr1->GetDirection().GetVnlMatrix().is_equal(inputPtrN->GetDirection().GetVnlMatrix(),
this->m_DirectionTolerance))
{
Expand Down
4 changes: 3 additions & 1 deletion Modules/Core/Common/include/itkImageToImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ ImageToImageFilter<TInputImage, TOutputImage>::VerifyInputInformation() const

if (!inputPtr1->IsCongruentImageGeometry(inputPtrN, m_CoordinateTolerance, m_DirectionTolerance))
{
std::ostringstream originString, spacingString, directionString;
std::ostringstream originString;
if (!inputPtr1->GetOrigin().GetVnlVector().is_equal(inputPtrN->GetOrigin().GetVnlVector(), coordinateTol))
{
originString.setf(std::ios::scientific);
Expand All @@ -195,6 +195,7 @@ ImageToImageFilter<TInputImage, TOutputImage>::VerifyInputInformation() const
<< " Origin: " << inputPtrN->GetOrigin() << std::endl;
originString << "\tTolerance: " << coordinateTol << std::endl;
}
std::ostringstream spacingString;
if (!inputPtr1->GetSpacing().GetVnlVector().is_equal(inputPtrN->GetSpacing().GetVnlVector(), coordinateTol))
{
spacingString.setf(std::ios::scientific);
Expand All @@ -203,6 +204,7 @@ ImageToImageFilter<TInputImage, TOutputImage>::VerifyInputInformation() const
<< " Spacing: " << inputPtrN->GetSpacing() << std::endl;
spacingString << "\tTolerance: " << coordinateTol << std::endl;
}
std::ostringstream directionString;
if (!inputPtr1->GetDirection().GetVnlMatrix().is_equal(inputPtrN->GetDirection().GetVnlMatrix(),
this->m_DirectionTolerance))
{
Expand Down
21 changes: 14 additions & 7 deletions Modules/Core/Common/test/itkByteSwapTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ itkByteSwapTest(int, char *[])

std::cout << "Starting test" << std::endl;

unsigned char uc = 'a', uc1 = 'a';
unsigned short us = 1, us1 = 1;
unsigned int ui = 1, ui1 = 1;
unsigned long ul = 1, ul1 = 1;
unsigned long long ull = 1, ull1 = 1;
float f = 1.0, f1 = 1.0;
double d = 1.0, d1 = 1.0;
unsigned char uc = 'a';
unsigned char uc1 = 'a';
unsigned short us = 1;
unsigned short us1 = 1;
unsigned int ui = 1;
unsigned int ui1 = 1;
unsigned long ul = 1;
unsigned long ul1 = 1;
unsigned long long ull = 1;
unsigned long long ull1 = 1;
float f = 1.0;
float f1 = 1.0;
double d = 1.0;
double d1 = 1.0;


// Try to swap a char
Expand Down
3 changes: 2 additions & 1 deletion Modules/Core/Common/test/itkExceptionObjectTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ itkExceptionObjectTest(int, char *[])
bool OneShouldFail = true;
try
{
human john, jane;
human john;
human jane;
naked_mole_rat hal;
OneShouldFail &= (john == john); // OK
OneShouldFail &= (jane == john); // OK
Expand Down
4 changes: 3 additions & 1 deletion Modules/Core/Common/test/itkImageTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ itkImageTest(int, char *[])

std::cout << "Test transform to/from physical vector." << std::endl;
using GradientType = itk::FixedArray<float, 2>;
GradientType truthGradient, outputGradient, testGradient;
GradientType truthGradient;
truthGradient[0] = 1.0;
truthGradient[1] = 1.0;
GradientType outputGradient;
image->TransformLocalVectorToPhysicalVector(truthGradient, outputGradient);
GradientType testGradient;
image->TransformPhysicalVectorToLocalVector(outputGradient, testGradient);
if (itk::Math::abs(truthGradient[0] - testGradient[0]) > eps ||
itk::Math::abs(truthGradient[1] - testGradient[1]) > eps)
Expand Down
17 changes: 7 additions & 10 deletions Modules/Core/Common/test/itkIteratorTests.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,15 @@ itkIteratorTests(int, char *[])
o3->Allocate();

// extra variables
double elapsedTime;
clock_t start, end;
unsigned long num = 190 * 190 * 190;

bool passed = true;

// memset
start = clock();
clock_t start = clock();
unsigned short * ptr = o3->GetBufferPointer();
memset(ptr, 0, num * sizeof(unsigned short));
end = clock();
elapsedTime = (end - start) / static_cast<double>(CLOCKS_PER_SEC);
clock_t end = clock();
double elapsedTime = (end - start) / static_cast<double>(CLOCKS_PER_SEC);

std::cout << "Raw pointer using memset" << std::endl;
std::cout << "\tTime = " << elapsedTime << std::endl;
Expand Down Expand Up @@ -98,14 +95,14 @@ itkIteratorTests(int, char *[])
}
}
// 3 nested loops
unsigned long ii, jj, kk, len = 190;
unsigned long len = 190;
start = clock();
{
unsigned int i = 0;
ptr = o3->GetBufferPointer();
for (ii = 0; ii < len; ++ii)
for (jj = 0; jj < len; ++jj)
for (kk = 0; kk < len; ++kk)
for (unsigned long ii = 0; ii < len; ++ii)
for (unsigned long jj = 0; jj < len; ++jj)
for (unsigned long kk = 0; kk < len; ++kk)
{
*ptr = 5;
++ptr;
Expand Down
Loading