formation_dt.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_FORMATION_FORMATION_DT_H
00033 #define RCSC_FORMATION_FORMATION_DT_H
00034 
00035 #include <rcsc/formation/formation.h>
00036 #include <rcsc/geom/delaunay_triangulation.h>
00037 #include <iostream>
00038 
00039 namespace rcsc {
00040 
00045 class FormationDT
00046     : public Formation {
00047 public:
00048 
00053     struct Param {
00054         Vector2D ball_; 
00055         std::vector< Vector2D > players_; 
00056 
00060         Param()
00061             : ball_( 0.0, 0.0 )
00062             , players_( 11 )
00063           { }
00064 
00068         Param( const Snapshot & data );
00069 
00075         Param( const Vector2D & ball,
00076                const std::vector< Vector2D > & players )
00077             : ball_( ball )
00078             , players_( players )
00079           { }
00080 
00087         const
00088         Param & assign( const Vector2D & ball,
00089                         const std::vector< Vector2D > & players )
00090           {
00091               ball_ = ball;
00092               players_ = players;
00093               return *this;
00094           }
00095 
00101         Vector2D getPosition( const int unum ) const;
00102     };
00103 
00104 private:
00105 
00107     std::string M_role_name[11];
00108 
00110     std::vector< Param > M_param;
00111 
00113     DelaunayTriangulation M_triangulation;
00114 
00115 public:
00116 
00120     FormationDT();
00121 
00126     const
00127     std::vector< Param > & params() const
00128       {
00129           return M_param;
00130       }
00131 
00136     static
00137     std::string name()
00138       {
00139           return std::string( "DelaunayTriangulation" );
00140       }
00141 
00146     static
00147     Formation * create()
00148       {
00149           return ( new FormationDT );
00150       }
00151 
00156     const
00157     DelaunayTriangulation & triangulation() const
00158       {
00159           return M_triangulation;
00160       }
00161 
00162     //--------------------------------------------------------------
00163 
00168     virtual
00169     std::string methodName() const
00170       {
00171           return FormationDT::name();
00172       }
00173 
00178     virtual
00179     Snapshot createDefaultParam();
00180 
00181 protected:
00188     virtual
00189     void createNewRole( const int unum,
00190                         const std::string & role_name,
00191                         const SideType type );
00197     virtual
00198     void setRoleName( const int unum,
00199                       const std::string & name );
00200 
00201 public:
00202 
00209     virtual
00210     std::string getRoleName( const int unum ) const;
00211 
00217     virtual
00218     Vector2D getPosition( const int unum,
00219                           const Vector2D & focus_point ) const;
00220 
00221     /*
00222       \brief get all positions for the current focus point
00223       \param focus_point current focus point, usually ball position
00224       \param positions contaner to store the result
00225      */
00226     virtual
00227     void getPositions( const Vector2D & focus_point,
00228                        std::vector< Vector2D > & positions ) const;
00229 
00234     virtual
00235     void train( const std::list< Snapshot > & train_data );
00236 
00242     virtual
00243     bool read( std::istream & is );
00244 
00250     virtual
00251     std::ostream & print( std::ostream & os ) const;
00252 
00253 private:
00254 
00255     Vector2D interpolate( const int unum,
00256                           const Vector2D & focus_point,
00257                           const DelaunayTriangulation::TrianglePtr tri ) const;
00258 
00264     bool readRoles( std::istream & is );
00265 
00271     bool readSamples( std::istream & is );
00272 
00273 };
00274 
00275 }
00276 
00277 #endif

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