00001 #ifndef __CImageSegmentation_H_2005_03_23_15_44_W_AI__
00002 #define __CImageSegmentation_H_2005_03_23_15_44_W_AI__ 1
00003
00004 #include <vector>
00005 #include <map>
00006 #include <assert.h>
00007
00008 namespace segmentation {
00009
00010
00011 template <class INDEX_TYPE = signed long int, INDEX_TYPE idxUndefinedSegment = -1>
00012 class TImageSegmentation
00013 {
00014 public:
00015 typedef INDEX_TYPE THE_INDEX_TYPE;
00016 enum { IdxUndefinedSegment = idxUndefinedSegment};
00017
00018
00019 TImageSegmentation(long width=0, long height=0);
00020
00021
00022
00023 TImageSegmentation(const TImageSegmentation & copy);
00024
00025
00026 ~TImageSegmentation();
00027
00028
00029 bool Init(long width, long height);
00030
00031
00032 inline INDEX_TYPE * operator * ();
00033 inline const INDEX_TYPE * operator * () const;
00034
00035
00036 inline INDEX_TYPE & operator () (const long x, const long y);
00037 inline const INDEX_TYPE & operator () (const long x, const long y) const;
00038
00039
00040 INDEX_TYPE Width() const
00041 { return mWidth; }
00042
00043
00044 INDEX_TYPE Height() const
00045 { return mHeight; }
00046
00047
00048
00049 bool GetUsedSegmentIndexes(std::map<INDEX_TYPE, size_t> &indexSet) const;
00050
00051
00052 bool ReorderSegmentIndexes();
00053
00054
00055 long GetSegmentCount() const;
00056
00057
00058 protected:
00059 typedef std::vector<INDEX_TYPE> INDEX_ARRAY;
00060
00061 INDEX_ARRAY mIndexArray;
00062 long mWidth;
00063 long mHeight;
00064
00065
00066
00067 inline
00068 bool InitDone() const
00069 {
00070 AssertValid();
00071 return mWidth>0;
00072 }
00073
00074 #if defined(DEBUG) || defined(_DEBUG)
00075
00076 inline
00077 void AssertValid() const
00078 {
00079 assert((mWidth==0 && mHeight==0 && mIndexArray.size()==0) ||
00080 (mWidth>0 && mHeight>0 && mIndexArray.size()==mWidth*mHeight));
00081 }
00082
00083 inline
00084 void AssertNonEmpty() const
00085 {
00086 assert(InitDone());
00087 }
00088
00089 #else // Release versions of these functions are empty
00090 inline
00091 void AssertValid() const {}
00092
00093 inline
00094 void AssertNonEmpty() const {}
00095 #endif
00096
00097 };
00098
00099 }
00100
00101 #include "TImageSegmentation.txx"
00102
00103 #endif
00104