Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

glt/colmap.cpp

Go to the documentation of this file.
00001 #include "colmap.h"
00002 
00015 #include <glt/rgb.h>
00016 
00017 #include <cassert>
00018 using namespace std;
00019 
00020 GltColorMap::GltColorMap()
00021 {
00022 }
00023 
00024 GltColorMap::~GltColorMap()
00025 {
00026 }
00027 
00028 void 
00029 GltColorMap::addEntry(const real t,const GltColor &color)
00030 {
00031     if (_map.size()==0)
00032     {
00033         _map.push_back(make_pair(t,color));
00034         return;
00035     }
00036 
00037     if (t<start())
00038     {
00039         _map.insert(_map.begin(),make_pair(t,color));
00040         return;
00041     }
00042 
00043     if (t>=end())
00044     {
00045         _map.push_back(make_pair(t,color));
00046         return;
00047     }
00048 
00049     iterator i,j;
00050     i = _map.begin();
00051     j = i; j++;
00052 
00053     while (i!=_map.end() && j!=_map.end())
00054         if (i->first<=t && j->first>t)
00055         {
00056             _map.insert(i,make_pair(t,color));
00057             break;
00058         }
00059         else
00060         {
00061             i++;
00062             j++;
00063         }
00064 
00065     assert(0);
00066 }
00067 
00068 void 
00069 GltColorMap::addEntry(const real t,const GltColor &color,const real alpha)
00070 {
00071     GltColor col(color);
00072     col.alpha() = alpha;
00073     addEntry(t,col);
00074 }
00075 
00076 void 
00077 GltColorMap::clear()
00078 {
00079     _map.clear();
00080 }
00081 
00082 GltColor 
00083 GltColorMap::lookup(const real t) const
00084 {
00085     if (_map.size()==0)
00086         return black;
00087     
00088     if (t<=start())
00089         return _map.front().second;
00090 
00091     if (t>=end())
00092         return _map.back().second;
00093 
00094     const_iterator i,j;
00095     i = _map.begin();
00096     j = i; j++;
00097 
00098     while (i!=_map.end() && j!=_map.end())
00099         if (i->first<=t && j->first>=t)
00100             return LERP(i->second,j->second,(t-i->first)/(j->first-i->first));
00101         else
00102         {
00103             i++;
00104             j++;
00105         }
00106 
00107     assert(0);
00108     return black;
00109 }
00110 
00111 real
00112 GltColorMap::lookup(const int i) const
00113 {
00114     assert(i>=0);
00115     assert(i<size());
00116     
00117     const_iterator j = _map.begin();
00118     for (int k=0; k<i; k++)
00119         j++;
00120 
00121     return j->first;
00122 }
00123 
00124 const int    GltColorMap::size()     const { return _map.size();           }
00125 const real   GltColorMap::start()    const { return _map.front().first;    }
00126 const real   GltColorMap::end()      const { return _map.back().first;     }
00127 const real   GltColorMap::duration() const { return end() - start();       }
00128 
00129 GltColorMap &GltColorMap::operator+=(const real x)
00130 {
00131     iterator i = _map.begin();
00132     for (; i!=_map.end(); i++)
00133         i->first += x;
00134     return *this;
00135 }
00136 
00137 GltColorMap &GltColorMap::operator-=(const real x)
00138 {
00139     iterator i = _map.begin();
00140     for (; i!=_map.end(); i++)
00141         i->first -= x;
00142     return *this;
00143 }
00144 
00145 GltColorMap &GltColorMap::operator*=(const real x)
00146 {
00147     iterator i = _map.begin();
00148     for (; i!=_map.end(); i++)
00149         i->first *= x;
00150     return *this;
00151 }
00152 
00153 GltColorMap &GltColorMap::operator/=(const real x)
00154 {
00155     iterator i = _map.begin();
00156     for (; i!=_map.end(); i++)
00157         i->first /= x;
00158     return *this;
00159 }
00160 

Generated on Tue Nov 5 11:11:03 2002 for GLT by doxygen1.2.18