]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/Histogram.cxx
creaMaracasVisu Library
[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         Histogram::Histogram( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag,vtkImageData* imageData):
37         wxPanel(parent,id,pos,size,flag)
38         {
39                  SetBackgroundColour(wxColour(255,255,255));
40                 //histogram
41                 histogram= new pHistogram(imageData);
42                 
43                 //plotter
44                 plotter=new pPlotterWindow(this, -1, wxPoint(0,0), wxSize(742,476), wxSUNKEN_BORDER );
45                 
46                 plotter->AddLayer(new pPlotterScaleX());
47                 plotter->AddLayer(new pPlotterScaleY());
48                 //is a plotter of histograms
49                 plotter->setType(2);
50                 //setting the popMenu
51                 plotter->setPopUpMenu(true,true,true,true,true,true,false,false,false,false,false,false,false);
52                 histogramSize=0;
53                 
54                 idHistogram=-1;
55                 
56                 //drawing
57                 drawHistogram();
58                 
59                 
60         }
61
62         Histogram::~Histogram()
63         {
64                 delete histogram;
65                 delete plotter;
66
67         }
68         /*
69         Draw the histogram in the plotter
70         */
71         void Histogram::drawHistogram()
72         {
73                 //int xValues[MAX],yValues[MAX],extent[6];
74                 double* xValues;
75                 double* yValues;
76                 
77                 vtkImageData* histogramImageData=histogram->getHistogram();
78                 
79                 //size
80                 histogramSize=histogram->getSize();
81
82                 //plotting
83                 xValues=(double*)malloc(NUM_POINTS*sizeof(double));
84                 yValues=(double*)malloc(NUM_POINTS*sizeof(double));
85                 
86                 unsigned short* histogramPointer=(unsigned short*)histogramImageData->GetScalarPointer(0,0,0);
87                 
88                 for(int i=0; i< histogramSize; i++)
89                 {
90                         xValues[i]=i;
91                         yValues[i]=log( (double) histogramPointer[i])*10;
92                 }
93
94                 
95                 pGraphicalFunction* histogramFunction=plotter->getFunctionForVectors(xValues,histogramSize,yValues,histogramSize);
96                 
97                 if (histogramFunction)
98                 {
99                         histogramFunction->setEditable(false);
100                         //smooth function
101                         histogramFunction->setType(2);
102                         //it is an histogram
103                         histogramFunction->setmType(2);
104                         idHistogram=plotter->addFunction(histogramFunction);
105                         //for setting range the vision
106                         plotter->addFunctionToMove(histogramFunction);
107                         wxPen mypen1(*wxBLUE, 1, wxSOLID );
108                         mypen1.SetWidth(2);
109                         histogramFunction->SetPen( mypen1 );
110                 }
111                 
112                 
113                         free(xValues);
114                         free(yValues);
115                 
116                 //plotter->setPopUpMenu(true,true,false,false,true,true,false,false,false,false,false,false,false);
117         }
118         
119         /*
120                 if the user resize the window   
121         */
122         void Histogram::OnSize(wxSizeEvent &WXUNUSED(event))
123         {
124                 int scrX,scrY;
125                 GetClientSize(&scrX,&scrY);
126                 plotter->SetSize(scrX,scrY);
127                 /*
128                 pGraphicalFunction* actual=plotter->getFunction(idTransferenceFunction);
129                 actual->setScreens(scrX,scrY);
130                 actual->setScales();
131                 */
132         }
133         
134         /*
135                 get a point of the Histogram
136                 given the grey value
137         */
138         int Histogram::getHistogramPoint(int gValue)
139         {
140                 return histogram->getHistogramPoint(gValue);
141         }
142         
143
144         //-------------------
145         // Getter and setters
146         //-------------------
147
148         int Histogram::getHistogramSize()
149         {
150                 return histogramSize;
151         }
152
153