Homepage Demos Overview Downloads Tutorials 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/debuget.h" // needed for ASSERT macros
00010 #include "Vision/RawCameraGenerator.h"
00011 #include "Vision/SegmentedColorGenerator.h"
00012 #include "Vision/cmv_types.h" // needed for 'run' type?
00013 #include "Wireless/Wireless.h"
00014 #include "Shared/Config.h"
00015 #include "Shared/get_time.h" // needed for time stamp, for serialization 
00016 
00017 #include "ShapeAgent.h"
00018 #include "BlobData.h"
00019 #include "SketchRoot.h"
00020 
00021 namespace DualCoding {
00022 
00023 class Lookout;
00024 class Pilot;
00025 class SketchDataRoot;
00026 class SketchSpace;
00027 class MapBuilder;
00028 class ParticleFilter;
00029 
00030 typedef unsigned char cmap_t;
00031 
00032 //! Mix-in for the BehaviorBase or StateNode class to give access to VisualRoutinesBehavior variables.
00033 class VRmixin {
00034 protected:
00035   static unsigned int instanceCount; //!< count of NewVRmixin instances -- when this hits zero, free sketch spaces
00036   static unsigned int crewCount; //!< count of "crew" (pilot, lookout, map builders) users -- stop these when no one is using them
00037   
00038 public:
00039   //! returns reference to the global space instances, call there from global constructors instead of accessing #camSkS, which might not be initialized yet
00040   static SketchSpace& getCamSkS();
00041   static SketchSpace& getLocalSkS();
00042   static SketchSpace& getWorldSkS();
00043   static ShapeSpace& getGroundShS();
00044 
00045   //! returns reference to the global WorldMapBuilder instance, call this from global constructors instead of accessing #worldmap or #localmap, which might not be initialized yet
00046   static MapBuilder& getMapBuilder();
00047   
00048   static SketchSpace& camSkS;      //!< The camera sketch space
00049   static ShapeSpace& camShS;       //!< The camera shape space
00050   
00051   static ShapeSpace& groundShS;    //!< The ground shape space of MapBuilder (MapBuilder::groundShS)
00052   
00053   static SketchSpace& localSkS;    //!< The localmap sketch space (LocalMapBuilder::localSkS)
00054   static ShapeSpace& localShS;     //!< The localmap shape space (LocalMapBuilder::localShS)
00055   
00056   static SketchSpace& worldSkS;    //!< The worldmap sketch space (WorldMapBuilder::localSkS)
00057   static ShapeSpace& worldShS;     //!< The worldmap sketch space (WorldMapBuilder::localShS)
00058   static Shape<AgentData> theAgent; //!< The robot (usually lives in worldShS)
00059   
00060   static MapBuilder& mapBuilder;   //!< the global world mapbuilder instance
00061   static Pilot pilot;              //!< the global Pilot instance
00062   static Lookout lookout;          //!< the global Lookout instance
00063   static ParticleFilter filter;    //!< particle filter for localization
00064   
00065 private:
00066   static Socket *camDialogSock;    //!< socket to talk with cam-space sketch viewer
00067   static Socket *camRleSock;       //!< socket for transmitting RLE images to cam-space sketch viewer
00068   static Socket *localDialogSock;  //!< socket to talk with local-space sketch viewer
00069   static Socket *localRleSock;     //!< socket for transmitting RLE images to local-space sketch viewer
00070   static Socket *worldDialogSock;  //!< socket to talk with world-space sketch viewer
00071   static Socket *worldRleSock;     //!< socket for transmitting RLE images to world-space sketch viewer
00072   
00073 public:
00074   //! Constructor
00075   VRmixin();
00076 
00077   //! Destructor
00078   virtual ~VRmixin(void);
00079   
00080   static void startCrew(); //!< starts map builders, pilot, and lookout
00081   static void stopCrew(); //!< stops map builders, pilot, and lookout
00082   
00083   // serialize the specified Sketch; should use RLE encoding later 
00084   static bool rleEncodeSketch(const SketchDataRoot& image);
00085   
00086   //! Import the current color-segmented camera image as a Sketch<uchar>
00087   static Sketch<uchar> sketchFromSeg();
00088   
00089   //! Import channel n image as a Sketch<uchar>
00090   static Sketch<uchar> sketchFromChannel(RawCameraGenerator::channel_id_t chan);
00091   
00092   //! Import the current y-channel camera image as a Sketch<uchar>
00093   static Sketch<uchar> sketchFromRawY();
00094   
00095   //! Import blobs from the current region list as a vector of Shape<BlobData>
00096   static std::vector<Shape<BlobData> >
00097   getBlobsFromRegionGenerator(int color, int minarea=0,
00098             BlobData::BlobOrientation_t orient=BlobData::groundplane,
00099             int maxblobs=50);
00100   
00101   //! processes a single line of input for a Sketch request
00102   static void processSketchRequest(const std::string &line, 
00103            SketchSpace &sketches, 
00104            ShapeSpace &shapes);
00105   
00106   //! project shapes from cam space to ground space
00107   static void projectToGround(const NEWMAT::Matrix& camToBase = kine->jointToBase(CameraFrameOffset),
00108             const NEWMAT::ColumnVector& ground_plane = kine->calculateGroundPlane());
00109 
00110 private:
00111   //! used so static member functions can access non-static members
00112   static VRmixin* theOne;
00113   
00114   // dummy functions to satisfy the compiler
00115   VRmixin (const VRmixin&);  //!< never call this
00116   VRmixin& operator=(const VRmixin&); //!< never call this
00117   
00118   //! Called whenever data is received on camDialogSocket
00119   static int camDialogSockCallback(char *buf, int bytes);
00120   
00121   //! Called whenever data is received on localDialogSocket
00122   static int localDialogSockCallback(char *buf, int bytes);
00123   
00124   //! Called whenever data is received on worldDialogSocket
00125   static int worldDialogSockCallback(char *buf, int bytes);
00126   
00127   static void dialogCallback(char* buf, int bytes, std::string& incomplete,
00128            SketchSpace &SkS, ShapeSpace &ShS);
00129 };
00130   
00131 } // namespace
00132 
00133 #endif

DualCoding 3.0beta
Generated Wed Oct 4 00:01:54 2006 by Doxygen 1.4.7