Ignore:
Timestamp:
02/15/18 00:42:07 (7 years ago)
Author:
Maciej Komosinski
Message:

Added support for "checkpoints" (intermediate phases of development of the Model when converting between genetic encodings). See Model.checkpoint() and conv_f1.cpp for an example.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/modelobj.cpp

    r722 r732  
    77ParamEntry modelobj_paramtab[] =
    88{
    9         { "Model", 1, 16, "Model", },
     9        { "Model", 1, 21, "Model", },
    1010        { "se", 0, PARAM_NOSTATIC, "startenergy", "f", FIELD(startenergy), },
    1111        { "Vstyle", 0, PARAM_NOSTATIC, "vis_style", "s", FIELD(vis_style), },
    1212
    13         { "geno", 0, PARAM_NOSTATIC | PARAM_READONLY, "geno", "o Geno", GETONLY(geno), },
    14         { "newFromString", 0, 0, "create new object", "p oModel(s genotype)", PROCEDURE(p_newfromstring), },
    15         { "newFromGeno", 0, 0, "create new object", "p oModel(oGeno)", PROCEDURE(p_newfromgeno), },
     13        { "geno", 0, PARAM_NOSTATIC | PARAM_READONLY, "Geno", "oGeno", GETONLY(geno), },
     14        { "newFromString", 0, 0, "Create a new object", "p oModel(s genotype)", PROCEDURE(p_newfromstring), },
     15        { "newFromGeno", 0, 0, "Create a new object", "p oModel(oGeno)", PROCEDURE(p_newfromgeno), },
     16        { "newWithCheckpoints", 0, 0, "Create a new object", "p oModel(x Geno object or string genotype)", PROCEDURE(p_newwithcheckpoints), "Creates a Model with the \"Checkpoints\" option enabled. Genotype converters supporting Checkpoints provide a sequence of Models that reflects development stages of the creature (this sequence is used purely for debugging and visualization of phenotype growth/development). Checkpoint Models can be accessed using getCheckpoint(i) for i ranging from 0 to numcheckpoints-1. Models created without the Checkpoint option and Models coming from unsupported converters have numcheckpoints=0." },
    1617
    17         { "numparts", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "number of parts", "d", GETONLY(numparts), },
    18         { "numjoints", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "number of joints", "d", GETONLY(numjoints), },
    19         { "numneurons", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "number of neurons", "d", GETONLY(numneurons), },
    20         { "numconnections", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "number of neuron connections", "d", GETONLY(numconnections), },
     18        { "numparts", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Number of parts", "d", GETONLY(numparts), },
     19        { "numjoints", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Number of joints", "d", GETONLY(numjoints), },
     20        { "numneurons", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Number of neurons", "d", GETONLY(numneurons), },
     21        { "numconnections", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Number of neuron connections", "d", GETONLY(numconnections), },
    2122
    2223        { "getPart", 0, PARAM_USERHIDDEN | PARAM_NOSTATIC, "getPart (static model information)", "p oPart(d index)", PROCEDURE(p_getpart), },
     
    2425        { "getNeuroDef", 0, PARAM_USERHIDDEN | PARAM_NOSTATIC, "getNeuroDef", "p oNeuroDef(d index)", PROCEDURE(p_getneuro), },
    2526
    26         { "size_x", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "bounding box x size", "f", FIELD(size.x), "(size_x,size_y,size_z) are dimensions of the axis-aligned bounding box of the creature, including imaginary Part sizes (Part.s, usually 1.0). A creature consisting of a single default part has the size of (2.0,2.0,2.0) - twice the Part.s value (like a sphere diameter is twice its radius).\nSee also: Creature.moveAbs" },
    27         { "size_y", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "bounding box y size", "f", FIELD(size.y), "See Model.size_x" },
    28         { "size_z", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "bounding box z size", "f", FIELD(size.z), "See Model.size_x" },
     27        { "size_x", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "Bounding box x size", "f", FIELD(size.x), "(size_x,size_y,size_z) are dimensions of the axis-aligned bounding box of the creature, including imaginary Part sizes (Part.s, usually 1.0). A creature consisting of a single default part has the size of (2.0,2.0,2.0) - twice the Part.s value (like a sphere diameter is twice its radius).\nSee also: Creature.moveAbs" },
     28        { "size_y", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "Bounding box y size", "f", FIELD(size.y), "See Model.size_x" },
     29        { "size_z", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "Bounding box z size", "f", FIELD(size.z), "See Model.size_x" },
    2930        { "bboxSize", 0, PARAM_READONLY | PARAM_NOSTATIC, "Bounding box size", "oXYZ", GETONLY(bboxsize) },
     31        { "numcheckpoints", 0, PARAM_DONTSAVE | PARAM_READONLY | PARAM_NOSTATIC, "Number of checkpoints", "d", GETONLY(numcheckpoints) },
     32        { "getCheckpoint", 0, PARAM_USERHIDDEN | PARAM_NOSTATIC, "getCheckpoint", "p oModel(d index)", PROCEDURE(p_getcheckpoint),
     33        "Checkpoint Model objects are only valid as long as the parent Model object exists.\n"
     34        "See also: Model.newWithCheckpoints()\n\n"
     35        "// incorrect usage - calling getCheckpoint() on a temporary object:\n"
     36        "var c=Model.newWithCheckpoints(\"XXX\").getCheckpoint(1).genotype.geno;\n\n"
     37        "// correct usage - keeping the parent Model reference in 'm':\n"
     38        "var m=Model.newWithCheckpoints(\"XXX\");\n"
     39        "var c=m.getCheckpoint(1).genotype.geno;\n"
     40        },
     41        { "shape_type", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Shape type", "d 0 3 ~Unknown~Illegal~Ball-and-stick~Solids", GETONLY(shape_type) },
     42        { "solid_model", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Solid shapes model", "oModel", GETONLY(solid_model), "Conversion of this Model to solid shapes. Note! Only available when this Model has shape_type==2 (Ball-and-stick)." },
    3043
    3144        { 0, 0, 0, },
     
    5770}
    5871
     72void ModelObj::p_newwithcheckpoints(ExtValue *args, ExtValue *ret)
     73{
     74        Model *m = NULL;
     75        if (args[0].getType() == TString)
     76                m = new Model(Geno(args[0].getString()), false, true);
     77        else
     78        {
     79                Geno *g = GenoObj::fromObject(args[0].getObject(), false);
     80                if (g)
     81                        m = new Model(*g, false, true);
     82                else
     83                        logPrintf("Model", "newWithCheckpoints", LOG_ERROR, "Geno or string expected, %s found", args[0].typeDescription().c_str());
     84        }
     85
     86        if (m != NULL)
     87                *ret = makeDynamicObject(m);
     88        else
     89                ret->setEmpty();
     90}
     91
    5992Param& ModelObj::getStaticParam()
    6093{
    6194#ifdef __CODEGUARD__
    6295        static ModelObj static_modelobj;
    63         static Param static_modelparam(modelobj_paramtab,&static_modelobj);
     96        static Param static_modelparam(modelobj_paramtab, &static_modelobj);
    6497#else
    6598        static Param static_modelparam(modelobj_paramtab);
     
    131164        *ret = Pt3D_Ext::makeDynamicObject(new Pt3D_Ext(size));
    132165}
     166
     167void ModelObj::p_getcheckpoint(PARAMPROCARGS)
     168{
     169        int i = args->getInt();
     170        if ((i < 0) || (i >= getCheckpointCount()))
     171        {
     172                ret->setEmpty();
     173                return;
     174        }
     175        ret->setObject(makeStaticObject(getCheckpoint(i)));
     176}
     177
     178void ModelObj::get_solid_model(ExtValue *ret)
     179{
     180        if (getShapeType() != Model::SHAPE_BALL_AND_STICK)
     181                ret->setEmpty();
     182        Model *m = new Model;
     183        m->open();
     184        m->buildUsingSolidShapeTypes(*this);
     185        m->close();
     186        *ret = makeDynamicObject(m);
     187}
     188
     189void ModelObj::get_shape_type(ExtValue *ret)
     190{
     191        ret->setInt(getShapeType());
     192}
Note: See TracChangeset for help on using the changeset viewer.