Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SoInterpolate.h
1 /**************************************************************************\
2  * Copyright (c) Kongsberg Oil & Gas Technologies AS
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32 
33 #ifndef COIN_SOINTERPOLATE_H
34 #define COIN_SOINTERPOLATE_H
35 
36 
37 #include <Inventor/engines/SoSubEngine.h>
38 #include <Inventor/engines/SoEngineOutput.h>
39 #include <Inventor/fields/SoSFFloat.h>
40 
41 class COIN_DLL_API SoInterpolate : public SoEngine {
42  typedef SoEngine inherited;
43  SO_ENGINE_ABSTRACT_HEADER(SoInterpolate);
44 
45 public:
46  static void initClass(void);
47  static void initClasses(void);
48 
50  SoEngineOutput output; // type varies for subclasses
51 
52 protected:
53  SoInterpolate();
54  virtual ~SoInterpolate(void);
55 };
56 
57 
58 
60 
61 
62 #define SO_INTERPOLATE_HEADER(_class_) \
63  SO_ENGINE_HEADER(_class_); \
64  public: \
65  _class_(); \
66  static void initClass(); \
67  protected: \
68  virtual ~_class_(); \
69  private: \
70  virtual void evaluate()
71 
72 
73 #define PRIVATE_SO_INTERPOLATE_CONSTRUCTOR(_class_, _type_, _valtype_, _default0_, _default1_) \
74  SO_ENGINE_CONSTRUCTOR(_class_); \
75  SO_ENGINE_ADD_INPUT(alpha, (0.0f)); \
76  SO_ENGINE_ADD_INPUT(input0, _default0_); \
77  SO_ENGINE_ADD_INPUT(input1, _default1_); \
78  SO_ENGINE_ADD_OUTPUT(output, _type_)
79 
80 #define PRIVATE_SO_INTERPOLATE_DESTRUCTOR(_class_) \
81 _class_::~_class_() \
82 { \
83 }
84 
85 #define PRIVATE_SO_INTERPOLATE_EVALUATE(_class_, _type_, _valtype_, _interpexp_) \
86 void \
87 _class_::evaluate(void) \
88 { \
89  int n0 = this->input0.getNum(); \
90  int n1 = this->input1.getNum(); \
91  float a = this->alpha.getValue(); \
92  for (int i = SbMax(n0, n1) - 1; i >= 0; i--) { \
93  _valtype_ v0 = this->input0[SbMin(i, n0-1)]; \
94  _valtype_ v1 = this->input1[SbMin(i, n1-1)]; \
95  SO_ENGINE_OUTPUT(output, _type_, set1Value(i, _interpexp_)); \
96  } \
97 }
98 
99 
100 // Considering the number of lines of code needed to implement
101 // the evaluate() method in each class, I'm amazed it is defined in
102 // a macro and not simply implemented for each class. But, I guess
103 // we'll have to supply this macro to keep the OIV compatibility,
104 // so here it is. Check the interpolator classes for examples on
105 // how to use it.
106 // pederb, 20000309
107 //
108 // There's another version of this macro for internal use in the
109 // SoSubEngineP.h file, so match any changes you do here with that
110 // macro also -- if applicable.
111 //
112 // mortene, 20000505
113 
114 #define SO_INTERPOLATE_SOURCE(_class_, _type_, _valtype_, _default0_, _default1_, _interpexp_) \
115  \
116 SO_ENGINE_SOURCE(_class_); \
117  \
118 _class_::_class_(void) \
119 { \
120  PRIVATE_SO_INTERPOLATE_CONSTRUCTOR(_class_, _type_, _valtype_, _default0_, _default1_); \
121  this->isBuiltIn = FALSE; \
122 } \
123  \
124 PRIVATE_SO_INTERPOLATE_DESTRUCTOR(_class_) \
125 PRIVATE_SO_INTERPOLATE_EVALUATE(_class_, _type_, _valtype_, _interpexp_)
126 
127 
128 #define SO_INTERPOLATE_INITCLASS(_class_, _classname_) \
129  \
130 void \
131 _class_::initClass(void) \
132 { \
133  SO_ENGINE_INIT_CLASS(_class_, SoInterpolate, "SoInterpolate"); \
134 }
135 
136 
138 
139 
140 #ifndef COIN_INTERNAL
141 // Include these header files for better Open Inventor compatibility.
142 #include <Inventor/engines/SoInterpolateFloat.h>
143 #include <Inventor/engines/SoInterpolateVec2f.h>
144 #include <Inventor/engines/SoInterpolateVec3f.h>
145 #include <Inventor/engines/SoInterpolateVec4f.h>
146 #include <Inventor/engines/SoInterpolateRotation.h>
147 #endif // !COIN_INTERNAL
148 
149 
150 #endif // !COIN_SOINTERPOLATE_H
The SoInterpolate class is the base class for all interpolator engines.
Definition: SoInterpolate.h:41
SoEngine is the base class for Coin engines.
Definition: SoEngine.h:43
The SoFieldContainer class is a base class for all classes that contain fields.
Definition: SoFieldContainer.h:43
SoEngineOutput output
Definition: SoInterpolate.h:50
SoSFFloat alpha
Definition: SoInterpolate.h:49
static void initClasses(void)
Definition: SoEngine.cpp:173
The SoEngineOutput class is the output slots in SoEngine instances.
Definition: SoEngineOutput.h:45
The SoSFFloat class is a container for a floating point value.
Definition: SoSFFloat.h:39