#include <ContourExtractData.h>
Public Member Functions | |
ContourExtractData (bool imagesResults=false) | |
~ContourExtractData () | |
void | SetImage (vtkImageData *imagedata) |
void | SetZtoBeAnalys (int z) |
void | SetLstManualContourModel (std::vector< manualContourModel * > lstManConMod) |
void | GetValuesInsideCrown (std::vector< double > *pLstValue, std::vector< double > *pLstValuePosX, std::vector< double > *pLstValuePosY, std::vector< double > *pLstValuePosZ) |
void | CalculateImageResult () |
vtkImageData * | GetVtkImageValueResult () |
vtkImageData * | GetVtkImageMaskResult () |
void | Statistics (std::vector< double > *inputLstValue, int grayRangeMin, int grayRangeMax, int *rCountRange, int *rsize, double *rmin, double *rmax, double *raverage, double *rstandardeviation) |
void | SetTypeOperation (int type) |
Private Member Functions | |
bool | isInside (int x, int y, int typeOperation) |
void | GetMinMaxPoint (int *minPoint, int *maxPoint, manualContourModel *manualcontourmodel) |
void | GetMinMaxPoint_Of_LstManConMod (int *minPoint, int *maxPoint) |
int | AnalisisContourInside (int x, int y, manualContourModel *manualcontourmodel) |
double | GetDataValue (int x, int y, int z) |
void | ResetImageResult (int z) |
void | PutVtkImageDataResultValue (int x, int y, int z, double value) |
void | InitVtkImagesResult () |
Private Attributes | |
bool | okImagesResults |
std::vector< manualContourModel * > | lstManConMod |
int | _typeOperation |
int | zImage |
vtkImageData * | imagedata |
vtkImageData * | imagedataValueResult |
vtkImageData * | imagedataMaskResult |
Definition at line 11 of file ContourExtractData.h.
ContourExtractData::ContourExtractData | ( | bool | imagesResults = false |
) |
Definition at line 6 of file ContourExtractData.cxx.
References _typeOperation, imagedata, imagedataMaskResult, and imagedataValueResult.
00007 { 00008 this->imagedata = NULL; 00009 imagedataValueResult = NULL; 00010 imagedataMaskResult = NULL; 00011 this->okImagesResults = okImagesResults; 00012 _typeOperation = 0; 00013 }
ContourExtractData::~ContourExtractData | ( | ) |
int ContourExtractData::AnalisisContourInside | ( | int | x, | |
int | y, | |||
manualContourModel * | manualcontourmodel | |||
) | [private] |
Definition at line 89 of file ContourExtractData.cxx.
References manualContourModel::GetNumberOfPointsSpline(), manualContourModel::GetSpline_i_Point(), and manualContourModel::UpdateSpline().
Referenced by isInside().
00093 { 00094 int result = 0; 00095 int i; 00096 //int np = manualcontourmodel->GetSizeLstPoints( ); // number of control points // JPRx 00097 00098 // JSTG 26-02-08 --------------------------------------------------------------------------------------- 00099 //int nps = manualviewbaseecontour->GetNumberOfPointsSpline(); // number of points in the spline 00100 int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline 00101 //double x1,y1,z1,x2,y2,z2,t; 00102 double x1,y1,z1,x2,y2,z2; 00103 double xx1, yy1,xx2, yy2; 00104 //double delta=( double ) ( np ) / ( double ) ( nps ); 00105 manualcontourmodel->UpdateSpline(); 00106 //------------------------------------------------------------------------------------------------------ 00107 double d; 00108 bool ok; 00109 // if (np>=2) 00110 // { 00111 // JSTG 26-02-08 --------------------------------------------------------------------------------------- 00112 nps--; 00113 //manualcontourmodel->GetSplinePoint(0,x1,y1,z1); 00114 manualcontourmodel->GetSpline_i_Point(0,&x1,&y1,&z1); 00115 for (i=1; i<=nps; i++) 00116 { 00117 ok=false; 00118 //t= delta * (double)(i%nps); 00119 //manualcontourmodel->GetSplinePoint(t,x2,y2,z2); 00120 manualcontourmodel->GetSpline_i_Point(i,&x2,&y2,&z2); 00121 //------------------------------------------------------------------------------------------------------ 00122 //by triangle similarity 00123 if ( ((y1<y2)&&(y>=y1)&&(y<y2)) || ((y1>y2)&&(y<=y1)&&(y>y2)) ) 00124 { 00125 if (y1<y2) { xx1=x1; yy1=y1; xx2=x2; yy2=y2;} else { xx1=x2; yy1=y2; xx2=x1; yy2=y1; } 00126 d = ( fabs(xx2-xx1)*(y-yy1) ) / (yy2-yy1) ; 00127 if ( ((xx1<xx2)&&(x<(xx1+d))) || ((xx1>xx2)&&(x<(xx1-d))) ) { result++; } 00128 } // if 00129 x1=x2; y1=y2; z1=z2; 00130 } // for i 00131 // } //if 00132 return result; 00133 }
void ContourExtractData::CalculateImageResult | ( | ) |
Definition at line 297 of file ContourExtractData.cxx.
References _typeOperation, GetDataValue(), GetMinMaxPoint_Of_LstManConMod(), imagedataMaskResult, imagedataValueResult, isInside(), okImagesResults, PutVtkImageDataResultValue(), ResetImageResult(), and zImage.
00298 { 00299 if (okImagesResults==true) 00300 { 00301 ResetImageResult(zImage); 00302 00303 int minPoint[2]; 00304 int maxPoint[2]; 00305 int i,j; 00306 double value; 00307 00308 minPoint[0] = 999999; 00309 minPoint[1] = 999999; 00310 maxPoint[0] = -999999; 00311 maxPoint[1] = -999999; 00312 00313 GetMinMaxPoint_Of_LstManConMod(minPoint,maxPoint); 00314 for (j=minPoint[1]; j<maxPoint[1]; j++) 00315 { 00316 for (i=minPoint[0]; i<maxPoint[0]; i++) 00317 { 00318 if (isInside(i,j,_typeOperation)==true) 00319 { 00320 value = GetDataValue(i,j,zImage); 00321 PutVtkImageDataResultValue(i,j,zImage, value ); 00322 } // if 00323 } // for i 00324 } // for j 00325 00326 00327 imagedataValueResult->Modified(); 00328 imagedataMaskResult->Modified(); 00329 } 00330 00331 }
double ContourExtractData::GetDataValue | ( | int | x, | |
int | y, | |||
int | z | |||
) | [private] |
Definition at line 189 of file ContourExtractData.cxx.
References imagedata.
Referenced by CalculateImageResult(), and GetValuesInsideCrown().
00190 { 00191 // wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)wxvtkbaseview; 00192 // int z = (int)wxvtk2dbaseview->GetVtkBaseData()->GetZ(); 00193 //JSTG 13-03-08----- 00194 //EED OJO avec JS _zz = z; 00195 //------------------ 00196 double result; 00197 void *p; 00198 p = imagedata->GetScalarPointer(x,y,z); 00199 00200 if (imagedata->GetScalarType()==VTK_CHAR) 00201 { 00202 char *pp = (char*)p; 00203 result = (double)(*pp); 00204 } 00205 else if (imagedata->GetScalarType()==VTK_SIGNED_CHAR) 00206 { 00207 signed char *pp = (signed char*)p; 00208 result = (double)(*pp); 00209 } 00210 else if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR) 00211 { 00212 unsigned char *pp = (unsigned char*)p; 00213 result = (double)(*pp); 00214 } 00215 else if (imagedata->GetScalarType()==VTK_SHORT) 00216 { 00217 short *pp = (short*)p; 00218 result = (double)(*pp); 00219 } 00220 else if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT) 00221 { 00222 unsigned short *pp = (unsigned short*)p; 00223 result = (double)(*pp); 00224 } 00225 else if (imagedata->GetScalarType()==VTK_INT) 00226 { 00227 int *pp = (int*)p; 00228 result = (double)(*pp); 00229 } 00230 else if (imagedata->GetScalarType()==VTK_UNSIGNED_INT) 00231 { 00232 unsigned int *pp = (unsigned int*)p; 00233 result = (double)(*pp); 00234 } 00235 else if (imagedata->GetScalarType()==VTK_LONG) 00236 { 00237 long *pp = (long*)p; 00238 result = (double)(*pp); 00239 } 00240 else if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG) 00241 { 00242 unsigned long *pp = (unsigned long*)p; 00243 result = (double)(*pp); 00244 } 00245 else if (imagedata->GetScalarType()==VTK_FLOAT) 00246 { 00247 float *pp = (float*)p; 00248 result = (double)(*pp); 00249 } 00250 else if (imagedata->GetScalarType()==VTK_DOUBLE) 00251 { 00252 double *pp = (double*)p; 00253 result = (double)(*pp); 00254 } 00255 00256 return result; 00257 }
void ContourExtractData::GetMinMaxPoint | ( | int * | minPoint, | |
int * | maxPoint, | |||
manualContourModel * | manualcontourmodel | |||
) | [private] |
Definition at line 44 of file ContourExtractData.cxx.
References manualContourModel::GetNumberOfPointsSpline(), manualContourModel::GetSpline_i_Point(), and manualContourModel::UpdateSpline().
Referenced by GetMinMaxPoint_Of_LstManConMod().
00048 { 00049 int i; 00050 //int np = manualcontourmodel->GetSizeLstPoints( ); // number of control points // JPRx 00051 00052 // JSTG 26-02-08 --------------------------------------------------------------------------------------- 00053 //int nps = manualviewbaseecontour->GetNumberOfPointsSpline(); // number of points in the spline 00054 int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline 00055 //------------------------------------------------------------------------------------------------------ 00056 00057 // JSTG 26-02-08 --------------------------------------------------------------------------------------- 00058 //double x,y,z,t; 00059 double x,y,z; 00060 //double delta=( double ) ( np ) / ( double ) ( nps ); 00061 manualcontourmodel->UpdateSpline(); 00062 for (i=0; i<nps; i++) 00063 { 00064 //t= delta * (double)i; 00065 //manualcontourmodel->GetSplinePoint(t,x,y,z); 00066 manualcontourmodel->GetSpline_i_Point(i,&x,&y,&z); 00067 if (x<minPoint[0]){ minPoint[0]=(int)x; } 00068 if (y<minPoint[1]){ minPoint[1]=(int)y; } 00069 if (x>maxPoint[0]){ maxPoint[0]=(int)x; } 00070 if (y>maxPoint[1]){ maxPoint[1]=(int)y; } 00071 } 00072 //------------------------------------------------------------------------------------------------------ 00073 }
void ContourExtractData::GetMinMaxPoint_Of_LstManConMod | ( | int * | minPoint, | |
int * | maxPoint | |||
) | [private] |
Definition at line 76 of file ContourExtractData.cxx.
References GetMinMaxPoint(), and lstManConMod.
Referenced by CalculateImageResult(), and GetValuesInsideCrown().
00080 { 00081 int i,size = lstManConMod.size(); 00082 for(i=0 ; i<size ; i++) 00083 { 00084 GetMinMaxPoint(minPoint,maxPoint,lstManConMod[i]); 00085 } 00086 }
void ContourExtractData::GetValuesInsideCrown | ( | std::vector< double > * | pLstValue, | |
std::vector< double > * | pLstValuePosX, | |||
std::vector< double > * | pLstValuePosY, | |||
std::vector< double > * | pLstValuePosZ | |||
) |
Definition at line 334 of file ContourExtractData.cxx.
References _typeOperation, GetDataValue(), GetMinMaxPoint_Of_LstManConMod(), isInside(), and zImage.
00338 { 00339 pLstValue->clear(); 00340 pLstValuePosX->clear(); 00341 pLstValuePosY->clear(); 00342 pLstValuePosZ->clear(); 00343 00344 // if (okImagesResults==true) 00345 // { 00346 // ResetImageResult(zImage); 00347 // } 00348 00349 int minPoint[2]; 00350 int maxPoint[2]; 00351 int i,j; 00352 double value; 00353 00354 00355 minPoint[0] = 999999; 00356 minPoint[1] = 999999; 00357 maxPoint[0] = -999999; 00358 maxPoint[1] = -999999; 00359 00360 GetMinMaxPoint_Of_LstManConMod(minPoint,maxPoint); 00361 00362 00363 for (j=minPoint[1]; j<maxPoint[1]; j++) 00364 { 00365 for (i=minPoint[0]; i<maxPoint[0]; i++) 00366 { 00367 if (isInside(i,j,_typeOperation)==true) 00368 { 00369 value = GetDataValue(i,j,zImage); 00370 00371 // Borrame 00372 // if (okImagesResults==true){ 00373 // PutVtkImageDataResultValue(i,j,zImage, value ); 00374 // } 00375 00376 pLstValue -> push_back( value ); 00377 pLstValuePosX -> push_back( i ); 00378 pLstValuePosY -> push_back( j ); 00379 pLstValuePosZ -> push_back( -1 ); 00380 } // if 00381 } // for 00382 } // for 00383 00384 00385 // Borrame 00386 // if (this->okImagesResults==true){ 00387 // imagedataValueResult->Modified(); 00388 // imagedataMaskResult->Modified(); 00389 // } 00390 00391 00392 }
vtkImageData * ContourExtractData::GetVtkImageMaskResult | ( | ) |
Definition at line 401 of file ContourExtractData.cxx.
References imagedataMaskResult.
00402 { 00403 return imagedataMaskResult; 00404 }
vtkImageData * ContourExtractData::GetVtkImageValueResult | ( | ) |
Definition at line 396 of file ContourExtractData.cxx.
References imagedataValueResult.
00397 { 00398 return imagedataValueResult; 00399 }
void ContourExtractData::InitVtkImagesResult | ( | ) | [private] |
Definition at line 406 of file ContourExtractData.cxx.
References imagedata, imagedataMaskResult, and imagedataValueResult.
Referenced by SetImage().
00407 { 00408 int ext[6]; 00409 int newDim[3]; 00410 double spc[3]; 00411 int scalartype; 00412 00413 imagedata->GetSpacing(spc); 00414 imagedata->GetExtent(ext); 00415 newDim[0]=ext[1]-ext[0]+1; 00416 newDim[1]=ext[3]-ext[2]+1; 00417 newDim[2]=ext[5]-ext[4]+1; 00418 scalartype = imagedata->GetScalarType(); 00419 00420 if (imagedataValueResult!=NULL) 00421 { 00422 imagedataValueResult->Delete(); 00423 } 00424 imagedataValueResult = vtkImageData::New(); 00425 // imagedataValueResult->SetScalarType(scalartype); 00426 imagedataValueResult->SetScalarTypeToUnsignedShort(); 00427 imagedataValueResult->SetSpacing(spc); 00428 imagedataValueResult->SetDimensions( newDim ); 00429 imagedataValueResult->AllocateScalars(); 00430 00431 if (imagedataMaskResult!=NULL) 00432 { 00433 imagedataMaskResult->Delete(); 00434 } 00435 imagedataMaskResult = vtkImageData::New(); 00436 // imagedataMaskResult->SetScalarType(scalartype); 00437 imagedataMaskResult->SetScalarTypeToUnsignedShort(); 00438 imagedataMaskResult->SetSpacing(spc); 00439 imagedataMaskResult->SetDimensions( newDim ); 00440 imagedataMaskResult->AllocateScalars(); 00441 }
bool ContourExtractData::isInside | ( | int | x, | |
int | y, | |||
int | typeOperation | |||
) | [private] |
Definition at line 138 of file ContourExtractData.cxx.
References AnalisisContourInside(), imagedata, and lstManConMod.
Referenced by CalculateImageResult(), and GetValuesInsideCrown().
00139 { 00140 bool result = false; 00141 int numberLeft = 0; 00142 int i,size = this->lstManConMod.size(); 00143 int numberInside = 0; 00144 00145 int ext[6]; 00146 imagedata->GetExtent(ext); 00147 00148 if ((x>=0) && (x<=ext[1]) && (y>=0) && (y<=ext[3])) 00149 { 00150 00151 if (typeOperation==0) // AND Intersection 00152 { 00153 for (i=0;i<size;i++) 00154 { 00155 numberLeft = AnalisisContourInside(x,y, lstManConMod[i] ); 00156 if ( (numberLeft % 2) ==1){ numberInside++; } 00157 } 00158 if ( numberInside == (size) ){ result=true; } 00159 } // AND Intersection 00160 00161 00162 if (typeOperation==1) // OR All 00163 { 00164 for (i=0;i<size;i++) 00165 { 00166 numberLeft = AnalisisContourInside(x,y, lstManConMod[i] ); 00167 if ( (numberLeft % 2) ==1){ result=true; } 00168 } 00169 } // OR All 00170 00171 if (typeOperation==2) // XOR crown 00172 { 00173 for (i=0;i<size;i++) 00174 { 00175 numberLeft = numberLeft + AnalisisContourInside(x,y, lstManConMod[i] ); 00176 } 00177 if ( numberLeft % 2 ==1){ result = true; } 00178 }// XOR crown 00179 00180 00181 00182 } 00183 00184 return result; 00185 }
void ContourExtractData::PutVtkImageDataResultValue | ( | int | x, | |
int | y, | |||
int | z, | |||
double | value | |||
) | [private] |
Definition at line 261 of file ContourExtractData.cxx.
References imagedataMaskResult, and imagedataValueResult.
Referenced by CalculateImageResult().
00262 { 00263 unsigned short *pValue; 00264 unsigned short *pMask; 00265 pValue = (unsigned short *)imagedataValueResult->GetScalarPointer(x,y,z); 00266 pMask = (unsigned short *)imagedataMaskResult->GetScalarPointer(x,y,z); 00267 *pMask = 255; 00268 *pValue = (unsigned short)value; 00269 }
void ContourExtractData::ResetImageResult | ( | int | z | ) | [private] |
Definition at line 272 of file ContourExtractData.cxx.
References imagedataMaskResult, imagedataValueResult, and okImagesResults.
Referenced by CalculateImageResult().
00273 { 00274 if (okImagesResults==true) 00275 { 00276 unsigned short *pValue; 00277 unsigned short *pMask; 00278 pValue = (unsigned short *)imagedataValueResult->GetScalarPointer(0,0,z); 00279 pMask = (unsigned short *)imagedataMaskResult->GetScalarPointer(0,0,z); 00280 00281 int ext[6]; 00282 imagedataValueResult->GetExtent(ext); 00283 00284 int i,size = (ext[1]-ext[0]+1) * (ext[3]-ext[2]+1); 00285 for(i=0; i<size; i++) 00286 { 00287 *pMask = 0; 00288 *pValue = 0; 00289 pMask++; 00290 pValue++; 00291 }// for 00292 } // if 00293 }
void ContourExtractData::SetImage | ( | vtkImageData * | imagedata | ) |
Definition at line 23 of file ContourExtractData.cxx.
References InitVtkImagesResult(), and okImagesResults.
00024 { 00025 this->imagedata = imagedata; 00026 if (this->okImagesResults==true){ 00027 InitVtkImagesResult(); 00028 } 00029 }
void ContourExtractData::SetLstManualContourModel | ( | std::vector< manualContourModel * > | lstManConMod | ) |
Definition at line 37 of file ContourExtractData.cxx.
00038 { 00039 this->lstManConMod = lstManConMod; 00040 }
void ContourExtractData::SetTypeOperation | ( | int | type | ) |
Definition at line 506 of file ContourExtractData.cxx.
References _typeOperation.
00507 { 00508 _typeOperation=type; 00509 }
void ContourExtractData::SetZtoBeAnalys | ( | int | z | ) |
Definition at line 31 of file ContourExtractData.cxx.
References zImage.
00032 { 00033 this->zImage = z; 00034 }
void ContourExtractData::Statistics | ( | std::vector< double > * | inputLstValue, | |
int | grayRangeMin, | |||
int | grayRangeMax, | |||
int * | rCountRange, | |||
int * | rsize, | |||
double * | rmin, | |||
double * | rmax, | |||
double * | raverage, | |||
double * | rstandardeviation | |||
) |
Definition at line 446 of file ContourExtractData.cxx.
References min.
00455 { 00456 double min = 0; 00457 double max = 0; 00458 double average = 0; 00459 double standardeviation = 0; 00460 double acum = 0; 00461 int size = 0; 00462 int countRange = 0; 00463 double ng; 00464 00465 if (inputLstValue!=NULL) 00466 { 00467 size=inputLstValue->size(); 00468 if (size>0){ 00469 max=(*inputLstValue)[0]; 00470 min=(*inputLstValue)[0]; 00471 // Average , countRange 00472 int i; 00473 for ( i=0; i<size; i++ ) 00474 { 00475 ng=(*inputLstValue)[i]; 00476 acum = acum + ng; 00477 if (max<ng) max=ng; // Max 00478 if (min>ng) min=ng; // Min 00479 if ((ng>=grayRangeMin) && (ng<=grayRangeMax)) countRange++; // countRange 00480 } 00481 average = acum / size; 00482 00483 // Standar Deviation 00484 acum=0; 00485 double tmp; 00486 for ( i=0; i<size; i++ ) 00487 { 00488 tmp = (*inputLstValue)[i] - average; 00489 acum = acum + tmp*tmp; 00490 } 00491 standardeviation = sqrt(acum/size); 00492 00493 } 00494 } 00495 00496 // OUTPUT 00497 *rsize = size; 00498 *rCountRange = countRange; 00499 *rmin = min; 00500 *rmax = max; 00501 *raverage = average; 00502 *rstandardeviation = standardeviation; 00503 }
int ContourExtractData::_typeOperation [private] |
Definition at line 44 of file ContourExtractData.h.
Referenced by CalculateImageResult(), ContourExtractData(), GetValuesInsideCrown(), and SetTypeOperation().
vtkImageData* ContourExtractData::imagedata [private] |
Definition at line 47 of file ContourExtractData.h.
Referenced by ContourExtractData(), GetDataValue(), InitVtkImagesResult(), and isInside().
vtkImageData* ContourExtractData::imagedataMaskResult [private] |
Definition at line 49 of file ContourExtractData.h.
Referenced by CalculateImageResult(), ContourExtractData(), GetVtkImageMaskResult(), InitVtkImagesResult(), PutVtkImageDataResultValue(), and ResetImageResult().
vtkImageData* ContourExtractData::imagedataValueResult [private] |
Definition at line 48 of file ContourExtractData.h.
Referenced by CalculateImageResult(), ContourExtractData(), GetVtkImageValueResult(), InitVtkImagesResult(), PutVtkImageDataResultValue(), and ResetImageResult().
std::vector<manualContourModel*> ContourExtractData::lstManConMod [private] |
Definition at line 43 of file ContourExtractData.h.
Referenced by GetMinMaxPoint_Of_LstManConMod(), and isInside().
bool ContourExtractData::okImagesResults [private] |
Definition at line 42 of file ContourExtractData.h.
Referenced by CalculateImageResult(), ResetImageResult(), and SetImage().
int ContourExtractData::zImage [private] |
Definition at line 46 of file ContourExtractData.h.
Referenced by CalculateImageResult(), GetValuesInsideCrown(), and SetZtoBeAnalys().