TigsInputFrame.H
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef TIGS_TIGSINPUTFRAME_H_DEFINED
00039 #define TIGS_TIGSINPUTFRAME_H_DEFINED
00040
00041 #include "Image/Hash.H"
00042 #include "Image/Image.H"
00043 #include "Image/Pixels.H"
00044 #include "Util/SimTime.H"
00045 #include "Util/log.H"
00046 #include "rutz/shared_ptr.h"
00047
00048
00049 class TigsInputFrame
00050 {
00051 public:
00052 TigsInputFrame(const Image<PixRGB<byte> >& in, const SimTime& t)
00053 :
00054 itsGhost(false),
00055 itsTime(t), itsHashInited(false),
00056 itsOrigbounds(in.getBounds()),
00057 itsOrigframe(in)
00058 {
00059
00060
00061
00062 ASSERT(in.getDims() == Dims(640,480));
00063 }
00064
00065 TigsInputFrame(const SimTime& t, const Dims& dims,
00066 const Digest<16>& hash)
00067 :
00068 itsGhost(true),
00069 itsTime(t), itsHashInited(true), itsHash(hash),
00070 itsOrigbounds(Rectangle(Point2D<int>(0,0), dims))
00071 {
00072 ASSERT(dims == Dims(640,480));
00073 }
00074
00075 static rutz::shared_ptr<TigsInputFrame>
00076 fromGhostString(const std::string& s);
00077
00078 std::string toGhostString() const;
00079
00080 bool isGhost() const { return itsGhost; }
00081
00082 SimTime t() const
00083 { return itsTime; }
00084
00085 Digest<16> getHash() const
00086 {
00087 if (!itsHashInited)
00088 {
00089 if (itsGhost)
00090 LFATAL("ghost frames must have a precomputed hash");
00091
00092
00093 const int msec = int(itsTime.msecs());
00094
00095 itsHash = md5rgb(&itsOrigframe, &msec, sizeof(msec));
00096 itsHashInited = true;
00097 }
00098
00099 return itsHash;
00100 }
00101
00102 const Rectangle& origbounds() const
00103 { return itsOrigbounds; }
00104
00105 const Image<PixRGB<byte> >& origframe() const
00106 {
00107 if (itsGhost)
00108 LFATAL("origframe() not allowed for ghost frames");
00109
00110 return itsOrigframe;
00111 }
00112
00113 const Image<PixRGB<byte> >& rgb() const
00114 {
00115 if (itsGhost)
00116 LFATAL("rgb() not allowed for ghost frames");
00117
00118 initialize();
00119 return itsRGB;
00120 }
00121
00122 const Image<float>& lum() const
00123 {
00124 if (itsGhost)
00125 LFATAL("lum() not allowed for ghost frames");
00126
00127 initialize();
00128 return itsLum;
00129 }
00130
00131 const Image<float>& rg() const
00132 {
00133 if (itsGhost)
00134 LFATAL("rg() not allowed for ghost frames");
00135
00136 initialize();
00137 return itsRG;
00138 }
00139
00140 const Image<float>& by() const
00141 {
00142 if (itsGhost)
00143 LFATAL("by() not allowed for ghost frames");
00144
00145 initialize();
00146 return itsBY;
00147 }
00148
00149 private:
00150 void initialize() const;
00151
00152 bool itsGhost;
00153
00154 SimTime itsTime;
00155
00156 mutable bool itsHashInited;
00157 mutable Digest<16> itsHash;
00158
00159 Rectangle itsOrigbounds;
00160
00161 Image<PixRGB<byte> > itsOrigframe;
00162 mutable Image<PixRGB<byte> > itsRGB;
00163 mutable Image<float> itsLum;
00164 mutable Image<float> itsRG;
00165 mutable Image<float> itsBY;
00166 };
00167
00168
00169
00170
00171
00172
00173
00174
00175 #endif // TIGS_TIGSINPUTFRAME_H_DEFINED