00001
00007 #include <vector>
00008 #include <algorithm>
00009 #include <string>
00010 using std::string;
00011
00012 #include "genericalgs.h"
00013 #include "stringparser.h"
00014 #include "retinalobjs.h"
00015 #include "ipc.h"
00016 #include "cmdparam.h"
00017 #include "globals.h"
00018
00019
00020
00021
00022
00023
00025 template<class RandomGen>
00026 struct synchronized_distribution {
00027 double operator() ( double mean, double radius )
00028 {
00029 static double value;
00030 int youngest_pe = ipc_num_processes()-1;
00031 bool am_youngest_pe = (ipc_my_process() == youngest_pe);
00032
00034 if (am_youngest_pe) value = RandomGen()(mean,radius);
00035 ipc_barrier();
00036
00038 if (!am_youngest_pe) ipc_get(&value, 1, youngest_pe);
00039 const double valcopy=value;
00040 ipc_barrier();
00041
00042 return valcopy;
00043 }
00044 };
00045
00047 template<class T,
00048 class urf=synchronized_distribution<Distributions::uniform>,
00049 class nrf=synchronized_distribution<Distributions::normal> >
00050 class DistributedValueGeneratorFactory
00051 : public ValueGeneratorFactory<T,urf,nrf> { };
00052
00053
00054
00055
00056
00057
00058
00059
00061 class WorldViews : public ValueGen {
00062 public:
00063 virtual ~WorldViews() { }
00064
00066 virtual void uninit() { Generic::delete_contents(contents); }
00067
00070 virtual void define( const string& regionname, const double height, const double width);
00071
00074 virtual void generate_default_contents();
00075
00077 virtual void reset() { reset(random_seed); }
00078
00081 virtual void reset(long int seed) {
00082 std::for_each(ISEQ(contents),std::mem_fun(&Retinal_Obj::reset));
00083 shuffled_rand_reset(seed);
00084 }
00085
00086 virtual bool next();
00087
00090 bool has_been_defined() const { return !contents.empty(); }
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 !std::count_if(ISEQ(contents),std::not1(std::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 const string name = contents[eye]->name();
00141 ipc_notify(IPC_ONE,IPC_WARNING,"Not enough objects in %s to retrieve object %d",name.c_str(),objnumber);
00142 return 0;
00143 }
00144 }
00145
00147 virtual double angle_of_object_at_location(int i, int j, int eye) const
00148 { return contents[eye]->mostactive(i+0.5,j+0.5).angle(); }
00150
00151
00154 static void set_current_eye(int eye)
00155 { current_eye = eye; }
00156
00158 static void register_params_and_commands( void );
00159
00161 static cmdstat set_distribution(int dist, bool& changed);
00162
00163
00164 private:
00166 typedef ValueGenerator<Retinal_Object::Variable> VGen;
00168 typedef ValueGenerator_Random<Retinal_Object::Variable,synchronized_distribution<Distributions::uniform> > UR_VGen;
00169
00171 vector_type contents;
00172
00173
00174 static int random_seed;
00175
00176
00177 static string default_command;
00178 static string default_subcommand;
00179
00180 static string default_type;
00181 static string default_angle;
00182 static string default_position;
00183 static string default_scale;
00184 static string default_offset;
00185 static string default_xsigma;
00186 static string default_ysigma;
00187 static string default_phase;
00188 static string default_size_scale;
00189 static string default_image_filename;
00190 static string default_clone_name;
00191
00192 static string imagepath;
00193
00194 static int distribution;
00195 static double input_offset;
00196 static int inputs_pereye;
00197 static double xsigma;
00198 static double ysigma;
00199 static int current_eye;
00200 static double scale_input;
00201 static Tristate input_log;
00202 static int input_accum_type;
00203 static double input_separation_max;
00204 static Tristate input_separation_max_enforce;
00205 static double input_separation_min;
00206 static Tristate input_separation_min_enforce;
00207 };