]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.h
#2490 creaMaracasVisu Feature New High - Histogram Interaction
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / HistogramWidget.h
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
28 #ifndef __HISTOGRAMW__
29 #define __HISTOGRAMW__
30
31
32 // ----------------------------------------------------------------------------
33 // wx headers inclusion.
34 // For compilers that support precompilation, includes <wx/wx.h>.
35 // ----------------------------------------------------------------------------
36 #include <wx/wxprec.h>
37 #ifdef __BORLANDC__
38 #pragma hdrstop
39 #endif
40 #ifndef WX_PRECOMP
41 #include <wx/wx.h>
42 #endif
43
44 #include "marTypes.h"
45 #include "pPlotter.h"
46 #include "pFunctionPoint.h"
47 #include  "vtkImageData.h"
48 #include "pHistogram.h"
49 #include "pPlotterScaleY.h"
50 #include "pPlotterScaleX.h"
51
52 //#define MAX 500
53 #define NUM_POINTS 100
54 #define WINDOW_SIZE 10
55
56 class creaMaracasVisu_EXPORT HistogramWidget:public wxPanel
57 {
58 public:
59         //---------------------
60         // Constructor
61         //----------------------
62
63         //HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag );
64         
65  
66         HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag,vtkImageData* imageData,int type);
67
68         HistogramWidget( wxWindow *parent, wxWindowID id);
69         
70         ~HistogramWidget();
71
72         /*
73         Draw the histogram in the plotter
74         */
75         void drawHistogram();
76         /*
77         Draw the transference function in the plotter
78         */
79         void drawTransferenceFunction();
80         /*
81                 if the user resize the window   
82         */
83         void OnSize( wxSizeEvent &WXUNUSED(event) );
84         //---------------------------------------
85         // Get Information from the widget
86         //---------------------------------------
87         /*
88                 get number of points of the transference function
89         */
90         int getSizeTransferenceFunction();
91         /*
92                 get number of points of the barColor
93         */
94         int getSizeBarColor();
95         /*
96                 get a point of the transference function
97         */
98         void getTransferenceFunctionPoint(int index,int& x,int& y);
99         /*
100                 get a  color int the bqr color
101         */
102         void getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue);
103         /*
104                 get a point of the Histogram
105                 given the grey value
106         */
107         int getHistogramPoint(int gValue);
108
109         //--------------------
110         // bar Information
111         //---------------------
112         /*
113          Get the porcentage of the positions of 
114          the min,max and actual in the bar range
115         */
116         float getMaxShowedPorcentage();
117         float getMinShowedPorcentage(); 
118         float getActualShowedPorcentage();      
119
120         //---------------------------------------
121         // setting data in transferences function
122         // and in bar color
123         //----------------------------------------
124         /*
125           Adds a point to the transference function
126         */
127         bool addPointToTransferenceFunction(double x, double y);
128         /*
129                 add a color point to the histogram
130                 @param x the level of grey to which the color is assigned
131                 @param red the level of red for the color
132                 @param green the level of red for the color
133                 @param blue the level of red for the color
134         */
135         bool addColorPoint(double x,int red,int green, int blue);
136         //--------------------
137         // plotter Information
138         //---------------------
139         void updatePlotter();
140         
141         //------------------------
142         //Erase data
143         //------------------------
144         
145
146         /*
147          Erase all the points that are in the transference function
148         */
149         void erasePointsTransferenceFunction();
150         /*
151         Erase the  color points in the plotter
152         */
153         void eraseColorPoints();
154
155         //-------------------
156         // Getter and setters
157         //-------------------
158
159         void setTransferenceFunctionHasPoints(bool hasPoints);
160         void setTransferenceFunctionHasColor(bool hasColorPoints);
161         int getHistogramSize();
162         void setType(int type);
163
164         /**
165         **      Initialize the histogram 
166         */
167         void initializeHistogram(vtkImageData* img);
168         /**
169         **      Returns two vectors, the grey level of the point and its value, the value is between [0,1]
170         **/
171         void GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value);
172
173         /**
174         **      Returns two vectors, the grey level of the point and its value, the red, green
175         **      and blue value is between [0,1]
176         **/
177         void GetValuesColorPointsFunction(std::vector<double>& greylevel,
178                                                                         std::vector<double>& red,
179                                                                         std::vector<double>& green,
180                                                                         std::vector<double>& blue);
181
182
183         
184 private:
185         
186          pHistogram*    histogram;
187          pPlotter*              plotter;
188          int                            idTransferenceFunction;
189          int                            histogramSize;
190          int                            idHistogram;
191          /*
192           if the image has already a transference
193           function and color defines to that function
194           we have to draw it in the widget
195          */
196          bool transferenceFunctionHasPoints;
197          bool transferenceFunctionHasColor;
198          wxPanel* getControls();
199          /*
200          * type=1 with transference function for moving
201          * type=2 without transference function for moving
202          */
203          int type;      
204          
205          DECLARE_CLASS(HistogramWidget);
206          //----------------------------------------------------------------------------
207         // wxWidget macro use declaration for handdling events
208         //----------------------------------------------------------------------------
209         DECLARE_EVENT_TABLE()
210         
211 };
212 #endif
213
214