Histogram.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "Histogram.h"
00009 #include "vtkImageCast.h"
00010 #include <math.h>
00011
00012
00013
00014
00015
00016 #ifndef WX_PRECOMP
00017 #include <wx/wx.h>
00018 #endif
00019
00020
00021
00022
00023
00024 IMPLEMENT_CLASS(Histogram, wxWindow)
00025
00026
00027
00028
00029 BEGIN_EVENT_TABLE(Histogram, wxWindow)
00030 EVT_SIZE (Histogram::OnSize)
00031 END_EVENT_TABLE()
00032
00033
00034
00035
00036
00037
00038 Histogram::Histogram( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag):
00039 wxPanel(parent,id,pos,size,flag)
00040 {
00041 SetBackgroundColour(wxColour(255,255,255));
00042
00043
00044
00045
00046
00047 plotter=new pPlotterWindow(this, -1, wxPoint(0,0), wxSize(742,476), wxSUNKEN_BORDER );
00048
00049 plotter->AddLayer(new pPlotterScaleX());
00050 plotter->AddLayer(new pPlotterScaleY());
00051
00052 plotter->setType(2);
00053
00054 plotter->setPopUpMenu(true,true,true,true,true,true,false,false,false,false,false,false,false);
00055 histogramSize=0;
00056
00057 idHistogram=-1;
00058
00059
00060
00061
00062
00063
00064 }
00065
00066 Histogram::~Histogram()
00067 {
00068 delete histogram;
00069 delete plotter;
00070
00071 }
00072
00073 void Histogram::Configure(vtkImageData* imageData)
00074 {
00075 histogram= new pHistogram(imageData);
00076 drawHistogram();
00077 }
00078
00079
00080
00081
00082 void Histogram::drawHistogram()
00083 {
00084
00085 double* xValues;
00086 double* yValues;
00087
00088 vtkImageData* histogramImageData=histogram->getHistogram();
00089
00090
00091 histogramSize=histogram->getSize();
00092
00093
00094 xValues=(double*)malloc(NUM_POINTS*sizeof(double));
00095 yValues=(double*)malloc(NUM_POINTS*sizeof(double));
00096
00097 unsigned short* histogramPointer=(unsigned short*)histogramImageData->GetScalarPointer(0,0,0);
00098
00099 for(int i=0; i< histogramSize; i++)
00100 {
00101 xValues[i]=i;
00102 yValues[i]=log( (double) histogramPointer[i])*10;
00103 }
00104
00105
00106 pGraphicalFunction* histogramFunction=plotter->getFunctionForVectors(xValues,histogramSize,yValues,histogramSize);
00107
00108 if (histogramFunction)
00109 {
00110 histogramFunction->setEditable(false);
00111
00112 histogramFunction->setType(2);
00113
00114 histogramFunction->setmType(2);
00115 idHistogram=plotter->addFunction(histogramFunction);
00116
00117 plotter->addFunctionToMove(histogramFunction);
00118 wxPen mypen1(*wxBLUE, 1, wxSOLID );
00119 mypen1.SetWidth(2);
00120 histogramFunction->SetPen( mypen1 );
00121 }
00122
00123
00124 free(xValues);
00125 free(yValues);
00126
00127
00128 }
00129
00130
00131
00132
00133 void Histogram::OnSize(wxSizeEvent &WXUNUSED(event))
00134 {
00135 int scrX,scrY;
00136 GetClientSize(&scrX,&scrY);
00137 plotter->SetSize(scrX,scrY);
00138
00139
00140
00141
00142
00143 }
00144
00145
00146
00147
00148
00149 int Histogram::getHistogramPoint(int gValue)
00150 {
00151 return histogram->getHistogramPoint(gValue);
00152 }
00153
00154
00155
00156
00157
00158
00159 int Histogram::getHistogramSize()
00160 {
00161 return histogramSize;
00162 }
00163
00164