From b63bc81f1d6985bacfe44e85443f006ccacc1160 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Fri, 3 Feb 2012 08:18:30 +0100 Subject: [PATCH] Moved from repository clitk to clitk.private/tests_dav --- itk/clitkRelativePositionAnalyzerFilter.h | 163 --------- itk/clitkRelativePositionAnalyzerFilter.txx | 330 ------------------ itk/clitkRelativePositionDataBase.cxx | 245 ------------- itk/clitkRelativePositionDataBase.h | 157 --------- ...tkRelativePositionDataBaseAnalyzerFilter.h | 78 ----- ...RelativePositionDataBaseAnalyzerFilter.txx | 134 ------- ...itkRelativePositionDataBaseBuilderFilter.h | 153 -------- ...kRelativePositionDataBaseBuilderFilter.txx | 159 --------- 8 files changed, 1419 deletions(-) delete mode 100644 itk/clitkRelativePositionAnalyzerFilter.h delete mode 100644 itk/clitkRelativePositionAnalyzerFilter.txx delete mode 100644 itk/clitkRelativePositionDataBase.cxx delete mode 100644 itk/clitkRelativePositionDataBase.h delete mode 100644 itk/clitkRelativePositionDataBaseAnalyzerFilter.h delete mode 100644 itk/clitkRelativePositionDataBaseAnalyzerFilter.txx delete mode 100644 itk/clitkRelativePositionDataBaseBuilderFilter.h delete mode 100644 itk/clitkRelativePositionDataBaseBuilderFilter.txx diff --git a/itk/clitkRelativePositionAnalyzerFilter.h b/itk/clitkRelativePositionAnalyzerFilter.h deleted file mode 100644 index a41df8b..0000000 --- a/itk/clitkRelativePositionAnalyzerFilter.h +++ /dev/null @@ -1,163 +0,0 @@ -/*========================================================================= - Program: vv http://www.creatis.insa-lyon.fr/rio/vv - - Authors belong to: - - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://www.centreleonberard.fr - - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the copyright notices for more information. - - It is distributed under dual licence - - - BSD See included LICENSE.txt file - - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ===========================================================================**/ - -#ifndef CLITKRELATIVEPOSITIONANALYZERFILTER_H -#define CLITKRELATIVEPOSITIONANALYZERFILTER_H - -// clitk -#include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h" -#include "clitkFilterBase.h" -#include "clitkSliceBySliceRelativePositionFilter.h" -#include "clitkRelativePositionDataBase.h" - -// itk -#include -#include - -namespace clitk { - - //-------------------------------------------------------------------- - /* - Analyze the relative position of a Target (mask image) according - to some Object (mask image), in a given Support (mask - image). Compute the optimal threshold allowing to remove the - maximal area from the Support without removing area belonging to - the Target. - */ - //-------------------------------------------------------------------- - - template - class RelativePositionAnalyzerFilter: - public itk::ImageToImageFilter - { - - public: - /** Standard class typedefs. */ - typedef itk::ImageToImageFilter Superclass; - typedef RelativePositionAnalyzerFilter Self; - typedef itk::SmartPointer Pointer; - typedef itk::SmartPointer ConstPointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(RelativePositionAnalyzerFilter, ImageToImageFilter); - - /** Some convenient typedefs. */ - typedef typename ImageType::ConstPointer ImageConstPointer; - typedef typename ImageType::Pointer ImagePointer; - typedef typename ImageType::RegionType RegionType; - typedef typename ImageType::PixelType PixelType; - typedef typename ImageType::SpacingType SpacingType; - typedef typename ImageType::SizeType SizeType; - typedef typename ImageType::IndexType IndexType; - typedef typename ImageType::PointType PointType; - - /** ImageDimension constants */ - itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension); - FILTERBASE_INIT; - typedef itk::Image FloatImageType; - - /** Input : initial image and object */ - void SetInputSupport(const ImageType * image); - void SetInputObject(const ImageType * image); - void SetInputTarget(const ImageType * image); - - // Input - // supportname, objectname multiple targetname - - // Options - itkGetConstMacro(BackgroundValue, PixelType); - itkSetMacro(BackgroundValue, PixelType); - - itkGetConstMacro(ForegroundValue, PixelType); - itkSetMacro(ForegroundValue, PixelType); - - clitk::RelativePositionDirectionType & GetDirection() { return m_Direction; } - void SetDirection(clitk::RelativePositionDirectionType & d) { m_Direction = d; } - - itkGetConstMacro(NumberOfBins, int); - itkSetMacro(NumberOfBins, int); - - itkGetConstMacro(AreaLossTolerance, double); - itkSetMacro(AreaLossTolerance, double); - - itkGetConstMacro(SupportSize, int); - itkGetConstMacro(TargetSize, int); - itkGetConstMacro(SizeWithThreshold, int); - itkGetConstMacro(SizeWithReverseThreshold, int); - - itkGetConstMacro(Info, clitk::RelativePositionInformationType); - itkGetConstMacro(InfoReverse, clitk::RelativePositionInformationType); - - // For debug - void PrintOptions(); - - // Print output - void Print(std::ostream & os=std::cout); - - // I dont want to verify inputs information - virtual void VerifyInputInformation() { } - - protected: - RelativePositionAnalyzerFilter(); - virtual ~RelativePositionAnalyzerFilter() {} - - itkSetMacro(SupportSize, int); - itkSetMacro(TargetSize, int); - itkSetMacro(SizeWithThreshold, int); - itkSetMacro(SizeWithReverseThreshold, int); - - PixelType m_BackgroundValue; - PixelType m_ForegroundValue; - ImagePointer m_Support; - ImagePointer m_Object; - ImagePointer m_Target; - int m_NumberOfBins; - double m_AreaLossTolerance; - int m_SupportSize; - int m_TargetSize; - int m_SizeWithReverseThreshold; - int m_SizeWithThreshold; - clitk::RelativePositionDirectionType m_Direction; - clitk::RelativePositionInformationType m_Info; - clitk::RelativePositionInformationType m_InfoReverse; - - virtual void GenerateOutputInformation(); - virtual void GenerateData(); - - typename FloatImageType::Pointer - ComputeFuzzyMap(ImageType * object, ImageType * target, ImageType * support, double angle); - - void - ComputeOptimalThresholds(FloatImageType * map, ImageType * target, int bins, double tolerance, - double & threshold, double & reverseThreshold); - private: - RelativePositionAnalyzerFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - }; // end class - //-------------------------------------------------------------------- - -} // end namespace clitk -//-------------------------------------------------------------------- - -#include "clitkRelativePositionAnalyzerFilter.txx" - -#endif diff --git a/itk/clitkRelativePositionAnalyzerFilter.txx b/itk/clitkRelativePositionAnalyzerFilter.txx deleted file mode 100644 index 63af119..0000000 --- a/itk/clitkRelativePositionAnalyzerFilter.txx +++ /dev/null @@ -1,330 +0,0 @@ -/*========================================================================= - Program: vv http://www.creatis.insa-lyon.fr/rio/vv - - Authors belong to: - - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://www.centreleonberard.fr - - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the copyright notices for more information. - - It is distributed under dual licence - - - BSD See included LICENSE.txt file - - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ===========================================================================**/ - -//-------------------------------------------------------------------- -template -clitk::RelativePositionAnalyzerFilter:: -RelativePositionAnalyzerFilter(): - itk::ImageToImageFilter() -{ - this->SetNumberOfRequiredInputs(3); // Input : support, object, target - SetBackgroundValue(0); - SetForegroundValue(1); - SetNumberOfBins(100); - SetAreaLossTolerance(0.01); - SetSupportSize(0); - SetTargetSize(0); - SetSizeWithThreshold(0); - SetSizeWithReverseThreshold(0); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -void -clitk::RelativePositionAnalyzerFilter:: -SetInputSupport(const ImageType * image) -{ - // Process object is not const-correct so the const casting is required. - this->SetNthInput(0, const_cast(image)); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -void -clitk::RelativePositionAnalyzerFilter:: -SetInputObject(const ImageType * image) -{ - // Process object is not const-correct so the const casting is required. - this->SetNthInput(1, const_cast(image)); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -void -clitk::RelativePositionAnalyzerFilter:: -SetInputTarget(const ImageType * image) -{ - // Process object is not const-correct so the const casting is required. - this->SetNthInput(2, const_cast(image)); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -void -clitk::RelativePositionAnalyzerFilter:: -PrintOptions() -{ - DD("TODO"); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -void -clitk::RelativePositionAnalyzerFilter:: -GenerateOutputInformation() -{ - ImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); - ImagePointer outputImage = this->GetOutput(0); - outputImage->SetRegions(outputImage->GetLargestPossibleRegion()); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -void -clitk::RelativePositionAnalyzerFilter:: -GenerateData() -{ - ImagePointer temp = dynamic_cast(itk::ProcessObject::GetInput(0)); - m_Object = dynamic_cast(itk::ProcessObject::GetInput(1)); - ImagePointer temp2 = dynamic_cast(itk::ProcessObject::GetInput(2)); - - // Remove object from support (keep initial image) - m_Support = clitk::Clone(temp); - clitk::AndNot(m_Support, m_Object, GetBackgroundValue()); - - // Remove object from target. Important because sometimes, there is - // overlap between target and object. - m_Target = clitk::Clone(temp2); - clitk::AndNot(m_Target, m_Object, GetBackgroundValue()); - - // Define filter to compute statics on mask image - typedef itk::LabelStatisticsImageFilter StatFilterType; - typename StatFilterType::Pointer statFilter = StatFilterType::New(); - - // Compute the initial support size - statFilter->SetInput(m_Support); - statFilter->SetLabelInput(m_Support); - statFilter->Update(); - SetSupportSize(statFilter->GetCount(GetForegroundValue())); - // DD(GetSupportSize()); - - // Compute the initial target size - ImagePointer s = clitk::ResizeImageLike(m_Support, m_Target, GetBackgroundValue()); - statFilter->SetInput(s); - statFilter->SetLabelInput(m_Target); - statFilter->Update(); - SetTargetSize(statFilter->GetCount(GetForegroundValue())); - // DD(GetTargetSize()); - - // - int bins = GetNumberOfBins(); - double tolerance = GetAreaLossTolerance(); - - // Compute Fuzzy map - double angle = GetDirection().angle1; - typename FloatImageType::Pointer map = ComputeFuzzyMap(m_Object, m_Target, m_Support, angle); - writeImage(map, "fuzzy_"+toString(clitk::rad2deg(angle))+".mha"); - - // Compute the optimal thresholds (direct and inverse) - double mThreshold=0.0; - double mReverseThreshold=1.0; - ComputeOptimalThresholds(map, m_Target, bins, tolerance, mThreshold, mReverseThreshold); - - // DD(mThreshold); - // DD(mReverseThreshold); - - // Use the threshold to compute new support - int s1 = GetSupportSize(); - if (mThreshold > 0.0) { - ImagePointer support1 = - clitk::SliceBySliceRelativePosition(m_Support, m_Object, 2, - mThreshold, - angle,false, // inverseFlag - false, // uniqueConnectedComponent - -1, true, - false);//singleObjectCCL - // Compute the new support size - statFilter->SetInput(support1); - statFilter->SetLabelInput(support1); - statFilter->Update(); - s1 = statFilter->GetCount(GetForegroundValue()); - } - - int s2 = GetSupportSize(); - if (mReverseThreshold < 1.0) { - ImagePointer support2 = - clitk::SliceBySliceRelativePosition(m_Support, m_Object, 2, - mReverseThreshold, - angle,true,// inverseFlag - false, // uniqueConnectedComponent - -1, true, - false); //singleObjectCCL - // Compute the new support size - statFilter = StatFilterType::New(); - statFilter->SetInput(support2); - statFilter->SetLabelInput(support2); - statFilter->Update(); - s2 = statFilter->GetCount(GetForegroundValue()); - } - - // Check threshold, if we gain nothing, we force to max/min thresholds - // DD(GetSupportSize()); - // DD(s1); - // DD(s2); - if (s1 >= GetSupportSize()) mThreshold = 0.0; - if (s2 >= GetSupportSize()) mReverseThreshold = 1.0; - - // Set results values - m_Info.threshold = mThreshold; - m_Info.sizeAfterThreshold = s1; - m_Info.sizeBeforeThreshold = GetSupportSize(); - m_Info.sizeReference = GetTargetSize(); - m_InfoReverse.threshold = mReverseThreshold; - m_InfoReverse.sizeAfterThreshold = s2; - m_InfoReverse.sizeBeforeThreshold = GetSupportSize(); - m_InfoReverse.sizeReference = GetTargetSize(); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -typename clitk::RelativePositionAnalyzerFilter::FloatImageType::Pointer -clitk::RelativePositionAnalyzerFilter:: -ComputeFuzzyMap(ImageType * object, ImageType * target, ImageType * support, double angle) -{ - typedef clitk::SliceBySliceRelativePositionFilter SliceRelPosFilterType; - typedef typename SliceRelPosFilterType::FloatImageType FloatImageType; - typename SliceRelPosFilterType::Pointer sliceRelPosFilter = SliceRelPosFilterType::New(); - sliceRelPosFilter->VerboseStepFlagOff(); - sliceRelPosFilter->WriteStepFlagOff(); - sliceRelPosFilter->SetInput(support); - sliceRelPosFilter->SetInputObject(object); - sliceRelPosFilter->SetDirection(2); - sliceRelPosFilter->SetIntermediateSpacingFlag(false); - //sliceRelPosFilter->AddOrientationTypeString(orientation); - sliceRelPosFilter->AddAnglesInRad(angle, 0.0); - sliceRelPosFilter->FuzzyMapOnlyFlagOn(); // do not threshold, only compute the fuzzy map - // sliceRelPosFilter->PrintOptions(); - sliceRelPosFilter->Update(); - typename FloatImageType::Pointer map = sliceRelPosFilter->GetFuzzyMap(); - writeImage(map, "fuzzy_0_"+toString(clitk::rad2deg(angle))+".mha"); - - // Resize object like map to allow SetBackground - ImagePointer temp = clitk::ResizeImageLike(object, map, GetBackgroundValue()); - // writeImage(map, "fuzzy_1_"+toString(clitk::rad2deg(angle))+".mha"); - - // Remove initial object from the fuzzy map - map = clitk::SetBackground(map, temp, GetForegroundValue(), 0.0, true); - writeImage(map, "fuzzy_2_"+toString(clitk::rad2deg(angle))+".mha"); - - // Resize the fuzzy map like the target, put 2.0 when outside - map = clitk::ResizeImageLike(map, target, 2.0); // Put 2.0 when out of initial map - writeImage(map, "fuzzy_3_"+toString(clitk::rad2deg(angle))+".mha"); - - // end - return map; -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -void -clitk::RelativePositionAnalyzerFilter:: -ComputeOptimalThresholds(FloatImageType * map, ImageType * target, int bins, double tolerance, - double & threshold, double & reverseThreshold) -{ - // Get the histogram of fuzzy values inside the target image - typedef itk::LabelStatisticsImageFilter FloatStatFilterType; - typename FloatStatFilterType::Pointer f = FloatStatFilterType::New(); - f->SetInput(map); - f->SetLabelInput(target); - f->UseHistogramsOn(); - f->SetHistogramParameters(bins, 0.0-(1.0/bins), 1.0+(1.0/bins)); - f->Update(); - int count = f->GetCount(GetForegroundValue()); - // DD(count); - typename FloatStatFilterType::HistogramPointer h = f->GetHistogram(GetForegroundValue()); - - // Debug : dump histogram - static int i=0; - std::ofstream histogramFile(std::string("fuzzy_histo_"+toString(i)+".txt").c_str()); - for(int j=0; jGetMeasurement(j,0) - << "\t" << h->GetFrequency(j) - << "\t" << (double)h->GetFrequency(j)/(double)count << std::endl; - } - histogramFile.close(); - std::ofstream histogramFile2(std::string("fuzzy_histo_R_"+toString(i)+".txt").c_str()); - for(int j=bins-1; j>=0; j--) { - histogramFile2 << h->GetMeasurement(j,0) - << "\t" << h->GetFrequency(j) - << "\t" << (double)h->GetFrequency(j)/(double)count << std::endl; - } - histogramFile2.close(); - i++; - - // Analyze the histogram (direct) - double sum = 0.0; - bool found = false; - threshold = 0.0; - for(int j=0; jGetFrequency(j)/(double)count); - // DD(j); - // DD(sum); - // DD(threshold); - // DD(h->GetBinMin(0,j)); - // DD(h->GetBinMax(0,j)); - if ((!found) && (sum > tolerance)) { - // We consider as threshold the laste before current, because - if (j==0) - threshold = h->GetBinMin(0,j); - else threshold = h->GetBinMin(0,j-1); // FIXME ? the last before reaching the threshold - // DD(threshold); - found = true; - j = bins; - } - } - - // Analyze the histogram (reverse) - sum = 0.0; - found = false; - reverseThreshold = 1.0; - for(int j=bins-1; j>0; j--) { - sum += ((double)h->GetFrequency(j)/(double)count); - // DD(j); - // DD(sum); - // DD(reverseThreshold); - // DD(h->GetBinMin(0,j)); - // DD(h->GetBinMax(0,j)); - if ((!found) && (sum > tolerance)) { - if (j==bins-1) - reverseThreshold = h->GetBinMax(0,j); - else reverseThreshold = h->GetBinMax(0,j-1);// FIXME ? the last before reaching the threshold - // DD(reverseThreshold); - found = true; - j = -1; - } - } - -} -//-------------------------------------------------------------------- - diff --git a/itk/clitkRelativePositionDataBase.cxx b/itk/clitkRelativePositionDataBase.cxx deleted file mode 100644 index 9ae6dd9..0000000 --- a/itk/clitkRelativePositionDataBase.cxx +++ /dev/null @@ -1,245 +0,0 @@ -/*========================================================================= - Program: vv http://www.creatis.insa-lyon.fr/rio/vv - - Authors belong to: - - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://www.centreleonberard.fr - - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the copyright notices for more information. - - It is distributed under dual licence - - - BSD See included LICENSE.txt file - - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ===========================================================================**/ - -#ifndef CLITKRELATIVEPOSITIONDATABASE_CXX -#define CLITKRELATIVEPOSITIONDATABASE_CXX - -// clitk -#include "clitkRelativePositionDataBase.h" - -namespace clitk { - - //-------------------------------------------------------------------- - void RelativePositionDataBase::ReadIndex(std::istream & is, IndexType & index) - { - is >> index.patient; - is >> index.station; - is >> index.object; - is >> index.direction.angle1; - index.direction.angle1 = clitk::deg2rad(index.direction.angle1); - is >> index.direction.angle2; - index.direction.angle2 = clitk::deg2rad(index.direction.angle2); - std::string s; - is >> s; - if (s=="true") index.direction.notFlag = true; - else index.direction.notFlag = false; - } - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - void RelativePositionDataBase::ReadInformation(std::istream & is, RelativePositionInformationType & v) - { - is >> v.threshold; - is >> v.sizeBeforeThreshold; - is >> v.sizeAfterThreshold; - is >> v.sizeReference; - } - //-------------------------------------------------------------------- - - //-------------------------------------------------------------------- - void RelativePositionDataBase::Read(const std::string & filename) - { - std::ifstream is; - openFileForReading(is, filename); - - std::string s; - IndexType index; - RelativePositionInformationType v; - while (is) { - skipComment(is); /* FIXME Read Index etc */ - ReadIndex(is, index); - ReadInformation(is, v); - - if (is) {// FIXME INSERT - // Set in station - if (m_DB.find(index.station) == m_DB.end()) { - MapByObjectType s; - m_DB[index.station] = s; - } - MapByObjectType & s = m_DB[index.station]; - - // Get Direction map from Object - if (s.find(index.object) == s.end()) { - MapByDirectionType r; - s[index.object] = r; - } - MapByDirectionType & r = s[index.object]; - - // Get Patient map from Direction - if (r.find(index.direction) == r.end()) { - MapByPatientType q; - r[index.direction] = q; - } - MapByPatientType & q = r[index.direction]; - - // Set value by patient - q[index.patient] = v; - - // Debug - // index.Println(); - // GetMapByPatient(index).find(index.patient)->second.Println(); - - } // End insertion - } // end loop reading - } - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - const RelativePositionDataBase::MapByDirectionType & - RelativePositionDataBase::GetMapByDirection(const IndexType & index) const - { - const MapByObjectType & a = GetMapByObject(index.station); - if (a.find(index.object) == a.end()) { - clitkExceptionMacro("Could not find index in DB (object= '" << index.object << "' not found)."); - } - return a.find(index.object)->second; - } - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - const RelativePositionDataBase::MapByObjectType & - RelativePositionDataBase::GetMapByObject(const std::string & station) const - { - if (m_DB.find(station) == m_DB.end()) { - clitkExceptionMacro("Could not find index in DB (station= '" << station << "' not found)."); - } - return m_DB.find(station)->second; - } - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - const RelativePositionDataBase::MapByPatientType & - RelativePositionDataBase::GetMapByPatient(const IndexType & index) const - { - const MapByDirectionType & a = GetMapByDirection(index); - if (a.find(index.direction) == a.end()) { - std::ostringstream s; - index.direction.Print(s); - clitkExceptionMacro("Could not find index in DB (direction= '" << s.str() << "' not found)."); - } - return a.find(index.direction)->second; - } - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - const RelativePositionInformationType & - RelativePositionDataBase::GetInformation(const IndexType & index) const - { - const RelativePositionDataBase::MapByPatientType & a = GetMapByPatient(index); - if (a.find(index.patient) == a.end()) { - clitkExceptionMacro("Could not find index in DB (patient= '" << index.patient << "' not found)."); - } - return a.find(index.patient)->second; - } - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - int RelativePositionDataBase::GetNumberOfPatient(const IndexType & index) const - { - const MapByPatientType & o = GetMapByPatient(index); - return o.size(); - } - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - std::vector & RelativePositionDataBase::GetListOfPatients(const IndexType & index) const - { - const MapByPatientType & o = GetMapByPatient(index); - std::vector * v = new std::vector; - MapToVecFirst(o, *v); - return *v; - } - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - double RelativePositionDataBase::GetAreaGain(const IndexType & index) const - { - // FIXME change name - const RelativePositionInformationType & v = GetInformation(index); - return v.sizeAfterThreshold/v.sizeBeforeThreshold; - } - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - double RelativePositionDataBase::GetThreshold(const IndexType & index) const - { - const RelativePositionInformationType & v = GetInformation(index); - return v.threshold; - } - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - void - RelativePositionDataBase::GetListOfObjects(const std::string & station, std::vector & objects) const - { - const MapByObjectType & a = GetMapByObject(station); - MapToVecFirst(a, objects); - } - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - void - RelativePositionDataBase::GetListOfDirections(const std::string & station, - const std::string & object, - std::vector & directions) const - { - IndexType i; - i.station = station; - i.object = object; - const MapByDirectionType & n = GetMapByDirection(i); - MapToVecFirst(n, directions); - } - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - bool RelativePositionDataBase::CheckIndex(const IndexType & index) const - { - try { - /*const RelativePositionInformationType & m = */ GetInformation(index); - } catch (clitk::ExceptionObject e) { - // std::cout << e.what() << std::endl; - return false; - } - return true; - } - //-------------------------------------------------------------------- - - //-------------------------------------------------------------------- - std::ostream& operator<<(std::ostream & os, const clitk::RelativePositionInformationType & rp) - { - rp.Print(os); - return os; - } - //-------------------------------------------------------------------- - -} // end namespace clitk -//-------------------------------------------------------------------- - -#endif diff --git a/itk/clitkRelativePositionDataBase.h b/itk/clitkRelativePositionDataBase.h deleted file mode 100644 index fa83a3e..0000000 --- a/itk/clitkRelativePositionDataBase.h +++ /dev/null @@ -1,157 +0,0 @@ -/*========================================================================= - Program: vv http://www.creatis.insa-lyon.fr/rio/vv - - Authors belong to: - - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://www.centreleonberard.fr - - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the copyright notices for more information. - - It is distributed under dual licence - - - BSD See included LICENSE.txt file - - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ===========================================================================**/ - -#ifndef CLITKRELATIVEPOSITIONDATABASE_H -#define CLITKRELATIVEPOSITIONDATABASE_H - -// clitk -#include "clitkCommon.h" - -namespace clitk { - - //-------------------------------------------------------------------- - /* - FIXME - */ - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - class RelativePositionDirectionType { - public: - double angle1; - double angle2; - bool notFlag; - - void Print(std::ostream & os = std::cout) const { - os << clitk::rad2deg(angle1) << " " << clitk::rad2deg(angle2) << " "; - if (notFlag) os << "true"; - else os << "false"; - os << " "; - } - - void PrintOptions(std::ostream & os = std::cout) const { - os << "angle1 = " << clitk::rad2deg(angle1) << std::endl - << "angle2 = " << clitk::rad2deg(angle2) << std::endl; - if (notFlag) os << "inverse" << std::endl; - } - - void Println(std::ostream & os = std::cout) const { - Print(os); - os << std::endl; - } - - bool operator< (const RelativePositionDirectionType &compare) const - { - if (angle1 < compare.angle1) return true; - if (angle1 > compare.angle1) return false; - - if (angle2 < compare.angle2) return true; - if (angle2 > compare.angle2) return false; - - if (notFlag == true) { - if (compare.notFlag == false) return true; - else return false; - } - return false; - } - }; - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - class RelativePositionDataBaseIndexType { - public: - std::string patient; - std::string station; - std::string object; - RelativePositionDirectionType direction; - void Print(std::ostream & os = std::cout) const { - os << patient << " " << station << " " << object << " "; - direction.Print(os); - } - void Println(std::ostream & os = std::cout) const { - Print(os); - os << std::endl; - } - }; - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - class RelativePositionInformationType { - public: - double threshold; - int sizeBeforeThreshold; - int sizeAfterThreshold; - int sizeReference; - void Print(std::ostream & os = std::cout) const { - os << threshold << " " << sizeBeforeThreshold << " " - << sizeAfterThreshold << " " << sizeReference; - } - void Println(std::ostream & os = std::cout) const { - Print(os); - os << std::endl; - } - }; - std::ostream& operator<<(std::ostream & os, const clitk::RelativePositionInformationType & rp); - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - class RelativePositionDataBase { - - public: - RelativePositionDataBase() {} - ~RelativePositionDataBase() {} - - typedef RelativePositionDataBaseIndexType IndexType; - - void Read(const std::string & filename); - double GetAreaGain(const IndexType & index) const; - double GetThreshold(const IndexType & index) const; - int GetNumberOfPatient(const IndexType & index) const; - std::vector & GetListOfPatients(const IndexType & index) const; - void GetListOfObjects(const std::string & station, std::vector & objects) const; - void GetListOfDirections(const std::string & station, - const std::string & object, - std::vector & directions) const; - bool CheckIndex(const IndexType & index) const; - - protected: - typedef std::map MapByPatientType; - typedef std::map MapByDirectionType; - typedef std::map MapByObjectType; - typedef std::map MapByStationType; - MapByStationType m_DB; - - void ReadIndex(std::istream & is, IndexType & index); - void ReadInformation(std::istream & is, RelativePositionInformationType & v); - - const MapByDirectionType & GetMapByDirection(const IndexType & index) const; - const MapByPatientType & GetMapByPatient(const IndexType & index) const; - const RelativePositionInformationType & GetInformation(const IndexType & index) const; - const MapByObjectType & GetMapByObject(const std::string & station) const; - - }; // end class - //-------------------------------------------------------------------- - -} // end namespace clitk -//-------------------------------------------------------------------- - -#endif diff --git a/itk/clitkRelativePositionDataBaseAnalyzerFilter.h b/itk/clitkRelativePositionDataBaseAnalyzerFilter.h deleted file mode 100644 index 7066c63..0000000 --- a/itk/clitkRelativePositionDataBaseAnalyzerFilter.h +++ /dev/null @@ -1,78 +0,0 @@ -/*========================================================================= - Program: vv http://www.creatis.insa-lyon.fr/rio/vv - - Authors belong to: - - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://www.centreleonberard.fr - - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the copyright notices for more information. - - It is distributed under dual licence - - - BSD See included LICENSE.txt file - - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ===========================================================================**/ - -#ifndef CLITKRELATIVEPOSITIONANALYZERFILTER_H -#define CLITKRELATIVEPOSITIONANALYZERFILTER_H - -// clitk -#include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h" -#include "clitkFilterBase.h" -#include "clitkRelativePositionDataBase.h" - -namespace clitk { - - //-------------------------------------------------------------------- - /* - Load a database of relative positions. Analyze it and provide - common relative position for each patient. - */ - //-------------------------------------------------------------------- - - class RelativePositionDataBaseAnalyzerFilter: - public virtual clitk::FilterBase, - public clitk::FilterWithAnatomicalFeatureDatabaseManagement - { - - public: - RelativePositionDataBaseAnalyzerFilter(); - virtual ~RelativePositionDataBaseAnalyzerFilter() {} - - // Input - itkGetConstMacro(DatabaseFilename, std::string); - itkSetMacro(DatabaseFilename, std::string); - itkGetConstMacro(StationName, std::string); - itkSetMacro(StationName, std::string); - itkGetConstMacro(ObjectName, std::string); - itkSetMacro(ObjectName, std::string); - itkGetConstMacro(OutputFilename, std::string); - itkSetMacro(OutputFilename, std::string); - - // For debug - void PrintOptions(); - - // Go ! - virtual void Update(); - - protected: - std::string m_DatabaseFilename; - std::string m_StationName; - std::string m_ObjectName; - std::string m_OutputFilename; - clitk::RelativePositionDataBase db; - - bool ComputeOptimalThreshold(RelativePositionDataBaseIndexType & index, double & threshold); - - }; // end class - //-------------------------------------------------------------------- - -} // end namespace clitk -//-------------------------------------------------------------------- - -#include "clitkRelativePositionDataBaseAnalyzerFilter.txx" - -#endif diff --git a/itk/clitkRelativePositionDataBaseAnalyzerFilter.txx b/itk/clitkRelativePositionDataBaseAnalyzerFilter.txx deleted file mode 100644 index 68d2a2b..0000000 --- a/itk/clitkRelativePositionDataBaseAnalyzerFilter.txx +++ /dev/null @@ -1,134 +0,0 @@ -/*========================================================================= - Program: vv http://www.creatis.insa-lyon.fr/rio/vv - - Authors belong to: - - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://www.centreleonberard.fr - - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the copyright notices for more information. - - It is distributed under dual licence - - - BSD See included LICENSE.txt file - - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ===========================================================================**/ - -//-------------------------------------------------------------------- -clitk::RelativePositionDataBaseAnalyzerFilter:: -RelativePositionDataBaseAnalyzerFilter(): - clitk::FilterBase(), - clitk::FilterWithAnatomicalFeatureDatabaseManagement() -{ - VerboseFlagOff(); - SetDatabaseFilename("default.dbrp"); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -void -clitk::RelativePositionDataBaseAnalyzerFilter:: -PrintOptions() -{ - DD("TODO"); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -void -clitk::RelativePositionDataBaseAnalyzerFilter:: -Update() -{ - // Load DB of relative position - db.Read(GetDatabaseFilename()); - - // Get list of objects, list of orientation - std::vector m_ListOfObjects; - db.GetListOfObjects(GetStationName(), m_ListOfObjects); - - // Set initial index in the DB - clitk::RelativePositionDataBase::IndexType index; - index.station = GetStationName(); - - // Loop over objects - std::vector m_ListOfThresholds; - for(unsigned int i=0; i m_ListOfDirections; - db.GetListOfDirections(GetStationName(), index.object, m_ListOfDirections); - - // Loop over direction - for(unsigned int j=0; j & ListOfPatients = db.GetListOfPatients(index); - // DD(ListOfPatients.size()); - // index.direction.Println(); - - // For a given station, object, direction - bool stop=false; - unsigned int i=0; - if (index.direction.notFlag) threshold = 0.0; - else threshold = 1.0; - while (!stop && (i - -namespace clitk { - - //-------------------------------------------------------------------- - /* - Analyze the relative position of a Target (mask image) according - to some Object, in a given Support. Indicate the main important - position of this Target according the Object. - */ - //-------------------------------------------------------------------- - - template - class RelativePositionDataBaseBuilderFilter: - public virtual FilterBase, - public clitk::FilterWithAnatomicalFeatureDatabaseManagement, - public itk::ImageToImageFilter - { - - public: - /** Standard class typedefs. */ - typedef itk::ImageToImageFilter Superclass; - typedef RelativePositionDataBaseBuilderFilter Self; - typedef itk::SmartPointer Pointer; - typedef itk::SmartPointer ConstPointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(RelativePositionDataBaseBuilderFilter, ImageToImageFilter); - - /** Some convenient typedefs. */ - typedef typename ImageType::ConstPointer ImageConstPointer; - typedef typename ImageType::Pointer ImagePointer; - typedef typename ImageType::RegionType RegionType; - typedef typename ImageType::PixelType PixelType; - typedef typename ImageType::SpacingType SpacingType; - typedef typename ImageType::SizeType SizeType; - typedef typename ImageType::IndexType IndexType; - typedef typename ImageType::PointType PointType; - - /** ImageDimension constants */ - itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension); - FILTERBASE_INIT; - typedef itk::Image FloatImageType; - - // Inputs - itkGetConstMacro(SupportName, std::string); - itkSetMacro(SupportName, std::string); - - itkGetConstMacro(TargetName, std::string); - itkSetMacro(TargetName, std::string); - - void AddObjectName(std::string s) { m_ObjectNames.push_back(s); } - std::string & GetObjectName(int i) { return m_ObjectNames[i]; } - int GetNumberOfObjects() { return m_ObjectNames.size(); } - - // Options - itkGetConstMacro(BackgroundValue, PixelType); - itkSetMacro(BackgroundValue, PixelType); - - itkGetConstMacro(ForegroundValue, PixelType); - itkSetMacro(ForegroundValue, PixelType); - - itkGetConstMacro(NumberOfBins, int); - itkSetMacro(NumberOfBins, int); - - itkGetConstMacro(NumberOfAngles, int); - itkSetMacro(NumberOfAngles, int); - - itkGetConstMacro(AreaLossTolerance, double); - itkSetMacro(AreaLossTolerance, double); - - // For debug - void PrintOptions(); - - // I dont want to verify inputs information - virtual void VerifyInputInformation() { } - - protected: - RelativePositionDataBaseBuilderFilter(); - virtual ~RelativePositionDataBaseBuilderFilter() {} - - PixelType m_BackgroundValue; - PixelType m_ForegroundValue; - - ImagePointer m_Support; - ImagePointer m_Object; - ImagePointer m_Target; - - std::string m_SupportName; - std::string m_TargetName; - std::vector m_ObjectNames; - - int m_NumberOfAngles; - std::vector m_ListOfAngles; - std::vector m_ListOfDirections; - - int m_NumberOfBins; - double m_AreaLossTolerance; - - virtual void GenerateOutputInformation(); - virtual void GenerateInputRequestedRegion(); - virtual void GenerateData(); - - typename FloatImageType::Pointer - ComputeFuzzyMap(ImageType * object, ImageType * target, double angle); - - void - ComputeOptimalThresholds(FloatImageType * map, ImageType * target, int bins, double tolerance, - double & threshold, double & reverseThreshold); - private: - RelativePositionDataBaseBuilderFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - }; // end class - //-------------------------------------------------------------------- - -} // end namespace clitk -//-------------------------------------------------------------------- - -#include "clitkRelativePositionDataBaseBuilderFilter.txx" - -#endif diff --git a/itk/clitkRelativePositionDataBaseBuilderFilter.txx b/itk/clitkRelativePositionDataBaseBuilderFilter.txx deleted file mode 100644 index 95a4e73..0000000 --- a/itk/clitkRelativePositionDataBaseBuilderFilter.txx +++ /dev/null @@ -1,159 +0,0 @@ -/*========================================================================= - Program: vv http://www.creatis.insa-lyon.fr/rio/vv - - Authors belong to: - - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://www.centreleonberard.fr - - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the copyright notices for more information. - - It is distributed under dual licence - - - BSD See included LICENSE.txt file - - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ===========================================================================**/ - -//-------------------------------------------------------------------- -template -clitk::RelativePositionDataBaseBuilderFilter:: -RelativePositionDataBaseBuilderFilter(): - clitk::FilterBase(), - clitk::FilterWithAnatomicalFeatureDatabaseManagement(), - itk::ImageToImageFilter() -{ - this->SetNumberOfRequiredInputs(0); // support - VerboseFlagOff(); - SetBackgroundValue(0); - SetForegroundValue(1); - SetNumberOfBins(100); - SetNumberOfAngles(4); - SetAreaLossTolerance(0.01); - m_ListOfAngles.clear(); - // SetSupportSize(0); - // SetTargetSize(0); - // SetSizeWithThreshold(0); - // SetSizeWithReverseThreshold(0); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -void -clitk::RelativePositionDataBaseBuilderFilter:: -PrintOptions() -{ - DD("TODO"); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -void -clitk::RelativePositionDataBaseBuilderFilter:: -GenerateOutputInformation() -{ - // ImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); - // ImagePointer outputImage = this->GetOutput(0); - // outputImage->SetRegions(outputImage->GetLargestPossibleRegion()); -} -//-------------------------------------------------------------------- - - -//-------------------------------------------------------------------- -template -void -clitk::RelativePositionDataBaseBuilderFilter:: -GenerateInputRequestedRegion() -{ - // Call default - // itk::ImageToImageFilter::GenerateInputRequestedRegion(); - // // Get input pointers and set requested region to common region - // ImagePointer input1 = dynamic_cast(itk::ProcessObject::GetInput(0)); - // input1->SetRequestedRegion(input1->GetLargestPossibleRegion()); -} -//-------------------------------------------------------------------- - -//-------------------------------------------------------------------- -template -void -clitk::RelativePositionDataBaseBuilderFilter:: -GenerateData() -{ - // Load database of anatomical elements - this->LoadAFDB(); - - // Get some information - std::string patient = this->GetAFDB()->GetTagValue("PatientID"); - - // Get input pointers - m_Support = this->GetAFDB()->template GetImage (GetSupportName()); - m_Target = this->GetAFDB()->template GetImage (GetTargetName()); - - // Build the list of tested directions - m_ListOfAngles.clear(); - for(int i=0; i180) a = 180-a; - m_ListOfAngles.push_back(clitk::deg2rad(a)); - RelativePositionDirectionType r; - r.angle1 = clitk::deg2rad(a); - r.angle2 = 0; - r.notFlag = false; - m_ListOfDirections.push_back(r); // only one direction - } - - - // Perform the RelativePositionAnalyzerFilter for each objects - typedef typename clitk::RelativePositionAnalyzerFilter FilterType; - for (int i=0; iGetAFDB()->template GetImage (GetObjectName(i)); - - for (unsigned int j=0; jSetInputSupport(m_Support); - filter->SetInputTarget(m_Target); - filter->SetInputObject(m_Object); // FIXME do AndNot before + only compute supportSize once. - filter->SetNumberOfBins(GetNumberOfBins()); - filter->SetAreaLossTolerance(GetAreaLossTolerance()); - filter->SetDirection(direction); - filter->Update(); - - // Results - std::ostringstream s; - s << patient << " " - << GetSupportName() << " " - // << GetTargetName() << " " // No need - << GetObjectName(i) <<" "; - // Normal - // if (filter->GetInfo().sizeAfterThreshold != filter->GetInfo().sizeBeforeThreshold) { - std::ostringstream os; - os << s.str(); - direction.notFlag = false; - direction.Print(os); - filter->GetInfo().Print(os); - std::cout << os.str() << std::endl; - // } - // Inverse - // if (filter->GetInfoReverse().sizeAfterThreshold != filter->GetInfoReverse().sizeBeforeThreshold) { - std::ostringstream oos; - oos << s.str(); - direction.notFlag = true; - direction.Print(oos); - filter->GetInfoReverse().Print(oos); - std::cout << oos.str() << std::endl; - // } - } // end direction - - } // end object -} -//-------------------------------------------------------------------- - - -- 2.47.1