Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Modules/SelfLocator/LinesTables2005.cpp

Go to the documentation of this file.
00001 /**
00002  * @file Modules/SelfLocator/LinesTables2005.cpp
00003  * 
00004  * This file contains a class that represents the tables used for localization based on field lines.
00005  *
00006  * @author <A href=mailto:roefer@tzi.de>Thomas Röfer</A>
00007  */
00008 
00009 #include "LinesTables2005.h"
00010 #include "Tools/Debugging/Debugging.h"
00011 #include "Tools/Streams/InStreams.h"
00012 
00013 Field LinesTables2005::field;
00014 LinesTables2005::ObsTable* LinesTables2005::observationTable = 0;
00015 LinesTables2005::TempTable* LinesTables2005::templateTable = 0;
00016 int LinesTables2005::refCount = 0;
00017 
00018 //#define SAVE
00019 //#define BOUNDARYASFIELDLINE
00020 
00021 static const char* fileName = "lines05.tab";
00022 
00023 LinesTables2005::LinesTables2005()
00024 {
00025   if(!refCount++)
00026   {
00027     int i;
00028     observationTable = new ObsTable[LinesPercept::numberOfLineTypes];
00029     templateTable = new TempTable;
00030 
00031 #ifdef SAVE
00032     OutBinaryFile stream(fileName);
00033     for(i = 0; i < LinesPercept::numberOfLineTypes; ++i)
00034     {
00035       observationTable[i].create(field,LinesPercept::LineType(i));
00036       stream << observationTable[i];
00037     }
00038     // create template table for yellow goal, as in field red player is assumed
00039     // the table contains always entries for the own goal
00040     templateTable->create(field,LinesPercept::yellowGoal);
00041     stream << *templateTable;
00042 #else
00043     InBinaryFile stream(fileName);
00044     if(stream.exists())
00045     {
00046       for(i = 0; i < LinesPercept::numberOfLineTypes; ++i)
00047         stream >> observationTable[i];
00048       stream >> *templateTable;
00049     }
00050     else
00051     {
00052       OUTPUT(idText, text, "LinesTables2005 : " << fileName << " not found");
00053     }
00054 #endif
00055   }
00056 }
00057 
00058 LinesTables2005::~LinesTables2005()
00059 {
00060   if(!--refCount)
00061   {
00062     delete [] observationTable;
00063     delete templateTable;
00064   }
00065 }
00066 
00067 template<int xSize,int ySize,int cellSize,int pointRes> void LinesTables2005::ObservationTable<xSize,ySize,cellSize,pointRes>::create(const Field& field,LinesPercept::LineType type)
00068 {
00069   for(int r = 0; r < 4; ++r)
00070     for(int y = 0; y < ySize; ++y)
00071       for(int x = 0; x < xSize; ++x)
00072       {
00073         Vector2<double> px(
00074           (x + 0.5 - xSize / 2) * cellSize,
00075           (y + 0.5 - ySize / 2) * cellSize
00076         );
00077         Vector2<double> p;
00078         if(
00079           field.getClosestPoint(
00080             p,
00081             Pose2D(r * pi_2, px),
00082             4,
00083             type))
00084         {
00085 #ifdef BOUNDARYASFIELDLINE
00086           if (type == LinesPercept::field)
00087           {
00088             Vector2<double> p2 = field.getClosestPoint(
00089               Pose2D(r * pi_2, px),
00090               4,
00091               LinesPercept::boundary);
00092             if ((p2 - px).abs() < (p - px).abs())
00093               p = p2;
00094           }
00095 #endif
00096           point[r][y][x][0] = char(sgn(p.x) * int(fabs(p.x / pointRes + 0.5)));
00097           point[r][y][x][1] = char(sgn(p.y) * int(fabs(p.y / pointRes + 0.5)));
00098           pointIsValid[r][y][x] = true;
00099         }
00100         else
00101           pointIsValid[r][y][x] = false;
00102       }
00103 }

Generated on Mon Mar 20 21:59:56 2006 for GT2005 by doxygen 1.3.6