C++ main module for gpm Package  1.0
GPM_PortGraph.h
Go to the documentation of this file.
1 #ifndef GPM_PortGraph_H
2 #define GPM_PortGraph_H
3 
4 #include "GPM_Graph.h"
5 
6 #include "CORE_Out.h"
7 
8 #include "GPM_Port.h"
9 
12 
13 // boost include
20 
21 
22 class GPM_PortGraph : public GPM_Graph{
23 SP_OBJECT(GPM_PortGraph);
24 // ATTRIBUTES
25 
26 public:
27  static const tFlag SEGMENT;
28  static const tFlag TRIANGLE;
29  static const tFlag TETRAHEDRON;
30  static const tFlag PYRAMID;
31  static const tFlag WEDGE;
32  static const tFlag HEXAHEDRON;
33 
34 
35 
36 private:
37 
38 
39 
40  tString mPath;
41  tString mPrefix;
42  unsigned int mIterations;
43  unsigned int mIterationsMaxNumber;
44 
45 
46  SV::GPM_PatternFunction mPatternFunctions;
47  SP::GPM_PatternFunction mF;
48 
49 
50 
51 protected:
52  // METHODS
53 
54  // CONSTRUCTORS
55 
57  GPM_PortGraph(void);
58 
59 
60 
61  // DESTRUCTORS
62 
63 
66  virtual ~GPM_PortGraph(void);
67 
68 
69 public:
70 
71  // NEW methods
72 
75  static inline SP::GPM_PortGraph New() {
76  SP::GPM_PortGraph p(new GPM_PortGraph(),GPM_PortGraph::Delete());
77  p->setThis(p);
78  return p;
79  }
80 
81  //SET & GET methods
82  // ----------------
85  inline void setPath(const tString& path) {
86  mPath=path;
87  }
90  inline tString getPath() const {
91  return mPath;
92  }
95  inline void setPrefix(const tString& v) {
96  mPrefix=v;
97  }
100  inline tString getPrefix() const {
101  return mPrefix;
102  }
103 
104 protected:
107  inline void setIteration(const int& v) {
108  mIterations=v;
109  }
110 public:
113  inline int getIteration() const {
114  return mIterations;
115  }
118  inline void setIterationsMaxNumber(const int& v) {
119  mIterationsMaxNumber=v;
120  }
121 public:
124  inline int getIterationsMaxNumber() const {
125  return mIterationsMaxNumber;
126  }
127 
128 
131  virtual SP::GPM_GraphElement newInstance(const tString& className) const;
134  virtual SP::GPM_Port newPort() const {
135  return GPM_Port::New();
136  }
137 
138 
141  inline tVertexIID addPort(const int& id) {
142  SP::GPM_Port port=newPort();
143  port->setId(id);
144  return GPM_Graph::addVertex(port);
145  }
146 
149  inline tVertexIID addPort() {
150  SP::GPM_Port port=newPort();
151  port->setId(generateVertexId());
152  return GPM_Graph::addVertex(port);
153  }
156  inline tVertexIID addPort(SP::GPM_Port port) {
157  return GPM_Graph::addVertex(port);
158  }
159 
160 
165  tBoolean addPortEdgeFromIds(const int& from,const int& to,
166  const int& fromPortId,const int& toPortId,
167  tVertexIID& fromPortIID,tVertexIID& toPortIID);
170  inline tBoolean addPortEdgeFromIds(const int& fromId,const int& toId,const int& fromPortId,const int& toPortId) {
171  tVertexIID fromPortIID,toPortIID;
172  return addPortEdgeFromIds(fromId,toId,fromPortId,toPortId,fromPortIID,toPortIID);
173  }
174 
175 
176 
177 
178 public:
181  void updateGraphElementsEnvironment(const map<tString,SP::GPM_Variable>& nodeEnvironment,
182  const map<tString,SP::GPM_Variable>& portEnvironment,
183  const map<tString,SP::GPM_Variable>& edgeEnvironment);
184 
187  void buildEnvironments(map<tString,SP::GPM_Variable>& nodeEnvironment,
188  map<tString,SP::GPM_Variable>& portEnvironment,
189  map<tString,SP::GPM_Variable>& edgeEnvironment) const;
190 
191 public:
194  void getConnectedNodesToPort(const tVertexIID& portIID,tVertexIID& sourceNode,tVertexIID& targetNode) const;
195 
198  void initGroupNames(const vector<tString>& nodeIds,const vector<tString>& portIds);
201  void initGroupNames() {
202  vector<tString> nodeIds,portIds;
203  initGroupNames(nodeIds,portIds);
204  }
205 
208  inline void clearPatternFunctions() {
209  mPatternFunctions.clear();
210  }
213  inline void addPatternFunction(SP::GPM_PatternFunction f) {
214  mPatternFunctions.add(f);
215  }
216 
219  inline SV::GPM_PatternFunction& getPatternFunctions() {
220  return mPatternFunctions;
221  }
222 
223  // Graph creation method
224  //======================
225 
236  void generateQuadGraph(const int& nTriangles,const tBoolean& withMiddle,const int& n,const int& m,const tReal& w,const tReal& h,const tReal& xmin,const tReal& ymin);
237 
238  // Graph properties method
239  //---------------------------
242  virtual tBoolean isValid() const;
246  virtual tString isEdgeValid(const GPM_Vertex& source,
247  const GPM_Vertex& target,
248  tBoolean& isValid) const;
249 
252  virtual tBoolean isMappingValid(const SV::GPM_Vertex& smallGraphVertices,
253  const vector<tVertexIID>& mapping,
254  CORE_Out& io) const;
255 
261  virtual tBoolean reduce(int& nReductions,CORE_Out& io);
262 
263  // primitive geometries to find
264  // ---------------------------
268  void findMesh(const vector<tFlag>& meshTypes,vector<vector<tVertexIID> >& geometries) const {
269  for (size_t i=0;i<meshTypes.size();i++)
270  findMesh(meshTypes[i],geometries);
271  }
275  void findMesh(const tFlag& meshType,vector<vector<tVertexIID> >& geometries) const;
276 
279  void findSegments(vector<vector<tVertexIID> >& geometry) const;
280 
281 
282 
283  // IO methods
284  // -----------
285 public:
288  virtual tBoolean exportToCurveFile(const tString& fileName,
289  const tString& title,
290  const tString& XLabel,
291  const tString& YLabel) const;
292  // Re-Writing
293  // ---------
294 private:
304  tBoolean rewrite(SV::GPM_PatternFunction& patternFunction,int& nReductions,CORE_Out& io);
305 
306 public:
316  inline tBoolean rewrite(int& nReductions,CORE_Out& io) {
317  return rewrite(mPatternFunctions,nReductions,io);
318  }
319 
320 protected:
323  virtual void patternsMappingSignalEmit(const SVC::GPM_PatternFunction patternFunction,
324  const vector<vector<vector<tVertexIID> > >& fmappings) const{
325  };
326 
327 private:
331  tBoolean makeOneReduction(tBoolean& mergingAllowed,CORE_Out& io);
332 
333  // RUNNER
334  // ======
335 public:
338  tBoolean run(CORE_Out& io);
341  tBoolean run(const tString& path,const tString& prefix,const int& nMaxIterations,CORE_Out& io) {
342  setPath(path);
343  setPrefix(prefix);
344  setIterationsMaxNumber(nMaxIterations);
345  return run(io);
346  }
347 
348 public:
349 
350 
351 
355  virtual tBoolean saveGraph(const tString& path,const tString& prefix,const int& nDigits,const int& iterations,tString& fn) const;
359  virtual tBoolean loadGraph(const tString& path,const tString& prefix,const int& nDigits,const int& iterations,CORE_Out& io,tString& fn);
360 };
361 
362 #endif
static const tFlag HEXAHEDRON
Definition: GPM_PortGraph.h:32
void setPath(const tString &path)
set the path
Definition: GPM_PortGraph.h:85
DEFINE_SPTR(GPM_PortGraph)
void initGroupNames()
init group name to type of the vertex
Definition: GPM_PortGraph.h:201
int getIteration() const
get the prefix
Definition: GPM_PortGraph.h:113
static const tFlag TRIANGLE
Definition: GPM_PortGraph.h:28
SV::GPM_PatternFunction & getPatternFunctions()
get the pattern functions
Definition: GPM_PortGraph.h:219
tString getPath() const
get the path
Definition: GPM_PortGraph.h:90
static const tFlag SEGMENT
Definition: GPM_PortGraph.h:27
static const tFlag TETRAHEDRON
Definition: GPM_PortGraph.h:29
int run(int argc, char *argv[])
Definition: GPM_ExamplesMain.cpp:3
tBoolean rewrite(int &nReductions, CORE_Out &io)
rewrite the graph substitute the patterns by the graphs defined in PatternFunctions algorithm: ...
Definition: GPM_PortGraph.h:316
static SP::GPM_PortGraph New()
create a graph
Definition: GPM_PortGraph.h:75
#define tBoolean
Definition: types.h:35
void setPrefix(const tString &v)
set the prefix
Definition: GPM_PortGraph.h:95
tVertexIID addPort()
add port
Definition: GPM_PortGraph.h:149
virtual void patternsMappingSignalEmit(const SVC::GPM_PatternFunction patternFunction, const vector< vector< vector< tVertexIID > > > &fmappings) const
signal emmiting when the matching of patterns is done
Definition: GPM_PortGraph.h:323
void addPatternFunction(SP::GPM_PatternFunction f)
add pattern function
Definition: GPM_PortGraph.h:213
This class describes a node.
Definition: GPM_Vertex.h:16
int getIterationsMaxNumber() const
get the max iterations number
Definition: GPM_PortGraph.h:124
void findMesh(const vector< tFlag > &meshTypes, vector< vector< tVertexIID > > &geometries) const
get all the geometries vertex <–> vertex without ports inside.
Definition: GPM_PortGraph.h:268
#define SP_OBJECT(X)
Definition: CORE_Pointers.h:176
void clearPatternFunctions()
clear pattern functions
Definition: GPM_PortGraph.h:208
tVertexIID addPort(const int &id)
add port
Definition: GPM_PortGraph.h:141
tVertexIID addVertex(SP::GPM_Vertex vertex)
add vertex vertex with id
Definition: GPM_Graph.cpp:306
tGraph::vertex_descriptor tVertexIID
Definition: GPM_Types.h:45
static const tFlag PYRAMID
Definition: GPM_PortGraph.h:30
#define DEFINE_SVPTR(X)
Definition: CORE_ListPointers.h:21
static SP::GPM_Port New()
create a port
Definition: GPM_Port.h:49
void setIteration(const int &v)
set the iteration
Definition: GPM_PortGraph.h:107
void setIterationsMaxNumber(const int &v)
set the max iterations number
Definition: GPM_PortGraph.h:118
#define tString
Definition: types.h:36
tVertexIID addPort(SP::GPM_Port port)
add port
Definition: GPM_PortGraph.h:156
This class describes a graph which is a list of vertices, ports & edges.
Definition: GPM_PortGraph.h:22
tBoolean addPortEdgeFromIds(const int &fromId, const int &toId, const int &fromPortId, const int &toPortId)
add 2 ports with ids fromPortId, toPortId from vertex with id from to vertex with id to ...
Definition: GPM_PortGraph.h:170
This class describes a patten function.
Definition: GPM_PatternFunction.h:20
this class describes the output by default write on standart output
Definition: CORE_Out.h:21
tString getPrefix() const
get the prefix
Definition: GPM_PortGraph.h:100
static const tFlag WEDGE
Definition: GPM_PortGraph.h:31
This class describes a graph which is a list of nodes & ports.
Definition: GPM_Graph.h:19
tBoolean run(const tString &path, const tString &prefix, const int &nMaxIterations, CORE_Out &io)
run the writer
Definition: GPM_PortGraph.h:341
#define tReal
Definition: types.h:18
virtual SP::GPM_Port newPort() const
create a port
Definition: GPM_PortGraph.h:134
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
#define tFlag
Definition: types.h:14