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];
156 imageData->GetExtent(ext);
166 getting ready the histogram
170 dataHistogramPointer[i]=0;
174 Constructing the Histogram
176 //int k=size/(maxLevelOfGrey-minLevelOfGrey);
178 for(i=0;i<sizeImage;i++)
181 hashing the histogram
183 //double p=((float)*dataImagePointer-minLevelOfGrey);
186 j=getIndex(*dataImagePointer);
187 dataHistogramPointer[j]++;
197 k=dataHistogramPointer[i];
202 Returns the poins of the histograms
204 vtkImageData* pHistogram::getHistogram()
210 hash por getting the index for the histogram vector of the original
212 @gValue: Level of grey for which wants the index in the histogrram
214 int pHistogram::getIndex(int gValue)
216 double p=((float)gValue-minLevelOfGrey)/(maxLevelOfGrey-minLevelOfGrey);
223 void pHistogram::setSize(int nSize)
230 int pHistogram::getImageSize()
235 Get Size of the histogram
237 int pHistogram::getSize()
242 Get the maximum value of grey of the histogram
244 int pHistogram::getMaximumLevelOfGrey()
246 return maxLevelOfGrey;
249 Get the minimum value of grey of the histogram
251 int pHistogram::getMinimumLevelOfGrey()
253 return minLevelOfGrey;
256 get a point of the Histogram
259 int pHistogram::getHistogramPoint(int gValue)
261 //double p=((float)gValue-minLevelOfGrey)/(maxLevelOfGrey-minLevelOfGrey); // JPRx
264 unsigned short* dataHistogramPointer=NULL;
265 dataHistogramPointer=(unsigned short*)points->GetScalarPointer(0,0,0);
267 return dataHistogramPointer[gValue];