00001
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
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
00059
00060
00061
00062 Path Plan(const Vector& start, const Vector& goal) const;
00063
00064
00065
00066
00067
00068
00069
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
00078 int MatchNode(const Vector& pos) const;
00079
00080
00081 Node& GetNode(const int index);
00082
00083
00084 ConStruct ToConStruct() const;
00085
00086
00087 void Render() const;
00088
00089
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;
00095 int begin_index;
00096 int end_index;
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;
00106
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_)