visual_sensor.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa AKIYAMA
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_PLAYER_VISUAL_SENSOR_H
00033 #define RCSC_PLAYER_VISUAL_SENSOR_H
00034 
00035 #include <rcsc/game_time.h>
00036 #include <rcsc/types.h>
00037 
00038 #include <map>
00039 #include <list>
00040 #include <vector>
00041 #include <string>
00042 #include <iostream>
00043 
00044 namespace rcsc {
00045 
00050 class VisualSensor {
00051 public:
00052     static const double DIST_ERR; 
00053     static const double DIR_ERR; 
00054 
00058     enum ObjectType {
00059         Obj_Goal,
00060         Obj_Goal_Behind,
00061         Obj_Marker,
00062         Obj_Marker_Behind,
00063         Obj_Line,
00064         Obj_Ball,
00065         Obj_Player,
00066         //Obj_Player_Behind,
00067         Obj_Unknown
00068     };
00069 
00073     enum PlayerType {
00074         Player_Teammate = 10,
00075         Player_Unknown_Teammate = 11,
00076         Player_Opponent = 20,
00077         Player_Unknown_Opponent = 21,
00078         Player_Unknown = 30,
00079         Player_Low_Mode,
00080         Player_Illegal
00081     };
00082 
00086     struct PolarT {
00087         double dist_; 
00088         double dir_; 
00089 
00093         PolarT()
00094             : dist_( VisualSensor::DIST_ERR )
00095             , dir_( VisualSensor::DIR_ERR )
00096           { }
00100         void reset()
00101           {
00102               dist_ = VisualSensor::DIST_ERR;
00103               dir_ = VisualSensor::DIR_ERR;
00104           }
00105     };
00106 
00110     struct MovableT
00111         : public PolarT {
00112         bool has_vel_; 
00113         double dist_chng_; 
00114         double dir_chng_; 
00115 
00119         MovableT()
00120             : PolarT()
00121             , has_vel_( false )
00122             , dist_chng_( 0.0 )
00123             , dir_chng_( 0.0 )
00124           { }
00128         void reset()
00129           {
00130               PolarT::reset();
00131               has_vel_ = false;
00132               dist_chng_ = 0.0;
00133               dir_chng_ = 0.0;
00134           }
00135     };
00136 
00140     struct LineT
00141         : public PolarT {
00143         LineID id_;
00144 
00148         LineT()
00149             : PolarT()
00150             , id_( Line_Unknown )
00151           { }
00155         void reset()
00156           {
00157               PolarT::reset();
00158               id_ = Line_Unknown;
00159           }
00160     };
00161 
00165     struct MarkerT
00166         : public PolarT {
00168         ObjectType object_type_;
00170         MarkerID id_;
00171 
00175         MarkerT()
00176             : PolarT()
00177             , object_type_( VisualSensor::Obj_Unknown )
00178             , id_( Marker_Unknown )
00179           { }
00183         void reset()
00184           {
00185               PolarT::reset();
00186               object_type_ = VisualSensor::Obj_Unknown;
00187               id_ = Marker_Unknown;
00188           }
00189     };
00190 
00194     struct BallT
00195         : public MovableT {
00196 
00200         BallT()
00201             : MovableT()
00202           { }
00206         void reset()
00207           {
00208               MovableT::reset();
00209           }
00210     };
00211 
00215     struct PlayerT
00216         : public MovableT {
00217         int    unum_; 
00218         bool   goalie_; 
00219         double body_; 
00220         double face_; 
00221         double arm_; 
00222         bool   tackle_; 
00223 
00227         PlayerT()
00228             : MovableT()
00229             , unum_( Unum_Unknown )
00230             , goalie_( false )
00231             , body_( VisualSensor::DIR_ERR )
00232             , face_( VisualSensor::DIR_ERR )
00233             , arm_( VisualSensor::DIR_ERR )
00234             , tackle_( false )
00235           { }
00239         void reset()
00240           {
00241               MovableT::reset();
00242               unum_ = Unum_Unknown;
00243               goalie_ = false;
00244               body_ = VisualSensor::DIR_ERR;
00245               face_ = VisualSensor::DIR_ERR;
00246               arm_ = VisualSensor::DIR_ERR;
00247               tackle_ = false;
00248           }
00249     };
00250 
00251 #define USE_LIST_VISUAL_OBJECT
00252 
00253 #ifdef USE_LIST_VISUAL_OBJECT
00254     typedef std::vector< BallT > BallCont;
00255     typedef std::list< MarkerT > MarkerCont;
00256     typedef std::list< LineT > LineCont;
00257     typedef std::list< PlayerT > PlayerCont;
00258 #else
00259     typedef std::vector< BallT > BallCont;
00260     typedef std::vector< MarkerT > MarkerCont;
00261     typedef std::vector< LineT > LineCont;
00262     typedef std::vector< PlayerT > PlayerCont;
00263 #endif
00264 
00265 private:
00266 
00267     GameTime M_time; 
00268 
00269     std::string M_opponent_team_name; 
00270 
00272     std::map< std::string, MarkerID > M_marker_map;
00274     std::map< std::string, MarkerID > M_marker_map_old;
00275 
00276     BallCont M_balls; 
00277     MarkerCont M_markers; 
00278     MarkerCont M_behind_markers; 
00279     LineCont M_lines; 
00280 
00281     PlayerCont M_teammates; 
00282     PlayerCont M_unknown_teammates; 
00283     PlayerCont M_opponents; 
00284     PlayerCont M_unknown_opponents; 
00285     PlayerCont M_unknown_players; 
00286 
00287 public:
00288 
00292     VisualSensor();
00293 
00301     void parse( const char * msg,
00302                 const char * team_name, // self team name
00303                 const double & version, // client version
00304                 const GameTime & current );
00305 
00310     const
00311     std::string & opponentTeamName() const
00312       {
00313           return M_opponent_team_name;
00314       }
00315 
00320     const
00321     GameTime & time() const
00322       {
00323           return M_time;
00324       }
00325 
00330     const
00331     BallCont & balls() const
00332       {
00333           return M_balls;
00334       }
00335 
00340     const
00341     MarkerCont & markers() const
00342       {
00343           return M_markers;
00344       }
00345 
00350     const
00351     MarkerCont & behindMarkers() const
00352       {
00353           return M_behind_markers;
00354       }
00355 
00360     const
00361     LineCont & lines() const
00362       {
00363           return M_lines;
00364       }
00365 
00370     const
00371     PlayerCont & teammates() const
00372       {
00373           return M_teammates;
00374       }
00375 
00380     const
00381     PlayerCont & unknownTeammates() const
00382       {
00383           return M_unknown_teammates;
00384       }
00385 
00390     const
00391     PlayerCont & opponents() const
00392       {
00393           return M_opponents;
00394       }
00395 
00400     const
00401     PlayerCont & unknownOpponents() const
00402       {
00403           return M_unknown_opponents;
00404       }
00405 
00410     const
00411     PlayerCont & unknownPlayers() const
00412       {
00413           return M_unknown_players;
00414       }
00415 
00421     std::ostream & print( std::ostream & os );
00422 
00423 private:
00425     ObjectType getObjectTypeOf( const char c )
00426       {
00427           switch ( c ) {
00428           case 'f':  return Obj_Marker;
00429           case 'g':  return Obj_Goal;
00430           case 'F':  return Obj_Marker_Behind;
00431           case 'G':  return Obj_Goal_Behind;
00432           case 'p':  case 'P':  return Obj_Player;
00433           case 'b':  case 'B':  return Obj_Ball;
00434           case 'l':  return Obj_Line;
00435           default:   return Obj_Unknown;
00436           }
00437       }
00438 
00447     bool parseMarker( const char * tok,
00448                       const double & version,
00449                       MarkerT * info );
00450 
00459     bool parseLine( const char * tok,
00460                     const double & version,
00461                     LineT * info );
00462 
00470     bool parseBall( const char * tok,
00471                     BallT * info );
00472 
00482     PlayerType parsePlayer( const char * tok,
00483                             const char * team_name,
00484                             const int team_name_len,
00485                             PlayerT * info );
00486 
00490     void clearAll();
00491 
00492 };
00493 
00494 }
00495 
00496 #endif

librcscに対してThu May 1 15:41:21 2008に生成されました。  doxygen 1.5.0