]> Creatis software - creaMaracasVisu.git/commitdiff
no message
authorEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Mon, 27 Jul 2009 15:06:08 +0000 (15:06 +0000)
committerEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Mon, 27 Jul 2009 15:06:08 +0000 (15:06 +0000)
lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourExtractData.cxx
lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourExtractData.h
lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.cxx

index 4e32b1e7990c9b767e5038a829c55c2148441699..4604878d8e968e079dbbe8e30d4677c5d2321ddd 100644 (file)
@@ -22,10 +22,10 @@ ContourExtractData::ContourExtractData( bool okImagesResults)
 //----------------------------------------------------------------------
 void ContourExtractData::SetImage( vtkImageData* imagedata)
   {
-    this->imagedata                    = imagedata;
-       if (this->okImagesResults==true){
-               InitVtkImagesResult();
-       }
+       this->imagedata                 = imagedata;
+               
+       // init vtk image result : valuesImage maskImage  
+       if (this->okImagesResults==true){  InitVtkImagesResult(); }
   }
 //----------------------------------------------------------------------
 void ContourExtractData::SetZtoBeAnalys( int z )
@@ -88,8 +88,8 @@ void ContourExtractData::GetMinMaxPoint_Of_LstManConMod(      int *minPoint,
                GetMinMaxPoint(minPoint,maxPoint,lstManConMod[i]);
        }
 }
-//------------------------------------------------------------------------
 
+//------------------------------------------------------------------------
 int ContourExtractData::AnalisisContourInside(int x, 
                                            int y, 
                                            manualContourModel *manualcontourmodel
@@ -129,11 +129,12 @@ int ContourExtractData::AnalisisContourInside(int x,
                        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)&&(y>=y1)&&(y<y2)) || ((y1>y2)&&(y>=y2)&&(y<y1)) )
                        {
                                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)) )   
                                { 
@@ -148,13 +149,14 @@ int ContourExtractData::AnalisisContourInside(int x,
                                } 
                        } // if point inside contour 
                        
+                       //Border verification
+                       if (   (x==(int)borderX) && (y==(int)borderY)   )  { inBorder=true; }// if point in border
                        
-                       //Border verication
-                       if (   (x==(int)borderX) && (y==(int)borderY)   )  
-                       { 
-                               inBorder=true;
-                               i=nps;
-                       }// if point in border
+                       // Verification : border in horizontal line 
+                       if ( ((int)y1==(int)y2)  &&  ((int)y1==y) && (x1<x2) && (x>=x1) && (x<=x2))             { inBorder=true;        }
+                       if ( ((int)y1==(int)y2)  &&  ((int)y1==y) && (x2<x1) && (x>=x2) && (x<=x1))             { inBorder=true;        }
+
+                       if (inBorder==true){ i=nps; }
                        
                        x1=x2; y1=y2; z1=z2;
                        
@@ -166,9 +168,99 @@ int ContourExtractData::AnalisisContourInside(int x,
        return result;
 }
 
+
 //------------------------------------------------------------------------
