Open Inventor Reference
MeVis/ThirdParty/Sources/Inventor/inventor/lib/database/include/Inventor/engines/SoInterpolate.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  * 
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027  *  Mountain View, CA  94043, or:
00028  * 
00029  *  http://www.sgi.com 
00030  * 
00031  *  For further information regarding this notice, see: 
00032  * 
00033  *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034  *
00035  */
00036 
00037 
00038 /*
00039  * Copyright (C) 1990,91   Silicon Graphics, Inc.
00040  *
00041  _______________________________________________________________________
00042  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00043  |
00044  |   $Revision: 1.1.1.1 $
00045  |
00046  |   Description:
00047  |      This file defines the abstract SoInterpolate class and
00048  |      macros used to derive classes from it, as well as the
00049  |      derived classes themselves.
00050  |
00051  |   Macros:
00052  |      SO_INTERPOLATE_HEADER
00053  |      SO_INTERPOLATE_SOURCE
00054  |      SO_INTERPOLATE_INITCLASS
00055  |
00056  |   Classes:
00057  |      
00058  |      SoInterpolate   (abstract base class)
00059  |      SoInterpolateFloat
00060  |      SoInterpolateRotation
00061  |      SoInterpolateVec2f
00062  |      SoInterpolateVec3f
00063  |      SoInterpolateVec4f
00064  |
00065  |   Author(s)          : Ronen Barzel
00066  |
00067  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00068  _______________________________________________________________________
00069  */
00070 
00071 #ifndef  _SO_INTERPOLATE_
00072 #define  _SO_INTERPOLATE_
00073 
00074 #include <Inventor/system/SbSystem.h>
00075 #include <Inventor/SoDB.h>
00076 #include <Inventor/engines/SoSubEngine.h>
00077 #include <Inventor/fields/SoSFFloat.h>
00078 #include <Inventor/fields/SoMFFloat.h>
00079 #include <Inventor/fields/SoMFRotation.h>
00080 #include <Inventor/fields/SoMFVec2f.h>
00081 #include <Inventor/fields/SoMFVec3f.h>
00082 #include <Inventor/fields/SoMFVec4f.h>
00083 
00084 
00087 
00101 
00102 
00103 class INVENTOR_API SoInterpolate : public SoEngine {
00104 
00105     SO_ENGINE_ABSTRACT_HEADER(SoInterpolate);
00106 
00107   public:
00109 
00110 
00112     SoSFFloat           alpha;
00113 
00115 
00117 
00118 
00122     SoEngineOutput      output;
00123 
00125 
00126   SoINTERNAL public:
00127     static void         initClass();
00128     static void         initClasses();  
00129 
00130   protected:
00131     SoInterpolate();
00132     static int max(int a, int b) { return (a > b) ? a : b; }
00133     static int clamp(int i, int n) { return (i < n) ? i : n-1; }
00134 
00135     ~SoInterpolate();
00136 };
00137 
00144 
00149 
00150 #define SO_INTERPOLATE_HEADER(className)                                \
00151                                                                         \
00152     SO_ENGINE_HEADER(className);                                        \
00153                                                                         \
00154   private:                                                              \
00155     ~className();                                                       \
00156     virtual void        evaluate();                                     \
00157                                                                         \
00158   SoINTERNAL public:                                                    \
00159     static void         initClass();                                    \
00160                                                                         \
00161   public:                                                               \
00162     className()
00163 
00171 
00172 #define SO_INTERPOLATE_SOURCE(className, type,                          \
00173                         valType, defaultVal0, defaultVal1, interpVal)   \
00174                                                                         \
00175 SO_ENGINE_SOURCE(className);                                            \
00176                                                                         \
00177 className::className()                                                  \
00178 {                                                                       \
00179     SO_ENGINE_CONSTRUCTOR(className);                                   \
00180     SO_ENGINE_ADD_INPUT(alpha, (0.0));                                  \
00181     SO_ENGINE_ADD_INPUT(input0, defaultVal0);                           \
00182     SO_ENGINE_ADD_INPUT(input1, defaultVal1);                           \
00183     SO_ENGINE_ADD_OUTPUT(output, type);                                 \
00184     isBuiltIn = TRUE;                                                   \
00185 }                                                                       \
00186                                                                         \
00187 className::~className()                                                 \
00188 {                                                                       \
00189 }                                                                       \
00190                                                                         \
00191 void                                                                    \
00192 className::evaluate()                                                   \
00193 {                                                                       \
00194     int n0 = input0.getNum();                                           \
00195     int n1 = input1.getNum();                                           \
00196     float a = alpha.getValue();                                         \
00197     for (int i=max(n0,n1)-1; i>=0; i--) {                               \
00198         valType v0 = input0[clamp(i,n0)];                               \
00199         valType v1 = input1[clamp(i,n1)];                               \
00200         SO_ENGINE_OUTPUT(output, type, set1Value(i, interpVal));        \
00201     }                                                                   \
00202 }
00203 
00212 
00213 #define SO_INTERPOLATE_INITCLASS(className, classPrintName)             \
00214                                                                         \
00215 void                                                                    \
00216 className::initClass()                                                  \
00217 {                                                                       \
00218     SO__ENGINE_INIT_CLASS(className, classPrintName, SoInterpolate);    \
00219 }
00220 
00221 
00222 
00223 
00224 
00225 
00228 
00255 
00256 
00257 class INVENTOR_API SoInterpolateFloat : public SoInterpolate {
00258     SO_INTERPOLATE_HEADER(SoInterpolateFloat);
00259 public:
00261 
00262 
00265     SoMFFloat           input0;
00266 
00269     SoMFFloat           input1;
00270 
00272 
00273 };
00274 
00277 
00304 
00305 
00306 class INVENTOR_API SoInterpolateRotation : public SoInterpolate {
00307     SO_INTERPOLATE_HEADER(SoInterpolateRotation);
00308 public:
00310 
00311 
00314     SoMFRotation        input0;
00315 
00318     SoMFRotation        input1;
00319 
00321 
00322 };
00323 
00326 
00353 
00354 
00355 class INVENTOR_API SoInterpolateVec2f : public SoInterpolate {
00356     SO_INTERPOLATE_HEADER(SoInterpolateVec2f);
00357 public:
00359 
00360 
00363     SoMFVec2f           input0;
00364 
00367     SoMFVec2f           input1;
00368 
00370 
00371 };
00372 
00375 
00402 
00403 
00404 class INVENTOR_API SoInterpolateVec3f : public SoInterpolate {
00405     SO_INTERPOLATE_HEADER(SoInterpolateVec3f);
00406 public:
00408 
00409 
00412     SoMFVec3f           input0;
00413 
00416     SoMFVec3f           input1;
00417 
00419 
00420 };
00421 
00424 
00451 
00452 
00453 class INVENTOR_API SoInterpolateVec4f : public SoInterpolate {
00454     SO_INTERPOLATE_HEADER(SoInterpolateVec4f);
00455 public:
00457 
00458 
00461     SoMFVec4f           input0;
00462 
00465     SoMFVec4f           input1;
00466 
00468 
00469 };
00470 
00471 #endif /* _SO_INTERPOLATE_ */