]> Creatis software - clitk.git/blob - registration/clitkSelectPointsGenericFilter.cxx
3754160131484d1aa9e77de4cbfe6081c3a50ad6
[clitk.git] / registration / clitkSelectPointsGenericFilter.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
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.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef clitkSelectPointsGenericFilter_cxx
19 #define clitkSelectPointsGenericFilter_cxx
20
21 /* =================================================
22  * @file   clitkSelectPointsGenericFilter.cxx
23  * @author 
24  * @date   
25  * 
26  * @brief 
27  * 
28  ===================================================*/
29
30 #include "clitkSelectPointsGenericFilter.h"
31
32
33 namespace clitk
34 {
35
36
37   //-----------------------------------------------------------
38   // Constructor
39   //-----------------------------------------------------------
40   SelectPointsGenericFilter::SelectPointsGenericFilter()
41   {
42     m_Verbose=false;
43   }
44
45
46   //-----------------------------------------------------------
47   // Update
48   //-----------------------------------------------------------
49   void SelectPointsGenericFilter::Update()
50   {
51     //-----------------------------
52     // Typedefs
53     //-----------------------------
54     typedef double ValueType;
55     typedef std::vector<ValueType> MeasureListType;
56
57     typedef itk::Point<double, 3> PointType;
58     typedef clitk::List<PointType> PointListType;
59     typedef clitk::Lists<PointType> PointListsType;
60
61    
62     //-----------------------------
63     // Input point lists
64     //-----------------------------   
65     PointListsType pointLists;
66     unsigned int numberOfPoints=0;
67     unsigned int numberOfLists=m_ArgsInfo.input_given;
68     for (unsigned int i=0; i<numberOfLists; i++)
69       {
70         // Read the lists
71         pointLists.push_back(PointListType(m_ArgsInfo.input_arg[i], m_Verbose) );
72
73         // Verify the number of points
74         if (i==0) numberOfPoints=pointLists[i].size();
75         else 
76           {
77             if  (numberOfPoints!=pointLists[i].size())
78               {
79                 std::cerr<<"Size of first list ("<<numberOfPoints
80                          <<") is different from size of list "<<i
81                          <<" ("<<pointLists[i].size()<<")..."<<std::endl;
82                 return;
83               }
84           }
85       }    
86     
87     //-----------------------------
88     // Reference point list
89     //-----------------------------
90     PointListType referencePointList;
91     if (m_Verbose) std::cout<<"Reference point list:"<<std::endl;
92     referencePointList=PointListType(m_ArgsInfo.ref_arg, m_Verbose);
93     if  (numberOfPoints!=referencePointList.size())
94       {
95         std::cerr<<"Size of the first list ("<<numberOfPoints
96                  <<") is different from size of the reference list ("
97                  << referencePointList.size() <<")..."<<std::endl;
98         return;
99       }
100
101     
102     //-----------------------------
103     // Select
104     //-----------------------------
105     PointListType sReferencePointList;
106     PointListsType sPointLists(numberOfLists);
107     unsigned int counter=0;
108     for (unsigned int number=0; number< referencePointList.size(); number++)
109       {
110         for (unsigned int component=0; component< m_ArgsInfo.component_given; component++)
111           {
112             if (  (referencePointList[number][m_ArgsInfo.component_arg[component]] >= m_ArgsInfo.lower_arg[component])
113                   &&  (referencePointList[number][m_ArgsInfo.component_arg[component]] <= m_ArgsInfo.upper_arg[component]) )
114               {
115                 if(m_Verbose) std::cout<<"Selecting point "<<number<<": "<<referencePointList[number]<<std::endl;
116                 sReferencePointList.push_back(referencePointList[number]);
117                 for (unsigned int i=0;i<pointLists.size();i++)
118                   sPointLists[i].push_back(pointLists[i][number]);
119                 counter++;
120               }
121           }
122       }
123     if (m_Verbose) std::cout<<"Selected "<<counter<<" points..."<<std::endl;
124     
125
126     
127     //-----------------------------
128     // Output
129     //-----------------------------
130     sReferencePointList.Write(m_ArgsInfo.sRef_arg,m_Verbose);
131     std::vector<std::string> filenames;
132     for (unsigned int i=0;i<pointLists.size();i++)
133       filenames.push_back(m_ArgsInfo.sInput_arg[i]);
134     sPointLists.Write(filenames,m_Verbose);
135
136   }
137
138
139 } //end clitk
140
141 #endif  //#define clitkSelectPointsGenericFilter_cxx