]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourPropagation.cxx
creaMaracasVisu Library
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / Contour / ContourPropagation.cxx
1 #include "ContourPropagation.h"
2
3 //Construction
4 ContourPropagation::ContourPropagation()
5 {
6         _propc = new PropContour();
7         _autoc = new AutoControlPoints();
8         _ext2D = new ExtractControlPoints2D();
9         _InX.clear();
10         _InY.clear();
11         _InZ.clear();
12         _sliceKeyContourVec.clear();
13 }
14 //Destruction
15 ContourPropagation::~ContourPropagation()
16 {
17 }
18 //-------------------------------------------------------------------------------------
19 void ContourPropagation::resetAppend()
20 {
21         _InX.clear();
22         _InY.clear();
23         _InZ.clear();
24         _InS.clear();
25         _propc->ResetKeyContours();
26         _sliceKeyContourVec.clear();
27 }
28
29 //-------------------------------------------------------------------------------------
30 bool ContourPropagation::ifSliceKeyContourExist(int slice)
31 {
32         bool result=false;
33         int i,size=_sliceKeyContourVec.size();
34         for (i=0; ((i<size) && (result==false)); i++)
35         {
36                 int temp=_sliceKeyContourVec[i];
37                 if (_sliceKeyContourVec[i]==slice)
38                 {
39                         result=true;
40                 }
41                 if (_sliceKeyContourVec[i]>slice)
42                 {
43                         i=size;
44                 }
45         }
46         return result;
47 }
48
49 //-------------------------------------------------------------------------------------
50 void ContourPropagation::OrdenarSliceKeyContourVec()
51 {
52         int i,j,tmp,size=_sliceKeyContourVec.size();
53         for (i=0;i<size;i++)
54         {
55                 for (j=0;j<size;j++)
56                 {
57                         if (_sliceKeyContourVec[i]<_sliceKeyContourVec[j])
58                         {
59                                 tmp=_sliceKeyContourVec[i];
60                                 _sliceKeyContourVec[i]=_sliceKeyContourVec[j];
61                                 _sliceKeyContourVec[j]=tmp;
62                         }
63                 }
64         }
65 }
66
67 //-------------------------------------------------------------------------------------
68 void ContourPropagation::appendContour(std::vector<double>*InX,std::vector<double>*InY,std::vector<double>*InZ)
69 {
70 /*
71         vectorFunctions *vf = new vectorFunctions();
72         vf->copyVector(InX,&_InX);
73         vf->copyVector(InY,&_InY);
74         vf->copyVector(InZ,&_InZ);
75         delete vf;
76 */
77
78
79         int i,size = InX->size();
80         if(size != 0)
81         {
82                 _sliceKeyContourVec.push_back( (*InZ)[0] );
83                 OrdenarSliceKeyContourVec();
84                 for(i=0; i<size; i++)
85                 {
86                         _InX.push_back( (*InX)[i] );
87                         _InY.push_back( (*InY)[i] );
88                         _InZ.push_back( (*InZ)[i] );
89                 }
90         }
91
92         _InS.push_back(InX->size());
93         _propc->SetKeyContours(InX,InY,InZ);
94 }
95 //-------------------------------------------------------------------------------------
96 //TEST CLASS FOR BBTK
97 void ContourPropagation::appendContour()
98 {
99         _InX.clear();
100         _InY.clear();
101         _InZ.clear();
102         _InS.clear();
103         _propc->ResetKeyContours();
104         FILE* fd;
105         fd = fopen("C:/bbtk_JS/data/SavedContours.txt","r");
106         _propc->ReadKeyContour( fd );
107         fclose(fd);
108         _propc->GetKeyContours(&_InX,&_InY,&_InZ,&_InS);
109 }
110 //-------------------------------------------------------------------------------------
111 bool ContourPropagation::mustOrderAppend()
112 {
113         bool orderA = true;
114         bool orderD = true;
115         bool mustOrder = false;
116         int i,j;
117
118         if(_InS.size()>2)
119         {
120                 //ASCENDING
121                 j=0;
122                 for(i=0; i<_InS.size()-1; i++)
123                 {
124                         if(_InZ[j]>_InZ[j+_InS[i]])
125                         {
126                                 orderA = false;
127                         }
128                         j = j+_InS[i];
129                 }
130                 //DESCENDING
131                 if(orderA == false)
132                 {
133                         j=0;
134                         for(i=0; i<_InS.size()-1; i++)
135                         {
136                                 if(_InZ[j]<_InZ[j+_InS[i]])
137                                 {
138                                         orderD = false;
139                                 }
140                                 j =     j+_InS[i];
141                         }
142                 }
143                 //IS ORGANIZED
144                 if((orderD == false) || (orderA == false))
145                 {
146                         mustOrder = true;
147                 }
148                 else
149                 {
150                         mustOrder = false;
151                 }
152                 return mustOrder;
153         }
154         return mustOrder;
155 }
156 //-------------------------------------------------------------------------------------
157 void ContourPropagation::orderAppend()
158 {
159         int i,j,cont,cont2;
160         std::vector<double> tempX;
161         std::vector<double> tempY;
162         std::vector<double> tempZ;
163         std::vector<int> tempS;
164         tempX.clear();
165         tempY.clear();
166         tempZ.clear();
167         tempS.clear();
168         
169         bool mustOrder = mustOrderAppend();
170
171         while( mustOrder == true )
172         {
173                 tempX.clear();
174                 tempY.clear();
175                 tempZ.clear();
176                 tempS.clear();
177                 cont = 0;
178                 for(i=0; i<_InS.size()-1; i++)
179                 {
180                         if(_InZ[cont]<_InZ[cont+_InS[i]])
181                         {
182                                 cont2 = cont;
183                                 for(j=0; j<_InS[i]; j++)
184                                 {
185                                         tempX.push_back( _InX[cont2] );
186                                         tempY.push_back( _InY[cont2] );
187                                         tempZ.push_back( _InZ[cont2] );
188                                         cont2++;
189                                 }
190                                 tempS.push_back( _InS[1] );
191                         }
192                         if(_InZ[cont]>_InZ[cont+_InS[i]])
193                         {
194                                 cont2 = cont+_InS[i];
195                                 for(j=0; j<_InS[i+1]; j++)
196                                 {
197                                         tempX.push_back( _InX[cont2] );
198                                         tempY.push_back( _InY[cont2] );
199                                         tempZ.push_back( _InZ[cont2] );
200                                         cont2++;
201                                 }
202                                 tempS.push_back( _InS[i+1] );
203                                 cont2 = cont;
204                                 for(j=0; j<_InS[i]; j++)
205                                 {
206                                         tempX.push_back( _InX[cont2] );
207                                         tempY.push_back( _InY[cont2] );
208                                         tempZ.push_back( _InZ[cont2] );
209                                         cont2++;
210                                 }
211                                 tempS.push_back( _InS[i] );
212                         }
213                         cont = cont + _InS[i];
214                 }
215                 _InX.clear();
216                 _InY.clear();
217                 _InZ.clear();   
218                 _InS.clear();
219                 vectorFunctions *vf = new vectorFunctions();
220                 vf->copyVector(&tempX,&_InX);
221                 vf->copyVector(&tempY,&_InY);
222                 vf->copyVector(&tempZ,&_InZ);
223                 delete vf;
224                 for(i=0; i<tempS.size(); i++)
225                 {
226                         _InS.push_back(tempS[i]);
227                 }
228                 mustOrder = mustOrderAppend();
229         }
230
231 }
232 //-------------------------------------------------------------------------------------
233 void ContourPropagation::CalculeSplinePropagation()
234 {
235         //_propc->SetKeyContours(&_InX,&_InY,&_InZ);
236         _propc->GetKeyContours(&_InX,&_InY,&_InZ,&_InS);
237         _propc->CalculeSplinePropagation();
238 }
239
240 //-------------------------------------------------------------------------------------
241 int ContourPropagation::FindIdWithZ(double z)
242 {
243         return _propc->FindIdWithZ(z);
244 }
245
246
247
248 //-------------------------------------------------------------------------------------
249 //INITIAL AUTOMATIC METHOD
250 void ContourPropagation::GetInitialControlPoints(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
251 {
252         _propc->GetIdContour(id,vecX,vecY,vecZ);
253         _ext2D->SetContour(vecX,vecY,vecZ);
254         _ext2D->GetInitialControlPoints(vecX,vecY,vecZ);
255 }
256
257 //-------------------------------------------------------------------------------------
258 //AUTOMATIC METHOD
259 void ContourPropagation::GetControlPoints(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
260 {
261         //_propc->SetKeyContours(&_InX,&_InY,&_InZ);
262 //      _propc->CalculeSplinePropagation();
263         _propc->GetIdContour(id,vecX,vecY,vecZ);
264         _ext2D->SetContour(vecX,vecY,vecZ);
265         _ext2D->GetControlPoints(vecX,vecY,vecZ);
266 }
267
268 //-------------------------------------------------------------------------------------
269 //SAMPLING METHOD
270 void ContourPropagation::GetControlPoints(int id, double samp, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
271 {
272 //      //_propc->SetKeyContours(&_InX,&_InY,&_InZ);
273 //      _propc->GetKeyContours(&_InX,&_InY,&_InZ,&_InS);
274 //      _propc->CalculeSplinePropagation();
275 //      int size = _InX.size();
276         _propc->GetIdContour(id,vecX,vecY,vecZ);
277 //      int size2 = vecX->size();
278         _ext2D->SetContour(vecX,vecY,vecZ);
279         _ext2D->SetSamplingControlPoints(samp);
280         _ext2D->GetSamplingControlPoints(vecX,vecY,vecZ);
281 }
282 //-------------------------------------------------------------------------------------
283 void ContourPropagation::GetContour(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
284 {
285         //orderAppend();
286         _propc->SetKeyContours(&_InX,&_InY,&_InZ);
287         _propc->CalculeSplinePropagation();
288         _propc->GetIdContour(id,vecX,vecY,vecZ);
289 }
290 //-------------------------------------------------------------------------------------
291 //TEST CLASS FOR BBTK
292 vtkImageData* ContourPropagation::GetKeyContours(std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ,std::vector<int>*vecS)
293 {
294         //orderAppend();
295         _propc->GetKeyContours(vecX,vecY,vecZ,vecS);    
296         return _propc->CalculeSplinePropagation();
297 }
298 //-------------------------------------------------------------------------------------
299 void ContourPropagation ::getMaxMinZ(double *minz, double *maxz)
300 {
301         vectorFunctions *vf = new vectorFunctions();
302         vf->minVector(&_InZ,minz);
303         vf->maxVector(&_InZ,maxz);
304         delete vf;
305 }
306 //-------------------------------------------------------------------------------------
307 void ContourPropagation::setInterpolationNumber(int num)
308 {
309         _propc->SetInterpNumber(num);
310 }
311 //-------------------------------------------------------------------------------------
312 //-------------------------------------------------------------------------------------
313 //-------------------------------------------------------------------------------------
314 //-------------------------------------------------------------------------------------
315 //-------------------------------------------------------------------------------------
316