OMKColorPolator.cpp

Go to the documentation of this file.
00001 /************************************************************************/
00002 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */
00003 /* 1993-2002, thereinafter the Software                                 */
00004 /*                                                                      */
00005 /* The Software has been developped within the Siames Project.          */
00006 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */
00007 /* property rights                                                      */
00008 /*                                                                      */
00009 /* The Software has been registered with the Agence pour la Protection  */
00010 /* des Programmes (APP) under registration number                       */
00011 /* IDDN.FR.001.510008.00.S.P.2001.000.41200                             */
00012 /*                                                                      */
00013 /* This file may be distributed under the terms of the Q Public License */
00014 /* version 1.0 as defined by Trolltech AS of Norway and appearing in    */
00015 /* the file LICENSE.QPL included in the packaging of this file.         */
00016 /*                                                                      */
00017 /* Licensees holding valid specific licenses issued by INRIA, CNRS or   */
00018 /* Universite Rennes 1 for the software may use this file in            */
00019 /* acordance with that specific license                                 */
00020 /************************************************************************/
00021                 
00022 #include "OMKColorPolator.h"
00023 #include "OMKNumericPolator.h"
00024 
00025 using namespace OMK ;
00026 using namespace OMK::Type ;
00027 
00029 // ColorPolator
00031 
00032 const SimpleTypeT< Color >& 
00033 ColorPolator::interpolate( SimpleTypeT< Color >& result,
00034                                                    const int interpolationLevel,
00035                                                    const Date& dateNeeded,
00036                                                    const Date& dateAfter,
00037                                                    const SimpleTypeT< Color >& valueAfter,
00038                                                    const Date& dateBefore,
00039                                                    int offsetToMostRecentOfDateBefore ) const
00040 {
00041   switch ( interpolationLevel ) 
00042   {
00043   case Constant :
00044   case ConstantContinuous : 
00045     result = get( 0 ) ;
00046     break ;
00047   case Linear :  
00048   case LinearContinuous : 
00049     {
00050       for( int i = 0 ; i < 4 ; i++ )
00051             {
00052               ((Color&)result)[i] = NumericPolatorT< float >::linearInterpolate( dateNeeded, 
00053                                                             dateAfter, 
00054                                                             ( (Color&)valueAfter )[i], 
00055                                                             dateBefore, 
00056                                                             ( (Color&)get( offsetToMostRecentOfDateBefore ) )[i] ) ;
00057             }
00058     }
00059     break ;
00060   case Quadratic :
00061   case QuadraticContinuous : 
00062     {
00063       for( int i = 0; i < 4; i++ )
00064             {
00065               ((Color&)result)[i] = NumericPolatorT< float >::quadraticInterpolate( dateNeeded, 
00066                                                                dateAfter, 
00067                                                                ( (Color&)valueAfter )[i], 
00068                                                                dateBefore, 
00069                                                                ( (Color&)get( offsetToMostRecentOfDateBefore ) )[i] ,
00070                                                                getDate( offsetToMostRecentOfDateBefore + 1 ), 
00071                                                                ( (Color&)get( offsetToMostRecentOfDateBefore + 1 ) )[i] ) ;
00072             }
00073     }
00074     break ;
00075   case Cubic :
00076   case CubicContinuous : 
00077     {
00078       for( int i = 0 ; i < 4 ; i++ )
00079             {   
00080               ((Color&)result)[i]  = NumericPolatorT< float >::cubicInterpolate(dateNeeded, 
00081                                                            dateAfter, 
00082                                                            ( (Color&)valueAfter )[i], 
00083                                                            dateBefore, 
00084                                                            ( (Color&)get( offsetToMostRecentOfDateBefore ) )[i],
00085                                                            getDate( offsetToMostRecentOfDateBefore + 1 ), 
00086                                                            ( (Color&)get( offsetToMostRecentOfDateBefore + 1 ) )[i], 
00087                                                            getDate( offsetToMostRecentOfDateBefore + 2 ), 
00088                                                            ( (Color&)get( offsetToMostRecentOfDateBefore + 2 ) )[i] ) ;
00089             }
00090     }
00091     break;
00092   default :
00093     OMTRACEID( OMK_DEBUG_OMK_TYPE, "ColorPolator<N>::interpolate: unknown polation level" ) ;
00094   }
00095   return result ;
00096 }
00097 
00098 //-----------------------------------------------------------------------------
00099 const SimpleTypeT< Color >& 
00100 ColorPolator::extrapolate( SimpleTypeT< Color >& result,
00101                                                    const int requestedPolationLevel,
00102                                                    const Date& t,
00103                                                    const Date& tIndice ) const
00104 {
00105   switch ( requestedPolationLevel ) 
00106   {
00107   case Constant : 
00108     result = get ( 0 ) ;
00109     break ;
00110     // Added by Guillermo Andrade
00111   case ConstantContinuous : 
00112     result = get ( 0 ) ;
00113 
00114     if( 1 < getNumberOfPresentValues() )
00115           {
00116             for( int i = 0 ; i < 4 ; i++ ) 
00117               {
00118                 ((Color&)result)[i]= ::NumericPolatorT< float >::linearInterpolate( t, 
00119                                                                tIndice, ( (Color&)get( 1 ) )[i], 
00120                                                                2*tIndice - getDate( 1 ), ( (Color&)get( 0 ) )[i] ) ;
00121               }
00122           }
00123     break ;
00124     //
00125   case Linear :
00126     {
00127       for( int i = 0 ; i < 4 ; i++ ) 
00128             {
00129               ((Color&)result)[i] = NumericPolatorT< float >::linearExtrapolate( t, 
00130                                                             tIndice, ( (Color&)get( 0 ) )[i], 
00131                                                             getDate( 1 ), ( (Color&)get( 1 ) )[i] ) ;
00132             }
00133     }
00134     break ; 
00135     // Added by Guillermo Andrade
00136   case LinearContinuous : 
00137     {
00138       for( int i = 0 ; i < 4 ; i++ ) 
00139             {
00140               ((Color&)result)[i] = NumericPolatorT< float >::linearExtrapolate( t, 
00141                                                             tIndice, ( (Color&)get( 0 ) )[i], 
00142                                                             getDate( 1 ), ( (Color&)get( 1 ) )[i] ) ;
00143             }
00144       if( 2 < getNumberOfPresentValues() )
00145             {
00146               for( int i = 0 ; i < 4 ; i++ ) 
00147                 {
00148                   float oldResult = NumericPolatorT< float >::linearExtrapolate( t, 
00149                                                                       getDate( 1 ), ( (Color&)get( 1 ) )[i], 
00150                       getDate( 2 ), ( (Color&)get( 2 ) )[i]) ;
00151                   ((Color&)result)[i] = ::NumericPolatorT< float >::linearInterpolate( t, 
00152                                                                   tIndice, oldResult, 
00153                                                                   2*tIndice - getDate( 1 ), ((Color&)result)[i] ) ;
00154                 }
00155             }
00156     }
00157     break ;
00158     //
00159   case Quadratic :
00160     {
00161       for( int i = 0 ; i < 4 ; i++ ) 
00162             {
00163               ((Color&)result)[i] = NumericPolatorT< float >::quadraticExtrapolate( t, 
00164                                                                tIndice, ( (Color&)get( 0 ) )[i], 
00165                                                                getDate( 1 ), ( (Color&)get( 1 ) )[i],
00166                                                                getDate( 2 ), ( (Color&)get( 2 ) )[i] ) ;
00167       }
00168           }
00169     break ; 
00170     // Added by Guillermo Andrade
00171   case QuadraticContinuous :
00172     {
00173       for( int i = 0 ; i < 4 ; i++ ) 
00174             {
00175               ((Color&)result)[i] = NumericPolatorT< float >::quadraticExtrapolate( t, 
00176                                                                tIndice, ( (Color&)get( 0 ) )[i], 
00177                                                                getDate( 1 ), ( (Color&)get( 1 ) )[i],
00178                                                                getDate( 2 ), ( (Color&)get( 2 ) )[i] ) ;
00179             }
00180       if( 3 < getNumberOfPresentValues() )
00181             {
00182               for( int i = 0 ; i < 4 ; i++ ) 
00183         {
00184           float oldResult = NumericPolatorT< float >::quadraticExtrapolate( t, 
00185                                                getDate( 1 ), ( (Color&)get( 1 ) )[i],
00186                                                            getDate( 2 ), ( (Color&)get( 2 ) )[i],
00187                                                            getDate( 3 ), ( (Color&)get( 3 ) )[i] ) ;
00188           ((Color&)result)[i] = ::NumericPolatorT< float >::linearInterpolate( t, 
00189                                                           tIndice, oldResult, 
00190                                                           2*tIndice - getDate( 1 ), ((Color&)result)[i] ) ;
00191         }
00192             }
00193     }
00194     break ; 
00195     //
00196   case Cubic :
00197     {
00198       for( int i = 0 ; i < 4 ; i++ )
00199             {
00200               ((Color&)result)[i] = NumericPolatorT< float >::cubicExtrapolate( t, 
00201                                                            tIndice, ( (Color&)get( 0 ) )[i], 
00202                                                            getDate( 1 ), ( (Color&)get( 1 ) )[i],
00203                                                            getDate( 2 ), ( (Color&)get( 2 ) )[i],
00204                                                            getDate( 3 ), ( (Color&)get( 3 ) )[i] ) ;
00205             }
00206     }
00207     break ; 
00208     // Added by Guillermo Andrade
00209   case CubicContinuous :
00210     {
00211       for( int i = 0 ; i < 4 ; i++ )
00212             {
00213               ((Color&)result)[i] = NumericPolatorT< float >::cubicExtrapolate( t, 
00214                                                            tIndice, ( (Color&)get( 0 ) )[i], 
00215                                                            getDate( 1 ), ( (Color&)get( 1 ) )[i],
00216                                                            getDate( 2 ), ( (Color&)get( 2 ) )[i],
00217                                                            getDate( 3 ), ( (Color&)get( 3 ) )[i] ) ;
00218             }
00219       if( 4 < getNumberOfPresentValues() )
00220             {
00221               for( int i = 0 ; i < 4 ; i++ )
00222         {
00223           float oldResult = NumericPolatorT< float >::cubicExtrapolate( t,  
00224                                                              getDate( 1 ), ( (Color&)get( 1 ) )[i], 
00225                                                              getDate( 2 ), ( (Color&)get( 2 ) )[i],
00226                                                              getDate( 3 ), ( (Color&)get( 3 ) )[i],
00227                                                              getDate( 4 ), ( (Color&)get( 4 ) )[i] ) ;
00228 
00229           ((Color&)result)[i] = ::NumericPolatorT< float >::linearExtrapolate( t, 
00230                                                           tIndice, oldResult, 
00231                                                           2*tIndice - getDate( 1 ), ((Color&)result)[i]) ;
00232         }
00233       }
00234     }
00235     break ; 
00236     //
00237   default :
00238     OMTRACEID( OMK_DEBUG_OMK_TYPE, "ColorPolator<N>::extrapolate: unknown polation level" ) ;
00239   }
00240   return result ;
00241 }
00242 
00243 //-----------------------------------------------------------------------------
00244 const SimpleTypeT< Color >& 
00245 ColorPolator::antepolate( SimpleTypeT< Color >& result,
00246                           const int requestedPolationLevel,
00247                           const Date& t,
00248                           const Date& tIndice,
00249                           unsigned int indice ) const 
00250 {
00251   switch ( requestedPolationLevel ) 
00252   {
00253   case Constant : 
00254   case ConstantContinuous : // Added by Guillermo Andrade
00255     result = get( indice ) ;
00256     break ;
00257   case Linear : 
00258     {
00259       for( int i = 0 ; i < 4 ; i++ ) 
00260             {
00261               ((Color&)result)[i] = NumericPolatorT< float >::linearExtrapolate( t, 
00262                                                             tIndice, ( (Color&)get( indice ) )[i], 
00263                                                             getDate( indice - 1 ), ( (Color&)get( indice - 1 ) )[i] ) ;
00264             }
00265     }
00266     break ; 
00267   case Quadratic :
00268   case QuadraticContinuous : // Added by Guillermo Andrade
00269     {
00270       for( int i = 0 ; i < 4 ; i++ ) 
00271             {
00272               ((Color&)result)[i] = NumericPolatorT< float >::quadraticExtrapolate( t, 
00273                                                                tIndice, ( (Color&)get( indice ) )[i], 
00274                                                    getDate( indice - 1 ), ( (Color&)get( indice - 1 ) )[i],
00275                                                    getDate( indice - 2 ), ( (Color&)get( indice - 2 ) )[i] ) ;
00276             }
00277     }
00278     break ; 
00279   case Cubic :
00280   case CubicContinuous : // Added by Guillermo Andrade
00281     {
00282       for( int i = 0 ; i < 4 ; i++ )
00283             {
00284               ((Color&)result)[i] = NumericPolatorT< float >::cubicExtrapolate( t, 
00285                                                                  tIndice, ( (Color&)get( indice ) )[i], 
00286                                                            getDate( indice - 1 ), ( (Color&)get( indice - 1 ) )[i],
00287                                                            getDate( indice - 2 ), ( (Color&)get( indice - 2 ) )[i],
00288                                                            getDate( indice - 3 ), ( (Color&)get( indice - 3 ) )[i] ) ;
00289             }
00290     }
00291     break ; 
00292   default :
00293     OMTRACEID( OMK_DEBUG_OMK_TYPE, "ColorPolator<N>::antepolate: unknown polation level" ) ; 
00294   }
00295   return result ;
00296 }

logo OpenMask

Documentation generated on Mon Jun 9 11:45:56 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007