]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.cxx
#2482 creaMaracasVisu Bug New High - ColorLayer refresh missing. The MPR is not...
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / HistogramWidget.cxx
index 999ff6f699c32cbd4f39a46d18ae556ad5aa82ad..9d80407174362c6653c4377464ef52e776354922 100644 (file)
@@ -128,7 +128,8 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
        
        
        void HistogramWidget::initializeHistogram(vtkImageData* img){
-               if(histogram ==NULL){
+               if(histogram ==NULL)
+               {
                        histogram= new pHistogram(img);
                }               
                //draw
@@ -160,13 +161,18 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
                xValues=(double*)malloc(NUM_POINTS*sizeof(double));
                yValues=(double*)malloc(NUM_POINTS*sizeof(double));
                
-               unsigned short* histogramPointer=(unsigned short*)histogramImageData->GetScalarPointer(0,0,0);
-               
-               for(int i=0; i< histogramSize; i++)
+               double* histogramPointer=(double*)histogramImageData->GetScalarPointer(0,0,0);
+               int i;
+               for(i=0; i< histogramSize; i++)
                {
                        xValues[i]=i;
-                       yValues[i]=log( (double) histogramPointer[i]);
-               }
+                       if (histogramPointer[i]==0)
+                       {
+                               yValues[i]=0;
+                       } else {
+                               yValues[i]=log(histogramPointer[i])*10;
+                       } // histogramPointer 
+               } // for i
 
                
                pGraphicalFunction* histogramFunction=plotter->getFunctionForVectors(xValues,histogramSize,yValues,histogramSize);
@@ -196,7 +202,6 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
        */
        void HistogramWidget::drawTransferenceFunction()
        {
-       
                        double xValues[5],yValues[5];
                        //xValues
                        int maxValueGrey=histogram->getMaximumLevelOfGrey();
@@ -214,7 +219,7 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
                        yValues[4]=0;
                        
                        pGraphicalFunction * tf = plotter ->getFunctionForVectors( xValues, 5, yValues, 5 ); 
-               printf("EED %p HistogramWidget::drawTransferenceFunction %p\n", this , tf);             
+                       printf("EED %p HistogramWidget::drawTransferenceFunction %p\n", this , tf);             
                        // Including and drawing the created function in the plotter
                        if (tf)
                        {
@@ -225,11 +230,13 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
                                tf->SetShowPoints(true);
                                idTransferenceFunction=plotter->addFunction( tf );
                                if(type==1)
+                               {
                                        plotter->addFunctionToMove(tf);
+                               }
                                wxPen mypen(*wxBLACK,0.5, wxSOLID  );
                                mypen.SetWidth(2);
                                tf->SetPen( mypen );
-                       }
+                       } // if tf
        }
 
        /*
@@ -241,7 +248,8 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
                GetClientSize(&scrX,&scrY);
                plotter->SetSize(scrX,scrY);
                pGraphicalFunction* actual=plotter->getFunction(idTransferenceFunction);
-               if(actual!=NULL){
+               if(actual!=NULL)
+               {
                        actual->setScreens(scrX,scrY);
                        actual->setScales();
                }
@@ -262,12 +270,12 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
        void HistogramWidget::getTransferenceFunctionPoint(int index,int& x,int& y)
        {
                pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
-               if(tf)
+               if(tf!=NULL)
                {
-                       wxNode* pnode=tf->GetPointAt(index);
-                       pFunctionPoint* point=(pFunctionPoint*)pnode->GetData();
-                       x=point->getRealX();
-                       y=point->getRealY();
+                       wxNode* pnode                           = tf->GetPointAt(index);
+                       pFunctionPoint* point   = (pFunctionPoint*)pnode->GetData();
+                       x                                                               = point->getRealX();
+                       y                                                               = point->getRealY();
                }
        }
        /*
@@ -288,21 +296,21 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
        /*
                get a  color int the bqr color
        */