+int ContourExtractData::AnalisisContourInsideV2(int x, int y, int iContour )
+{
+       bool inBorder=false;
+       int result      = 0;
+       int i;
 
+       int nps=_lstlstlstVecX1[iContour][y].size();
+       
+       double x1,y1,x2,y2;
+       double borderX, borderY;
+       double xx1, yy1,xx2, yy2;
+       double xx=x, yy=y;
+       double d;
 
+       for (i=0; i<nps; i++)
+       {
+               x1=_lstlstlstVecX1[iContour][y][i];
+               y1=_lstlstlstVecY1[iContour][y][i];
+               x2=_lstlstlstVecX2[iContour][y][i];
+               y2=_lstlstlstVecY2[iContour][y][i];
+               
+               borderX=x1;
+               borderY=y1;
+               
+               if (y1<y2) 
+               { 
+                       xx1=x1; yy1=y1; xx2=x2; yy2=y2;
+               } else {
+                       xx1=x2; yy1=y2; xx2=x1; yy2=y1; 
+               } 
+               
+               double difxx2xx1=fabs(xx2-xx1);
+               if (difxx2xx1==0) difxx2xx1=0.0000000001;
+               
+               // Finding border looking in vertical direction  AND  verifing if pixel is at right of the line 
+               if  ( (yy>=yy1)&&(yy<=yy2) ) 
+               {
+                               
+                       //by triangle similarity
+                       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 (xx1<=xx2)   
+                               { 
+                                       borderX = xx1+d;
+                                       borderY = y;
+                               } else { 
+                                       borderX = xx1-d;
+                                       borderY = y;
+                               } 
+                       } 
+               } // if point inside y 
+               
+               
+               // Finding border looking in vertical direction
+               if ( ((xx1<=xx2)&&(xx>=xx1)&&(xx<xx2)) || ((xx1>xx2)&&(xx>=xx2)&&(xx<xx1)) )
+               {
+                       if ( (yy2-yy1)/difxx2xx1 <= 1.0)
+                       {
+                               //by triangle similarity
+                               d = ( fabs(xx1-xx)*(yy2-yy1) ) / difxx2xx1;
+                               if (yy1+d<=yy2) {
+                                       borderX=x;
+                                       borderY=yy1+d;
+                               }
+                       }                       
+               } // if point inside x                  
+               
+               
+               //Border verification
+               if (   (x==(int)borderX) && (y==(int)borderY)   )  { inBorder=true; }// if point in border
+               
+               // Verification : border in horizontal line 
+               if ( ((int)y1==(int)y2)  &&  ((int)y1==y) && (x1<x2) && (x>=x1) && (x<=x2))             { inBorder=true;        }
+               if ( ((int)y1==(int)y2)  &&  ((int)y1==y) && (x2<x1) && (x>=x2) && (x<=x1))             { inBorder=true;        }
+               
+               if (inBorder==true){ i=nps; }           
+       } // for i
+
+       
+       if (inBorder==true)     { result=1;     }
+       
+       return result;
+}
+
+
+
+//------------------------------------------------------------------------
 bool ContourExtractData::isInside(int x, int y, int typeOperation)
 {
        bool result                             = false;
@@ -186,7 +278,8 @@ bool ContourExtractData::isInside(int x, int y, int typeOperation)
                {
                        for (i=0;i<size;i++)
                        {
-                               numberLeft =  AnalisisContourInside(x,y, lstManConMod[i] );
+//                             numberLeft =  AnalisisContourInside(x,y, lstManConMod[i] );
+                               numberLeft =  AnalisisContourInsideV2(x,y, i );
                                if ( (numberLeft % 2) ==1){         numberInside++;  }
                        }
                        if ( numberInside == (size) ){ result=true; }
@@ -197,7 +290,8 @@ bool ContourExtractData::isInside(int x, int y, int typeOperation)
                {
                        for (i=0;i<size;i++)
                        {
-                               numberLeft =  AnalisisContourInside(x,y, lstManConMod[i] );
+//                             numberLeft =  AnalisisContourInside(x,y, lstManConMod[i] );
+                               numberLeft =  AnalisisContourInsideV2(x,y, i );
                                if ( (numberLeft % 2) ==1){ result=true;  }
                        }
                } // OR  All
@@ -206,7 +300,8 @@ bool ContourExtractData::isInside(int x, int y, int typeOperation)
                {
                        for (i=0;i<size;i++)
                        {
-                               numberLeft = numberLeft + AnalisisContourInside(x,y, lstManConMod[i] );
+//                             numberLeft = numberLeft + AnalisisContourInside(x,y, lstManConMod[i] );
+                               numberLeft = numberLeft + AnalisisContourInsideV2(x,y, i );
                        }
                        if ( numberLeft % 2 ==1){       result = true;  } 
                }// XOR  crown
@@ -318,17 +413,6 @@ void ContourExtractData::ResetImageResult(int z)
                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;
-                       *pValue = 0;
-                       pMask++;
-                       pValue++;
-               }// for
-       */ 
-               
        } // if
 }
 
