All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GPMBuilder.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 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 GPMBuilder.cpp
22 
23  \brief This class defines the GPM Builder class.
24 */
25 
26 // TerraLib Includes
27 #include "../../dataaccess/datasource/DataSource.h"
28 #include "../../graph/core/AbstractGraphFactory.h"
29 #include "../../graph/Globals.h"
30 #include "GPMBuilder.h"
33 
34 // STL Includes
35 #include <cassert>
36 
38  m_constructor(constructor),
39  m_weights(weights),
40  m_gpm(0)
41 {
42 }
43 
45 {
46  delete m_constructor;
47 }
48 
49 bool te::sa::GPMBuilder::setGPMInfo(te::da::DataSourcePtr ds, const std::string& dataSetName, const std::string& attributeName)
50 {
51  //set input data source
52  m_ds = ds;
53 
54  //create gpm
55  m_gpm.reset(new te::sa::GeneralizedProximityMatrix());
56 
57  m_gpm->setDataSetName(dataSetName);
58  m_gpm->setAttributeName(attributeName);
59 
60 // graph type
62 
63 // connection info
64  std::map<std::string, std::string> connInfo;
65 
66 // graph information
67  std::map<std::string, std::string> graphInfo;
68  graphInfo["GRAPH_DATA_SOURCE_TYPE"] = "MEM";
69  graphInfo["GRAPH_NAME"] = dataSetName + "_graph";
70  graphInfo["GRAPH_DESCRIPTION"] = "Generated by GPM Builder.";
71 
72  //create output graph
73  m_gpm->setGraph(te::graph::AbstractGraphFactory::make(graphType, connInfo, graphInfo));
74 
75  return true;
76 }
77 
78 std::auto_ptr<te::sa::GeneralizedProximityMatrix> te::sa::GPMBuilder::build()
79 {
80  assert(m_gpm.get());
81 
82  if(m_constructor)
83  {
84  m_constructor->construct(m_ds.get(), m_gpm.get());
85 
86  if(m_weights)
87  m_weights->calculate(m_gpm.get());
88  }
89 
90  return m_gpm;
91 }
std::auto_ptr< GeneralizedProximityMatrix > build()
Definition: GPMBuilder.cpp:78
This class defines a an Abstract class for a GPM constructor.
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
This class defines a Generalized Proximity Matrix.
bool setGPMInfo(te::da::DataSourcePtr ds, const std::string &dataSetName, const std::string &attributeName)
Function used to create a empty gpm (using a MEMORY DIRECT graph)
Definition: GPMBuilder.cpp:49
virtual ~GPMBuilder()
Virtual destructor.
Definition: GPMBuilder.cpp:44
GPMBuilder(GPMConstructorAbstractStrategy *constructor, GPMWeightsAbstractStrategy *weights)
Default constructor.
Definition: GPMBuilder.cpp:37
This class defines a an Abstract class for a GPM constructor.
static const std::string sm_factoryGraphTypeDirectedGraph
Directed Graph Factory Name.
Definition: Globals.h:54
This class defines a an Abstract class to calculates a weight for a GPM.
This class defines the GPM Builder class.
This class defines a an Abstract class to calculates a weight for a GPM.
static AbstractGraph * make()
It creates and returns an empty graph with default graph type.