Aleph-w  1.5a.2
Biblioteca general de algoritmos y estructuras de datos
 Todo Clases Archivos Funciones Variables 'typedefs' Enumeraciones Amigas Grupos Páginas
tpl_euclidian_graph.H
1 
2 # ifndef TPL_EUCLIDIAN_GRAPH_H
3 # define TPL_EUCLIDIAN_GRAPH_H
4 
5 # include <tpl_graph.H>
6 # include <point.H>
7 
8 namespace Aleph
9 {
10 
15  template <typename Node_Info>
16 class Euclidian_Node : public Graph_Node <Node_Info>
17 {
18 public:
19 
20  typedef Node_Info Item_Type;
21 
22  typedef Euclidian_Node Node;
23 
24  typedef Node_Info Node_Type;
25 
26 private:
27 
28  Point position;
29 
30 public:
31 
33  : Graph_Node<Node_Info>(), position()
34  {
35  /* Empty */
36  }
37 
38  Euclidian_Node(const Node_Info & info)
39  : Graph_Node<Node_Info>(info), position()
40  {
41  /* Empty */
42  }
43 
44  Euclidian_Node(const Point & _position)
45  : Graph_Node<Node_Info>(), position(_position)
46  {
47  /* Empty */
48  }
49 
50  Euclidian_Node(const Node_Info & info, const Point & _position)
51  : Graph_Node<Node_Info>(info), position(_position)
52  {
53  /* Empty */
54  }
55 
57  : Graph_Node<Node_Info>(node), position(node->get_position())
58  {
59  /* Empty */
60  }
61 
62  Point & get_position() { return position; }
63 
64  const Point & get_position() const { return position; }
65 }; // End class Euclidian_Node
66 
67 
68  template <typename Arc_Info>
69 class Euclidian_Arc : public Graph_Arc <Arc_Info>
70 {
71 public:
72 
73  typedef Arc_Info Arc_Item;
74 
75  typedef Euclidian_Arc Arc;
76 
77  typedef Arc_Info Arc_Type;
78 
81  {
82  /* Empty */
83  }
84 
85  Euclidian_Arc(const Arc_Info & info)
86  : Graph_Arc<Arc_Info>(info)
87  {
88  /* Empty */
89  }
90 
91  Euclidian_Arc(void * src, void * tgt, const Arc_Info & info)
92  : Graph_Arc<Arc_Info>(src, tgt, info)
93  {
94  /* Empty */
95  }
96 
97  Euclidian_Arc(void * src, void * tgt)
98  : Graph_Arc<Arc_Info>(src, tgt)
99  {
100  /* Empty */
101  }
102 }; // End class Euclidian_Arc
103 
104  template <class __Euclidian_Node, class __Euclidian_Arc>
105 class Euclidian_Graph : public List_Graph <__Euclidian_Node, __Euclidian_Arc>
106 {
107 public:
108 
109  typedef __Euclidian_Node Node;
110 
111  typedef __Euclidian_Arc Arc;
112 
114 
115  typedef typename Node::Node_Type Node_Type;
116 
117  typedef typename Arc::Arc_Type Arc_Type;
118 
119  Euclidian_Graph() : Graph()
120  {
121  /* Empty */
122  }
123 
124  Euclidian_Graph(const Euclidian_Graph <Node, Arc> & euclidian_graph)
125  : Graph()
126  {
127  copy_graph(*this, const_cast<Euclidian_Graph <Node, Arc> &> (euclidian_graph), false);
128  }
129 
130  virtual Node * insert_node(Node * node)
131  {
132  return Graph::insert_node(node);
133  }
134 
135  virtual Node * insert_node(const Node_Type & info)
136  {
137  return insert_node(new Node(info));
138  }
139 
140  virtual Node * insert_node(const Point & position)
141  {
142  return insert_node(new Node(position));
143  }
144 
145  virtual Node * insert_node(const Node_Type & info, const Point & position)
146  {
147  return insert_node(new Node(info, position));
148  }
149 
150  Geom_Number get_distance(Arc * arc)
151  {
152  const Point & src_point = get_src_node(arc)->get_position();
153  const Point & tgt_point = get_tgt_node(arc)->get_position();
154  return src_point.distance_with(tgt_point);
155  }
156 
158  {
159  if (this == &eg)
160  return *this;
161  copy_graph(*this, const_cast<Euclidian_Graph<Node, Arc> &>(eg), false);
162  return *this;
163  }
164 
165  virtual ~Euclidian_Graph()
166  {
167  clear_graph(*this);
168  }
169 
170  Node * search_node(const Point &);
171 }; // End class Euclidian_Graph
172 
173  template <class __Euclidian_Node, class __Euclidian_Arc>
175  : public Euclidian_Graph<__Euclidian_Node, __Euclidian_Arc>
176 {
177 public:
178 
180  {
182  }
183 
186  {
188  }
189 
191  {
193  }
194 
195  }; // End class Euclidian_Digraph
196 
197  template <class Node, class Arc>
198  Node * Euclidian_Graph<Node, Arc>::search_node(const Point & point)
199  {
200  for (typename Euclidian_Graph<Node, Arc>::Node_Iterator it; it.has_current(); it.next())
201  {
202  Euclidian_Graph<Node, Arc>::Node * curr = it.get_current();
203  if (curr->get_position() == point)
204  return curr;
205  }
206  return NULL;
207  }
208 
209  template <class __Euclidian_Graph>
211  {
212  Point * ptr_east_point;
213  Point * ptr_north_point;
214  Point * ptr_west_point;
215  Point * ptr_south_point;
216 
217  DynArray<Point> points;
218 
219  Geom_Number x_node_ratio;
220  Geom_Number y_node_ratio;
221 
222  Geom_Number x_scale;
223  Geom_Number y_scale;
224 
225  public:
227  : x_node_ratio(0), y_node_ratio(0), x_scale(1), y_scale(1),
228  ptr_east_point(NULL), ptr_north_point(NULL), ptr_west_point(NULL), ptr_south_point(NULL)
229  {
230  // Empty
231  }
232 
233  Abstract_Euclidian_Plane(__Euclidian_Graph & graph)
234  : x_node_ratio(0), y_node_ratio(0), x_scale(1), y_scale(1),
235  ptr_east_point(NULL), ptr_north_point(NULL), ptr_west_point(NULL), ptr_south_point(NULL)
236  {
237  if (graph.get_num_nodes() < 1)
238  return;
239 
240  typename __Euclidian_Graph::Node_Iterator itor(graph);
241  points.append(itor.get_current()->get_position());
242  ptr_west_point = ptr_north_point = ptr_east_point = ptr_south_point = &points.access(0);
243 
244  for (int i = 1 ; itor.has_current(); itor.next(), ++i)
245  {
246  const Point & p = itor.get_current()->get_position();
247  points.append(p);
248  if (p.get_x() < ptr_west_point->get_x())
249  ptr_west_point = &points.access(i);
250  if (p.get_y() > ptr_north_point->get_y())
251  ptr_north_point = &points.access(i);
252  if (p.get_x() > ptr_east_point->get_x())
253  ptr_east_point = &points.access(i);
254  if (p.get_y() < ptr_south_point->get_y())
255  ptr_south_point = &points.access(i);
256  }
257  }
258 
260  {
261  /* Empty */
262  }
263 
264  Point & add_point(typename __Euclidian_Graph::Node * node)
265  {
266  if (node == NULL)
267  throw std::domain_error("node is NULL");
268  points.append(node->get_position());
269  Point & p = points.top();
270  if (points.size() == 1)
271  ptr_west_point = ptr_north_point = ptr_east_point = ptr_south_point = &points.access(0);
272  else
273  {
274  if (p.get_x() < ptr_west_point->get_x())
275  ptr_west_point = &p;
276  if (p.get_y() > ptr_north_point->get_y())
277  ptr_north_point = &p;
278  if (p.get_x() > ptr_east_point->get_x())
279  ptr_east_point = &p;
280  if (p.get_y() < ptr_south_point->get_y())
281  ptr_south_point = &p;
282  }
283  return p;
284  }
285 
286  const Point & get_west_point() const
287  {
288  if (points.size() < 1)
289  throw std::logic_error("There are no points on plane");
290  return *ptr_west_point;
291  }
292 
293  const Point & get_north_point() const
294  {
295  if (points.size() < 1)
296  throw std::logic_error("There are no points on plane");
297  return *ptr_north_point;
298  }
299 
300  const Point & get_east_point() const
301  {
302  if (points.size() < 1)
303  throw std::logic_error("There are no points on plane");
304  return *ptr_east_point;
305  }
306 
307  const Point & get_south_point() const
308  {
309  if (points.size() < 1)
310  throw std::logic_error("There are no points on plane");
311  return *ptr_south_point;
312  }
313 
314  const Geom_Number get_width() const
315  {
316  if (points.size() < 1)
317  return Geom_Number(0);
318  return ptr_east_point->get_x() - ptr_west_point->get_x();
319  }
320 
321  const Geom_Number get_height() const
322  {
323  if (points.size() < 1)
324  return Geom_Number(0);
325  return ptr_north_point->get_y() - ptr_south_point->get_y();
326  }
327 
328  const Geom_Number & get_x_node_ratio() const { return x_node_ratio; }
329 
330  void set_x_node_ratio(const Geom_Number & _x_node_ratio) { x_node_ratio = _x_node_ratio; }
331 
332  const Geom_Number & get_y_node_ratio() const { return y_node_ratio; }
333 
334  void set_y_node_ratio(const Geom_Number & _y_node_ratio) { y_node_ratio = _y_node_ratio; }
335 
336  const Geom_Number & get_x_scale() const { return x_scale; }
337 
338  void set_x_scale(const Geom_Number & _x_scale) { x_scale = _x_scale; }
339 
340  const Geom_Number & get_y_scale() const { return y_scale; }
341 
342  void set_y_scale(const Geom_Number & _y_scale) { y_scale = _y_scale; }
343 
344  }; // End class Abstract_Euclidian_Plane
345 
346 } // End namespace Aleph
347 
348 # endif // TPL_EUCLIDIAN_GRAPH_H
349 
Definition: tpl_euclidian_graph.H:69
Definition: tpl_graph.H:29
Definition: tpl_euclidian_graph.H:16
Definition: tpl_graph.H:21
virtual Node * insert_node(Node *node)
Definition: tpl_euclidian_graph.H:130
size_t size() const
Retorna dimensión actual (más lejano índice escrito)
Definition: tpl_dynArray.H:523
T & top()
Retorna el último elemento del arreglo como si fuese una pila.
Definition: tpl_dynArray.H:1154
Definition: point.H:87
const Geom_Number & get_y() const
retorna el valor de la coordenada y
Definition: point.H:166
Definition: tpl_euclidian_graph.H:174
const Geom_Number & get_x() const
retorna el valor de la coordenada x
Definition: point.H:161
void clear_graph(GT &g)
Definition: tpl_graph.H:2486
T & append()
Definition: tpl_dynArray.H:1115
Definition: tpl_graph.H:19
void copy_graph(GT &gtgt, GT &gsrc, const bool cookie_map=false)
Definition: tpl_graph.H:2505
Geom_Number distance_with(const Point &p) const
retorna la distancia euclidiana entre this y el punto p
Definition: point.H:853
T & access(const size_t i)
Definition: tpl_dynArray.H:793
Definition: tpl_euclidian_graph.H:105
virtual Node * insert_node(const Node_Type &info)
Definition: tpl_euclidian_graph.H:135
virtual Node * insert_node(Node *node)
Definition: tpl_graph.H:2215
Definition: tpl_euclidian_graph.H:210

Leandro Rabindranath León