1 | // This file is a part of the Framsticks GDK library.
|
---|
2 | // Copyright (C) 2002-2011 Szymon Ulatowski. See LICENSE.txt for details.
|
---|
3 | // Refer to http://www.framsticks.com/ for further information.
|
---|
4 |
|
---|
5 | #include <stdlib.h>
|
---|
6 | #include <math.h>
|
---|
7 | #include <stdio.h>
|
---|
8 | #include <string.h>
|
---|
9 | #include <ctype.h>
|
---|
10 | #include <time.h>
|
---|
11 | #include <errno.h>
|
---|
12 |
|
---|
13 | /////////////////////////////// MODELPARTS.CPP ///////////////
|
---|
14 |
|
---|
15 | #include "modelparts.h"
|
---|
16 | #include "model.h"
|
---|
17 |
|
---|
18 | #include "nonstd.h"
|
---|
19 | #include "param.h"
|
---|
20 | #include "neurolibrary.h"
|
---|
21 | #include "multirange.h"
|
---|
22 | #include "extvalue.h"
|
---|
23 |
|
---|
24 | #include "neuroclsobject.h"
|
---|
25 |
|
---|
26 | template<>
|
---|
27 | char ModelUserTags::reg[5]={0};
|
---|
28 |
|
---|
29 | /////////////////////////
|
---|
30 |
|
---|
31 | PartBase::~PartBase()
|
---|
32 | {if (mapped) delete mapped;}
|
---|
33 |
|
---|
34 | void PartBase::notifyMappingChange()
|
---|
35 | {
|
---|
36 | if (owner) owner->partmappingchanged=1;
|
---|
37 | }
|
---|
38 |
|
---|
39 | void PartBase::setMapping(const IRange &r)
|
---|
40 | {
|
---|
41 | if (mapped) (*mapped)=r;
|
---|
42 | else mapped=new MultiRange(r);
|
---|
43 | notifyMappingChange();
|
---|
44 | }
|
---|
45 |
|
---|
46 | void PartBase::clearMapping()
|
---|
47 | {
|
---|
48 | if (mapped) {delete mapped; mapped=0;}
|
---|
49 | }
|
---|
50 |
|
---|
51 | void PartBase::addMapping(const IRange &r)
|
---|
52 | {
|
---|
53 | if (mapped) mapped->add(r);
|
---|
54 | else mapped=new MultiRange(r);
|
---|
55 | notifyMappingChange();
|
---|
56 | }
|
---|
57 |
|
---|
58 | void PartBase::setMapping(const MultiRange &mr)
|
---|
59 | {
|
---|
60 | if (mapped) (*mapped)=mr;
|
---|
61 | else mapped=new MultiRange(mr);
|
---|
62 | notifyMappingChange();
|
---|
63 | }
|
---|
64 |
|
---|
65 | void PartBase::addMapping(const MultiRange &mr)
|
---|
66 | {
|
---|
67 | if (mapped) mapped->add(mr);
|
---|
68 | else mapped=new MultiRange(mr);
|
---|
69 | notifyMappingChange();
|
---|
70 | }
|
---|
71 |
|
---|
72 | void PartBase::setInfo(const SString& name,const SString& value)
|
---|
73 | {
|
---|
74 | strSetField(info,name,value);
|
---|
75 | }
|
---|
76 |
|
---|
77 | void PartBase::setInfo(const SString& name,int value)
|
---|
78 | {
|
---|
79 | setInfo(name,SString::valueOf(value));
|
---|
80 | }
|
---|
81 |
|
---|
82 | void PartBase::setInfo(const SString& name,double value)
|
---|
83 | {
|
---|
84 | setInfo(name,SString::valueOf(value));
|
---|
85 | }
|
---|
86 |
|
---|
87 | SString PartBase::getInfo(const SString& name)
|
---|
88 | {
|
---|
89 | return strGetField(info,name);
|
---|
90 | }
|
---|
91 |
|
---|
92 | /////////////////////////
|
---|
93 |
|
---|
94 | NeuroClass::NeuroClass(ParamEntry *_props,SString _description,
|
---|
95 | int _prefinputs,int _prefoutput,int _preflocation,
|
---|
96 | int *_vectordata,bool own_vd,int vhints)
|
---|
97 | :longname(_props->id),
|
---|
98 | name(_props->name),
|
---|
99 | description(_description),
|
---|
100 | props(_props),
|
---|
101 | prefinputs(_prefinputs),
|
---|
102 | prefoutput(_prefoutput),
|
---|
103 | preflocation(_preflocation),
|
---|
104 | vectordata(_vectordata),ownedvectordata(own_vd),
|
---|
105 | visualhints(vhints),impl(0),active(1),genactive(0)
|
---|
106 | {}
|
---|
107 |
|
---|
108 | NeuroClass::~NeuroClass()
|
---|
109 | {
|
---|
110 | setSymbolGlyph(0,0);
|
---|
111 | }
|
---|
112 |
|
---|
113 | NeuroClass::NeuroClass()
|
---|
114 | :name("Invalid"),props(empty_paramtab),
|
---|
115 | prefinputs(0), prefoutput(0),
|
---|
116 | preflocation(0), vectordata(0), ownedvectordata(0),
|
---|
117 | impl(0), active(1), genactive(0)
|
---|
118 | {}
|
---|
119 |
|
---|
120 | SString NeuroClass::getSummary()
|
---|
121 | {
|
---|
122 | SString t;
|
---|
123 | t=getDescription();
|
---|
124 | if (t.len()) t+="\n\n";
|
---|
125 | t+="Characteristics:\n";
|
---|
126 | if(getPreferredInputs())
|
---|
127 | {
|
---|
128 | if (getPreferredInputs()<0) t+=" supports any number of inputs\n";
|
---|
129 | else if (getPreferredInputs()==1) t+=" uses single input\n";
|
---|
130 | else {sprintf(t.directAppend(30)," uses %d inputs\n",getPreferredInputs()); t.endAppend();}
|
---|
131 | }
|
---|
132 | else t+=" does not use inputs\n";
|
---|
133 | if(getPreferredOutput())
|
---|
134 | t+=" provides output value\n";
|
---|
135 | else
|
---|
136 | t+=" does not provide output value\n";
|
---|
137 | switch(getPreferredLocation())
|
---|
138 | {
|
---|
139 | case 0: t+=" does not require location in body\n"; break;
|
---|
140 | case 1: t+=" should be located on a Part\n"; break;
|
---|
141 | case 2: t+=" should be located on a Joint\n"; break;
|
---|
142 | }
|
---|
143 | Param p=getProperties();
|
---|
144 | if (p.getPropCount())
|
---|
145 | {
|
---|
146 | if (t.len()) t+="\n\n";
|
---|
147 | t+="Properties:\n";
|
---|
148 | const char *h;
|
---|
149 | int i;
|
---|
150 | for(i=0;i<p.getPropCount();i++)
|
---|
151 | {
|
---|
152 | if (i) t+="\n";
|
---|
153 | t+=" "; t+=p.name(i); t+=" ("; t+=p.id(i); t+=")";
|
---|
154 | switch(*p.type(i))
|
---|
155 | {
|
---|
156 | case 'd': t+=" integer";
|
---|
157 | {long a,b,c; if (p.getMinMax(i,a,b,c)>=2) {sprintf(t.directAppend(30)," %d..%d",a,b); t.endAppend();}}
|
---|
158 | break;
|
---|
159 | case 'f': t+=" float";
|
---|
160 | {double a,b,c; if (p.getMinMax(i,a,b,c)>=2) {sprintf(t.directAppend(30)," %g..%g",a,b); t.endAppend();}}
|
---|
161 | break;
|
---|
162 | case 's': t+=" string"; break;
|
---|
163 | case 'x': t+=" anything"; break;
|
---|
164 | }
|
---|
165 | if (h=p.help(i)) if (*h) {t+=" - "; t+=h;}
|
---|
166 | }
|
---|
167 | }
|
---|
168 | return t;
|
---|
169 | }
|
---|
170 |
|
---|
171 | /////////////////////////
|
---|
172 |
|
---|
173 | /////////////////////////////////////
|
---|
174 |
|
---|
175 | Neuro::Neuro(double _state,double _inertia,double _force,double _sigmo)
|
---|
176 | :state(_state),PartBase(getDefaultStyle())
|
---|
177 | #ifdef MODEL_V1_COMPATIBLE
|
---|
178 | ,inertia(_inertia),force(_force),sigmo(_sigmo)
|
---|
179 | #endif
|
---|
180 | {
|
---|
181 | #ifdef MODEL_V1_COMPATIBLE
|
---|
182 | olditems=0;
|
---|
183 | #endif
|
---|
184 | flags=0;
|
---|
185 | myclass=0;
|
---|
186 | knownclass=1;
|
---|
187 | }
|
---|
188 |
|
---|
189 | Neuro::Neuro(void):PartBase(getDefaultStyle())
|
---|
190 | {
|
---|
191 | #include "defassign-f0_neuro.h"
|
---|
192 | state=0.0;
|
---|
193 | myclass=0;
|
---|
194 | knownclass=1;
|
---|
195 | refno=0;
|
---|
196 | pos=Pt3D_0; rot=Pt3D_0;
|
---|
197 | parent=0; part=0; joint=0;
|
---|
198 | parentcount=0;
|
---|
199 | #ifdef MODEL_V1_COMPATIBLE
|
---|
200 | olditems=0;
|
---|
201 | #endif
|
---|
202 | flags=0;
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | Neuro::~Neuro()
|
---|
207 | {
|
---|
208 | #ifdef MODEL_V1_COMPATIBLE
|
---|
209 | if (olditems) delete olditems;
|
---|
210 | #endif
|
---|
211 | int i;
|
---|
212 | for(i=0;i<inputs.size();i++)
|
---|
213 | {
|
---|
214 | NInput &ni=inputs(i);
|
---|
215 | if (ni.info) delete ni.info;
|
---|
216 | }
|
---|
217 | }
|
---|
218 |
|
---|
219 | SString** Neuro::inputInfo(int i)
|
---|
220 | {
|
---|
221 | if (i>=getInputCount()) return 0;
|
---|
222 | return &inputs(i).info;
|
---|
223 | }
|
---|
224 |
|
---|
225 | void Neuro::setInputInfo(int i,const SString& name,const SString &value)
|
---|
226 | {
|
---|
227 | SString **s=inputInfo(i);
|
---|
228 | if (!s) return;
|
---|
229 | if (!*s) *s=new SString();
|
---|
230 | strSetField(**s,name,value);
|
---|
231 | }
|
---|
232 |
|
---|
233 | void Neuro::setInputInfo(int i,const SString& name,int value)
|
---|
234 | {
|
---|
235 | setInputInfo(i,name,SString::valueOf(value));
|
---|
236 | }
|
---|
237 |
|
---|
238 | void Neuro::setInputInfo(int i,const SString& name,double value)
|
---|
239 | {
|
---|
240 | setInputInfo(i,name,SString::valueOf(value));
|
---|
241 | }
|
---|
242 |
|
---|
243 | SString Neuro::getInputInfo(int i)
|
---|
244 | {
|
---|
245 | SString **s=inputInfo(i);
|
---|
246 | if (!s) return SString();
|
---|
247 | if (!*s) return SString();
|
---|
248 | return **s;
|
---|
249 | }
|
---|
250 |
|
---|
251 | SString Neuro::getInputInfo(int i,const SString& name)
|
---|
252 | {
|
---|
253 | SString **s=inputInfo(i);
|
---|
254 | if (!s) return SString();
|
---|
255 | if (!*s) return SString();
|
---|
256 | return strGetField(**s,name);
|
---|
257 | }
|
---|
258 |
|
---|
259 | void Neuro::operator=(const Neuro& src)
|
---|
260 | {
|
---|
261 | refno=src.refno;
|
---|
262 | #ifdef MODEL_V1_COMPATIBLE
|
---|
263 | neuro_refno=-1;
|
---|
264 | conn_refno=-1;
|
---|
265 | force=src.force;
|
---|
266 | sigmo=src.sigmo;
|
---|
267 | inertia=src.inertia;
|
---|
268 | weight=src.weight;
|
---|
269 | olditems=0;
|
---|
270 | #endif
|
---|
271 | state=src.state;
|
---|
272 | part_refno=-1;
|
---|
273 | joint_refno=-1;
|
---|
274 | pos=src.pos; rot=src.rot;
|
---|
275 | parent=0; part=0; joint=0;
|
---|
276 | parentcount=0;
|
---|
277 | flags=0;
|
---|
278 | myclass=src.myclass;
|
---|
279 | knownclass=src.knownclass;
|
---|
280 | myclassname=src.myclassname;
|
---|
281 | myclassparams=src.myclassparams;
|
---|
282 | }
|
---|
283 |
|
---|
284 | void Neuro::attachToPart(int i)
|
---|
285 | {attachToPart((i>=0)?owner->getPart(i):0);}
|
---|
286 |
|
---|
287 | void Neuro::attachToJoint(int i)
|
---|
288 | {attachToJoint((i>=0)?owner->getJoint(i):0);}
|
---|
289 |
|
---|
290 | int Neuro::getClassCount()
|
---|
291 | {return NeuroLibrary::staticlibrary.getClassCount();}
|
---|
292 |
|
---|
293 | NeuroClass* Neuro::getClass(int classindex)
|
---|
294 | {return NeuroLibrary::staticlibrary.getClass(classindex);}
|
---|
295 |
|
---|
296 | NeuroClass* Neuro::getClass(const SString& classname)
|
---|
297 | {return NeuroLibrary::staticlibrary.findClass(classname);}
|
---|
298 |
|
---|
299 | int Neuro::getClassIndex(const NeuroClass*nc)
|
---|
300 | {return NeuroLibrary::staticlibrary.classes.find((void*)nc);}
|
---|
301 |
|
---|
302 | NeuroClass* Neuro::getClass()
|
---|
303 | {
|
---|
304 | checkClass();
|
---|
305 | return myclass;
|
---|
306 | }
|
---|
307 |
|
---|
308 | void Neuro::setClass(NeuroClass* cl)
|
---|
309 | {
|
---|
310 | myclass=cl;
|
---|
311 | myclassname=cl->getName();
|
---|
312 | knownclass=1;
|
---|
313 | }
|
---|
314 |
|
---|
315 | SString Neuro::getClassName(int classindex)
|
---|
316 | {
|
---|
317 | NeuroClass *cl=NeuroLibrary::staticlibrary.getClass(classindex);
|
---|
318 | return cl? cl->getName() : SString();
|
---|
319 | }
|
---|
320 |
|
---|
321 | void Neuro::setDetails(const SString& details)
|
---|
322 | {
|
---|
323 | int colon=details.indexOf(':');
|
---|
324 | if (colon>=0) {myclassname=details.substr(0,colon); myclassparams=details.substr(colon+1);}
|
---|
325 | else {myclassname=details; myclassparams=0;}
|
---|
326 | knownclass=0;
|
---|
327 | }
|
---|
328 |
|
---|
329 | SString Neuro::getDetails()
|
---|
330 | {
|
---|
331 | SString ret=getClassName();
|
---|
332 | if (myclassparams.len()) {if (!ret.len()) ret="N"; ret+=":"; ret+=myclassparams;}
|
---|
333 | return ret;
|
---|
334 | }
|
---|
335 |
|
---|
336 | void Neuro::checkClass()
|
---|
337 | {
|
---|
338 | if (knownclass) return;
|
---|
339 | myclass=getClass(myclassname);
|
---|
340 | knownclass=1;
|
---|
341 | }
|
---|
342 |
|
---|
343 | SyntParam Neuro::classProperties()
|
---|
344 | {
|
---|
345 | NeuroClass *cl=getClass();
|
---|
346 | ParamEntry *pe = cl ? cl->getParamTab() : emptyParamTab;
|
---|
347 | return SyntParam(pe,&myclassparams);
|
---|
348 | }
|
---|
349 |
|
---|
350 | SString Neuro::getClassName()
|
---|
351 | {
|
---|
352 | return myclassname;
|
---|
353 | }
|
---|
354 |
|
---|
355 | void Neuro::setClassName(const SString& clazz)
|
---|
356 | {
|
---|
357 | myclassname=clazz;
|
---|
358 | knownclass=0;
|
---|
359 | }
|
---|
360 |
|
---|
361 | int Neuro::addInput(Neuro* child,float weight,const SString *info)
|
---|
362 | {
|
---|
363 | inputs+=NInput(child,weight,(info&&(info->len()))?new SString(*info):0);
|
---|
364 | child->parentcount++;
|
---|
365 | if (child->parentcount==1) {child->parent=this;}
|
---|
366 | return inputs.size()-1;
|
---|
367 | }
|
---|
368 |
|
---|
369 | int Neuro::findInput(Neuro* child) const
|
---|
370 | {
|
---|
371 | for(int i=0;i<inputs.size();i++)
|
---|
372 | if (inputs(i).n==child) return i;
|
---|
373 | return -1;
|
---|
374 | }
|
---|
375 |
|
---|
376 | Neuro* Neuro::getInput(int i,float &weight) const
|
---|
377 | {
|
---|
378 | if (i>=getInputCount()) return 0;
|
---|
379 | NInput &inp=inputs(i);
|
---|
380 | weight=inp.weight;
|
---|
381 | return inp.n;
|
---|
382 | }
|
---|
383 |
|
---|
384 | float Neuro::getInputWeight(int i) const
|
---|
385 | {
|
---|
386 | return inputs(i).weight;
|
---|
387 | }
|
---|
388 |
|
---|
389 | void Neuro::setInputWeight(int i,float w)
|
---|
390 | {
|
---|
391 | inputs(i).weight=w;
|
---|
392 | }
|
---|
393 |
|
---|
394 | void Neuro::setInput(int i,Neuro* n)
|
---|
395 | {
|
---|
396 | NInput &inp=inputs(i);
|
---|
397 | inp.n=n;
|
---|
398 | }
|
---|
399 |
|
---|
400 | void Neuro::setInput(int i,Neuro* n,float w)
|
---|
401 | {
|
---|
402 | NInput &inp=inputs(i);
|
---|
403 | inp.n=n;
|
---|
404 | inp.weight=w;
|
---|
405 | }
|
---|
406 |
|
---|
407 | void Neuro::removeInput(int refno)
|
---|
408 | {
|
---|
409 | Neuro *child=getInput(refno);
|
---|
410 | child->parentcount--;
|
---|
411 | if (child->parent==this) child->parent=0;
|
---|
412 | SString *s=inputs(refno).info;
|
---|
413 | if (s) delete s;
|
---|
414 | inputs.remove(refno);
|
---|
415 | }
|
---|
416 |
|
---|
417 | int Neuro::removeInput(Neuro* child)
|
---|
418 | {
|
---|
419 | int i=findInput(child);
|
---|
420 | if (i>=0) removeInput(i);
|
---|
421 | return i;
|
---|
422 | }
|
---|
423 |
|
---|
424 | int Neuro::getOutputsCount() const
|
---|
425 | {
|
---|
426 | int c=0;
|
---|
427 | for(int i=0;i<owner->getNeuroCount();i++)
|
---|
428 | for(int j=0;j<owner->getNeuro(i)->getInputCount();j++) c+=owner->getNeuro(i)->getInput(j)==this;
|
---|
429 | return c;
|
---|
430 | }
|
---|
431 |
|
---|
432 | int Neuro::isOldEffector()
|
---|
433 | {
|
---|
434 | static SString bend("|"),rot("@");
|
---|
435 | return ((getClassName()==bend)||(getClassName()==rot));
|
---|
436 | }
|
---|
437 |
|
---|
438 | int Neuro::isOldReceptor()
|
---|
439 | {
|
---|
440 | static SString g("G"),t("T"),s("S");
|
---|
441 | return ((getClassName()==g)||(getClassName()==t)||(getClassName()==s));
|
---|
442 | }
|
---|
443 |
|
---|
444 | int Neuro::isOldNeuron()
|
---|
445 | {
|
---|
446 | static SString n("N");
|
---|
447 | return (getClassName()==n);
|
---|
448 | }
|
---|
449 |
|
---|
450 | int Neuro::isNNConnection()
|
---|
451 | {
|
---|
452 | static SString conn("-");
|
---|
453 | return (getClassName()==conn);
|
---|
454 | }
|
---|
455 |
|
---|
456 | int Neuro::findInputs(SList& result,const char* classname,const Part* part,const Joint* joint) const
|
---|
457 | {
|
---|
458 | Neuro *nu;
|
---|
459 | SString cn(classname);
|
---|
460 | int n0=result.size();
|
---|
461 | for(int i=0;nu=getInput(i);i++)
|
---|
462 | {
|
---|
463 | if (part)
|
---|
464 | if (nu->part != part) continue;
|
---|
465 | if (joint)
|
---|
466 | if (nu->joint != joint) continue;
|
---|
467 | if (classname)
|
---|
468 | if (nu->getClassName() != cn) continue;
|
---|
469 | result+=(void*)nu;
|
---|
470 | }
|
---|
471 | return result.size()-n0;
|
---|
472 | }
|
---|
473 |
|
---|
474 | int Neuro::findOutputs(SList& result,const char* classname,const Part* part,const Joint* joint) const
|
---|
475 | { // not very efficient...
|
---|
476 | Neuro *nu,*inp;
|
---|
477 | SString cn(classname);
|
---|
478 | SList found;
|
---|
479 | int n0=result.size();
|
---|
480 | for(int i=0;nu=getModel().getNeuro(i);i++)
|
---|
481 | {
|
---|
482 | if (part)
|
---|
483 | if (nu->part != part) continue;
|
---|
484 | if (joint)
|
---|
485 | if (nu->joint != joint) continue;
|
---|
486 | if (classname)
|
---|
487 | if (inp->getClassName() != cn) continue;
|
---|
488 | for (int j=0;inp=nu->getInput(j);j++)
|
---|
489 | if (inp==this)
|
---|
490 | {
|
---|
491 | result+=(void*)nu;
|
---|
492 | break;
|
---|
493 | }
|
---|
494 | }
|
---|
495 | return result.size()-n0;
|
---|
496 | }
|
---|
497 |
|
---|
498 | void Neuro::get_inputCount(PARAMGETARGS)
|
---|
499 | {ret->setInt(inputs.size());}
|
---|
500 |
|
---|
501 | void Neuro::p_getInputNeuroDef(ExtValue *args,ExtValue *ret)
|
---|
502 | {
|
---|
503 | int i=args->getInt();
|
---|
504 | if ((i<0)||(i>=inputs.size()))
|
---|
505 | ret->setEmpty();
|
---|
506 | else
|
---|
507 | ret->setObject(ExtObject(&st_neuroparam,inputs(i).n));
|
---|
508 | }
|
---|
509 |
|
---|
510 | void Neuro::p_getInputWeight(ExtValue *args,ExtValue *ret)
|
---|
511 | {
|
---|
512 | int i=args->getInt();
|
---|
513 | if ((i<0)||(i>=inputs.size()))
|
---|
514 | ret->setEmpty();
|
---|
515 | else
|
---|
516 | ret->setDouble(inputs(i).weight);
|
---|
517 | }
|
---|
518 |
|
---|
519 | void Neuro::p_getInputNeuroIndex(ExtValue *args,ExtValue *ret)
|
---|
520 | {
|
---|
521 | int i=args->getInt();
|
---|
522 | if ((i<0)||(i>=inputs.size()))
|
---|
523 | ret->setInt(-1);
|
---|
524 | else
|
---|
525 | ret->setInt(inputs(i).n->refno);
|
---|
526 | }
|
---|
527 |
|
---|
528 | void Neuro::get_classObject(PARAMGETARGS)
|
---|
529 | {
|
---|
530 | NeuroClassExt::makeStaticObject(ret,getClass());
|
---|
531 | }
|
---|
532 |
|
---|
533 | /////// old items
|
---|
534 | #ifdef MODEL_V1_COMPATIBLE
|
---|
535 | void OldItems::buildlist()
|
---|
536 | { // guaranteed to work only for old NN layouts
|
---|
537 | // (neurons,neuro connections, old receptors and effectors)
|
---|
538 | if (listok) return;
|
---|
539 | // inputs can contain both neuroitem connections (details="") and direct neuron references (details="N")
|
---|
540 | // in OldItems we create neuroitems freom direct references
|
---|
541 | for(int i=0;i<neuro.getInputCount();i++)
|
---|
542 | {
|
---|
543 | float w;
|
---|
544 | Neuro *n=neuro.getInput(i,w);
|
---|
545 | if (n->isOldNeuron())
|
---|
546 | {
|
---|
547 | Neuro *ni=new Neuro();
|
---|
548 | ni->setClassName("-");
|
---|
549 | ni->weight=w;
|
---|
550 | ni->neuro_refno=neuro.refno;
|
---|
551 | ni->conn_refno=n->refno;
|
---|
552 | items+=ni;
|
---|
553 | syntitems+=ni;
|
---|
554 | }
|
---|
555 | else
|
---|
556 | {
|
---|
557 | items+=n;
|
---|
558 | n->weight=w;
|
---|
559 | }
|
---|
560 | }
|
---|
561 | SList outputs;
|
---|
562 | neuro.findOutputs(outputs);
|
---|
563 | FOREACH(Neuro*,n,outputs)
|
---|
564 | {
|
---|
565 | if (n->isNNConnection() || n->isOldNeuron())
|
---|
566 | outputs-=n;
|
---|
567 | }
|
---|
568 | items+=outputs;
|
---|
569 | listok=1;
|
---|
570 | }
|
---|
571 |
|
---|
572 | void OldItems::freelist()
|
---|
573 | {
|
---|
574 | FOREACH(Neuro*,n,syntitems)
|
---|
575 | delete n;
|
---|
576 | syntitems.clear();
|
---|
577 | items.clear();
|
---|
578 | listok=0;
|
---|
579 | }
|
---|
580 |
|
---|
581 | int OldItems::getItemCount()
|
---|
582 | {
|
---|
583 | buildlist();
|
---|
584 | return items.size();
|
---|
585 | }
|
---|
586 |
|
---|
587 | NeuroItem *OldItems::getNeuroItem(int i)
|
---|
588 | {
|
---|
589 | buildlist();
|
---|
590 | return (NeuroItem*)items(i);
|
---|
591 | }
|
---|
592 |
|
---|
593 | NeuroItem *OldItems::addNewNeuroItem()
|
---|
594 | {
|
---|
595 | Neuro *nu=neuro.getModel().addNewNeuro();
|
---|
596 | nu->setClassName("-");
|
---|
597 | if (listok) items+=nu;
|
---|
598 | neuro.addInput(nu);
|
---|
599 | return (NeuroItem*)nu;
|
---|
600 | }
|
---|
601 |
|
---|
602 | int OldItems::findNeuroItem(NeuroItem *ni)
|
---|
603 | {
|
---|
604 | buildlist();
|
---|
605 | return items.find((void*)ni);
|
---|
606 | }
|
---|
607 | #endif
|
---|
608 |
|
---|
609 | ///////////////////////////////////////
|
---|
610 |
|
---|
611 | const SString& Part::getDefaultStyle()
|
---|
612 | {static SString s("part"); return s;}
|
---|
613 | const SString& Joint::getDefaultStyle()
|
---|
614 | {static SString s("joint"); return s;}
|
---|
615 | /*
|
---|
616 | const SString& Neuro::getDefaultStyle()
|
---|
617 | {static SString s("neuro"); return s;}
|
---|
618 | const SString& NeuroItem::getDefaultStyle()
|
---|
619 | {static SString s("neuroitem"); return s;}
|
---|
620 | */
|
---|
621 | const SString& Neuro::getDefaultStyle()
|
---|
622 | {static SString s("neuro"); return s;}
|
---|
623 |
|
---|
624 | Part::Part():PartBase(getDefaultStyle())
|
---|
625 | {
|
---|
626 | o=Orient_1;
|
---|
627 | p=Pt3D_0;
|
---|
628 | rot=Pt3D_0;
|
---|
629 | flags=0;
|
---|
630 | #include "defassign-f0_part.h"
|
---|
631 | }
|
---|
632 |
|
---|
633 | void Part::operator=(const Part& src)
|
---|
634 | {
|
---|
635 | p=src.p; o=src.o;
|
---|
636 | flags=src.flags;
|
---|
637 | mass=src.mass; density=src.density;
|
---|
638 | friction=src.friction;
|
---|
639 | ingest=src.ingest;
|
---|
640 | assim=src.assim;
|
---|
641 | size=src.size;
|
---|
642 | rot=src.rot;
|
---|
643 | refno=src.refno;
|
---|
644 | }
|
---|
645 |
|
---|
646 | ///////////////////////////
|
---|
647 |
|
---|
648 | Joint::Joint():PartBase(getDefaultStyle())
|
---|
649 | {
|
---|
650 | rot=Pt3D_0;
|
---|
651 | #include "defassign-f0_joint.h"
|
---|
652 | d.x=JOINT_DELTA_MARKER;
|
---|
653 | part1=0; part2=0;
|
---|
654 | flags=0;
|
---|
655 | usedelta=0;
|
---|
656 | }
|
---|
657 |
|
---|
658 | void Joint::operator=(const Joint& src)
|
---|
659 | {
|
---|
660 | rot=src.rot;
|
---|
661 | d=src.d;
|
---|
662 | stamina=src.stamina;
|
---|
663 | stif=src.stif; rotstif=src.rotstif;
|
---|
664 | part1=0; part2=0;
|
---|
665 | flags=src.flags;
|
---|
666 | usedelta=src.usedelta;
|
---|
667 | refno=src.refno;
|
---|
668 | }
|
---|
669 |
|
---|
670 | void Joint::attachToParts(Part* p1,Part* p2)
|
---|
671 | {
|
---|
672 | part1=p1;
|
---|
673 | part2=p2;
|
---|
674 | if (p1 && p2)
|
---|
675 | {
|
---|
676 | o=rot;
|
---|
677 | if (usedelta)
|
---|
678 | {
|
---|
679 | p1->o.transform(p2->o,o);
|
---|
680 | // p2->o.x=p1->o/o.x; p2->o.y=p1->o/o.y; p2->o.z=p1->o/o.z;
|
---|
681 | p2->p=p2->o.transform(d)+p1->p;
|
---|
682 | }
|
---|
683 | }
|
---|
684 | }
|
---|
685 |
|
---|
686 | void Joint::attachToParts(int p1,int p2)
|
---|
687 | {
|
---|
688 | attachToParts((p1>=0)?owner->getPart(p1):0,(p2>=0)?owner->getPart(p2):0);
|
---|
689 | }
|
---|
690 |
|
---|
691 | void Joint::resetDelta()
|
---|
692 | {
|
---|
693 | d=Pt3D(JOINT_DELTA_MARKER,0,0);
|
---|
694 | }
|
---|
695 |
|
---|
696 | void Joint::useDelta(int false_or_true)
|
---|
697 | {
|
---|
698 | usedelta=false_or_true;
|
---|
699 | }
|
---|
700 |
|
---|
701 | int Joint::isDelta()
|
---|
702 | {
|
---|
703 | return usedelta;
|
---|
704 | }
|
---|
705 |
|
---|
706 | /////////////////////////////////////////////////////////////////
|
---|
707 | /////////////////////////////////////////////////////////////////
|
---|
708 |
|
---|
709 | #include "f0classes.h"
|
---|
710 |
|
---|
711 | #ifdef MODEL_V1_COMPATIBLE
|
---|
712 |
|
---|
713 | #define FIELDSTRUCT Neuro
|
---|
714 | ParamEntry f0_old_neuro_tab[]=
|
---|
715 | {
|
---|
716 | {"Connections",2,6,"n",},
|
---|
717 | {"Other properties",},
|
---|
718 | {"p",0,0,"part ref#","d",FIELD(part_refno),},
|
---|
719 | {"j",0,0,"joint ref#","d",FIELD(joint_refno),},
|
---|
720 | {"s",1,0,"state","f",FIELD(state),},
|
---|
721 | {"in",1,0,"Inertia","f",FIELD(inertia),},
|
---|
722 | {"fo",1,0,"Force","f",FIELD(force),},
|
---|
723 | {"si",1,0,"Sigmoid","f",FIELD(sigmo),},
|
---|
724 | {0,0,0,},
|
---|
725 | };
|
---|
726 | #undef FIELDSTRUCT
|
---|
727 |
|
---|
728 | #define FIELDSTRUCT NeuroItem
|
---|
729 | ParamEntry f0_neuroitem_paramtab[]=
|
---|
730 | {
|
---|
731 | {"Connections",3,12,"ni",},
|
---|
732 | {"Geometry",},
|
---|
733 | {"Other",},
|
---|
734 | {"n",0,0,"neuron ref#","d",FIELD(neuro_refno),},
|
---|
735 | {"c",2,0,"connection ref#","d",FIELD(conn_refno),},
|
---|
736 | {"w",2,0,"connection weight","f",FIELD(weight),},
|
---|
737 | {"p",0,0,"part ref#","d",FIELD(part_refno),},
|
---|
738 | {"j",0,0,"joint ref#","d",FIELD(joint_refno),},
|
---|
739 | {"px",1,0,"position.x","f",FIELD(pos.x),},
|
---|
740 | {"py",1,0,"position.y","f",FIELD(pos.y),},
|
---|
741 | {"pz",1,0,"position.z","f",FIELD(pos.z),},
|
---|
742 | {"rx",1,0,"rotation.x","f",FIELD(rot.x),},
|
---|
743 | {"ry",1,0,"rotation.y","f",FIELD(rot.y),},
|
---|
744 | {"rz",1,0,"rotation.z","f",FIELD(rot.z),},
|
---|
745 | {"d",2,0,"item details","s",GETSET(details),},
|
---|
746 | {0,0,0,},
|
---|
747 | };
|
---|
748 | #undef FIELDSTRUCT
|
---|
749 | #endif
|
---|
750 |
|
---|
751 | ////////////////////////////////////////
|
---|
752 |
|
---|
753 | ParamEntry Neuro::emptyParamTab[]=
|
---|
754 | {
|
---|
755 | {"Undefined Neuro",1,0,"?",},
|
---|
756 | {0,0,0,},
|
---|
757 | };
|
---|
758 |
|
---|
759 | static Param staticparam;
|
---|
760 |
|
---|
761 | ParamInterface &Part::extraProperties()
|
---|
762 | {
|
---|
763 | staticparam.setParamTab(f0_part_xtra_paramtab);
|
---|
764 | staticparam.select(this);
|
---|
765 | return staticparam;
|
---|
766 | }
|
---|
767 |
|
---|
768 | ParamInterface &Joint::extraProperties()
|
---|
769 | {
|
---|
770 | staticparam.setParamTab(f0_joint_xtra_paramtab);
|
---|
771 | staticparam.select(this);
|
---|
772 | return staticparam;
|
---|
773 | }
|
---|
774 |
|
---|
775 | ParamInterface &Neuro::extraProperties()
|
---|
776 | {
|
---|
777 | staticparam.setParamTab(f0_neuro_xtra_paramtab);
|
---|
778 | staticparam.select(this);
|
---|
779 | return staticparam;
|
---|
780 | }
|
---|
781 |
|
---|
782 | ParamInterface &Part::properties()
|
---|
783 | {
|
---|
784 | staticparam.setParamTab(f0_part_paramtab);
|
---|
785 | staticparam.select(this);
|
---|
786 | return staticparam;
|
---|
787 | }
|
---|
788 |
|
---|
789 | ParamInterface &Joint::properties()
|
---|
790 | {
|
---|
791 | staticparam.setParamTab(usedelta?f0_joint_paramtab:f0_nodeltajoint_paramtab);
|
---|
792 | staticparam.select(this);
|
---|
793 | return staticparam;
|
---|
794 | }
|
---|
795 |
|
---|
796 | ParamInterface &Neuro::properties()
|
---|
797 | {
|
---|
798 | staticparam.setParamTab(f0_neuro_paramtab);
|
---|
799 | staticparam.select(this);
|
---|
800 | return staticparam;
|
---|
801 | }
|
---|
802 |
|
---|
803 | class NeuroExtParamTab: public ParamTab
|
---|
804 | {
|
---|
805 | public:
|
---|
806 | NeuroExtParamTab():ParamTab(f0_neuro_paramtab)
|
---|
807 | {
|
---|
808 | #define FIELDSTRUCT NeuroExt
|
---|
809 | ParamEntry entry={"class",2,0,"neuro class","s",GETSET(neuroclass)};
|
---|
810 | #undef FIELDSTRUCT
|
---|
811 | add(&entry);
|
---|
812 |
|
---|
813 | #define FIELDSTRUCT Neuro
|
---|
814 | ParamEntry entry2={"state",2,0,"state","f",FIELD(state)};
|
---|
815 | #undef FIELDSTRUCT
|
---|
816 | add(&entry2);
|
---|
817 | }
|
---|
818 | };
|
---|
819 |
|
---|
820 | ////////////////////////
|
---|
821 |
|
---|
822 | NeuroConn::NeuroConn()
|
---|
823 | {
|
---|
824 | #include "defassign-f0_neuroconn.h"
|
---|
825 | }
|
---|
826 |
|
---|
827 | //////////////////////////////////////
|
---|
828 |
|
---|
829 | ParamEntry *NeuroExt::getParamTab()
|
---|
830 | {
|
---|
831 | static NeuroExtParamTab tab;
|
---|
832 | return tab.getParamTab();
|
---|
833 | }
|
---|
834 |
|
---|
835 | void NeuroExt::get_neuroclass(PARAMGETARGS)
|
---|
836 | {ret->setString(getClassName());}
|
---|
837 |
|
---|
838 | int NeuroExt::set_neuroclass(PARAMSETARGS)
|
---|
839 | {setClassName(arg->getString());return PSET_CHANGED;}
|
---|
840 |
|
---|
841 | Param st_neuroparam(f0_neuro_paramtab,0,"NeuroDef");
|
---|
842 | Param st_jointparam(f0_joint_paramtab,0,"Joint");
|
---|
843 | Param st_partparam(f0_part_paramtab,0,"Part");
|
---|
844 |
|
---|
845 |
|
---|