2 This class plots image's histograms in a plotter
5 //---------------------
7 //----------------------
8 #include "HistogramWidget.h"
9 #include "vtkImageCast.h"
11 // ----------------------------------------------------------------------------
12 // WX headers inclusion.
13 // For compilers that support precompilation, includes <wx/wx.h>.
14 // ----------------------------------------------------------------------------
20 //----------------------------------------------------------------------------
21 // Class implementation
22 //----------------------------------------------------------------------------
24 IMPLEMENT_CLASS(HistogramWidget, wxWindow)
25 //----------------------------------------------------------------------------
27 //----------------------------------------------------------------------------
29 BEGIN_EVENT_TABLE(HistogramWidget, wxWindow)
30 EVT_SIZE (HistogramWidget::OnSize)
32 //---------------------
34 //----------------------
35 //wxScrolledWindow(wxWindow* parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxHSCROLL | wxVSCROLL, const wxString& name = "scrolledWindow")
36 //wxWindow(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxPanelNameStr)
37 //pPlotterWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag )
39 HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag):wxWindow(parent,id,pos,size,flag)
43 HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag,vtkImageData* imageData,int type):
44 wxPanel(parent,id,pos,size,flag)
46 SetBackgroundColour(wxColour(255,255,255));
48 histogram= new pHistogram(imageData);
51 plotter=new pPlotter(this, 400,350);
53 //is a plotter of histograms
56 plotter->setPopUpMenu(true,true,true,true,true,true,false,false,false,false,false,false,false);
58 idTransferenceFunction=-1;
60 transferenceFunctionHasColor=true;
61 transferenceFunctionHasPoints=true;
66 drawTransferenceFunction();
70 HistogramWidget::~HistogramWidget()
77 Draw the histogram in the plotter
79 void HistogramWidget::drawHistogram()
81 //int xValues[MAX],yValues[MAX],extent[6];
85 vtkImageData* histogramImageData=histogram->getHistogram();
88 histogramSize=histogram->getSize();
91 xValues=(double*)malloc(NUM_POINTS*sizeof(double));
92 yValues=(double*)malloc(NUM_POINTS*sizeof(double));
94 unsigned short* histogramPointer=(unsigned short*)histogramImageData->GetScalarPointer(0,0,0);
96 for(int i=0; i< histogramSize; i++)
99 yValues[i]=log( (double) histogramPointer[i]);
103 pGraphicalFunction* histogramFunction=plotter->getFunctionForVectors(xValues,histogramSize,yValues,histogramSize);
105 if (histogramFunction)
107 histogramFunction->setEditable(false);
109 histogramFunction->setType(2);
111 histogramFunction->setmType(2);
112 idHistogram=plotter->addFunction(histogramFunction);
113 //for setting range the vision
114 plotter->addFunctionToMove(histogramFunction);
115 wxPen mypen1(*wxBLUE, 1, wxSOLID );
117 histogramFunction->SetPen( mypen1 );
125 Draw the transference function in the plotter
128 void HistogramWidget::drawTransferenceFunction()
131 double xValues[5],yValues[5];
133 int maxValueGrey=histogram->getMaximumLevelOfGrey();
135 xValues[1]=maxValueGrey/16;
136 xValues[2]=maxValueGrey/8;
137 xValues[3]=maxValueGrey/16+(maxValueGrey-maxValueGrey/2)/2;
138 xValues[4]=maxValueGrey;
147 pGraphicalFunction * tf = plotter ->getFunctionForVectors( xValues, 5, yValues, 5 );
148 // Including and drawing the created function in the plotter
152 //is the actual Function
155 tf->SetShowPoints(true);
156 idTransferenceFunction=plotter->addFunction( tf );
158 plotter->addFunctionToMove(tf);
159 wxPen mypen(*wxBLACK,0.5, wxSOLID );
166 if the user resize the window
168 void HistogramWidget::OnSize(wxSizeEvent &WXUNUSED(event))
171 GetClientSize(&scrX,&scrY);
172 plotter->SetSize(scrX,scrY);
173 pGraphicalFunction* actual=plotter->getFunction(idTransferenceFunction);
174 actual->setScreens(scrX,scrY);
179 get number of points of the transference function
181 int HistogramWidget::getSizeTransferenceFunction()
183 pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
184 return tf->getSizePoints();
188 get a point of the transference function
190 void HistogramWidget::getTransferenceFunctionPoint(int index,int& x,int& y)
192 pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
195 wxNode* pnode=tf->GetPointAt(index);
196 pFunctionPoint* point=(pFunctionPoint*)pnode->GetData();
202 get a point of the Histogram
205 int HistogramWidget::getHistogramPoint(int gValue)
207 return histogram->getHistogramPoint(gValue);
210 get number of points of the barColor
212 int HistogramWidget::getSizeBarColor()
214 return plotter->getColorPointsSize();
217 get a color int the bqr color
219 void HistogramWidget:: getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
222 plotter->getBarColorDataAt(index,tmp,red,green,blue);
226 Returns the maximum value ot the histogram that is show to the user
228 float HistogramWidget::getMaxShowedPorcentage()
230 float porcentageMaxX=plotter->getMaxShowedPorcentage();
231 pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
232 int min=histogramFunction->getMinX();
233 float x=porcentageMaxX*(histogramFunction->getMaxX()-min);
237 Returns the minimum value ot the histogram that is show to the user
239 float HistogramWidget::getMinShowedPorcentage()
241 float porcentageMinX=plotter->getMinShowedPorcentage();
242 pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
243 int min=histogramFunction->getMinX();
244 float x=porcentageMinX*(histogramFunction->getMaxX()-min);
248 Returns the minimum value ot the histogram that is show to the user
250 float HistogramWidget::getActualShowedPorcentage()
252 float porcentageActualX=plotter->getMinShowedPorcentage();
253 pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
254 int min=histogramFunction->getMinX();
255 float x=porcentageActualX*(histogramFunction->getMaxX()-min);
258 //---------------------------------------
259 // setting data in transferences function
261 //----------------------------------------
263 Adds a point to the transference function
265 bool HistogramWidget::addPointToTransferenceFunction(double x, double y)
267 pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
268 return tf->AddPoint(x,y);
271 add a color point to the histogram
272 @param x the level of grey to which the color is assigned
273 @param red the level of red for the color
274 @param green the level of red for the color
275 @param blue the level of red for the color
277 bool HistogramWidget::addColorPoint(double x,int red,int green, int blue)
279 return plotter->addColorPoint(x,red,green,blue);
282 //------------------------
284 //------------------------
286 Erase all the points that are in the transference function
289 void HistogramWidget::erasePointsTransferenceFunction(/*bool allPoints*/)
291 if(transferenceFunctionHasPoints)
293 // we have to erase the points
294 pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
295 int numOfPoints=tf->getSizePoints();
296 int i=numOfPoints-1;//-2;
299 tf->deletePointAt(i);
305 //we set for actual the histogram
306 //plotter->setActual()
309 Erase the color points in the plotter
311 void HistogramWidget::eraseColorPoints()
313 plotter->eraseColorPoints();
318 void HistogramWidget::updatePlotter()
323 //-------------------
324 // Getter and setters
325 //-------------------
327 void HistogramWidget::setTransferenceFunctionHasPoints(bool hasPoints)
329 transferenceFunctionHasPoints=hasPoints;
332 void HistogramWidget::setTransferenceFunctionHasColor(bool hasColorPoints)
334 transferenceFunctionHasPoints=hasColorPoints;
336 int HistogramWidget::getHistogramSize()
338 return histogramSize;
340 void HistogramWidget::setType(int type)