]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourExtractData.cxx
ViewerNV 2D with color Transfer Function
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / Contour / ContourExtractData.cxx
index e64fa03a444370e831d5e8e3162e631fd35192d8..4e32b1e7990c9b767e5038a829c55c2148441699 100644 (file)
@@ -69,6 +69,10 @@ void ContourExtractData::GetMinMaxPoint(int *minPoint,
                if (x>maxPoint[0]){ maxPoint[0]=(int)x; }
                if (y>maxPoint[1]){ maxPoint[1]=(int)y; }
        }
+       minPoint[0]--;
+       minPoint[1]--;
+       maxPoint[0]++;
+       maxPoint[1]++;
 //------------------------------------------------------------------------------------------------------
 }
 
@@ -91,6 +95,7 @@ int ContourExtractData::AnalisisContourInside(int x,
                                            manualContourModel *manualcontourmodel
                                            )
 {
+       bool inBorder=false;
        int result      = 0;
        int i;
        //int   np              = manualcontourmodel->GetSizeLstPoints( );  // number of control points // JPRx
@@ -98,8 +103,8 @@ int ContourExtractData::AnalisisContourInside(int x,
 // 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,t;
        double x1,y1,z1,x2,y2,z2;
+       double borderX, borderY;
        double xx1, yy1,xx2, yy2;
        //double delta=( double ) ( np  ) / ( double ) ( nps  );
        manualcontourmodel->UpdateSpline();
@@ -109,26 +114,55 @@ int ContourExtractData::AnalisisContourInside(int x,
 //     if (np>=2)
 //     {
 // JSTG 26-02-08 ---------------------------------------------------------------------------------------
-               nps--;
+//             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++)
                {
+                       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<y2)&&(y>=y1)&&(y<y2)) || ((y1>y2)&&(y<=y1)&&(y>y2)) )
                        {
                                if (y1<y2) { xx1=x1; yy1=y1; xx2=x2; yy2=y2;} else { xx1=x2; yy1=y2; xx2=x1; yy2=y1; } 
                                d = ( fabs(xx2-xx1)*(y-yy1) ) / (yy2-yy1) ;
-                               if (  ((xx1<xx2)&&(x<(xx1+d)))  ||  ((xx1>xx2)&&(x<(xx1-d)))  ) { result++; }
-                       } // if
+                               if ( (xx1<xx2)&&(x<(xx1+d)) )   
+                               { 
+                                       result++; 
+                                       borderX=xx1+d;
+                                       borderY=y;
+                               } 
+                               if ( (xx1>xx2)&&(x<(xx1-d)) )  { 
+                                       result++; 
+                                       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 (inBorder==true)     { result=1;     }
+       
        return result;
 }
 
@@ -197,22 +231,62 @@ double ContourExtractData::GetDataValue(int x, int y, int z)
        void *p;
        p = imagedata->GetScalarPointer(x,y,z);
 
-       if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR)
-       {       unsigned char *pp = (unsigned char*)p;
+       if (imagedata->GetScalarType()==VTK_CHAR)
+       {
+               char *pp = (char*)p;
+               result = (double)(*pp);
+       }
+       else if (imagedata->GetScalarType()==VTK_SIGNED_CHAR)
+       {
+               signed char *pp = (signed char*)p;
+               result = (double)(*pp);
+       }
+       else if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR)
+       {
+               unsigned char *pp = (unsigned char*)p;
+               result = (double)(*pp);
+       }
+       else if (imagedata->GetScalarType()==VTK_SHORT)
+       {
+               short *pp = (short*)p;
+               result = (double)(*pp);
+       }
+       else if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT)
+       {
+               unsigned short *pp = (unsigned short*)p;
+               result = (double)(*pp);
+       }
+       else if (imagedata->GetScalarType()==VTK_INT)
+       {
+               int *pp = (int*)p;
+               result = (double)(*pp);
+       }
+       else if (imagedata->GetScalarType()==VTK_UNSIGNED_INT)
+       {
+               unsigned int *pp = (unsigned int*)p;
+               result = (double)(*pp);
+       }
+       else if (imagedata->GetScalarType()==VTK_LONG)
+       {
+               long *pp = (long*)p;
                result = (double)(*pp);
        }
