Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

vuSpectralImage.cpp

Go to the documentation of this file.
00001 #include <stddef.h>
00002 #include "vuSpectralImage.h"
00003 #include "vuColourXYZa.h"
00004 
00006 
00007 
00008 vuSpectralImage::vuSpectralImage()
00009 {
00010   spix = NULL;
00011   mask = NULL;
00012   maxx = maxy = 0;
00013   init(0,0);
00014 }
00015 
00016 vuSpectralImage::~vuSpectralImage()
00017 {
00018     if(spix) delete [] spix;
00019     spix = NULL;
00020     if(mask) delete [] mask;
00021     mask = NULL;
00022 }
00023 
00024 bool vuSpectralImage::init(int sizx, int sizy)
00025 {
00026     if(maxx != sizx || maxy != sizy) {
00027         maxx=sizx;
00028         maxy=sizy;
00029         if(spix) delete [] spix;
00030         if(mask) delete [] mask;
00031         if(sizx && sizy)
00032         {
00033             spix = new vuColour7a[maxx*maxy];
00034             if(!spix) return false;
00035             mask = new bool[maxx*maxy];
00036             if(!mask) return false;
00037         }
00038     }
00039     if(sizx && sizy)
00040     {
00041         int i;
00042         for(i=0; i<maxx*maxy; i++)
00043             spix[i] = 0.0f;
00044         set_mask(false);
00045     } else { spix = NULL; mask = NULL; }
00046     return true;
00047 }
00048 
00049 void vuSpectralImage::set_mask(bool value)
00050 {
00051     int i;
00052     for(i=0; i<maxx*maxy; i++)
00053         mask[i] = 0;
00054 }
00055 
00056 void vuSpectralImage::create_black_mask()
00057 {
00058     int i;
00059     for(i=0; i<maxx*maxy; i++)
00060         mask[i] = spix[i].maxComponent()>0.00001f;
00061 }
00062 
00063 bool vuSpectralImage::get_rgb(byte *buf, int size) const
00064 {
00065   int sizeXY = maxx*maxy;
00066   if(spix == NULL || buf == NULL || size<3*sizeXY) return false;
00067   vuColourRGBa rgba;
00068   const vuColour7a *spec = spix;
00069   int i;
00070   for(i=0;i<sizeXY;i++, spec++)
00071   {
00072       if(mask[i]) {
00073           rgba.from(*spec*light);
00074           rgba.clampTo01();
00075           *(buf++)=(unsigned char)(255.f*rgba[0]);
00076           *(buf++)=(unsigned char)(255.f*rgba[1]);
00077           *(buf++)=(unsigned char)(255.f*rgba[2]);
00078       } else {
00079           *(buf++)= 0; *(buf++)= 0; *(buf++)= 0;
00080       }
00081   }
00082   return true;
00083 }
00084 
00085 bool vuSpectralImage::getRGBImage(vuImage& img) const
00086 {
00087     if(img.getWidth() != maxx ||
00088        img.getHeight() != maxy)
00089         img.init(maxx,maxy);
00090     if(!get_rgb(img.get_buffer(), img.getWidth()*img.getHeight()*3))
00091         return false;
00092     else
00093         return true;
00094 }
00095 
00096 void vuSpectralImage::set_light(vuColour7a light)
00097 {
00098         this->light = light;
00099 }
00100 
00101 
00102 void vuSpectralImage::get_extents(int &sizx, int &sizy)
00103 {
00104         sizx=maxx;
00105         sizy=maxy;
00106 }
00107 
00108 const vuColour7a& vuSpectralImage::get_light() const
00109 {
00110         return light;
00111 }

Generated on Wed Dec 15 21:20:36 2004 for vuVolume by  doxygen 1.3.9.1