X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2Fwidgets%2FmanualPaint%2FFillFilter.cpp;h=476a23593d1acb04f947f234750ba3e66c18b6f2;hb=9a8f7c9cb08ffcb57f1558b9d20f7fbcd95df017;hp=694c6abc8d92e852c5f4374795b4d78d0986ded4;hpb=d0338585b83d4b0422ad465dedd0f885b3441600;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.cpp b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.cpp index 694c6ab..476a235 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.cpp +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.cpp @@ -1,302 +1,554 @@ +/*# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Sant�) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ */ #include "FillFilter.h" +#include "creaVtk_MACROS.h" +#include -FillFilter::FillFilter() + + +FillFilter::FillFilter() { - _tolerancefill = 50; - _distancefill = 500; - _limitRecursionFill = 50000; - _auxImageFill = NULL; + _tolerancefill = 50; + _distancefill = 500; +/* + _limitRecursionFill = 50000; +*/ + _auxImageFill = NULL; + _maxXback = 0; + _maxYback = 0; + _maxZback = 0; } //--------------------------------------------------------------------------- -FillFilter::~FillFilter() +FillFilter::~FillFilter() { - if (_auxImageFill!=NULL) - { - _auxImageFill->Delete(); - } + if (_auxImageFill != NULL) + { + _auxImageFill->Delete(); + } } //--------------------------------------------------------------------------- -void FillFilter::SetImage(vtkImageData *image) // virtual -{ - baseFilterManualPaint::SetImage(image); - if (_auxImageFill!=NULL) - { - _auxImageFill->Delete(); - } - _auxImageFill = vtkImageData::New(); - _auxImageFill->SetDimensions(_maxX+1,_maxY+1,_maxZ+1); - _auxImageFill->SetOrigin(0,0,0); - _auxImageFill->SetExtent( 0 , _maxX , 0 , _maxY , 0, _maxZ ); - _auxImageFill->SetWholeExtent( 0 , _maxX , 0 , _maxY , 0, _maxZ ); - _auxImageFill->SetScalarTypeToUnsignedChar(); - _auxImageFill->AllocateScalars(); +void FillFilter::SetImages(vtkImageData *image,vtkImageData *image2) // virtual +{ + baseFilterManualPaint::SetImages(image,image2); + if ((_maxX!=_maxXback) || (_maxY!=_maxYback) || (_maxZ!=_maxZback)) + { + if (_auxImageFill != NULL) + { + _auxImageFill->Delete(); + } + _auxImageFill = vtkImageData::New(); + _auxImageFill->SetDimensions(_maxX + 1, _maxY + 1, _maxZ + 1); + _auxImageFill->SetOrigin(0, 0, 0); + _auxImageFill->SetExtent(0, _maxX, 0, _maxY, 0, _maxZ); +//EED 2017-01-01 Migration VTK7 +#if VTK_MAJOR_VERSION <= 5 + _auxImageFill->SetWholeExtent(0, _maxX, 0, _maxY, 0, _maxZ); + _auxImageFill->SetScalarTypeToUnsignedChar(); + _auxImageFill->AllocateScalars(); +#else + _auxImageFill->AllocateScalars(VTK_UNSIGNED_CHAR,1); +#endif + } + unsigned char * ptrAuxImageFill = (unsigned char *)_auxImageFill->GetScalarPointer(); + memset(ptrAuxImageFill, 0, (_maxX+1) * (_maxY+1) * (_maxZ+1) ); + + _maxXback=_maxX; + _maxYback=_maxY; + _maxZback=_maxZ; } -//--------------------------------------------------------------------------- -void FillFilter::Run() // virtual -{ - if ((_px>=_minX) && (_px<=_maxX) && (_py>=_minY) && (_py<=_maxY) && (_pz>=_minZ) && (_pz<=_maxZ)) - { - _graylevelbasefill = _image->GetScalarComponentAsDouble(_px,_py,_pz, 0); - _pxfill = _px; - _pyfill = _py; - _pzfill = _pz; - _distbasefill = _distancefill*_distancefill; - _countRecursiveFill = 0; - _countRecursiveFillProblem = 0; - _countProgressingFill = 0; - unsigned char *pImage = (unsigned char *)_auxImageFill->GetScalarPointer(); - _usingAuxImageFill=false; - memset ( pImage , 0 , _maxX*_maxY*_maxZ ); - - FillToolRecursive(_px,_py,_pz); - printf("--\n"); - - int ii,jj,kk; - while (_countRecursiveFillProblem!=0) - { - _countRecursiveFillProblem = 0; - _usingAuxImageFill=true; - for(ii=0;ii<=_maxX;ii++) - { - for(jj=0;jj<=_maxY;jj++) - { - for(kk=0;kk<=_maxZ;kk++) - { - pImage=(unsigned char *)_auxImageFill->GetScalarPointer(ii,jj,kk); - if ( (*pImage)==1 ) - { - FillToolRecursive(ii,jj,kk); - } - } // for kk - } // for jj - } //for ii - printf("-\n"); - } // while - - } //if _minX _maxX _minY _maxY _minZ _maxZ -} //--------------------------------------------------------------------------- -void FillFilter::FillToolRecursive(int px,int py, int pz) +void FillFilter::Run() // virtual { - _countRecursiveFill++; - - _countProgressingFill++; - if (_countProgressingFill>200000) - { - printf("R %ld \n", _countRecursiveFill ); - _countProgressingFill=0; - } - - if ((px>=_minX) && (px<=_maxX) && (py>=_minY) && (py<=_maxY) && (pz>=_minZ) && (pz<=_maxZ)) - { - if (_usingAuxImageFill==true) - { - this->CalculateMinMaxRegion(px,py,pz); //DFCH - _auxImageFill->SetScalarComponentFromFloat (px, py, pz,0, 0); - } - _tmpDistfill=(px-_pxfill)*(px-_pxfill) + (py-_pyfill)*(py-_pyfill) + (pz-_pzfill)*(pz-_pzfill); - _tmpiglfill=_image->GetScalarComponentAsDouble(px,py,pz, 0); - - float grayLBFMTOL = _graylevelbasefill-_tolerancefill; - float grayLBFPTOL = _graylevelbasefill+_tolerancefill; - bool isInRange = false; - //DFCH - if( _RangeMin <= grayLBFMTOL && _RangeMax >= grayLBFPTOL ) - { - isInRange = true; - }//fi esle - else if( _RangeMin > grayLBFMTOL && _RangeMax >= grayLBFPTOL ) - { - grayLBFMTOL = _RangeMin; - isInRange = true; - }//fi esle - else if( _RangeMin <= grayLBFMTOL && _RangeMax < grayLBFPTOL ) - { - grayLBFPTOL = _RangeMax; - isInRange = true; - }//fi esle - else if( ( _RangeMin <= _graylevelbasefill ) && ( _graylevelbasefill <= _RangeMax ) ) - { - grayLBFMTOL = _RangeMin; - grayLBFPTOL = _RangeMax; - isInRange = true; - }//fi esle - - if( isInRange ) - { - _auxGrayLevelValidationFill = (_tmpiglfill!=_graylevel) && - (_tmpiglfill>=grayLBFMTOL) && - (_tmpiglfill<=grayLBFPTOL) && - (_tmpDistfill<=_distbasefill); //DFCH - }//fi - else - { - _auxGrayLevelValidationFill = false; - }//esle - //DFCH - /*_auxGrayLevelValidationFill = (_tmpiglfill!=_graylevel) && - (_tmpiglfill>=_graylevelbasefill-_tolerancefill) && - (_tmpiglfill<=_graylevelbasefill+_tolerancefill) && - (_tmpDistfill<=_distbasefill);*/ //DFCH - - - if ( _auxGrayLevelValidationFill==true ) - { - this->CalculateMinMaxRegion(px,py,pz); //DFCH - _image->SetScalarComponentFromFloat (px,py,pz, 0, (float)_graylevel ); - - if (_countRecursiveFill< _limitRecursionFill) - { - - if (_2D3D==0) //2D - { - if (_direction==0) // YZ - { - //FillToolRecursive(px+1,py,pz); - //FillToolRecursive(px-1,py,pz); - FillToolRecursive(px,py+1,pz); - FillToolRecursive(px,py-1,pz); - FillToolRecursive(px,py,pz-1); - FillToolRecursive(px,py,pz+1); - } - if (_direction==1) // XZ - { - FillToolRecursive(px+1,py,pz); - FillToolRecursive(px-1,py,pz); - //FillToolRecursive(px,py+1,pz); - //FillToolRecursive(px,py-1,pz); - FillToolRecursive(px,py,pz-1); - FillToolRecursive(px,py,pz+1); - } - if (_direction==2) // XY - { - FillToolRecursive(px+1,py,pz); - FillToolRecursive(px,py+1,pz); - FillToolRecursive(px-1,py,pz); - FillToolRecursive(px,py-1,pz); - //FillToolRecursive(px,py,pz-1); - //FillToolRecursive(px,py,pz+1); - } - } else { // 3D - - FillToolRecursive(px+1,py,pz); - FillToolRecursive(px-1,py,pz); - FillToolRecursive(px,py+1,pz); - FillToolRecursive(px,py-1,pz); - FillToolRecursive(px,py,pz-1); - FillToolRecursive(px,py,pz+1); - } // 2D 3D - - } //_countRecursiveFill - } // _graylevel - - - if ( (_auxGrayLevelValidationFill==true ) && - (_countRecursiveFill>= _limitRecursionFill) - ) - { - _countRecursiveFillProblem++; - - if (_2D3D==0) //2D - { - if (_direction==0) // YZ - { - //SetAuxImageFill(px+1,py,pz); - //SetAuxImageFill(px-1,py,pz); - SetAuxImageFill(px,py+1,pz); - SetAuxImageFill(px,py-1,pz); - SetAuxImageFill(px,py,pz-1); - SetAuxImageFill(px,py,pz+1); - } - if (_direction==1) // XZ - { - SetAuxImageFill(px+1,py,pz); - SetAuxImageFill(px-1,py,pz); - //SetAuxImageFill(px,py+1,pz); - //SetAuxImageFill(px,py-1,pz); - SetAuxImageFill(px,py,pz-1); - SetAuxImageFill(px,py,pz+1); - } - if (_direction==2) // XY - { - SetAuxImageFill(px+1,py,pz); - SetAuxImageFill(px-1,py,pz); - SetAuxImageFill(px,py+1,pz); - SetAuxImageFill(px,py-1,pz); - //SetAuxImageFill(px,py,pz-1); - //SetAuxImageFill(px,py,pz+1); - } - } else { // 3D - - SetAuxImageFill(px+1,py,pz); - SetAuxImageFill(px-1,py,pz); - SetAuxImageFill(px,py+1,pz); - SetAuxImageFill(px,py-1,pz); - SetAuxImageFill(px,py,pz-1); - SetAuxImageFill(px,py,pz+1); - } // 2D 3D - - } // _graylevel //_limitRecursionFill - - - } //if _minX _maxX _minY _maxY _minZ _maxZ - - - _countRecursiveFill--; - + long int ivi; + if ((_px >= _minX) && (_px <= _maxX) && (_py >= _minY) && (_py <= _maxY) + && (_pz >= _minZ) && (_pz <= _maxZ)) + { + _graylevelbasefill = _image->GetScalarComponentAsDouble(_px, _py, _pz,0); + _distbasefill = _distancefill * _distancefill; +/* + _pxfill = _px; + _pyfill = _py; + _pzfill = _pz; + _countRecursiveFill = 0; + _countRecursiveFillProblem = 0; + _countProgressingFill = 0; + DEF_POINTER_IMAGE_VTK_CREA_set(v_image,ss_image,p_image,st_image,_image) + if (_image2!=NULL) + { + DEF_POINTER_IMAGE_VTK_CREA_set(v_image2,ss_image2,p_image2,st_image2,_image2) + } // if _image2 +*/ +// _usingAuxImageFill = false; + ivi = _px + _py*(_maxX+1) + _pz*(_maxX+1)*(_maxY+1); // index vector image + FillToolLoop(_px, _py, _pz, ivi); + } //if _minX _maxX _minY _maxY _minZ _maxZ } //--------------------------------------------------------------------------- -void FillFilter::SetAuxImageFill(int px,int py, int pz) +void FillFilter::FillToolLoop(int px, int py, int pz,long int iviA) { - if ((px>=_minX) && (px<=_maxX) && (py>=_minY) && (py<=_maxY) && (pz>=_minZ) && (pz<=_maxZ)) - { - this->CalculateMinMaxRegion(px,py,pz); //DFCH - _auxImageFill->SetScalarComponentFromFloat (px, py, pz,0, 1); - } + double difX,difY,difZ,_tmpDistfill; + std::vector lstX; + std::vector lstY; + std::vector lstZ; + std::vector lstivi; + lstX.push_back(px); + lstY.push_back(py); + lstZ.push_back(pz); + lstivi.push_back( iviA ); + + DEF_POINTER_IMAGE_VTK_CREA_set(v_image,ss_image,p_image,st_image,_image) + if (_image2!=NULL) + { + DEF_POINTER_IMAGE_VTK_CREA_set(v_image2,ss_image2,p_image2,st_image2,_image2) + } // if _image2 + + DEF_POINTER_IMAGE_VTK_CREA(v_auxImageFill,ss_auxImageFill,p_auxImageFill,st_auxImageFill,_auxImageFill) + while ( lstX.size()!=0 ) + { + // if point inside image + if ((lstX[0] >= _minX) && (lstX[0] <= _maxX) && (lstY[0] >= _minY) && (lstY[0] <= _maxY) && (lstZ[0] >= _minZ) && (lstZ[0] <= _maxZ)) + { + difX = px-lstX[0]; + difY = py-lstY[0]; + difZ = pz-lstZ[0]; + _tmpDistfill = difX*difX + difY*difY + difZ*difZ; + // if distance of center point + if (_tmpDistfill<=_distbasefill) + { + // if point not visited + GETVALUE2_VTK_CREA(v_auxImageFill,p_auxImageFill,st_auxImageFill,lstivi[0] ); + if (v_auxImageFill==0) + { + // If Gray Level valid + + //EED01 + // _tmpiglfill = _image->GetScalarComponentAsDouble(px, py, pz, 0); + GETVALUE2_VTK_CREA(_tmpiglfill,p_image,st_image,lstivi[0]) + + if (_image2!=NULL) + { + //EED01 + // _tmpiglfill2 = _image2->GetScalarComponentAsDouble(px, py, pz, 0); + GETVALUE2_VTK_CREA(_tmpiglfill2,p_image2,st_image2,lstivi[0]) + } else { + _tmpiglfill2 = _tmpiglfill; + } + + float grayLBFMTOL = _graylevelbasefill - _tolerancefill; + float grayLBFPTOL = _graylevelbasefill + _tolerancefill; + bool isInRange = false; + //DFCH + if (_RangeMin <= grayLBFMTOL && _RangeMax >= grayLBFPTOL) { + isInRange = true; + } //fi esle + else if (_RangeMin > grayLBFMTOL && _RangeMax >= grayLBFPTOL) { + grayLBFMTOL = _RangeMin; + isInRange = true; + } //fi esle + else if (_RangeMin <= grayLBFMTOL && _RangeMax < grayLBFPTOL) { + grayLBFPTOL = _RangeMax; + isInRange = true; + } //fi esle + else if ((_RangeMin <= _graylevelbasefill) && (_graylevelbasefill <= _RangeMax)) { + grayLBFMTOL = _RangeMin; + grayLBFPTOL = _RangeMax; + isInRange = true; + } //fi Range + + if (isInRange) + { + _auxGrayLevelValidationFill = (_tmpiglfill != _graylevel) + && (_tmpiglfill2 != _graylevel) + && (_tmpiglfill >= grayLBFMTOL) + && (_tmpiglfill <= grayLBFPTOL) + && (_tmpDistfill <= _distbasefill); //DFCH + } else { + _auxGrayLevelValidationFill = false; + } // if isInRange + + if (_auxGrayLevelValidationFill) + { + // Modifie image + if (_image2!=NULL) + { + // _image2->SetScalarComponentFromFloat(px, py, pz, 0,(float) _graylevel); + SETVALUE2_VTK_CREA(_graylevel,p_image2,st_image2,lstivi[0]) + } else { + // _image->SetScalarComponentFromFloat(px, py, pz, 0,(float) _graylevel); + SETVALUE2_VTK_CREA(_graylevel,p_image,st_image,lstivi[0]) + } // if _image2 + + // Add neighborhood points in the list + if (_2D3D == 0) //2D + { + if (_direction == 0) // YZ + { + //lstX.push_back(lstX[0]+1); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]+_OneColumn); + //lstX.push_back(lstX[0]-1); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]-_OneColumn); + lstX.push_back(lstX[0] ); lstY.push_back(lstY[0]+1); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]+_OneLine); + lstX.push_back(lstX[0] ); lstY.push_back(lstY[0]-1); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]-_OneLine); + lstX.push_back(lstX[0] ); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0]+1); lstivi.push_back( lstivi[0]+_OnePlane); + lstX.push_back(lstX[0] ); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0]-1); lstivi.push_back( lstivi[0]-_OnePlane); + } + if (_direction == 1) // XZ + { + lstX.push_back(lstX[0]+1); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]+_OneColumn); + lstX.push_back(lstX[0]-1); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]-_OneColumn); + // lstX.push_back(lstX[0] ); lstY.push_back(lstY[0]+1); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]+_OneLine); + // lstX.push_back(lstX[0] ); lstY.push_back(lstY[0]-1); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]-_OneLine); + lstX.push_back(lstX[0] ); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0]+1); lstivi.push_back( lstivi[0]+_OnePlane); + lstX.push_back(lstX[0] ); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0]-1); lstivi.push_back( lstivi[0]-_OnePlane); + } + if (_direction == 2) // XY + { + lstX.push_back(lstX[0]+1); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]+_OneColumn); + lstX.push_back(lstX[0]-1); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]-_OneColumn); + lstX.push_back(lstX[0] ); lstY.push_back(lstY[0]+1); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]+_OneLine); + lstX.push_back(lstX[0] ); lstY.push_back(lstY[0]-1); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]-_OneLine); + //lstX.push_back(lstX[0] ); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0]+1); lstivi.push_back( lstivi[0]+_OnePlane); + //lstX.push_back(lstX[0] ); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0]-1); lstivi.push_back( lstivi[0]-_OnePlane); + } + } else { // 3D + lstX.push_back(lstX[0]+1); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]+_OneColumn); + lstX.push_back(lstX[0]-1); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]-_OneColumn); + lstX.push_back(lstX[0] ); lstY.push_back(lstY[0]+1); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]+_OneLine); + lstX.push_back(lstX[0] ); lstY.push_back(lstY[0]-1); lstZ.push_back(lstZ[0] ); lstivi.push_back( lstivi[0]-_OneLine); + lstX.push_back(lstX[0] ); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0]+1); lstivi.push_back( lstivi[0]+_OnePlane); + lstX.push_back(lstX[0] ); lstY.push_back(lstY[0] ); lstZ.push_back(lstZ[0]-1); lstivi.push_back( lstivi[0]-_OnePlane); + } // 2D 3D + + + + + + + + } // if gray level valid _auxGrayLevelValidationFill + + } // if point not visited + // Add point to already visited + SETVALUE2_VTK_CREA(1,p_auxImageFill,st_auxImageFill,lstivi[0]); + } // if distance of center point + } // if point inside image + // Remove point from the list + lstX.erase( lstX.begin() ); + lstY.erase( lstY.begin() ); + lstZ.erase( lstZ.begin() ); + lstivi.erase( lstivi.begin() ); + } // while _lstX.size } +/* + + //--------------------------------------------------------------------------- -void FillFilter::SetToleranceFill(double tolerancefill) +void FillFilter::Run2() // virtual { - _tolerancefill = tolerancefill; -} -//--------------------------------------------------------------------------- -void FillFilter::SetDistanceFill(int distancefill) + long int ivi; + if ((_px >= _minX) && (_px <= _maxX) && (_py >= _minY) && (_py <= _maxY) + && (_pz >= _minZ) && (_pz <= _maxZ)) + { + _graylevelbasefill = _image->GetScalarComponentAsDouble(_px, _py, _pz,0); + _pxfill = _px; + _pyfill = _py; + _pzfill = _pz; + _distbasefill = _distancefill * _distancefill; + _countRecursiveFill = 0; + _countRecursiveFillProblem = 0; + _countProgressingFill = 0; + _usingAuxImageFill = false; + + ivi = _px + _py*(_maxX+1) + _pz*(_maxX+1)*(_maxY+1); // index vector image + +DEF_POINTER_IMAGE_VTK_CREA_set(v_image,ss_image,p_image,st_image,_image) +if (_image2!=NULL) { - _distancefill = distancefill; + DEF_POINTER_IMAGE_VTK_CREA_set(v_image2,ss_image2,p_image2,st_image2,_image2) } +//EED01 +// FillToolRecursive(_px, _py, _pz); + FillToolRecursive(_px, _py, _pz, ivi); + unsigned char *pImage; + pImage = (unsigned char *) _auxImageFill->GetScalarPointer(); + int ii, jj, kk; + ivi = 0; + + while (_countRecursiveFillProblem != 0) + { + _countRecursiveFillProblem = 0; + _usingAuxImageFill = true; + for (kk = 0; kk <= _maxZ; kk++) + { + for (jj = 0; jj <= _maxY; jj++) + { + for (ii = 0; ii <= _maxX; ii++) + { + if (pImage[ivi] == 1) + { +//EED01 +// FillToolRecursive(ii, jj, kk); + FillToolRecursive(ii, jj, kk, ivi); + } // if + ivi++; + } // for ii + } // for jj + } //for kk +// printf("-\n"); + } // while + } //if _minX _maxX _minY _maxY _minZ _maxZ +} + + + //--------------------------------------------------------------------------- -void FillFilter::SetRangeMin( int min ) +void FillFilter::FillToolRecursive(int px, int py, int pz,long int ivi) { - _RangeMin = min; +//ups ??EED DEF_POINTER_IMAGE_VTK_CREA(v_image,ss_image,p_image,st_image,_image) +//ups ??EED DEF_POINTER_IMAGE_VTK_CREA(v_image2,ss_image2,p_image2,st_image2,_image2) + + _countRecursiveFill++; + _countProgressingFill++; + if (_countProgressingFill > 200000) + { + printf("R %ld \n", _countRecursiveFill); + _countProgressingFill = 0; + } + + if ((px >= _minX) && (px <= _maxX) && (py >= _minY) && (py <= _maxY) + && (pz >= _minZ) && (pz <= _maxZ)) + { + if (_usingAuxImageFill == true) + { +//UPS ??EED this->_IMManager->AddModifiedPixel(px, py, pz); //DFCH +//EED01 +// _auxImageFill->SetScalarComponentFromFloat(px, py, pz, 0, 0); + _ptrAuxImageFill[ ivi ]=0; + } + difX=px-_pxfill; + difY=py-_pyfill; + difZ=pz-_pzfill; + _tmpDistfill = difX*difX + difY*difY + difZ*difZ; +// _tmpDistfill = (px-_pxfill)*(px-_pxfill) +// + (py-_pyfill)*(py-_pyfill) +// + (pz-_pzfill)*(pz-_pzfill); + +//if (_countRecursiveFill >1 ) +//{ +// printf(" -> %d %d %d cr=%ld r=%f\n", px,py,pz,_countRecursiveFill , _tmpDistfill); +//} + + +//EED01 +// _tmpiglfill = _image->GetScalarComponentAsDouble(px, py, pz, 0); +GETVALUE2_VTK_CREA(_tmpiglfill,p_image,st_image,ivi) + + if (_image2!=NULL) + { +//EED01 +// _tmpiglfill2 = _image2->GetScalarComponentAsDouble(px, py, pz, 0); +GETVALUE2_VTK_CREA(_tmpiglfill2,p_image2,st_image2,ivi) + } else { + _tmpiglfill2 = _tmpiglfill; + } + + float grayLBFMTOL = _graylevelbasefill - _tolerancefill; + float grayLBFPTOL = _graylevelbasefill + _tolerancefill; + bool isInRange = false; + //DFCH + if (_RangeMin <= grayLBFMTOL && _RangeMax >= grayLBFPTOL) { + isInRange = true; + } //fi esle + else if (_RangeMin > grayLBFMTOL && _RangeMax >= grayLBFPTOL) { + grayLBFMTOL = _RangeMin; + isInRange = true; + } //fi esle + else if (_RangeMin <= grayLBFMTOL && _RangeMax < grayLBFPTOL) { + grayLBFPTOL = _RangeMax; + isInRange = true; + } //fi esle + else if ((_RangeMin <= _graylevelbasefill) && (_graylevelbasefill <= _RangeMax)) { + grayLBFMTOL = _RangeMin; + grayLBFPTOL = _RangeMax; + isInRange = true; + } //fi Range + + if (isInRange) + { + _auxGrayLevelValidationFill = (_tmpiglfill != _graylevel) + && (_tmpiglfill2 != _graylevel) + && (_tmpiglfill >= grayLBFMTOL) + && (_tmpiglfill <= grayLBFPTOL) + && (_tmpDistfill <= _distbasefill); //DFCH + } else { + _auxGrayLevelValidationFill = false; + } // if isInRange + + + if (_auxGrayLevelValidationFill == true) + { +//UPS ??EED this->_IMManager->AddModifiedPixel(px, py, pz); //DFCH + if (_image2!=NULL) + { +//EED01 +// _image2->SetScalarComponentFromFloat(px, py, pz, 0,(float) _graylevel); +SETVALUE2_VTK_CREA(_graylevel,p_image2,st_image2,ivi) + } else { +//EED01 +// _image->SetScalarComponentFromFloat(px, py, pz, 0,(float) _graylevel); +SETVALUE2_VTK_CREA(_graylevel,p_image,st_image,ivi) + } + + if (_countRecursiveFill < _limitRecursionFill) + { + + if (_2D3D == 0) //2D + { + if (_direction == 0) // YZ + { + //FillToolRecursive(px+1,py,pz); + //FillToolRecursive(px-1,py,pz); + FillToolRecursive(px, py + 1, pz, ivi+_OneLine ); + FillToolRecursive(px, py - 1, pz, ivi-_OneLine ); + FillToolRecursive(px, py, pz - 1, ivi-_OnePlane ); + FillToolRecursive(px, py, pz + 1, ivi+_OnePlane ); + } + if (_direction == 1) // XZ + { + FillToolRecursive(px + 1, py, pz, ivi+_OneColumn); + FillToolRecursive(px - 1, py, pz, ivi-_OneColumn); + //FillToolRecursive(px,py+1,pz); + //FillToolRecursive(px,py-1,pz); + FillToolRecursive(px, py, pz - 1, ivi-_OnePlane ); + FillToolRecursive(px, py, pz + 1, ivi+_OnePlane ); + } + if (_direction == 2) // XY + { + FillToolRecursive(px + 1, py, pz, ivi+_OneColumn); + FillToolRecursive(px, py + 1, pz, ivi+_OneLine); + FillToolRecursive(px - 1, py, pz, ivi-_OneColumn); + FillToolRecursive(px, py - 1, pz, ivi-_OneLine); + //FillToolRecursive(px,py,pz-1); + //FillToolRecursive(px,py,pz+1); + } + } else { // 3D + FillToolRecursive(px + 1, py, pz, ivi+_OneColumn ); + FillToolRecursive(px - 1, py, pz, ivi-_OneColumn ); + FillToolRecursive(px, py + 1, pz, ivi+_OneLine ); + FillToolRecursive(px, py - 1, pz, ivi-_OneLine ); + FillToolRecursive(px, py, pz - 1, ivi-_OnePlane ); + FillToolRecursive(px, py, pz + 1, ivi+_OnePlane ); + } // 2D 3D + + } //_countRecursiveFill + } // _graylevel + + if ((_auxGrayLevelValidationFill == true) && (_countRecursiveFill >= _limitRecursionFill)) + { + _countRecursiveFillProblem++; + if (_2D3D == 0) //2D + { + if (_direction == 0) // YZ + { + //SetAuxImageFill(px+1,py,pz); + //SetAuxImageFill(px-1,py,pz); + SetAuxImageFill(px, py + 1, pz,ivi+_OneLine); + SetAuxImageFill(px, py - 1, pz,ivi-_OneLine); + SetAuxImageFill(px, py, pz - 1,ivi-_OnePlane); + SetAuxImageFill(px, py, pz + 1,ivi+_OnePlane); + } + if (_direction == 1) // XZ + { + SetAuxImageFill(px + 1, py, pz,ivi+_OneColumn); + SetAuxImageFill(px - 1, py, pz,ivi-_OneColumn); + //SetAuxImageFill(px,py+1,pz); + //SetAuxImageFill(px,py-1,pz); + SetAuxImageFill(px, py, pz - 1,ivi-_OnePlane); + SetAuxImageFill(px, py, pz + 1,ivi+_OnePlane); + } + if (_direction == 2) // XY + { + SetAuxImageFill(px + 1, py, pz,ivi+_OneColumn); + SetAuxImageFill(px - 1, py, pz,ivi-_OneColumn); + SetAuxImageFill(px, py + 1, pz,ivi+_OneLine); + SetAuxImageFill(px, py - 1, pz,ivi-_OneLine); + //SetAuxImageFill(px,py,pz-1); + //SetAuxImageFill(px,py,pz+1); + } + } else { // 3D + SetAuxImageFill(px + 1, py, pz,ivi+_OneColumn); + SetAuxImageFill(px - 1, py, pz,ivi-_OneColumn); + SetAuxImageFill(px, py + 1, pz,ivi+_OneLine); + SetAuxImageFill(px, py - 1, pz,ivi-_OneLine); + SetAuxImageFill(px, py, pz - 1,ivi-_OnePlane); + SetAuxImageFill(px, py, pz + 1,ivi+_OnePlane); + } // 2D 3D + + } // _graylevel //_limitRecursionFill + + } //if _minX _maxX _minY _maxY _minZ _maxZ + _countRecursiveFill--; } + //--------------------------------------------------------------------------- -void FillFilter::SetRangeMax( int max ) +void FillFilter::SetAuxImageFill(int px, int py, int pz, long int ivi) { - _RangeMax = max; + if ((px >= _minX) && (px <= _maxX) && (py >= _minY) && (py <= _maxY) + && (pz >= _minZ) && (pz <= _maxZ)) + { + this->_IMManager->AddModifiedPixel(px, py, pz); //DFCH +//EED01 +// _auxImageFill->SetScalarComponentFromFloat(px, py, pz, 0, 1); + _ptrAuxImageFill[ ivi ]=1; + } // if px py pz } +*/ + //--------------------------------------------------------------------------- -int FillFilter::GetRangeMin( ) +void FillFilter::SetToleranceFill(double tolerancefill) { - return( _RangeMin ); + _tolerancefill = tolerancefill; } //--------------------------------------------------------------------------- -int FillFilter::GetRangeMax( ) +void FillFilter::SetDistanceFill(int distancefill) { - return( _RangeMax ); + _distancefill = distancefill; } + +