Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

MapBuilderRequest.cc

Go to the documentation of this file.
00001 //-*-c++-*-
00002 
00003 #include "Shared/ProjectInterface.h"
00004 #include "Vision/SegmentedColorGenerator.h"
00005 #include "Vision/AprilTags/TagFamily.h"
00006 
00007 #include "Crew/MapBuilderRequest.h"
00008 #include "Crew/MapBuilder.h"
00009 
00010 using namespace std;
00011 
00012 namespace DualCoding {
00013 
00014 coordinate_t MapBuilderRequest::defaultMarkerHeight = 7.0f * 25.4f;  // 7 inches converted to millimeters
00015 
00016 bool MapBuilderRequest::validateRequest() {
00017   return validateColors(objectColors) & validateColors(occluderColors) & validateSift() & validateRequestType();
00018 }
00019 
00020 bool MapBuilderRequest::validateAdd(ShapeType_t type, std::string const &color_name) {
00021   if ( type >= numDataTypes ) {
00022     cerr << "*** Warning: MapBuilderRequest::addObject called with invalid shape type " << type << endl;
00023     return false;
00024   }
00025   const color_index c = ProjectInterface::getColorIndex(color_name);
00026   if ( c == -1U) {
00027     cerr << "*** Warning: MapBuilderRequest::addObject called with invalid color name '" << color_name << "'" << endl;
00028     return false;
00029   }
00030   return true;
00031 }  
00032 
00033 bool MapBuilderRequest:: validateColors(const map<ShapeType_t,set<color_index> > &shapes2colors) {
00034   color_index const numcolors = ProjectInterface::getNumColors();
00035   bool valid = true;
00036   for ( map<ShapeType_t,set<color_index> >::const_iterator shape_it = shapes2colors.begin();
00037   shape_it != shapes2colors.end(); shape_it++ ) {
00038     if ( shape_it->first == 0 || shape_it->first >= numDataTypes ) {
00039       cerr << "*** Warning: Mapbuilder request contains invalid shape type: " << shape_it->first << endl;
00040       valid = false;
00041     }
00042     for ( set<color_index>::const_iterator color_it = shape_it->second.begin();
00043     color_it != shape_it->second.end(); color_it++ )
00044       if ( *color_it > numcolors ) {
00045   valid = false;
00046   cerr << "*** Warning: MapBuilder request involving " << data_name(shape_it->first)
00047        << " contains invalid color index " << *color_it << endl;
00048       }
00049   }
00050   return valid;
00051 }
00052 
00053 bool MapBuilderRequest::validateSift() {
00054   return siftObjectNames.empty() || !siftDatabasePath.empty();
00055 }
00056 
00057 bool MapBuilderRequest:: validateRequestType() {
00058   if ( (pursueShapes || doScan || worldTargets.size()>0) &&
00059        getRequestType() == MapBuilderRequest::cameraMap ) {
00060     cout << "Warning: switching MapBuilderRequest type from cameraMap to localMap because request parameters require head movement." << endl;
00061     requestType = MapBuilderRequest::localMap;
00062   }
00063   if ( immediateRequest )
00064     if ( pursueShapes || doScan || searchArea.isValid() || worldTargets.size() > 0 || numSamples > 1 ) {
00065       cout << "Warning: MapBuilderRequest setting immedateRequest = false because of conflict with pursueShapes, doScan, searchArea, worldTargets, or numSamples" << endl;
00066       immediateRequest = false;
00067     }
00068   return true;
00069 }
00070 
00071 std::set<color_index> MapBuilderRequest::allColors() {
00072   std::set<color_index> result;
00073   for (color_index i = 1; i < ProjectInterface::defSegmentedColorGenerator->getNumColors(); i++ )
00074     if ( strcmp(ProjectInterface::getColorName(i), "unsaturated") != 0 )
00075       result.insert(i);
00076   return result;
00077 }
00078 
00079 void MapBuilderRequest::addObjectColor(ShapeType_t type, std::string const &color_name) {
00080   if ( validateAdd(type,color_name) )
00081     objectColors[type].insert(ProjectInterface::getColorIndex(color_name));
00082 }
00083 
00084 void MapBuilderRequest::addAllObjectColors(ShapeType_t type) {
00085   objectColors[type] = allColors();
00086 }
00087 
00088 void MapBuilderRequest::addOccluderColor(ShapeType_t type, std::string const &color_name) {
00089   if ( validateAdd(type,color_name) )
00090     occluderColors[type].insert(ProjectInterface::getColorIndex(color_name));
00091 }
00092  
00093 void MapBuilderRequest::addMinBlobArea(std::string const &color_name, int area) {
00094   if ( validateAdd(blobDataType,color_name) )
00095     minBlobAreas[ProjectInterface::getColorIndex(color_name)] = area;
00096 }
00097 
00098 void MapBuilderRequest::addAllMinBlobAreas(int area) {
00099   for (color_index i = 1; i < ProjectInterface::defSegmentedColorGenerator->getNumColors(); i++ )
00100     minBlobAreas[i] = area;
00101 }
00102 
00103 void MapBuilderRequest::addBlobOrientation(std::string const &color_name, BlobData::BlobOrientation_t orient, coordinate_t assumedHeight){
00104   blobOrientations[ProjectInterface::getColorIndex(color_name)] = orient;
00105   assumedBlobHeights[ProjectInterface::getColorIndex(color_name)] =  assumedHeight;
00106 }
00107  
00108 void MapBuilderRequest::addMarkerType(MarkerType_t type) {
00109   markerTypes.insert(type);
00110 }
00111 
00112 void MapBuilderRequest::addSiftObject(string const &name) {
00113   siftObjectNames.insert(name);
00114 }
00115 
00116 void MapBuilderRequest::setAprilTagFamily() {
00117   int const notFound = 100000;
00118   int bits = notFound, minimumHammingDistance;
00119   for ( std::map<std::pair<int,int>,AprilTags::TagFamily*>::const_iterator it = AprilTags::TagFamily::tagFamilyRegistry.begin();
00120   it != AprilTags::TagFamily::tagFamilyRegistry.end(); it++ )
00121     if ( it->first.first < bits ) {
00122       bits = it->first.first;
00123       minimumHammingDistance = it->first.second;
00124     }
00125   if ( bits == notFound ) {
00126     cerr << "*** Warning: MapBuilderRequest::setAprilTagFamily called but there are no tag families available!" << endl;
00127     return;
00128   }
00129   aprilTagFamily = std::pair<int,int>(bits,minimumHammingDistance);
00130 }
00131 
00132 void MapBuilderRequest::setAprilTagFamily(int bits, int minimumHammingDistance) {
00133   aprilTagFamily = std::pair<int,int>(bits,minimumHammingDistance);
00134   if ( AprilTags::TagFamily::tagFamilyRegistry[aprilTagFamily] == NULL )
00135     cerr << "*** Error: MapBuilderRequest::setAprilTagFamily cannot find requested "
00136    << bits << "h" << minimumHammingDistance << " tag family!" << endl;
00137 }
00138 
00139 
00140 
00141 } // namespace

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