H3D API  2.4.1
CoordinateInterpolator.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 //
28 //
30 #ifndef __COORDINATEINTERPOLATOR_H__
31 #define __COORDINATEINTERPOLATOR_H__
32 
34 #include <H3D/MFVec3f.h>
35 
36 namespace H3D {
37 
56  class H3DAPI_API CoordinateInterpolator : public X3DInterpolatorNode {
57  public:
58 
65  struct MFValue : TypedField< MFVec3f, Types< SFFloat, MFFloat, MFVec3f > > {
66  virtual void update() {
67  CoordinateInterpolator *interpolator =
68  static_cast<CoordinateInterpolator*>( getOwner() );
69  H3DFloat fraction = static_cast<SFFloat*>(routes_in[0])->getValue(interpolator->id);
70  int key_size = static_cast<MFFloat*>(routes_in[1])->size();
71  H3DFloat weight = 0;
72  int key_index = static_cast<CoordinateInterpolator*>(owner)->lookupKey( fraction, weight );
73  vector< Vec3f > key_values = static_cast<MFVec3f*>(routes_in[2])->getValue();
74  int value_size = 0;
75  if( key_size != 0 )
76  value_size = (int) key_values.size() / key_size;
77  value.resize( value_size );
78 
79  if ( key_index >= 0 &&
80  (key_index + 2)* value_size - 1 < (int)key_values.size() ) {
81  if (weight<=0)
82  for (int x = 0; x < value_size; ++x )
83  value[x] = key_values[ key_index*value_size + x ];
84  else if (weight>=1)
85  for (int x = 0; x < value_size; ++x )
86  value[x] = key_values[ (key_index+1)*value_size + x];
87  else { // else, interpolate linearly
88  for (int x = 0; x < value_size; ++x ) {
89  Vec3f a = key_values[ key_index*value_size + x ];
90  Vec3f b = key_values[ (key_index+1)*value_size + x ];
91  value[ x ] = (1-weight)*a + (weight)*b;
92  }
93  }
94  }
95  }
96  };
97 #ifdef __BORLANDC__
98  friend struct MFValue;
99 #endif
100 
102  CoordinateInterpolator( Inst< SFNode > _metadata = 0,
103  Inst< SFFloat > _set_fraction = 0,
104  Inst< MFFloat > _key = 0,
105  Inst< MFVec3f > _keyValue = 0,
106  Inst< MFValue > _value_changed = 0 );
107 
112  H3DUniquePtr< MFVec3f > keyValue;
113 
118  H3DUniquePtr< MFValue > value_changed;
119 
122  };
123 }
124 
125 #endif
Contains the MFVec3f field class.
Header file for X3DInterpolatorNode, X3D scene-graph node.
This node linearly interpolates among a list of MFVec3f values to produce an MFVec3f value_changed ev...
Definition: CoordinateInterpolator.h:56
static H3DNodeDatabase database
The H3DNodeDatabase for the node.
Definition: CoordinateInterpolator.h:121
H3DUniquePtr< MFValue > value_changed
The linearly interpolated result value.
Definition: CoordinateInterpolator.h:118
H3DUniquePtr< MFVec3f > keyValue
The values to interpolate between.
Definition: CoordinateInterpolator.h:112
The MFFloat field contains a vector of single-precision floating point numbers.
Definition: MFFloat.h:42
The MFVec3f field contains a vector of Vec3f.
Definition: MFVec3f.h:41
The SFFloat field contains one single-precision floating point number.
Definition: SFFloat.h:41
A template modifier class for adding type checking on the routes to any Field class.
Definition: TypedField.h:84
The abstract node X3DInterpolatorNode forms the basis for all types of interpolators specified in thi...
Definition: X3DInterpolatorNode.h:123
H3DDouble x
float H3DFloat
Type getValue(const char *s, const char *&rest)
Function that reads characters from a char * and converts them to a given type.
Definition: X3DFieldConversion.h:134
H3D API namespace.
Definition: Anchor.h:38
The SFValue field updates the interpolated value from the fields routed to it.
Definition: CoordinateInterpolator.h:65
virtual void update()
Make the field up to date given that an event has occured.
Definition: CoordinateInterpolator.h:66
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194