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 /*!
34   \class SoInterpolate SoInterpolate.h Inventor/engines/SoInterpolate.h
35   \brief The SoInterpolate class is the base class for all interpolator engines.
36 
37   \ingroup engines
38 
39   Interpolators are used to linearly interpolate between two values.
40 
41   In Coin, we've chosen to implement all interpolators in separate
42   files. If you want to be OIV compatible when programming, you should
43   include the SoInterpolate.h, and not the interpolator file(s) you
44   need.
45 */
46 
47 #include <Inventor/engines/SoInterpolate.h>
48 #include <Inventor/lists/SoEngineOutputList.h>
49 
50 #if COIN_DEBUG
51 #include <Inventor/errors/SoDebugError.h>
52 #endif // COIN_DEBUG
53 
54 #include "engines/SoSubEngineP.h"
55 
56 /*!
57   \var SoSFFloat SoInterpolate::alpha
58 
59   The value which says how much we've should interpolate from first
60   value to second value. A value equal to 0 will give an output equal
61   to the first value, alpha equal to 1 gives the second value, any
62   value in between gives a "weighted" interpolation between the two
63   values.
64 */
65 /*!
66   \var SoEngineOutput SoInterpolate::output
67 
68   Interpolated values from the input fields. The type of the output
69   will of course be the same as the type of the input fields of each
70   non-abstract subclass inheriting SoInterpolate.
71 */
72 
73 SO_ENGINE_ABSTRACT_SOURCE(SoInterpolate);
74 
75 
76 /*!
77   Default constructor.
78 */
SoInterpolate(void)79 SoInterpolate::SoInterpolate(void)
80 {
81   // Don't use standard SO_ENGINE_CONSTRUCTOR.
82 
83   // Catch attempts to use an engine class which has not been
84   // initialized.
85   assert(SoInterpolate::classTypeId != SoType::badType());
86   // Initialize a inputdata container for the class only once.
87   if (!SoInterpolate::inputdata) {
88     // FIXME: is this really necessary for SoInterpolate? 20000505 mortene.
89     SoInterpolate::inputdata =
90       new SoFieldData(SoInterpolate::parentinputdata ?
91                       *SoInterpolate::parentinputdata : NULL);
92     SoInterpolate::outputdata =
93       new SoEngineOutputData(SoInterpolate::parentoutputdata ?
94                              *SoInterpolate::parentoutputdata : NULL);
95   }
96 
97   SO_ENGINE_ADD_INPUT(alpha, (0.0f));
98 }
99 
100 // Documented in superclass.
101 void
initClass(void)102 SoInterpolate::initClass(void)
103 {
104   SO_ENGINE_INTERNAL_INIT_ABSTRACT_CLASS(SoInterpolate);
105 }
106 
107 /*!
108   This method is provided only for API compatibility, and does nothing
109   in Coin.
110 */
111 void
initClasses(void)112 SoInterpolate::initClasses(void)
113 {
114 }
115 
116 /*!
117   Destructor.
118 */
~SoInterpolate()119 SoInterpolate::~SoInterpolate()
120 {
121 #if COIN_DEBUG && 0 // debug
122   SoDebugError::postInfo("SoInterpolate::~SoInterpolate", "%p", this);
123 #endif // debug
124   delete this->inputdata; this->inputdata = NULL;
125   delete this->outputdata; this->outputdata = NULL;
126 }
127