Changeset 899 for cpp/frams/model
- Timestamp:
- 11/30/19 02:13:25 (5 years ago)
- Location:
- cpp/frams/model
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/model/modelparts.cpp
r844 r899 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 7Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2019 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 74 74 } 75 75 76 void PartBase::setInfo(const SString & name, const SString&value)76 void PartBase::setInfo(const SString &name, const SString &value) 77 77 { 78 78 strSetField(info, name, value); 79 79 } 80 80 81 void PartBase::setInfo(const SString &name, int value)81 void PartBase::setInfo(const SString &name, int value) 82 82 { 83 83 setInfo(name, SString::valueOf(value)); 84 84 } 85 85 86 void PartBase::setInfo(const SString &name, double value)86 void PartBase::setInfo(const SString &name, double value) 87 87 { 88 88 setInfo(name, SString::valueOf(value)); 89 89 } 90 90 91 SString PartBase::getInfo(const SString &name)91 SString PartBase::getInfo(const SString &name) 92 92 { 93 93 return strGetField(info, name); … … 134 134 } 135 135 136 void NeuroClass::setGenActive(const char *genactive_classes[])137 { 138 for (const char **n = genactive_classes; *n; n++)139 { 140 NeuroClass *cls = Neuro::getClass(*n);136 void NeuroClass::setGenActive(const char *genactive_classes[]) 137 { 138 for (const char **n = genactive_classes; *n; n++) 139 { 140 NeuroClass *cls = Neuro::getClass(*n); 141 141 if (cls) cls->genactive = 1; 142 142 } … … 223 223 } 224 224 225 SString **Neuro::inputInfo(int i)225 SString **Neuro::inputInfo(int i) 226 226 { 227 227 if (i >= getInputCount()) return 0; … … 229 229 } 230 230 231 void Neuro::setInputInfo(int i, const SString &name, const SString &value)231 void Neuro::setInputInfo(int i, const SString &name, const SString &value) 232 232 { 233 233 SString **s = inputInfo(i); … … 237 237 } 238 238 239 void Neuro::setInputInfo(int i, const SString &name, int value)239 void Neuro::setInputInfo(int i, const SString &name, int value) 240 240 { 241 241 setInputInfo(i, name, SString::valueOf(value)); 242 242 } 243 243 244 void Neuro::setInputInfo(int i, const SString &name, double value)244 void Neuro::setInputInfo(int i, const SString &name, double value) 245 245 { 246 246 setInputInfo(i, name, SString::valueOf(value)); … … 255 255 } 256 256 257 SString Neuro::getInputInfo(int i, const SString &name)257 SString Neuro::getInputInfo(int i, const SString &name) 258 258 { 259 259 SString **s = inputInfo(i); … … 263 263 } 264 264 265 void Neuro::operator=(const Neuro &src)265 void Neuro::operator=(const Neuro &src) 266 266 { 267 267 refno = src.refno; … … 294 294 } 295 295 296 NeuroClass *Neuro::getClass(int classindex)296 NeuroClass *Neuro::getClass(int classindex) 297 297 { 298 298 return NeuroLibrary::staticlibrary.getClass(classindex); 299 299 } 300 300 301 NeuroClass * Neuro::getClass(const SString&classname)301 NeuroClass *Neuro::getClass(const SString &classname) 302 302 { 303 303 return NeuroLibrary::staticlibrary.findClass(classname); 304 304 } 305 305 306 int Neuro::getClassIndex(const NeuroClass *nc)307 { 308 return NeuroLibrary::staticlibrary.classes.find((void *)nc);309 } 310 311 NeuroClass *Neuro::getClass()306 int Neuro::getClassIndex(const NeuroClass *nc) 307 { 308 return NeuroLibrary::staticlibrary.classes.find((void *)nc); 309 } 310 311 NeuroClass *Neuro::getClass() 312 312 { 313 313 checkClass(); … … 315 315 } 316 316 317 void Neuro::setClass(NeuroClass *cl)317 void Neuro::setClass(NeuroClass *cl) 318 318 { 319 319 myclass = cl; … … 328 328 } 329 329 330 void Neuro::setDetails(const SString &details)330 void Neuro::setDetails(const SString &details) 331 331 { 332 332 int colon = details.indexOf(':'); … … 362 362 } 363 363 364 void Neuro::setClassName(const SString &clazz)364 void Neuro::setClassName(const SString &clazz) 365 365 { 366 366 myclassname = clazz; … … 368 368 } 369 369 370 int Neuro::addInput(Neuro *child, double weight, const SString *info)370 int Neuro::addInput(Neuro *child, double weight, const SString *info) 371 371 { 372 372 inputs += NInput(child, weight, (info && (info->len())) ? new SString(*info) : 0); … … 376 376 } 377 377 378 int Neuro::findInput(Neuro *child) const378 int Neuro::findInput(Neuro *child) const 379 379 { 380 380 for (int i = 0; i < inputs.size(); i++) … … 383 383 } 384 384 385 Neuro *Neuro::getInput(int i, double &weight) const385 Neuro *Neuro::getInput(int i, double &weight) const 386 386 { 387 387 if (i >= getInputCount()) return 0; … … 401 401 } 402 402 403 void Neuro::setInput(int i, Neuro *n)403 void Neuro::setInput(int i, Neuro *n) 404 404 { 405 405 NInput &inp = inputs(i); … … 407 407 } 408 408 409 void Neuro::setInput(int i, Neuro *n, double w)409 void Neuro::setInput(int i, Neuro *n, double w) 410 410 { 411 411 NInput &inp = inputs(i); … … 424 424 } 425 425 426 int Neuro::removeInput(Neuro *child)426 int Neuro::removeInput(Neuro *child) 427 427 { 428 428 int i = findInput(child); … … 463 463 } 464 464 465 int Neuro::findInputs(SList & result, const char* classname, const Part* part, const Joint*joint) const465 int Neuro::findInputs(SList &result, const char *classname, const Part *part, const Joint *joint) const 466 466 { 467 467 Neuro *nu; … … 476 476 if (classname) 477 477 if (nu->getClassName() != cn) continue; 478 result += (void *)nu;478 result += (void *)nu; 479 479 } 480 480 return result.size() - n0; 481 481 } 482 482 483 int Neuro::findOutputs(SList & result, const char* classname, const Part* part, const Joint*joint) const483 int Neuro::findOutputs(SList &result, const char *classname, const Part *part, const Joint *joint) const 484 484 { // not very efficient... 485 485 Neuro *nu, *inp; … … 498 498 if (inp == this) 499 499 { 500 result += (void*)nu;501 break;500 result += (void *)nu; 501 break; 502 502 } 503 503 } … … 576 576 } 577 577 578 void Part::operator=(const Part &src)578 void Part::operator=(const Part &src) 579 579 { 580 580 p = src.p; o = src.o; … … 612 612 Pt3D x = p2 - p1; 613 613 Pt3D dir(x.y, x.z, x.x); 614 p = p1 + x *0.5;614 p = p1 + x * 0.5; 615 615 rot.getAngles(x, dir); 616 616 } 617 617 618 Param &Part::getStaticParam()618 Param &Part::getStaticParam() 619 619 { 620 620 static Param p(f0_part_paramtab, 0, "Part"); … … 637 637 } 638 638 639 void Joint::operator=(const Joint &src)639 void Joint::operator=(const Joint &src) 640 640 { 641 641 rot = src.rot; … … 652 652 } 653 653 654 void Joint::attachToParts(Part * p1, Part*p2)654 void Joint::attachToParts(Part *p1, Part *p2) 655 655 { 656 656 part1 = p1; … … 695 695 } 696 696 697 Param &Joint::getStaticParam()697 Param &Joint::getStaticParam() 698 698 { 699 699 static Param p(f0_joint_paramtab, 0, "Joint"); … … 760 760 }; 761 761 762 Param &Neuro::getStaticParam()762 Param &Neuro::getStaticParam() 763 763 { 764 764 static Param p(f0_neuro_paramtab, 0, "NeuroDef"); -
cpp/frams/model/modelparts.h
r844 r899 24 24 class MultiRange; 25 25 26 typedef UserTags<Model, void *, 5> ModelUserTags;26 typedef UserTags<Model, void *, 5> ModelUserTags; 27 27 28 28 /** Common base for model elements. */ … … 31 31 public: 32 32 SString vis_style; 33 PartBase(const SString &s) :vis_style(s), mapped(0) {}33 PartBase(const SString &s) :vis_style(s), mapped(0) {} 34 34 ~PartBase(); 35 static SString getDefaultStyle() { return SString("none"); }35 static SString getDefaultStyle() { return SString("none"); } 36 36 MultiRange *mapped; 37 37 enum PartBaseFlags { Selected = 1 }; … … 48 48 49 49 void clearMapping(); 50 MultiRange *getMapping() { return mapped; }50 MultiRange *getMapping() { return mapped; } 51 51 void setMapping(const IRange &mr); 52 52 void addMapping(const IRange &mr); … … 54 54 void addMapping(const MultiRange &mr); 55 55 56 void setInfo(const SString & name, const SString&value);57 void setInfo(const SString &name, int value);58 void setInfo(const SString &name, double value);59 SString getInfo(const SString &name);56 void setInfo(const SString &name, const SString &value); 57 void setInfo(const SString &name, int value); 58 void setInfo(const SString &name, double value); 59 SString getInfo(const SString &name); 60 60 }; 61 61 … … 94 94 95 95 Part(enum Shape s = SHAPE_BALL_AND_STICK); 96 Part(const Part &src) :PartBase(getDefaultStyle()) { operator=(src); }97 void operator=(const Part &src);96 Part(const Part &src) :PartBase(getDefaultStyle()) { operator=(src); } 97 void operator=(const Part &src); 98 98 99 99 void setPositionAndRotationFromAxis(const Pt3D &p1, const Pt3D &p2); … … 101 101 void setRot(const Pt3D &r);///< set part.rot (rotation angles) and calculate part.o 102 102 103 static Param &getStaticParam();103 static Param &getStaticParam(); 104 104 }; 105 105 … … 128 128 129 129 Joint(); 130 Joint(const Joint &src) :PartBase(getDefaultStyle()) { operator=(src); }131 void operator=(const Joint &src);130 Joint(const Joint &src) :PartBase(getDefaultStyle()) { operator=(src); } 131 void operator=(const Joint &src); 132 132 133 133 /** connect two parts with this joint. … … 135 135 @see isDelta() 136 136 */ 137 void attachToParts(Part * p1, Part*p2);137 void attachToParts(Part *p1, Part *p2); 138 138 /// @see attachToParts(Part*,Part*) 139 139 void attachToParts(int p1, int p2); … … 168 168 Pt3D vcolor; 169 169 170 static Param &getStaticParam();170 static Param &getStaticParam(); 171 171 }; 172 172 173 173 #define JOINT_DELTA_MARKER 99999.0 174 174 175 ////////////////// NN ///////////////// 175 176 177 ////////////////// Neural Network ///////////////// 176 178 177 179 class NeuroClass; 178 180 179 typedef UserTags<NeuroClass, void *, 5> NeuroClassUserTags;181 typedef UserTags<NeuroClass, void *, 5> NeuroClassUserTags; 180 182 181 183 /** Information about neuron class. … … 184 186 { 185 187 bool ownedvectordata; 186 void operator=(const NeuroClass & nosuchthich){}188 void operator=(const NeuroClass &nosuchthich) {} 187 189 public: 188 190 SString name, longname, description; … … 207 209 /** class name for use in Neuro::setClassName(), Neuro::setDetails() (former 'moredata' field), 208 210 eg. "N","-",G" */ 209 const SString &getName() { return name; }211 const SString &getName() { return name; } 210 212 /** human friendly name, eg. "Neuron","Link","Gyroscope" */ 211 const SString &getLongName() { return longname; }213 const SString &getLongName() { return longname; } 212 214 /** long description */ 213 const SString &getDescription() { return description; }214 ParamEntry *getParamTab() { return props; }215 const SString &getDescription() { return description; } 216 ParamEntry *getParamTab() { return props; } 215 217 216 218 /** NeuroClass specific properties, recognized by all neurons of this class */ … … 240 242 } 241 243 */ 242 int *getSymbolGlyph()244 int *getSymbolGlyph() 243 245 { 244 246 return vectordata; … … 246 248 void setSymbolGlyph(int *data, bool owned = 1) 247 249 { 248 if (vectordata &&ownedvectordata) delete[]vectordata;250 if (vectordata && ownedvectordata) delete[]vectordata; 249 251 vectordata = data; ownedvectordata = owned; 250 252 } … … 282 284 283 285 static void resetActive(); ///< set default values of active and genactive for all classes 284 static void setGenActive(const char* classes[]); ///< set genactive for specified classes 285 }; 286 287 class Neuro; 288 289 /** Single processing unit in Framsticks NN. */ 286 static void setGenActive(const char *classes[]); ///< set genactive for specified classes 287 }; 288 289 290 291 292 293 294 /** Single processing unit in Framsticks neural network. */ 290 295 class Neuro : public PartBase 291 296 { … … 305 310 /** set myclass and make knownclass=true */ 306 311 void checkClass(); 307 SString **inputInfo(int i);312 SString **inputInfo(int i); 308 313 void defassign(); 309 314 … … 313 318 Param extraProperties(); 314 319 315 void setInputInfo(int i, const SString &name, const SString &value);316 void setInputInfo(int i, const SString &name, int value);317 void setInputInfo(int i, const SString &name, double value);320 void setInputInfo(int i, const SString &name, const SString &value); 321 void setInputInfo(int i, const SString &name, int value); 322 void setInputInfo(int i, const SString &name, double value); 318 323 SString getInputInfo(int i); 319 SString getInputInfo(int i, const SString &name);320 321 NeuroClass *getClass();322 void setClass(NeuroClass *);324 SString getInputInfo(int i, const SString &name); 325 326 NeuroClass *getClass(); 327 void setClass(NeuroClass *); 323 328 324 329 SString getClassParams() { return myclassparams; } 325 void setClassParams(const SString &cp) { myclassparams = cp; }330 void setClassParams(const SString &cp) { myclassparams = cp; } 326 331 327 332 SString getClassName(); 328 void setClassName(const SString &clazz);333 void setClassName(const SString &clazz); 329 334 330 335 /** return neuro unit details encoded as <CLASS> ":" <PROPERTIES> … … 351 356 @see getDetails() 352 357 */ 353 void setDetails(const SString &);358 void setDetails(const SString &); 354 359 355 360 #define STATRICKCLASS Neuro … … 377 382 Neuro(); 378 383 Neuro(double _state, double _inertia, double _force, double _sigmo); 379 Neuro(const Neuro &src) :PartBase(getDefaultStyle()) { operator=(src); }384 Neuro(const Neuro &src) :PartBase(getDefaultStyle()) { operator=(src); } 380 385 381 386 ~Neuro(); 382 387 383 void operator=(const Neuro &src);388 void operator=(const Neuro &src); 384 389 385 390 /** Attach this Neuro to the specified Part or detach it from the body if p==NULL. … … 387 392 @see getPart() 388 393 */ 389 void attachToPart(Part *p) { part = p; joint = 0; }394 void attachToPart(Part *p) { part = p; joint = 0; } 390 395 391 396 /** Attach this Neuro to the specified Joint or detach it from the body if p==NULL. … … 393 398 @see getJoint() 394 399 */ 395 void attachToJoint(Joint *j) { joint = j; part = 0; }400 void attachToJoint(Joint *j) { joint = j; part = 0; } 396 401 397 402 void attachToPart(int i); … … 422 427 423 428 /** @return the Neuro connected as i-th input */ 424 Neuro *getInput(int i) const { return (i >= inputs.size()) ? 0 : inputs(i).n; }429 Neuro *getInput(int i) const { return (i >= inputs.size()) ? 0 : inputs(i).n; } 425 430 /** @return the Neuro connected as i-th input. 426 431 @param weight 427 432 */ 428 Neuro *getInput(int i, double &weight) const;433 Neuro *getInput(int i, double &weight) const; 429 434 /** @return connectin weight for i-th input */ 430 435 double getInputWeight(int i) const; … … 432 437 void setInputWeight(int i, double weight); 433 438 /** connect i-th input with another neuron */ 434 void setInput(int i, Neuro *n);439 void setInput(int i, Neuro *n); 435 440 /** connect i-th input with another neuron */ 436 void setInput(int i, Neuro *n, double weight);441 void setInput(int i, Neuro *n, double weight); 437 442 /** add new input. @return its reference number */ 438 int addInput(Neuro * child, double weight = 1.0, const SString*info = 0);443 int addInput(Neuro *child, double weight = 1.0, const SString *info = 0); 439 444 /** @return reference number [0..InputCount-1] of the input 440 445 or -1 if 'child' is not connected with this Neuro.*/ 441 int findInput(Neuro *child) const;446 int findInput(Neuro *child) const; 442 447 void removeInput(paInt refno); 443 448 /** @return reference number of the child connection, like findInput() */ 444 int removeInput(Neuro *child);445 446 int findInputs(SList & result, const char* classname = 0, const Part* part = 0, const Joint*joint = 0) const;447 int findOutputs(SList & result, const char* classname = 0, const Part* part = 0, const Joint*joint = 0) const;449 int removeInput(Neuro *child); 450 451 int findInputs(SList &result, const char *classname = 0, const Part *part = 0, const Joint *joint = 0) const; 452 int findOutputs(SList &result, const char *classname = 0, const Part *part = 0, const Joint *joint = 0) const; 448 453 449 454 /* class database retrieval */ … … 453 458 */ 454 459 static SString getClassName(int classindex); 455 static NeuroClass *getClass(int classindex);456 static NeuroClass * getClass(const SString&classname);457 static int getClassIndex(const NeuroClass *nc);460 static NeuroClass *getClass(int classindex); 461 static NeuroClass *getClass(const SString &classname); 462 static int getClassIndex(const NeuroClass *nc); 458 463 459 464 // not really private, but you should not access those directly … … 468 473 Orient o; ///< rotation matrix calculated from "rot" 469 474 static ParamEntry emptyParamTab[]; 470 static Param &getStaticParam();475 static Param &getStaticParam(); 471 476 }; 472 477
Note: See TracChangeset
for help on using the changeset viewer.