Histogram.cxx

Go to the documentation of this file.
00001 /*
00002  This class plots image's histograms in a plotter
00003 */
00004 
00005  //---------------------
00006  // Includes
00007  //----------------------
00008  #include "Histogram.h"
00009  #include  "vtkImageCast.h"
00010  #include  <math.h>
00011 // ----------------------------------------------------------------------------
00012 // WX headers inclusion.
00013 // For compilers that support precompilation, includes <wx/wx.h>.
00014 // ----------------------------------------------------------------------------
00015 
00016         #ifndef WX_PRECOMP
00017         #include <wx/wx.h>
00018         #endif
00019 
00020 //----------------------------------------------------------------------------
00021 // Class implementation
00022 //----------------------------------------------------------------------------
00023 
00024 IMPLEMENT_CLASS(Histogram, wxWindow)
00025 //----------------------------------------------------------------------------
00026 // Event Table
00027 //----------------------------------------------------------------------------
00028 
00029 BEGIN_EVENT_TABLE(Histogram, wxWindow)
00030         EVT_SIZE  (Histogram::OnSize)
00031 END_EVENT_TABLE()
00032  //---------------------
00033  // Constructor
00034  //----------------------
00035 
00036 //EED Borrame 07Mai2009
00037 //Histogram::Histogram( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag,vtkImageData* imageData):
00038         Histogram::Histogram( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag):
00039         wxPanel(parent,id,pos,size,flag)
00040         {
00041                  SetBackgroundColour(wxColour(255,255,255));
00042                 //histogram
00043 //EED Borrame 07Mai2009
00044 //              histogram= new pHistogram(imageData);
00045                 
00046                 //plotter
00047                 plotter=new pPlotterWindow(this, -1, wxPoint(0,0), wxSize(742,476), wxSUNKEN_BORDER );
00048                 
00049                 plotter->AddLayer(new pPlotterScaleX());
00050                 plotter->AddLayer(new pPlotterScaleY());
00051                 //is a plotter of histograms
00052                 plotter->setType(2);
00053                 //setting the popMenu
00054                 plotter->setPopUpMenu(true,true,true,true,true,true,false,false,false,false,false,false,false);
00055                 histogramSize=0;
00056                 
00057                 idHistogram=-1;
00058                 
00059 //EED Borrame 07Mai2009
00060                 //drawing
00061 //              drawHistogram();
00062                 
00063                 
00064         }
00065 
00066         Histogram::~Histogram()
00067         {
00068                 delete histogram;
00069                 delete plotter;
00070 
00071         }
00072 
00073     void Histogram::Configure(vtkImageData* imageData)
00074         {
00075                 histogram= new pHistogram(imageData);
00076                 drawHistogram();
00077         }
00078 
00079         /*
00080         Draw the histogram in the plotter
00081         */
00082         void Histogram::drawHistogram()
00083         {
00084                 //int xValues[MAX],yValues[MAX],extent[6];
00085                 double* xValues;
00086                 double* yValues;
00087                 
00088                 vtkImageData* histogramImageData=histogram->getHistogram();
00089                 
00090                 //size
00091                 histogramSize=histogram->getSize();
00092 
00093                 //plotting
00094                 xValues=(double*)malloc(NUM_POINTS*sizeof(double));
00095                 yValues=(double*)malloc(NUM_POINTS*sizeof(double));
00096                 
00097                 unsigned short* histogramPointer=(unsigned short*)histogramImageData->GetScalarPointer(0,0,0);
00098                 
00099                 for(int i=0; i< histogramSize; i++)
00100                 {
00101                         xValues[i]=i;
00102                         yValues[i]=log( (double) histogramPointer[i])*10;
00103                 }
00104 
00105                 
00106                 pGraphicalFunction* histogramFunction=plotter->getFunctionForVectors(xValues,histogramSize,yValues,histogramSize);
00107                 
00108                 if (histogramFunction)
00109                 {
00110                         histogramFunction->setEditable(false);
00111                         //smooth function
00112                         histogramFunction->setType(2);
00113                         //it is an histogram
00114                         histogramFunction->setmType(2);
00115                         idHistogram=plotter->addFunction(histogramFunction);
00116                         //for setting range the vision
00117                         plotter->addFunctionToMove(histogramFunction);
00118                         wxPen mypen1(*wxBLUE, 1, wxSOLID );
00119                         mypen1.SetWidth(2);
00120                         histogramFunction->SetPen( mypen1 );
00121                 }
00122                 
00123                 
00124                         free(xValues);
00125                         free(yValues);
00126                 
00127                 //plotter->setPopUpMenu(true,true,false,false,true,true,false,false,false,false,false,false,false);
00128         }
00129         
00130         /*
00131                 if the user resize the window   
00132         */
00133         void Histogram::OnSize(wxSizeEvent &WXUNUSED(event))
00134         {
00135                 int scrX,scrY;
00136                 GetClientSize(&scrX,&scrY);
00137                 plotter->SetSize(scrX,scrY);
00138                 /*
00139                 pGraphicalFunction* actual=plotter->getFunction(idTransferenceFunction);
00140                 actual->setScreens(scrX,scrY);
00141                 actual->setScales();
00142                 */
00143         }
00144         
00145         /*
00146                 get a point of the Histogram
00147                 given the grey value
00148         */
00149         int Histogram::getHistogramPoint(int gValue)
00150         {
00151                 return histogram->getHistogramPoint(gValue);
00152         }
00153         
00154 
00155         //-------------------
00156         // Getter and setters
00157         //-------------------
00158 
00159         int Histogram::getHistogramSize()
00160         {
00161                 return histogramSize;
00162         }
00163 
00164 

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1