• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

include/DGVBlitzArrayCaster.h

Go to the documentation of this file.
00001 
00022 #ifndef DGVBLITZARRAYCASTER_H
00023 #define DGVBLITZARRAYCASTER_H
00024 
00025 #include <QImage>
00026 
00027 #include "DGVAliases.h"
00028 
00036 template<typename type>
00037 class DGV_TEMPLATEDLL DGVBlitzArrayCaster
00038 {
00039 public:
00040     DGVBlitzArrayCaster();
00041     virtual ~DGVBlitzArrayCaster();
00042 
00043     QImage* arrayToQImage(const Array<type,2> &data);
00044     void QImageToArray(QImage *image, Array<type,2> &newArray);
00045 
00046     inline type getMin()
00047     {   return min; }
00048     inline type getMax()
00049     {   return max; }
00050     inline type getMean()
00051     {   return mean;    }
00052 
00053 protected:
00054     type min; 
00055         type max; 
00056         type mean; 
00057 };
00058 
00059 template<typename type>
00060 DGVBlitzArrayCaster<type>::DGVBlitzArrayCaster()
00061 {
00062     //ctor
00063 }
00064 
00065 template<typename type>
00066 DGVBlitzArrayCaster<type>::~DGVBlitzArrayCaster()
00067 {
00068     //dtor
00069 }
00070 
00071 template<typename type>
00072 QImage* DGVBlitzArrayCaster<type>::arrayToQImage(const Array<type,2> &data)
00073 {
00074     QImage *image = new QImage(data.cols(),data.rows(),QImage::Format_Indexed8);
00075     type tmp;
00076 
00078     if(data.cols() > 0 && data.rows() > 0)
00079         min = max = data(0,0);
00080 
00081     for(int j = 0; j < data.rows(); j ++)
00082         for(int k = 0; k < data.cols(); k ++)
00083         {
00084             if(max < data(j,k))
00085                 max = data(j,k);
00086             if(min > data(j,k))
00087                 min = data(j,k);
00088         }
00089     qDebug() << "\nMax Pixel: " << max << ", Min Pixel: " << min;
00090     max -= min;
00091 
00093     image->setNumColors(256);
00094     for(int j = 0; j < 256; j ++)
00095         image->setColor(j,qRgb(j, j, j));
00096 
00098     if(max > 255 || min < 0)
00099     {
00100         if(min < 0)
00101             max -= min;
00102 
00104         for(int j = 0; j < data.rows(); j ++)
00105             for(int k = 0; k < data.cols(); k ++)
00106             {
00107                 tmp = static_cast<type>( (data(j,k)-min)/static_cast<double>(max)*255.0 );
00108                 //cerr << " tmp: " << tmp << ", ";
00109                 image->setPixel(k,j,static_cast<uint>(tmp));
00110             }
00111     }
00112     else
00113     {
00115         for(int j = 0; j < data.rows(); j ++)
00116             for(int k = 0; k < data.cols(); k ++)
00117                 image->setPixel(k,j,static_cast<uint>(data(j,k)));
00118     }
00119 
00120     return image;
00121 }
00122 
00123 template<typename type>
00124 void DGVBlitzArrayCaster<type>::QImageToArray(QImage *image, Array<type,2> &newArray)
00125 {
00126     newArray.resize(image->height(),image->width());
00127 
00128     for(int j = 0; j < image->height(); j ++)
00129         for(int k = 0; k < image->width(); k ++)
00130             newArray(j,k) = qGray(image->pixel(k,j));
00131 }
00132 
00133 #endif // DGVBLITZARRAYCASTER_H

Generated on Wed Sep 8 2010 01:36:51 for DGV by  doxygen 1.7.1