Changeset 259
- Timestamp:
- 12/05/14 08:09:47 (10 years ago)
- Location:
- cpp/frams/genetics/f9
- Files:
-
- 2 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); -
cpp/frams/genetics/f9/conv_f9.h
r197 r259 21 21 struct XYZ_LOC 22 22 { 23 int x, y,z; //coordinates xyz of a vertex - represented as int's so that it is easy and safe to check identity. Could also be done using lists of Model's Parts, but that would involve comparing floats24 XYZ_LOC() { x=y=z=0;}25 void add(int delta[3]) { x+=delta[0]; y+=delta[1]; z+=delta[2];}26 bool same_coordinates(const XYZ_LOC &loc) { return x==loc.x && y==loc.y && z==loc.z;}23 int x, y, z; //coordinates xyz of a vertex - represented as int's so that it is easy and safe to check identity. Could also be done using lists of Model's Parts, but that would involve comparing floats 24 XYZ_LOC() { x = y = z = 0; } 25 void add(int delta[3]) { x += delta[0]; y += delta[1]; z += delta[2]; } 26 bool same_coordinates(const XYZ_LOC &loc) { return x == loc.x && y == loc.y && z == loc.z; } 27 27 }; 28 28 29 29 30 30 // The f9->f0 converter 31 class GenoConv_f90 : public GenoConverter31 class GenoConv_f90 : public GenoConverter 32 32 { 33 33 public: … … 39 39 protected: 40 40 //auxiliary methods 41 int addSegment(Model &m, vector<XYZ_LOC> &vertices,const XYZ_LOC &new_vertex,int recently_added);42 int findVertexAt(vector<XYZ_LOC> &vertices, const XYZ_LOC &new_vertex);43 int addNewVertex(Model &m, vector<XYZ_LOC> &punkty,const XYZ_LOC &nowypunkt);41 int addSegment(Model &m, int genenr, vector<XYZ_LOC> &vertices, const XYZ_LOC &new_vertex, int recently_added); 42 int findVertexAt(vector<XYZ_LOC> &vertices, const XYZ_LOC &new_vertex); 43 int addNewVertex(Model &m, vector<XYZ_LOC> &punkty, const XYZ_LOC &nowypunkt); 44 44 void setColors(Model &m); //sets fixed (independent from genes) colors and widths on a model, purely for aesthetic purposes 45 45 void perturbPartLocations(Model &m); //deterministic "body noise", see APPLY_DETERMINISTIC_BODY_NOISE
Note: See TracChangeset
for help on using the changeset viewer.