X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2FContour%2FContourExtractData.cxx;h=da3d19b816e7aab56e211799800c3660d91ba27c;hb=e263b7ace0f53d647a731553a3f67700838ad146;hp=4e32b1e7990c9b767e5038a829c55c2148441699;hpb=42ef0b76d65a1b4cdde710db14ada2eed990a63b;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourExtractData.cxx b/lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourExtractData.cxx index 4e32b1e..da3d19b 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourExtractData.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourExtractData.cxx @@ -1,60 +1,97 @@ +/*# --------------------------------------------------------------------- +# +# 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 "ContourExtractData.h" //---------------------------------------------------------------------- ContourExtractData::ContourExtractData( bool okImagesResults) - { - this->imagedata = NULL; +{ + this->imagedata = NULL; imagedataValueResult = NULL; imagedataMaskResult = NULL; this->okImagesResults = okImagesResults; _typeOperation = 0; - } +} - // ------------------------------------------------------------------------ +// ------------------------------------------------------------------------ - ContourExtractData::~ContourExtractData() - { - } +ContourExtractData::~ContourExtractData() +{ +} //---------------------------------------------------------------------- void ContourExtractData::SetImage( vtkImageData* imagedata) - { - this->imagedata = imagedata; - if (this->okImagesResults==true){ - InitVtkImagesResult(); - } - } +{ + this->imagedata = imagedata; + this->imagedata->GetScalarRange(scalarRange); + + // RaC 20-11-09 Changes in InitLstContoursLinesYPoints + int ext[6]; + +//EED 2017-01-01 Migration VTK7 +#if VTK_MAJOR_VERSION <= 5 + this->imagedata->GetWholeExtent(ext); +#else + this->imagedata->GetExtent(ext); +#endif + + _sizeImageY = ext[3]-ext[2]+1; + + // init vtk image result : valuesImage maskImage + if (this->okImagesResults==true){ InitVtkImagesResult(); } +} //---------------------------------------------------------------------- void ContourExtractData::SetZtoBeAnalys( int z ) - { +{ this->zImage = z; - } +} //------------------------------------------------------------------------ - void ContourExtractData::SetLstManualContourModel( std::vector lstManConMod) - { - this->lstManConMod = lstManConMod; - } +void ContourExtractData::SetLstManualContourModel( std::vector lstManConMod) +{ + this->lstManConMod = lstManConMod; +} //------------------------------------------------------------------------ void ContourExtractData::GetMinMaxPoint(int *minPoint, - int *maxPoint, - manualContourModel *manualcontourmodel - ) + int *maxPoint, + manualBaseModel *manualcontourmodel + ) { int i; //int np = manualcontourmodel->GetSizeLstPoints( ); // number of control points // JPRx -// JSTG 26-02-08 --------------------------------------------------------------------------------------- + // JSTG 26-02-08 --------------------------------------------------------------------------------------- //int nps = manualviewbaseecontour->GetNumberOfPointsSpline(); // number of points in the spline int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline -//------------------------------------------------------------------------------------------------------ - -// JSTG 26-02-08 --------------------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------ + + // JSTG 26-02-08 --------------------------------------------------------------------------------------- //double x,y,z,t; double x,y,z; //double delta=( double ) ( np ) / ( double ) ( nps ); @@ -73,102 +110,117 @@ void ContourExtractData::GetMinMaxPoint(int *minPoint, minPoint[1]--; maxPoint[0]++; maxPoint[1]++; -//------------------------------------------------------------------------------------------------------ + //------------------------------------------------------------------------------------------------------ } //------------------------------------------------------------------------ void ContourExtractData::GetMinMaxPoint_Of_LstManConMod( int *minPoint, - int *maxPoint - ) + int *maxPoint + ) { int i,size = lstManConMod.size(); + for(i=0 ; iGetSizeLstPoints( ); // number of control points // JPRx -// JSTG 26-02-08 --------------------------------------------------------------------------------------- - //int nps = manualviewbaseecontour->GetNumberOfPointsSpline(); // number of points in the spline - int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline - double x1,y1,z1,x2,y2,z2; + int nps=_lstlstlstVecX1[iContour][y].size(); + + double x1,y1,x2,y2; double borderX, borderY; double xx1, yy1,xx2, yy2; - //double delta=( double ) ( np ) / ( double ) ( nps ); - manualcontourmodel->UpdateSpline(); -//------------------------------------------------------------------------------------------------------ + double xx=x, yy=y; double d; - bool ok; -// if (np>=2) -// { -// JSTG 26-02-08 --------------------------------------------------------------------------------------- -// nps--; - //manualcontourmodel->GetSplinePoint(0,x1,y1,z1); - manualcontourmodel->GetSpline_i_Point(0,&x1,&y1,&z1); - x1=x1+0.5; y1=y1+0.5; - for (i=1; i<=nps; i++) + + for (i=0; i=yy1)&&(yy<=yy2) ) { - borderX=x1; - borderY=y1; - - ok=false; - //t= delta * (double)(i%nps); - //manualcontourmodel->GetSplinePoint(t,x2,y2,z2); - manualcontourmodel->GetSpline_i_Point(i,&x2,&y2,&z2); - x2=x2+0.5; y2=y2+0.5; -//------------------------------------------------------------------------------------------------------ - //by triangle similarity - if ( ((y1=y1)&&(yy2)&&(y<=y1)&&(y>y2)) ) + d = ( fabs(xx2-xx1)*(yy-yy1) ) / (yy2-yy1) ; + if ( (xx1<=xx2)&&(x<(xx1+d)) ) { result++; } + if ( (xx1>xx2)&&(x<(xx1-d)) ) { result++; } + + if ( (yy2-yy1)/difxx2xx1 >= 1.0) { - if (y1xx2)&&(x<(xx1-d)) ) { - result++; - borderX=xx1-d; - borderY=y; + borderX = xx1+d; + borderY = y; + } else { + borderX = xx1-d; + borderY = y; } - } // if point inside contour - - - //Border verication - if ( (x==(int)borderX) && (y==(int)borderY) ) - { - inBorder=true; - i=nps; - }// if point in border - - x1=x2; y1=y2; z1=z2; - - } // for i -// } //if - + } + } // if point inside y + + + // Finding border looking in vertical direction + if ( ((xx1<=xx2)&&(xx>=xx1)&&(xxxx2)&&(xx>=xx2)&&(xx=x1) && (x<=x2)) { inBorder=true; } + if ( ((int)y1==(int)y2) && ((int)y1==y) && (x2=x2) && (x<=x1)) { inBorder=true; } + + if (inBorder==true){ i=nps; } + } // for i + if (inBorder==true) { result=1; } - + return result; } -//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +// typeOperation=0 AND +// typeOperation=1 OR +// typeOperation=2 XOR bool ContourExtractData::isInside(int x, int y, int typeOperation) { bool result = false; @@ -176,44 +228,90 @@ bool ContourExtractData::isInside(int x, int y, int typeOperation) int i,size = this->lstManConMod.size(); int numberInside = 0; + /* RaC 20-11-09 (C1) Changes to use the method without the image. int ext[6]; imagedata->GetExtent(ext); if ((x>=0) && (x<=ext[1]) && (y>=0) && (y<=ext[3])) { + */ - if (typeOperation==0) // AND Intersection + if (typeOperation==0) // AND Intersection + { + for (i=0;iGetTypeModel()==7) { - numberLeft = AnalisisContourInside(x,y, lstManConMod[i] ); - if ( (numberLeft % 2) ==1){ numberInside++; } - } - if ( numberInside == (size) ){ result=true; } - } // AND Intersection + if(mbm->IsPoint(x,y)==true) + { + numberLeft=1; + } + }//if + else + { + numberLeft = AnalisisContourInsideV2(x,y, i ); + }//else + + if ( (numberLeft % 2) ==1){ numberInside++; } + } + if ( numberInside == (size) ){ result=true; } + } // AND Intersection + numberLeft=0; - if (typeOperation==1) // OR All + if (typeOperation==1) // OR All + { + for (i=0;iGetTypeModel()==7) + { + if(mbm->IsPoint(x,y)==true) + { + numberLeft=1; + } + }//if + else { - numberLeft = AnalisisContourInside(x,y, lstManConMod[i] ); - if ( (numberLeft % 2) ==1){ result=true; } - } - } // OR All + numberLeft = AnalisisContourInsideV2(x,y, i ); + }//else + if ( (numberLeft % 2) ==1){ result=true; } + } + } // OR All + + numberLeft=0; - if (typeOperation==2) // XOR crown + if (typeOperation==2) // XOR crown + { + for (i=0;iGetTypeModel()==7) + { + if(mbm->IsPoint(x,y)==true) + { + numberLeft=1; + } + }//if + else { - numberLeft = numberLeft + AnalisisContourInside(x,y, lstManConMod[i] ); - } - if ( numberLeft % 2 ==1){ result = true; } - }// XOR crown + numberLeft = numberLeft + AnalisisContourInsideV2(x,y, i ); + }//else + } + if ( numberLeft % 2 ==1){ result = true; } + }// XOR crown - } + + //RaC } return result; } @@ -222,10 +320,10 @@ bool ContourExtractData::isInside(int x, int y, int typeOperation) double ContourExtractData::GetDataValue(int x, int y, int z) { -// wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)wxvtkbaseview; -// int z = (int)wxvtk2dbaseview->GetVtkBaseData()->GetZ(); + // wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)wxvtkbaseview; + // int z = (int)wxvtk2dbaseview->GetVtkBaseData()->GetZ(); //JSTG 13-03-08----- -//EED OJO avec JS _zz = z; + //EED OJO avec JS _zz = z; //------------------ double result; void *p; @@ -296,10 +394,13 @@ void ContourExtractData::PutVtkImageDataResultValue( int x, int y, int z, double { unsigned short *pValue; unsigned short *pMask; - pValue = (unsigned short *)imagedataValueResult->GetScalarPointer(x,y,z); - pMask = (unsigned short *)imagedataMaskResult->GetScalarPointer(x,y,z); - *pMask = 255; - *pValue = (unsigned short)value; +//EED 2017-12-18 + imagedataValueResult->SetScalarComponentFromDouble(x,y,z,0,value); + imagedataMaskResult->SetScalarComponentFromDouble(x,y,z,0,255); +// pValue = (unsigned short *)imagedataValueResult->GetScalarPointer(x,y,z); +// *pValue = (unsigned short)value; +// pMask = (unsigned char *)imagedataMaskResult->GetScalarPointer(x,y,z); +// *pMask = 255; } //------------------------------------------------------------------------ @@ -311,24 +412,13 @@ void ContourExtractData::ResetImageResult(int z) unsigned short *pMask; pValue = (unsigned short *)imagedataValueResult->GetScalarPointer(0,0,z); pMask = (unsigned short *)imagedataMaskResult->GetScalarPointer(0,0,z); - + int ext[6]; imagedataValueResult->GetExtent(ext); int size = (ext[1]-ext[0]+1) * (ext[3]-ext[2]+1); - memset(pValue,0,size*2); - memset(pMask,0,size*2); - /* - int i; - for(i=0; iGetScalarSize() ); + memset(pMask,0, size*imagedataMaskResult->GetScalarSize() ); } // if } @@ -351,29 +441,51 @@ void ContourExtractData::CalculateImageResult() maxPoint[1] = -999999; GetMinMaxPoint_Of_LstManConMod(minPoint,maxPoint); + InitLstContoursLinesYPoints(); + for (j=minPoint[1]; j<=maxPoint[1]; j++) { for (i=minPoint[0]; i<=maxPoint[0]; i++) { - if (isInside(i,j,_typeOperation)==true) + + //RaC 20-11-09 Changes specified in isInside (C1) + int ext[6]; + imagedata->GetExtent(ext); + + if ((i>=0) && (i<=ext[1]) && (j>=0) && (j<=ext[3])) { - value = GetDataValue(i,j,zImage); - PutVtkImageDataResultValue(i,j,zImage, value ); - } // if + if (isInside(i,j,_typeOperation)==true) + { + value = GetDataValue(i,j,zImage); + if ( (value>=scalarRange[0]) && (value<=scalarRange[1]) ) + { + PutVtkImageDataResultValue(i,j,zImage, value ); + } // scalarRange + } // if isInside + + } // if ext } // for i } // for j imagedataValueResult->Modified(); imagedataMaskResult->Modified(); + +//EED 2017-01-01 Migration VTK7 +#if VTK_MAJOR_VERSION <= 5 imagedataValueResult->Update(); imagedataMaskResult->Update(); +#else + //... +#endif + } // if } //------------------------------------------------------------------------ -void ContourExtractData::GetValuesInsideCrown(std::vector *pLstValue, +void ContourExtractData::GetValuesInsideCrown( int *numberOfPixels, + std::vector *pLstValue, std::vector *pLstValuePosX, std::vector *pLstValuePosY, std::vector *pLstValuePosZ) @@ -383,16 +495,16 @@ void ContourExtractData::GetValuesInsideCrown(std::vector *pLstValue, pLstValuePosY->clear(); pLstValuePosZ->clear(); -// if (okImagesResults==true) -// { -// ResetImageResult(zImage); -// } + // if (okImagesResults==true) + // { + // ResetImageResult(zImage); + // } int minPoint[2]; int maxPoint[2]; int i,j; double value; - + int acum=0; minPoint[0] = 999999; minPoint[1] = 999999; @@ -400,37 +512,36 @@ void ContourExtractData::GetValuesInsideCrown(std::vector *pLstValue, maxPoint[1] = -999999; GetMinMaxPoint_Of_LstManConMod(minPoint,maxPoint); - + InitLstContoursLinesYPoints(); for (j=minPoint[1]; j<=maxPoint[1]; j++) { for (i=minPoint[0]; i<=maxPoint[0]; i++) { - if (isInside(i,j,_typeOperation)==true) + //RaC 20-11-09 Changes specified in isInside (C1) + int ext[6]; + imagedata->GetExtent(ext); + + if ((i>=0) && (i<=ext[1]) && (j>=0) && (j<=ext[3])) { - value = GetDataValue(i,j,zImage); - -// Borrame -// if (okImagesResults==true){ -// PutVtkImageDataResultValue(i,j,zImage, value ); -// } - - pLstValue -> push_back( value ); - pLstValuePosX -> push_back( i ); - pLstValuePosY -> push_back( j ); - pLstValuePosZ -> push_back( -1 ); - } // if + if (isInside(i,j,_typeOperation)==true) + { + + acum++; + value = GetDataValue(i,j,zImage); + if ( (value>=scalarRange[0]) && (value<=scalarRange[1]) ) + { + pLstValue -> push_back( value ); + pLstValuePosX -> push_back( i ); + pLstValuePosY -> push_back( j ); + pLstValuePosZ -> push_back( -1 ); + } // scalarRange + } // if isInside + } // if ext } // for } // for - -// Borrame -// if (this->okImagesResults==true){ -// imagedataValueResult->Modified(); -// imagedataMaskResult->Modified(); -// } - - + *numberOfPixels = acum; } //------------------------------------------------------------------------ @@ -447,41 +558,58 @@ vtkImageData *ContourExtractData::GetVtkImageMaskResult() // ------------------------------------------------------------------------ void ContourExtractData::InitVtkImagesResult() { - printf("EED ContourExtractData::InitVtkImagesResult\n"); - int ext[6]; - int newDim[3]; - double spc[3]; - int scalartype; - - imagedata->GetSpacing(spc); - imagedata->GetExtent(ext); - newDim[0]=ext[1]-ext[0]+1; - newDim[1]=ext[3]-ext[2]+1; - newDim[2]=ext[5]-ext[4]+1; - scalartype = imagedata->GetScalarType(); - - if (imagedataValueResult!=NULL) - { - imagedataValueResult->Delete(); - } - imagedataValueResult = vtkImageData::New(); -// imagedataValueResult->SetScalarType(scalartype); - imagedataValueResult->SetScalarTypeToUnsignedShort(); - imagedataValueResult->SetSpacing(spc); - imagedataValueResult->SetDimensions( newDim ); - imagedataValueResult->AllocateScalars(); - - if (imagedataMaskResult!=NULL) - { - imagedataMaskResult->Delete(); - } - imagedataMaskResult = vtkImageData::New(); -// imagedataMaskResult->SetScalarType(scalartype); - imagedataMaskResult->SetScalarTypeToUnsignedShort(); - imagedataMaskResult->SetSpacing(spc); - imagedataMaskResult->SetDimensions( newDim ); - imagedataMaskResult->AllocateScalars(); - printf("EED ContourExtractData::InitVtkImagesResult %p %p\n", imagedataValueResult, imagedataMaskResult); + int ext[6]; + int newDim[3]; + double spc[3]; + int scalartype; + + imagedata->GetSpacing(spc); + imagedata->GetExtent(ext); + newDim[0]=ext[1]-ext[0]+1; + newDim[1]=ext[3]-ext[2]+1; + newDim[2]=ext[5]-ext[4]+1; + scalartype = imagedata->GetScalarType(); + + if (imagedataValueResult!=NULL) + { + imagedataValueResult->Delete(); + } + imagedataValueResult = vtkImageData::New(); + imagedataValueResult->SetSpacing(spc); + imagedataValueResult->SetDimensions( newDim ); + +//EED 2017-01-01 Migration VTK7 +#if VTK_MAJOR_VERSION <= 5 + +//EED 2017-12-18 + imagedataValueResult->SetScalarType(scalartype); + //imagedataValueResult->SetScalarTypeToUnsignedShort(); + imagedataValueResult->AllocateScalars(); +#else + imagedataValueResult->AllocateScalars(scalartype,1); +#endif + + + if (imagedataMaskResult!=NULL) + { + imagedataMaskResult->Delete(); + } + imagedataMaskResult = vtkImageData::New(); + + + imagedataMaskResult->SetSpacing(spc); + imagedataMaskResult->SetDimensions( newDim ); + +//EED 2017-01-01 Migration VTK7 +#if VTK_MAJOR_VERSION <= 5 + //EED 2017-12-18 + //imagedataMaskResult->SetScalarTypeToUnsignedShort(); + imagedataMaskResult->SetScalarTypeToUnsignedChar(); + imagedataMaskResult->AllocateScalars(); +#else + imagedataMaskResult->AllocateScalars(VTK_UNSIGNED_CHAR,1); +#endif + } @@ -498,18 +626,18 @@ void ContourExtractData::InitVolumeStatistics() //------------------------------------------------------------------------ void ContourExtractData::SetVolumeStatistics(int rCountRange, - int rsize, - double minValue, - double maxValue, - double acum_average, - double acum_standardeviation) + int rsize, + double minValue, + double maxValue, + double acum_average, + double acum_standardeviation) { vol_rCountRange = vol_rCountRange + rCountRange; vol_rsize = vol_rsize + rsize; - + if (minValuevol_maxValue){ vol_maxValue = maxValue; } - + vol_acum_average = vol_acum_average + acum_average; vol_acum_standardeviation = vol_acum_standardeviation + acum_standardeviation; } @@ -541,25 +669,25 @@ void ContourExtractData::Statistics( std::vector *inputLstValue, double *rmax, double *raverage, double *rstandardeviation - ) + ) { - double min = 0; - double max = 0; - double average = 0; - double standardeviation = 0; - double acum_average = 0; - double acum_standardeviation = 0; - int size = 0; - int countRange = 0; - double ng; - - if (inputLstValue!=NULL) - { + double min = 0; + double max = 0; + double average = 0; + double standardeviation = 0; + double acum_average = 0; + double acum_standardeviation = 0; + int size = 0; + int countRange = 0; + double ng; + + if (inputLstValue!=NULL) + { size=inputLstValue->size(); if (size>0){ - max=(*inputLstValue)[0]; - min=(*inputLstValue)[0]; - // Average , countRange + max=(*inputLstValue)[0]; + min=(*inputLstValue)[0]; + // Average , countRange int i; for ( i=0; i *inputLstValue, } // for average average = acum_average / size; - // Standar Deviation + // Standar Deviation acum_standardeviation=0; double tmp; - for ( i=0; iGetNumberOfPointsSpline(); // number of points in the spline + manualcontourmodel->UpdateSpline(); + //------------------------------------------------------------------------------------------------------ + + for (y=0;yGetSpline_i_Point(0,&x1,&y1,&z1); + x1=x1+0.5; y1=y1+0.5; + for (i=1; iGetSpline_i_Point(i,&x2,&y2,&z2); + x2=x2+0.5; y2=y2+0.5; + if ( ((y1=y1)&&(y<=y2)) || ((y1>y2)&&(y>=y2)&&(y<=y1)) || ((int)y1==y) || ((int)y2==y) ) + { + _lstlstlstVecX1[iContour][y].push_back(x1); + _lstlstlstVecY1[iContour][y].push_back(y1); + _lstlstlstVecX2[iContour][y].push_back(x2); + _lstlstlstVecY2[iContour][y].push_back(y2); + } + x1=x2; y1=y2; z1=z2; + } // for i Points in spline + } // y + +} + +void ContourExtractData::InitLstContoursLinesYPoints() +{ + // init InInside Optimisation + int i; + + _lstlstlstVecX1.clear(); + _lstlstlstVecY1.clear(); + _lstlstlstVecX2.clear(); + _lstlstlstVecY2.clear(); + + /* RaC 20-11-09 + int ext[6]; + this->imagedata->GetWholeExtent(ext); + int sizeY = ext[3]-ext[2]+1; + */ + std::vector vecDouble; + std::vector< std::vector > vecVecDouble; + for ( i=0 ; i<_sizeImageY ; i++ ) + { + vecVecDouble.push_back( vecDouble ); + } + + //Fill structure with points + int sizeContours = lstManConMod.size(); + for( i=0 ; i