2 This class plots image's histograms in a plotter
5 //---------------------
7 //----------------------
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(Histogram, wxWindow)
25 //----------------------------------------------------------------------------
27 //----------------------------------------------------------------------------
29 BEGIN_EVENT_TABLE(Histogram, wxWindow)
30 EVT_SIZE (Histogram::OnSize)
32 //---------------------
34 //----------------------
36 Histogram::Histogram( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag,vtkImageData* imageData):
37 wxPanel(parent,id,pos,size,flag)
39 SetBackgroundColour(wxColour(255,255,255));
41 histogram= new pHistogram(imageData);
44 plotter=new pPlotterWindow(this, -1, wxPoint(0,0), wxSize(742,476), wxSUNKEN_BORDER );
46 plotter->AddLayer(new pPlotterScaleX());
47 plotter->AddLayer(new pPlotterScaleY());
48 //is a plotter of histograms
51 plotter->setPopUpMenu(true,true,true,true,true,true,false,false,false,false,false,false,false);
62 Histogram::~Histogram()
69 Draw the histogram in the plotter
71 void Histogram::drawHistogram()
73 //int xValues[MAX],yValues[MAX],extent[6];
77 vtkImageData* histogramImageData=histogram->getHistogram();
80 histogramSize=histogram->getSize();
83 xValues=(double*)malloc(NUM_POINTS*sizeof(double));
84 yValues=(double*)malloc(NUM_POINTS*sizeof(double));
86 unsigned short* histogramPointer=(unsigned short*)histogramImageData->GetScalarPointer(0,0,0);
88 for(int i=0; i< histogramSize; i++)
91 yValues[i]=log( (double) histogramPointer[i])*10;
95 pGraphicalFunction* histogramFunction=plotter->getFunctionForVectors(xValues,histogramSize,yValues,histogramSize);
97 if (histogramFunction)
99 histogramFunction->setEditable(false);
101 histogramFunction->setType(2);
103 histogramFunction->setmType(2);
104 idHistogram=plotter->addFunction(histogramFunction);
105 //for setting range the vision
106 plotter->addFunctionToMove(histogramFunction);
107 wxPen mypen1(*wxBLUE, 1, wxSOLID );
109 histogramFunction->SetPen( mypen1 );
116 //plotter->setPopUpMenu(true,true,false,false,true,true,false,false,false,false,false,false,false);
120 if the user resize the window
122 void Histogram::OnSize(wxSizeEvent &WXUNUSED(event))
125 GetClientSize(&scrX,&scrY);
126 plotter->SetSize(scrX,scrY);
128 pGraphicalFunction* actual=plotter->getFunction(idTransferenceFunction);
129 actual->setScreens(scrX,scrY);
135 get a point of the Histogram
138 int Histogram::getHistogramPoint(int gValue)
140 return histogram->getHistogramPoint(gValue);
144 //-------------------
145 // Getter and setters
146 //-------------------
148 int Histogram::getHistogramSize()
150 return histogramSize;