1 // This is brl/bbas/bgrl2/bgrl2_edge.h 2 #ifndef bgrl2_edge_h_ 3 #define bgrl2_edge_h_ 4 5 //: 6 // \file 7 // \brief A templated directed edge class for a generic graph class 8 // \author Amir Tamrakar 9 // \date February 30, 2005 10 // 11 // This edge has pointers to its source and target vertices 12 // 13 // \verbatim 14 // Modifications 15 // Amir Tamrakar Feb 30, 2005 Initial version. 16 // Ozge C. Ozcanli Nov 15, 2008 Moved up to vxl, minor fixes 17 // \endverbatim 18 19 #include <iostream> 20 #ifdef _MSC_VER 21 # include <vcl_msvc_warnings.h> 22 #endif 23 #include <vbl/vbl_ref_count.h> 24 #include <vbl/vbl_smart_ptr.h> 25 26 //: A Directed edge in a graph 27 template<class V> 28 class bgrl2_edge : public vbl_ref_count 29 { 30 protected: 31 typedef vbl_smart_ptr<V> V_sptr; 32 33 public: 34 // Constructor bgrl2_edge()35 bgrl2_edge() : vbl_ref_count(), source_(nullptr), target_(nullptr) {} 36 37 // Constructor bgrl2_edge(V_sptr v1,V_sptr v2)38 bgrl2_edge(V_sptr v1, V_sptr v2) : vbl_ref_count(), source_(v1), target_(v2) {} 39 40 // Destructor 41 ~bgrl2_edge() override= default; 42 43 //: Smart pointer to the vertex where this edge originates source()44 V_sptr source() const { return source_; } 45 46 //: Smart pointer to the vertex where this edge points to target()47 V_sptr target() const { return target_; } 48 49 //: Returns target(edge) if v = source(edge) and source(edge) otherwise. 50 V_sptr opposite(V_sptr v); 51 52 //: set the source vertex set_source(V_sptr v)53 void set_source(V_sptr v) { source_ = v; } 54 55 //: set the target vertex set_target(V_sptr v)56 void set_target(V_sptr v) { target_ = v; } 57 58 //: Determine if ``this'' edge shares a vertex with other edge 59 // Return the shared node if so, otherwise return 0 60 V_sptr shared_vertex(const bgrl2_edge<V >& other) const; 61 62 //: Print an ascii summary to the stream 63 virtual void print_summary(std::ostream &os) const; 64 65 protected: 66 67 //: The source vertex 68 V_sptr source_; 69 70 //: The target vertex 71 V_sptr target_; 72 }; 73 74 #endif // bgrl2_edge_h_ 75