00001
00007 #include <vector>
00008 #include <string>
00009
00010 #include "genericalgs.h"
00011 #include "stringparser.h"
00012 #include "retinalobjs.h"
00013 #include "ipc.h"
00014 #include "cmdparam.h"
00015 #include "globals.h"
00016
00017
00018
00019
00020
00021
00023 template<randomgen_fnPtr random_fn>
00024 double synchronized_distribution ( double mean, double radius )
00025 {
00026 static double value;
00027 int youngest_pe = ipc_num_processes()-1;
00028 bool am_youngest_pe = (ipc_my_process() == youngest_pe);
00029
00031 if (am_youngest_pe) value = (random_fn)(mean,radius);
00032 ipc_barrier();
00033
00035 if (!am_youngest_pe) ipc_get(&value, 1, youngest_pe);
00036 const double valcopy=value;
00037 ipc_barrier();
00038
00039 return valcopy;
00040 }
00041
00042
00043
00045 template<class T,
00046 randomgen_fnPtr urf=synchronized_distribution<uniform_distribution>,
00047 randomgen_fnPtr nrf=synchronized_distribution<normal_distribution> >
00048 class DistributedValueGeneratorFactory : public ValueGeneratorFactory<T,urf,nrf> {
00049 public:
00050 DistributedValueGeneratorFactory() : ValueGeneratorFactory<T,urf,nrf>() { };
00051 virtual ~DistributedValueGeneratorFactory() { }
00052 virtual void error (const string& s) const { ipc_notify(IPC_ONE,IPC_ERROR, s.c_str()); }
00053 virtual void warning(const string& s) const { ipc_notify(IPC_ONE,IPC_WARNING,s.c_str()); }
00054 };
00055
00056
00057
00058
00059
00060
00061
00062
00064 class WorldViews : public ValueGen {
00065 public:
00066 virtual ~WorldViews() { }
00067
00069 virtual void uninit() { Generic::delete_contents(contents); }
00070
00074 virtual void init();
00075
00077 virtual void reset() { reset(random_seed); }
00078
00081 virtual void reset(long int seed) {
00082 for_each(ISEQ(contents),mem_fun(&Retinal_Obj::reset));
00083 shuffled_rand_reset(seed);
00084 }
00085
00086 virtual bool next();
00087
00090 void define( unsigned n_eyes=num_eyes );
00091 bool create_object(StringArgs arglist, const string& name,
00092 WorldViews& reference_contents, bool link_eyes=true);
00093 void remove_object(const string& parent="", const string& name="");
00094 void print_object ( const string& parent="", const string& name="") const;
00096 bool is_empty() const { return !count_if(ISEQ(contents),not1(mem_fun(&Retinal_Composite::is_empty))); }
00098
00101
00103 typedef Retinal_Composite* value_type;
00105 typedef std::vector<value_type> vector_type;
00107 typedef vector_type::iterator iterator;
00109 typedef vector_type::const_iterator const_iterator;
00111 iterator begin() { return contents.begin(); }
00113 iterator end() { return contents.end(); }
00115 const_iterator begin() const { return contents.begin(); }
00117 const_iterator end() const { return contents.end(); }
00119
00122 const Retinal_Obj* view(int eye) const {
00123 return contents[eye];
00124 }
00125
00128
00130 virtual bool is_active(int objnumber, int eye) const {
00131 return (objnumber>= int(contents[eye]->size()) ? false :
00132 ((*contents[eye])[objnumber]->get_active()));
00133 }
00134
00136 virtual double angle_of_object(int objnumber, int eye) const {
00137 if (objnumber< int(contents[eye]->size()))
00138 return contents[eye][objnumber].angle();
00139 else {
00140 ipc_notify(IPC_ONE,IPC_WARNING,"Not enough objects in eye to retrieve object %d",objnumber);
00141 return 0;
00142 }
00143 }
00144
00146 virtual double angle_of_object_at_location(int i, int j, int eye) const
00147 { return contents[eye]->mostactive(i+0.5,j+0.5).angle(); }
00149
00150
00153 static void set_current_eye(int eye)
00154 { current_eye = eye; }
00155
00157 static void register_params_and_commands( void );
00158
00160 static cmdstat set_distribution(int dist, bool& changed);
00161
00162
00163 private:
00165 typedef ValueGenerator<Retinal_Object::Variable> VGen;
00167 typedef ValueGenerator_Random<Retinal_Object::Variable,synchronized_distribution<uniform_distribution> > UR_VGen;
00168
00170 vector_type contents;
00171
00172
00173 static int random_seed;
00174
00175
00176 static char default_command[CMD_MAX_LINE_LENGTH];
00177
00178 static const int MAX_INPUT_DEFAULT_LENGTH=128;
00179 static char default_type[MAX_INPUT_DEFAULT_LENGTH];
00180 static char default_angle[MAX_INPUT_DEFAULT_LENGTH];
00181 static char default_position[MAX_INPUT_DEFAULT_LENGTH];
00182 static char default_scale[MAX_INPUT_DEFAULT_LENGTH];
00183 static char default_offset[MAX_INPUT_DEFAULT_LENGTH];
00184 static char default_xsigma[MAX_INPUT_DEFAULT_LENGTH];
00185 static char default_ysigma[MAX_INPUT_DEFAULT_LENGTH];
00186 static char default_phase[MAX_INPUT_DEFAULT_LENGTH];
00187 static char default_size_scale[MAX_INPUT_DEFAULT_LENGTH];
00188 static char default_image_filename[MAX_INPUT_DEFAULT_LENGTH];
00189 static char default_clone_name[CMD_MAX_LINE_LENGTH];
00190
00191 static char imagepath[CMD_MAX_LINE_LENGTH];
00192
00193 static int distribution;
00194 static double input_offset;
00195 static int inputs_pereye;
00196 static double xsigma;
00197 static double ysigma;
00198 static int current_eye;
00199 static double scale_input;
00200 static int input_log;
00201 static int input_accum_type;
00202 static double input_separation_max;
00203 static int input_separation_max_enforce;
00204 static double input_separation_min;
00205 static int input_separation_min_enforce;
00206 };