Skip to content

Commit

Permalink
Merge pull request #30 from jhlegarreta/FixSignedUnsignedComparisonWa…
Browse files Browse the repository at this point in the history
…rning

COMP: Fix compiler warnings
  • Loading branch information
thewtex committed Apr 8, 2019
2 parents ebd95bf + 1eb6613 commit 9434a6e
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 72 deletions.
7 changes: 4 additions & 3 deletions include/itkAnisotropicDiffusionLBRImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ class AnisotropicDiffusionLBRImageFilter : public ImageToImageFilter< TImage, TI
using PixelType = typename ImageType::PixelType;
using ScalarType = TScalar;

static const unsigned int Dimension = ImageType::ImageDimension;
using ImageDimensionType = typename ImageType::ImageDimensionType;
static constexpr ImageDimensionType ImageDimension = ImageType::ImageDimension;

using TensorType = SymmetricSecondRankTensor< ScalarType, Dimension >;
using TensorImageType = Image< TensorType, Dimension >;
using TensorType = SymmetricSecondRankTensor< ScalarType, ImageDimension >;
using TensorImageType = Image< TensorType, ImageDimension >;

using StructureTensorFilterType = StructureTensorImageFilter<ImageType, TensorImageType>;
using LinearDiffusionFilterType = LinearAnisotropicDiffusionLBRImageFilter<ImageType, ScalarType>;
Expand Down
8 changes: 4 additions & 4 deletions include/itkAnisotropicDiffusionLBRImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ AnisotropicDiffusionLBRImageFilter< TImage, TScalar >

// const SpacingType unitSpacing(1); // Better below for non-uniform spacing.
double minSpacing = referenceSpacing[0];
for( unsigned int i = 1; i < Dimension; ++i )
for( ImageDimensionType i = 1; i < ImageDimension; ++i )
{
minSpacing = std::min(minSpacing,referenceSpacing[i]);
}
Expand Down Expand Up @@ -108,8 +108,8 @@ struct AnisotropicDiffusionLBRImageFilter< TImage, TScalar >
S.ComputeEigenAnalysis(eigenValues,eigenVectors);

// For convenience, eigenvalues are sorted by increasing order
Vector<int,Dimension> order;
for(int i=0; i<(int)Dimension; ++i) order[i]=i;
Vector<int, ImageDimension> order;
for(ImageDimensionType i=0; i < ImageDimension; ++i) order[i]=i;

OrderingType ordering(eigenValues);

Expand All @@ -119,7 +119,7 @@ struct AnisotropicDiffusionLBRImageFilter< TImage, TScalar >
EigenValuesArrayType ev = this->eigenValuesFunctor->EigenValuesTransform(eigenValues);

