2 //----------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------
6 #include "pHistogram.h"
7 //#include "vtkJPEGReader.h"
8 #include "vtkImageData.h"
9 #include "vtkImageCast.h"
18 // ----------------------------------------------------------------------------
19 // WX headers inclusion.
20 // For compilers that support precompilation, includes <wx/wx.h>.
21 // ----------------------------------------------------------------------------
28 //----------------------------------------------------------------------------
29 // Class implementation
30 //----------------------------------------------------------------------------
32 //IMPLEMENT_CLASS(pHistogram, wxObject)
34 //----------------------------------------------------------------------------
36 //----------------------------------------------------------------------------
37 pHistogram::pHistogram(std::string filePath)
40 points= vtkImageData::New();
46 pHistogram::pHistogram(vtkImageData* imageData)
48 points= vtkImageData::New();
53 vtkImageCast* cast= vtkImageCast::New();
54 cast->SetInput(imageData);
55 cast->SetOutputScalarTypeToInt();
59 buildHistogram(imageData);
62 pHistogram::~pHistogram()
64 if(points!=NULL)points->Delete();
66 //----------------------------------------------------------------------------
68 //----------------------------------------------------------------------------
70 void pHistogram::setImagePath(std::string filePath)
75 void pHistogram::buildHistogram()
78 reader: is the reader of the image
79 histogramVector:Is the image data of the original image
80 imageData: vtkImageData of the image that we are reading
81 range :it has the (min/max) range of the levels of grey
83 points= vtkImageData::New();
84 vtkMetaImageReader *reader = vtkMetaImageReader::New();
85 vtkImageData* imageData=NULL;
89 reader->SetFileName(path.c_str());
94 imageData=reader->GetOutput();
95 imageData->GetScalarRange(range);
96 initializePoints(size);
102 Calculate the histogram and save it in the attribute points
103 it is used if the user had given the imageData
104 Pre: Size had to be setted if the user wants
105 another value that 100
107 void pHistogram::buildHistogram(vtkImageData* imageData)
109 initializePoints(size);
110 setPoints(imageData);
114 getting ready the points
116 void pHistogram::initializePoints(int xDimension)
118 //setting image data of the points
119 points->SetDimensions(xDimension,1,1);
120 points->SetScalarTypeToUnsignedShort();
121 points->AllocateScalars();
126 constructing the histogram
128 void pHistogram::setPoints(vtkImageData* imageData)
133 unsigned short* dataImagePointer=NULL;
134 unsigned short* dataHistogramPointer=NULL;
136 dataImagePointer=(unsigned short*)imageData->GetScalarPointer(0,0,0);
137 dataHistogramPointer=(unsigned short*)points->GetScalarPointer(0,0,0);
146 imageData->GetScalarRange(range);
148 Setting the minimun and maximum levels of grey
150 maxLevelOfGrey=(int)range[1];
151 minLevelOfGrey=(int)range[0];
152 //std::cout<<"maxLevelOfGrey "<<maxLevelOfGrey<<" minLevelOfGrey "<<minLevelOfGrey<<std::endl;
157 imageData->GetExtent(ext);
167 getting ready the histogram
171 dataHistogramPointer[i]=0;
175 Constructing the Histogram
177 //int k=size/(maxLevelOfGrey-minLevelOfGrey);
179 for(i=0;i<sizeImage;i++)
182 hashing the histogram
184 //double p=((float)*dataImagePointer-minLevelOfGrey);
187 j=getIndex(*dataImagePointer);
188 //std::cout<<j<<std::endl;
189 dataHistogramPointer[j]++;
199 k=dataHistogramPointer[i];
204 Returns the poins of the histograms
206 vtkImageData* pHistogram::getHistogram()
212 hash por getting the index for the histogram vector of the original
214 @gValue: Level of grey for which wants the index in the histogrram
216 int pHistogram::getIndex(int gValue)
219 double p=((double)gValue-minLevelOfGrey)/(maxLevelOfGrey-minLevelOfGrey);
221 //std::cout<<"gValue "<<gValue<<" k "<<k<<std::endl;
227 void pHistogram::setSize(int nSize)
234 int pHistogram::getImageSize()
239 Get Size of the histogram
241 int pHistogram::getSize()
246 Get the maximum value of grey of the histogram
248 int pHistogram::getMaximumLevelOfGrey()
250 return maxLevelOfGrey;
253 Get the minimum value of grey of the histogram
255 int pHistogram::getMinimumLevelOfGrey()
257 return minLevelOfGrey;
260 get a point of the Histogram
263 int pHistogram::getHistogramPoint(int gValue)
265 //double p=((float)gValue-minLevelOfGrey)/(maxLevelOfGrey-minLevelOfGrey); // JPRx
268 unsigned short* dataHistogramPointer=NULL;
269 dataHistogramPointer=(unsigned short*)points->GetScalarPointer(0,0,0);
271 return dataHistogramPointer[gValue];