diff options
| author | Tim Redfern <tim@herge.(none)> | 2013-05-14 12:15:14 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@herge.(none)> | 2013-05-14 12:15:14 +0100 |
| commit | af4dca452a95a5b43ac0395f9505ade583aacf2f (patch) | |
| tree | 2f30b0baa498cb6e22b90ec4c31c6056b26c9b45 | |
| parent | f780d225c3a91dfb3a480bb734446858321002a0 (diff) | |
comparison and arithmetic
| -rwxr-xr-x | rotord/rotor.cpp | 3 | ||||
| -rwxr-xr-x | rotord/rotor.h | 101 | ||||
| -rw-r--r-- | rotord/utils.cpp | 19 | ||||
| -rw-r--r-- | rotord/utils.h | 7 |
4 files changed, 120 insertions, 10 deletions
diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 9e42f47..0f78100 100755 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -18,6 +18,9 @@ Node_factory::Node_factory(){ add_type("video_cycler",new Video_cycler()); add_type("luma_levels",new Luma_levels()); add_type("echo_trails",new Echo_trails()); + add_type("track_time",new Track_time()); + add_type("comparison",new Comparison()); //TODO: alias to symbols + add_type("arithmetic",new Arithmetic()); //TODO: alias to symbols } bool Signal_input::connect(Signal_node* source) { diff --git a/rotord/rotor.h b/rotord/rotor.h index 884d822..fa166a2 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -348,6 +348,105 @@ namespace Rotor { return time.time/time.duration; } }; +#define COMPARISON_Equal 1 +#define COMPARISON_Not_equal 2 +#define COMPARISON_Greater 3 +#define COMPARISON_Less 4 +#define COMPARISON_Greater_or_equal 5 +#define COMPARISON_Less_or_equal 6 + class Comparison: public Signal_node { + public: + Comparison(){}; + Comparison(map<string,string> &settings) { + base_settings(settings); + value=find_setting(settings,"value",0.0f); + string _op=find_setting(settings,"operator","=="); + if (_op=="==") op=COMPARISON_Equal; + if (_op=="!=") op=COMPARISON_Not_equal; + if (_op==">") op=COMPARISON_Greater; + if (_op=="<") op=COMPARISON_Less; + if (_op==">=") op=COMPARISON_Greater_or_equal; + if (_op=="<=") op=COMPARISON_Less_or_equal; + }; + Comparison* clone(map<string,string> &_settings) { return new Comparison(_settings);}; + const float get_output(const Time_spec &time) { + if (inputs.size()) { //there should there be a way to specify number of inputs in the code rather than in xml + if (inputs[0]->connection) { + float in= (((Signal_node*)inputs[0]->connection)->get_output(time)); + switch (op) { + case COMPARISON_Equal: + return fequal(value,in)?1.0f:0.0f; + break; + case COMPARISON_Not_equal: + return fequal(value,in)?0.0f:1.0f; + break; + case COMPARISON_Greater: + return fgreater(value,in)?1.0f:0.0f; + break; + case COMPARISON_Less: + return fless(value,in)?1.0f:0.0f; + break; + case COMPARISON_Greater_or_equal: + return fgreater_or_equal(value,in)?1.0f:0.0f; + break; + case COMPARISON_Less_or_equal: + return fless_or_equal(value,in)?1.0f:0.0f; + break; + } + } + } + return 0.0f; + } + int op; + float value; + }; +#define ARITHMETIC_plus 1 +#define ARITHMETIC_minus 2 +#define ARITHMETIC_multiply 3 +#define ARITHMETIC_divide 4 +#define ARITHMETIC_modulo 5 + class Arithmetic: public Signal_node { + public: + Arithmetic(){}; + Arithmetic(map<string,string> &settings) { + base_settings(settings); + value=find_setting(settings,"value",0.0f); + string _op=find_setting(settings,"operator","+"); + if (_op=="+") op=ARITHMETIC_plus; + if (_op=="-") op=ARITHMETIC_minus; + if (_op=="*") op=ARITHMETIC_multiply; + if (_op=="/") op=ARITHMETIC_divide; + if (_op=="%") op=ARITHMETIC_modulo; + }; + Arithmetic* clone(map<string,string> &_settings) { return new Arithmetic(_settings);}; + const float get_output(const Time_spec &time) { + if (inputs.size()) { //there should there be a way to specify number of inputs in the code rather than in xml + if (inputs[0]->connection) { + float in= (((Signal_node*)inputs[0]->connection)->get_output(time)); + switch (op) { + case ARITHMETIC_plus: + return in+value; + break; + case ARITHMETIC_minus: + return in-value; + break; + case ARITHMETIC_multiply: + return in*value; + break; + case ARITHMETIC_divide: + return in/value; + break; + case ARITHMETIC_modulo: + return fmod(in,value); + break; + } + } + } + return 0.0f; + } + int op; + float value; + }; class Signal_divide: public Signal_node { public: Signal_divide(){}; @@ -457,7 +556,7 @@ namespace Rotor { if (inputs.size()) { if (image_inputs[0]->connection){ if (inputs[0]->connection) { - if (fmoreorequal(1.0f,(((Signal_node*)inputs[0]->connection)->get_output((Time_spec)frame)))) { + if (fgreater_or_equal(1.0f,(((Signal_node*)inputs[0]->connection)->get_output((Time_spec)frame)))) { Image *in=(((Image_node*)image_inputs[0]->connection)->get_output(frame)); image->setup(frame.w,frame.h); for (int i=0;i<in->w*in->h*3;i++) { diff --git a/rotord/utils.cpp b/rotord/utils.cpp index 9e8beb6..9828124 100644 --- a/rotord/utils.cpp +++ b/rotord/utils.cpp @@ -4,21 +4,26 @@ using namespace std; //float equality bool fequal(const float u,const float v){ - if (abs(u-v)<.001) return true; + if (abs(u-v)<FLOAT_THRESHOLD) return true; else return false; }; -bool flessorequal(const float u,const float v){ +bool fless_or_equal(const float u,const float v){ //v is less or equal to u - if (u-v>-.001) return true; + if (u-v>-FLOAT_THRESHOLD) return true; else return false; }; -bool fmoreorequal(const float u,const float v){ +bool fgreater_or_equal(const float u,const float v){ //v is more or equal to u - if (v-u>-.001) return true; + if (v-u>-FLOAT_THRESHOLD) return true; else return false; }; bool fless(const float u,const float v){ - //v is less or equal to u - if (u-v>.001) return true; + //v is less than u + if (u-v>FLOAT_THRESHOLD) return true; + else return false; +}; +bool fgreater(const float u,const float v){ + //v is greater than u + if (v-u>FLOAT_THRESHOLD) return true; else return false; }; diff --git a/rotord/utils.h b/rotord/utils.h index c0c9752..3859afe 100644 --- a/rotord/utils.h +++ b/rotord/utils.h @@ -1,7 +1,10 @@ #include <cmath> +#define FLOAT_THRESHOLD .001f + //float equality bool fequal(const float u,const float v); -bool flessorequal(const float u,const float v); -bool fmoreorequal(const float u,const float v); +bool fless_or_equal(const float u,const float v); +bool fgreater_or_equal(const float u,const float v); bool fless(const float u,const float v); +bool fgreater(const float u,const float v); |
