00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef TRANSPORT_RANDOMINPUT_C_DEFINED
00040 #define TRANSPORT_RANDOMINPUT_C_DEFINED
00041
00042 #include "Transport/ShiftedImage.H"
00043
00044 #include "Image/Image.H"
00045 #include "Raster/Raster.H"
00046 #include "Image/Pixels.H"
00047
00048
00049 #include "Image/ShapeOps.H"
00050
00051 #include "Raster/GenericFrame.H"
00052
00053
00054 ShiftedImage::ShiftedImage(OptionManager& mgr)
00055 :
00056 FrameIstream(mgr, "Random Input", "ShiftedImage")
00057 {
00058 itsStep = 0;
00059
00060 itsIsPlanar = false;
00061 itsIsFoe = false;
00062 itsIsRotation = false;
00063 }
00064
00065
00066 ShiftedImage::~ShiftedImage()
00067 {}
00068
00069
00070 void ShiftedImage::setConfigInfo(const std::string& options)
00071 {
00072
00073
00074
00075
00076 LINFO("options: %s", options.c_str());
00077 if (options.size() == 0) return;
00078
00079
00080
00081
00082 std::string rops = options;
00083 std::string::size_type fcpos = rops.find_first_of(':');
00084 std::string img = rops.substr(0, fcpos);
00085 itsImage = Raster::ReadRGB(img);
00086 LINFO("Image: %s: (%d %d)",img.c_str(),
00087 itsImage.getWidth(), itsImage.getHeight());
00088
00089
00090 std::string command = rops.substr(fcpos+1);
00091 std::string::size_type fbpos = rops.find_first_of('[');
00092 std::string::size_type bbpos = rops.find_first_of(']');
00093 std::string params;
00094 if(fbpos != std::string::npos)
00095 {
00096 std::string temp = rops.substr(fcpos+1, fbpos - fcpos - 1);
00097 command = temp;
00098 params = rops.substr(fbpos+1,bbpos - fbpos - 1);
00099 }
00100 LINFO("Command: %s Params: %s", command.c_str(), params.c_str());
00101
00102
00103 if(!command.compare("planar")) setConfigPlanar(params);
00104 else
00105 if(!command.compare("foe")) setConfigFoe(params);
00106 else
00107 if(!command.compare("rotation")) setConfigRotation(params);
00108 else LFATAL("unknown ShiftedImage option: %s", command.c_str());
00109 }
00110
00111
00112 void ShiftedImage::setConfigPlanar(const std::string& params)
00113 {
00114 itsIsPlanar = true;
00115
00116 itsTotalSteps = 30;
00117
00118 itsDx = 2.0;
00119 itsDy = 0.0;
00120 LINFO("Planar Motion");
00121 }
00122
00123
00124 void ShiftedImage::setConfigFoe(const std::string& params)
00125 {
00126 itsIsFoe = true;
00127 itsFoe = Point2D<int>(160,120);
00128
00129 itsTotalSteps = 30;
00130
00131 itsDx = 0.0;
00132 itsDy = 0.0;
00133 LINFO("Focus of Expansion");
00134 }
00135
00136
00137 void ShiftedImage::setConfigRotation(const std::string& params)
00138 {
00139 itsIsRotation = true;
00140 itsRotationCenter = Point2D<int>(160,120);
00141
00142 LINFO("Rotation Motion");
00143 }
00144
00145
00146 GenericFrameSpec ShiftedImage::peekFrameSpec()
00147 {
00148 GenericFrameSpec result;
00149
00150 result.nativeType = GenericFrame::RGB_U8;
00151 result.videoFormat = VIDFMT_AUTO;
00152 result.videoByteSwap = false;
00153 result.dims = itsImage.getDims();
00154 result.floatFlags = 0;
00155
00156 return result;
00157 }
00158
00159
00160 GenericFrame ShiftedImage::readFrame()
00161 {
00162 Image<PixRGB<byte> > result;
00163
00164
00165 if(itsIsPlanar) result = getPlanarMotionStimuli(itsStep);
00166 else if(itsIsFoe) result = getFoeStimuli(itsStep);
00167 else if(itsIsRotation) result = getRotationMotionStimuli(itsStep);
00168
00169 itsStep++;
00170
00171 return GenericFrame(result);
00172 }
00173
00174
00175 Image<PixRGB<byte> > ShiftedImage::getPlanarMotionStimuli(uint step)
00176 {
00177
00178 step = step % itsTotalSteps;
00179
00180 uint width = itsImage.getWidth();
00181 uint height = itsImage.getHeight();
00182 float scale = 1.25;
00183 Image<PixRGB<byte> > temp = rescale(itsImage, scale*width, scale*height);
00184 float nwidth = temp.getWidth();
00185 float nheight = temp.getHeight();
00186
00187 float sleft = 0.0; if(itsDx < 0.0) sleft = nwidth - 1 - width;
00188 float stop = 0.0; if(itsDy < 0.0) stop = nheight - 1 - height;
00189
00190 float left = sleft + itsDx*step;
00191 float top = stop + itsDy*step;
00192
00193
00194
00195
00196 Rectangle r =
00197 Rectangle::tlbrI(top, left, top+height-1, left+width-1);
00198
00199
00200
00201
00202
00203
00204
00205
00206 Image<PixRGB<byte> > result = crop(temp, r);
00207 return result;
00208 }
00209
00210
00211 Image<PixRGB<byte> > ShiftedImage::getFoeStimuli(uint step)
00212 {
00213 uint mag = 2;
00214
00215
00216 step = step % itsTotalSteps;
00217
00218
00219 if(step == 0) return itsImage;
00220
00221 uint width = itsImage.getWidth();
00222 uint height = itsImage.getHeight();
00223
00224 float nsize = (step/(itsTotalSteps - 1.0));
00225 float scale = 1.0 / (1.0 - nsize*1.0/mag);
00226 Image<PixRGB<byte> > temp = rescale(itsImage, scale*width, scale*height);
00227 float nwidth = temp.getWidth();
00228 float nheight = temp.getHeight();
00229
00230 float px = float(itsFoe.i)/float(width);
00231 float py = float(itsFoe.j)/float(height);
00232
00233 float foeX = px*nwidth;
00234 float foeY = py*nheight;
00235
00236 LINFO("[%d] %d %d -> %f %f", step, itsFoe.i, itsFoe.j, itsDx, itsDy);
00237
00238 float left = foeX - float(itsFoe.i) + itsDx*step;
00239 float top = foeY - float(itsFoe.j) + itsDy*step;
00240
00241
00242
00243
00244
00245 Rectangle r =
00246 Rectangle::tlbrI(top, left, top+height-1, left+width-1);
00247
00248 LINFO("[%3d/%3d] FOE(%7.3f %7.3f) %f p(%7.3f %7.3f) [[%7.3f %7.3f]] "
00249 "[%3d %3d %3d %3d] temp(%3d %3d) ((%3d %3d))",
00250 step, itsTotalSteps,
00251 foeX,foeY, scale, px, py, top, left,
00252 r.top(), r.left(), r.bottomI(), r.rightI(),
00253 temp.getWidth(), temp.getHeight(),
00254 r.width(),r.height());
00255 Image<PixRGB<byte> > result = crop(temp, r);
00256
00257 return result;
00258 }
00259
00260
00261 Image<PixRGB<byte> > ShiftedImage::getRotationMotionStimuli(uint step)
00262 {
00263 uint width = itsImage.getWidth();
00264 uint height = itsImage.getHeight();
00265 Image<PixRGB<byte> > temp(width, height, ZEROS);
00266
00267 LINFO("Rotation Motion: FIXXX: NOT YET IMPLEMENTED");
00268
00269 return temp;
00270 }
00271
00272
00273
00274
00275
00276
00277
00278 #endif // TRANSPORT_RANDOMINPUT_C_DEFINED