-       void HistogramWidget:: getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
+       void HistogramWidget::getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
        {
-               double tmp=x;
+               double tmp      = x;
                plotter->getBarColorDataAt(index,tmp,red,green,blue);
-               x=(int)tmp;
+               x                               = (int)tmp;
        }
        /*
         Returns the  maximum value ot the histogram that is show to the user 
        */
        float HistogramWidget::getMaxShowedPorcentage()
        {
-               float  porcentageMaxX=plotter->getMaxShowedPorcentage();
-               pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
-               int min=histogramFunction->getMinX();
-               float x=porcentageMaxX*(histogramFunction->getMaxX()-min);
+               float  porcentageMaxX                                           = plotter->getMaxShowedPorcentage();
+               pGraphicalFunction* histogramFunction   = plotter->getFunction(idHistogram);
+               int min                                                                                 = histogramFunction->getMinX();
+               float x                                                                                 = porcentageMaxX*(histogramFunction->getMaxX()-min);
                return min+ x;
        }
        /*
@@ -310,10 +318,10 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
        */
        float HistogramWidget::getMinShowedPorcentage()
        {
-               float  porcentageMinX=plotter->getMinShowedPorcentage();
-               pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
-               int min=histogramFunction->getMinX();
-               float x=porcentageMinX*(histogramFunction->getMaxX()-min);
+               float  porcentageMinX                                           = plotter->getMinShowedPorcentage();
+               pGraphicalFunction* histogramFunction   = plotter->getFunction(idHistogram);
+               int min                                                                                 = histogramFunction->getMinX();
+               float x                                                                                 = porcentageMinX*(histogramFunction->getMaxX()-min);
                return min+ x;
        }
        /*
@@ -321,11 +329,11 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
        */
        float HistogramWidget::getActualShowedPorcentage()
        {
-               float  porcentageActualX=plotter->getMinShowedPorcentage();
-               pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
-               int min=histogramFunction->getMinX();
-               float x=porcentageActualX*(histogramFunction->getMaxX()-min);
-               return min+ x;
+               float  porcentageActualX                                        = plotter->getMinShowedPorcentage();
+               pGraphicalFunction* histogramFunction   = plotter->getFunction(idHistogram);
+               int min                                                                                 = histogramFunction->getMinX();
+               float x                                                                                 = porcentageActualX*(histogramFunction->getMaxX()-min);
+               return min + x;
        }
        //---------------------------------------
        // setting data in transferences function
@@ -339,7 +347,10 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
                bool result=false;
                pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
 //printf("EED %p HistogramWidget::addPointToTransferenceFunction tp%p x%f y%f %d\n",this, tf, x ,y, idTransferenceFunction);
-               if (tf!=NULL) { result=tf->AddPoint(x,y); }
+               if (tf!=NULL) 
+               { 
+                       result=tf->AddPoint(x,y); 
+               } // if tf
                
                return result;
        }
@@ -403,26 +414,29 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
 
        void HistogramWidget::setTransferenceFunctionHasPoints(bool hasPoints)
        {
-               transferenceFunctionHasPoints=hasPoints;
+               transferenceFunctionHasPoints = hasPoints;
        }
 
        void HistogramWidget::setTransferenceFunctionHasColor(bool hasColorPoints)
        {
-               transferenceFunctionHasPoints=hasColorPoints;
+               transferenceFunctionHasPoints = hasColorPoints;
        }
+
        int HistogramWidget::getHistogramSize()
        {
                return histogramSize;
        }
+
        void HistogramWidget::setType(int type)
        {
-               this->type=type;
+               this->type = type;
        }
 
 /**
 **     Returns two vectors, the grey level of the point and its value, the value is between [0,1]
 **/
-       void HistogramWidget::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value){
+       void HistogramWidget::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value)
+       {
                plotter->GetValuesPointsFunction(greylevel,value,histogramSize);
        }