Ignore:
Timestamp:
05/21/23 23:16:51 (11 months ago)
Author:
Maciej Komosinski
Message:

Multiple issues fixed when calculating bending range for the '|' bending muscle (earlier it was always 1.0 despite the code that supposedly calculated this)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f4/f4_general.cpp

    r1241 r1249  
    1212#include <frams/model/model.h> // for min and max attributes
    1313#include <common/nonstd_math.h>
     14#include <algorithm> // std::min, std::max
    1415
    1516#ifdef DMALLOC
     
    4647        anglepos = nangle;
    4748        commacount = 0;
    48         childcount = 0;
     49        stickchildcount = 0;
    4950        P = newP;
    5051        rolling = 0;
     
    6566                        //firstend = ndad->lastend;
    6667                        //OM = ndad->OM;
    67                         ndad->childcount++;
     68                        ndad->stickchildcount++;
    6869                }
    6970                if (ndad->type == CELL_NEURON)
     
    7677        // adjust lastend
    7778        //lastend = firstend + ((Orient)OM * (Pt3D(1,0,0) * P.len));
    78         mz = 1;
     79        P.muscle_bend_range = 1;
    7980}
    8081
     
    9697        anglepos = nangle;
    9798        commacount = 0;
    98         childcount = 0;
     99        stickchildcount = 0;
    99100        P = newP;
    100101        rolling = 0;
     
    115116                        //firstend = ndad->lastend;
    116117                        //OM = ndad->OM;
    117                         ndad->childcount++;
     118                        ndad->stickchildcount++;
    118119                }
    119120                if (ndad->type == CELL_NEURON)
     
    126127        // adjust lastend
    127128        //lastend = firstend + ((Orient)OM * (Pt3D(1,0,0) * P.len));
    128         mz = 1;
     129        P.muscle_bend_range = 1;
    129130}
    130131
     
    548549
    549550
    550 void f4_Cell::adjustRec()
    551 {
    552         //f4_OrientMat rot;
    553         int i;
    554 
    555         if (recProcessedFlag)
     551void f4_Cell::adjustRecur()
     552{
     553        if (recurProcessedFlag)
    556554                // already processed
    557555                return;
    558556
    559557        // mark it processed
    560         recProcessedFlag = 1;
     558        recurProcessedFlag = true;
    561559
    562560        // make sure its parent is processed first
    563561        if (dadlink != NULL)
    564                 dadlink->adjustRec();
     562                dadlink->adjustRecur();
    565563
    566564        // count children
    567         childcount = 0;
    568         for (i = 0; i < org->cell_count; i++)
     565        stickchildcount = 0;
     566        for (int i = 0; i < org->cell_count; i++)
    569567        {
    570568                if (org->C[i]->dadlink == this)
    571569                        if (org->C[i]->type == CELL_STICK)
    572                                 childcount++;
    573         }
     570                                stickchildcount++;
     571        }
     572
     573        if (dadlink == NULL)
     574                P.muscle_bend_range = 1.0;
     575        else
     576                P.muscle_bend_range = 1.0 / std::max(1, dadlink->stickchildcount); //bend range in f1: 0, 1 (line XX[|]) -> 100%, 2 (Y-shape X(X[|],X)) -> 50%, 3 (cross X(X[|],X,X)) -> 33%
     577        //MacKo 2023-05: but shouldn't this formula ^^ also take commacount into consideration, like in f1?
    574578
    575579        if (type == CELL_STICK)
     
    580584                        // rotation due to rolling
    581585                        xrot = rolling;
    582                         mz = 1;
    583586                }
    584587                else
     
    589592                        Padj.propagateAlong(false);
    590593
    591                         //rot = Orient_1;
     594                        //f4_OrientMat rot = Orient_1;
    592595
    593596                        // rotation due to rolling
     
    612615                        // rotation in world coordinates
    613616                        //OM =  ((f4_OrientMat)dadlink->OM) * OM;
    614                         mz = dadlink->mz / dadlink->childcount;
    615617                }
    616618                //Pt3D lastoffset = (Orient)OM * (Pt3D(1,0,0)*P.len);
     
    737739        // reset recursive traverse flags
    738740        for (int i = 0; i < cell_count; i++)
    739                 C[i]->recProcessedFlag = 0;
     741                C[i]->recurProcessedFlag = false;
    740742        // process every cell
    741743        for (int i = 0; i < cell_count; i++)
    742                 C[i]->adjustRec();
     744                C[i]->adjustRecur();
    743745
    744746        //DB( printf("Cell simulation done, %d cells. \n", nc); )
    745747
    746748        if (PRINT_CELLS_DEVELOPMENT) print_cells("Final");
     749        if (PRINT_CELLS_DEVELOPMENT)
     750                for (int i = 0; i < cell_count; i++)
     751                        printf("%d,%d,dad=%d\tstick_children=%d\tcommas=%d\t|:range=%g\n", i, C[i]->nr, C[i]->dadlink ? C[i]->dadlink->nr : -1, C[i]->stickchildcount, C[i]->commacount, C[i]->P.muscle_bend_range);
    747752
    748753        return errorcode;
Note: See TracChangeset for help on using the changeset viewer.