X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkAddRelativePositionConstraintToLabelImageFilter.txx;h=a3759f49fa2f69606401d0d5289faaf96c70f3d3;hb=4cfd18a5e026b6b20a4dfbdd32606b0fc18883b5;hp=a9f8a910893efd4049270c3dbfeb8bf2b794524e;hpb=765020625fbc092d283e221e36c83e60a1844cb7;p=clitk.git diff --git a/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx b/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx index a9f8a91..a3759f4 100644 --- a/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx +++ b/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx @@ -22,6 +22,7 @@ #include "clitkAutoCropFilter.h" #include "clitkResampleImageWithOptionsFilter.h" #include "clitkBooleanOperatorLabelImageFilter.h" +#include "clitkCropLikeImageFilter.h" // itk #include @@ -32,7 +33,11 @@ #include #include #include -#include +#if ITK_VERSION_MAJOR >= 4 + #include +#else + #include +#endif // itk [Bloch et al] #include "RelativePositionPropImageFilter.h" @@ -57,6 +62,10 @@ AddRelativePositionConstraintToLabelImageFilter(): CombineWithOrFlagOff(); VerboseStepFlagOff(); WriteStepFlagOff(); + FuzzyMapOnlyFlagOff(); + FastFlagOff(); + SetRadius(2.0); + SetK1(vcl_acos(-1.0)/2); } //-------------------------------------------------------------------- @@ -117,22 +126,24 @@ clitk::AddRelativePositionConstraintToLabelImageFilter:: AddOrientationTypeString(std::string t) { m_OrientationTypeString.push_back(t); - switch (t[0]) { - case 'L' : AddOrientationType(AtLeftTo); break; - case 'R' : AddOrientationType(AtRightTo);break; - case 'A' : AddOrientationType(AntTo);break; - case 'P' : AddOrientationType(PostTo);break; - case 'S' : AddOrientationType(SupTo);break; - case 'I' : AddOrientationType(InfTo);break; - case 'N': - if (t == "NotLeftTo") { AddOrientationType(AtLeftTo); InverseOrientationFlagOn(); break; } - if (t == "NotRightTo") { AddOrientationType(AtRightTo); InverseOrientationFlagOn(); break; } - if (t == "NotAntTo") { AddOrientationType(AntTo); InverseOrientationFlagOn(); break; } - if (t == "NotPostTo") { AddOrientationType(PostTo); InverseOrientationFlagOn(); break; } - if (t == "NotSupTo") { AddOrientationType(SupTo); InverseOrientationFlagOn(); break; } - if (t == "NotInfTo") { AddOrientationType(InfTo); InverseOrientationFlagOn(); break; } - default: clitkExceptionMacro("Error, you must provide L,R or A,P or S,I (or NotLeftTo, NotRightTo etc)"); - } + + if (t == "LeftTo") { AddOrientationType(LeftTo); return; } + if (t == "RightTo") { AddOrientationType(RightTo); return; } + if (t == "AntTo") { AddOrientationType(AntTo); return; } + if (t == "PostTo") { AddOrientationType(PostTo); return; } + if (t == "SupTo") { AddOrientationType(SupTo); return; } + if (t == "InfTo") { AddOrientationType(InfTo); return; } + + if (t == "NotLeftTo") { AddOrientationType(LeftTo); InverseOrientationFlagOn(); return; } + if (t == "NotRightTo") { AddOrientationType(RightTo); InverseOrientationFlagOn(); return; } + if (t == "NotAntTo") { AddOrientationType(AntTo); InverseOrientationFlagOn(); return; } + if (t == "NotPostTo") { AddOrientationType(PostTo); InverseOrientationFlagOn(); return; } + if (t == "NotSupTo") { AddOrientationType(SupTo); InverseOrientationFlagOn(); return; } + if (t == "NotInfTo") { AddOrientationType(InfTo); InverseOrientationFlagOn(); return; } + + if (t == "Angle") return; + + clitkExceptionMacro("Error, you must provide LeftTo,RightTo or AntTo,PostTo or SupTo,InfTo (or NotLeftTo, NotRightTo etc) but you give " << t); } //-------------------------------------------------------------------- @@ -171,15 +182,27 @@ GenerateInputRequestedRegion() template void clitk::AddRelativePositionConstraintToLabelImageFilter:: -AddAngles(double a, double b) +AddAnglesInRad(double a, double b) { - AddOrientationTypeString("Angle"); + m_OrientationTypeString.push_back("Angle"); + m_OrientationType.push_back(Angle); m_Angle1.push_back(a); m_Angle2.push_back(b); } //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +template +void +clitk::AddRelativePositionConstraintToLabelImageFilter:: +AddAnglesInDeg(double a, double b) +{ + AddAnglesInRad(clitk::deg2rad(a), clitk::deg2rad(b)); +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- template void @@ -188,11 +211,11 @@ AddOrientationType(OrientationTypeEnumeration orientation) { m_OrientationType.push_back(orientation); switch (orientation) { - case AtRightTo: + case RightTo: m_Angle1.push_back(clitk::deg2rad(0)); m_Angle2.push_back(clitk::deg2rad(0)); break; - case AtLeftTo: + case LeftTo: m_Angle1.push_back(clitk::deg2rad(180)); m_Angle2.push_back(clitk::deg2rad(0)); break; @@ -226,6 +249,26 @@ AddOrientationType(OrientationTypeEnumeration orientation) //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +template +void +clitk::AddRelativePositionConstraintToLabelImageFilter:: +PrintOptions() +{ + DD((int)this->GetBackgroundValue()); + DD((int)this->GetObjectBackgroundValue()); + DDV(this->GetOrientationTypeString(), (uint)this->GetNumberOfAngles()); + DD(this->GetIntermediateSpacingFlag()); + DD(this->GetIntermediateSpacing()); + DD(this->GetFuzzyThreshold()); + DD(this->GetAutoCropFlag()); + DD(this->GetInverseOrientationFlag()); + DD(this->GetRemoveObjectFlag()); + DD(this->GetCombineWithOrFlag()); +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- template void @@ -236,6 +279,18 @@ GenerateData() clitkExceptionMacro("Add at least one orientation type"); } + if (GetVerboseOptionFlag()) { + for(int i=0; i(itk::ProcessObject::GetInput(0)); object = dynamic_cast(itk::ProcessObject::GetInput(1)); @@ -304,14 +359,14 @@ GenerateData() //-------------------------------------------------------------------- // Step 1 : resample if (m_IntermediateSpacingFlag) { - StartNewStep("Resample object to intermediate spacing"); + StartNewStep("Resample object to intermediate spacing (" + toString(m_IntermediateSpacing) + ")"); typedef clitk::ResampleImageWithOptionsFilter ResampleFilterType; typename ResampleFilterType::Pointer resampleFilter = ResampleFilterType::New(); resampleFilter->SetInput(working_image); resampleFilter->SetDefaultPixelValue(0); resampleFilter->SetOutputIsoSpacing(m_IntermediateSpacing); resampleFilter->SetGaussianFilteringEnabled(false); - // resampleFilter->SetVerboseOptions(true); + //resampleFilter->SetVerboseOptions(true); resampleFilter->Update(); working_image = resampleFilter->GetOutput(); StopCurrentStep(working_image); @@ -325,17 +380,17 @@ GenerateData() typedef itk::RelativePositionPropImageFilter RelPosFilterType; typename RelPosFilterType::Pointer relPosFilter; - typename FloatImageType::Pointer m_FuzzyMap; for(int i=0; iSetFast(GetFastFlag()); + relPosFilter->SetRadius(GetRadius()); relPosFilter->SetInput(working_image); relPosFilter->SetAlpha1(m_Angle1[i]); // xy plane relPosFilter->SetAlpha2(m_Angle2[i]); - relPosFilter->SetK1(M_PI/2.0); // Opening parameter, default = pi/2 - relPosFilter->SetFast(true); - relPosFilter->SetRadius(1); // seems sufficient in this case + relPosFilter->SetK1(GetK1());// M_PI/2.0); // Opening parameter, default = pi/2 // relPosFilter->SetVerboseProgress(true); + relPosFilter->Update(); relPos = relPosFilter->GetOutput(); @@ -359,16 +414,60 @@ GenerateData() // Divide by the number of relpos if (GetNumberOfAngles() != 1) { +#if ITK_VERSION_MAJOR >= 4 + typedef itk::DivideImageFilter DivideFilter; + typename DivideFilter::Pointer divideFilter = DivideFilter::New(); + divideFilter->SetConstant2(GetNumberOfAngles()); +#else typedef itk::DivideByConstantImageFilter DivideFilter; typename DivideFilter::Pointer divideFilter = DivideFilter::New(); - divideFilter->SetInput(m_FuzzyMap); divideFilter->SetConstant(GetNumberOfAngles()); +#endif + divideFilter->SetInput(m_FuzzyMap); divideFilter->Update(); m_FuzzyMap = divideFilter->GetOutput(); } relPos = m_FuzzyMap; StopCurrentStep(relPos); + if (GetFuzzyMapOnlyFlag()) { + // If the spacing is used, recompute fuzzy map with the input size/spacing + if (m_IntermediateSpacingFlag) { + StartNewStep("Resample FuzzyMap to come back to the same sampling than input"); + typedef clitk::ResampleImageWithOptionsFilter ResampleFilterType; + typename ResampleFilterType::Pointer resampleFilter = ResampleFilterType::New(); + resampleFilter->SetDefaultPixelValue(0.0); //Default fuzzymap value FIXME + resampleFilter->SetInput(relPos); + resampleFilter->SetOutputSpacing(input->GetSpacing()); + resampleFilter->SetGaussianFilteringEnabled(false); + resampleFilter->Update(); + relPos = m_FuzzyMap = resampleFilter->GetOutput(); + StopCurrentStep(relPos); + + // Need to put exactly the same size + if (relPos->GetLargestPossibleRegion() != input->GetLargestPossibleRegion()) { + StartNewStep("Pad to get the same size than input"); + typename FloatImageType::Pointer temp = FloatImageType::New(); + temp->CopyInformation(input); + temp->SetRegions(input->GetLargestPossibleRegion()); // Do not forget !! + temp->Allocate(); + temp->FillBuffer(0.0); // Default fuzzymap value FIXME + typename PasteFloatFilterType::Pointer padFilter2 = PasteFloatFilterType::New(); + padFilter2->SetSourceImage(relPos); + padFilter2->SetDestinationImage(temp); + padFilter2->SetDestinationIndex(input->GetLargestPossibleRegion().GetIndex()); + padFilter2->SetSourceRegion(relPos->GetLargestPossibleRegion()); + padFilter2->Update(); + relPos = padFilter2->GetOutput(); + StopCurrentStep(relPos); + m_FuzzyMap = relPos; + } + } + else { + StopCurrentStep(relPos); + } + return; + } //-------------------------------------------------------------------- //--------------------------------------------------------------------