1 #include "ContourPropagation.h"
4 ContourPropagation::ContourPropagation()
6 _propc = new PropContour();
7 _autoc = new AutoControlPoints();
8 _ext2D = new ExtractControlPoints2D();
12 _sliceKeyContourVec.clear();
15 ContourPropagation::~ContourPropagation()
18 //-------------------------------------------------------------------------------------
19 void ContourPropagation::resetAppend()
25 _propc->ResetKeyContours();
26 _sliceKeyContourVec.clear();
29 //-------------------------------------------------------------------------------------
30 bool ContourPropagation::ifSliceKeyContourExist(int slice)
33 int i,size=_sliceKeyContourVec.size();
34 for (i=0; ((i<size) && (result==false)); i++)
36 int temp=_sliceKeyContourVec[i];
37 if (_sliceKeyContourVec[i]==slice)
41 if (_sliceKeyContourVec[i]>slice)
49 //-------------------------------------------------------------------------------------
50 void ContourPropagation::OrdenarSliceKeyContourVec()
52 int i,j,tmp,size=_sliceKeyContourVec.size();
57 if (_sliceKeyContourVec[i]<_sliceKeyContourVec[j])
59 tmp=_sliceKeyContourVec[i];
60 _sliceKeyContourVec[i]=_sliceKeyContourVec[j];
61 _sliceKeyContourVec[j]=tmp;
67 //-------------------------------------------------------------------------------------
68 void ContourPropagation::appendContour(std::vector<double>*InX,std::vector<double>*InY,std::vector<double>*InZ)
71 vectorFunctions *vf = new vectorFunctions();
72 vf->copyVector(InX,&_InX);
73 vf->copyVector(InY,&_InY);
74 vf->copyVector(InZ,&_InZ);
79 int i,size = InX->size();
82 _sliceKeyContourVec.push_back( (*InZ)[0] );
83 OrdenarSliceKeyContourVec();
86 _InX.push_back( (*InX)[i] );
87 _InY.push_back( (*InY)[i] );
88 _InZ.push_back( (*InZ)[i] );
92 _InS.push_back(InX->size());
93 _propc->SetKeyContours(InX,InY,InZ);
95 //-------------------------------------------------------------------------------------
97 void ContourPropagation::appendContour()
103 _propc->ResetKeyContours();
105 fd = fopen("C:/bbtk_JS/data/SavedContours.txt","r");
106 _propc->ReadKeyContour( fd );
108 _propc->GetKeyContours(&_InX,&_InY,&_InZ,&_InS);
110 //-------------------------------------------------------------------------------------
111 bool ContourPropagation::mustOrderAppend()
115 bool mustOrder = false;
122 for(i=0; i<_InS.size()-1; i++)
124 if(_InZ[j]>_InZ[j+_InS[i]])
134 for(i=0; i<_InS.size()-1; i++)
136 if(_InZ[j]<_InZ[j+_InS[i]])
144 if((orderD == false) || (orderA == false))
156 //-------------------------------------------------------------------------------------
157 void ContourPropagation::orderAppend()
160 std::vector<double> tempX;
161 std::vector<double> tempY;
162 std::vector<double> tempZ;
163 std::vector<int> tempS;
169 bool mustOrder = mustOrderAppend();
171 while( mustOrder == true )
178 for(i=0; i<_InS.size()-1; i++)
180 if(_InZ[cont]<_InZ[cont+_InS[i]])
183 for(j=0; j<_InS[i]; j++)
185 tempX.push_back( _InX[cont2] );
186 tempY.push_back( _InY[cont2] );
187 tempZ.push_back( _InZ[cont2] );
190 tempS.push_back( _InS[1] );
192 if(_InZ[cont]>_InZ[cont+_InS[i]])
194 cont2 = cont+_InS[i];
195 for(j=0; j<_InS[i+1]; j++)
197 tempX.push_back( _InX[cont2] );
198 tempY.push_back( _InY[cont2] );
199 tempZ.push_back( _InZ[cont2] );
202 tempS.push_back( _InS[i+1] );
204 for(j=0; j<_InS[i]; j++)
206 tempX.push_back( _InX[cont2] );
207 tempY.push_back( _InY[cont2] );
208 tempZ.push_back( _InZ[cont2] );
211 tempS.push_back( _InS[i] );
213 cont = cont + _InS[i];
219 vectorFunctions *vf = new vectorFunctions();
220 vf->copyVector(&tempX,&_InX);
221 vf->copyVector(&tempY,&_InY);
222 vf->copyVector(&tempZ,&_InZ);
224 for(i=0; i<tempS.size(); i++)
226 _InS.push_back(tempS[i]);
228 mustOrder = mustOrderAppend();
232 //-------------------------------------------------------------------------------------
233 void ContourPropagation::CalculeSplinePropagation()
235 //_propc->SetKeyContours(&_InX,&_InY,&_InZ);
236 _propc->GetKeyContours(&_InX,&_InY,&_InZ,&_InS);
237 _propc->CalculeSplinePropagation();
240 //-------------------------------------------------------------------------------------
241 int ContourPropagation::FindIdWithZ(double z)
243 return _propc->FindIdWithZ(z);
248 //-------------------------------------------------------------------------------------
249 //INITIAL AUTOMATIC METHOD
250 void ContourPropagation::GetInitialControlPoints(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
252 _propc->GetIdContour(id,vecX,vecY,vecZ);
253 _ext2D->SetContour(vecX,vecY,vecZ);
254 _ext2D->GetInitialControlPoints(vecX,vecY,vecZ);
257 //-------------------------------------------------------------------------------------
259 void ContourPropagation::GetControlPoints(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
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);
268 //-------------------------------------------------------------------------------------
270 void ContourPropagation::GetControlPoints(int id, double samp, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
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);
282 //-------------------------------------------------------------------------------------
283 void ContourPropagation::GetContour(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);
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)
295 _propc->GetKeyContours(vecX,vecY,vecZ,vecS);
296 return _propc->CalculeSplinePropagation();
298 //-------------------------------------------------------------------------------------
299 void ContourPropagation ::getMaxMinZ(double *minz, double *maxz)
301 vectorFunctions *vf = new vectorFunctions();
302 vf->minVector(&_InZ,minz);
303 vf->maxVector(&_InZ,maxz);
306 //-------------------------------------------------------------------------------------
307 void ContourPropagation::setInterpolationNumber(int num)
309 _propc->SetInterpNumber(num);
311 //-------------------------------------------------------------------------------------
312 //-------------------------------------------------------------------------------------
313 //-------------------------------------------------------------------------------------
314 //-------------------------------------------------------------------------------------
315 //-------------------------------------------------------------------------------------