From c10e756720fe30ad2ffdcb54d83737aaad77190b Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 21 Jan 2014 16:34:54 +0000 Subject: variable_array_type connection wrong --- NT/NT.layout | 16 ++++++++-------- NT/src/graph.cpp | 12 +++++++++++- NT/src/graph.h | 4 ++++ NT/src/nodes.h | 5 ++++- NT/src/rotor.cpp | 35 +++++++++++++++++++++++------------ NT/src/rotor.h | 23 ++++++++++++----------- 6 files changed, 62 insertions(+), 33 deletions(-) (limited to 'NT') diff --git a/NT/NT.layout b/NT/NT.layout index 6d0700e..319c62d 100644 --- a/NT/NT.layout +++ b/NT/NT.layout @@ -1,14 +1,14 @@ - + - + - + - + @@ -16,14 +16,14 @@ - + - + - + - + diff --git a/NT/src/graph.cpp b/NT/src/graph.cpp index 87a7b87..65bd6c8 100644 --- a/NT/src/graph.cpp +++ b/NT/src/graph.cpp @@ -29,6 +29,12 @@ bool Graph::load_file(std::string filename,std::string media_path){ cerr<<"Rotor: graph "<::iterator it=nodes.begin();it!=nodes.end();++it) { + if (it->second->get_type()==type) return it->second; + } + return nullptr; +}; bool Graph::parse_json(string &data,string &media_path){ Json::Value root; // will contain the root value after parsing. Json::Reader reader; @@ -62,8 +68,9 @@ bool Graph::parse_json(string &data,string &media_path){ // //node.create_links(nodes) //will allow the nodes to be passed into each member of a variable array - node->create_connections(nodes); nodes[node_id]=node; + nodes[node_id]->create_connections(nodes); + } else cerr << "ERROR: duplicate node '"< nodes; diff --git a/NT/src/nodes.h b/NT/src/nodes.h index 4b1b2ac..0f885da 100644 --- a/NT/src/nodes.h +++ b/NT/src/nodes.h @@ -45,7 +45,10 @@ namespace Rotor{ }; const double &get_output(const Frame_parameters &frame){ result=1.0f; - for (auto var:factors->get_values()) result*=var.get(frame); + for (auto val:factors->get_values()) { + std::cerr<<"got value: "<*>(p))->get_output(f).c_str()); + } + } } diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 0a016a2..96a89ef 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -89,7 +89,9 @@ namespace Rotor { }; class Variable { //pure virtual base type for variable pointers public: - Variable(){connection=nullptr;}; + Variable(){ + connection=nullptr; + }; virtual ~Variable(){}; virtual Json::Value to_json()=0; virtual void init(Json::Value s)=0; @@ -109,7 +111,11 @@ namespace Rotor { }; template class Variable_type : public Variable { public: - Variable_type(std::string _name="",std::string _input="",bool _connectable=true){name=_name;input=_input;connectable=_connectable;}; + Variable_type(std::string _name="",std::string _input="",bool _connectable=true){ + name=_name; + input=_input; + connectable=_connectable; + }; void init(Json::Value s){ std::istringstream cur(s["value"].asString()); cur >> value; @@ -131,7 +137,7 @@ namespace Rotor { return TypeName::Get(); } //have to cast connect and get_output to use templated return types - bool connect(Node* target){ + bool connect(Node* target){ if (connectable){ if (dynamic_cast*>(target)){ connection=target; @@ -143,7 +149,7 @@ namespace Rotor { const T& get(const Frame_parameters &frame){ if (connection){ return (dynamic_cast*>(connection))->get_output(frame); - } + } return value; } protected: @@ -175,13 +181,8 @@ namespace Rotor { std::string get_type(){ return TypeName::Get(); } - bool connect(Node* target){ - if (connectable){ - if (dynamic_cast*>(target)){ - connection=target; - return true; - } - } + bool connect(Node* target){ + //array does not connect this way return false; } void add(std::string _name,std::string _input,bool _connectable=true){ -- cgit v1.2.3