-       if (imagedata->GetScalarType()==VTK_FLOAT)
-       {       float *pp = (float*)p;
+       else if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG)
+       {
+               unsigned long *pp = (unsigned long*)p;
                result = (double)(*pp);
        }
-       if (imagedata->GetScalarType()==VTK_SHORT)
-       {       short *pp = (short*)p;
+       else if (imagedata->GetScalarType()==VTK_FLOAT)
+       {       
+               float *pp = (float*)p;
                result = (double)(*pp);
        }
-       if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT)
-       {       unsigned short *pp = (unsigned short*)p;
+       else if (imagedata->GetScalarType()==VTK_DOUBLE)
+       {
+               double *pp = (double*)p;
                result = (double)(*pp);
        }
+
        return result;
 }
 
@@ -241,7 +315,11 @@ void ContourExtractData::ResetImageResult(int z)
                int ext[6];
                imagedataValueResult->GetExtent(ext);
 
-               int i,size = (ext[1]-ext[0]+1) * (ext[3]-ext[2]+1); 
+               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; i<size; i++)
                {
                        *pMask  = 0;
@@ -249,6 +327,8 @@ void ContourExtractData::ResetImageResult(int z)
                        pMask++;
                        pValue++;
                }// for
+       */ 
+               
        } // if
 }
 
@@ -271,9 +351,9 @@ void ContourExtractData::CalculateImageResult()
                maxPoint[1] = -999999;
 
                GetMinMaxPoint_Of_LstManConMod(minPoint,maxPoint);
-               for (j=minPoint[1]; j<maxPoint[1]; j++)
+               for (j=minPoint[1]; j<=maxPoint[1]; j++)
                {
-                       for (i=minPoint[0]; i<maxPoint[0]; i++)
+                       for (i=minPoint[0]; i<=maxPoint[0]; i++)
                        {
                                if (isInside(i,j,_typeOperation)==true)
                                {
@@ -286,7 +366,9 @@ void ContourExtractData::CalculateImageResult()
 
                imagedataValueResult->Modified();
                imagedataMaskResult->Modified();
-       }
+               imagedataValueResult->Update();
+               imagedataMaskResult->Update();
+       } // if
 
 }
 
