[Insight-developers] Disable concept checking for a specific file?

Dan Mueller dan.muel at gmail.com
Fri Dec 31 10:12:59 EST 2010


Hi Luis,

> Could you please elaborate ?
I was trying to avoid elaborating on the use case because it gets
quite complicated. Oh well, here goes...

There are a number of classes whose concept checking I wish to
suppress, including:
    itk::AndImageFilter (checks for integer pixel type)
    itk::OrImageFilter (checks for integer pixel type)
    etc...

The concept checks are NOT wrong; they are perfectly valid (in
isolation) and should not be removed. So then why do I want to
suppress them?

Well...

I am nearly finished preparing an Insight Journal article titled
"Using the Strategy Pattern to Simplify ITK". As you can guess, this
article describes the strategy software design pattern and the use of
"algorithm families". For example:
    Family: BinaryPixelMath
    Algorithms: And, Or, Add, Subtract, Multiple, etc

At run-time the user will be able to choose the algorithm strategy. For example:
    typedef Image<unsigned char, 2> ImageType;
    typedef SimpleUnaryPixelMathImageFilter<ImageType,ImageType>
UnaryPixelMathImageType;
    UnaryPixelMathImageType::Pointer filter = UnaryPixelMathImageType::New();
    filter->SetStrategy(UnaryPixelMathStrategy::Add); // <<<<
    filter->SetInput1(input1);
    filter->SetInput2(input2);
    filter->Update();

The user is still responsible for defining the template parameters of
the "umbrella" filter. Let's take two examples:
    Example 1: typedef Image<unsigned char, 2> ImageType;
    Example 2: typedef Image<float, 2> ImageType;

Example 1 works just fine: And, Or, Add, Subtract filters can all be
defined for pixel type unsigned char.
However, Example 2 does not compile due to concept checking. The
logical operator filters (And/Or) have concept checks for pixel type
is integer (and rightly so).

So the issue is that concept checks are done at compile time, but it
may be that the user does not invoke the offending strategy at
run-time. If they do (ie. invoke "And" on two floating-point images) a
run-time exception will be thrown.

As I see it I have the following options:
    1. Disable concept checking globally
    2. Don't group these filters together (eg. create
LogicalUnaryPixelMath umbrella filter)
    3. Locally suppress concept checking, then re-enable

I don't like option 1. Option 2 means some filters which belong
together can not be grouped. Option 3 is the approach I hope to get
working. The code I gave below works fairly well: concept checking is
globally enabled, but is disabled after you include the
UnaryPixelMathImageFilter header file.

Sorry if I have not described the situation well enough. I will
probably publish the IJ article in the next week or two (with Option 3
half working), so it might be easier to give advice with the code at
hand...

Cheers, Dan

FYI: So far I have implemented the following strategies:
UnaryPixelMath: Abs, Acos, Asin, Atan, BoundedReciprocal, Cos, Exp,
ExpNegative, InvertIntensity, Log10, Log, Not, Sigmoid, Sin, Sqrt,
Square, Tan
BinaryPixelMath: Add, Subtract, Multiply, Divide, WeightedAdd,
AbsoluteValueDifference, BinaryMagnitude, ConstrainedValueAddition,
ConstrainedValueDifference, Mask, MaskNegated, Maximum, Minimum,
SquaredDifference
DistanceMap: Danielsson, SignedDanielsson, SignedMaurer
Gradient: FiniteDifference, RecursiveGaussian
GradientMagnitude: FiniteDifference, RecursiveGaussian, Morphological,
Laplacian, LaplacianRecursiveGaussian
Threshold: Binary, Single, Double, Otsu, KappaSigma
Projection: Binary, BinaryThreshold, Maximum, Minimum, Sum, Mean,
StandardDeviation, Median
ImageToImageMetric: CompareHistogram, CorrelationCoefficientHistogram,
GradientDifference, Histogram, KappaStatistic,
KullbackLeiblerCompareHistogram, MatchCardinality,
MattesMutualInformation, MeanReciprocalSquareDifference,
MeanSquaresHistogram, MeanSquares, MutualInformationHistogram,
MutualInformation, NormalizedCorrelation,
NormalizedMutualInformationHistogram
Interpolate: Linear, BSpline, CosineWindowedSinc, HammingWindowedSinc,
LanczosWindowedSinc, WelchWindowedSinc
Optimizer: Amoeba, ConjugateGradient, FRPR, GradientDescent, LBFGSB,
LBFGS, LevenbergMarquardt, OnePlusOneEvolutionary, Powell,
RegularStepGradientDescent, VersorRigid3DTransform, VersorTransform
Transform: Translation, Scale, Euler2D, Euler3D, Rigid2D, Rigid3D,
Versor, VersorRigid3D, Similarity2D, Similarity3D, Affine

I plan to implement the following strategies, then submit the IJ article:
NaryPixelMath: Add, Maximum
Morphology: BinaryDilate, BinaryErode, BinaryOpen, BinaryClose,
GreyscaleOpen, GreyscaleClose, GreyscaleDilate, GreyscaleErode,
AnchorOpen, AnchorClose, VanHerkGilWermanOpen, VanHerkGilWermanClose
Smoothing: Bilateral, CurvatureFlow, DiscreteGaussian,
SmoothingRecursiveGaussian, Median
RegionGrowing: KLMRegionGrow, ConfidenceConnected, ConnectedThreshold,
IsolatedConnected, NeighborhoodConnected
MinimaMaxima: HConcave, HMaxima, HMinima, RegionalMaxima, RegionalMinima

On 31 December 2010 14:09, Luis Ibanez <luis.ibanez at kitware.com> wrote:
> Hi Dan,
>
> I'm curious about the class in which you are finding
> necessary to disable the concept checking.
>
> Maybe what we should do is to fix the concept check
> in that class, so it reflects the conditions of actual use.
>
> Could you please elaborate ?
>
>
>    Thanks
>
>
>         Luis
>
>
> --------------------------------------------------------------------
> On Thu, Dec 30, 2010 at 2:25 AM, Dan Mueller <dan.muel at gmail.com> wrote:
>> Hi Insight Developers,
>>
>> Is there a way to disable concept checking for a specific file?
>>
>> In general I want concept checking turned on (i.e. I don't want to
>> globally disable concept checking using the CMake option). However I
>> have a specific file(s) for which I want to disable concept checking
>> (it fails the concept check, but the failure is acceptable). I know, I
>> know -- this isn't the intent of concept checking, but hey, I want to
>> do it anyway :D
>>
>> I can force concept checking to be disabled from a particular point
>> onwards, but I can't figure out how (if at all possible) I can
>> "re-enable" it. Is this possible?
>>
>> Example:
>>
>> // Files I want concept checked
>> #include "itkAFileToBeConceptChecked.h"
>> #include "itkAnotherFileToBeConceptChecked.h"
>>
>> // Force disabling of concept checking
>> #undef ITK_USE_CONCEPT_CHECKING
>> #undef itkConceptConstraintsMacro
>> #undef itkConceptMacro
>> #define itkConceptConstraintsMacro()
>> #define itkConceptMacro(name, concept) enum { name = 0 }
>>
>> // Files I DO NOT want concept checked
>> #include "itkFileNotToBeConceptChecked.h"
>>
>> // TODO: I should re-enable concept checking <<< What to do?
>>
>> // Files I want concept checked
>> #include "itkYetAnotherFileToBeConceptChecked.h"
>>
>> Thanks for any ideas.
>>
>> Cheers, Dan


More information about the Insight-developers mailing list