1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/** 
 * @file BallCandidates.h
 *
 * Declaration of class BallCandidates
 */

#ifndef _BallCandidates_h_
#define _BallCandidates_h_

#include <Tools/Math/Vector2.h>
#include <Tools/ImageProcessing/ImagePrimitives.h>
//#include <Tools/ColorClasses.h>

#include <Tools/DataStructures/Serializer.h>

#include <list>
#include <vector>

class BallCandidates
{
public:
  BallCandidates(){}

  class ClassifiedPixel
  {
  public:
    Pixel pixel;
    unsigned char c; // ColorClasses::Color, NOTE: sizeof(ColorClasses::Color) == 4
  };

  template<typename T>
  class PatchT 
  {
  private:
    size_t _size;
    
  public:
    PatchT() : _size(0)
    {}

    PatchT(size_t size) : 
      _size(size), 
      data(size*size)
    {}

    PatchT(const Vector2i& min, const Vector2i& max) : 
      _size(0),
      min(min), 
      max(max)
    {}

    PatchT(const Vector2i& min, const Vector2i& max, size_t size) :
      _size(size),
      min(min), 
      max(max),
      data(size*size)
    {}

    void setSize(size_t size) {
      _size = size;
      data.resize(size*size);
    }

    size_t size() const {
      return _size;
    }

    Vector2i center() const {
      return Vector2i((min.x + max.x)/2, (min.y + max.y)/2);
    }

    double radius() const {
      return static_cast<double>(max.x - min.x)/2.0;
    }

    int width() const {
      return max.x - min.x;
    }

    int height() const {
      return max.y - min.y;
    }

  public:
    Vector2i min;
    Vector2i max;
    std::vector<T> data;
  };

  typedef PatchT<unsigned char> Patch;
  typedef PatchT<Pixel> PatchYUV;
  typedef PatchT<ClassifiedPixel> PatchYUVClassified;

  typedef std::list<Patch> PatchesList;
  PatchesList patches;

  typedef std::list<PatchYUV> PatchesYUVList;
  PatchesYUVList patchesYUV;

  typedef std::list<PatchYUVClassified> PatchYUVClassifiedList;
  PatchYUVClassifiedList patchesYUVClassified;

  Patch& nextFreePatch() {
    patches.emplace_back();
    return patches.back();
  }

  PatchYUV& nextFreePatchYUV() {
    patchesYUV.emplace_back();
    return patchesYUV.back();
  }

  PatchYUVClassified& nextFreePatchYUVClassified() {
    patchesYUVClassified.emplace_back();
    return patchesYUVClassified.back();
  }

  void reset()
  {
    patches.clear();
    patchesYUV.clear();
    patchesYUVClassified.clear();
  }

  virtual ~BallCandidates() {}
};

class BallCandidatesTop : public BallCandidates
{
public:
  virtual ~BallCandidatesTop() {}
};

namespace naoth
{
  template<>
  class Serializer<BallCandidates>
  {
  public:
    static void serialize(const BallCandidates& representation, std::ostream& stream);<--- Function 'serialize' argument 1 names different: declaration 'representation' definition 'r'.
    static void deserialize(std::istream& stream, BallCandidates& representation);<--- Function 'deserialize' argument 2 names different: declaration 'representation' definition 'r'.
  };

  template<>
  class Serializer<BallCandidatesTop> : public Serializer<BallCandidates>
  {};
}


#endif //_BallCandidates_h_