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 printf("EED %p HistogramWidget::drawTransferenceFunction %p\n", this , tf);
149 // Including and drawing the created function in the plotter
153 //is the actual Function
156 tf->SetShowPoints(true);
157 idTransferenceFunction=plotter->addFunction( tf );
159 plotter->addFunctionToMove(tf);
160 wxPen mypen(*wxBLACK,0.5, wxSOLID );
167 if the user resize the window
169 void HistogramWidget::OnSize(wxSizeEvent &WXUNUSED(event))
172 GetClientSize(&scrX,&scrY);
173 plotter->SetSize(scrX,scrY);
174 pGraphicalFunction* actual=plotter->getFunction(idTransferenceFunction);
176 actual->setScreens(scrX,scrY);
182 get number of points of the transference function
184 int HistogramWidget::getSizeTransferenceFunction()
186 pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
187 return tf->getSizePoints();
191 get a point of the transference function
193 void HistogramWidget::getTransferenceFunctionPoint(int index,int& x,int& y)
195 pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
198 wxNode* pnode=tf->GetPointAt(index);
199 pFunctionPoint* point=(pFunctionPoint*)pnode->GetData();
205 get a point of the Histogram
208 int HistogramWidget::getHistogramPoint(int gValue)
210 return histogram->getHistogramPoint(gValue);
213 get number of points of the barColor
215 int HistogramWidget::getSizeBarColor()
217 return plotter->getColorPointsSize();
220 get a color int the bqr color
222 void HistogramWidget:: getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
225 plotter->getBarColorDataAt(index,tmp,red,green,blue);
229 Returns the maximum value ot the histogram that is show to the user
231 float HistogramWidget::getMaxShowedPorcentage()
233 float porcentageMaxX=plotter->getMaxShowedPorcentage();
234 pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
235 int min=histogramFunction->getMinX();
236 float x=porcentageMaxX*(histogramFunction->getMaxX()-min);
240 Returns the minimum value ot the histogram that is show to the user
242 float HistogramWidget::getMinShowedPorcentage()
244 float porcentageMinX=plotter->getMinShowedPorcentage();
245 pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
246 int min=histogramFunction->getMinX();
247 float x=porcentageMinX*(histogramFunction->getMaxX()-min);
251 Returns the minimum value ot the histogram that is show to the user
253 float HistogramWidget::getActualShowedPorcentage()
255 float porcentageActualX=plotter->getMinShowedPorcentage();
256 pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
257 int min=histogramFunction->getMinX();
258 float x=porcentageActualX*(histogramFunction->getMaxX()-min);
261 //---------------------------------------
262 // setting data in transferences function
264 //----------------------------------------
266 Adds a point to the transference function
268 bool HistogramWidget::addPointToTransferenceFunction(double x, double y)
271 pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
272 printf("EED %p HistogramWidget::addPointToTransferenceFunction tp%p x%f y%f %d\n",this, tf, x ,y, idTransferenceFunction);
273 if (tf!=NULL) { result=tf->AddPoint(x,y); }
278 add a color point to the histogram
279 @param x the level of grey to which the color is assigned
280 @param red the level of red for the color
281 @param green the level of red for the color
282 @param blue the level of red for the color
284 bool HistogramWidget::addColorPoint(double x,int red,int green, int blue)
286 return plotter->addColorPoint(x,red,green,blue);
289 //------------------------
291 //------------------------
293 Erase all the points that are in the transference function
296 void HistogramWidget::erasePointsTransferenceFunction(/*bool allPoints*/)
298 if(transferenceFunctionHasPoints)
300 // we have to erase the points
301 pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
303 int numOfPoints=tf->getSizePoints();
304 int i=numOfPoints-1;//-2;
307 tf->deletePointAt(i);
311 } // if transferenceFunctionHasPoints
313 //we set for actual the histogram
314 //plotter->setActual()
317 Erase the color points in the plotter
319 void HistogramWidget::eraseColorPoints()
321 plotter->eraseColorPoints();
326 void HistogramWidget::updatePlotter()
331 //-------------------
332 // Getter and setters
333 //-------------------
335 void HistogramWidget::setTransferenceFunctionHasPoints(bool hasPoints)
337 transferenceFunctionHasPoints=hasPoints;
340 void HistogramWidget::setTransferenceFunctionHasColor(bool hasColorPoints)
342 transferenceFunctionHasPoints=hasColorPoints;
344 int HistogramWidget::getHistogramSize()
346 return histogramSize;
348 void HistogramWidget::setType(int type)