Ignore:
Timestamp:
11/05/17 21:45:20 (6 years ago)
Author:
Maciej Komosinski
Message:
  • Setting default NeuroClass? active/genactive in preconfigured genetics
  • genactive becomes bool (was int)
  • Code formatting
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/modelparts.h

    r544 r714  
    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-2017  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    2626class MultiRange;
    2727
    28 typedef UserTags<Model,void*,5> ModelUserTags;
     28typedef UserTags<Model, void*, 5> ModelUserTags;
    2929
    3030/** Common base for model elements. */
     
    3232{
    3333public:
    34 SString vis_style;
    35 PartBase(const SString& s):vis_style(s),mapped(0) {}
    36 ~PartBase();
    37 static SString getDefaultStyle(){return SString("none");}
    38 MultiRange *mapped;
    39 enum PartBaseFlags { Selected=1 };
    40 int flags;
    41 Model *owner;   ///< backlink to the model
    42 
    43 SString info;
    44 
    45 Model &getModel() const {return *owner;}
    46 
    47 ModelUserTags userdata;
    48 
    49 void notifyMappingChange();
    50 
    51 void clearMapping();
    52 MultiRange* getMapping() {return mapped;}
    53 void setMapping(const IRange &mr);
    54 void addMapping(const IRange &mr);
    55 void setMapping(const MultiRange &mr);
    56 void addMapping(const MultiRange &mr);
    57 
    58 void setInfo(const SString& name,const SString& value);
    59 void setInfo(const SString& name,int value);
    60 void setInfo(const SString& name,double value);
    61 SString getInfo(const SString& name);
     34        SString vis_style;
     35        PartBase(const SString& s) :vis_style(s), mapped(0) {}
     36        ~PartBase();
     37        static SString getDefaultStyle(){ return SString("none"); }
     38        MultiRange *mapped;
     39        enum PartBaseFlags { Selected = 1 };
     40        int flags;
     41        Model *owner;   ///< backlink to the model
     42
     43        SString info;
     44
     45        Model &getModel() const { return *owner; }
     46
     47        ModelUserTags userdata;
     48
     49        void notifyMappingChange();
     50
     51        void clearMapping();
     52        MultiRange* getMapping() { return mapped; }
     53        void setMapping(const IRange &mr);
     54        void addMapping(const IRange &mr);
     55        void setMapping(const MultiRange &mr);
     56        void addMapping(const MultiRange &mr);
     57
     58        void setInfo(const SString& name, const SString& value);
     59        void setInfo(const SString& name, int value);
     60        void setInfo(const SString& name, double value);
     61        SString getInfo(const SString& name);
    6262};
    6363
     
    6565/// You can use this class for querying and adjusting constructed
    6666/// model properties
    67 class Part: public PartBase
    68 {
    69 friend class Model;
    70 static SString getDefaultStyle();
    71 Part(double _mass,double _size,double _density,double _friction,double _ingest,double _assim)
    72           :PartBase(getDefaultStyle()),mass(_mass),size(_size),density(_density),friction(_friction),ingest(_ingest),assim(_assim)
     67class Part : public PartBase
     68{
     69        friend class Model;
     70        static SString getDefaultStyle();
     71        Part(double _mass, double _size, double _density, double _friction, double _ingest, double _assim)
     72                :PartBase(getDefaultStyle()), mass(_mass), size(_size), density(_density), friction(_friction), ingest(_ingest), assim(_assim)
    7373        {}
    74 void defassign();
    75 public:
    76 // base properties - have special meaning and therefore are often accessed directly for convenience
    77 Pt3D p;    ///< 3d coordinates of the part
    78 Orient o;  ///< orientation in 3d space (rotation matrix)
    79 /// ParamInterface object is preferred way to get/set other properties.
    80 Param extraProperties();
    81 Param properties();
    82 paInt refno;
    83 Pt3D rot;///< rotation angles
    84 
    85 ///
    86 paInt shape;///default=old Framsticks compatible, do not mix with shapes>0
    87 enum Shape {SHAPE_BALL_AND_STICK=0, SHAPE_ELLIPSOID=1, SHAPE_CUBOID=2, SHAPE_CYLINDER=3};
    88 double mass,size,density,friction,ingest,assim,hollow;
    89 Pt3D scale;
    90 Pt3D food;
    91 //SList points; // collistion points
    92 //Slist neurons; // "select * from owner->neurons where part=this" ;-)
    93 
    94 Pt3D vcolor;
    95 double vsize;
    96 
    97 Part(enum Shape s=SHAPE_BALL_AND_STICK);
    98 Part(const Part& src):PartBase(getDefaultStyle()) {operator=(src);}
    99 void operator=(const Part& src);
    100 
    101 void setPositionAndRotationFromAxis(const Pt3D &p1,const Pt3D &p2);
    102 void setOrient(const Orient &o);///< set part.o and calculates part.rot (rotation angles)
    103 void setRot(const Pt3D &r);///< set part.rot (rotation angles) and calculate part.o
    104 
    105 static Param& getStaticParam();
     74        void defassign();
     75public:
     76        // base properties - have special meaning and therefore are often accessed directly for convenience
     77        Pt3D p;    ///< 3d coordinates of the part
     78        Orient o;  ///< orientation in 3d space (rotation matrix)
     79        /// ParamInterface object is preferred way to get/set other properties.
     80        Param extraProperties();
     81        Param properties();
     82        paInt refno;
     83        Pt3D rot;///< rotation angles
     84
     85        ///
     86        paInt shape;///default=old Framsticks compatible, do not mix with shapes>0
     87        enum Shape { SHAPE_BALL_AND_STICK = 0, SHAPE_ELLIPSOID = 1, SHAPE_CUBOID = 2, SHAPE_CYLINDER = 3 };
     88        double mass, size, density, friction, ingest, assim, hollow;
     89        Pt3D scale;
     90        Pt3D food;
     91        //SList points; // collistion points
     92        //Slist neurons; // "select * from owner->neurons where part=this" ;-)
     93
     94        Pt3D vcolor;
     95        double vsize;
     96
     97        Part(enum Shape s = SHAPE_BALL_AND_STICK);
     98        Part(const Part& src) :PartBase(getDefaultStyle()) { operator=(src); }
     99        void operator=(const Part& src);
     100
     101        void setPositionAndRotationFromAxis(const Pt3D &p1, const Pt3D &p2);
     102        void setOrient(const Orient &o);///< set part.o and calculates part.rot (rotation angles)
     103        void setRot(const Pt3D &r);///< set part.rot (rotation angles) and calculate part.o
     104
     105        static Param& getStaticParam();
    106106};
    107107
    108108/// Imaginary connection between two parts.
    109109/// Joint has no mass nor intertia but can transfer forces.
    110 class Joint: public PartBase
    111 {
    112 friend class Model;
    113 SString getDefaultStyle();
    114 Joint(double _stamina,double _stif,double _rotstif,double _d)
    115         :PartBase(getDefaultStyle()),stamina(_stamina),stif(_stif),rotstif(_rotstif)
    116         {d=Pt3D(_d,0,0);}
    117 void defassign();
    118 void resetDeltaMarkers();
    119 public:
    120 // base properties:
    121 paInt p1_refno,p2_refno; ///< parts' reference numbers
    122 
    123 Part *part1,*part2;     ///< references to parts
    124 class Pt3D d;           ///< position delta between parts
    125 class Pt3D rot; ///< orientation delta between parts expressed as 3 angles
    126 enum Shape {SHAPE_BALL_AND_STICK=0, SHAPE_FIXED=1};
    127 paInt shape;///< ball-and-stick=old Framsticks compatible, creates a physical rod between parts (cylinder or cuboid), do not mix with shape>0,  fixed=merge parts into one physical entity
    128 
    129 Joint();
    130 Joint(const Joint& src):PartBase(getDefaultStyle()) {operator=(src);}
    131 void operator=(const Joint& src);
    132 
    133 /** connect two parts with this joint.
    134     p2 position will be adjusted if delta option is in effect.
    135     @see isDelta()
    136   */
    137 void attachToParts(Part* p1,Part* p2);
    138 /// @see attachToParts(Part*,Part*)
    139 void attachToParts(int p1,int p2);
    140 
    141 /** discard delta information but don't disable delta flag.
    142     delta will be calculated from parts positions during final consistency check.
    143  */
    144 void resetDelta();
    145 
    146 /** enable or disable delta option.
    147     delta value is not changed.
    148  */
    149 void useDelta(bool use);
    150 
    151 /** @return true if delta option is in effect.
    152     @see useDelta(), resetDelta(), useDelta()
    153 */
    154 bool isDelta();
    155 
    156 /// ParamInterface object is preferred way to get/set other properties.
    157 Param extraProperties();
    158 Param properties();
    159 
    160 // do not touch these:
    161 paInt refno; ///< this joint's reference number
    162 double stamina;
    163 double stif,rotstif;    ///< stiffness for moving and bending forces
    164 class Orient o; ///< orientation delta between parts as rotation matrix
    165 /** flag: generated f0 should include delta data.
    166     set by 'singlestep' if j: attributes use delta option */
    167 bool usedelta;
    168 Pt3D vcolor;
    169 
    170 static Param& getStaticParam();
     110class Joint : public PartBase
     111{
     112        friend class Model;
     113        SString getDefaultStyle();
     114        Joint(double _stamina, double _stif, double _rotstif, double _d)
     115                :PartBase(getDefaultStyle()), stamina(_stamina), stif(_stif), rotstif(_rotstif)
     116        {
     117                d = Pt3D(_d, 0, 0);
     118        }
     119        void defassign();
     120        void resetDeltaMarkers();
     121public:
     122        // base properties:
     123        paInt p1_refno, p2_refno; ///< parts' reference numbers
     124
     125        Part *part1, *part2;    ///< references to parts
     126        class Pt3D d;           ///< position delta between parts
     127        class Pt3D rot; ///< orientation delta between parts expressed as 3 angles
     128        enum Shape { SHAPE_BALL_AND_STICK = 0, SHAPE_FIXED = 1 };
     129        paInt shape;///< ball-and-stick=old Framsticks compatible, creates a physical rod between parts (cylinder or cuboid), do not mix with shape>0,  fixed=merge parts into one physical entity
     130
     131        Joint();
     132        Joint(const Joint& src) :PartBase(getDefaultStyle()) { operator=(src); }
     133        void operator=(const Joint& src);
     134
     135        /** connect two parts with this joint.
     136                p2 position will be adjusted if delta option is in effect.
     137                @see isDelta()
     138                */
     139        void attachToParts(Part* p1, Part* p2);
     140        /// @see attachToParts(Part*,Part*)
     141        void attachToParts(int p1, int p2);
     142
     143        /** discard delta information but don't disable delta flag.
     144                delta will be calculated from parts positions during final consistency check.
     145                */
     146        void resetDelta();
     147
     148        /** enable or disable delta option.
     149                delta value is not changed.
     150                */
     151        void useDelta(bool use);
     152
     153        /** @return true if delta option is in effect.
     154                @see useDelta(), resetDelta(), useDelta()
     155                */
     156        bool isDelta();
     157
     158        /// ParamInterface object is preferred way to get/set other properties.
     159        Param extraProperties();
     160        Param properties();
     161
     162        // do not touch these:
     163        paInt refno; ///< this joint's reference number
     164        double stamina;
     165        double stif, rotstif;   ///< stiffness for moving and bending forces
     166        class Orient o; ///< orientation delta between parts as rotation matrix
     167        /** flag: generated f0 should include delta data.
     168                set by 'singlestep' if j: attributes use delta option */
     169        bool usedelta;
     170        Pt3D vcolor;
     171
     172        static Param& getStaticParam();
    171173};
    172174
     
    177179class NeuroClass;
    178180
    179 typedef UserTags<NeuroClass,void*,5> NeuroClassUserTags;
     181typedef UserTags<NeuroClass, void*, 5> NeuroClassUserTags;
    180182
    181183/** Information about neuron class.
     
    183185class NeuroClass
    184186{
    185 bool ownedvectordata;
    186 void operator=(const NeuroClass& nosuchthich){}
    187   public:
    188 SString name,longname,description;
    189 ParamEntry *props;
    190 bool ownedprops;//< destructor will free props using ParamObject::freeParamTab
    191 paInt prefinputs,prefoutput;
    192 paInt preflocation;
    193 int *vectordata;
    194 paInt visualhints;
    195 
    196 //void *impl;
    197 int impl_count;
    198 bool active;
    199 int genactive;
    200 NeuroClassUserTags userdata;
    201 
    202 //////////////////////
    203 ~NeuroClass();
    204 NeuroClass();
    205 NeuroClass(ParamEntry *_props,SString _description,
    206            int _prefinputs,int _prefoutput,int _preflocation,int *_vectordata,bool own_vd=1,int vhints=0);
    207 /** class name for use in Neuro::setClassName(), Neuro::setDetails() (former 'moredata' field),
    208     eg. "N","-",G" */
    209 const SString& getName() {return name;}
    210 /** human friendly name, eg. "Neuron","Link","Gyroscope"  */
    211 const SString& getLongName() {return longname;}
    212 /** long description */
    213 const SString& getDescription() {return description;}
    214 ParamEntry* getParamTab() {return props;}
    215 
    216 /** NeuroClass specific properties, recognized by all neurons of this class */
    217 Param getProperties() {return Param(props);}
    218 
    219 /** preferred number of inputs, -1 = no preference (any number will go).
    220     extra inputs may be ignored by the object (depends on the class).
    221  */
    222 int getPreferredInputs() {return (int)prefinputs;}
    223 
    224 /** @return 0 if this object doesn't provide useful output signal. */
    225 int getPreferredOutput() {return (int)prefoutput;}
    226 
    227 /** @return 0 if the object doesn't need any assignment to the body element.
    228     @return 1 = it likes to be attached to the Part ( @see Neuro::attachToPart() )
    229     @return 2 = the object prefers to have the Joint ( @see Neuro::attachToJoint() )
    230  */
    231 int getPreferredLocation() {return (int)preflocation;}
    232 /** vector drawing to be used in neuro net diagram.
    233     interpretation:
    234        {   
    235            LEN = datalength (excluding this number)
    236            NL = number_of_lines
    237 line#1 ->  NS = number_of_segments, x1,y1, x2,y2, ... xNS-1,yNS-1,
    238          ...
    239 line#NL -> NS = number_of_segments, x1,y1, x2,y2, ... xNS-1,yNS-1,
    240        }
    241  */
    242 int* getSymbolGlyph()
    243  {return vectordata;}
    244 void setSymbolGlyph(int *data,bool owned=1)
    245  {if (vectordata&&ownedvectordata) delete []vectordata;
    246  vectordata=data; ownedvectordata=owned;}
    247 /** additional information about how the neuron should be drawn
    248     used by structure view (and maybe some other components).
    249     return value is defined by the enum Hint
    250     @see enum Hint
    251  */
    252 int getVisualHints()
    253  {return (int)visualhints;}
    254 
    255 enum Hint
    256         /** don't draw neurons of this class */
    257  { Invisible=1,
    258         /** don't draw classname label below the neuron */
    259    DontShowClass=2,
    260         /** draw the neuron at the first part when attached to joint (default is in the middle) */
    261    AtFirstPart=4,
    262         /** draw the neuron at the second part when attached to joint (default is in the middle) */
    263    AtSecondPart=8,
    264         /** use effector colour for this neuro unit */
    265    EffectorClass=16,
    266         /** use receptor colour for this neuro unit */
    267    ReceptorClass=32,
    268    V1BendMuscle=64,
    269    V1RotMuscle=128,
    270    LinearMuscle=256
    271  };
    272 
    273 /** textual summary, automatically generated from other properties (like the neuro class tooltip) */
    274 SString getSummary();
     187        bool ownedvectordata;
     188        void operator=(const NeuroClass& nosuchthich){}
     189public:
     190        SString name, longname, description;
     191        ParamEntry *props;
     192        bool ownedprops;//< destructor will free props using ParamObject::freeParamTab
     193        paInt prefinputs, prefoutput;
     194        paInt preflocation;
     195        int *vectordata;
     196        paInt visualhints;
     197
     198        //void *impl;
     199        int impl_count;
     200        bool active;
     201        bool genactive;
     202        NeuroClassUserTags userdata;
     203
     204        //////////////////////
     205        ~NeuroClass();
     206        NeuroClass();
     207        NeuroClass(ParamEntry *_props, SString _description,
     208                int _prefinputs, int _prefoutput, int _preflocation, int *_vectordata, bool own_vd = 1, int vhints = 0);
     209        /** class name for use in Neuro::setClassName(), Neuro::setDetails() (former 'moredata' field),
     210                eg. "N","-",G" */
     211        const SString& getName() { return name; }
     212        /** human friendly name, eg. "Neuron","Link","Gyroscope"  */
     213        const SString& getLongName() { return longname; }
     214        /** long description */
     215        const SString& getDescription() { return description; }
     216        ParamEntry* getParamTab() { return props; }
     217
     218        /** NeuroClass specific properties, recognized by all neurons of this class */
     219        Param getProperties() { return Param(props); }
     220
     221        /** preferred number of inputs, -1 = no preference (any number will go).
     222                extra inputs may be ignored by the object (depends on the class).
     223                */
     224        int getPreferredInputs() { return (int)prefinputs; }
     225
     226        /** @return 0 if this object doesn't provide useful output signal. */
     227        int getPreferredOutput() { return (int)prefoutput; }
     228
     229        /** @return 0 if the object doesn't need any assignment to the body element.
     230                @return 1 = it likes to be attached to the Part ( @see Neuro::attachToPart() )
     231                @return 2 = the object prefers to have the Joint ( @see Neuro::attachToJoint() )
     232                */
     233        int getPreferredLocation() { return (int)preflocation; }
     234        /** vector drawing to be used in neuro net diagram.
     235                interpretation:
     236                {
     237                LEN = datalength (excluding this number)
     238                NL = number_of_lines
     239                line#1 ->  NS = number_of_segments, x1,y1, x2,y2, ... xNS-1,yNS-1,
     240                ...
     241                line#NL -> NS = number_of_segments, x1,y1, x2,y2, ... xNS-1,yNS-1,
     242                }
     243                */
     244        int* getSymbolGlyph()
     245        {
     246                return vectordata;
     247        }
     248        void setSymbolGlyph(int *data, bool owned = 1)
     249        {
     250                if (vectordata&&ownedvectordata) delete[]vectordata;
     251                vectordata = data; ownedvectordata = owned;
     252        }
     253        /** additional information about how the neuron should be drawn
     254                used by structure view (and maybe some other components).
     255                return value is defined by the enum Hint
     256                @see enum Hint
     257                */
     258        int getVisualHints()
     259        {
     260                return (int)visualhints;
     261        }
     262
     263        enum Hint
     264                /** don't draw neurons of this class */
     265        {
     266                Invisible = 1,
     267                /** don't draw classname label below the neuron */
     268                DontShowClass = 2,
     269                /** draw the neuron at the first part when attached to joint (default is in the middle) */
     270                AtFirstPart = 4,
     271                /** draw the neuron at the second part when attached to joint (default is in the middle) */
     272                AtSecondPart = 8,
     273                /** use effector colour for this neuro unit */
     274                EffectorClass = 16,
     275                /** use receptor colour for this neuro unit */
     276                ReceptorClass = 32,
     277                V1BendMuscle = 64,
     278                V1RotMuscle = 128,
     279                LinearMuscle = 256
     280        };
     281
     282        /** textual summary, automatically generated from other properties (like the neuro class tooltip) */
     283        SString getSummary();
     284
     285        static void resetActive(); ///< set default values of active and genactive for all classes
     286        static void setGenActive(const char* classes[]); ///< set genactive for specified classes
    275287};
    276288
     
    283295class OldItems
    284296{
    285 Neuro &neuro;
    286 SList syntitems; ///< to be deleted
    287 SList items;
    288 int listok;
    289   public:
    290 OldItems(Neuro &n):neuro(n),listok(0) {}
    291 ~OldItems() {freelist();}
    292 void buildlist();
    293 void freelist();
    294 
    295 int getItemCount();
    296 NeuroItem *getNeuroItem(int i);
    297 NeuroItem *addNewNeuroItem();
    298 int findNeuroItem(NeuroItem *n);
     297        Neuro &neuro;
     298        SList syntitems; ///< to be deleted
     299        SList items;
     300        int listok;
     301public:
     302        OldItems(Neuro &n):neuro(n),listok(0) {}
     303        ~OldItems() {freelist();}
     304        void buildlist();
     305        void freelist();
     306
     307        int getItemCount();
     308        NeuroItem *getNeuroItem(int i);
     309        NeuroItem *addNewNeuroItem();
     310        int findNeuroItem(NeuroItem *n);
    299311};
    300312#endif
    301313
    302314/** Single processing unit in Framsticks NN.  */
    303 class Neuro: public PartBase
    304 {
    305 friend class Model;
    306 static SString getDefaultStyle();
    307 
    308 struct NInput { Neuro *n; double weight; SString *info;
    309         NInput(Neuro *_n,double w,SString *i=0):n(_n),weight(w),info(i) {} };
    310 
    311 SListTempl<NInput> inputs;
    312 
    313 NeuroClass *myclass;
    314 bool knownclass;
    315 SString myclassname, myclassparams;
    316 /** set myclass and make knownclass=true */
    317 void checkClass();
    318 SString** inputInfo(int i);
    319 void defassign();
    320 
    321 public:
    322 enum NeuroFlags { HoldState=2 };
    323 Param properties();
    324 Param extraProperties();
    325 
    326 void setInputInfo(int i,const SString& name,const SString &value);
    327 void setInputInfo(int i,const SString& name,int value);
    328 void setInputInfo(int i,const SString& name,double value);
    329 SString getInputInfo(int i);
    330 SString getInputInfo(int i,const SString& name);
    331 
    332 NeuroClass* getClass();
    333 void setClass(NeuroClass*);
    334 
    335 SString getClassParams() {return myclassparams;}
    336 void setClassParams(const SString& cp) {myclassparams=cp;}
    337 
    338 SString getClassName();
    339 void setClassName(const SString& clazz);
    340 
    341 /** return neuro unit details encoded as <CLASS> ":" <PROPERTIES>
    342    
    343     new Neuro can be created as root object (without parent) or can be
    344     the child of existing Neuro. Children of the Neuro are its inputs.
    345     Standard Framsticks neuron calculates the sum of all input units - other processing
    346     units don't have to treat them equally and can even ignore some of them.
    347     There are hints about expected inputs in the class database, @see getClass
    348 
    349     Application should not assume anything about classes and its properties
    350     except for two standard classes: (information about all current classes
    351     can be retrieved with getClass/getClassProperties methods)
    352     - getClassName()="N" is the standard Framsticks neuron, accepts any number of inputs,
    353       compatible with old Neuro object
    354     - getClassName()="-" is the neuron link, compatible with old Neuro-Neuro link
    355       (NeuroItem with empty details)
    356     Empty details defaults to "-" if the parent unit is specified,
    357     and "N" if the unit has no parent.
    358  */
    359 SString getDetails();
    360 
    361 /** details = classname + ":" + classparams
    362     @see getDetails()
    363  */
    364 void setDetails(const SString&);
     315class Neuro : public PartBase
     316{
     317        friend class Model;
     318        static SString getDefaultStyle();
     319
     320        struct NInput {
     321                Neuro *n; double weight; SString *info;
     322                NInput(Neuro *_n, double w, SString *i = 0) :n(_n), weight(w), info(i) {}
     323        };
     324
     325        SListTempl<NInput> inputs;
     326
     327        NeuroClass *myclass;
     328        bool knownclass;
     329        SString myclassname, myclassparams;
     330        /** set myclass and make knownclass=true */
     331        void checkClass();
     332        SString** inputInfo(int i);
     333        void defassign();
     334
     335public:
     336        enum NeuroFlags { HoldState = 2 };
     337        Param properties();
     338        Param extraProperties();
     339
     340        void setInputInfo(int i, const SString& name, const SString &value);
     341        void setInputInfo(int i, const SString& name, int value);
     342        void setInputInfo(int i, const SString& name, double value);
     343        SString getInputInfo(int i);
     344        SString getInputInfo(int i, const SString& name);
     345
     346        NeuroClass* getClass();
     347        void setClass(NeuroClass*);
     348
     349        SString getClassParams() { return myclassparams; }
     350        void setClassParams(const SString& cp) { myclassparams = cp; }
     351
     352        SString getClassName();
     353        void setClassName(const SString& clazz);
     354
     355        /** return neuro unit details encoded as <CLASS> ":" <PROPERTIES>
     356
     357                new Neuro can be created as root object (without parent) or can be
     358                the child of existing Neuro. Children of the Neuro are its inputs.
     359                Standard Framsticks neuron calculates the sum of all input units - other processing
     360                units don't have to treat them equally and can even ignore some of them.
     361                There are hints about expected inputs in the class database, @see getClass
     362
     363                Application should not assume anything about classes and its properties
     364                except for two standard classes: (information about all current classes
     365                can be retrieved with getClass/getClassProperties methods)
     366                - getClassName()="N" is the standard Framsticks neuron, accepts any number of inputs,
     367                compatible with old Neuro object
     368                - getClassName()="-" is the neuron link, compatible with old Neuro-Neuro link
     369                (NeuroItem with empty details)
     370                Empty details defaults to "-" if the parent unit is specified,
     371                and "N" if the unit has no parent.
     372                */
     373        SString getDetails();
     374
     375        /** details = classname + ":" + classparams
     376                @see getDetails()
     377                */
     378        void setDetails(const SString&);
    365379
    366380#define STATRICKCLASS Neuro
    367 PARAMGETDEF(details) {arg1->setString(getDetails());}
    368 PARAMSETDEF(details) {setDetails(arg1->getString());return PSET_CHANGED;}
    369 PARAMGETDEF(inputCount);
    370 PARAMPROCDEF(p_getInputNeuroDef);
    371 PARAMPROCDEF(p_getInputNeuroIndex);
    372 PARAMPROCDEF(p_getInputWeight);
    373 PARAMGETDEF(classObject);
     381        PARAMGETDEF(details) { arg1->setString(getDetails()); }
     382        PARAMSETDEF(details) { setDetails(arg1->getString()); return PSET_CHANGED; }
     383        PARAMGETDEF(inputCount);
     384        PARAMPROCDEF(p_getInputNeuroDef);
     385        PARAMPROCDEF(p_getInputNeuroIndex);
     386        PARAMPROCDEF(p_getInputWeight);
     387        PARAMGETDEF(classObject);
    374388#undef STATRICKCLASS
    375389
    376 ///@param handle_defaults_when_saving see SyntParam
    377 SyntParam classProperties(bool handle_defaults_when_saving=true);
    378 // base properties:
    379 paInt refno; ///< unique reference number (former 'neuro' refno)
    380 
    381 paInt part_refno; ///< can be used by some items as the part ref#
    382 paInt joint_refno; ///< can be used by some items as the joint ref#
    383 
    384 Pt3D pos,rot;   ///< default = zero
    385 
    386 ModelUserTags userdata;
    387 
    388 Neuro();
    389 Neuro(double _state,double _inertia,double _force,double _sigmo);
    390 Neuro(const Neuro& src):PartBase(getDefaultStyle()) {operator=(src);}
    391 
    392 ~Neuro();
    393 
    394 void operator=(const Neuro& src);
    395 
    396 /** Attach this Neuro to the specified Part or detach it from the body if p==NULL.
    397     Neuro can be attached to either Part or Joint, but not both.
    398     @see getPart()
    399  */
    400 void attachToPart(Part* p) {part=p; joint=0;}
    401 
    402 /** Attach this Neuro to the specified Joint or detach it from the body if p==NULL.
    403     Neuro can be attached to either Part or Joint, but not both.
    404     @see getJoint()
    405  */
    406 void attachToJoint(Joint* j) {joint=j; part=0;}
    407 
    408 void attachToPart(int i);
    409 void attachToJoint(int i);
    410 
    411 /** @return Part the Neuro is attached to, or NULL if it has no defined location on the body.
    412     @see attachToPart()
    413  */
    414 Part *getPart() {return part;}
    415 
    416 /** @return Joint the Neuro is attached to, or NULL if it has no defined location on the body.
    417     @see attachToJoint()
    418  */
    419 Joint *getJoint() {return joint;}
    420 
    421 int isOldEffector();
    422 int isOldReceptor();
    423 int isOldNeuron();
    424 int isNNConnection();
    425 
    426 /** @return the number of inputs connected to this Neuro.
    427     Functions like getInput(), getInputWeight() will accept connection number [0..InputCount-1]
    428  */
    429 int getInputCount() const {return inputs.size();}
    430 
    431 /// @return the number of output connections (including possible self-connections)
    432 int getOutputsCount() const;
    433 
    434 /** @return the Neuro connected as i-th input */
    435 Neuro* getInput(int i) const {return (i>=inputs.size())?0:inputs(i).n;}
    436 /** @return the Neuro connected as i-th input.
    437     @param weight
    438  */
    439 Neuro* getInput(int i,double &weight) const;
    440 /** @return connectin weight for i-th input */
    441 double getInputWeight(int i) const;
    442 /** change connection weight for i-th input */
    443 void setInputWeight(int i,double weight);
    444 /** connect i-th input with another neuron */
    445 void setInput(int i,Neuro*n);
    446 /** connect i-th input with another neuron */
    447 void setInput(int i,Neuro*n,double weight);
    448 /** add new input. @return its reference number */
    449 int addInput(Neuro* child,double weight=1.0,const SString* info=0);
    450 /** @return reference number [0..InputCount-1] of the input
    451    or -1 if 'child' is not connected with this Neuro.*/
    452 int findInput(Neuro* child) const;
    453 void removeInput(paInt refno);
    454 /**    @return reference number of the child connection, like findInput() */
    455 int removeInput(Neuro* child);
    456 
    457 int findInputs(SList& result,const char* classname=0,const Part* part=0,const Joint* joint=0) const;
    458 int findOutputs(SList& result,const char* classname=0,const Part* part=0,const Joint* joint=0) const;
    459 
    460 /* class database retrieval */
    461 static int getClassCount();
    462 /** @return Neuro class name.
    463     @param classindex 0 .. getClassCount()
    464  */
    465 static SString getClassName(int classindex);
    466 static NeuroClass* getClass(int classindex);
    467 static NeuroClass* getClass(const SString& classname);
    468 static int getClassIndex(const NeuroClass*nc);
     390        ///@param handle_defaults_when_saving see SyntParam
     391        SyntParam classProperties(bool handle_defaults_when_saving = true);
     392        // base properties:
     393        paInt refno; ///< unique reference number (former 'neuro' refno)
     394
     395        paInt part_refno; ///< can be used by some items as the part ref#
     396        paInt joint_refno; ///< can be used by some items as the joint ref#
     397
     398        Pt3D pos, rot;  ///< default = zero
     399
     400        ModelUserTags userdata;
     401
     402        Neuro();
     403        Neuro(double _state, double _inertia, double _force, double _sigmo);
     404        Neuro(const Neuro& src) :PartBase(getDefaultStyle()) { operator=(src); }
     405
     406        ~Neuro();
     407
     408        void operator=(const Neuro& src);
     409
     410        /** Attach this Neuro to the specified Part or detach it from the body if p==NULL.
     411                Neuro can be attached to either Part or Joint, but not both.
     412                @see getPart()
     413                */
     414        void attachToPart(Part* p) { part = p; joint = 0; }
     415
     416        /** Attach this Neuro to the specified Joint or detach it from the body if p==NULL.
     417                Neuro can be attached to either Part or Joint, but not both.
     418                @see getJoint()
     419                */
     420        void attachToJoint(Joint* j) { joint = j; part = 0; }
     421
     422        void attachToPart(int i);
     423        void attachToJoint(int i);
     424
     425        /** @return Part the Neuro is attached to, or NULL if it has no defined location on the body.
     426                @see attachToPart()
     427                */
     428        Part *getPart() { return part; }
     429
     430        /** @return Joint the Neuro is attached to, or NULL if it has no defined location on the body.
     431                @see attachToJoint()
     432                */
     433        Joint *getJoint() { return joint; }
     434
     435        int isOldEffector();
     436        int isOldReceptor();
     437        int isOldNeuron();
     438        int isNNConnection();
     439
     440        /** @return the number of inputs connected to this Neuro.
     441                Functions like getInput(), getInputWeight() will accept connection number [0..InputCount-1]
     442                */
     443        int getInputCount() const { return inputs.size(); }
     444
     445        /// @return the number of output connections (including possible self-connections)
     446        int getOutputsCount() const;
     447
     448        /** @return the Neuro connected as i-th input */
     449        Neuro* getInput(int i) const { return (i >= inputs.size()) ? 0 : inputs(i).n; }
     450        /** @return the Neuro connected as i-th input.
     451                @param weight
     452                */
     453        Neuro* getInput(int i, double &weight) const;
     454        /** @return connectin weight for i-th input */
     455        double getInputWeight(int i) const;
     456        /** change connection weight for i-th input */
     457        void setInputWeight(int i, double weight);
     458        /** connect i-th input with another neuron */
     459        void setInput(int i, Neuro*n);
     460        /** connect i-th input with another neuron */
     461        void setInput(int i, Neuro*n, double weight);
     462        /** add new input. @return its reference number */
     463        int addInput(Neuro* child, double weight = 1.0, const SString* info = 0);
     464        /** @return reference number [0..InputCount-1] of the input
     465           or -1 if 'child' is not connected with this Neuro.*/
     466        int findInput(Neuro* child) const;
     467        void removeInput(paInt refno);
     468        /**    @return reference number of the child connection, like findInput() */
     469        int removeInput(Neuro* child);
     470
     471        int findInputs(SList& result, const char* classname = 0, const Part* part = 0, const Joint* joint = 0) const;
     472        int findOutputs(SList& result, const char* classname = 0, const Part* part = 0, const Joint* joint = 0) const;
     473
     474        /* class database retrieval */
     475        static int getClassCount();
     476        /** @return Neuro class name.
     477                @param classindex 0 .. getClassCount()
     478                */
     479        static SString getClassName(int classindex);
     480        static NeuroClass* getClass(int classindex);
     481        static NeuroClass* getClass(const SString& classname);
     482        static int getClassIndex(const NeuroClass*nc);
    469483
    470484#ifdef MODEL_V1_COMPATIBLE
    471 friend class OldItems;
    472 paInt neuro_refno; ///< parent ref# (called neuro_refno for compatibility with old Neuro class), @see moredata
    473 paInt conn_refno; ///< the other neuron ref# in N-N connections, can be used by some other items
    474 double weight; ///< weight of the N-N connection and (all?) receptors
    475 double inertia,force,sigmo; //!!!
    476 
    477 /** @deprecated provided only for compatibility with old Neuro/NeuroItem classes.
    478     use getInputCount() instead. @sa getInputCount() */
    479 int getItemCount() {return oldItems().getItemCount();}
    480 
    481 /** @deprecated provided only for compatibility with old Neuro/NeuroItem classes.
    482     use getInput() instead. @sa getInput() */
    483 NeuroItem* getNeuroItem(int i) {return oldItems().getNeuroItem(i);}
     485        friend class OldItems;
     486        paInt neuro_refno; ///< parent ref# (called neuro_refno for compatibility with old Neuro class), @see moredata
     487        paInt conn_refno; ///< the other neuron ref# in N-N connections, can be used by some other items
     488        double weight; ///< weight of the N-N connection and (all?) receptors
     489        double inertia,force,sigmo; //!!!
     490
     491        /** @deprecated provided only for compatibility with old Neuro/NeuroItem classes.
     492                use getInputCount() instead. @sa getInputCount() */
     493        int getItemCount() {return oldItems().getItemCount();}
     494
     495        /** @deprecated provided only for compatibility with old Neuro/NeuroItem classes.
     496                use getInput() instead. @sa getInput() */
     497        NeuroItem* getNeuroItem(int i) {return oldItems().getNeuroItem(i);}
    484498#endif
    485499
    486   protected:
     500protected:
    487501#ifdef MODEL_V1_COMPATIBLE
    488 /** old Neuro compatibility */
    489 OldItems* olditems;
    490 OldItems& oldItems() {if (!olditems) olditems=new OldItems(*this); return *olditems;}
    491 void invalidateOldItems() {if (olditems) olditems->freelist();}
     502        /** old Neuro compatibility */
     503        OldItems* olditems;
     504        OldItems& oldItems() {if (!olditems) olditems=new OldItems(*this); return *olditems;}
     505        void invalidateOldItems() {if (olditems) olditems->freelist();}
    492506#endif
    493507
    494   public:
    495 
    496 // not really private, but you should not access those directly
    497 double state;
    498 
    499 /** may reference parent neuron if parentcount is exacty 1. parent is invalid otherwise. @sa parentcount */
    500 Neuro *parent;
    501 int parentcount; ///< @sa parent
    502 
    503 Part *part;     ///< link to the Part
    504 Joint *joint;   ///< link to the Joint - required by some objects (eg.muscles)
    505 Orient o;       ///< rotation matrix calculated from "rot"
    506 static ParamEntry emptyParamTab[];
    507 static Param& getStaticParam();
     508public:
     509
     510        // not really private, but you should not access those directly
     511        double state;
     512
     513        /** may reference parent neuron if parentcount is exacty 1. parent is invalid otherwise. @sa parentcount */
     514        Neuro *parent;
     515        int parentcount; ///< @sa parent
     516
     517        Part *part;     ///< link to the Part
     518        Joint *joint;   ///< link to the Joint - required by some objects (eg.muscles)
     519        Orient o;       ///< rotation matrix calculated from "rot"
     520        static ParamEntry emptyParamTab[];
     521        static Param& getStaticParam();
    508522};
    509523
     
    515529{
    516530public:
    517 NeuroItem() {}
     531        NeuroItem() {}
    518532};
    519533#endif
    520534
    521 class NeuroExt: public Neuro
    522 {
    523   public:
     535class NeuroExt : public Neuro
     536{
     537public:
    524538#define STATRICKCLASS NeuroExt
    525 PARAMGETDEF(neuroclass);
    526 PARAMSETDEF(neuroclass);
     539        PARAMGETDEF(neuroclass);
     540        PARAMSETDEF(neuroclass);
    527541#undef STATRICKCLASS
    528 static ParamEntry *getParamTab();
     542        static ParamEntry *getParamTab();
    529543};
    530544
    531545class NeuroConn
    532546{
    533 void defassign();
    534   public:
    535 int n1_refno,n2_refno;
    536 double weight;
    537 SString info;
    538 NeuroConn();
    539 };
    540 
    541 extern ParamEntry f0_part_paramtab[],f0_joint_paramtab[],f0_nodeltajoint_paramtab[],f0_neuro_paramtab[],f0_neuroconn_paramtab[],f0_neuroitem_paramtab[];
     547        void defassign();
     548public:
     549        int n1_refno, n2_refno;
     550        double weight;
     551        SString info;
     552        NeuroConn();
     553};
     554
     555extern ParamEntry f0_part_paramtab[], f0_joint_paramtab[], f0_nodeltajoint_paramtab[], f0_neuro_paramtab[], f0_neuroconn_paramtab[], f0_neuroitem_paramtab[];
    542556
    543557#endif
Note: See TracChangeset for help on using the changeset viewer.