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 MapBuilderRequest {
00023   friend class MapBuilder;
00024 
00025 public:
00026   enum MapBuilderRequestType_t { 
00027     cameraMap, 
00028     groundMap,
00029     localMap, 
00030     worldMap
00031   };
00032 
00033   typedef unsigned int MapBuilderVerbosity_t;
00034   static coordinate_t defaultMarkerHeight;
00035 
00036   MapBuilderRequestType_t requestType;  //!< Type of map to build
00037   std::map<ShapeType_t, std::set<color_index> > objectColors;   //!< For each object type, a set of object color indices
00038   std::map<ShapeType_t, std::set<color_index> > occluderColors;   //!< For each object type, a set of occluder color indices
00039   std::map<color_index, int> minBlobAreas;  //!< Minimum acceptable areas for blobs of specified colors, e.g., req.minBlobAreas[pink_index]=50
00040   std::map<color_index, BlobData::BlobOrientation_t> blobOrientations; //!< Default orientation for blobs of specified colors
00041   std::map<color_index, coordinate_t> assumedBlobHeights; //!< Fixed heights for pillar or poster blobs of specified colors
00042   std::set<MarkerType_t> markerTypes; //!< Types of markers to search for
00043   std::map<MarkerType_t, coordinate_t> markerHeights; //!< Assumed height above ground  in mm for markers of this type
00044   unsigned int floorColor;
00045   string siftDatabasePath; //!< Path to the SIFT object database to load
00046   std::set<std::string> siftObjectNames;  //!< Names of objects to search for; if empty, search for everything
00047   std::pair<int,int> aprilTagFamily; //!< AprilTag family to use, e.g., Tag16h5 would be std::pair<int,int>(16,5) 
00048   unsigned int motionSettleTime;  //!< Time in msec to wait before taking measurements or throwing completion event after head reaches gazePt.
00049   int numSamples; //!< Number of camera images to combine, for noise reduction
00050   int sampleInterval; //!< Interval in msec between successive samples
00051   float maxDist; //!< Ignore objects farther than this distance
00052   bool clearCamera; //!< If true (default), clear the camera sketch and shape spaces at start of request.
00053   bool clearLocal; //!< If true (default), clear the local sketch and shape spaces at start of request.
00054   bool clearWorld; //!< If true (default is false), clear the world sketch and shape spaces at start of request.
00055   bool pursueShapes; //!< If true, generate new gaze points as shapes are recognized
00056   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.
00057   bool manualHeadMotion; //!< If true, waits for !msg MoveHead before moving to next gaze point (for debugging)
00058   bool rawY; //!< If true, leave an intensity (Y-channel) image in camera space for debugging
00059   bool removePts; //!< If true, remove pending gaze points if they're visible in current image
00060   bool doScan; //!< If true, do a continuous scan of the area to find interest points to be examined
00061   AngPi dTheta; //!< Angular step for scanning
00062   ShapeRoot searchArea; //!< The area to search, in egocentric coords
00063   std::queue<LookoutSearchRequest*> worldTargets; //!< Queue of search requests for world targets
00064   void (*userImageProcessing)(); //!< User routine to call after a camera image is received
00065   void (*userCamProcessing)(); //!< User routine to call after cam space processing
00066   void (*userGroundProcessing)(); //!< User routine to call after ground space processing
00067   void (*userLocalProcessing)(); //!< User routine to call after local space processing
00068   void (*userWorldProcessing)(); //!< User routine to call after world space processing
00069   bool (*exitTest)(); //!< If true, terminate map building and post completion event
00070   enum GroundPlaneAssumption_t { onStand, onLegs, onWheel, custom } groundPlaneAssumption;
00071   PlaneEquation customGroundPlane; //!< User-supplied ground plane
00072   BehaviorBase* requestingBehavior; //!< The Behavior making this request; used for posting mapbuilder events
00073   MapBuilderVerbosity_t setVerbosity; //!< Verbosity elements to force on
00074   MapBuilderVerbosity_t clearVerbosity; //!< Verbosity elements to force off
00075   fmat::Transform baseTransform; //!< Used by the Pilot when rotating the body to simulate a pan/tilt
00076 
00077 private:
00078   std::vector<Point> gazePts;
00079   std::vector<fmat::Transform> baseToCamMats;
00080   unsigned int requestID; //!< Set by mapbuilder when the request is added to its request queue
00081   MapBuilderVerbosity_t verbosity; //!< Merger of global default verbosity settings and set/clear for this request
00082 
00083 public:
00084   //! Constructor
00085   MapBuilderRequest(MapBuilderRequestType_t reqtype=cameraMap)
00086     : requestType(reqtype), objectColors(), occluderColors(), 
00087       minBlobAreas(), blobOrientations(), assumedBlobHeights(), markerTypes(), markerHeights(), floorColor(0),
00088       siftDatabasePath(""), siftObjectNames(), aprilTagFamily(),
00089       motionSettleTime(1000), numSamples(1), sampleInterval(0), maxDist(1e10f), 
00090       clearCamera(true), clearLocal(true), clearWorld(false),
00091       pursueShapes(false), immediateRequest(false), manualHeadMotion(false), rawY(true), removePts(true), 
00092       doScan(false), dTheta((float)M_PI/18),
00093       searchArea(), worldTargets(),
00094       userImageProcessing(NULL), userCamProcessing(NULL), userGroundProcessing(NULL), 
00095       userLocalProcessing(NULL), userWorldProcessing(NULL),
00096       exitTest(NULL),
00097       groundPlaneAssumption(onLegs), customGroundPlane(), requestingBehavior(NULL),
00098       setVerbosity(0), clearVerbosity(0),
00099       baseTransform(),
00100       gazePts(), baseToCamMats(),
00101       requestID(0),
00102       verbosity(0) // MapBuilder will set this during execution
00103   {}
00104 
00105   //! Copy constructor
00106   MapBuilderRequest(const MapBuilderRequest &req)
00107     : requestType(req.requestType),
00108       objectColors(req.objectColors), occluderColors(req.occluderColors), 
00109       minBlobAreas(req.minBlobAreas), blobOrientations(req.blobOrientations), assumedBlobHeights(req.assumedBlobHeights),
00110       markerTypes(req.markerTypes), markerHeights(req.markerHeights),
00111       floorColor(req.floorColor),
00112       siftDatabasePath(req.siftDatabasePath), siftObjectNames(req.siftObjectNames),
00113       aprilTagFamily(req.aprilTagFamily),
00114       motionSettleTime(req.motionSettleTime),
00115       numSamples(req.numSamples), sampleInterval(req.sampleInterval),
00116       maxDist(req.maxDist),
00117       clearCamera(req.clearCamera), clearLocal(req.clearLocal), clearWorld(req.clearWorld),
00118       pursueShapes(req.pursueShapes),
00119       immediateRequest(req.immediateRequest),
00120       manualHeadMotion(req.manualHeadMotion),
00121       rawY(req.rawY), removePts(req.removePts), 
00122       doScan(req.doScan), dTheta(req.dTheta),
00123       searchArea(req.searchArea), worldTargets(req.worldTargets),
00124       userImageProcessing(req.userImageProcessing), 
00125       userCamProcessing(req.userCamProcessing), 
00126       userGroundProcessing(req.userGroundProcessing), 
00127       userLocalProcessing(req.userLocalProcessing), 
00128       userWorldProcessing(req.userWorldProcessing),
00129       exitTest(req.exitTest),
00130       groundPlaneAssumption(req.groundPlaneAssumption),
00131       customGroundPlane(req.customGroundPlane),
00132       requestingBehavior(req.requestingBehavior),
00133       setVerbosity(req.setVerbosity), clearVerbosity(req.clearVerbosity),
00134       baseTransform(req.baseTransform),
00135       gazePts(req.gazePts), baseToCamMats(req.baseToCamMats),
00136       requestID(req.requestID), verbosity(req.verbosity)
00137       {}
00138 
00139   //! Assignment operator
00140   MapBuilderRequest& operator=(const MapBuilderRequest &req) {
00141     requestType = req.requestType;
00142     objectColors = req.objectColors;
00143     occluderColors = req.occluderColors;
00144     minBlobAreas = req.minBlobAreas;
00145     blobOrientations = req.blobOrientations;
00146     assumedBlobHeights = req.assumedBlobHeights;
00147     markerTypes = req.markerTypes;
00148     markerHeights = req.markerHeights;
00149     floorColor = req.floorColor;
00150     siftDatabasePath = req.siftDatabasePath;
00151     siftObjectNames = req.siftObjectNames;
00152     aprilTagFamily = req.aprilTagFamily;
00153     motionSettleTime = req.motionSettleTime;
00154     numSamples = req.numSamples;
00155     sampleInterval = req.sampleInterval;
00156     maxDist = req.maxDist;
00157     clearCamera = req.clearCamera;
00158     clearLocal = req.clearLocal;
00159     clearWorld = req.clearWorld;
00160     pursueShapes = req.pursueShapes;
00161     immediateRequest = req.immediateRequest;
00162     manualHeadMotion = req.manualHeadMotion;
00163     rawY = req.rawY;
00164     removePts = req.removePts;
00165     doScan = req.doScan;
00166     dTheta = req.dTheta;
00167     searchArea = req.searchArea;
00168     worldTargets = req.worldTargets;
00169     userImageProcessing = req.userImageProcessing;
00170     userCamProcessing = req.userCamProcessing;
00171     userGroundProcessing = req.userGroundProcessing;
00172     userLocalProcessing = req.userLocalProcessing;
00173     userWorldProcessing = req.userWorldProcessing;
00174     exitTest = req.exitTest;
00175     groundPlaneAssumption = req.groundPlaneAssumption;
00176     customGroundPlane = req.customGroundPlane;
00177     requestingBehavior = req.requestingBehavior;
00178     setVerbosity = req.setVerbosity;
00179     clearVerbosity = req.clearVerbosity;
00180     baseTransform = req.baseTransform;
00181     gazePts = req.gazePts;
00182     baseToCamMats = req.baseToCamMats;
00183     requestID = req.requestID;
00184     verbosity = req.verbosity;
00185     return *this;
00186   }
00187 
00188   virtual ~MapBuilderRequest() {} //!< Destructor
00189 
00190   MapBuilderRequestType_t getRequestType() const { return requestType; }
00191 
00192   //! Set of all non-zero/non-unsaturated colors (useful for requesting markers of all possible colors)
00193   std::set<color_index> allColors();
00194 
00195   //! Shortcut for specifying an objectColors entry
00196   void addObjectColor(ShapeType_t type, std::string const &color_name);
00197 
00198   //! Shortcut for specifying all object colors
00199   void addAllObjectColors(ShapeType_t type);
00200 
00201   //! Shortcut for specifying an occluderColors entry
00202   void addOccluderColor(ShapeType_t type, std::string const &color_name);
00203   
00204   //! Shortcut for specifying a minimum blob area
00205   void addMinBlobArea(std::string const &color_name, int area);
00206 
00207   //! Shortcut for specifying a minimum blob area for all blob colors
00208   void addAllMinBlobAreas(int area);
00209 
00210   //! Shortcut for specifying a blob's orientation and (for poster orientations) assumed height
00211   void addBlobOrientation(std::string const &color_name, BlobData::BlobOrientation_t orient, coordinate_t assumedHeight=0);
00212   
00213   //! Shortcut for specifying a marker type to look for
00214   void addMarkerType(MarkerType_t type);
00215 
00216   //! Shortcut for specifying a SIFT object type to look for
00217   void addSiftObject(string const &name);
00218 
00219   //! Shortcut for requesting AprilTag extraction using the smallest available tag family
00220   void setAprilTagFamily();
00221 
00222   //! Shortcut for selecting a specific AprilTag family
00223   void setAprilTagFamily(int bits, int minimumHammingDistance);
00224 
00225 protected:
00226   bool validateRequest(); //!< check object types, colors, etc.
00227   static bool validateColors(const map<ShapeType_t,set<color_index> > &shapes2colors);
00228   bool validateSift();
00229   bool validateRequestType();
00230   static bool validateAdd(ShapeType_t type, std::string const &color_name);
00231 
00232 };
00233 
00234 } // namespace
00235 
00236 #endif

Tekkotsu v5.1CVS
Generated Fri Mar 16 05:26:44 2012 by Doxygen 1.6.3