From: Eduardo DAVILA Date: Wed, 9 Oct 2019 13:53:39 +0000 (+0200) Subject: #3312 creaMaracasVisu Feature New Normal - Optifisation fill tool in manual _paint X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=874205e7c7c6744db73d30756b6e7a1c47122a29;p=creaMaracasVisu.git #3312 creaMaracasVisu Feature New Normal - Optifisation fill tool in manual _paint --- diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.cpp b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.cpp index fa5510b..4ffbbc3 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.cpp +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.cpp @@ -26,11 +26,17 @@ #include "FillFilter.h" #include "creaVtk_MACROS.h" +#include + + + FillFilter::FillFilter() { _tolerancefill = 50; _distancefill = 500; +/* _limitRecursionFill = 50000; +*/ _auxImageFill = NULL; _maxXback = 0; _maxYback = 0; @@ -68,18 +74,218 @@ void FillFilter::SetImages(vtkImageData *image,vtkImageData *image2) // virtual #else _auxImageFill->AllocateScalars(VTK_UNSIGNED_CHAR,1); #endif - _ptrAuxImageFill = (unsigned char *)_auxImageFill->GetScalarPointer(); - memset(_ptrAuxImageFill, 0, (_maxX+1) * (_maxY+1) * (_maxZ+1) ); + 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 { + 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::FillToolLoop(int px, int py, int pz,long int iviA) +{ + 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::Run2() // virtual +{ + long int ivi; if ((_px >= _minX) && (_px <= _maxX) && (_py >= _minY) && (_py <= _maxY) && (_pz >= _minZ) && (_pz <= _maxZ)) @@ -135,6 +341,8 @@ if (_image2!=NULL) } //if _minX _maxX _minY _maxY _minZ _maxZ } + + //--------------------------------------------------------------------------- void FillFilter::FillToolRecursive(int px, int py, int pz,long int ivi) { @@ -218,11 +426,6 @@ GETVALUE2_VTK_CREA(_tmpiglfill2,p_image2,st_image2,ivi) _auxGrayLevelValidationFill = false; } // if isInRange - //DFCH - /*_auxGrayLevelValidationFill = (_tmpiglfill!=_graylevel) && - (_tmpiglfill>=_graylevelbasefill-_tolerancefill) && - (_tmpiglfill<=_graylevelbasefill+_tolerancefill) && - (_tmpDistfill<=_distbasefill);*/ //DFCH if (_auxGrayLevelValidationFill == true) { @@ -329,6 +532,7 @@ SETVALUE2_VTK_CREA(_graylevel,p_image,st_image,ivi) _countRecursiveFill--; } + //--------------------------------------------------------------------------- void FillFilter::SetAuxImageFill(int px, int py, int pz, long int ivi) { @@ -341,6 +545,8 @@ void FillFilter::SetAuxImageFill(int px, int py, int pz, long int ivi) _ptrAuxImageFill[ ivi ]=1; } // if px py pz } +*/ + //--------------------------------------------------------------------------- void FillFilter::SetToleranceFill(double tolerancefill) diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.h index 9a3e3b8..415e682 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/FillFilter.h @@ -35,7 +35,13 @@ public: virtual ~FillFilter(); void Run(); + void FillToolLoop(int px, int py, int pz,long int iviA) ; + +/* + void Run2(); void FillToolRecursive(int px,int py, int pz, long int ivi); + void SetAuxImageFill(int px,int py, int pz,long int ivi); +*/ void SetToleranceFill(double tolerancefill); void SetDistanceFill(int distancefill); @@ -46,34 +52,36 @@ private: int _distancefill; double _graylevelbasefill; - int _pxfill; - int _pyfill; - int _pzfill; double _distbasefill; - double _tmpDistfill; double _tmpiglfill; double _tmpiglfill2; - long int _countRecursiveFill; - long int _countRecursiveFillProblem; vtkImageData *_auxImageFill; -//EED01 - unsigned char *_ptrAuxImageFill; - bool _usingAuxImageFill; bool _auxGrayLevelValidationFill; - long int _countProgressingFill; - long int _limitRecursionFill; - void SetAuxImageFill(int px,int py, int pz,long int ivi); int _maxXback; int _maxYback; int _maxZback; - +/* +//EED01 + int _pxfill; + int _pyfill; + int _pzfill; + long int _countRecursiveFill; + long int _countRecursiveFillProblem; + unsigned char *_ptrAuxImageFill; + long int _countProgressingFill; + long int _limitRecursionFill; + bool _usingAuxImageFill; + double _tmpDistfill; int difX; int difY; int difZ; +*/ + + protected: @@ -90,9 +98,6 @@ protected: char *p_image2 ; int st_image2 ; - - - };