1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "ContourPropagation.h"
29 ContourPropagation::ContourPropagation()
31 _propc = new PropContour();
32 _autoc = new AutoControlPoints();
33 _ext2D = new ExtractControlPoints2D();
37 _sliceKeyContourVec.clear();
40 ContourPropagation::~ContourPropagation()
43 //-------------------------------------------------------------------------------------
44 void ContourPropagation::resetAppend()
50 _propc->ResetKeyContours();
51 _sliceKeyContourVec.clear();
54 //-------------------------------------------------------------------------------------
55 bool ContourPropagation::ifSliceKeyContourExist(int slice)
58 int i,size=_sliceKeyContourVec.size();
59 for (i=0; ((i<size) && (result==false)); i++)
61 //int temp=_sliceKeyContourVec[i]; // JPRx
62 if (_sliceKeyContourVec[i]==slice)
66 if (_sliceKeyContourVec[i]>slice)
74 //-------------------------------------------------------------------------------------
75 void ContourPropagation::OrdenarSliceKeyContourVec()
77 int i,j,tmp,size=_sliceKeyContourVec.size();
82 if (_sliceKeyContourVec[i]<_sliceKeyContourVec[j])
84 tmp=_sliceKeyContourVec[i];
85 _sliceKeyContourVec[i]=_sliceKeyContourVec[j];
86 _sliceKeyContourVec[j]=tmp;
92 //-------------------------------------------------------------------------------------
93 void ContourPropagation::appendContour(std::vector<double>*InX,std::vector<double>*InY,std::vector<double>*InZ)
96 vectorFunctions *vf = new vectorFunctions();
97 vf->copyVector(InX,&_InX);
98 vf->copyVector(InY,&_InY);
99 vf->copyVector(InZ,&_InZ);
104 int i,size = InX->size();
107 _sliceKeyContourVec.push_back( (*InZ)[0] );
108 OrdenarSliceKeyContourVec();
109 for(i=0; i<size; i++)
111 _InX.push_back( (*InX)[i] );
112 _InY.push_back( (*InY)[i] );
113 _InZ.push_back( (*InZ)[i] );
117 _InS.push_back(InX->size());
118 _propc->SetKeyContours(InX,InY,InZ);
120 //-------------------------------------------------------------------------------------
121 //TEST CLASS FOR BBTK
122 void ContourPropagation::appendContour()
128 _propc->ResetKeyContours();
130 fd = fopen("C:/bbtk_JS/data/SavedContours.txt","r");
131 _propc->ReadKeyContour( fd );
133 _propc->GetKeyContours(&_InX,&_InY,&_InZ,&_InS);
135 //-------------------------------------------------------------------------------------
136 bool ContourPropagation::mustOrderAppend()
140 bool mustOrder = false;
147 for(i=0; i<(int)(_InS.size())-1; i++)
149 if(_InZ[j]>_InZ[j+_InS[i]])
159 for(i=0; i<(int)(_InS.size())-1; i++)
161 if(_InZ[j]<_InZ[j+_InS[i]])
169 if((orderD == false) || (orderA == false))
181 //-------------------------------------------------------------------------------------
182 void ContourPropagation::orderAppend()
185 std::vector<double> tempX;
186 std::vector<double> tempY;
187 std::vector<double> tempZ;
188 std::vector<int> tempS;
194 bool mustOrder = mustOrderAppend();
196 while( mustOrder == true )
203 for(i=0; i<(int)(_InS.size())-1; i++)
205 if(_InZ[cont]<_InZ[cont+_InS[i]])
208 for(j=0; j<_InS[i]; j++)
210 tempX.push_back( _InX[cont2] );
211 tempY.push_back( _InY[cont2] );
212 tempZ.push_back( _InZ[cont2] );
215 tempS.push_back( _InS[1] );
217 if(_InZ[cont]>_InZ[cont+_InS[i]])
219 cont2 = cont+_InS[i];
220 for(j=0; j<_InS[i+1]; j++)
222 tempX.push_back( _InX[cont2] );
223 tempY.push_back( _InY[cont2] );
224 tempZ.push_back( _InZ[cont2] );
227 tempS.push_back( _InS[i+1] );
229 for(j=0; j<_InS[i]; j++)
231 tempX.push_back( _InX[cont2] );
232 tempY.push_back( _InY[cont2] );
233 tempZ.push_back( _InZ[cont2] );
236 tempS.push_back( _InS[i] );
238 cont = cont + _InS[i];
244 vectorFunctions *vf = new vectorFunctions();
245 vf->copyVector(&tempX,&_InX);
246 vf->copyVector(&tempY,&_InY);
247 vf->copyVector(&tempZ,&_InZ);
249 for(i=0; i<(int)(tempS.size()); i++)
251 _InS.push_back(tempS[i]);
253 mustOrder = mustOrderAppend();
257 //-------------------------------------------------------------------------------------
258 void ContourPropagation::CalculeSplinePropagation()
260 //_propc->SetKeyContours(&_InX,&_InY,&_InZ);
261 _propc->GetKeyContours(&_InX,&_InY,&_InZ,&_InS);
262 _propc->CalculeSplinePropagation();
265 //-------------------------------------------------------------------------------------
266 int ContourPropagation::FindIdWithZ(double z)
268 return _propc->FindIdWithZ(z);
273 //-------------------------------------------------------------------------------------
274 //INITIAL AUTOMATIC METHOD
275 void ContourPropagation::GetInitialControlPoints(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
277 _propc->GetIdContour(id,vecX,vecY,vecZ);
278 _ext2D->SetContour(vecX,vecY,vecZ);
279 _ext2D->GetInitialControlPoints(vecX,vecY,vecZ);
282 //-------------------------------------------------------------------------------------
284 void ContourPropagation::GetControlPoints(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
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);
293 //-------------------------------------------------------------------------------------
295 void ContourPropagation::GetControlPoints(int id, double samp, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
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);
307 //-------------------------------------------------------------------------------------
308 void ContourPropagation::GetContour(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
311 _propc->SetKeyContours(&_InX,&_InY,&_InZ);
312 _propc->CalculeSplinePropagation();
313 _propc->GetIdContour(id,vecX,vecY,vecZ);
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)
320 _propc->GetKeyContours(vecX,vecY,vecZ,vecS);
321 return _propc->CalculeSplinePropagation();
323 //-------------------------------------------------------------------------------------
324 void ContourPropagation ::getMaxMinZ(double *minz, double *maxz)
326 vectorFunctions *vf = new vectorFunctions();
327 vf->minVector(&_InZ,minz);
328 vf->maxVector(&_InZ,maxz);
331 //-------------------------------------------------------------------------------------
332 void ContourPropagation::setInterpolationNumber(int num)
334 _propc->SetInterpNumber(num);
336 //-------------------------------------------------------------------------------------
337 //-------------------------------------------------------------------------------------
338 //-------------------------------------------------------------------------------------
339 //-------------------------------------------------------------------------------------
340 //-------------------------------------------------------------------------------------