Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

MapBuilderRequest.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_MapBuilderRequest_h_
00003 #define INCLUDED_MapBuilderRequest_h_
00004 
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "Shared/fmatSpatial.h"
00007 #include "Vision/colors.h"   // for color_index
00008 
00009 #include <queue>
00010 
00011 #include "DualCoding/BlobData.h"
00012 #include "DualCoding/MarkerData.h"
00013 #include "DualCoding/Point.h"
00014 #include "DualCoding/ShapeTypes.h"
00015 
00016 using namespace std;
00017 
00018 namespace DualCoding {
00019 
00020 class LookoutSearchRequest;
00021 
00022 class GazePoint {
00023   public:
00024     enum GazePointType_t {
00025       visible,
00026       centered
00027     } type;
00028     Point point;
00029     GazePoint(GazePointType_t _type, Point _point) : type(_type), point(_point) {}
00030     GazePoint() : type(), point() {}
00031   };
00032 
00033 class MapBuilderRequest {
00034   friend class MapBuilder;
00035 
00036 public:
00037   enum MapBuilderRequestType_t { 
00038     cameraMap, 
00039     groundMap,
00040     localMap, 
00041     worldMap
00042   };
00043 
00044   typedef unsigned int MapBuilderVerbosity_t;
00045   static coordinate_t defaultMarkerHeight;
00046 
00047   MapBuilderRequestType_t requestType;  //!< Type of map to build
00048   std::map<ShapeType_t, std::set<color_index> > objectColors;   //!< For each object type, a set of object color indices
00049   std::map<ShapeType_t, std::set<color_index> > secondColors;   //!< For two-colored objects (the bar color for dominoes)
00050   std::map<ShapeType_t, std::set<color_index> > occluderColors;   //!< For each object type, a set of occluder color indices
00051   float minLineLength; //!< Minimum length of a line with valid endpoints, for isAdmissible() test
00052   float minRayLength; //!< Minimum length of a line with an invalid endpoint, for isAdmissible() test
00053   float minEllipseSemiMajor; //!< Minimum length of ellipse semimajor axis, for isAdmissible() test
00054   std::map<color_index, int> minBlobAreas;  //!< Minimum acceptable areas for blobs of specified colors, e.g., req.minBlobAreas[pink_index]=50
00055   std::map<color_index, BlobData::BlobOrientation_t> blobOrientations; //!< Default orientation for blobs of specified colors
00056   std::map<color_index, coordinate_t> assumedBlobHeights; //!< Fixed heights for pillar or poster blobs of specified colors
00057   std::map<color_index, coordinate_t> assumedCylinderHeights; //!< Fixed heights for cylinders of specified colors
00058   std::set<MarkerType_t> markerTypes; //!< Types of markers to search for
00059   std::map<MarkerType_t, coordinate_t> markerHeights; //!< Assumed height above ground  in mm for markers of this type
00060   unsigned int floorColor;
00061   string siftDatabasePath; //!< Path to the SIFT object database to load
00062   std::set<std::string> siftObjectNames;  //!< Names of objects to search for; if empty, search for everything
00063   std::pair<int,int> aprilTagFamily; //!< AprilTag family to use, e.g., Tag16h5 would be std::pair<int,int>(16,5) 
00064   fmat::Column<3> dominoDimensions; //!< length, width, and height of a domino (in mm)
00065   fmat::Column<3> naughtDimensions; //!< length, width, and height of a naught (in mm)
00066   fmat::Column<3> crossDimensions; //!< length, width, and height of a cross (in mm)
00067   unsigned int motionSettleTime;  //!< Time in msec to wait before taking measurements or throwing completion event after head reaches gazePt.
00068   int numSamples; //!< Number of camera images to combine, for noise reduction
00069   int sampleInterval; //!< Interval in msec between successive samples
00070   float maxDist; //!< Ignore objects farther than this distance
00071   bool clearCamera; //!< If true (default), clear the camera sketch and shape spaces at start of request.
00072   bool clearLocal; //!< If true (default), clear the local sketch and shape spaces at start of request.
00073   bool clearWorld; //!< If true (default is false), clear the world sketch and shape spaces at start of request.
00074   bool ignoreCamera; //!< Don't clear or import shapes from camera space; just work in local and/or world space
00075   bool pursueShapes; //!< If true, generate new gaze points as shapes are recognized
00076   bool immediateRequest; //!< If true, the current camera image is processed immediately and results are available when MapBuilder::executeRequest() returns, so there's no need to set up an event listener.  Only possible if numSamples == 1 and no head motion is required.
00077   bool manualHeadMotion; //!< If true, waits for !msg MoveHead before moving to next gaze point (for debugging)
00078   bool rawY; //!< If true, leave an intensity (Y-channel) image in camera space for debugging
00079   bool removePts; //!< If true, remove pending gaze points if they're visible in current image
00080   bool doScan; //!< If true, do a continuous scan of the area to find interest points to be examined
00081   AngPi dTheta; //!< Angular step for scanning
00082   ShapeRoot searchArea; //!< The area to search, in egocentric or allocentric coords
00083   std::queue<LookoutSearchRequest*> worldTargets; //!< Queue of search requests for world targets
00084   void (*userImageProcessing)(); //!< User routine to call after a camera image is received
00085   void (*userCamProcessing)(); //!< User routine to call after cam space processing
00086   void (*userGroundProcessing)(); //!< User routine to call after ground space processing
00087   void (*userLocalProcessing)(); //!< User routine to call after local space processing
00088   void (*userWorldProcessing)(); //!< User routine to call after world space processing
00089   bool (*exitTest)(); //!< If true, terminate map building and post completion event
00090   enum GroundPlaneAssumption_t { onStand, onLegs, onWheel, custom } groundPlaneAssumption;
00091   PlaneEquation customGroundPlane; //!< User-supplied ground plane
00092   BehaviorBase* requestingBehavior; //!< The Behavior making this request; used for posting mapbuilder events
00093   MapBuilderVerbosity_t setVerbosity; //!< Verbosity elements to force on
00094   MapBuilderVerbosity_t clearVerbosity; //!< Verbosity elements to force off
00095   fmat::Transform baseTransform; //!< Used by the Pilot when rotating the body to simulate a pan/tilt
00096 
00097 private:
00098   std::vector<GazePoint> gazePts;
00099   std::vector<fmat::Transform> baseToCamMats;
00100   unsigned int requestID; //!< Set by mapbuilder when the request is added to its request queue
00101   MapBuilderVerbosity_t verbosity; //!< Merger of global default verbosity settings and set/clear for this request
00102 
00103 public:
00104   //! Constructor
00105   MapBuilderRequest(MapBuilderRequestType_t reqtype=cameraMap)
00106     : requestType(reqtype), objectColors(), secondColors(), occluderColors(), 
00107       minLineLength(70), minRayLength(40), minEllipseSemiMajor(9),
00108       minBlobAreas(), blobOrientations(), assumedBlobHeights(), 
00109       assumedCylinderHeights(), markerTypes(), markerHeights(), floorColor(0),
00110       siftDatabasePath(""), siftObjectNames(), aprilTagFamily(),
00111       dominoDimensions(fmat::pack(200.0, 89.0, 67.0)),
00112       naughtDimensions(fmat::pack(90.0, 90.0, 57.0)),
00113       crossDimensions(fmat::pack(100.0, 68.0, 41.0)),
00114       motionSettleTime(1000), numSamples(1), sampleInterval(0), maxDist(1e10f), 
00115       clearCamera(true), clearLocal(true), clearWorld(false), ignoreCamera(false),
00116       pursueShapes(false), immediateRequest(false), manualHeadMotion(false), rawY(true), removePts(true), 
00117       doScan(false), dTheta((float)M_PI/18),
00118       searchArea(), worldTargets(),
00119       userImageProcessing(NULL), userCamProcessing(NULL), userGroundProcessing(NULL), 
00120       userLocalProcessing(NULL), userWorldProcessing(NULL),
00121       exitTest(NULL),
00122       groundPlaneAssumption(onLegs), customGroundPlane(), requestingBehavior(NULL),
00123       setVerbosity(0), clearVerbosity(0),
00124       baseTransform(),
00125       gazePts(), baseToCamMats(),
00126       requestID(0),
00127       verbosity(0) // MapBuilder will set this during execution
00128   {}
00129 
00130   //! Copy constructor
00131   MapBuilderRequest(const MapBuilderRequest &req)
00132     : requestType(req.requestType),
00133       objectColors(req.objectColors), secondColors(req.secondColors), occluderColors(req.occluderColors),
00134       minLineLength(req.minLineLength), minRayLength(req.minRayLength),
00135       minEllipseSemiMajor(req.minEllipseSemiMajor),
00136       minBlobAreas(req.minBlobAreas), blobOrientations(req.blobOrientations), assumedBlobHeights(req.assumedBlobHeights), 
00137       assumedCylinderHeights(req.assumedCylinderHeights),
00138       markerTypes(req.markerTypes), markerHeights(req.markerHeights),
00139       floorColor(req.floorColor),
00140       siftDatabasePath(req.siftDatabasePath), siftObjectNames(req.siftObjectNames),
00141       aprilTagFamily(req.aprilTagFamily),
00142       dominoDimensions(req.dominoDimensions),
00143       naughtDimensions(req.naughtDimensions),
00144       crossDimensions(req.crossDimensions),
00145       motionSettleTime(req.motionSettleTime),
00146       numSamples(req.numSamples), sampleInterval(req.sampleInterval),
00147       maxDist(req.maxDist),
00148       clearCamera(req.clearCamera), clearLocal(req.clearLocal), clearWorld(req.clearWorld),
00149       ignoreCamera(req.ignoreCamera), pursueShapes(req.pursueShapes),
00150       immediateRequest(req.immediateRequest),
00151       manualHeadMotion(req.manualHeadMotion),
00152       rawY(req.rawY), removePts(req.removePts), 
00153       doScan(req.doScan), dTheta(req.dTheta),
00154       searchArea(req.searchArea), worldTargets(req.worldTargets),
00155       userImageProcessing(req.userImageProcessing), 
00156       userCamProcessing(req.userCamProcessing), 
00157       userGroundProcessing(req.userGroundProcessing), 
00158       userLocalProcessing(req.userLocalProcessing), 
00159       userWorldProcessing(req.userWorldProcessing),
00160       exitTest(req.exitTest),
00161       groundPlaneAssumption(req.groundPlaneAssumption),
00162       customGroundPlane(req.customGroundPlane),
00163       requestingBehavior(req.requestingBehavior),
00164       setVerbosity(req.setVerbosity), clearVerbosity(req.clearVerbosity),
00165       baseTransform(req.baseTransform),
00166       gazePts(req.gazePts), baseToCamMats(req.baseToCamMats),
00167       requestID(req.requestID), verbosity(req.verbosity)
00168       {}
00169 
00170   //! Assignment operator
00171   MapBuilderRequest& operator=(const MapBuilderRequest &req) {
00172     requestType = req.requestType;
00173     objectColors = req.objectColors;
00174     secondColors = req.secondColors;
00175     occluderColors = req.occluderColors;
00176     minLineLength = req.minLineLength;
00177     minRayLength = req.minRayLength;
00178     minEllipseSemiMajor = req.minEllipseSemiMajor;
00179     minBlobAreas = req.minBlobAreas;
00180     blobOrientations = req.blobOrientations;
00181     assumedBlobHeights = req.assumedBlobHeights;
00182     markerTypes = req.markerTypes;
00183     markerHeights = req.markerHeights;
00184     floorColor = req.floorColor;
00185     siftDatabasePath = req.siftDatabasePath;
00186     siftObjectNames = req.siftObjectNames;
00187     aprilTagFamily = req.aprilTagFamily;
00188     dominoDimensions = req.dominoDimensions;
00189     naughtDimensions = req.naughtDimensions;
00190     crossDimensions = req.crossDimensions;
00191     motionSettleTime = req.motionSettleTime;
00192     numSamples = req.numSamples;
00193     sampleInterval = req.sampleInterval;
00194     maxDist = req.maxDist;
00195     clearCamera = req.clearCamera;
00196     clearLocal = req.clearLocal;
00197     clearWorld = req.clearWorld;
00198     ignoreCamera = req.ignoreCamera;
00199     pursueShapes = req.pursueShapes;
00200     immediateRequest = req.immediateRequest;
00201     manualHeadMotion = req.manualHeadMotion;
00202     rawY = req.rawY;
00203     removePts = req.removePts;
00204     doScan = req.doScan;
00205     dTheta = req.dTheta;
00206     searchArea = req.searchArea;
00207     worldTargets = req.worldTargets;
00208     userImageProcessing = req.userImageProcessing;
00209     userCamProcessing = req.userCamProcessing;
00210     userGroundProcessing = req.userGroundProcessing;
00211     userLocalProcessing = req.userLocalProcessing;
00212     userWorldProcessing = req.userWorldProcessing;
00213     exitTest = req.exitTest;
00214     groundPlaneAssumption = req.groundPlaneAssumption;
00215     customGroundPlane = req.customGroundPlane;
00216     requestingBehavior = req.requestingBehavior;
00217     setVerbosity = req.setVerbosity;
00218     clearVerbosity = req.clearVerbosity;
00219     baseTransform = req.baseTransform;
00220     gazePts = req.gazePts;
00221     baseToCamMats = req.baseToCamMats;
00222     requestID = req.requestID;
00223     verbosity = req.verbosity;
00224     return *this;
00225   }
00226 
00227   virtual ~MapBuilderRequest() {} //!< Destructor
00228 
00229   MapBuilderRequestType_t getRequestType() const { return requestType; }
00230 
00231   //! Set of all non-zero/non-unsaturated colors (useful for requesting markers of all possible colors)
00232   std::set<color_index> allColors();
00233 
00234   //! Shortcut for specifying an objectColors entry
00235   void addObjectColor(ShapeType_t type, std::string const &color_name);
00236   
00237   //! Shortcut for specifying an objectColors entry
00238   void addObjectColor(ShapeType_t type, rgb color);
00239 
00240   //! Shortcut for specifying a secondColors entry
00241   void addSecondColor(ShapeType_t type, std::string const &color_name);
00242   
00243   //! Shortcut for specifying a secondColors entry
00244   void addSecondColor(ShapeType_t type, rgb color);
00245 
00246   //! Shortcut for specifying all object colors
00247   void addAllObjectColors(ShapeType_t type);
00248 
00249   //! Shortcut for specifying an occluderColors entry
00250   void addOccluderColor(ShapeType_t type, std::string const &color_name);
00251   
00252   //! Shortcut for specifying a minimum blob area
00253   void addMinBlobArea(std::string const &color_name, int area);
00254 
00255   //! Shortcut for specifying a minimum blob area for all blob colors
00256   void addAllMinBlobAreas(int area);
00257 
00258   //! Shortcut for specifying a blob's orientation and (for poster orientations) assumed height
00259   void addBlobOrientation(std::string const &color_name, BlobData::BlobOrientation_t orient, coordinate_t assumedHeight=0);
00260   
00261   //! Shortcut for specifying a blob's orientation and (for poster orientations) assumed height
00262   void addBlobOrientation(rgb color, BlobData::BlobOrientation_t orient, coordinate_t assumedHeight=0);
00263   
00264   //! Shortcut for specifying a cylinder's height
00265   void addCylinderHeight(std::string const &color_name, coordinate_t assumedHeight=0);
00266   
00267   //! Shortcut for specifying a cylinder's height
00268   void addCylinderHeight(rgb color, coordinate_t assumedHeight=0);
00269 
00270   //! Shortcut for specifying a marker type to look for
00271   void addMarkerType(MarkerType_t type);
00272 
00273   //! Shortcut for specifying a SIFT object type to look for
00274   void addSiftObject(string const &name);
00275 
00276   //! Look for shapes that could match this one
00277   void addAttributes(const ShapeRoot &shape);
00278 
00279   //! Shortcut for requesting AprilTag extraction using the smallest available tag family
00280   void setAprilTagFamily();
00281 
00282   //! Shortcut for selecting a specific AprilTag family
00283   void setAprilTagFamily(int bits, int minimumHammingDistance);
00284 
00285   //! Shortcut for requesting agent recognition (seeing other robots)
00286   void addAgentRecognition();
00287 
00288 protected:
00289   bool validateRequest(); //!< check object types, colors, etc.
00290   static bool validateColors(const map<ShapeType_t,set<color_index> > &shapes2colors);
00291   bool validateSift();
00292   bool validateRequestType();
00293   static bool validateAdd(ShapeType_t type, std::string const &color_name);
00294 
00295 };
00296 
00297 } // namespace
00298 
00299 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:44 2016 by Doxygen 1.6.3