]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.cxx
creaButtonContainer & creaPanelButtonContainer: Updates in doxygen documentation...
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / HistogramWidget.cxx
index 4febab2d37b4d3e9fd3d3f6e0b5a350540a0c115..d3dbfc46b1898b5599aa4500d64b48504cd3cb73 100644 (file)
@@ -8,6 +8,7 @@
  #include "HistogramWidget.h"
  #include  "vtkImageCast.h"
  #include  <math.h>
+
 // ----------------------------------------------------------------------------
 // WX headers inclusion.
 // For compilers that support precompilation, includes <wx/wx.h>.
@@ -15,8 +16,9 @@
 
        #ifndef WX_PRECOMP
        #include <wx/wx.h>
-       #endif
 
+       #endif
+#include <wx/bitmap.h>
 //----------------------------------------------------------------------------
 // Class implementation
 //----------------------------------------------------------------------------
@@ -41,15 +43,16 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
        }
  */
        HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag,vtkImageData* imageData,int type):
-       wxPanel(parent,id,pos,size,flag)
+       wxPanel(parent,id,wxDefaultPosition,wxDefaultSize)
        {
                 SetBackgroundColour(wxColour(255,255,255));
                //histogram
                histogram= new pHistogram(imageData);
+
                
                //plotter
                plotter=new pPlotter(this, 400,350);
-
+               
                //is a plotter of histograms
                plotter->setType(2);
                //setting the popMenu
@@ -59,14 +62,55 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
                idHistogram=-1;
                transferenceFunctionHasColor=true;
                transferenceFunctionHasPoints=true;
-               this->type=type;;
+               this->type=type;
                
+               this->SetAutoLayout(true);
+               this->Refresh();
+        
                //drawing
                drawHistogram();
                drawTransferenceFunction();
                
        }
 
+       HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id)
+               : wxPanel(parent,id){
+
+
+                       SetBackgroundColour(wxColour(255,255,255));
+                       histogram = NULL;       
+                       
+                       
+                       //plotter
+                       plotter=new pPlotter(this, 400,350);
+                       
+                       //is a plotter of histograms
+                       plotter->setType(2);
+                       //setting the popMenu
+                       plotter->setPopUpMenu(true,true,true,true,true,true,false,false,false,false,false,false,false);
+                       histogramSize=0;
+                       idTransferenceFunction=-1;
+                       idHistogram=-1;
+                       transferenceFunctionHasColor=true;
+                       transferenceFunctionHasPoints=true;
+                       this->type=type;;
+                       this->SetAutoLayout(true);
+                       this->Refresh();
+               
+                               
+       }
+
+       
+       
+       void HistogramWidget::initializeHistogram(vtkImageData* img){
+               if(histogram ==NULL){
+                       histogram= new pHistogram(img);
+               }               
+               //draw
+               drawHistogram();
+               drawTransferenceFunction();
+       }
+
        HistogramWidget::~HistogramWidget()
        {
                delete histogram;
@@ -145,6 +189,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);             
                        // Including and drawing the created function in the plotter
                        if (tf)
                        {
@@ -171,8 +216,10 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
                GetClientSize(&scrX,&scrY);
                plotter->SetSize(scrX,scrY);
                pGraphicalFunction* actual=plotter->getFunction(idTransferenceFunction);
-               actual->setScreens(scrX,scrY);
-               actual->setScales();
+               if(actual!=NULL){
+                       actual->setScreens(scrX,scrY);
+                       actual->setScales();
+               }
                
        }
        /*
@@ -264,8 +311,12 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
        */
        bool  HistogramWidget::addPointToTransferenceFunction(double x, double y)
        {
+               bool result=false;
                pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
-               return tf->AddPoint(x,y);
+//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); }
+               
+               return result;
        }
        /*
                add a color point to the histogram
@@ -292,15 +343,16 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
                {
                        // we have to erase the points
                        pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
-                       int numOfPoints=tf->getSizePoints();
-                       int i=numOfPoints-1;//-2;
-                       while(i>=0)
-                       {
-                               tf->deletePointAt(i);
-                               i--;
-                       }
-                       
-               }
+                       if (tf!=NULL){
+                               int numOfPoints=tf->getSizePoints();
+                               int i=numOfPoints-1;//-2;
+                               while(i>=0)
+                               {
+                                       tf->deletePointAt(i);
+                                       i--;
+                               } // while
+                       } // if tf
+               } // if transferenceFunctionHasPoints
                
        //we set for actual the histogram
                //plotter->setActual()
@@ -342,4 +394,21 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint
                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){
+               plotter->GetValuesPointsFunction(greylevel,value,histogramSize);
+       }
 
+/**
+**     Returns two vectors, the grey level of the point and its value, the red, green
+**     and blue value is between [0,1]
+**/
+       void HistogramWidget::GetValuesColorPointsFunction(std::vector<double>& greylevel,
+                                                               std::vector<double>& red,
+                                                               std::vector<double>& green,
+                                                               std::vector<double>& blue)
+       {
+               plotter->GetValuesColorPointsFunction(greylevel,red,green,blue);
+       }