@@ -351,6 +435,8 @@ 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++)
@@ -400,7 +486,7 @@ void ContourExtractData::GetValuesInsideCrown(std::vector<double> *pLstValue,
        maxPoint[1] = -999999;
 
        GetMinMaxPoint_Of_LstManConMod(minPoint,maxPoint);
-
+    InitLstContoursLinesYPoints();
 
        for (j=minPoint[1]; j<=maxPoint[1]; j++)
        {
@@ -447,7 +533,6 @@ vtkImageData *ContourExtractData::GetVtkImageMaskResult()
 // ------------------------------------------------------------------------
 void ContourExtractData::InitVtkImagesResult()
 {
-       printf("EED ContourExtractData::InitVtkImagesResult\n");
          int ext[6];
          int newDim[3];
          double spc[3];
@@ -481,7 +566,6 @@ void ContourExtractData::InitVtkImagesResult()
          imagedataMaskResult->SetSpacing(spc);
          imagedataMaskResult->SetDimensions( newDim );
          imagedataMaskResult->AllocateScalars();
-       printf("EED ContourExtractData::InitVtkImagesResult %p %p\n", imagedataValueResult, imagedataMaskResult);
 }
 
 
@@ -600,3 +684,69 @@ void ContourExtractData::SetTypeOperation(int type)
 {
        _typeOperation=type;
 }
+
+//------------------------------------------------------------------------
+void ContourExtractData::Fill_lstlstlstVecXY(int iContour, int sizeY)
+{
+       int i,y;
+       double x1,y1,z1,x2,y2,z2;
+       manualContourModel *manualcontourmodel= lstManConMod[iContour]; 
+       int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline
+       manualcontourmodel->UpdateSpline();
+       //------------------------------------------------------------------------------------------------------
+       
+       for (y=0;y<sizeY;y++)
+       {
+               manualcontourmodel->GetSpline_i_Point(0,&x1,&y1,&z1);
+               x1=x1+0.5; y1=y1+0.5;
+               for (i=1; i<=nps; i++)
+               {
+                       manualcontourmodel->GetSpline_i_Point(i,&x2,&y2,&z2);
+                       x2=x2+0.5; y2=y2+0.5;
+                       if ( ((y1<y2)&&(y>=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();
+       
+       int ext[6];
+       this->imagedata->GetWholeExtent(ext);
+       int sizeY = ext[3]-ext[2]+1;
+       std::vector<double> vecDouble;
+       std::vector< std::vector<double> > vecVecDouble;
+       for ( i=0 ; i<sizeY ; i++ )
+       {
+               vecVecDouble.push_back( vecDouble );
+       }
+       
+       //Fill structure with points
+       int sizeContours = lstManConMod.size();
+       for( i=0 ; i<sizeContours ; i++ )
+       {
+               _lstlstlstVecX1.push_back( vecVecDouble );
+               _lstlstlstVecY1.push_back( vecVecDouble );
+               _lstlstlstVecX2.push_back( vecVecDouble );
+               _lstlstlstVecY2.push_back( vecVecDouble );
+               Fill_lstlstlstVecXY(i,sizeY);
+       }
+       
+}
+
+
index 658f5d4319b521f4fe3205e71a1726642d81d3c8..a1d4ddc3ee27679360d2e12e89e763b73363413b 100644 (file)
        int AnalisisContourInside(      int x, 
                                                                int y, 
                                                                manualContourModel *manualcontourmodel );
+       int AnalisisContourInsideV2(int x, int y, int iContour );
+         
        double GetDataValue(int x, int y, int z);
        void PutVtkImageDataResultValue( int x, int y,int z, double value );
        void InitVtkImagesResult();
 
-
          //--Volume Statistics--
          int           vol_rCountRange;
          int           vol_rsize;
                                                           double minValue,double maxValue,
                                                           double acum_average, double acum_standardeviation);
          
+         // Optimize IsInside
+         // List of contours , list of linesY, list of points over the line
+         std::vector< std::vector< std::vector<double> > >             _lstlstlstVecX1;
+         std::vector< std::vector< std::vector<double> > >             _lstlstlstVecY1;
+         std::vector< std::vector< std::vector<double> > >             _lstlstlstVecX2;
+         std::vector< std::vector< std::vector<double> > >             _lstlstlstVecY2;
+         void Fill_lstlstlstVecXY(int iContour, int sizeY);
+         void InitLstContoursLinesYPoints();
+
   };
 
 
index 693b7d8510c8f1d2bc5f6c251e70a951ce550e39..4f4e5b5d3e91e9764cc07387abff23a633b92ebc 100644 (file)
@@ -4,11 +4,8 @@
  *  \brief Class bbtk::ThresholdImageView . 
  */
 
-
 #include "ThresholdImageView.h"
 
-
-
   //=========================================================================
        ThresholdImageView::ThresholdImageView( )
   {
@@ -36,7 +33,6 @@
 //----------------------------------------------------------------------------
 void ThresholdImageView::SetImage(vtkImageData* image)
 {
-       printf("ThresholdImageView::SetImage %p\n", image);
        _image = image;
 }
 
@@ -78,15 +74,12 @@ void ThresholdImageView::onThreshold()
                range[1]=255;
        }
        
-       
        int minTot = floor (range[0]);
        int maxTot = ceil (range[1]);
        
-       
        int minVal = floor (_minValue);
        int maxVal = floor (_maxValue);
        
-       
        if (!_actorPresent)
        {
                if (_imageReslicer==NULL)
@@ -163,7 +156,6 @@ void ThresholdImageView::onThreshold()
                baseView->GetRenderer()->AddActor( _thresholdActor );
                _actorPresent = true;
        }
-       
        else
        {
                _imageReslicer->SetResliceAxesOrigin(0,0,z);
@@ -192,7 +184,6 @@ void ThresholdImageView::onThreshold()
                                _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
                        }
                }
-               
                _thresholdTable->Build( );
                _thresholdMapper->SetLookupTable( _thresholdTable );
                _thresholdMapper->SetInput( img );
@@ -219,13 +210,10 @@ void ThresholdImageView::onThresholdInterpolation(bool interpolate)
                {
                        _thresholdActor->InterpolateOn( );
                }
-               
                else
                {
                        _thresholdActor->InterpolateOff( );
-               }
-               
-//EED          _theViewPanel->RefreshInterface();
+               }               
        }
 }
 
@@ -236,8 +224,6 @@ void ThresholdImageView::onThresholdChangeOpacity (int opacity)
        {
                _thresholdActor->SetOpacity(opacity*0.1);
        }
-       
-//EED  _theViewPanel->RefreshInterface();
 }
 
 //----------------------------------------------------------------------------
@@ -248,9 +234,7 @@ void ThresholdImageView::onThresholdRemove()
                wxVtkBaseView * baseView = _baseView;
                baseView->GetRenderer()->RemoveActor( _thresholdActor );
                _actorPresent = false;
-       }
-       
-//EED  _theViewPanel->RefreshInterface();
+       }       
 }