00001 #include "ContourPropagation.h"
00002
00003
00004 ContourPropagation::ContourPropagation()
00005 {
00006 _propc = new PropContour();
00007 _autoc = new AutoControlPoints();
00008 _ext2D = new ExtractControlPoints2D();
00009 _InX.clear();
00010 _InY.clear();
00011 _InZ.clear();
00012 _sliceKeyContourVec.clear();
00013 }
00014
00015 ContourPropagation::~ContourPropagation()
00016 {
00017 }
00018
00019 void ContourPropagation::resetAppend()
00020 {
00021 _InX.clear();
00022 _InY.clear();
00023 _InZ.clear();
00024 _InS.clear();
00025 _propc->ResetKeyContours();
00026 _sliceKeyContourVec.clear();
00027 }
00028
00029
00030 bool ContourPropagation::ifSliceKeyContourExist(int slice)
00031 {
00032 bool result=false;
00033 int i,size=_sliceKeyContourVec.size();
00034 for (i=0; ((i<size) && (result==false)); i++)
00035 {
00036
00037 if (_sliceKeyContourVec[i]==slice)
00038 {
00039 result=true;
00040 }
00041 if (_sliceKeyContourVec[i]>slice)
00042 {
00043 i=size;
00044 }
00045 }
00046 return result;
00047 }
00048
00049
00050 void ContourPropagation::OrdenarSliceKeyContourVec()
00051 {
00052 int i,j,tmp,size=_sliceKeyContourVec.size();
00053 for (i=0;i<size;i++)
00054 {
00055 for (j=0;j<size;j++)
00056 {
00057 if (_sliceKeyContourVec[i]<_sliceKeyContourVec[j])
00058 {
00059 tmp=_sliceKeyContourVec[i];
00060 _sliceKeyContourVec[i]=_sliceKeyContourVec[j];
00061 _sliceKeyContourVec[j]=tmp;
00062 }
00063 }
00064 }
00065 }
00066
00067
00068 void ContourPropagation::appendContour(std::vector<double>*InX,std::vector<double>*InY,std::vector<double>*InZ)
00069 {
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 int i,size = InX->size();
00080 if(size != 0)
00081 {
00082 _sliceKeyContourVec.push_back( (*InZ)[0] );
00083 OrdenarSliceKeyContourVec();
00084 for(i=0; i<size; i++)
00085 {
00086 _InX.push_back( (*InX)[i] );
00087 _InY.push_back( (*InY)[i] );
00088 _InZ.push_back( (*InZ)[i] );
00089 }
00090 }
00091
00092 _InS.push_back(InX->size());
00093 _propc->SetKeyContours(InX,InY,InZ);
00094 }
00095
00096
00097 void ContourPropagation::appendContour()
00098 {
00099 _InX.clear();
00100 _InY.clear();
00101 _InZ.clear();
00102 _InS.clear();
00103 _propc->ResetKeyContours();
00104 FILE* fd;
00105 fd = fopen("C:/bbtk_JS/data/SavedContours.txt","r");
00106 _propc->ReadKeyContour( fd );
00107 fclose(fd);
00108 _propc->GetKeyContours(&_InX,&_InY,&_InZ,&_InS);
00109 }
00110
00111 bool ContourPropagation::mustOrderAppend()
00112 {
00113 bool orderA = true;
00114 bool orderD = true;
00115 bool mustOrder = false;
00116 int i,j;
00117
00118 if(_InS.size()>2)
00119 {
00120
00121 j=0;
00122 for(i=0; i<(int)(_InS.size())-1; i++)
00123 {
00124 if(_InZ[j]>_InZ[j+_InS[i]])
00125 {
00126 orderA = false;
00127 }
00128 j = j+_InS[i];
00129 }
00130
00131 if(orderA == false)
00132 {
00133 j=0;
00134 for(i=0; i<(int)(_InS.size())-1; i++)
00135 {
00136 if(_InZ[j]<_InZ[j+_InS[i]])
00137 {
00138 orderD = false;
00139 }
00140 j = j+_InS[i];
00141 }
00142 }
00143
00144 if((orderD == false) || (orderA == false))
00145 {
00146 mustOrder = true;
00147 }
00148 else
00149 {
00150 mustOrder = false;
00151 }
00152 return mustOrder;
00153 }
00154 return mustOrder;
00155 }
00156
00157 void ContourPropagation::orderAppend()
00158 {
00159 int i,j,cont,cont2;
00160 std::vector<double> tempX;
00161 std::vector<double> tempY;
00162 std::vector<double> tempZ;
00163 std::vector<int> tempS;
00164 tempX.clear();
00165 tempY.clear();
00166 tempZ.clear();
00167 tempS.clear();
00168
00169 bool mustOrder = mustOrderAppend();
00170
00171 while( mustOrder == true )
00172 {
00173 tempX.clear();
00174 tempY.clear();
00175 tempZ.clear();
00176 tempS.clear();
00177 cont = 0;
00178 for(i=0; i<(int)(_InS.size())-1; i++)
00179 {
00180 if(_InZ[cont]<_InZ[cont+_InS[i]])
00181 {
00182 cont2 = cont;
00183 for(j=0; j<_InS[i]; j++)
00184 {
00185 tempX.push_back( _InX[cont2] );
00186 tempY.push_back( _InY[cont2] );
00187 tempZ.push_back( _InZ[cont2] );
00188 cont2++;
00189 }
00190 tempS.push_back( _InS[1] );
00191 }
00192 if(_InZ[cont]>_InZ[cont+_InS[i]])
00193 {
00194 cont2 = cont+_InS[i];
00195 for(j=0; j<_InS[i+1]; j++)
00196 {
00197 tempX.push_back( _InX[cont2] );
00198 tempY.push_back( _InY[cont2] );
00199 tempZ.push_back( _InZ[cont2] );
00200 cont2++;
00201 }
00202 tempS.push_back( _InS[i+1] );
00203 cont2 = cont;
00204 for(j=0; j<_InS[i]; j++)
00205 {
00206 tempX.push_back( _InX[cont2] );
00207 tempY.push_back( _InY[cont2] );
00208 tempZ.push_back( _InZ[cont2] );
00209 cont2++;
00210 }
00211 tempS.push_back( _InS[i] );
00212 }
00213 cont = cont + _InS[i];
00214 }
00215 _InX.clear();
00216 _InY.clear();
00217 _InZ.clear();
00218 _InS.clear();
00219 vectorFunctions *vf = new vectorFunctions();
00220 vf->copyVector(&tempX,&_InX);
00221 vf->copyVector(&tempY,&_InY);
00222 vf->copyVector(&tempZ,&_InZ);
00223 delete vf;
00224 for(i=0; i<(int)(tempS.size()); i++)
00225 {
00226 _InS.push_back(tempS[i]);
00227 }
00228 mustOrder = mustOrderAppend();
00229 }
00230
00231 }
00232
00233 void ContourPropagation::CalculeSplinePropagation()
00234 {
00235
00236 _propc->GetKeyContours(&_InX,&_InY,&_InZ,&_InS);
00237 _propc->CalculeSplinePropagation();
00238 }
00239
00240
00241 int ContourPropagation::FindIdWithZ(double z)
00242 {
00243 return _propc->FindIdWithZ(z);
00244 }
00245
00246
00247
00248
00249
00250 void ContourPropagation::GetInitialControlPoints(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
00251 {
00252 _propc->GetIdContour(id,vecX,vecY,vecZ);
00253 _ext2D->SetContour(vecX,vecY,vecZ);
00254 _ext2D->GetInitialControlPoints(vecX,vecY,vecZ);
00255 }
00256
00257
00258
00259 void ContourPropagation::GetControlPoints(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
00260 {
00261
00262
00263 _propc->GetIdContour(id,vecX,vecY,vecZ);
00264 _ext2D->SetContour(vecX,vecY,vecZ);
00265 _ext2D->GetControlPoints(vecX,vecY,vecZ);
00266 }
00267
00268
00269
00270 void ContourPropagation::GetControlPoints(int id, double samp, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
00271 {
00272
00273
00274
00275
00276 _propc->GetIdContour(id,vecX,vecY,vecZ);
00277
00278 _ext2D->SetContour(vecX,vecY,vecZ);
00279 _ext2D->SetSamplingControlPoints(samp);
00280 _ext2D->GetSamplingControlPoints(vecX,vecY,vecZ);
00281 }
00282
00283 void ContourPropagation::GetContour(int id, std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ)
00284 {
00285
00286 _propc->SetKeyContours(&_InX,&_InY,&_InZ);
00287 _propc->CalculeSplinePropagation();
00288 _propc->GetIdContour(id,vecX,vecY,vecZ);
00289 }
00290
00291
00292 vtkImageData* ContourPropagation::GetKeyContours(std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ,std::vector<int>*vecS)
00293 {
00294
00295 _propc->GetKeyContours(vecX,vecY,vecZ,vecS);
00296 return _propc->CalculeSplinePropagation();
00297 }
00298
00299 void ContourPropagation ::getMaxMinZ(double *minz, double *maxz)
00300 {
00301 vectorFunctions *vf = new vectorFunctions();
00302 vf->minVector(&_InZ,minz);
00303 vf->maxVector(&_InZ,maxz);
00304 delete vf;
00305 }
00306
00307 void ContourPropagation::setInterpolationNumber(int num)
00308 {
00309 _propc->SetInterpNumber(num);
00310 }
00311
00312
00313
00314
00315
00316