Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

VRmixin.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef _VRmixin_h_
00003 #define _VRmixin_h_
00004 
00005 #include <string>
00006 #include <iostream>
00007 
00008 #include "Behaviors/BehaviorBase.h"
00009 #include "Shared/fmatSpatial.h"
00010 #include "Vision/RawCameraGenerator.h"
00011 #include "Motion/WalkMC.h" // so we can test for TGT_HAS_WALK (Pilot support)
00012 
00013 #include "ShapeAgent.h"
00014 #include "BlobData.h"
00015 #include "SketchRoot.h"
00016 
00017 #if (defined(TGT_HAS_ARMS) || !defined(STRICT_TGT_MODEL)) && !defined(TGT_IS_AIBO)
00018 class Grasper;
00019 #endif
00020 
00021 namespace DualCoding {
00022 
00023 class Lookout;
00024 #ifdef TGT_HAS_WALK
00025 class Pilot;
00026 #endif
00027 class SketchDataRoot;
00028 class SketchSpace;
00029 class ShapeRoot;
00030 class MapBuilder;
00031 class ShapeBasedParticleFilter;
00032 class VisualOdometry;//ImageProfileOdometry;
00033   
00034 typedef unsigned char cmap_t;
00035 
00036 //! Mix-in for the BehaviorBase or StateNode class to give access to VisualRoutinesBehavior variables.
00037 class VRmixin {
00038 protected:
00039   static unsigned int instanceCount; //!< count of VRmixin instances -- when this hits zero, free sketch spaces
00040   static unsigned int crewCount; //!< count of "crew" (pilot, lookout, map builders) users -- stop these when no one is using them
00041   
00042 public:
00043   //! returns reference to the global space instances, call there from global constructors instead of accessing #camSkS, which might not be initialized yet
00044   static SketchSpace& getCamSkS();
00045   static SketchSpace& getLocalSkS();
00046   static SketchSpace& getWorldSkS();
00047   static ShapeSpace& getGroundShS();
00048 
00049   static SketchSpace& camSkS;      //!< The camera sketch space
00050   static ShapeSpace& camShS;       //!< The camera shape space
00051   
00052   static ShapeSpace& groundShS;    //!< The ground shape space of MapBuilder (MapBuilder::groundShS)
00053   
00054   static SketchSpace& localSkS;    //!< The localmap sketch space (LocalMapBuilder::localSkS)
00055   static ShapeSpace& localShS;     //!< The localmap shape space (LocalMapBuilder::localShS)
00056   
00057   static SketchSpace& worldSkS;    //!< The worldmap sketch space (WorldMapBuilder::localSkS)
00058   static ShapeSpace& worldShS;     //!< The worldmap sketch space (WorldMapBuilder::localShS)
00059   static Shape<AgentData> theAgent; //!< The robot (usually lives in worldShS)
00060   
00061   static MapBuilder* mapBuilder;   //!< the global world mapbuilder instance
00062   static Lookout* lookout;         //!< the global Lookout instance
00063 #ifdef TGT_HAS_WALK
00064   static Pilot* pilot;              //!< the global Pilot instance
00065 #endif
00066 #if (defined(TGT_HAS_ARMS) || !defined(STRICT_TGT_MODEL)) && !defined(TGT_IS_AIBO)
00067   static Grasper* grasper;
00068 #endif
00069   
00070   static ShapeBasedParticleFilter *particleFilter;   //!< the global particle filter instance
00071   static bool isWalkingFlag;  //flag indicating if the robot is walking.
00072 
00073 private:
00074   static Socket *camDialogSock;    //!< socket to talk with cam-space sketch viewer
00075   static Socket *camSketchSock;       //!< socket for transmitting sketch images to cam-space sketch viewer
00076   static Socket *localDialogSock;  //!< socket to talk with local-space sketch viewer
00077   static Socket *localSketchSock;     //!< socket for transmitting sketch images to local-space sketch viewer
00078   static Socket *worldDialogSock;  //!< socket to talk with world-space sketch viewer
00079   static Socket *worldSketchSock;     //!< socket for transmitting sketch images to world-space sketch viewer
00080   
00081 public:
00082   //! Constructor
00083   VRmixin();
00084 
00085   //! Destructor
00086   virtual ~VRmixin(void);
00087   
00088   static void startCrew(); //!< starts map builders, pilot, and lookout
00089   static void stopCrew(); //!< stops map builders, pilot, and lookout
00090   static void requireCrew(const std::string &memberName); //!< checks to make sure Crew is instantiated
00091 
00092   static bool isWalking();
00093 
00094   // serialize the specified Sketch; should use SKETCH encoding later 
00095   static bool encodeSketch(const SketchDataRoot& image);
00096   
00097   //! Import the current color-segmented camera image as a Sketch<uchar>.  Must be called from doEvent().
00098   static Sketch<uchar> sketchFromSeg();
00099   
00100   //! Import channel n image as a Sketch<uchar>.  Must be called from doEvent().
00101   static Sketch<uchar> sketchFromChannel(const RawCameraGenerator::channel_id_t chan);
00102   
00103   //! Import the current y-channel camera image as a Sketch<uchar>a.  Must be called from doEvent().
00104   static Sketch<uchar> sketchFromRawY();
00105   
00106   //! Import the current camera image as a Sketch<yuv>.  Must be called from doEvent().
00107   static Sketch<yuv> sketchFromYUV();
00108   
00109   //! Import the current depth image as a Sketch<usint>.  Must be called from doEvent().
00110   static Sketch<usint> sketchFromDepth();
00111   
00112   //! Import blobs from the current region list as a vector of Shape<BlobData>
00113   static std::vector<Shape<BlobData> >
00114   getBlobsFromRegionGenerator(const color_index color, int minarea=25,
00115             const BlobData::BlobOrientation_t orient=BlobData::groundplane,
00116             const coordinate_t height=0,
00117             const int maxblobs=50);
00118   
00119   //! processes a single line of input for a Sketch request
00120   static void processSketchRequest(const std::string &line, 
00121            SketchSpace &sketches, 
00122            ShapeSpace &shapes);
00123   
00124 #ifdef TGT_HAS_CAMERA
00125   //! Project shapes from cam space to ground space, uses CameraFrameOffset and Kinematics::calculateGroundPlane()
00126   static void projectToGround();
00127 #endif
00128   // without camera, require they provide the camToBase parameter...
00129   //! Project shapes from cam space to ground space, will assume Kinematics::calculateGroundPlane() if plane is not specified
00130   static void projectToGround(const fmat::Transform& camToBase);
00131   static void projectToGround(const fmat::Transform& camToBase, const PlaneEquation& groundplane);
00132   
00133   static bool autoRefreshWorldAllowed;
00134   static bool autoRefreshLocalAllowed;
00135   static bool autoRefreshCameraAllowed;
00136   static void refreshSketchWorld();
00137   static void refreshSketchLocal();
00138   static void refreshSketchCamera();
00139   static void autoRefreshSketchWorld();
00140   static void autoRefreshSketchLocal();
00141   static void autoRefreshSketchCamera();
00142   
00143   //! Used by ShapeSpacePlannerBase::addRobotObstacles to display robot body obstacles at correct point in worldShS
00144   static Point robotObstaclesPt;
00145 
00146   //! Used by ShapeSpacePlannerBase::addRobotObstacles to display robot body obstacles at correct orientation in worldShS
00147   static AngTwoPi robotObstaclesOri;
00148 
00149   static std::vector<ShapeRoot> drawShapes; //!< Vector of shapes to be drawn into the RawCam image
00150 
00151   static VisualOdometry *imageOdometry;
00152 
00153 private:
00154   //! used so static member functions can access non-static members; works because there will always be a unique instance of VRmixin
00155   static VRmixin* theOne;
00156   
00157   // dummy functions to satisfy the compiler
00158   VRmixin (const VRmixin&);  //!< never call this
00159   VRmixin& operator=(const VRmixin&); //!< never call this
00160   
00161   //! Called whenever data is received on camDialogSocket
00162   static int camDialogSockCallback(char *buf, int bytes);
00163   
00164   //! Called whenever data is received on localDialogSocket
00165   static int localDialogSockCallback(char *buf, int bytes);
00166   
00167   //! Called whenever data is received on worldDialogSocket
00168   static int worldDialogSockCallback(char *buf, int bytes);
00169   
00170   static void dialogCallback(char* buf, int bytes, std::string& incomplete,
00171            SketchSpace &SkS, ShapeSpace &ShS);
00172 };
00173   
00174 } // namespace
00175 
00176 #endif

DualCoding 5.1CVS
Generated Mon May 9 04:56:28 2016 by Doxygen 1.6.3