]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourPropagation.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / Contour / ContourPropagation.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "ContourPropagation.h"
27
28 //Construction
29 ContourPropagation::ContourPropagation()
30 {
31         _propc = new PropContour();
32         _autoc = new AutoControlPoints();
33         _ext2D = new ExtractControlPoints2D();
34         _InX.clear();
35         _InY.clear();
36         _InZ.clear();
37         _sliceKeyContourVec.clear();
38 }
39 //Destruction
40 ContourPropagation::~ContourPropagation()
41 {
42 }
43 //-------------------------------------------------------------------------------------
44 void ContourPropagation::resetAppend()
45 {
46         _InX.clear();
47         _InY.clear();
48         _InZ.clear();
49         _InS.clear();
50         _propc->ResetKeyContours();
51         _sliceKeyContourVec.clear();
52 }
53
54 //-------------------------------------------------------------------------------------
55 bool ContourPropagation::ifSliceKeyContourExist(int slice)
56 {
57         bool result=false;
58         int i,size=_sliceKeyContourVec.size();
59         for (i=0; ((i<size) && (result==false)); i++)
60         {
61                 //int temp=_sliceKeyContourVec[i]; // JPRx
62                 if (_sliceKeyContourVec[i]==slice)
63                 {
64                         result=true;
65                 }
66                 if (_sliceKeyContourVec[i]>slice)
67                 {
68                         i=size;
69                 }
70         }
71         return result;
72 }
73
74 //-------------------------------------------------------------------------------------
75 void ContourPropagation::OrdenarSliceKeyContourVec()
76 {
77         int i,j,tmp,size=_sliceKeyContourVec.size();
78         for (i=0;i<size;i++)
79         {
80                 for (j=0;j<size;j++)
81                 {
82                         if (_sliceKeyContourVec[i]<_sliceKeyContourVec[j])
83                         {
84                                 tmp=_sliceKeyContourVec[i];
85                                 _sliceKeyContourVec[i]=_sliceKeyContourVec[j];
86                                 _sliceKeyContourVec[j]=tmp;
87                         }
88                 }
89         }
90 }
91
92 //-------------------------------------------------------------------------------------
93 void ContourPropagation::appendContour(std::vector<double>*InX,std::vector<double>*InY,std::vector<double>*InZ)
94 {
95 /*
96         vectorFunctions *vf = new vectorFunctions();
97         vf->copyVector(InX,&_InX);
98         vf->copyVector(InY,&_InY);
99         vf->copyVector(InZ,&_InZ);
100         delete vf;
101 */
102
103
104         int i,size = InX->size();
105         if(size != 0)
106         {
107                 _sliceKeyContourVec.push_back( (*InZ)[0] );
108                 OrdenarSliceKeyContourVec();
109                 for(i=0; i<size; i++)
110                 {
111                         _InX.push_back( (*InX)[i] );
112                         _InY.push_back( (*InY)[i] );
113                         _InZ.push_back( (*InZ)[i] );
114                 }
115         }
116
117         _InS.push_back(InX->size());
118         _propc->SetKeyContours(InX,InY,InZ);
119 }
120 //-------------------------------------------------------------------------------------
121 //TEST CLASS FOR BBTK
122 void ContourPropagation::appendContour()
123 {
124         _InX.clear();
125         _InY.clear();
126         _InZ.clear();
127         _InS.clear();
128         _propc->ResetKeyContours();
129         FILE* fd;
130         fd = fopen("C:/bbtk_JS/data/SavedContours.txt","r");
131         _propc->ReadKeyContour( fd );
132         fclose(fd);
133         _propc->GetKeyContours(&_InX,&_InY,&_InZ,&_InS);
134 }
135 //-------------------------------------------------------------------------------------
136 bool ContourPropagation::mustOrderAppend()
137 {
138         bool orderA = true;
139         bool orderD = true;
140         bool mustOrder = false;
141         int i,j;
142
143         if(_InS.size()>2)
144         {
145                 //ASCENDING
146                 j=0;
147                 for(i=0; i<(int)(_InS.size())-1; i++)
148                 {
149                         if(_InZ[j]>_InZ[j+_InS[i]])
150                         {
151                                 orderA = false;
152                         }
153                         j = j+_InS[i];
154                 }
155                 //DESCENDING
156                 if(orderA == false)
157                 {
158                         j=0;
159                         for(i=0; i<(int)(_InS.size())-1; i++)
160                         {
161                                 if(_InZ[j]<_InZ[j+_InS[i]])
162                                 {
163                                         orderD = false;
164                                 }
165                                 j =     j+_InS[i];
166                         }
167                 }
168                 //IS ORGANIZED
169                 if((orderD == false) || (orderA == false))
170                 {
171                         mustOrder = true;
172                 }
173                 else
174                 {
175                         mustOrder = false;
176                 }
177                 return mustOrder;
178         }
179         return mustOrder;
180 }
181 //-------------------------------------------------------------------------------------
182 void ContourPropagation::orderAppend()
183 {
184         int i,j,cont,cont2;
185         std::vector<double> tempX;
186         std::vector<double> tempY;
187         std::vector<double> tempZ;
188         std::vector<int> tempS;
189         tempX.clear();
190         tempY.clear();
191         tempZ.clear();
192         tempS.clear();
193         
194         bool mustOrder = mustOrderAppend();
195
196         while( mustOrder == true )
197         {
198                 tempX.clear();
199                 tempY.clear();
200                 tempZ.clear();
201                 tempS.clear();
202                 cont = 0;
203                 for(i=0; i<(int)(_InS.size())-1; i++)
204                 {
205                         if(_InZ[cont]<_InZ[cont+_InS[i]])
206                         {
207                                 cont2 = cont;
208                                 for(j=0; j<_InS[i]; j++)
209                                 {
210                                         tempX.push_back( _InX[cont2] );
211                                         tempY.push_back( _InY[cont2] );
212                                         tempZ.push_back( _InZ[cont2] );
213                                         cont2++;
214                                 }
215                                 tempS.push_back( _InS[1] );
216                         }
217                         if(_InZ[cont]>_InZ[cont+_InS[i]])
218                         {
219                                 cont2 = cont+_InS[i];
220                                 for(j=0; j<_InS[i+1]; j++)
221                                 {
222                                         tempX.push_back( _InX[cont2] );
223                                         tempY.push_back( _InY[cont2] );
224                                         tempZ.push_back( _InZ[cont2] );
225                                         cont2++;
226                                 }
227                                 tempS.push_back( _InS[i+1] );
228                                 cont2 = cont;
229                                 for(j=0; j<_InS[i]; j++)
230                                 {
231                                         tempX.push_back( _InX[cont2] );
232                                         tempY.push_back( _InY[cont2] );
233                                         tempZ.push_back( _InZ[cont2] );
234                                         cont2++;
235                                 }
236                                 tempS.push_back( _InS[i] );
237                         }
238                         cont = cont + _InS[i];
239                 }
240                 _InX.clear();
241                 _InY.clear();
242                 _InZ.clear();   
243                 _InS.clear();
244                 vectorFunctions *vf = new vectorFunctions();
245                 vf->copyVector(&tempX,&_InX);
246                 vf->copyVector(&tempY,&_InY);
247                 vf->copyVector(&tempZ,&_InZ);
248                 delete vf;
249                 for(i=0; i<(int)(tempS.size()); i++)
250                 {
251                         _InS.push_back(tempS[i]);
252                 }
253                 mustOrder = mustOrderAppend();
254         }
255
256 }
257 //-------------------------------------------------------------------------------------
258 void ContourPropagation::CalculeSplinePropagation()
259 {
260         //_propc->SetKeyContours(&_InX,&_InY,&_InZ);
261         _propc->GetKeyContours(&_InX,&_InY,&_InZ,&_InS);
262         _propc->CalculeSplinePropagation();
263 }
264
265 //-------------------------------------------------------------------------------------
266 int ContourPropagation::FindIdWithZ(double z)
267 {
268         return _propc->FindIdWithZ(z);
269 }
270
271
272
273 //-------------------------------------------------------------------------------------
274 //INITIAL AUTOMATIC METHOD
275 void ContourPropagation::GetInitialControlPoints(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
276 {
277         _propc->GetIdContour(id,vecX,vecY,vecZ);
278         _ext2D->SetContour(vecX,vecY,vecZ);
279         _ext2D->GetInitialControlPoints(vecX,vecY,vecZ);
280 }
281
282 //-------------------------------------------------------------------------------------
283 //AUTOMATIC METHOD
284 void ContourPropagation::GetControlPoints(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
285 {
286         //_propc->SetKeyContours(&_InX,&_InY,&_InZ);
287 //      _propc->CalculeSplinePropagation();
288         _propc->GetIdContour(id,vecX,vecY,vecZ);
289         _ext2D->SetContour(vecX,vecY,vecZ);
290         _ext2D->GetControlPoints(vecX,vecY,vecZ);
291 }
292
293 //-------------------------------------------------------------------------------------
294 //SAMPLING METHOD
295 void ContourPropagation::GetControlPoints(int id, double samp, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
296 {
297 //      //_propc->SetKeyContours(&_InX,&_InY,&_InZ);
298 //      _propc->GetKeyContours(&_InX,&_InY,&_InZ,&_InS);
299 //      _propc->CalculeSplinePropagation();
300 //      int size = _InX.size();
301         _propc->GetIdContour(id,vecX,vecY,vecZ);
302 //      int size2 = vecX->size();
303         _ext2D->SetContour(vecX,vecY,vecZ);
304         _ext2D->SetSamplingControlPoints(samp);
305         _ext2D->GetSamplingControlPoints(vecX,vecY,vecZ);
306 }
307 //-------------------------------------------------------------------------------------
308 void ContourPropagation::GetContour(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
309 {
310         //orderAppend();
311         _propc->SetKeyContours(&_InX,&_InY,&_InZ);
312         _propc->CalculeSplinePropagation();
313         _propc->GetIdContour(id,vecX,vecY,vecZ);
314 }
315 //-------------------------------------------------------------------------------------
316 //TEST CLASS FOR BBTK
317 vtkImageData* ContourPropagation::GetKeyContours(std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ,std::vector<int>*vecS)
318 {
319         //orderAppend();
320         _propc->GetKeyContours(vecX,vecY,vecZ,vecS);    
321         return _propc->CalculeSplinePropagation();
322 }
323 //-------------------------------------------------------------------------------------
324 void ContourPropagation ::getMaxMinZ(double *minz, double *maxz)
325 {
326         vectorFunctions *vf = new vectorFunctions();
327         vf->minVector(&_InZ,minz);
328         vf->maxVector(&_InZ,maxz);
329         delete vf;
330 }
331 //-------------------------------------------------------------------------------------
332 void ContourPropagation::setInterpolationNumber(int num)
333 {
334         _propc->SetInterpNumber(num);
335 }
336 //-------------------------------------------------------------------------------------
337 //-------------------------------------------------------------------------------------
338 //-------------------------------------------------------------------------------------
339 //-------------------------------------------------------------------------------------
340 //-------------------------------------------------------------------------------------
341