00001 #ifndef Impala_Visualization_MapFunction_h
00002 #define Impala_Visualization_MapFunction_h
00003
00004 #include "Basis/ILog.h"
00005 #include "Core/Array/Arrays.h"
00006 #include "Core/VideoSet/Segmentation.h"
00007
00008 namespace Impala {
00009 namespace Visualization {
00010
00011 class MapFunction
00012 {
00013 public:
00014 MapFunction(int width, int height)
00015 {
00016 mWidth = width;
00017 mHeight = height;
00018 }
00019
00020 virtual void ShotToXY(int shot, int* x, int* y) = 0;
00021 virtual int XYToShot(int x, int y) = 0;
00022 virtual int GetNrShots() = 0;
00023
00024 int GetWidth()
00025 {
00026 return mWidth;
00027 }
00028
00029 int GetHeight()
00030 {
00031 return mHeight;
00032 }
00033
00034 protected:
00035 int mWidth, mHeight;
00036 };
00037
00038
00039 class VideoSquareMapFunction : public MapFunction
00040 {
00041 public:
00042 typedef Core::VideoSet::Segmentation Segmentation;
00043
00044 VideoSquareMapFunction(Segmentation *segmentation, int width, int height) :
00045 MapFunction(width, height)
00046 {
00047 mSegmentation = segmentation;
00048 }
00049
00050 virtual void ShotToXY(int shot, int* x, int* y)
00051 {
00052 int videos = mSegmentation->GetNrVideos();
00053 int video = mSegmentation->GetVideoId(shot);
00054 int shotsinvideo = mSegmentation->GetNrShotsVideo(video);
00055 int videoshot = shot - mSegmentation->GetFirstShotVideo(video);
00056 *x = videoshot * mWidth / shotsinvideo;
00057 *y = video * mHeight / videos;
00058 }
00059
00060 virtual int XYToShot(int x, int y)
00061 {
00062 int videos = mSegmentation->GetNrVideos();
00063 int video = y * videos / mHeight;
00064 if (video < 0) video = 0;
00065 if (video > videos-1) video = videos-1;
00066
00067 int shotsinvideo = mSegmentation->GetNrShotsVideo(video);
00068
00069 int videoshot = x * shotsinvideo / mWidth;
00070 if (videoshot < 0) videoshot = 0;
00071 if (videoshot > shotsinvideo-1) videoshot = shotsinvideo-1;
00072
00073 return videoshot + mSegmentation->GetFirstShotVideo(video);
00074 }
00075
00076 virtual int GetNrShots()
00077 {
00078 return mSegmentation->GetNrShots();
00079 }
00080
00081 private:
00082 Segmentation *mSegmentation;
00083 };
00084
00085 }
00086 }
00087 #endif