]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/Histogram.cxx
c84931f0c2038f46765ac2d0c7861de2030805c8
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / Histogram.cxx
1 /*
2  This class plots image's histograms in a plotter
3 */
4
5  //---------------------
6  // Includes
7  //----------------------
8  #include "Histogram.h"
9  #include  "vtkImageCast.h"
10  #include  <math.h>
11 // ----------------------------------------------------------------------------
12 // WX headers inclusion.
13 // For compilers that support precompilation, includes <wx/wx.h>.
14 // ----------------------------------------------------------------------------
15
16         #ifndef WX_PRECOMP
17         #include <wx/wx.h>
18         #endif
19
20 //----------------------------------------------------------------------------
21 // Class implementation
22 //----------------------------------------------------------------------------
23
24 IMPLEMENT_CLASS(Histogram, wxWindow)
25 //----------------------------------------------------------------------------
26 // Event Table
27 //----------------------------------------------------------------------------
28
29 BEGIN_EVENT_TABLE(Histogram, wxWindow)
30         EVT_SIZE  (Histogram::OnSize)
31 END_EVENT_TABLE()
32  //---------------------
33  // Constructor
34  //----------------------
35
36 //EED Borrame 07Mai2009
37 //Histogram::Histogram( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag,vtkImageData* imageData):
38         Histogram::Histogram( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag):
39         wxPanel(parent,id,pos,size,flag)
40         {
41                  SetBackgroundColour(wxColour(255,255,255));
42                 //histogram
43 //EED Borrame 07Mai2009
44 //              histogram= new pHistogram(imageData);
45                 
46                 //plotter
47                 plotter=new pPlotterWindow(this, -1, wxPoint(0,0), wxSize(742,476), wxSUNKEN_BORDER );
48                 
49                 plotter->AddLayer(new pPlotterScaleX());
50                 plotter->AddLayer(new pPlotterScaleY());
51                 //is a plotter of histograms
52                 plotter->setType(2);
53                 //setting the popMenu
54                 plotter->setPopUpMenu(true,true,true,true,true,true,false,false,false,false,false,false,false);
55                 histogramSize=0;
56                 
57                 idHistogram=-1;
58                 
59 //EED Borrame 07Mai2009
60                 //drawing
61 //              drawHistogram();
62                 
63                 
64         }
65
66         Histogram::~Histogram()
67         {
68                 delete histogram;
69                 delete plotter;
70
71         }
72
73     void Histogram::Configure(vtkImageData* imageData)
74         {
75                 histogram= new pHistogram(imageData);
76                 drawHistogram();
77         }
78
79         /*
80         Draw the histogram in the plotter
81         */
82         void Histogram::drawHistogram()
83         {
84                 //int xValues[MAX],yValues[MAX],extent[6];
85                 double* xValues;
86                 double* yValues;
87                 
88                 vtkImageData* histogramImageData=histogram->getHistogram();
89                 
90                 //size
91                 histogramSize=histogram->getSize();
92
93                 //plotting
94                 xValues=(double*)malloc(NUM_POINTS*sizeof(double));
95                 yValues=(double*)malloc(NUM_POINTS*sizeof(double));
96                 
97                 unsigned short* histogramPointer=(unsigned short*)histogramImageData->GetScalarPointer(0,0,0);
98                 
99                 for(int i=0; i< histogramSize; i++)
100                 {
101                         xValues[i]=i;
102                         yValues[i]=log( (double) histogramPointer[i])*10;
103                 }
104
105                 
106                 pGraphicalFunction* histogramFunction=plotter->getFunctionForVectors(xValues,histogramSize,yValues,histogramSize);
107                 
108                 if (histogramFunction)
109                 {
110                         histogramFunction->setEditable(false);
111                         //smooth function
112                         histogramFunction->setType(2);
113                         //it is an histogram
114                         histogramFunction->setmType(2);
115                         idHistogram=plotter->addFunction(histogramFunction);
116                         //for setting range the vision
117                         plotter->addFunctionToMove(histogramFunction);
118                         wxPen mypen1(*wxBLUE, 1, wxSOLID );
119                         mypen1.SetWidth(2);
120                         histogramFunction->SetPen( mypen1 );
121                 }
122                 
123                 
124                         free(xValues);
125                         free(yValues);
126                 
127                 //plotter->setPopUpMenu(true,true,false,false,true,true,false,false,false,false,false,false,false);
128         }
129         
130         /*
131                 if the user resize the window   
132         */
133         void Histogram::OnSize(wxSizeEvent &WXUNUSED(event))
134         {
135                 int scrX,scrY;
136                 GetClientSize(&scrX,&scrY);
137                 plotter->SetSize(scrX,scrY);
138                 /*
139                 pGraphicalFunction* actual=plotter->getFunction(idTransferenceFunction);
140                 actual->setScreens(scrX,scrY);
141                 actual->setScales();
142                 */
143         }
144         
145         /*
146                 get a point of the Histogram
147                 given the grey value
148         */
149         int Histogram::getHistogramPoint(int gValue)
150         {
151                 return histogram->getHistogramPoint(gValue);
152         }
153         
154
155         //-------------------
156         // Getter and setters
157         //-------------------
158
159         int Histogram::getHistogramSize()
160         {
161                 return histogramSize;
162         }
163
164