Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Network.h

00001 // Network.h: interface for the Network class.
00002 //
00004 
00005 #if !defined(AFX_NETWORK_H__751BFE9D_1DCC_44AD_A59F_CF1F4D1EB378__INCLUDED_)
00006 #define AFX_NETWORK_H__751BFE9D_1DCC_44AD_A59F_CF1F4D1EB378__INCLUDED_
00007 
00008 #if _MSC_VER > 1000
00009 #pragma once
00010 #endif // _MSC_VER > 1000
00011 
00012 #include "entity.h"
00013 #include "path.h"
00014 //A Network is a collection of Paths that intersect at Nodes
00015 //these paths are known as Edges
00016 //Network assumes that all Edges are entirely traced
00017 
00018 /*
00019   Network aims to be context independent; that is, it is intended to be the storage backbone
00020   for things like:
00021   --Coverage traces
00022   --HGVG and company
00023   --whatever other roadmap comes up in the future
00024 */
00025 class Network : public Entity{
00026 public:
00027 
00028   class Node{
00029   public:
00030     Node(const Vector& inpos);
00031     Node(const ConStruct& context);
00032     ~Node(){};
00033 
00034     void AddEdge(const int index)
00035       {edges.push_back(index);};
00036 
00037     void RemoveEdge(const int edge_index);
00038 
00039     int EdgeIndex(const int index) const
00040       {return edges[index];};
00041 
00042     int NumEdges() const
00043       {return edges.size();};
00044 
00045     //archive the node in a ConStruct
00046     ConStruct ToConStruct() const;
00047 
00048     const Vector& GetPosition() const {return pos;};
00049   private:
00050     std::vector<int> edges;
00051     Vector pos;
00052   };
00053 
00054   Network(const ConStruct& con);
00055   Network(const ConStruct& con, const PathFactory& path_factory);
00056   ~Network();
00057 
00058   //provides functionality for path planning only on the Network
00059   //the Network can only plan Paths between Points on the same connected set
00060   //for planning paths between points in the entire workspace,
00061   //use the derived class Roadmap
00062   Path Plan(const Vector& start, const Vector& goal) const;
00063 
00064   //add an Edge to the Network;
00065   //the Network automatically figures out if Edge is connected to current Network
00066   //or adds new Nodes if Edge has endpoints not on the current Network
00067   //if client is not sure that the endpoints don't exist in the node, pass in NO_NODE
00068   //if an Edge connects to the Network at a point other than a Node, a new Node is
00069   //created and the intersected Edge is split accordingly
00070   void AddEdge(const Path& p, const int begin_node, const int end_node);
00071 
00072 
00073   void AddCycleEdge(const Path& p);
00074 
00075   bool HasEdge(const int node1, const int node2) const;
00076   static const int NO_NODE;
00077   //retrieve Node index number; if there is no match on the given position, NO_NODE is returned
00078   int MatchNode(const Vector& pos) const;
00079   
00080   //retrieve Node by index number
00081   Node& GetNode(const int index);
00082 
00083   //archive this class in a ConStruct
00084   ConStruct ToConStruct() const;
00085 
00086   //render using OpenGL
00087   void Render() const;
00088 
00089   //an Edge is the connection between two nodes
00090   struct Edge{
00091     Edge(const Path& ip, const int begin, const int end) : p(ip), begin_index(begin), end_index(end){};
00092     Edge(const ConStruct& con) : p(con.Struct("path")),
00093       begin_index(con.Int("begin_index", NO_NODE)), end_index(con.Int("end_index", NO_NODE)){}
00094     Path p;         //path data between nodes
00095     int begin_index;  //node at p.Point(Path::BEGIN)
00096     int end_index;  //node at p.Point(Path::END)
00097   };
00098   int NumEdges() const{ return edges.size();};
00099   const Edge& GetEdge(const int index) const { return edges[index];};
00100   
00101 private:
00102   std::vector<Edge> edges;
00103   std::vector<Node> nodes;
00104 
00105   const double node_match_threshold; //matching threshold between an arbitrary point and Node position
00106                                      //used when adding Edges or referring to a Node by position
00107 
00108   int AddEdgeHelper(const int node, const int new_edge, const Vector& pt);
00109 };
00110 
00111 #endif // !defined(AFX_NETWORK_H__751BFE9D_1DCC_44AD_A59F_CF1F4D1EB378__INCLUDED_)

Generated on Fri Jan 12 14:15:02 2007 for Construct by  doxygen 1.4.3-20050530