00001
00002 #ifndef INCLUDED_LookoutRequests_h_
00003 #define INCLUDED_LookoutRequests_h_
00004
00005 #include "Shared/ProjectInterface.h"
00006 #include "Shared/WorldState.h"
00007
00008 #include "DualCoding/Sketch.h"
00009 #include "DualCoding/Point.h"
00010 #include "DualCoding/ShapeRoot.h"
00011 #include "DualCoding/VRmixin.h"
00012
00013 namespace DualCoding {
00014
00015
00016 class LookoutRequestBase {
00017 public:
00018
00019 enum HeadMotionType_t {
00020 noMotion,
00021 pointAt,
00022 scan,
00023 track,
00024 search,
00025 numHeadMotionTypes
00026 };
00027
00028 static const char* const headMotionTypeNames[numHeadMotionTypes];
00029
00030 HeadMotionType_t getHeadMotionType() const { return headMotionType; }
00031 void setHeadMotionType(const HeadMotionType_t htype) { headMotionType = htype; }
00032
00033 enum LookoutResultType_t {
00034 noResult,
00035 imageResult,
00036 distanceResult,
00037 interestPoints
00038 };
00039
00040 LookoutResultType_t getResultType() const { return resultType; }
00041 void setResultType(const LookoutResultType_t rtype) { resultType = rtype; }
00042
00043
00044 LookoutRequestBase(HeadMotionType_t htype=noMotion, LookoutResultType_t rtype=noResult) :
00045 headMotionType(htype), resultType(rtype), requestID(0) {}
00046
00047
00048 virtual ~LookoutRequestBase() {}
00049
00050
00051 LookoutRequestBase(const LookoutRequestBase &req) :
00052 headMotionType(req.headMotionType),
00053 resultType(req.resultType),
00054 requestID(req.requestID) {}
00055
00056 HeadMotionType_t headMotionType;
00057 LookoutResultType_t resultType;
00058 unsigned int requestID;
00059
00060 private:
00061 LookoutRequestBase& operator=(const LookoutRequestBase&);
00062
00063 public:
00064
00065
00066 class Task {
00067 public:
00068 enum TaskType_t { noTask, visObjTask, visRegTask, irTask };
00069
00070 virtual TaskType_t getTaskType() const = 0;
00071 virtual Task* clone() const = 0;
00072
00073
00074 Task(AngPi _dTheta) : dTheta(_dTheta), data() {}
00075
00076
00077 Task(const Task& t) : dTheta(t.dTheta), data(t.data) {}
00078
00079
00080 virtual ~Task() {}
00081
00082 AngPi dTheta;
00083 std::vector<Point> data;
00084 Task& operator=(const Task&);
00085 };
00086
00087 class IRTask : public Task {
00088 public:
00089 IRTask(AngPi _dTheta) : Task(_dTheta) {}
00090 IRTask(const IRTask& t) : Task(t) {}
00091 virtual TaskType_t getTaskType() const { return irTask; }
00092 virtual Task* clone() const { return new IRTask(*this); }
00093 };
00094
00095
00096 class VisionTask : public Task {
00097 public:
00098 virtual TaskType_t getTaskType() const { return noTask; }
00099 std::set<color_index> index;
00100 VisionTask(const VisionTask& vt) : Task(vt), index(vt.index) {}
00101 VisionTask(const std::set<color_index>& _index, AngPi _dTheta)
00102 : Task(_dTheta), index(_index) {}
00103 VisionTask(int _index, AngPi _dTheta)
00104 : Task(_dTheta), index() { index.insert(_index); }
00105 virtual Task* clone() const { return new VisionTask(*this); }
00106 };
00107
00108
00109 class VisionObjectTask : public VisionTask {
00110 public:
00111 VisionObjectTask(const std::set<color_index>& sid, AngPi _dTheta=0)
00112 : VisionTask(sid,_dTheta) {}
00113 VisionObjectTask(const VisionObjectTask& vot) : VisionTask(vot) {}
00114 virtual TaskType_t getTaskType() const { return visObjTask; }
00115 virtual Task* clone() const { return new VisionObjectTask(*this); }
00116 };
00117
00118
00119 class VisionRegionTask : public VisionTask {
00120 public:
00121 VisionRegionTask(const std::set<color_index>& colorIndex, AngPi _dTheta=0,
00122 unsigned int _minArea=200)
00123 : VisionTask(colorIndex,_dTheta), minArea(_minArea) {}
00124 VisionRegionTask(int colorIndex, AngPi _dTheta,
00125 unsigned int _minArea=200)
00126 : VisionTask(colorIndex,_dTheta), minArea(_minArea) {}
00127 VisionRegionTask(const VisionRegionTask& vrt)
00128 : VisionTask(vrt), minArea(vrt.minArea) {}
00129 virtual TaskType_t getTaskType() const { return visRegTask; }
00130 virtual Task* clone() const { return new VisionRegionTask(*this); }
00131 unsigned int minArea;
00132 };
00133
00134
00135
00136 };
00137
00138
00139
00140
00141 class LookoutPointRequest : public LookoutRequestBase {
00142 public:
00143
00144 LookoutPointRequest() :
00145 LookoutRequestBase(noMotion,imageResult),
00146 #ifdef TGT_HAS_CAMERA
00147 joint(CameraFrameOffset),
00148 #else
00149 joint(0),
00150 #endif
00151 toBaseMatrix(),
00152 gazePt(), motionSettleTime(1000),
00153 numSamples(1), sampleCounter(0), sampleInterval(0),
00154 image(), sketchFunc(VRmixin::sketchFromSeg)
00155 {}
00156
00157
00158 LookoutPointRequest(const LookoutPointRequest &p)
00159 : LookoutRequestBase(p), joint(p.joint), toBaseMatrix(p.toBaseMatrix),
00160 gazePt(p.gazePt), motionSettleTime(p.motionSettleTime),
00161 numSamples(p.numSamples), sampleCounter(p.sampleCounter), sampleInterval(p.sampleInterval),
00162 image(p.image), sketchFunc(p.sketchFunc)
00163 {}
00164
00165 public:
00166 void setTarget(const Point &target) {
00167 gazePt = target;
00168 headMotionType = pointAt;
00169 }
00170
00171 unsigned int joint;
00172 fmat::Transform toBaseMatrix;
00173 Point gazePt;
00174 unsigned int motionSettleTime;
00175 int numSamples;
00176 int sampleCounter;
00177 int sampleInterval;
00178 Sketch<uchar> image;
00179 Sketch<uchar> (*sketchFunc)();
00180
00181 private:
00182 LookoutPointRequest& operator=(const LookoutPointRequest&);
00183 };
00184
00185
00186
00187
00188 class LookoutScanRequest : public LookoutRequestBase {
00189 public:
00190
00191 std::vector<Task*> tasks;
00192 float scanSpeed;
00193 ShapeRoot searchArea;
00194 unsigned int motionSettleTime;
00195
00196 static const float defSpd;
00197
00198
00199 LookoutScanRequest(float _speed=defSpd):
00200 LookoutRequestBase(scan,interestPoints),
00201 tasks(), scanSpeed(_speed), searchArea(), motionSettleTime(1000) {}
00202
00203
00204 LookoutScanRequest(const Task& _task, float _speed=defSpd) :
00205 LookoutRequestBase(scan,interestPoints), tasks(), scanSpeed(_speed), searchArea(), motionSettleTime(1000)
00206 { addTask(_task); }
00207
00208
00209 LookoutScanRequest(const LookoutScanRequest& req)
00210 : LookoutRequestBase(req), tasks(), scanSpeed(req.scanSpeed), searchArea(req.searchArea), motionSettleTime(req.motionSettleTime)
00211 {
00212 for (std::vector<Task*>::const_iterator it = req.tasks.begin();
00213 it != req.tasks.end(); it++)
00214 addTask(**it);
00215 }
00216
00217
00218 virtual ~LookoutScanRequest();
00219
00220 void addTask(const Task& t) { tasks.push_back(t.clone()); }
00221
00222 };
00223
00224
00225
00226
00227
00228
00229 class LookoutTrackRequest : public LookoutRequestBase {
00230 public:
00231
00232 friend class Lookout;
00233
00234
00235 LookoutTrackRequest(const ShapeRoot& target=ShapeRoot())
00236 : LookoutRequestBase(track), targetShape(target),
00237 minBlobArea(80), exitTest(NULL), cindex(0) {}
00238
00239
00240 LookoutTrackRequest(const LookoutTrackRequest& req)
00241 : LookoutRequestBase(req), targetShape(req.targetShape),
00242 minBlobArea(req.minBlobArea), exitTest(req.exitTest), cindex(req.cindex) {}
00243
00244 ShapeRoot targetShape;
00245 int minBlobArea;
00246 bool (*exitTest)();
00247
00248 LookoutTrackRequest& operator=(const LookoutTrackRequest&);
00249
00250 private:
00251 color_index cindex;
00252 };
00253
00254
00255
00256
00257
00258 class LookoutSearchRequest : public LookoutRequestBase {
00259 public:
00260
00261 friend class Lookout;
00262
00263
00264 LookoutSearchRequest(const ShapeRoot& target=ShapeRoot())
00265 : LookoutRequestBase(search,imageResult), targetShape(target),
00266 minBlobArea(80), exitTest(NULL), image(),
00267 #ifdef TGT_HAS_CAMERA
00268 joint(CameraFrameOffset),
00269 #else
00270 joint(0),
00271 #endif
00272 toBaseMatrix(),
00273 cindex(0) {}
00274
00275
00276 LookoutSearchRequest(const LookoutSearchRequest& req)
00277 : LookoutRequestBase(req), targetShape(req.targetShape),
00278 minBlobArea(req.minBlobArea), exitTest(req.exitTest),
00279 image(req.image), joint(req.joint), toBaseMatrix(req.toBaseMatrix),
00280 cindex(req.cindex) {}
00281
00282 ShapeRoot targetShape;
00283 int minBlobArea;
00284 bool (*exitTest)();
00285 Sketch<uchar> image;
00286 unsigned int joint;
00287 fmat::Transform toBaseMatrix;
00288
00289 private:
00290 color_index cindex;
00291
00292 LookoutSearchRequest& operator=(const LookoutSearchRequest&);
00293 };
00294
00295
00296 }
00297
00298 #endif