All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryGraphBuilder.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file QueryGraphBuilder.cpp
22 
23  \brief This class defines the Query strategy to build a graph having
24  a exist graph as input parameters.
25 
26  The query must be defined using only the terralib Query module
27  elements.
28 */
29 
30 // TerraLib
31 #include "../../common/Translator.h"
32 #include "../../common/progress/TaskProgress.h"
33 #include "../../dataaccess/query/Expression.h"
34 #include "../core/AbstractGraphFactory.h"
35 #include "../core/Edge.h"
36 #include "../core/GraphMetadata.h"
37 #include "../core/Vertex.h"
38 #include "../core/VertexProperty.h"
39 #include "../graphs/Graph.h"
40 #include "../iterator/QueryIterator.h"
41 #include "../Config.h"
42 #include "../Exception.h"
43 #include "QueryGraphBuilder.h"
44 
45 // STL
46 #include <cassert>
47 #include <cstdlib>
48 #include <iostream>
49 
50 
52 {
53 
54 }
55 
57 {
58 }
59 
60 bool te::graph::QueryGraphBuilder::build(te::graph::AbstractGraph* g, te::da::Expression* eEdge, te::da::Expression* eVertex, const std::map<std::string, std::string>& dsInfo, const std::string& graphType, const std::map<std::string, std::string>& gInfo)
61 {
62  //create output graph
63  m_graph = te::graph::AbstractGraphFactory::make(graphType, dsInfo, gInfo);
64 
65  assert(m_graph);
66 
67  //copy attributes
68  for(int t = 0; t < g->getEdgePropertySize(); ++ t)
69  {
71  p->setParent(0);
72 
73  m_graph->addEdgeProperty(p);
74  }
75 
76  for(int t = 0; t < g->getVertexPropertySize(); ++ t)
77  {
79  p->setParent(0);
80 
81  m_graph->addVertexProperty(p);
82  }
83 
84  //create iterator
86 
87  {
89 
90  g->setIterator(it);
91 
92  te::graph::Vertex* vertex = g->getFirstVertex();
93 
95 
97  t.setMessage(TR_GRAPH("Query Graph Builder - Vertex..."));
98  t.useTimer(true);
99 
100 
101  //copy elements
102  while(it->isVertexIteratorAfterEnd() == false)
103  {
104  if(vertex)
105  {
106  te::graph::Vertex* vNew = new te::graph::Vertex(vertex);
107 
108  m_graph->add(vNew);
109  }
110 
111  vertex = g->getNextVertex();
112 
113  t.pulse();
114  }
115 
116  delete it;
117  }
118 
119  {
121 
122  g->setIterator(it);
123 
124  te::graph::Edge* edge = g->getFirstEdge();
125 
127 
129  t.setMessage(TR_GRAPH("Query Graph Builder - Edges..."));
130  t.useTimer(true);
131 
132 
133  //copy elements
134  while(it->isEdgeIteratorAfterEnd() == false)
135  {
136  if(edge)
137  {
138  te::graph::Edge* eNew = new te::graph::Edge(edge);
139 
140  m_graph->add(eNew);
141  }
142 
143  edge = g->getNextEdge();
144 
145  t.pulse();
146  }
147 
148  delete it;
149 
150  }
151 
152  g->setIterator(oldIt);
153 
154  return true;
155 }
156 
Abstract class used to define the main functions of graph struct. All graph implementations must used...
Definition: AbstractGraph.h:56
static AbstractGraph * make()
It creates and returns an empty graph with default graph type.
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
Definition: Edge.h:58
void setParent(Property *p)
It associate this property to the informed parent.
Definition: Property.h:159
virtual te::dt::Property * getVertexProperty(int idx)
Get a vertex property given a index.
void setIterator(te::graph::AbstractIterator *i)
Used to associate a iterator to graph.
void setTotalSteps(int value)
Set the task total stepes.
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
Definition: Vertex.h:68
This abstract class provides the common functions for graph builder classes. Each builder strategy ha...
QueryGraphBuilder()
Default constructor.
virtual te::graph::GraphMetadata * getMetadata()=0
Function used to access the graph metadata.
This class defines the Query strategy to build a graph having a exist graph as input parameters...
#define TR_GRAPH(message)
It marks a string in order to get translated. This is a special mark used in the Graph module of Terr...
Definition: Config.h:58
virtual te::graph::Vertex * getNextVertex()
It returns a pointer to the next vertex element of a graph.
virtual bool isEdgeIteratorAfterEnd()
Used to check the iterator position.
virtual te::dt::Property * getEdgeProperty(int idx)
Get a edge property given a index.
virtual int getVertexPropertySize()=0
Used to verify the number of properties associated to vertex elements.
te::graph::Edge * getNextEdge()
It returns a pointer to the next edge element of a graph.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
This class defines a commun interface to represents a graph iterator class. The main diferency to ano...
bool build(te::graph::AbstractGraph *g, te::da::Expression *eEdge, te::da::Expression *eVertex, const std::map< std::string, std::string > &dsInfo, const std::string &graphType, const std::map< std::string, std::string > &gInfo)
Function used to generated the vertex id based on raster coordenate.
te::graph::Edge * getFirstEdge()
It returns a pointer to the first edge element of a graph.
virtual bool isVertexIteratorAfterEnd()
Used to check the iterator position.
It models a property definition.
Definition: Property.h:59
This is an abstract class that models a query expression.
Definition: Expression.h:47
void useTimer(bool flag)
Used to define if task use progress timer information.
virtual size_t getVertexInteratorCount()
It returns the number of elements of this iterator.
virtual ~QueryGraphBuilder()
Virtual destructor.
void setMessage(const std::string &message)
Set the task message.
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
This class defines a commun interface to represents a graph iterator class. The main diferency to ano...
Definition: QueryIterator.h:66
virtual int getEdgePropertySize()=0
Used to verify the number of properties associated to edge elements.
virtual size_t getEdgeInteratorCount()
It returns the number of elements of this iterator.
virtual Property * clone() const =0
It returns a clone of the object.
te::graph::AbstractIterator * getIterator()
Used to get a iterator associated to graph.
virtual te::graph::Vertex * getFirstVertex()
It returns a pointer to the first vertex element of a graph.