//--------------------------------------------------------------------
// Step 1 : resample
if (m_IntermediateSpacingFlag) {
- StartNewStep("Resample object to intermediate spacing");
+ StartNewStep("Resample object to intermediate spacing (" + toString(m_IntermediateSpacing) + ")");
typedef clitk::ResampleImageWithOptionsFilter<ImageType> 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<ImageType>(working_image);
clitk::LabelImageOverlapMeasureFilter<ImageType>::
GenerateInputRequestedRegion()
{
- // DD("GenerateInputRequestedRegion");
// Call default
itk::ImageToImageFilter<ImageType, ImageType>::GenerateInputRequestedRegion();
// Get input pointers and set requested region to common region
// Resize like the union
ImagePointer input1 = clitk::ResizeImageLike<ImageType>(m_Input1, bbo, GetBackgroundValue());
ImagePointer input2 = clitk::ResizeImageLike<ImageType>(m_Input2, bbo, GetBackgroundValue());
+ //DD(input1->GetLargestPossibleRegion());
+ //DD(input2->GetLargestPossibleRegion());
// Compute overlap image
ImagePointer image_union = clitk::Clone<ImageType>(input1);
clitk::Or<ImageType>(image_union, input2, GetBackgroundValue());
clitk::And<ImageType>(image_intersection, input2, GetBackgroundValue());
- // writeImage<ImageType>(image_union, "union.mha");
- // writeImage<ImageType>(image_intersection, "intersection.mha");
+ //writeImage<ImageType>(image_union, "union.mha");
+ //writeImage<ImageType>(image_intersection, "intersection.mha");
// Compute size
typedef itk::LabelStatisticsImageFilter<ImageType, ImageType> StatFilterType;
statFilter->Update();
int in2 = statFilter->GetCount(GetLabel1());
- std::cout << in1 << " " << in2 << " " << inter << " " << u << " " << 2.0*(double)inter/(double)(in1+in2) << std::endl;
+ std::cout << in1 << " " << in2 << " " << inter << " " << u << " "
+ << 2.0*(double)inter/(double)(in1+in2) << std::endl;
}
//--------------------------------------------------------------------
// itk
#include <itkBoundingBox.h>
#include <itkJoinSeriesImageFilter.h>
+#include <itkChangeInformationImageFilter.h>
/*
According to
typename ImageType::PixelType & BG);
//--------------------------------------------------------------------
-
+ //--------------------------------------------------------------------
+ template<class ImageType>
+ typename ImageType::Pointer
+ RemoveNegativeIndexFromRegion(ImageType * input);
+ //--------------------------------------------------------------------
+
} // end clitk namespace
//--------------------------------------------------------------------
+ //--------------------------------------------------------------------
+ template<class ImageType>
+ typename ImageType::Pointer
+ RemoveNegativeIndexFromRegion(ImageType * input) {
+ typedef itk::ChangeInformationImageFilter< ImageType > InfoFilterType;
+ typename InfoFilterType::Pointer indexChangeFilter = InfoFilterType::New();
+ indexChangeFilter->ChangeRegionOn();
+ // The next line is commented because not exist in itk 3
+ // typename InfoFilterType::OutputImageOffsetValueType indexShift[3];
+ long indexShift[3];
+ typename ImageType::IndexType index = input->GetLargestPossibleRegion().GetIndex();
+ for(uint i=0;i<ImageType::ImageDimension; i++)
+ indexShift[i] = (index[i]<0 ? -index[i]:0);
+ typename ImageType::PointType origin;
+ for(uint i=0;i<ImageType::ImageDimension; i++)
+ origin[i] = input->GetOrigin()[i] - indexShift[i]*input->GetSpacing()[i];
+ indexChangeFilter->SetOutputOffset( indexShift );
+ indexChangeFilter->SetInput(input);
+ indexChangeFilter->SetOutputOrigin(origin);
+ indexChangeFilter->ChangeOriginOn();
+ indexChangeFilter->Update();
+ return indexChangeFilter->GetOutput();
+ }
+ //--------------------------------------------------------------------
} // end of namespace
itkSetMacro(ObjectCCLSelectionIgnoreSingleCCLFlag, bool);
itkBooleanMacro(ObjectCCLSelectionIgnoreSingleCCLFlag);
+ itkGetConstMacro(VerboseSlicesFlag, bool);
+ itkSetMacro(VerboseSlicesFlag, bool);
+ itkBooleanMacro(VerboseSlicesFlag);
+
protected:
SliceBySliceRelativePositionFilter();
virtual ~SliceBySliceRelativePositionFilter() {}
int m_ObjectCCLSelectionDimension;
int m_ObjectCCLSelectionDirection;
bool m_ObjectCCLSelectionIgnoreSingleCCLFlag;
+ bool m_VerboseSlicesFlag;
private:
SliceBySliceRelativePositionFilter(const Self&); //purposely not implemented
SetObjectCCLSelectionDimension(0);
SetObjectCCLSelectionDirection(1);
ObjectCCLSelectionIgnoreSingleCCLFlagOff();
+ VerboseSlicesFlagOff();
}
//--------------------------------------------------------------------
m_working_input,
this->GetObjectBackgroundValue());
+ // Index can be negative in some cases, and lead to problem with
+ // some filter. So we correct it.
+ m_working_input = clitk::RemoveNegativeIndexFromRegion<ImageType>(m_working_input);
+ m_working_object = clitk::RemoveNegativeIndexFromRegion<ImageType>(m_working_object);
+
// End
this->template StopCurrentStep<ImageType>(m_working_input);
}
typedef clitk::AddRelativePositionConstraintToLabelImageFilter<SliceType> RelPosFilterType;
typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New();
relPosFilter->VerboseStepFlagOff();
+ if (GetVerboseSlicesFlag()) {
+ std::cout << "Slice " << i << std::endl;
+ relPosFilter->VerboseStepFlagOn();
+ }
relPosFilter->WriteStepFlagOff();
// relPosFilter->VerboseMemoryFlagOn();
relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId()+"-"+toString(i));
// Set Get image
void SetImageFilename(TagType tag, std::string f);
- template<class ImageType>
+
+ template<class ImageType>
typename ImageType::Pointer GetImage(TagType tag, bool reload=false);
- template<class ImageType>
+
+ template<class ImageType>
+ bool CheckImage(TagType tag);
+
+ template<class ImageType>
void SetImage(TagType tag, std::string f, typename ImageType::Pointer image, bool write=false);
- template<class ImageType>
+
+ template<class ImageType>
void ReleaseImage(TagType tag);
// Set Get Double
//--------------------------------------------------------------------
+//--------------------------------------------------------------------
+template<class ImageType>
+bool AnatomicalFeatureDatabase::
+CheckImage(std::string tag)
+{
+ if (m_MapOfTag.find(tag) == m_MapOfTag.end()) {
+ return false;
+ }
+ else {
+ typename ImageType::Pointer image;
+ if (m_MapOfImage[tag]) {
+ image = static_cast<ImageType *>(m_MapOfImage[tag]);
+ }
+ else {
+ std::string s = m_MapOfTag[tag];
+ // Read the file
+ std::string n = GetPath()+"/"+s;
+ // image = readImage<ImageType>();
+ typedef itk::ImageFileReader<ImageType> ReaderType;
+ typename ReaderType::Pointer reader = ReaderType::New();
+ reader->SetFileName(n.c_str());
+ try {
+ reader->Update();
+ } catch(itk::ExceptionObject & err) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+//--------------------------------------------------------------------
+
+
//--------------------------------------------------------------------
template<class ImageType>
void AnatomicalFeatureDatabase::
m_AFDB = NULL;
SetAFDBFilename("default.afdb");
SetAFDBPath("./");
+ DisplayUsedStructuresOnlyFlagOff();
}
//--------------------------------------------------------------------
return m_AFDB;
}
//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+void clitk::FilterWithAnatomicalFeatureDatabaseManagement::
+AddUsedStructures(std::string station, std::string structure)
+{
+ if (!GetDisplayUsedStructuresOnlyFlag()) return;
+ std::cout << station << "\t" << structure;
+ bool founded = true;
+ bool tag = GetAFDB()->TagExist(structure);
+ if (tag) {
+ typedef typename itk::Image<uchar, 3> ImageType;
+ founded = GetAFDB()->CheckImage<ImageType>(structure);
+ if (!founded) {
+ std::cout << " \t Image not exist in DB ";
+ std::cout << "<" << GetAFDB()->GetTagValue(structure) << "> ";
+ }
+ }
+ if (!tag) std::cout << " \t Tag not found in DB";
+ std::cout << std::endl;
+}
+//--------------------------------------------------------------------
// Run-time type information (and related methods)
itkTypeMacro(FilterWithAnatomicalFeatureDatabaseManagement, Object);
- // Set/Get filename
- // itkBooleanMacro(AFDBFilenameGivenFlag);
- // itkSetMacro(AFDBFilenameGivenFlag, bool);
- // itkGetConstMacro(AFDBFilenameGivenFlag, bool);
- // GGO_DefineOption_Flag(afdb, SetAFDBFilenameGivenFlag);
-
- // itkBooleanMacro(AFDBPathGivenFlag);
- // itkSetMacro(AFDBPathGivenFlag, bool);
- // itkGetConstMacro(AFDBPathGivenFlag, bool);
- // GGO_DefineOption_Flag(afdb_path, SetAFDBPathGivenFlag);
-
itkSetMacro(AFDBFilename, std::string);
itkGetConstMacro(AFDBFilename, std::string);
- // GGO_DefineOption_WithTest(afdb, SetAFDBFilename, std::string, AFDBFilenameGivenFlag);
itkSetMacro(AFDBPath, std::string);
itkGetConstMacro(AFDBPath, std::string);
- // GGO_DefineOption_WithTest(afdb_path, SetAFDBPath, std::string, AFDBPathGivenFlag);
+
+ itkGetConstMacro(DisplayUsedStructuresOnlyFlag, bool);
+ itkSetMacro(DisplayUsedStructuresOnlyFlag, bool);
+ itkBooleanMacro(DisplayUsedStructuresOnlyFlag);
void WriteAFDB();
void LoadAFDB();
virtual ~FilterWithAnatomicalFeatureDatabaseManagement() {}
std::string m_AFDBFilename;
- // bool m_AFDBFilenameGivenFlag;
std::string m_AFDBPath;
- // bool m_AFDBPathGivenFlag;
clitk::AnatomicalFeatureDatabase::Pointer m_AFDB;
+ // For debug: display used structures but do not perform
+ // segmentation
+ bool m_DisplayUsedStructuresOnlyFlag;
+ void AddUsedStructures(std::string station, std::string structure);
+
private:
FilterWithAnatomicalFeatureDatabaseManagement(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
//--------------------------------------------------------------------
template <class TImageType>
clitk::RelativePositionList<TImageType>::
-RelativePositionList() {
+RelativePositionList():
+ clitk::FilterBase(),
+ clitk::FilterWithAnatomicalFeatureDatabaseManagement(),
+ itk::ImageToImageFilter<TImageType, TImageType>()
+{
ComputeOverlapFlagOff();
}
//--------------------------------------------------------------------
// Get input
m_working_input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
+ std::string s = GetInputName();
+
+ // Debug
+ if (GetDisplayUsedStructuresOnlyFlag()) {
+ for(uint i=0; i<mArgsInfoList.size(); i++) {
+ // Check if we only want to display structure name
+ AddUsedStructures(s, mArgsInfoList[i].object_arg);
+ }
+ return;
+ }
// Loop on RelativePositionList of operations
- std::string s = GetInputName();
for(uint i=0; i<mArgsInfoList.size(); i++) {
+
// clitk::PrintMemory(true, "Start");
std::string text = "["+s+"] limits ";
if (mArgsInfoList[i].orientation_given) text += std::string(mArgsInfoList[i].orientation_arg[0])+" ";
filter->SetAutoCropFlag(!options.noAutoCrop_flag);
}
//--------------------------------------------------------------------
+
+
// Create all RelativePositionList
for(unsigned int i=0; i<mListOfRelativePositionListFilename.size(); i++) {
RelPosListPointer rpl = RelPosListType::New();
+ rpl->SetDisplayUsedStructuresOnlyFlag(this->GetDisplayUsedStructuresOnlyFlag());
rpl->SetAFDB(GetAFDB());
rpl->Read(mListOfRelativePositionListFilename[i]);
std::string s = rpl->GetInputName();
relpos->SetCurrentStepNumber(GetCurrentStepNumber());
relpos->SetWriteStepFlag(GetWriteStepFlag());
relpos->SetInput(input);
- if (overlap) {
- std::string n = name.substr(8,2);
- MaskImagePointer ref = this->GetAFDB()->template GetImage <MaskImageType>("S"+n+"_Ref");
+ if (!this->GetDisplayUsedStructuresOnlyFlag() && overlap) {
+ std::string n = name.substr(8,3);
+ MaskImagePointer ref = this->GetAFDB()->template GetImage <MaskImageType>(n+"_Ref");
relpos->SetReferenceImageForOverlapMeasure(ref);
}
relpos->Update();
//------------------------------------------------------------------------------
void vvImageContour::SetDepth(double d)
{
- mDepth = d+0.5; // FIXME to not be equal to overlay
// Move the actor to be visible
double position[3] = {0, 0, 0};
- int orientation = ComputeCurrentOrientation();
+ int orientation = ComputeCurrentOrientation();
position[orientation] = -mDepth;
for(unsigned int i=0; i<mSquaresActorList.size(); i++)
mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
mImageContour[i]->SetLineWidth(mContourWidth);
mImageContour[i]->SetPreserveMemoryModeEnabled(true);
- mImageContour[i]->SetDepth(mDepth);
+ mImageContour[i]->SetDepth(mDepth+0.5);
mImageContour[i]->HideActors();
mOverlayActors.push_back(vvBinaryImageOverlayActor::New());
if (!mSlicerManager) return;
for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {
mOverlayActors[i]->SetDepth(d);
- mImageContour[i]->SetDepth(d);
+ mImageContour[i]->SetDepth(d+0.5);
}
Update(true);
}
mImageContour.push_back(vvImageContour::New());
mImageContour[i]->SetSlicer(mCurrentSlicerManager->GetSlicer(i));
mImageContour[i]->SetColor(1.0, 0.0, 0.0);
+ mImageContour[i]->SetDepth(100); // to be in front of (whe used with ROI tool)
mImageContourLower.push_back(vvImageContour::New());
mImageContourLower[i]->SetSlicer(mCurrentSlicerManager->GetSlicer(i));
mImageContourLower[i]->SetColor(0.0, 0.0, 1.0);
+ mImageContourLower[i]->SetDepth(100); // to be in front of (whe used with ROI tool)
}
valueChangedT1(mThresholdSlider1->GetValue());