C++ main module for gpm Package  1.0
GPM_ConwayGraph.h
Go to the documentation of this file.
1 #ifndef GPM_ConwayGraph_H
2 #define GPM_ConwayGraph_H
3 
4 #include "GPM_PortGraph.h"
5 
6 #include "GPM_ConwayFunction.h"
7 
190 class GPM_ConwayGraph : public virtual GPM_PortGraph {
191 
192  SP_OBJECT(GPM_ConwayGraph);
193  // ATTRIBUTES
194 
195 public:
196  static const tFlag UNDEFINED;
197  static const tFlag DEAD;
198  static const tFlag ALIVE;
199  static const tFlag DEAD_OR_ALIVE;
200 
201 private:
202 
203  int mHeight;
204  int mWidth;
205  int mColors[4];
206  int mStates[4];
207  int mPixelSize[2];
208 
209 protected:
210  // METHODS
211 
212  // CONSTRUCTORS
213 
216  GPM_ConwayGraph(void);
217 
218 
219 
220  // DESTRUCTORS
221 
222 
225  virtual ~GPM_ConwayGraph(void);
226 
227 
228 
229 public:
232  inline static SP::GPM_ConwayGraph New() {
233  SP::GPM_ConwayGraph p(new GPM_ConwayGraph(),GPM_ConwayGraph::Delete());
234  p->setThis(p);
235  return p;
236  };
237 
240  inline GPM_Node* getCell(const int& i,const int& j) {
241  int index=i+j*mWidth;
242  return dynamic_cast<GPM_Node*>(getVertex(index).get());
243  }
246  inline const GPM_Node* getCell(const int& i,const int& j) const {
247  int index=i+j*mWidth;
248  return dynamic_cast<const GPM_Node*>(getVertex(index).get());
249  }
252  inline void setSize(const int& width,const int& height) {
253  mWidth=width;
254  mHeight=height;
255  }
258  inline void setPixelSize(const int pixelSize[2]) {
259  for (int i=0;i<2;i++) mPixelSize[i]=pixelSize[i];
260  }
263  inline void setPixelSize(const int& pw,const int& ph) {
264  mPixelSize[0]=pw;mPixelSize[1]=ph;
265  }
266 
269  tBoolean createPatternFunctions(SV::GPM_PatternFunction& patternFunctions) const;
270 
273  virtual void patternsMappingSignalEmit(const SVC::GPM_PatternFunction patternFunction,
274  const vector<vector<vector<tVertexIID> > >& fmappings) const;
275 
276 
279  virtual tBoolean saveGraph(const tString& path,const tString& prefix,const int& iterations) const;
280 
283  SP::GPM_PortGraph createPatternGraph() const;
284 
287  void createGraph(const int& n,const int& p);
290  SP::GPM_ConwayFunction createPatternFunction(SP::GPM_PortGraph pattern) const;
291 
292 
293  // IMAGE IN/OUTPUTS
296  tBoolean saveToImageFile(const int& pw,const int& ph,const tString& fileName) const;
299  inline tBoolean saveToImageFile(const tString& fileName) const {
300  return saveToImageFile(mPixelSize[0],mPixelSize[1],fileName);
301  }
304  tBoolean loadFromImageFile(const int& pw,const int& ph,const tString& fileName);
307  inline tBoolean loadFromImageFile(const tString& fileName) {
308  return loadFromImageFile(mPixelSize[0],mPixelSize[1],fileName);
309  }
310 
311 
312 
313 private:
314  void createGrid(const int& n,const int& p,GPM_ConwayGraph& grid) const;
317  int getStateColor(const tFlag& state) const;
320  tFlag getState(const int& color) const;
321 
322 };
323 
324 #endif
void setSize(const int &width, const int &height)
set size
Definition: GPM_ConwayGraph.h:252
tBoolean loadFromImageFile(const tString &fileName)
load the graph from the image
Definition: GPM_ConwayGraph.h:307
static SP::GPM_ConwayGraph New()
create a test class
Definition: GPM_ConwayGraph.h:232
This class consist in modeling conway problem.
Definition: GPM_ConwayGraph.h:190
GPM_Node * getCell(const int &i, const int &j)
get the cell at index i,j
Definition: GPM_ConwayGraph.h:240
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_ConwayGraph.cpp:214
SP::GPM_PortGraph createPatternGraph() const
create a pattern graph
Definition: GPM_ConwayGraph.cpp:127
static const tFlag DEAD
Definition: GPM_ConwayGraph.h:197
tBoolean saveToImageFile(const tString &fileName) const
save the graph to image
Definition: GPM_ConwayGraph.h:299
GPM_ConwayGraph(void)
create
Definition: GPM_ConwayGraph.cpp:15
static const tFlag ALIVE
Definition: GPM_ConwayGraph.h:198
#define tBoolean
Definition: types.h:35
tBoolean loadFromImageFile(const int &pw, const int &ph, const tString &fileName)
load the graph from the image
Definition: GPM_ConwayGraph.cpp:100
tBoolean createPatternFunctions(SV::GPM_PatternFunction &patternFunctions) const
create the pattern functions for rewriting graph
Definition: GPM_ConwayGraph.cpp:219
tBoolean saveToImageFile(const int &pw, const int &ph, const tString &fileName) const
save the graph to image
Definition: GPM_ConwayGraph.cpp:75
DEFINE_SPTR(GPM_ConwayGraph)
void setPixelSize(const int &pw, const int &ph)
set pixel size
Definition: GPM_ConwayGraph.h:263
static const tFlag UNDEFINED
Definition: GPM_ConwayGraph.h:196
virtual tBoolean saveGraph(const tString &path, const tString &prefix, const int &iterations) const
save the graph during running
Definition: GPM_ConwayGraph.cpp:68
static const tFlag DEAD_OR_ALIVE
Definition: GPM_ConwayGraph.h:199
SP::GPM_Vertex getVertex(const tVertexIID &iid) const
get vertex with internal id
Definition: GPM_Graph.cpp:330
void createGraph(const int &n, const int &p)
create an initial graph
Definition: GPM_ConwayGraph.cpp:135
#define tString
Definition: types.h:36
This class describes a graph which is a list of vertices, ports & edges.
Definition: GPM_PortGraph.h:22
virtual ~GPM_ConwayGraph(void)
destroy
Definition: GPM_ConwayGraph.cpp:39
void setPixelSize(const int pixelSize[2])
set pixel size
Definition: GPM_ConwayGraph.h:258
SP::GPM_ConwayFunction createPatternFunction(SP::GPM_PortGraph pattern) const
create pattern function
Definition: GPM_ConwayGraph.cpp:205
const GPM_Node * getCell(const int &i, const int &j) const
get the cell at index i,j
Definition: GPM_ConwayGraph.h:246
This class describes a node.
Definition: GPM_Node.h:14
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
#define tFlag
Definition: types.h:14