TuttleOFX  1
Lut.hpp
Go to the documentation of this file.
00001 #ifndef _LUTENGINE_LUT_HPP_
00002 #define _LUTENGINE_LUT_HPP_
00003 
00004 #include "AbstractLut.hpp"
00005 #include "Color.hpp"
00006 #include "Interpolator.hpp"
00007 
00008 namespace tuttle
00009 {
00010 
00011 class Lut3D : public AbstractLut
00012 {
00013 public:
00014         Lut3D()
00015                 : AbstractLut()
00016         {}
00017 
00018         Lut3D( Interpolator* interpolator, size_t _dimSize, double* data = NULL );
00019         Lut3D( const Lut3D& lut3d );
00020 
00021         const size_t totalSize() const;
00022         inline Color getIndexedColor( int _x, int _y, int _z ) const;
00023         inline Color getColor( Color const& color ) const              { return _interpolator->interpolate( this, color ); }
00024         inline Color getColor( double _r, double _g, double _b ) const { return _interpolator->interpolate( this, _r, _g, _b ); }
00025         inline void  setIndexedColor( int _x, int _y, int _z, Color _color );
00026         inline void  setIndexedValues( int _x, int _y, int _z, double _r, double _g, double _b );
00027 
00028 private:
00029         inline int getIndex( const int _x, const int _y, const int _z ) const
00030         {
00031                 return( ( ( _x * _dimSize * _dimSize ) + ( _y * _dimSize ) + _z ) * 3 );
00032         }
00033 
00034 };
00035 
00036 inline const size_t Lut3D::totalSize() const
00037 {
00038         return _dimSize * _dimSize * _dimSize;
00039 }
00040 
00041 inline Color Lut3D::getIndexedColor( int _x, int _y, int _z ) const
00042 {
00043         int ref = getIndex( _x, _y, _z );
00044 
00045         return Color( _data[ ref ], _data[ ref + 1 ], _data[ ref + 2 ] );
00046 }
00047 
00048 inline void Lut3D::setIndexedColor( int _x, int _y, int _z, Color _color )
00049 {
00050         setIndexedValues( _x, _y, _z, _color.x, _color.y, _color.z );
00051 }
00052 
00053 inline void Lut3D::setIndexedValues( int _x, int _y, int _z, double _r, double _g, double _b )
00054 {
00055         int ref = getIndex( _x, _y, _z );
00056 
00057         _data[ref    ] = _r;
00058         _data[ref + 1] = _g;
00059         _data[ref + 2] = _b;
00060 }
00061 
00062 }
00063 
00064 #endif // HD3DLUT_H