Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

PerceptionSearch.h

Go to the documentation of this file.
00001 #ifndef PERCEPTION_SEARCH_H_
00002 #define PERCEPTION_SEARCH_H_
00003 
00004 // Tekkotsu Library
00005 #include "DualCoding/AgentData.h"
00006 #include "DualCoding/ShapeAgent.h"
00007 #include "DualCoding/ShapeCylinder.h"
00008 #include "DualCoding/ShapeFuns.h"
00009 #include "DualCoding/ShapeRoot.h"
00010 #include "DualCoding/VRmixin.h"
00011 #include "Crew/MapBuilder.h"
00012 #include "Shared/Measures.h"
00013 using namespace DualCoding;
00014 
00015 // C++ Library
00016 #include <cstdlib>
00017 
00018 namespace Kodu {
00019 
00020     //! Specifies the four main directions (north, east, south, and west)
00021     enum Direction_t {
00022         DT_EAST         = 0,
00023         DT_NORTH        = 1L << 1,
00024         DT_SOUTH        = 1L << 2,
00025         DT_WEST         = 1L << 3
00026     };
00027 
00028     //! Logical OR operation
00029     inline
00030     Direction_t operator|(Direction_t dt1, Direction_t dt2) {
00031         return Direction_t(static_cast<int>(dt1) | static_cast<int>(dt2));
00032     }
00033 
00034     //! Logical AND operation
00035     inline
00036     Direction_t operator&(Direction_t dt1, Direction_t dt2) {
00037         return Direction_t(static_cast<int>(dt1) & static_cast<int>(dt2));
00038     }
00039 
00040     //! Specifies what region(s) the agent should focus on when using conditions such as see and bump
00041     enum SearchLocation_t {
00042         SL_UNRESTRICTED     = 0,
00043         SL_BEHIND           = 1L << 1,
00044         SL_IN_FRONT         = 1L << 2,
00045         SL_TO_LEFT          = 1L << 3,
00046         SL_TO_RIGHT         = 1L << 4,
00047         SL_CLOSE_BY         = 1L << 5,
00048         SL_FAR_AWAY         = 1L << 6
00049     };
00050     
00051     //! Logical OR operation
00052     inline
00053     SearchLocation_t operator|(SearchLocation_t rs1, SearchLocation_t rs2) {
00054         return SearchLocation_t(static_cast<int>(rs1) | static_cast<int>(rs2));
00055     }
00056 
00057     //! Logicial OR Equals operation
00058     inline
00059     SearchLocation_t operator|=(SearchLocation_t rs1, SearchLocation_t rs2) {
00060         return (rs1 = rs1 | rs2);
00061     }
00062 
00063     //! Logical AND operation
00064     inline
00065     SearchLocation_t operator&(SearchLocation_t rs1, SearchLocation_t rs2) {
00066         return SearchLocation_t(static_cast<int>(rs1) & static_cast<int>(rs2));
00067     }
00068 
00069     class HasAprilTagID : public UnaryShapeRootPred {
00070     public:
00071         HasAprilTagID(int aprilTagId)
00072           : UnaryShapeRootPred(),
00073             id(aprilTagId)
00074         { }
00075 
00076         ~HasAprilTagID() { }
00077 
00078         bool operator()(const ShapeRoot&) const;
00079 
00080     private:
00081         int id;
00082     };
00083 
00084     class IsMatchForTargetObject : public UnaryShapeRootPred {
00085     public:
00086         IsMatchForTargetObject(const ShapeRoot& kTargetObject)
00087           : UnaryShapeRootPred(),
00088             targetObject(kTargetObject)
00089         { }
00090 
00091         ~IsMatchForTargetObject() { }
00092 
00093         bool operator()(const ShapeRoot&) const;
00094 
00095     private:
00096         ShapeRoot targetObject;
00097     };
00098 
00099     class IsNotWorldShape : public UnaryShapeRootPred {
00100     public:
00101         IsNotWorldShape()
00102           : UnaryShapeRootPred()
00103         { }
00104 
00105         ~IsNotWorldShape() { }
00106 
00107         bool operator()(const ShapeRoot&) const;
00108     };
00109 
00110     class IsStar : public UnaryShapeRootPred {
00111     public:
00112         IsStar()
00113           : UnaryShapeRootPred()
00114         { }
00115 
00116         ~IsStar() { }
00117 
00118         bool operator()(const ShapeRoot&) const;
00119     };
00120 
00121     class IsShapeOfType : public UnaryShapeRootPred {
00122     public:
00123         IsShapeOfType(ShapeType_t shapeType)
00124           : UnaryShapeRootPred(),
00125             targetShapeType(shapeType)
00126         { }
00127 
00128         ~IsShapeOfType() { }
00129 
00130         bool operator()(const ShapeRoot&) const;
00131 
00132     private:
00133         ShapeType_t targetShapeType;
00134     };
00135 
00136     class IsNotExcludedShape : public UnaryShapeRootPred {
00137     public:
00138         IsNotExcludedShape(const ShapeRoot& kExecption)
00139           : UnaryShapeRootPred(),
00140             excludedShape(kExecption)
00141         { }
00142 
00143         ~IsNotExcludedShape() { }
00144 
00145         bool operator()(const ShapeRoot&) const;
00146 
00147     private:
00148         ShapeRoot excludedShape;
00149     };
00150 
00151     class ClearSelfShape : public UnaryShapeRootPred {
00152         public:
00153             ClearSelfShape() : UnaryShapeRootPred()
00154                 {}
00155             ~ClearSelfShape() {}
00156             bool operator()(const ShapeRoot&) const;
00157     };
00158     
00159     // Assumes the "Agent" data is always valid
00160 #define PERCEPTION_SEARCH(Dir)                                                  \
00161     class Is##Dir##Agent : public UnaryShapeRootPred {              \
00162     public:                                                                     \
00163         Is##Dir##Agent() : UnaryShapeRootPred() { }                 \
00164                                                                                 \
00165         ~Is##Dir##Agent() { }                                                   \
00166                                                                                 \
00167         bool operator()(const ShapeRoot&) const;                    \
00168     };
00169 
00170     // Creates IsLeftOfAgent and IsRightOfAgent
00171     PERCEPTION_SEARCH(LeftOf);
00172     PERCEPTION_SEARCH(RightOf);
00173 
00174     // Creates IsInFrontOfAgent and IsBehindAgent
00175     PERCEPTION_SEARCH(InFront);
00176     PERCEPTION_SEARCH(Behind);
00177 
00178     // Creates IsCloseByAgent and IsFarAwayFromAgent
00179     PERCEPTION_SEARCH(CloseBy);
00180     PERCEPTION_SEARCH(FarAwayFrom);
00181 
00182     //! Calculate the bearing from the agent's position and orientation to a specified point
00183     float bearingFromAgentToPoint(const Point&);
00184 
00185     //! Calcaulate the bearing from the agent's position and orientation to a specified shape
00186     float bearingFromAgentToObject(const ShapeRoot&);
00187 
00188     //! Calculates the distance between the agent's and a specified point's centroids
00189     float distanceFromAgentToPoint(const Point&);
00190 
00191     //! Calculates the distance between the agent's and a specified shape's centroids
00192     float distanceFromAgentToObject(const ShapeRoot&);
00193 
00194     //! Calculates the length of the open space in between the agent and a specified shape
00195     float distanceInBetweenAgentAndObject(const ShapeRoot&);
00196 
00197     //! Calculates the perceived radius of a target shape
00198     float objectRadius(const ShapeRoot&);
00199 
00200     
00201 
00202     //! Returns the closest shape/object to the agent
00203     ShapeRoot getClosestObject(const std::vector<ShapeRoot>&);
00204 
00205     //! Returns the closest object to a specified point (ASSUMES point and shapes are in SAME shape space)
00206     ShapeRoot getClosestObjectToPoint(const std::vector<ShapeRoot>&, const Point&);
00207 
00208     //! Returns the objects located in the specified region(s) relative to the agent orientation
00209     std::vector<ShapeRoot> getObjectsLocated(const std::vector<ShapeRoot>&, SearchLocation_t);
00210 
00211     //! Returns the objects that are a specified color
00212     std::vector<ShapeRoot> getMatchingObjects(const std::vector<ShapeRoot>& kObjects,
00213                                               const std::string& kColor, const std::string& kType);
00214 
00215     //! Returns the closest object that matches the specified criteria (excluding the specified shape)
00216     ShapeRoot getClosestObjectMatching(const std::string& color, const std::string& type, SearchLocation_t location,
00217                                        const ShapeRoot& kExcludedShape = ShapeRoot());
00218 }
00219 
00220 #endif // PERCEPTION_SEARCH_H_

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