@@ -320,9 +402,9 @@ void ContourExtractData::GetValuesInsideCrown(std::vector<double> *pLstValue,
        GetMinMaxPoint_Of_LstManConMod(minPoint,maxPoint);
 
 
-       for (j=minPoint[1]; j<maxPoint[1]; j++)
+       for (j=minPoint[1]; j<=maxPoint[1]; j++)
        {
-               for (i=minPoint[0]; i<maxPoint[0]; i++)
+               for (i=minPoint[0]; i<=maxPoint[0]; i++)
                {
                        if (isInside(i,j,_typeOperation)==true)
                        {
@@ -365,6 +447,7 @@ vtkImageData *ContourExtractData::GetVtkImageMaskResult()
 // ------------------------------------------------------------------------
 void ContourExtractData::InitVtkImagesResult()
 {
+       printf("EED ContourExtractData::InitVtkImagesResult\n");
          int ext[6];
          int newDim[3];
          double spc[3];
@@ -398,9 +481,55 @@ void ContourExtractData::InitVtkImagesResult()
          imagedataMaskResult->SetSpacing(spc);
          imagedataMaskResult->SetDimensions( newDim );
          imagedataMaskResult->AllocateScalars();
+       printf("EED ContourExtractData::InitVtkImagesResult %p %p\n", imagedataValueResult, imagedataMaskResult);
 }
 
 
+//------------------------------------------------------------------------
+void ContourExtractData::InitVolumeStatistics()
+{
+       vol_rCountRange                         = 0;
+       vol_rsize                                       = 0;
+       vol_minValue                            = 9999999;
+       vol_maxValue                            =-9999999;
+       vol_acum_average                        = 0;
+       vol_acum_standardeviation       = 0;
+}
+
+//------------------------------------------------------------------------
+void ContourExtractData::SetVolumeStatistics(int rCountRange, 
+                                                                                       int rsize,
+                                                                                       double minValue,
+                                                                                       double maxValue,
+                                                                                       double acum_average,
+                                                                                       double acum_standardeviation)
+{
+       vol_rCountRange                         = vol_rCountRange + rCountRange; 
+       vol_rsize                                       = vol_rsize + rsize; 
+       
+       if (minValue<vol_minValue){ vol_minValue = minValue;  }
+       if (maxValue>vol_maxValue){ vol_maxValue = maxValue;  }
+       
+       vol_acum_average                        = vol_acum_average + acum_average; 
+       vol_acum_standardeviation       = vol_acum_standardeviation + acum_standardeviation; 
+}
+
+//------------------------------------------------------------------------
+void ContourExtractData::GetVolumeStatistics(int *vol_rCountRange, 
+                                                                                        int *vol_rsize,
+                                                                                        double *vol_minValue,
+                                                                                        double *vol_maxValue,
+                                                                                        double *vol_average,
+                                                                                        double *vol_standardeviation)
+{
+       *vol_rCountRange                = this->vol_rCountRange; 
+       *vol_rsize                              = this->vol_rsize; 
+       *vol_minValue                   = this->vol_minValue; 
+       *vol_maxValue                   = this->vol_maxValue; 
+       *vol_average                    = this->vol_acum_average / this->vol_rsize;
+       *vol_standardeviation   = sqrt(this->vol_acum_standardeviation / this->vol_rsize);
+}
+
 
 //------------------------------------------------------------------------
 void ContourExtractData::Statistics( std::vector<double> *inputLstValue, 
@@ -411,15 +540,17 @@ void ContourExtractData::Statistics( std::vector<double> *inputLstValue,
                                                                        double  *rmin, 
                                                                        double  *rmax,
                                                                        double  *raverage,
-                                                                       double  *rstandardeviation)
+                                                                       double  *rstandardeviation
+                                                                               )
 {
-         double min                            = 0;
-         double max                            = 0;
-         double average                        = 0;
-         double standardeviation       = 0;
-         double acum                           = 0;
-         int    size                           = 0;
-         int    countRange                     = 0;
+         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)
@@ -433,25 +564,27 @@ void ContourExtractData::Statistics( std::vector<double> *inputLstValue,
                        for ( i=0; i<size; i++ )
                        {
                                ng=(*inputLstValue)[i];
-                               acum = acum + ng;
+                               acum_average = acum_average + ng;
                                if (max<ng) max=ng;             // Max
                                if (min>ng) min=ng;     // Min
                                if ((ng>=grayRangeMin) && (ng<=grayRangeMax)) countRange++;  // countRange
-                       }
-                       average = acum / size;
+                       } // for average
+                       average = acum_average / size;
 
          // Standar Deviation
-                       acum=0;
+                       acum_standardeviation=0;
                        double tmp;
                        for ( i=0; i<size; i++ )
                        {
                 tmp = (*inputLstValue)[i] - average;
-                               acum = acum + tmp*tmp;
-                       }
-                       standardeviation = sqrt(acum/size);
-
-               }
-         }
+                               acum_standardeviation = acum_standardeviation + tmp*tmp;
+                       } // for standar deviation
+                       standardeviation = sqrt(acum_standardeviation/size);
+                       SetVolumeStatistics(countRange, size,
+                                                               min,max,
+                                                           acum_average,acum_standardeviation);
+               } // if size
+         } // if NULL
 
          // OUTPUT
                *rsize                          = size;