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 MapBuilder;
00030 class ShapeBasedParticleFilter;
00031   
00032 typedef unsigned char cmap_t;
00033 
00034 //! Mix-in for the BehaviorBase or StateNode class to give access to VisualRoutinesBehavior variables.
00035 class VRmixin {
00036 protected:
00037   static unsigned int instanceCount; //!< count of VRmixin instances -- when this hits zero, free sketch spaces
00038   static unsigned int crewCount; //!< count of "crew" (pilot, lookout, map builders) users -- stop these when no one is using them
00039   
00040 public:
00041   //! returns reference to the global space instances, call there from global constructors instead of accessing #camSkS, which might not be initialized yet
00042   static SketchSpace& getCamSkS();
00043   static SketchSpace& getLocalSkS();
00044   static SketchSpace& getWorldSkS();
00045   static ShapeSpace& getGroundShS();
00046 
00047   static SketchSpace& camSkS;      //!< The camera sketch space
00048   static ShapeSpace& camShS;       //!< The camera shape space
00049   
00050   static ShapeSpace& groundShS;    //!< The ground shape space of MapBuilder (MapBuilder::groundShS)
00051   
00052   static SketchSpace& localSkS;    //!< The localmap sketch space (LocalMapBuilder::localSkS)
00053   static ShapeSpace& localShS;     //!< The localmap shape space (LocalMapBuilder::localShS)
00054   
00055   static SketchSpace& worldSkS;    //!< The worldmap sketch space (WorldMapBuilder::localSkS)
00056   static ShapeSpace& worldShS;     //!< The worldmap sketch space (WorldMapBuilder::localShS)
00057   static Shape<AgentData> theAgent; //!< The robot (usually lives in worldShS)
00058   
00059   static MapBuilder* mapBuilder;   //!< the global world mapbuilder instance
00060   static Lookout* lookout;         //!< the global Lookout instance
00061 #ifdef TGT_HAS_WALK
00062   static Pilot* pilot;              //!< the global Pilot instance
00063 #endif
00064 #if (defined(TGT_HAS_ARMS) || !defined(STRICT_TGT_MODEL)) && !defined(TGT_IS_AIBO)
00065   static Grasper* grasper;
00066 #endif
00067   
00068   static ShapeBasedParticleFilter *particleFilter;   //!< the global particle filter instance
00069 
00070 private:
00071   static Socket *camDialogSock;    //!< socket to talk with cam-space sketch viewer
00072   static Socket *camSketchSock;       //!< socket for transmitting sketch images to cam-space sketch viewer
00073   static Socket *localDialogSock;  //!< socket to talk with local-space sketch viewer
00074   static Socket *localSketchSock;     //!< socket for transmitting sketch images to local-space sketch viewer
00075   static Socket *worldDialogSock;  //!< socket to talk with world-space sketch viewer
00076   static Socket *worldSketchSock;     //!< socket for transmitting sketch images to world-space sketch viewer
00077   
00078 public:
00079   //! Constructor
00080   VRmixin();
00081 
00082   //! Destructor
00083   virtual ~VRmixin(void);
00084   
00085   static void startCrew(); //!< starts map builders, pilot, and lookout
00086   static void stopCrew(); //!< stops map builders, pilot, and lookout
00087 
00088   // serialize the specified Sketch; should use SKETCH encoding later 
00089   static bool encodeSketch(const SketchDataRoot& image);
00090   
00091   //! Import the current color-segmented camera image as a Sketch<uchar>
00092   static Sketch<uchar> sketchFromSeg();
00093   
00094   //! Import channel n image as a Sketch<uchar>
00095   static Sketch<uchar> sketchFromChannel(const RawCameraGenerator::channel_id_t chan);
00096   
00097   //! Import the current y-channel camera image as a Sketch<uchar>
00098   static Sketch<uchar> sketchFromRawY();
00099   
00100   //! Import the current camera image as a Sketch<yuv>
00101   static Sketch<yuv> sketchFromYUV();
00102   
00103   //! Import the current depth image as a Sketch<usint>
00104   static Sketch<usint> sketchFromDepth();
00105   
00106   //! Import blobs from the current region list as a vector of Shape<BlobData>
00107   static std::vector<Shape<BlobData> >
00108   getBlobsFromRegionGenerator(const color_index color, int minarea=25,
00109             const BlobData::BlobOrientation_t orient=BlobData::groundplane,
00110             const coordinate_t height=0,
00111             const int maxblobs=50);
00112   
00113   //! processes a single line of input for a Sketch request
00114   static void processSketchRequest(const std::string &line, 
00115            SketchSpace &sketches, 
00116            ShapeSpace &shapes);
00117   
00118 #ifdef TGT_HAS_CAMERA
00119   //! Project shapes from cam space to ground space, uses CameraFrameOffset and Kinematics::calculateGroundPlane()
00120   static void projectToGround();
00121 #endif
00122   // without camera, require they provide the camToBase parameter...
00123   //! Project shapes from cam space to ground space, will assume Kinematics::calculateGroundPlane() if plane is not specified
00124   static void projectToGround(const fmat::Transform& camToBase);
00125   static void projectToGround(const fmat::Transform& camToBase, const PlaneEquation& groundplane);
00126 
00127 private:
00128   //! used so static member functions can access non-static members; works because there will always be a unique instance of VRmixin
00129   static VRmixin* theOne;
00130   
00131   // dummy functions to satisfy the compiler
00132   VRmixin (const VRmixin&);  //!< never call this
00133   VRmixin& operator=(const VRmixin&); //!< never call this
00134   
00135   //! Called whenever data is received on camDialogSocket
00136   static int camDialogSockCallback(char *buf, int bytes);
00137   
00138   //! Called whenever data is received on localDialogSocket
00139   static int localDialogSockCallback(char *buf, int bytes);
00140   
00141   //! Called whenever data is received on worldDialogSocket
00142   static int worldDialogSockCallback(char *buf, int bytes);
00143   
00144   static void dialogCallback(char* buf, int bytes, std::string& incomplete,
00145            SketchSpace &SkS, ShapeSpace &ShS);
00146 };
00147   
00148 } // namespace
00149 
00150 #endif

DualCoding 5.1CVS
Generated Fri Mar 16 05:23:48 2012 by Doxygen 1.6.3