axisExtractor.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003 
00004 =========================================================================*/
00005 
00006 
00007 #include "vtkPolyData.h"
00008 #include "vtkObjectFactory.h"
00009 
00010 //#include "vtkimagethreshold.h"
00011 //#include "vtkImageCast.h"
00012 //#include "vtkImageSeedConnectivity.h"
00013 //#include "vtkImageData.h"
00014 //#include "vtkMarchingCubes.h"
00015 //#include "vtkDoubleArray.h"
00016 //#include "vtkPointData.h"
00017 //#include "vtkextractvoi.h"
00018 
00019 #include "vtkMath.h"
00020 
00021 
00022 #include "axisExtractor.h"
00023 
00024 #define min(a,b) (((a)<(b))?(a):(b)) 
00025 
00026 
00027 vtkStandardNewMacro(axisExtractor);
00028 
00029 
00030 axisExtractor::axisExtractor() {
00031         
00032         this->NumberOfRequiredInputs = 1;
00033 
00034         this->humbral=0.45 ;
00035         this->maxpropradio=100;
00036         this->maxpropmasa=10;
00037         this->minpropmasa=0;
00038         
00039         this->resample= vtkImageResample::New();
00040         this->resample->SetDimensionality (3);
00041         
00042         this->extrac = vtkExtractVOI::New();
00043         this->extrac->SetInput(this->resample->GetOutput());
00044         this->extrac->SetSampleRate(1, 1, 1);
00045         
00046         this->thresh = vtkImageThreshold::New();
00047         this->thresh->SetInput(this->extrac->GetOutput());
00048         this->thresh->SetInValue(255);
00049         this->thresh->SetOutValue(0);
00050         this->thresh->ReleaseDataFlagOff();
00051 
00052         this->cast = vtkImageCast::New();
00053         this->cast->SetInput(this->thresh->GetOutput());
00054         this->cast->SetOutputScalarTypeToUnsignedChar();
00055 
00056         this->connect = vtkImageSeedConnectivity::New();
00057         this->connect->SetInput(this->cast->GetOutput());
00058         this->connect->SetInputConnectValue(255);
00059         this->connect->SetOutputConnectedValue(255);
00060         this->connect->SetOutputUnconnectedValue(0);
00061 
00062         this->dataprov=vtkImageData::New();
00063         this->dataprov->SetScalarTypeToChar();
00064 
00065         this->datatotal=vtkImageData::New();
00066         this->datatotal->SetScalarTypeToChar();
00067 
00068         
00069                         
00070 
00071 }
00072 
00073 //----------------------------------------------------------------------------
00074 // Specify the input data or filter.
00075 void axisExtractor::SetInput(vtkImageData *input)
00076 {
00077         double minspac;
00078         double espprin[3];
00079         
00080         
00081         this->vtkProcessObject::SetNthInput(0, input);
00082         this->resample->SetInput(input);
00083         input->GetSpacing(espprin);
00084         
00085 
00086         minspac=min(espprin[0],min(espprin[1],espprin[2]));
00087   
00088 
00089         this->resample->SetAxisOutputSpacing( 0, minspac);
00090         this->resample->SetAxisOutputSpacing( 1, minspac);
00091         this->resample->SetAxisOutputSpacing( 2, minspac);
00092         this->resample->Update();
00093 
00094         
00095 }
00096 
00097 
00098 //----------------------------------------------------------------------------
00099 // Specify the input data or filter.
00100 
00101 void axisExtractor::Execute()
00102 {
00103         this->points = vtkPoints::New();
00104         this->lineas = vtkCellArray::New();
00105         this->buenos=0;
00106         this->iter=0;
00107         this->flagg=0;
00108 
00109         this->datatotal->Delete();
00110         this->datatotal=vtkImageData::New();
00111         this->datatotal->SetScalarTypeToUnsignedChar();
00112 
00113         this->datatotal->SetExtent(this->resample->GetOutput()->GetExtent());
00114         this->datatotal->SetSpacing(this->resample->GetOutput()->GetSpacing());
00115 
00116         this->blanquear2();
00117 
00118         
00119         while( !m_Stack0.empty()){
00120                 this->avanzar();
00121                 this->iter++;
00122         }
00123 
00124 
00125         this->GetOutput()->SetPoints (this->points);
00126         this->GetOutput()->SetLines(this->lineas);
00127         this->GetOutput()->Modified();
00128                         
00129         // this->GetOutput()->GetPointData()->SetVectors(this->salidas);
00130 }
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 //----------------------------------------------------------------------------
00140 // Specify the input data or filter.
00141 vtkImageData *axisExtractor::GetInput()
00142 {
00143         if (this->NumberOfInputs < 1){
00144                 return NULL;
00145     }
00146   
00147         return (vtkImageData *)(this->Inputs[0]);
00148 }
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 //----------------------------------------------------------------------------
00157 // Specify the input data or filter.
00158 vtkImageData *axisExtractor::GetVolumen()
00159 {
00160 
00161         return this->datatotal;
00162 }
00163 
00164 
00165 
00166 
00167 
00168 
00169 //----------------------------------------------------------------------------
00170 void axisExtractor::PrintSelf(ostream& os, vtkIndent indent)
00171 {
00172         this->Superclass::PrintSelf(os,indent);
00173 }
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 //----------------------------------------------------------------------------
00183 void axisExtractor::SetMaxPropRadio(double value)
00184 {
00185         this->maxpropradio=value;
00186 }
00187 
00188 
00189 
00190 //----------------------------------------------------------------------------
00191 double axisExtractor::GetMaxPropRadio()
00192 {
00193         return this->maxpropradio;
00194 }
00195 
00196 
00197   
00198 //----------------------------------------------------------------------------
00199 
00200 void axisExtractor::SetHumbral(double value)
00201 {
00202         this->humbral=value;
00203 }
00204 
00205   
00206   
00207   //----------------------------------------------------------------------------
00208 
00209 double axisExtractor::GetHumbral()
00210 {
00211         return this->humbral;
00212 }
00213 
00214 
00215 //----------------------------------------------------------------------------
00216 
00217 void axisExtractor::SetMaxPropMasa(double value)
00218 {
00219         this->maxpropmasa=value;
00220 }
00221 
00222   
00223   
00224   //----------------------------------------------------------------------------
00225 
00226 double axisExtractor::GetMaxPropMasa()
00227 {
00228         return this->maxpropmasa;
00229 }
00230 
00231 
00232 //----------------------------------------------------------------------------
00233 
00234 void axisExtractor::SetMinPropMasa(double value)
00235 {
00236         this->minpropmasa=value;
00237 }
00238 
00239   
00240   
00241   //----------------------------------------------------------------------------
00242 
00243 double axisExtractor::GetMinPropMasa()
00244 {
00245         return this->minpropmasa;
00246 }
00247 
00248 
00249 
00250 
00251 
00252 
00253 
00254         //----------------------------------------------------------------------------
00255 void axisExtractor::SetPoint(double puntoactualprov[3] )
00256 {
00257 
00258         realtoreal(puntoactualprov,puntoactualprov);
00259 
00260                 
00261         m_Stack0.push(puntoactualprov[0]);
00262         m_Stack1.push(puntoactualprov[1]);
00263         m_Stack2.push(puntoactualprov[2]);
00264         m_Stack3.push(puntoactualprov[0]);
00265         m_Stack4.push(puntoactualprov[1]);
00266         m_Stack5.push(puntoactualprov[2]);
00267         m_Stack.push(0);
00268 
00269 }
00270 
00271 
00272 
00273 
00274 
00275 
00276 
00277 
00278 
00279 //----------------------------------------------------------------------------
00280 void axisExtractor::realtoreal(double a[3], double b[3] )
00281 {
00282                 
00283         double espprin[3];
00284         int extprin[6];                         
00285         
00286         this->resample->GetOutput()->GetSpacing(espprin);
00287         this->resample->GetOutput()->GetExtent(extprin);
00288 
00289         b[0]=a[0]+(espprin[0]*extprin[0]);
00290         b[1]=a[1]+(espprin[1]*extprin[2]);
00291         b[2]=a[2];
00292 
00293         
00294 
00295 }
00296 
00297 
00298 
00299 
00300 //----------------------------------------------------------------------------
00301 void axisExtractor::realtoreal2(double a[3], double b[3] )
00302 {
00303                 
00304         double espprin[3];
00305         int extprin[6];                         
00306         
00307         this->resample->GetOutput()->GetSpacing(espprin);
00308         this->resample->GetOutput()->GetExtent(extprin);
00309 
00310         b[0]=a[0]-(espprin[0]*extprin[0]);
00311         b[1]=a[1]-(espprin[1]*extprin[2]);
00312         b[2]=a[2];
00313 
00314         
00315 
00316 }
00317 
00318 
00319 
00320 
00321 
00322 //----------------------------------------------------------------------------
00323 void axisExtractor::realtoindex(double a[3], int b[3] )
00324 {
00325         double c[3];
00326 
00327         double minspac;
00328 
00329         double espprin[3];
00330         int extprin[6];                         
00331         
00332         this->resample->GetOutput()->GetSpacing(espprin);
00333         this->resample->GetOutput()->GetExtent(extprin);
00334 
00335         minspac=min(espprin[0],min(espprin[1],espprin[2]));
00336                 
00337         c[0]=(a[0]/minspac);
00338         c[1]=(a[1]/minspac);
00339         c[2]=(a[2]/minspac);
00340 
00341         b[0]=(int)(a[0]/minspac);
00342         b[1]=(int)(a[1]/minspac);
00343         b[2]=(int)(a[2]/minspac);
00344 
00345         if(c[0]-b[0]>0.5){
00346                 b[0]+=1;
00347         }
00348         if(c[1]-b[1]>0.5){
00349                 b[1]+=1;
00350         }
00351         if(c[2]-b[2]>0.5){
00352                 b[2]+=1;
00353         }
00354         
00355 
00356 }       
00357 
00358 
00359 
00360 
00361 
00362 
00363 //----------------------------------------------------------------------------
00364 void axisExtractor::indextoreal(int a[3], double b[3] )
00365 {       
00366         double minspac;
00367 
00368         double espprin[3];
00369         int extprin[6];                         
00370         
00371         this->resample->GetOutput()->GetSpacing(espprin);
00372         this->resample->GetOutput()->GetExtent(extprin);
00373 
00374         minspac=min(espprin[0],min(espprin[1],espprin[2]));
00375         
00376         b[0]=(a[0])*minspac;
00377         b[1]=(a[1])*minspac;
00378         b[2]=a[2]*minspac;
00379 }
00380 
00381 
00382 
00383 
00384 
00385 //----------------------------------------------------------------------------
00386 void axisExtractor::indextoreal(double a[3], double b[3] )
00387 {       
00388         double minspac;
00389 
00390         double espprin[3];
00391         int extprin[6];                         
00392         
00393         this->resample->GetOutput()->GetSpacing(espprin);
00394         this->resample->GetOutput()->GetExtent(extprin);
00395 
00396         minspac=min(espprin[0],min(espprin[1],espprin[2]));
00397         
00398         b[0]=(a[0])*minspac;
00399         b[1]=(a[1])*minspac;
00400         b[2]=a[2]*minspac;
00401 }
00402 
00403 
00404 
00405 
00406 //----------------------------------------------------------------------------
00407 void axisExtractor::searc(int i, int j, int k)
00408 {
00409 
00410         unsigned char *ptr;
00411         unsigned char   ptri;
00412         char *ptr2;
00413         
00414         int radio;
00415 
00416         int i2, j2, k2;
00417         int i3, j3, k3;
00418                 
00419         ptr=(unsigned char *)   this->connect->GetOutput()->GetScalarPointer(i,j,k);
00420         ptr2=(char *)   this->dataprov->GetScalarPointer(i,j,k);
00421 
00422         ptri=*ptr;
00423 
00424         int ext[6];
00425         
00426         this->connect->GetOutput()->GetExtent(ext);
00427 
00428         radio=(ext[1]-ext[0])/2;
00429 
00430         i2=i-ext[0]-radio;
00431         j2=j-ext[2]-radio;
00432         k2=k-ext[4]-radio;
00433 
00434 
00435         if(ptri==255){
00436                 *ptr2=this->label;
00437                 this->vector[this->label-1][0]+=1;
00438                 this->vector[this->label-1][1]+=i;
00439                 this->vector[this->label-1][2]+=j;
00440                 this->vector[this->label-1][3]+=k;
00441         }
00442         else if(ptri==0){
00443                 *ptr2=-this->label2;
00444                 this->vectorb[this->label2-1][0]+=1;
00445                 this->vectorb[this->label2-1][1]+=i;
00446                 this->vectorb[this->label2-1][2]+=j;
00447                 this->vectorb[this->label2-1][3]+=k;
00448         }
00449 
00450 
00451         for(i3=-1;i3<=1;i3++){
00452                         for(j3=-1;j3<=1;j3++){
00453                                 for(k3=-1;k3<=1;k3++){
00454                                         if(i+i3>=ext[0] && i+i3<=ext[1] && j+j3>=ext[2] && j+j3<=ext[3] && k+k3>=ext[4] &&  k+k3<=ext[5] ){
00455                                                 ptr=(unsigned char *)   this->connect->GetOutput()->GetScalarPointer(i+i3,j+j3,k+k3);
00456                                                 ptr2=(char *)   this->dataprov->GetScalarPointer(i+i3,j+j3,k+k3);
00457                                                 if(ptri==255 && *ptr==255 && *ptr2==0 && (radio*radio)>=((i2+i3)*(i2+i3))+((j2+j3)*(j2+j3))+((k2+k3)*(k2+k3)) && ((radio-1)*(radio-1))<=((i2+i3)*(i2+i3))+((j2+j3)*(j2+j3))+((k2+k3)*(k2+k3))){
00458                                                         this->searc(i+i3, j+j3, k+k3);
00459                                                 }
00460                                                 else if(ptri==0 && *ptr==0 && *ptr2==0 && (radio*radio)>=((i2+i3)*(i2+i3))+((j2+j3)*(j2+j3))+((k2+k3)*(k2+k3)) && ((radio-1)*(radio-1))<=((i2+i3)*(i2+i3))+((j2+j3)*(j2+j3))+((k2+k3)*(k2+k3))){
00461                                                         this->searc(i+i3, j+j3, k+k3);
00462                                                 }
00463                                         }
00464                                 }
00465                         }
00466                 }
00467 
00468 
00469         
00470 
00471         
00472 }
00473 
00474 
00475 //----------------------------------------------------------------------------
00476 void axisExtractor::find_components( )
00477 {
00478         int ext[6];
00479         int i, j, k, radio;
00480         int i2, j2, k2;
00481 
00482         
00483         unsigned char *ptr;
00484         char *ptr2;
00485 
00486         this->connect->GetOutput()->GetExtent(ext);
00487 
00488 
00489         radio=(ext[1]-ext[0])/2;
00490 
00491         this->label=0;
00492         this->label2=0;
00493                 
00494 
00495 
00496         for(i=ext[0], i2=-radio;i<=ext[1];i++, i2++){
00497                         for(j=ext[2], j2=-radio;j<=ext[3];j++, j2++){
00498                                 for(k=ext[4], k2=-radio;k<=ext[5];k++, k2++){
00499                                         ptr=(unsigned char *)   this->connect->GetOutput()->GetScalarPointer(i,j,k);
00500                                         ptr2=(char *)   this->dataprov->GetScalarPointer(i,j,k);
00501 
00502                                         if(*ptr==255 && *ptr2==0 && (radio*radio)>=(i2*i2)+(j2*j2)+(k2*k2) && ((radio-1)*(radio-1))<=(i2*i2)+(j2*j2)+(k2*k2)  ){
00503                                                 this->label=this->label+1;
00504                                                 this->vector[this->label-1][0]=0;
00505                                                 this->vector[this->label-1][1]=0;
00506                                                 this->vector[this->label-1][2]=0;
00507                                                 this->vector[this->label-1][3]=0;
00508                                                 this->searc(i, j, k);
00509                                                 
00510                                         }
00511                                         else if(*ptr==0 && *ptr2==0 && (radio*radio)>=(i2*i2)+(j2*j2)+(k2*k2) && ((radio-1)*(radio-1))<=(i2*i2)+(j2*j2)+(k2*k2)  ){
00512                                                 this->label2=this->label2+1;
00513                                                 this->vectorb[this->label2-1][0]=0;
00514                                                 this->vectorb[this->label2-1][1]=0;
00515                                                 this->vectorb[this->label2-1][2]=0;
00516                                                 this->vectorb[this->label2-1][3]=0;
00517                                                 this->searc(i, j, k);
00518                                                 
00519                                         }
00520                                 }
00521                         }
00522                 }
00523 
00524 
00525 
00526         
00527 
00528         
00529         
00530 }
00531 
00532 
00533 
00534 
00535 //----------------------------------------------------------------------------
00536 unsigned short axisExtractor::maximo( )
00537 {
00538         int ext[6];
00539         int i, j, k;
00540         unsigned short max=0;
00541 
00542         this->extrac->GetOutput()->GetExtent(ext);
00543 
00544         unsigned short *ptr;
00545         
00546 
00547         for(i=ext[0];i<=ext[1];i++){
00548                         for(j=ext[2];j<=ext[3];j++){
00549                                 for(k=ext[4];k<=ext[5];k++){
00550                                         ptr=(unsigned short *)this->extrac->GetOutput()->GetScalarPointer(i,j,k);
00551                                         if(*ptr>max){
00552                                                 max=*ptr;
00553                                                 
00554                                         }
00555                                 }
00556                         }
00557                 }
00558 
00559                 return max;
00560 
00561 
00562 }
00563 
00564 
00565 
00566 
00567 //----------------------------------------------------------------------------
00568 void axisExtractor::blanquear()
00569 {
00570         int ext[6];
00571         int i, j, k;
00572         
00573         this->dataprov->GetExtent(ext);
00574 
00575         char *ptr;
00576 
00577 
00578 
00579         for(i=ext[0];i<=ext[1];i++){
00580                         for(j=ext[2];j<=ext[3];j++){
00581                                 for(k=ext[4];k<=ext[5];k++){
00582                                         ptr=(char *)    this->dataprov->GetScalarPointer(i,j,k);
00583                                         *ptr=0;
00584                                 }
00585                         }
00586                 }
00587 }
00588 
00589 
00590 
00591 
00592 
00593 
00594 //----------------------------------------------------------------------------
00595 void axisExtractor::blanquear2()
00596 {
00597         int ext[6];
00598         int i, j, k;
00599         
00600         this->datatotal->GetExtent(ext);
00601 
00602         unsigned char *ptr;
00603 
00604 
00605 
00606         for(i=ext[0];i<=ext[1];i++){
00607                         for(j=ext[2];j<=ext[3];j++){
00608                                 for(k=ext[4];k<=ext[5];k++){
00609                                         ptr=(unsigned char *)   this->datatotal->GetScalarPointer(i,j,k);
00610                                         *ptr=0;
00611                                 }
00612                         }
00613                 }
00614 }
00615 
00616 
00617 
00618 
00619 //----------------------------------------------------------------------------
00620 void axisExtractor::copiar(vtkImageData *data, vtkImageData *data2 )
00621 {
00622         int ext[6];
00623         int i, j, k;
00624         
00625         data->GetExtent(ext);
00626 
00627         unsigned char *ptr, *ptr2;
00628 
00629         for(i=ext[0];i<=ext[1];i++){
00630                         for(j=ext[2];j<=ext[3];j++){
00631                                 for(k=ext[4];k<=ext[5];k++){
00632                                         ptr=(unsigned char *)   data->GetScalarPointer(i,j,k);
00633                                         ptr2=(unsigned char *)  data2->GetScalarPointer(i,j,k);
00634                                         if(*ptr!=0 && *ptr2==0){
00635                                                 *ptr2=*ptr;
00636                                         }
00637                                 }
00638                         }
00639                 }
00640 
00641         data2->Modified();
00642 }
00643 
00644 
00645 
00646 
00647 
00648 //----------------------------------------------------------------------------
00649 double axisExtractor::distancia(double a[3], double b[3] )
00650 {
00651         
00652         
00653         return sqrt(((a[0]-b[0])*(a[0]-b[0]))+((a[1]-b[1])*(a[1]-b[1]))+((a[2]-b[2])*(a[2]-b[2])));
00654 }
00655 
00656 
00657 
00658 
00659 
00660 
00661 
00662 
00663 //----------------------------------------------------------------------------
00664 int axisExtractor::envolumen(int a[3], vtkImageData *datae )
00665 {
00666         
00667         int res;
00668 
00669 
00670         unsigned char *ptr;
00671 
00672         
00673         ptr=(unsigned char *)   datae->GetScalarPointer(a);
00674 
00675         if(*ptr==0){
00676                 res=0;
00677         }
00678         else{
00679                 res=1;
00680         }
00681         
00682         
00683         return res;
00684 }
00685 
00686 
00687 
00688 
00689 
00690 
00691 
00692 //----------------------------------------------------------------------------
00693 void axisExtractor::corte(double punto1[3], double punto2[3], double punto3[3], double centro[3],  double radio )
00694 {
00695         
00696         double m1, m2, m3;
00697         double b1, b2, b3;
00698         double c0, c1, c2;
00699         double* roots;
00700         double root;
00701         
00702 
00703         m1=punto2[0]-punto1[0];
00704         m2=punto2[1]-punto1[1];
00705         m3=punto2[2]-punto1[2];
00706 
00707         b1=punto1[0]-centro[0];
00708         b2=punto1[1]-centro[1];
00709         b3=punto1[2]-centro[2];
00710 
00711         c0=m1*m1+m2*m2+m3*m3;
00712         c1=2*m1*b1+2*m2*b2+2*m3*b3;
00713         c2=b1*b1+b2*b2+b3*b3-radio*radio;
00714 
00715         roots=vtkMath::SolveQuadratic  (c0, c1, c2);
00716 
00717         if(roots[1]>=0 && roots[1]<=1){
00718                 root=roots[1];
00719         }
00720         else{
00721                 root=roots[2];
00722         }
00723 
00724         punto3[0]=punto1[0]+root*(punto2[0]-punto1[0]);
00725         punto3[1]=punto1[1]+root*(punto2[1]-punto1[1]);
00726         punto3[2]=punto1[2]+root*(punto2[2]-punto1[2]);
00727                 
00728 }
00729 
00730 
00731 
00732 
00733 
00734 
00735 
00736 
00737 
00738 
00739 
00740 
00741 //----------------------------------------------------------------------------
00742 void axisExtractor::redondear(vtkImageData *data )
00743 {
00744         int ext[6];
00745         int i, j, k, radio;
00746         int i2, j2, k2;
00747 
00748         data->GetExtent(ext);
00749 
00750         unsigned char *ptr;
00751 
00752         radio=(ext[1]-ext[0])/2;
00753 
00754         double tmpsqrt;
00755         for(i=ext[0], i2=-radio;i<=ext[1];i++, i2++){
00756                         for(j=ext[2], j2=-radio;j<=ext[3];j++, j2++){
00757                                 for(k=ext[4], k2=-radio;k<=ext[5];k++, k2++){
00758                                         ptr=(unsigned char *)   data->GetScalarPointer(i,j,k);
00759                                         tmpsqrt =       (i2*i2)+(j2*j2)+(k2*k2);
00760                                         if( radio<sqrt(tmpsqrt) ){
00761                                                 *ptr=0;
00762                                                 
00763                                         }
00764                                 }
00765                         }
00766                 }
00767 }
00768 
00769 
00770 
00771 
00772 
00773 
00774 
00775 
00776 
00777 
00778 
00779 
00780 
00781 //----------------------------------------------------------------------------
00782 void axisExtractor::avanzar()
00783 {
00784 
00785 
00786 
00787         
00788         double puntoactual[3];
00789         double puntoanterior[3];
00790         double puntoactualdis[3];
00791         double puntoactualcorre[3];
00792         int puntoactualarr[3];
00793         double radioactual;
00794         double dirant[3];
00795         double vector2[50][3];
00796         double vector2b[3];
00797         unsigned long vectortemp[4];
00798         double vector2temp[3];
00799         double maxmasa;
00800         int extint[6];
00801         int extintreal[6];
00802         int indesxdis[3];
00803         int indexp;
00804         double norvec;
00805         double provvc[3];
00806         double proprov;
00807         double puntoactualcorre2[3]; 
00808         int radiotrabajo=1;
00809         int radiocorte=0;
00810         int radiocorte2=0;
00811         int radiocorte3=0;
00812         int radiocorte4=0;
00813         int radiocorte5=0;
00814         int radiocorte6=0;
00815         int radiocorte7=0;
00816         int radiocorte8=0;
00817         int radiocorte9=0;
00818         int radiocorte10=0;
00819         int radiocorte11=0;
00820         int cantidadanterior=0;
00821         int cantidadanteriorb=0;
00822         int flag =0;
00823         int flag2 =0;
00824         int flag3 =0;
00825         int flag4 =0;
00826         int flag5 =0;
00827         int flag6 =0;
00828         int flag7 =0;
00829         int i, j;
00830 
00831                                 
00832                 
00833         if(!m_Stack0.empty()){
00834         
00835                 indexp=m_Stack.top();
00836 
00837                 puntoactual[0]=m_Stack0.top();
00838                 puntoactual[1]=m_Stack1.top();
00839                 puntoactual[2]=m_Stack2.top();
00840 
00841                 puntoanterior[0]=m_Stack3.top();
00842                 puntoanterior[1]=m_Stack4.top();
00843                 puntoanterior[2]=m_Stack5.top();
00844 
00845                 m_Stack0.pop();
00846                 m_Stack1.pop();
00847                 m_Stack2.pop();
00848                 m_Stack3.pop();
00849                 m_Stack4.pop();
00850                 m_Stack5.pop();
00851                 m_Stack.pop();
00852 
00853                 dirant[0]=puntoanterior[0]-puntoactual[0];
00854                 dirant[1]=puntoanterior[1]-puntoactual[1];
00855                 dirant[2]=puntoanterior[2]-puntoactual[2];
00856                 
00857                 radioactual=distancia(puntoactual, puntoanterior);
00858 
00859                 realtoindex(puntoactual, puntoactualarr);
00860                 
00861                 for(this->label=1, this->label2=0;flag4==0  &&(this->label>0) && (this->label==1 && ( radiocorte==0 || radiotrabajo<=radiocorte4 ) ) ||  (this->label>1 && radiotrabajo<=radiocorte4) ;radiotrabajo++){
00862                                         
00863                         extint[0]=puntoactualarr[0]-radiotrabajo;
00864                         extint[1]=puntoactualarr[0]+radiotrabajo;
00865                         extint[2]=puntoactualarr[1]-radiotrabajo;
00866                         extint[3]=puntoactualarr[1]+radiotrabajo;
00867                         extint[4]=puntoactualarr[2]-radiotrabajo;
00868                         extint[5]=puntoactualarr[2]+radiotrabajo;
00869 
00870                         extrac->SetVOI(extint);
00871                         extrac->UpdateWholeExtent();
00872                         extrac->Update();
00873                         extrac->GetOutput()->GetExtent(extintreal);
00874 
00875                         if(extint[0]!=extintreal[0] || extint[1]!=extintreal[1] || extint[2]!=extintreal[2] || extint[3]!=extintreal[3] || extint[4]!=extintreal[4] || extint[5]!=extintreal[5]){
00876                                 flag4 =1;
00877                                 radiotrabajo++;
00878                                 break;
00879                         }
00880                         
00881                         if(puntoactualarr[0]>=extintreal[0] && puntoactualarr[0]<=extintreal[1] && puntoactualarr[1]>=extintreal[2] && puntoactualarr[1]<=extintreal[3] && puntoactualarr[2]>=extintreal[4] && puntoactualarr[2]<=extintreal[5]  ){
00882 
00883                                 thresh->ThresholdByUpper(this->maximo()*this->humbral);
00884                                 thresh->UpdateWholeExtent();
00885                                 thresh->Update();
00886 
00887                                 redondear(thresh->GetOutput());
00888 
00889                                 cast->UpdateWholeExtent();
00890                                 cast->Update();
00891 
00892                                 connect->RemoveAllSeeds();
00893                                 connect->AddSeed(puntoactualarr[0],puntoactualarr[1],puntoactualarr[2]);
00894                                 connect->UpdateWholeExtent();
00895                                 connect->Update();
00896 
00897                                 this->dataprov->Delete();
00898 
00899                                 this->dataprov=vtkImageData::New();
00900                                 this->dataprov->SetScalarTypeToChar();
00901 
00902                                 this->dataprov->SetExtent(this->connect->GetOutput()->GetExtent());
00903                                 this->dataprov->SetSpacing(this->connect->GetOutput()->GetSpacing());
00904                         
00905                                 this->blanquear();
00906 
00907                                 this->find_components();
00908 
00909                                 if(this->label2>0 && flag==0){
00910                                         radiocorte=radiotrabajo;
00911                                         vector2b[0]=((double)vectorb[0][1]/(double)vectorb[0][0])-(double)puntoactualarr[0];
00912                                         vector2b[1]=((double)vectorb[0][2]/(double)vectorb[0][0])-(double)puntoactualarr[1];
00913                                         vector2b[2]=((double)vectorb[0][3]/(double)vectorb[0][0])-(double)puntoactualarr[2];
00914                                         flag =1;
00915                                 }
00916                                 if(this->label2>1 && flag5==0){
00917                                         radiocorte5=radiotrabajo;
00918                                         flag5 =1;
00919                                 }
00920 
00921                                 if( this->label>1 && flag2==0){
00922                                         radiocorte2=radiotrabajo;
00923                                         flag2 =1;
00924                                 }
00925 
00926                                 if(radiocorte5==0){
00927                                         radiocorte6=radiocorte2;
00928                                 }
00929                                 else{
00930                                         radiocorte6=min(radiocorte2, radiocorte5);
00931                                 }
00932 
00933                                 if((radiocorte6-radiocorte)>1 && flagg<=4){
00934                                         flag4 =1;
00935                                         radiotrabajo++;
00936                                         flag7 =0;
00937                                         break;
00938                                 }
00939                                 else{
00940                                         flag7 =1;
00941                                 }
00942                                 
00943                                 if(this->label>2 && flag3==0){
00944                                         radiocorte3=radiotrabajo;
00945                                         flag3 =1;
00946                                 }
00947                                 if( this->label==2 && cantidadanterior!=this->label){
00948                                         radiocorte7=radiotrabajo;
00949 
00950                                 }
00951                                 if( this->label==3 && cantidadanterior!=this->label){
00952                                         radiocorte8=radiotrabajo;
00953                                 }
00954                                 if( cantidadanterior!=this->label || cantidadanteriorb!=this->label2){
00955                                         if(radiocorte2==0){
00956                                                 radiocorte4=radiotrabajo+10*(radiotrabajo-radiocorte9);
00957                                         }
00958                                         else{
00959                                                 radiocorte4=radiotrabajo+(radiotrabajo-radiocorte9);
00960                                         }
00961                                         radiocorte9=radiotrabajo;
00962                                 }
00963                                 
00964                                 cantidadanterior=this->label;
00965                                 cantidadanteriorb=this->label2;
00966                                 
00967                         }
00968                         
00969                 }
00970                 radiotrabajo--;
00971                 radiocorte10=radiotrabajo;
00972 
00973                 if(flag7==1){
00974                         if(this->label>=2 && radiocorte10!=radiocorte9+1){
00975                                 radiotrabajo=radiocorte9+1;
00976                                 
00977                                 extint[0]=puntoactualarr[0]-radiotrabajo;
00978                                 extint[1]=puntoactualarr[0]+radiotrabajo;
00979                                 extint[2]=puntoactualarr[1]-radiotrabajo;
00980                                 extint[3]=puntoactualarr[1]+radiotrabajo;
00981                                 extint[4]=puntoactualarr[2]-radiotrabajo;
00982                                 extint[5]=puntoactualarr[2]+radiotrabajo;
00983 
00984                                 extrac->SetVOI(extint);
00985                                 extrac->UpdateWholeExtent();
00986                                 extrac->Update();
00987                                 extrac->GetOutput()->GetExtent(extintreal);
00988         
00989                                 thresh->ThresholdByUpper(this->maximo()*this->humbral);
00990                                 thresh->UpdateWholeExtent();
00991                                 thresh->Update();
00992 
00993                                 redondear(thresh->GetOutput());
00994 
00995                                 cast->UpdateWholeExtent();
00996                                 cast->Update();
00997 
00998                                 connect->RemoveAllSeeds();
00999                                 connect->AddSeed(puntoactualarr[0],puntoactualarr[1],puntoactualarr[2]);
01000                                 connect->UpdateWholeExtent();
01001                                 connect->Update();
01002 
01003                                 this->dataprov->Delete();
01004 
01005                                 this->dataprov=vtkImageData::New();
01006                                 this->dataprov->SetScalarTypeToChar();
01007 
01008                                 this->dataprov->SetExtent(this->connect->GetOutput()->GetExtent());
01009                                 this->dataprov->SetSpacing(this->connect->GetOutput()->GetSpacing());
01010 
01011                         
01012                                 this->blanquear();
01013 
01014                                 this->find_components();
01015                         }
01016                 }
01017 
01018                 if(flag7==1){
01019                         flagg=0;
01020                         if(this->label>1){
01021                                 //printf("no corrigio\n");
01022                                 
01023                                 realtoreal2(puntoactual, provvc);
01024                                 points->InsertPoint(buenos,provvc);
01025                                                                                 
01026                                 if(buenos>0){
01027                                         lineas->InsertNextCell(2);
01028                                         lineas->InsertCellPoint(indexp);
01029                                         lineas->InsertCellPoint(buenos);
01030                                 }
01031 
01032                                 buenos++;
01033                         }
01034                 }
01035                 else{
01036                         flagg++;
01037                         //printf("corrigio\n");
01038                         
01039                         provvc[0]=0;
01040                         provvc[1]=0;
01041                         provvc[2]=0;
01042 
01043                         norvec=distancia(provvc, vector2b);
01044 
01045                         proprov=(radiocorte6-radiocorte)/(2*norvec);
01046                                 
01047                         puntoactualcorre[0]=(puntoactualarr[0]-(vector2b[0]*proprov));
01048                         puntoactualcorre[1]=(puntoactualarr[1]-(vector2b[1]*proprov));
01049                         puntoactualcorre[2]=(puntoactualarr[2]-(vector2b[2]*proprov));
01050 
01051                         indextoreal(puntoactualcorre, puntoactualcorre2);
01052                                                 
01053                         m_Stack0.push(puntoactualcorre2[0]);
01054                         m_Stack1.push(puntoactualcorre2[1]);
01055                         m_Stack2.push(puntoactualcorre2[2]);
01056                         m_Stack3.push(puntoanterior[0]);
01057                         m_Stack4.push(puntoanterior[1]);
01058                         m_Stack5.push(puntoanterior[2]);
01059                         m_Stack.push(indexp);
01060 
01061                         
01062                 }
01063 
01064                 if(flag7==1){
01065                                 
01066                         if(this->label>1){
01067                                 
01068                                 maxmasa=0;
01069                                 for(i=0;i<this->label;i++){
01070                                         vector2[i][0]=((double)vector[i][1]/(double)vector[i][0])-(double)puntoactualarr[0];
01071                                         vector2[i][1]=((double)vector[i][2]/(double)vector[i][0])-(double)puntoactualarr[1];
01072                                         vector2[i][2]=((double)vector[i][3]/(double)vector[i][0])-(double)puntoactualarr[2];
01073                                         if(maxmasa<vector[i][0]){
01074                                                 maxmasa=vector[i][0];
01075                                         }       
01076                                 }
01077 
01078                                 for(i=0;i<this->label;i++){
01079                                         for(j=i;j<this->label;j++){
01080                                                 if(vector[j][0]<vector[i][0]){
01081                                                         vectortemp[0]=vector[i][0];
01082                                                         vectortemp[1]=vector[i][1];
01083                                                         vectortemp[2]=vector[i][2];
01084                                                         vectortemp[3]=vector[i][3];
01085                                                         vector2temp[0]=vector2[i][0];
01086                                                         vector2temp[1]=vector2[i][1];
01087                                                         vector2temp[2]=vector2[i][2];
01088                                                         
01089                                                         vector[i][0]=vector[j][0];
01090                                                         vector[i][1]=vector[j][1];
01091                                                         vector[i][2]=vector[j][2];
01092                                                         vector[i][3]=vector[j][3];
01093                                                         vector2[i][0]=vector2[j][0];
01094                                                         vector2[i][1]=vector2[j][1];
01095                                                         vector2[i][2]=vector2[j][2];
01096                                                 
01097                                                         vector[j][0]=vectortemp[0];
01098                                                         vector[j][1]=vectortemp[1];
01099                                                         vector[j][2]=vectortemp[2];
01100                                                         vector[j][3]=vectortemp[3];
01101                                                         vector2[j][0]=vector2temp[0];
01102                                                         vector2[j][1]=vector2temp[1];
01103                                                         vector2[j][2]=vector2temp[2];
01104                                                 }
01105                                         }
01106                                         
01107                                 }
01108 
01109                                 
01110                                 for(i=0;i<this->label;i++){
01111                                         if(maxmasa*this->minpropmasa<vector[i][0]){
01112 
01113                                                 indesxdis[0]=(int) (puntoactualarr[0]+vector2[i][0]);
01114                                                 indesxdis[1]=(int) (puntoactualarr[1]+vector2[i][1]);
01115                                                 indesxdis[2]=(int) (puntoactualarr[2]+vector2[i][2]);
01116         
01117                                                 indextoreal(indesxdis, puntoactualdis);
01118                 
01119                                                 if(envolumen(indesxdis, datatotal)==0){
01120                                                         m_Stack0.push(puntoactualdis[0]);
01121                                                         m_Stack1.push(puntoactualdis[1]);
01122                                                         m_Stack2.push(puntoactualdis[2]);
01123                                                         m_Stack3.push(puntoactual[0]);
01124                                                         m_Stack4.push(puntoactual[1]);
01125                                                         m_Stack5.push(puntoactual[2]);
01126                                                         m_Stack.push(buenos-1);
01127                                                 }
01128                                         
01129                                         }
01130                                         
01131                                 }
01132 
01133                                 if(this->label>1 ){
01134                                         copiar(this->connect->GetOutput(),  datatotal );
01135                                 }
01136 
01137                         }
01138                 }
01139                 
01140         }
01141         
01142 
01143 }

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1