1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkSQLGraphReader.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16   Copyright 2008 Sandia Corporation.
17   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18   the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
20 /**
21  * @class   vtkSQLGraphReader
22  * @brief   read a vtkGraph from a database
23  *
24  *
25  *
26  * Creates a vtkGraph using one or two vtkSQLQuery's.  The first (required)
27  * query must have one row for each arc in the graph.
28  * The query must have two columns which represent the source and target
29  * node ids.
30  *
31  * The second (optional) query has one row for each node in the graph.
32  * The table must have a field whose values match those in the arc table.
33  * If the node table is not given,
34  * a node will be created for each unique source or target identifier
35  * in the arc table.
36  *
37  * The source, target, and node ID fields must be of the same type,
38  * and must be either vtkStringArray or a subclass of vtkDataArray.
39  *
40  * All columns in the queries, including the source, target, and node index
41  * fields, are copied into the arc data and node data of the resulting
42  * vtkGraph.  If the node query is not given, the node data will contain
43  * a single "id" column with the same type as the source/target id arrays.
44  *
45  * If parallel arcs are collected, not all the arc data is not copied into
46  * the output.  Only the source and target id arrays will be transferred.
47  * An additional vtkIdTypeArray column called "weight" is created which
48  * contains the number of times each arc appeared in the input.
49  *
50  * If the node query contains positional data, the user may specify the
51  * names of these fields.
52  * These arrays must be data arrays.  The z-coordinate array is optional,
53  * and if not given the z-coordinates are set to zero.
54  */
55 
56 #ifndef vtkSQLGraphReader_h
57 #define vtkSQLGraphReader_h
58 
59 #include "vtkGraphAlgorithm.h"
60 #include "vtkIOSQLModule.h" // For export macro
61 
62 class vtkSQLQuery;
63 
64 class VTKIOSQL_EXPORT vtkSQLGraphReader : public vtkGraphAlgorithm
65 {
66 public:
67   static vtkSQLGraphReader* New();
68   vtkTypeMacro(vtkSQLGraphReader, vtkGraphAlgorithm);
69   void PrintSelf(ostream& os, vtkIndent indent);
70 
71   ///@{
72   /**
73    * When set, creates a directed graph, as opposed to an undirected graph.
74    */
75   vtkSetMacro(Directed, bool);
76   vtkGetMacro(Directed, bool);
77   vtkBooleanMacro(Directed, bool);
78   ///@}
79 
80   ///@{
81   /**
82    * The query that retrieves the node information.
83    */
84   virtual void SetVertexQuery(vtkSQLQuery* q);
85   vtkGetObjectMacro(VertexQuery, vtkSQLQuery);
86   ///@}
87 
88   ///@{
89   /**
90    * The query that retrieves the arc information.
91    */
92   virtual void SetEdgeQuery(vtkSQLQuery* q);
93   vtkGetObjectMacro(EdgeQuery, vtkSQLQuery);
94   ///@}
95 
96   ///@{
97   /**
98    * The name of the field in the arc query for the source node of each arc.
99    */
100   vtkSetStringMacro(SourceField);
101   vtkGetStringMacro(SourceField);
102   ///@}
103 
104   ///@{
105   /**
106    * The name of the field in the arc query for the target node of each arc.
107    */
108   vtkSetStringMacro(TargetField);
109   vtkGetStringMacro(TargetField);
110   ///@}
111 
112   ///@{
113   /**
114    * The name of the field in the node query for the node ID.
115    */
116   vtkSetStringMacro(VertexIdField);
117   vtkGetStringMacro(VertexIdField);
118   ///@}
119 
120   ///@{
121   /**
122    * The name of the field in the node query for the node's x coordinate.
123    */
124   vtkSetStringMacro(XField);
125   vtkGetStringMacro(XField);
126   ///@}
127 
128   ///@{
129   /**
130    * The name of the field in the node query for the node's y coordinate.
131    */
132   vtkSetStringMacro(YField);
133   vtkGetStringMacro(YField);
134   ///@}
135 
136   ///@{
137   /**
138    * The name of the field in the node query for the node's z coordinate.
139    */
140   vtkSetStringMacro(ZField);
141   vtkGetStringMacro(ZField);
142   ///@}
143 
144   ///@{
145   /**
146    * When set, creates a graph with no parallel arcs.
147    * Parallel arcs are combined into one arc.
148    * No cell fields are passed to the output, except the vtkGhostType array if
149    * it exists, but a new field "weight" is created that holds the number of
150    * duplicates of that arc in the input.
151    */
152   vtkSetMacro(CollapseEdges, bool);
153   vtkGetMacro(CollapseEdges, bool);
154   vtkBooleanMacro(CollapseEdges, bool);
155   ///@}
156 
157 protected:
158   vtkSQLGraphReader();
159   ~vtkSQLGraphReader() override;
160 
161   bool Directed;
162   bool CollapseEdges;
163   vtkSQLQuery* EdgeQuery;
164   vtkSQLQuery* VertexQuery;
165   char* SourceField;
166   char* TargetField;
167   char* VertexIdField;
168   char* XField;
169   char* YField;
170   char* ZField;
171 
172   virtual int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*);
173 
174   virtual int RequestDataObject(vtkInformation*, vtkInformationVector**, vtkInformationVector*);
175 
176 private:
177   vtkSQLGraphReader(const vtkSQLGraphReader&) = delete;
178   void operator=(const vtkSQLGraphReader&) = delete;
179 };
180 
181 #endif
182