diff options
Diffstat (limited to 'rotord/src/rotor.h')
| -rw-r--r-- | rotord/src/rotor.h | 91 |
1 files changed, 49 insertions, 42 deletions
diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h index 9c484c9..05cff46 100644 --- a/rotord/src/rotor.h +++ b/rotord/src/rotor.h @@ -234,8 +234,6 @@ namespace Rotor { Node* connection; string description; string title; - virtual double get_time_used()=0; - virtual double get_time_taken()=0; }; class Image_input: public Input{ public: @@ -245,8 +243,10 @@ namespace Rotor { connect(_connect); }; Image* get(const Frame_spec& time); - double get_time_used(); - double get_time_taken(); + double get_time_taken(){return time_taken;}; + void reset_time_taken(){time_taken=0.0;}; + private: + double time_taken; }; class Signal_input: public Input{ public: @@ -256,8 +256,6 @@ namespace Rotor { connect(_connect); }; double get(const Time_spec& time); - double get_time_used(); - double get_time_taken(); }; class Parameter: public Signal_input{ public: @@ -409,49 +407,58 @@ namespace Rotor { } } } + void set_parameter(const std::string &key,const std::string &value){ + if (parameters.find(key)!=parameters.end()) parameters[key]->value=toFloat(value); + }; void update(const Time_spec &time){ gettimeofday(&frame_time, NULL); for (auto p: parameters){ p.second->get(time); } } - void set_parameter(const std::string &key,const std::string &value){ - if (parameters.find(key)!=parameters.end()) parameters[key]->value=toFloat(value); - }; void reset(){ - time_taken=0.0; + time_used=time_taken=0.0; init(); } - void time_frame(){ - struct timeval end_time; - gettimeofday(&end_time, NULL); - time_taken+=((end_time.tv_sec-frame_time.tv_sec) + (end_time.tv_usec-frame_time.tv_usec)/1000000.0); + double get_time_used(){ + return time_used; } - virtual double get_time_used()=0; - double time_taken; + double time_taken,time_used; protected: - struct timeval frame_time; + struct timeval frame_time; }; class Signal_node: public Node{ - public: - virtual ~Signal_node(){}; - const double get_output(const Time_spec &time) { - update(time); - double o=output(time); - time_frame(); - return o; - }; - const double get_time_for_value(const double &value) { - return 0.0; + public: + virtual ~Signal_node(){}; + const double get_output(const Time_spec &time) { + update(time); + return output(time); + }; + const double get_time_for_value(const double &value) { + return 0.0; + }; + virtual const double output(const Time_spec &time) { return 0.0; }; }; - virtual const double output(const Time_spec &time) { return 0.0; }; - double get_time_used(){ - double t=time_taken; - for (auto i:inputs) t-=i->get_time_taken(); - for (auto p:parameters) t-=p.second->get_time_taken(); - return t; - } - }; + // + // There is a conceptual problem with the timing + // if we connect more than one node to an output, need it to be counted only once + // if more than 1 input of a node is connected to the same output, how do we calculate this? + // do we need to reference count? + // + // image node inits -> start timer + // call other nodes + // end timer + // + // each node knows how long it had the timer + // and what nodes it called + // calls change SO + // the INPUTS need to track time SEPERATELY from the node itself + // YES! + // then each input knows how long it should seperately time + // is there a case for a timer object? + // + // class timer: start, stop, + // class Image_node: public Node{ public: virtual ~Image_node(){ @@ -462,6 +469,7 @@ namespace Rotor { image_inputs.push_back(new Image_input(_desc,_title,_connect)); }; Image *get_image_output(const Frame_spec &frame) { + for (auto i:image_inputs) i->reset_time_taken(); update((Time_spec)frame); image.setup(frame.w,frame.h); Image *i=output(frame); @@ -474,14 +482,13 @@ namespace Rotor { image.clear(); } Image image; - double get_time_used(){ - double t=time_taken; - for (auto i:inputs) t-=i->get_time_taken(); - for (auto p:parameters) t-=p.second->get_time_taken(); - for (auto i:image_inputs) t-=i->get_time_taken(); - return t; + void time_frame(){ + struct timeval end_time; + gettimeofday(&end_time, NULL); + time_taken=((end_time.tv_sec-frame_time.tv_sec) + ((end_time.tv_usec-frame_time.tv_usec)/1000000.0)); + for (auto i:image_inputs) time_taken-=i->get_time_taken(); + time_used+=time_taken; } - private: double image_time; //? could be used to detect image reuse? |
