Changeset 1017 for cpp/frams/genetics/fS/fS_general.cpp
- Timestamp:
- 07/20/20 16:37:38 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/fS/fS_general.cpp
r1006 r1017 16 16 int fS_Genotype::precision = 4; 17 17 bool fS_Genotype::TURN_WITH_ROTATION = false; 18 std::map<string, double> Node::minValues; 19 std::map<string, double> Node::defaultValues; 20 std::map<string, double> Node::maxValues; 18 21 19 22 void Node::prepareParams() 20 23 { 21 defaultValues = { 22 {INGESTION, Model::getDefPart().ingest}, 23 {FRICTION, Model::getDefPart().friction}, 24 {STIFFNESS, Model::getDefJoint().stif}, 25 {ROT_X, 0.0}, 26 {ROT_Y, 0.0}, 27 {ROT_Z, 0.0}, 28 {RX, 0.0}, 29 {RY, 0.0}, 30 {RZ, 0.0}, 31 {SIZE, 1.0}, 32 {SIZE_X, Model::getDefPart().scale.x}, 33 {SIZE_Y, Model::getDefPart().scale.y}, 34 {SIZE_Z, Model::getDefPart().scale.z} 35 }; 24 if(minValues.empty()) 25 { 26 minValues = { 27 {INGESTION, Model::getMinPart().ingest}, 28 {FRICTION, Model::getMinPart().friction}, 29 {ROT_X, -M_PI}, 30 {ROT_Y, -M_PI}, 31 {ROT_Z, -M_PI}, 32 {RX, -M_PI}, 33 {RY, -M_PI}, 34 {RZ, -M_PI}, 35 {SIZE, 0.01}, 36 {SIZE_X, Model::getMinPart().scale.x}, 37 {SIZE_Y, Model::getMinPart().scale.y}, 38 {SIZE_Z, Model::getMinPart().scale.z} 39 }; 40 } 41 42 if(maxValues.empty()) 43 { 44 maxValues = { 45 {INGESTION, Model::getMaxPart().ingest}, 46 {FRICTION, Model::getMaxPart().friction}, 47 {ROT_X, M_PI}, 48 {ROT_Y, M_PI}, 49 {ROT_Z, M_PI}, 50 {RX, M_PI}, 51 {RY, M_PI}, 52 {RZ, M_PI}, 53 {SIZE, 100.0}, 54 {SIZE_X, Model::getMaxPart().scale.x}, 55 {SIZE_Y, Model::getMaxPart().scale.y}, 56 {SIZE_Z, Model::getMaxPart().scale.z} 57 }; 58 } 59 if(defaultValues.empty()) 60 { 61 defaultValues = { 62 {INGESTION, Model::getDefPart().ingest}, 63 {FRICTION, Model::getDefPart().friction}, 64 {ROT_X, 0.0}, 65 {ROT_Y, 0.0}, 66 {ROT_Z, 0.0}, 67 {RX, 0.0}, 68 {RY, 0.0}, 69 {RZ, 0.0}, 70 {SIZE, 1.0}, 71 {SIZE_X, Model::getDefPart().scale.x}, 72 {SIZE_Y, Model::getDefPart().scale.y}, 73 {SIZE_Z, Model::getDefPart().scale.z} 74 }; 75 } 36 76 } 37 77 … … 58 98 fr = _state->fr; 59 99 s = _state->s; 60 stif = _state->stif;61 100 } 62 101 … … 259 298 if(paramsEndIndex == -1) 260 299 throw fS_Exception("Lacking param end sign", restOfGenotype.start); 300 261 301 for (int i = 0; i < int(separators.size()) - 1; i++) 262 302 { … … 297 337 } 298 338 299 double Node::getParam( stringkey)339 double Node::getParam(const string &key) 300 340 { 301 341 auto item = params.find(key); 302 342 if (item != params.end()) 303 343 return item->second; 304 else 305 return defaultValues.at(key); 306 } 307 308 309 void Node::getState(State *_state) 344 return defaultValues.at(key); 345 } 346 347 double Node::getParam(const string &key, double defaultValue) 348 { 349 auto item = params.find(key); 350 if (item != params.end()) 351 return item->second; 352 return defaultValue; 353 } 354 355 356 void Node::getState(State *_state, bool calculateLocation) 310 357 { 311 358 if (state != nullptr) … … 328 375 else if (mod == MODIFIERS[2]) 329 376 state->s *= multiplier; 330 else if (mod == MODIFIERS[3]) 331 state->stif *= multiplier; 332 } 333 334 if (parent != nullptr) 377 } 378 379 if (parent != nullptr && calculateLocation) 335 380 { 336 381 // Rotate … … 341 386 } 342 387 for (int i = 0; i < int(children.size()); i++) 343 children[i]->getState(state );388 children[i]->getState(state, calculateLocation); 344 389 } 345 390 … … 388 433 } 389 434 390 Pt3D Node::calculateSize()435 void Node::calculateSize(Pt3D &scale) 391 436 { 392 437 double sizeMultiplier = getParam(SIZE) * state->s; 393 double sx = getParam(SIZE_X) * sizeMultiplier; 394 double sy = getParam(SIZE_Y) * sizeMultiplier; 395 double sz = getParam(SIZE_Z) * sizeMultiplier; 396 return Pt3D(sx, sy, sz); 438 scale.x = getParam(SIZE_X) * sizeMultiplier; 439 scale.y = getParam(SIZE_Y) * sizeMultiplier; 440 scale.z = getParam(SIZE_Z) * sizeMultiplier; 397 441 } 398 442 … … 400 444 { 401 445 double result; 402 Pt3D size = calculateSize(); 446 Pt3D size; 447 calculateSize(size); 403 448 double radiiProduct = size.x * size.y * size.z; 404 449 switch (partType) … … 421 466 bool Node::isPartSizeValid() 422 467 { 423 Pt3D size = calculateSize(); 468 Pt3D size; 469 calculateSize(size); 424 470 double volume = calculateVolume(); 425 471 Part_MinMaxDef minP = Model::getMinPart(); … … 449 495 Pt3D Node::getVectorRotation() 450 496 { 451 return Pt3D(getParam(ROT_X ), getParam(ROT_Y), getParam(ROT_Z));497 return Pt3D(getParam(ROT_X, 0.0), getParam(ROT_Y, 0.0), getParam(ROT_Z, 0.0)); 452 498 } 453 499 454 500 Pt3D Node::getRotation() 455 501 { 456 Pt3D rotation = Pt3D(getParam(RX ), getParam(RY), getParam(RZ));502 Pt3D rotation = Pt3D(getParam(RX, 0.0), getParam(RY, 0.0), getParam(RZ, 0.0)); 457 503 if(fS_Genotype::TURN_WITH_ROTATION) 458 504 rotation += getVectorRotation(); … … 492 538 { 493 539 part = new Part(partType); 494 part->p = Pt3D(state->location.x, 495 state->location.y, 496 state->location.z); 540 part->p = Pt3D(state->location); 497 541 498 542 part->friction = getParam(FRICTION) * state->fr; 499 543 part->ingest = getParam(INGESTION) * state->ing; 500 Pt3D size = calculateSize(); 501 part->scale.x = size.x; 502 part->scale.y = size.y; 503 part->scale.z = size.z; 544 calculateSize(part->scale); 504 545 part->setRot(getRotation()); 505 546 } … … 508 549 { 509 550 Joint *j = new Joint(); 510 j->stif = getParam(STIFFNESS) * state->stif;511 j->rotstif = j->stif;512 513 551 j->attachToParts(parent->part, part); 514 552 switch (joint) … … 650 688 } 651 689 652 void fS_Genotype::getState( )690 void fS_Genotype::getState(bool calculateLocation) 653 691 { 654 692 State *initialState = new State(Pt3D(0), Pt3D(1, 0, 0)); 655 startNode->getState(initialState );693 startNode->getState(initialState, calculateLocation); 656 694 } 657 695 … … 662 700 model.open(using_checkpoints); 663 701 664 getState( );702 getState(true); 665 703 startNode->buildModel(model, nullptr); 666 704 buildNeuroConnections(model); … … 808 846 int fS_Genotype::checkValidityOfPartSizes() 809 847 { 810 getState( );848 getState(false); 811 849 vector<Node*> nodes = getAllNodes(); 812 850 for (int i = 0; i < int(nodes.size()); i++)
Note: See TracChangeset
for help on using the changeset viewer.