GPaR sofware
Graph with ports Module Examples
The following examples will show how to use the library for rewriting port graphs:
Some examples:
A snow flake 3D example consists in replacing a triangle by a tetrahedron thanks to 2 rules described as folow (the state of ports is undefined by default. It may be either + or -):
The coordinates of the new nodes U,V,W,X are described as follow:
- X=(1/3).(A+B+C)+eps.(sqrt(2)/6).AB^AC where eps=1 if state of node A is 1 or eps=-1 if the state of node A is -1
- U=(1/2)(A+B)
- V=(1/2)(A+C)
- W=(1/2)(B+C)
The rules are as follow:
- erase edges [a2,b1],[b2,c1],[a1,c2]
- add edges [a2,u1],[u2,b1],[b2,v1],[v2,c1],[w1,c2],w2,a1]
- modify the states of nodes A,B,C
The large graph is a tetrahedron with contains :
- 4 nodes A(0,0,-sqrt(2)/sqrt(3)) B(1/2,sqrt(3)/6,0) C(-1/2,sqrt(3)/6,0) D(0,-sqrt(3)/3),0)
- 12 ports (qb,qc,qd,ra,rc(-),rd(+),pa,pb(+),pd(-),ta,tb(-),tc(+))
- 18 edges [A,qb],[A,qc],[A,qd],[B,ra],[B,rc],[B,rd],[C,pa],[C,pb],[C,pd],[D,ta],[D,tb],[D,tc], [qb,ra],[qc,pa],[qd,ta],[ra,pb],[rc,pb],[rd,tb]
The results obtain after 5 iterations is given as follow:
snow flake 3D
To simulate this example, 2 classes have to been created:
The GPM_3DSnowGraph::createPatternFunctions create the 2 functions with 2 differents patterns and with the same transformer graph with the same rules.
The rules consist in
- removing 3 edges from mapped pattern graph,
- adding 6 edges from mapped pattern graph to new copy of transformer graph in large graph
- setting the group name of mapped pattern nodes
f->setPatternGraph(pattern);
f->setTransformerGraph(transformer);
f->addPEdgeToRemove(pattern_iidp[0][1],pattern_iidp[1][0]);
f->addPEdgeToRemove(pattern_iidp[0][2],pattern_iidp[2][0]);
f->addPEdgeToRemove(pattern_iidp[1][2],pattern_iidp[2][1]);
f->addPTEdgeToAdd(pattern_iidp[0][1],transformer_iidcp[0][1]);
f->addPTEdgeToAdd(pattern_iidp[0][2],transformer_iidcp[1][0]);
f->addPTEdgeToAdd(pattern_iidp[1][0],transformer_iidcp[0][0]);
f->addPTEdgeToAdd(pattern_iidp[1][2],transformer_iidcp[2][1]);
f->addPTEdgeToAdd(pattern_iidp[2][0],transformer_iidcp[1][1]);
f->addPTEdgeToAdd(pattern_iidp[2][1],transformer_iidcp[2][0]);
f->setPatternVertexGroupName(pattern_iidv[0],"1");
f->setPatternVertexGroupName(pattern_iidv[1],"1");
f->setPatternVertexGroupName(pattern_iidv[2],"1");
return f;
}
To update the coordianates of the copied transformer graph is done by specializing the method GPM_PatternFunction::updateStates :
const vector<tVertexIID>& mappingP2L,
const map<tVertexIID,tVertexIID>& mappingT2L) {
map<tVertexIID,tVertexIID>::const_iterator mappingT2LIter;
if (cnode== null) return false;
if (cnode== null) return false;
if (cnode== null) return false;
mappingT2LIter=mappingT2L.find(0);
if (mappingT2LIter!=mappingT2L.end()) {
if (node== null) return false;
}
mappingT2LIter=mappingT2L.find(1);
if (mappingT2LIter!=mappingT2L.end()) {
if (node== null) return false;
}
mappingT2LIter=mappingT2L.find(2);
if (mappingT2LIter!=mappingT2L.end()) {
if (node== null) return false;
}
mappingT2LIter=mappingT2L.find(3);
if (mappingT2LIter!=mappingT2L.end()) {
if (node== null) return false;
}
int k=0;
for (k=0;k<3;k++) {
AB[k]=B[k]-A[k];
AC[k]=C[k]-A[k];
}
AB[3]=AB[0];
AC[3]=AC[0];
AB[4]=AB[1];
AC[4]=AC[1];
for (k=0;k<3;k++) {
ABvAC[k]=AB[k+1]*AC[k+2]-AB[k+2]*AC[k+1];
}
for (k=0;k<3;k++) {
U[k]=0.5*(A[k]+B[k]);
V[k]=0.5*(A[k]+C[k]);
W[k]=0.5*(B[k]+C[k]);
X[k]=((A[k]+B[k]+C[k])/3.)+eps*(sqrt(2)/6)*ABvAC[k];
}
return succeeds;
}
Creating pattern graph (or similarly tranfsformer graph) is as follow:
SP::GPM_Vertex v;
size_t i,j,index=0;
for (i=0;i<3;i++) {
iidv[i]=pattern->addVertex(index++);
pattern->getVertex(iidv[i])->setGroupName("0");
}
v=pattern->getVertex(iidv[0]);
for (i=0;i<3;i++) {
for (j=i+1;j<3;j++) {
pattern->addPortEdgeFromIds(iidv[i],iidv[j],index+1,index+2,iidp[i][j],iidp[j][i]);index+=2;
}
}
if (eps>0) {
v->setGroupName("1");
pattern->getVertex(iidp[1][2])->setTag("-");
pattern->getVertex(iidp[2][1])->setTag("+");
} else {
v->setGroupName("-1");
pattern->getVertex(iidp[1][2])->setTag("+");
pattern->getVertex(iidp[2][1])->setTag("-");
}
pattern->updateGroupId();
return pattern;
}
|