# SoInterpolate.h

    00001 /**************************************************************************\
    00002  *
    00003  *  This file is part of the Coin 3D visualization library.
    00004  *  Copyright (C) 1998-2003 by Systems in Motion.  All rights reserved.
    00005  *
    00006  *  This library is free software; you can redistribute it and/or
    00007  *  modify it under the terms of the GNU General Public License
    00008  *  ("GPL") version 2 as published by the Free Software Foundation.
    00009  *  See the file LICENSE.GPL at the root directory of this source
    00010  *  distribution for additional information about the GNU GPL.
    00011  *
    00012  *  For using Coin with software that can not be combined with the GNU
    00013  *  GPL, and for taking advantage of the additional benefits of our
    00014  *  support services, please contact Systems in Motion about acquiring
    00015  *  a Coin Professional Edition License.
    00016  *
    00017  *  See <URL:http://www.coin3d.org> for  more information.
    00018  *
    00019  *  Systems in Motion, Teknobyen, Abels Gate 5, 7030 Trondheim, NORWAY.
    00020  *  <URL:http://www.sim.no>.
    00021  *
    00022 \**************************************************************************/
    00023
    00024 #ifndef COIN_SOINTERPOLATE_H
    00025 #define COIN_SOINTERPOLATE_H
    00026
    00027
    00028 #include <Inventor/engines/SoSubEngine.h>
    00029 #include <Inventor/engines/SoEngineOutput.h>
    00030 #include <Inventor/fields/SoSFFloat.h>
    00031
    00032 class COIN_DLL_API SoInterpolate : public SoEngine {
    00033   typedef SoEngine inherited;
    00034   SO_ENGINE_ABSTRACT_HEADER(SoInterpolate);
    00035
    00036 public:
    00037   static void initClass(void);
    00038   static void initClasses(void);
    00039
    00040   SoSFFloat alpha;
    00041   SoEngineOutput output; // type varies for subclasses
    00042
    00043 protected:
    00044   SoInterpolate();
    00045   virtual ~SoInterpolate();
    00046 };
    00047
    00048
    00049
    00051
    00052
    00053 #define SO_INTERPOLATE_HEADER(_class_) \
    00054   SO_ENGINE_HEADER(_class_); \
    00055   public: \
    00056     _class_(); \
    00057     static void initClass(); \
    00058   protected: \
    00059     virtual ~_class_(); \
    00060   private: \
    00061     virtual void evaluate()
    00062
    00063
    00064 #define PRIVATE_SO_INTERPOLATE_CONSTRUCTOR(_class_, _type_, _valtype_, _default0_, _default1_) \
    00065   SO_ENGINE_CONSTRUCTOR(_class_); \
    00066   SO_ENGINE_ADD_INPUT(alpha, (0.0f)); \
    00067   SO_ENGINE_ADD_INPUT(input0, _default0_); \
    00068   SO_ENGINE_ADD_INPUT(input1, _default1_); \
    00069   SO_ENGINE_ADD_OUTPUT(output, _type_)
    00070
    00071 #define PRIVATE_SO_INTERPOLATE_DESTRUCTOR(_class_) \
    00072 _class_::~_class_() \
    00073 { \
    00074 }
    00075
    00076 #define PRIVATE_SO_INTERPOLATE_EVALUATE(_class_, _type_, _valtype_, _interpexp_) \
    00077 void \
    00078 _class_::evaluate(void) \
    00079 { \
    00080   int n0 = this->input0.getNum(); \
    00081   int n1 = this->input1.getNum(); \
    00082   float a = this->alpha.getValue(); \
    00083   for (int i = SbMax(n0, n1) - 1; i >= 0; i--) { \
    00084     _valtype_ v0 = this->input0[SbMin(i, n0-1)]; \
    00085     _valtype_ v1 = this->input1[SbMin(i, n1-1)]; \
    00086     SO_ENGINE_OUTPUT(output, _type_, set1Value(i, _interpexp_)); \
    00087   } \
    00088 }
    00089
    00090
    00091 // Considering the number of lines of code needed to implement
    00092 // the evaluate() method in each class, I'm amazed it is defined in
    00093 // a macro and not simply implemented for each class. But, I guess
    00094 // we'll have to supply this macro to keep the OIV compatibility,
    00095 // so here it is. Check the interpolator classes for examples on
    00096 // how to use it.
    00097 //                                               pederb, 20000309
    00098 //
    00099 // There's another version of this macro for internal use in the
    00100 // SoSubEngineP.h file, so match any changes you do here with that
    00101 // macro also -- if applicable.
    00102 //
    00103 //                                               mortene, 20000505
    00104
    00105 #define SO_INTERPOLATE_SOURCE(_class_, _type_, _valtype_, _default0_, _default1_, _interpexp_) \
    00106  \
    00107 SO_ENGINE_SOURCE(_class_); \
    00108  \
    00109 _class_::_class_(void) \
    00110 { \
    00111   PRIVATE_SO_INTERPOLATE_CONSTRUCTOR(_class_, _type_, _valtype_, _default0_, _default1_); \
    00112   this->isBuiltIn = FALSE; \
    00113 } \
    00114  \
    00115 PRIVATE_SO_INTERPOLATE_DESTRUCTOR(_class_) \
    00116 PRIVATE_SO_INTERPOLATE_EVALUATE(_class_, _type_, _valtype_, _interpexp_)
    00117
    00118
    00119 #define SO_INTERPOLATE_INITCLASS(_class_, _classname_) \
    00120  \
    00121 void \
    00122 _class_::initClass(void) \
    00123 { \
    00124   SO_ENGINE_INIT_CLASS(_class_, SoInterpolate, "SoInterpolate"); \
    00125 }
    00126
    00127
    00129
    00130
    00131 #ifndef COIN_INTERNAL
    00132 // Include these header files for better Open Inventor compatibility.
    00133 #include <Inventor/engines/SoInterpolateFloat.h>
    00134 #include <Inventor/engines/SoInterpolateVec2f.h>
    00135 #include <Inventor/engines/SoInterpolateVec3f.h>
    00136 #include <Inventor/engines/SoInterpolateVec4f.h>
    00137 #include <Inventor/engines/SoInterpolateRotation.h>
    00138 #endif // !COIN_INTERNAL
    00139
    00140
    00141 #endif // !COIN_SOINTERPOLATE_H