00001
00007 #ifndef __RETINALOBJS_H__
00008 #define __RETINALOBJS_H__
00009
00010 #include <vector>
00011 #include <algorithm>
00012 #include <string>
00013 using std::string;
00014
00015 #include "matrix.h"
00016
00017 #include "genericalgs.h"
00018 #include "valuegen.h"
00019 #include "valuegenmap.h"
00020 #include "pnm_io.h"
00021 #include "boundingbox.h"
00022 #include "robj.h"
00023 #include "tristate.h"
00024 #include "mathconstants.h"
00025
00026
00027
00028
00029
00030
00031 #ifndef RADIANS_TO_DEGREES
00032 #define RADIANS_TO_DEGREES(theta) (180.0*(theta)/(Math::pi))
00033 #endif
00034
00036 #ifndef CONSTRAIN_ANGLE
00037 #define CONSTRAIN_ANGLE(angle) \
00038 (((angle)>=0) ? \
00039 fmod( (angle), (Math::pi) ) : \
00040 fmod( (angle) + 2*(Math::pi)*(-1*floor((angle)/((Math::pi)*2))+1), (Math::pi)) )
00041 #endif
00042
00043
00044
00045
00046
00047
00048 class Retinal_Composite;
00049
00075 class Retinal_Object : public Retinal_Obj {
00076 protected:
00078 typedef AARBoundingBox<Coordinate> BBox;
00079
00080 public:
00082 typedef double Variable;
00084 typedef ValueGenerator<Variable> VarGen;
00086 typedef ValueGeneratorMap<Variable> VarMap;
00087
00090 Retinal_Object(const string& name_val, const VarMap& init_vars=VarMap())
00091 : bounding_box(), active(true), name_(name_val),
00092 default_act(0.0), parentptr(0) {
00093 vars.merge(init_vars);
00094 set_var_default("scale",1.0);
00095 }
00096
00097 Retinal_Object(const Retinal_Object& b)
00098 : Retinal_Obj(b), bounding_box(b.bounding_box), vars(b.vars),
00099 active(b.active), name_(b.name_),
00100 default_act(b.default_act), parentptr(0) { }
00101
00102 virtual ~Retinal_Object() { }
00104
00105
00112 virtual bool next() { return vars.next(); }
00113 virtual void reset() { vars.reset(); }
00114 virtual bool update() const {
00115
00116 theta = get_var("theta");
00117 cx = get_var("cx");
00118 cy = get_var("cy");
00119 scale = get_var("scale");
00120 offset = get_var("offset");
00121 default_act = default_activ();
00122
00123 return true;
00124 }
00125
00131 virtual Activity activation(Coordinate x, Coordinate y) const {
00132 return offset + scale *
00133 ((!active || !bounding_box.inside(x,y)) ? default_act : activ(x,y));
00134 }
00136
00137
00140
00141 virtual string stringrep() const;
00142
00144 virtual Retinal_Object* clone() const =0;
00145
00147 virtual void relink (const Retinal_Object* master)
00148 { if (master) vars.relink(&(master->vars)); }
00149
00151 bool get_active() const { return active; }
00153 void set_active(bool whether_active) { active=whether_active; }
00154
00156 const string& name() const { return name_; }
00157 const string& get_name() const { return name_; }
00159 void set_name(const string& newname) { name_=newname; }
00160
00162 const Variable get_var(const string& varname) const { return vars.get(varname); }
00163
00165 Variable* get_varptr(const string& varname) { return vars.getptr(varname); }
00166
00170 string vargen_stringrep(const string& varname) const {
00171 VarGen* v = vars.getvalgenptr(varname);
00172 return v? v->stringrep() : "";
00173 }
00174
00176 virtual const Retinal_Composite* get_parent() const { return parentptr; }
00177
00179 virtual void set_parent(const Retinal_Composite* _parentptr)
00180 { parentptr=_parentptr; }
00181
00182
00184 virtual Angle angle() const { return get_var("theta"); }
00185
00187 virtual Retinal_Object* find(const string& othername)
00188 { return (othername=="" || othername==name_ ? this : 0); }
00189
00191 void merge_vars(const VarMap& init_vars) { vars.merge(init_vars); }
00192
00202 virtual bool inside(Coordinate x, Coordinate y) const
00203 { return bounding_box.inside(x,y); }
00205
00206
00220 virtual Activity default_activation() const
00221 { return get_var("offset") + get_var("scale") * default_act; }
00222
00224 mutable BBox bounding_box;
00226
00227
00228 protected:
00229 friend class DefaultActivityAccumulator;
00230
00232 const void set_var_default(const string& varname, Variable val)
00233 { vars.set_default(varname,val); }
00234
00235 private:
00236 VarMap vars;
00237 bool active;
00238 string name_;
00239 mutable Variable default_act,theta,cx,cy,scale,offset;
00240 const Retinal_Composite* parentptr;
00241
00248 virtual Activity activ(Coordinate x, Coordinate y) const =0;
00249
00257 virtual Activity default_activ() const { return 0.0; }
00258
00259
00261 void operator= (const Retinal_Object &) { abort(); }
00262 };
00263
00264
00265
00266
00267 #ifndef NO_VALGEN_STRINGS
00268
00269 class RetinalObjectStringArgs {
00270 public:
00272 typedef std::map<string,string> DefaultsMap;
00274 typedef std::vector<string> ParamList;
00275
00282 RetinalObjectStringArgs( StringArgs arglist,
00283 VGenFactory<Retinal_Object::Variable>& vgf,
00284 DefaultsMap dm=DefaultsMap(),
00285 Retinal_Object* m=0)
00286 : args(arglist), defaults(dm), master(m), f(vgf), parser(args.p) { }
00287
00294 Retinal_Object::VarMap vars(const ParamList& params);
00295
00296
00300
00306 string get_default(const string& name) const {
00307 std::map<string,string>::const_iterator existing = defaults.find(name);
00308 return (existing == defaults.end() ? string() : (*existing).second);
00309 }
00310
00312 void set_default(const string& name, const string& value)
00313 { defaults[name]=value; }
00314
00316 void error(const string& s) const { parser.error(s); }
00317
00319 const string parsed_get_default(const string& name) const
00320 { return parser.parse(get_default(name)); }
00321
00323 const string parsed_next(const string& name)
00324 { return parser.parse(args.next(get_default(name))); }
00325
00327 Retinal_Object::Variable& parse(const string& s, Retinal_Object::Variable& x) const
00328 { return parser.parse(s,x); }
00330
00331
00332 private:
00334 inline void set_linked(const string& name, const string& value,
00335 Retinal_Object::VarMap& vars) {
00336 vars.set(name, f.create(StringArgs(parser,parser.parse(value)),
00337 (!master ? 0 : master->get_varptr(name)) ) );
00338 }
00339
00340 friend class RetinalObjectFactory;
00341
00342 StringArgs args;
00343 DefaultsMap defaults;
00344 Retinal_Object* master;
00345 VGenFactory<Retinal_Object::Variable>& f;
00346 const StringParser& parser;
00347 };
00348 #endif
00349
00350
00351
00352
00353
00354
00355
00365 class Retinal_Composite : public Retinal_Object {
00366 public:
00368 enum AccumulationType { Max, Min, Add, OneHot, Replace };
00369
00372 Retinal_Composite( const string& name_val, AccumulationType accum_type_i=Max,
00373 const VarMap& init_vars=VarMap())
00374 : Retinal_Object(name_val,init_vars),
00375 accum_type(accum_type_i), dominant_child(0) {
00376 set_var_default("size_scale",1.0);
00377 }
00378
00379 #ifndef NO_VALGEN_STRINGS
00380 RetinalObjectStringArgs::ParamList paramlist();
00381 Retinal_Composite( const string& name_val, RetinalObjectStringArgs& sa)
00382 : Retinal_Object(name_val), dominant_child(0) {
00383 sa.set_default("size_scale","1.0");
00384 merge_vars(sa.vars(paramlist()));
00385 accum_type = Retinal_Composite::AccumulationType(get_var("accum_type"));
00386 }
00387 #endif
00388
00389 Retinal_Composite(const Retinal_Composite& b)
00390 : Retinal_Object(b), children(b.children), accum_type(b.accum_type),
00391 dominant_child(0) {
00392 std::transform(ISEQ(children),children.begin(),std::mem_fun(&Retinal_Object::clone));
00393 }
00394
00395 virtual ~Retinal_Composite() { remove_all(); };
00397
00398
00401 virtual bool next();
00402 virtual void reset();
00403 virtual bool update() const;
00405
00406
00409
00410
00415 virtual Coordinate nominal_height() const {
00416 const Variable size_scale = get_var("size_scale");
00417 return (get_parent()? get_parent()->nominal_height()/size_scale : 0);
00418 }
00419
00420 virtual Coordinate nominal_width() const {
00421 const Variable size_scale = get_var("size_scale");
00422 return (get_parent()? get_parent()->nominal_width()/size_scale : 0);
00423 }
00424
00426 virtual void add(Retinal_Object* obj) {
00427 children.push_back(obj);
00428 if (obj) obj->set_parent(this);
00429 }
00430
00432 virtual bool is_empty() const { return (children.empty()); }
00433
00439 virtual Retinal_Object* find(const string& othername) {
00440 if (Retinal_Object::find(othername)) return this;
00441 for (iterator i=children.begin(); i!=children.end(); i++) {
00442 Retinal_Object* child_ptr = (*i)->find(othername);
00443 if (child_ptr) return child_ptr;
00444 }
00445 return 0;
00446 }
00447
00449 virtual void remove(const string& childname="") {
00450 for (iterator i=children.begin(); i!=children.end(); i++)
00451 if (childname=="" || ((*i)->name() == childname)) {
00452 if (dominant_child==*i) dominant_child=0;
00453 delete *i;
00454 children.erase(i);
00455 i--;
00456 }
00457 }
00458
00460 virtual void remove_all() { Generic::delete_contents(children); dominant_child=0; }
00461
00464 virtual const Retinal_Object& mostactive(Coordinate x, Coordinate y) const;
00465
00466
00468 Retinal_Object* operator[] (unsigned int idx) const { return children[idx]; }
00469 size_t size() const { return children.size(); }
00471
00472
00475 virtual string stringrep() const;
00476 virtual Retinal_Object* clone() const
00477 { return new Retinal_Composite(*this); };
00478 bool inside(Coordinate x, Coordinate y) const;
00480
00481 protected:
00483 typedef std::vector<Retinal_Object*> ChildrenContainer;
00485 typedef ChildrenContainer::iterator iterator;
00487 typedef ChildrenContainer::const_iterator const_iterator;
00489 ChildrenContainer children;
00490
00492 AccumulationType accum_type;
00494 Activity accum_base() const;
00496 mutable Variable cosmt,sinmt,cx,cy,div_size;
00498 mutable Retinal_Object* dominant_child;
00499
00500 private:
00501 virtual Activity activ(Coordinate x, Coordinate y) const;
00502 virtual Activity default_activ() const;
00503 };
00504
00505
00506
00516 class Retinal_ManagedComposite : public Retinal_Composite {
00517 public:
00518 Retinal_ManagedComposite
00519 ( const string& name_val,
00520 Tristate* min_distance_enforce, double* min_distance,
00521 Tristate* max_distance_enforce, double* max_distance,
00522 AccumulationType accum_type_i=Max, const VarMap& init_vars=VarMap())
00523 : Retinal_Composite(name_val,accum_type_i,init_vars),
00524 min_dist_enforce(min_distance_enforce), min_dist(min_distance),
00525 max_dist_enforce(max_distance_enforce), max_dist(max_distance) { }
00526
00527 Retinal_ManagedComposite(const Retinal_ManagedComposite& b)
00528 : Retinal_Composite(b),
00529 min_dist_enforce(b.min_dist_enforce), min_dist(b.min_dist),
00530 max_dist_enforce(b.max_dist_enforce), max_dist(b.max_dist) { }
00531
00532 virtual bool next();
00533
00534 virtual Retinal_Object* clone() const
00535 { return new Retinal_ManagedComposite(*this); };
00536
00537 private:
00538 Tristate* min_dist_enforce; double* min_dist;
00539 Tristate* max_dist_enforce; double* max_dist;
00540
00541 bool distance_valid(const Retinal_Object& obj1, const Retinal_Object& obj2);
00542 bool accumulate_managed_next(bool val, Retinal_Object* r);
00543 };
00544
00545
00546
00556 class Retinal_AnchoredManagedComposite : public Retinal_ManagedComposite {
00557 public:
00558 Retinal_AnchoredManagedComposite
00559 ( const string& name_val,
00560 Tristate* min_distance_enforce, double* min_distance,
00561 Tristate* max_distance_enforce, double* max_distance,
00562 AccumulationType accum_type_i=Add, const VarMap& init_vars=VarMap(),
00563 Coordinate height_=0, Coordinate width_=0)
00564 : Retinal_ManagedComposite(name_val,
00565 min_distance_enforce, min_distance,
00566 max_distance_enforce, max_distance,
00567 accum_type_i, init_vars),
00568 height(height_), width(width_) { }
00569
00570 virtual string stringrep() const;
00571
00572 virtual Retinal_Object* clone() const
00573 { return new Retinal_AnchoredManagedComposite(*this); };
00574
00575 virtual Angle angle() const {
00576
00577 return ( (children.begin()==children.end()) ? 0 :
00578 children.back()->angle() );
00579 }
00580
00581 virtual Coordinate nominal_height() const { return height; }
00582 virtual Coordinate nominal_width() const { return width; }
00583
00584 void resize(const Coordinate height_, const Coordinate width_)
00585 { height=height_; width=width_; }
00586
00587 private:
00588 virtual Activity activ(Coordinate x, Coordinate y) const;
00589 Coordinate height;
00590 Coordinate width;
00591 };
00592
00593
00594
00595
00596
00597
00598
00600 template<class RandomGen=Distributions::uniform>
00601 class Retinal_RandomNoise : public Retinal_Object {
00602 public:
00603 Retinal_RandomNoise( const string& name_val, const VarMap& init_vars=VarMap())
00604 : Retinal_Object(name_val, init_vars) { }
00605
00606 #ifndef NO_VALGEN_STRINGS
00607 RetinalObjectStringArgs::ParamList paramlist() {
00608 RetinalObjectStringArgs::ParamList p;
00609 p.push_back("scale");
00610 p.push_back("offset");
00611 return p;
00612 }
00613 Retinal_RandomNoise( const string& name_val, RetinalObjectStringArgs& sa)
00614 : Retinal_Object(name_val,sa.vars(paramlist())) { }
00615 #endif
00616
00617 virtual Activity activation(Coordinate, Coordinate) const {
00618 const Activity rad=scale*0.5;
00619 return RandomGen()(offset+rad,rad);
00620 }
00621
00622 virtual bool update() const {
00623 scale = get_var("scale");
00624 offset = get_var("offset");
00625
00626 return Retinal_Object::update();
00627 }
00628
00629 virtual Retinal_Object* clone() const
00630 { return new Retinal_RandomNoise(*this); }
00631
00632 private:
00633 mutable Variable scale,offset;
00634 virtual Activity activ(Coordinate, Coordinate) const { return 0; }
00635 };
00636
00637 typedef Retinal_RandomNoise<> Retinal_UniformRandomNoise;
00638
00639
00641 class Retinal_CircularGaussian : public Retinal_Object {
00642 public:
00643 Retinal_CircularGaussian( const string& name_val, const VarMap& init_vars=VarMap(),
00644 const Coordinate bound_multiplier=2.5)
00645 : Retinal_Object(name_val,init_vars), bound_mult(bound_multiplier) { }
00646
00647 #ifndef NO_VALGEN_STRINGS
00648 RetinalObjectStringArgs::ParamList paramlist();
00649 Retinal_CircularGaussian( const string& name_val, RetinalObjectStringArgs& sa,
00650 const Coordinate bound_multiplier=2.5)
00651 : Retinal_Object(name_val,sa.vars(paramlist())), bound_mult(bound_multiplier) { }
00652 #endif
00653
00654 Retinal_CircularGaussian(const Retinal_CircularGaussian& b)
00655 : Retinal_Object(b), bound_mult(b.bound_mult) { }
00656
00657 virtual bool update() const;
00658
00659 virtual Retinal_Object* clone() const
00660 { return new Retinal_CircularGaussian(*this); };
00661
00662 private:
00663 const Coordinate bound_mult;
00664 mutable Variable cx,cy,div_sigmasq;
00665 virtual Activity activ(Coordinate x, Coordinate y) const;
00666 };
00667
00668
00669
00671 class Retinal_Gaussian : public Retinal_Object {
00672 public:
00673 Retinal_Gaussian( const string& name_val, const VarMap& init_vars=VarMap(),
00674 const Coordinate bound_multiplier=2.5)
00675 : Retinal_Object(name_val,init_vars), bound_mult(bound_multiplier) { }
00676
00677 #ifndef NO_VALGEN_STRINGS
00678 RetinalObjectStringArgs::ParamList paramlist();
00679 Retinal_Gaussian( const string& name_val, RetinalObjectStringArgs& sa,
00680 const Coordinate bound_multiplier=2.5)
00681 : Retinal_Object(name_val,sa.vars(paramlist())), bound_mult(bound_multiplier) { }
00682 #endif
00683
00684 Retinal_Gaussian(const Retinal_Gaussian& b)
00685 : Retinal_Object(b), bound_mult(b.bound_mult) { }
00686
00687 virtual bool update() const;
00688
00689 virtual Retinal_Object* clone() const
00690 { return new Retinal_Gaussian(*this); };
00691
00692 private:
00693 const Coordinate bound_mult;
00694 mutable Variable cx,cy,cost,sint,div_xsigma,div_ysigma;
00695 virtual Activity activ(Coordinate x, Coordinate y) const;
00696 };
00697
00698
00699
00701 class Retinal_Rectangle : public Retinal_Object {
00702 public:
00703 Retinal_Rectangle( const string& name_val, const VarMap& init_vars=VarMap())
00704 : Retinal_Object(name_val,init_vars) { }
00705
00706 #ifndef NO_VALGEN_STRINGS
00707 RetinalObjectStringArgs::ParamList paramlist();
00708 Retinal_Rectangle( const string& name_val, RetinalObjectStringArgs& sa)
00709 : Retinal_Object(name_val,sa.vars(paramlist())) { }
00710 #endif
00711
00712 virtual bool update() const;
00713
00714 virtual Retinal_Object* clone() const
00715 { return new Retinal_Rectangle(*this); };
00716
00717 private:
00718 virtual Activity activ(Coordinate, Coordinate) const
00719 { return 1.0; }
00720 };
00721
00722
00723
00725 class Retinal_SineGrating : public Retinal_Object {
00726 public:
00727 Retinal_SineGrating( const string& name_val, const VarMap& init_vars=VarMap())
00728 : Retinal_Object(name_val,init_vars) { }
00729
00730 #ifndef NO_VALGEN_STRINGS
00731 RetinalObjectStringArgs::ParamList paramlist();
00732 Retinal_SineGrating( const string& name_val, RetinalObjectStringArgs& sa)
00733 : Retinal_Object(name_val,sa.vars(paramlist())) { }
00734 #endif
00735
00736 virtual bool update() const;
00737
00738 virtual Retinal_Object* clone() const
00739 { return new Retinal_SineGrating(*this); };
00740
00741 private:
00742 mutable Variable cost,sint,phase,freq,cx,cy;
00743 virtual Activity activ(Coordinate x, Coordinate y) const;
00744 };
00745
00746
00753 class Retinal_Gabor : public Retinal_Object {
00754 public:
00755 Retinal_Gabor( const string& name_val, const VarMap& init_vars=VarMap(),
00756 const Coordinate bound_multiplier=2.5)
00757 : Retinal_Object(name_val,init_vars), bound_mult(bound_multiplier) { }
00758
00759 #ifndef NO_VALGEN_STRINGS
00760 RetinalObjectStringArgs::ParamList paramlist();
00761 Retinal_Gabor( const string& name_val, RetinalObjectStringArgs& sa,
00762 const Coordinate bound_multiplier=2.5)
00763 : Retinal_Object(name_val), bound_mult(bound_multiplier) {
00764
00765 sa.set_default("ysigma", sa.get_default("xsigma"));
00766 sa.set_default("freq", "1.0");
00767 sa.set_default("phase", "0");
00768 merge_vars(sa.vars(paramlist()));
00769 }
00770 #endif
00771
00772 Retinal_Gabor(const Retinal_Gabor& b)
00773 : Retinal_Object(b), bound_mult(b.bound_mult) { }
00774
00775 virtual bool update() const;
00776
00777 virtual Retinal_Object* clone() const
00778 { return new Retinal_Gabor(*this); };
00779
00780 private:
00781 const Coordinate bound_mult;
00782 mutable Variable cx,cy,cost,sint,div_xsigmasq,div_ysigmasq,freq,phase;
00783 virtual Activity activ(Coordinate x, Coordinate y) const;
00784 };
00785
00786
00788 class Retinal_FuzzyLine : public Retinal_Object {
00789 public:
00790 Retinal_FuzzyLine( const string& name_val, const VarMap& init_vars=VarMap() )
00791 : Retinal_Object(name_val,init_vars) { }
00792
00793 #ifndef NO_VALGEN_STRINGS
00794 RetinalObjectStringArgs::ParamList paramlist();
00795 Retinal_FuzzyLine( const string& name_val, RetinalObjectStringArgs& sa)
00796 : Retinal_Object(name_val,sa.vars(paramlist())) { }
00797 #endif
00798
00799 virtual bool update() const;
00800
00801 virtual Retinal_Object* clone() const
00802 { return new Retinal_FuzzyLine(*this); };
00803
00804 private:
00805 mutable Variable cx,cy,centerw,cost,sint,div_ysigmasq;
00806 virtual Activity activ(Coordinate x, Coordinate y) const;
00807 };
00808
00809
00812 class Retinal_FuzzyDisc : public Retinal_Object {
00813 public:
00814 Retinal_FuzzyDisc( const string& name_val, const VarMap& init_vars=VarMap() )
00815 : Retinal_Object(name_val,init_vars) { }
00816
00817 #ifndef NO_VALGEN_STRINGS
00818 RetinalObjectStringArgs::ParamList paramlist();
00819 Retinal_FuzzyDisc( const string& name_val, RetinalObjectStringArgs& sa)
00820 : Retinal_Object(name_val,sa.vars(paramlist())) { }
00821 #endif
00822
00823 virtual bool update() const;
00824
00825 virtual Retinal_Object* clone() const
00826 { return new Retinal_FuzzyDisc(*this); };
00827
00828 private:
00829 mutable Variable cx,cy,centerw,div_ysigmasq;
00830 virtual Activity activ(Coordinate x, Coordinate y) const;
00831 };
00832
00833
00836 class Retinal_FuzzyRing : public Retinal_Object {
00837 public:
00838 Retinal_FuzzyRing( const string& name_val, const VarMap& init_vars=VarMap() )
00839 : Retinal_Object(name_val,init_vars) { }
00840
00841 #ifndef NO_VALGEN_STRINGS
00842 RetinalObjectStringArgs::ParamList paramlist();
00843 Retinal_FuzzyRing( const string& name_val, RetinalObjectStringArgs& sa)
00844 : Retinal_Object(name_val,sa.vars(paramlist())) { }
00845 #endif
00846
00847 virtual bool update() const;
00848
00849 virtual Retinal_Object* clone() const
00850 { return new Retinal_FuzzyRing(*this); };
00851
00852 private:
00853 mutable Variable cx,cy,centerw,div_ysigmasq,radius;
00854 virtual Activity activ(Coordinate x, Coordinate y) const;
00855 };
00856
00857
00859 class Retinal_PGM : public Retinal_Object {
00860 public:
00861 Retinal_PGM(const string& name_val, const string& filename_base,
00862 const VarMap& init_vars=VarMap() )
00863 : Retinal_Object(name_val,init_vars), basename(filename_base), ascale(1.0),
00864 aoffset(0.0), transparent_level(-1)
00865 { set_active(pgm_read(basename,image)); border=mat::edge_average(image); }
00866
00867 #ifndef NO_VALGEN_STRINGS
00868 RetinalObjectStringArgs::ParamList paramlist();
00869 Retinal_PGM( const string& name_val, RetinalObjectStringArgs& sa,
00870 Retinal_Composite* parent);
00871 #endif
00872
00873 Retinal_PGM(const Retinal_PGM& b)
00874 : Retinal_Object(b), basename(b.basename), image(b.image),
00875 border(b.border), transparent_level(b.transparent_level) { }
00876
00877 virtual bool update() const;
00878
00879 virtual Retinal_Object* clone() const
00880 { return new Retinal_PGM(*this); };
00881
00882 virtual string stringrep() const { return Retinal_Object::stringrep()+ " " + basename; }
00883
00884 virtual bool inside(Coordinate x, Coordinate y) const;
00885
00886 private:
00887
00888 string basename;
00889 typedef MatrixType<Activity>::rectangular image_type;
00890 image_type image;
00891 mutable Variable border,cx,cy,cosmt,sinmt,div_size,xoff,yoff,ascale,aoffset;
00892 Activity transparent_level;
00893 virtual Activity activ(Coordinate x, Coordinate y) const;
00894 virtual Activity default_activ() const { return border; }
00895
00896 Activity pixel_value(Coordinate x, Coordinate y, bool& inbounds) const;
00897 };
00898
00899
00900
00901
00902
00903
00904
00912 #ifndef NO_VALGEN_STRINGS
00913 class RetinalObjectFactory {
00914 public:
00915 virtual ~RetinalObjectFactory() { }
00916
00918 virtual Retinal_Object* create(const string& name,
00919 RetinalObjectStringArgs sa,
00920 Retinal_Composite* basecomposite,
00921 Retinal_Composite* parent) const {
00922 const string typenam = sa.parsed_next("type");
00923
00924 if (typenam=="Input_CircularGaussian" ) return new Retinal_CircularGaussian (name,sa);
00925 else if (typenam=="Input_Composite" ) return new Retinal_Composite (name,sa);
00926 else if (typenam=="Input_FuzzyDisc" ) return new Retinal_FuzzyDisc (name,sa);
00927 else if (typenam=="Input_FuzzyLine" ) return new Retinal_FuzzyLine (name,sa);
00928 else if (typenam=="Input_FuzzyRing" ) return new Retinal_FuzzyRing (name,sa);
00929 else if (typenam=="Input_Gabor" ) return new Retinal_Gabor (name,sa);
00930 else if (typenam=="Input_Gaussian" ) return new Retinal_Gaussian (name,sa);
00931 else if (typenam=="Input_Rectangle" ) return new Retinal_Rectangle (name,sa);
00932 else if (typenam=="Input_PGM" ) return new Retinal_PGM (name,sa,parent);
00933 else if (typenam=="Input_SineGrating" ) return new Retinal_SineGrating (name,sa);
00934 else if (typenam=="Input_UniformRandomNoise" ) return new Retinal_UniformRandomNoise (name,sa);
00935 else if (typenam=="Input_Clone" ) return new_Retinal_Clone (name,sa,basecomposite);
00936 else {
00937 sa.error("Unknown retinal object type: `"+typenam+"'");
00938 return 0;
00939 }
00940 }
00941
00942 private:
00945 Retinal_Object* new_Retinal_Clone( const string& name_val,
00946 RetinalObjectStringArgs& sa,
00947 Retinal_Composite* basecomposite) const {
00948 const string oldname = sa.parsed_next("clone_name");
00949 Retinal_Object* oldobj = basecomposite->find(oldname);
00950 if (!oldobj) {
00951 sa.error("No object named `" + oldname + "' found to clone");
00952 return 0;
00953 }
00954
00955
00956 Retinal_Object* newobj = oldobj->clone();
00957 if (name_val!="") newobj->set_name(name_val);
00958 if (sa.master) newobj->relink(sa.master);
00959
00960 newobj->merge_vars(sa.vars(RetinalObjectStringArgs::ParamList()));
00961 newobj->reset();
00962
00963 return newobj;
00964 }
00965 };
00966 #endif
00967
00968
00969 #endif