]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/Histogram.cxx
#2490 creaMaracasVisu Feature New High - Histogram Interaction
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / Histogram.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 /*
27  This class plots image's histograms in a plotter
28 */
29
30  //---------------------
31  // Includes
32  //----------------------
33  #include "Histogram.h"
34  #include  "vtkImageCast.h"
35  #include  <math.h>
36 // ----------------------------------------------------------------------------
37 // WX headers inclusion.
38 // For compilers that support precompilation, includes <wx/wx.h>.
39 // ----------------------------------------------------------------------------
40
41         #ifndef WX_PRECOMP
42         #include <wx/wx.h>
43         #endif
44
45 //----------------------------------------------------------------------------
46 // Class implementation
47 //----------------------------------------------------------------------------
48
49 IMPLEMENT_CLASS(Histogram, wxWindow)
50 //----------------------------------------------------------------------------
51 // Event Table
52 //----------------------------------------------------------------------------
53
54 BEGIN_EVENT_TABLE(Histogram, wxWindow)
55         EVT_SIZE  (Histogram::OnSize)
56 END_EVENT_TABLE()
57  //---------------------
58  // Constructor
59  //----------------------
60
61 //EED Borrame 07Mai2009
62 //Histogram::Histogram( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag,vtkImageData* imageData):
63         Histogram::Histogram( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag):
64         wxPanel(parent,id,pos,size,flag)
65         {
66                  SetBackgroundColour(wxColour(255,255,255));
67                 //histogram
68 //EED Borrame 07Mai2009
69 //              histogram= new pHistogram(imageData);
70                 
71                 //plotter
72                 plotter=new pPlotterWindow(this, -1, wxPoint(0,0), wxSize(742,476), wxSUNKEN_BORDER );
73                 
74                 plotter->AddLayer(new pPlotterScaleX());
75                 plotter->AddLayer(new pPlotterScaleY());
76                 //is a plotter of histograms
77                 plotter->setType(2);
78                 //setting the popMenu
79                 plotter->setPopUpMenu(true,true,true,true,true,true,false,false,false,false,false,false,false);
80                 histogramSize=0;
81                 
82                 idHistogram=-1;
83                 
84 //EED Borrame 07Mai2009
85                 //drawing
86 //              drawHistogram();
87                 
88                 
89         }
90
91         Histogram::~Histogram()
92         {
93                 delete histogram;
94                 delete plotter;
95
96         }
97
98    void Histogram::Configure(vtkImageData* imageData)
99         {
100                 histogram= new pHistogram(imageData);
101                 drawHistogram();
102         }
103
104         /*
105         Draw the histogram in the plotter
106         */
107         void Histogram::drawHistogram()
108         {
109                 //int xValues[MAX],yValues[MAX],extent[6];
110                 double* xValues;
111                 double* yValues;
112                 
113                 vtkImageData* histogramImageData=histogram->getHistogram();
114                 
115                 //size
116                 histogramSize=histogram->getSize();
117
118                 //plotting
119                 xValues=(double*)malloc(NUM_POINTS*sizeof(double));
120                 yValues=(double*)malloc(NUM_POINTS*sizeof(double));
121                 
122                 double* histogramPointer=(double*)histogramImageData->GetScalarPointer(0,0,0);
123                 
124                 int i;
125                 for(i=0; i< histogramSize; i++)
126                 {
127                         xValues[i]=i;
128                         if (histogramPointer[i]==0)
129                         {
130                                 yValues[i]=0;
131                         } else {
132                                 yValues[i]=log(histogramPointer[i])*10;
133                         } // if histogramPointer
134                 } // for i
135
136                 
137                 pGraphicalFunction* histogramFunction=plotter->getFunctionForVectors(xValues,histogramSize,yValues,histogramSize);
138                 
139                 if (histogramFunction)
140                 {
141                         histogramFunction->setEditable(false);
142                         //smooth function
143                         histogramFunction->setType(2);
144                         //it is an histogram
145                         histogramFunction->setmType(2);
146                         idHistogram=plotter->addFunction(histogramFunction);
147                         //for setting range the vision
148                         plotter->addFunctionToMove(histogramFunction);
149                         wxPen mypen1(*wxBLUE, 1, wxSOLID );
150                         mypen1.SetWidth(2);
151                         histogramFunction->SetPen( mypen1 );
152                 }
153                 
154                 
155                         free(xValues);
156                         free(yValues);
157                 
158                 //plotter->setPopUpMenu(true,true,false,false,true,true,false,false,false,false,false,false,false);
159         }
160         
161         /*
162                 if the user resize the window   
163         */
164         void Histogram::OnSize(wxSizeEvent &WXUNUSED(event))
165         {
166                 int scrX,scrY;
167                 GetClientSize(&scrX,&scrY);
168                 plotter->SetSize(scrX,scrY);
169
170                 /*
171                 pGraphicalFunction* actual=plotter->getFunction(idTransferenceFunction);
172                 actual->setScreens(scrX,scrY);
173                 actual->setScales();
174                 */
175         }
176         
177         /*
178                 get a point of the Histogram
179                 given the grey value
180         */
181         int Histogram::getHistogramPoint(int gValue)
182         {
183                 return histogram->getHistogramPoint(gValue);
184         }
185         
186
187         //-------------------
188         // Getter and setters
189         //-------------------
190
191         int Histogram::getHistogramSize()
192         {
193                 return histogramSize;
194         }
195
196         wxWindow* Histogram::GetWindow()
197         {
198                 return this;
199         }
200
201         pPlotterWindow* Histogram::GetPlotterWindow()
202         {
203                 return plotter;
204         } 
205
206
207