Changeset 259 for cpp/frams/genetics/f9/conv_f9.cpp
- Timestamp:
- 12/05/14 08:09:47 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f9/conv_f9.cpp
r197 r259 8 8 #include <common/nonstd_stl.h> //ARRAY_LENGTH 9 9 10 #define APPLY_DETERMINISTIC_BODY_NOISE //this representation easily produces perfectly vertical sticks that would stay upright forever. In most cases such infinite perfection is not desired, so we make the construct less perfect by perturbing its coordinates.10 #define APPLY_DETERMINISTIC_BODY_NOISE //this genetic representation easily produces perfectly vertical sticks that would stay upright forever in simulation. In most cases such infinite perfection is not desired, so we make the construct less perfect by perturbing its coordinates. 11 11 12 12 GenoConv_f90::GenoConv_f90() … … 15 15 in_format = '9'; 16 16 out_format = '0'; 17 mapsupport = 0; //would be easy and nice to add!17 mapsupport = 1; 18 18 } 19 19 … … 31 31 Model m; 32 32 m.open(); 33 int recently_added = addSegment(m, vertices, current, 0xDead);33 int recently_added = addSegment(m, 0, vertices, current, 0xDead); 34 34 for (int i = 0; i < in.len(); i++) 35 35 { … … 44 44 (*(delta + axis)) += dir * 2 - 1; //+1 or -1 in the given axis 45 45 current.add(delta); 46 recently_added = addSegment(m, vertices, current, recently_added);46 recently_added = addSegment(m, i, vertices, current, recently_added); 47 47 } 48 48 } … … 54 54 if (m.getPartCount() < 2) //only one part <=> there were no valid turtle commands in the input genotype 55 55 return ""; //so we return an invalid f0 genotype 56 if (map != NULL) 57 m.getCurrentToF0Map(*map); 56 58 return m.getF0Geno().getGene(); 57 59 } 58 60 59 int GenoConv_f90::addSegment(Model &m, vector<XYZ_LOC> &vertices, const XYZ_LOC &new_vertex, int recently_added)61 int GenoConv_f90::addSegment(Model &m, int genenr, vector<XYZ_LOC> &vertices, const XYZ_LOC &new_vertex, int recently_added) 60 62 { 61 63 if (vertices.size() < 1) //empty model? … … 72 74 Part *p1 = m.getPart(recently_added); 73 75 Part *p2 = m.getPart(vertex_here); 74 if (m.findJoint(p1, p2) < 0 && m.findJoint(p2, p1) < 0) //new Joint needed? should always be true if we just created a new Part (vertex_here was <0) 75 { 76 m.addNewJoint(p1, p2); 77 } 76 p1->addMapping(MultiRange(genenr, genenr)); 77 p2->addMapping(MultiRange(genenr, genenr)); 78 79 int j12 = m.findJoint(p1, p2); 80 int j21 = m.findJoint(p2, p1); 81 if (j12 >= 0) 82 m.getJoint(j12)->addMapping(MultiRange(genenr, genenr)); 83 else if (j21 >= 0) 84 m.getJoint(j21)->addMapping(MultiRange(genenr, genenr)); 85 else //both j12<0 and j21<0. New Joint needed. Should always happen if we just created a new Part (vertex_here was <0) 86 m.addNewJoint(p1, p2)->addMapping(MultiRange(genenr, genenr)); 78 87 return vertex_here; 79 88 } … … 134 143 int parts_count = m.getPartCount(); 135 144 SList jlist; 136 for (int i = 0; i <parts_count; i++)145 for (int i = 0; i < parts_count; i++) 137 146 { 138 147 Part *p = m.getPart(i);
Note: See TracChangeset
for help on using the changeset viewer.