1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef clitkLists_txx
19 #define clitkLists_txx
20 #include "clitkLists.h"
27 //---------------------------------------------------------------------
29 //---------------------------------------------------------------------
30 template<class ListItemType>
31 void Lists< ListItemType>::Read(const std::vector<string>& filenames, bool verbose)
35 this->resize(filenames.size());
38 for (unsigned int i=0; i<filenames.size();i++)
39 this->at(i).Read(filenames[i],verbose);
43 //---------------------------------------------------------------------
45 //---------------------------------------------------------------------
46 template<class ListItemType>
47 Lists<itk::FixedArray<double,1> > Lists<ListItemType>::Norm(void)
49 Lists<itk::FixedArray<double,1> > norm;
51 // Normalize the lists
52 for (unsigned int i=0; i<this->size();i++)
53 norm.push_back(this->at(i).Norm());
58 //---------------------------------------------------------------------
59 // ReadPointPairs (specific for DARS- IX point list format)
60 //---------------------------------------------------------------------
61 template<class ListItemType>
63 Lists<ListItemType>::ReadAndConvertPointPairs(const std::vector<std::string>& fileNames, ListType& refList, const typename ImageType::Pointer referenceImage, bool verbose)
67 this->resize(fileNames.size());
69 bool pointWasFound=true;
70 unsigned int pointNumber=0;
71 itk::ContinuousIndex<ValueType, Dimension> item1;
72 std::vector<itk::ContinuousIndex<ValueType, Dimension> > item2(fileNames.size());
73 itk::Point<ValueType, Dimension> point1, point2;
74 unsigned int totalNumberOfPoints=0;
75 std::vector<unsigned int> addedNumberOfPoints,ommittedNumberOfPoints;
76 std::vector<bool> pointIsUnsure(fileNames.size());
77 std::vector<std::vector<bool> > ommittedNumberOfPointsUnsure;
79 // Loop over the points
83 if (verbose) std::cout<<std::endl<<"Processing point number: "<<pointNumber<<"..."<<std::endl;
84 if (verbose) std::cout<<"Point number: "<<pointNumber<<" was found in list number: ";
87 bool veryUnsure=false;
88 for (unsigned int i =0; i< fileNames.size(); i++)
91 pointWasFound=this->at(i).ReadPointPair(fileNames[i],pointNumber,item1,item2[i],veryUnsure);
92 if (verbose && pointWasFound) std::cout<<" "<<i;
95 pointIsUnsure[i]= veryUnsure;
98 if(!pointWasFound) break;
100 if (verbose) std::cout<<std::endl;
102 // The point was found
105 totalNumberOfPoints++;
109 for (unsigned int i =0; i< fileNames.size(); i++)
110 if (pointIsUnsure[i])
116 // At least one of the lists had it tagged as veryUnsure
119 ommittedNumberOfPoints.push_back(pointNumber);
120 ommittedNumberOfPointsUnsure.push_back(pointIsUnsure);
121 if (verbose) std::cout<<"Omitting item "<<pointNumber<<" (very unsure): "<<item1<<" ; "<<item2[0]<<std::endl;
125 addedNumberOfPoints.push_back(pointNumber);
126 // Add the point to all the lists
127 for (unsigned int i =0; i< fileNames.size(); i++)
129 if (verbose) std::cout<<"Adding item "<<pointNumber<<": "<<item1<<" ; "<<item2[i]<<std::endl;
132 referenceImage->TransformContinuousIndexToPhysicalPoint(item1, point1);
133 refList.push_back(point1);
135 referenceImage->TransformContinuousIndexToPhysicalPoint(item2[i], point2);
136 if (verbose) std::cout<<"Converted items "<<pointNumber<<" to points: "<<point1<<" ; "<<point2<<std::endl;
137 this->at(i).push_back(point2);
149 std::cout<<std::endl<<totalNumberOfPoints<<" points processed, "<< ommittedNumberOfPoints.size() <<" points omitted, "<< addedNumberOfPoints.size()<<" points added."<<std::endl;
150 std::cout<<"Added point numbers: "<< std::endl;
151 for (unsigned int i=0; i< addedNumberOfPoints.size();i++)
152 std::cout<<addedNumberOfPoints[i] <<std::endl;
153 std::cout<<"Omitted point numbers: "<< std::endl;
154 for (unsigned int i=0; i< ommittedNumberOfPoints.size();i++)
156 std::cout<<ommittedNumberOfPoints[i] <<"\t";
157 for (unsigned int j=0; j< fileNames.size();j++)
158 std::cout<<ommittedNumberOfPointsUnsure[i][j]<<" ";
159 std::cout<<std::endl;
167 //---------------------------------------------------------------------
169 //---------------------------------------------------------------------
170 template<class ListItemType>
171 void Lists<ListItemType>::Write(const std::vector<std::string> fileNames, const bool verbose)
173 for (unsigned int i =0; i< fileNames.size(); i++)
174 this->at(i).Write(fileNames[i], verbose);