TensorType DiffusionTensor;
for(int i=0; i<(int)Dimension; ++i){
for(ImageDimensionType i=0; i < ImageDimension; ++i){
DiffusionTensor(order[i],order[i]) = ev[i];
for(int j=0; j<i; ++j) DiffusionTensor(i,j) = 0.;
}
Expand Down
3 changes: 2 additions & 1 deletion include/itkCoherenceEnhancingDiffusionImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class CoherenceEnhancingDiffusionImageFilter:
/** Run-time type information (and related methods). */
itkTypeMacro(CoherenceEnhancingDiffusionImageFilter, AnisotropicDiffusionLBRImageFilter);

static const unsigned int Dimension = Superclass::Dimension;
using InputImageDimensionType = typename Superclass::InputImageType::ImageDimensionType;
static constexpr InputImageDimensionType InputImageDimension = Superclass::InputImageType::ImageDimension;

using EigenValuesArrayType = typename Superclass::EigenValuesArrayType;
EigenValuesArrayType EigenValuesTransform(const EigenValuesArrayType &) const override;
Expand Down
12 changes: 6 additions & 6 deletions include/itkCoherenceEnhancingDiffusionImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,46 @@ CoherenceEnhancingDiffusionImageFilter< TImage, TScalar >
::EigenValuesTransform(const EigenValuesArrayType & ev0) const
{
const ScalarType evMin = ev0[0];
const ScalarType evMax = ev0[Dimension-1];
const ScalarType evMax = ev0[InputImageDimension-1];

EigenValuesArrayType ev;
switch(m_Enhancement)
{
// Weickert's filter.
case CED:
for( unsigned int i = 0; i < Dimension; ++i )
for( InputImageDimensionType i = 0; i < InputImageDimension; ++i )
{
ev[i] = g_CED(evMax-ev0[i]);
}
break;

// A variance, requiring stronger coherence.
case cCED:
for( unsigned int i = 0; i < Dimension; ++i )
for( InputImageDimensionType i = 0; i < InputImageDimension; ++i )
{
ev[i] = g_CED( (evMax-ev0[i])/(1.+ev0[i]/m_Lambda) );
}
break;

// Weickert's filter.
case EED:
for( unsigned int i = 0; i < Dimension; ++i )
for( InputImageDimensionType i = 0; i < InputImageDimension; ++i )
{
ev[i] = g_EED(ev0[i]-evMin);
}
break;

// A variant, promoting diffusion in at least one direction at each point.
case cEED:
for( unsigned int i = 0; i < Dimension; ++i )
for( InputImageDimensionType i = 0; i < InputImageDimension; ++i )
{
ev[i] = g_EED(ev0[i]);
}
break;

// Isotropic tensors, closely related to Perona-Malik's approach.
case Isotropic:
for( unsigned int i = 0; i < Dimension; ++i )
for( InputImageDimensionType i = 0; i < InputImageDimension; ++i )
{
ev[i] = g_EED(evMax);
}
Expand Down
21 changes: 11 additions & 10 deletions include/itkLinearAnisotropicDiffusionLBRImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ class LinearAnisotropicDiffusionLBRImageFilter:
using ImageType = TImage;
using PixelType = typename ImageType::PixelType;

static constexpr unsigned int Dimension = ImageType::ImageDimension;
using ImageDimensionType = typename ImageType::ImageDimensionType;
static constexpr ImageDimensionType ImageDimension = ImageType::ImageDimension;

using ScalarType = TScalar;
using TensorType = SymmetricSecondRankTensor< ScalarType, Dimension >;
using TensorImageType = Image< TensorType, Dimension >;
using RegionType = ImageRegion< Dimension >;
using TensorType = SymmetricSecondRankTensor< ScalarType, ImageDimension >;
using TensorImageType = Image< TensorType, ImageDimension >;
using RegionType = ImageRegion< ImageDimension >;

void SetInputImage(const ImageType* image);
void SetInputTensor(const TensorImageType* tensorImage);
Expand All @@ -94,14 +95,14 @@ class LinearAnisotropicDiffusionLBRImageFilter:
typename ImageType::ConstPointer GetInputImage();
typename TensorImageType::ConstPointer GetInputTensor();

using IndexType = Index<Dimension>;
using IndexType = Index<ImageDimension>;

// ******* Containers for the stencils used in the discretization
static const unsigned int HalfStencilSize = (Dimension == 2) ? 3 : 6;
static const unsigned int HalfStencilSize = (ImageDimension == 2) ? 3 : 6;
static const unsigned int StencilSize = 2 * HalfStencilSize;

using StencilCoefficientsType = Vector<ScalarType,HalfStencilSize>;
using OffsetType = Offset<Dimension>;
using OffsetType = Offset<ImageDimension>;
using StencilOffsetsType = Vector<OffsetType, HalfStencilSize>;

using InternalSizeT = int;
Expand All @@ -114,10 +115,10 @@ class LinearAnisotropicDiffusionLBRImageFilter:
virtual void ImageUpdateLoop(); /// Automatically called by GenerateData

using StencilType = std::pair< StencilBufferIndicesType, StencilCoefficientsType >;
using StencilImageType = Image< StencilType, Dimension >;
using StencilImageType = Image< StencilType, ImageDimension >;
typename StencilImageType::Pointer m_StencilImage;

using ScalarImageType = Image<ScalarType,Dimension>;
using ScalarImageType = Image<ScalarType, ImageDimension>;
typename ScalarImageType::Pointer m_DiagonalCoefficients;

virtual ScalarType MaxStableTimeStep();
Expand All @@ -140,7 +141,7 @@ class LinearAnisotropicDiffusionLBRImageFilter:
struct StencilFunctor;
struct FunctorType;

using VectorType = Vector<ScalarType,Dimension>;
using VectorType = Vector<ScalarType, ImageDimension>;
static ScalarType ScalarProduct(const TensorType &, const VectorType &, const VectorType &);

};
Expand Down
84 changes: 42 additions & 42 deletions include/itkLinearAnisotropicDiffusionLBRImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ public:
{
region = region_;
prod[0] = 1;
for( auto i = 1; i < Dimension; ++i )
for( ImageDimensionType i = 1; i < ImageDimension; ++i )
{
prod[i]=prod[i-1]*region.GetSize()[i-1];
}
for(auto i = 0; i < Dimension; ++i )
for(ImageDimensionType i = 0; i < ImageDimension; ++i )
{
invSpacing[i] = ScalarType(1) / spacing[i];
}
Expand All @@ -118,7 +118,7 @@ public:
InternalSizeT BufferIndex(const IndexType & x) const
{
IndexValueType ans=0;
for( auto i = 0; i < Dimension; ++i )
for( ImageDimensionType i = 0; i < ImageDimension; ++i )
{
ans += this->prod[i] * ( x[i] - this->region.GetIndex()[i] );
}
Expand All @@ -133,15 +133,15 @@ public:
// Diffusion tensors are homogeneous to the inverse of norms, and are thus rescaled with an inverse spacing.

TensorType D;
for(auto i=0; i<Dimension; ++i)
for(auto j=i; j<Dimension; ++j)
for(ImageDimensionType i=0; i<ImageDimension; ++i)
for(ImageDimensionType j=i; j<ImageDimension; ++j)
D(i,j)=tensor(i,j)*this->invSpacing[i]*this->invSpacing[j];
this->Stencil( Dispatch< Dimension >(), D, offsets, stencil.second );
this->Stencil( Dispatch< ImageDimension >(), D, offsets, stencil.second );

InternalSizeT * yIndex = &stencil.first[0];

//Compute buffer offsets from geometrical offsets
for(auto i=0; i<(int)HalfStencilSize; ++i){
for(unsigned int i=0; i<HalfStencilSize; ++i){
for(auto orientation = 0; orientation<2; ++orientation, ++yIndex){
const IndexType y = orientation ? x-offsets[i] : x+offsets[i];
if(this->region.IsInside(y)){
Expand All @@ -163,24 +163,24 @@ protected:
static void Stencil(const Dispatch< 2 > &, const TensorType & D, StencilOffsetsType & offsets, StencilCoefficientsType & coefficients)
{
// Construct a superbase, and make it obtuse with Selling's algorithm
VectorType sb[Dimension+1]; //SuperBase
for(auto i=0; i<Dimension; ++i)
VectorType sb[ImageDimension+1]; //SuperBase
for(ImageDimensionType i=0; i<ImageDimension; ++i)
{
for(auto j=0; j<Dimension; ++j)
for(ImageDimensionType j=0; j<ImageDimension; ++j)
{
sb[i][j]=(i==j);
}
}

sb[Dimension] = -(sb[0]+sb[1]);
sb[ImageDimension] = -(sb[0]+sb[1]);
constexpr int maxIter = 200;
int iter=0;
for(; iter<maxIter; ++iter)
{
bool same=true;
for(auto i=1; i<=Dimension && same; ++i)
for(ImageDimensionType i=1; i<=ImageDimension && same; ++i)
{
for(auto j=0; j<i && same; ++j)
for(ImageDimensionType j=0; j<i && same; ++j)
{
if( ScalarProduct(D,sb[i],sb[j]) > 0 )
{
Expand All @@ -202,7 +202,7 @@ protected:
std::cerr << "Warning: Selling's algorithm not stabilized." << std::endl;
}

for( auto i = 0; i < 3; ++i )
for( ImageDimensionType i = 0; i < 3; ++i )
{
coefficients[i] = (-0.5)*ScalarProduct(D,sb[(i+1)%3],sb[(i+2)%3]);
assert(coefficients[i]>=0);
Expand All @@ -214,26 +214,26 @@ protected:
static void Stencil(const Dispatch< 3 > &, const TensorType & D, StencilOffsetsType & offsets, StencilCoefficientsType & coefficients)
{
// Construct a superbase, and make it obtuse with Selling's algorithm
VectorType sb[Dimension+1];
for(auto i=0; i<Dimension; ++i)
VectorType sb[ImageDimension+1];
for(ImageDimensionType i=0; i<ImageDimension; ++i)
{
for(auto j=0; j<Dimension; ++j)
for(ImageDimensionType j=0; j<ImageDimension; ++j)
{
sb[i][j] = (i==j);
}
}
sb[Dimension]=-(sb[0]+sb[1]+sb[2]);
sb[ImageDimension]=-(sb[0]+sb[1]+sb[2]);

constexpr int maxIter = 200;
int iter=0;
for(; iter<maxIter; ++iter)
{
bool same=true;
for(auto i=1; i<=Dimension && same; ++i)
for(auto j=0; j<i && same; ++j)
for(ImageDimensionType i=1; i<=ImageDimension && same; ++i)
for(ImageDimensionType j=0; j<i && same; ++j)
if( ScalarProduct(D,sb[i],sb[j]) > 0 ){
const VectorType u=sb[i], v=sb[j];
for(auto k=0,l=0; k<=Dimension; ++k)
for(auto k=0,l=0; k<=ImageDimension; ++k)
if(k!=i && k!=j)
sb[l++]=sb[k]+u;
sb[2]=-u;
Expand All @@ -248,40 +248,40 @@ protected:
}

// Computation of the weights
SymmetricSecondRankTensor<ScalarType,Dimension+1> Weights;
for(auto i=1; i<Dimension+1; ++i)
SymmetricSecondRankTensor<ScalarType,ImageDimension+1> Weights;
for(ImageDimensionType i=1; i<ImageDimension+1; ++i)
{
for(auto j=0; j<i; ++j)
for(ImageDimensionType j=0; j<i; ++j)
{
Weights(i,j) = (-0.5)*ScalarProduct(D,sb[i],sb[j]);
}
}

// Now that the obtuse superbasis has been created, generate the stencil.
// First get the dual basis. Obtained by computing the comatrix of Basis[1..Dimension].
// First get the dual basis. Obtained by computing the comatrix of Basis[1..ImageDimension].

for(auto i=0; i<Dimension; ++i)
for(ImageDimensionType i=0; i<ImageDimension; ++i)
{
for(auto j=0; j<Dimension; ++j)
for(ImageDimensionType j=0; j<ImageDimension; ++j)
{
offsets[i][j] = sb[(i+1)%Dimension][(j+1)%Dimension]*sb[(i+2)%Dimension][(j+2)%Dimension]
- sb[(i+2)%Dimension][(j+1)%Dimension]*sb[(i+1)%Dimension][(j+2)%Dimension];
offsets[i][j] = sb[(i+1)%ImageDimension][(j+1)%ImageDimension]*sb[(i+2)%ImageDimension][(j+2)%ImageDimension]
- sb[(i+2)%ImageDimension][(j+1)%ImageDimension]*sb[(i+1)%ImageDimension][(j+2)%ImageDimension];
}
}

offsets[Dimension ] = offsets[0]-offsets[1];
offsets[Dimension+1] = offsets[0]-offsets[2];
offsets[Dimension+2] = offsets[1]-offsets[2];
offsets[ImageDimension ] = offsets[0]-offsets[1];
offsets[ImageDimension+1] = offsets[0]-offsets[2];
offsets[ImageDimension+2] = offsets[1]-offsets[2];

// The corresponding coefficients are given by the scalar products.
for(auto i=0; i<Dimension; ++i)
for(ImageDimensionType i=0; i<ImageDimension; ++i)
{
coefficients[i]=Weights(i,3);
}

coefficients[Dimension] = Weights(0,1);
coefficients[Dimension+1] = Weights(0,2);
coefficients[Dimension+2] = Weights(1,2);
coefficients[ImageDimension] = Weights(0,1);
coefficients[ImageDimension+1] = Weights(0,2);
coefficients[ImageDimension+2] = Weights(1,2);
}

RegionType region;
Expand Down Expand Up @@ -325,7 +325,7 @@ LinearAnisotropicDiffusionLBRImageFilter< TImage, TScalar >
!stencilIt.IsAtEnd();
++stencilIt, ++diagIt)
{
for(auto i = 0; i < (int)StencilSize; ++i)
for(unsigned int i = 0; i < StencilSize; ++i)
{
const InternalSizeT yIndex = stencilIt.Value().first[i];
if( yIndex != OutsideBufferIndex() )
Expand Down Expand Up @@ -452,7 +452,7 @@ LinearAnisotropicDiffusionLBRImageFilter< TImage, TScalar >
::ImageUpdate(ScalarType delta)
{
//Setting up iterators
ImageRegion<Dimension> region = GetRequestedRegion();
ImageRegion<ImageDimension> region = GetRequestedRegion();

ImageRegionConstIterator<ImageType> inputIt(m_PreviousImage,region);
ImageRegionIterator<ImageType> outputIt(m_NextImage,region);
Expand All @@ -471,7 +471,7 @@ LinearAnisotropicDiffusionLBRImageFilter< TImage, TScalar >
!inputIt.IsAtEnd();
++inputIt, ++outputIt, ++stencilIt )
{
for( auto i = 0; i < (int)StencilSize; ++i )
for( unsigned int i = 0; i < StencilSize; ++i )
{
const InternalSizeT yIndex = stencilIt.Value().first[i];
if( yIndex != OutsideBufferIndex() )
Expand Down Expand Up @@ -514,13 +514,13 @@ LinearAnisotropicDiffusionLBRImageFilter< TImage, TScalar>
const VectorType & v)
{
ScalarType result(0);
for( auto i = 0; i < Dimension; ++i )
for( ImageDimensionType i = 0; i < ImageDimension; ++i )
{
result += m(i,i) * u[i] * v[i];
}
for( auto i = 0; i < Dimension; ++i )
for( ImageDimensionType i = 0; i < ImageDimension; ++i )
{
for( auto j = i+1; j < Dimension; ++j )
for( ImageDimensionType j = i+1; j < ImageDimension; ++j )
{
result += m(i,j) * (u[i] * v[j] + u[j] * v[i]);
}
Expand Down

0 comments on commit 9434a6e

Please sign in to comment.