debug_client.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_DEBUG_CLIENT_H
00033 #define RCSC_PLAYER_DEBUG_CLIENT_H
00034 
00035 #include <rcsc/geom/vector_2d.h>
00036 #include <rcsc/geom/triangle_2d.h>
00037 #include <rcsc/geom/rect_2d.h>
00038 #include <rcsc/geom/circle_2d.h>
00039 
00040 #include <boost/shared_ptr.hpp>
00041 
00042 #include <fstream>
00043 #include <vector>
00044 #include <string>
00045 #include <utility>
00046 
00047 namespace rcsc {
00048 
00049 class UDPSocket;
00050 class WorldModel;
00051 
00060 class DebugClient {
00061 public:
00062     enum ServerType {
00063         SoccerViewer,
00064         SoccerWindow2,
00065     };
00066 
00067     static const std::size_t MAX_LINE = 50;
00068     static const std::size_t MAX_TRIANGLE = 50;
00069     static const std::size_t MAX_RECT = 50;
00070     static const std::size_t MAX_CIRCLE = 50;
00071 
00072 private:
00073 
00075     bool M_on;
00076 
00078     bool M_connected;
00079 
00081     boost::shared_ptr< UDPSocket > M_socket;
00082 
00084     bool M_write_mode;
00085 
00087     std::string M_main_buffer;
00089     int M_target_unum;
00091     Vector2D M_target_point;
00093     std::string M_message;
00094 
00096     std::vector< std::pair< Vector2D, Vector2D > > M_lines;
00098     std::vector< Triangle2D > M_triangles;
00100     std::vector< Rect2D > M_rectangles;
00102     std::vector< Circle2D > M_circles;
00103 
00104 
00105 public:
00109     DebugClient();
00110 
00114     ~DebugClient();
00115 
00121     void connect( const std::string & hostname,
00122                   const int port );
00123 
00127     void setWriteMode( const bool on );
00128 
00133     void writeAll( const WorldModel & world );
00134 
00135 private:
00139     void close();
00140 
00147     void toStr( const WorldModel & world );
00148 
00152     void send();
00153 
00158     void write( const long & cycle );
00159 
00160 public:
00164     void clear();
00165 
00169     void addMessage( const char * msg,
00170                      ... );
00171 
00176     void setTarget( const int unum )
00177       {
00178           M_target_unum = unum;
00179       }
00180 
00185     void setTarget( const Vector2D & p )
00186       {
00187           M_target_point = p;
00188       }
00189 
00195     void addLine( const Vector2D & from,
00196                   const Vector2D & to );
00197 
00204     void addTriangle( const Vector2D & v1,
00205                       const Vector2D & v2,
00206                       const Vector2D & v3 )
00207       {
00208           if ( M_on )
00209           {
00210               addTriangle( Triangle2D( v1, v2, v3 ) );
00211           }
00212       }
00213 
00218     void addTriangle( const Triangle2D & tri );
00219 
00224     void addRectangle( const Rect2D & rect );
00225 
00231     void addCircle( const Vector2D & center,
00232                     const double & radius )
00233       {
00234           addCircle( Circle2D( center, radius ) );
00235       }
00236 
00241     void addCircle( const Circle2D & circle );
00242 };
00243 
00244 }
00245 
00246 #endif

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