2 //##############################################################################
4 #include "../include/node.h"
8 using namespace LatticeGraph;
10 //##############################################################################
11 //##################### Ceiling Cat & Basement Cat ######################
12 //##############################################################################
14 Node::Node():uid(++suid){
21 Node::Node(Vtx::Vortex& data):uid(++suid){
25 //##############################################################################
26 //##################### Get stuff ######################
27 //##############################################################################
29 unsigned int Node::getUid(){
33 Vtx::Vortex& Node::getData(){
37 std::vector<std::weak_ptr <Edge> >& Node::getEdges(){
41 std::weak_ptr<Edge> Node::getEdge(int idx) {
42 return this->edges.at(idx);
45 std::shared_ptr<Node> Node::getConnectedNode(std::shared_ptr<Edge> e){
46 return (e->getVortex(0).lock()->getUid() != this->Node::getUid()) ? e->getVortex(0).lock() : e->getVortex(1).lock() ;
49 //##############################################################################
50 //##################### Set stuff ######################
51 //##############################################################################
53 void Node::setData(Vtx::Vortex& data){
57 //##############################################################################
58 //##################### +/- stuff ######################
59 //##############################################################################
61 void Node::addEdge(std::weak_ptr<Edge> e){
62 this->edges.push_back(e);
65 void Node::removeEdgeUid(unsigned int uid){
66 for (size_t ii=0; ii < this->Node::edges.size(); ++ii){
67 if(this->Node::getEdge(ii).lock()->getUid() == uid){
68 this->Node::getEdges().erase(this->Node::getEdges().begin()+ii);
74 void Node::removeEdgeIdx(unsigned int idx){
75 this->Node::getEdges().erase(this->Node::getEdges().begin()+idx);
78 void Node::removeEdge(std::shared_ptr<Node> n) {
79 for(std::weak_ptr<Edge> e1 : this->Node::getEdges()){
80 for(std::weak_ptr<Edge> e2 : n->getEdges()){
81 if (Node::getConnectedNode(e1.lock())->getUid() == e2.lock()->getUid()){
82 this->Node::removeEdgeUid(e2.lock()->getUid());
89 void Node::removeEdge(std::weak_ptr<Edge> edge){
90 this->Node::removeEdgeUid(edge.lock()->getUid());
93 void Node::removeEdges(){
94 for(size_t ii=0; ii<this->getEdges().size(); ++ii){
95 this->Node::removeEdge(this->Node::getEdge(ii));
97 this->Node::getEdges().clear();
100 //##############################################################################