[286] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
| 2 | // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski. |
---|
| 3 | // See LICENSE.txt for details. |
---|
[109] | 4 | |
---|
| 5 | #include <common/nonstd_math.h> |
---|
| 6 | #include "model.h" |
---|
[375] | 7 | #include <common/log.h> |
---|
[109] | 8 | #include <frams/util/multimap.h> |
---|
[391] | 9 | #include <common/loggers/loggers.h> |
---|
[109] | 10 | |
---|
| 11 | Model::Model() |
---|
| 12 | { |
---|
[522] | 13 | autobuildmaps = false; |
---|
| 14 | init(); |
---|
[109] | 15 | } |
---|
| 16 | |
---|
| 17 | void Model::init() |
---|
| 18 | { |
---|
[522] | 19 | partmappingchanged = 0; |
---|
| 20 | buildstatus = empty; |
---|
| 21 | modelfromgenotype = 0; |
---|
| 22 | startenergy = 1.0; |
---|
| 23 | checklevel = 1; |
---|
[109] | 24 | #ifdef MODEL_V1_COMPATIBLE |
---|
[522] | 25 | oldneurocount=-1; // == unknown |
---|
| 26 | oldconnections=0; |
---|
[109] | 27 | #endif |
---|
[522] | 28 | map = 0; |
---|
| 29 | f0map = 0; |
---|
| 30 | f0genoknown = 1; |
---|
| 31 | shape = SHAPE_UNKNOWN; |
---|
[109] | 32 | } |
---|
| 33 | |
---|
| 34 | void Model::moveElementsFrom(Model &source) |
---|
| 35 | { |
---|
[522] | 36 | int i; |
---|
| 37 | open(); |
---|
| 38 | for (i = 0; i < source.getPartCount(); i++) |
---|
| 39 | addPart(source.getPart(i)); |
---|
| 40 | for (i = 0; i < source.getJointCount(); i++) |
---|
| 41 | addJoint(source.getJoint(i)); |
---|
| 42 | for (i = 0; i < source.getNeuroCount(); i++) |
---|
| 43 | addNeuro(source.getNeuro(i)); |
---|
| 44 | source.parts.clear(); source.joints.clear(); source.neurons.clear(); |
---|
| 45 | source.clear(); |
---|
[109] | 46 | } |
---|
| 47 | |
---|
| 48 | void Model::internalCopy(const Model &mod) |
---|
| 49 | { |
---|
[522] | 50 | geno = mod.geno; |
---|
| 51 | f0genoknown = 0; |
---|
| 52 | startenergy = mod.startenergy; |
---|
| 53 | if (mod.getStatus() == valid) |
---|
[109] | 54 | { |
---|
[522] | 55 | modelfromgenotype = mod.modelfromgenotype; |
---|
| 56 | {for (int i = 0; i < mod.getPartCount(); i++) |
---|
| 57 | addPart(new Part(*mod.getPart(i))); } |
---|
| 58 | {for (int i = 0; i < mod.getJointCount(); i++) |
---|
| 59 | { |
---|
| 60 | Joint *oldj = mod.getJoint(i); |
---|
| 61 | Joint *j = new Joint(*oldj); |
---|
[109] | 62 | addJoint(j); |
---|
[522] | 63 | j->attachToParts(oldj->part1->refno, oldj->part2->refno); |
---|
| 64 | }} |
---|
| 65 | {for (int i = 0; i < mod.getNeuroCount(); i++) |
---|
| 66 | { |
---|
| 67 | Neuro *oldn = mod.getNeuro(i); |
---|
| 68 | Neuro *n = new Neuro(*oldn); |
---|
[109] | 69 | addNeuro(n); |
---|
[522] | 70 | if (oldn->part_refno >= 0) n->attachToPart(oldn->part_refno); |
---|
[109] | 71 | else n->attachToJoint(oldn->joint_refno); |
---|
[522] | 72 | }} |
---|
| 73 | for (int i = 0; i < mod.getNeuroCount(); i++) |
---|
[109] | 74 | { |
---|
[522] | 75 | Neuro *oldn = mod.getNeuro(i); |
---|
| 76 | Neuro *n = getNeuro(i); |
---|
| 77 | for (int ni = 0; ni < oldn->getInputCount(); ni++) |
---|
[109] | 78 | { |
---|
[522] | 79 | double w; |
---|
| 80 | Neuro *oldinput = oldn->getInput(ni, w); |
---|
| 81 | SString info = n->getInputInfo(ni); |
---|
| 82 | n->addInput(getNeuro(oldinput->refno), w, &info); |
---|
[109] | 83 | } |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
[522] | 89 | Model::Model(const Geno &src, bool buildmaps) |
---|
[109] | 90 | :autobuildmaps(buildmaps) |
---|
[522] | 91 | { |
---|
| 92 | init(src); |
---|
| 93 | } |
---|
[109] | 94 | |
---|
| 95 | void Model::operator=(const Model &mod) |
---|
| 96 | { |
---|
[522] | 97 | clear(); |
---|
| 98 | open(); |
---|
| 99 | internalCopy(mod); |
---|
| 100 | buildstatus = mod.buildstatus; |
---|
[109] | 101 | } |
---|
| 102 | |
---|
[522] | 103 | Model::Model(const Model &mod, bool buildmaps) |
---|
[109] | 104 | :autobuildmaps(buildmaps) |
---|
| 105 | { |
---|
[522] | 106 | init(); |
---|
| 107 | open(); |
---|
| 108 | internalCopy(mod); |
---|
| 109 | buildstatus = mod.buildstatus; |
---|
[109] | 110 | } |
---|
| 111 | |
---|
| 112 | void Model::init(const Geno &src) |
---|
| 113 | { |
---|
[522] | 114 | init(); |
---|
| 115 | modelfromgenotype = 1; |
---|
| 116 | geno = src; |
---|
| 117 | build(); |
---|
[109] | 118 | } |
---|
| 119 | |
---|
| 120 | void Model::resetAllDelta() |
---|
| 121 | { |
---|
[522] | 122 | for (int i = 0; i < getJointCount(); i++) |
---|
| 123 | getJoint(i)->resetDelta(); |
---|
[109] | 124 | } |
---|
| 125 | |
---|
| 126 | void Model::useAllDelta(bool yesno) |
---|
| 127 | { |
---|
[522] | 128 | for (int i = 0; i < getJointCount(); i++) |
---|
| 129 | getJoint(i)->useDelta(yesno); |
---|
[109] | 130 | } |
---|
| 131 | |
---|
| 132 | Model::~Model() |
---|
| 133 | { |
---|
[522] | 134 | delmodel_list.action((intptr_t)this); |
---|
| 135 | clear(); |
---|
[109] | 136 | } |
---|
| 137 | |
---|
| 138 | void Model::clear() |
---|
| 139 | { |
---|
[522] | 140 | FOREACH(Part*, p, parts) |
---|
| 141 | delete p; |
---|
| 142 | FOREACH(Joint*, j, joints) |
---|
| 143 | delete j; |
---|
| 144 | FOREACH(Neuro*, n, neurons) |
---|
| 145 | delete n; |
---|
| 146 | parts.clear(); joints.clear(); neurons.clear(); |
---|
| 147 | delMap(); |
---|
| 148 | delF0Map(); |
---|
| 149 | init(); |
---|
| 150 | geno = Geno(); |
---|
| 151 | f0geno = Geno(); |
---|
[109] | 152 | } |
---|
| 153 | |
---|
| 154 | Part *Model::addPart(Part *p) |
---|
| 155 | { |
---|
[522] | 156 | p->owner = this; |
---|
| 157 | p->refno = parts.size(); |
---|
| 158 | parts += p; |
---|
| 159 | return p; |
---|
[109] | 160 | } |
---|
| 161 | |
---|
| 162 | Joint *Model::addJoint(Joint *j) |
---|
| 163 | { |
---|
[522] | 164 | j->owner = this; |
---|
| 165 | j->refno = joints.size(); |
---|
| 166 | joints += j; |
---|
| 167 | return j; |
---|
[109] | 168 | } |
---|
| 169 | |
---|
| 170 | Neuro *Model::addNeuro(Neuro *n) |
---|
| 171 | { |
---|
[522] | 172 | n->owner = this; |
---|
| 173 | n->refno = neurons.size(); |
---|
| 174 | neurons += n; |
---|
| 175 | return n; |
---|
[109] | 176 | } |
---|
| 177 | |
---|
| 178 | void Model::removeNeuros(SList &nlist) |
---|
| 179 | { |
---|
[522] | 180 | FOREACH(Neuro*, nu, nlist) |
---|
[109] | 181 | { |
---|
[522] | 182 | int i = findNeuro(nu); |
---|
| 183 | if (i >= 0) removeNeuro(i); |
---|
[109] | 184 | } |
---|
| 185 | } |
---|
| 186 | |
---|
[522] | 187 | void Model::removePart(int partindex, int removeattachedjoints, int removeattachedneurons) |
---|
[109] | 188 | { |
---|
[522] | 189 | Part *p = getPart(partindex); |
---|
| 190 | if (removeattachedjoints) |
---|
[109] | 191 | { |
---|
[522] | 192 | SList jlist; |
---|
| 193 | findJoints(jlist, p); |
---|
| 194 | FOREACH(Joint*, j, jlist) |
---|
[109] | 195 | { |
---|
[522] | 196 | int i = findJoint(j); |
---|
| 197 | if (i >= 0) removeJoint(i, removeattachedneurons); |
---|
[109] | 198 | } |
---|
| 199 | } |
---|
[522] | 200 | if (removeattachedneurons) |
---|
[109] | 201 | { |
---|
[522] | 202 | SList nlist; |
---|
| 203 | findNeuros(nlist, 0, p); |
---|
| 204 | removeNeuros(nlist); |
---|
[109] | 205 | } |
---|
[522] | 206 | parts -= partindex; |
---|
| 207 | delete p; |
---|
[109] | 208 | } |
---|
| 209 | |
---|
[522] | 210 | void Model::removeJoint(int jointindex, int removeattachedneurons) |
---|
[109] | 211 | { |
---|
[522] | 212 | Joint *j = getJoint(jointindex); |
---|
| 213 | if (removeattachedneurons) |
---|
[109] | 214 | { |
---|
[522] | 215 | SList nlist; |
---|
| 216 | findNeuros(nlist, 0, 0, j); |
---|
| 217 | removeNeuros(nlist); |
---|
[109] | 218 | } |
---|
[522] | 219 | joints -= jointindex; |
---|
| 220 | delete j; |
---|
[109] | 221 | } |
---|
| 222 | |
---|
[522] | 223 | void Model::removeNeuro(int neuroindex, bool removereferences) |
---|
[109] | 224 | { |
---|
[522] | 225 | Neuro* thisN = getNeuro(neuroindex); |
---|
[109] | 226 | |
---|
[522] | 227 | if (removereferences) |
---|
[109] | 228 | { |
---|
[522] | 229 | Neuro* n; |
---|
| 230 | // remove all references to thisN |
---|
| 231 | for (int i = 0; n = (Neuro*)neurons(i); i++) |
---|
[109] | 232 | { |
---|
[522] | 233 | Neuro *inp; |
---|
| 234 | for (int j = 0; inp = n->getInput(j); j++) |
---|
| 235 | if (inp == thisN) |
---|
[109] | 236 | { |
---|
| 237 | n->removeInput(j); |
---|
| 238 | j--; |
---|
| 239 | } |
---|
| 240 | } |
---|
| 241 | } |
---|
| 242 | |
---|
[522] | 243 | neurons -= neuroindex; |
---|
| 244 | delete thisN; |
---|
[109] | 245 | } |
---|
| 246 | |
---|
| 247 | MultiMap& Model::getMap() |
---|
| 248 | { |
---|
[522] | 249 | if (!map) map = new MultiMap(); |
---|
| 250 | return *map; |
---|
[109] | 251 | } |
---|
| 252 | |
---|
| 253 | void Model::delMap() |
---|
| 254 | { |
---|
[522] | 255 | if (map) { delete map; map = 0; } |
---|
[109] | 256 | } |
---|
| 257 | void Model::delF0Map() |
---|
| 258 | { |
---|
[522] | 259 | if (f0map) { delete f0map; f0map = 0; } |
---|
[109] | 260 | } |
---|
| 261 | |
---|
[522] | 262 | void Model::makeGenToGenMap(MultiMap& result, const MultiMap& gen1tomodel, const MultiMap& gen2tomodel) |
---|
[109] | 263 | { |
---|
[522] | 264 | result.clear(); |
---|
| 265 | MultiMap m; |
---|
| 266 | m.addReversed(gen2tomodel); |
---|
| 267 | result.addCombined(gen1tomodel, m); |
---|
[109] | 268 | } |
---|
| 269 | |
---|
| 270 | void Model::getCurrentToF0Map(MultiMap& result) |
---|
| 271 | { |
---|
[522] | 272 | result.clear(); |
---|
| 273 | if (!map) return; |
---|
| 274 | const MultiMap& f0m = getF0Map(); |
---|
| 275 | makeGenToGenMap(result, *map, f0m); |
---|
[109] | 276 | } |
---|
| 277 | |
---|
| 278 | void Model::rebuild(bool buildm) |
---|
| 279 | { |
---|
[522] | 280 | autobuildmaps = buildm; |
---|
| 281 | clear(); |
---|
| 282 | build(); |
---|
[109] | 283 | } |
---|
| 284 | |
---|
| 285 | void Model::initMap() |
---|
| 286 | { |
---|
[522] | 287 | if (!map) map = new MultiMap(); |
---|
| 288 | else map->clear(); |
---|
[109] | 289 | } |
---|
| 290 | |
---|
| 291 | void Model::initF0Map() |
---|
| 292 | { |
---|
[522] | 293 | if (!f0map) f0map = new MultiMap(); |
---|
| 294 | else f0map->clear(); |
---|
[109] | 295 | } |
---|
| 296 | |
---|
| 297 | void Model::build() |
---|
| 298 | { |
---|
[522] | 299 | f0errorposition = -1; |
---|
| 300 | f0warnposition = -1; |
---|
| 301 | MultiMap *convmap = autobuildmaps ? new MultiMap() : NULL; |
---|
| 302 | f0geno = (geno.getFormat() == '0') ? geno : geno.getConverted('0', convmap); |
---|
| 303 | f0genoknown = 1; |
---|
| 304 | if (f0geno.isInvalid()) |
---|
[109] | 305 | { |
---|
[522] | 306 | buildstatus = invalid; |
---|
| 307 | if (convmap) delete convmap; |
---|
| 308 | return; |
---|
[109] | 309 | } |
---|
[522] | 310 | SString f0txt = f0geno.getGene(); |
---|
| 311 | buildstatus = building; // was: open(); |
---|
| 312 | if (autobuildmaps) |
---|
[109] | 313 | { |
---|
[522] | 314 | partmappingchanged = 0; |
---|
| 315 | initMap(); |
---|
| 316 | initF0Map(); |
---|
[109] | 317 | } |
---|
[522] | 318 | int pos = 0, lnum = 1, lastpos = 0; |
---|
| 319 | SString line; |
---|
| 320 | MultiRange frommap; |
---|
| 321 | LoggerToMemory mh(LoggerBase::Enable | LoggerBase::DontBlock); |
---|
| 322 | for (; f0txt.getNextToken(pos, line, '\n'); lnum++) |
---|
[109] | 323 | { |
---|
[522] | 324 | if (autobuildmaps) |
---|
[109] | 325 | { |
---|
[522] | 326 | frommap.clear(); |
---|
| 327 | frommap.add(lastpos, pos - 1); |
---|
[109] | 328 | } |
---|
[522] | 329 | mh.reset(); |
---|
| 330 | if (singleStepBuild(line, lnum, autobuildmaps ? (&frommap) : 0) == -1) |
---|
[109] | 331 | { |
---|
[522] | 332 | buildstatus = invalid; |
---|
| 333 | f0errorposition = lastpos; |
---|
| 334 | if (convmap) delete convmap; |
---|
| 335 | return; |
---|
[109] | 336 | } |
---|
[522] | 337 | if (mh.getWarningCount()) |
---|
| 338 | { |
---|
| 339 | if (f0warnposition < 0) f0warnposition = lastpos; |
---|
| 340 | } |
---|
| 341 | lastpos = pos; |
---|
[109] | 342 | } |
---|
[522] | 343 | mh.disable(); |
---|
| 344 | close(); |
---|
| 345 | if (convmap) |
---|
[109] | 346 | { |
---|
[522] | 347 | *f0map = *map; |
---|
| 348 | if (geno.getFormat() != '0') |
---|
[109] | 349 | { |
---|
[522] | 350 | MultiMap tmp; |
---|
| 351 | tmp.addCombined(*convmap, getMap()); |
---|
| 352 | *map = tmp; |
---|
[109] | 353 | } |
---|
[522] | 354 | delete convmap; |
---|
[109] | 355 | } |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | const MultiMap& Model::getF0Map() |
---|
| 359 | { |
---|
[522] | 360 | if (!f0map) |
---|
[109] | 361 | { |
---|
[522] | 362 | f0map = new MultiMap(); |
---|
| 363 | makeGeno(f0geno, f0map); |
---|
| 364 | f0genoknown = 1; |
---|
[109] | 365 | } |
---|
[522] | 366 | return *f0map; |
---|
[109] | 367 | } |
---|
| 368 | |
---|
| 369 | Geno Model::rawGeno() |
---|
| 370 | { |
---|
[522] | 371 | Geno tmpgen; |
---|
| 372 | makeGeno(tmpgen); |
---|
| 373 | return tmpgen; |
---|
[109] | 374 | } |
---|
| 375 | |
---|
[522] | 376 | void Model::makeGeno(Geno &g, MultiMap *map, bool handle_defaults) |
---|
[109] | 377 | { |
---|
[522] | 378 | if ((buildstatus != valid) && (buildstatus != building)) |
---|
[109] | 379 | { |
---|
[522] | 380 | g = Geno(0, 0, 0, "invalid model"); |
---|
| 381 | return; |
---|
[109] | 382 | } |
---|
| 383 | |
---|
[522] | 384 | SString gen; |
---|
[109] | 385 | |
---|
[522] | 386 | Param modelparam(f0_model_paramtab); |
---|
| 387 | Param partparam(f0_part_paramtab); |
---|
| 388 | Param jointparam(f0_joint_paramtab); |
---|
| 389 | Param neuroparam(f0_neuro_paramtab); |
---|
| 390 | Param connparam(f0_neuroconn_paramtab); |
---|
[109] | 391 | |
---|
[522] | 392 | static Part defaultpart; |
---|
| 393 | static Joint defaultjoint; |
---|
| 394 | static Neuro defaultneuro; |
---|
| 395 | static Model defaultmodel; |
---|
| 396 | static NeuroConn defaultconn; |
---|
| 397 | //static NeuroItem defaultneuroitem; |
---|
[109] | 398 | |
---|
[522] | 399 | Part *p; |
---|
| 400 | Joint *j; |
---|
| 401 | Neuro *n; |
---|
| 402 | int i; |
---|
| 403 | int len; |
---|
| 404 | int a, b; |
---|
| 405 | //NeuroItem *ni; |
---|
[109] | 406 | |
---|
[522] | 407 | SString mod_props; |
---|
| 408 | modelparam.select(this); |
---|
| 409 | modelparam.save2(mod_props, handle_defaults ? &defaultmodel : NULL, true, !handle_defaults); |
---|
| 410 | if (mod_props.len() > 1) //are there any non-default values? ("\n" is empty) |
---|
[109] | 411 | { |
---|
[522] | 412 | gen += "m:"; |
---|
| 413 | gen += mod_props; |
---|
[109] | 414 | } |
---|
| 415 | |
---|
[522] | 416 | for (i = 0; p = (Part*)parts(i); i++) |
---|
[109] | 417 | { |
---|
[522] | 418 | partparam.select(p); |
---|
| 419 | len = gen.len(); |
---|
| 420 | gen += "p:"; |
---|
| 421 | partparam.save2(gen, handle_defaults ? &defaultpart : NULL, true, !handle_defaults); |
---|
| 422 | if (map) |
---|
| 423 | map->add(len, gen.len() - 1, partToMap(i)); |
---|
[109] | 424 | } |
---|
[522] | 425 | for (i = 0; j = (Joint*)joints(i); i++) |
---|
[109] | 426 | { |
---|
[522] | 427 | jointparam.select(j); |
---|
| 428 | len = gen.len(); |
---|
| 429 | jointparam.setParamTab(j->usedelta ? f0_joint_paramtab : f0_nodeltajoint_paramtab); |
---|
| 430 | gen += "j:"; |
---|
| 431 | jointparam.save2(gen, handle_defaults ? &defaultjoint : NULL, true, !handle_defaults); |
---|
| 432 | if (map) |
---|
| 433 | map->add(len, gen.len() - 1, jointToMap(i)); |
---|
[109] | 434 | } |
---|
[522] | 435 | for (i = 0; n = (Neuro*)neurons(i); i++) |
---|
[109] | 436 | { |
---|
[522] | 437 | neuroparam.select(n); |
---|
| 438 | len = gen.len(); |
---|
| 439 | gen += "n:"; |
---|
| 440 | neuroparam.save2(gen, handle_defaults ? &defaultneuro : NULL, true, !handle_defaults); |
---|
| 441 | if (map) |
---|
| 442 | map->add(len, gen.len() - 1, neuroToMap(i)); |
---|
[109] | 443 | } |
---|
[522] | 444 | for (a = 0; a < neurons.size(); a++) |
---|
[109] | 445 | { // inputs |
---|
[522] | 446 | n = (Neuro*)neurons(a); |
---|
| 447 | // if ((n->getInputCount()==1)&&(n->getInput(0).refno <= n->refno)) |
---|
| 448 | // continue; // already done with Neuro::conn_refno |
---|
[109] | 449 | |
---|
[522] | 450 | for (b = 0; b < n->getInputCount(); b++) |
---|
[109] | 451 | { |
---|
[522] | 452 | double w; |
---|
| 453 | NeuroConn nc; |
---|
| 454 | Neuro* n2 = n->getInput(b, w); |
---|
| 455 | // if (((n2.parentcount==1)&&(n2.parent)&&(n2.parent->refno < n2.refno)) ^ |
---|
| 456 | // (n2.neuro_refno>=0)) |
---|
| 457 | // printf("!!!! bad Neuro::neuro_refno ?!\n"); |
---|
[109] | 458 | |
---|
[522] | 459 | // if ((n2.parentcount==1)&&(n2.parent)&&(n2.parent->refno < n2.refno)) |
---|
| 460 | // if (n2.neuro_refno>=0) |
---|
| 461 | // continue; // already done with Neuro::neuro_refno |
---|
[109] | 462 | |
---|
[522] | 463 | nc.n1_refno = n->refno; nc.n2_refno = n2->refno; |
---|
| 464 | nc.weight = w; |
---|
| 465 | SString **s = n->inputInfo(b); |
---|
| 466 | if ((s) && (*s)) |
---|
| 467 | nc.info = **s; |
---|
| 468 | connparam.select(&nc); |
---|
| 469 | len = gen.len(); |
---|
| 470 | gen += "c:"; |
---|
| 471 | connparam.save2(gen, handle_defaults ? &defaultconn : NULL, true, !handle_defaults); |
---|
| 472 | if (map) |
---|
| 473 | map->add(len, gen.len() - 1, neuroToMap(n->refno)); |
---|
[109] | 474 | } |
---|
| 475 | } |
---|
[522] | 476 | g = Geno(gen.c_str(), '0'); |
---|
[109] | 477 | } |
---|
| 478 | |
---|
| 479 | ////////////// |
---|
| 480 | |
---|
| 481 | void Model::open() |
---|
| 482 | { |
---|
[522] | 483 | if (buildstatus == building) return; |
---|
| 484 | buildstatus = building; |
---|
| 485 | modelfromgenotype = 0; |
---|
| 486 | partmappingchanged = 0; |
---|
| 487 | f0genoknown = 0; |
---|
| 488 | delMap(); |
---|
[109] | 489 | } |
---|
| 490 | |
---|
| 491 | void Model::checkpoint() |
---|
| 492 | {} |
---|
| 493 | |
---|
| 494 | void Model::setGeno(const Geno& newgeno) |
---|
| 495 | { |
---|
[522] | 496 | geno = newgeno; |
---|
[109] | 497 | } |
---|
| 498 | |
---|
| 499 | void Model::clearMap() |
---|
| 500 | { |
---|
[522] | 501 | Part *p; Joint *j; Neuro *n; |
---|
| 502 | int i; |
---|
| 503 | delMap(); |
---|
| 504 | delF0Map(); |
---|
| 505 | for (i = 0; p = (Part*)parts(i); i++) |
---|
| 506 | p->clearMapping(); |
---|
| 507 | for (i = 0; j = (Joint*)joints(i); i++) |
---|
| 508 | j->clearMapping(); |
---|
| 509 | for (i = 0; n = (Neuro*)neurons(i); i++) |
---|
| 510 | n->clearMapping(); |
---|
[109] | 511 | } |
---|
| 512 | |
---|
| 513 | int Model::close() |
---|
| 514 | { |
---|
[522] | 515 | if (buildstatus != building) |
---|
| 516 | logPrintf("Model", "close", LOG_WARN, "Unexpected close() - no open()"); |
---|
| 517 | if (internalcheck(1) > 0) |
---|
[109] | 518 | { |
---|
[522] | 519 | buildstatus = valid; |
---|
[109] | 520 | |
---|
[522] | 521 | if (partmappingchanged) |
---|
[109] | 522 | { |
---|
[522] | 523 | getMap(); |
---|
| 524 | Part *p; Joint *j; Neuro *n; |
---|
| 525 | int i; |
---|
| 526 | for (i = 0; p = (Part*)parts(i); i++) |
---|
| 527 | if (p->getMapping()) |
---|
| 528 | map->add(*p->getMapping(), partToMap(i)); |
---|
| 529 | for (i = 0; j = (Joint*)joints(i); i++) |
---|
| 530 | if (j->getMapping()) |
---|
| 531 | map->add(*j->getMapping(), jointToMap(i)); |
---|
| 532 | for (i = 0; n = (Neuro*)neurons(i); i++) |
---|
| 533 | if (n->getMapping()) |
---|
| 534 | map->add(*n->getMapping(), neuroToMap(i)); |
---|
[109] | 535 | } |
---|
| 536 | } |
---|
[522] | 537 | else |
---|
| 538 | buildstatus = invalid; |
---|
[109] | 539 | |
---|
[522] | 540 | return (buildstatus == valid); |
---|
[109] | 541 | } |
---|
| 542 | |
---|
| 543 | int Model::validate() |
---|
| 544 | { |
---|
[522] | 545 | return internalcheck(0); |
---|
[109] | 546 | } |
---|
| 547 | |
---|
[522] | 548 | Pt3D Model::whereDelta(const Part& start, const Pt3D& rot, const Pt3D& delta) |
---|
[109] | 549 | { |
---|
[522] | 550 | Orient roto; |
---|
| 551 | roto = rot; |
---|
| 552 | Orient o; |
---|
| 553 | roto.transform(o, start.o); |
---|
| 554 | //o.x=start.o/roto.x; |
---|
| 555 | //o.y=start.o/roto.y; |
---|
| 556 | //o.z=start.o/roto.z; |
---|
| 557 | return o.transform(delta) + start.p; |
---|
[109] | 558 | } |
---|
| 559 | |
---|
[522] | 560 | int Model::singleStepBuild(const SString &singleline, const MultiRange* srcrange) |
---|
[109] | 561 | { |
---|
[522] | 562 | return singleStepBuild(singleline, 0, srcrange); |
---|
[495] | 563 | } |
---|
| 564 | |
---|
[522] | 565 | int Model::singleStepBuild(const SString &singleline, int line_num, const MultiRange* srcrange) |
---|
[495] | 566 | { |
---|
[522] | 567 | SString error_message; |
---|
| 568 | int result = singleStepBuildNoLog(singleline, error_message, srcrange); |
---|
| 569 | if (result < 0) |
---|
[495] | 570 | { |
---|
[522] | 571 | if (error_message.len() == 0) // generic error when no detailed message is available |
---|
| 572 | error_message = "Invalid f0 code"; |
---|
| 573 | if (line_num>0) |
---|
| 574 | error_message += SString::sprintf(", line #%d", line_num); |
---|
| 575 | error_message += nameForErrors(); |
---|
| 576 | logPrintf("Model", "build", LOG_ERROR, "%s", error_message.c_str()); |
---|
[495] | 577 | } |
---|
[522] | 578 | return result; |
---|
[495] | 579 | } |
---|
| 580 | |
---|
[522] | 581 | int Model::singleStepBuildNoLog(const SString &line, SString& error_message, const MultiRange* srcrange) |
---|
[495] | 582 | { |
---|
[522] | 583 | error_message = SString::empty(); |
---|
| 584 | int pos = 0; const char*t = line.c_str(); |
---|
| 585 | for (; *t; t++, pos++) |
---|
| 586 | if (!strchr(" \r\t", *t)) break; |
---|
| 587 | if (*t == '#') return 0; |
---|
| 588 | if (!*t) return 0; |
---|
| 589 | if (!strncmp(t, "p:", 2)) |
---|
[109] | 590 | { |
---|
[522] | 591 | Param partparam(f0_part_paramtab); |
---|
| 592 | Part *p = new Part(); |
---|
| 593 | partparam.select(p); |
---|
| 594 | pos += 2; |
---|
| 595 | if (partparam.load2(line, pos) & ParamInterface::LOAD2_PARSE_FAILED) { delete p; error_message = "Invalid 'p:'"; return -1; } |
---|
| 596 | p->o.rotate(p->rot); |
---|
| 597 | parts += p; |
---|
| 598 | p->owner = this; |
---|
| 599 | if (srcrange) p->setMapping(*srcrange); |
---|
| 600 | return getPartCount() - 1; |
---|
[109] | 601 | } |
---|
[522] | 602 | if (!strncmp(t, "m:", 2)) |
---|
[109] | 603 | { |
---|
[522] | 604 | Param modelparam(f0_model_paramtab); |
---|
| 605 | modelparam.select(this); |
---|
| 606 | pos += 2; |
---|
| 607 | if (modelparam.load2(line, pos) & ParamInterface::LOAD2_PARSE_FAILED) { error_message = "Invalid 'm:'"; return -1; } |
---|
| 608 | return 0; |
---|
[109] | 609 | } |
---|
[522] | 610 | else if (!strncmp(t, "j:", 2)) |
---|
[109] | 611 | { |
---|
[522] | 612 | Param jointparam(f0_joint_paramtab); |
---|
| 613 | Joint *j = new Joint(); |
---|
| 614 | jointparam.select(j); |
---|
| 615 | pos += 2; |
---|
| 616 | j->owner = this; |
---|
| 617 | if (jointparam.load2(line, pos) & ParamInterface::LOAD2_PARSE_FAILED) { delete j; error_message = "Invalid 'j:'"; return -1; } |
---|
| 618 | bool p1_ok = false, p2_ok = false; |
---|
| 619 | if ((p1_ok = ((j->p1_refno >= 0) && (j->p1_refno < getPartCount()))) && |
---|
| 620 | (p2_ok = ((j->p2_refno >= 0) && (j->p2_refno < getPartCount())))) |
---|
[109] | 621 | { |
---|
[522] | 622 | addJoint(j); |
---|
| 623 | if ((j->d.x != JOINT_DELTA_MARKER) || (j->d.y != JOINT_DELTA_MARKER) || (j->d.z != JOINT_DELTA_MARKER)) |
---|
[114] | 624 | { |
---|
[522] | 625 | j->useDelta(1); |
---|
| 626 | j->resetDeltaMarkers(); |
---|
[114] | 627 | } |
---|
[522] | 628 | j->attachToParts(j->p1_refno, j->p2_refno); |
---|
| 629 | if (srcrange) j->setMapping(*srcrange); |
---|
| 630 | return j->refno; |
---|
[109] | 631 | } |
---|
[522] | 632 | else |
---|
[109] | 633 | { |
---|
[522] | 634 | error_message = SString::sprintf("Invalid reference to Part #%d", p1_ok ? j->p1_refno : j->p2_refno); |
---|
| 635 | delete j; |
---|
| 636 | return -1; |
---|
[109] | 637 | } |
---|
| 638 | } |
---|
[522] | 639 | else if (!strncmp(t, "n:", 2)) // neuro (or the old neuro object as the special case) |
---|
[109] | 640 | { |
---|
[522] | 641 | Param neuroparam(f0_neuro_paramtab); |
---|
| 642 | Neuro *nu = new Neuro(); |
---|
| 643 | neuroparam.select(nu); |
---|
| 644 | pos += 2; |
---|
| 645 | if (neuroparam.load2(line, pos) & ParamInterface::LOAD2_PARSE_FAILED) { delete nu; error_message = "Invalid 'n:'"; return -1; } |
---|
[109] | 646 | #ifdef MODEL_V1_COMPATIBLE |
---|
[522] | 647 | if (nu->neuro_refno>=0) // parent specified... |
---|
[109] | 648 | { |
---|
[522] | 649 | if (nu->neuro_refno >= getNeuroCount()) // and it's illegal |
---|
[109] | 650 | { |
---|
[522] | 651 | delete nu; |
---|
| 652 | return -1; |
---|
[109] | 653 | } |
---|
[522] | 654 | Neuro *parentNU=getNeuro(nu->neuro_refno); |
---|
| 655 | parentNU->addInput(nu,nu->weight); |
---|
| 656 | // default class for parented units: n-n link |
---|
| 657 | //if (nu->moredata.len()==0) nu->moredata="-"; |
---|
[109] | 658 | } |
---|
[522] | 659 | else |
---|
[109] | 660 | #endif |
---|
| 661 | { |
---|
[522] | 662 | // default class for unparented units: standard neuron |
---|
| 663 | if (nu->getClassName().len() == 0) nu->setClassName("N"); |
---|
[109] | 664 | } |
---|
[522] | 665 | /* |
---|
| 666 | if (nu->conn_refno>=0) // input specified... |
---|
[109] | 667 | { |
---|
[522] | 668 | if (nu->conn_refno >= getNeuroCount()) // and it's illegal |
---|
| 669 | { |
---|
[109] | 670 | delete nu; |
---|
| 671 | return -1; |
---|
| 672 | } |
---|
[522] | 673 | Neuro *inputNU=getNeuro(nu->conn_refno); |
---|
| 674 | nu->addInput(inputNU,nu->weight); |
---|
| 675 | } |
---|
| 676 | */ |
---|
[109] | 677 | #ifdef MODEL_V1_COMPATIBLE |
---|
[522] | 678 | nu->weight=1.0; |
---|
[109] | 679 | #endif |
---|
[522] | 680 | nu->owner = this; |
---|
| 681 | // attach to part/joint |
---|
| 682 | if (nu->part_refno >= 0) |
---|
| 683 | nu->attachToPart(nu->part_refno); |
---|
| 684 | if (nu->joint_refno >= 0) |
---|
| 685 | nu->attachToJoint(nu->joint_refno); |
---|
| 686 | if (srcrange) nu->setMapping(*srcrange); |
---|
| 687 | // todo: check part/joint ref# |
---|
[109] | 688 | #ifdef MODEL_V1_COMPATIBLE |
---|
[522] | 689 | if (hasOldNeuroLayout()) |
---|
[109] | 690 | { |
---|
[522] | 691 | int count=old_getNeuroCount(); |
---|
| 692 | neurons.insert(count,nu); |
---|
| 693 | oldneurocount=count+1; |
---|
| 694 | return oldneurocount-1; |
---|
[109] | 695 | } |
---|
[522] | 696 | else |
---|
[109] | 697 | #endif |
---|
| 698 | { |
---|
[522] | 699 | neurons += nu; |
---|
| 700 | return neurons.size() - 1; |
---|
[109] | 701 | } |
---|
| 702 | } |
---|
[522] | 703 | else if (!strncmp(t, "c:", 2)) // add input |
---|
[109] | 704 | { |
---|
[522] | 705 | Param ncparam(f0_neuroconn_paramtab); |
---|
| 706 | NeuroConn c; |
---|
| 707 | ncparam.select(&c); |
---|
| 708 | pos += 2; |
---|
| 709 | if (ncparam.load2(line, pos) & ParamInterface::LOAD2_PARSE_FAILED) { error_message = "Invalid 'c:'"; return -1; } |
---|
| 710 | bool n1_ok = false, n2_ok = false; |
---|
| 711 | if ((n1_ok = ((c.n1_refno >= 0) && (c.n1_refno < getNeuroCount()))) |
---|
| 712 | && (n2_ok = ((c.n2_refno >= 0) && (c.n2_refno < getNeuroCount())))) |
---|
[109] | 713 | { |
---|
[522] | 714 | Neuro *na = getNeuro(c.n1_refno); |
---|
| 715 | Neuro *nb = getNeuro(c.n2_refno); |
---|
| 716 | na->addInput(nb, c.weight, &c.info); |
---|
| 717 | if (srcrange) |
---|
| 718 | na->addMapping(*srcrange); |
---|
| 719 | return 0; |
---|
[109] | 720 | } |
---|
[522] | 721 | error_message = SString::sprintf("Invalid reference to Neuro #%d", n1_ok ? c.n2_refno : c.n1_refno); |
---|
| 722 | return -1; |
---|
[109] | 723 | } |
---|
| 724 | #ifdef MODEL_V1_COMPATIBLE |
---|
[522] | 725 | else if (!strncmp(t,"ni:",3)) // old neuroitem |
---|
[109] | 726 | { |
---|
[522] | 727 | // we always use old layout for "ni:" |
---|
| 728 | Param neuroitemparam(f0_neuroitem_paramtab); |
---|
| 729 | Neuro *nu=new Neuro(); |
---|
| 730 | neuroitemparam.select(nu); |
---|
| 731 | pos+=3; |
---|
| 732 | if (neuroitemparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) {delete nu; return -1;} |
---|
| 733 | // illegal parent? |
---|
| 734 | if ((nu->neuro_refno<0)||(nu->neuro_refno>=old_getNeuroCount())) |
---|
[109] | 735 | { |
---|
[522] | 736 | delete nu; |
---|
| 737 | return -1; |
---|
[109] | 738 | } |
---|
[522] | 739 | Neuro *parentN=getNeuro(nu->neuro_refno); |
---|
| 740 | // copy part/joint refno from parent, if possible |
---|
| 741 | if ((nu->part_refno<0)&&(parentN->part_refno>=0)) |
---|
| 742 | nu->part_refno=parentN->part_refno; |
---|
| 743 | if ((nu->joint_refno<0)&&(parentN->joint_refno>=0)) |
---|
| 744 | nu->joint_refno=parentN->joint_refno; |
---|
| 745 | nu->owner=this; |
---|
| 746 | // attach to part/joint |
---|
| 747 | if (nu->part_refno>=0) |
---|
| 748 | nu->attachToPart(nu->part_refno); |
---|
| 749 | if (nu->joint_refno>=0) |
---|
| 750 | nu->attachToJoint(nu->joint_refno); |
---|
| 751 | if (srcrange) |
---|
| 752 | nu->setMapping(*srcrange); |
---|
| 753 | // special case: old muscles |
---|
| 754 | // PARENT neuron will be set up to be the CHILD of the current one (!) |
---|
| 755 | if (nu->isOldEffector()) |
---|
[109] | 756 | { |
---|
[522] | 757 | nu->neuro_refno=parentN->refno; |
---|
| 758 | neurons+=nu; |
---|
| 759 | nu->owner=this; |
---|
| 760 | nu->addInput(parentN,nu->weight); // (!) |
---|
| 761 | nu->weight=1.0; |
---|
| 762 | parentN->invalidateOldItems(); |
---|
| 763 | return 0; // !!! -> ...getItemCount()-1; |
---|
| 764 | } |
---|
| 765 | parentN->addInput(nu,nu->weight); |
---|
[109] | 766 | neurons+=nu; |
---|
| 767 | parentN->invalidateOldItems(); |
---|
[522] | 768 | if (nu->getClassName().len()==0) |
---|
[109] | 769 | { |
---|
[522] | 770 | nu->setClassName("-"); |
---|
| 771 | // for compatibility, "ni" can define a n-n connection |
---|
| 772 | // referring to non-existent neuron (which will be hopefully defined later) |
---|
| 773 | // internal check will add the proper input to this unit |
---|
| 774 | // if conn_refno >=0 and input count==0 |
---|
| 775 | oldconnections=1; |
---|
| 776 | if (srcrange) |
---|
| 777 | parentN->addMapping(*srcrange); |
---|
[109] | 778 | } |
---|
[522] | 779 | else |
---|
| 780 | nu->weight=1.0; |
---|
| 781 | return 0; // !!! -> ...getItemCount()-1; |
---|
[109] | 782 | } |
---|
| 783 | #endif |
---|
[522] | 784 | else return -1; |
---|
[109] | 785 | } |
---|
| 786 | |
---|
| 787 | #ifdef MODEL_V1_COMPATIBLE |
---|
| 788 | int Model::addOldConnectionsInputs() |
---|
| 789 | { |
---|
[522] | 790 | if (!oldconnections) return 1; |
---|
| 791 | Neuro* n; |
---|
| 792 | for (int i=0;i<neurons.size();i++) |
---|
[109] | 793 | { |
---|
[522] | 794 | n=(Neuro*)neurons(i); |
---|
| 795 | if (n->conn_refno>=0) |
---|
| 796 | if (n->isNNConnection()) |
---|
| 797 | if (n->conn_refno < old_getNeuroCount()) |
---|
[109] | 798 | { // good reference |
---|
[522] | 799 | Neuro* parent=n->parent; // nn connection has exactly one parent |
---|
| 800 | int inp=parent->findInput(n); |
---|
| 801 | Neuro* target=getNeuro(n->conn_refno); |
---|
| 802 | parent->setInput(inp,target,n->weight); |
---|
| 803 | removeNeuro(i,0); // no need to remove references |
---|
| 804 | i--; |
---|
[109] | 805 | } |
---|
[522] | 806 | else |
---|
[109] | 807 | { |
---|
[522] | 808 | logPrintf("Model","internalCheck",LOG_ERROR, |
---|
| 809 | "illegal N-N connection #%d (reference to #%d)%s", |
---|
| 810 | i,n->conn_refno,nameForErrors().c_str()); |
---|
| 811 | return 0; |
---|
[109] | 812 | } |
---|
| 813 | } |
---|
[522] | 814 | oldconnections=0; |
---|
| 815 | return 1; |
---|
[109] | 816 | } |
---|
| 817 | #endif |
---|
| 818 | |
---|
| 819 | ///////////// |
---|
| 820 | |
---|
[522] | 821 | /** change the sequence of neuro units |
---|
| 822 | and fix references in "-" objects (n-n connections) */ |
---|
| 823 | void Model::moveNeuro(int oldpos, int newpos) |
---|
[109] | 824 | { |
---|
[522] | 825 | if (oldpos == newpos) return; // nop! |
---|
| 826 | Neuro *n = getNeuro(oldpos); |
---|
| 827 | neurons -= oldpos; |
---|
| 828 | neurons.insert(newpos, n); |
---|
| 829 | // conn_refno could be broken -> fix it |
---|
[109] | 830 | #ifdef MODEL_V1_COMPATIBLE |
---|
[522] | 831 | for (int i=0;i<neurons.size();i++) |
---|
[109] | 832 | { |
---|
[522] | 833 | Neuro *n2=getNeuro(i); |
---|
| 834 | if (n2->isNNConnection()) |
---|
| 835 | if (n2->conn_refno == oldpos) n2->conn_refno=newpos; |
---|
| 836 | else |
---|
| 837 | { if (n2->conn_refno > oldpos) n2->conn_refno--; |
---|
| 838 | if (n2->conn_refno >= newpos) n2->conn_refno++; } |
---|
[109] | 839 | } |
---|
[522] | 840 | invalidateOldNeuroCount(); |
---|
[109] | 841 | #endif |
---|
| 842 | } |
---|
| 843 | |
---|
| 844 | #ifdef MODEL_V1_COMPATIBLE |
---|
| 845 | /** move all old neurons (class "N") to the front of the neurons list. |
---|
[522] | 846 | @return number of old neurons |
---|
| 847 | */ |
---|
[109] | 848 | int Model::reorderToOldLayout() |
---|
| 849 | { |
---|
[522] | 850 | Neuro *n; |
---|
| 851 | int neurocount=0; |
---|
| 852 | for (int i=0;i<neurons.size();i++) |
---|
[109] | 853 | { |
---|
[522] | 854 | n=(Neuro*)neurons(i); |
---|
| 855 | if (n->isOldNeuron()) |
---|
[109] | 856 | { |
---|
[522] | 857 | moveNeuro(i,neurocount); |
---|
| 858 | neurocount++; |
---|
| 859 | i=neurocount-1; |
---|
[109] | 860 | } |
---|
| 861 | } |
---|
[522] | 862 | return neurocount; |
---|
[109] | 863 | } |
---|
| 864 | #endif |
---|
| 865 | //////////// |
---|
| 866 | |
---|
| 867 | void Model::updateNeuroRefno() |
---|
| 868 | { |
---|
[522] | 869 | for (int i = 0; i < neurons.size(); i++) |
---|
[109] | 870 | { |
---|
[522] | 871 | Neuro* n = (Neuro*)neurons(i); |
---|
| 872 | n->refno = i; |
---|
[109] | 873 | } |
---|
| 874 | } |
---|
| 875 | |
---|
| 876 | #define VALIDMINMAX(var,template,field) \ |
---|
| 877 | if (var -> field < getMin ## template () . field) \ |
---|
| 878 | { var->field= getMin ## template () . field; \ |
---|
[495] | 879 | logPrintf("Model","internalCheck",LOG_WARN,# field " too small in " # template " #%d (adjusted)",i);} \ |
---|
[109] | 880 | else if (var -> field > getMax ## template () . field) \ |
---|
| 881 | { var->field= getMax ## template () . field; \ |
---|
[495] | 882 | logPrintf("Model","internalCheck",LOG_WARN,# field " too big in " # template " #%d (adjusted)",i);} |
---|
[109] | 883 | |
---|
| 884 | #define LINKFLAG 0x8000000 |
---|
| 885 | |
---|
| 886 | void Model::updateRefno() |
---|
| 887 | { |
---|
[522] | 888 | int i; |
---|
| 889 | for (i = 0; i < getPartCount(); i++) getPart(i)->refno = i; |
---|
| 890 | for (i = 0; i < getJointCount(); i++) getJoint(i)->refno = i; |
---|
| 891 | for (i = 0; i < getNeuroCount(); i++) getNeuro(i)->refno = i; |
---|
[109] | 892 | } |
---|
| 893 | |
---|
[495] | 894 | SString Model::nameForErrors() const |
---|
| 895 | { |
---|
[522] | 896 | if (geno.getName().len()>0) |
---|
| 897 | return SString::sprintf(" in '%s'", geno.getName().c_str()); |
---|
| 898 | return SString::empty(); |
---|
[495] | 899 | } |
---|
| 900 | |
---|
[109] | 901 | int Model::internalcheck(int final) |
---|
| 902 | { |
---|
[522] | 903 | Part *p; |
---|
| 904 | Joint *j; |
---|
| 905 | Neuro *n; |
---|
| 906 | int i, k; |
---|
| 907 | int ret = 1; |
---|
| 908 | shape = SHAPE_UNKNOWN; |
---|
| 909 | if ((parts.size() == 0) && (neurons.size() == 0)) return 0; |
---|
| 910 | if (parts.size() == 0) |
---|
| 911 | size = Pt3D_0; |
---|
| 912 | else |
---|
[109] | 913 | { |
---|
[522] | 914 | Pt3D bbmin = ((Part*)parts(0))->p, bbmax = bbmin; |
---|
| 915 | for (i = 0; i < parts.size(); i++) |
---|
[165] | 916 | { |
---|
[522] | 917 | p = (Part*)parts(i); |
---|
| 918 | p->owner = this; |
---|
| 919 | p->refno = i; |
---|
| 920 | if (p->shape == 0) |
---|
[269] | 921 | { |
---|
[522] | 922 | if (checklevel > 0) |
---|
| 923 | p->mass = 0.0; |
---|
[269] | 924 | } |
---|
[528] | 925 | //VALIDMINMAX(p,part,mass);//mass is very special |
---|
| 926 | // VALIDMINMAX are managed manually when adding part properties in f0-def! |
---|
| 927 | // (could be made dynamic but not really worth the effort) |
---|
[522] | 928 | VALIDMINMAX(p, Part, size); |
---|
[528] | 929 | VALIDMINMAX(p, Part, scale.x); |
---|
| 930 | VALIDMINMAX(p, Part, scale.y); |
---|
| 931 | VALIDMINMAX(p, Part, scale.z); |
---|
| 932 | VALIDMINMAX(p, Part, hollow); |
---|
[522] | 933 | VALIDMINMAX(p, Part, density); |
---|
| 934 | VALIDMINMAX(p, Part, friction); |
---|
| 935 | VALIDMINMAX(p, Part, ingest); |
---|
| 936 | VALIDMINMAX(p, Part, assim); |
---|
[528] | 937 | VALIDMINMAX(p, Part, vsize); |
---|
| 938 | VALIDMINMAX(p, Part, vcolor.x); |
---|
| 939 | VALIDMINMAX(p, Part, vcolor.y); |
---|
| 940 | VALIDMINMAX(p, Part, vcolor.z); |
---|
[522] | 941 | p->flags &= ~LINKFLAG; // for delta joint cycle detection |
---|
| 942 | if (p->p.x - p->size < bbmin.x) bbmin.x = p->p.x - p->size; |
---|
| 943 | if (p->p.y - p->size < bbmin.y) bbmin.y = p->p.y - p->size; |
---|
| 944 | if (p->p.z - p->size < bbmin.z) bbmin.z = p->p.z - p->size; |
---|
| 945 | if (p->p.x + p->size > bbmax.x) bbmax.x = p->p.x + p->size; |
---|
| 946 | if (p->p.y + p->size > bbmax.y) bbmax.y = p->p.y + p->size; |
---|
| 947 | if (p->p.z + p->size > bbmax.z) bbmax.z = p->p.z + p->size; |
---|
| 948 | if (shape == SHAPE_UNKNOWN) |
---|
| 949 | shape = (p->shape == Part::SHAPE_DEFAULT) ? SHAPE_OLD : SHAPE_NEW; |
---|
| 950 | else if (shape != SHAPE_ILLEGAL) |
---|
| 951 | { |
---|
| 952 | if ((p->shape == Part::SHAPE_DEFAULT) ^ (shape == SHAPE_OLD)) |
---|
| 953 | { |
---|
| 954 | shape = SHAPE_ILLEGAL; |
---|
| 955 | logPrintf("Model", "internalCheck", LOG_WARN, "Inconsistent part shapes (mixed old and new shapes)%s", nameForErrors().c_str()); |
---|
| 956 | } |
---|
| 957 | } |
---|
[269] | 958 | } |
---|
[522] | 959 | size = bbmax - bbmin; |
---|
| 960 | for (i = 0; i < joints.size(); i++) |
---|
[109] | 961 | { |
---|
[522] | 962 | j = (Joint*)joints(i); |
---|
[528] | 963 | // VALIDMINMAX are managed manually when adding joint properties in f0-def! |
---|
| 964 | // (could be made dynamic but not really worth the effort) |
---|
[522] | 965 | VALIDMINMAX(j, Joint, stamina); |
---|
| 966 | VALIDMINMAX(j, Joint, stif); |
---|
| 967 | VALIDMINMAX(j, Joint, rotstif); |
---|
[528] | 968 | VALIDMINMAX(p, Part, vcolor.x); |
---|
| 969 | VALIDMINMAX(p, Part, vcolor.y); |
---|
| 970 | VALIDMINMAX(p, Part, vcolor.z); |
---|
[522] | 971 | j->refno = i; |
---|
| 972 | j->owner = this; |
---|
| 973 | if (j->part1 && j->part2 && (j->part1 != j->part2)) |
---|
[109] | 974 | { |
---|
[522] | 975 | j->p1_refno = j->part1->refno; |
---|
| 976 | j->p2_refno = j->part2->refno; |
---|
| 977 | if (checklevel > 0) |
---|
[109] | 978 | { |
---|
[522] | 979 | if (j->part1->shape == 0) |
---|
| 980 | j->part1->mass += 1.0; |
---|
| 981 | if (j->part2->shape == 0) |
---|
| 982 | j->part2->mass += 1.0; |
---|
[109] | 983 | } |
---|
[522] | 984 | if ((j->usedelta) && ((j->d.x != JOINT_DELTA_MARKER) || (j->d.y != JOINT_DELTA_MARKER) || (j->d.z != JOINT_DELTA_MARKER))) |
---|
| 985 | { // delta positioning -> calc. orient. |
---|
| 986 | if (j->part2->flags & LINKFLAG) |
---|
| 987 | { |
---|
| 988 | ret = 0; |
---|
| 989 | logPrintf("Model", "internalCheck", LOG_ERROR, |
---|
| 990 | "Delta joint cycle detected at Joint #%d%s", |
---|
| 991 | i, nameForErrors().c_str()); |
---|
| 992 | } |
---|
| 993 | j->resetDeltaMarkers(); |
---|
| 994 | j->o = j->rot; |
---|
| 995 | j->part1->o.transform(j->part2->o, j->o); |
---|
| 996 | // j->part2->o.x=j->part1->o/j->o.x; |
---|
| 997 | // j->part2->o.y=j->part1->o/j->o.y; |
---|
| 998 | // j->part2->o.z=j->part1->o/j->o.z; |
---|
| 999 | j->part2->p = j->part2->o.transform(j->d) + j->part1->p; |
---|
| 1000 | j->part2->flags |= LINKFLAG; j->part1->flags |= LINKFLAG; // for delta joint cycle detection |
---|
| 1001 | } |
---|
| 1002 | else |
---|
| 1003 | { // abs.positioning -> calc. delta |
---|
| 1004 | if (final) |
---|
| 1005 | { |
---|
| 1006 | // calc orient delta |
---|
| 1007 | // Orient tmpo(j->part2->o); |
---|
| 1008 | // tmpo*=j->part1->o; |
---|
| 1009 | Orient tmpo; |
---|
| 1010 | j->part1->o.revTransform(tmpo, j->part2->o); |
---|
| 1011 | tmpo.getAngles(j->rot); |
---|
| 1012 | j->o = j->rot; |
---|
| 1013 | // calc position delta |
---|
| 1014 | Pt3D tmpp(j->part2->p); |
---|
| 1015 | tmpp -= j->part1->p; |
---|
| 1016 | j->d = j->part2->o.revTransform(tmpp); |
---|
| 1017 | } |
---|
| 1018 | } |
---|
| 1019 | if (final) |
---|
| 1020 | { |
---|
| 1021 | if (j->shape != Joint::SHAPE_SOLID) |
---|
| 1022 | { |
---|
| 1023 | if (j->d() > getMaxJoint().d.x) |
---|
| 1024 | { |
---|
| 1025 | ret = 0; |
---|
| 1026 | logPrintf("Model", "internalCheck", LOG_ERROR, "Joint #%d too long%s", i, nameForErrors().c_str()); |
---|
| 1027 | } |
---|
| 1028 | } |
---|
| 1029 | } |
---|
[109] | 1030 | } |
---|
[522] | 1031 | else |
---|
[109] | 1032 | { |
---|
[522] | 1033 | logPrintf("Model", "internalCheck", LOG_ERROR, "Illegal part references in Joint #%d%s", i, nameForErrors().c_str()); |
---|
| 1034 | ret = 0; |
---|
[109] | 1035 | } |
---|
[522] | 1036 | if (shape != SHAPE_ILLEGAL) |
---|
[109] | 1037 | { |
---|
[522] | 1038 | if ((j->shape == Joint::SHAPE_DEFAULT) ^ (shape == SHAPE_OLD)) |
---|
[109] | 1039 | { |
---|
[522] | 1040 | shape = SHAPE_ILLEGAL; |
---|
| 1041 | logPrintf("Model", "internalCheck", LOG_WARN, "Inconsistent joint shapes (mixed old and new shapes)%s", nameForErrors().c_str()); |
---|
[109] | 1042 | } |
---|
| 1043 | } |
---|
| 1044 | } |
---|
| 1045 | } |
---|
| 1046 | #ifdef MODEL_V1_COMPATIBLE |
---|
[522] | 1047 | if (!addOldConnectionsInputs()) |
---|
| 1048 | return 0; |
---|
[109] | 1049 | #endif |
---|
| 1050 | |
---|
[522] | 1051 | updateNeuroRefno(); // valid refno is important for n-n connections check (later) |
---|
[109] | 1052 | |
---|
[522] | 1053 | for (i = 0; i < neurons.size(); i++) |
---|
[109] | 1054 | { |
---|
[522] | 1055 | n = (Neuro*)neurons(i); |
---|
[109] | 1056 | #ifdef MODEL_V1_COMPATIBLE |
---|
[522] | 1057 | VALIDMINMAX(n,Neuro,inertia); |
---|
| 1058 | VALIDMINMAX(n,Neuro,force); |
---|
| 1059 | VALIDMINMAX(n,Neuro,sigmo); |
---|
| 1060 | n->conn_refno=-1; |
---|
| 1061 | n->weight=1.0; |
---|
| 1062 | n->neuro_refno=-1; |
---|
[109] | 1063 | #endif |
---|
[522] | 1064 | n->part_refno = (n->part) ? n->part->refno : -1; |
---|
| 1065 | n->joint_refno = (n->joint) ? n->joint->refno : -1; |
---|
[109] | 1066 | } |
---|
| 1067 | |
---|
[522] | 1068 | if (parts.size() && (checklevel > 0)) |
---|
[109] | 1069 | { |
---|
[522] | 1070 | for (i = 0; i < parts.size(); i++) |
---|
[109] | 1071 | { |
---|
[522] | 1072 | p = (Part*)parts(i); |
---|
| 1073 | if (p->shape == 0) |
---|
| 1074 | if (p->mass <= 0.001) |
---|
| 1075 | p->mass = 1.0; |
---|
| 1076 | p->flags &= ~LINKFLAG; |
---|
[109] | 1077 | } |
---|
[522] | 1078 | getPart(0)->flags |= LINKFLAG; |
---|
| 1079 | int change = 1; |
---|
| 1080 | while (change) |
---|
[109] | 1081 | { |
---|
[522] | 1082 | change = 0; |
---|
| 1083 | for (i = 0; i < joints.size(); i++) |
---|
[109] | 1084 | { |
---|
[522] | 1085 | j = (Joint*)joints(i); |
---|
| 1086 | if (j->part1->flags&LINKFLAG) |
---|
[109] | 1087 | { |
---|
[522] | 1088 | if (!(j->part2->flags&LINKFLAG)) |
---|
[109] | 1089 | { |
---|
[522] | 1090 | change = 1; |
---|
| 1091 | j->part2->flags |= LINKFLAG; |
---|
[109] | 1092 | } |
---|
| 1093 | } |
---|
[522] | 1094 | else |
---|
| 1095 | if (j->part2->flags&LINKFLAG) |
---|
[109] | 1096 | { |
---|
[522] | 1097 | if (!(j->part1->flags&LINKFLAG)) |
---|
| 1098 | { |
---|
| 1099 | change = 1; |
---|
| 1100 | j->part1->flags |= LINKFLAG; |
---|
[109] | 1101 | } |
---|
[522] | 1102 | } |
---|
[109] | 1103 | } |
---|
| 1104 | } |
---|
[522] | 1105 | for (i = 0; i < parts.size(); i++) |
---|
[109] | 1106 | { |
---|
[522] | 1107 | p = (Part*)parts(i); |
---|
| 1108 | if (!(p->flags&LINKFLAG)) |
---|
[109] | 1109 | { |
---|
[522] | 1110 | logPrintf("Model", "internalCheck", LOG_ERROR, "Not all parts connected (eg. Part #0 and Part #%d)%s", i, nameForErrors().c_str()); |
---|
| 1111 | ret = 0; |
---|
| 1112 | break; |
---|
[109] | 1113 | } |
---|
| 1114 | } |
---|
| 1115 | } |
---|
| 1116 | |
---|
[522] | 1117 | for (i = 0; i < joints.size(); i++) |
---|
[109] | 1118 | { |
---|
[522] | 1119 | j = (Joint*)joints(i); |
---|
| 1120 | if (j->p1_refno == j->p2_refno) |
---|
[109] | 1121 | { |
---|
[522] | 1122 | logPrintf("Model", "internalCheck", LOG_ERROR, "Illegal self connection, Joint #%d%s", i, nameForErrors().c_str()); |
---|
| 1123 | ret = 0; |
---|
| 1124 | break; |
---|
[109] | 1125 | } |
---|
[522] | 1126 | for (k = i + 1; k < joints.size(); k++) |
---|
[109] | 1127 | { |
---|
[522] | 1128 | Joint* j2 = (Joint*)joints(k); |
---|
| 1129 | if (((j->p1_refno == j2->p1_refno) && (j->p2_refno == j2->p2_refno)) |
---|
| 1130 | || ((j->p1_refno == j2->p2_refno) && (j->p2_refno == j2->p1_refno))) |
---|
[109] | 1131 | { |
---|
[522] | 1132 | logPrintf("Model", "internalCheck", LOG_ERROR, "Illegal duplicate Joint #%d and Joint #%d%s", i, k, nameForErrors().c_str()); |
---|
| 1133 | ret = 0; |
---|
| 1134 | break; |
---|
[109] | 1135 | } |
---|
| 1136 | } |
---|
| 1137 | } |
---|
[522] | 1138 | if (shape == SHAPE_ILLEGAL) |
---|
| 1139 | ret = 0; |
---|
| 1140 | return ret; |
---|
[109] | 1141 | } |
---|
| 1142 | |
---|
| 1143 | ///////////// |
---|
| 1144 | |
---|
| 1145 | int Model::getErrorPosition(bool includingwarnings) |
---|
| 1146 | { |
---|
[522] | 1147 | return includingwarnings ? |
---|
| 1148 | ((f0errorposition >= 0) ? f0errorposition : f0warnposition) |
---|
| 1149 | : |
---|
| 1150 | f0errorposition; |
---|
[109] | 1151 | } |
---|
| 1152 | |
---|
| 1153 | const Geno& Model::getGeno() const |
---|
| 1154 | { |
---|
[522] | 1155 | return geno; |
---|
[109] | 1156 | } |
---|
| 1157 | |
---|
| 1158 | const Geno Model::getF0Geno() |
---|
| 1159 | { |
---|
[522] | 1160 | if (buildstatus == building) |
---|
| 1161 | logPrintf("Model", "getGeno", LOG_WARN, "Model was not completed - missing close()"); |
---|
| 1162 | if (buildstatus != valid) |
---|
| 1163 | return Geno("", '0', "", "invalid"); |
---|
| 1164 | if (!f0genoknown) |
---|
[109] | 1165 | { |
---|
[522] | 1166 | if (autobuildmaps) |
---|
[109] | 1167 | { |
---|
[522] | 1168 | initF0Map(); |
---|
| 1169 | makeGeno(f0geno, f0map); |
---|
[109] | 1170 | } |
---|
[522] | 1171 | else |
---|
[109] | 1172 | { |
---|
[522] | 1173 | delF0Map(); |
---|
| 1174 | makeGeno(f0geno); |
---|
[109] | 1175 | } |
---|
[522] | 1176 | f0genoknown = 1; |
---|
[109] | 1177 | } |
---|
[522] | 1178 | return f0geno; |
---|
[109] | 1179 | } |
---|
| 1180 | |
---|
| 1181 | int Model::getPartCount() const |
---|
| 1182 | { |
---|
[522] | 1183 | return parts.size(); |
---|
[109] | 1184 | } |
---|
| 1185 | |
---|
| 1186 | Part* Model::getPart(int i) const |
---|
| 1187 | { |
---|
[522] | 1188 | return ((Part*)parts(i)); |
---|
[109] | 1189 | } |
---|
| 1190 | |
---|
| 1191 | int Model::getJointCount() const |
---|
| 1192 | { |
---|
[522] | 1193 | return joints.size(); |
---|
[109] | 1194 | } |
---|
| 1195 | |
---|
| 1196 | Joint* Model::getJoint(int i) const |
---|
| 1197 | { |
---|
[522] | 1198 | return ((Joint*)joints(i)); |
---|
[109] | 1199 | } |
---|
| 1200 | |
---|
[522] | 1201 | int Model::findJoints(SList& result, const Part* part) |
---|
[109] | 1202 | { |
---|
[522] | 1203 | Joint *j; |
---|
| 1204 | int n0 = result.size(); |
---|
| 1205 | if (part) |
---|
| 1206 | for (int i = 0; j = (Joint*)joints(i); i++) |
---|
| 1207 | if ((j->part1 == part) || (j->part2 == part)) result += (void*)j; |
---|
| 1208 | return result.size() - n0; |
---|
[109] | 1209 | } |
---|
| 1210 | |
---|
| 1211 | int Model::findNeuro(Neuro* n) |
---|
[522] | 1212 | { |
---|
| 1213 | return neurons.find(n); |
---|
| 1214 | } |
---|
[109] | 1215 | |
---|
| 1216 | int Model::findPart(Part* p) |
---|
[522] | 1217 | { |
---|
| 1218 | return parts.find(p); |
---|
| 1219 | } |
---|
[109] | 1220 | |
---|
| 1221 | int Model::findJoint(Joint* j) |
---|
[522] | 1222 | { |
---|
| 1223 | return joints.find(j); |
---|
| 1224 | } |
---|
[109] | 1225 | |
---|
| 1226 | int Model::findJoint(Part *p1, Part *p2) |
---|
| 1227 | { |
---|
[522] | 1228 | Joint* j; |
---|
| 1229 | for (int i = 0; j = getJoint(i); i++) |
---|
| 1230 | if ((j->part1 == p1) && (j->part2 == p2)) return i; |
---|
| 1231 | return -1; |
---|
[109] | 1232 | } |
---|
| 1233 | |
---|
| 1234 | |
---|
| 1235 | //////////////////// |
---|
| 1236 | |
---|
| 1237 | #ifdef MODEL_V1_COMPATIBLE |
---|
| 1238 | void Model::calcOldNeuroCount() |
---|
| 1239 | { |
---|
[522] | 1240 | if (oldneurocount>=0) return; |
---|
| 1241 | oldneurocount=reorderToOldLayout(); |
---|
[109] | 1242 | } |
---|
| 1243 | |
---|
| 1244 | int Model::old_getNeuroCount() |
---|
| 1245 | { calcOldNeuroCount(); |
---|
[522] | 1246 | return oldneurocount;} |
---|
[109] | 1247 | |
---|
| 1248 | Neuro* Model::old_getNeuro(int i) |
---|
| 1249 | {calcOldNeuroCount(); |
---|
| 1250 | return (i<oldneurocount)? (Neuro*)getNeuro(i) : (Neuro*)0; |
---|
| 1251 | } |
---|
| 1252 | |
---|
| 1253 | int Model::old_findNeuro(Neuro* n) |
---|
| 1254 | {calcOldNeuroCount(); |
---|
| 1255 | return findNeuro(n);} |
---|
| 1256 | |
---|
| 1257 | Neuro *Model::old_addNewNeuro() |
---|
| 1258 | { |
---|
[522] | 1259 | int count=old_getNeuroCount(); |
---|
| 1260 | Neuro *nu=addNewNeuro(); |
---|
| 1261 | nu->setClassName("N"); |
---|
| 1262 | moveNeuro(nu->refno,oldneurocount); |
---|
| 1263 | oldneurocount=count+1; |
---|
| 1264 | return (Neuro*)nu; |
---|
[109] | 1265 | } |
---|
| 1266 | #endif |
---|
| 1267 | |
---|
| 1268 | /////////////////////// |
---|
| 1269 | |
---|
| 1270 | int Model::getNeuroCount() const |
---|
[522] | 1271 | { |
---|
| 1272 | return neurons.size(); |
---|
| 1273 | } |
---|
[109] | 1274 | |
---|
| 1275 | Neuro* Model::getNeuro(int i) const |
---|
[522] | 1276 | { |
---|
| 1277 | return (Neuro*)neurons(i); |
---|
| 1278 | } |
---|
[109] | 1279 | |
---|
| 1280 | int Model::getConnectionCount() const |
---|
| 1281 | { |
---|
[522] | 1282 | int n = 0; |
---|
| 1283 | for (int i = 0; i < getNeuroCount(); i++) |
---|
| 1284 | n += getNeuro(i)->getInputCount(); |
---|
| 1285 | return n; |
---|
[109] | 1286 | } |
---|
| 1287 | |
---|
| 1288 | int Model::findNeuros(SList& result, |
---|
[522] | 1289 | const char* classname, const Part* part, const Joint* joint) |
---|
[109] | 1290 | { |
---|
[522] | 1291 | Neuro *nu; |
---|
| 1292 | SString cn(classname); |
---|
| 1293 | int n0 = result.size(); |
---|
| 1294 | for (int i = 0; nu = (Neuro*)neurons(i); i++) |
---|
[109] | 1295 | { |
---|
[522] | 1296 | if (part) |
---|
| 1297 | if (nu->part != part) continue; |
---|
| 1298 | if (joint) |
---|
| 1299 | if (nu->joint != joint) continue; |
---|
| 1300 | if (classname) |
---|
| 1301 | if (nu->getClassName() != cn) continue; |
---|
| 1302 | result += (void*)nu; |
---|
[109] | 1303 | } |
---|
[522] | 1304 | return result.size() - n0; |
---|
[109] | 1305 | } |
---|
| 1306 | |
---|
| 1307 | /////////////////// |
---|
| 1308 | |
---|
| 1309 | void Model::disturb(double amount) |
---|
| 1310 | { |
---|
[522] | 1311 | int i; |
---|
| 1312 | if (amount <= 0) return; |
---|
| 1313 | for (i = 0; i < parts.size(); i++) |
---|
[109] | 1314 | { |
---|
[522] | 1315 | Part *p = getPart(i); |
---|
| 1316 | p->p.x += (rnd01 - 0.5)*amount; |
---|
| 1317 | p->p.y += (rnd01 - 0.5)*amount; |
---|
| 1318 | p->p.z += (rnd01 - 0.5)*amount; |
---|
[109] | 1319 | } |
---|
[522] | 1320 | for (i = 0; i < joints.size(); i++) |
---|
[109] | 1321 | { |
---|
[522] | 1322 | Joint *j = getJoint(i); |
---|
| 1323 | Pt3D tmpp(j->part2->p); |
---|
| 1324 | tmpp -= j->part1->p; |
---|
| 1325 | j->d = j->part2->o.revTransform(tmpp); |
---|
[109] | 1326 | } |
---|
| 1327 | } |
---|
| 1328 | |
---|
[274] | 1329 | void Model::move(const Pt3D& shift) |
---|
| 1330 | { |
---|
[522] | 1331 | FOREACH(Part*, p, parts) |
---|
| 1332 | p->p += shift; |
---|
[274] | 1333 | } |
---|
| 1334 | |
---|
| 1335 | void Model::rotate(const Orient& rotation) |
---|
| 1336 | { |
---|
[522] | 1337 | FOREACH(Part*, p, parts) |
---|
[274] | 1338 | { |
---|
[522] | 1339 | p->p = rotation.transform(p->p); |
---|
| 1340 | p->setOrient(rotation.transform(p->o)); |
---|
[274] | 1341 | } |
---|
| 1342 | } |
---|
| 1343 | |
---|
[269] | 1344 | void Model::buildUsingNewShapes(const Model& old, Part::Shape default_shape, float thickness) |
---|
| 1345 | { |
---|
[522] | 1346 | for (int i = 0; i < old.getJointCount(); i++) |
---|
[269] | 1347 | { |
---|
[522] | 1348 | Joint *oj = old.getJoint(i); |
---|
| 1349 | Part *p = addNewPart(default_shape); |
---|
| 1350 | p->p = (oj->part1->p + oj->part2->p) / 2; |
---|
| 1351 | Orient o; |
---|
| 1352 | o.lookAt(oj->part1->p - oj->part2->p); |
---|
| 1353 | p->rot = o.getAngles(); |
---|
| 1354 | p->scale.x = oj->part1->p.distanceTo(oj->part2->p) / 2; |
---|
| 1355 | p->scale.y = thickness; |
---|
| 1356 | p->scale.z = thickness; |
---|
[269] | 1357 | } |
---|
[522] | 1358 | for (int i = 0; i < old.getPartCount(); i++) |
---|
[269] | 1359 | { |
---|
[522] | 1360 | Part *op = old.getPart(i); |
---|
| 1361 | for (int j = 0; j < old.getJointCount(); j++) |
---|
[269] | 1362 | { |
---|
[522] | 1363 | Joint *oj = old.getJoint(j); |
---|
| 1364 | if ((oj->part1 == op) || (oj->part2 == op)) |
---|
[269] | 1365 | { |
---|
[522] | 1366 | for (int j2 = j + 1; j2 < old.getJointCount(); j2++) |
---|
[269] | 1367 | { |
---|
[522] | 1368 | Joint *oj2 = old.getJoint(j2); |
---|
| 1369 | if ((oj2->part1 == op) || (oj2->part2 == op)) |
---|
[269] | 1370 | { |
---|
[522] | 1371 | addNewJoint(getPart(j), getPart(j2), Joint::SHAPE_SOLID); |
---|
[269] | 1372 | } |
---|
| 1373 | } |
---|
[522] | 1374 | break; |
---|
[269] | 1375 | } |
---|
| 1376 | } |
---|
| 1377 | } |
---|
| 1378 | } |
---|
| 1379 | |
---|
[109] | 1380 | ////////////////////// |
---|
| 1381 | |
---|
[522] | 1382 | class MinPart : public Part { public: MinPart() { Param par(f0_part_paramtab, this); par.setMin(); } }; |
---|
| 1383 | class MaxPart : public Part { public: MaxPart() { Param par(f0_part_paramtab, this); par.setMax(); } }; |
---|
| 1384 | class MinJoint : public Joint { public: MinJoint() { Param par(f0_joint_paramtab, this); par.setMin(); } }; |
---|
| 1385 | class MaxJoint : public Joint { public: MaxJoint() { Param par(f0_joint_paramtab, this); par.setMax(); } }; |
---|
| 1386 | class MinNeuro : public Neuro { public: MinNeuro() { Param par(f0_neuro_paramtab, this); par.setMin(); } }; |
---|
| 1387 | class MaxNeuro : public Neuro { public: MaxNeuro() { Param par(f0_neuro_paramtab, this); par.setMax(); } }; |
---|
[109] | 1388 | |
---|
[522] | 1389 | Part& Model::getMinPart() { static MinPart part; return part; } |
---|
| 1390 | Part& Model::getMaxPart() { static MaxPart part; return part; } |
---|
| 1391 | Part& Model::getDefPart() { static Part part; return part; } |
---|
| 1392 | Joint& Model::getMinJoint() { static MinJoint joint; return joint; } |
---|
| 1393 | Joint& Model::getMaxJoint() { static MaxJoint joint; return joint; } |
---|
| 1394 | Joint& Model::getDefJoint() { static Joint joint; return joint; } |
---|
| 1395 | Neuro& Model::getMinNeuro() { static MinNeuro neuro; return neuro; } |
---|
| 1396 | Neuro& Model::getMaxNeuro() { static MaxNeuro neuro; return neuro; } |
---|
| 1397 | Neuro& Model::getDefNeuro() { static Neuro neuro; return neuro; } |
---|