2 This class plots image's histograms in a plotter
5 //---------------------
7 //----------------------
8 #include "HistogramWidget.h"
9 #include "vtkImageCast.h"
12 // ----------------------------------------------------------------------------
13 // WX headers inclusion.
14 // For compilers that support precompilation, includes <wx/wx.h>.
15 // ----------------------------------------------------------------------------
21 #include <wx/bitmap.h>
22 //----------------------------------------------------------------------------
23 // Class implementation
24 //----------------------------------------------------------------------------
26 IMPLEMENT_CLASS(HistogramWidget, wxWindow)
27 //----------------------------------------------------------------------------
29 //----------------------------------------------------------------------------
31 BEGIN_EVENT_TABLE(HistogramWidget, wxWindow)
32 EVT_SIZE (HistogramWidget::OnSize)
34 //---------------------
36 //----------------------
37 //wxScrolledWindow(wxWindow* parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxHSCROLL | wxVSCROLL, const wxString& name = "scrolledWindow")
38 //wxWindow(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxPanelNameStr)
39 //pPlotterWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag )
41 HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag):wxWindow(parent,id,pos,size,flag)
45 HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag,vtkImageData* imageData,int type):
46 wxPanel(parent,id,wxDefaultPosition,wxDefaultSize)
48 SetBackgroundColour(wxColour(255,255,255));
50 histogram= new pHistogram(imageData);
54 plotter=new pPlotter(this, 400,350);
56 //is a plotter of histograms
59 plotter->setPopUpMenu(true,true,true,true,true,true,false,false,false,false,false,false,false);
61 idTransferenceFunction=-1;
63 transferenceFunctionHasColor=true;
64 transferenceFunctionHasPoints=true;
67 this->SetAutoLayout(true);
72 drawTransferenceFunction();
76 HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id)
80 SetBackgroundColour(wxColour(255,255,255));
85 plotter=new pPlotter(this, 400,350);
87 //is a plotter of histograms
90 plotter->setPopUpMenu(true,true,true,true,true,true,false,false,false,false,false,false,false);
92 idTransferenceFunction=-1;
94 transferenceFunctionHasColor=true;
95 transferenceFunctionHasPoints=true;
97 this->SetAutoLayout(true);
105 void HistogramWidget::initializeHistogram(vtkImageData* img){
106 if(histogram ==NULL){
107 histogram= new pHistogram(img);
111 drawTransferenceFunction();
114 HistogramWidget::~HistogramWidget()
121 Draw the histogram in the plotter
123 void HistogramWidget::drawHistogram()
125 //int xValues[MAX],yValues[MAX],extent[6];
129 vtkImageData* histogramImageData=histogram->getHistogram();
132 histogramSize=histogram->getSize();
135 xValues=(double*)malloc(NUM_POINTS*sizeof(double));
136 yValues=(double*)malloc(NUM_POINTS*sizeof(double));
138 unsigned short* histogramPointer=(unsigned short*)histogramImageData->GetScalarPointer(0,0,0);
140 for(int i=0; i< histogramSize; i++)
143 yValues[i]=log( (double) histogramPointer[i]);
147 pGraphicalFunction* histogramFunction=plotter->getFunctionForVectors(xValues,histogramSize,yValues,histogramSize);
149 if (histogramFunction)
151 histogramFunction->setEditable(false);
153 histogramFunction->setType(2);
155 histogramFunction->setmType(2);
156 idHistogram=plotter->addFunction(histogramFunction);
157 //for setting range the vision
158 plotter->addFunctionToMove(histogramFunction);
159 wxPen mypen1(*wxBLUE, 1, wxSOLID );
161 histogramFunction->SetPen( mypen1 );
169 Draw the transference function in the plotter
172 void HistogramWidget::drawTransferenceFunction()
175 double xValues[5],yValues[5];
177 int maxValueGrey=histogram->getMaximumLevelOfGrey();
179 xValues[1]=maxValueGrey/16;
180 xValues[2]=maxValueGrey/8;
181 xValues[3]=maxValueGrey/16+(maxValueGrey-maxValueGrey/2)/2;
182 xValues[4]=maxValueGrey;
191 pGraphicalFunction * tf = plotter ->getFunctionForVectors( xValues, 5, yValues, 5 );
192 printf("EED %p HistogramWidget::drawTransferenceFunction %p\n", this , tf);
193 // Including and drawing the created function in the plotter
197 //is the actual Function
200 tf->SetShowPoints(true);
201 idTransferenceFunction=plotter->addFunction( tf );
203 plotter->addFunctionToMove(tf);
204 wxPen mypen(*wxBLACK,0.5, wxSOLID );
211 if the user resize the window
213 void HistogramWidget::OnSize(wxSizeEvent &WXUNUSED(event))
216 GetClientSize(&scrX,&scrY);
217 plotter->SetSize(scrX,scrY);
218 pGraphicalFunction* actual=plotter->getFunction(idTransferenceFunction);
220 actual->setScreens(scrX,scrY);
226 get number of points of the transference function
228 int HistogramWidget::getSizeTransferenceFunction()
230 pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
231 return tf->getSizePoints();
235 get a point of the transference function
237 void HistogramWidget::getTransferenceFunctionPoint(int index,int& x,int& y)
239 pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
242 wxNode* pnode=tf->GetPointAt(index);
243 pFunctionPoint* point=(pFunctionPoint*)pnode->GetData();
249 get a point of the Histogram
252 int HistogramWidget::getHistogramPoint(int gValue)
254 return histogram->getHistogramPoint(gValue);
257 get number of points of the barColor
259 int HistogramWidget::getSizeBarColor()
261 return plotter->getColorPointsSize();
264 get a color int the bqr color
266 void HistogramWidget:: getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
269 plotter->getBarColorDataAt(index,tmp,red,green,blue);
273 Returns the maximum value ot the histogram that is show to the user
275 float HistogramWidget::getMaxShowedPorcentage()
277 float porcentageMaxX=plotter->getMaxShowedPorcentage();
278 pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
279 int min=histogramFunction->getMinX();
280 float x=porcentageMaxX*(histogramFunction->getMaxX()-min);
284 Returns the minimum value ot the histogram that is show to the user
286 float HistogramWidget::getMinShowedPorcentage()
288 float porcentageMinX=plotter->getMinShowedPorcentage();
289 pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
290 int min=histogramFunction->getMinX();
291 float x=porcentageMinX*(histogramFunction->getMaxX()-min);
295 Returns the minimum value ot the histogram that is show to the user
297 float HistogramWidget::getActualShowedPorcentage()
299 float porcentageActualX=plotter->getMinShowedPorcentage();
300 pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
301 int min=histogramFunction->getMinX();
302 float x=porcentageActualX*(histogramFunction->getMaxX()-min);
305 //---------------------------------------
306 // setting data in transferences function
308 //----------------------------------------
310 Adds a point to the transference function
312 bool HistogramWidget::addPointToTransferenceFunction(double x, double y)
315 pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
316 //printf("EED %p HistogramWidget::addPointToTransferenceFunction tp%p x%f y%f %d\n",this, tf, x ,y, idTransferenceFunction);
317 if (tf!=NULL) { result=tf->AddPoint(x,y); }
322 add a color point to the histogram
323 @param x the level of grey to which the color is assigned
324 @param red the level of red for the color
325 @param green the level of red for the color
326 @param blue the level of red for the color
328 bool HistogramWidget::addColorPoint(double x,int red,int green, int blue)
330 return plotter->addColorPoint(x,red,green,blue);
333 //------------------------
335 //------------------------
337 Erase all the points that are in the transference function
340 void HistogramWidget::erasePointsTransferenceFunction(/*bool allPoints*/)
342 if(transferenceFunctionHasPoints)
344 // we have to erase the points
345 pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
347 int numOfPoints=tf->getSizePoints();
348 int i=numOfPoints-1;//-2;
351 tf->deletePointAt(i);
355 } // if transferenceFunctionHasPoints
357 //we set for actual the histogram
358 //plotter->setActual()
361 Erase the color points in the plotter
363 void HistogramWidget::eraseColorPoints()
365 plotter->eraseColorPoints();
370 void HistogramWidget::updatePlotter()
375 //-------------------
376 // Getter and setters
377 //-------------------
379 void HistogramWidget::setTransferenceFunctionHasPoints(bool hasPoints)
381 transferenceFunctionHasPoints=hasPoints;
384 void HistogramWidget::setTransferenceFunctionHasColor(bool hasColorPoints)
386 transferenceFunctionHasPoints=hasColorPoints;
388 int HistogramWidget::getHistogramSize()
390 return histogramSize;
392 void HistogramWidget::setType(int type)
398 ** Returns two vectors, the grey level of the point and its value, the value is between [0,1]
400 void HistogramWidget::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value){
401 plotter->GetValuesPointsFunction(greylevel,value,histogramSize);
405 ** Returns two vectors, the grey level of the point and its value, the red, green
406 ** and blue value is between [0,1]
408 void HistogramWidget::GetValuesColorPointsFunction(std::vector<double>& greylevel,
409 std::vector<double>& red,
410 std::vector<double>& green,
411 std::vector<double>& blue)
413 plotter->GetValuesColorPointsFunction(greylevel,red,green,blue);