Ignore:
Timestamp:
02/15/18 00:42:07 (6 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/model.h

    r726 r732  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1515
    1616extern ParamEntry f0_model_paramtab[];
    17 
    18 //#define EASYMAPDEBUG
    1917
    2018enum ModelBuildStatus { empty, building, invalid, valid };
     
    6462        /// make model map in build()
    6563        bool autobuildmaps;
     64        /// supports adding checkpoints
     65        bool using_checkpoints;
     66        /// means less strict validation
     67        bool is_checkpoint;
    6668        /// valid if build from f0 genotype
    6769        int f0errorposition;
     
    7577        SList parts, joints, neurons;
    7678        char partmappingchanged;
     79        vector<Model*> checkpoints;
    7780
    7881        void internalCopy(const Model &mod);
     
    9598                EDITING_CHECK, ///< Used in Model::validate(). Default validation - does not modify elements of the Model.
    9699                FINAL_CHECK,   ///< Used in Model::close() when a Model is built from a genotype. Like EDITING_CHECK, but also calculates Joint::d and Joint::rot.
    97                 LIVE_CHECK     ///< used in Model::close() when a Model is built from a Creature. Like FINAL_CHECK but does not limit joint length which could make some liveModels invalid.
     100                LIVE_CHECK,     ///< used in Model::close() when a Model is built from a Creature. Like FINAL_CHECK but does not limit joint length which could make some liveModels invalid.
     101                CHECKPOINT_CHECK     ///< used when storing checkpoint models. Like LIVE_CHECK, excluding consistency check (disjoint parts are acceptable)
    98102        };
    99103protected:
    100104        ShapeType shape;
    101105
    102         void updateNeuroRefno(); // set Neuro::refno for all neurons
    103106        SString nameForErrors() const;
    104107        int internalcheck(CheckType check);
    105108
    106         void moveNeuro(int oldpos, int newpos);
    107 
    108         void init(const Geno &srcgen);
     109        void init(const Geno &srcgen, bool _using_checkpoints, bool _is_checkpoint);
    109110        void init();
    110111
     
    134135        int getErrorPosition(bool includingwarnings = false);
    135136        ShapeType getShapeType() const { return shape; }
     137        bool isUsingCheckpoints() const { return using_checkpoints; }
     138        bool isCheckpoint() const { return is_checkpoint; }
    136139
    137140        void updateRefno(); // set ::refno for all elements
     141
     142        int getCheckpointCount();
     143        Model* getCheckpoint(int i);
    138144
    139145        /// The bounding box size. Valid if the model is valid. Read only.
     
    153159           @see getMap()
    154160           */
    155         Model(const Geno &src, bool buildmaps = false);
    156         Model(const Model &mod, bool buildmaps = false);
     161        Model(const Geno &src, bool buildmaps = false, bool _using_checkpoints = false, bool _is_checkpoint = false);
     162        Model(const Model &mod, bool buildmaps = false, bool _using_checkpoints = false, bool _is_checkpoint = false);
    157163        /** duplicate the model.
    158164                the resulting object's status is 'building' (opened).
     
    255261        void clear();
    256262
    257         enum ItemType { UnknownType,ModelType,PartType,JointType,NeuronType,NeuronConnectionType };
     263        enum ItemType { UnknownType, ModelType, PartType, JointType, NeuronType, NeuronConnectionType, CheckpointType };
    258264        static ItemType itemTypeFromLinePrefix(const char* line);
    259265        /** Execute single line of <B>f0</B> genotype.
     
    264270                @param srcrange source genotype range which will be mapped to this element
    265271                */
    266         int addFromString(ItemType item_type,const SString &singleline, int line_num, const MultiRange* srcrange = NULL);
     272        int addFromString(ItemType item_type, const SString &singleline, int line_num, const MultiRange* srcrange = NULL);
    267273        /** Execute single line of <B>f0</B> genotype - compatiblity variant */
    268         int addFromString(ItemType item_type,const SString &singleline, const MultiRange* srcrange = NULL);
     274        int addFromString(ItemType item_type, const SString &singleline, const MultiRange* srcrange = NULL);
    269275        /** Execute single line of <B>f0</B> genotype - low level variant, used by Model::build(), error messages returned as string instead of calling logger */
    270         int addFromStringNoLog(ItemType item_type,const SString &singleline, SString& error_message, const MultiRange* srcrange = 0);
     276        int addFromStringNoLog(ItemType item_type, const SString &singleline, SString& error_message, const MultiRange* srcrange = 0);
    271277
    272278        /// separate build stages (for future use)
     
    289295        /// or modify the model created from the genotype.
    290296        /// Between open() and close() the model is not fully usable.
    291         void open();
     297        void open(bool _using_checkpoints = false, bool _is_checkpoint = false);
    292298
    293299        /// Current model written as f0 genotype while building
     
    379385        void buildUsingSolidShapeTypes(const Model& src_ballandstick_shapes, Part::Shape use_shape = Part::SHAPE_CYLINDER, float thickness = 0.2);
    380386
    381 #ifdef EASYMAPDEBUG
    382         static int partToMap(int i) {return 0+i;}
    383         static int jointToMap(int i) {return 10+i;}
    384         static int neuroToMap(int i) {return 20+i;}
    385         static int mapToPart(int i) {return i-0;}
    386         static int mapToJoint(int i) {return i-10;}
    387         static int mapToNeuro(int i) {return i-20;}
    388 #else
    389         static int partToMap(int i) { return 0x10000000 + i; }
    390         static int jointToMap(int i) { return 0x20000000 + i; }
    391         static int neuroToMap(int i) { return 0x30000000 + i; }
    392         static int mapToPart(int i) { return i - 0x10000000; }
    393         static int mapToJoint(int i) { return i - 0x20000000; }
    394         static int mapToNeuro(int i) { return i - 0x30000000; }
    395 #endif
     387protected:
     388        static const int MODEL_MAPPING_OFFSET = 0x10000000;
     389public:
     390        static int elementToMap(ItemType t, int i);
     391        struct TypeAndIndex
     392        {
     393                ItemType type; int index;
     394                TypeAndIndex() :type(UnknownType), index(0) {}
     395                TypeAndIndex(ItemType _type, int _index) :type(_type), index(_index) {}
     396        };
     397        static TypeAndIndex mapToElement(int i);
     398        static int partToMap(int i);
     399        static int jointToMap(int i);
     400        static int neuroToMap(int i);
     401        static int mapToPart(int i);
     402        static int mapToJoint(int i);
     403        static int mapToNeuro(int i);
    396404
    397405        static void makeGenToGenMap(MultiMap& result, const MultiMap& gen1tomodel, const MultiMap& gen2tomodel);
Note: See TracChangeset for help on using the changeset viewer.