From 3c89981c4f78fe15b1087f40e51e37c0c1fb087c Mon Sep 17 00:00:00 2001 From: dsarrut Date: Tue, 15 Feb 2011 10:45:37 +0000 Subject: [PATCH] add 'OR' operation --- itk/clitkBooleanOperatorLabelImageFilter.h | 7 +++-- itk/clitkBooleanOperatorLabelImageFilter.txx | 29 ++++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/itk/clitkBooleanOperatorLabelImageFilter.h b/itk/clitkBooleanOperatorLabelImageFilter.h index f81b440..13a9b74 100644 --- a/itk/clitkBooleanOperatorLabelImageFilter.h +++ b/itk/clitkBooleanOperatorLabelImageFilter.h @@ -81,7 +81,8 @@ namespace clitk { // Set type of operation typedef enum { And = 0, - AndNot = 1 + AndNot = 1, + Or = 2 } OperationTypeEnumeration; itkGetMacro(OperationType, OperationTypeEnumeration); itkSetMacro(OperationType, OperationTypeEnumeration); @@ -105,7 +106,8 @@ namespace clitk { virtual void GenerateInputRequestedRegion(); virtual void GenerateData(); - virtual void ReleaseInputs() { } // Do not release date to keep input in memory and continue ... + // Do not release date to keep input in memory and continue ... + virtual void ReleaseInputs() { } Input1ImagePixelType mBackgroundValue1; Input2ImagePixelType mBackgroundValue2; @@ -120,6 +122,7 @@ namespace clitk { template void LoopAndNot(Iter1 it1, Iter1 it2, Iter2 ot); template void LoopAnd(Iter1 it1, Iter1 it2, Iter2 ot); + template void LoopOr(Iter1 it1, Iter1 it2, Iter2 ot); private: BooleanOperatorLabelImageFilter(const Self&); //purposely not implemented diff --git a/itk/clitkBooleanOperatorLabelImageFilter.txx b/itk/clitkBooleanOperatorLabelImageFilter.txx index 20f811a..1a7a98b 100644 --- a/itk/clitkBooleanOperatorLabelImageFilter.txx +++ b/itk/clitkBooleanOperatorLabelImageFilter.txx @@ -154,9 +154,6 @@ namespace clitk { } // Compute intersection bounding box (in physical coordinate) and regions (in pixel coordinate) - // DD(input1->GetLargestPossibleRegion()); - // DD(input2->GetLargestPossibleRegion()); - // DD(outputImage->GetLargestPossibleRegion()); typedef itk::BoundingBox BBType; typename BBType::Pointer bbInput1 = BBType::New(); ComputeBBFromImageRegion(input1, input1->GetLargestPossibleRegion(), bbInput1); @@ -165,20 +162,13 @@ namespace clitk { typename BBType::Pointer bbOutput = BBType::New(); ComputeBBFromImageRegion(outputImage, outputImage->GetLargestPossibleRegion(), bbOutput); - // DD(bbInput1); - // DD(bbInput2); - // DD(bbOutput); - typename BBType::Pointer bb = BBType::New(); ComputeBBIntersection(bb, bbInput1, bbInput2); - // DD(bb); ComputeBBIntersection(bb, bb, bbOutput); - // DD(bb); ComputeRegionFromBB(input1, bb, input1Region); ComputeRegionFromBB(input2, bb, input2Region); ComputeRegionFromBB(outputImage, bb, outputRegion); - } //-------------------------------------------------------------------- @@ -212,9 +202,6 @@ namespace clitk { OutputImagePointer output = this->GetOutput(0); // Get Region iterators - // DD(input1Region); - // DD(input2Region); - // DD(outputRegion); itk::ImageRegionConstIterator it1(input1, input1Region); itk::ImageRegionConstIterator it2(input2, input2Region); itk::ImageRegionIterator ot (output, outputRegion); @@ -225,6 +212,7 @@ namespace clitk { switch (m_OperationType) { case AndNot: LoopAndNot(it1, it2, ot); break; case And: LoopAnd(it1, it2, ot); break; + case Or: LoopOr(it1, it2, ot); break; } } //-------------------------------------------------------------------- @@ -245,7 +233,8 @@ namespace clitk { //-------------------------------------------------------------------- LOOP_BEGIN(LoopAndNot) - if ((it1.Get() != mBackgroundValue1) && (it2.Get() == mBackgroundValue2)) { ot.Set(mForegroundValue); } + if ((it1.Get() != mBackgroundValue1) && (it2.Get() == mBackgroundValue2)) + { ot.Set(mForegroundValue); } else { ot.Set(mBackgroundValue); } LOOP_END //-------------------------------------------------------------------- @@ -253,7 +242,17 @@ namespace clitk { //-------------------------------------------------------------------- LOOP_BEGIN(LoopAnd) - if ((it1.Get() != mBackgroundValue1) && (it2.Get() != mBackgroundValue2)) { ot.Set(mForegroundValue); } + if ((it1.Get() != mBackgroundValue1) && (it2.Get() != mBackgroundValue2)) + { ot.Set(mForegroundValue); } + else { ot.Set(mBackgroundValue); } + LOOP_END + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + LOOP_BEGIN(LoopOr) + if ((it1.Get() != mBackgroundValue1) || (it2.Get() != mBackgroundValue2)) + { ot.Set(mForegroundValue); } else { ot.Set(mBackgroundValue); } LOOP_END //-------------------------------------------------------------------- -- 2.45.2