//---------------------------------------------------------------------------- // Class definition include //---------------------------------------------------------------------------- #include "pHistogram.h" //#include "vtkJPEGReader.h" #include "vtkImageData.h" #include "vtkImageCast.h" //----------------- // C++ //----------------- #include #include #include #include // ---------------------------------------------------------------------------- // WX headers inclusion. // For compilers that support precompilation, includes . // ---------------------------------------------------------------------------- /* #ifndef WX_PRECOMP #include #endif */ //---------------------------------------------------------------------------- // Class implementation //---------------------------------------------------------------------------- //IMPLEMENT_CLASS(pHistogram, wxObject) //---------------------------------------------------------------------------- // Constructors //---------------------------------------------------------------------------- pHistogram::pHistogram(std::string filePath) { path=filePath; points= vtkImageData::New(); size=100; sizeImage=0; buildHistogram(); } pHistogram::pHistogram(vtkImageData* imageData) { points= vtkImageData::New(); size=100; sizeImage=0; //cast /* vtkImageCast* cast= vtkImageCast::New(); cast->SetInput(imageData); cast->SetOutputScalarTypeToInt(); cast->Update(); */ //build the histogram buildHistogram(imageData); } pHistogram::~pHistogram() { if(points!=NULL)points->Delete(); } //---------------------------------------------------------------------------- // Methods //---------------------------------------------------------------------------- void pHistogram::setImagePath(std::string filePath) { path=filePath; } void pHistogram::buildHistogram() { /* reader: is the reader of the image histogramVector:Is the image data of the original image imageData: vtkImageData of the image that we are reading range :it has the (min/max) range of the levels of grey */ points= vtkImageData::New(); vtkMetaImageReader *reader = vtkMetaImageReader::New(); vtkImageData* imageData=NULL; double range[2]; //reading reader->SetFileName(path.c_str()); reader->Update(); // getting the data imageData=reader->GetOutput(); imageData->GetScalarRange(range); initializePoints(size); setPoints(imageData); } /* Calculate the histogram and save it in the attribute points it is used if the user had given the imageData Pre: Size had to be setted if the user wants another value that 100 */ void pHistogram::buildHistogram(vtkImageData* imageData) { initializePoints(size); setPoints(imageData); } /* getting ready the points */ void pHistogram::initializePoints(int xDimension) { //setting image data of the points points->SetDimensions(xDimension,1,1); points->SetScalarTypeToUnsignedShort(); points->AllocateScalars(); points->Update(); } /* constructing the histogram */ void pHistogram::setPoints(vtkImageData* imageData) { /* Pointers */ unsigned short* dataImagePointer=NULL; unsigned short* dataHistogramPointer=NULL; dataImagePointer=(unsigned short*)imageData->GetScalarPointer(0,0,0); dataHistogramPointer=(unsigned short*)points->GetScalarPointer(0,0,0); /* Range of greys */ double range[2]; if(imageData==NULL) range[1]=1; else imageData->GetScalarRange(range); /* Setting the minimun and maximum levels of grey */ maxLevelOfGrey=(int)range[1]; minLevelOfGrey=(int)range[0]; //std::cout<<"maxLevelOfGrey "<GetExtent(ext); int sx,sy,sz; sx=ext[1]+1; sy=ext[3]+1; sz=ext[5]+1; sizeImage=sx*sy*sz; int i; /* getting ready the histogram */ for(i=0;iGetScalarPointer(0,0,0); return dataHistogramPointer[gValue]; }