1 /* 2 * Interpolator.h 3 * 4 * Copyright (C) 1999 Stephen F. White 5 * 6 * This program 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 * This program 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 this program (see the file "COPYING" for details); if 18 * not, write to the Free Software Foundation, Inc., 675 Mass Ave, 19 * Cambridge, MA 02139, USA. 20 */ 21 22 #pragma once 23 24 #include "Node.h" 25 #include "ProtoMacros.h" 26 #include "Proto.h" 27 #include "MFFloat.h" 28 29 class FieldValue; 30 class CommandList; 31 32 class ProtoInterpolator : public WonderlandExportProto { 33 public: 34 ProtoInterpolator(Scene *scene, const char *name, 35 int keyType, int keysType, 36 FieldValue *defaultValue); 37 virtual Node *create(Scene *scene) = 0; 38 getNodeClass()39 int getNodeClass() const 40 { return CHILD_NODE | INTERPOLATOR_NODE; } 41 getStride(void)42 int getStride(void) { return m_stride; } 43 44 FieldIndex key; 45 FieldIndex keyValue; 46 47 protected: 48 int m_stride; 49 }; 50 51 52 class Interpolator : public Node { 53 public: 54 Interpolator(Scene *scene, Proto *proto); 55 getProfile(void)56 virtual int getProfile(void) const { return PROFILE_INTERCHANGE; } 57 58 int getNumKeys() const; 59 float getKey(int index) const; 60 virtual float getKeyValue(int channel, int index) const; 61 void setKey(int index, float value); 62 virtual void setKeyValue(int channel, int index, float value); 63 void backupKey(int index); 64 void backup(CommandList *list); 65 void receiveEvent(int eventIn, double timestamp, 66 FieldValue *value); 67 virtual void insertKey(int pos, float key, const float *values); 68 void insertKey(int pos, float key, 69 const float *values, int numValues); 70 void deleteKeys(int start, int end); 71 virtual void interpolate(float k, float *values); 72 virtual FieldValue *getInterpolatedFieldValue(float k); 73 virtual void sendInterpolatedEvent(double timestamp, float k); 74 void sendInterpolatedValue(double, float); 75 virtual int getNumChannels() const = 0; 76 virtual FieldValue *createKey(void *value) const = 0; 77 virtual FieldValue *createKeys(void *value, int numKeys) const = 0; 78 getStride()79 virtual int getStride() const { return 1; } 80 81 int findKey(float value) const; 82 int findLessKey(float value) const; 83 int findKeyInclusive(float value) const; 84 int findKeyExclusive(float value) const; 85 bool getNearestKeys(float k, float *k1, float *k2, 86 int *pos1, int *pos2); 87 getFraction()88 float getFraction() const { return m_fraction; } 89 90 void recordKey(FieldValue *value, bool isrunning); 91 virtual void recordValue(int key, FieldValue *value); 92 93 void removeKeys(float firstFraction, float lastFraction); 94 void removeOldKeys(double currentTime, double oldTime); 95 isInterpolator()96 bool isInterpolator() { return true; } set_fraction_Field()97 int set_fraction_Field() { return m_set_fractionField; } value_changed_Field()98 int value_changed_Field() { return m_value_changedField; } 99 100 fieldMacros(MFFloat, key, ProtoInterpolator); 101 102 // keyValue can not use FieldMacros cause datatype is various at this point 103 hasX3domOnOutputChange(void)104 virtual bool hasX3domOnOutputChange(void) { return true; } 105 106 protected: 107 float m_fraction; 108 float m_oldRecordedFraction; 109 FieldIndex m_set_fractionField; 110 FieldIndex m_keyValueField; 111 FieldIndex m_keyField; 112 FieldIndex m_value_changedField; 113 }; 114 115 Interpolator *dynamic_cast_Interpolator(Node* node); 116 117 #define ADD_FLIP void flip(int index) { keyValue()->flip(index); } 118 #define ADD_SWAP void swap(int fromTo) { keyValue()->swap(fromTo); } 119 120