[286] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
[920] | 2 | // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. |
---|
[286] | 3 | // See LICENSE.txt for details. |
---|
[109] | 4 | |
---|
| 5 | #ifndef _MODELPARTS_H_ |
---|
| 6 | #define _MODELPARTS_H_ |
---|
| 7 | |
---|
| 8 | #include <frams/util/3d.h> |
---|
[121] | 9 | #include <frams/genetics/genoconv.h> |
---|
[109] | 10 | |
---|
| 11 | #include <frams/util/extvalue.h> |
---|
| 12 | #include <frams/util/list.h> |
---|
| 13 | #include <frams/util/sstring.h> |
---|
| 14 | #include <frams/util/sstringutils.h> |
---|
| 15 | #include <frams/param/param.h> |
---|
| 16 | #include <frams/param/syntparam.h> |
---|
| 17 | #include <frams/util/usertags.h> |
---|
| 18 | #include <frams/param/paramtabobj.h> |
---|
| 19 | |
---|
| 20 | #include <stdio.h> |
---|
| 21 | |
---|
| 22 | class Model; |
---|
| 23 | class IRange; |
---|
| 24 | class MultiRange; |
---|
| 25 | |
---|
[899] | 26 | typedef UserTags<Model, void *, 5> ModelUserTags; |
---|
[109] | 27 | |
---|
[934] | 28 | |
---|
| 29 | /// Introduced only because we can't have a forward declaration of enum in the Model class, |
---|
| 30 | /// and we would need a forward declaration because of mutual (cyclic) dependence of declarations of Model and NeuroClass. |
---|
| 31 | /// https://stackoverflow.com/questions/27019292/is-in-class-enum-forward-declaration-possible |
---|
| 32 | /// Use Model::... instead of ModelEnum::... |
---|
| 33 | class ModelEnum |
---|
| 34 | { |
---|
| 35 | public: |
---|
| 36 | enum ShapeType { SHAPE_BALL_AND_STICK, SHAPE_SOLIDS, SHAPE_UNKNOWN, SHAPE_ILLEGAL }; |
---|
| 37 | }; |
---|
| 38 | |
---|
| 39 | |
---|
[109] | 40 | /** Common base for model elements. */ |
---|
| 41 | class PartBase |
---|
| 42 | { |
---|
| 43 | public: |
---|
[714] | 44 | SString vis_style; |
---|
[899] | 45 | PartBase(const SString &s) :vis_style(s), mapped(0) {} |
---|
[714] | 46 | ~PartBase(); |
---|
[899] | 47 | static SString getDefaultStyle() { return SString("none"); } |
---|
[714] | 48 | MultiRange *mapped; |
---|
| 49 | enum PartBaseFlags { Selected = 1 }; |
---|
| 50 | int flags; |
---|
| 51 | Model *owner; ///< backlink to the model |
---|
[109] | 52 | |
---|
[714] | 53 | SString info; |
---|
[109] | 54 | |
---|
[714] | 55 | Model &getModel() const { return *owner; } |
---|
[109] | 56 | |
---|
[714] | 57 | ModelUserTags userdata; |
---|
[109] | 58 | |
---|
[714] | 59 | void notifyMappingChange(); |
---|
[109] | 60 | |
---|
[714] | 61 | void clearMapping(); |
---|
[899] | 62 | MultiRange *getMapping() { return mapped; } |
---|
[714] | 63 | void setMapping(const IRange &mr); |
---|
| 64 | void addMapping(const IRange &mr); |
---|
| 65 | void setMapping(const MultiRange &mr); |
---|
| 66 | void addMapping(const MultiRange &mr); |
---|
[109] | 67 | |
---|
[899] | 68 | void setInfo(const SString &name, const SString &value); |
---|
| 69 | void setInfo(const SString &name, int value); |
---|
| 70 | void setInfo(const SString &name, double value); |
---|
| 71 | SString getInfo(const SString &name); |
---|
[109] | 72 | }; |
---|
| 73 | |
---|
[408] | 74 | /// Part is the only real physical object in the Framsticks creature. |
---|
[109] | 75 | /// You can use this class for querying and adjusting constructed |
---|
| 76 | /// model properties |
---|
[714] | 77 | class Part : public PartBase |
---|
[109] | 78 | { |
---|
[714] | 79 | friend class Model; |
---|
| 80 | static SString getDefaultStyle(); |
---|
| 81 | Part(double _mass, double _size, double _density, double _friction, double _ingest, double _assim) |
---|
| 82 | :PartBase(getDefaultStyle()), mass(_mass), size(_size), density(_density), friction(_friction), ingest(_ingest), assim(_assim) |
---|
[109] | 83 | {} |
---|
[714] | 84 | void defassign(); |
---|
[109] | 85 | public: |
---|
[714] | 86 | // base properties - have special meaning and therefore are often accessed directly for convenience |
---|
| 87 | Pt3D p; ///< 3d coordinates of the part |
---|
| 88 | Orient o; ///< orientation in 3d space (rotation matrix) |
---|
| 89 | /// ParamInterface object is preferred way to get/set other properties. |
---|
| 90 | Param extraProperties(); |
---|
| 91 | Param properties(); |
---|
| 92 | paInt refno; |
---|
| 93 | Pt3D rot;///< rotation angles |
---|
[109] | 94 | |
---|
[714] | 95 | /// |
---|
| 96 | paInt shape;///default=old Framsticks compatible, do not mix with shapes>0 |
---|
| 97 | enum Shape { SHAPE_BALL_AND_STICK = 0, SHAPE_ELLIPSOID = 1, SHAPE_CUBOID = 2, SHAPE_CYLINDER = 3 }; |
---|
| 98 | double mass, size, density, friction, ingest, assim, hollow; |
---|
| 99 | Pt3D scale; |
---|
| 100 | Pt3D food; |
---|
| 101 | //SList points; // collistion points |
---|
| 102 | //Slist neurons; // "select * from owner->neurons where part=this" ;-) |
---|
[109] | 103 | |
---|
[714] | 104 | Pt3D vcolor; |
---|
| 105 | double vsize; |
---|
[109] | 106 | |
---|
[714] | 107 | Part(enum Shape s = SHAPE_BALL_AND_STICK); |
---|
[899] | 108 | Part(const Part &src) :PartBase(getDefaultStyle()) { operator=(src); } |
---|
| 109 | void operator=(const Part &src); |
---|
[109] | 110 | |
---|
[714] | 111 | void setPositionAndRotationFromAxis(const Pt3D &p1, const Pt3D &p2); |
---|
| 112 | void setOrient(const Orient &o);///< set part.o and calculates part.rot (rotation angles) |
---|
| 113 | void setRot(const Pt3D &r);///< set part.rot (rotation angles) and calculate part.o |
---|
[109] | 114 | |
---|
[899] | 115 | static Param &getStaticParam(); |
---|
[109] | 116 | }; |
---|
| 117 | |
---|
[934] | 118 | class Part_MinMaxDef : public Part //contains additional information for Model::getMinPart()/getMaxPart()/getDefPart() |
---|
| 119 | { |
---|
| 120 | public: |
---|
| 121 | double volume; ///< Introduced to limit the range of volumes (~mass) in simulation of solids. Genetic operators should observe this min,max volume by calculating and limiting the volume of Parts based on their type and sx,sy,sz. |
---|
| 122 | |
---|
| 123 | void defassign(); |
---|
| 124 | Part_MinMaxDef() { defassign(); } |
---|
| 125 | }; |
---|
| 126 | |
---|
[109] | 127 | /// Imaginary connection between two parts. |
---|
| 128 | /// Joint has no mass nor intertia but can transfer forces. |
---|
[714] | 129 | class Joint : public PartBase |
---|
[109] | 130 | { |
---|
[714] | 131 | friend class Model; |
---|
| 132 | SString getDefaultStyle(); |
---|
| 133 | Joint(double _stamina, double _stif, double _rotstif, double _d) |
---|
| 134 | :PartBase(getDefaultStyle()), stamina(_stamina), stif(_stif), rotstif(_rotstif) |
---|
| 135 | { |
---|
| 136 | d = Pt3D(_d, 0, 0); |
---|
| 137 | } |
---|
| 138 | void defassign(); |
---|
| 139 | void resetDeltaMarkers(); |
---|
[109] | 140 | public: |
---|
[714] | 141 | // base properties: |
---|
| 142 | paInt p1_refno, p2_refno; ///< parts' reference numbers |
---|
[109] | 143 | |
---|
[714] | 144 | Part *part1, *part2; ///< references to parts |
---|
| 145 | class Pt3D d; ///< position delta between parts |
---|
| 146 | class Pt3D rot; ///< orientation delta between parts expressed as 3 angles |
---|
[932] | 147 | enum Shape { |
---|
| 148 | SHAPE_BALL_AND_STICK = 0, ///< old Framsticks compatible, creates a physical rod between parts (cylinder or cuboid), do not mix with part.shape>0 |
---|
| 149 | SHAPE_FIXED = 1, ///< merge parts into one physical entity |
---|
| 150 | SHAPE_HINGE_X = 2, ///< hinge connection, revolving around X axis defined by hinge_pos and hinge_rot |
---|
| 151 | SHAPE_HINGE_XY = 3 ///< double hinge connection, revolving around X and Y axes defined by hinge_pos and hinge_rot |
---|
| 152 | }; |
---|
[915] | 153 | paInt shape;///< values of type Shape (paInt for integration with Param) |
---|
| 154 | class Pt3D hinge_pos; ///< hinge position (relative to part1) for HINGE_X and HINGE_XY |
---|
| 155 | class Pt3D hinge_rot; ///< hinge orientation (relative to part1) for HINGE_X and HINGE_XY |
---|
| 156 | double hinge_limit_x[2], hinge_limit_y[2]; ///< hinge movement range - i.e., extreme allowed values of a state. A state can be an angle or other physical property. limit[0] <= 0 <= limit[1]. Relative Part position and orientation as set in the Model define the initial state 0. |
---|
[109] | 157 | |
---|
[714] | 158 | Joint(); |
---|
[899] | 159 | Joint(const Joint &src) :PartBase(getDefaultStyle()) { operator=(src); } |
---|
| 160 | void operator=(const Joint &src); |
---|
[109] | 161 | |
---|
[714] | 162 | /** connect two parts with this joint. |
---|
| 163 | p2 position will be adjusted if delta option is in effect. |
---|
| 164 | @see isDelta() |
---|
| 165 | */ |
---|
[899] | 166 | void attachToParts(Part *p1, Part *p2); |
---|
[714] | 167 | /// @see attachToParts(Part*,Part*) |
---|
| 168 | void attachToParts(int p1, int p2); |
---|
[109] | 169 | |
---|
[714] | 170 | /** discard delta information but don't disable delta flag. |
---|
| 171 | delta will be calculated from parts positions during final consistency check. |
---|
| 172 | */ |
---|
| 173 | void resetDelta(); |
---|
[109] | 174 | |
---|
[714] | 175 | /** enable or disable delta option. |
---|
| 176 | delta value is not changed. |
---|
| 177 | */ |
---|
| 178 | void useDelta(bool use); |
---|
[109] | 179 | |
---|
[714] | 180 | /** @return true if delta option is in effect. |
---|
| 181 | @see useDelta(), resetDelta(), useDelta() |
---|
| 182 | */ |
---|
| 183 | bool isDelta(); |
---|
[109] | 184 | |
---|
[714] | 185 | /// ParamInterface object is preferred way to get/set other properties. |
---|
| 186 | Param extraProperties(); |
---|
| 187 | Param properties(); |
---|
[109] | 188 | |
---|
[714] | 189 | // do not touch these: |
---|
| 190 | paInt refno; ///< this joint's reference number |
---|
| 191 | double stamina; |
---|
| 192 | double stif, rotstif; ///< stiffness for moving and bending forces |
---|
| 193 | class Orient o; ///< orientation delta between parts as rotation matrix |
---|
| 194 | /** flag: generated f0 should include delta data. |
---|
| 195 | set by 'singlestep' if j: attributes use delta option */ |
---|
| 196 | bool usedelta; |
---|
| 197 | Pt3D vcolor; |
---|
[109] | 198 | |
---|
[899] | 199 | static Param &getStaticParam(); |
---|
[109] | 200 | }; |
---|
| 201 | |
---|
| 202 | #define JOINT_DELTA_MARKER 99999.0 |
---|
| 203 | |
---|
| 204 | |
---|
[899] | 205 | |
---|
| 206 | ////////////////// Neural Network ///////////////// |
---|
| 207 | |
---|
[109] | 208 | class NeuroClass; |
---|
| 209 | |
---|
[899] | 210 | typedef UserTags<NeuroClass, void *, 5> NeuroClassUserTags; |
---|
[109] | 211 | |
---|
| 212 | /** Information about neuron class. |
---|
| 213 | */ |
---|
| 214 | class NeuroClass |
---|
| 215 | { |
---|
[714] | 216 | bool ownedvectordata; |
---|
[899] | 217 | void operator=(const NeuroClass &nosuchthich) {} |
---|
[714] | 218 | public: |
---|
| 219 | SString name, longname, description; |
---|
| 220 | ParamEntry *props; |
---|
| 221 | bool ownedprops;//< destructor will free props using ParamObject::freeParamTab |
---|
| 222 | paInt prefinputs, prefoutput; |
---|
| 223 | paInt preflocation; |
---|
[932] | 224 | |
---|
| 225 | static constexpr int SUPPORTED_SHAPE_BALL_AND_STICK = 1; |
---|
| 226 | static constexpr int SUPPORTED_SHAPE_SOLIDS = 2; |
---|
| 227 | static constexpr int SUPPORTED_SHAPE_ALL = SUPPORTED_SHAPE_BALL_AND_STICK | SUPPORTED_SHAPE_SOLIDS; |
---|
| 228 | paInt supported_shape_types; //< bitfield of 'Model::shape' values: NeuroClass::SUPPORTED_SHAPE_xxx = 1 << Model::SHAPE_xxx |
---|
[714] | 229 | int *vectordata; |
---|
| 230 | paInt visualhints; |
---|
[109] | 231 | |
---|
[714] | 232 | //void *impl; |
---|
| 233 | int impl_count; |
---|
| 234 | bool active; |
---|
| 235 | bool genactive; |
---|
| 236 | NeuroClassUserTags userdata; |
---|
[109] | 237 | |
---|
[714] | 238 | ////////////////////// |
---|
| 239 | ~NeuroClass(); |
---|
| 240 | NeuroClass(); |
---|
| 241 | NeuroClass(ParamEntry *_props, SString _description, |
---|
[932] | 242 | int _prefinputs, int _prefoutput, int _preflocation, int *_vectordata, bool own_vd = 1, int vhints = 0, int sup_shapes = NeuroClass::SUPPORTED_SHAPE_ALL); |
---|
[714] | 243 | /** class name for use in Neuro::setClassName(), Neuro::setDetails() (former 'moredata' field), |
---|
| 244 | eg. "N","-",G" */ |
---|
[899] | 245 | const SString &getName() { return name; } |
---|
[714] | 246 | /** human friendly name, eg. "Neuron","Link","Gyroscope" */ |
---|
[899] | 247 | const SString &getLongName() { return longname; } |
---|
[714] | 248 | /** long description */ |
---|
[899] | 249 | const SString &getDescription() { return description; } |
---|
| 250 | ParamEntry *getParamTab() { return props; } |
---|
[109] | 251 | |
---|
[714] | 252 | /** NeuroClass specific properties, recognized by all neurons of this class */ |
---|
| 253 | Param getProperties() { return Param(props); } |
---|
[109] | 254 | |
---|
[714] | 255 | /** preferred number of inputs, -1 = no preference (any number will go). |
---|
| 256 | extra inputs may be ignored by the object (depends on the class). |
---|
| 257 | */ |
---|
| 258 | int getPreferredInputs() { return (int)prefinputs; } |
---|
[109] | 259 | |
---|
[714] | 260 | /** @return 0 if this object doesn't provide useful output signal. */ |
---|
| 261 | int getPreferredOutput() { return (int)prefoutput; } |
---|
[109] | 262 | |
---|
[714] | 263 | /** @return 0 if the object doesn't need any assignment to the body element. |
---|
| 264 | @return 1 = it likes to be attached to the Part ( @see Neuro::attachToPart() ) |
---|
| 265 | @return 2 = the object prefers to have the Joint ( @see Neuro::attachToJoint() ) |
---|
| 266 | */ |
---|
| 267 | int getPreferredLocation() { return (int)preflocation; } |
---|
| 268 | /** vector drawing to be used in neuro net diagram. |
---|
| 269 | interpretation: |
---|
| 270 | { |
---|
| 271 | LEN = datalength (excluding this number) |
---|
| 272 | NL = number_of_lines |
---|
| 273 | line#1 -> NS = number_of_segments, x1,y1, x2,y2, ... xNS-1,yNS-1, |
---|
| 274 | ... |
---|
| 275 | line#NL -> NS = number_of_segments, x1,y1, x2,y2, ... xNS-1,yNS-1, |
---|
| 276 | } |
---|
| 277 | */ |
---|
[932] | 278 | int getSupportedShapeTypes() { return (int)supported_shape_types; } |
---|
[934] | 279 | bool isShapeTypeSupported(ModelEnum::ShapeType t) { return (1 << (int)t) & supported_shape_types; } |
---|
[899] | 280 | int *getSymbolGlyph() |
---|
[714] | 281 | { |
---|
| 282 | return vectordata; |
---|
| 283 | } |
---|
| 284 | void setSymbolGlyph(int *data, bool owned = 1) |
---|
| 285 | { |
---|
[899] | 286 | if (vectordata && ownedvectordata) delete[]vectordata; |
---|
[714] | 287 | vectordata = data; ownedvectordata = owned; |
---|
| 288 | } |
---|
| 289 | /** additional information about how the neuron should be drawn |
---|
| 290 | used by structure view (and maybe some other components). |
---|
| 291 | return value is defined by the enum Hint |
---|
| 292 | @see enum Hint |
---|
| 293 | */ |
---|
| 294 | int getVisualHints() |
---|
| 295 | { |
---|
| 296 | return (int)visualhints; |
---|
| 297 | } |
---|
[109] | 298 | |
---|
[714] | 299 | enum Hint |
---|
[738] | 300 | { |
---|
[714] | 301 | /** don't draw neurons of this class */ |
---|
| 302 | Invisible = 1, |
---|
| 303 | /** don't draw classname label below the neuron */ |
---|
| 304 | DontShowClass = 2, |
---|
| 305 | /** draw the neuron at the first part when attached to joint (default is in the middle) */ |
---|
| 306 | AtFirstPart = 4, |
---|
| 307 | /** draw the neuron at the second part when attached to joint (default is in the middle) */ |
---|
| 308 | AtSecondPart = 8, |
---|
| 309 | /** use effector colour for this neuro unit */ |
---|
| 310 | EffectorClass = 16, |
---|
| 311 | /** use receptor colour for this neuro unit */ |
---|
| 312 | ReceptorClass = 32, |
---|
[937] | 313 | IsV1BendMuscle = 64, |
---|
| 314 | IsV1RotMuscle = 128, |
---|
| 315 | IsLinearMuscle = 256, |
---|
| 316 | IsSolidMuscle = 512 |
---|
[714] | 317 | }; |
---|
[109] | 318 | |
---|
[714] | 319 | /** textual summary, automatically generated from other properties (like the neuro class tooltip) */ |
---|
| 320 | SString getSummary(); |
---|
| 321 | |
---|
| 322 | static void resetActive(); ///< set default values of active and genactive for all classes |
---|
[899] | 323 | static void setGenActive(const char *classes[]); ///< set genactive for specified classes |
---|
[109] | 324 | }; |
---|
| 325 | |
---|
| 326 | |
---|
[899] | 327 | |
---|
| 328 | |
---|
| 329 | |
---|
| 330 | |
---|
| 331 | /** Single processing unit in Framsticks neural network. */ |
---|
[714] | 332 | class Neuro : public PartBase |
---|
[109] | 333 | { |
---|
[714] | 334 | friend class Model; |
---|
| 335 | static SString getDefaultStyle(); |
---|
[109] | 336 | |
---|
[714] | 337 | struct NInput { |
---|
| 338 | Neuro *n; double weight; SString *info; |
---|
| 339 | NInput(Neuro *_n, double w, SString *i = 0) :n(_n), weight(w), info(i) {} |
---|
| 340 | }; |
---|
[109] | 341 | |
---|
[714] | 342 | SListTempl<NInput> inputs; |
---|
[109] | 343 | |
---|
[714] | 344 | NeuroClass *myclass; |
---|
| 345 | bool knownclass; |
---|
| 346 | SString myclassname, myclassparams; |
---|
| 347 | /** set myclass and make knownclass=true */ |
---|
| 348 | void checkClass(); |
---|
[899] | 349 | SString **inputInfo(int i); |
---|
[714] | 350 | void defassign(); |
---|
[109] | 351 | |
---|
| 352 | public: |
---|
[714] | 353 | enum NeuroFlags { HoldState = 2 }; |
---|
| 354 | Param properties(); |
---|
| 355 | Param extraProperties(); |
---|
[109] | 356 | |
---|
[899] | 357 | void setInputInfo(int i, const SString &name, const SString &value); |
---|
| 358 | void setInputInfo(int i, const SString &name, int value); |
---|
| 359 | void setInputInfo(int i, const SString &name, double value); |
---|
[714] | 360 | SString getInputInfo(int i); |
---|
[899] | 361 | SString getInputInfo(int i, const SString &name); |
---|
[109] | 362 | |
---|
[899] | 363 | NeuroClass *getClass(); |
---|
| 364 | void setClass(NeuroClass *); |
---|
[109] | 365 | |
---|
[714] | 366 | SString getClassParams() { return myclassparams; } |
---|
[899] | 367 | void setClassParams(const SString &cp) { myclassparams = cp; } |
---|
[109] | 368 | |
---|
[714] | 369 | SString getClassName(); |
---|
[899] | 370 | void setClassName(const SString &clazz); |
---|
[109] | 371 | |
---|
[714] | 372 | /** return neuro unit details encoded as <CLASS> ":" <PROPERTIES> |
---|
[109] | 373 | |
---|
[714] | 374 | new Neuro can be created as root object (without parent) or can be |
---|
| 375 | the child of existing Neuro. Children of the Neuro are its inputs. |
---|
| 376 | Standard Framsticks neuron calculates the sum of all input units - other processing |
---|
| 377 | units don't have to treat them equally and can even ignore some of them. |
---|
| 378 | There are hints about expected inputs in the class database, @see getClass |
---|
[109] | 379 | |
---|
[714] | 380 | Application should not assume anything about classes and its properties |
---|
| 381 | except for two standard classes: (information about all current classes |
---|
| 382 | can be retrieved with getClass/getClassProperties methods) |
---|
| 383 | - getClassName()="N" is the standard Framsticks neuron, accepts any number of inputs, |
---|
| 384 | compatible with old Neuro object |
---|
| 385 | - getClassName()="-" is the neuron link, compatible with old Neuro-Neuro link |
---|
| 386 | (NeuroItem with empty details) |
---|
| 387 | Empty details defaults to "-" if the parent unit is specified, |
---|
| 388 | and "N" if the unit has no parent. |
---|
| 389 | */ |
---|
| 390 | SString getDetails(); |
---|
[109] | 391 | |
---|
[714] | 392 | /** details = classname + ":" + classparams |
---|
| 393 | @see getDetails() |
---|
| 394 | */ |
---|
[899] | 395 | void setDetails(const SString &); |
---|
[714] | 396 | |
---|
[109] | 397 | #define STATRICKCLASS Neuro |
---|
[714] | 398 | PARAMGETDEF(details) { arg1->setString(getDetails()); } |
---|
| 399 | PARAMSETDEF(details) { setDetails(arg1->getString()); return PSET_CHANGED; } |
---|
| 400 | PARAMGETDEF(inputCount); |
---|
| 401 | PARAMPROCDEF(p_getInputNeuroDef); |
---|
| 402 | PARAMPROCDEF(p_getInputNeuroIndex); |
---|
| 403 | PARAMPROCDEF(p_getInputWeight); |
---|
| 404 | PARAMGETDEF(classObject); |
---|
[109] | 405 | #undef STATRICKCLASS |
---|
| 406 | |
---|
[714] | 407 | ///@param handle_defaults_when_saving see SyntParam |
---|
| 408 | SyntParam classProperties(bool handle_defaults_when_saving = true); |
---|
| 409 | // base properties: |
---|
| 410 | paInt refno; ///< unique reference number (former 'neuro' refno) |
---|
[109] | 411 | |
---|
[714] | 412 | paInt part_refno; ///< can be used by some items as the part ref# |
---|
| 413 | paInt joint_refno; ///< can be used by some items as the joint ref# |
---|
[109] | 414 | |
---|
[714] | 415 | Pt3D pos, rot; ///< default = zero |
---|
[109] | 416 | |
---|
[714] | 417 | ModelUserTags userdata; |
---|
[109] | 418 | |
---|
[714] | 419 | Neuro(); |
---|
| 420 | Neuro(double _state, double _inertia, double _force, double _sigmo); |
---|
[899] | 421 | Neuro(const Neuro &src) :PartBase(getDefaultStyle()) { operator=(src); } |
---|
[109] | 422 | |
---|
[714] | 423 | ~Neuro(); |
---|
[109] | 424 | |
---|
[899] | 425 | void operator=(const Neuro &src); |
---|
[109] | 426 | |
---|
[714] | 427 | /** Attach this Neuro to the specified Part or detach it from the body if p==NULL. |
---|
| 428 | Neuro can be attached to either Part or Joint, but not both. |
---|
| 429 | @see getPart() |
---|
| 430 | */ |
---|
[899] | 431 | void attachToPart(Part *p) { part = p; joint = 0; } |
---|
[109] | 432 | |
---|
[714] | 433 | /** Attach this Neuro to the specified Joint or detach it from the body if p==NULL. |
---|
| 434 | Neuro can be attached to either Part or Joint, but not both. |
---|
| 435 | @see getJoint() |
---|
| 436 | */ |
---|
[899] | 437 | void attachToJoint(Joint *j) { joint = j; part = 0; } |
---|
[109] | 438 | |
---|
[714] | 439 | void attachToPart(int i); |
---|
| 440 | void attachToJoint(int i); |
---|
[109] | 441 | |
---|
[714] | 442 | /** @return Part the Neuro is attached to, or NULL if it has no defined location on the body. |
---|
| 443 | @see attachToPart() |
---|
| 444 | */ |
---|
| 445 | Part *getPart() { return part; } |
---|
[109] | 446 | |
---|
[714] | 447 | /** @return Joint the Neuro is attached to, or NULL if it has no defined location on the body. |
---|
| 448 | @see attachToJoint() |
---|
| 449 | */ |
---|
| 450 | Joint *getJoint() { return joint; } |
---|
[109] | 451 | |
---|
[714] | 452 | int isOldEffector(); |
---|
| 453 | int isOldReceptor(); |
---|
| 454 | int isOldNeuron(); |
---|
| 455 | int isNNConnection(); |
---|
[109] | 456 | |
---|
[714] | 457 | /** @return the number of inputs connected to this Neuro. |
---|
| 458 | Functions like getInput(), getInputWeight() will accept connection number [0..InputCount-1] |
---|
| 459 | */ |
---|
| 460 | int getInputCount() const { return inputs.size(); } |
---|
[109] | 461 | |
---|
[714] | 462 | /// @return the number of output connections (including possible self-connections) |
---|
| 463 | int getOutputsCount() const; |
---|
[109] | 464 | |
---|
[714] | 465 | /** @return the Neuro connected as i-th input */ |
---|
[899] | 466 | Neuro *getInput(int i) const { return (i >= inputs.size()) ? 0 : inputs(i).n; } |
---|
[714] | 467 | /** @return the Neuro connected as i-th input. |
---|
| 468 | @param weight |
---|
| 469 | */ |
---|
[899] | 470 | Neuro *getInput(int i, double &weight) const; |
---|
[714] | 471 | /** @return connectin weight for i-th input */ |
---|
| 472 | double getInputWeight(int i) const; |
---|
| 473 | /** change connection weight for i-th input */ |
---|
| 474 | void setInputWeight(int i, double weight); |
---|
| 475 | /** connect i-th input with another neuron */ |
---|
[899] | 476 | void setInput(int i, Neuro *n); |
---|
[714] | 477 | /** connect i-th input with another neuron */ |
---|
[899] | 478 | void setInput(int i, Neuro *n, double weight); |
---|
[714] | 479 | /** add new input. @return its reference number */ |
---|
[899] | 480 | int addInput(Neuro *child, double weight = 1.0, const SString *info = 0); |
---|
[714] | 481 | /** @return reference number [0..InputCount-1] of the input |
---|
| 482 | or -1 if 'child' is not connected with this Neuro.*/ |
---|
[899] | 483 | int findInput(Neuro *child) const; |
---|
[714] | 484 | void removeInput(paInt refno); |
---|
| 485 | /** @return reference number of the child connection, like findInput() */ |
---|
[899] | 486 | int removeInput(Neuro *child); |
---|
[109] | 487 | |
---|
[899] | 488 | int findInputs(SList &result, const char *classname = 0, const Part *part = 0, const Joint *joint = 0) const; |
---|
| 489 | int findOutputs(SList &result, const char *classname = 0, const Part *part = 0, const Joint *joint = 0) const; |
---|
[109] | 490 | |
---|
[714] | 491 | /* class database retrieval */ |
---|
| 492 | static int getClassCount(); |
---|
| 493 | /** @return Neuro class name. |
---|
| 494 | @param classindex 0 .. getClassCount() |
---|
| 495 | */ |
---|
| 496 | static SString getClassName(int classindex); |
---|
[899] | 497 | static NeuroClass *getClass(int classindex); |
---|
| 498 | static NeuroClass *getClass(const SString &classname); |
---|
| 499 | static int getClassIndex(const NeuroClass *nc); |
---|
[109] | 500 | |
---|
[714] | 501 | // not really private, but you should not access those directly |
---|
| 502 | double state; |
---|
[109] | 503 | |
---|
[714] | 504 | /** may reference parent neuron if parentcount is exacty 1. parent is invalid otherwise. @sa parentcount */ |
---|
| 505 | Neuro *parent; |
---|
| 506 | int parentcount; ///< @sa parent |
---|
[109] | 507 | |
---|
[714] | 508 | Part *part; ///< link to the Part |
---|
| 509 | Joint *joint; ///< link to the Joint - required by some objects (eg.muscles) |
---|
| 510 | Orient o; ///< rotation matrix calculated from "rot" |
---|
| 511 | static ParamEntry emptyParamTab[]; |
---|
[899] | 512 | static Param &getStaticParam(); |
---|
[109] | 513 | }; |
---|
| 514 | |
---|
[714] | 515 | class NeuroExt : public Neuro |
---|
[109] | 516 | { |
---|
[714] | 517 | public: |
---|
[109] | 518 | #define STATRICKCLASS NeuroExt |
---|
[714] | 519 | PARAMGETDEF(neuroclass); |
---|
| 520 | PARAMSETDEF(neuroclass); |
---|
[952] | 521 | PARAMGETDEF(liveNeuro); |
---|
[109] | 522 | #undef STATRICKCLASS |
---|
[714] | 523 | static ParamEntry *getParamTab(); |
---|
[109] | 524 | }; |
---|
| 525 | |
---|
| 526 | class NeuroConn |
---|
| 527 | { |
---|
[714] | 528 | void defassign(); |
---|
| 529 | public: |
---|
| 530 | int n1_refno, n2_refno; |
---|
| 531 | double weight; |
---|
| 532 | SString info; |
---|
| 533 | NeuroConn(); |
---|
[109] | 534 | }; |
---|
| 535 | |
---|
[934] | 536 | extern ParamEntry f0_part_paramtab[], f0_part_minmaxdef_paramtab[], f0_joint_paramtab[], f0_nodeltajoint_paramtab[], f0_neuro_paramtab[], f0_neuroconn_paramtab[], f0_neuroitem_paramtab[]; |
---|
[109] | 537 | |
---|
| 538 | #endif |
---|