H3D API  2.4.1
X3DInterpolatorNode.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __X3DINTERPOLATORNODE_H__
30 #define __X3DINTERPOLATORNODE_H__
31 
32 #include <H3D/X3DChildNode.h>
33 #include <H3D/SFFloat.h>
34 #include <H3D/MFFloat.h>
35 
36 namespace H3D {
37 
123  class H3DAPI_API X3DInterpolatorNode : public X3DChildNode {
124  public:
125 
127  X3DInterpolatorNode( Inst< SFNode > _metadata = 0,
128  Inst< SFFloat > _set_fraction = 0,
129  Inst< MFFloat > _key = 0 );
130 
134  int lookupKey( H3DFloat f, H3DFloat &w ) {
135  w = 0;
136  vector<H3DFloat> keys = key->getValue();
137  if( keys.size() == 0 ) return -1;
138 
139  if ( keys.size() == 1 || f <= keys[0] ) {
140  w = 0;
141  return 0;
142  }
143  if ( f >= keys[keys.size()-1] ) {
144  w = 1;
145  return (int)keys.size() - 2;
146  }
147 
148  // we know here that f is larger than keys[0] so we know that we will
149  // go into the if-statement at some point.
150  for( size_t i = keys.size()-1; true; --i) {
151  if ( f > keys[i] ) {
152  w = (f-keys[i])/(keys[i+1]-keys[i]);
153  if( w < 0 ) w = 0;
154  if( w > 1 ) w = 1;
155  return (int) i;
156  }
157  }
158  return -1; // something must have gone wrong to get here
159  }
160 
167  H3DUniquePtr< SFFloat > set_fraction;
168 
174  H3DUniquePtr< MFFloat > key;
175 
178  };
179 }
180 
181 #endif
Contains the MFFloat field class.
Contains the SFFloat field class.
Header file for X3DChildNode, X3D scene-graph node.
This abstract node type indicates that the concrete nodes which are instantiated based on it may be u...
Definition: X3DChildNode.h:42
The abstract node X3DInterpolatorNode forms the basis for all types of interpolators specified in thi...
Definition: X3DInterpolatorNode.h:123
H3DUniquePtr< MFFloat > key
The key field contains the list of key times, which could appear as: key [0 0.25 0....
Definition: X3DInterpolatorNode.h:174
H3DUniquePtr< SFFloat > set_fraction
The set_fraction inputOnly field receives an SFFloat event and causes the interpolator node function ...
Definition: X3DInterpolatorNode.h:167
int lookupKey(H3DFloat f, H3DFloat &w)
Utility function for Interpolator nodes to be able to find the index for the key pair to interpolate ...
Definition: X3DInterpolatorNode.h:134
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: X3DInterpolatorNode.h:177
float H3DFloat
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194